@nmtjs/client 0.12.5 → 0.12.7

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.
@@ -0,0 +1,32 @@
1
+ import type { TAnyAPIContract } from '@nmtjs/contract';
2
+ import { EventEmitter, type ProtocolBaseClientCallOptions, type ProtocolBaseTransformer, ProtocolError, type ProtocolTransport } from '@nmtjs/protocol/client';
3
+ import type { ClientCallers, ResolveAPIContract, ResolveClientEvents, RuntimeInputContractTypeProvider, RuntimeOutputContractTypeProvider } from './types.ts';
4
+ export { ErrorCode, ProtocolBlob, type ProtocolBlobMetadata, TransportType, } from '@nmtjs/protocol';
5
+ export * from './types.ts';
6
+ export declare class ClientError extends ProtocolError {
7
+ }
8
+ export declare abstract class BaseClient<APIContract extends TAnyAPIContract = TAnyAPIContract, SafeCall extends boolean = false, API extends ResolveAPIContract<APIContract, RuntimeInputContractTypeProvider, RuntimeOutputContractTypeProvider> = ResolveAPIContract<APIContract, RuntimeInputContractTypeProvider, RuntimeOutputContractTypeProvider>> extends EventEmitter<ResolveClientEvents<API>> {
9
+ readonly transport: ProtocolTransport;
10
+ readonly options: {
11
+ timeout: number;
12
+ autoreconnect?: boolean;
13
+ safe?: SafeCall;
14
+ };
15
+ _: {
16
+ api: API;
17
+ safe: SafeCall;
18
+ };
19
+ protected abstract transformer: ProtocolBaseTransformer;
20
+ protected callers: ClientCallers<API, SafeCall>;
21
+ protected auth: any;
22
+ constructor(transport: ProtocolTransport, options: {
23
+ timeout: number;
24
+ autoreconnect?: boolean;
25
+ safe?: SafeCall;
26
+ });
27
+ protected _call(namespace: string, procedure: string, payload: any, options: ProtocolBaseClientCallOptions): Promise<any>;
28
+ get call(): ClientCallers<API, SafeCall>;
29
+ setAuth(auth: any): void;
30
+ connect(): Promise<void>;
31
+ disconnect(): Promise<void>;
32
+ }
package/dist/common.js CHANGED
@@ -1,41 +1,45 @@
1
- import { EventEmitter, ProtocolError } from "@nmtjs/protocol/client";
2
- export { ErrorCode, ProtocolBlob, TransportType } from "@nmtjs/protocol";
1
+ import { EventEmitter, ProtocolError, } from '@nmtjs/protocol/client';
2
+ export { ErrorCode, ProtocolBlob, TransportType, } from '@nmtjs/protocol';
3
3
  export * from "./types.js";
4
- export class ClientError extends ProtocolError {}
4
+ export class ClientError extends ProtocolError {
5
+ }
5
6
  export class BaseClient extends EventEmitter {
6
- _;
7
- callers;
8
- auth;
9
- constructor(transport, options) {
10
- super();
11
- this.transport = transport;
12
- this.options = options;
13
- if (this.options.autoreconnect) {
14
- this.transport.on("disconnected", () => setTimeout(this.connect.bind(this), 1e3));
15
- }
16
- }
17
- async _call(namespace, procedure, payload, options) {
18
- const call = await this.transport.call(namespace, procedure, payload, options, this.transformer);
19
- if (this.options.safe) {
20
- return await call.promise.then((result) => ({ result })).catch((error) => ({ error }));
21
- } else {
22
- return await call.promise.catch((error) => {
23
- throw error;
24
- });
25
- }
26
- }
27
- get call() {
28
- return this.callers;
29
- }
30
- setAuth(auth) {
31
- this.auth = auth;
32
- }
33
- connect() {
34
- return this.transport.connect(this.auth, this.transformer);
35
- }
36
- disconnect() {
37
- return this.transport.disconnect();
38
- }
7
+ transport;
8
+ options;
9
+ _;
10
+ callers;
11
+ auth;
12
+ constructor(transport, options) {
13
+ super();
14
+ this.transport = transport;
15
+ this.options = options;
16
+ if (this.options.autoreconnect) {
17
+ this.transport.on('disconnected', () => setTimeout(this.connect.bind(this), 1000));
18
+ }
19
+ }
20
+ async _call(namespace, procedure, payload, options) {
21
+ const call = await this.transport.call(namespace, procedure, payload, options, this.transformer);
22
+ if (this.options.safe) {
23
+ return await call.promise
24
+ .then((result) => ({ result }))
25
+ .catch((error) => ({ error }));
26
+ }
27
+ else {
28
+ return await call.promise.catch((error) => {
29
+ throw error;
30
+ });
31
+ }
32
+ }
33
+ get call() {
34
+ return this.callers;
35
+ }
36
+ setAuth(auth) {
37
+ this.auth = auth;
38
+ }
39
+ connect() {
40
+ return this.transport.connect(this.auth, this.transformer);
41
+ }
42
+ disconnect() {
43
+ return this.transport.disconnect();
44
+ }
39
45
  }
40
-
41
- //# sourceMappingURL=common.js.map
@@ -0,0 +1,16 @@
1
+ import type { TAnyAPIContract } from '@nmtjs/contract';
2
+ import { ProtocolBaseTransformer } from '@nmtjs/protocol/client';
3
+ import { BaseClient } from './common.ts';
4
+ export declare class RuntimeContractTransformer extends ProtocolBaseTransformer {
5
+ protected contract: TAnyAPIContract;
6
+ constructor(contract: TAnyAPIContract);
7
+ decodeEvent(namespace: string, event: string, payload: any): unknown;
8
+ decodeRPC(namespace: string, procedure: string, payload: any): unknown;
9
+ decodeRPCChunk(namespace: string, procedure: string, payload: any): unknown;
10
+ encodeRPC(namespace: string, procedure: string, payload: any): unknown;
11
+ }
12
+ export declare class RuntimeClient<APIContract extends TAnyAPIContract, SafeCall extends boolean> extends BaseClient<APIContract, SafeCall> {
13
+ contract: APIContract;
14
+ protected transformer: RuntimeContractTransformer;
15
+ constructor(contract: APIContract, ...args: ConstructorParameters<typeof BaseClient<APIContract, SafeCall>>);
16
+ }
package/dist/runtime.js CHANGED
@@ -1,60 +1,63 @@
1
- import { ErrorCode } from "@nmtjs/protocol";
2
- import { ProtocolBaseTransformer } from "@nmtjs/protocol/client";
3
- import { NeemataTypeError, t } from "@nmtjs/type";
1
+ import { ErrorCode } from '@nmtjs/protocol';
2
+ import { ProtocolBaseTransformer } from '@nmtjs/protocol/client';
3
+ import { NeemataTypeError, t } from '@nmtjs/type';
4
4
  import { BaseClient, ClientError } from "./common.js";
5
5
  export class RuntimeContractTransformer extends ProtocolBaseTransformer {
6
- contract;
7
- constructor(contract) {
8
- super();
9
- this.contract = contract;
10
- }
11
- decodeEvent(namespace, event, payload) {
12
- const type = this.contract.namespaces[namespace].events[event].payload;
13
- return type.decode(payload);
14
- }
15
- decodeRPC(namespace, procedure, payload) {
16
- const type = this.contract.namespaces[namespace].procedures[procedure].output;
17
- if (type instanceof t.NeverType) return undefined;
18
- return type.decode(payload);
19
- }
20
- decodeRPCChunk(namespace, procedure, payload) {
21
- const type = this.contract.namespaces[namespace].procedures[procedure].stream;
22
- if (!type || type instanceof t.NeverType) return undefined;
23
- return type.decode(payload);
24
- }
25
- encodeRPC(namespace, procedure, payload) {
26
- const type = this.contract.namespaces[namespace].procedures[procedure].input;
27
- if (type instanceof t.NeverType) return undefined;
28
- try {
29
- return type.encode(payload);
30
- } catch (error) {
31
- if (error instanceof NeemataTypeError) {
32
- throw new ClientError(ErrorCode.ValidationError, `Invalid payload for ${namespace}.${procedure}: ${error.message}`, error.issues);
33
- }
34
- throw error;
35
- }
36
- }
6
+ contract;
7
+ constructor(contract) {
8
+ super();
9
+ this.contract = contract;
10
+ }
11
+ decodeEvent(namespace, event, payload) {
12
+ const type = this.contract.namespaces[namespace].events[event].payload;
13
+ return type.decode(payload);
14
+ }
15
+ decodeRPC(namespace, procedure, payload) {
16
+ const type = this.contract.namespaces[namespace].procedures[procedure].output;
17
+ if (type instanceof t.NeverType)
18
+ return undefined;
19
+ return type.decode(payload);
20
+ }
21
+ decodeRPCChunk(namespace, procedure, payload) {
22
+ const type = this.contract.namespaces[namespace].procedures[procedure].stream;
23
+ if (!type || type instanceof t.NeverType)
24
+ return undefined;
25
+ return type.decode(payload);
26
+ }
27
+ encodeRPC(namespace, procedure, payload) {
28
+ const type = this.contract.namespaces[namespace].procedures[procedure].input;
29
+ if (type instanceof t.NeverType)
30
+ return undefined;
31
+ try {
32
+ return type.encode(payload);
33
+ }
34
+ catch (error) {
35
+ if (error instanceof NeemataTypeError) {
36
+ throw new ClientError(ErrorCode.ValidationError, `Invalid payload for ${namespace}.${procedure}: ${error.message}`, error.issues);
37
+ }
38
+ throw error;
39
+ }
40
+ }
37
41
  }
38
42
  export class RuntimeClient extends BaseClient {
39
- transformer;
40
- constructor(contract, ...args) {
41
- super(...args);
42
- this.contract = contract;
43
- this.transformer = new RuntimeContractTransformer(this.contract);
44
- const callers = {};
45
- const namespaces = Object.entries(this.contract.namespaces);
46
- for (const [namespaceKey, namespace] of namespaces) {
47
- callers[namespaceKey] = {};
48
- const procedures = Object.entries(namespace.procedures);
49
- for (const [procedureKey, procedure] of procedures) {
50
- callers[namespaceKey][procedureKey] = (payload, options) => this._call(namespace.name, procedure.name, payload, {
51
- timeout: procedure.timeout || namespace.timeout || options.timeout,
52
- ...options
53
- });
54
- }
55
- }
56
- this.callers = callers;
57
- }
43
+ contract;
44
+ transformer;
45
+ constructor(contract, ...args) {
46
+ super(...args);
47
+ this.contract = contract;
48
+ this.transformer = new RuntimeContractTransformer(this.contract);
49
+ const callers = {};
50
+ const namespaces = Object.entries(this.contract.namespaces);
51
+ for (const [namespaceKey, namespace] of namespaces) {
52
+ callers[namespaceKey] = {};
53
+ const procedures = Object.entries(namespace.procedures);
54
+ for (const [procedureKey, procedure] of procedures) {
55
+ callers[namespaceKey][procedureKey] = (payload, options) => this._call(namespace.name, procedure.name, payload, {
56
+ timeout: procedure.timeout || namespace.timeout || options.timeout,
57
+ ...options,
58
+ });
59
+ }
60
+ }
61
+ this.callers = callers;
62
+ }
58
63
  }
59
-
60
- //# sourceMappingURL=runtime.js.map
@@ -0,0 +1,7 @@
1
+ import type { TAnyAPIContract } from '@nmtjs/contract';
2
+ import { ProtocolBaseTransformer } from '@nmtjs/protocol/client';
3
+ import { BaseClient } from './common.ts';
4
+ export declare class StaticClient<APIContract extends TAnyAPIContract, SafeCall extends boolean = false> extends BaseClient<APIContract, SafeCall> {
5
+ protected transformer: ProtocolBaseTransformer;
6
+ constructor(...args: ConstructorParameters<typeof BaseClient<APIContract, SafeCall>>);
7
+ }
package/dist/static.js CHANGED
@@ -1,21 +1,31 @@
1
- import { ProtocolBaseTransformer } from "@nmtjs/protocol/client";
1
+ import { ProtocolBaseTransformer } from '@nmtjs/protocol/client';
2
2
  import { BaseClient } from "./common.js";
3
3
  export class StaticClient extends BaseClient {
4
- transformer;
5
- constructor(...args) {
6
- super(...args);
7
- this.transformer = new ProtocolBaseTransformer();
8
- this.callers = new Proxy(Object(), { get: (target, namespace) => {
9
- if (namespace === "then") return target;
10
- return new Proxy(Object(), { get: (target, procedure) => {
11
- if (procedure === "then") return target;
12
- return (payload, options) => this._call(namespace, procedure, payload, {
13
- ...options,
14
- timeout: options?.timeout ?? this.options.timeout
15
- });
16
- } });
17
- } });
18
- }
4
+ transformer;
5
+ constructor(...args) {
6
+ super(...args);
7
+ this.transformer = new ProtocolBaseTransformer();
8
+ this.callers = new Proxy(Object(), {
9
+ get: (target, namespace) => {
10
+ // `await client.call.namespaceName` or `await client.call.namespaceName.procedureName`
11
+ // without explicitly calling a function implicitly calls .then() on target
12
+ // FIXME: this basically makes "then" a reserved word
13
+ if (namespace === 'then')
14
+ return target;
15
+ return new Proxy(Object(), {
16
+ get: (target, procedure) => {
17
+ // `await client.call.namespaceName` or `await client.call.namespaceName.procedureName`
18
+ // without explicitly calling a function implicitly calls .then() on target
19
+ // FIXME: this basically makes "then" a reserved word
20
+ if (procedure === 'then')
21
+ return target;
22
+ return (payload, options) => this._call(namespace, procedure, payload, {
23
+ ...options,
24
+ timeout: options?.timeout ?? this.options.timeout,
25
+ });
26
+ },
27
+ });
28
+ },
29
+ });
30
+ }
19
31
  }
20
-
21
- //# sourceMappingURL=static.js.map
@@ -0,0 +1,70 @@
1
+ import type { CallTypeProvider, OneOf, TypeProvider } from '@nmtjs/common';
2
+ import type { TAnyAPIContract, TAnyProcedureContract } from '@nmtjs/contract';
3
+ import type { InputType, OutputType, ProtocolBaseClientCallOptions, ProtocolError, ProtocolServerStreamInterface } from '@nmtjs/protocol/client';
4
+ import type { BaseTypeAny, t } from '@nmtjs/type';
5
+ export interface StaticInputContractTypeProvider extends TypeProvider {
6
+ output: this['input'] extends BaseTypeAny ? t.infer.encoded.input<this['input']> : never;
7
+ }
8
+ export interface RuntimeInputContractTypeProvider extends TypeProvider {
9
+ output: this['input'] extends BaseTypeAny ? t.infer.decoded.input<this['input']> : never;
10
+ }
11
+ export interface StaticOutputContractTypeProvider extends TypeProvider {
12
+ output: this['input'] extends BaseTypeAny ? t.infer.encoded.output<this['input']> : never;
13
+ }
14
+ export interface RuntimeOutputContractTypeProvider extends TypeProvider {
15
+ output: this['input'] extends BaseTypeAny ? t.infer.decoded.output<this['input']> : never;
16
+ }
17
+ export type AnyResolvedAPIContract = Record<string, {
18
+ procedures: Record<string, {
19
+ contract: TAnyProcedureContract;
20
+ input: any;
21
+ output: any;
22
+ }>;
23
+ events: Record<string, {
24
+ payload: any;
25
+ }>;
26
+ }>;
27
+ export type ResolveAPIContract<C extends TAnyAPIContract = TAnyAPIContract, InputTypeProvider extends TypeProvider = TypeProvider, OutputTypeProvider extends TypeProvider = TypeProvider> = {
28
+ [N in keyof C['namespaces']]: {
29
+ procedures: {
30
+ [P in keyof C['namespaces'][N]['procedures']]: {
31
+ contract: C['namespaces'][N]['procedures'][P];
32
+ input: InputType<CallTypeProvider<InputTypeProvider, C['namespaces'][N]['procedures'][P]['input']>>;
33
+ output: C['namespaces'][N]['procedures'][P]['stream'] extends undefined | t.NeverType ? OutputType<CallTypeProvider<OutputTypeProvider, C['namespaces'][N]['procedures'][P]['output']>> : {
34
+ result: OutputType<CallTypeProvider<OutputTypeProvider, C['namespaces'][N]['procedures'][P]['output']>>;
35
+ stream: ProtocolServerStreamInterface<CallTypeProvider<OutputTypeProvider, C['namespaces'][N]['procedures'][P]['stream']>>;
36
+ };
37
+ };
38
+ };
39
+ events: {
40
+ [KE in keyof C['namespaces'][N]['events']]: {
41
+ payload: OutputType<CallTypeProvider<OutputTypeProvider, C['namespaces'][N]['events'][KE]['payload']>>;
42
+ };
43
+ };
44
+ };
45
+ };
46
+ export type ResolveClientEvents<C extends AnyResolvedAPIContract = AnyResolvedAPIContract> = {
47
+ [N in keyof C]: {
48
+ [E in keyof C[N]['events'] as `${Extract<N, string>}/${Extract<E, string>}`]: [
49
+ C[N]['events'][E]['payload']
50
+ ];
51
+ };
52
+ }[keyof C];
53
+ export type ClientCallers<Resolved extends AnyResolvedAPIContract, SafeCall extends boolean> = {
54
+ [N in keyof Resolved]: {
55
+ [P in keyof Resolved[N]['procedures']]: (...args: Resolved[N]['procedures'][P]['input'] extends t.NeverType ? [data?: undefined, options?: Partial<ProtocolBaseClientCallOptions>] : undefined extends t.infer.encoded.input<Resolved[N]['procedures'][P]['contract']['input']> ? [
56
+ data?: Resolved[N]['procedures'][P]['input'],
57
+ options?: Partial<ProtocolBaseClientCallOptions>
58
+ ] : [
59
+ data: Resolved[N]['procedures'][P]['input'],
60
+ options?: Partial<ProtocolBaseClientCallOptions>
61
+ ]) => SafeCall extends true ? Promise<OneOf<[
62
+ {
63
+ output: Resolved[N]['procedures'][P]['output'];
64
+ },
65
+ {
66
+ error: ProtocolError;
67
+ }
68
+ ]>> : Promise<Resolved[N]['procedures'][P]['output']>;
69
+ };
70
+ };
package/dist/types.js CHANGED
@@ -1,3 +1 @@
1
1
  export {};
2
-
3
- //# sourceMappingURL=types.js.map
package/package.json CHANGED
@@ -3,39 +3,41 @@
3
3
  "type": "module",
4
4
  "exports": {
5
5
  ".": {
6
+ "types": "./dist/common.d.ts",
6
7
  "import": "./dist/common.js",
7
- "types": "./src/common.ts"
8
+ "module-sync": "./dist/common.js"
8
9
  },
9
10
  "./runtime": {
11
+ "types": "./dist/runtime.d.ts",
10
12
  "import": "./dist/runtime.js",
11
- "types": "./src/runtime.ts"
13
+ "module-sync": "./dist/runtime.js"
12
14
  },
13
15
  "./static": {
16
+ "types": "./dist/static.d.ts",
14
17
  "import": "./dist/static.js",
15
- "types": "./src/static.ts"
18
+ "module-sync": "./dist/static.js"
16
19
  }
17
20
  },
18
21
  "peerDependencies": {
19
- "@nmtjs/type": "0.12.5",
20
- "@nmtjs/contract": "0.12.5",
21
- "@nmtjs/common": "0.12.5",
22
- "@nmtjs/protocol": "0.12.5"
22
+ "@nmtjs/type": "0.12.7",
23
+ "@nmtjs/contract": "0.12.7",
24
+ "@nmtjs/common": "0.12.7",
25
+ "@nmtjs/protocol": "0.12.7"
23
26
  },
24
27
  "devDependencies": {
25
- "@nmtjs/contract": "0.12.5",
26
- "@nmtjs/common": "0.12.5",
27
- "@nmtjs/type": "0.12.5",
28
- "@nmtjs/protocol": "0.12.5"
28
+ "@nmtjs/contract": "0.12.7",
29
+ "@nmtjs/type": "0.12.7",
30
+ "@nmtjs/common": "0.12.7",
31
+ "@nmtjs/protocol": "0.12.7"
29
32
  },
30
33
  "files": [
31
- "src",
32
34
  "dist",
33
35
  "LICENSE.md",
34
36
  "README.md"
35
37
  ],
36
- "version": "0.12.5",
38
+ "version": "0.12.7",
37
39
  "scripts": {
38
- "build": "neemata-build --root=./src './**/*.ts'",
40
+ "build": "tsc",
39
41
  "type-check": "tsc --noEmit"
40
42
  }
41
43
  }
@@ -1 +0,0 @@
1
- {"mappings":"AACA,SACE,cAGA,qBAEK,wBAAwB;AAS/B,SACE,WACA,cAEA,qBACK;AACP,cAAc;AAEd,OAAO,MAAM,oBAAoB,cAAc,CAAE;AAEjD,OAAO,MAAe,mBAYZ,aAAuC;CAC/C;CAMA,AAAU;CACV,AAAU;CAEV,YACWA,WACAC,SAKT;AACA,SAAO;OAPE;OACA;AAQT,MAAI,KAAK,QAAQ,eAAe;AAC9B,QAAK,UAAU,GAAG,gBAAgB,MAChC,WAAW,KAAK,QAAQ,KAAK,KAAK,EAAE,IAAK,CAC1C;EACF;CACF;CAED,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: {\n timeout: number\n autoreconnect?: boolean\n safe?: SafeCall\n }","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 {\n ErrorCode,\n ProtocolBlob,\n type ProtocolBlobMetadata,\n TransportType,\n} from '@nmtjs/protocol'\nexport * from './types.ts'\n\nexport class ClientError extends ProtocolError {}\n\nexport abstract class BaseClient<\n APIContract extends TAnyAPIContract = TAnyAPIContract,\n SafeCall extends boolean = false,\n API extends ResolveAPIContract<\n APIContract,\n RuntimeInputContractTypeProvider,\n RuntimeOutputContractTypeProvider\n > = ResolveAPIContract<\n APIContract,\n RuntimeInputContractTypeProvider,\n RuntimeOutputContractTypeProvider\n >,\n> extends EventEmitter<ResolveClientEvents<API>> {\n _!: {\n api: API\n safe: SafeCall\n }\n\n protected abstract transformer: ProtocolBaseTransformer\n protected callers!: ClientCallers<API, SafeCall>\n protected auth: any\n\n constructor(\n readonly transport: ProtocolTransport,\n readonly options: {\n timeout: number\n autoreconnect?: boolean\n safe?: SafeCall\n },\n ) {\n super()\n\n if (this.options.autoreconnect) {\n this.transport.on('disconnected', () =>\n setTimeout(this.connect.bind(this), 1000),\n )\n }\n }\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"}
@@ -1 +0,0 @@
1
- {"mappings":"AACA,SAAS,iBAAiB,iBAAiB;AAC3C,SAAS,+BAA+B,wBAAwB;AAChE,SAAS,kBAAkB,SAAS,aAAa;AACjD,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,EAAE,UAAW,QAAO;AACxC,SAAO,KAAK,OAAO,QAAQ;CAC5B;CAED,eAAeF,WAAmBG,WAAmBD,SAAc;EACjE,MAAM,OACJ,KAAK,SAAS,WAAW,WAAW,WAAW,WAAW;AAC5D,OAAK,QAAQ,gBAAgB,EAAE,UAAW,QAAO;AACjD,SAAO,KAAK,OAAO,QAAQ;CAC5B;CAED,UAAUF,WAAmBG,WAAmBD,SAAc;EAC5D,MAAM,OAAO,KAAK,SAAS,WAAW,WAAW,WAAW,WAAW;AACvE,MAAI,gBAAgB,EAAE,UAAW,QAAO;AACxC,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;EACvD,MAAMC,UAAe,CAAE;EACvB,MAAM,aAAa,OAAO,QAAQ,KAAK,SAAS,WAAW;AAC3D,OAAK,MAAM,CAAC,cAAc,UAAU,IAAI,YAAY;AAClD,WAAQ,gBAAgB,CAAE;GAE1B,MAAM,aAAa,OAAO,QAAQ,UAAU,WAAW;AAEvD,QAAK,MAAM,CAAC,cAAc,UAAU,IAAI,YAAY;AAClD,YAAQ,cAAc,gBAAgB,CAAC,SAAS,YAC9C,KAAK,MAAM,UAAU,MAAM,UAAU,MAAM,SAAS;KAClD,SAAS,UAAU,WAAW,UAAU,WAAW,QAAQ;KAC3D,GAAG;IACJ,EAAC;GACL;EACF;AACD,OAAK,UAAU;CAChB;AACF","names":["contract: TAnyAPIContract","namespace: string","event: string","payload: any","procedure: string","contract: APIContract","callers: any"],"sources":["../src/runtime.ts"],"sourcesContent":["import type { TAnyAPIContract } from '@nmtjs/contract'\nimport { ErrorCode } from '@nmtjs/protocol'\nimport { ProtocolBaseTransformer } from '@nmtjs/protocol/client'\nimport { NeemataTypeError, t } 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 t.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 || type instanceof t.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 t.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 const callers: any = {}\n const namespaces = Object.entries(this.contract.namespaces)\n for (const [namespaceKey, namespace] of namespaces) {\n callers[namespaceKey] = {} as any\n\n const procedures = Object.entries(namespace.procedures)\n\n for (const [procedureKey, procedure] of procedures) {\n 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 this.callers = callers\n }\n}\n"],"version":3,"file":"runtime.js"}
@@ -1 +0,0 @@
1
- {"mappings":"AACA,SAAS,+BAA+B,wBAAwB;AAChE,SAAS,kBAAkB,aAAa;AAExC,OAAO,MAAM,qBAGH,WAAkC;CAC1C,AAAU;CAEV,YACE,GAAG,MACH;AACA,QAAM,GAAG,KAAK;AAEd,OAAK,cAAc,IAAI;AAEvB,OAAK,UAAU,IAAI,MAAM,QAAQ,EAAE,EACjC,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,MAAM,WAAqB,WAAqB,SAAS;KAC5D,GAAG;KACH,SAAS,SAAS,WAAW,KAAK,QAAQ;IAC3C,EAAC;GACL,EACF;EACF,EACF;CACF;AACF","names":[],"sources":["../src/static.ts"],"sourcesContent":["import type { TAnyAPIContract } from '@nmtjs/contract'\nimport { ProtocolBaseTransformer } from '@nmtjs/protocol/client'\nimport { BaseClient } from './common.ts'\n\nexport class StaticClient<\n APIContract extends TAnyAPIContract,\n SafeCall extends boolean = false,\n> extends BaseClient<APIContract, SafeCall> {\n protected transformer: ProtocolBaseTransformer\n\n constructor(\n ...args: ConstructorParameters<typeof BaseClient<APIContract, SafeCall>>\n ) {\n super(...args)\n\n this.transformer = new ProtocolBaseTransformer()\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(namespace as string, procedure as string, payload, {\n ...options,\n timeout: options?.timeout ?? this.options.timeout,\n })\n },\n })\n },\n })\n }\n}\n"],"version":3,"file":"static.js"}
package/dist/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"mappings":"","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type { CallTypeProvider, OneOf, TypeProvider } from '@nmtjs/common'\nimport type { TAnyAPIContract, TAnyProcedureContract } from '@nmtjs/contract'\nimport type {\n InputType,\n OutputType,\n ProtocolBaseClientCallOptions,\n ProtocolError,\n ProtocolServerStreamInterface,\n} from '@nmtjs/protocol/client'\nimport type { BaseTypeAny, 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 AnyResolvedAPIContract = Record<\n string,\n {\n procedures: Record<\n string,\n {\n contract: TAnyProcedureContract\n input: any\n output: any\n }\n >\n events: Record<\n string,\n {\n payload: any\n }\n >\n }\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']]: {\n procedures: {\n [P in keyof C['namespaces'][N]['procedures']]: {\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\n | undefined\n | t.NeverType\n ? OutputType<\n CallTypeProvider<\n OutputTypeProvider,\n C['namespaces'][N]['procedures'][P]['output']\n >\n >\n : {\n result: 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']]: {\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 AnyResolvedAPIContract = AnyResolvedAPIContract,\n> = {\n [N in keyof C]: {\n [E in keyof C[N]['events'] as `${Extract<N, string>}/${Extract<E, string>}`]: [\n C[N]['events'][E]['payload'],\n ]\n }\n}[keyof C]\n\nexport type ClientCallers<\n Resolved extends AnyResolvedAPIContract,\n SafeCall extends boolean,\n> = {\n [N in keyof Resolved]: {\n [P in keyof Resolved[N]['procedures']]: (\n ...args: Resolved[N]['procedures'][P]['input'] extends t.NeverType\n ? [data?: undefined, options?: Partial<ProtocolBaseClientCallOptions>]\n : undefined extends t.infer.encoded.input<\n Resolved[N]['procedures'][P]['contract']['input']\n >\n ? [\n data?: Resolved[N]['procedures'][P]['input'],\n options?: Partial<ProtocolBaseClientCallOptions>,\n ]\n : [\n data: Resolved[N]['procedures'][P]['input'],\n options?: Partial<ProtocolBaseClientCallOptions>,\n ]\n ) => SafeCall extends true\n ? Promise<\n OneOf<\n [\n {\n output: Resolved[N]['procedures'][P]['output']\n },\n { error: ProtocolError },\n ]\n >\n >\n : Promise<Resolved[N]['procedures'][P]['output']>\n }\n}\n"],"version":3,"file":"types.js"}
package/src/common.ts DELETED
@@ -1,105 +0,0 @@
1
- import type { TAnyAPIContract } from '@nmtjs/contract'
2
- import {
3
- EventEmitter,
4
- type ProtocolBaseClientCallOptions,
5
- type ProtocolBaseTransformer,
6
- ProtocolError,
7
- type ProtocolTransport,
8
- } from '@nmtjs/protocol/client'
9
- import type {
10
- ClientCallers,
11
- ResolveAPIContract,
12
- ResolveClientEvents,
13
- RuntimeInputContractTypeProvider,
14
- RuntimeOutputContractTypeProvider,
15
- } from './types.ts'
16
-
17
- export {
18
- ErrorCode,
19
- ProtocolBlob,
20
- type ProtocolBlobMetadata,
21
- TransportType,
22
- } from '@nmtjs/protocol'
23
- export * from './types.ts'
24
-
25
- export class ClientError extends ProtocolError {}
26
-
27
- export abstract class BaseClient<
28
- APIContract extends TAnyAPIContract = TAnyAPIContract,
29
- SafeCall extends boolean = false,
30
- API extends ResolveAPIContract<
31
- APIContract,
32
- RuntimeInputContractTypeProvider,
33
- RuntimeOutputContractTypeProvider
34
- > = ResolveAPIContract<
35
- APIContract,
36
- RuntimeInputContractTypeProvider,
37
- RuntimeOutputContractTypeProvider
38
- >,
39
- > extends EventEmitter<ResolveClientEvents<API>> {
40
- _!: {
41
- api: API
42
- safe: SafeCall
43
- }
44
-
45
- protected abstract transformer: ProtocolBaseTransformer
46
- protected callers!: ClientCallers<API, SafeCall>
47
- protected auth: any
48
-
49
- constructor(
50
- readonly transport: ProtocolTransport,
51
- readonly options: {
52
- timeout: number
53
- autoreconnect?: boolean
54
- safe?: SafeCall
55
- },
56
- ) {
57
- super()
58
-
59
- if (this.options.autoreconnect) {
60
- this.transport.on('disconnected', () =>
61
- setTimeout(this.connect.bind(this), 1000),
62
- )
63
- }
64
- }
65
-
66
- protected async _call(
67
- namespace: string,
68
- procedure: string,
69
- payload: any,
70
- options: ProtocolBaseClientCallOptions,
71
- ) {
72
- const call = await this.transport.call(
73
- namespace,
74
- procedure,
75
- payload,
76
- options,
77
- this.transformer,
78
- )
79
- if (this.options.safe) {
80
- return await call.promise
81
- .then((result) => ({ result }))
82
- .catch((error) => ({ error }))
83
- } else {
84
- return await call.promise.catch((error) => {
85
- throw error
86
- })
87
- }
88
- }
89
-
90
- get call() {
91
- return this.callers
92
- }
93
-
94
- setAuth(auth: any) {
95
- this.auth = auth
96
- }
97
-
98
- connect() {
99
- return this.transport.connect(this.auth, this.transformer)
100
- }
101
-
102
- disconnect() {
103
- return this.transport.disconnect()
104
- }
105
- }
package/src/runtime.ts DELETED
@@ -1,83 +0,0 @@
1
- import type { TAnyAPIContract } from '@nmtjs/contract'
2
- import { ErrorCode } from '@nmtjs/protocol'
3
- import { ProtocolBaseTransformer } from '@nmtjs/protocol/client'
4
- import { NeemataTypeError, t } from '@nmtjs/type'
5
- import { BaseClient, ClientError } from './common.ts'
6
-
7
- export class RuntimeContractTransformer extends ProtocolBaseTransformer {
8
- protected contract: TAnyAPIContract
9
-
10
- constructor(contract: TAnyAPIContract) {
11
- super()
12
-
13
- this.contract = contract
14
- }
15
-
16
- decodeEvent(namespace: string, event: string, payload: any) {
17
- const type = this.contract.namespaces[namespace].events[event].payload
18
- return type.decode(payload)
19
- }
20
-
21
- decodeRPC(namespace: string, procedure: string, payload: any) {
22
- const type =
23
- this.contract.namespaces[namespace].procedures[procedure].output
24
- if (type instanceof t.NeverType) return undefined
25
- return type.decode(payload)
26
- }
27
-
28
- decodeRPCChunk(namespace: string, procedure: string, payload: any) {
29
- const type =
30
- this.contract.namespaces[namespace].procedures[procedure].stream
31
- if (!type || type instanceof t.NeverType) return undefined
32
- return type.decode(payload)
33
- }
34
-
35
- encodeRPC(namespace: string, procedure: string, payload: any) {
36
- const type = this.contract.namespaces[namespace].procedures[procedure].input
37
- if (type instanceof t.NeverType) return undefined
38
- try {
39
- return type.encode(payload)
40
- } catch (error) {
41
- if (error instanceof NeemataTypeError) {
42
- throw new ClientError(
43
- ErrorCode.ValidationError,
44
- `Invalid payload for ${namespace}.${procedure}: ${error.message}`,
45
- error.issues,
46
- )
47
- }
48
- throw error
49
- }
50
- }
51
- }
52
-
53
- export class RuntimeClient<
54
- APIContract extends TAnyAPIContract,
55
- SafeCall extends boolean,
56
- > extends BaseClient<APIContract, SafeCall> {
57
- protected transformer: RuntimeContractTransformer
58
-
59
- constructor(
60
- public contract: APIContract,
61
- ...args: ConstructorParameters<typeof BaseClient<APIContract, SafeCall>>
62
- ) {
63
- super(...args)
64
-
65
- this.transformer = new RuntimeContractTransformer(this.contract)
66
- const callers: any = {}
67
- const namespaces = Object.entries(this.contract.namespaces)
68
- for (const [namespaceKey, namespace] of namespaces) {
69
- callers[namespaceKey] = {} as any
70
-
71
- const procedures = Object.entries(namespace.procedures)
72
-
73
- for (const [procedureKey, procedure] of procedures) {
74
- callers[namespaceKey][procedureKey] = (payload, options) =>
75
- this._call(namespace.name, procedure.name, payload, {
76
- timeout: procedure.timeout || namespace.timeout || options.timeout,
77
- ...options,
78
- })
79
- }
80
- }
81
- this.callers = callers
82
- }
83
- }
package/src/static.ts DELETED
@@ -1,40 +0,0 @@
1
- import type { TAnyAPIContract } from '@nmtjs/contract'
2
- import { ProtocolBaseTransformer } from '@nmtjs/protocol/client'
3
- import { BaseClient } from './common.ts'
4
-
5
- export class StaticClient<
6
- APIContract extends TAnyAPIContract,
7
- SafeCall extends boolean = false,
8
- > extends BaseClient<APIContract, SafeCall> {
9
- protected transformer: ProtocolBaseTransformer
10
-
11
- constructor(
12
- ...args: ConstructorParameters<typeof BaseClient<APIContract, SafeCall>>
13
- ) {
14
- super(...args)
15
-
16
- this.transformer = new ProtocolBaseTransformer()
17
-
18
- this.callers = new Proxy(Object(), {
19
- get: (target, namespace) => {
20
- // `await client.call.namespaceName` or `await client.call.namespaceName.procedureName`
21
- // without explicitly calling a function implicitly calls .then() on target
22
- // FIXME: this basically makes "then" a reserved word
23
- if (namespace === 'then') return target
24
- return new Proxy(Object(), {
25
- get: (target, procedure) => {
26
- // `await client.call.namespaceName` or `await client.call.namespaceName.procedureName`
27
- // without explicitly calling a function implicitly calls .then() on target
28
- // FIXME: this basically makes "then" a reserved word
29
- if (procedure === 'then') return target
30
- return (payload, options) =>
31
- this._call(namespace as string, procedure as string, payload, {
32
- ...options,
33
- timeout: options?.timeout ?? this.options.timeout,
34
- })
35
- },
36
- })
37
- },
38
- })
39
- }
40
- }
package/src/types.ts DELETED
@@ -1,151 +0,0 @@
1
- import type { CallTypeProvider, OneOf, TypeProvider } from '@nmtjs/common'
2
- import type { TAnyAPIContract, TAnyProcedureContract } from '@nmtjs/contract'
3
- import type {
4
- InputType,
5
- OutputType,
6
- ProtocolBaseClientCallOptions,
7
- ProtocolError,
8
- ProtocolServerStreamInterface,
9
- } from '@nmtjs/protocol/client'
10
- import type { BaseTypeAny, t } from '@nmtjs/type'
11
-
12
- export interface StaticInputContractTypeProvider extends TypeProvider {
13
- output: this['input'] extends BaseTypeAny
14
- ? t.infer.encoded.input<this['input']>
15
- : never
16
- }
17
-
18
- export interface RuntimeInputContractTypeProvider extends TypeProvider {
19
- output: this['input'] extends BaseTypeAny
20
- ? t.infer.decoded.input<this['input']>
21
- : never
22
- }
23
-
24
- export interface StaticOutputContractTypeProvider extends TypeProvider {
25
- output: this['input'] extends BaseTypeAny
26
- ? t.infer.encoded.output<this['input']>
27
- : never
28
- }
29
-
30
- export interface RuntimeOutputContractTypeProvider extends TypeProvider {
31
- output: this['input'] extends BaseTypeAny
32
- ? t.infer.decoded.output<this['input']>
33
- : never
34
- }
35
-
36
- export type AnyResolvedAPIContract = Record<
37
- string,
38
- {
39
- procedures: Record<
40
- string,
41
- {
42
- contract: TAnyProcedureContract
43
- input: any
44
- output: any
45
- }
46
- >
47
- events: Record<
48
- string,
49
- {
50
- payload: any
51
- }
52
- >
53
- }
54
- >
55
-
56
- export type ResolveAPIContract<
57
- C extends TAnyAPIContract = TAnyAPIContract,
58
- InputTypeProvider extends TypeProvider = TypeProvider,
59
- OutputTypeProvider extends TypeProvider = TypeProvider,
60
- > = {
61
- [N in keyof C['namespaces']]: {
62
- procedures: {
63
- [P in keyof C['namespaces'][N]['procedures']]: {
64
- contract: C['namespaces'][N]['procedures'][P]
65
- input: InputType<
66
- CallTypeProvider<
67
- InputTypeProvider,
68
- C['namespaces'][N]['procedures'][P]['input']
69
- >
70
- >
71
- output: C['namespaces'][N]['procedures'][P]['stream'] extends
72
- | undefined
73
- | t.NeverType
74
- ? OutputType<
75
- CallTypeProvider<
76
- OutputTypeProvider,
77
- C['namespaces'][N]['procedures'][P]['output']
78
- >
79
- >
80
- : {
81
- result: OutputType<
82
- CallTypeProvider<
83
- OutputTypeProvider,
84
- C['namespaces'][N]['procedures'][P]['output']
85
- >
86
- >
87
- stream: ProtocolServerStreamInterface<
88
- CallTypeProvider<
89
- OutputTypeProvider,
90
- C['namespaces'][N]['procedures'][P]['stream']
91
- >
92
- >
93
- }
94
- }
95
- }
96
- events: {
97
- [KE in keyof C['namespaces'][N]['events']]: {
98
- payload: OutputType<
99
- CallTypeProvider<
100
- OutputTypeProvider,
101
- C['namespaces'][N]['events'][KE]['payload']
102
- >
103
- >
104
- }
105
- }
106
- }
107
- }
108
-
109
- export type ResolveClientEvents<
110
- C extends AnyResolvedAPIContract = AnyResolvedAPIContract,
111
- > = {
112
- [N in keyof C]: {
113
- [E in keyof C[N]['events'] as `${Extract<N, string>}/${Extract<E, string>}`]: [
114
- C[N]['events'][E]['payload'],
115
- ]
116
- }
117
- }[keyof C]
118
-
119
- export type ClientCallers<
120
- Resolved extends AnyResolvedAPIContract,
121
- SafeCall extends boolean,
122
- > = {
123
- [N in keyof Resolved]: {
124
- [P in keyof Resolved[N]['procedures']]: (
125
- ...args: Resolved[N]['procedures'][P]['input'] extends t.NeverType
126
- ? [data?: undefined, options?: Partial<ProtocolBaseClientCallOptions>]
127
- : undefined extends t.infer.encoded.input<
128
- Resolved[N]['procedures'][P]['contract']['input']
129
- >
130
- ? [
131
- data?: Resolved[N]['procedures'][P]['input'],
132
- options?: Partial<ProtocolBaseClientCallOptions>,
133
- ]
134
- : [
135
- data: Resolved[N]['procedures'][P]['input'],
136
- options?: Partial<ProtocolBaseClientCallOptions>,
137
- ]
138
- ) => SafeCall extends true
139
- ? Promise<
140
- OneOf<
141
- [
142
- {
143
- output: Resolved[N]['procedures'][P]['output']
144
- },
145
- { error: ProtocolError },
146
- ]
147
- >
148
- >
149
- : Promise<Resolved[N]['procedures'][P]['output']>
150
- }
151
- }