@quantform/core 0.7.0-beta.32 → 0.7.0-beta.34
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.
- package/dist/cli/dev.js +1 -1
- package/dist/cli/internal/script.d.ts +1 -1
- package/dist/cli/internal/script.d.ts.map +1 -1
- package/dist/cli/internal/script.js +5 -2
- package/dist/cli/replay.d.ts.map +1 -1
- package/dist/cli/replay.js +3 -35
- package/dist/cli/run.d.ts.map +1 -1
- package/dist/cli/run.js +3 -37
- package/dist/index.d.ts +1 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -4
- package/dist/replay/index.d.ts +6 -4
- package/dist/replay/index.d.ts.map +1 -1
- package/dist/replay/index.js +6 -4
- package/dist/replay/replay-guard.d.ts +10 -0
- package/dist/replay/replay-guard.d.ts.map +1 -0
- package/dist/replay/replay-guard.js +8 -0
- package/dist/replay/replay.d.ts +10 -0
- package/dist/replay/replay.d.ts.map +1 -0
- package/dist/replay/replay.js +9 -0
- package/dist/replay/use-replay-breakpoint.d.ts +3 -0
- package/dist/replay/use-replay-breakpoint.d.ts.map +1 -0
- package/dist/replay/use-replay-breakpoint.js +22 -0
- package/dist/replay/use-replay-manager.d.ts +12 -0
- package/dist/replay/use-replay-manager.d.ts.map +1 -0
- package/dist/replay/use-replay-manager.js +88 -0
- package/dist/replay/use-replay-storage-buffer.d.ts +15 -0
- package/dist/replay/use-replay-storage-buffer.d.ts.map +1 -0
- package/dist/replay/use-replay-storage-buffer.js +50 -0
- package/dist/replay/use-replay-storage.d.ts +11 -8
- package/dist/replay/use-replay-storage.d.ts.map +1 -1
- package/dist/replay/use-replay-storage.js +34 -5
- package/dist/replay/use-replay-storage.spec.d.ts +2 -0
- package/dist/replay/use-replay-storage.spec.d.ts.map +1 -0
- package/dist/replay/use-replay-storage.spec.js +74 -0
- package/dist/replay/use-replay.d.ts +2 -2
- package/dist/replay/use-replay.d.ts.map +1 -1
- package/dist/replay/use-replay.js +8 -20
- package/dist/replay/use-replay.spec.js +125 -101
- package/dist/storage/index.d.ts +1 -0
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +1 -0
- package/dist/use-execution-mode.d.ts +1 -1
- package/dist/use-execution-mode.js +7 -7
- package/dist/use-timestamp.js +2 -2
- package/package.json +1 -1
- package/src/cli/dev.ts +1 -1
- package/src/cli/internal/script.ts +29 -3
- package/src/cli/replay.ts +4 -16
- package/src/cli/run.ts +4 -18
- package/src/index.ts +1 -4
- package/src/replay/index.ts +6 -4
- package/src/replay/replay-guard.ts +11 -0
- package/src/replay/replay.ts +13 -0
- package/src/replay/use-replay-breakpoint.ts +29 -0
- package/src/replay/use-replay-manager.ts +106 -0
- package/src/replay/use-replay-storage-buffer.ts +43 -0
- package/src/replay/use-replay-storage.spec.ts +85 -0
- package/src/replay/use-replay-storage.ts +26 -5
- package/src/replay/use-replay.spec.ts +10 -3
- package/src/replay/use-replay.ts +11 -17
- package/src/storage/index.ts +1 -0
- package/src/use-execution-mode.ts +8 -8
- package/src/use-timestamp.ts +2 -2
- package/dist/replay/use-replay-coordinator.d.ts +0 -10
- package/dist/replay/use-replay-coordinator.d.ts.map +0 -1
- package/dist/replay/use-replay-coordinator.js +0 -119
- package/dist/replay/use-replay-reader.d.ts +0 -7
- package/dist/replay/use-replay-reader.d.ts.map +0 -1
- package/dist/replay/use-replay-reader.js +0 -32
- package/dist/replay/use-replay-reader.spec.d.ts +0 -2
- package/dist/replay/use-replay-reader.spec.d.ts.map +0 -1
- package/dist/replay/use-replay-reader.spec.js +0 -58
- package/dist/replay/use-replay-writer.d.ts +0 -6
- package/dist/replay/use-replay-writer.d.ts.map +0 -1
- package/dist/replay/use-replay-writer.js +0 -14
- package/dist/replay/use-replay-writer.spec.d.ts +0 -2
- package/dist/replay/use-replay-writer.spec.d.ts.map +0 -1
- package/dist/replay/use-replay-writer.spec.js +0 -53
- package/dist/replay/with-replay.d.ts +0 -4
- package/dist/replay/with-replay.d.ts.map +0 -1
- package/dist/replay/with-replay.js +0 -8
- package/src/replay/use-replay-coordinator.ts +0 -142
- package/src/replay/use-replay-reader.spec.ts +0 -64
- package/src/replay/use-replay-reader.ts +0 -23
- package/src/replay/use-replay-writer.spec.ts +0 -56
- package/src/replay/use-replay-writer.ts +0 -17
- package/src/replay/with-replay.ts +0 -10
|
@@ -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 +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 +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 +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;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,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,142 +0,0 @@
|
|
|
1
|
-
import { defer, filter, map, Subject } from 'rxjs';
|
|
2
|
-
|
|
3
|
-
import { dependency } from '@lib/use-hash';
|
|
4
|
-
import { useMemo } from '@lib/use-memo';
|
|
5
|
-
|
|
6
|
-
import { between } from '..';
|
|
7
|
-
import { useReplayOptions } from './use-replay-options';
|
|
8
|
-
import { useReplayReader } from './use-replay-reader';
|
|
9
|
-
|
|
10
|
-
export function useReplayCoordinator() {
|
|
11
|
-
const options = useReplayOptions();
|
|
12
|
-
|
|
13
|
-
return useMemo(() => {
|
|
14
|
-
let timestamp = options.from;
|
|
15
|
-
let stopAcquire = 1;
|
|
16
|
-
let sequence = 0;
|
|
17
|
-
const subscriptions = Array.of<SampleCursor>();
|
|
18
|
-
const stream$ = new Subject<[SampleCursor, { timestamp: number }]>();
|
|
19
|
-
|
|
20
|
-
const subscribe = (dependencies: dependency[]) => {
|
|
21
|
-
const cursor = useSampleCursor(dependencies);
|
|
22
|
-
|
|
23
|
-
if (!subscriptions.includes(cursor)) {
|
|
24
|
-
subscriptions.push(cursor);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return defer(() => {
|
|
28
|
-
tryContinue();
|
|
29
|
-
|
|
30
|
-
return stream$.pipe(
|
|
31
|
-
filter(([cur]) => cur === cursor),
|
|
32
|
-
map(([, it]) => it)
|
|
33
|
-
);
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const current = async () => {
|
|
38
|
-
let next: SampleCursor | undefined;
|
|
39
|
-
|
|
40
|
-
for (const cursor of subscriptions) {
|
|
41
|
-
if (cursor.size() == 0 && !cursor.completed) {
|
|
42
|
-
await cursor.fetchNextPage(timestamp, options.to + 1);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (cursor.peek()) {
|
|
46
|
-
if (!next || next.peek().timestamp > cursor.peek().timestamp) {
|
|
47
|
-
next = cursor;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return next;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const processNext = async () => {
|
|
56
|
-
const cursor = await current();
|
|
57
|
-
|
|
58
|
-
if (!cursor || !cursor.peek()) {
|
|
59
|
-
stream$.complete();
|
|
60
|
-
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const sample = cursor.dequeue();
|
|
65
|
-
|
|
66
|
-
timestamp = sample.timestamp;
|
|
67
|
-
sequence++;
|
|
68
|
-
|
|
69
|
-
stream$.next([cursor, sample]);
|
|
70
|
-
|
|
71
|
-
return true;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const next = async () => {
|
|
75
|
-
if (await processNext()) {
|
|
76
|
-
if (stopAcquire === 0) {
|
|
77
|
-
setImmediate(next);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const stop = () => stopAcquire++;
|
|
83
|
-
const tryContinue = () => {
|
|
84
|
-
if (stopAcquire == 0) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
stopAcquire = Math.max(0, stopAcquire - 1);
|
|
89
|
-
|
|
90
|
-
if (stopAcquire != 0) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
next();
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
return {
|
|
98
|
-
timestamp: () => timestamp,
|
|
99
|
-
stop,
|
|
100
|
-
tryContinue,
|
|
101
|
-
subscribe
|
|
102
|
-
};
|
|
103
|
-
}, [useReplayCoordinator.name]);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
type SampleCursor = Awaited<ReturnType<typeof useSampleCursor>>;
|
|
107
|
-
|
|
108
|
-
function useSampleCursor<T>(dependencies: dependency[]) {
|
|
109
|
-
return useMemo(() => {
|
|
110
|
-
const read = useReplayReader<T>(dependencies);
|
|
111
|
-
let page = new Array<{ timestamp: number; payload: T }>();
|
|
112
|
-
let index = 0;
|
|
113
|
-
let completed = false;
|
|
114
|
-
|
|
115
|
-
const size = () => page.length - index;
|
|
116
|
-
const peek = () => page[index];
|
|
117
|
-
const dequeue = () => page[index++];
|
|
118
|
-
const fetchNextPage = async (from: number, to: number) => {
|
|
119
|
-
if (completed) {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
index = 0;
|
|
124
|
-
|
|
125
|
-
page = await read({
|
|
126
|
-
where: {
|
|
127
|
-
timestamp: between(from, to)
|
|
128
|
-
},
|
|
129
|
-
limit: 10000
|
|
130
|
-
});
|
|
131
|
-
completed = page.length == 0;
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
return {
|
|
135
|
-
size,
|
|
136
|
-
peek,
|
|
137
|
-
dequeue,
|
|
138
|
-
fetchNextPage,
|
|
139
|
-
completed
|
|
140
|
-
};
|
|
141
|
-
}, [useSampleCursor.name, ...dependencies]);
|
|
142
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { makeTestModule, mockedFunc } from '@lib/make-test-module';
|
|
2
|
-
import { gt, Storage } from '@lib/storage';
|
|
3
|
-
|
|
4
|
-
import { useReplayReader } from './use-replay-reader';
|
|
5
|
-
import { useReplayStorage } from './use-replay-storage';
|
|
6
|
-
|
|
7
|
-
jest.mock('./use-replay-storage', () => ({
|
|
8
|
-
...jest.requireActual('./use-replay-storage'),
|
|
9
|
-
useReplayStorage: jest.fn()
|
|
10
|
-
}));
|
|
11
|
-
|
|
12
|
-
describe(useReplayReader.name, () => {
|
|
13
|
-
let fixtures: Awaited<ReturnType<typeof getFixtures>>;
|
|
14
|
-
|
|
15
|
-
beforeEach(async () => {
|
|
16
|
-
fixtures = await getFixtures();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
test('read sample candle data from storage', async () => {
|
|
20
|
-
await fixtures.givenDataStored(fixtures.sample);
|
|
21
|
-
const data = await fixtures.whenDataRequested();
|
|
22
|
-
|
|
23
|
-
expect(data).toEqual(fixtures.sample);
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
async function getFixtures() {
|
|
28
|
-
const { act } = await makeTestModule([]);
|
|
29
|
-
|
|
30
|
-
const dependencies = ['binance:btc-usdt', 'candle', 'h1'];
|
|
31
|
-
const query: jest.MockedFunction<Storage['query']> = jest.fn();
|
|
32
|
-
|
|
33
|
-
mockedFunc(useReplayStorage).mockReturnValue({ query } as any);
|
|
34
|
-
|
|
35
|
-
return {
|
|
36
|
-
sample: [
|
|
37
|
-
{ timestamp: 1, payload: { o: 1.1, h: 1.1, l: 1.1, c: 1.1 } },
|
|
38
|
-
{ timestamp: 2, payload: { o: 1.1, h: 2.2, l: 1.1, c: 2.2 } },
|
|
39
|
-
{ timestamp: 3, payload: { o: 1.1, h: 3.3, l: 1.1, c: 3.3 } }
|
|
40
|
-
],
|
|
41
|
-
|
|
42
|
-
givenDataStored<T>(data: { timestamp: number; payload: T }[]) {
|
|
43
|
-
return query.mockReturnValue(
|
|
44
|
-
Promise.resolve(
|
|
45
|
-
data.map(it => ({
|
|
46
|
-
kind: 'sample',
|
|
47
|
-
timestamp: it.timestamp,
|
|
48
|
-
json: JSON.stringify(it.payload)
|
|
49
|
-
}))
|
|
50
|
-
)
|
|
51
|
-
);
|
|
52
|
-
},
|
|
53
|
-
|
|
54
|
-
async whenDataRequested<T>() {
|
|
55
|
-
return await act(() =>
|
|
56
|
-
useReplayReader<T>(dependencies)({
|
|
57
|
-
where: {
|
|
58
|
-
timestamp: gt(0)
|
|
59
|
-
}
|
|
60
|
-
})
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Query, QueryObject } from '@lib/storage';
|
|
2
|
-
import { dependency, useHash } from '@lib/use-hash';
|
|
3
|
-
|
|
4
|
-
import { replaySerializableObject, useReplayStorage } from './use-replay-storage';
|
|
5
|
-
|
|
6
|
-
export function useReplayReader<T>(dependencies: dependency[]) {
|
|
7
|
-
const storage = useReplayStorage();
|
|
8
|
-
const key = useHash(dependencies);
|
|
9
|
-
|
|
10
|
-
return async (query: Query<QueryObject>) =>
|
|
11
|
-
(
|
|
12
|
-
await storage.query(replaySerializableObject(key), {
|
|
13
|
-
where: {
|
|
14
|
-
timestamp: query.where?.timestamp
|
|
15
|
-
},
|
|
16
|
-
limit: query.limit,
|
|
17
|
-
orderBy: query.orderBy
|
|
18
|
-
})
|
|
19
|
-
).map(it => ({
|
|
20
|
-
timestamp: it.timestamp,
|
|
21
|
-
payload: JSON.parse(it.json) as T
|
|
22
|
-
}));
|
|
23
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { makeTestModule, mockedFunc } from '@lib/make-test-module';
|
|
2
|
-
import { Storage } from '@lib/storage';
|
|
3
|
-
import { useHash } from '@lib/use-hash';
|
|
4
|
-
|
|
5
|
-
import { useReplayStorage } from './use-replay-storage';
|
|
6
|
-
import { useReplayWriter } from './use-replay-writer';
|
|
7
|
-
|
|
8
|
-
jest.mock('./use-replay-storage', () => ({
|
|
9
|
-
...jest.requireActual('./use-replay-storage'),
|
|
10
|
-
useReplayStorage: jest.fn()
|
|
11
|
-
}));
|
|
12
|
-
|
|
13
|
-
describe.skip(useReplayWriter.name, () => {
|
|
14
|
-
let fixtures: Awaited<ReturnType<typeof getFixtures>>;
|
|
15
|
-
|
|
16
|
-
beforeEach(async () => {
|
|
17
|
-
fixtures = await getFixtures();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test('write sample candle data to storage', async () => {
|
|
21
|
-
await fixtures.whenReplayDataWritten(fixtures.sample);
|
|
22
|
-
await fixtures.thenReplayDataSaved(fixtures.sample);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
async function getFixtures() {
|
|
27
|
-
const { act } = await makeTestModule([]);
|
|
28
|
-
|
|
29
|
-
const dependencies = ['binance:btc-usdt', 'candle', 'h1'];
|
|
30
|
-
const save: Storage['save'] = jest.fn();
|
|
31
|
-
|
|
32
|
-
mockedFunc(useReplayStorage).mockReturnValue({ save } as any);
|
|
33
|
-
|
|
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
|
-
|
|
41
|
-
whenReplayDataWritten<T>(data: { timestamp: number; payload: T }[]) {
|
|
42
|
-
return act(() => useReplayWriter(dependencies)(data));
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
async thenReplayDataSaved<T>(data: { timestamp: number; payload: T }[]) {
|
|
46
|
-
expect(save).toHaveBeenCalledWith(
|
|
47
|
-
useHash(dependencies),
|
|
48
|
-
data.map(it => ({
|
|
49
|
-
kind: 'sample',
|
|
50
|
-
timestamp: it.timestamp,
|
|
51
|
-
json: JSON.stringify(it.payload)
|
|
52
|
-
}))
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { dependency, useHash } from '@lib/use-hash';
|
|
2
|
-
|
|
3
|
-
import { replaySerializableObject, useReplayStorage } from './use-replay-storage';
|
|
4
|
-
|
|
5
|
-
export function useReplayWriter<T>(dependencies: dependency[]) {
|
|
6
|
-
const storage = useReplayStorage();
|
|
7
|
-
const key = useHash(dependencies);
|
|
8
|
-
|
|
9
|
-
return (samples: { timestamp: number; payload: T }[]) =>
|
|
10
|
-
storage.save(
|
|
11
|
-
replaySerializableObject(key),
|
|
12
|
-
samples.map(it => ({
|
|
13
|
-
timestamp: it.timestamp,
|
|
14
|
-
json: JSON.stringify(it.payload)
|
|
15
|
-
}))
|
|
16
|
-
);
|
|
17
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Observable } from 'rxjs';
|
|
2
|
-
|
|
3
|
-
import { dependency } from '@lib/use-hash';
|
|
4
|
-
import { withMemo } from '@lib/with-memo';
|
|
5
|
-
|
|
6
|
-
export function withReplay<T extends Array<dependency>, U extends Observable<K>, K>(
|
|
7
|
-
fn: (...args: T) => U
|
|
8
|
-
): (...args: T) => U {
|
|
9
|
-
return withMemo(fn);
|
|
10
|
-
}
|