dreaction-client-core 1.1.7 → 1.1.10
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 +6 -8
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +12 -3
- package/package.json +2 -2
- package/src/index.ts +21 -17
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import WebSocket from 'ws';
|
|
2
|
-
import type { Command, CommandMap, CommandTypeKey, CustomCommandArg } from 'dreaction-protocol';
|
|
2
|
+
import type { Command, CommandMap, CommandTypeKey, CustomCommandArg, CustomCommandRegisterPayload } from 'dreaction-protocol';
|
|
3
3
|
import { ClientOptions } from './client-options';
|
|
4
4
|
export type { ClientOptions };
|
|
5
5
|
export { assertHasLoggerPlugin } from './plugins/logger';
|
|
@@ -35,12 +35,9 @@ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
|
|
|
35
35
|
export type CustomCommandArgs<Args extends CustomCommandArg[]> = UnionToIntersection<Args extends Array<infer U> ? U extends CustomCommandArg ? {
|
|
36
36
|
[K in U as U['name']]: ArgTypeMap[U['type']];
|
|
37
37
|
} : never : never>;
|
|
38
|
-
export interface CustomCommand<Args extends CustomCommandArg[] = CustomCommandArg[]> {
|
|
38
|
+
export interface CustomCommand<Args extends CustomCommandArg[] = CustomCommandArg[]> extends Omit<CustomCommandRegisterPayload, 'id' | 'args'> {
|
|
39
39
|
id?: number;
|
|
40
|
-
|
|
41
|
-
handler: (args: CustomCommandArgs<Args>) => void;
|
|
42
|
-
title?: string;
|
|
43
|
-
description?: string;
|
|
40
|
+
handler: (args: CustomCommandArgs<Args>) => any | Promise<any>;
|
|
44
41
|
args?: Args;
|
|
45
42
|
}
|
|
46
43
|
type ExtractFeatures<T> = T extends {
|
|
@@ -114,7 +111,8 @@ export declare const corePlugins: (((dreaction: DReactionCore) => {
|
|
|
114
111
|
};
|
|
115
112
|
}))[];
|
|
116
113
|
export type InferPluginsFromCreators<Client, PC extends PluginCreator<Client>[]> = PC extends Array<infer P extends PluginCreator<Client>> ? ReturnType<P>[] : never;
|
|
117
|
-
export
|
|
114
|
+
export type CorePluginFeatures = InferFeaturesFromPlugins<DReactionCore, typeof corePlugins>;
|
|
115
|
+
export interface DReaction extends DReactionCore, CorePluginFeatures {
|
|
118
116
|
}
|
|
119
117
|
export declare class DReactionImpl implements Omit<DReactionCore, 'options' | 'plugins' | 'configure' | 'connect' | 'use' | 'close'> {
|
|
120
118
|
options: ClientOptions<DReactionCore>;
|
|
@@ -179,7 +177,7 @@ export declare class DReactionImpl implements Omit<DReactionCore, 'options' | 'p
|
|
|
179
177
|
* Adds a plugin to the system
|
|
180
178
|
*/
|
|
181
179
|
use(pluginCreator: PluginCreator<this>): this & PluginFeatures<this, typeof pluginCreator>;
|
|
182
|
-
registerCustomCommand(config: CustomCommand
|
|
180
|
+
registerCustomCommand(config: CustomCommand, optHandler?: () => void): () => void;
|
|
183
181
|
}
|
|
184
182
|
export declare function createClient<Client extends DReactionCore = DReactionCore>(options?: ClientOptions<Client>): Client;
|
|
185
183
|
//# 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,
|
|
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,EA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,EAAE,aAAa,EAAE,CAAM;IAErC;;OAEG;IACH,qBAAqB,SAAK;IAE1B;;OAEG;IACH,UAAU,qBAAiB;IAE3B;;OAEG;IACH,SAAS,CACP,OAAO,GAAE,aAAa,CAAC,IAAI,CAAM,GAChC,aAAa,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,SAAS,aAAa,CAAC,IAAI,CAAC,EAAE,GAC3D,IAAI,GAAG,wBAAwB,CAAC,IAAI,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,GACrE,IAAI;IAiCR,KAAK;IAOL;;OAEG;IACH,OAAO;IAuIP;;OAEG;IACH,IAAI,GAAI,IAAI,SAAS,cAAc,QAC3B,IAAI,YACA,UAAU,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,cACzB,OAAO,UAmCnB;IAEF;;OAEG;IACH,OAAO,CAAC,MAAM,EAAE,aAAa;IAW7B;;OAEG;IACH,WAAW,CAAC,IAAI,EAAE,GAAG,EAAE,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;CAwGd;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
|
@@ -189,9 +189,16 @@ class DReactionImpl {
|
|
|
189
189
|
}
|
|
190
190
|
return cc.command === command.payload.command;
|
|
191
191
|
})
|
|
192
|
-
.forEach((cc) =>
|
|
193
|
-
? command.payload.args
|
|
194
|
-
|
|
192
|
+
.forEach(async (cc) => {
|
|
193
|
+
const res = await cc.handler(typeof command.payload === 'object' ? command.payload.args : {});
|
|
194
|
+
if (res) {
|
|
195
|
+
// has return value
|
|
196
|
+
this.send('customCommand.response', {
|
|
197
|
+
command: cc.command,
|
|
198
|
+
payload: res,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
});
|
|
195
202
|
}
|
|
196
203
|
else if (command.type === 'setClientId') {
|
|
197
204
|
this.options.setClientId && this.options.setClientId(command.payload);
|
|
@@ -375,6 +382,7 @@ class DReactionImpl {
|
|
|
375
382
|
title,
|
|
376
383
|
description,
|
|
377
384
|
args,
|
|
385
|
+
responseViewType: config.responseViewType,
|
|
378
386
|
};
|
|
379
387
|
// Increment our id counter
|
|
380
388
|
this.customCommandLatestId += 1;
|
|
@@ -386,6 +394,7 @@ class DReactionImpl {
|
|
|
386
394
|
title: customHandler.title,
|
|
387
395
|
description: customHandler.description,
|
|
388
396
|
args: customHandler.args,
|
|
397
|
+
responseViewType: customHandler.responseViewType,
|
|
389
398
|
});
|
|
390
399
|
return () => {
|
|
391
400
|
this.customCommands = this.customCommands.filter((cc) => cc.id !== customHandler.id);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dreaction-client-core",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.10",
|
|
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.6"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"typescript": "^5.4.5"
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
CommandMap,
|
|
5
5
|
CommandTypeKey,
|
|
6
6
|
CustomCommandArg,
|
|
7
|
+
CustomCommandRegisterPayload,
|
|
7
8
|
} from 'dreaction-protocol';
|
|
8
9
|
import validate from './validate';
|
|
9
10
|
import logger from './plugins/logger';
|
|
@@ -72,13 +73,9 @@ export type CustomCommandArgs<Args extends CustomCommandArg[]> =
|
|
|
72
73
|
|
|
73
74
|
export interface CustomCommand<
|
|
74
75
|
Args extends CustomCommandArg[] = CustomCommandArg[]
|
|
75
|
-
> {
|
|
76
|
+
> extends Omit<CustomCommandRegisterPayload, 'id' | 'args'> {
|
|
76
77
|
id?: number;
|
|
77
|
-
|
|
78
|
-
handler: (args: CustomCommandArgs<Args>) => void;
|
|
79
|
-
|
|
80
|
-
title?: string;
|
|
81
|
-
description?: string;
|
|
78
|
+
handler: (args: CustomCommandArgs<Args>) => any | Promise<any>;
|
|
82
79
|
args?: Args;
|
|
83
80
|
}
|
|
84
81
|
|
|
@@ -154,13 +151,12 @@ export type InferPluginsFromCreators<
|
|
|
154
151
|
: never;
|
|
155
152
|
// #endregion
|
|
156
153
|
|
|
157
|
-
type CorePluginFeatures = InferFeaturesFromPlugins<
|
|
154
|
+
export type CorePluginFeatures = InferFeaturesFromPlugins<
|
|
158
155
|
DReactionCore,
|
|
159
156
|
typeof corePlugins
|
|
160
157
|
>;
|
|
161
158
|
|
|
162
|
-
|
|
163
|
-
export interface DReaction extends DReactionCore {}
|
|
159
|
+
export interface DReaction extends DReactionCore, CorePluginFeatures {}
|
|
164
160
|
|
|
165
161
|
// these are not for you.
|
|
166
162
|
const reservedFeatures = [
|
|
@@ -383,13 +379,19 @@ export class DReactionImpl
|
|
|
383
379
|
|
|
384
380
|
return cc.command === command.payload.command;
|
|
385
381
|
})
|
|
386
|
-
.forEach((cc) =>
|
|
387
|
-
cc.handler(
|
|
388
|
-
typeof command.payload === 'object'
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
)
|
|
392
|
-
|
|
382
|
+
.forEach(async (cc) => {
|
|
383
|
+
const res = await cc.handler(
|
|
384
|
+
typeof command.payload === 'object' ? command.payload.args : {}
|
|
385
|
+
);
|
|
386
|
+
|
|
387
|
+
if (res) {
|
|
388
|
+
// has return value
|
|
389
|
+
this.send('customCommand.response', {
|
|
390
|
+
command: cc.command,
|
|
391
|
+
payload: res,
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
});
|
|
393
395
|
} else if (command.type === 'setClientId') {
|
|
394
396
|
this.options.setClientId && this.options.setClientId(command.payload);
|
|
395
397
|
}
|
|
@@ -544,7 +546,7 @@ export class DReactionImpl
|
|
|
544
546
|
}
|
|
545
547
|
|
|
546
548
|
registerCustomCommand(
|
|
547
|
-
config: CustomCommand
|
|
549
|
+
config: CustomCommand,
|
|
548
550
|
optHandler?: () => void
|
|
549
551
|
): () => void {
|
|
550
552
|
let command: string;
|
|
@@ -621,6 +623,7 @@ export class DReactionImpl
|
|
|
621
623
|
title,
|
|
622
624
|
description,
|
|
623
625
|
args,
|
|
626
|
+
responseViewType: config.responseViewType,
|
|
624
627
|
};
|
|
625
628
|
|
|
626
629
|
// Increment our id counter
|
|
@@ -635,6 +638,7 @@ export class DReactionImpl
|
|
|
635
638
|
title: customHandler.title,
|
|
636
639
|
description: customHandler.description,
|
|
637
640
|
args: customHandler.args,
|
|
641
|
+
responseViewType: customHandler.responseViewType,
|
|
638
642
|
});
|
|
639
643
|
|
|
640
644
|
return () => {
|