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

Types generation #112

Merged
merged 4 commits into from
Jul 25, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion copy-proto
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
Expand All @@ -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",
Expand All @@ -37,4 +38,4 @@
"typescript": {
"definition": "lib/index.d.ts"
}
}
}
6 changes: 3 additions & 3 deletions src/api/mock.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -18,8 +18,8 @@ class StreamMock<T> implements Stream<T> {
}

export const streams = {
event: new StreamMock<Event>(),
execution: new StreamMock<Execution>()
event: new StreamMock<any>(),
execution: new StreamMock<any>()
}

export default (endpoint: string): API => ({
Expand Down
216 changes: 216 additions & 0 deletions src/api/typedef/event.d.ts
Original file line number Diff line number Diff line change
@@ -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<api.CreateEventResponse>;

/**
* 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<types.Event>;
}

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;
}
}
}
Loading