@nmtjs/client 0.6.0 → 0.6.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.
- package/dist/runtime.js +5 -2
- package/dist/runtime.js.map +1 -1
- package/dist/static.js +7 -7
- package/dist/static.js.map +1 -1
- package/dist/types.js.map +1 -1
- package/lib/runtime.ts +9 -3
- package/lib/static.ts +13 -8
- package/lib/types.ts +13 -14
- package/package.json +5 -5
package/dist/runtime.js
CHANGED
|
@@ -71,8 +71,11 @@ export class RuntimeContractTransformer extends ProtocolBaseTransformer {
|
|
|
71
71
|
export class RuntimeClient extends ProtocolBaseClient {
|
|
72
72
|
_;
|
|
73
73
|
#callers = {};
|
|
74
|
-
constructor(contract,
|
|
75
|
-
super(
|
|
74
|
+
constructor(contract, options){
|
|
75
|
+
super({
|
|
76
|
+
...options,
|
|
77
|
+
transformer: new RuntimeContractTransformer(contract)
|
|
78
|
+
});
|
|
76
79
|
const callers = {};
|
|
77
80
|
for (const [namespaceKey, namespace] of Object.entries(contract.namespaces)){
|
|
78
81
|
namespace.procedures;
|
package/dist/runtime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../lib/runtime.ts"],"sourcesContent":["import type { TAnyAPIContract } from '@nmtjs/contract'\nimport {\n ProtocolBaseClient,\n ProtocolBaseTransformer,\n type ProtocolTransport,\n} from '@nmtjs/protocol/client'\nimport type { BaseClientFormat } from '@nmtjs/protocol/client'\nimport { ErrorCode } from '@nmtjs/protocol/common'\nimport { type BaseTypeAny, NeverType } from '@nmtjs/type'\nimport { type Compiled, compile } from '@nmtjs/type/compiler'\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 #types = new Set<BaseTypeAny>()\n #compiled = new Map<BaseTypeAny, Compiled>()\n\n constructor(contract: TAnyAPIContract) {\n super()\n\n this.#contract = contract\n\n for (const namespace of Object.values(contract.namespaces)) {\n for (const procedure of Object.values(namespace.procedures)) {\n const { input, output, stream } = procedure\n this.#registerType(input)\n this.#registerType(output)\n this.#registerType(stream)\n }\n\n for (const subscription of Object.values(namespace.subscriptions)) {\n const { input, output } = subscription\n this.#registerType(input)\n this.#registerType(output)\n\n for (const event of Object.values(subscription.events)) {\n this.#registerType(event.payload)\n }\n }\n\n for (const event of Object.values(namespace.events)) {\n this.#registerType(event.payload)\n }\n }\n\n this.#compile()\n }\n\n decodeEvent(namespace: string, event: string, payload: any) {\n const type = this.#contract.namespaces[namespace].events[event].payload\n if (type instanceof NeverType) return undefined\n const compiled = this.#compiled.get(type)!\n return compiled.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 const compiled = this.#compiled.get(type)!\n return compiled.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\n const compiled = this.#compiled.get(type)!\n return compiled.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\n const compiled = this.#compiled.get(type)!\n if (!compiled.check(payload)) {\n const errors = compiled.errors(payload)\n throw new ClientError(\n ErrorCode.ValidationError,\n 'Invalid RPC payload',\n errors,\n )\n }\n\n return compiled.encode(payload)\n }\n\n #registerType(type: BaseTypeAny) {\n this.#types.add(type)\n }\n\n #compile() {\n for (const type of this.#types) {\n this.#compiled.set(type, compile(type))\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 transport: ProtocolTransport
|
|
1
|
+
{"version":3,"sources":["../../lib/runtime.ts"],"sourcesContent":["import type { TAnyAPIContract } from '@nmtjs/contract'\nimport {\n ProtocolBaseClient,\n ProtocolBaseTransformer,\n type ProtocolTransport,\n} from '@nmtjs/protocol/client'\nimport type { BaseClientFormat } from '@nmtjs/protocol/client'\nimport { ErrorCode } from '@nmtjs/protocol/common'\nimport { type BaseTypeAny, NeverType } from '@nmtjs/type'\nimport { type Compiled, compile } from '@nmtjs/type/compiler'\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 #types = new Set<BaseTypeAny>()\n #compiled = new Map<BaseTypeAny, Compiled>()\n\n constructor(contract: TAnyAPIContract) {\n super()\n\n this.#contract = contract\n\n for (const namespace of Object.values(contract.namespaces)) {\n for (const procedure of Object.values(namespace.procedures)) {\n const { input, output, stream } = procedure\n this.#registerType(input)\n this.#registerType(output)\n this.#registerType(stream)\n }\n\n for (const subscription of Object.values(namespace.subscriptions)) {\n const { input, output } = subscription\n this.#registerType(input)\n this.#registerType(output)\n\n for (const event of Object.values(subscription.events)) {\n this.#registerType(event.payload)\n }\n }\n\n for (const event of Object.values(namespace.events)) {\n this.#registerType(event.payload)\n }\n }\n\n this.#compile()\n }\n\n decodeEvent(namespace: string, event: string, payload: any) {\n const type = this.#contract.namespaces[namespace].events[event].payload\n if (type instanceof NeverType) return undefined\n const compiled = this.#compiled.get(type)!\n return compiled.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 const compiled = this.#compiled.get(type)!\n return compiled.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\n const compiled = this.#compiled.get(type)!\n return compiled.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\n const compiled = this.#compiled.get(type)!\n if (!compiled.check(payload)) {\n const errors = compiled.errors(payload)\n throw new ClientError(\n ErrorCode.ValidationError,\n 'Invalid RPC payload',\n errors,\n )\n }\n\n return compiled.encode(payload)\n }\n\n #registerType(type: BaseTypeAny) {\n this.#types.add(type)\n }\n\n #compile() {\n for (const type of this.#types) {\n this.#compiled.set(type, compile(type))\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"],"names":["ProtocolBaseClient","ProtocolBaseTransformer","ErrorCode","NeverType","compile","ClientError","RuntimeContractTransformer","Set","Map","constructor","contract","namespace","Object","values","namespaces","procedure","procedures","input","output","stream","subscription","subscriptions","event","events","payload","decodeEvent","type","undefined","compiled","get","decode","decodeRPC","decodeRPCChunk","encodeRPC","check","errors","ValidationError","encode","add","set","RuntimeClient","_","options","transformer","callers","namespaceKey","entries","procedureKey","_call","name","timeout","call"],"mappings":"AACA,SACEA,kBAAkB,EAClBC,uBAAuB,QAElB,yBAAwB;AAE/B,SAASC,SAAS,QAAQ,yBAAwB;AAClD,SAA2BC,SAAS,QAAQ,cAAa;AACzD,SAAwBC,OAAO,QAAQ,uBAAsB;AAC7D,SAASC,WAAW,QAAQ,cAAa;AAQzC,OAAO,MAAMC,mCAAmCL;IAC9C,CAAA,QAAS,CAAiB;IAC1B,CAAA,KAAM,GAAG,IAAIM,MAAkB;IAC/B,CAAA,QAAS,GAAG,IAAIC,MAA4B;IAE5CC,YAAYC,QAAyB,CAAE;QACrC,KAAK;QAEL,IAAI,CAAC,CAAA,QAAS,GAAGA;QAEjB,KAAK,MAAMC,aAAaC,OAAOC,MAAM,CAACH,SAASI,UAAU,EAAG;YAC1D,KAAK,MAAMC,aAAaH,OAAOC,MAAM,CAACF,UAAUK,UAAU,EAAG;gBAC3D,MAAM,EAAEC,KAAK,EAAEC,MAAM,EAAEC,MAAM,EAAE,GAAGJ;gBAClC,IAAI,CAAC,CAAA,YAAa,CAACE;gBACnB,IAAI,CAAC,CAAA,YAAa,CAACC;gBACnB,IAAI,CAAC,CAAA,YAAa,CAACC;YACrB;YAEA,KAAK,MAAMC,gBAAgBR,OAAOC,MAAM,CAACF,UAAUU,aAAa,EAAG;gBACjE,MAAM,EAAEJ,KAAK,EAAEC,MAAM,EAAE,GAAGE;gBAC1B,IAAI,CAAC,CAAA,YAAa,CAACH;gBACnB,IAAI,CAAC,CAAA,YAAa,CAACC;gBAEnB,KAAK,MAAMI,SAASV,OAAOC,MAAM,CAACO,aAAaG,MAAM,EAAG;oBACtD,IAAI,CAAC,CAAA,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,OAAQ,GAAGE;IAClB;IAEA,IAAIO,OAAO;QACT,OAAO,IAAI,CAAC,CAAA,OAAQ;IACtB;AACF"}
|
package/dist/static.js
CHANGED
|
@@ -2,15 +2,15 @@ import { ProtocolBaseClient } from '@nmtjs/protocol/client';
|
|
|
2
2
|
export class StaticClient extends ProtocolBaseClient {
|
|
3
3
|
_;
|
|
4
4
|
#callers;
|
|
5
|
-
constructor(
|
|
6
|
-
super(
|
|
5
|
+
constructor(options){
|
|
6
|
+
super(options);
|
|
7
7
|
this.#callers = new Proxy(Object(), {
|
|
8
|
-
get: (target,
|
|
9
|
-
if (
|
|
8
|
+
get: (target, namespace)=>{
|
|
9
|
+
if (namespace === 'then') return target;
|
|
10
10
|
return new Proxy(Object(), {
|
|
11
|
-
get: (target,
|
|
12
|
-
if (
|
|
13
|
-
return (payload, options)=>this._call(
|
|
11
|
+
get: (target, procedure)=>{
|
|
12
|
+
if (procedure === 'then') return target;
|
|
13
|
+
return (payload, options)=>this._call(namespace, procedure, payload, options);
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
16
|
}
|
package/dist/static.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../lib/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(transport: ProtocolTransport
|
|
1
|
+
{"version":3,"sources":["../../lib/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"],"names":["ProtocolBaseClient","StaticClient","_","constructor","options","Proxy","Object","get","target","namespace","procedure","payload","_call","call"],"mappings":"AACA,SAEEA,kBAAkB,QAEb,yBAAwB;AAS/B,OAAO,MAAMC,qBAMHD;IACRE,EAAuB;IAEvB,CAAA,OAAQ,CAAoC;IAE5CC,YAAYC,OAIX,CAAE;QACD,KAAK,CAACA;QAEN,IAAI,CAAC,CAAA,OAAQ,GAAG,IAAIC,MAAMC,UAAU;YAClCC,KAAK,CAACC,QAAQC;gBAIZ,IAAIA,cAAc,QAAQ,OAAOD;gBACjC,OAAO,IAAIH,MAAMC,UAAU;oBACzBC,KAAK,CAACC,QAAQE;wBAIZ,IAAIA,cAAc,QAAQ,OAAOF;wBACjC,OAAO,CAACG,SAASP,UACf,IAAI,CAACQ,KAAK,CACRH,WACAC,WACAC,SACAP;oBAEN;gBACF;YACF;QACF;IACF;IAEA,IAAIS,OAAO;QACT,OAAO,IAAI,CAAC,CAAA,OAAQ;IACtB;AACF"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../lib/types.ts"],"sourcesContent":["import type { CallTypeProvider, TypeProvider } from '@nmtjs/common'\nimport type { TAnyAPIContract } from '@nmtjs/contract'\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../lib/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"],"names":[],"mappings":"AAsEA,WAkBC"}
|
package/lib/runtime.ts
CHANGED
|
@@ -117,10 +117,16 @@ export class RuntimeClient<
|
|
|
117
117
|
|
|
118
118
|
constructor(
|
|
119
119
|
contract: APIContract,
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
options: {
|
|
121
|
+
transport: ProtocolTransport
|
|
122
|
+
format: BaseClientFormat
|
|
123
|
+
timeout?: number
|
|
124
|
+
},
|
|
122
125
|
) {
|
|
123
|
-
super(
|
|
126
|
+
super({
|
|
127
|
+
...options,
|
|
128
|
+
transformer: new RuntimeContractTransformer(contract),
|
|
129
|
+
})
|
|
124
130
|
|
|
125
131
|
const callers = {} as any
|
|
126
132
|
|
package/lib/static.ts
CHANGED
|
@@ -23,26 +23,31 @@ export class StaticClient<
|
|
|
23
23
|
|
|
24
24
|
#callers: ClientCallers<ResolvedAPIContract>
|
|
25
25
|
|
|
26
|
-
constructor(
|
|
27
|
-
|
|
26
|
+
constructor(options: {
|
|
27
|
+
transport: ProtocolTransport
|
|
28
|
+
format: BaseClientFormat
|
|
29
|
+
timeout?: number
|
|
30
|
+
}) {
|
|
31
|
+
super(options)
|
|
28
32
|
|
|
29
33
|
this.#callers = new Proxy(Object(), {
|
|
30
|
-
get: (target,
|
|
34
|
+
get: (target, namespace) => {
|
|
31
35
|
// `await client.call.namespaceName` or `await client.call.namespaceName.procedureName`
|
|
32
36
|
// without explicitly calling a function implicitly calls .then() on target
|
|
33
37
|
// FIXME: this basically makes "then" a reserved word
|
|
34
|
-
if (
|
|
38
|
+
if (namespace === 'then') return target
|
|
35
39
|
return new Proxy(Object(), {
|
|
36
|
-
get: (target,
|
|
40
|
+
get: (target, procedure) => {
|
|
37
41
|
// `await client.call.namespaceName` or `await client.call.namespaceName.procedureName`
|
|
38
42
|
// without explicitly calling a function implicitly calls .then() on target
|
|
39
43
|
// FIXME: this basically makes "then" a reserved word
|
|
40
|
-
if (
|
|
44
|
+
if (procedure === 'then') return target
|
|
41
45
|
return (payload, options) =>
|
|
42
46
|
this._call(
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
namespace as string,
|
|
48
|
+
procedure as string,
|
|
45
49
|
payload,
|
|
50
|
+
options,
|
|
46
51
|
)
|
|
47
52
|
},
|
|
48
53
|
})
|
package/lib/types.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { CallTypeProvider, TypeProvider } from '@nmtjs/common'
|
|
2
2
|
import type { TAnyAPIContract } from '@nmtjs/contract'
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
ProtocolBaseClientCallOptions,
|
|
5
|
+
ProtocolServerStreamInterface,
|
|
6
|
+
} from '@nmtjs/protocol/client'
|
|
4
7
|
import type { InputType, OutputType } from '@nmtjs/protocol/common'
|
|
5
8
|
import type { BaseTypeAny, NeverType, t } from '@nmtjs/type'
|
|
6
9
|
|
|
@@ -31,20 +34,20 @@ export type ResolveAPIContract<
|
|
|
31
34
|
? OutputType<
|
|
32
35
|
CallTypeProvider<T, C['namespaces'][N]['procedures'][P]['output']>
|
|
33
36
|
>
|
|
34
|
-
:
|
|
35
|
-
|
|
37
|
+
: {
|
|
38
|
+
response: OutputType<
|
|
36
39
|
CallTypeProvider<
|
|
37
40
|
T,
|
|
38
41
|
C['namespaces'][N]['procedures'][P]['output']
|
|
39
42
|
>
|
|
40
|
-
|
|
41
|
-
stream:
|
|
43
|
+
>
|
|
44
|
+
stream: ProtocolServerStreamInterface<
|
|
42
45
|
CallTypeProvider<
|
|
43
46
|
T,
|
|
44
47
|
C['namespaces'][N]['procedures'][P]['stream']
|
|
45
48
|
>
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
>
|
|
50
|
+
}
|
|
48
51
|
}
|
|
49
52
|
}
|
|
50
53
|
events: {
|
|
@@ -65,25 +68,21 @@ export type ResolveClientEvents<
|
|
|
65
68
|
}
|
|
66
69
|
}
|
|
67
70
|
|
|
68
|
-
export type ClientCallOptions = {
|
|
69
|
-
signal?: AbortSignal
|
|
70
|
-
}
|
|
71
|
-
|
|
72
71
|
export type ClientCallers<Resolved extends ResolveAPIContract> = {
|
|
73
72
|
[N in keyof Resolved]: {
|
|
74
73
|
[P in keyof Resolved[N]['procedures']]: (
|
|
75
74
|
...args: Resolved[N]['procedures'][P]['input'] extends NeverType
|
|
76
|
-
? [options?:
|
|
75
|
+
? [options?: ProtocolBaseClientCallOptions]
|
|
77
76
|
: t.infer.input.encoded<
|
|
78
77
|
Resolved[N]['procedures'][P]['contract']['input']
|
|
79
78
|
> extends undefined
|
|
80
79
|
? [
|
|
81
80
|
data?: Resolved[N]['procedures'][P]['input'],
|
|
82
|
-
options?:
|
|
81
|
+
options?: ProtocolBaseClientCallOptions,
|
|
83
82
|
]
|
|
84
83
|
: [
|
|
85
84
|
data: Resolved[N]['procedures'][P]['input'],
|
|
86
|
-
options?:
|
|
85
|
+
options?: ProtocolBaseClientCallOptions,
|
|
87
86
|
]
|
|
88
87
|
) => Promise<Resolved[N]['procedures'][P]['output']>
|
|
89
88
|
}
|
package/package.json
CHANGED
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@nmtjs/
|
|
23
|
-
"@nmtjs/
|
|
24
|
-
"@nmtjs/
|
|
25
|
-
"@nmtjs/protocol": "0.6.
|
|
22
|
+
"@nmtjs/type": "0.6.2",
|
|
23
|
+
"@nmtjs/contract": "0.6.2",
|
|
24
|
+
"@nmtjs/common": "0.6.2",
|
|
25
|
+
"@nmtjs/protocol": "0.6.2"
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
|
28
28
|
"index.ts",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"LICENSE.md",
|
|
33
33
|
"README.md"
|
|
34
34
|
],
|
|
35
|
-
"version": "0.6.
|
|
35
|
+
"version": "0.6.2",
|
|
36
36
|
"scripts": {
|
|
37
37
|
"build": "neemata-build -p neutral --root=./lib './**/*.ts'",
|
|
38
38
|
"type-check": "tsc --noEmit"
|