Skip to content
This repository has been archived by the owner on Nov 14, 2019. It is now read-only.

Commit

Permalink
Merge pull request #143 from mesg-foundation/feature/exists-api
Browse files Browse the repository at this point in the history
Add exists api for services
  • Loading branch information
Nicolas Mahé authored Oct 2, 2019
2 parents dc09d39 + badd6fd commit df1a184
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 82 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@

#### Breaking Changes
#### Added

- ([#143](https://github.com/mesg-foundation/mesg-js/pull/143)) Add new `service.Hash` and `service.Exists` APIs

#### Changed
#### Fixed
#### Removed

- ([#143](https://github.com/mesg-foundation/mesg-js/pull/143)) Remove service.delete api

## [v4.4.0](https://github.com/mesg-foundation/mesg-js/compare/v4.4.0)

#### Added
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mesg-js",
"version": "4.5.0-beta.2",
"version": "4.5.0-beta.4",
"description": "",
"main": "lib/index.js",
"scripts": {
Expand Down
10 changes: 7 additions & 3 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import {
EventCreateInputs, EventCreateOutputs, EventStreamInputs,
ExecutionCreateInputs, ExecutionGetInputs, ExecutionUpdateInputs, ExecutionCreateOutputs, ExecutionGetOutputs, ExecutionUpdateOutputs, ExecutionStreamInputs,
InstanceCreateInputs, InstanceGetInputs, InstanceListInputs, InstanceDeleteInputs, InstanceCreateOutputs, InstanceGetOutputs, InstanceListOutputs, InstanceDeleteOutputs,
ServiceCreateInputs, ServiceGetInputs, ServiceListInputs, ServiceDeleteInputs, ServiceCreateOutputs, ServiceGetOutputs, ServiceListOutputs, ServiceDeleteOutputs,
ServiceCreateInputs, ServiceGetInputs, ServiceListInputs, ServiceCreateOutputs, ServiceGetOutputs, ServiceListOutputs, ServiceExistsOutputs,
ProcessCreateInputs, ProcessGetInputs, ProcessListInputs, ProcessDeleteInputs, ProcessCreateOutputs, ProcessGetOutputs, ProcessListOutputs, ProcessDeleteOutputs,
OwnershipListInputs, OwnershipListOutputs,
Credential
Credential,
ServiceExistsInputs,
ServiceHashInputs,
ServiceHashOutputs
} from './types'

const promisify = (client, method) => (request, credential?: Credential) => {
Expand Down Expand Up @@ -55,8 +58,9 @@ export default (endpoint: string): API => {
service: {
create: promisify(service, 'Create') as (request: ServiceCreateInputs, credential?: Credential) => ServiceCreateOutputs,
get: promisify(service, 'Get') as (request: ServiceGetInputs, credential?: Credential) => ServiceGetOutputs,
exists: promisify(service, 'Exists') as (request: ServiceExistsInputs, credential?: Credential) => ServiceExistsOutputs,
hash: promisify(service, 'Hash') as (request: ServiceHashInputs, credential?: Credential) => ServiceHashOutputs,
list: promisify(service, 'List') as (request: ServiceListInputs, credential?: Credential) => ServiceListOutputs,
delete: promisify(service, 'Delete') as (request: ServiceDeleteInputs, credential?: Credential) => ServiceDeleteOutputs
},
process: {
create: promisify(process, 'Create') as (request: ProcessCreateInputs, credential?: Credential) => ProcessCreateOutputs,
Expand Down
3 changes: 2 additions & 1 deletion src/api/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ export default (endpoint: string): API => ({
service: {
create() { return Promise.resolve({ hash }) },
get() { return Promise.resolve({ sid: 'xxx', source: 'xxx' }) },
hash() { return Promise.resolve({ hash }) },
exists() { return Promise.resolve({ exists: true }) },
list() { return Promise.resolve({ services: [] }) },
delete() { return Promise.resolve({}) },
},
process: {
create() { return Promise.resolve({ hash }) },
Expand Down
157 changes: 102 additions & 55 deletions src/api/typedef/service.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,20 +366,6 @@ declare namespace mesg {
*/
public create(request: mesg.api.ICreateServiceRequest): Promise<mesg.api.CreateServiceResponse>;

/**
* Calls Delete.
* @param request DeleteServiceRequest message or plain object
* @param callback Node-style callback called with the error, if any, and DeleteServiceResponse
*/
public delete(request: mesg.api.IDeleteServiceRequest, callback: mesg.api.Service.DeleteCallback): void;

/**
* Calls Delete.
* @param request DeleteServiceRequest message or plain object
* @returns Promise
*/
public delete(request: mesg.api.IDeleteServiceRequest): Promise<mesg.api.DeleteServiceResponse>;

/**
* Calls Get.
* @param request GetServiceRequest message or plain object
Expand Down Expand Up @@ -407,6 +393,34 @@ declare namespace mesg {
* @returns Promise
*/
public list(request: mesg.api.IListServiceRequest): Promise<mesg.api.ListServiceResponse>;

/**
* Calls Exists.
* @param request ExistsServiceRequest message or plain object
* @param callback Node-style callback called with the error, if any, and ExistsServiceResponse
*/
public exists(request: mesg.api.IExistsServiceRequest, callback: mesg.api.Service.ExistsCallback): void;

/**
* Calls Exists.
* @param request ExistsServiceRequest message or plain object
* @returns Promise
*/
public exists(request: mesg.api.IExistsServiceRequest): Promise<mesg.api.ExistsServiceResponse>;

/**
* Calls Hash.
* @param request CreateServiceRequest message or plain object
* @param callback Node-style callback called with the error, if any, and HashServiceResponse
*/
public hash(request: mesg.api.ICreateServiceRequest, callback: mesg.api.Service.HashCallback): void;

/**
* Calls Hash.
* @param request CreateServiceRequest message or plain object
* @returns Promise
*/
public hash(request: mesg.api.ICreateServiceRequest): Promise<mesg.api.HashServiceResponse>;
}

namespace Service {
Expand All @@ -418,13 +432,6 @@ declare namespace mesg {
*/
type CreateCallback = (error: (Error|null), response?: mesg.api.CreateServiceResponse) => void;

/**
* Callback as used by {@link mesg.api.Service#delete_}.
* @param error Error, if any
* @param [response] DeleteServiceResponse
*/
type DeleteCallback = (error: (Error|null), response?: mesg.api.DeleteServiceResponse) => void;

/**
* Callback as used by {@link mesg.api.Service#get}.
* @param error Error, if any
Expand All @@ -438,6 +445,20 @@ declare namespace mesg {
* @param [response] ListServiceResponse
*/
type ListCallback = (error: (Error|null), response?: mesg.api.ListServiceResponse) => void;

/**
* Callback as used by {@link mesg.api.Service#exists}.
* @param error Error, if any
* @param [response] ExistsServiceResponse
*/
type ExistsCallback = (error: (Error|null), response?: mesg.api.ExistsServiceResponse) => void;

/**
* Callback as used by {@link mesg.api.Service#hash}.
* @param error Error, if any
* @param [response] HashServiceResponse
*/
type HashCallback = (error: (Error|null), response?: mesg.api.HashServiceResponse) => void;
}

/** Properties of a CreateServiceRequest. */
Expand Down Expand Up @@ -528,40 +549,6 @@ declare namespace mesg {
public hash: Uint8Array;
}

/** Properties of a DeleteServiceRequest. */
interface IDeleteServiceRequest {

/** DeleteServiceRequest hash */
hash?: (Uint8Array|null);
}

/** Represents a DeleteServiceRequest. */
class DeleteServiceRequest implements IDeleteServiceRequest {

/**
* Constructs a new DeleteServiceRequest.
* @param [properties] Properties to set
*/
constructor(properties?: mesg.api.IDeleteServiceRequest);

/** DeleteServiceRequest hash. */
public hash: Uint8Array;
}

/** Properties of a DeleteServiceResponse. */
interface IDeleteServiceResponse {
}

/** Represents a DeleteServiceResponse. */
class DeleteServiceResponse implements IDeleteServiceResponse {

/**
* Constructs a new DeleteServiceResponse.
* @param [properties] Properties to set
*/
constructor(properties?: mesg.api.IDeleteServiceResponse);
}

/** Properties of a GetServiceRequest. */
interface IGetServiceRequest {

Expand Down Expand Up @@ -615,6 +602,66 @@ declare namespace mesg {
/** ListServiceResponse services. */
public services: mesg.types.IService[];
}

/** Properties of an ExistsServiceRequest. */
interface IExistsServiceRequest {

/** ExistsServiceRequest hash */
hash?: (Uint8Array|null);
}

/** Represents an ExistsServiceRequest. */
class ExistsServiceRequest implements IExistsServiceRequest {

/**
* Constructs a new ExistsServiceRequest.
* @param [properties] Properties to set
*/
constructor(properties?: mesg.api.IExistsServiceRequest);

/** ExistsServiceRequest hash. */
public hash: Uint8Array;
}

/** Properties of an ExistsServiceResponse. */
interface IExistsServiceResponse {

/** ExistsServiceResponse exists */
exists?: (boolean|null);
}

/** Represents an ExistsServiceResponse. */
class ExistsServiceResponse implements IExistsServiceResponse {

/**
* Constructs a new ExistsServiceResponse.
* @param [properties] Properties to set
*/
constructor(properties?: mesg.api.IExistsServiceResponse);

/** ExistsServiceResponse exists. */
public exists: boolean;
}

/** Properties of a HashServiceResponse. */
interface IHashServiceResponse {

/** HashServiceResponse hash */
hash?: (Uint8Array|null);
}

/** Represents a HashServiceResponse. */
class HashServiceResponse implements IHashServiceResponse {

/**
* Constructs a new HashServiceResponse.
* @param [properties] Properties to set
*/
constructor(properties?: mesg.api.IHashServiceResponse);

/** HashServiceResponse hash. */
public hash: Uint8Array;
}
}
}

Expand Down
12 changes: 8 additions & 4 deletions src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,18 @@ export type InstanceDeleteOutputs = Promise<InstanceType.mesg.api.IDeleteInstanc
export type ServiceGetInputs = ServiceType.mesg.api.IGetServiceRequest
export type ServiceGetOutputs = Promise<Service>

export type ServiceHashInputs = ServiceType.mesg.api.ICreateServiceRequest
export type ServiceHashOutputs = Promise<ServiceType.mesg.api.IHashServiceResponse>

export type ServiceExistsInputs = ServiceType.mesg.api.IExistsServiceRequest
export type ServiceExistsOutputs = Promise<ServiceType.mesg.api.IExistsServiceResponse>

export type ServiceListInputs = ServiceType.mesg.api.IListServiceRequest
export type ServiceListOutputs = Promise<ServiceType.mesg.api.IListServiceResponse>

export type ServiceCreateInputs = ServiceType.mesg.api.ICreateServiceRequest
export type ServiceCreateOutputs = Promise<ServiceType.mesg.api.ICreateServiceResponse>

export type ServiceDeleteInputs = ServiceType.mesg.api.IDeleteServiceRequest
export type ServiceDeleteOutputs = Promise<ServiceType.mesg.api.IDeleteServiceResponse>

export type ProcessGetInputs = ProcessType.mesg.api.IGetProcessRequest
export type ProcessGetOutputs = Promise<Process>

Expand Down Expand Up @@ -130,9 +133,10 @@ export type API = {
}
service: {
get: (request: ServiceGetInputs, credential?: Credential) => ServiceGetOutputs
hash: (request: ServiceHashInputs, credential?: Credential) => ServiceHashOutputs
exists: (request: ServiceExistsInputs, credential?: Credential) => ServiceExistsOutputs
list: (request: ServiceListInputs, credential?: Credential) => ServiceListOutputs
create: (request: ServiceCreateInputs, credential?: Credential) => ServiceCreateOutputs
delete: (request: ServiceDeleteInputs, credential?: Credential) => ServiceDeleteOutputs
},
process: {
get: (request: ProcessGetInputs, credential?: Credential) => ProcessGetOutputs
Expand Down
47 changes: 30 additions & 17 deletions src/protobuf/api/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@ service Service {
// It will return an unique identifier which is used to interact with the Service.
rpc Create (CreateServiceRequest) returns (CreateServiceResponse) {}

// Delete a Service.
// An error is returned if one or more Instances of the Service are running.
rpc Delete (DeleteServiceRequest) returns (DeleteServiceResponse) {}

// Get returns a Service matching the criteria of the request.
rpc Get(GetServiceRequest) returns (types.Service) {}

// List returns services specified in a request.
rpc List(ListServiceRequest) returns (ListServiceResponse) {}

// Exists return if a service already exists.
rpc Exists(ExistsServiceRequest) returns (ExistsServiceResponse) {}

// Hash return the hash of a service
rpc Hash(CreateServiceRequest) returns (HashServiceResponse) {}
}

// The request's data for the `Create` API.
Expand Down Expand Up @@ -69,19 +71,6 @@ message CreateServiceResponse {
];
}

// The request's data for the `Delete` API.
message DeleteServiceRequest {
// The service's hash to delete.
bytes hash = 1 [
(gogoproto.customtype) = "github.com/mesg-foundation/engine/hash.Hash",
(gogoproto.nullable) = false
];
}

// The response's data for the `Delete` API, doesn't contain anything.
message DeleteServiceResponse {
}

// The request's data for the `Get` API.
message GetServiceRequest {
// The service's hash to fetch.
Expand All @@ -99,3 +88,27 @@ message ListServiceResponse {
// List of services that match the request's filters.
repeated types.Service services = 1;
}

// The request's data for the `List` API.
message ExistsServiceRequest {
// The service's hash of the existing service. This hash is nil if exists is fals.
bytes hash = 1 [
(gogoproto.customtype) = "github.com/mesg-foundation/engine/hash.Hash",
(gogoproto.nullable) = false
];
}

// The response's data for the `Exists` API.
message ExistsServiceResponse {
// True if a service already exists, false otherwise.
bool exists = 1;
}

// The request's data for the `Hash` API.
message HashServiceResponse {
// Hash of the service calculated.
bytes hash = 1 [
(gogoproto.customtype) = "github.com/mesg-foundation/engine/hash.Hash",
(gogoproto.nullable) = false
];
}

0 comments on commit df1a184

Please sign in to comment.