@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
@@ -1,7 +1,8 @@
1
1
  import { Dependency } from '../module';
2
+ import { Timestamp } from '../use-timestamp';
2
3
  type ReplayOptions = {
3
- from: number;
4
- to: number;
4
+ from: Timestamp<'ns'>;
5
+ to: Timestamp<'ns'>;
5
6
  limit?: number;
6
7
  storage?: string;
7
8
  };
@@ -9,8 +10,8 @@ type ReplayOptions = {
9
10
  *
10
11
  */
11
12
  export declare function replayOptions(options: Omit<ReplayOptions, 'from' | 'to'> & {
12
- from: number;
13
- to: number;
13
+ from: Timestamp<'ns'>;
14
+ to: Timestamp<'ns'>;
14
15
  }): Dependency;
15
16
  /**
16
17
  * Will return current replay execution options.
@@ -1 +1 @@
1
- {"version":3,"file":"use-replay-options.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;AAIrD,KAAK,aAAa,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;GAEG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GACzE,UAAU,CASZ;AAED;;GAEG;AACH,eAAO,MAAM,gBAAgB,qBAAkD,CAAC"}
1
+ {"version":3,"file":"use-replay-options.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAI/C,KAAK,aAAa,GAAG;IACnB,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;IACtB,EAAE,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;GAEG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC,GAAG;IAC5C,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;IACtB,EAAE,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;CACrB,GACA,UAAU,CASZ;AAED;;GAEG;AACH,eAAO,MAAM,gBAAgB,qBAAkD,CAAC"}
@@ -9,7 +9,11 @@ const injectionToken = Symbol('replay-options');
9
9
  function replayOptions(options) {
10
10
  return {
11
11
  provide: injectionToken,
12
- useValue: Object.assign({ storage: 'backtest', limit: 10000 }, options)
12
+ useValue: {
13
+ storage: 'backtest',
14
+ limit: 10000,
15
+ ...options
16
+ }
13
17
  };
14
18
  }
15
19
  exports.replayOptions = replayOptions;
@@ -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);