dreaction-client-core 1.1.3 → 1.1.6
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/client-options.d.ts +5 -0
- package/lib/client-options.d.ts.map +1 -1
- package/lib/index.d.ts +5 -12
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -7
- package/package.json +2 -2
- package/src/client-options.ts +6 -0
- package/src/index.ts +13 -15
package/lib/client-options.d.ts
CHANGED
|
@@ -63,6 +63,11 @@ export interface ClientOptions<Client> extends Omit<LifeCycleMethods, 'onCommand
|
|
|
63
63
|
* A way for the client libraries to identify themselves.
|
|
64
64
|
*/
|
|
65
65
|
client?: Record<string, string | number | boolean>;
|
|
66
|
+
/**
|
|
67
|
+
* A way for the connect libraries to identify themselves.
|
|
68
|
+
* different with client because its should be a user side
|
|
69
|
+
*/
|
|
70
|
+
info?: Record<string, string | number | boolean>;
|
|
66
71
|
/**
|
|
67
72
|
* Save the client id provided by the server
|
|
68
73
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-options.d.ts","sourceRoot":"","sources":["../src/client-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAC1D,OAAO,aAAa,MAAM,IAAI,CAAC;AAE/B,KAAK,gBAAgB,GAAG,SAAS,CAAC;AAElC;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,MAAM,CACnC,SAAQ,IAAI,CAAC,gBAAgB,EAAE,WAAW,CAAC;IAC3C;;;;;OAKG;IACH,YAAY,CAAC,EACT,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,gBAAgB,CAAC,GACpC,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,aAAa,CAAC,GACjC,IAAI,CAAC;IAET;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAErB;;OAEG;IACH,IAAI,CAAC,EA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from 'ws';
|
|
2
|
-
import type { Command, CommandMap, CommandTypeKey } from 'dreaction-protocol';
|
|
2
|
+
import type { Command, CommandMap, CommandTypeKey, CustomCommandArg } from 'dreaction-protocol';
|
|
3
3
|
import { ClientOptions } from './client-options';
|
|
4
4
|
export type { ClientOptions };
|
|
5
5
|
export { assertHasLoggerPlugin } from './plugins/logger';
|
|
6
6
|
export type { LoggerPlugin } from './plugins/logger';
|
|
7
7
|
export { assertHasStateResponsePlugin, hasStateResponsePlugin, } from './plugins/state-responses';
|
|
8
8
|
export type { StateResponsePlugin } from './plugins/state-responses';
|
|
9
|
-
export declare enum ArgType {
|
|
10
|
-
String = "string"
|
|
11
|
-
}
|
|
12
|
-
export interface CustomCommandArg {
|
|
13
|
-
name: string;
|
|
14
|
-
type: ArgType;
|
|
15
|
-
}
|
|
16
9
|
export interface LifeCycleMethods {
|
|
17
10
|
onCommand?: (command: Command) => void;
|
|
18
11
|
onConnect?: () => void;
|
|
@@ -36,7 +29,7 @@ interface DisplayConfig {
|
|
|
36
29
|
important?: boolean;
|
|
37
30
|
}
|
|
38
31
|
interface ArgTypeMap {
|
|
39
|
-
|
|
32
|
+
string: string;
|
|
40
33
|
}
|
|
41
34
|
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
42
35
|
export type CustomCommandArgs<Args extends CustomCommandArg[]> = UnionToIntersection<Args extends Array<infer U> ? U extends CustomCommandArg ? {
|
|
@@ -45,7 +38,7 @@ export type CustomCommandArgs<Args extends CustomCommandArg[]> = UnionToIntersec
|
|
|
45
38
|
export interface CustomCommand<Args extends CustomCommandArg[] = CustomCommandArg[]> {
|
|
46
39
|
id?: number;
|
|
47
40
|
command: string;
|
|
48
|
-
handler: (args
|
|
41
|
+
handler: (args: CustomCommandArgs<Args>) => void;
|
|
49
42
|
title?: string;
|
|
50
43
|
description?: string;
|
|
51
44
|
args?: Args;
|
|
@@ -65,7 +58,7 @@ export interface DReactionCore {
|
|
|
65
58
|
close: () => this;
|
|
66
59
|
send: <Type extends keyof CommandMap>(type: Type, payload?: CommandMap[Type], important?: boolean) => void;
|
|
67
60
|
display: (config: DisplayConfig) => void;
|
|
68
|
-
|
|
61
|
+
registerCustomCommand: <Args extends CustomCommandArg[] = Exclude<CustomCommand['args'], undefined>>(config: CustomCommand<Args>) => () => void | ((config: string, optHandler?: () => void) => () => void);
|
|
69
62
|
/**
|
|
70
63
|
* Set the configuration options.
|
|
71
64
|
*/
|
|
@@ -186,7 +179,7 @@ export declare class DReactionImpl implements Omit<DReactionCore, 'options' | 'p
|
|
|
186
179
|
* Adds a plugin to the system
|
|
187
180
|
*/
|
|
188
181
|
use(pluginCreator: PluginCreator<this>): this & PluginFeatures<this, typeof pluginCreator>;
|
|
189
|
-
|
|
182
|
+
registerCustomCommand(config: CustomCommand | string, optHandler?: () => void): () => void;
|
|
190
183
|
}
|
|
191
184
|
export declare function createClient<Client extends DReactionCore = DReactionCore>(options?: ClientOptions<Client>): Client;
|
|
192
185
|
//# 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,
|
|
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,EACjB,MAAM,oBAAoB,CAAC;AAW5B,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,YAAY,EAAE,aAAa,EAAE,CAAC;AAC9B,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,YAAY,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAC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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;IA4HP;;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,GAAG,MAAM,EAC9B,UAAU,CAAC,EAAE,MAAM,IAAI,GACtB,MAAM,IAAI;CAsGd;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
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.DReactionImpl = exports.corePlugins = exports.
|
|
6
|
+
exports.DReactionImpl = exports.corePlugins = exports.hasStateResponsePlugin = exports.assertHasStateResponsePlugin = exports.assertHasLoggerPlugin = void 0;
|
|
7
7
|
exports.createClient = createClient;
|
|
8
8
|
const validate_1 = __importDefault(require("./validate"));
|
|
9
9
|
const logger_1 = __importDefault(require("./plugins/logger"));
|
|
@@ -20,10 +20,6 @@ Object.defineProperty(exports, "assertHasLoggerPlugin", { enumerable: true, get:
|
|
|
20
20
|
var state_responses_2 = require("./plugins/state-responses");
|
|
21
21
|
Object.defineProperty(exports, "assertHasStateResponsePlugin", { enumerable: true, get: function () { return state_responses_2.assertHasStateResponsePlugin; } });
|
|
22
22
|
Object.defineProperty(exports, "hasStateResponsePlugin", { enumerable: true, get: function () { return state_responses_2.hasStateResponsePlugin; } });
|
|
23
|
-
var ArgType;
|
|
24
|
-
(function (ArgType) {
|
|
25
|
-
ArgType["String"] = "string";
|
|
26
|
-
})(ArgType || (exports.ArgType = ArgType = {}));
|
|
27
23
|
exports.corePlugins = [
|
|
28
24
|
(0, image_1.default)(),
|
|
29
25
|
(0, logger_1.default)(),
|
|
@@ -125,7 +121,7 @@ class DReactionImpl {
|
|
|
125
121
|
*/
|
|
126
122
|
connect() {
|
|
127
123
|
this.connected = true;
|
|
128
|
-
const { createSocket, secure, host, environment, port, name, client = {}, getClientId, } = this.options;
|
|
124
|
+
const { createSocket, secure, host, environment, port, name, client = {}, info = {}, getClientId, } = this.options;
|
|
129
125
|
const { onCommand, onConnect, onDisconnect } = this.options;
|
|
130
126
|
// establish a connection to the server
|
|
131
127
|
const protocol = secure ? 'wss' : 'ws';
|
|
@@ -143,6 +139,7 @@ class DReactionImpl {
|
|
|
143
139
|
this.send('client.intro', {
|
|
144
140
|
environment,
|
|
145
141
|
...client,
|
|
142
|
+
...info,
|
|
146
143
|
name,
|
|
147
144
|
clientId,
|
|
148
145
|
dreactionCoreClientVersion: 'DREACTION_CORE_CLIENT_VERSION',
|
|
@@ -317,7 +314,7 @@ class DReactionImpl {
|
|
|
317
314
|
// chain-friendly
|
|
318
315
|
return this;
|
|
319
316
|
}
|
|
320
|
-
|
|
317
|
+
registerCustomCommand(config, optHandler) {
|
|
321
318
|
let command;
|
|
322
319
|
let handler;
|
|
323
320
|
let title;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dreaction-client-core",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.6",
|
|
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.3"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"typescript": "^5.4.5"
|
package/src/client-options.ts
CHANGED
|
@@ -81,6 +81,12 @@ export interface ClientOptions<Client>
|
|
|
81
81
|
*/
|
|
82
82
|
client?: Record<string, string | number | boolean>;
|
|
83
83
|
|
|
84
|
+
/**
|
|
85
|
+
* A way for the connect libraries to identify themselves.
|
|
86
|
+
* different with client because its should be a user side
|
|
87
|
+
*/
|
|
88
|
+
info?: Record<string, string | number | boolean>;
|
|
89
|
+
|
|
84
90
|
/**
|
|
85
91
|
* Save the client id provided by the server
|
|
86
92
|
*/
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import WebSocket from 'ws';
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
Command,
|
|
4
|
+
CommandMap,
|
|
5
|
+
CommandTypeKey,
|
|
6
|
+
CustomCommandArg,
|
|
7
|
+
} from 'dreaction-protocol';
|
|
3
8
|
import validate from './validate';
|
|
4
9
|
import logger from './plugins/logger';
|
|
5
10
|
import image from './plugins/image';
|
|
@@ -21,15 +26,6 @@ export {
|
|
|
21
26
|
} from './plugins/state-responses';
|
|
22
27
|
export type { StateResponsePlugin } from './plugins/state-responses';
|
|
23
28
|
|
|
24
|
-
export enum ArgType {
|
|
25
|
-
String = 'string',
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface CustomCommandArg {
|
|
29
|
-
name: string;
|
|
30
|
-
type: ArgType;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
29
|
// #region Plugin Types
|
|
34
30
|
export interface LifeCycleMethods {
|
|
35
31
|
onCommand?: (command: Command) => void;
|
|
@@ -56,7 +52,7 @@ interface DisplayConfig {
|
|
|
56
52
|
}
|
|
57
53
|
|
|
58
54
|
interface ArgTypeMap {
|
|
59
|
-
|
|
55
|
+
string: string;
|
|
60
56
|
}
|
|
61
57
|
|
|
62
58
|
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
|
|
@@ -79,7 +75,7 @@ export interface CustomCommand<
|
|
|
79
75
|
> {
|
|
80
76
|
id?: number;
|
|
81
77
|
command: string;
|
|
82
|
-
handler: (args
|
|
78
|
+
handler: (args: CustomCommandArgs<Args>) => void;
|
|
83
79
|
|
|
84
80
|
title?: string;
|
|
85
81
|
description?: string;
|
|
@@ -114,7 +110,7 @@ export interface DReactionCore {
|
|
|
114
110
|
important?: boolean
|
|
115
111
|
) => void;
|
|
116
112
|
display: (config: DisplayConfig) => void;
|
|
117
|
-
|
|
113
|
+
registerCustomCommand: <
|
|
118
114
|
Args extends CustomCommandArg[] = Exclude<CustomCommand['args'], undefined>
|
|
119
115
|
>(
|
|
120
116
|
config: CustomCommand<Args>
|
|
@@ -301,6 +297,7 @@ export class DReactionImpl
|
|
|
301
297
|
port,
|
|
302
298
|
name,
|
|
303
299
|
client = {},
|
|
300
|
+
info = {},
|
|
304
301
|
getClientId,
|
|
305
302
|
} = this.options;
|
|
306
303
|
const { onCommand, onConnect, onDisconnect } = this.options;
|
|
@@ -325,6 +322,7 @@ export class DReactionImpl
|
|
|
325
322
|
this.send('client.intro', {
|
|
326
323
|
environment,
|
|
327
324
|
...client,
|
|
325
|
+
...info,
|
|
328
326
|
name,
|
|
329
327
|
clientId,
|
|
330
328
|
dreactionCoreClientVersion: 'DREACTION_CORE_CLIENT_VERSION',
|
|
@@ -540,12 +538,12 @@ export class DReactionImpl
|
|
|
540
538
|
return this as this & PluginFeatures<this, typeof pluginCreator>;
|
|
541
539
|
}
|
|
542
540
|
|
|
543
|
-
|
|
541
|
+
registerCustomCommand(
|
|
544
542
|
config: CustomCommand | string,
|
|
545
543
|
optHandler?: () => void
|
|
546
544
|
): () => void {
|
|
547
545
|
let command: string;
|
|
548
|
-
let handler: () => void;
|
|
546
|
+
let handler: (args: Record<string, any>) => void;
|
|
549
547
|
let title!: string;
|
|
550
548
|
let description!: string;
|
|
551
549
|
let args!: CustomCommandArg[];
|