diff --git a/copy-proto b/copy-proto index a841d2e..b88d287 100755 --- a/copy-proto +++ b/copy-proto @@ -1,17 +1,25 @@ #!/bin/sh DEF_REPO="mesg-foundation/core" -DEF_BRANCH="dev" +DEF_BRANCH="${1:-dev}" PROTO_PATH="https://raw.githubusercontent.com/$DEF_REPO/$DEF_BRANCH/protobuf" DIR="./" rm -rf src/protobuf +rm -rf src/api/typedef mkdir -p src/protobuf/api mkdir -p src/protobuf/types +mkdir -p src/api/typedef ressources="event execution instance service" for ressource in $ressources; do curl -o "./src/protobuf/api/${ressource}.proto" "$PROTO_PATH/api/${ressource}.proto" curl -o "./src/protobuf/types/${ressource}.proto" "$PROTO_PATH/types/${ressource}.proto" + npx pbjs -t static-module \ + --no-create --no-encode --no-decode --no-verify --no-convert --no-delimited \ + -o "./src/api/typedef/$ressource.js" \ + "./src/protobuf/types/${ressource}.proto" "./src/protobuf/api/${ressource}.proto" + npx pbts -o "./src/api/typedef/$ressource.d.ts" --name mesg "./src/api/typedef/$ressource.js" + rm "./src/api/typedef/$ressource.js" done curl -o "./src/protobuf/api/core.proto" "$PROTO_PATH/coreapi/api.proto" diff --git a/package.json b/package.json index 405af73..f205470 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "", "main": "lib/index.js", "scripts": { - "build": "rimraf ./lib && tsc && ncp ./src/protobuf/ ./lib/protobuf/", + "build": "rimraf ./lib && tsc && ncp ./src/protobuf/ ./lib/protobuf/ && ncp src/api/typedef lib/api/typedef", "prepublishOnly": "npm run test && npm run build", "test": "ts-node ./node_modules/tape/bin/tape 'src/**/*_test.ts'", "coverage": "rimraf ./istanbul && tsc --project tsconfig-istanbul.json && ncp ./src/protobuf/ ./istanbul/protobuf && istanbul cover -x 'istanbul/**/*_test.js' --report html ./node_modules/.bin/tape 'istanbul/**/*_test.js'", @@ -26,6 +26,7 @@ "istanbul": "^0.4.5", "ncp": "^2.0.0", "nodemon": "^1.19.1", + "protobufjs": "^6.8.8", "rimraf": "^2.6.2", "sinon": "^6.1.3", "tape": "^4.10.2", @@ -37,4 +38,4 @@ "typescript": { "definition": "lib/index.d.ts" } -} +} \ No newline at end of file diff --git a/src/api/mock.ts b/src/api/mock.ts index 39782f4..8acdfbd 100644 --- a/src/api/mock.ts +++ b/src/api/mock.ts @@ -1,5 +1,5 @@ import { EventEmitter } from 'events' -import { API, Event, Execution } from './types' +import { API } from './types' import { Stream } from '../util/grpc'; const hash = 'hash' @@ -18,8 +18,8 @@ class StreamMock implements Stream { } export const streams = { - event: new StreamMock(), - execution: new StreamMock() + event: new StreamMock(), + execution: new StreamMock() } export default (endpoint: string): API => ({ diff --git a/src/api/typedef/event.d.ts b/src/api/typedef/event.d.ts new file mode 100644 index 0000000..758e7b3 --- /dev/null +++ b/src/api/typedef/event.d.ts @@ -0,0 +1,216 @@ +import * as $protobuf from "protobufjs"; +export = mesg; + +declare namespace mesg { + + + /** Namespace types. */ + namespace types { + + /** Properties of an Event. */ + interface IEvent { + + /** Event hash */ + hash?: (string|null); + + /** Event instanceHash */ + instanceHash?: (string|null); + + /** Event key */ + key?: (string|null); + + /** Event data */ + data?: (string|null); + } + + /** Represents an Event. */ + class Event implements IEvent { + + /** + * Constructs a new Event. + * @param [properties] Properties to set + */ + constructor(properties?: types.IEvent); + + /** Event hash. */ + public hash: string; + + /** Event instanceHash. */ + public instanceHash: string; + + /** Event key. */ + public key: string; + + /** Event data. */ + public data: string; + } + } + + /** Namespace api. */ + namespace api { + + /** Represents an Event */ + class Event extends $protobuf.rpc.Service { + + /** + * Constructs a new Event service. + * @param rpcImpl RPC implementation + * @param [requestDelimited=false] Whether requests are length-delimited + * @param [responseDelimited=false] Whether responses are length-delimited + */ + constructor(rpcImpl: $protobuf.RPCImpl, requestDelimited?: boolean, responseDelimited?: boolean); + + /** + * Calls Create. + * @param request CreateEventRequest message or plain object + * @param callback Node-style callback called with the error, if any, and CreateEventResponse + */ + public create(request: api.ICreateEventRequest, callback: api.Event.CreateCallback): void; + + /** + * Calls Create. + * @param request CreateEventRequest message or plain object + * @returns Promise + */ + public create(request: api.ICreateEventRequest): Promise; + + /** + * Calls Stream. + * @param request StreamEventRequest message or plain object + * @param callback Node-style callback called with the error, if any, and Event + */ + public stream(request: api.IStreamEventRequest, callback: api.Event.StreamCallback): void; + + /** + * Calls Stream. + * @param request StreamEventRequest message or plain object + * @returns Promise + */ + public stream(request: api.IStreamEventRequest): Promise; + } + + namespace Event { + + /** + * Callback as used by {@link api.Event#create}. + * @param error Error, if any + * @param [response] CreateEventResponse + */ + type CreateCallback = (error: (Error|null), response?: api.CreateEventResponse) => void; + + /** + * Callback as used by {@link api.Event#stream}. + * @param error Error, if any + * @param [response] Event + */ + type StreamCallback = (error: (Error|null), response?: types.Event) => void; + } + + /** Properties of a StreamEventRequest. */ + interface IStreamEventRequest { + + /** StreamEventRequest filter */ + filter?: (api.StreamEventRequest.IFilter|null); + } + + /** Represents a StreamEventRequest. */ + class StreamEventRequest implements IStreamEventRequest { + + /** + * Constructs a new StreamEventRequest. + * @param [properties] Properties to set + */ + constructor(properties?: api.IStreamEventRequest); + + /** StreamEventRequest filter. */ + public filter?: (api.StreamEventRequest.IFilter|null); + } + + namespace StreamEventRequest { + + /** Properties of a Filter. */ + interface IFilter { + + /** Filter hash */ + hash?: (string|null); + + /** Filter instanceHash */ + instanceHash?: (string|null); + + /** Filter key */ + key?: (string|null); + } + + /** Represents a Filter. */ + class Filter implements IFilter { + + /** + * Constructs a new Filter. + * @param [properties] Properties to set + */ + constructor(properties?: api.StreamEventRequest.IFilter); + + /** Filter hash. */ + public hash: string; + + /** Filter instanceHash. */ + public instanceHash: string; + + /** Filter key. */ + public key: string; + } + } + + /** Properties of a CreateEventRequest. */ + interface ICreateEventRequest { + + /** CreateEventRequest instanceHash */ + instanceHash?: (string|null); + + /** CreateEventRequest key */ + key?: (string|null); + + /** CreateEventRequest data */ + data?: (string|null); + } + + /** Represents a CreateEventRequest. */ + class CreateEventRequest implements ICreateEventRequest { + + /** + * Constructs a new CreateEventRequest. + * @param [properties] Properties to set + */ + constructor(properties?: api.ICreateEventRequest); + + /** CreateEventRequest instanceHash. */ + public instanceHash: string; + + /** CreateEventRequest key. */ + public key: string; + + /** CreateEventRequest data. */ + public data: string; + } + + /** Properties of a CreateEventResponse. */ + interface ICreateEventResponse { + + /** CreateEventResponse hash */ + hash?: (string|null); + } + + /** Represents a CreateEventResponse. */ + class CreateEventResponse implements ICreateEventResponse { + + /** + * Constructs a new CreateEventResponse. + * @param [properties] Properties to set + */ + constructor(properties?: api.ICreateEventResponse); + + /** CreateEventResponse hash. */ + public hash: string; + } + } +} diff --git a/src/api/typedef/execution.d.ts b/src/api/typedef/execution.d.ts new file mode 100644 index 0000000..3d488f4 --- /dev/null +++ b/src/api/typedef/execution.d.ts @@ -0,0 +1,384 @@ +import * as $protobuf from "protobufjs"; +export = mesg; + +declare namespace mesg { + + + /** Namespace types. */ + namespace types { + + /** Status enum. */ + enum Status { + Unknown = 0, + Created = 1, + InProgress = 2, + Completed = 3, + Failed = 4 + } + + /** Properties of an Execution. */ + interface IExecution { + + /** Execution hash */ + hash?: (string|null); + + /** Execution parentHash */ + parentHash?: (string|null); + + /** Execution eventHash */ + eventHash?: (string|null); + + /** Execution status */ + status?: (types.Status|null); + + /** Execution instanceHash */ + instanceHash?: (string|null); + + /** Execution taskKey */ + taskKey?: (string|null); + + /** Execution inputs */ + inputs?: (string|null); + + /** Execution outputs */ + outputs?: (string|null); + + /** Execution error */ + error?: (string|null); + + /** Execution tags */ + tags?: (string[]|null); + } + + /** Represents an Execution. */ + class Execution implements IExecution { + + /** + * Constructs a new Execution. + * @param [properties] Properties to set + */ + constructor(properties?: types.IExecution); + + /** Execution hash. */ + public hash: string; + + /** Execution parentHash. */ + public parentHash: string; + + /** Execution eventHash. */ + public eventHash: string; + + /** Execution status. */ + public status: types.Status; + + /** Execution instanceHash. */ + public instanceHash: string; + + /** Execution taskKey. */ + public taskKey: string; + + /** Execution inputs. */ + public inputs: string; + + /** Execution outputs. */ + public outputs: string; + + /** Execution error. */ + public error: string; + + /** Execution tags. */ + public tags: string[]; + } + } + + /** Namespace api. */ + namespace api { + + /** Represents an Execution */ + class Execution extends $protobuf.rpc.Service { + + /** + * Constructs a new Execution service. + * @param rpcImpl RPC implementation + * @param [requestDelimited=false] Whether requests are length-delimited + * @param [responseDelimited=false] Whether responses are length-delimited + */ + constructor(rpcImpl: $protobuf.RPCImpl, requestDelimited?: boolean, responseDelimited?: boolean); + + /** + * Calls Create. + * @param request CreateExecutionRequest message or plain object + * @param callback Node-style callback called with the error, if any, and CreateExecutionResponse + */ + public create(request: api.ICreateExecutionRequest, callback: api.Execution.CreateCallback): void; + + /** + * Calls Create. + * @param request CreateExecutionRequest message or plain object + * @returns Promise + */ + public create(request: api.ICreateExecutionRequest): Promise; + + /** + * Calls Get. + * @param request GetExecutionRequest message or plain object + * @param callback Node-style callback called with the error, if any, and Execution + */ + public get(request: api.IGetExecutionRequest, callback: api.Execution.GetCallback): void; + + /** + * Calls Get. + * @param request GetExecutionRequest message or plain object + * @returns Promise + */ + public get(request: api.IGetExecutionRequest): Promise; + + /** + * Calls Stream. + * @param request StreamExecutionRequest message or plain object + * @param callback Node-style callback called with the error, if any, and Execution + */ + public stream(request: api.IStreamExecutionRequest, callback: api.Execution.StreamCallback): void; + + /** + * Calls Stream. + * @param request StreamExecutionRequest message or plain object + * @returns Promise + */ + public stream(request: api.IStreamExecutionRequest): Promise; + + /** + * Calls Update. + * @param request UpdateExecutionRequest message or plain object + * @param callback Node-style callback called with the error, if any, and UpdateExecutionResponse + */ + public update(request: api.IUpdateExecutionRequest, callback: api.Execution.UpdateCallback): void; + + /** + * Calls Update. + * @param request UpdateExecutionRequest message or plain object + * @returns Promise + */ + public update(request: api.IUpdateExecutionRequest): Promise; + } + + namespace Execution { + + /** + * Callback as used by {@link api.Execution#create}. + * @param error Error, if any + * @param [response] CreateExecutionResponse + */ + type CreateCallback = (error: (Error|null), response?: api.CreateExecutionResponse) => void; + + /** + * Callback as used by {@link api.Execution#get}. + * @param error Error, if any + * @param [response] Execution + */ + type GetCallback = (error: (Error|null), response?: types.Execution) => void; + + /** + * Callback as used by {@link api.Execution#stream}. + * @param error Error, if any + * @param [response] Execution + */ + type StreamCallback = (error: (Error|null), response?: types.Execution) => void; + + /** + * Callback as used by {@link api.Execution#update}. + * @param error Error, if any + * @param [response] UpdateExecutionResponse + */ + type UpdateCallback = (error: (Error|null), response?: api.UpdateExecutionResponse) => void; + } + + /** Properties of a CreateExecutionRequest. */ + interface ICreateExecutionRequest { + + /** CreateExecutionRequest instanceHash */ + instanceHash?: (string|null); + + /** CreateExecutionRequest taskKey */ + taskKey?: (string|null); + + /** CreateExecutionRequest inputs */ + inputs?: (string|null); + + /** CreateExecutionRequest tags */ + tags?: (string[]|null); + } + + /** Represents a CreateExecutionRequest. */ + class CreateExecutionRequest implements ICreateExecutionRequest { + + /** + * Constructs a new CreateExecutionRequest. + * @param [properties] Properties to set + */ + constructor(properties?: api.ICreateExecutionRequest); + + /** CreateExecutionRequest instanceHash. */ + public instanceHash: string; + + /** CreateExecutionRequest taskKey. */ + public taskKey: string; + + /** CreateExecutionRequest inputs. */ + public inputs: string; + + /** CreateExecutionRequest tags. */ + public tags: string[]; + } + + /** Properties of a CreateExecutionResponse. */ + interface ICreateExecutionResponse { + + /** CreateExecutionResponse hash */ + hash?: (string|null); + } + + /** Represents a CreateExecutionResponse. */ + class CreateExecutionResponse implements ICreateExecutionResponse { + + /** + * Constructs a new CreateExecutionResponse. + * @param [properties] Properties to set + */ + constructor(properties?: api.ICreateExecutionResponse); + + /** CreateExecutionResponse hash. */ + public hash: string; + } + + /** Properties of a GetExecutionRequest. */ + interface IGetExecutionRequest { + + /** GetExecutionRequest hash */ + hash?: (string|null); + } + + /** Represents a GetExecutionRequest. */ + class GetExecutionRequest implements IGetExecutionRequest { + + /** + * Constructs a new GetExecutionRequest. + * @param [properties] Properties to set + */ + constructor(properties?: api.IGetExecutionRequest); + + /** GetExecutionRequest hash. */ + public hash: string; + } + + /** Properties of a StreamExecutionRequest. */ + interface IStreamExecutionRequest { + + /** StreamExecutionRequest filter */ + filter?: (api.StreamExecutionRequest.IFilter|null); + } + + /** Represents a StreamExecutionRequest. */ + class StreamExecutionRequest implements IStreamExecutionRequest { + + /** + * Constructs a new StreamExecutionRequest. + * @param [properties] Properties to set + */ + constructor(properties?: api.IStreamExecutionRequest); + + /** StreamExecutionRequest filter. */ + public filter?: (api.StreamExecutionRequest.IFilter|null); + } + + namespace StreamExecutionRequest { + + /** Properties of a Filter. */ + interface IFilter { + + /** Filter statuses */ + statuses?: (types.Status[]|null); + + /** Filter instanceHash */ + instanceHash?: (string|null); + + /** Filter taskKey */ + taskKey?: (string|null); + + /** Filter tags */ + tags?: (string[]|null); + } + + /** Represents a Filter. */ + class Filter implements IFilter { + + /** + * Constructs a new Filter. + * @param [properties] Properties to set + */ + constructor(properties?: api.StreamExecutionRequest.IFilter); + + /** Filter statuses. */ + public statuses: types.Status[]; + + /** Filter instanceHash. */ + public instanceHash: string; + + /** Filter taskKey. */ + public taskKey: string; + + /** Filter tags. */ + public tags: string[]; + } + } + + /** Properties of an UpdateExecutionRequest. */ + interface IUpdateExecutionRequest { + + /** UpdateExecutionRequest hash */ + hash?: (string|null); + + /** UpdateExecutionRequest outputs */ + outputs?: (string|null); + + /** UpdateExecutionRequest error */ + error?: (string|null); + } + + /** Represents an UpdateExecutionRequest. */ + class UpdateExecutionRequest implements IUpdateExecutionRequest { + + /** + * Constructs a new UpdateExecutionRequest. + * @param [properties] Properties to set + */ + constructor(properties?: api.IUpdateExecutionRequest); + + /** UpdateExecutionRequest hash. */ + public hash: string; + + /** UpdateExecutionRequest outputs. */ + public outputs: string; + + /** UpdateExecutionRequest error. */ + public error: string; + + /** UpdateExecutionRequest result. */ + public result?: ("outputs"|"error"); + } + + /** Properties of an UpdateExecutionResponse. */ + interface IUpdateExecutionResponse { + } + + /** Represents an UpdateExecutionResponse. */ + class UpdateExecutionResponse implements IUpdateExecutionResponse { + + /** + * Constructs a new UpdateExecutionResponse. + * @param [properties] Properties to set + */ + constructor(properties?: api.IUpdateExecutionResponse); + } + } +} diff --git a/src/api/typedef/instance.d.ts b/src/api/typedef/instance.d.ts new file mode 100644 index 0000000..24ba03e --- /dev/null +++ b/src/api/typedef/instance.d.ts @@ -0,0 +1,285 @@ +import * as $protobuf from "protobufjs"; +export = mesg; + +declare namespace mesg { + + + /** Namespace types. */ + namespace types { + + /** Properties of an Instance. */ + interface IInstance { + + /** Instance hash */ + hash?: (string|null); + + /** Instance serviceHash */ + serviceHash?: (string|null); + } + + /** Represents an Instance. */ + class Instance implements IInstance { + + /** + * Constructs a new Instance. + * @param [properties] Properties to set + */ + constructor(properties?: types.IInstance); + + /** Instance hash. */ + public hash: string; + + /** Instance serviceHash. */ + public serviceHash: string; + } + } + + /** Namespace api. */ + namespace api { + + /** Represents an Instance */ + class Instance extends $protobuf.rpc.Service { + + /** + * Constructs a new Instance service. + * @param rpcImpl RPC implementation + * @param [requestDelimited=false] Whether requests are length-delimited + * @param [responseDelimited=false] Whether responses are length-delimited + */ + constructor(rpcImpl: $protobuf.RPCImpl, requestDelimited?: boolean, responseDelimited?: boolean); + + /** + * Calls Get. + * @param request GetInstanceRequest message or plain object + * @param callback Node-style callback called with the error, if any, and Instance + */ + public get(request: api.IGetInstanceRequest, callback: api.Instance.GetCallback): void; + + /** + * Calls Get. + * @param request GetInstanceRequest message or plain object + * @returns Promise + */ + public get(request: api.IGetInstanceRequest): Promise; + + /** + * Calls List. + * @param request ListInstancesRequest message or plain object + * @param callback Node-style callback called with the error, if any, and ListInstancesResponse + */ + public list(request: api.IListInstancesRequest, callback: api.Instance.ListCallback): void; + + /** + * Calls List. + * @param request ListInstancesRequest message or plain object + * @returns Promise + */ + public list(request: api.IListInstancesRequest): Promise; + + /** + * Calls Create. + * @param request CreateInstanceRequest message or plain object + * @param callback Node-style callback called with the error, if any, and CreateInstanceResponse + */ + public create(request: api.ICreateInstanceRequest, callback: api.Instance.CreateCallback): void; + + /** + * Calls Create. + * @param request CreateInstanceRequest message or plain object + * @returns Promise + */ + public create(request: api.ICreateInstanceRequest): Promise; + + /** + * Calls Delete. + * @param request DeleteInstanceRequest message or plain object + * @param callback Node-style callback called with the error, if any, and DeleteInstanceResponse + */ + public delete(request: api.IDeleteInstanceRequest, callback: api.Instance.DeleteCallback): void; + + /** + * Calls Delete. + * @param request DeleteInstanceRequest message or plain object + * @returns Promise + */ + public delete(request: api.IDeleteInstanceRequest): Promise; + } + + namespace Instance { + + /** + * Callback as used by {@link api.Instance#get}. + * @param error Error, if any + * @param [response] Instance + */ + type GetCallback = (error: (Error|null), response?: types.Instance) => void; + + /** + * Callback as used by {@link api.Instance#list}. + * @param error Error, if any + * @param [response] ListInstancesResponse + */ + type ListCallback = (error: (Error|null), response?: api.ListInstancesResponse) => void; + + /** + * Callback as used by {@link api.Instance#create}. + * @param error Error, if any + * @param [response] CreateInstanceResponse + */ + type CreateCallback = (error: (Error|null), response?: api.CreateInstanceResponse) => void; + + /** + * Callback as used by {@link api.Instance#delete_}. + * @param error Error, if any + * @param [response] DeleteInstanceResponse + */ + type DeleteCallback = (error: (Error|null), response?: api.DeleteInstanceResponse) => void; + } + + /** Properties of a GetInstanceRequest. */ + interface IGetInstanceRequest { + + /** GetInstanceRequest hash */ + hash?: (string|null); + } + + /** Represents a GetInstanceRequest. */ + class GetInstanceRequest implements IGetInstanceRequest { + + /** + * Constructs a new GetInstanceRequest. + * @param [properties] Properties to set + */ + constructor(properties?: api.IGetInstanceRequest); + + /** GetInstanceRequest hash. */ + public hash: string; + } + + /** Properties of a ListInstancesRequest. */ + interface IListInstancesRequest { + + /** ListInstancesRequest serviceHash */ + serviceHash?: (string|null); + } + + /** Represents a ListInstancesRequest. */ + class ListInstancesRequest implements IListInstancesRequest { + + /** + * Constructs a new ListInstancesRequest. + * @param [properties] Properties to set + */ + constructor(properties?: api.IListInstancesRequest); + + /** ListInstancesRequest serviceHash. */ + public serviceHash: string; + } + + /** Properties of a ListInstancesResponse. */ + interface IListInstancesResponse { + + /** ListInstancesResponse instances */ + instances?: (types.IInstance[]|null); + } + + /** Represents a ListInstancesResponse. */ + class ListInstancesResponse implements IListInstancesResponse { + + /** + * Constructs a new ListInstancesResponse. + * @param [properties] Properties to set + */ + constructor(properties?: api.IListInstancesResponse); + + /** ListInstancesResponse instances. */ + public instances: types.IInstance[]; + } + + /** Properties of a CreateInstanceRequest. */ + interface ICreateInstanceRequest { + + /** CreateInstanceRequest serviceHash */ + serviceHash?: (string|null); + + /** CreateInstanceRequest env */ + env?: (string[]|null); + } + + /** Represents a CreateInstanceRequest. */ + class CreateInstanceRequest implements ICreateInstanceRequest { + + /** + * Constructs a new CreateInstanceRequest. + * @param [properties] Properties to set + */ + constructor(properties?: api.ICreateInstanceRequest); + + /** CreateInstanceRequest serviceHash. */ + public serviceHash: string; + + /** CreateInstanceRequest env. */ + public env: string[]; + } + + /** Properties of a CreateInstanceResponse. */ + interface ICreateInstanceResponse { + + /** CreateInstanceResponse hash */ + hash?: (string|null); + } + + /** Represents a CreateInstanceResponse. */ + class CreateInstanceResponse implements ICreateInstanceResponse { + + /** + * Constructs a new CreateInstanceResponse. + * @param [properties] Properties to set + */ + constructor(properties?: api.ICreateInstanceResponse); + + /** CreateInstanceResponse hash. */ + public hash: string; + } + + /** Properties of a DeleteInstanceRequest. */ + interface IDeleteInstanceRequest { + + /** DeleteInstanceRequest hash */ + hash?: (string|null); + + /** DeleteInstanceRequest deleteData */ + deleteData?: (boolean|null); + } + + /** Represents a DeleteInstanceRequest. */ + class DeleteInstanceRequest implements IDeleteInstanceRequest { + + /** + * Constructs a new DeleteInstanceRequest. + * @param [properties] Properties to set + */ + constructor(properties?: api.IDeleteInstanceRequest); + + /** DeleteInstanceRequest hash. */ + public hash: string; + + /** DeleteInstanceRequest deleteData. */ + public deleteData: boolean; + } + + /** Properties of a DeleteInstanceResponse. */ + interface IDeleteInstanceResponse { + } + + /** Represents a DeleteInstanceResponse. */ + class DeleteInstanceResponse implements IDeleteInstanceResponse { + + /** + * Constructs a new DeleteInstanceResponse. + * @param [properties] Properties to set + */ + constructor(properties?: api.IDeleteInstanceResponse); + } + } +} diff --git a/src/api/typedef/service.d.ts b/src/api/typedef/service.d.ts new file mode 100644 index 0000000..aa361ca --- /dev/null +++ b/src/api/typedef/service.d.ts @@ -0,0 +1,616 @@ +import * as $protobuf from "protobufjs"; +export = mesg; + +declare namespace mesg { + + + /** Namespace types. */ + namespace types { + + /** Properties of a Service. */ + interface IService { + + /** Service hash */ + hash?: (string|null); + + /** Service sid */ + sid?: (string|null); + + /** Service name */ + name?: (string|null); + + /** Service description */ + description?: (string|null); + + /** Service configuration */ + configuration?: (types.Service.IConfiguration|null); + + /** Service tasks */ + tasks?: (types.Service.ITask[]|null); + + /** Service events */ + events?: (types.Service.IEvent[]|null); + + /** Service dependencies */ + dependencies?: (types.Service.IDependency[]|null); + + /** Service repository */ + repository?: (string|null); + + /** Service source */ + source?: (string|null); + } + + /** Represents a Service. */ + class Service implements IService { + + /** + * Constructs a new Service. + * @param [properties] Properties to set + */ + constructor(properties?: types.IService); + + /** Service hash. */ + public hash: string; + + /** Service sid. */ + public sid: string; + + /** Service name. */ + public name: string; + + /** Service description. */ + public description: string; + + /** Service configuration. */ + public configuration?: (types.Service.IConfiguration|null); + + /** Service tasks. */ + public tasks: types.Service.ITask[]; + + /** Service events. */ + public events: types.Service.IEvent[]; + + /** Service dependencies. */ + public dependencies: types.Service.IDependency[]; + + /** Service repository. */ + public repository: string; + + /** Service source. */ + public source: string; + } + + namespace Service { + + /** Properties of an Event. */ + interface IEvent { + + /** Event key */ + key?: (string|null); + + /** Event name */ + name?: (string|null); + + /** Event description */ + description?: (string|null); + + /** Event data */ + data?: (types.Service.IParameter[]|null); + } + + /** Represents an Event. */ + class Event implements IEvent { + + /** + * Constructs a new Event. + * @param [properties] Properties to set + */ + constructor(properties?: types.Service.IEvent); + + /** Event key. */ + public key: string; + + /** Event name. */ + public name: string; + + /** Event description. */ + public description: string; + + /** Event data. */ + public data: types.Service.IParameter[]; + } + + /** Properties of a Task. */ + interface ITask { + + /** Task key */ + key?: (string|null); + + /** Task name */ + name?: (string|null); + + /** Task description */ + description?: (string|null); + + /** Task inputs */ + inputs?: (types.Service.IParameter[]|null); + + /** Task outputs */ + outputs?: (types.Service.IParameter[]|null); + } + + /** Represents a Task. */ + class Task implements ITask { + + /** + * Constructs a new Task. + * @param [properties] Properties to set + */ + constructor(properties?: types.Service.ITask); + + /** Task key. */ + public key: string; + + /** Task name. */ + public name: string; + + /** Task description. */ + public description: string; + + /** Task inputs. */ + public inputs: types.Service.IParameter[]; + + /** Task outputs. */ + public outputs: types.Service.IParameter[]; + } + + /** Properties of a Parameter. */ + interface IParameter { + + /** Parameter key */ + key?: (string|null); + + /** Parameter name */ + name?: (string|null); + + /** Parameter description */ + description?: (string|null); + + /** Parameter type */ + type?: (string|null); + + /** Parameter optional */ + optional?: (boolean|null); + + /** Parameter repeated */ + repeated?: (boolean|null); + + /** Parameter object */ + object?: (types.Service.IParameter[]|null); + } + + /** Represents a Parameter. */ + class Parameter implements IParameter { + + /** + * Constructs a new Parameter. + * @param [properties] Properties to set + */ + constructor(properties?: types.Service.IParameter); + + /** Parameter key. */ + public key: string; + + /** Parameter name. */ + public name: string; + + /** Parameter description. */ + public description: string; + + /** Parameter type. */ + public type: string; + + /** Parameter optional. */ + public optional: boolean; + + /** Parameter repeated. */ + public repeated: boolean; + + /** Parameter object. */ + public object: types.Service.IParameter[]; + } + + /** Properties of a Configuration. */ + interface IConfiguration { + + /** Configuration volumes */ + volumes?: (string[]|null); + + /** Configuration volumesFrom */ + volumesFrom?: (string[]|null); + + /** Configuration ports */ + ports?: (string[]|null); + + /** Configuration args */ + args?: (string[]|null); + + /** Configuration command */ + command?: (string|null); + + /** Configuration env */ + env?: (string[]|null); + } + + /** Represents a Configuration. */ + class Configuration implements IConfiguration { + + /** + * Constructs a new Configuration. + * @param [properties] Properties to set + */ + constructor(properties?: types.Service.IConfiguration); + + /** Configuration volumes. */ + public volumes: string[]; + + /** Configuration volumesFrom. */ + public volumesFrom: string[]; + + /** Configuration ports. */ + public ports: string[]; + + /** Configuration args. */ + public args: string[]; + + /** Configuration command. */ + public command: string; + + /** Configuration env. */ + public env: string[]; + } + + /** Properties of a Dependency. */ + interface IDependency { + + /** Dependency key */ + key?: (string|null); + + /** Dependency image */ + image?: (string|null); + + /** Dependency volumes */ + volumes?: (string[]|null); + + /** Dependency volumesFrom */ + volumesFrom?: (string[]|null); + + /** Dependency ports */ + ports?: (string[]|null); + + /** Dependency args */ + args?: (string[]|null); + + /** Dependency command */ + command?: (string|null); + + /** Dependency env */ + env?: (string[]|null); + } + + /** Represents a Dependency. */ + class Dependency implements IDependency { + + /** + * Constructs a new Dependency. + * @param [properties] Properties to set + */ + constructor(properties?: types.Service.IDependency); + + /** Dependency key. */ + public key: string; + + /** Dependency image. */ + public image: string; + + /** Dependency volumes. */ + public volumes: string[]; + + /** Dependency volumesFrom. */ + public volumesFrom: string[]; + + /** Dependency ports. */ + public ports: string[]; + + /** Dependency args. */ + public args: string[]; + + /** Dependency command. */ + public command: string; + + /** Dependency env. */ + public env: string[]; + } + } + } + + /** Namespace api. */ + namespace api { + + /** Represents a Service */ + class Service extends $protobuf.rpc.Service { + + /** + * Constructs a new Service service. + * @param rpcImpl RPC implementation + * @param [requestDelimited=false] Whether requests are length-delimited + * @param [responseDelimited=false] Whether responses are length-delimited + */ + constructor(rpcImpl: $protobuf.RPCImpl, requestDelimited?: boolean, responseDelimited?: boolean); + + /** + * Calls Create. + * @param request CreateServiceRequest message or plain object + * @param callback Node-style callback called with the error, if any, and CreateServiceResponse + */ + public create(request: api.ICreateServiceRequest, callback: api.Service.CreateCallback): void; + + /** + * Calls Create. + * @param request CreateServiceRequest message or plain object + * @returns Promise + */ + public create(request: api.ICreateServiceRequest): Promise; + + /** + * 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: api.IDeleteServiceRequest, callback: api.Service.DeleteCallback): void; + + /** + * Calls Delete. + * @param request DeleteServiceRequest message or plain object + * @returns Promise + */ + public delete(request: api.IDeleteServiceRequest): Promise; + + /** + * Calls Get. + * @param request GetServiceRequest message or plain object + * @param callback Node-style callback called with the error, if any, and Service + */ + public get(request: api.IGetServiceRequest, callback: api.Service.GetCallback): void; + + /** + * Calls Get. + * @param request GetServiceRequest message or plain object + * @returns Promise + */ + public get(request: api.IGetServiceRequest): Promise; + + /** + * Calls List. + * @param request ListServiceRequest message or plain object + * @param callback Node-style callback called with the error, if any, and ListServiceResponse + */ + public list(request: api.IListServiceRequest, callback: api.Service.ListCallback): void; + + /** + * Calls List. + * @param request ListServiceRequest message or plain object + * @returns Promise + */ + public list(request: api.IListServiceRequest): Promise; + } + + namespace Service { + + /** + * Callback as used by {@link api.Service#create}. + * @param error Error, if any + * @param [response] CreateServiceResponse + */ + type CreateCallback = (error: (Error|null), response?: api.CreateServiceResponse) => void; + + /** + * Callback as used by {@link api.Service#delete_}. + * @param error Error, if any + * @param [response] DeleteServiceResponse + */ + type DeleteCallback = (error: (Error|null), response?: api.DeleteServiceResponse) => void; + + /** + * Callback as used by {@link api.Service#get}. + * @param error Error, if any + * @param [response] Service + */ + type GetCallback = (error: (Error|null), response?: types.Service) => void; + + /** + * Callback as used by {@link api.Service#list}. + * @param error Error, if any + * @param [response] ListServiceResponse + */ + type ListCallback = (error: (Error|null), response?: api.ListServiceResponse) => void; + } + + /** Properties of a CreateServiceRequest. */ + interface ICreateServiceRequest { + + /** CreateServiceRequest sid */ + sid?: (string|null); + + /** CreateServiceRequest name */ + name?: (string|null); + + /** CreateServiceRequest description */ + description?: (string|null); + + /** CreateServiceRequest configuration */ + configuration?: (types.Service.IConfiguration|null); + + /** CreateServiceRequest tasks */ + tasks?: (types.Service.ITask[]|null); + + /** CreateServiceRequest events */ + events?: (types.Service.IEvent[]|null); + + /** CreateServiceRequest dependencies */ + dependencies?: (types.Service.IDependency[]|null); + + /** CreateServiceRequest repository */ + repository?: (string|null); + + /** CreateServiceRequest source */ + source?: (string|null); + } + + /** Represents a CreateServiceRequest. */ + class CreateServiceRequest implements ICreateServiceRequest { + + /** + * Constructs a new CreateServiceRequest. + * @param [properties] Properties to set + */ + constructor(properties?: api.ICreateServiceRequest); + + /** CreateServiceRequest sid. */ + public sid: string; + + /** CreateServiceRequest name. */ + public name: string; + + /** CreateServiceRequest description. */ + public description: string; + + /** CreateServiceRequest configuration. */ + public configuration?: (types.Service.IConfiguration|null); + + /** CreateServiceRequest tasks. */ + public tasks: types.Service.ITask[]; + + /** CreateServiceRequest events. */ + public events: types.Service.IEvent[]; + + /** CreateServiceRequest dependencies. */ + public dependencies: types.Service.IDependency[]; + + /** CreateServiceRequest repository. */ + public repository: string; + + /** CreateServiceRequest source. */ + public source: string; + } + + /** Properties of a CreateServiceResponse. */ + interface ICreateServiceResponse { + + /** CreateServiceResponse hash */ + hash?: (string|null); + } + + /** Represents a CreateServiceResponse. */ + class CreateServiceResponse implements ICreateServiceResponse { + + /** + * Constructs a new CreateServiceResponse. + * @param [properties] Properties to set + */ + constructor(properties?: api.ICreateServiceResponse); + + /** CreateServiceResponse hash. */ + public hash: string; + } + + /** Properties of a DeleteServiceRequest. */ + interface IDeleteServiceRequest { + + /** DeleteServiceRequest hash */ + hash?: (string|null); + } + + /** Represents a DeleteServiceRequest. */ + class DeleteServiceRequest implements IDeleteServiceRequest { + + /** + * Constructs a new DeleteServiceRequest. + * @param [properties] Properties to set + */ + constructor(properties?: api.IDeleteServiceRequest); + + /** DeleteServiceRequest hash. */ + public hash: string; + } + + /** Properties of a DeleteServiceResponse. */ + interface IDeleteServiceResponse { + } + + /** Represents a DeleteServiceResponse. */ + class DeleteServiceResponse implements IDeleteServiceResponse { + + /** + * Constructs a new DeleteServiceResponse. + * @param [properties] Properties to set + */ + constructor(properties?: api.IDeleteServiceResponse); + } + + /** Properties of a GetServiceRequest. */ + interface IGetServiceRequest { + + /** GetServiceRequest hash */ + hash?: (string|null); + } + + /** Represents a GetServiceRequest. */ + class GetServiceRequest implements IGetServiceRequest { + + /** + * Constructs a new GetServiceRequest. + * @param [properties] Properties to set + */ + constructor(properties?: api.IGetServiceRequest); + + /** GetServiceRequest hash. */ + public hash: string; + } + + /** Properties of a ListServiceRequest. */ + interface IListServiceRequest { + } + + /** Represents a ListServiceRequest. */ + class ListServiceRequest implements IListServiceRequest { + + /** + * Constructs a new ListServiceRequest. + * @param [properties] Properties to set + */ + constructor(properties?: api.IListServiceRequest); + } + + /** Properties of a ListServiceResponse. */ + interface IListServiceResponse { + + /** ListServiceResponse services */ + services?: (types.IService[]|null); + } + + /** Represents a ListServiceResponse. */ + class ListServiceResponse implements IListServiceResponse { + + /** + * Constructs a new ListServiceResponse. + * @param [properties] Properties to set + */ + constructor(properties?: api.IListServiceResponse); + + /** ListServiceResponse services. */ + public services: types.IService[]; + } + } +} diff --git a/src/api/types.ts b/src/api/types.ts index c1d91b9..a1d1c04 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -1,121 +1,68 @@ import { Stream } from '../util/grpc' +import * as EventType from './typedef/event' +import * as ExecutionType from './typedef/execution' +import * as InstanceType from './typedef/instance' +import * as ServiceType from './typedef/service' -export type JSONString = string export type hash = string -export type Event = { - hash?: hash - instanceHash: string - key: string - data: string +export const ExecutionStatus = { + UNKNOWN: 0, + CREATED: 1, + IN_PROGRESS: 2, + COMPLETED: 3, + FAILED: 4 } -export enum ExecutionStatus { - UNKNOWN = 0, - CREATED = 1, - IN_PROGRESS = 2, - COMPLETED = 3, - FAILED = 4, -} -export type Execution = { - hash?: hash - parentHash: hash - eventHash: hash - status: ExecutionStatus - instanceHash: string - taskKey: string - inputs: JSONString - outputs?: JSONString - error?: string - tags?: string[] -} +export type Event = EventType.types.IEvent -export type Instance = { - hash?: hash - serviceHash: hash -} +export type Execution = ExecutionType.types.IExecution -export type Service = { - hash?: hash - sid: string - name?: string - description?: string - configuration?: ServiceConfiguration - tasks?: ServiceTask[] - events?: ServiceEvent[] - dependencies?: ServiceDependency[] - repository?: string - source: string -} +export type Instance = InstanceType.types.IInstance -export type ServiceConfiguration = any // TODO -export type ServiceTask = any // TODO -export type ServiceEvent = any // TODO -export type ServiceDependency = any // TODO +export type Service = ServiceType.types.IService -export type EventCreateInputs = { - instanceHash: string - key: string - data: JSONString -} -export type EventCreateOutputs = Promise<{ hash: hash }> +export type EventCreateInputs = EventType.api.ICreateEventRequest +export type EventCreateOutputs = Promise -export type EventStreamInputs = { filter?: { hash?: string, instanceHash?: string, key?: string } } +export type EventStreamInputs = EventType.api.StreamEventRequest export type EventStreamOutputs = Stream -export type ExecutionGetInputs = { hash: hash } +export type ExecutionGetInputs = ExecutionType.api.IGetExecutionRequest export type ExecutionGetOutputs = Promise -export type ExecutionStreamInputs = { filter?: { statuses?: ExecutionStatus[], instanceHash?: hash, taskKey?: string, tags?: string[] } } +export type ExecutionStreamInputs = ExecutionType.api.IStreamExecutionRequest export type ExecutionStreamOutputs = Stream -export type ExecutionCreateInputs = { - instanceHash: hash, - taskKey: string, - inputs: JSONString, - tags?: string[] -} -export type ExecutionCreateOutputs = Promise<{ hash: hash }> +export type ExecutionCreateInputs = ExecutionType.api.ICreateExecutionRequest +export type ExecutionCreateOutputs = Promise -export type ExecutionUpdateInputs = { hash: hash, outputs?: JSONString, error?: string } -export type ExecutionUpdateOutputs = Promise<{}> +export type ExecutionUpdateInputs = ExecutionType.api.IUpdateExecutionRequest +export type ExecutionUpdateOutputs = Promise -export type InstanceGetInputs = { hash: hash } +export type InstanceGetInputs = InstanceType.api.IGetInstanceRequest export type InstanceGetOutputs = Promise -export type InstanceListInputs = { serviceHash?: hash } -export type InstanceListOutputs = Promise<{ instances: Instance[] }> +export type InstanceListInputs = InstanceType.api.IListInstancesRequest +export type InstanceListOutputs = Promise -export type InstanceCreateInputs = { - serviceHash: hash, - env?: string[] -} -export type InstanceCreateOutputs = Promise<{ hash: hash }> +export type InstanceCreateInputs = InstanceType.api.ICreateInstanceRequest +export type InstanceCreateOutputs = Promise -export type InstanceDeleteInputs = { hash: hash, deleteData?: boolean } -export type InstanceDeleteOutputs = Promise<{}> +export type InstanceDeleteInputs = InstanceType.api.IDeleteInstanceRequest +export type InstanceDeleteOutputs = Promise -export type ServiceGetInputs = { hash: hash } +export type ServiceGetInputs = ServiceType.api.IGetServiceRequest export type ServiceGetOutputs = Promise -export type ServiceListInputs = {} -export type ServiceListOutputs = Promise<{ services: Service[] }> - -export type ServiceCreateInputs = { - sid: string, - name: string, - description: string, - configuration: ServiceConfiguration, - tasks: ServiceTask[], - events: ServiceEvent[], - dependencies: ServiceDependency[], - repository: string, - source: string -} -export type ServiceCreateOutputs = Promise<{ hash: hash }> +export type ServiceListInputs = ServiceType.api.IListServiceRequest +export type ServiceListOutputs = Promise -export type ServiceDeleteInputs = { hash: hash } -export type ServiceDeleteOutputs = Promise<{}> +export type ServiceCreateInputs = ServiceType.api.ICreateServiceRequest +export type ServiceCreateOutputs = Promise + +export type ServiceDeleteInputs = ServiceType.api.IDeleteServiceRequest +export type ServiceDeleteOutputs = Promise export type InfoOutputs = Promise<{ version: string, services: { sid: string, hash: hash, url: string, key: string }[] }> @@ -145,4 +92,4 @@ export type API = { core: { info: () => InfoOutputs } -} \ No newline at end of file +}