dreaction-client-core 1.2.2 → 1.4.0

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.
Files changed (49) hide show
  1. package/lib/core.d.ts +30 -0
  2. package/lib/core.d.ts.map +1 -0
  3. package/lib/core.js +317 -0
  4. package/lib/index.d.ts +16 -195
  5. package/lib/index.d.ts.map +1 -1
  6. package/lib/index.js +22 -461
  7. package/lib/plugins/api-response.d.ts +15 -4
  8. package/lib/plugins/api-response.d.ts.map +1 -1
  9. package/lib/plugins/api-response.js +16 -4
  10. package/lib/plugins/benchmark.d.ts +1 -1
  11. package/lib/plugins/benchmark.d.ts.map +1 -1
  12. package/lib/plugins/clear.d.ts +1 -1
  13. package/lib/plugins/clear.d.ts.map +1 -1
  14. package/lib/plugins/image.d.ts +1 -1
  15. package/lib/plugins/image.d.ts.map +1 -1
  16. package/lib/plugins/index.d.ts +52 -0
  17. package/lib/plugins/index.d.ts.map +1 -0
  18. package/lib/plugins/index.js +36 -0
  19. package/lib/plugins/issue.d.ts +19 -0
  20. package/lib/plugins/issue.d.ts.map +1 -0
  21. package/lib/plugins/issue.js +20 -0
  22. package/lib/plugins/logger.d.ts +20 -5
  23. package/lib/plugins/logger.d.ts.map +1 -1
  24. package/lib/plugins/logger.js +8 -26
  25. package/lib/plugins/repl.d.ts +1 -1
  26. package/lib/plugins/repl.d.ts.map +1 -1
  27. package/lib/plugins/state-responses.d.ts +17 -5
  28. package/lib/plugins/state-responses.d.ts.map +1 -1
  29. package/lib/plugins/state-responses.js +10 -19
  30. package/lib/types.d.ts +73 -0
  31. package/lib/types.d.ts.map +1 -0
  32. package/lib/types.js +3 -0
  33. package/lib/utils/plugin-guard.d.ts +12 -0
  34. package/lib/utils/plugin-guard.d.ts.map +1 -0
  35. package/lib/utils/plugin-guard.js +19 -0
  36. package/package.json +2 -2
  37. package/src/core.ts +428 -0
  38. package/src/index.ts +38 -720
  39. package/src/plugins/api-response.ts +39 -6
  40. package/src/plugins/benchmark.ts +1 -1
  41. package/src/plugins/clear.ts +1 -1
  42. package/src/plugins/image.ts +1 -1
  43. package/src/plugins/index.ts +26 -0
  44. package/src/plugins/issue.ts +25 -0
  45. package/src/plugins/logger.ts +17 -39
  46. package/src/plugins/state-responses.ts +19 -29
  47. package/src/types.ts +127 -0
  48. package/src/utils/plugin-guard.ts +31 -0
  49. package/src/plugins/repl.ts +0 -63
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.corePlugins = exports.issue = exports.clear = exports.apiResponse = exports.stateResponses = exports.benchmark = exports.image = exports.logger = void 0;
7
+ const logger_1 = __importDefault(require("./logger"));
8
+ const image_1 = __importDefault(require("./image"));
9
+ const benchmark_1 = __importDefault(require("./benchmark"));
10
+ const state_responses_1 = __importDefault(require("./state-responses"));
11
+ const api_response_1 = __importDefault(require("./api-response"));
12
+ const clear_1 = __importDefault(require("./clear"));
13
+ const issue_1 = __importDefault(require("./issue"));
14
+ var logger_2 = require("./logger");
15
+ Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return __importDefault(logger_2).default; } });
16
+ var image_2 = require("./image");
17
+ Object.defineProperty(exports, "image", { enumerable: true, get: function () { return __importDefault(image_2).default; } });
18
+ var benchmark_2 = require("./benchmark");
19
+ Object.defineProperty(exports, "benchmark", { enumerable: true, get: function () { return __importDefault(benchmark_2).default; } });
20
+ var state_responses_2 = require("./state-responses");
21
+ Object.defineProperty(exports, "stateResponses", { enumerable: true, get: function () { return __importDefault(state_responses_2).default; } });
22
+ var api_response_2 = require("./api-response");
23
+ Object.defineProperty(exports, "apiResponse", { enumerable: true, get: function () { return __importDefault(api_response_2).default; } });
24
+ var clear_2 = require("./clear");
25
+ Object.defineProperty(exports, "clear", { enumerable: true, get: function () { return __importDefault(clear_2).default; } });
26
+ var issue_2 = require("./issue");
27
+ Object.defineProperty(exports, "issue", { enumerable: true, get: function () { return __importDefault(issue_2).default; } });
28
+ exports.corePlugins = [
29
+ (0, image_1.default)(),
30
+ (0, logger_1.default)(),
31
+ (0, benchmark_1.default)(),
32
+ (0, state_responses_1.default)(),
33
+ (0, api_response_1.default)(),
34
+ (0, clear_1.default)(),
35
+ (0, issue_1.default)(),
36
+ ];
@@ -0,0 +1,19 @@
1
+ import type { DReactionCore, InferFeatures } from '../types';
2
+ /**
3
+ * Provides issue reporting feature
4
+ */
5
+ declare const issue: () => (dreaction: DReactionCore) => {
6
+ features: {
7
+ reportIssue: (id: string, name?: string, description?: string) => void;
8
+ };
9
+ };
10
+ export default issue;
11
+ export type IssuePlugin = ReturnType<typeof issue>;
12
+ export type IssueFeatures = InferFeatures<ReturnType<typeof issue>>;
13
+ export declare const hasIssuePlugin: (client: DReactionCore) => client is DReactionCore & {
14
+ reportIssue: (id: string, name?: string, description?: string) => void;
15
+ };
16
+ export declare const assertHasIssuePlugin: (client: DReactionCore) => asserts client is DReactionCore & {
17
+ reportIssue: (id: string, name?: string, description?: string) => void;
18
+ };
19
+ //# sourceMappingURL=issue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"issue.d.ts","sourceRoot":"","sources":["../../src/plugins/issue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAU,aAAa,EAAE,MAAM,UAAU,CAAC;AAGrE;;GAEG;AACH,QAAA,MAAM,KAAK,oBAAqB,aAAa;;0BAGrB,MAAM,SAAS,MAAM,gBAAgB,MAAM;;CAKlE,CAAC;AAEF,eAAe,KAAK,CAAC;AAErB,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,KAAK,CAAC,CAAC;AACnD,MAAM,MAAM,aAAa,GAAG,aAAa,CAAC,UAAU,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC;AAIpE,eAAO,MAAM,cAAc;sBAdH,MAAM,SAAS,MAAM,gBAAgB,MAAM;CAcvB,CAAC;AAC7C,eAAO,MAAM,oBAAoB;sBAfT,MAAM,SAAS,MAAM,gBAAgB,MAAM;CAed,CAAC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertHasIssuePlugin = exports.hasIssuePlugin = void 0;
4
+ const plugin_guard_1 = require("../utils/plugin-guard");
5
+ /**
6
+ * Provides issue reporting feature
7
+ */
8
+ const issue = () => (dreaction) => {
9
+ return {
10
+ features: {
11
+ reportIssue: (id, name, description) => {
12
+ dreaction.send('report.issue', { id, name, description }, true);
13
+ },
14
+ },
15
+ };
16
+ };
17
+ exports.default = issue;
18
+ const issueGuard = (0, plugin_guard_1.createPluginGuard)(['reportIssue'], 'issue');
19
+ exports.hasIssuePlugin = issueGuard.has;
20
+ exports.assertHasIssuePlugin = issueGuard.assert;
@@ -1,6 +1,6 @@
1
- import type { DReactionCore, InferFeatures } from '../';
1
+ import type { DReactionCore, InferFeatures } from '../types';
2
2
  /**
3
- * Provides 4 features for logging. log & debug are the same.
3
+ * Provides logging features: log, info, debug, warn, error
4
4
  */
5
5
  declare const logger: () => (dreaction: DReactionCore) => {
6
6
  features: {
@@ -9,11 +9,26 @@ declare const logger: () => (dreaction: DReactionCore) => {
9
9
  logImportant: (...args: any[]) => void;
10
10
  debug: (message: any, important?: any) => void;
11
11
  warn: (message: any) => void;
12
- error: (message: any, stack: any) => void;
12
+ error: (message: any, stack?: any) => void;
13
13
  };
14
14
  };
15
15
  export default logger;
16
16
  export type LoggerPlugin = ReturnType<typeof logger>;
17
- export declare const hasLoggerPlugin: (dreaction: DReactionCore) => dreaction is DReactionCore & InferFeatures<DReactionCore, ReturnType<typeof logger>>;
18
- export declare const assertHasLoggerPlugin: (dreaction: DReactionCore) => asserts dreaction is DReactionCore & InferFeatures<DReactionCore, ReturnType<typeof logger>>;
17
+ export type LoggerFeatures = InferFeatures<ReturnType<typeof logger>>;
18
+ export declare const hasLoggerPlugin: (client: DReactionCore) => client is DReactionCore & {
19
+ log: (...args: any[]) => void;
20
+ info: (...args: any[]) => void;
21
+ logImportant: (...args: any[]) => void;
22
+ debug: (message: any, important?: any) => void;
23
+ warn: (message: any) => void;
24
+ error: (message: any, stack?: any) => void;
25
+ };
26
+ export declare const assertHasLoggerPlugin: (client: DReactionCore) => asserts client is DReactionCore & {
27
+ log: (...args: any[]) => void;
28
+ info: (...args: any[]) => void;
29
+ logImportant: (...args: any[]) => void;
30
+ debug: (message: any, important?: any) => void;
31
+ warn: (message: any) => void;
32
+ error: (message: any, stack?: any) => void;
33
+ };
19
34
  //# sourceMappingURL=logger.d.ts.map
@@ -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;;;;;;;;;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"}
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/plugins/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAU,aAAa,EAAE,MAAM,UAAU,CAAC;AAGrE;;GAEG;AACH,QAAA,MAAM,MAAM,oBAAqB,aAAa;;uBAGzB,GAAG,EAAE;wBAIJ,GAAG,EAAE;gCAIG,GAAG,EAAE;;;;;CAYlC,CAAC;AAEF,eAAe,MAAM,CAAC;AAEtB,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,MAAM,CAAC,CAAC;AACrD,MAAM,MAAM,cAAc,GAAG,aAAa,CAAC,UAAU,CAAC,OAAO,MAAM,CAAC,CAAC,CAAC;AAOtE,eAAO,MAAM,eAAe;mBAhCP,GAAG,EAAE;oBAIJ,GAAG,EAAE;4BAIG,GAAG,EAAE;;;;CAwBW,CAAC;AAC/C,eAAO,MAAM,qBAAqB;mBAjCb,GAAG,EAAE;oBAIJ,GAAG,EAAE;4BAIG,GAAG,EAAE;;;;CAyBoB,CAAC"}
@@ -1,22 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.assertHasLoggerPlugin = exports.hasLoggerPlugin = void 0;
4
+ const plugin_guard_1 = require("../utils/plugin-guard");
4
5
  /**
5
- * Provides 4 features for logging. log & debug are the same.
6
+ * Provides logging features: log, info, debug, warn, error
6
7
  */
7
8
  const logger = () => (dreaction) => {
8
9
  return {
9
10
  features: {
10
11
  log: (...args) => {
11
- const content = args && args.length === 1 ? args[0] : args;
12
+ const content = args.length === 1 ? args[0] : args;
12
13
  dreaction.send('log', { level: 'debug', message: content }, false);
13
14
  },
14
15
  info: (...args) => {
15
- const content = args && args.length === 1 ? args[0] : args;
16
+ const content = args.length === 1 ? args[0] : args;
16
17
  dreaction.send('log', { level: 'debug', message: content }, false);
17
18
  },
18
19
  logImportant: (...args) => {
19
- const content = args && args.length === 1 ? args[0] : args;
20
+ const content = args.length === 1 ? args[0] : args;
20
21
  dreaction.send('log', { level: 'debug', message: content }, true);
21
22
  },
22
23
  debug: (message, important = false) => dreaction.send('log', { level: 'debug', message }, !!important),
@@ -26,25 +27,6 @@ const logger = () => (dreaction) => {
26
27
  };
27
28
  };
28
29
  exports.default = logger;
29
- const hasLoggerPlugin = (dreaction) => {
30
- return (dreaction &&
31
- 'log' in dreaction &&
32
- typeof dreaction.log === 'function' &&
33
- 'info' in dreaction &&
34
- typeof dreaction.info === 'function' &&
35
- 'logImportant' in dreaction &&
36
- typeof dreaction.logImportant === 'function' &&
37
- 'debug' in dreaction &&
38
- typeof dreaction.debug === 'function' &&
39
- 'warn' in dreaction &&
40
- typeof dreaction.warn === 'function' &&
41
- 'error' in dreaction &&
42
- typeof dreaction.error === 'function');
43
- };
44
- exports.hasLoggerPlugin = hasLoggerPlugin;
45
- const assertHasLoggerPlugin = (dreaction) => {
46
- if (!(0, exports.hasLoggerPlugin)(dreaction)) {
47
- throw new Error('This DReaction client has not had the logger plugin applied to it. Make sure that you add `use(logger())` before adding this plugin.');
48
- }
49
- };
50
- exports.assertHasLoggerPlugin = assertHasLoggerPlugin;
30
+ const loggerGuard = (0, plugin_guard_1.createPluginGuard)(['log', 'info', 'logImportant', 'debug', 'warn', 'error'], 'logger');
31
+ exports.hasLoggerPlugin = loggerGuard.has;
32
+ exports.assertHasLoggerPlugin = loggerGuard.assert;
@@ -1,4 +1,4 @@
1
- import type { DReactionCore } from '../';
1
+ import type { DReactionCore } from '../types';
2
2
  export type AcceptableRepls = object | Function | string | number;
3
3
  declare const repl: () => (dreaction: DReactionCore) => {
4
4
  onCommand: ({ type, payload }: import("dreaction-protocol").Command) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"repl.d.ts","sourceRoot":"","sources":["../../src/plugins/repl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAU,MAAM,KAAK,CAAC;AAGjD,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AAElE,QAAA,MAAM,IAAI,oBAAqB,aAAa;;;qBA2CzB,MAAM,SAAS,eAAe;;CAahD,CAAC;AACF,eAAe,IAAI,CAAC"}
1
+ {"version":3,"file":"repl.d.ts","sourceRoot":"","sources":["../../src/plugins/repl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAU,MAAM,UAAU,CAAC;AAGtD,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AAElE,QAAA,MAAM,IAAI,oBAAqB,aAAa;;;qBA2CzB,MAAM,SAAS,eAAe;;CAahD,CAAC;AACF,eAAe,IAAI,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { StateActionCompletePayload, StateBackupResponsePayload, StateKeysResponsePayload, StateValuesChangePayload, StateValuesResponsePayload } from 'dreaction-protocol';
2
- import type { DReactionCore, InferFeatures } from '../';
2
+ import type { DReactionCore, InferFeatures } from '../types';
3
3
  /**
4
4
  * Provides helper functions for send state responses.
5
5
  */
@@ -9,12 +9,24 @@ declare const stateResponse: () => (dreaction: DReactionCore) => {
9
9
  stateValuesResponse: (path: StateValuesResponsePayload["path"], value: StateValuesResponsePayload["value"], valid?: StateValuesResponsePayload["value"]) => void;
10
10
  stateKeysResponse: (path: StateKeysResponsePayload["path"], keys: StateKeysResponsePayload["keys"], valid?: StateKeysResponsePayload["valid"]) => void;
11
11
  stateValuesChange: (changes: StateValuesChangePayload["changes"]) => false | void;
12
- /** sends the state backup over to the server */
13
12
  stateBackupResponse: (state: StateBackupResponsePayload["state"]) => void;
14
13
  };
15
14
  };
16
- export type StateResponsePlugin = ReturnType<typeof stateResponse>;
17
15
  export default stateResponse;
18
- export declare const hasStateResponsePlugin: (dreaction: DReactionCore) => dreaction is DReactionCore & InferFeatures<DReactionCore, ReturnType<typeof stateResponse>>;
19
- export declare const assertHasStateResponsePlugin: (dreaction: DReactionCore) => asserts dreaction is DReactionCore & InferFeatures<DReactionCore, ReturnType<typeof stateResponse>>;
16
+ export type StateResponsePlugin = ReturnType<typeof stateResponse>;
17
+ export type StateResponseFeatures = InferFeatures<ReturnType<typeof stateResponse>>;
18
+ export declare const hasStateResponsePlugin: (client: DReactionCore) => client is DReactionCore & {
19
+ stateActionComplete: (name: StateActionCompletePayload["name"], action: StateActionCompletePayload["action"], important?: any) => void;
20
+ stateValuesResponse: (path: StateValuesResponsePayload["path"], value: StateValuesResponsePayload["value"], valid?: StateValuesResponsePayload["value"]) => void;
21
+ stateKeysResponse: (path: StateKeysResponsePayload["path"], keys: StateKeysResponsePayload["keys"], valid?: StateKeysResponsePayload["valid"]) => void;
22
+ stateValuesChange: (changes: StateValuesChangePayload["changes"]) => false | void;
23
+ stateBackupResponse: (state: StateBackupResponsePayload["state"]) => void;
24
+ };
25
+ export declare const assertHasStateResponsePlugin: (client: DReactionCore) => asserts client is DReactionCore & {
26
+ stateActionComplete: (name: StateActionCompletePayload["name"], action: StateActionCompletePayload["action"], important?: any) => void;
27
+ stateValuesResponse: (path: StateValuesResponsePayload["path"], value: StateValuesResponsePayload["value"], valid?: StateValuesResponsePayload["value"]) => void;
28
+ stateKeysResponse: (path: StateKeysResponsePayload["path"], keys: StateKeysResponsePayload["keys"], valid?: StateKeysResponsePayload["valid"]) => void;
29
+ stateValuesChange: (changes: StateValuesChangePayload["changes"]) => false | void;
30
+ stateBackupResponse: (state: StateBackupResponsePayload["state"]) => void;
31
+ };
20
32
  //# sourceMappingURL=state-responses.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"state-responses.d.ts","sourceRoot":"","sources":["../../src/plugins/state-responses.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,0BAA0B,EAC1B,wBAAwB,EACxB,wBAAwB,EACxB,0BAA0B,EAC3B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,aAAa,EAAU,aAAa,EAAE,MAAM,KAAK,CAAC;AAEhE;;GAEG;AACH,QAAA,MAAM,aAAa,oBAAqB,aAAa;;oCAIvC,0BAA0B,CAAC,MAAM,CAAC,UAChC,0BAA0B,CAAC,QAAQ,CAAC;oCAMtC,0BAA0B,CAAC,MAAM,CAAC,SACjC,0BAA0B,CAAC,OAAO,CAAC,UACnC,0BAA0B,CAAC,OAAO,CAAC;kCAIpC,wBAAwB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AEF,eAAe,aAAa,CAAC;AAE7B,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AACnE,MAAM,MAAM,qBAAqB,GAAG,aAAa,CAC/C,UAAU,CAAC,OAAO,aAAa,CAAC,CACjC,CAAC;AAaF,eAAO,MAAM,sBAAsB;gCA9CrB,0BAA0B,CAAC,MAAM,CAAC,UAChC,0BAA0B,CAAC,QAAQ,CAAC;gCAMtC,0BAA0B,CAAC,MAAM,CAAC,SACjC,0BAA0B,CAAC,OAAO,CAAC,UACnC,0BAA0B,CAAC,OAAO,CAAC;8BAIpC,wBAAwB,CAAC,MAAM,CAAC,QAChC,wBAAwB,CAAC,MAAM,CAAC,UAC/B,wBAAwB,CAAC,OAAO,CAAC;iCAGb,wBAAwB,CAAC,SAAS,CAAC;iCAInC,0BAA0B,CAAC,OAAO,CAAC;CAwBV,CAAC;AAC7D,eAAO,MAAM,4BAA4B;gCA/C3B,0BAA0B,CAAC,MAAM,CAAC,UAChC,0BAA0B,CAAC,QAAQ,CAAC;gCAMtC,0BAA0B,CAAC,MAAM,CAAC,SACjC,0BAA0B,CAAC,OAAO,CAAC,UACnC,0BAA0B,CAAC,OAAO,CAAC;8BAIpC,wBAAwB,CAAC,MAAM,CAAC,QAChC,wBAAwB,CAAC,MAAM,CAAC,UAC/B,wBAAwB,CAAC,OAAO,CAAC;iCAGb,wBAAwB,CAAC,SAAS,CAAC;iCAInC,0BAA0B,CAAC,OAAO,CAAC;CAyBD,CAAC"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.assertHasStateResponsePlugin = exports.hasStateResponsePlugin = void 0;
4
+ const plugin_guard_1 = require("../utils/plugin-guard");
4
5
  /**
5
6
  * Provides helper functions for send state responses.
6
7
  */
@@ -12,27 +13,17 @@ const stateResponse = () => (dreaction) => {
12
13
  stateKeysResponse: (path, keys, valid = true) => dreaction.send('state.keys.response', { path, keys, valid }),
13
14
  stateValuesChange: (changes) => changes.length > 0 &&
14
15
  dreaction.send('state.values.change', { changes }),
15
- /** sends the state backup over to the server */
16
16
  stateBackupResponse: (state) => dreaction.send('state.backup.response', { state }),
17
17
  },
18
18
  };
19
19
  };
20
20
  exports.default = stateResponse;
21
- const hasStateResponsePlugin = (dreaction) => dreaction &&
22
- 'stateActionComplete' in dreaction &&
23
- typeof dreaction.stateActionComplete === 'function' &&
24
- 'stateValuesResponse' in dreaction &&
25
- typeof dreaction.stateValuesResponse === 'function' &&
26
- 'stateKeysResponse' in dreaction &&
27
- typeof dreaction.stateKeysResponse === 'function' &&
28
- 'stateValuesChange' in dreaction &&
29
- typeof dreaction.stateValuesChange === 'function' &&
30
- 'stateBackupResponse' in dreaction &&
31
- typeof dreaction.stateBackupResponse === 'function';
32
- exports.hasStateResponsePlugin = hasStateResponsePlugin;
33
- const assertHasStateResponsePlugin = (dreaction) => {
34
- if (!(0, exports.hasStateResponsePlugin)(dreaction)) {
35
- throw new Error('This DReaction client has not had the state responses plugin applied to it. Make sure that you add `use(stateResponse())` before adding this plugin.');
36
- }
37
- };
38
- exports.assertHasStateResponsePlugin = assertHasStateResponsePlugin;
21
+ const stateResponseGuard = (0, plugin_guard_1.createPluginGuard)([
22
+ 'stateActionComplete',
23
+ 'stateValuesResponse',
24
+ 'stateKeysResponse',
25
+ 'stateValuesChange',
26
+ 'stateBackupResponse',
27
+ ], 'state responses');
28
+ exports.hasStateResponsePlugin = stateResponseGuard.has;
29
+ exports.assertHasStateResponsePlugin = stateResponseGuard.assert;
package/lib/types.d.ts ADDED
@@ -0,0 +1,73 @@
1
+ import type { Command, CommandMap, CustomCommandArg, CustomCommandRegisterPayload } from 'dreaction-protocol';
2
+ import type { ClientOptions } from './client-options';
3
+ type AnyFunction = (...args: any[]) => any;
4
+ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
5
+ export interface DisplayConfig {
6
+ name: string;
7
+ value?: object | string | number | boolean | null | undefined;
8
+ preview?: string;
9
+ image?: string | {
10
+ uri: string;
11
+ };
12
+ important?: boolean;
13
+ }
14
+ interface ArgTypeMap {
15
+ string: string;
16
+ }
17
+ export type CustomCommandArgs<Args extends CustomCommandArg[]> = UnionToIntersection<Args extends Array<infer U> ? U extends CustomCommandArg ? {
18
+ [K in U as U['name']]: ArgTypeMap[U['type']];
19
+ } : never : never>;
20
+ export interface CustomCommand<Args extends CustomCommandArg[] = CustomCommandArg[]> extends Omit<CustomCommandRegisterPayload, 'id' | 'args'> {
21
+ id?: number;
22
+ handler: (args: CustomCommandArgs<Args>) => any | Promise<any>;
23
+ args?: Args;
24
+ }
25
+ export interface LifeCycleMethods {
26
+ onCommand?: (command: Command) => void;
27
+ onConnect?: () => void;
28
+ onDisconnect?: () => void;
29
+ }
30
+ export interface Plugin<Client> extends LifeCycleMethods {
31
+ features?: {
32
+ [key: string]: AnyFunction;
33
+ };
34
+ onPlugin?: (client: Client) => void;
35
+ }
36
+ export type PluginCreator<Client> = (client: Client) => Plugin<Client>;
37
+ /**
38
+ * Extract features from a single PluginCreator
39
+ */
40
+ type ExtractPluginFeatures<P> = P extends PluginCreator<any> ? ReturnType<P> extends {
41
+ features: infer F;
42
+ } ? F : {} : {};
43
+ /**
44
+ * Extract features type from a plugin or array of plugins.
45
+ * Supports:
46
+ * - Single PluginCreator: InferFeatures<typeof myPlugin>
47
+ * - Array of PluginCreators: InferFeatures<typeof plugins>
48
+ * - Legacy format: InferFeatures<Client, PluginCreator> (second param is the plugin)
49
+ */
50
+ export type InferFeatures<ClientOrPlugin, LegacyPluginCreator = never> = [
51
+ LegacyPluginCreator
52
+ ] extends [never] ? ClientOrPlugin extends PluginCreator<any>[] ? UnionToIntersection<ExtractPluginFeatures<ClientOrPlugin[number]>> : ExtractPluginFeatures<ClientOrPlugin> : ExtractPluginFeatures<LegacyPluginCreator>;
53
+ /**
54
+ * @deprecated Use InferFeatures instead
55
+ */
56
+ export type InferFeaturesFromPlugins<_Client, Plugins extends PluginCreator<any>[]> = UnionToIntersection<ExtractPluginFeatures<Plugins[number]>>;
57
+ export interface DReactionCore {
58
+ connected: boolean;
59
+ isReady: boolean;
60
+ options: ClientOptions<this>;
61
+ plugins: Plugin<this>[];
62
+ startTimer: () => () => number;
63
+ close: () => this;
64
+ send: <Type extends keyof CommandMap>(type: Type, payload?: CommandMap[Type], important?: boolean) => void;
65
+ display: (config: DisplayConfig) => void;
66
+ registerCustomCommand: <Args extends CustomCommandArg[] = Exclude<CustomCommand['args'], undefined>>(config: CustomCommand<Args>) => () => void | ((config: string, optHandler?: () => void) => () => void);
67
+ configure: (options?: ClientOptions<this>) => ClientOptions<this>['plugins'] extends PluginCreator<this>[] ? this & InferFeatures<ClientOptions<this>['plugins']> : this;
68
+ use: <P extends PluginCreator<this>>(pluginCreator: P) => this & InferFeatures<P>;
69
+ connect: () => this;
70
+ waitForConnect: () => Promise<void>;
71
+ }
72
+ export {};
73
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,UAAU,EACV,gBAAgB,EAChB,4BAA4B,EAC7B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGtD,KAAK,WAAW,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;AAE3C,KAAK,mBAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,GAAG,KAAK,CAAC,SAAS,CAC7E,CAAC,EAAE,MAAM,CAAC,KACP,IAAI,GACL,CAAC,GACD,KAAK,CAAC;AAEV,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAA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IAAI,CAAC,EAC1B,SAAS,CAAC,EAAE,OAAO,KAChB,IAAI,CAAC;IACV,OAAO,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,IAAI,CAAC;IACzC,qBAAqB,EAAE,CACrB,IAAI,SAAS,gBAAgB,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC,EAE3E,MAAM,EAAE,aAAa,CAAC,IAAI,CAAC,KACxB,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CAAC,CAAC;IAC5E,SAAS,EAAE,CACT,OAAO,CAAC,EAAE,aAAa,CAAC,IAAI,CAAC,KAC1B,aAAa,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,SAAS,aAAa,CAAC,IAAI,CAAC,EAAE,GAC7D,IAAI,GAAG,aAAa,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,GACpD,IAAI,CAAC;IACT,GAAG,EAAE,CAAC,CAAC,SAAS,aAAa,CAAC,IAAI,CAAC,EACjC,aAAa,EAAE,CAAC,KACb,IAAI,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;IAC7B,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,cAAc,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACrC"}
package/lib/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // #endregion
@@ -0,0 +1,12 @@
1
+ import type { DReactionCore } from '../types';
2
+ type AnyFunction = (...args: any[]) => any;
3
+ /**
4
+ * Create type guard functions for plugin features.
5
+ * Reduces boilerplate for hasXxxPlugin and assertHasXxxPlugin patterns.
6
+ */
7
+ export declare function createPluginGuard<T extends Record<string, AnyFunction>>(featureNames: (keyof T)[], pluginName: string): {
8
+ has: (client: DReactionCore) => client is DReactionCore & T;
9
+ assert: (client: DReactionCore) => asserts client is DReactionCore & T;
10
+ };
11
+ export {};
12
+ //# sourceMappingURL=plugin-guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-guard.d.ts","sourceRoot":"","sources":["../../src/utils/plugin-guard.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C,KAAK,WAAW,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;AAE3C;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EACrE,YAAY,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,EACzB,UAAU,EAAE,MAAM;kBAEG,aAAa,KAAG,MAAM,IAAI,aAAa,GAAG,CAAC;qBAOtD,aAAa,KACpB,QAAQ,MAAM,IAAI,aAAa,GAAG,CAAC;EAUvC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createPluginGuard = createPluginGuard;
4
+ /**
5
+ * Create type guard functions for plugin features.
6
+ * Reduces boilerplate for hasXxxPlugin and assertHasXxxPlugin patterns.
7
+ */
8
+ function createPluginGuard(featureNames, pluginName) {
9
+ const has = (client) => {
10
+ return featureNames.every((name) => name in client && typeof client[name] === 'function');
11
+ };
12
+ const assert = (client) => {
13
+ if (!has(client)) {
14
+ throw new Error(`This DReaction client has not had the ${pluginName} plugin applied to it. ` +
15
+ `Make sure that you add the plugin before using these features.`);
16
+ }
17
+ };
18
+ return { has, assert };
19
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dreaction-client-core",
3
- "version": "1.2.2",
3
+ "version": "1.4.0",
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.9"
20
+ "dreaction-protocol": "1.0.11"
21
21
  },
22
22
  "devDependencies": {
23
23
  "typescript": "^5.4.5"