@nmtjs/client 0.4.2 → 0.4.4
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.
|
@@ -8,6 +8,7 @@ export class StaticClient extends Client {
|
|
|
8
8
|
for (const [serviceKey, serviceName] of Object.entries(services)){
|
|
9
9
|
callers[serviceKey] = new Proxy(Object(), {
|
|
10
10
|
get: (target, prop, receiver)=>{
|
|
11
|
+
if (prop === 'then') return target;
|
|
11
12
|
return this.createCaller(serviceName, prop);
|
|
12
13
|
}
|
|
13
14
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../lib/client-static.ts"],"sourcesContent":["import type { TServiceContract, TSubscriptionContract } from '@nmtjs/contract'\nimport type { NeverType, t } from '@nmtjs/type'\nimport { Client, type ClientOptions } from './client.ts'\nimport type { Subscription } from './subscription.ts'\nimport type { ClientCallOptions, InputType, OutputType } from './types.ts'\n\ntype ClientServices = Record<string, TServiceContract>\n\ntype ClientServicesResolved<Services extends ClientServices> = {\n [K in keyof Services]: {\n [P in keyof Services[K]['procedures']]: {\n contract: Services[K]['procedures'][P]\n input: InputType<t.infer.encoded<Services[K]['procedures'][P]['input']>>\n output: OutputType<\n t.infer.encoded<Services[K]['procedures'][P]['output']>\n >\n events: Services[K]['procedures'][P] extends TSubscriptionContract\n ? {\n [KE in keyof Services[K]['procedures'][P]['events']]: {\n payload: OutputType<\n t.infer.encoded<\n Services[K]['procedures'][P]['events'][KE]['payload']\n >\n >\n }\n }\n : {}\n }\n }\n}\n\ntype ClientCallers<\n Services extends ClientServicesResolved<Record<string, TServiceContract>>,\n> = {\n [K in keyof Services]: {\n [P in keyof Services[K]]: (\n ...args: Services[K][P]['input'] extends never\n ? [options?: ClientCallOptions]\n : Services[K][P]['input'] extends undefined\n ? [data?: Services[K][P]['input'], options?: ClientCallOptions]\n : [data: Services[K][P]['input'], options?: ClientCallOptions]\n ) => Promise<\n Services[K][P]['contract'] extends TSubscriptionContract\n ? {\n payload: Services[K][P]['output'] extends never\n ? undefined\n : Services[K][P]['output']\n subscription: Subscription<{\n [KE in keyof Services[K][P]['events']]: [\n Services[K][P]['events'][KE],\n ]\n }>\n }\n : Services[K][P]['output'] extends never\n ? void\n : Services[K][P]['output']\n >\n }\n}\n\nexport class StaticClient<Services extends ClientServices> extends Client {\n $types!: ClientServicesResolved<Services>\n #callers: ClientCallers<this['$types']>\n\n constructor(\n services: { [K in keyof Services]: Services[K]['name'] },\n options: ClientOptions,\n ) {\n super(options, Object.values(services))\n\n const callers = {} as any\n\n for (const [serviceKey, serviceName] of Object.entries(services)) {\n callers[serviceKey] = new Proxy(Object(), {\n get: (target, prop, receiver) => {\n return this.createCaller(serviceName, prop as string)\n },\n })\n }\n\n this.#callers = callers\n }\n\n get call() {\n return this.#callers\n }\n}\n"],"names":["Client","StaticClient","$types","constructor","services","options","Object","values","callers","serviceKey","serviceName","entries","Proxy","get","target","prop","receiver","createCaller","call"],"mappings":"AAEA,SAASA,MAAM,QAA4B,cAAa;AA0DxD,OAAO,MAAMC,qBAAsDD;IACjEE,OAAyC;IACzC,CAAA,OAAQ,CAA+B;IAEvCC,YACEC,QAAwD,EACxDC,OAAsB,CACtB;QACA,KAAK,CAACA,SAASC,OAAOC,MAAM,CAACH;QAE7B,MAAMI,UAAU,CAAC;QAEjB,KAAK,MAAM,CAACC,YAAYC,YAAY,IAAIJ,OAAOK,OAAO,CAACP,UAAW;YAChEI,OAAO,CAACC,WAAW,GAAG,IAAIG,MAAMN,UAAU;gBACxCO,KAAK,CAACC,QAAQC,MAAMC;
|
|
1
|
+
{"version":3,"sources":["../../../lib/client-static.ts"],"sourcesContent":["import type { TServiceContract, TSubscriptionContract } from '@nmtjs/contract'\nimport type { NeverType, t } from '@nmtjs/type'\nimport { Client, type ClientOptions } from './client.ts'\nimport type { Subscription } from './subscription.ts'\nimport type { ClientCallOptions, InputType, OutputType } from './types.ts'\n\ntype ClientServices = Record<string, TServiceContract>\n\ntype ClientServicesResolved<Services extends ClientServices> = {\n [K in keyof Services]: {\n [P in keyof Services[K]['procedures']]: {\n contract: Services[K]['procedures'][P]\n input: InputType<t.infer.encoded<Services[K]['procedures'][P]['input']>>\n output: OutputType<\n t.infer.encoded<Services[K]['procedures'][P]['output']>\n >\n events: Services[K]['procedures'][P] extends TSubscriptionContract\n ? {\n [KE in keyof Services[K]['procedures'][P]['events']]: {\n payload: OutputType<\n t.infer.encoded<\n Services[K]['procedures'][P]['events'][KE]['payload']\n >\n >\n }\n }\n : {}\n }\n }\n}\n\ntype ClientCallers<\n Services extends ClientServicesResolved<Record<string, TServiceContract>>,\n> = {\n [K in keyof Services]: {\n [P in keyof Services[K]]: (\n ...args: Services[K][P]['input'] extends never\n ? [options?: ClientCallOptions]\n : Services[K][P]['input'] extends undefined\n ? [data?: Services[K][P]['input'], options?: ClientCallOptions]\n : [data: Services[K][P]['input'], options?: ClientCallOptions]\n ) => Promise<\n Services[K][P]['contract'] extends TSubscriptionContract\n ? {\n payload: Services[K][P]['output'] extends never\n ? undefined\n : Services[K][P]['output']\n subscription: Subscription<{\n [KE in keyof Services[K][P]['events']]: [\n Services[K][P]['events'][KE],\n ]\n }>\n }\n : Services[K][P]['output'] extends never\n ? void\n : Services[K][P]['output']\n >\n }\n}\n\nexport class StaticClient<Services extends ClientServices> extends Client {\n $types!: ClientServicesResolved<Services>\n #callers: ClientCallers<this['$types']>\n\n constructor(\n services: { [K in keyof Services]: Services[K]['name'] },\n options: ClientOptions,\n ) {\n super(options, Object.values(services))\n\n const callers = {} as any\n\n for (const [serviceKey, serviceName] of Object.entries(services)) {\n callers[serviceKey] = new Proxy(Object(), {\n get: (target, prop, receiver) => {\n // `await client.call.serviceName` or `await client.call.serviceName.procedureName`\n // without explicitly calling a function implicitly calls .then() on target\n // FIXME: this basically makes \"then\" a reserved word\n if (prop === 'then') return target\n return this.createCaller(serviceName, prop as string)\n },\n })\n }\n\n this.#callers = callers\n }\n\n get call() {\n return this.#callers\n }\n}\n"],"names":["Client","StaticClient","$types","constructor","services","options","Object","values","callers","serviceKey","serviceName","entries","Proxy","get","target","prop","receiver","createCaller","call"],"mappings":"AAEA,SAASA,MAAM,QAA4B,cAAa;AA0DxD,OAAO,MAAMC,qBAAsDD;IACjEE,OAAyC;IACzC,CAAA,OAAQ,CAA+B;IAEvCC,YACEC,QAAwD,EACxDC,OAAsB,CACtB;QACA,KAAK,CAACA,SAASC,OAAOC,MAAM,CAACH;QAE7B,MAAMI,UAAU,CAAC;QAEjB,KAAK,MAAM,CAACC,YAAYC,YAAY,IAAIJ,OAAOK,OAAO,CAACP,UAAW;YAChEI,OAAO,CAACC,WAAW,GAAG,IAAIG,MAAMN,UAAU;gBACxCO,KAAK,CAACC,QAAQC,MAAMC;oBAIlB,IAAID,SAAS,QAAQ,OAAOD;oBAC5B,OAAO,IAAI,CAACG,YAAY,CAACP,aAAaK;gBACxC;YACF;QACF;QAEA,IAAI,CAAC,CAAA,OAAQ,GAAGP;IAClB;IAEA,IAAIU,OAAO;QACT,OAAO,IAAI,CAAC,CAAA,OAAQ;IACtB;AACF"}
|
package/lib/client-static.ts
CHANGED
|
@@ -73,6 +73,10 @@ export class StaticClient<Services extends ClientServices> extends Client {
|
|
|
73
73
|
for (const [serviceKey, serviceName] of Object.entries(services)) {
|
|
74
74
|
callers[serviceKey] = new Proxy(Object(), {
|
|
75
75
|
get: (target, prop, receiver) => {
|
|
76
|
+
// `await client.call.serviceName` or `await client.call.serviceName.procedureName`
|
|
77
|
+
// without explicitly calling a function implicitly calls .then() on target
|
|
78
|
+
// FIXME: this basically makes "then" a reserved word
|
|
79
|
+
if (prop === 'then') return target
|
|
76
80
|
return this.createCaller(serviceName, prop as string)
|
|
77
81
|
},
|
|
78
82
|
})
|
package/package.json
CHANGED
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@nmtjs/type": "0.4.
|
|
23
|
-
"@nmtjs/
|
|
24
|
-
"@nmtjs/
|
|
22
|
+
"@nmtjs/type": "0.4.4",
|
|
23
|
+
"@nmtjs/common": "0.4.4",
|
|
24
|
+
"@nmtjs/contract": "0.4.4"
|
|
25
25
|
},
|
|
26
26
|
"files": [
|
|
27
27
|
"index.ts",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"LICENSE.md",
|
|
32
32
|
"README.md"
|
|
33
33
|
],
|
|
34
|
-
"version": "0.4.
|
|
34
|
+
"version": "0.4.4",
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "neemata-build -p neutral ./index.ts './lib/**/*.ts'",
|
|
37
37
|
"type-check": "tsc --noEmit"
|