@nmtjs/client 0.7.0 → 0.7.2

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.
@@ -1 +1 @@
1
- {"mappings":"AAEA,SACE,oBACA,+BAEK,wBAAwB;AAC/B,SAAS,iBAAiB,wBAAwB;AAClD,SAA2B,kBAAkB,iBAAiB,aAAa;AAC3E,SAAS,mBAAmB,aAAa;AAQzC,OAAO,MAAM,mCAAmC,wBAAwB;CACtE;CAEA,YAAYA,UAA2B;AACrC,SAAO;AAEP,OAAKC,YAAY;CAClB;CAED,YAAYC,WAAmBC,OAAeC,SAAc;EAC1D,MAAM,OAAO,KAAKH,UAAU,WAAW,WAAW,OAAO,OAAO;AAChE,SAAO,KAAK,OAAO,QAAQ;CAC5B;CAED,UAAUC,WAAmBG,WAAmBD,SAAc;EAC5D,MAAM,OACJ,KAAKH,UAAU,WAAW,WAAW,WAAW,WAAW;AAC7D,MAAI,gBAAgB,UAAW,QAAO;AACtC,SAAO,KAAK,OAAO,QAAQ;CAC5B;CAED,eAAeC,WAAmBG,WAAmBD,SAAc;EACjE,MAAM,OACJ,KAAKH,UAAU,WAAW,WAAW,WAAW,WAAW;AAC7D,MAAI,gBAAgB,UAAW,QAAO;AACtC,SAAO,KAAK,OAAO,QAAQ;CAC5B;CAED,UAAUC,WAAmBG,WAAmBD,SAAc;EAC5D,MAAM,OACJ,KAAKH,UAAU,WAAW,WAAW,WAAW,WAAW;AAC7D,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,sBAMH,mBAA6D;CACrE;CACA,WAAW,CAAE;CAEb,YACEK,UACAC,SAKA;AACA,QAAM;GACJ,GAAG;GACH,aAAa,IAAI,2BAA2B;EAC7C,EAAC;EAEF,MAAM,UAAU,CAAE;AAElB,OAAK,MAAM,CAAC,cAAc,UAAU,IAAI,OAAO,QAC7C,SAAS,WACV,EAAE;AACD,aAAU;AAEV,WAAQ,gBAAgB,CAAE;AAE1B,QAAK,MAAM,CAAC,cAAc,UAAU,IAAI,OAAO,QAC7C,UAAU,WACX,EAAE;AACD,YAAQ,cAAc,gBAAgB,CAAC,SAAS,YAC9C,KAAK,MAAM,UAAU,MAAM,UAAU,MAAM,SAAS;KAClD,SAAS,UAAU;KACnB,GAAG;IACJ,EAAC;GACL;EACF;AACD,OAAKC,WAAW;CACjB;CAED,IAAI,OAAO;AACT,SAAO,KAAKA;CACb;AACF","names":["contract: TAnyAPIContract","#contract","namespace: string","event: string","payload: any","procedure: string","contract: APIContract","options: {\n transport: ProtocolTransport\n format: BaseClientFormat\n timeout?: number\n }","#callers"],"sources":["src/runtime.ts"],"sourcesContent":["import type { TAnyAPIContract } from '@nmtjs/contract'\nimport type { BaseClientFormat } from '@nmtjs/protocol/client'\nimport {\n ProtocolBaseClient,\n ProtocolBaseTransformer,\n type ProtocolTransport,\n} from '@nmtjs/protocol/client'\nimport { ErrorCode } from '@nmtjs/protocol/common'\nimport { type BaseTypeAny, NeemataTypeError, NeverType } from '@nmtjs/type'\nimport { ClientError } from './common.ts'\nimport type {\n ClientCallers,\n ResolveAPIContract,\n ResolveClientEvents,\n RuntimeContractTypeProvider,\n} from './types.ts'\n\nexport class RuntimeContractTransformer extends ProtocolBaseTransformer {\n #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 =\n 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 ResolvedAPIContract extends ResolveAPIContract<\n APIContract,\n RuntimeContractTypeProvider\n > = ResolveAPIContract<APIContract, RuntimeContractTypeProvider>,\n> extends ProtocolBaseClient<ResolveClientEvents<ResolvedAPIContract>> {\n _!: ResolvedAPIContract\n #callers = {} as ClientCallers<ResolvedAPIContract>\n\n constructor(\n contract: APIContract,\n options: {\n transport: ProtocolTransport\n format: BaseClientFormat\n timeout?: number\n },\n ) {\n super({\n ...options,\n transformer: new RuntimeContractTransformer(contract),\n })\n\n const callers = {} as any\n\n for (const [namespaceKey, namespace] of Object.entries(\n contract.namespaces,\n )) {\n namespace.procedures\n\n callers[namespaceKey] = {} as any\n\n for (const [procedureKey, procedure] of Object.entries(\n namespace.procedures,\n )) {\n callers[namespaceKey][procedureKey] = (payload, options) =>\n this._call(namespace.name, procedure.name, payload, {\n timeout: namespace.timeout,\n ...options,\n })\n }\n }\n this.#callers = callers\n }\n\n get call() {\n return this.#callers\n }\n}\n"],"version":3}
1
+ {"mappings":"AAEA,SACE,oBACA,+BAEK,wBAAwB;AAC/B,SAAS,iBAAiB,wBAAwB;AAClD,SAA2B,kBAAkB,iBAAiB,aAAa;AAC3E,SAAS,mBAAmB,aAAa;AASzC,OAAO,MAAM,mCAAmC,wBAAwB;CACtE;CAEA,YAAYA,UAA2B;AACrC,SAAO;AAEP,OAAKC,YAAY;CAClB;CAED,YAAYC,WAAmBC,OAAeC,SAAc;EAC1D,MAAM,OAAO,KAAKH,UAAU,WAAW,WAAW,OAAO,OAAO;AAChE,SAAO,KAAK,OAAO,QAAQ;CAC5B;CAED,UAAUC,WAAmBG,WAAmBD,SAAc;EAC5D,MAAM,OACJ,KAAKH,UAAU,WAAW,WAAW,WAAW,WAAW;AAC7D,MAAI,gBAAgB,UAAW,QAAO;AACtC,SAAO,KAAK,OAAO,QAAQ;CAC5B;CAED,eAAeC,WAAmBG,WAAmBD,SAAc;EACjE,MAAM,OACJ,KAAKH,UAAU,WAAW,WAAW,WAAW,WAAW;AAC7D,MAAI,gBAAgB,UAAW,QAAO;AACtC,SAAO,KAAK,OAAO,QAAQ;CAC5B;CAED,UAAUC,WAAmBG,WAAmBD,SAAc;EAC5D,MAAM,OACJ,KAAKH,UAAU,WAAW,WAAW,WAAW,WAAW;AAC7D,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,sBAWH,mBAA6D;CACrE;CACA,WAAW,CAAE;CAEb,YACEK,UACAC,SAKA;AACA,QAAM;GACJ,GAAG;GACH,aAAa,IAAI,2BAA2B;EAC7C,EAAC;EAEF,MAAM,UAAU,CAAE;AAElB,OAAK,MAAM,CAAC,cAAc,UAAU,IAAI,OAAO,QAC7C,SAAS,WACV,EAAE;AACD,aAAU;AAEV,WAAQ,gBAAgB,CAAE;AAE1B,QAAK,MAAM,CAAC,cAAc,UAAU,IAAI,OAAO,QAC7C,UAAU,WACX,EAAE;AACD,YAAQ,cAAc,gBAAgB,CAAC,SAAS,YAC9C,KAAK,MAAM,UAAU,MAAM,UAAU,MAAM,SAAS;KAClD,SAAS,UAAU;KACnB,GAAG;IACJ,EAAC;GACL;EACF;AACD,OAAKC,WAAW;CACjB;CAED,IAAI,OAAO;AACT,SAAO,KAAKA;CACb;AACF","names":["contract: TAnyAPIContract","#contract","namespace: string","event: string","payload: any","procedure: string","contract: APIContract","options: {\n transport: ProtocolTransport\n format: BaseClientFormat\n timeout?: number\n }","#callers"],"sources":["src/runtime.ts"],"sourcesContent":["import type { TAnyAPIContract } from '@nmtjs/contract'\nimport type { BaseClientFormat } from '@nmtjs/protocol/client'\nimport {\n ProtocolBaseClient,\n ProtocolBaseTransformer,\n type ProtocolTransport,\n} from '@nmtjs/protocol/client'\nimport { ErrorCode } from '@nmtjs/protocol/common'\nimport { type BaseTypeAny, NeemataTypeError, NeverType } from '@nmtjs/type'\nimport { ClientError } from './common.ts'\nimport type {\n ClientCallers,\n ResolveAPIContract,\n ResolveClientEvents,\n RuntimeInputContractTypeProvider,\n RuntimeOutputContractTypeProvider,\n} from './types.ts'\n\nexport class RuntimeContractTransformer extends ProtocolBaseTransformer {\n #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 =\n 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 ResolvedAPIContract extends ResolveAPIContract<\n APIContract,\n RuntimeInputContractTypeProvider,\n RuntimeOutputContractTypeProvider\n > = ResolveAPIContract<\n APIContract,\n RuntimeInputContractTypeProvider,\n RuntimeOutputContractTypeProvider\n >,\n> extends ProtocolBaseClient<ResolveClientEvents<ResolvedAPIContract>> {\n _!: ResolvedAPIContract\n #callers = {} as ClientCallers<ResolvedAPIContract>\n\n constructor(\n contract: APIContract,\n options: {\n transport: ProtocolTransport\n format: BaseClientFormat\n timeout?: number\n },\n ) {\n super({\n ...options,\n transformer: new RuntimeContractTransformer(contract),\n })\n\n const callers = {} as any\n\n for (const [namespaceKey, namespace] of Object.entries(\n contract.namespaces,\n )) {\n namespace.procedures\n\n callers[namespaceKey] = {} as any\n\n for (const [procedureKey, procedure] of Object.entries(\n namespace.procedures,\n )) {\n callers[namespaceKey][procedureKey] = (payload, options) =>\n this._call(namespace.name, procedure.name, payload, {\n timeout: namespace.timeout,\n ...options,\n })\n }\n }\n this.#callers = callers\n }\n\n get call() {\n return this.#callers\n }\n}\n"],"version":3}
@@ -1 +1 @@
1
- {"mappings":"AACA,SAEE,0BAEK,wBAAwB;AAS/B,OAAO,MAAM,qBAMH,mBAA6D;CACrE;CAEA;CAEA,YAAYA,SAIT;AACD,QAAM,QAAQ;AAEd,OAAKC,WAAW,IAAI,MAAM,QAAQ,EAAE,EAClC,KAAK,CAAC,QAAQ,cAAc;AAI1B,OAAI,cAAc,OAAQ,QAAO;AACjC,UAAO,IAAI,MAAM,QAAQ,EAAE,EACzB,KAAK,CAAC,QAAQ,cAAc;AAI1B,QAAI,cAAc,OAAQ,QAAO;AACjC,WAAO,CAAC,SAAS,YACf,KAAK,MACH,WACA,WACA,SACA,QACD;GACJ,EACF;EACF,EACF;CACF;CAED,IAAI,OAAO;AACT,SAAO,KAAKA;CACb;AACF","names":["options: {\n transport: ProtocolTransport\n format: BaseClientFormat\n timeout?: number\n }","#callers"],"sources":["src/static.ts"],"sourcesContent":["import type { TAnyAPIContract } from '@nmtjs/contract'\nimport {\n type BaseClientFormat,\n ProtocolBaseClient,\n type ProtocolTransport,\n} from '@nmtjs/protocol/client'\n\nimport type {\n ClientCallers,\n ResolveAPIContract,\n ResolveClientEvents,\n StaticContractTypeProvider,\n} from './types.ts'\n\nexport class StaticClient<\n APIContract extends TAnyAPIContract,\n ResolvedAPIContract extends ResolveAPIContract<\n APIContract,\n StaticContractTypeProvider\n > = ResolveAPIContract<APIContract, StaticContractTypeProvider>,\n> extends ProtocolBaseClient<ResolveClientEvents<ResolvedAPIContract>> {\n _!: ResolvedAPIContract\n\n #callers: ClientCallers<ResolvedAPIContract>\n\n constructor(options: {\n transport: ProtocolTransport\n format: BaseClientFormat\n timeout?: number\n }) {\n super(options)\n\n this.#callers = new Proxy(Object(), {\n get: (target, namespace) => {\n // `await client.call.namespaceName` or `await client.call.namespaceName.procedureName`\n // without explicitly calling a function implicitly calls .then() on target\n // FIXME: this basically makes \"then\" a reserved word\n if (namespace === 'then') return target\n return new Proxy(Object(), {\n get: (target, procedure) => {\n // `await client.call.namespaceName` or `await client.call.namespaceName.procedureName`\n // without explicitly calling a function implicitly calls .then() on target\n // FIXME: this basically makes \"then\" a reserved word\n if (procedure === 'then') return target\n return (payload, options) =>\n this._call(\n namespace as string,\n procedure as string,\n payload,\n options,\n )\n },\n })\n },\n })\n }\n\n get call() {\n return this.#callers\n }\n}\n"],"version":3}
1
+ {"mappings":"AACA,SAEE,0BAEK,wBAAwB;AAU/B,OAAO,MAAM,qBAWH,mBAA6D;CACrE;CAEA;CAEA,YAAYA,SAIT;AACD,QAAM,QAAQ;AAEd,OAAKC,WAAW,IAAI,MAAM,QAAQ,EAAE,EAClC,KAAK,CAAC,QAAQ,cAAc;AAI1B,OAAI,cAAc,OAAQ,QAAO;AACjC,UAAO,IAAI,MAAM,QAAQ,EAAE,EACzB,KAAK,CAAC,QAAQ,cAAc;AAI1B,QAAI,cAAc,OAAQ,QAAO;AACjC,WAAO,CAAC,SAAS,YACf,KAAK,MACH,WACA,WACA,SACA,QACD;GACJ,EACF;EACF,EACF;CACF;CAED,IAAI,OAAO;AACT,SAAO,KAAKA;CACb;AACF","names":["options: {\n transport: ProtocolTransport\n format: BaseClientFormat\n timeout?: number\n }","#callers"],"sources":["src/static.ts"],"sourcesContent":["import type { TAnyAPIContract } from '@nmtjs/contract'\nimport {\n type BaseClientFormat,\n ProtocolBaseClient,\n type ProtocolTransport,\n} from '@nmtjs/protocol/client'\n\nimport type {\n ClientCallers,\n ResolveAPIContract,\n ResolveClientEvents,\n StaticInputContractTypeProvider,\n StaticOutputContractTypeProvider,\n} from './types.ts'\n\nexport class StaticClient<\n APIContract extends TAnyAPIContract,\n ResolvedAPIContract extends ResolveAPIContract<\n APIContract,\n StaticInputContractTypeProvider,\n StaticOutputContractTypeProvider\n > = ResolveAPIContract<\n APIContract,\n StaticInputContractTypeProvider,\n StaticOutputContractTypeProvider\n >,\n> extends ProtocolBaseClient<ResolveClientEvents<ResolvedAPIContract>> {\n _!: ResolvedAPIContract\n\n #callers: ClientCallers<ResolvedAPIContract>\n\n constructor(options: {\n transport: ProtocolTransport\n format: BaseClientFormat\n timeout?: number\n }) {\n super(options)\n\n this.#callers = new Proxy(Object(), {\n get: (target, namespace) => {\n // `await client.call.namespaceName` or `await client.call.namespaceName.procedureName`\n // without explicitly calling a function implicitly calls .then() on target\n // FIXME: this basically makes \"then\" a reserved word\n if (namespace === 'then') return target\n return new Proxy(Object(), {\n get: (target, procedure) => {\n // `await client.call.namespaceName` or `await client.call.namespaceName.procedureName`\n // without explicitly calling a function implicitly calls .then() on target\n // FIXME: this basically makes \"then\" a reserved word\n if (procedure === 'then') return target\n return (payload, options) =>\n this._call(\n namespace as string,\n procedure as string,\n payload,\n options,\n )\n },\n })\n },\n })\n }\n\n get call() {\n return this.#callers\n }\n}\n"],"version":3}
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":"","names":[],"sources":["src/types.ts"],"sourcesContent":["import type { CallTypeProvider, TypeProvider } from '@nmtjs/common'\nimport type { TAnyAPIContract } from '@nmtjs/contract'\nimport type {\n ProtocolBaseClientCallOptions,\n ProtocolServerStreamInterface,\n} from '@nmtjs/protocol/client'\nimport type { InputType, OutputType } from '@nmtjs/protocol/common'\nimport type { BaseTypeAny, NeverType, t } from '@nmtjs/type'\n\nexport interface StaticContractTypeProvider extends TypeProvider {\n output: this['input'] extends BaseTypeAny\n ? t.infer.input.decoded<this['input']>\n : never\n}\n\nexport interface RuntimeContractTypeProvider extends TypeProvider {\n output: this['input'] extends BaseTypeAny\n ? t.infer.decoded<this['input']>\n : never\n}\n\nexport type ResolveAPIContract<\n C extends TAnyAPIContract = TAnyAPIContract,\n T 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<T, C['namespaces'][N]['procedures'][P]['input']>\n >\n output: C['namespaces'][N]['procedures'][P]['stream'] extends NeverType\n ? OutputType<\n CallTypeProvider<T, C['namespaces'][N]['procedures'][P]['output']>\n >\n : {\n response: OutputType<\n CallTypeProvider<\n T,\n C['namespaces'][N]['procedures'][P]['output']\n >\n >\n stream: ProtocolServerStreamInterface<\n CallTypeProvider<\n T,\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<T, C['namespaces'][N]['events'][KE]['payload']>\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']]: C[N]['events'][KE]['payload']\n }\n}\n\nexport type ClientCallers<Resolved extends ResolveAPIContract> = {\n [N in keyof Resolved]: {\n [P in keyof Resolved[N]['procedures']]: (\n ...args: Resolved[N]['procedures'][P]['input'] extends NeverType\n ? [options?: ProtocolBaseClientCallOptions]\n : t.infer.input.encoded<\n Resolved[N]['procedures'][P]['contract']['input']\n > extends undefined\n ? [\n data?: Resolved[N]['procedures'][P]['input'],\n options?: ProtocolBaseClientCallOptions,\n ]\n : [\n data: Resolved[N]['procedures'][P]['input'],\n options?: ProtocolBaseClientCallOptions,\n ]\n ) => Promise<Resolved[N]['procedures'][P]['output']>\n }\n}\n"],"version":3}
1
+ {"mappings":"","names":[],"sources":["src/types.ts"],"sourcesContent":["import type { CallTypeProvider, TypeProvider } from '@nmtjs/common'\nimport type { TAnyAPIContract } from '@nmtjs/contract'\nimport type {\n ProtocolBaseClientCallOptions,\n ProtocolServerStreamInterface,\n} from '@nmtjs/protocol/client'\nimport type { InputType, OutputType } from '@nmtjs/protocol/common'\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 response: 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']]: C[N]['events'][KE]['payload']\n }\n}\n\nexport type ClientCallers<Resolved extends ResolveAPIContract> = {\n [N in keyof Resolved]: {\n [P in keyof Resolved[N]['procedures']]: (\n ...args: Resolved[N]['procedures'][P]['input'] extends NeverType\n ? [options?: ProtocolBaseClientCallOptions]\n : t.infer.encoded.input<\n Resolved[N]['procedures'][P]['contract']['input']\n > extends undefined\n ? [\n data?: Resolved[N]['procedures'][P]['input'],\n options?: ProtocolBaseClientCallOptions,\n ]\n : [\n data: Resolved[N]['procedures'][P]['input'],\n options?: ProtocolBaseClientCallOptions,\n ]\n ) => Promise<Resolved[N]['procedures'][P]['output']>\n }\n}\n"],"version":3}
package/package.json CHANGED
@@ -16,10 +16,10 @@
16
16
  }
17
17
  },
18
18
  "dependencies": {
19
- "@nmtjs/type": "0.7.0",
20
- "@nmtjs/protocol": "0.7.0",
21
- "@nmtjs/contract": "0.7.0",
22
- "@nmtjs/common": "0.7.0"
19
+ "@nmtjs/type": "0.7.2",
20
+ "@nmtjs/contract": "0.7.2",
21
+ "@nmtjs/common": "0.7.2",
22
+ "@nmtjs/protocol": "0.7.2"
23
23
  },
24
24
  "files": [
25
25
  "src",
@@ -27,7 +27,7 @@
27
27
  "LICENSE.md",
28
28
  "README.md"
29
29
  ],
30
- "version": "0.7.0",
30
+ "version": "0.7.2",
31
31
  "scripts": {
32
32
  "build": "neemata-build --root=./src './**/*.ts'",
33
33
  "type-check": "tsc --noEmit"
package/src/runtime.ts CHANGED
@@ -12,7 +12,8 @@ import type {
12
12
  ClientCallers,
13
13
  ResolveAPIContract,
14
14
  ResolveClientEvents,
15
- RuntimeContractTypeProvider,
15
+ RuntimeInputContractTypeProvider,
16
+ RuntimeOutputContractTypeProvider,
16
17
  } from './types.ts'
17
18
 
18
19
  export class RuntimeContractTransformer extends ProtocolBaseTransformer {
@@ -66,8 +67,13 @@ export class RuntimeClient<
66
67
  APIContract extends TAnyAPIContract,
67
68
  ResolvedAPIContract extends ResolveAPIContract<
68
69
  APIContract,
69
- RuntimeContractTypeProvider
70
- > = ResolveAPIContract<APIContract, RuntimeContractTypeProvider>,
70
+ RuntimeInputContractTypeProvider,
71
+ RuntimeOutputContractTypeProvider
72
+ > = ResolveAPIContract<
73
+ APIContract,
74
+ RuntimeInputContractTypeProvider,
75
+ RuntimeOutputContractTypeProvider
76
+ >,
71
77
  > extends ProtocolBaseClient<ResolveClientEvents<ResolvedAPIContract>> {
72
78
  _!: ResolvedAPIContract
73
79
  #callers = {} as ClientCallers<ResolvedAPIContract>
package/src/static.ts CHANGED
@@ -9,15 +9,21 @@ import type {
9
9
  ClientCallers,
10
10
  ResolveAPIContract,
11
11
  ResolveClientEvents,
12
- StaticContractTypeProvider,
12
+ StaticInputContractTypeProvider,
13
+ StaticOutputContractTypeProvider,
13
14
  } from './types.ts'
14
15
 
15
16
  export class StaticClient<
16
17
  APIContract extends TAnyAPIContract,
17
18
  ResolvedAPIContract extends ResolveAPIContract<
18
19
  APIContract,
19
- StaticContractTypeProvider
20
- > = ResolveAPIContract<APIContract, StaticContractTypeProvider>,
20
+ StaticInputContractTypeProvider,
21
+ StaticOutputContractTypeProvider
22
+ > = ResolveAPIContract<
23
+ APIContract,
24
+ StaticInputContractTypeProvider,
25
+ StaticOutputContractTypeProvider
26
+ >,
21
27
  > extends ProtocolBaseClient<ResolveClientEvents<ResolvedAPIContract>> {
22
28
  _!: ResolvedAPIContract
23
29
 
package/src/types.ts CHANGED
@@ -7,43 +7,62 @@ import type {
7
7
  import type { InputType, OutputType } from '@nmtjs/protocol/common'
8
8
  import type { BaseTypeAny, NeverType, t } from '@nmtjs/type'
9
9
 
10
- export interface StaticContractTypeProvider extends TypeProvider {
10
+ export interface StaticInputContractTypeProvider extends TypeProvider {
11
11
  output: this['input'] extends BaseTypeAny
12
- ? t.infer.input.decoded<this['input']>
12
+ ? t.infer.encoded.input<this['input']>
13
13
  : never
14
14
  }
15
15
 
16
- export interface RuntimeContractTypeProvider extends TypeProvider {
16
+ export interface RuntimeInputContractTypeProvider extends TypeProvider {
17
17
  output: this['input'] extends BaseTypeAny
18
- ? t.infer.decoded<this['input']>
18
+ ? t.infer.decoded.input<this['input']>
19
+ : never
20
+ }
21
+
22
+ export interface StaticOutputContractTypeProvider extends TypeProvider {
23
+ output: this['input'] extends BaseTypeAny
24
+ ? t.infer.encoded.output<this['input']>
25
+ : never
26
+ }
27
+
28
+ export interface RuntimeOutputContractTypeProvider extends TypeProvider {
29
+ output: this['input'] extends BaseTypeAny
30
+ ? t.infer.decoded.output<this['input']>
19
31
  : never
20
32
  }
21
33
 
22
34
  export type ResolveAPIContract<
23
35
  C extends TAnyAPIContract = TAnyAPIContract,
24
- T extends TypeProvider = TypeProvider,
36
+ InputTypeProvider extends TypeProvider = TypeProvider,
37
+ OutputTypeProvider extends TypeProvider = TypeProvider,
25
38
  > = {
26
39
  [N in keyof C['namespaces'] as C['namespaces'][N]['name']]: {
27
40
  procedures: {
28
41
  [P in keyof C['namespaces'][N]['procedures'] as C['namespaces'][N]['procedures'][P]['name']]: {
29
42
  contract: C['namespaces'][N]['procedures'][P]
30
43
  input: InputType<
31
- CallTypeProvider<T, C['namespaces'][N]['procedures'][P]['input']>
44
+ CallTypeProvider<
45
+ InputTypeProvider,
46
+ C['namespaces'][N]['procedures'][P]['input']
47
+ >
32
48
  >
33
49
  output: C['namespaces'][N]['procedures'][P]['stream'] extends NeverType
34
50
  ? OutputType<
35
- CallTypeProvider<T, C['namespaces'][N]['procedures'][P]['output']>
51
+ CallTypeProvider<
52
+ OutputTypeProvider,
53
+ C['namespaces'][N]['procedures'][P]['output']
54
+ >
36
55
  >
37
56
  : {
38
57
  response: OutputType<
39
58
  CallTypeProvider<
40
- T,
59
+ OutputTypeProvider,
41
60
  C['namespaces'][N]['procedures'][P]['output']
42
61
  >
43
62
  >
44
63
  stream: ProtocolServerStreamInterface<
45
64
  CallTypeProvider<
46
- T,
65
+ OutputTypeProvider,
47
66
  C['namespaces'][N]['procedures'][P]['stream']
48
67
  >
49
68
  >
@@ -53,7 +72,10 @@ export type ResolveAPIContract<
53
72
  events: {
54
73
  [KE in keyof C['namespaces'][N]['events'] as C['namespaces'][N]['events'][KE]['name']]: {
55
74
  payload: OutputType<
56
- CallTypeProvider<T, C['namespaces'][N]['events'][KE]['payload']>
75
+ CallTypeProvider<
76
+ OutputTypeProvider,
77
+ C['namespaces'][N]['events'][KE]['payload']
78
+ >
57
79
  >
58
80
  }
59
81
  }
@@ -73,7 +95,7 @@ export type ClientCallers<Resolved extends ResolveAPIContract> = {
73
95
  [P in keyof Resolved[N]['procedures']]: (
74
96
  ...args: Resolved[N]['procedures'][P]['input'] extends NeverType
75
97
  ? [options?: ProtocolBaseClientCallOptions]
76
- : t.infer.input.encoded<
98
+ : t.infer.encoded.input<
77
99
  Resolved[N]['procedures'][P]['contract']['input']
78
100
  > extends undefined
79
101
  ? [