@nodescript/protocomm
Advanced tools
Comparing version 0.2.0 to 0.5.1
@@ -1,4 +0,8 @@ | ||
import { ObjectPropsDef } from 'airtight'; | ||
import { Event } from 'typesafe-event'; | ||
export declare type DomainDef<S> = { | ||
import { ObjectPropsDef } from '@nodescript/schema'; | ||
import { ChannelEvent } from './channel-event.js'; | ||
export interface EventPayload<T> { | ||
channel: string; | ||
payload: T; | ||
} | ||
export type DomainDef<S> = { | ||
name: string; | ||
@@ -8,12 +12,12 @@ methods: DomainMethods<S>; | ||
}; | ||
export declare type DomainMethod<Params, Returns> = (params: Params) => Promise<Returns>; | ||
declare type IsMethod<S, K extends keyof S> = S[K] extends DomainMethod<any, any> ? K : never; | ||
declare type IsEvent<S, K extends keyof S> = S[K] extends Event<any> ? K : never; | ||
export declare type DomainMethods<S> = { | ||
export type DomainMethod<Params, Returns> = (params: Params) => Promise<Returns>; | ||
type IsMethod<S, K extends keyof S> = S[K] extends DomainMethod<any, any> ? K : never; | ||
type IsEvent<S, K extends keyof S> = S[K] extends ChannelEvent<any> ? K : never; | ||
export type DomainMethods<S> = { | ||
[K in keyof S as IsMethod<S, K>]: S[K] extends DomainMethod<infer P, infer R> ? DomainMethodDef<P, R> : never; | ||
}; | ||
export declare type DomainEvents<S> = { | ||
[K in keyof S as IsEvent<S, K>]: S[K] extends Event<infer E> ? DomainEventDef<E> : never; | ||
export type DomainEvents<S> = { | ||
[K in keyof S as IsEvent<S, K>]: S[K] extends ChannelEvent<infer E> ? DomainEventDef<E> : never; | ||
}; | ||
export declare type DomainMethodDef<P = any, R = any> = { | ||
export type DomainMethodDef<P = any, R = any> = { | ||
type: MethodType; | ||
@@ -23,6 +27,6 @@ params: ObjectPropsDef<P>; | ||
}; | ||
export declare type DomainEventDef<E> = { | ||
export type DomainEventDef<E> = { | ||
params: ObjectPropsDef<E>; | ||
}; | ||
export declare type MethodType = 'query' | 'command'; | ||
export type MethodType = 'query' | 'command'; | ||
export {}; |
@@ -1,2 +0,2 @@ | ||
import { Exception } from 'typesafe-exception'; | ||
import { Exception } from '@nodescript/exception'; | ||
/** | ||
@@ -3,0 +3,0 @@ * PoC client for sending protocol messages via HTTP. |
@@ -0,1 +1,2 @@ | ||
export * from './channel-event.js'; | ||
export * from './domain.js'; | ||
@@ -2,0 +3,0 @@ export * from './http-client.js'; |
// This file is auto-generated | ||
export * from './channel-event.js'; | ||
export * from './domain.js'; | ||
@@ -3,0 +4,0 @@ export * from './http-client.js'; |
@@ -1,5 +0,5 @@ | ||
import { Schema } from 'airtight'; | ||
import { Exception } from 'typesafe-exception'; | ||
import { Exception } from '@nodescript/exception'; | ||
import { Schema } from '@nodescript/schema'; | ||
import { DomainDef, DomainEventDef, DomainMethodDef } from './domain.js'; | ||
export declare type ProtocolMethodDesc = { | ||
export type ProtocolMethodDesc = { | ||
domainDef: DomainDef<any>; | ||
@@ -10,3 +10,3 @@ methodDef: DomainMethodDef<any, any>; | ||
}; | ||
export declare type ProtocolEventDesc = { | ||
export type ProtocolEventDesc = { | ||
domainDef: DomainDef<any>; | ||
@@ -16,3 +16,3 @@ eventDef: DomainEventDef<any>; | ||
}; | ||
export declare type ProtocolDomains<P> = { | ||
export type ProtocolDomains<P> = { | ||
[K in keyof P]: DomainDef<P[K]>; | ||
@@ -19,0 +19,0 @@ }; |
@@ -1,3 +0,3 @@ | ||
import { Schema } from 'airtight'; | ||
import { Exception } from 'typesafe-exception'; | ||
import { Exception } from '@nodescript/exception'; | ||
import { Schema } from '@nodescript/schema'; | ||
/** | ||
@@ -4,0 +4,0 @@ * Convenience class for accessing static metadata for domains. |
@@ -1,3 +0,4 @@ | ||
import { Event } from 'typesafe-event'; | ||
import { Exception } from 'typesafe-exception'; | ||
import { Event } from '@nodescript/event'; | ||
import { Exception } from '@nodescript/exception'; | ||
import { ChannelEvent } from './channel-event.js'; | ||
import { DomainMethod } from './domain.js'; | ||
@@ -20,3 +21,3 @@ import { ProtocolIndex } from './protocol.js'; | ||
protected awaitingCommands: Map<number, AwaitingCommand<any>>; | ||
protected eventMap: Map<string, Event<any>>; | ||
protected eventMap: Map<string, ChannelEvent<any>>; | ||
client: P; | ||
@@ -33,3 +34,3 @@ constructor(index: ProtocolIndex<P>, sendRequest: (req: RpcMethodRequest) => void); | ||
protected createMethod<Req, Res>(domainName: string, methodName: string): DomainMethod<Req, Res>; | ||
protected createEvent(domainName: string, eventName: string): Event<any>; | ||
protected createEvent(domainName: string, eventName: string): ChannelEvent<any>; | ||
protected handleMethodResponse(res: RpcMethodResponse): void; | ||
@@ -36,0 +37,0 @@ protected handleEvent(res: RpcEvent): void; |
@@ -1,3 +0,3 @@ | ||
import { Event } from 'typesafe-event'; | ||
import { Exception } from 'typesafe-exception'; | ||
import { Exception } from '@nodescript/exception'; | ||
import { ChannelEvent } from './channel-event.js'; | ||
/** | ||
@@ -59,3 +59,3 @@ * PoC client for exchanging messages in RPC format via an abstract transport | ||
createEvent(domainName, eventName) { | ||
const evt = new Event(); | ||
const evt = new ChannelEvent(); | ||
this.eventMap.set(`${domainName}.${eventName}`, evt); | ||
@@ -86,3 +86,6 @@ return evt; | ||
} | ||
event.emit(res.params); | ||
event.emit({ | ||
channel: res.channel, | ||
data: res.data, | ||
}); | ||
} | ||
@@ -89,0 +92,0 @@ isMethodResponse(msg) { |
@@ -1,2 +0,2 @@ | ||
import { Event } from 'typesafe-event'; | ||
import { ChannelEvent } from './channel-event.js'; | ||
import { MethodNotFound } from './protocol.js'; | ||
@@ -40,3 +40,2 @@ import { RpcMethodRequest } from './rpc-messages.js'; | ||
const { domain, method, params } = rpcReq; | ||
const key = `${domain}.${method}`; | ||
const { reqSchema, resSchema, } = this.protocolIndex.lookupMethod(domain, method); | ||
@@ -46,7 +45,7 @@ const domainImpl = this.protocolImpl[domain]; | ||
if (!methodImpl) { | ||
throw new MethodNotFound(key); | ||
throw new MethodNotFound(`${domain}.${method}`); | ||
} | ||
const decodedParams = reqSchema.decode(params, { strictRequired: true }); | ||
const res = await methodImpl.call(domainImpl, decodedParams); | ||
return resSchema.decode(res, { strictRequired: true }); | ||
return resSchema.decode(res); | ||
} | ||
@@ -58,7 +57,8 @@ registerEvents() { | ||
const ev = this.protocolImpl[domainName][eventName]; | ||
if (ev instanceof Event) { | ||
ev.on(params => this.sendEvent({ | ||
if (ev instanceof ChannelEvent) { | ||
ev.on(payload => this.sendEvent({ | ||
domain: domainName, | ||
event: eventName, | ||
params: paramSchema.decode(params), | ||
channel: payload.channel, | ||
data: paramSchema.decode(payload.data), | ||
})); | ||
@@ -65,0 +65,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { Schema } from 'airtight'; | ||
import { Schema } from '@nodescript/schema'; | ||
export interface RpcError { | ||
@@ -23,4 +23,5 @@ name: string; | ||
event: string; | ||
params: any; | ||
channel: string; | ||
data: any; | ||
} | ||
export declare const RpcEvent: Schema<RpcEvent>; |
@@ -1,2 +0,2 @@ | ||
import { Schema } from 'airtight'; | ||
import { Schema } from '@nodescript/schema'; | ||
export const RpcError = new Schema({ | ||
@@ -34,6 +34,7 @@ id: 'RpcError', | ||
domain: { type: 'string' }, | ||
channel: { type: 'string' }, | ||
event: { type: 'string' }, | ||
params: { type: 'any' }, | ||
data: { type: 'any' }, | ||
}, | ||
}); | ||
//# sourceMappingURL=rpc-messages.js.map |
{ | ||
"name": "@nodescript/protocomm", | ||
"version": "0.2.0", | ||
"version": "0.5.1", | ||
"type": "module", | ||
@@ -32,11 +32,11 @@ "description": "Bi-directional transport-agnostic JSON-based messaging", | ||
"dependencies": { | ||
"airtight": "^4.2.0", | ||
"typesafe-event": "^2.0.1", | ||
"typesafe-exception": "^2.0.4" | ||
"@nodescript/event": "^2.1.1", | ||
"@nodescript/exception": "^2.0.8", | ||
"@nodescript/schema": "^5.2.1" | ||
}, | ||
"devDependencies": { | ||
"@nodescript/eslint-config": "^1.0.0", | ||
"@types/mocha": "^9.1.1", | ||
"@types/node": "^17.0.35", | ||
"@ubio/eslint-config": "^1.3.5", | ||
"eslint": "^7.32.0", | ||
"eslint": "^8.24.0", | ||
"mocha": "^10.0.0", | ||
@@ -48,3 +48,3 @@ "npm-run-all": "^4.1.5", | ||
"type": "git", | ||
"url": "git+https://github.com/NodeScriptLang/protocomm.git" | ||
"url": "git+https://github.com/nodescript/protocomm.git" | ||
}, | ||
@@ -56,3 +56,3 @@ "keywords": [ | ||
"license": "ISC", | ||
"homepage": "https://github.com/NodeScriptLang/protocomm#readme" | ||
"homepage": "https://github.com/nodescript/protocomm#readme" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
36868
26
555
2
+ Added@nodescript/event@^2.1.1
+ Added@nodescript/exception@^2.0.8
+ Added@nodescript/schema@^5.2.1
+ Added@nodescript/event@2.1.1(transitive)
+ Added@nodescript/exception@2.0.8(transitive)
+ Added@nodescript/schema@5.2.2(transitive)
- Removedairtight@^4.2.0
- Removedtypesafe-event@^2.0.1
- Removedtypesafe-exception@^2.0.4
- Removedairtight@4.3.3(transitive)
- Removedtypesafe-event@2.0.3(transitive)
- Removedtypesafe-exception@2.0.4(transitive)