@nmtjs/client 0.6.2 → 0.6.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.
- package/dist/common.js +1 -1
- package/dist/common.js.map +1 -1
- package/dist/runtime.js.map +1 -1
- package/lib/common.ts +2 -2
- package/lib/runtime.ts +1 -1
- package/package.json +5 -6
- package/tsconfig.json +0 -3
package/dist/common.js
CHANGED
|
@@ -2,4 +2,4 @@ import { ProtocolError } from '@nmtjs/protocol/client';
|
|
|
2
2
|
export * from "./types.js";
|
|
3
3
|
export class ClientError extends ProtocolError {
|
|
4
4
|
}
|
|
5
|
-
export {
|
|
5
|
+
export { ErrorCode, ProtocolBlob, TransportType } from '@nmtjs/protocol/common';
|
package/dist/common.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../lib/common.ts"],"sourcesContent":["import { ProtocolError } from '@nmtjs/protocol/client'\n\nexport * from './types.ts'\n\nexport class ClientError extends ProtocolError {}\n\nexport {\n
|
|
1
|
+
{"version":3,"sources":["../../lib/common.ts"],"sourcesContent":["import { ProtocolError } from '@nmtjs/protocol/client'\n\nexport * from './types.ts'\n\nexport class ClientError extends ProtocolError {}\n\nexport {\n ErrorCode,\n ProtocolBlob,\n type ProtocolBlobMetadata,\n TransportType,\n} from '@nmtjs/protocol/common'\n"],"names":["ProtocolError","ClientError","ErrorCode","ProtocolBlob","TransportType"],"mappings":"AAAA,SAASA,aAAa,QAAQ,yBAAwB;AAEtD,cAAc,aAAY;AAE1B,OAAO,MAAMC,oBAAoBD;AAAe;AAEhD,SACEE,SAAS,EACTC,YAAY,EAEZC,aAAa,QACR,yBAAwB"}
|
package/dist/runtime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../lib/runtime.ts"],"sourcesContent":["import type { TAnyAPIContract } from '@nmtjs/contract'\nimport
|
|
1
|
+
{"version":3,"sources":["../../lib/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, 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","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
|
2
|
+
import type { BaseClientFormat } from '@nmtjs/protocol/client'
|
|
2
3
|
import {
|
|
3
4
|
ProtocolBaseClient,
|
|
4
5
|
ProtocolBaseTransformer,
|
|
5
6
|
type ProtocolTransport,
|
|
6
7
|
} from '@nmtjs/protocol/client'
|
|
7
|
-
import type { BaseClientFormat } from '@nmtjs/protocol/client'
|
|
8
8
|
import { ErrorCode } from '@nmtjs/protocol/common'
|
|
9
9
|
import { type BaseTypeAny, NeverType } from '@nmtjs/type'
|
|
10
10
|
import { type Compiled, compile } from '@nmtjs/type/compiler'
|
package/package.json
CHANGED
|
@@ -19,20 +19,19 @@
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@nmtjs/
|
|
23
|
-
"@nmtjs/
|
|
24
|
-
"@nmtjs/
|
|
25
|
-
"@nmtjs/
|
|
22
|
+
"@nmtjs/contract": "0.6.4",
|
|
23
|
+
"@nmtjs/common": "0.6.4",
|
|
24
|
+
"@nmtjs/protocol": "0.6.4",
|
|
25
|
+
"@nmtjs/type": "0.6.4"
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
|
28
28
|
"index.ts",
|
|
29
29
|
"lib",
|
|
30
30
|
"dist",
|
|
31
|
-
"tsconfig.json",
|
|
32
31
|
"LICENSE.md",
|
|
33
32
|
"README.md"
|
|
34
33
|
],
|
|
35
|
-
"version": "0.6.
|
|
34
|
+
"version": "0.6.4",
|
|
36
35
|
"scripts": {
|
|
37
36
|
"build": "neemata-build -p neutral --root=./lib './**/*.ts'",
|
|
38
37
|
"type-check": "tsc --noEmit"
|
package/tsconfig.json
DELETED