@nmtjs/client 0.11.0 → 0.11.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/common.js +4 -1
- package/dist/common.js.map +1 -1
- package/package.json +9 -9
- package/src/common.ts +12 -3
package/dist/common.js
CHANGED
|
@@ -4,13 +4,16 @@ export * from "./types.js";
|
|
|
4
4
|
export class ClientError extends ProtocolError {}
|
|
5
5
|
export class BaseClient extends EventEmitter {
|
|
6
6
|
_;
|
|
7
|
+
callers;
|
|
7
8
|
auth;
|
|
8
9
|
constructor(transport, options) {
|
|
9
10
|
super();
|
|
10
11
|
this.transport = transport;
|
|
11
12
|
this.options = options;
|
|
13
|
+
if (this.options.autoreconnect) {
|
|
14
|
+
this.transport.on("disconnected", () => setTimeout(this.connect.bind(this), 1e3));
|
|
15
|
+
}
|
|
12
16
|
}
|
|
13
|
-
callers = {};
|
|
14
17
|
async _call(namespace, procedure, payload, options) {
|
|
15
18
|
const call = await this.transport.call(namespace, procedure, payload, options, this.transformer);
|
|
16
19
|
if (this.options.safe) {
|
package/dist/common.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AACA,SACE,cAGA,qBAEK,wBAAwB;AAS/B,SACE,WACA,cAEA,qBACK;AACP,cAAc;AAEd,OAAO,MAAM,oBAAoB,cAAc,CAAE;AAEjD,OAAO,MAAe,mBAGZ,aAQR;CACA;CAUA,AAAU;CAEV,YACYA,WACAC,
|
|
1
|
+
{"mappings":"AACA,SACE,cAGA,qBAEK,wBAAwB;AAS/B,SACE,WACA,cAEA,qBACK;AACP,cAAc;AAEd,OAAO,MAAM,oBAAoB,cAAc,CAAE;AAEjD,OAAO,MAAe,mBAGZ,aAQR;CACA;CAUA,AAAU;CACV,AAAU;CAEV,YACYA,WACAC,SAKV;AACA,SAAO;OAPG;OACA;AAQV,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> 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 callers!: ClientCallers<this['_']['api'], this['_']['safe']>\n protected auth: any\n\n constructor(\n protected transport: ProtocolTransport,\n protected 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"}
|
package/package.json
CHANGED
|
@@ -16,16 +16,16 @@
|
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
|
-
"@nmtjs/type": "0.11.
|
|
20
|
-
"@nmtjs/contract": "0.11.
|
|
21
|
-
"@nmtjs/
|
|
22
|
-
"@nmtjs/
|
|
19
|
+
"@nmtjs/type": "0.11.2",
|
|
20
|
+
"@nmtjs/contract": "0.11.2",
|
|
21
|
+
"@nmtjs/protocol": "0.11.2",
|
|
22
|
+
"@nmtjs/common": "0.11.2"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@nmtjs/type": "0.11.
|
|
26
|
-
"@nmtjs/
|
|
27
|
-
"@nmtjs/
|
|
28
|
-
"@nmtjs/protocol": "0.11.
|
|
25
|
+
"@nmtjs/type": "0.11.2",
|
|
26
|
+
"@nmtjs/common": "0.11.2",
|
|
27
|
+
"@nmtjs/contract": "0.11.2",
|
|
28
|
+
"@nmtjs/protocol": "0.11.2"
|
|
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.11.
|
|
36
|
+
"version": "0.11.2",
|
|
37
37
|
"scripts": {
|
|
38
38
|
"build": "neemata-build --root=./src './**/*.ts'",
|
|
39
39
|
"type-check": "tsc --noEmit"
|
package/src/common.ts
CHANGED
|
@@ -46,16 +46,25 @@ export abstract class BaseClient<
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
protected abstract transformer: ProtocolBaseTransformer
|
|
49
|
+
protected callers!: ClientCallers<this['_']['api'], this['_']['safe']>
|
|
49
50
|
protected auth: any
|
|
50
51
|
|
|
51
52
|
constructor(
|
|
52
53
|
protected transport: ProtocolTransport,
|
|
53
|
-
protected options: {
|
|
54
|
+
protected options: {
|
|
55
|
+
timeout: number
|
|
56
|
+
autoreconnect?: boolean
|
|
57
|
+
safe?: SafeCall
|
|
58
|
+
},
|
|
54
59
|
) {
|
|
55
60
|
super()
|
|
56
|
-
}
|
|
57
61
|
|
|
58
|
-
|
|
62
|
+
if (this.options.autoreconnect) {
|
|
63
|
+
this.transport.on('disconnected', () =>
|
|
64
|
+
setTimeout(this.connect.bind(this), 1000),
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
59
68
|
|
|
60
69
|
protected async _call(
|
|
61
70
|
namespace: string,
|