dreaction-client-core 1.2.0 → 1.2.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/lib/index.d.ts +17 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +51 -1
- package/lib/plugins/logger.d.ts +1 -0
- package/lib/plugins/logger.d.ts.map +1 -1
- package/lib/plugins/logger.js +6 -0
- package/package.json +2 -2
- package/src/index.ts +66 -2
- package/src/plugins/logger.ts +6 -0
package/lib/index.d.ts
CHANGED
|
@@ -63,6 +63,10 @@ export interface DReactionCore {
|
|
|
63
63
|
configure: (options?: ClientOptions<this>) => ClientOptions<this>['plugins'] extends PluginCreator<this>[] ? this & InferFeaturesFromPlugins<this, ClientOptions<this>['plugins']> : this;
|
|
64
64
|
use: <P extends PluginCreator<this>>(pluginCreator: P) => this & InferFeaturesFromPlugin<this, P>;
|
|
65
65
|
connect: () => this;
|
|
66
|
+
/**
|
|
67
|
+
* Wait for connection to be established
|
|
68
|
+
*/
|
|
69
|
+
waitForConnect: () => Promise<void>;
|
|
66
70
|
}
|
|
67
71
|
export type InferFeatures<Client = DReactionCore, PC extends PluginCreator<Client> = PluginCreator<Client>> = PC extends (client: Client) => {
|
|
68
72
|
features: infer U;
|
|
@@ -70,6 +74,7 @@ export type InferFeatures<Client = DReactionCore, PC extends PluginCreator<Clien
|
|
|
70
74
|
export declare const corePlugins: (((dreaction: DReactionCore) => {
|
|
71
75
|
features: {
|
|
72
76
|
log: (...args: any[]) => void;
|
|
77
|
+
info: (...args: any[]) => void;
|
|
73
78
|
logImportant: (...args: any[]) => void;
|
|
74
79
|
debug: (message: any, important?: any) => void;
|
|
75
80
|
warn: (message: any) => void;
|
|
@@ -149,6 +154,12 @@ export declare class DReactionImpl implements Omit<DReactionCore, 'options' | 'p
|
|
|
149
154
|
* The current ID for custom commands
|
|
150
155
|
*/
|
|
151
156
|
customCommandLatestId: number;
|
|
157
|
+
/**
|
|
158
|
+
* Promise resolvers for connection wait
|
|
159
|
+
*/
|
|
160
|
+
private connectPromiseResolve;
|
|
161
|
+
private connectPromiseReject;
|
|
162
|
+
private connectPromise;
|
|
152
163
|
/**
|
|
153
164
|
* Starts a timer and returns a function you can call to stop it and return the elapsed time.
|
|
154
165
|
*/
|
|
@@ -161,7 +172,7 @@ export declare class DReactionImpl implements Omit<DReactionCore, 'options' | 'p
|
|
|
161
172
|
/**
|
|
162
173
|
* Connect to the DReaction server.
|
|
163
174
|
*/
|
|
164
|
-
connect(): this
|
|
175
|
+
connect(): this;
|
|
165
176
|
/**
|
|
166
177
|
* Sends a command to the server
|
|
167
178
|
*/
|
|
@@ -179,6 +190,11 @@ export declare class DReactionImpl implements Omit<DReactionCore, 'options' | 'p
|
|
|
179
190
|
*/
|
|
180
191
|
use(pluginCreator: PluginCreator<this>): this & PluginFeatures<this, typeof pluginCreator>;
|
|
181
192
|
registerCustomCommand(config: CustomCommand, optHandler?: () => void): () => void;
|
|
193
|
+
/**
|
|
194
|
+
* Wait for connection to be established.
|
|
195
|
+
* Returns a promise that resolves when the connection is ready.
|
|
196
|
+
*/
|
|
197
|
+
waitForConnect(): Promise<void>;
|
|
182
198
|
}
|
|
183
199
|
export declare function createClient<Client extends DReactionCore = DReactionCore>(options?: ClientOptions<Client>): Client;
|
|
184
200
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,IAAI,CAAC;AAC3B,OAAO,KAAK,EACV,OAAO,EACP,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,4BAA4B,EAC7B,MAAM,oBAAoB,CAAC;AAW5B,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,YAAY,EAAE,aAAa,EAAE,CAAC;AAC9B,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAk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,KAAK,EAAE,KAAK;IAInC;;OAEG;IACH,GAAG,CACD,aAAa,EAAE,aAAa,CAAC,IAAI,CAAC,GACjC,IAAI,GAAG,cAAc,CAAC,IAAI,EAAE,OAAO,aAAa,CAAC;IA0DpD,qBAAqB,CACnB,MAAM,EAAE,aAAa,EACrB,UAAU,CAAC,EAAE,MAAM,IAAI,GACtB,MAAM,IAAI;IAyGb;;;OAGG;IACH,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;CAchC;AAGD,wBAAgB,YAAY,CAAC,MAAM,SAAS,aAAa,GAAG,aAAa,EACvE,OAAO,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,GAGyB,MAAM,CAC/D"}
|
package/lib/index.js
CHANGED
|
@@ -82,6 +82,12 @@ class DReactionImpl {
|
|
|
82
82
|
* The current ID for custom commands
|
|
83
83
|
*/
|
|
84
84
|
customCommandLatestId = 1;
|
|
85
|
+
/**
|
|
86
|
+
* Promise resolvers for connection wait
|
|
87
|
+
*/
|
|
88
|
+
connectPromiseResolve = null;
|
|
89
|
+
connectPromiseReject = null;
|
|
90
|
+
connectPromise = null;
|
|
85
91
|
/**
|
|
86
92
|
* Starts a timer and returns a function you can call to stop it and return the elapsed time.
|
|
87
93
|
*/
|
|
@@ -116,6 +122,12 @@ class DReactionImpl {
|
|
|
116
122
|
close() {
|
|
117
123
|
this.connected = false;
|
|
118
124
|
this.socket && this.socket.close && this.socket.close();
|
|
125
|
+
// Reject any pending connection promise
|
|
126
|
+
if (this.connectPromiseReject) {
|
|
127
|
+
this.connectPromiseReject(new Error('Connection closed'));
|
|
128
|
+
this.connectPromiseResolve = null;
|
|
129
|
+
this.connectPromiseReject = null;
|
|
130
|
+
}
|
|
119
131
|
return this;
|
|
120
132
|
}
|
|
121
133
|
/**
|
|
@@ -123,11 +135,21 @@ class DReactionImpl {
|
|
|
123
135
|
*/
|
|
124
136
|
connect() {
|
|
125
137
|
this.connected = true;
|
|
138
|
+
// Create a new promise for this connection attempt
|
|
139
|
+
this.connectPromise = new Promise((resolve, reject) => {
|
|
140
|
+
this.connectPromiseResolve = resolve;
|
|
141
|
+
this.connectPromiseReject = reject;
|
|
142
|
+
});
|
|
126
143
|
const { createSocket, secure, host, environment, port, name, client = {}, info = {}, getClientId, } = this.options;
|
|
127
144
|
const { onCommand, onConnect, onDisconnect } = this.options;
|
|
128
145
|
if (!host) {
|
|
129
146
|
console.log('host is not config, skip connect.');
|
|
130
|
-
|
|
147
|
+
if (this.connectPromiseReject) {
|
|
148
|
+
this.connectPromiseReject(new Error('Host is not configured'));
|
|
149
|
+
this.connectPromiseResolve = null;
|
|
150
|
+
this.connectPromiseReject = null;
|
|
151
|
+
}
|
|
152
|
+
return this;
|
|
131
153
|
}
|
|
132
154
|
// establish a connection to the server
|
|
133
155
|
const protocol = secure ? 'wss' : 'ws';
|
|
@@ -138,6 +160,12 @@ class DReactionImpl {
|
|
|
138
160
|
onConnect && onConnect();
|
|
139
161
|
// trigger our plugins onConnect
|
|
140
162
|
this.plugins.forEach((p) => p.onConnect && p.onConnect());
|
|
163
|
+
// Resolve the connection promise
|
|
164
|
+
if (this.connectPromiseResolve) {
|
|
165
|
+
this.connectPromiseResolve();
|
|
166
|
+
this.connectPromiseResolve = null;
|
|
167
|
+
this.connectPromiseReject = null;
|
|
168
|
+
}
|
|
141
169
|
const getClientIdPromise = getClientId || emptyPromise;
|
|
142
170
|
getClientIdPromise(name).then((clientId) => {
|
|
143
171
|
this.isReady = true;
|
|
@@ -161,6 +189,12 @@ class DReactionImpl {
|
|
|
161
189
|
// fires when we disconnect
|
|
162
190
|
const onClose = () => {
|
|
163
191
|
this.isReady = false;
|
|
192
|
+
// Reject connection promise if still pending
|
|
193
|
+
if (this.connectPromiseReject) {
|
|
194
|
+
this.connectPromiseReject(new Error('Connection failed or closed'));
|
|
195
|
+
this.connectPromiseResolve = null;
|
|
196
|
+
this.connectPromiseReject = null;
|
|
197
|
+
}
|
|
164
198
|
// trigger our disconnect handler
|
|
165
199
|
onDisconnect && onDisconnect();
|
|
166
200
|
// as well as the plugin's onDisconnect
|
|
@@ -406,6 +440,22 @@ class DReactionImpl {
|
|
|
406
440
|
});
|
|
407
441
|
};
|
|
408
442
|
}
|
|
443
|
+
/**
|
|
444
|
+
* Wait for connection to be established.
|
|
445
|
+
* Returns a promise that resolves when the connection is ready.
|
|
446
|
+
*/
|
|
447
|
+
waitForConnect() {
|
|
448
|
+
if (this.isReady) {
|
|
449
|
+
// Already connected, resolve immediately
|
|
450
|
+
return Promise.resolve();
|
|
451
|
+
}
|
|
452
|
+
if (this.connectPromise) {
|
|
453
|
+
// Return existing promise
|
|
454
|
+
return this.connectPromise;
|
|
455
|
+
}
|
|
456
|
+
// No connection attempt in progress
|
|
457
|
+
return Promise.reject(new Error('Not connected. Call connect() first.'));
|
|
458
|
+
}
|
|
409
459
|
}
|
|
410
460
|
exports.DReactionImpl = DReactionImpl;
|
|
411
461
|
// convenience factory function
|
package/lib/plugins/logger.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { DReactionCore, InferFeatures } from '../';
|
|
|
5
5
|
declare const logger: () => (dreaction: DReactionCore) => {
|
|
6
6
|
features: {
|
|
7
7
|
log: (...args: any[]) => void;
|
|
8
|
+
info: (...args: any[]) => void;
|
|
8
9
|
logImportant: (...args: any[]) => void;
|
|
9
10
|
debug: (message: any, important?: any) => void;
|
|
10
11
|
warn: (message: any) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/plugins/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAU,aAAa,EAAE,MAAM,KAAK,CAAC;AAEhE;;GAEG;AACH,QAAA,MAAM,MAAM,oBAAqB,aAAa
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/plugins/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAU,aAAa,EAAE,MAAM,KAAK,CAAC;AAEhE;;GAEG;AACH,QAAA,MAAM,MAAM,oBAAqB,aAAa;;;;;;;;;CAuB7C,CAAC;AAEF,eAAe,MAAM,CAAC;AAEtB,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,MAAM,CAAC,CAAC;AAErD,eAAO,MAAM,eAAe,cACf,aAAa,KACvB,SAAS,IAAI,aAAa,GAC3B,aAAa,CAAC,aAAa,EAAE,UAAU,CAAC,OAAO,MAAM,CAAC,CAgBvD,CAAC;AAEF,eAAO,MAAM,qBAAqB,cACrB,aAAa,KACvB,QAAQ,SAAS,IAAI,aAAa,GACnC,aAAa,CAAC,aAAa,EAAE,UAAU,CAAC,OAAO,MAAM,CAAC,CAMvD,CAAC"}
|
package/lib/plugins/logger.js
CHANGED
|
@@ -11,6 +11,10 @@ const logger = () => (dreaction) => {
|
|
|
11
11
|
const content = args && args.length === 1 ? args[0] : args;
|
|
12
12
|
dreaction.send('log', { level: 'debug', message: content }, false);
|
|
13
13
|
},
|
|
14
|
+
info: (...args) => {
|
|
15
|
+
const content = args && args.length === 1 ? args[0] : args;
|
|
16
|
+
dreaction.send('log', { level: 'debug', message: content }, false);
|
|
17
|
+
},
|
|
14
18
|
logImportant: (...args) => {
|
|
15
19
|
const content = args && args.length === 1 ? args[0] : args;
|
|
16
20
|
dreaction.send('log', { level: 'debug', message: content }, true);
|
|
@@ -26,6 +30,8 @@ const hasLoggerPlugin = (dreaction) => {
|
|
|
26
30
|
return (dreaction &&
|
|
27
31
|
'log' in dreaction &&
|
|
28
32
|
typeof dreaction.log === 'function' &&
|
|
33
|
+
'info' in dreaction &&
|
|
34
|
+
typeof dreaction.info === 'function' &&
|
|
29
35
|
'logImportant' in dreaction &&
|
|
30
36
|
typeof dreaction.logImportant === 'function' &&
|
|
31
37
|
'debug' in dreaction &&
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dreaction-client-core",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"@types/ws": "^8.5.13",
|
|
18
18
|
"eventemitter-strict": "^1.0.1",
|
|
19
19
|
"ws": "^8.18.0",
|
|
20
|
-
"dreaction-protocol": "1.0.
|
|
20
|
+
"dreaction-protocol": "1.0.9"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"typescript": "^5.4.5"
|
package/src/index.ts
CHANGED
|
@@ -127,6 +127,11 @@ export interface DReactionCore {
|
|
|
127
127
|
) => this & InferFeaturesFromPlugin<this, P>;
|
|
128
128
|
|
|
129
129
|
connect: () => this;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Wait for connection to be established
|
|
133
|
+
*/
|
|
134
|
+
waitForConnect: () => Promise<void>;
|
|
130
135
|
}
|
|
131
136
|
|
|
132
137
|
export type InferFeatures<
|
|
@@ -229,6 +234,13 @@ export class DReactionImpl
|
|
|
229
234
|
*/
|
|
230
235
|
customCommandLatestId = 1;
|
|
231
236
|
|
|
237
|
+
/**
|
|
238
|
+
* Promise resolvers for connection wait
|
|
239
|
+
*/
|
|
240
|
+
private connectPromiseResolve: (() => void) | null = null;
|
|
241
|
+
private connectPromiseReject: ((error: Error) => void) | null = null;
|
|
242
|
+
private connectPromise: Promise<void> | null = null;
|
|
243
|
+
|
|
232
244
|
/**
|
|
233
245
|
* Starts a timer and returns a function you can call to stop it and return the elapsed time.
|
|
234
246
|
*/
|
|
@@ -278,6 +290,13 @@ export class DReactionImpl
|
|
|
278
290
|
this.connected = false;
|
|
279
291
|
this.socket && this.socket.close && this.socket.close();
|
|
280
292
|
|
|
293
|
+
// Reject any pending connection promise
|
|
294
|
+
if (this.connectPromiseReject) {
|
|
295
|
+
this.connectPromiseReject(new Error('Connection closed'));
|
|
296
|
+
this.connectPromiseResolve = null;
|
|
297
|
+
this.connectPromiseReject = null;
|
|
298
|
+
}
|
|
299
|
+
|
|
281
300
|
return this;
|
|
282
301
|
}
|
|
283
302
|
|
|
@@ -286,6 +305,13 @@ export class DReactionImpl
|
|
|
286
305
|
*/
|
|
287
306
|
connect() {
|
|
288
307
|
this.connected = true;
|
|
308
|
+
|
|
309
|
+
// Create a new promise for this connection attempt
|
|
310
|
+
this.connectPromise = new Promise<void>((resolve, reject) => {
|
|
311
|
+
this.connectPromiseResolve = resolve;
|
|
312
|
+
this.connectPromiseReject = reject;
|
|
313
|
+
});
|
|
314
|
+
|
|
289
315
|
const {
|
|
290
316
|
createSocket,
|
|
291
317
|
secure,
|
|
@@ -301,7 +327,12 @@ export class DReactionImpl
|
|
|
301
327
|
|
|
302
328
|
if (!host) {
|
|
303
329
|
console.log('host is not config, skip connect.');
|
|
304
|
-
|
|
330
|
+
if (this.connectPromiseReject) {
|
|
331
|
+
this.connectPromiseReject(new Error('Host is not configured'));
|
|
332
|
+
this.connectPromiseResolve = null;
|
|
333
|
+
this.connectPromiseReject = null;
|
|
334
|
+
}
|
|
335
|
+
return this;
|
|
305
336
|
}
|
|
306
337
|
|
|
307
338
|
// establish a connection to the server
|
|
@@ -316,8 +347,14 @@ export class DReactionImpl
|
|
|
316
347
|
// trigger our plugins onConnect
|
|
317
348
|
this.plugins.forEach((p) => p.onConnect && p.onConnect());
|
|
318
349
|
|
|
319
|
-
|
|
350
|
+
// Resolve the connection promise
|
|
351
|
+
if (this.connectPromiseResolve) {
|
|
352
|
+
this.connectPromiseResolve();
|
|
353
|
+
this.connectPromiseResolve = null;
|
|
354
|
+
this.connectPromiseReject = null;
|
|
355
|
+
}
|
|
320
356
|
|
|
357
|
+
const getClientIdPromise = getClientId || emptyPromise;
|
|
321
358
|
getClientIdPromise(name!).then((clientId) => {
|
|
322
359
|
this.isReady = true;
|
|
323
360
|
// introduce ourselves
|
|
@@ -342,6 +379,14 @@ export class DReactionImpl
|
|
|
342
379
|
// fires when we disconnect
|
|
343
380
|
const onClose = () => {
|
|
344
381
|
this.isReady = false;
|
|
382
|
+
|
|
383
|
+
// Reject connection promise if still pending
|
|
384
|
+
if (this.connectPromiseReject) {
|
|
385
|
+
this.connectPromiseReject(new Error('Connection failed or closed'));
|
|
386
|
+
this.connectPromiseResolve = null;
|
|
387
|
+
this.connectPromiseReject = null;
|
|
388
|
+
}
|
|
389
|
+
|
|
345
390
|
// trigger our disconnect handler
|
|
346
391
|
onDisconnect && onDisconnect();
|
|
347
392
|
|
|
@@ -653,6 +698,25 @@ export class DReactionImpl
|
|
|
653
698
|
});
|
|
654
699
|
};
|
|
655
700
|
}
|
|
701
|
+
|
|
702
|
+
/**
|
|
703
|
+
* Wait for connection to be established.
|
|
704
|
+
* Returns a promise that resolves when the connection is ready.
|
|
705
|
+
*/
|
|
706
|
+
waitForConnect(): Promise<void> {
|
|
707
|
+
if (this.isReady) {
|
|
708
|
+
// Already connected, resolve immediately
|
|
709
|
+
return Promise.resolve();
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
if (this.connectPromise) {
|
|
713
|
+
// Return existing promise
|
|
714
|
+
return this.connectPromise;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
// No connection attempt in progress
|
|
718
|
+
return Promise.reject(new Error('Not connected. Call connect() first.'));
|
|
719
|
+
}
|
|
656
720
|
}
|
|
657
721
|
|
|
658
722
|
// convenience factory function
|
package/src/plugins/logger.ts
CHANGED
|
@@ -10,6 +10,10 @@ const logger = () => (dreaction: DReactionCore) => {
|
|
|
10
10
|
const content = args && args.length === 1 ? args[0] : args;
|
|
11
11
|
dreaction.send('log', { level: 'debug', message: content }, false);
|
|
12
12
|
},
|
|
13
|
+
info: (...args) => {
|
|
14
|
+
const content = args && args.length === 1 ? args[0] : args;
|
|
15
|
+
dreaction.send('log', { level: 'debug', message: content }, false);
|
|
16
|
+
},
|
|
13
17
|
logImportant: (...args) => {
|
|
14
18
|
const content = args && args.length === 1 ? args[0] : args;
|
|
15
19
|
dreaction.send('log', { level: 'debug', message: content }, true);
|
|
@@ -36,6 +40,8 @@ export const hasLoggerPlugin = (
|
|
|
36
40
|
dreaction &&
|
|
37
41
|
'log' in dreaction &&
|
|
38
42
|
typeof dreaction.log === 'function' &&
|
|
43
|
+
'info' in dreaction &&
|
|
44
|
+
typeof dreaction.info === 'function' &&
|
|
39
45
|
'logImportant' in dreaction &&
|
|
40
46
|
typeof dreaction.logImportant === 'function' &&
|
|
41
47
|
'debug' in dreaction &&
|