@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
@@ -1,119 +0,0 @@
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.useReplayCoordinator = void 0;
13
- const rxjs_1 = require("rxjs");
14
- const use_memo_1 = require("../use-memo");
15
- const __1 = require("..");
16
- const use_replay_options_1 = require("./use-replay-options");
17
- const use_replay_reader_1 = require("./use-replay-reader");
18
- function useReplayCoordinator() {
19
- const options = (0, use_replay_options_1.useReplayOptions)();
20
- return (0, use_memo_1.useMemo)(() => {
21
- let timestamp = options.from;
22
- let stopAcquire = 1;
23
- let sequence = 0;
24
- const subscriptions = Array.of();
25
- const stream$ = new rxjs_1.Subject();
26
- const subscribe = (dependencies) => {
27
- const cursor = useSampleCursor(dependencies);
28
- if (!subscriptions.includes(cursor)) {
29
- subscriptions.push(cursor);
30
- }
31
- return (0, rxjs_1.defer)(() => {
32
- tryContinue();
33
- return stream$.pipe((0, rxjs_1.filter)(([cur]) => cur === cursor), (0, rxjs_1.map)(([, it]) => it));
34
- });
35
- };
36
- const current = () => __awaiter(this, void 0, void 0, function* () {
37
- let next;
38
- for (const cursor of subscriptions) {
39
- if (cursor.size() == 0 && !cursor.completed) {
40
- yield cursor.fetchNextPage(timestamp, options.to + 1);
41
- }
42
- if (cursor.peek()) {
43
- if (!next || next.peek().timestamp > cursor.peek().timestamp) {
44
- next = cursor;
45
- }
46
- }
47
- }
48
- return next;
49
- });
50
- const processNext = () => __awaiter(this, void 0, void 0, function* () {
51
- const cursor = yield current();
52
- if (!cursor || !cursor.peek()) {
53
- stream$.complete();
54
- return false;
55
- }
56
- const sample = cursor.dequeue();
57
- timestamp = sample.timestamp;
58
- sequence++;
59
- stream$.next([cursor, sample]);
60
- return true;
61
- });
62
- const next = () => __awaiter(this, void 0, void 0, function* () {
63
- if (yield processNext()) {
64
- if (stopAcquire === 0) {
65
- setImmediate(next);
66
- }
67
- }
68
- });
69
- const stop = () => stopAcquire++;
70
- const tryContinue = () => {
71
- if (stopAcquire == 0) {
72
- return;
73
- }
74
- stopAcquire = Math.max(0, stopAcquire - 1);
75
- if (stopAcquire != 0) {
76
- return;
77
- }
78
- next();
79
- };
80
- return {
81
- timestamp: () => timestamp,
82
- stop,
83
- tryContinue,
84
- subscribe
85
- };
86
- }, [useReplayCoordinator.name]);
87
- }
88
- exports.useReplayCoordinator = useReplayCoordinator;
89
- function useSampleCursor(dependencies) {
90
- return (0, use_memo_1.useMemo)(() => {
91
- const read = (0, use_replay_reader_1.useReplayReader)(dependencies);
92
- let page = new Array();
93
- let index = 0;
94
- let completed = false;
95
- const size = () => page.length - index;
96
- const peek = () => page[index];
97
- const dequeue = () => page[index++];
98
- const fetchNextPage = (from, to) => __awaiter(this, void 0, void 0, function* () {
99
- if (completed) {
100
- return;
101
- }
102
- index = 0;
103
- page = yield read({
104
- where: {
105
- timestamp: (0, __1.between)(from, to)
106
- },
107
- limit: 10000
108
- });
109
- completed = page.length == 0;
110
- });
111
- return {
112
- size,
113
- peek,
114
- dequeue,
115
- fetchNextPage,
116
- completed
117
- };
118
- }, [useSampleCursor.name, ...dependencies]);
119
- }
@@ -1,7 +0,0 @@
1
- import { Query, QueryObject } from '../storage';
2
- import { dependency } from '../use-hash';
3
- export declare function useReplayReader<T>(dependencies: dependency[]): (query: Query<QueryObject>) => Promise<{
4
- timestamp: number;
5
- payload: T;
6
- }[]>;
7
- //# sourceMappingURL=use-replay-reader.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-replay-reader.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay-reader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,UAAU,EAAW,MAAM,eAAe,CAAC;AAIpD,wBAAgB,eAAe,CAAC,CAAC,EAAE,YAAY,EAAE,UAAU,EAAE,WAItC,MAAM,WAAW,CAAC;;;KAaxC"}
@@ -1,32 +0,0 @@
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.useReplayReader = void 0;
13
- const use_hash_1 = require("../use-hash");
14
- const use_replay_storage_1 = require("./use-replay-storage");
15
- function useReplayReader(dependencies) {
16
- const storage = (0, use_replay_storage_1.useReplayStorage)();
17
- const key = (0, use_hash_1.useHash)(dependencies);
18
- return (query) => __awaiter(this, void 0, void 0, function* () {
19
- var _a;
20
- return (yield storage.query((0, use_replay_storage_1.replaySerializableObject)(key), {
21
- where: {
22
- timestamp: (_a = query.where) === null || _a === void 0 ? void 0 : _a.timestamp
23
- },
24
- limit: query.limit,
25
- orderBy: query.orderBy
26
- })).map(it => ({
27
- timestamp: it.timestamp,
28
- payload: JSON.parse(it.json)
29
- }));
30
- });
31
- }
32
- exports.useReplayReader = useReplayReader;
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=use-replay-reader.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-replay-reader.spec.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay-reader.spec.ts"],"names":[],"mappings":""}
@@ -1,58 +0,0 @@
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_reader_1 = require("./use-replay-reader");
15
- const use_replay_storage_1 = require("./use-replay-storage");
16
- jest.mock('./use-replay-storage', () => (Object.assign(Object.assign({}, jest.requireActual('./use-replay-storage')), { useReplayStorage: jest.fn() })));
17
- describe(use_replay_reader_1.useReplayReader.name, () => {
18
- let fixtures;
19
- beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
20
- fixtures = yield getFixtures();
21
- }));
22
- test('read sample candle data from storage', () => __awaiter(void 0, void 0, void 0, function* () {
23
- yield fixtures.givenDataStored(fixtures.sample);
24
- const data = yield fixtures.whenDataRequested();
25
- expect(data).toEqual(fixtures.sample);
26
- }));
27
- });
28
- function getFixtures() {
29
- return __awaiter(this, void 0, void 0, function* () {
30
- const { act } = yield (0, make_test_module_1.makeTestModule)([]);
31
- const dependencies = ['binance:btc-usdt', 'candle', 'h1'];
32
- const query = jest.fn();
33
- (0, make_test_module_1.mockedFunc)(use_replay_storage_1.useReplayStorage).mockReturnValue({ query });
34
- return {
35
- sample: [
36
- { timestamp: 1, payload: { o: 1.1, h: 1.1, l: 1.1, c: 1.1 } },
37
- { timestamp: 2, payload: { o: 1.1, h: 2.2, l: 1.1, c: 2.2 } },
38
- { timestamp: 3, payload: { o: 1.1, h: 3.3, l: 1.1, c: 3.3 } }
39
- ],
40
- givenDataStored(data) {
41
- return query.mockReturnValue(Promise.resolve(data.map(it => ({
42
- kind: 'sample',
43
- timestamp: it.timestamp,
44
- json: JSON.stringify(it.payload)
45
- }))));
46
- },
47
- whenDataRequested() {
48
- return __awaiter(this, void 0, void 0, function* () {
49
- return yield act(() => (0, use_replay_reader_1.useReplayReader)(dependencies)({
50
- where: {
51
- timestamp: (0, storage_1.gt)(0)
52
- }
53
- }));
54
- });
55
- }
56
- };
57
- });
58
- }
@@ -1,6 +0,0 @@
1
- import { dependency } from '../use-hash';
2
- export declare function useReplayWriter<T>(dependencies: dependency[]): (samples: {
3
- timestamp: number;
4
- payload: T;
5
- }[]) => Promise<void>;
6
- //# sourceMappingURL=use-replay-writer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-replay-writer.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay-writer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAW,MAAM,eAAe,CAAC;AAIpD,wBAAgB,eAAe,CAAC,CAAC,EAAE,YAAY,EAAE,UAAU,EAAE,aAI1C;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,CAAC,CAAA;CAAE,EAAE,mBAQrD"}
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useReplayWriter = void 0;
4
- const use_hash_1 = require("../use-hash");
5
- const use_replay_storage_1 = require("./use-replay-storage");
6
- function useReplayWriter(dependencies) {
7
- const storage = (0, use_replay_storage_1.useReplayStorage)();
8
- const key = (0, use_hash_1.useHash)(dependencies);
9
- return (samples) => storage.save((0, use_replay_storage_1.replaySerializableObject)(key), samples.map(it => ({
10
- timestamp: it.timestamp,
11
- json: JSON.stringify(it.payload)
12
- })));
13
- }
14
- exports.useReplayWriter = useReplayWriter;
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=use-replay-writer.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-replay-writer.spec.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay-writer.spec.ts"],"names":[],"mappings":""}
@@ -1,53 +0,0 @@
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 use_hash_1 = require("../use-hash");
14
- const use_replay_storage_1 = require("./use-replay-storage");
15
- const use_replay_writer_1 = require("./use-replay-writer");
16
- jest.mock('./use-replay-storage', () => (Object.assign(Object.assign({}, jest.requireActual('./use-replay-storage')), { useReplayStorage: jest.fn() })));
17
- describe.skip(use_replay_writer_1.useReplayWriter.name, () => {
18
- let fixtures;
19
- beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
20
- fixtures = yield getFixtures();
21
- }));
22
- test('write sample candle data to storage', () => __awaiter(void 0, void 0, void 0, function* () {
23
- yield fixtures.whenReplayDataWritten(fixtures.sample);
24
- yield fixtures.thenReplayDataSaved(fixtures.sample);
25
- }));
26
- });
27
- function getFixtures() {
28
- return __awaiter(this, void 0, void 0, function* () {
29
- const { act } = yield (0, make_test_module_1.makeTestModule)([]);
30
- const dependencies = ['binance:btc-usdt', 'candle', 'h1'];
31
- const save = jest.fn();
32
- (0, make_test_module_1.mockedFunc)(use_replay_storage_1.useReplayStorage).mockReturnValue({ save });
33
- return {
34
- sample: [
35
- { timestamp: 1, payload: { o: 1.1, h: 1.1, l: 1.1, c: 1.1 } },
36
- { timestamp: 2, payload: { o: 1.1, h: 2.2, l: 1.1, c: 2.2 } },
37
- { timestamp: 3, payload: { o: 1.1, h: 3.3, l: 1.1, c: 3.3 } }
38
- ],
39
- whenReplayDataWritten(data) {
40
- return act(() => (0, use_replay_writer_1.useReplayWriter)(dependencies)(data));
41
- },
42
- thenReplayDataSaved(data) {
43
- return __awaiter(this, void 0, void 0, function* () {
44
- expect(save).toHaveBeenCalledWith((0, use_hash_1.useHash)(dependencies), data.map(it => ({
45
- kind: 'sample',
46
- timestamp: it.timestamp,
47
- json: JSON.stringify(it.payload)
48
- })));
49
- });
50
- }
51
- };
52
- });
53
- }
@@ -1,4 +0,0 @@
1
- import { Observable } from 'rxjs';
2
- import { dependency } from '../use-hash';
3
- export declare function withReplay<T extends Array<dependency>, U extends Observable<K>, K>(fn: (...args: T) => U): (...args: T) => U;
4
- //# sourceMappingURL=with-replay.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"with-replay.d.ts","sourceRoot":"","sources":["../../src/replay/with-replay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAGlC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,wBAAgB,UAAU,CAAC,CAAC,SAAS,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,EAChF,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,GACpB,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,CAEnB"}
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.withReplay = void 0;
4
- const use_1 = require("../use");
5
- function withReplay(fn) {
6
- return (0, use_1.use)(fn);
7
- }
8
- exports.withReplay = withReplay;
package/dist/strat.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import { Observable } from 'rxjs';
2
- import { Dependency } from './module';
3
- export declare function strat(fn: () => Observable<unknown>, dependencies: Dependency[]): {
4
- fn: () => Observable<unknown>;
5
- dependencies: Dependency[];
6
- };
7
- //# sourceMappingURL=strat.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"strat.d.ts","sourceRoot":"","sources":["../src/strat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,UAAU,CAAC,OAAO,CAAC,EAAE,YAAY,EAAE,UAAU,EAAE;cAA/C,WAAW,OAAO,CAAC;;EAElD"}
package/dist/strat.js DELETED
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.strat = void 0;
4
- function strat(fn, dependencies) {
5
- return { fn, dependencies };
6
- }
7
- exports.strat = strat;
@@ -1,9 +0,0 @@
1
- import { Observable } from 'rxjs';
2
- import { dependency } from './use-hash';
3
- export declare const useExclusiveLock: () => {
4
- acquire: (dependencies: dependency[]) => void;
5
- release: (dependencies: dependency[]) => void;
6
- alreadyAcquired: (dependencies: dependency[]) => boolean;
7
- };
8
- export declare function exclusive<T>(dependencies: dependency[]): (input: Observable<T>) => Observable<T>;
9
- //# sourceMappingURL=use-lock.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-lock.d.ts","sourceRoot":"","sources":["../src/use-lock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,UAAU,EAAE,MAAM,MAAM,CAAC;AAGpD,OAAO,EAAE,UAAU,EAAW,MAAM,eAAe,CAAC;AAEpD,eAAO,MAAM,gBAAgB;4BAEI,UAAU,EAAE;4BAUZ,UAAU,EAAE;oCAUJ,UAAU,EAAE;CAWnD,CAAC;AAEH,wBAAgB,SAAS,CAAC,CAAC,EAAE,YAAY,EAAE,UAAU,EAAE,WACtC,WAAW,CAAC,CAAC,mBAU7B"}
package/dist/use-lock.js DELETED
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.exclusive = exports.useExclusiveLock = void 0;
4
- const rxjs_1 = require("rxjs");
5
- const use_1 = require("./use");
6
- const use_hash_1 = require("./use-hash");
7
- exports.useExclusiveLock = (0, use_1.use)(() => {
8
- const locking = {};
9
- const acquire = (dependencies) => {
10
- const hash = (0, use_hash_1.useHash)(dependencies);
11
- if (locking[hash]) {
12
- throw Error('nested locks not allowed');
13
- }
14
- locking[hash] = true;
15
- };
16
- const release = (dependencies) => {
17
- const hash = (0, use_hash_1.useHash)(dependencies);
18
- if (!locking[hash]) {
19
- throw Error('nested locks not allowed');
20
- }
21
- locking[hash] = false;
22
- };
23
- const alreadyAcquired = (dependencies) => {
24
- const hash = (0, use_hash_1.useHash)(dependencies);
25
- return locking[hash] == true;
26
- };
27
- return {
28
- acquire,
29
- release,
30
- alreadyAcquired
31
- };
32
- });
33
- function exclusive(dependencies) {
34
- return (input) => {
35
- const { acquire, release, alreadyAcquired } = (0, exports.useExclusiveLock)();
36
- acquire(dependencies);
37
- return input.pipe((0, rxjs_1.filter)(() => alreadyAcquired(dependencies)), (0, rxjs_1.finalize)(() => release(dependencies)));
38
- };
39
- }
40
- exports.exclusive = exclusive;
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-request.d.ts","sourceRoot":"","sources":["../src/use-request.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,aAAa,GACrB,KAAK,GACL,MAAM,GACN,MAAM,GACN,KAAK,GACL,QAAQ,GACR,SAAS,GACT,SAAS,GACT,OAAO,GACP,OAAO,CAAC;AAEZ,qBAAa,mBAAoB,SAAQ,KAAK;IAChC,QAAQ,CAAC,UAAU,EAAE,MAAM;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC;gBAAxD,UAAU,EAAE,MAAM,EAAW,IAAI,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC;CAG9E;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE;IAC/B,MAAM,EAAE,aAAa,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;;;GAmBA"}
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useRequest = exports.RequestNetworkError = void 0;
4
- const rxjs_1 = require("rxjs");
5
- const undici_1 = require("undici");
6
- const use_timestamp_1 = require("./use-timestamp");
7
- class RequestNetworkError extends Error {
8
- constructor(statusCode, json) {
9
- super(`Request network error, received status code: ${statusCode}`);
10
- this.statusCode = statusCode;
11
- this.json = json;
12
- }
13
- }
14
- exports.RequestNetworkError = RequestNetworkError;
15
- function useRequest(args) {
16
- return (0, rxjs_1.from)((0, undici_1.request)(args.url, {
17
- method: args.method,
18
- headers: args.headers,
19
- body: args.body
20
- })).pipe((0, rxjs_1.switchMap)(it => {
21
- if (it.statusCode !== 200) {
22
- return (0, rxjs_1.throwError)(() => new RequestNetworkError(it.statusCode, () => it.body.json()));
23
- }
24
- return (0, rxjs_1.from)(it.body.json());
25
- }), (0, rxjs_1.map)(payload => ({ timestamp: (0, use_timestamp_1.useTimestamp)(), payload })));
26
- }
27
- exports.useRequest = useRequest;
@@ -1,6 +0,0 @@
1
- import { Observable } from 'rxjs';
2
- export declare function useSocket(url: string): [Observable<{
3
- timestamp: number;
4
- payload: unknown;
5
- }>, (message: unknown) => void];
6
- //# sourceMappingURL=use-socket.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-socket.d.ts","sourceRoot":"","sources":["../src/use-socket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAMlC,wBAAgB,SAAS,CACvB,GAAG,EAAE,MAAM,GACV,CAAC,UAAU,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC,CAkDnF"}
@@ -1,4 +0,0 @@
1
- import { Observable } from 'rxjs';
2
- import { dependency } from './use-hash';
3
- export declare function useState<T>(initialValue: T, dependencies: dependency[]): [Observable<Readonly<T>>, (value: T | ((p: T) => T)) => Readonly<T>];
4
- //# sourceMappingURL=use-state.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-state.d.ts","sourceRoot":"","sources":["../src/use-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,UAAU,EAAE,MAAM,MAAM,CAAC;AAInD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,wBAAgB,QAAQ,CAAC,CAAC,EACxB,YAAY,EAAE,CAAC,EACf,YAAY,EAAE,UAAU,EAAE,GACzB,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAoBtE"}
package/dist/use-state.js DELETED
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useState = void 0;
4
- const rxjs_1 = require("rxjs");
5
- const use_memo_1 = require("./use-memo");
6
- function useState(initialValue, dependencies) {
7
- return (0, use_memo_1.useMemo)(() => {
8
- const state = new rxjs_1.BehaviorSubject(initialValue);
9
- const setState = (newState) => {
10
- if (newState instanceof Function) {
11
- const value = newState(state.value);
12
- if (value) {
13
- state.next(value);
14
- }
15
- }
16
- else {
17
- state.next(newState);
18
- }
19
- return state.value;
20
- };
21
- return [state.asObservable(), setState];
22
- }, dependencies);
23
- }
24
- exports.useState = useState;
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=use-state.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-state.spec.d.ts","sourceRoot":"","sources":["../src/use-state.spec.ts"],"names":[],"mappings":""}
@@ -1,36 +0,0 @@
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 use_state_1 = require("./use-state");
14
- describe(use_state_1.useState.name, () => {
15
- let fixtures;
16
- beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
17
- fixtures = yield getFixtures();
18
- }));
19
- test('keep same state between multiple requests for the same dependency', () => __awaiter(void 0, void 0, void 0, function* () {
20
- const state1 = yield fixtures.givenState({ text: 'Hello my state' }, ['my-state']);
21
- const state2 = yield fixtures.givenState({ text: 'Hello my override state' }, [
22
- 'my-state'
23
- ]);
24
- expect(Object.is(state1, state2)).toBeTruthy();
25
- }));
26
- });
27
- function getFixtures() {
28
- return __awaiter(this, void 0, void 0, function* () {
29
- const { act } = yield (0, make_test_module_1.makeTestModule)([]);
30
- return {
31
- givenState(value, dependencies) {
32
- return act(() => (0, use_state_1.useState)(value, dependencies));
33
- }
34
- };
35
- });
36
- }
package/dist/use.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import { Observable } from 'rxjs';
2
- import { dependency } from './use-hash';
3
- export declare function use<T extends Array<dependency>, U>(fn: (...args: T) => U): (...args: T) => U;
4
- export declare function use<T extends Array<dependency>, U>(fn: (...args: T) => Observable<U>): (...args: T) => Observable<U>;
5
- //# sourceMappingURL=use.d.ts.map
package/dist/use.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"use.d.ts","sourceRoot":"","sources":["../src/use.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,UAAU,EAAe,MAAM,MAAM,CAAC;AAK7D,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGxC,wBAAgB,GAAG,CAAC,CAAC,SAAS,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,EAChD,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,GACpB,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC;AACrB,wBAAgB,GAAG,CAAC,CAAC,SAAS,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,EAChD,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,GAChC,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=use.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use.spec.d.ts","sourceRoot":"","sources":["../src/use.spec.ts"],"names":[],"mappings":""}
@@ -1,5 +0,0 @@
1
- import { map, Observable } from 'rxjs';
2
-
3
- export function asReadonly<T>() {
4
- return (input: Observable<T>) => input.pipe(map(it => it as Readonly<T>));
5
- }
package/src/defined.ts DELETED
@@ -1,6 +0,0 @@
1
- import { filter, Observable } from 'rxjs';
2
-
3
- export function defined<T>() {
4
- return (observable: Observable<T | undefined | null>) =>
5
- observable.pipe(filter(it => it !== undefined && it !== null));
6
- }
package/src/exclude.ts DELETED
@@ -1,9 +0,0 @@
1
- import { filter, map, Observable } from 'rxjs';
2
-
3
- export function exclude<T, S extends symbol>(s: S) {
4
- return (observable: Observable<T | S>) =>
5
- observable.pipe(
6
- filter(it => it !== s),
7
- map(it => it as Exclude<T, typeof s>)
8
- );
9
- }
package/src/not-found.ts DELETED
@@ -1 +0,0 @@
1
- export const notFound = Symbol.for('not-found');