dreaction-client-core 1.0.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 (52) hide show
  1. package/lib/client-options.d.ts +77 -0
  2. package/lib/client-options.d.ts.map +1 -0
  3. package/lib/client-options.js +2 -0
  4. package/lib/index.d.ts +190 -0
  5. package/lib/index.d.ts.map +1 -0
  6. package/lib/index.js +401 -0
  7. package/lib/plugins/api-response.d.ts +13 -0
  8. package/lib/plugins/api-response.d.ts.map +1 -0
  9. package/lib/plugins/api-response.js +23 -0
  10. package/lib/plugins/benchmark.d.ts +15 -0
  11. package/lib/plugins/benchmark.d.ts.map +1 -0
  12. package/lib/plugins/benchmark.js +31 -0
  13. package/lib/plugins/clear.d.ts +11 -0
  14. package/lib/plugins/clear.d.ts.map +1 -0
  15. package/lib/plugins/clear.js +13 -0
  16. package/lib/plugins/image.d.ts +19 -0
  17. package/lib/plugins/image.d.ts.map +1 -0
  18. package/lib/plugins/image.js +24 -0
  19. package/lib/plugins/logger.d.ts +18 -0
  20. package/lib/plugins/logger.d.ts.map +1 -0
  21. package/lib/plugins/logger.js +44 -0
  22. package/lib/plugins/repl.d.ts +10 -0
  23. package/lib/plugins/repl.d.ts.map +1 -0
  24. package/lib/plugins/repl.js +55 -0
  25. package/lib/plugins/state-responses.d.ts +20 -0
  26. package/lib/plugins/state-responses.d.ts.map +1 -0
  27. package/lib/plugins/state-responses.js +38 -0
  28. package/lib/reactotron-core-client.d.ts +191 -0
  29. package/lib/reactotron-core-client.d.ts.map +1 -0
  30. package/lib/reactotron-core-client.js +400 -0
  31. package/lib/serialize.d.ts +20 -0
  32. package/lib/serialize.d.ts.map +1 -0
  33. package/lib/serialize.js +112 -0
  34. package/lib/stopwatch.d.ts +6 -0
  35. package/lib/stopwatch.d.ts.map +1 -0
  36. package/lib/stopwatch.js +45 -0
  37. package/lib/validate.d.ts +9 -0
  38. package/lib/validate.d.ts.map +1 -0
  39. package/lib/validate.js +26 -0
  40. package/package.json +29 -0
  41. package/src/client-options.ts +95 -0
  42. package/src/index.ts +654 -0
  43. package/src/plugins/api-response.ts +32 -0
  44. package/src/plugins/benchmark.ts +35 -0
  45. package/src/plugins/clear.ts +14 -0
  46. package/src/plugins/image.ts +34 -0
  47. package/src/plugins/logger.ts +59 -0
  48. package/src/plugins/repl.ts +63 -0
  49. package/src/plugins/state-responses.ts +75 -0
  50. package/src/serialize.ts +125 -0
  51. package/src/stopwatch.ts +50 -0
  52. package/src/validate.ts +38 -0
@@ -0,0 +1,13 @@
1
+ import type { DReactionCore } from '../';
2
+ /**
3
+ * Sends API request/response information.
4
+ */
5
+ declare const apiResponse: () => (reactotron: DReactionCore) => {
6
+ features: {
7
+ apiResponse: (request: {
8
+ status: number;
9
+ }, response: any, duration: number) => void;
10
+ };
11
+ };
12
+ export default apiResponse;
13
+ //# sourceMappingURL=api-response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-response.d.ts","sourceRoot":"","sources":["../../src/plugins/api-response.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAU,MAAM,KAAK,CAAC;AAEjD;;GAEG;AACH,QAAA,MAAM,WAAW,qBAAsB,aAAa;;+BAInC;YAAE,MAAM,EAAE,MAAM,CAAA;SAAE,YACjB,GAAG,YACH,MAAM;;CAkBvB,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Sends API request/response information.
5
+ */
6
+ const apiResponse = () => (reactotron) => {
7
+ return {
8
+ features: {
9
+ apiResponse: (request, response, duration) => {
10
+ const ok = response &&
11
+ response.status &&
12
+ typeof response.status === 'number' &&
13
+ response.status >= 200 &&
14
+ response.status <= 299;
15
+ const important = !ok;
16
+ reactotron.send('api.response',
17
+ // @ts-ignore
18
+ { request, response, duration }, important);
19
+ },
20
+ },
21
+ };
22
+ };
23
+ exports.default = apiResponse;
@@ -0,0 +1,15 @@
1
+ import type { DReactionCore } from '../';
2
+ /**
3
+ * Runs small high-unscientific benchmarks for you.
4
+ */
5
+ declare const benchmark: () => (reactotron: DReactionCore) => {
6
+ features: {
7
+ benchmark: (title: string) => {
8
+ step: (stepTitle: string) => void;
9
+ stop: (stopTitle: string) => void;
10
+ last: (stopTitle: string) => void;
11
+ };
12
+ };
13
+ };
14
+ export default benchmark;
15
+ //# sourceMappingURL=benchmark.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"benchmark.d.ts","sourceRoot":"","sources":["../../src/plugins/benchmark.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAU,MAAM,KAAK,CAAC;AAEjD;;GAEG;AACH,QAAA,MAAM,SAAS,qBAAsB,aAAa;;2BAGtB,MAAM;8BAGL,MAAM;8BAWN,MAAM;8BAAN,MAAM;;;CAUlC,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Runs small high-unscientific benchmarks for you.
5
+ */
6
+ const benchmark = () => (reactotron) => {
7
+ const { startTimer } = reactotron;
8
+ const benchmark = (title) => {
9
+ const steps = [];
10
+ const elapsed = startTimer();
11
+ const step = (stepTitle) => {
12
+ const previousTime = steps.length === 0 ? 0 : steps[steps.length - 1].time;
13
+ const nextTime = elapsed();
14
+ steps.push({
15
+ title: stepTitle,
16
+ time: nextTime,
17
+ delta: nextTime - previousTime,
18
+ });
19
+ };
20
+ steps.push({ title, time: 0, delta: 0 });
21
+ const stop = (stopTitle) => {
22
+ step(stopTitle);
23
+ reactotron.send('benchmark.report', { title, steps });
24
+ };
25
+ return { step, stop, last: stop };
26
+ };
27
+ return {
28
+ features: { benchmark },
29
+ };
30
+ };
31
+ exports.default = benchmark;
@@ -0,0 +1,11 @@
1
+ import type { DReactionCore } from '../';
2
+ /**
3
+ * Clears the reactotron server.
4
+ */
5
+ declare const clear: () => (reactotron: DReactionCore) => {
6
+ features: {
7
+ clear: () => void;
8
+ };
9
+ };
10
+ export default clear;
11
+ //# sourceMappingURL=clear.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clear.d.ts","sourceRoot":"","sources":["../../src/plugins/clear.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAU,MAAM,KAAK,CAAC;AAEjD;;GAEG;AACH,QAAA,MAAM,KAAK,qBAAsB,aAAa;;;;CAM7C,CAAC;AAEF,eAAe,KAAK,CAAC"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Clears the reactotron server.
5
+ */
6
+ const clear = () => (reactotron) => {
7
+ return {
8
+ features: {
9
+ clear: () => reactotron.send('clear'),
10
+ },
11
+ };
12
+ };
13
+ exports.default = clear;
@@ -0,0 +1,19 @@
1
+ import type { DReactionCore } from '../';
2
+ export interface ImagePayload {
3
+ uri: string;
4
+ preview: string;
5
+ caption?: string;
6
+ width?: number;
7
+ height?: number;
8
+ filename?: string;
9
+ }
10
+ /**
11
+ * Provides an image.
12
+ */
13
+ declare const image: () => (reactotron: DReactionCore) => {
14
+ features: {
15
+ image: (payload: ImagePayload) => void;
16
+ };
17
+ };
18
+ export default image;
19
+ //# sourceMappingURL=image.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../src/plugins/image.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAU,MAAM,KAAK,CAAC;AAEjD,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,QAAA,MAAM,KAAK,qBAAsB,aAAa;;yBAIvB,YAAY;;CAalC,CAAC;AAEF,eAAe,KAAK,CAAC"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Provides an image.
5
+ */
6
+ const image = () => (reactotron) => {
7
+ return {
8
+ features: {
9
+ // expanded just to show the specs
10
+ image: (payload) => {
11
+ const { uri, preview, filename, width, height, caption } = payload;
12
+ return reactotron.send('image', {
13
+ uri,
14
+ preview,
15
+ filename,
16
+ width,
17
+ height,
18
+ caption,
19
+ });
20
+ },
21
+ },
22
+ };
23
+ };
24
+ exports.default = image;
@@ -0,0 +1,18 @@
1
+ import type { DReactionCore, InferFeatures } from '../';
2
+ /**
3
+ * Provides 4 features for logging. log & debug are the same.
4
+ */
5
+ declare const logger: () => (dreaction: DReactionCore) => {
6
+ features: {
7
+ log: (...args: any[]) => void;
8
+ logImportant: (...args: any[]) => void;
9
+ debug: (message: any, important?: any) => void;
10
+ warn: (message: any) => void;
11
+ error: (message: any, stack: any) => void;
12
+ };
13
+ };
14
+ export default logger;
15
+ export type LoggerPlugin = ReturnType<typeof logger>;
16
+ export declare const hasLoggerPlugin: (dreaction: DReactionCore) => dreaction is DReactionCore & InferFeatures<DReactionCore, ReturnType<typeof logger>>;
17
+ export declare const assertHasLoggerPlugin: (dreaction: DReactionCore) => asserts dreaction is DReactionCore & InferFeatures<DReactionCore, ReturnType<typeof logger>>;
18
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +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;;;;;;;;CAmB7C,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,CAcvD,CAAC;AAEF,eAAO,MAAM,qBAAqB,cACrB,aAAa,KACvB,QAAQ,SAAS,IAAI,aAAa,GACnC,aAAa,CAAC,aAAa,EAAE,UAAU,CAAC,OAAO,MAAM,CAAC,CAMvD,CAAC"}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertHasLoggerPlugin = exports.hasLoggerPlugin = void 0;
4
+ /**
5
+ * Provides 4 features for logging. log & debug are the same.
6
+ */
7
+ const logger = () => (dreaction) => {
8
+ return {
9
+ features: {
10
+ log: (...args) => {
11
+ const content = args && args.length === 1 ? args[0] : args;
12
+ dreaction.send('log', { level: 'debug', message: content }, false);
13
+ },
14
+ logImportant: (...args) => {
15
+ const content = args && args.length === 1 ? args[0] : args;
16
+ dreaction.send('log', { level: 'debug', message: content }, true);
17
+ },
18
+ debug: (message, important = false) => dreaction.send('log', { level: 'debug', message }, !!important),
19
+ warn: (message) => dreaction.send('log', { level: 'warn', message }, true),
20
+ error: (message, stack) => dreaction.send('log', { level: 'error', message, stack }, true),
21
+ },
22
+ };
23
+ };
24
+ exports.default = logger;
25
+ const hasLoggerPlugin = (dreaction) => {
26
+ return (dreaction &&
27
+ 'log' in dreaction &&
28
+ typeof dreaction.log === 'function' &&
29
+ 'logImportant' in dreaction &&
30
+ typeof dreaction.logImportant === 'function' &&
31
+ 'debug' in dreaction &&
32
+ typeof dreaction.debug === 'function' &&
33
+ 'warn' in dreaction &&
34
+ typeof dreaction.warn === 'function' &&
35
+ 'error' in dreaction &&
36
+ typeof dreaction.error === 'function');
37
+ };
38
+ exports.hasLoggerPlugin = hasLoggerPlugin;
39
+ const assertHasLoggerPlugin = (dreaction) => {
40
+ if (!(0, exports.hasLoggerPlugin)(dreaction)) {
41
+ throw new Error('This Reactotron client has not had the logger plugin applied to it. Make sure that you add `use(logger())` before adding this plugin.');
42
+ }
43
+ };
44
+ exports.assertHasLoggerPlugin = assertHasLoggerPlugin;
@@ -0,0 +1,10 @@
1
+ import type { DReactionCore } from '../';
2
+ export type AcceptableRepls = object | Function | string | number;
3
+ declare const repl: () => (reactotron: DReactionCore) => {
4
+ onCommand: ({ type, payload }: import("dreaction-protocol").Command) => void;
5
+ features: {
6
+ repl: (name: string, value: AcceptableRepls) => void;
7
+ };
8
+ };
9
+ export default repl;
10
+ //# sourceMappingURL=repl.d.ts.map
@@ -0,0 +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,qBAAsB,aAAa;;;qBA2C1B,MAAM,SAAS,eAAe;;CAahD,CAAC;AACF,eAAe,IAAI,CAAC"}
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const repl = () => (reactotron) => {
4
+ const myRepls = {};
5
+ // let currentContext = null
6
+ return {
7
+ onCommand: ({ type, payload }) => {
8
+ if (type.substr(0, 5) !== 'repl.')
9
+ return;
10
+ switch (type.substr(5)) {
11
+ case 'ls':
12
+ reactotron.send('repl.ls.response', Object.keys(myRepls));
13
+ break;
14
+ // case "cd":
15
+ // const changeTo = myRepls.find(r => r.name === payload)
16
+ // if (!changeTo) {
17
+ // reactotron.send("repl.cd.response", "That REPL does not exist")
18
+ // break
19
+ // }
20
+ // currentContext = payload
21
+ // reactotron.send("repl.cd.response", `Change REPL to "${payload}"`)
22
+ // break
23
+ case 'execute':
24
+ // if (!currentContext) {
25
+ // reactotron.send(
26
+ // "repl.execute.response",
27
+ // "You must first select the REPL to use. Try 'ls'"
28
+ // )
29
+ // break
30
+ // }
31
+ // const currentRepl = myRepls.find(r => r.name === currentContext)
32
+ // if (!currentRepl) {
33
+ // reactotron.send("repl.execute.response", "The selected REPL no longer exists.")
34
+ // break
35
+ // }
36
+ reactotron.send('repl.execute.response', function () {
37
+ return eval(payload); // eslint-disable-line no-eval
38
+ }.call(myRepls));
39
+ break;
40
+ }
41
+ },
42
+ features: {
43
+ repl: (name, value) => {
44
+ if (!name) {
45
+ throw new Error('You must provide a name for your REPL');
46
+ }
47
+ if (myRepls[name]) {
48
+ throw new Error('You are already REPLing an item with that name');
49
+ }
50
+ myRepls[name] = value;
51
+ },
52
+ },
53
+ };
54
+ };
55
+ exports.default = repl;
@@ -0,0 +1,20 @@
1
+ import type { StateActionCompletePayload, StateBackupResponsePayload, StateKeysResponsePayload, StateValuesChangePayload, StateValuesResponsePayload } from 'dreaction-protocol';
2
+ import type { DReactionCore, InferFeatures } from '../';
3
+ /**
4
+ * Provides helper functions for send state responses.
5
+ */
6
+ declare const stateResponse: () => (reactotron: DReactionCore) => {
7
+ features: {
8
+ stateActionComplete: (name: StateActionCompletePayload["name"], action: StateActionCompletePayload["action"], important?: any) => void;
9
+ stateValuesResponse: (path: StateValuesResponsePayload["path"], value: StateValuesResponsePayload["value"], valid?: StateValuesResponsePayload["value"]) => void;
10
+ stateKeysResponse: (path: StateKeysResponsePayload["path"], keys: StateKeysResponsePayload["keys"], valid?: StateKeysResponsePayload["valid"]) => void;
11
+ stateValuesChange: (changes: StateValuesChangePayload["changes"]) => false | void;
12
+ /** sends the state backup over to the server */
13
+ stateBackupResponse: (state: StateBackupResponsePayload["state"]) => void;
14
+ };
15
+ };
16
+ export type StateResponsePlugin = ReturnType<typeof stateResponse>;
17
+ export default stateResponse;
18
+ export declare const hasStateResponsePlugin: (reactotron: DReactionCore) => reactotron is DReactionCore & InferFeatures<DReactionCore, ReturnType<typeof stateResponse>>;
19
+ export declare const assertHasStateResponsePlugin: (reactotron: DReactionCore) => asserts reactotron is DReactionCore & InferFeatures<DReactionCore, ReturnType<typeof stateResponse>>;
20
+ //# sourceMappingURL=state-responses.d.ts.map
@@ -0,0 +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,qBAAsB,aAAa;;oCAIxC,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,CAAC,MAAM,CAAC,QAChC,wBAAwB,CAAC,MAAM,CAAC,UAC/B,wBAAwB,CAAC,OAAO,CAAC;qCAGb,wBAAwB,CAAC,SAAS,CAAC;QAIhE,gDAAgD;qCACnB,0BAA0B,CAAC,OAAO,CAAC;;CAIrE,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AAEnE,eAAe,aAAa,CAAC;AAE7B,eAAO,MAAM,sBAAsB,eACrB,aAAa,KACxB,UAAU,IAAI,aAAa,GAC5B,aAAa,CAAC,aAAa,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,CAWT,CAAC;AAEvD,eAAO,MAAM,4BAA4B,eAC3B,aAAa,KACxB,QAAQ,UAAU,IAAI,aAAa,GACpC,aAAa,CAAC,aAAa,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,CAM9D,CAAC"}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertHasStateResponsePlugin = exports.hasStateResponsePlugin = void 0;
4
+ /**
5
+ * Provides helper functions for send state responses.
6
+ */
7
+ const stateResponse = () => (reactotron) => {
8
+ return {
9
+ features: {
10
+ stateActionComplete: (name, action, important = false) => reactotron.send('state.action.complete', { name, action }, !!important),
11
+ stateValuesResponse: (path, value, valid = true) => reactotron.send('state.values.response', { path, value, valid }),
12
+ stateKeysResponse: (path, keys, valid = true) => reactotron.send('state.keys.response', { path, keys, valid }),
13
+ stateValuesChange: (changes) => changes.length > 0 &&
14
+ reactotron.send('state.values.change', { changes }),
15
+ /** sends the state backup over to the server */
16
+ stateBackupResponse: (state) => reactotron.send('state.backup.response', { state }),
17
+ },
18
+ };
19
+ };
20
+ exports.default = stateResponse;
21
+ const hasStateResponsePlugin = (reactotron) => reactotron &&
22
+ 'stateActionComplete' in reactotron &&
23
+ typeof reactotron.stateActionComplete === 'function' &&
24
+ 'stateValuesResponse' in reactotron &&
25
+ typeof reactotron.stateValuesResponse === 'function' &&
26
+ 'stateKeysResponse' in reactotron &&
27
+ typeof reactotron.stateKeysResponse === 'function' &&
28
+ 'stateValuesChange' in reactotron &&
29
+ typeof reactotron.stateValuesChange === 'function' &&
30
+ 'stateBackupResponse' in reactotron &&
31
+ typeof reactotron.stateBackupResponse === 'function';
32
+ exports.hasStateResponsePlugin = hasStateResponsePlugin;
33
+ const assertHasStateResponsePlugin = (reactotron) => {
34
+ if (!(0, exports.hasStateResponsePlugin)(reactotron)) {
35
+ throw new Error('This Reactotron 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;
@@ -0,0 +1,191 @@
1
+ import WebSocket from 'ws';
2
+ import type { Command, CommandTypeKey } from 'dreaction-protocol';
3
+ import { ClientOptions } from './client-options';
4
+ export type { ClientOptions };
5
+ export { assertHasLoggerPlugin } from './plugins/logger';
6
+ export type { LoggerPlugin } from './plugins/logger';
7
+ export { assertHasStateResponsePlugin, hasStateResponsePlugin, } from './plugins/state-responses';
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
+ export interface LifeCycleMethods {
17
+ onCommand?: (command: Command) => void;
18
+ onConnect?: () => void;
19
+ onDisconnect?: () => void;
20
+ }
21
+ type AnyFunction = (...args: any[]) => any;
22
+ export interface Plugin<Client> extends LifeCycleMethods {
23
+ features?: {
24
+ [key: string]: AnyFunction;
25
+ };
26
+ onPlugin?: (client: Client) => void;
27
+ }
28
+ export type PluginCreator<Client> = (client: Client) => Plugin<Client>;
29
+ interface DisplayConfig {
30
+ name: string;
31
+ value?: object | string | number | boolean | null | undefined;
32
+ preview?: string;
33
+ image?: string | {
34
+ uri: string;
35
+ };
36
+ important?: boolean;
37
+ }
38
+ interface ArgTypeMap {
39
+ [ArgType.String]: string;
40
+ }
41
+ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
42
+ export type CustomCommandArgs<Args extends CustomCommandArg[]> = UnionToIntersection<Args extends Array<infer U> ? U extends CustomCommandArg ? {
43
+ [K in U as U['name']]: ArgTypeMap[U['type']];
44
+ } : never : never>;
45
+ export interface CustomCommand<Args extends CustomCommandArg[] = CustomCommandArg[]> {
46
+ id?: number;
47
+ command: string;
48
+ handler: (args?: CustomCommandArgs<Args>) => void;
49
+ title?: string;
50
+ description?: string;
51
+ args?: Args;
52
+ }
53
+ type ExtractFeatures<T> = T extends {
54
+ features: infer U;
55
+ } ? U : never;
56
+ type PluginFeatures<Client, P extends PluginCreator<Client>> = ExtractFeatures<ReturnType<P>>;
57
+ export type InferFeaturesFromPlugins<Client, Plugins extends PluginCreator<Client>[]> = UnionToIntersection<PluginFeatures<Client, Plugins[number]>>;
58
+ type InferFeaturesFromPlugin<Client, P extends PluginCreator<Client>> = UnionToIntersection<PluginFeatures<Client, P>>;
59
+ export interface ReactotronCore {
60
+ options: ClientOptions<this>;
61
+ plugins: Plugin<this>[];
62
+ startTimer: () => () => number;
63
+ close: () => void;
64
+ send: <Type extends CommandTypeKey, Payload extends Command<Type>['payload']>(type: Type, payload?: Payload, important?: boolean) => void;
65
+ display: (config: DisplayConfig) => void;
66
+ onCustomCommand: <Args extends CustomCommandArg[] = Exclude<CustomCommand['args'], undefined>>(config: CustomCommand<Args>) => () => void | ((config: string, optHandler?: () => void) => () => void);
67
+ /**
68
+ * Set the configuration options.
69
+ */
70
+ configure: (options: ClientOptions<this>) => ClientOptions<this>['plugins'] extends PluginCreator<this>[] ? this & InferFeaturesFromPlugins<this, ClientOptions<this>['plugins']> : this;
71
+ use: <P extends PluginCreator<this>>(pluginCreator: P) => this & InferFeaturesFromPlugin<this, P>;
72
+ connect: () => this;
73
+ }
74
+ export type InferFeatures<Client = ReactotronCore, PC extends PluginCreator<Client> = PluginCreator<Client>> = PC extends (client: Client) => {
75
+ features: infer U;
76
+ } ? U : never;
77
+ export declare const corePlugins: (((reactotron: ReactotronCore) => {
78
+ features: {
79
+ log: (...args: any[]) => void;
80
+ logImportant: (...args: any[]) => void;
81
+ debug: (message: any, important?: any) => void;
82
+ warn: (message: any) => void;
83
+ error: (message: any, stack: any) => void;
84
+ };
85
+ }) | ((reactotron: ReactotronCore) => {
86
+ features: {
87
+ image: (payload: import("./plugins/image").ImagePayload) => void;
88
+ };
89
+ }) | ((reactotron: ReactotronCore) => {
90
+ features: {
91
+ benchmark: (title: string) => {
92
+ step: (stepTitle: string) => void;
93
+ stop: (stopTitle: string) => void;
94
+ last: (stopTitle: string) => void;
95
+ };
96
+ };
97
+ }) | ((reactotron: ReactotronCore) => {
98
+ features: {
99
+ stateActionComplete: (name: import("dreaction-protocol").StateActionCompletePayload["name"], action: import("dreaction-protocol").StateActionCompletePayload["action"], important?: any) => void;
100
+ stateValuesResponse: (path: import("dreaction-protocol").StateValuesResponsePayload["path"], value: import("dreaction-protocol").StateValuesResponsePayload["value"], valid?: import("dreaction-protocol").StateValuesResponsePayload["value"]) => void;
101
+ stateKeysResponse: (path: import("dreaction-protocol").StateKeysResponsePayload["path"], keys: import("dreaction-protocol").StateKeysResponsePayload["keys"], valid?: import("dreaction-protocol").StateKeysResponsePayload["valid"]) => void;
102
+ stateValuesChange: (changes: import("dreaction-protocol").StateValuesChangePayload["changes"]) => false | void;
103
+ stateBackupResponse: (state: import("dreaction-protocol").StateBackupResponsePayload["state"]) => void;
104
+ };
105
+ }) | ((reactotron: ReactotronCore) => {
106
+ features: {
107
+ apiResponse: (request: {
108
+ status: number;
109
+ }, response: any, duration: number) => void;
110
+ };
111
+ }) | ((reactotron: ReactotronCore) => {
112
+ features: {
113
+ clear: () => void;
114
+ };
115
+ }) | ((reactotron: ReactotronCore) => {
116
+ onCommand: ({ type, payload }: Command<CommandTypeKey, any>) => void;
117
+ features: {
118
+ repl: (name: string, value: import("./plugins/repl").AcceptableRepls) => void;
119
+ };
120
+ }))[];
121
+ export type InferPluginsFromCreators<Client, PC extends PluginCreator<Client>[]> = PC extends Array<infer P extends PluginCreator<Client>> ? ReturnType<P>[] : never;
122
+ type CorePluginFeatures = InferFeaturesFromPlugins<ReactotronCore, typeof corePlugins>;
123
+ export interface Reactotron extends ReactotronCore, CorePluginFeatures {
124
+ }
125
+ export declare class ReactotronImpl implements Omit<ReactotronCore, 'options' | 'plugins' | 'configure' | 'connect' | 'use'> {
126
+ options: ClientOptions<ReactotronCore>;
127
+ /**
128
+ * Are we connected to a server?
129
+ */
130
+ connected: boolean;
131
+ /**
132
+ * The socket we're using.
133
+ */
134
+ socket: WebSocket;
135
+ /**
136
+ * Available plugins.
137
+ */
138
+ plugins: Plugin<this>[];
139
+ /**
140
+ * Messages that need to be sent.
141
+ */
142
+ sendQueue: string[];
143
+ /**
144
+ * Are we ready to start communicating?
145
+ */
146
+ isReady: boolean;
147
+ /**
148
+ * The last time we sent a message.
149
+ */
150
+ lastMessageDate: Date;
151
+ /**
152
+ * The registered custom commands
153
+ */
154
+ customCommands: CustomCommand[];
155
+ /**
156
+ * The current ID for custom commands
157
+ */
158
+ customCommandLatestId: number;
159
+ /**
160
+ * Starts a timer and returns a function you can call to stop it and return the elapsed time.
161
+ */
162
+ startTimer: () => () => number;
163
+ /**
164
+ * Set the configuration options.
165
+ */
166
+ configure(options: ClientOptions<this>): ClientOptions<this>['plugins'] extends PluginCreator<this>[] ? this & InferFeaturesFromPlugins<this, ClientOptions<this>['plugins']> : this;
167
+ close(): void;
168
+ /**
169
+ * Connect to the Reactotron server.
170
+ */
171
+ connect(): this;
172
+ /**
173
+ * Sends a command to the server
174
+ */
175
+ send: <Type extends CommandTypeKey, Payload extends Command<Type>["payload"]>(type: Type, payload?: Payload, important?: boolean) => void;
176
+ /**
177
+ * Sends a custom command to the server to displays nicely.
178
+ */
179
+ display(config: DisplayConfig): void;
180
+ /**
181
+ * Client libraries can hijack this to report errors.
182
+ */
183
+ reportError(this: any, error: Error): void;
184
+ /**
185
+ * Adds a plugin to the system
186
+ */
187
+ use(pluginCreator: PluginCreator<this>): this & PluginFeatures<this, typeof pluginCreator>;
188
+ onCustomCommand(config: CustomCommand | string, optHandler?: () => void): () => void;
189
+ }
190
+ export declare function createClient<Client extends ReactotronCore = ReactotronCore>(options?: ClientOptions<Client>): Client;
191
+ //# sourceMappingURL=reactotron-core-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reactotron-core-client.d.ts","sourceRoot":"","sources":["../src/reactotron-core-client.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,IAAI,CAAC;AAC3B,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAWlE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,YAAY,EAAE,aAAa,EAAE,CAAC;AAC9B,OAAO,EAAE,qB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