@quantform/core 0.7.22 → 0.7.25

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 (195) hide show
  1. package/lib/app.d.ts +12 -0
  2. package/lib/app.d.ts.map +1 -0
  3. package/lib/app.js +35 -0
  4. package/lib/cli/build.d.ts.map +1 -1
  5. package/lib/cli/build.js +8 -18
  6. package/lib/cli/index.js +3 -12
  7. package/lib/cli/internal/script.d.ts +1 -1
  8. package/lib/cli/internal/script.d.ts.map +1 -1
  9. package/lib/cli/internal/script.js +8 -28
  10. package/lib/cli/live.js +10 -22
  11. package/lib/cli/paper.js +10 -22
  12. package/lib/cli/replay.d.ts.map +1 -1
  13. package/lib/cli/replay.js +15 -26
  14. package/lib/index.d.ts +1 -6
  15. package/lib/index.d.ts.map +1 -1
  16. package/lib/index.js +1 -6
  17. package/lib/make-test-module.d.ts +1 -6
  18. package/lib/make-test-module.d.ts.map +1 -1
  19. package/lib/make-test-module.js +19 -30
  20. package/lib/module.d.ts.map +1 -1
  21. package/lib/module.js +9 -24
  22. package/lib/module.spec.js +8 -17
  23. package/lib/replay/use-replay-options.d.ts +5 -4
  24. package/lib/replay/use-replay-options.d.ts.map +1 -1
  25. package/lib/replay/use-replay-options.js +5 -1
  26. package/lib/replay/use-replay-scheduler.d.ts +7 -6
  27. package/lib/replay/use-replay-scheduler.d.ts.map +1 -1
  28. package/lib/replay/use-replay-scheduler.js +64 -70
  29. package/lib/replay/use-replay-storage-buffer.d.ts +3 -2
  30. package/lib/replay/use-replay-storage-buffer.d.ts.map +1 -1
  31. package/lib/replay/use-replay-storage-buffer.js +12 -23
  32. package/lib/replay/use-replay-storage-cursor.d.ts +9 -8
  33. package/lib/replay/use-replay-storage-cursor.d.ts.map +1 -1
  34. package/lib/replay/use-replay-storage-cursor.js +17 -25
  35. package/lib/replay/use-replay-storage.d.ts +5 -4
  36. package/lib/replay/use-replay-storage.d.ts.map +1 -1
  37. package/lib/replay/use-replay-storage.js +32 -39
  38. package/lib/session/use-session-storage.d.ts +1 -1
  39. package/lib/session/use-session-storage.d.ts.map +1 -1
  40. package/lib/session/use-session-storage.js +8 -5
  41. package/lib/shared/environment.js +1 -1
  42. package/lib/shared/index.d.ts +0 -1
  43. package/lib/shared/index.d.ts.map +1 -1
  44. package/lib/shared/index.js +0 -1
  45. package/lib/simulator/use-simulator.spec.js +17 -30
  46. package/lib/storage/in-memory/in-memory-storage.d.ts.map +1 -1
  47. package/lib/storage/in-memory/in-memory-storage.factory.js +2 -2
  48. package/lib/storage/in-memory/in-memory-storage.js +56 -55
  49. package/lib/storage/in-memory/in-memory-storage.spec.js +90 -100
  50. package/lib/storage/storage.d.ts +9 -8
  51. package/lib/storage/storage.d.ts.map +1 -1
  52. package/lib/storage/storage.js +8 -2
  53. package/lib/storage/use-cache.d.ts +1 -1
  54. package/lib/storage/use-cache.d.ts.map +1 -1
  55. package/lib/storage/use-cache.js +5 -5
  56. package/lib/storage/use-cache.spec.js +14 -25
  57. package/lib/storage/use-storage.d.ts +1 -1
  58. package/lib/storage/use-storage.d.ts.map +1 -1
  59. package/lib/storage/use-storage.js +9 -6
  60. package/lib/use-execution-mode.js +2 -2
  61. package/lib/use-hash.spec.js +3 -6
  62. package/lib/use-logger.d.ts +1 -1
  63. package/lib/use-logger.d.ts.map +1 -1
  64. package/lib/use-logger.js +10 -7
  65. package/lib/use-memo.spec.js +14 -25
  66. package/lib/use-socket.d.ts +3 -2
  67. package/lib/use-socket.d.ts.map +1 -1
  68. package/lib/use-socket.js +2 -2
  69. package/lib/use-timestamp.d.ts +14 -1
  70. package/lib/use-timestamp.d.ts.map +1 -1
  71. package/lib/use-timestamp.js +30 -3
  72. package/lib/with-request.d.ts +2 -1
  73. package/lib/with-request.d.ts.map +1 -1
  74. package/lib/with-request.js +4 -13
  75. package/package.json +6 -10
  76. package/src/app.ts +52 -0
  77. package/src/cli/build.ts +11 -6
  78. package/src/cli/internal/script.ts +25 -54
  79. package/src/cli/replay.ts +13 -2
  80. package/src/index.ts +1 -6
  81. package/src/make-test-module.ts +13 -21
  82. package/src/module.ts +0 -3
  83. package/src/replay/use-replay-options.ts +7 -3
  84. package/src/replay/use-replay-scheduler.ts +75 -67
  85. package/src/replay/use-replay-storage-buffer.ts +2 -1
  86. package/src/replay/use-replay-storage-cursor.ts +33 -28
  87. package/src/replay/use-replay-storage.ts +36 -27
  88. package/src/session/use-session-storage.ts +7 -5
  89. package/src/shared/index.ts +0 -1
  90. package/src/storage/in-memory/in-memory-storage.spec.ts +55 -54
  91. package/src/storage/in-memory/in-memory-storage.ts +24 -7
  92. package/src/storage/storage.ts +16 -7
  93. package/src/storage/use-cache.ts +4 -4
  94. package/src/storage/use-storage.ts +8 -6
  95. package/src/use-hash.spec.ts +3 -6
  96. package/src/use-logger.ts +9 -6
  97. package/src/use-socket.ts +5 -5
  98. package/src/use-timestamp.ts +41 -3
  99. package/src/with-request.ts +3 -3
  100. package/lib/asset/asset.d.ts +0 -41
  101. package/lib/asset/asset.d.ts.map +0 -1
  102. package/lib/asset/asset.js +0 -76
  103. package/lib/asset/asset.spec.d.ts +0 -2
  104. package/lib/asset/asset.spec.d.ts.map +0 -1
  105. package/lib/asset/asset.spec.js +0 -54
  106. package/lib/asset/index.d.ts +0 -2
  107. package/lib/asset/index.d.ts.map +0 -1
  108. package/lib/asset/index.js +0 -17
  109. package/lib/component/distinct-until-timesamp-changed.d.ts +0 -5
  110. package/lib/component/distinct-until-timesamp-changed.d.ts.map +0 -1
  111. package/lib/component/distinct-until-timesamp-changed.js +0 -9
  112. package/lib/component/error.d.ts +0 -17
  113. package/lib/component/error.d.ts.map +0 -1
  114. package/lib/component/error.js +0 -33
  115. package/lib/component/index.d.ts +0 -8
  116. package/lib/component/index.d.ts.map +0 -1
  117. package/lib/component/index.js +0 -23
  118. package/lib/component/ohlc-operator.d.ts +0 -11
  119. package/lib/component/ohlc-operator.d.ts.map +0 -1
  120. package/lib/component/ohlc-operator.js +0 -69
  121. package/lib/component/ohlc-operator.spec.d.ts +0 -2
  122. package/lib/component/ohlc-operator.spec.d.ts.map +0 -1
  123. package/lib/component/ohlc-operator.spec.js +0 -110
  124. package/lib/component/ohlc.d.ts +0 -12
  125. package/lib/component/ohlc.d.ts.map +0 -1
  126. package/lib/component/ohlc.js +0 -20
  127. package/lib/component/ohlc.spec.d.ts +0 -2
  128. package/lib/component/ohlc.spec.d.ts.map +0 -1
  129. package/lib/component/ohlc.spec.js +0 -25
  130. package/lib/component/timeframe.d.ts +0 -15
  131. package/lib/component/timeframe.d.ts.map +0 -1
  132. package/lib/component/timeframe.js +0 -21
  133. package/lib/core.d.ts +0 -3
  134. package/lib/core.d.ts.map +0 -1
  135. package/lib/core.js +0 -17
  136. package/lib/instrument/commission/commission.d.ts +0 -16
  137. package/lib/instrument/commission/commission.d.ts.map +0 -1
  138. package/lib/instrument/commission/commission.js +0 -28
  139. package/lib/instrument/commission/commission.spec.d.ts +0 -2
  140. package/lib/instrument/commission/commission.spec.d.ts.map +0 -1
  141. package/lib/instrument/commission/commission.spec.js +0 -30
  142. package/lib/instrument/index.d.ts +0 -3
  143. package/lib/instrument/index.d.ts.map +0 -1
  144. package/lib/instrument/index.js +0 -18
  145. package/lib/instrument/instrument.d.ts +0 -28
  146. package/lib/instrument/instrument.d.ts.map +0 -1
  147. package/lib/instrument/instrument.js +0 -53
  148. package/lib/instrument/instrument.spec.d.ts +0 -2
  149. package/lib/instrument/instrument.spec.d.ts.map +0 -1
  150. package/lib/instrument/instrument.spec.js +0 -51
  151. package/lib/operators.d.ts +0 -5
  152. package/lib/operators.d.ts.map +0 -1
  153. package/lib/operators.js +0 -16
  154. package/lib/shared/datetime.d.ts +0 -3
  155. package/lib/shared/datetime.d.ts.map +0 -1
  156. package/lib/shared/datetime.js +0 -7
  157. package/lib/strategy.d.ts +0 -15
  158. package/lib/strategy.d.ts.map +0 -1
  159. package/lib/strategy.js +0 -26
  160. package/lib/strategy.spec.d.ts +0 -2
  161. package/lib/strategy.spec.d.ts.map +0 -1
  162. package/lib/strategy.spec.js +0 -34
  163. package/lib/when-socket.d.ts +0 -8
  164. package/lib/when-socket.d.ts.map +0 -1
  165. package/lib/when-socket.js +0 -53
  166. package/lib/with-memo.d.ts +0 -5
  167. package/lib/with-memo.d.ts.map +0 -1
  168. package/lib/with-memo.js +0 -20
  169. package/lib/with-memo.spec.d.ts +0 -2
  170. package/lib/with-memo.spec.d.ts.map +0 -1
  171. package/lib/with-memo.spec.js +0 -47
  172. package/src/asset/asset.spec.ts +0 -70
  173. package/src/asset/asset.ts +0 -89
  174. package/src/asset/index.ts +0 -1
  175. package/src/component/distinct-until-timesamp-changed.ts +0 -11
  176. package/src/component/error.ts +0 -32
  177. package/src/component/index.ts +0 -7
  178. package/src/component/ohlc-operator.spec.ts +0 -125
  179. package/src/component/ohlc-operator.ts +0 -122
  180. package/src/component/ohlc.spec.ts +0 -30
  181. package/src/component/ohlc.ts +0 -18
  182. package/src/component/timeframe.ts +0 -17
  183. package/src/core.ts +0 -16
  184. package/src/instrument/commission/commission.spec.ts +0 -35
  185. package/src/instrument/commission/commission.ts +0 -27
  186. package/src/instrument/index.ts +0 -2
  187. package/src/instrument/instrument.spec.ts +0 -76
  188. package/src/instrument/instrument.ts +0 -65
  189. package/src/operators.ts +0 -18
  190. package/src/shared/datetime.ts +0 -5
  191. package/src/strategy.spec.ts +0 -42
  192. package/src/strategy.ts +0 -36
  193. package/src/when-socket.ts +0 -61
  194. package/src/with-memo.spec.ts +0 -46
  195. package/src/with-memo.ts +0 -33
package/lib/app.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { Observable } from 'rxjs';
2
+ import { Dependency } from './module';
3
+ export type AppStart<T> = {
4
+ run: (dependencies: Dependency[]) => Promise<T | undefined>;
5
+ };
6
+ export type AppHandle = {
7
+ use: AppUse;
8
+ start: <T>(strategy: () => Observable<T>) => AppStart<T | undefined>;
9
+ };
10
+ export type AppUse = (module: Dependency | Dependency[]) => AppHandle;
11
+ export declare function app(): AppHandle;
12
+ //# sourceMappingURL=app.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwC,UAAU,EAAE,MAAM,MAAM,CAAC;AAExE,OAAO,EAAE,UAAU,EAAU,MAAM,aAAa,CAAC;AAOjD,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;IACxB,GAAG,EAAE,CAAC,YAAY,EAAE,UAAU,EAAE,KAAK,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;CAC7D,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;CACtE,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,EAAE,KAAK,SAAS,CAAC;AAEtE,wBAAgB,GAAG,IAAI,SAAS,CA+B/B"}
package/lib/app.js ADDED
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.app = void 0;
4
+ const rxjs_1 = require("rxjs");
5
+ const module_1 = require("./module");
6
+ const storage_1 = require("./storage");
7
+ const use_execution_mode_1 = require("./use-execution-mode");
8
+ const use_logger_1 = require("./use-logger");
9
+ const use_memo_1 = require("./use-memo");
10
+ function app() {
11
+ const deps = [
12
+ use_memo_1.useMemo.options(),
13
+ (0, use_logger_1.logger)(new use_logger_1.ConsoleLoggerFactory()),
14
+ use_execution_mode_1.useExecutionMode.paperOptions({ recording: false }),
15
+ storage_1.useStorageFactory.options(new storage_1.InMemoryStorageFactory())
16
+ ];
17
+ const start = (strategy) => ({
18
+ async run(dependencies = []) {
19
+ const module = new module_1.Module([...deps, ...dependencies]);
20
+ const { act } = await module.awake();
21
+ return await act(() => (0, rxjs_1.firstValueFrom)(strategy().pipe((0, rxjs_1.defaultIfEmpty)(undefined), (0, rxjs_1.last)())));
22
+ }
23
+ });
24
+ const use = (module) => {
25
+ if (Array.isArray(module)) {
26
+ deps.push(...module);
27
+ }
28
+ else {
29
+ deps.push(module);
30
+ }
31
+ return { use, start };
32
+ };
33
+ return { use, start };
34
+ }
35
+ exports.app = app;
@@ -1 +1 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/cli/build.ts"],"names":[],"mappings":"AAIA,4BAAkC,OAAO,CAAC,MAAM,CAAC,CAUhD"}
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/cli/build.ts"],"names":[],"mappings":"AAIA,4BAAkC,OAAO,CAAC,MAAM,CAAC,CAehD"}
package/lib/cli/build.js CHANGED
@@ -1,26 +1,16 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  const child_process_1 = require("child_process");
13
4
  const workspace_1 = require("../cli/internal/workspace");
14
- function default_1() {
15
- return __awaiter(this, void 0, void 0, function* () {
16
- return new Promise((resolve, reject) => {
17
- const process = (0, child_process_1.spawn)('swc', ['./src', '--out-dir', (0, workspace_1.buildDirectory)()], {
18
- stdio: 'inherit',
19
- shell: true
20
- });
21
- process.once('exit', resolve);
22
- process.once('error', reject);
5
+ async function default_1() {
6
+ return new Promise((resolve, reject) => {
7
+ const child = (0, child_process_1.spawn)('tsc', ['--project', 'tsconfig.json', '--outDir', (0, workspace_1.buildDirectory)()], {
8
+ cwd: process.cwd(),
9
+ stdio: 'inherit',
10
+ shell: true
23
11
  });
12
+ child.once('exit', resolve);
13
+ child.once('error', reject);
24
14
  });
25
15
  }
26
16
  exports.default = default_1;
package/lib/cli/index.js CHANGED
@@ -1,14 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
- return new (P || (P = Promise))(function (resolve, reject) {
6
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
- step((generator = generator.apply(thisArg, _arguments || [])).next());
10
- });
11
- };
12
3
  var __importDefault = (this && this.__importDefault) || function (mod) {
13
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
14
5
  };
@@ -23,9 +14,9 @@ const replay_1 = __importDefault(require("../cli/replay"));
23
14
  commander_1.program
24
15
  .command('build')
25
16
  .description('builds a production version of the app')
26
- .action(() => __awaiter(void 0, void 0, void 0, function* () {
27
- yield (0, build_1.default)();
28
- }));
17
+ .action(async () => {
18
+ await (0, build_1.default)();
19
+ });
29
20
  commander_1.program
30
21
  .command('live')
31
22
  .argument('<name>', 'strategy to execute')
@@ -3,6 +3,6 @@ export declare class Script {
3
3
  private readonly filename;
4
4
  private readonly dependencies;
5
5
  constructor(filename: string, dependencies: Dependency[]);
6
- run(): Promise<unknown[]>;
6
+ run(): Promise<any>;
7
7
  }
8
8
  //# sourceMappingURL=script.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"script.d.ts","sourceRoot":"","sources":["../../../src/cli/internal/script.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,UAAU,EAAU,MAAM,aAAa,CAAC;AAMjD,qBAAa,MAAM;IAEf,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,YAAY;gBADZ,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,UAAU,EAAE;IAGvC,GAAG;CA0CV"}
1
+ {"version":3,"file":"script.d.ts","sourceRoot":"","sources":["../../../src/cli/internal/script.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAIzC,qBAAa,MAAM;IAEf,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,YAAY;gBADZ,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,UAAU,EAAE;IAGvC,GAAG;CA0BV"}
@@ -22,44 +22,24 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
25
  Object.defineProperty(exports, "__esModule", { value: true });
35
26
  exports.Script = void 0;
36
27
  const path_1 = require("path");
37
28
  const rxjs_1 = require("rxjs");
38
- const core_1 = require("../../core");
39
- const module_1 = require("../../module");
40
- const replay_1 = require("../../replay");
41
29
  const workspace_1 = require("./workspace");
42
30
  class Script {
43
31
  constructor(filename, dependencies) {
44
32
  this.filename = filename;
45
33
  this.dependencies = dependencies;
46
34
  }
47
- run() {
48
- return __awaiter(this, void 0, void 0, function* () {
49
- const script = yield Promise.resolve(`${(0, path_1.join)((0, workspace_1.buildDirectory)(), this.filename)}`).then(s => __importStar(require(s)));
50
- const { dependencies, description } = script.default;
51
- const module = new module_1.Module([...(0, core_1.core)(), ...dependencies, ...this.dependencies]);
52
- const { act } = yield module.awake();
53
- return yield act(() => {
54
- process.stdin.resume();
55
- return (0, rxjs_1.firstValueFrom)((0, rxjs_1.merge)((0, rxjs_1.forkJoin)(description.before.map(before => before()))
56
- .pipe((0, rxjs_1.switchMap)(() => (0, rxjs_1.forkJoin)(description.behavior.map(behavior => behavior())).pipe((0, rxjs_1.last)())))
57
- .pipe((0, rxjs_1.last)()), (0, replay_1.whenReplayFinished)().pipe((0, rxjs_1.last)()), (0, rxjs_1.fromEvent)(process, 'exit'), (0, rxjs_1.fromEvent)(process, 'SIGINT'), (0, rxjs_1.fromEvent)(process, 'SIGUSR1'), (0, rxjs_1.fromEvent)(process, 'SIGUSR2'), (0, rxjs_1.fromEvent)(process, 'uncaughtException')).pipe((0, rxjs_1.catchError)(e => {
58
- console.error(e);
59
- return (0, rxjs_1.of)(e);
60
- }), (0, rxjs_1.take)(1), (0, rxjs_1.switchMap)(it => { var _a; return (_a = (0, rxjs_1.forkJoin)(description.after.map(after => after())).pipe((0, rxjs_1.last)())) !== null && _a !== void 0 ? _a : (0, rxjs_1.of)(it); }), (0, rxjs_1.finalize)(() => process.exit(0))));
61
- });
62
- });
35
+ async run() {
36
+ const script = await Promise.resolve(`${(0, path_1.join)((0, workspace_1.buildDirectory)(), this.filename)}`).then(s => __importStar(require(s)));
37
+ const { run } = script.default;
38
+ process.stdin.resume();
39
+ return (0, rxjs_1.firstValueFrom)((0, rxjs_1.merge)(run(this.dependencies), (0, rxjs_1.fromEvent)(process, 'exit'), (0, rxjs_1.fromEvent)(process, 'SIGINT'), (0, rxjs_1.fromEvent)(process, 'SIGUSR1'), (0, rxjs_1.fromEvent)(process, 'SIGUSR2'), (0, rxjs_1.fromEvent)(process, 'uncaughtException')).pipe((0, rxjs_1.catchError)(e => {
40
+ console.error(e);
41
+ return (0, rxjs_1.of)(e);
42
+ }), (0, rxjs_1.take)(1), (0, rxjs_1.finalize)(() => process.exit(0))));
63
43
  }
64
44
  }
65
45
  exports.Script = Script;
package/lib/cli/live.js CHANGED
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -16,18 +7,15 @@ const build_1 = __importDefault(require("../cli/build"));
16
7
  const session_1 = require("../session");
17
8
  const use_execution_mode_1 = require("../use-execution-mode");
18
9
  const script_1 = require("./internal/script");
19
- function default_1(name, options) {
20
- var _a, _b;
21
- return __awaiter(this, void 0, void 0, function* () {
22
- if (yield (0, build_1.default)()) {
23
- return;
24
- }
25
- const script = new script_1.Script(name, [
26
- session_1.useSession.options({ id: (_a = options.id) !== null && _a !== void 0 ? _a : Date.now().toString() }),
27
- use_execution_mode_1.useExecutionMode.liveOptions({ recording: (_b = options.recording) !== null && _b !== void 0 ? _b : false })
28
- ]);
29
- const output = yield script.run();
30
- console.log(output);
31
- });
10
+ async function default_1(name, options) {
11
+ if (await (0, build_1.default)()) {
12
+ return;
13
+ }
14
+ const script = new script_1.Script(name, [
15
+ session_1.useSession.options({ id: options.id ?? Date.now().toString() }),
16
+ use_execution_mode_1.useExecutionMode.liveOptions({ recording: options.recording ?? false })
17
+ ]);
18
+ const output = await script.run();
19
+ console.log(output);
32
20
  }
33
21
  exports.default = default_1;
package/lib/cli/paper.js CHANGED
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -16,18 +7,15 @@ const build_1 = __importDefault(require("../cli/build"));
16
7
  const session_1 = require("../session");
17
8
  const use_execution_mode_1 = require("../use-execution-mode");
18
9
  const script_1 = require("./internal/script");
19
- function default_1(name, options) {
20
- var _a, _b;
21
- return __awaiter(this, void 0, void 0, function* () {
22
- if (yield (0, build_1.default)()) {
23
- return;
24
- }
25
- const script = new script_1.Script(name, [
26
- session_1.useSession.options({ id: (_a = options.id) !== null && _a !== void 0 ? _a : Date.now().toString() }),
27
- use_execution_mode_1.useExecutionMode.paperOptions({ recording: (_b = options.recording) !== null && _b !== void 0 ? _b : false })
28
- ]);
29
- const output = yield script.run();
30
- console.log(output);
31
- });
10
+ async function default_1(name, options) {
11
+ if (await (0, build_1.default)()) {
12
+ return;
13
+ }
14
+ const script = new script_1.Script(name, [
15
+ session_1.useSession.options({ id: options.id ?? Date.now().toString() }),
16
+ use_execution_mode_1.useExecutionMode.paperOptions({ recording: options.recording ?? false })
17
+ ]);
18
+ const output = await script.run();
19
+ console.log(output);
32
20
  }
33
21
  exports.default = default_1;
@@ -1 +1 @@
1
- {"version":3,"file":"replay.d.ts","sourceRoot":"","sources":["../../src/cli/replay.ts"],"names":[],"mappings":"AAOA,yBACE,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE;IAAE,EAAE,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,iBAkBvE"}
1
+ {"version":3,"file":"replay.d.ts","sourceRoot":"","sources":["../../src/cli/replay.ts"],"names":[],"mappings":"AAQA,yBACE,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE;IAAE,EAAE,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,iBA4BvE"}
package/lib/cli/replay.js CHANGED
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -16,23 +7,21 @@ const build_1 = __importDefault(require("../cli/build"));
16
7
  const replay_1 = require("../replay");
17
8
  const session_1 = require("../session");
18
9
  const use_execution_mode_1 = require("../use-execution-mode");
10
+ const use_timestamp_1 = require("../use-timestamp");
19
11
  const script_1 = require("./internal/script");
20
- function default_1(name, options) {
21
- var _a, _b;
22
- return __awaiter(this, void 0, void 0, function* () {
23
- if (yield (0, build_1.default)()) {
24
- return;
25
- }
26
- const from = options.from ? new Date(options.from).getTime() : 0;
27
- const to = options.to ? new Date(options.to).getTime() : 1893452400; // 01-01-2030;
28
- const storage = (_a = options.storage) !== null && _a !== void 0 ? _a : 'backtest';
29
- const script = new script_1.Script(name, [
30
- session_1.useSession.options({ id: (_b = options.id) !== null && _b !== void 0 ? _b : Date.now().toString() }),
31
- (0, replay_1.replayOptions)({ from, to, storage }),
32
- use_execution_mode_1.useExecutionMode.replayOptions()
33
- ]);
34
- const output = yield script.run();
35
- console.log(output);
36
- });
12
+ async function default_1(name, options) {
13
+ if (await (0, build_1.default)()) {
14
+ return;
15
+ }
16
+ const from = (0, use_timestamp_1.convert)((0, use_timestamp_1.s)(options.from ? new Date(options.from).getTime() : 0), 'ms', 'ns');
17
+ const to = (0, use_timestamp_1.convert)((0, use_timestamp_1.s)(options.to ? new Date(options.to).getTime() : new Date().getTime()), 'ms', 'ns');
18
+ const storage = options.storage ?? 'backtest';
19
+ const script = new script_1.Script(name, [
20
+ session_1.useSession.options({ id: options.id ?? Date.now().toString() }),
21
+ (0, replay_1.replayOptions)({ from, to, storage }),
22
+ use_execution_mode_1.useExecutionMode.replayOptions()
23
+ ]);
24
+ const output = await script.run();
25
+ console.log(output);
37
26
  }
38
27
  exports.default = default_1;
package/lib/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from './component';
1
+ export * from './app';
2
2
  export * from './shared';
3
3
  export * from './storage';
4
4
  export * from './module';
@@ -6,18 +6,13 @@ export * from './use-memo';
6
6
  export * from './use-timestamp';
7
7
  export * from './simulator';
8
8
  export * from './make-test-module';
9
- export * from './core';
10
9
  export * from './use-execution-mode';
11
10
  export * from './storage';
12
11
  export * from './use-logger';
13
12
  export * from './replay';
14
13
  export * from './use-socket';
15
- export * from './when-socket';
16
14
  export * from './with-request';
17
- export * from './with-memo';
18
15
  export * from './session';
19
- export * from './strategy';
20
- export * from './operators';
21
16
  export * from './replay';
22
17
  export * from './uri';
23
18
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,WAAW,CAAC;AAC1B,cAAc,yBAAyB,CAAC;AACxC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC"}
package/lib/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./component"), exports);
17
+ __exportStar(require("./app"), exports);
18
18
  __exportStar(require("./shared"), exports);
19
19
  __exportStar(require("./storage"), exports);
20
20
  __exportStar(require("./module"), exports);
@@ -22,17 +22,12 @@ __exportStar(require("./use-memo"), exports);
22
22
  __exportStar(require("./use-timestamp"), exports);
23
23
  __exportStar(require("./simulator"), exports);
24
24
  __exportStar(require("./make-test-module"), exports);
25
- __exportStar(require("./core"), exports);
26
25
  __exportStar(require("./use-execution-mode"), exports);
27
26
  __exportStar(require("./storage"), exports);
28
27
  __exportStar(require("./use-logger"), exports);
29
28
  __exportStar(require("./replay"), exports);
30
29
  __exportStar(require("./use-socket"), exports);
31
- __exportStar(require("./when-socket"), exports);
32
30
  __exportStar(require("./with-request"), exports);
33
- __exportStar(require("./with-memo"), exports);
34
31
  __exportStar(require("./session"), exports);
35
- __exportStar(require("./strategy"), exports);
36
- __exportStar(require("./operators"), exports);
37
32
  __exportStar(require("./replay"), exports);
38
33
  __exportStar(require("./uri"), exports);
@@ -1,14 +1,9 @@
1
- /// <reference types="jest" />
2
- import { Observable, Subject } from 'rxjs';
1
+ import { Observable } from 'rxjs';
3
2
  import { Dependency } from './module';
4
3
  export declare function makeTestModule(dependencies: Dependency[]): Promise<{
5
4
  act: <T>(func: () => T) => T;
6
5
  get: <T_1>(token: import("tsyringe/dist/typings/providers/injection-token").default<T_1>) => T_1;
7
6
  }>;
8
- type MockableFunction = (...args: any[]) => any;
9
- export declare const mockedFunc: <Func extends MockableFunction>(mockedFunc: Func) => jest.MockedFunction<Func>;
10
7
  export declare function toArray<T>(observable: Observable<T>): (Error | T)[];
11
8
  export type InferObservableType<T> = T extends Observable<infer U> ? U : never;
12
- export declare function mockSubject<T extends jest.FunctionProperties<Required<T>>, M extends keyof jest.FunctionProperties<Required<T>>>(object: T, method: M): Subject<InferObservableType<ReturnType<jest.FunctionProperties<Required<T>>[M]>>>;
13
- export {};
14
9
  //# sourceMappingURL=make-test-module.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"make-test-module.d.ts","sourceRoot":"","sources":["../src/make-test-module.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAG3C,OAAO,EAAE,UAAU,EAAU,MAAM,aAAa,CAAC;AAEjD,wBAAsB,cAAc,CAAC,YAAY,EAAE,UAAU,EAAE;;;GAS9D;AAED,KAAK,gBAAgB,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;AAEhD,eAAO,MAAM,UAAU,gFAC+B,CAAC;AAEvD,wBAAgB,OAAO,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,iBAyBnD;AAED,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CAAC,SAAS,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAE/E,wBAAgB,WAAW,CACzB,CAAC,SAAS,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAC9C,CAAC,SAAS,MAAM,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EACpD,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,qFAQrB"}
1
+ {"version":3,"file":"make-test-module.d.ts","sourceRoot":"","sources":["../src/make-test-module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAAE,UAAU,EAAU,MAAM,aAAa,CAAC;AAOjD,wBAAsB,cAAc,CAAC,YAAY,EAAE,UAAU,EAAE;;;GAe9D;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,iBAyBnD;AAED,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CAAC,SAAS,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC"}
@@ -1,31 +1,26 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.mockSubject = exports.toArray = exports.mockedFunc = exports.makeTestModule = void 0;
13
- const rxjs_1 = require("rxjs");
14
- const core_1 = require("./core");
3
+ exports.toArray = exports.makeTestModule = void 0;
15
4
  const module_1 = require("./module");
16
- function makeTestModule(dependencies) {
17
- return __awaiter(this, void 0, void 0, function* () {
18
- const module = new module_1.Module([...(0, core_1.core)(), ...dependencies]);
19
- const { act } = yield module.awake();
20
- return {
21
- act,
22
- get: module.get.bind(module)
23
- };
24
- });
5
+ const storage_1 = require("./storage");
6
+ const use_execution_mode_1 = require("./use-execution-mode");
7
+ const use_logger_1 = require("./use-logger");
8
+ const use_memo_1 = require("./use-memo");
9
+ async function makeTestModule(dependencies) {
10
+ const module = new module_1.Module([
11
+ use_memo_1.useMemo.options(),
12
+ (0, use_logger_1.logger)(new use_logger_1.ConsoleLoggerFactory()),
13
+ use_execution_mode_1.useExecutionMode.paperOptions({ recording: false }),
14
+ storage_1.useStorageFactory.options(new storage_1.InMemoryStorageFactory()),
15
+ ...dependencies
16
+ ]);
17
+ const { act } = await module.awake();
18
+ return {
19
+ act,
20
+ get: module.get.bind(module)
21
+ };
25
22
  }
26
23
  exports.makeTestModule = makeTestModule;
27
- const mockedFunc = (mockedFunc) => mockedFunc;
28
- exports.mockedFunc = mockedFunc;
29
24
  function toArray(observable) {
30
25
  const array = Array.of();
31
26
  const clone = (it) => {
@@ -36,7 +31,7 @@ function toArray(observable) {
36
31
  return it.map(it => clone(it));
37
32
  }
38
33
  if (typeof it === 'object') {
39
- return Object.assign({}, it);
34
+ return { ...it };
40
35
  }
41
36
  return it;
42
37
  };
@@ -47,9 +42,3 @@ function toArray(observable) {
47
42
  return array;
48
43
  }
49
44
  exports.toArray = toArray;
50
- function mockSubject(object, method) {
51
- const subject = new rxjs_1.Subject();
52
- jest.spyOn(object, method).mockReturnValue(subject.asObservable());
53
- return subject;
54
- }
55
- exports.mockSubject = mockSubject;
@@ -1 +1 @@
1
- {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":";AAAA,OAAO,kBAAkB,CAAC;AAE1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAEL,mBAAmB,EACnB,MAAM,EACN,UAAU,EACV,SAAS,EACT,cAAc,EAEf,MAAM,UAAU,CAAC;AAElB,eAAO,MAAM,QAAQ,mBAAa,CAAC;AACnC,eAAO,MAAM,OAAO,eAAS,CAAC;AAC9B,eAAO,MAAM,UAAU,kBAAY,CAAC;AAEpC,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,cAAc,CAAC;IACxB,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,QAAQ,CAAC,EAAE,GAAG,CAAC;CAChB,CAAC;AAuBF,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,iBAAiB,CAAC,MAAM,CAAC,QAElE;AAED;;GAEG;AACH,eAAO,MAAM,UAAU,oCAQtB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,YAI5B,CAAC;AAEF;;;GAGG;AACH,qBAAa,MAAM;IAGL,OAAO,CAAC,QAAQ,CAAC,YAAY;IAFzC,OAAO,CAAC,SAAS,CAAC,CAAsB;gBAEX,YAAY,EAAE,UAAU,EAAE;IAEvD;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC;QAAE,GAAG,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;KAAE,CAAC;IAWxD;;;OAGG;IACH,OAAO;IAQP;;;OAGG;IACH,SAAS,CAAC,cAAc,IAAI,mBAAmB;IAgB/C;;;;;OAKG;IACH,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC;IAYnC;;;;OAIG;IACH,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE;CAWzC"}
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":";AAAA,OAAO,kBAAkB,CAAC;AAE1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAEL,mBAAmB,EACnB,MAAM,EACN,UAAU,EACV,SAAS,EACT,cAAc,EAEf,MAAM,UAAU,CAAC;AAElB,eAAO,MAAM,QAAQ,mBAAa,CAAC;AACnC,eAAO,MAAM,OAAO,eAAS,CAAC;AAC9B,eAAO,MAAM,UAAU,kBAAY,CAAC;AAEpC,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,cAAc,CAAC;IACxB,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,QAAQ,CAAC,EAAE,GAAG,CAAC;CAChB,CAAC;AAoBF,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,iBAAiB,CAAC,MAAM,CAAC,QAElE;AAED;;GAEG;AACH,eAAO,MAAM,UAAU,oCAQtB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,YAI5B,CAAC;AAEF;;;GAGG;AACH,qBAAa,MAAM;IAGL,OAAO,CAAC,QAAQ,CAAC,YAAY;IAFzC,OAAO,CAAC,SAAS,CAAC,CAAsB;gBAEX,YAAY,EAAE,UAAU,EAAE;IAEvD;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC;QAAE,GAAG,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;KAAE,CAAC;IAWxD;;;OAGG;IACH,OAAO;IAQP;;;OAGG;IACH,SAAS,CAAC,cAAc,IAAI,mBAAmB;IAgB/C;;;;;OAKG;IACH,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC;IAYnC;;;;OAIG;IACH,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE;CAWzC"}
package/lib/module.js CHANGED
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.Module = exports.throwWithContext = exports.useContext = exports.setAsyncLocalStorage = exports.provideAll = exports.provide = exports.provider = void 0;
13
4
  require("reflect-metadata");
@@ -28,9 +19,6 @@ function notInitializedModuleError() {
28
19
  function missingInjectionTokenError(token) {
29
20
  return new Error(`Unable to resolve unregistered dependency: ${token.toString()}`);
30
21
  }
31
- /**
32
- *
33
- */
34
22
  let moduleLocalStorage = new node_async_hooks_1.AsyncLocalStorage();
35
23
  function setAsyncLocalStorage(als) {
36
24
  moduleLocalStorage = als;
@@ -67,16 +55,14 @@ class Module {
67
55
  /**
68
56
  * Builds and initializes dependencies.
69
57
  */
70
- awake() {
71
- return __awaiter(this, void 0, void 0, function* () {
72
- this.container = this.buildContainer();
73
- return {
74
- /**
75
- * Associate callback function with current executing module
76
- */
77
- act: (func) => moduleLocalStorage.run(this, func)
78
- };
79
- });
58
+ async awake() {
59
+ this.container = this.buildContainer();
60
+ return {
61
+ /**
62
+ * Associate callback function with current executing module
63
+ */
64
+ act: (func) => moduleLocalStorage.run(this, func)
65
+ };
80
66
  }
81
67
  /**
82
68
  * Disposes all dependencies instantiated by this module.
@@ -95,12 +81,11 @@ class Module {
95
81
  buildContainer() {
96
82
  const childContainer = tsyringe_1.container.createChildContainer();
97
83
  this.dependencies.forEach(it => {
98
- var _a;
99
84
  if (it.useValue) {
100
85
  childContainer.register(it.provide, { useValue: it.useValue });
101
86
  }
102
87
  else {
103
- childContainer.register(it.provide, (_a = it.useClass) !== null && _a !== void 0 ? _a : it.provide, {
88
+ childContainer.register(it.provide, it.useClass ?? it.provide, {
104
89
  lifecycle: tsyringe_1.Lifecycle.Singleton
105
90
  });
106
91
  }
@@ -5,15 +5,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
7
  };
8
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
- return new (P || (P = Promise))(function (resolve, reject) {
11
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
- step((generator = generator.apply(thisArg, _arguments || [])).next());
15
- });
16
- };
17
8
  Object.defineProperty(exports, "__esModule", { value: true });
18
9
  const module_1 = require("./module");
19
10
  describe(module_1.Module.name, () => {
@@ -21,28 +12,28 @@ describe(module_1.Module.name, () => {
21
12
  beforeEach(() => {
22
13
  fixtures = getFixtures();
23
14
  });
24
- test('builds empty module', () => __awaiter(void 0, void 0, void 0, function* () {
15
+ test('builds empty module', async () => {
25
16
  const module = fixtures.givenModuleCreated([]);
26
17
  fixtures.whenModuleBuilt(module);
27
- }));
28
- test('builds module and resolves single value dependency', () => __awaiter(void 0, void 0, void 0, function* () {
18
+ });
19
+ test('builds module and resolves single value dependency', async () => {
29
20
  const definition = fixtures.definitions.singleValue;
30
21
  const module = fixtures.givenModuleCreated(definition);
31
22
  fixtures.whenModuleBuilt(module);
32
23
  fixtures.thenCanResolveDependencies(module, definition);
33
- }));
34
- test('builds module and resolves single class dependency', () => __awaiter(void 0, void 0, void 0, function* () {
24
+ });
25
+ test('builds module and resolves single class dependency', async () => {
35
26
  const definition = fixtures.definitions.singleClass;
36
27
  const module = fixtures.givenModuleCreated(definition);
37
28
  fixtures.whenModuleBuilt(module);
38
29
  fixtures.thenCanResolveDependencies(module, definition);
39
- }));
40
- test('builds module and resolves many class dependencies', () => __awaiter(void 0, void 0, void 0, function* () {
30
+ });
31
+ test('builds module and resolves many class dependencies', async () => {
41
32
  const definition = fixtures.definitions.manyClass;
42
33
  const module = fixtures.givenModuleCreated(definition);
43
34
  fixtures.whenModuleBuilt(module);
44
35
  fixtures.thenCanResolveDependencies(module, definition);
45
- }));
36
+ });
46
37
  });
47
38
  function getFixtures() {
48
39
  return {