@quantform/core 0.7.22 → 0.7.24

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 (194) 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.map +1 -1
  18. package/lib/make-test-module.js +18 -20
  19. package/lib/module.d.ts.map +1 -1
  20. package/lib/module.js +9 -24
  21. package/lib/module.spec.js +8 -17
  22. package/lib/replay/use-replay-options.d.ts +5 -4
  23. package/lib/replay/use-replay-options.d.ts.map +1 -1
  24. package/lib/replay/use-replay-options.js +5 -1
  25. package/lib/replay/use-replay-scheduler.d.ts +7 -6
  26. package/lib/replay/use-replay-scheduler.d.ts.map +1 -1
  27. package/lib/replay/use-replay-scheduler.js +64 -70
  28. package/lib/replay/use-replay-storage-buffer.d.ts +3 -2
  29. package/lib/replay/use-replay-storage-buffer.d.ts.map +1 -1
  30. package/lib/replay/use-replay-storage-buffer.js +12 -23
  31. package/lib/replay/use-replay-storage-cursor.d.ts +9 -8
  32. package/lib/replay/use-replay-storage-cursor.d.ts.map +1 -1
  33. package/lib/replay/use-replay-storage-cursor.js +17 -25
  34. package/lib/replay/use-replay-storage.d.ts +5 -4
  35. package/lib/replay/use-replay-storage.d.ts.map +1 -1
  36. package/lib/replay/use-replay-storage.js +32 -39
  37. package/lib/session/use-session-storage.d.ts +1 -1
  38. package/lib/session/use-session-storage.d.ts.map +1 -1
  39. package/lib/session/use-session-storage.js +8 -5
  40. package/lib/shared/environment.js +1 -1
  41. package/lib/shared/index.d.ts +0 -1
  42. package/lib/shared/index.d.ts.map +1 -1
  43. package/lib/shared/index.js +0 -1
  44. package/lib/simulator/use-simulator.spec.js +17 -30
  45. package/lib/storage/in-memory/in-memory-storage.d.ts.map +1 -1
  46. package/lib/storage/in-memory/in-memory-storage.factory.js +2 -2
  47. package/lib/storage/in-memory/in-memory-storage.js +56 -55
  48. package/lib/storage/in-memory/in-memory-storage.spec.js +90 -100
  49. package/lib/storage/storage.d.ts +9 -8
  50. package/lib/storage/storage.d.ts.map +1 -1
  51. package/lib/storage/storage.js +8 -2
  52. package/lib/storage/use-cache.d.ts +1 -1
  53. package/lib/storage/use-cache.d.ts.map +1 -1
  54. package/lib/storage/use-cache.js +5 -5
  55. package/lib/storage/use-cache.spec.js +14 -25
  56. package/lib/storage/use-storage.d.ts +1 -1
  57. package/lib/storage/use-storage.d.ts.map +1 -1
  58. package/lib/storage/use-storage.js +9 -6
  59. package/lib/use-execution-mode.js +2 -2
  60. package/lib/use-hash.spec.js +3 -6
  61. package/lib/use-logger.d.ts +1 -1
  62. package/lib/use-logger.d.ts.map +1 -1
  63. package/lib/use-logger.js +10 -7
  64. package/lib/use-memo.spec.js +14 -25
  65. package/lib/use-socket.d.ts +3 -2
  66. package/lib/use-socket.d.ts.map +1 -1
  67. package/lib/use-socket.js +2 -2
  68. package/lib/use-timestamp.d.ts +14 -1
  69. package/lib/use-timestamp.d.ts.map +1 -1
  70. package/lib/use-timestamp.js +30 -3
  71. package/lib/with-request.d.ts +2 -1
  72. package/lib/with-request.d.ts.map +1 -1
  73. package/lib/with-request.js +4 -13
  74. package/package.json +6 -10
  75. package/src/app.ts +52 -0
  76. package/src/cli/build.ts +11 -6
  77. package/src/cli/internal/script.ts +25 -54
  78. package/src/cli/replay.ts +13 -2
  79. package/src/index.ts +1 -6
  80. package/src/make-test-module.ts +12 -2
  81. package/src/module.ts +0 -3
  82. package/src/replay/use-replay-options.ts +7 -3
  83. package/src/replay/use-replay-scheduler.ts +75 -67
  84. package/src/replay/use-replay-storage-buffer.ts +2 -1
  85. package/src/replay/use-replay-storage-cursor.ts +33 -28
  86. package/src/replay/use-replay-storage.ts +36 -27
  87. package/src/session/use-session-storage.ts +7 -5
  88. package/src/shared/index.ts +0 -1
  89. package/src/storage/in-memory/in-memory-storage.spec.ts +55 -54
  90. package/src/storage/in-memory/in-memory-storage.ts +24 -7
  91. package/src/storage/storage.ts +16 -7
  92. package/src/storage/use-cache.ts +4 -4
  93. package/src/storage/use-storage.ts +8 -6
  94. package/src/use-hash.spec.ts +3 -6
  95. package/src/use-logger.ts +9 -6
  96. package/src/use-socket.ts +5 -5
  97. package/src/use-timestamp.ts +41 -3
  98. package/src/with-request.ts +3 -3
  99. package/lib/asset/asset.d.ts +0 -41
  100. package/lib/asset/asset.d.ts.map +0 -1
  101. package/lib/asset/asset.js +0 -76
  102. package/lib/asset/asset.spec.d.ts +0 -2
  103. package/lib/asset/asset.spec.d.ts.map +0 -1
  104. package/lib/asset/asset.spec.js +0 -54
  105. package/lib/asset/index.d.ts +0 -2
  106. package/lib/asset/index.d.ts.map +0 -1
  107. package/lib/asset/index.js +0 -17
  108. package/lib/component/distinct-until-timesamp-changed.d.ts +0 -5
  109. package/lib/component/distinct-until-timesamp-changed.d.ts.map +0 -1
  110. package/lib/component/distinct-until-timesamp-changed.js +0 -9
  111. package/lib/component/error.d.ts +0 -17
  112. package/lib/component/error.d.ts.map +0 -1
  113. package/lib/component/error.js +0 -33
  114. package/lib/component/index.d.ts +0 -8
  115. package/lib/component/index.d.ts.map +0 -1
  116. package/lib/component/index.js +0 -23
  117. package/lib/component/ohlc-operator.d.ts +0 -11
  118. package/lib/component/ohlc-operator.d.ts.map +0 -1
  119. package/lib/component/ohlc-operator.js +0 -69
  120. package/lib/component/ohlc-operator.spec.d.ts +0 -2
  121. package/lib/component/ohlc-operator.spec.d.ts.map +0 -1
  122. package/lib/component/ohlc-operator.spec.js +0 -110
  123. package/lib/component/ohlc.d.ts +0 -12
  124. package/lib/component/ohlc.d.ts.map +0 -1
  125. package/lib/component/ohlc.js +0 -20
  126. package/lib/component/ohlc.spec.d.ts +0 -2
  127. package/lib/component/ohlc.spec.d.ts.map +0 -1
  128. package/lib/component/ohlc.spec.js +0 -25
  129. package/lib/component/timeframe.d.ts +0 -15
  130. package/lib/component/timeframe.d.ts.map +0 -1
  131. package/lib/component/timeframe.js +0 -21
  132. package/lib/core.d.ts +0 -3
  133. package/lib/core.d.ts.map +0 -1
  134. package/lib/core.js +0 -17
  135. package/lib/instrument/commission/commission.d.ts +0 -16
  136. package/lib/instrument/commission/commission.d.ts.map +0 -1
  137. package/lib/instrument/commission/commission.js +0 -28
  138. package/lib/instrument/commission/commission.spec.d.ts +0 -2
  139. package/lib/instrument/commission/commission.spec.d.ts.map +0 -1
  140. package/lib/instrument/commission/commission.spec.js +0 -30
  141. package/lib/instrument/index.d.ts +0 -3
  142. package/lib/instrument/index.d.ts.map +0 -1
  143. package/lib/instrument/index.js +0 -18
  144. package/lib/instrument/instrument.d.ts +0 -28
  145. package/lib/instrument/instrument.d.ts.map +0 -1
  146. package/lib/instrument/instrument.js +0 -53
  147. package/lib/instrument/instrument.spec.d.ts +0 -2
  148. package/lib/instrument/instrument.spec.d.ts.map +0 -1
  149. package/lib/instrument/instrument.spec.js +0 -51
  150. package/lib/operators.d.ts +0 -5
  151. package/lib/operators.d.ts.map +0 -1
  152. package/lib/operators.js +0 -16
  153. package/lib/shared/datetime.d.ts +0 -3
  154. package/lib/shared/datetime.d.ts.map +0 -1
  155. package/lib/shared/datetime.js +0 -7
  156. package/lib/strategy.d.ts +0 -15
  157. package/lib/strategy.d.ts.map +0 -1
  158. package/lib/strategy.js +0 -26
  159. package/lib/strategy.spec.d.ts +0 -2
  160. package/lib/strategy.spec.d.ts.map +0 -1
  161. package/lib/strategy.spec.js +0 -34
  162. package/lib/when-socket.d.ts +0 -8
  163. package/lib/when-socket.d.ts.map +0 -1
  164. package/lib/when-socket.js +0 -53
  165. package/lib/with-memo.d.ts +0 -5
  166. package/lib/with-memo.d.ts.map +0 -1
  167. package/lib/with-memo.js +0 -20
  168. package/lib/with-memo.spec.d.ts +0 -2
  169. package/lib/with-memo.spec.d.ts.map +0 -1
  170. package/lib/with-memo.spec.js +0 -47
  171. package/src/asset/asset.spec.ts +0 -70
  172. package/src/asset/asset.ts +0 -89
  173. package/src/asset/index.ts +0 -1
  174. package/src/component/distinct-until-timesamp-changed.ts +0 -11
  175. package/src/component/error.ts +0 -32
  176. package/src/component/index.ts +0 -7
  177. package/src/component/ohlc-operator.spec.ts +0 -125
  178. package/src/component/ohlc-operator.ts +0 -122
  179. package/src/component/ohlc.spec.ts +0 -30
  180. package/src/component/ohlc.ts +0 -18
  181. package/src/component/timeframe.ts +0 -17
  182. package/src/core.ts +0 -16
  183. package/src/instrument/commission/commission.spec.ts +0 -35
  184. package/src/instrument/commission/commission.ts +0 -27
  185. package/src/instrument/index.ts +0 -2
  186. package/src/instrument/instrument.spec.ts +0 -76
  187. package/src/instrument/instrument.ts +0 -65
  188. package/src/operators.ts +0 -18
  189. package/src/shared/datetime.ts +0 -5
  190. package/src/strategy.spec.ts +0 -42
  191. package/src/strategy.ts +0 -36
  192. package/src/when-socket.ts +0 -61
  193. package/src/with-memo.spec.ts +0 -46
  194. package/src/with-memo.ts +0 -33
@@ -1,27 +1,28 @@
1
1
  import { Observable } from 'rxjs';
2
+ import { Timestamp } from '../use-timestamp';
2
3
  import { ReplayQuery } from './use-replay-storage-cursor';
3
- export declare const useReplayScheduler: () => {
4
+ export declare function useReplayScheduler(): {
4
5
  stream: Observable<[{
5
6
  size(): number;
6
7
  peek(): {
7
- timestamp: number;
8
+ timestamp: Timestamp<"ns">;
8
9
  payload: any;
9
10
  };
10
11
  dequeue(): {
11
- timestamp: number;
12
+ timestamp: Timestamp<"ns">;
12
13
  payload: any;
13
14
  };
14
15
  completed(): boolean;
15
16
  fetchNextPage(): Promise<void>;
16
17
  }, {
17
- timestamp: number;
18
+ timestamp: Timestamp<'ns'>;
18
19
  payload: any;
19
20
  }]>;
20
- timestamp(): number;
21
+ timestamp(): Timestamp<"ns">;
21
22
  stop(): void;
22
23
  tryContinue: () => void;
23
24
  watch<T>(query: ReplayQuery<T>): Observable<{
24
- timestamp: number;
25
+ timestamp: Timestamp<'ns'>;
25
26
  payload: T;
26
27
  }>;
27
28
  };
@@ -1 +1 @@
1
- {"version":3,"file":"use-replay-scheduler.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay-scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,UAAU,EAAW,MAAM,MAAM,CAAC;AAM/D,OAAO,EAAE,WAAW,EAA0B,MAAM,6BAA6B,CAAC;AAElF,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;mBASmC,MAAM;iBAAW,GAAG;;;;;;mBA+DzB,MAAM;;;CAgBjE,CAAC"}
1
+ {"version":3,"file":"use-replay-scheduler.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay-scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,UAAU,EAAW,MAAM,MAAM,CAAC;AAG/D,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAI/C,OAAO,EAAE,WAAW,EAA0B,MAAM,6BAA6B,CAAC;AAElF,wBAAgB,kBAAkB;;;;;;;;;;;;;;mBAYb,UAAU,IAAI,CAAC;iBAAW,GAAG;;;;;;mBAkEjB,UAAU,IAAI,CAAC;;;EAiB/C"}
@@ -1,77 +1,71 @@
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.useReplayScheduler = void 0;
13
4
  const rxjs_1 = require("rxjs");
14
- const with_memo_1 = require("../with-memo");
5
+ const use_memo_1 = require("../use-memo");
15
6
  const use_replay_options_1 = require("./use-replay-options");
16
7
  const use_replay_storage_cursor_1 = require("./use-replay-storage-cursor");
17
- exports.useReplayScheduler = (0, with_memo_1.withMemo)(() => {
18
- const { from } = (0, use_replay_options_1.useReplayOptions)();
19
- const { get, cursor } = (0, use_replay_storage_cursor_1.useReplayStorageCursor)();
20
- let timestamp = from;
21
- let stopAcquire = 1;
22
- let processing = false;
23
- const stream$ = new rxjs_1.Subject();
24
- const processNext = () => __awaiter(void 0, void 0, void 0, function* () {
25
- const storage = yield cursor();
26
- if (!storage || !storage.peek()) {
27
- stream$.complete();
28
- return false;
29
- }
30
- const sample = storage.dequeue();
31
- timestamp = sample.timestamp;
32
- stream$.next([storage, sample]);
33
- return true;
34
- });
35
- const next = () => __awaiter(void 0, void 0, void 0, function* () {
36
- if (processing) {
37
- return;
38
- }
39
- processing = true;
40
- while (stopAcquire === 0) {
41
- if (!(yield processNext())) {
42
- break;
8
+ function useReplayScheduler() {
9
+ return (0, use_memo_1.useMemo)(() => {
10
+ const { from } = (0, use_replay_options_1.useReplayOptions)();
11
+ const { get, cursor } = (0, use_replay_storage_cursor_1.useReplayStorageCursor)();
12
+ let timestamp = from;
13
+ let stopAcquire = 1;
14
+ let processing = false;
15
+ const stream$ = new rxjs_1.Subject();
16
+ const processNext = async () => {
17
+ const storage = await cursor();
18
+ if (!storage || !storage.peek()) {
19
+ stream$.complete();
20
+ return false;
43
21
  }
44
- yield new Promise(it => setImmediate(it));
45
- }
46
- processing = false;
47
- });
48
- const tryContinue = () => {
49
- if (stopAcquire === 0) {
50
- return;
51
- }
52
- stopAcquire--;
53
- if (stopAcquire === 0) {
54
- next();
55
- }
56
- };
57
- return {
58
- stream: stream$.asObservable(),
59
- timestamp() {
60
- return timestamp;
61
- },
62
- stop() {
63
- stopAcquire++;
64
- },
65
- tryContinue,
66
- watch(query) {
67
- const storage = get(query);
68
- return (0, rxjs_1.defer)(() => {
69
- tryContinue();
70
- return stream$.pipe((0, rxjs_1.filter)(([cur]) => cur === storage), (0, rxjs_1.map)(([, it]) => ({
71
- timestamp: it.timestamp,
72
- payload: it.payload
73
- })));
74
- });
75
- }
76
- };
77
- });
22
+ const sample = storage.dequeue();
23
+ timestamp = sample.timestamp;
24
+ stream$.next([storage, sample]);
25
+ return true;
26
+ };
27
+ const next = async () => {
28
+ if (processing) {
29
+ return;
30
+ }
31
+ processing = true;
32
+ while (stopAcquire === 0) {
33
+ if (!(await processNext())) {
34
+ break;
35
+ }
36
+ await new Promise(it => setImmediate(it));
37
+ }
38
+ processing = false;
39
+ };
40
+ const tryContinue = () => {
41
+ if (stopAcquire === 0) {
42
+ return;
43
+ }
44
+ stopAcquire--;
45
+ if (stopAcquire === 0) {
46
+ next();
47
+ }
48
+ };
49
+ return {
50
+ stream: stream$.asObservable(),
51
+ timestamp() {
52
+ return timestamp;
53
+ },
54
+ stop() {
55
+ stopAcquire++;
56
+ },
57
+ tryContinue,
58
+ watch(query) {
59
+ const storage = get(query);
60
+ return (0, rxjs_1.defer)(() => {
61
+ tryContinue();
62
+ return stream$.pipe((0, rxjs_1.filter)(([cur]) => cur === storage), (0, rxjs_1.map)(([, it]) => ({
63
+ timestamp: it.timestamp,
64
+ payload: it.payload
65
+ })));
66
+ });
67
+ }
68
+ };
69
+ }, [useReplayScheduler.name]);
70
+ }
71
+ exports.useReplayScheduler = useReplayScheduler;
@@ -1,12 +1,13 @@
1
+ import { Timestamp } from '../use-timestamp';
1
2
  import { ReplayQuery } from './use-replay-storage-cursor';
2
3
  export declare function useReplayStorageBuffer<T>(storage: ReplayQuery<T>): {
3
4
  size(): number;
4
5
  peek(): {
5
- timestamp: number;
6
+ timestamp: Timestamp<'ns'>;
6
7
  payload: T;
7
8
  };
8
9
  dequeue(): {
9
- timestamp: number;
10
+ timestamp: Timestamp<'ns'>;
10
11
  payload: T;
11
12
  };
12
13
  completed(): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"use-replay-storage-buffer.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay-storage-buffer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE1D,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC;;;mBAGlC,MAAM;iBAAW,CAAC;;;mBAAlB,MAAM;iBAAW,CAAC;;;;EAwChD"}
1
+ {"version":3,"file":"use-replay-storage-buffer.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay-storage-buffer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAG/C,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE1D,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC;;;mBAGlC,UAAU,IAAI,CAAC;iBAAW,CAAC;;;mBAA3B,UAAU,IAAI,CAAC;iBAAW,CAAC;;;;EAwCzD"}
@@ -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.useReplayStorageBuffer = void 0;
13
4
  const storage_1 = require("../storage");
@@ -31,21 +22,19 @@ function useReplayStorageBuffer(storage) {
31
22
  completed() {
32
23
  return completed;
33
24
  },
34
- fetchNextPage() {
35
- return __awaiter(this, void 0, void 0, function* () {
36
- if (completed) {
37
- return;
38
- }
39
- index = 0;
40
- page = yield storage.query({
41
- where: { timestamp: (0, storage_1.between)(from, to) },
42
- limit,
43
- offset: count,
44
- orderBy: 'ASC'
45
- });
46
- count += page.length;
47
- completed = page.length === 0;
25
+ async fetchNextPage() {
26
+ if (completed) {
27
+ return;
28
+ }
29
+ index = 0;
30
+ page = await storage.query({
31
+ where: { timestamp: (0, storage_1.between)(from, to) },
32
+ limit,
33
+ offset: count,
34
+ orderBy: 'ASC'
48
35
  });
36
+ count += page.length;
37
+ completed = page.length === 0;
49
38
  }
50
39
  };
51
40
  }
@@ -1,27 +1,28 @@
1
1
  import { Query, QueryObject } from '../storage';
2
+ import { Timestamp } from '../use-timestamp';
2
3
  export interface ReplayQuery<V> {
3
4
  query(query: Query<QueryObject> & {
4
5
  where: {
5
6
  timestamp: {
6
7
  type: 'between';
7
- min: number;
8
- max: number;
8
+ min: Timestamp<'ns'>;
9
+ max: Timestamp<'ns'>;
9
10
  };
10
11
  };
11
12
  }): Promise<{
12
- timestamp: number;
13
+ timestamp: Timestamp<'ns'>;
13
14
  payload: V;
14
15
  }[]>;
15
16
  }
16
- export declare const useReplayStorageCursor: () => {
17
+ export declare function useReplayStorageCursor(): {
17
18
  get<T>(query: ReplayQuery<T>): {
18
19
  size(): number;
19
20
  peek(): {
20
- timestamp: number;
21
+ timestamp: Timestamp<"ns">;
21
22
  payload: T;
22
23
  };
23
24
  dequeue(): {
24
- timestamp: number;
25
+ timestamp: Timestamp<"ns">;
25
26
  payload: T;
26
27
  };
27
28
  completed(): boolean;
@@ -30,11 +31,11 @@ export declare const useReplayStorageCursor: () => {
30
31
  cursor(): Promise<{
31
32
  size(): number;
32
33
  peek(): {
33
- timestamp: number;
34
+ timestamp: Timestamp<"ns">;
34
35
  payload: any;
35
36
  };
36
37
  dequeue(): {
37
- timestamp: number;
38
+ timestamp: Timestamp<"ns">;
38
39
  payload: any;
39
40
  };
40
41
  completed(): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"use-replay-storage-cursor.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay-storage-cursor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAKlD,MAAM,WAAW,WAAW,CAAC,CAAC;IAC5B,KAAK,CACH,KAAK,EAAE,KAAK,CAAC,WAAW,CAAC,GAAG;QAC1B,KAAK,EAAE;YAAE,SAAS,EAAE;gBAAE,IAAI,EAAE,SAAS,CAAC;gBAAC,GAAG,EAAE,MAAM,CAAC;gBAAC,GAAG,EAAE,MAAM,CAAA;aAAE,CAAA;SAAE,CAAC;KACrE,GACA,OAAO,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,CAAC,CAAA;KAAE,EAAE,CAAC,CAAC;CACjD;AAED,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkCjC,CAAC"}
1
+ {"version":3,"file":"use-replay-storage-cursor.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay-storage-cursor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAElD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAI/C,MAAM,WAAW,WAAW,CAAC,CAAC;IAC5B,KAAK,CACH,KAAK,EAAE,KAAK,CAAC,WAAW,CAAC,GAAG;QAC1B,KAAK,EAAE;YACL,SAAS,EAAE;gBAAE,IAAI,EAAE,SAAS,CAAC;gBAAC,GAAG,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;gBAAC,GAAG,EAAE,SAAS,CAAC,IAAI,CAAC,CAAA;aAAE,CAAC;SAC5E,CAAC;KACH,GACA,OAAO,CAAC;QAAE,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;QAAC,OAAO,EAAE,CAAC,CAAA;KAAE,EAAE,CAAC,CAAC;CAC1D;AAED,wBAAgB,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoCrC"}
@@ -1,34 +1,25 @@
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.useReplayStorageCursor = void 0;
13
- const with_memo_1 = require("../with-memo");
4
+ const use_memo_1 = require("../use-memo");
14
5
  const use_replay_storage_buffer_1 = require("./use-replay-storage-buffer");
15
- exports.useReplayStorageCursor = (0, with_memo_1.withMemo)(() => {
16
- const cursors = Array.of();
17
- return {
18
- get(query) {
19
- const buffer = (0, use_replay_storage_buffer_1.useReplayStorageBuffer)(query);
20
- cursors.push(buffer);
21
- return buffer;
22
- },
23
- cursor() {
24
- return __awaiter(this, void 0, void 0, function* () {
6
+ function useReplayStorageCursor() {
7
+ return (0, use_memo_1.useMemo)(() => {
8
+ const cursors = Array.of();
9
+ return {
10
+ get(query) {
11
+ const buffer = (0, use_replay_storage_buffer_1.useReplayStorageBuffer)(query);
12
+ cursors.push(buffer);
13
+ return buffer;
14
+ },
15
+ async cursor() {
25
16
  let current;
26
17
  for (const cursor of cursors) {
27
18
  if (cursor.completed()) {
28
19
  continue;
29
20
  }
30
21
  if (cursor.size() == 0) {
31
- yield cursor.fetchNextPage();
22
+ await cursor.fetchNextPage();
32
23
  }
33
24
  if (cursor.peek()) {
34
25
  if (!current || current.peek().timestamp > cursor.peek().timestamp) {
@@ -37,7 +28,8 @@ exports.useReplayStorageCursor = (0, with_memo_1.withMemo)(() => {
37
28
  }
38
29
  }
39
30
  return current;
40
- });
41
- }
42
- };
43
- });
31
+ }
32
+ };
33
+ }, [useReplayStorageCursor.name]);
34
+ }
35
+ exports.useReplayStorageCursor = useReplayStorageCursor;
@@ -1,24 +1,25 @@
1
1
  import { InferQueryObject, Query, QueryObject, QueryObjectType } from '../storage';
2
2
  import { Uri } from '../uri';
3
+ import { Timestamp } from '../use-timestamp';
3
4
  export type ReplayStorageQuery<V> = {
4
5
  sync: <T extends QueryObjectType<K>, K extends QueryObject>(query: Query<InferQueryObject<T>> & {
5
6
  where: {
6
7
  timestamp: {
7
8
  type: 'between';
8
- min: number;
9
- max: number;
9
+ min: Timestamp<'ns'>;
10
+ max: Timestamp<'ns'>;
10
11
  };
11
12
  };
12
13
  }, storage: {
13
14
  save: (objects: {
14
- timestamp: number;
15
+ timestamp: Timestamp<'ns'>;
15
16
  payload: V;
16
17
  }[]) => Promise<void>;
17
18
  }) => Promise<void>;
18
19
  };
19
20
  export declare function useReplayStorage<V, P extends Record<string, string | number>>(uri: Uri<P>, { sync }: ReplayStorageQuery<V>): {
20
21
  watch: () => import("rxjs").Observable<{
21
- timestamp: number;
22
+ timestamp: Timestamp<"ns">;
22
23
  payload: V;
23
24
  }>;
24
25
  };
@@ -1 +1 @@
1
- {"version":3,"file":"use-replay-storage.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay-storage.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,gBAAgB,EAChB,KAAK,EACL,WAAW,EACX,eAAe,EAGhB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAO/B,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI;IAClC,IAAI,EAAE,CAAC,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,EACxD,KAAK,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,GAAG;QAClC,KAAK,EAAE;YAAE,SAAS,EAAE;gBAAE,IAAI,EAAE,SAAS,CAAC;gBAAC,GAAG,EAAE,MAAM,CAAC;gBAAC,GAAG,EAAE,MAAM,CAAA;aAAE,CAAA;SAAE,CAAC;KACrE,EACD,OAAO,EAAE;QAAE,IAAI,EAAE,CAAC,OAAO,EAAE;YAAE,SAAS,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,CAAC,CAAA;SAAE,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;KAAE,KAC/E,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB,CAAC;AASF,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,EAC3E,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,EACX,EAAE,IAAI,EAAE,EAAE,kBAAkB,CAAC,CAAC,CAAC;;;;;EA+DhC"}
1
+ {"version":3,"file":"use-replay-storage.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay-storage.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,gBAAgB,EAChB,KAAK,EACL,WAAW,EACX,eAAe,EAGhB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAG/B,OAAO,EAAM,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAKnD,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI;IAClC,IAAI,EAAE,CAAC,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,EACxD,KAAK,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,GAAG;QAClC,KAAK,EAAE;YACL,SAAS,EAAE;gBAAE,IAAI,EAAE,SAAS,CAAC;gBAAC,GAAG,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;gBAAC,GAAG,EAAE,SAAS,CAAC,IAAI,CAAC,CAAA;aAAE,CAAC;SAC5E,CAAC;KACH,EACD,OAAO,EAAE;QACP,IAAI,EAAE,CAAC,OAAO,EAAE;YAAE,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;YAAC,OAAO,EAAE,CAAC,CAAA;SAAE,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;KAChF,KACE,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB,CAAC;AASF,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,EAC3E,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,EACX,EAAE,IAAI,EAAE,EAAE,kBAAkB,CAAC,CAAC,CAAC;;;;;EAmEhC"}
@@ -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.useReplayStorage = void 0;
13
4
  const rxjs_1 = require("rxjs");
@@ -15,47 +6,46 @@ const hash_code_1 = require("../hash-code");
15
6
  const storage_1 = require("../storage");
16
7
  const use_logger_1 = require("../use-logger");
17
8
  const use_memo_1 = require("../use-memo");
9
+ const use_timestamp_1 = require("../use-timestamp");
18
10
  const use_replay_options_1 = require("./use-replay-options");
19
11
  const use_replay_scheduler_1 = require("./use-replay-scheduler");
20
12
  const storageIndexObject = storage_1.Storage.createObject('index://range', {
21
- timestamp: 'number',
13
+ timestamp: 'bigint',
22
14
  uri: 'string',
23
- min: 'number',
24
- max: 'number'
15
+ min: 'bigint',
16
+ max: 'bigint'
25
17
  });
26
18
  function useReplayStorage(uri, { sync }) {
27
19
  const { watch } = (0, use_replay_scheduler_1.useReplayScheduler)();
28
- const { info } = (0, use_logger_1.useLogger)(useReplayStorage.name);
20
+ const { info, error } = (0, use_logger_1.useLogger)(useReplayStorage.name);
29
21
  const options = (0, use_replay_options_1.useReplayOptions)();
30
22
  const storage = (0, storage_1.useStorage)([options.storage]);
31
23
  const storageObjectKey = uri.query;
32
24
  const storageObject = storage_1.Storage.createObject(storageObjectKey, {
33
- timestamp: 'number',
25
+ timestamp: 'bigint',
34
26
  payload: 'string'
35
27
  });
36
- const id = (0, hash_code_1.hashCode)(storageObjectKey);
28
+ const id = (0, use_timestamp_1.ns)((0, hash_code_1.hashCode)(storageObjectKey));
37
29
  return {
38
30
  watch: () => (0, use_memo_1.useMemo)(() => watch({
39
- query(query) {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- const [index] = yield storage.query(storageIndexObject, {
42
- limit: 1,
43
- where: { timestamp: (0, storage_1.eq)(id) }
44
- });
45
- const { min, max } = query.where.timestamp;
46
- if (!index || min < index.min || max > index.max) {
47
- info(`fetching replay for ${storageObjectKey} started`);
48
- yield sync(query, {
49
- save(objects) {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- yield storage.save(storageObject, objects.map(it => ({
52
- timestamp: it.timestamp,
53
- payload: JSON.stringify(it.payload)
54
- })));
55
- });
31
+ async query(query) {
32
+ const [index] = await storage.query(storageIndexObject, {
33
+ limit: 1,
34
+ where: { timestamp: (0, storage_1.eq)(id) }
35
+ });
36
+ const { min, max } = query.where.timestamp;
37
+ if (!index || min < index.min || max > index.max) {
38
+ info(`fetching replay for ${storageObjectKey} started`);
39
+ try {
40
+ await sync(query, {
41
+ async save(objects) {
42
+ await storage.save(storageObject, objects.map(it => ({
43
+ timestamp: it.timestamp,
44
+ payload: JSON.stringify(it.payload)
45
+ })));
56
46
  }
57
47
  });
58
- yield storage.save(storageIndexObject, [
48
+ await storage.save(storageIndexObject, [
59
49
  {
60
50
  timestamp: id,
61
51
  max,
@@ -63,13 +53,16 @@ function useReplayStorage(uri, { sync }) {
63
53
  uri: storageObjectKey
64
54
  }
65
55
  ]);
66
- info(`fetching replay for ${storageObjectKey} finished`);
67
56
  }
68
- return (yield storage.query(storageObject, query)).map(it => ({
69
- timestamp: it.timestamp,
70
- payload: JSON.parse(it.payload)
71
- }));
72
- });
57
+ catch (err) {
58
+ error(`fetching replay for ${storageObjectKey} failed: ${err}`);
59
+ }
60
+ info(`fetching replay for ${storageObjectKey} finished`);
61
+ }
62
+ return (await storage.query(storageObject, query)).map(it => ({
63
+ timestamp: it.timestamp,
64
+ payload: JSON.parse(it.payload)
65
+ }));
73
66
  }
74
67
  }).pipe((0, rxjs_1.share)()), [useReplayStorage.name, storageObjectKey])
75
68
  };
@@ -1,2 +1,2 @@
1
- export declare const useSessionStorage: () => import("../storage").Storage;
1
+ export declare function useSessionStorage(): import("../storage").Storage;
2
2
  //# sourceMappingURL=use-session-storage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-session-storage.d.ts","sourceRoot":"","sources":["../../src/session/use-session-storage.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,iBAAiB,sCAI5B,CAAC"}
1
+ {"version":3,"file":"use-session-storage.d.ts","sourceRoot":"","sources":["../../src/session/use-session-storage.ts"],"names":[],"mappings":"AAIA,wBAAgB,iBAAiB,mCAMhC"}
@@ -3,8 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useSessionStorage = void 0;
4
4
  const session_1 = require("../session");
5
5
  const storage_1 = require("../storage");
6
- const with_memo_1 = require("../with-memo");
7
- exports.useSessionStorage = (0, with_memo_1.withMemo)(() => {
8
- const { id } = (0, session_1.useSession)();
9
- return (0, storage_1.useStorage)(['session', id]);
10
- });
6
+ const use_memo_1 = require("../use-memo");
7
+ function useSessionStorage() {
8
+ return (0, use_memo_1.useMemo)(() => {
9
+ const { id } = (0, session_1.useSession)();
10
+ return (0, storage_1.useStorage)(['session', id]);
11
+ }, [useSessionStorage.name]);
12
+ }
13
+ exports.useSessionStorage = useSessionStorage;
@@ -10,6 +10,6 @@ function getEnvVar(name, optional = false) {
10
10
  if (!value && !optional) {
11
11
  throw new Error(`Missing environment variable: ${name}`);
12
12
  }
13
- return value !== null && value !== void 0 ? value : '';
13
+ return value ?? '';
14
14
  }
15
15
  exports.getEnvVar = getEnvVar;
@@ -1,4 +1,3 @@
1
- export * from '../shared/datetime';
2
1
  export * from '../shared/decimals';
3
2
  export * from '../shared/environment';
4
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC"}
@@ -14,6 +14,5 @@ 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("../shared/datetime"), exports);
18
17
  __exportStar(require("../shared/decimals"), exports);
19
18
  __exportStar(require("../shared/environment"), exports);
@@ -1,43 +1,30 @@
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 make_test_module_1 = require("../make-test-module");
13
4
  const use_execution_mode_1 = require("../use-execution-mode");
14
5
  const use_simulator_1 = require("./use-simulator");
15
6
  describe(use_simulator_1.useSimulator.name, () => {
16
7
  let fixtures;
17
- beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
18
- fixtures = yield getFixtures();
19
- }));
20
- test('get real value when simulator mode disabled', () => __awaiter(void 0, void 0, void 0, function* () {
21
- const { act } = yield fixtures.givenModule(false);
8
+ beforeEach(async () => {
9
+ fixtures = await getFixtures();
10
+ });
11
+ test('get real value when simulator mode disabled', async () => {
12
+ const { act } = await fixtures.givenModule(false);
22
13
  const value = act(() => (0, use_simulator_1.useSimulator)('simulator', 'real'));
23
14
  expect(value).toBe('real');
24
- }));
25
- test('get simulation value when simulator mode enabled', () => __awaiter(void 0, void 0, void 0, function* () {
26
- const { act } = yield fixtures.givenModule(true);
15
+ });
16
+ test('get simulation value when simulator mode enabled', async () => {
17
+ const { act } = await fixtures.givenModule(true);
27
18
  const value = act(() => (0, use_simulator_1.useSimulator)('simulator', 'real'));
28
19
  expect(value).toBe('simulator');
29
- }));
30
- });
31
- function getFixtures() {
32
- return __awaiter(this, void 0, void 0, function* () {
33
- return {
34
- givenModule(isSimulation) {
35
- return __awaiter(this, void 0, void 0, function* () {
36
- return isSimulation
37
- ? yield (0, make_test_module_1.makeTestModule)([use_execution_mode_1.useExecutionMode.paperOptions({ recording: false })])
38
- : yield (0, make_test_module_1.makeTestModule)([use_execution_mode_1.useExecutionMode.liveOptions({ recording: false })]);
39
- });
40
- }
41
- };
42
20
  });
21
+ });
22
+ async function getFixtures() {
23
+ return {
24
+ async givenModule(isSimulation) {
25
+ return isSimulation
26
+ ? await (0, make_test_module_1.makeTestModule)([use_execution_mode_1.useExecutionMode.paperOptions({ recording: false })])
27
+ : await (0, make_test_module_1.makeTestModule)([use_execution_mode_1.useExecutionMode.liveOptions({ recording: false })]);
28
+ }
29
+ };
43
30
  }