@nmtjs/client 0.10.1 → 0.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/common.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { EventEmitter, ProtocolError } from "@nmtjs/protocol/client";
2
- export * from "./types.js";
3
2
  export { ErrorCode, ProtocolBlob, TransportType } from "@nmtjs/protocol";
3
+ export * from "./types.js";
4
4
  export class ClientError extends ProtocolError {}
5
5
  export class BaseClient extends EventEmitter {
6
6
  _;
@@ -1 +1 @@
1
- {"mappings":"AACA,SACE,cAGA,qBAEK,wBAAwB;AAS/B,cAAc;AAEd,SACE,WACA,cAEA,qBACK;AAEP,OAAO,MAAM,oBAAoB,cAAc,CAAE;AAEjD,OAAO,MAAe,mBAGZ,aAQR;CACA;CAUA,AAAU;CAEV,YACYA,WACAC,SACV;AACA,SAAO;OAHG;OACA;CAGX;CAED,AAAU,UAAU,CAAE;CAEtB,MAAgB,MACdC,WACAC,WACAC,SACAC,SACA;EACA,MAAM,OAAO,MAAM,KAAK,UAAU,KAChC,WACA,WACA,SACA,SACA,KAAK,YACN;AACD,MAAI,KAAK,QAAQ,MAAM;AACrB,UAAO,MAAM,KAAK,QACf,KAAK,CAAC,YAAY,EAAE,OAAQ,GAAE,CAC9B,MAAM,CAAC,WAAW,EAAE,MAAO,GAAE;EACjC,OAAM;AACL,UAAO,MAAM,KAAK,QAAQ,MAAM,CAAC,UAAU;AACzC,UAAM;GACP,EAAC;EACH;CACF;CAED,IAAI,OAAO;AACT,SAAO,KAAK;CACb;CAED,QAAQC,MAAW;AACjB,OAAK,OAAO;CACb;CAED,UAAU;AACR,SAAO,KAAK,UAAU,QAAQ,KAAK,MAAM,KAAK,YAAY;CAC3D;CAED,aAAa;AACX,SAAO,KAAK,UAAU,YAAY;CACnC;AACF","names":["transport: ProtocolTransport","options: { timeout: number; safe?: SafeCall }","namespace: string","procedure: string","payload: any","options: ProtocolBaseClientCallOptions","auth: any"],"sources":["../src/common.ts"],"sourcesContent":["import type { TAnyAPIContract } from '@nmtjs/contract'\nimport {\n EventEmitter,\n type ProtocolBaseClientCallOptions,\n type ProtocolBaseTransformer,\n ProtocolError,\n type ProtocolTransport,\n} from '@nmtjs/protocol/client'\nimport type {\n ClientCallers,\n ResolveAPIContract,\n ResolveClientEvents,\n RuntimeInputContractTypeProvider,\n RuntimeOutputContractTypeProvider,\n} from './types.ts'\n\nexport * from './types.ts'\n\nexport {\n ErrorCode,\n ProtocolBlob,\n type ProtocolBlobMetadata,\n TransportType,\n} from '@nmtjs/protocol'\n\nexport class ClientError extends ProtocolError {}\n\nexport abstract class BaseClient<\n APIContract extends TAnyAPIContract = TAnyAPIContract,\n SafeCall extends boolean = false,\n> extends EventEmitter<\n ResolveClientEvents<\n ResolveAPIContract<\n APIContract,\n RuntimeInputContractTypeProvider,\n RuntimeOutputContractTypeProvider\n >\n >\n> {\n _!: {\n api: ResolveAPIContract<\n APIContract,\n RuntimeInputContractTypeProvider,\n RuntimeOutputContractTypeProvider\n >\n safe: SafeCall\n }\n\n protected abstract transformer: ProtocolBaseTransformer\n protected auth: any\n\n constructor(\n protected transport: ProtocolTransport,\n protected options: { timeout: number; safe?: SafeCall },\n ) {\n super()\n }\n\n protected callers = {} as ClientCallers<this['_']['api'], this['_']['safe']>\n\n protected async _call(\n namespace: string,\n procedure: string,\n payload: any,\n options: ProtocolBaseClientCallOptions,\n ) {\n const call = await this.transport.call(\n namespace,\n procedure,\n payload,\n options,\n this.transformer,\n )\n if (this.options.safe) {\n return await call.promise\n .then((result) => ({ result }))\n .catch((error) => ({ error }))\n } else {\n return await call.promise.catch((error) => {\n throw error\n })\n }\n }\n\n get call() {\n return this.callers\n }\n\n setAuth(auth: any) {\n this.auth = auth\n }\n\n connect() {\n return this.transport.connect(this.auth, this.transformer)\n }\n\n disconnect() {\n return this.transport.disconnect()\n }\n}\n"],"version":3,"file":"common.js"}
1
+ {"mappings":"AACA,SACE,cAGA,qBAEK,wBAAwB;AAS/B,SACE,WACA,cAEA,qBACK;AACP,cAAc;AAEd,OAAO,MAAM,oBAAoB,cAAc,CAAE;AAEjD,OAAO,MAAe,mBAGZ,aAQR;CACA;CAUA,AAAU;CAEV,YACYA,WACAC,SACV;AACA,SAAO;OAHG;OACA;CAGX;CAED,AAAU,UAAU,CAAE;CAEtB,MAAgB,MACdC,WACAC,WACAC,SACAC,SACA;EACA,MAAM,OAAO,MAAM,KAAK,UAAU,KAChC,WACA,WACA,SACA,SACA,KAAK,YACN;AACD,MAAI,KAAK,QAAQ,MAAM;AACrB,UAAO,MAAM,KAAK,QACf,KAAK,CAAC,YAAY,EAAE,OAAQ,GAAE,CAC9B,MAAM,CAAC,WAAW,EAAE,MAAO,GAAE;EACjC,OAAM;AACL,UAAO,MAAM,KAAK,QAAQ,MAAM,CAAC,UAAU;AACzC,UAAM;GACP,EAAC;EACH;CACF;CAED,IAAI,OAAO;AACT,SAAO,KAAK;CACb;CAED,QAAQC,MAAW;AACjB,OAAK,OAAO;CACb;CAED,UAAU;AACR,SAAO,KAAK,UAAU,QAAQ,KAAK,MAAM,KAAK,YAAY;CAC3D;CAED,aAAa;AACX,SAAO,KAAK,UAAU,YAAY;CACnC;AACF","names":["transport: ProtocolTransport","options: { timeout: number; safe?: SafeCall }","namespace: string","procedure: string","payload: any","options: ProtocolBaseClientCallOptions","auth: any"],"sources":["../src/common.ts"],"sourcesContent":["import type { TAnyAPIContract } from '@nmtjs/contract'\nimport {\n EventEmitter,\n type ProtocolBaseClientCallOptions,\n type ProtocolBaseTransformer,\n ProtocolError,\n type ProtocolTransport,\n} from '@nmtjs/protocol/client'\nimport type {\n ClientCallers,\n ResolveAPIContract,\n ResolveClientEvents,\n RuntimeInputContractTypeProvider,\n RuntimeOutputContractTypeProvider,\n} from './types.ts'\n\nexport {\n ErrorCode,\n ProtocolBlob,\n type ProtocolBlobMetadata,\n TransportType,\n} from '@nmtjs/protocol'\nexport * from './types.ts'\n\nexport class ClientError extends ProtocolError {}\n\nexport abstract class BaseClient<\n APIContract extends TAnyAPIContract = TAnyAPIContract,\n SafeCall extends boolean = false,\n> extends EventEmitter<\n ResolveClientEvents<\n ResolveAPIContract<\n APIContract,\n RuntimeInputContractTypeProvider,\n RuntimeOutputContractTypeProvider\n >\n >\n> {\n _!: {\n api: ResolveAPIContract<\n APIContract,\n RuntimeInputContractTypeProvider,\n RuntimeOutputContractTypeProvider\n >\n safe: SafeCall\n }\n\n protected abstract transformer: ProtocolBaseTransformer\n protected auth: any\n\n constructor(\n protected transport: ProtocolTransport,\n protected options: { timeout: number; safe?: SafeCall },\n ) {\n super()\n }\n\n protected callers = {} as ClientCallers<this['_']['api'], this['_']['safe']>\n\n protected async _call(\n namespace: string,\n procedure: string,\n payload: any,\n options: ProtocolBaseClientCallOptions,\n ) {\n const call = await this.transport.call(\n namespace,\n procedure,\n payload,\n options,\n this.transformer,\n )\n if (this.options.safe) {\n return await call.promise\n .then((result) => ({ result }))\n .catch((error) => ({ error }))\n } else {\n return await call.promise.catch((error) => {\n throw error\n })\n }\n }\n\n get call() {\n return this.callers\n }\n\n setAuth(auth: any) {\n this.auth = auth\n }\n\n connect() {\n return this.transport.connect(this.auth, this.transformer)\n }\n\n disconnect() {\n return this.transport.disconnect()\n }\n}\n"],"version":3,"file":"common.js"}
package/dist/runtime.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ErrorCode } from "@nmtjs/protocol";
2
2
  import { ProtocolBaseTransformer } from "@nmtjs/protocol/client";
3
- import { NeemataTypeError, NeverType } from "@nmtjs/type";
3
+ import { NeemataTypeError, t } from "@nmtjs/type";
4
4
  import { BaseClient, ClientError } from "./common.js";
5
5
  export class RuntimeContractTransformer extends ProtocolBaseTransformer {
6
6
  contract;
@@ -14,17 +14,17 @@ export class RuntimeContractTransformer extends ProtocolBaseTransformer {
14
14
  }
15
15
  decodeRPC(namespace, procedure, payload) {
16
16
  const type = this.contract.namespaces[namespace].procedures[procedure].output;
17
- if (type instanceof NeverType) return undefined;
17
+ if (type instanceof type.NeverType) return undefined;
18
18
  return type.decode(payload);
19
19
  }
20
20
  decodeRPCChunk(namespace, procedure, payload) {
21
21
  const type = this.contract.namespaces[namespace].procedures[procedure].stream;
22
- if (type instanceof NeverType) return undefined;
22
+ if (type instanceof t.NeverType) return undefined;
23
23
  return type.decode(payload);
24
24
  }
25
25
  encodeRPC(namespace, procedure, payload) {
26
26
  const type = this.contract.namespaces[namespace].procedures[procedure].input;
27
- if (type instanceof NeverType) return undefined;
27
+ if (type instanceof t.NeverType) return undefined;
28
28
  try {
29
29
  return type.encode(payload);
30
30
  } catch (error) {
@@ -1 +1 @@
1
- {"mappings":"AACA,SAAS,iBAAiB,iBAAiB;AAC3C,SAAS,+BAA+B,wBAAwB;AAChE,SAAS,kBAAkB,iBAAiB,aAAa;AACzD,SAAS,YAAY,mBAAmB,aAAa;AAErD,OAAO,MAAM,mCAAmC,wBAAwB;CACtE,AAAU;CAEV,YAAYA,UAA2B;AACrC,SAAO;AAEP,OAAK,WAAW;CACjB;CAED,YAAYC,WAAmBC,OAAeC,SAAc;EAC1D,MAAM,OAAO,KAAK,SAAS,WAAW,WAAW,OAAO,OAAO;AAC/D,SAAO,KAAK,OAAO,QAAQ;CAC5B;CAED,UAAUF,WAAmBG,WAAmBD,SAAc;EAC5D,MAAM,OACJ,KAAK,SAAS,WAAW,WAAW,WAAW,WAAW;AAC5D,MAAI,gBAAgB,UAAW,QAAO;AACtC,SAAO,KAAK,OAAO,QAAQ;CAC5B;CAED,eAAeF,WAAmBG,WAAmBD,SAAc;EACjE,MAAM,OACJ,KAAK,SAAS,WAAW,WAAW,WAAW,WAAW;AAC5D,MAAI,gBAAgB,UAAW,QAAO;AACtC,SAAO,KAAK,OAAO,QAAQ;CAC5B;CAED,UAAUF,WAAmBG,WAAmBD,SAAc;EAC5D,MAAM,OAAO,KAAK,SAAS,WAAW,WAAW,WAAW,WAAW;AACvE,MAAI,gBAAgB,UAAW,QAAO;AACtC,MAAI;AACF,UAAO,KAAK,OAAO,QAAQ;EAC5B,SAAQ,OAAO;AACd,OAAI,iBAAiB,kBAAkB;AACrC,UAAM,IAAI,YACR,UAAU,kBACT,sBAAsB,UAAU,GAAG,UAAU,IAAI,MAAM,QAAQ,GAChE,MAAM;GAET;AACD,SAAM;EACP;CACF;AACF;AAED,OAAO,MAAM,sBAGH,WAAkC;CAC1C,AAAU;CAEV,YACSE,UACP,GAAG,MACH;AACA,QAAM,GAAG,KAAK;OAHP;AAKP,OAAK,cAAc,IAAI,2BAA2B,KAAK;EAEvD,MAAM,aAAa,OAAO,QAAQ,KAAK,SAAS,WAAW;AAC3D,OAAK,MAAM,CAAC,cAAc,UAAU,IAAI,YAAY;AAClD,QAAK,QAAQ,gBAAgB,CAAE;GAE/B,MAAM,aAAa,OAAO,QAAQ,UAAU,WAAW;AAEvD,QAAK,MAAM,CAAC,cAAc,UAAU,IAAI,YAAY;AAClD,SAAK,QAAQ,cAAc,gBAAgB,CAAC,SAAS,YACnD,KAAK,MAAM,UAAU,MAAM,UAAU,MAAM,SAAS;KAClD,SAAS,UAAU,WAAW,UAAU,WAAW,QAAQ;KAC3D,GAAG;IACJ,EAAC;GACL;EACF;CACF;AACF","names":["contract: TAnyAPIContract","namespace: string","event: string","payload: any","procedure: string","contract: APIContract"],"sources":["../src/runtime.ts"],"sourcesContent":["import type { TAnyAPIContract } from '@nmtjs/contract'\nimport { ErrorCode } from '@nmtjs/protocol'\nimport { ProtocolBaseTransformer } from '@nmtjs/protocol/client'\nimport { NeemataTypeError, NeverType } from '@nmtjs/type'\nimport { BaseClient, ClientError } from './common.ts'\n\nexport class RuntimeContractTransformer extends ProtocolBaseTransformer {\n protected contract: TAnyAPIContract\n\n constructor(contract: TAnyAPIContract) {\n super()\n\n this.contract = contract\n }\n\n decodeEvent(namespace: string, event: string, payload: any) {\n const type = this.contract.namespaces[namespace].events[event].payload\n return type.decode(payload)\n }\n\n decodeRPC(namespace: string, procedure: string, payload: any) {\n const type =\n this.contract.namespaces[namespace].procedures[procedure].output\n if (type instanceof NeverType) return undefined\n return type.decode(payload)\n }\n\n decodeRPCChunk(namespace: string, procedure: string, payload: any) {\n const type =\n this.contract.namespaces[namespace].procedures[procedure].stream\n if (type instanceof NeverType) return undefined\n return type.decode(payload)\n }\n\n encodeRPC(namespace: string, procedure: string, payload: any) {\n const type = this.contract.namespaces[namespace].procedures[procedure].input\n if (type instanceof NeverType) return undefined\n try {\n return type.encode(payload)\n } catch (error) {\n if (error instanceof NeemataTypeError) {\n throw new ClientError(\n ErrorCode.ValidationError,\n `Invalid payload for ${namespace}.${procedure}: ${error.message}`,\n error.issues,\n )\n }\n throw error\n }\n }\n}\n\nexport class RuntimeClient<\n APIContract extends TAnyAPIContract,\n SafeCall extends boolean,\n> extends BaseClient<APIContract, SafeCall> {\n protected transformer: RuntimeContractTransformer\n\n constructor(\n public contract: APIContract,\n ...args: ConstructorParameters<typeof BaseClient<APIContract, SafeCall>>\n ) {\n super(...args)\n\n this.transformer = new RuntimeContractTransformer(this.contract)\n\n const namespaces = Object.entries(this.contract.namespaces)\n for (const [namespaceKey, namespace] of namespaces) {\n this.callers[namespaceKey] = {} as any\n\n const procedures = Object.entries(namespace.procedures)\n\n for (const [procedureKey, procedure] of procedures) {\n this.callers[namespaceKey][procedureKey] = (payload, options) =>\n this._call(namespace.name, procedure.name, payload, {\n timeout: procedure.timeout || namespace.timeout || options.timeout,\n ...options,\n })\n }\n }\n }\n}\n"],"version":3,"file":"runtime.js"}
1
+ {"mappings":"AACA,SAAS,iBAAiB,iBAAiB;AAC3C,SAAS,+BAA+B,wBAAwB;AAChE,SAAS,kBAAkB,SAAS,aAAa;AACjD,SAAS,YAAY,mBAAmB,aAAa;AAErD,OAAO,MAAM,mCAAmC,wBAAwB;CACtE,AAAU;CAEV,YAAYA,UAA2B;AACrC,SAAO;AAEP,OAAK,WAAW;CACjB;CAED,YAAYC,WAAmBC,OAAeC,SAAc;EAC1D,MAAM,OAAO,KAAK,SAAS,WAAW,WAAW,OAAO,OAAO;AAC/D,SAAO,KAAK,OAAO,QAAQ;CAC5B;CAED,UAAUF,WAAmBG,WAAmBD,SAAc;EAC5D,MAAM,OACJ,KAAK,SAAS,WAAW,WAAW,WAAW,WAAW;AAC5D,MAAI,gBAAgB,KAAK,UAAW,QAAO;AAC3C,SAAO,KAAK,OAAO,QAAQ;CAC5B;CAED,eAAeF,WAAmBG,WAAmBD,SAAc;EACjE,MAAM,OACJ,KAAK,SAAS,WAAW,WAAW,WAAW,WAAW;AAC5D,MAAI,gBAAgB,EAAE,UAAW,QAAO;AACxC,SAAO,KAAK,OAAO,QAAQ;CAC5B;CAED,UAAUF,WAAmBG,WAAmBD,SAAc;EAC5D,MAAM,OAAO,KAAK,SAAS,WAAW,WAAW,WAAW,WAAW;AACvE,MAAI,gBAAgB,EAAE,UAAW,QAAO;AACxC,MAAI;AACF,UAAO,KAAK,OAAO,QAAQ;EAC5B,SAAQ,OAAO;AACd,OAAI,iBAAiB,kBAAkB;AACrC,UAAM,IAAI,YACR,UAAU,kBACT,sBAAsB,UAAU,GAAG,UAAU,IAAI,MAAM,QAAQ,GAChE,MAAM;GAET;AACD,SAAM;EACP;CACF;AACF;AAED,OAAO,MAAM,sBAGH,WAAkC;CAC1C,AAAU;CAEV,YACSE,UACP,GAAG,MACH;AACA,QAAM,GAAG,KAAK;OAHP;AAKP,OAAK,cAAc,IAAI,2BAA2B,KAAK;EAEvD,MAAM,aAAa,OAAO,QAAQ,KAAK,SAAS,WAAW;AAC3D,OAAK,MAAM,CAAC,cAAc,UAAU,IAAI,YAAY;AAClD,QAAK,QAAQ,gBAAgB,CAAE;GAE/B,MAAM,aAAa,OAAO,QAAQ,UAAU,WAAW;AAEvD,QAAK,MAAM,CAAC,cAAc,UAAU,IAAI,YAAY;AAClD,SAAK,QAAQ,cAAc,gBAAgB,CAAC,SAAS,YACnD,KAAK,MAAM,UAAU,MAAM,UAAU,MAAM,SAAS;KAClD,SAAS,UAAU,WAAW,UAAU,WAAW,QAAQ;KAC3D,GAAG;IACJ,EAAC;GACL;EACF;CACF;AACF","names":["contract: TAnyAPIContract","namespace: string","event: string","payload: any","procedure: string","contract: APIContract"],"sources":["../src/runtime.ts"],"sourcesContent":["import type { TAnyAPIContract } from '@nmtjs/contract'\nimport { ErrorCode } from '@nmtjs/protocol'\nimport { ProtocolBaseTransformer } from '@nmtjs/protocol/client'\nimport { NeemataTypeError, t } from '@nmtjs/type'\nimport { BaseClient, ClientError } from './common.ts'\n\nexport class RuntimeContractTransformer extends ProtocolBaseTransformer {\n protected contract: TAnyAPIContract\n\n constructor(contract: TAnyAPIContract) {\n super()\n\n this.contract = contract\n }\n\n decodeEvent(namespace: string, event: string, payload: any) {\n const type = this.contract.namespaces[namespace].events[event].payload\n return type.decode(payload)\n }\n\n decodeRPC(namespace: string, procedure: string, payload: any) {\n const type =\n this.contract.namespaces[namespace].procedures[procedure].output\n if (type instanceof type.NeverType) return undefined\n return type.decode(payload)\n }\n\n decodeRPCChunk(namespace: string, procedure: string, payload: any) {\n const type =\n this.contract.namespaces[namespace].procedures[procedure].stream\n if (type instanceof t.NeverType) return undefined\n return type.decode(payload)\n }\n\n encodeRPC(namespace: string, procedure: string, payload: any) {\n const type = this.contract.namespaces[namespace].procedures[procedure].input\n if (type instanceof t.NeverType) return undefined\n try {\n return type.encode(payload)\n } catch (error) {\n if (error instanceof NeemataTypeError) {\n throw new ClientError(\n ErrorCode.ValidationError,\n `Invalid payload for ${namespace}.${procedure}: ${error.message}`,\n error.issues,\n )\n }\n throw error\n }\n }\n}\n\nexport class RuntimeClient<\n APIContract extends TAnyAPIContract,\n SafeCall extends boolean,\n> extends BaseClient<APIContract, SafeCall> {\n protected transformer: RuntimeContractTransformer\n\n constructor(\n public contract: APIContract,\n ...args: ConstructorParameters<typeof BaseClient<APIContract, SafeCall>>\n ) {\n super(...args)\n\n this.transformer = new RuntimeContractTransformer(this.contract)\n\n const namespaces = Object.entries(this.contract.namespaces)\n for (const [namespaceKey, namespace] of namespaces) {\n this.callers[namespaceKey] = {} as any\n\n const procedures = Object.entries(namespace.procedures)\n\n for (const [procedureKey, procedure] of procedures) {\n this.callers[namespaceKey][procedureKey] = (payload, options) =>\n this._call(namespace.name, procedure.name, payload, {\n timeout: procedure.timeout || namespace.timeout || options.timeout,\n ...options,\n })\n }\n }\n }\n}\n"],"version":3,"file":"runtime.js"}
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":"","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type { CallTypeProvider, OneOf, TypeProvider } from '@nmtjs/common'\nimport type { TAnyAPIContract } from '@nmtjs/contract'\nimport type {\n ProtocolBaseClientCallOptions,\n ProtocolError,\n ProtocolServerStreamInterface,\n} from '@nmtjs/protocol/client'\nimport type { InputType, OutputType } from '@nmtjs/protocol/client'\nimport type { BaseTypeAny, NeverType, t } from '@nmtjs/type'\n\nexport interface StaticInputContractTypeProvider extends TypeProvider {\n output: this['input'] extends BaseTypeAny\n ? t.infer.encoded.input<this['input']>\n : never\n}\n\nexport interface RuntimeInputContractTypeProvider extends TypeProvider {\n output: this['input'] extends BaseTypeAny\n ? t.infer.decoded.input<this['input']>\n : never\n}\n\nexport interface StaticOutputContractTypeProvider extends TypeProvider {\n output: this['input'] extends BaseTypeAny\n ? t.infer.encoded.output<this['input']>\n : never\n}\n\nexport interface RuntimeOutputContractTypeProvider extends TypeProvider {\n output: this['input'] extends BaseTypeAny\n ? t.infer.decoded.output<this['input']>\n : never\n}\n\nexport type ResolveAPIContract<\n C extends TAnyAPIContract = TAnyAPIContract,\n InputTypeProvider extends TypeProvider = TypeProvider,\n OutputTypeProvider extends TypeProvider = TypeProvider,\n> = {\n [N in keyof C['namespaces'] as C['namespaces'][N]['name']]: {\n procedures: {\n [P in keyof C['namespaces'][N]['procedures'] as C['namespaces'][N]['procedures'][P]['name']]: {\n contract: C['namespaces'][N]['procedures'][P]\n input: InputType<\n CallTypeProvider<\n InputTypeProvider,\n C['namespaces'][N]['procedures'][P]['input']\n >\n >\n output: C['namespaces'][N]['procedures'][P]['stream'] extends NeverType\n ? OutputType<\n CallTypeProvider<\n OutputTypeProvider,\n C['namespaces'][N]['procedures'][P]['output']\n >\n >\n : {\n result: OutputType<\n CallTypeProvider<\n OutputTypeProvider,\n C['namespaces'][N]['procedures'][P]['output']\n >\n >\n stream: ProtocolServerStreamInterface<\n CallTypeProvider<\n OutputTypeProvider,\n C['namespaces'][N]['procedures'][P]['stream']\n >\n >\n }\n }\n }\n events: {\n [KE in keyof C['namespaces'][N]['events'] as C['namespaces'][N]['events'][KE]['name']]: {\n payload: OutputType<\n CallTypeProvider<\n OutputTypeProvider,\n C['namespaces'][N]['events'][KE]['payload']\n >\n >\n }\n }\n }\n}\n\nexport type ResolveClientEvents<\n C extends ResolveAPIContract = ResolveAPIContract,\n> = {\n [N in keyof C]: {\n [KE in keyof C[N]['events'] as `${Extract<N, string>}/${Extract<KE, string>}`]: [\n C[N]['events'][KE]['payload'],\n ]\n }\n}[keyof C]\n\nexport type ClientCallers<\n Resolved extends ResolveAPIContract,\n SafeCall extends boolean,\n> = {\n [N in keyof Resolved]: {\n [P in keyof Resolved[N]['procedures']]: (\n ...args: Resolved[N]['procedures'][P]['input'] extends NeverType\n ? [data?: undefined, options?: Partial<ProtocolBaseClientCallOptions>]\n : undefined extends t.infer.encoded.input<\n Resolved[N]['procedures'][P]['contract']['input']\n >\n ? [\n data?: Resolved[N]['procedures'][P]['input'],\n options?: Partial<ProtocolBaseClientCallOptions>,\n ]\n : [\n data: Resolved[N]['procedures'][P]['input'],\n options?: Partial<ProtocolBaseClientCallOptions>,\n ]\n ) => SafeCall extends true\n ? Promise<\n OneOf<\n [\n {\n error?: undefined\n output: Resolved[N]['procedures'][P]['output']\n },\n { error: ProtocolError; output?: undefined },\n ]\n >\n >\n : Promise<Resolved[N]['procedures'][P]['output']>\n }\n}\n"],"version":3,"file":"types.js"}
1
+ {"mappings":"","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type { CallTypeProvider, OneOf, TypeProvider } from '@nmtjs/common'\nimport type { TAnyAPIContract } from '@nmtjs/contract'\nimport type {\n InputType,\n OutputType,\n ProtocolBaseClientCallOptions,\n ProtocolError,\n ProtocolServerStreamInterface,\n} from '@nmtjs/protocol/client'\nimport type { BaseTypeAny, t } from '@nmtjs/type'\n\nexport interface StaticInputContractTypeProvider extends TypeProvider {\n output: this['input'] extends BaseTypeAny\n ? t.infer.encoded.input<this['input']>\n : never\n}\n\nexport interface RuntimeInputContractTypeProvider extends TypeProvider {\n output: this['input'] extends BaseTypeAny\n ? t.infer.decoded.input<this['input']>\n : never\n}\n\nexport interface StaticOutputContractTypeProvider extends TypeProvider {\n output: this['input'] extends BaseTypeAny\n ? t.infer.encoded.output<this['input']>\n : never\n}\n\nexport interface RuntimeOutputContractTypeProvider extends TypeProvider {\n output: this['input'] extends BaseTypeAny\n ? t.infer.decoded.output<this['input']>\n : never\n}\n\nexport type ResolveAPIContract<\n C extends TAnyAPIContract = TAnyAPIContract,\n InputTypeProvider extends TypeProvider = TypeProvider,\n OutputTypeProvider extends TypeProvider = TypeProvider,\n> = {\n [N in keyof C['namespaces'] as C['namespaces'][N]['name']]: {\n procedures: {\n [P in keyof C['namespaces'][N]['procedures'] as C['namespaces'][N]['procedures'][P]['name']]: {\n contract: C['namespaces'][N]['procedures'][P]\n input: InputType<\n CallTypeProvider<\n InputTypeProvider,\n C['namespaces'][N]['procedures'][P]['input']\n >\n >\n output: C['namespaces'][N]['procedures'][P]['stream'] extends t.NeverType\n ? OutputType<\n CallTypeProvider<\n OutputTypeProvider,\n C['namespaces'][N]['procedures'][P]['output']\n >\n >\n : {\n result: OutputType<\n CallTypeProvider<\n OutputTypeProvider,\n C['namespaces'][N]['procedures'][P]['output']\n >\n >\n stream: ProtocolServerStreamInterface<\n CallTypeProvider<\n OutputTypeProvider,\n C['namespaces'][N]['procedures'][P]['stream']\n >\n >\n }\n }\n }\n events: {\n [KE in keyof C['namespaces'][N]['events'] as C['namespaces'][N]['events'][KE]['name']]: {\n payload: OutputType<\n CallTypeProvider<\n OutputTypeProvider,\n C['namespaces'][N]['events'][KE]['payload']\n >\n >\n }\n }\n }\n}\n\nexport type ResolveClientEvents<\n C extends ResolveAPIContract = ResolveAPIContract,\n> = {\n [N in keyof C]: {\n [KE in keyof C[N]['events'] as `${Extract<N, string>}/${Extract<KE, string>}`]: [\n C[N]['events'][KE]['payload'],\n ]\n }\n}[keyof C]\n\nexport type ClientCallers<\n Resolved extends ResolveAPIContract,\n SafeCall extends boolean,\n> = {\n [N in keyof Resolved]: {\n [P in keyof Resolved[N]['procedures']]: (\n ...args: Resolved[N]['procedures'][P]['input'] extends t.NeverType\n ? [data?: undefined, options?: Partial<ProtocolBaseClientCallOptions>]\n : undefined extends t.infer.encoded.input<\n Resolved[N]['procedures'][P]['contract']['input']\n >\n ? [\n data?: Resolved[N]['procedures'][P]['input'],\n options?: Partial<ProtocolBaseClientCallOptions>,\n ]\n : [\n data: Resolved[N]['procedures'][P]['input'],\n options?: Partial<ProtocolBaseClientCallOptions>,\n ]\n ) => SafeCall extends true\n ? Promise<\n OneOf<\n [\n {\n error?: undefined\n output: Resolved[N]['procedures'][P]['output']\n },\n { error: ProtocolError; output?: undefined },\n ]\n >\n >\n : Promise<Resolved[N]['procedures'][P]['output']>\n }\n}\n"],"version":3,"file":"types.js"}
package/package.json CHANGED
@@ -16,16 +16,16 @@
16
16
  }
17
17
  },
18
18
  "peerDependencies": {
19
- "@nmtjs/type": "0.10.1",
20
- "@nmtjs/contract": "0.10.1",
21
- "@nmtjs/protocol": "0.10.1",
22
- "@nmtjs/common": "0.10.1"
19
+ "@nmtjs/type": "0.10.3",
20
+ "@nmtjs/contract": "0.10.3",
21
+ "@nmtjs/common": "0.10.3",
22
+ "@nmtjs/protocol": "0.10.3"
23
23
  },
24
24
  "devDependencies": {
25
- "@nmtjs/type": "0.10.1",
26
- "@nmtjs/contract": "0.10.1",
27
- "@nmtjs/common": "0.10.1",
28
- "@nmtjs/protocol": "0.10.1"
25
+ "@nmtjs/contract": "0.10.3",
26
+ "@nmtjs/common": "0.10.3",
27
+ "@nmtjs/type": "0.10.3",
28
+ "@nmtjs/protocol": "0.10.3"
29
29
  },
30
30
  "files": [
31
31
  "src",
@@ -33,7 +33,7 @@
33
33
  "LICENSE.md",
34
34
  "README.md"
35
35
  ],
36
- "version": "0.10.1",
36
+ "version": "0.10.3",
37
37
  "scripts": {
38
38
  "build": "neemata-build --root=./src './**/*.ts'",
39
39
  "type-check": "tsc --noEmit"
package/src/common.ts CHANGED
@@ -14,14 +14,13 @@ import type {
14
14
  RuntimeOutputContractTypeProvider,
15
15
  } from './types.ts'
16
16
 
17
- export * from './types.ts'
18
-
19
17
  export {
20
18
  ErrorCode,
21
19
  ProtocolBlob,
22
20
  type ProtocolBlobMetadata,
23
21
  TransportType,
24
22
  } from '@nmtjs/protocol'
23
+ export * from './types.ts'
25
24
 
26
25
  export class ClientError extends ProtocolError {}
27
26
 
package/src/runtime.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { TAnyAPIContract } from '@nmtjs/contract'
2
2
  import { ErrorCode } from '@nmtjs/protocol'
3
3
  import { ProtocolBaseTransformer } from '@nmtjs/protocol/client'
4
- import { NeemataTypeError, NeverType } from '@nmtjs/type'
4
+ import { NeemataTypeError, t } from '@nmtjs/type'
5
5
  import { BaseClient, ClientError } from './common.ts'
6
6
 
7
7
  export class RuntimeContractTransformer extends ProtocolBaseTransformer {
@@ -21,20 +21,20 @@ export class RuntimeContractTransformer extends ProtocolBaseTransformer {
21
21
  decodeRPC(namespace: string, procedure: string, payload: any) {
22
22
  const type =
23
23
  this.contract.namespaces[namespace].procedures[procedure].output
24
- if (type instanceof NeverType) return undefined
24
+ if (type instanceof type.NeverType) return undefined
25
25
  return type.decode(payload)
26
26
  }
27
27
 
28
28
  decodeRPCChunk(namespace: string, procedure: string, payload: any) {
29
29
  const type =
30
30
  this.contract.namespaces[namespace].procedures[procedure].stream
31
- if (type instanceof NeverType) return undefined
31
+ if (type instanceof t.NeverType) return undefined
32
32
  return type.decode(payload)
33
33
  }
34
34
 
35
35
  encodeRPC(namespace: string, procedure: string, payload: any) {
36
36
  const type = this.contract.namespaces[namespace].procedures[procedure].input
37
- if (type instanceof NeverType) return undefined
37
+ if (type instanceof t.NeverType) return undefined
38
38
  try {
39
39
  return type.encode(payload)
40
40
  } catch (error) {
package/src/types.ts CHANGED
@@ -1,12 +1,13 @@
1
1
  import type { CallTypeProvider, OneOf, TypeProvider } from '@nmtjs/common'
2
2
  import type { TAnyAPIContract } from '@nmtjs/contract'
3
3
  import type {
4
+ InputType,
5
+ OutputType,
4
6
  ProtocolBaseClientCallOptions,
5
7
  ProtocolError,
6
8
  ProtocolServerStreamInterface,
7
9
  } from '@nmtjs/protocol/client'
8
- import type { InputType, OutputType } from '@nmtjs/protocol/client'
9
- import type { BaseTypeAny, NeverType, t } from '@nmtjs/type'
10
+ import type { BaseTypeAny, t } from '@nmtjs/type'
10
11
 
11
12
  export interface StaticInputContractTypeProvider extends TypeProvider {
12
13
  output: this['input'] extends BaseTypeAny
@@ -47,7 +48,7 @@ export type ResolveAPIContract<
47
48
  C['namespaces'][N]['procedures'][P]['input']
48
49
  >
49
50
  >
50
- output: C['namespaces'][N]['procedures'][P]['stream'] extends NeverType
51
+ output: C['namespaces'][N]['procedures'][P]['stream'] extends t.NeverType
51
52
  ? OutputType<
52
53
  CallTypeProvider<
53
54
  OutputTypeProvider,
@@ -99,7 +100,7 @@ export type ClientCallers<
99
100
  > = {
100
101
  [N in keyof Resolved]: {
101
102
  [P in keyof Resolved[N]['procedures']]: (
102
- ...args: Resolved[N]['procedures'][P]['input'] extends NeverType
103
+ ...args: Resolved[N]['procedures'][P]['input'] extends t.NeverType
103
104
  ? [data?: undefined, options?: Partial<ProtocolBaseClientCallOptions>]
104
105
  : undefined extends t.infer.encoded.input<
105
106
  Resolved[N]['procedures'][P]['contract']['input']