@nmtjs/client 0.9.0 → 0.10.0
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 +1 -1
- package/dist/common.js.map +1 -1
- package/dist/runtime.js +1 -1
- package/dist/runtime.js.map +1 -1
- package/package.json +9 -9
- package/src/common.ts +3 -3
- package/src/runtime.ts +1 -1
package/dist/common.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EventEmitter, ProtocolError } from "@nmtjs/protocol/client";
|
|
2
2
|
export * from "./types.js";
|
|
3
|
+
export { ErrorCode, ProtocolBlob, TransportType } from "@nmtjs/protocol";
|
|
3
4
|
export class ClientError extends ProtocolError {}
|
|
4
|
-
export { ErrorCode, ProtocolBlob, TransportType } from "@nmtjs/protocol/common";
|
|
5
5
|
export class BaseClient extends EventEmitter {
|
|
6
6
|
_;
|
|
7
7
|
auth;
|
package/dist/common.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AACA,SACE,cAGA,qBAEK,wBAAwB;AAS/B,cAAc;AAEd,OAAO,MAAM,oBAAoB,cAAc,CAAE;AAEjD,
|
|
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"}
|
package/dist/runtime.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { ErrorCode } from "@nmtjs/protocol";
|
|
1
2
|
import { ProtocolBaseTransformer } from "@nmtjs/protocol/client";
|
|
2
|
-
import { ErrorCode } from "@nmtjs/protocol/common";
|
|
3
3
|
import { NeemataTypeError, NeverType } from "@nmtjs/type";
|
|
4
4
|
import { BaseClient, ClientError } from "./common.js";
|
|
5
5
|
export class RuntimeContractTransformer extends ProtocolBaseTransformer {
|
package/dist/runtime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AACA,SAAS,+BAA+B,wBAAwB;AAChE,SAAS,
|
|
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"}
|
package/package.json
CHANGED
|
@@ -16,16 +16,16 @@
|
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
|
-
"@nmtjs/type": "0.
|
|
20
|
-
"@nmtjs/
|
|
21
|
-
"@nmtjs/
|
|
22
|
-
"@nmtjs/protocol": "0.
|
|
19
|
+
"@nmtjs/type": "0.10.0",
|
|
20
|
+
"@nmtjs/contract": "0.10.0",
|
|
21
|
+
"@nmtjs/common": "0.10.0",
|
|
22
|
+
"@nmtjs/protocol": "0.10.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@nmtjs/type": "0.
|
|
26
|
-
"@nmtjs/
|
|
27
|
-
"@nmtjs/
|
|
28
|
-
"@nmtjs/protocol": "0.
|
|
25
|
+
"@nmtjs/type": "0.10.0",
|
|
26
|
+
"@nmtjs/contract": "0.10.0",
|
|
27
|
+
"@nmtjs/common": "0.10.0",
|
|
28
|
+
"@nmtjs/protocol": "0.10.0"
|
|
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.
|
|
36
|
+
"version": "0.10.0",
|
|
37
37
|
"scripts": {
|
|
38
38
|
"build": "neemata-build --root=./src './**/*.ts'",
|
|
39
39
|
"type-check": "tsc --noEmit"
|
package/src/common.ts
CHANGED
|
@@ -16,14 +16,14 @@ import type {
|
|
|
16
16
|
|
|
17
17
|
export * from './types.ts'
|
|
18
18
|
|
|
19
|
-
export class ClientError extends ProtocolError {}
|
|
20
|
-
|
|
21
19
|
export {
|
|
22
20
|
ErrorCode,
|
|
23
21
|
ProtocolBlob,
|
|
24
22
|
type ProtocolBlobMetadata,
|
|
25
23
|
TransportType,
|
|
26
|
-
} from '@nmtjs/protocol
|
|
24
|
+
} from '@nmtjs/protocol'
|
|
25
|
+
|
|
26
|
+
export class ClientError extends ProtocolError {}
|
|
27
27
|
|
|
28
28
|
export abstract class BaseClient<
|
|
29
29
|
APIContract extends TAnyAPIContract = TAnyAPIContract,
|
package/src/runtime.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { TAnyAPIContract } from '@nmtjs/contract'
|
|
2
|
+
import { ErrorCode } from '@nmtjs/protocol'
|
|
2
3
|
import { ProtocolBaseTransformer } from '@nmtjs/protocol/client'
|
|
3
|
-
import { ErrorCode } from '@nmtjs/protocol/common'
|
|
4
4
|
import { NeemataTypeError, NeverType } from '@nmtjs/type'
|
|
5
5
|
import { BaseClient, ClientError } from './common.ts'
|
|
6
6
|
|