@quantform/core 0.7.0-beta.4 → 0.7.0-beta.41

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 (179) hide show
  1. package/dist/asset/asset.d.ts +3 -0
  2. package/dist/asset/asset.d.ts.map +1 -1
  3. package/dist/asset/asset.js +7 -1
  4. package/dist/cli/dev.d.ts.map +1 -1
  5. package/dist/cli/dev.js +3 -36
  6. package/dist/cli/internal/script.d.ts +8 -0
  7. package/dist/cli/internal/script.d.ts.map +1 -0
  8. package/dist/cli/internal/script.js +58 -0
  9. package/dist/cli/pull.d.ts.map +1 -1
  10. package/dist/cli/pull.js +4 -83
  11. package/dist/cli/replay.d.ts.map +1 -1
  12. package/dist/cli/replay.js +3 -35
  13. package/dist/cli/run.d.ts.map +1 -1
  14. package/dist/cli/run.js +3 -37
  15. package/dist/index.d.ts +5 -14
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +5 -14
  18. package/dist/instrument/instrument.d.ts +3 -0
  19. package/dist/instrument/instrument.d.ts.map +1 -1
  20. package/dist/instrument/instrument.js +7 -1
  21. package/dist/make-test-module.d.ts +3 -2
  22. package/dist/make-test-module.d.ts.map +1 -1
  23. package/dist/make-test-module.js +13 -2
  24. package/dist/operators.d.ts +5 -0
  25. package/dist/operators.d.ts.map +1 -0
  26. package/dist/operators.js +16 -0
  27. package/dist/replay/index.d.ts +6 -4
  28. package/dist/replay/index.d.ts.map +1 -1
  29. package/dist/replay/index.js +6 -4
  30. package/dist/replay/replay-guard.d.ts +10 -0
  31. package/dist/replay/replay-guard.d.ts.map +1 -0
  32. package/dist/replay/replay-guard.js +8 -0
  33. package/dist/replay/replay.d.ts +10 -0
  34. package/dist/replay/replay.d.ts.map +1 -0
  35. package/dist/replay/replay.js +9 -0
  36. package/dist/replay/use-replay-breakpoint.d.ts +3 -0
  37. package/dist/replay/use-replay-breakpoint.d.ts.map +1 -0
  38. package/dist/replay/use-replay-breakpoint.js +22 -0
  39. package/dist/replay/use-replay-manager.d.ts +12 -0
  40. package/dist/replay/use-replay-manager.d.ts.map +1 -0
  41. package/dist/replay/use-replay-manager.js +88 -0
  42. package/dist/replay/use-replay-storage-buffer.d.ts +15 -0
  43. package/dist/replay/use-replay-storage-buffer.d.ts.map +1 -0
  44. package/dist/replay/use-replay-storage-buffer.js +50 -0
  45. package/dist/replay/use-replay-storage.d.ts +11 -8
  46. package/dist/replay/use-replay-storage.d.ts.map +1 -1
  47. package/dist/replay/use-replay-storage.js +34 -5
  48. package/dist/replay/use-replay-storage.spec.d.ts +2 -0
  49. package/dist/replay/use-replay-storage.spec.d.ts.map +1 -0
  50. package/dist/replay/use-replay-storage.spec.js +74 -0
  51. package/dist/replay/use-replay.d.ts +2 -2
  52. package/dist/replay/use-replay.d.ts.map +1 -1
  53. package/dist/replay/use-replay.js +8 -20
  54. package/dist/replay/use-replay.spec.js +125 -101
  55. package/dist/session/use-session-storage.js +2 -2
  56. package/dist/session/use-session.js +2 -2
  57. package/dist/storage/index.d.ts +1 -0
  58. package/dist/storage/index.d.ts.map +1 -1
  59. package/dist/storage/index.js +1 -0
  60. package/dist/storage/use-storage.d.ts.map +1 -1
  61. package/dist/storage/use-storage.js +2 -2
  62. package/dist/use-execution-mode.d.ts +6 -1
  63. package/dist/use-execution-mode.d.ts.map +1 -1
  64. package/dist/use-execution-mode.js +16 -8
  65. package/dist/use-logger.js +4 -4
  66. package/dist/use-memo.d.ts +0 -10
  67. package/dist/use-memo.d.ts.map +1 -1
  68. package/dist/use-memo.js +0 -10
  69. package/dist/use-timestamp.js +2 -2
  70. package/dist/when-socket.d.ts +8 -0
  71. package/dist/when-socket.d.ts.map +1 -0
  72. package/dist/{use-socket.js → when-socket.js} +6 -5
  73. package/dist/with-memo.d.ts +5 -0
  74. package/dist/with-memo.d.ts.map +1 -0
  75. package/dist/{use.js → with-memo.js} +5 -5
  76. package/dist/with-memo.spec.d.ts +2 -0
  77. package/dist/with-memo.spec.d.ts.map +1 -0
  78. package/dist/{use.spec.js → with-memo.spec.js} +3 -3
  79. package/dist/{use-request.d.ts → with-request.d.ts} +5 -4
  80. package/dist/with-request.d.ts.map +1 -0
  81. package/dist/with-request.js +69 -0
  82. package/package.json +1 -1
  83. package/src/asset/asset.ts +6 -0
  84. package/src/cli/dev.ts +4 -20
  85. package/src/cli/internal/script.ts +49 -0
  86. package/src/cli/pull.ts +6 -66
  87. package/src/cli/replay.ts +4 -16
  88. package/src/cli/run.ts +4 -18
  89. package/src/index.ts +5 -14
  90. package/src/instrument/instrument.ts +6 -0
  91. package/src/make-test-module.ts +24 -4
  92. package/src/operators.ts +18 -0
  93. package/src/replay/index.ts +6 -4
  94. package/src/replay/replay-guard.ts +11 -0
  95. package/src/replay/replay.ts +13 -0
  96. package/src/replay/use-replay-breakpoint.ts +29 -0
  97. package/src/replay/use-replay-manager.ts +106 -0
  98. package/src/replay/use-replay-storage-buffer.ts +43 -0
  99. package/src/replay/use-replay-storage.spec.ts +85 -0
  100. package/src/replay/use-replay-storage.ts +26 -5
  101. package/src/replay/use-replay.spec.ts +10 -3
  102. package/src/replay/use-replay.ts +11 -17
  103. package/src/session/use-session-storage.ts +2 -2
  104. package/src/session/use-session.ts +2 -2
  105. package/src/storage/index.ts +1 -0
  106. package/src/storage/use-storage.ts +2 -2
  107. package/src/use-execution-mode.ts +16 -8
  108. package/src/use-logger.ts +4 -4
  109. package/src/use-memo.ts +0 -10
  110. package/src/use-timestamp.ts +2 -2
  111. package/src/{use-socket.ts → when-socket.ts} +6 -4
  112. package/src/{use.spec.ts → with-memo.spec.ts} +3 -3
  113. package/src/{use.ts → with-memo.ts} +4 -4
  114. package/src/with-request.ts +83 -0
  115. package/dist/as-readonly.d.ts +0 -3
  116. package/dist/as-readonly.d.ts.map +0 -1
  117. package/dist/as-readonly.js +0 -8
  118. package/dist/defined.d.ts +0 -3
  119. package/dist/defined.d.ts.map +0 -1
  120. package/dist/defined.js +0 -8
  121. package/dist/exclude.d.ts +0 -3
  122. package/dist/exclude.d.ts.map +0 -1
  123. package/dist/exclude.js +0 -8
  124. package/dist/not-found.d.ts +0 -2
  125. package/dist/not-found.d.ts.map +0 -1
  126. package/dist/not-found.js +0 -4
  127. package/dist/replay/use-replay-coordinator.d.ts +0 -10
  128. package/dist/replay/use-replay-coordinator.d.ts.map +0 -1
  129. package/dist/replay/use-replay-coordinator.js +0 -119
  130. package/dist/replay/use-replay-reader.d.ts +0 -7
  131. package/dist/replay/use-replay-reader.d.ts.map +0 -1
  132. package/dist/replay/use-replay-reader.js +0 -32
  133. package/dist/replay/use-replay-reader.spec.d.ts +0 -2
  134. package/dist/replay/use-replay-reader.spec.d.ts.map +0 -1
  135. package/dist/replay/use-replay-reader.spec.js +0 -58
  136. package/dist/replay/use-replay-writer.d.ts +0 -6
  137. package/dist/replay/use-replay-writer.d.ts.map +0 -1
  138. package/dist/replay/use-replay-writer.js +0 -14
  139. package/dist/replay/use-replay-writer.spec.d.ts +0 -2
  140. package/dist/replay/use-replay-writer.spec.d.ts.map +0 -1
  141. package/dist/replay/use-replay-writer.spec.js +0 -53
  142. package/dist/replay/with-replay.d.ts +0 -4
  143. package/dist/replay/with-replay.d.ts.map +0 -1
  144. package/dist/replay/with-replay.js +0 -8
  145. package/dist/strat.d.ts +0 -7
  146. package/dist/strat.d.ts.map +0 -1
  147. package/dist/strat.js +0 -7
  148. package/dist/use-lock.d.ts +0 -9
  149. package/dist/use-lock.d.ts.map +0 -1
  150. package/dist/use-lock.js +0 -40
  151. package/dist/use-request.d.ts.map +0 -1
  152. package/dist/use-request.js +0 -27
  153. package/dist/use-socket.d.ts +0 -6
  154. package/dist/use-socket.d.ts.map +0 -1
  155. package/dist/use-state.d.ts +0 -4
  156. package/dist/use-state.d.ts.map +0 -1
  157. package/dist/use-state.js +0 -24
  158. package/dist/use-state.spec.d.ts +0 -2
  159. package/dist/use-state.spec.d.ts.map +0 -1
  160. package/dist/use-state.spec.js +0 -36
  161. package/dist/use.d.ts +0 -5
  162. package/dist/use.d.ts.map +0 -1
  163. package/dist/use.spec.d.ts +0 -2
  164. package/dist/use.spec.d.ts.map +0 -1
  165. package/src/as-readonly.ts +0 -5
  166. package/src/defined.ts +0 -6
  167. package/src/exclude.ts +0 -9
  168. package/src/not-found.ts +0 -1
  169. package/src/replay/use-replay-coordinator.ts +0 -142
  170. package/src/replay/use-replay-reader.spec.ts +0 -64
  171. package/src/replay/use-replay-reader.ts +0 -23
  172. package/src/replay/use-replay-writer.spec.ts +0 -56
  173. package/src/replay/use-replay-writer.ts +0 -17
  174. package/src/replay/with-replay.ts +0 -10
  175. package/src/strat.ts +0 -7
  176. package/src/use-lock.ts +0 -52
  177. package/src/use-request.ts +0 -47
  178. package/src/use-state.spec.ts +0 -31
  179. package/src/use-state.ts +0 -30
@@ -0,0 +1,10 @@
1
+ import { Observable } from 'rxjs';
2
+ import { dependency } from '../use-hash';
3
+ export declare function replayGuard<T extends Array<dependency>, K>(fn: (...args: T) => Observable<{
4
+ timestamp: number;
5
+ payload: K;
6
+ }>): (...args: T) => Observable<{
7
+ timestamp: number;
8
+ payload: K;
9
+ }>;
10
+ //# sourceMappingURL=replay-guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replay-guard.d.ts","sourceRoot":"","sources":["../../src/replay/replay-guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAI3C,wBAAgB,WAAW,CAAC,CAAC,SAAS,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,EACxD,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,UAAU,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,CAAC,CAAA;CAAE,CAAC,GAChE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,UAAU,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,CAAC,CAAA;CAAE,CAAC,CAE/D"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.replayGuard = void 0;
4
+ const use_replay_breakpoint_1 = require("./use-replay-breakpoint");
5
+ function replayGuard(fn) {
6
+ return (...args) => (0, use_replay_breakpoint_1.useReplayBreakpoint)(fn(...args));
7
+ }
8
+ exports.replayGuard = replayGuard;
@@ -0,0 +1,10 @@
1
+ import { Observable } from 'rxjs';
2
+ import { dependency } from '../use-hash';
3
+ export declare function replay<T extends Array<dependency>, K>(fn: (...args: T) => Observable<{
4
+ timestamp: number;
5
+ payload: K;
6
+ }>, dependencies: dependency[]): (...args: T) => Observable<{
7
+ timestamp: number;
8
+ payload: K;
9
+ }>;
10
+ //# sourceMappingURL=replay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replay.d.ts","sourceRoot":"","sources":["../../src/replay/replay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAK3C,wBAAgB,MAAM,CAAC,CAAC,SAAS,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,EACnD,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,UAAU,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,CAAC,CAAA;CAAE,CAAC,EACjE,YAAY,EAAE,UAAU,EAAE,GACzB,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,UAAU,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,CAAC,CAAA;CAAE,CAAC,CAE/D"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.replay = void 0;
4
+ const with_memo_1 = require("../with-memo");
5
+ const use_replay_1 = require("./use-replay");
6
+ function replay(fn, dependencies) {
7
+ return (0, with_memo_1.withMemo)((...args) => (0, use_replay_1.useReplay)(fn(...args), [...dependencies, ...args]));
8
+ }
9
+ exports.replay = replay;
@@ -0,0 +1,3 @@
1
+ import { Observable } from 'rxjs';
2
+ export declare function useReplayBreakpoint<T>(input: Observable<T>): Observable<T>;
3
+ //# sourceMappingURL=use-replay-breakpoint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-replay-breakpoint.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay-breakpoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,UAAU,EAAE,MAAM,MAAM,CAAC;AAO5C,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAqB1E"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useReplayBreakpoint = void 0;
4
+ const rxjs_1 = require("rxjs");
5
+ const use_execution_mode_1 = require("../use-execution-mode");
6
+ const use_logger_1 = require("../use-logger");
7
+ const use_replay_manager_1 = require("./use-replay-manager");
8
+ function useReplayBreakpoint(input) {
9
+ const { isReplay } = (0, use_execution_mode_1.useExecutionMode)();
10
+ if (!isReplay) {
11
+ return input;
12
+ }
13
+ const { info } = (0, use_logger_1.useLogger)('useReplayBreakpoint');
14
+ const { stop, tryContinue } = (0, use_replay_manager_1.useReplayManager)();
15
+ info('locking resource...');
16
+ stop();
17
+ return input.pipe((0, rxjs_1.finalize)(() => {
18
+ info('unlocking resource');
19
+ tryContinue();
20
+ }));
21
+ }
22
+ exports.useReplayBreakpoint = useReplayBreakpoint;
@@ -0,0 +1,12 @@
1
+ import { Observable } from 'rxjs';
2
+ import { dependency } from '../use-hash';
3
+ export declare const useReplayManager: () => {
4
+ timestamp(): number;
5
+ stop(): void;
6
+ tryContinue: () => void;
7
+ when<T>(dependencies: dependency[]): Observable<{
8
+ timestamp: number;
9
+ payload: T;
10
+ }>;
11
+ };
12
+ //# sourceMappingURL=use-replay-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-replay-manager.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,UAAU,EAAW,MAAM,MAAM,CAAC;AAE/D,OAAO,EAAE,UAAU,EAAW,MAAM,eAAe,CAAC;AAOpD,eAAO,MAAM,gBAAgB;;;;0BA8EH,UAAU,EAAE;mBAA2B,MAAM;;;CAkBrE,CAAC"}
@@ -0,0 +1,88 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.useReplayManager = void 0;
13
+ const rxjs_1 = require("rxjs");
14
+ const use_hash_1 = require("../use-hash");
15
+ const use_logger_1 = require("../use-logger");
16
+ const with_memo_1 = require("../with-memo");
17
+ const use_replay_options_1 = require("./use-replay-options");
18
+ const use_replay_storage_buffer_1 = require("./use-replay-storage-buffer");
19
+ exports.useReplayManager = (0, with_memo_1.withMemo)(() => {
20
+ const { from, to } = (0, use_replay_options_1.useReplayOptions)();
21
+ const { info } = (0, use_logger_1.useLogger)('useReplayManager');
22
+ let timestamp = from;
23
+ let stopAcquire = 1;
24
+ const subscriptions = Array.of();
25
+ const stream$ = new rxjs_1.Subject();
26
+ const getNextStorage = () => __awaiter(void 0, void 0, void 0, function* () {
27
+ let next;
28
+ for (const cursor of subscriptions) {
29
+ if (cursor.size() == 0 && !cursor.completed()) {
30
+ yield cursor.fetchNextPage(timestamp, to + 1);
31
+ }
32
+ if (cursor.peek()) {
33
+ if (!next || next.peek().timestamp > cursor.peek().timestamp) {
34
+ next = cursor;
35
+ }
36
+ }
37
+ }
38
+ return next;
39
+ });
40
+ const processNext = () => __awaiter(void 0, void 0, void 0, function* () {
41
+ const cursor = yield getNextStorage();
42
+ if (!cursor || !cursor.peek()) {
43
+ stream$.complete();
44
+ return false;
45
+ }
46
+ const sample = cursor.dequeue();
47
+ timestamp = sample.timestamp;
48
+ stream$.next([cursor, sample]);
49
+ return true;
50
+ });
51
+ const next = () => __awaiter(void 0, void 0, void 0, function* () {
52
+ if (yield processNext()) {
53
+ if (stopAcquire === 0) {
54
+ setImmediate(next);
55
+ }
56
+ }
57
+ });
58
+ const tryContinue = () => {
59
+ if (stopAcquire == 0) {
60
+ return;
61
+ }
62
+ stopAcquire = Math.max(0, stopAcquire - 1);
63
+ if (stopAcquire != 0) {
64
+ return;
65
+ }
66
+ next();
67
+ };
68
+ return {
69
+ timestamp() {
70
+ return timestamp;
71
+ },
72
+ stop() {
73
+ stopAcquire++;
74
+ },
75
+ tryContinue,
76
+ when(dependencies) {
77
+ const storage = (0, use_replay_storage_buffer_1.useReplayStorageBuffer)(dependencies);
78
+ if (!subscriptions.includes(storage)) {
79
+ info('subscribing to replay', (0, use_hash_1.useHash)(dependencies));
80
+ subscriptions.push(storage);
81
+ }
82
+ return (0, rxjs_1.defer)(() => {
83
+ tryContinue();
84
+ return stream$.pipe((0, rxjs_1.filter)(([cur]) => cur === storage), (0, rxjs_1.map)(([, it]) => ({ timestamp: it.timestamp, payload: it.payload })));
85
+ });
86
+ }
87
+ };
88
+ });
@@ -0,0 +1,15 @@
1
+ import { dependency } from '../use-hash';
2
+ export declare const useReplayStorageBuffer: <T>(dependencies: dependency[]) => {
3
+ size(): number;
4
+ peek(): {
5
+ timestamp: number;
6
+ payload: T;
7
+ };
8
+ dequeue(): {
9
+ timestamp: number;
10
+ payload: T;
11
+ };
12
+ completed(): boolean;
13
+ fetchNextPage(from: number, to: number): Promise<void>;
14
+ };
15
+ //# sourceMappingURL=use-replay-storage-buffer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-replay-storage-buffer.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay-storage-buffer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAK3C,eAAO,MAAM,sBAAsB;;;mBAGC,MAAM;;;;mBAAN,MAAM;;;;wBAiBZ,MAAM,MAAM,MAAM;CAgB9C,CAAC"}
@@ -0,0 +1,50 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.useReplayStorageBuffer = void 0;
13
+ const storage_1 = require("../storage");
14
+ const with_memo_1 = require("../with-memo");
15
+ const use_replay_storage_1 = require("./use-replay-storage");
16
+ exports.useReplayStorageBuffer = (0, with_memo_1.withMemo)((dependencies) => {
17
+ const { query } = (0, use_replay_storage_1.useReplayStorage)(dependencies);
18
+ let page = new Array();
19
+ let index = 0;
20
+ let completed = false;
21
+ return {
22
+ size() {
23
+ return page.length - index;
24
+ },
25
+ peek() {
26
+ return page[index];
27
+ },
28
+ dequeue() {
29
+ return page[index++];
30
+ },
31
+ completed() {
32
+ return completed;
33
+ },
34
+ fetchNextPage(from, to) {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ if (completed) {
37
+ return;
38
+ }
39
+ index = 0;
40
+ page = yield query({
41
+ where: {
42
+ timestamp: (0, storage_1.between)(from, to)
43
+ },
44
+ limit: 10000
45
+ });
46
+ completed = page.length == 0;
47
+ });
48
+ }
49
+ };
50
+ });
@@ -1,10 +1,13 @@
1
- import { Storage } from '../storage';
2
- export declare const replaySerializableObject: (key: string) => {
3
- discriminator: string;
4
- type: {
5
- timestamp: "number";
6
- json: "string";
7
- };
1
+ import { Query, QueryObject } from '../storage';
2
+ import { dependency } from '../use-hash';
3
+ export declare function useReplayStorage<T>(dependencies: dependency[]): {
4
+ query(query: Query<QueryObject>): Promise<{
5
+ timestamp: number;
6
+ payload: T;
7
+ }[]>;
8
+ save(objects: {
9
+ timestamp: number;
10
+ payload: T;
11
+ }[]): Promise<void>;
8
12
  };
9
- export declare function useReplayStorage(): Storage;
10
13
  //# sourceMappingURL=use-replay-storage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-replay-storage.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAc,MAAM,cAAc,CAAC;AAEnD,eAAO,MAAM,wBAAwB,QAAS,MAAM;;;;;;CACgB,CAAC;AAErE,wBAAgB,gBAAgB,YAE/B"}
1
+ {"version":3,"file":"use-replay-storage.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAuB,MAAM,cAAc,CAAC;AACvE,OAAO,EAAE,UAAU,EAAW,MAAM,eAAe,CAAC;AAEpD,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,YAAY,EAAE,UAAU,EAAE;iBASvC,MAAM,WAAW,CAAC;;;;kBAMvB;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,CAAC,CAAA;KAAE,EAAE;EAUpD"}
@@ -1,10 +1,39 @@
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
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useReplayStorage = exports.replaySerializableObject = void 0;
12
+ exports.useReplayStorage = void 0;
4
13
  const storage_1 = require("../storage");
5
- const replaySerializableObject = (key) => storage_1.Storage.createObject(key, { timestamp: 'number', json: 'string' });
6
- exports.replaySerializableObject = replaySerializableObject;
7
- function useReplayStorage() {
8
- return (0, storage_1.useStorage)(['replay']);
14
+ const use_hash_1 = require("../use-hash");
15
+ function useReplayStorage(dependencies) {
16
+ const storage = (0, storage_1.useStorage)(['replay']);
17
+ const storageObjectKey = (0, use_hash_1.useHash)(dependencies);
18
+ const storageObject = storage_1.Storage.createObject(storageObjectKey, {
19
+ timestamp: 'number',
20
+ payload: 'string'
21
+ });
22
+ return {
23
+ query(query) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ return (yield storage.query(storageObject, query)).map(it => ({
26
+ timestamp: it.timestamp,
27
+ payload: JSON.parse(it.payload)
28
+ }));
29
+ });
30
+ },
31
+ save(objects) {
32
+ return storage.save(storageObject, objects.map(it => ({
33
+ timestamp: it.timestamp,
34
+ payload: JSON.stringify(it.payload)
35
+ })));
36
+ }
37
+ };
9
38
  }
10
39
  exports.useReplayStorage = useReplayStorage;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=use-replay-storage.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-replay-storage.spec.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay-storage.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,74 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const make_test_module_1 = require("../make-test-module");
13
+ const storage_1 = require("../storage");
14
+ const use_replay_storage_1 = require("./use-replay-storage");
15
+ jest.mock('@lib/storage', () => (Object.assign(Object.assign({}, jest.requireActual('@lib/storage')), { useStorage: jest.fn() })));
16
+ describe(use_replay_storage_1.useReplayStorage.name, () => {
17
+ let fixtures;
18
+ beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
19
+ fixtures = yield getFixtures();
20
+ }));
21
+ describe('query', () => {
22
+ test('happy path', () => __awaiter(void 0, void 0, void 0, function* () {
23
+ yield fixtures.given.stored(fixtures.sample);
24
+ const sample = yield fixtures.when.queried({});
25
+ expect(sample).toEqual(fixtures.sample);
26
+ }));
27
+ });
28
+ describe('save', () => {
29
+ test('happy path', () => __awaiter(void 0, void 0, void 0, function* () {
30
+ yield fixtures.when.saved(fixtures.sample);
31
+ yield fixtures.then.stored(fixtures.sample);
32
+ }));
33
+ });
34
+ });
35
+ function getFixtures() {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ const { act } = yield (0, make_test_module_1.makeTestModule)([]);
38
+ const dependencies = ['binance:btc-usdt', 'candle', 'h1'];
39
+ const save = jest.fn();
40
+ const query = jest.fn();
41
+ (0, make_test_module_1.mockedFunc)(storage_1.useStorage).mockReturnValue({ save, query });
42
+ return {
43
+ sample: [
44
+ { timestamp: 1, payload: { o: 1.1, h: 1.1, l: 1.1, c: 1.1 } },
45
+ { timestamp: 2, payload: { o: 1.1, h: 2.2, l: 1.1, c: 2.2 } },
46
+ { timestamp: 3, payload: { o: 1.1, h: 3.3, l: 1.1, c: 3.3 } }
47
+ ],
48
+ given: {
49
+ stored(sample) {
50
+ return query.mockReturnValue(Promise.resolve(sample.map(it => ({
51
+ timestamp: it.timestamp,
52
+ payload: JSON.stringify(it.payload)
53
+ }))));
54
+ }
55
+ },
56
+ when: {
57
+ saved(sample) {
58
+ return act(() => (0, use_replay_storage_1.useReplayStorage)(dependencies).save(sample));
59
+ },
60
+ queried(query) {
61
+ return act(() => (0, use_replay_storage_1.useReplayStorage)(dependencies).query(query));
62
+ }
63
+ },
64
+ then: {
65
+ stored(sample) {
66
+ expect(save).toHaveBeenCalledWith(expect.anything(), sample.map(it => ({
67
+ timestamp: it.timestamp,
68
+ payload: JSON.stringify(it.payload)
69
+ })));
70
+ }
71
+ }
72
+ };
73
+ });
74
+ }
@@ -1,9 +1,9 @@
1
1
  import { Observable } from 'rxjs';
2
2
  import { dependency } from '../use-hash';
3
- export declare const useReplay: <T>(input: Observable<{
3
+ export declare function useReplay<T>(input: Observable<{
4
4
  timestamp: number;
5
5
  payload: T;
6
- }>, dependencies: dependency[]) => Observable<{
6
+ }>, dependencies: dependency[]): Observable<{
7
7
  timestamp: number;
8
8
  payload: T;
9
9
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"use-replay.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,UAAU,EAAE,MAAM,MAAM,CAAC;AAIlD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAI3C,eAAO,MAAM,SAAS;eACW,MAAM;;kBACvB,UAAU,EAAE;eADK,MAAM;;EAwBtC,CAAC"}
1
+ {"version":3,"file":"use-replay.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAO,MAAM,MAAM,CAAC;AAGvC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAK3C,wBAAgB,SAAS,CAAC,CAAC,EACzB,KAAK,EAAE,UAAU,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,CAAC,CAAA;CAAE,CAAC,EACpD,YAAY,EAAE,UAAU,EAAE;eADK,MAAM;aAAW,CAAC;GAkBlD"}
@@ -1,32 +1,20 @@
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.useReplay = void 0;
13
4
  const rxjs_1 = require("rxjs");
14
- const use_replay_coordinator_1 = require("../replay/use-replay-coordinator");
15
5
  const use_execution_mode_1 = require("../use-execution-mode");
16
- const use_replay_writer_1 = require("./use-replay-writer");
17
- const useReplay = (input, dependencies) => {
6
+ const use_replay_manager_1 = require("./use-replay-manager");
7
+ const use_replay_storage_1 = require("./use-replay-storage");
8
+ function useReplay(input, dependencies) {
18
9
  const { isReplay, recording } = (0, use_execution_mode_1.useExecutionMode)();
19
10
  if (isReplay) {
20
- const { subscribe } = (0, use_replay_coordinator_1.useReplayCoordinator)();
21
- return subscribe(dependencies).pipe((0, rxjs_1.map)(it => it));
11
+ const { when } = (0, use_replay_manager_1.useReplayManager)();
12
+ return when(dependencies);
22
13
  }
23
14
  if (recording) {
24
- const writer = (0, use_replay_writer_1.useReplayWriter)(dependencies);
25
- return input.pipe((0, rxjs_1.concatMap)((it) => __awaiter(void 0, void 0, void 0, function* () {
26
- yield writer([it]);
27
- return it;
28
- })));
15
+ const { save } = (0, use_replay_storage_1.useReplayStorage)(dependencies);
16
+ return input.pipe((0, rxjs_1.tap)(it => save([it])));
29
17
  }
30
18
  return input;
31
- };
19
+ }
32
20
  exports.useReplay = useReplay;