@quantform/core 0.7.0-beta.33 → 0.7.0-beta.35
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/pull.d.ts.map +1 -1
- package/dist/cli/pull.js +4 -81
- 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 +6 -1
- package/dist/use-execution-mode.d.ts.map +1 -1
- package/dist/use-execution-mode.js +16 -8
- package/dist/use-timestamp.js +2 -2
- package/package.json +1 -1
- package/src/cli/pull.ts +6 -63
- 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 +16 -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,10 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useReplayStorage =
|
|
12
|
+
exports.useReplayStorage = void 0;
|
|
4
13
|
const storage_1 = require("../storage");
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
14
|
+
const use_hash_1 = require("../use-hash");
|
|
15
|
+
function useReplayStorage(dependencies) {
|
|
16
|
+
const storage = (0, storage_1.useStorage)(['replay']);
|
|
17
|
+
const storageObjectKey = (0, use_hash_1.useHash)(dependencies);
|
|
18
|
+
const storageObject = storage_1.Storage.createObject(storageObjectKey, {
|
|
19
|
+
timestamp: 'number',
|
|
20
|
+
payload: 'string'
|
|
21
|
+
});
|
|
22
|
+
return {
|
|
23
|
+
query(query) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
return (yield storage.query(storageObject, query)).map(it => ({
|
|
26
|
+
timestamp: it.timestamp,
|
|
27
|
+
payload: JSON.parse(it.payload)
|
|
28
|
+
}));
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
save(objects) {
|
|
32
|
+
return storage.save(storageObject, objects.map(it => ({
|
|
33
|
+
timestamp: it.timestamp,
|
|
34
|
+
payload: JSON.stringify(it.payload)
|
|
35
|
+
})));
|
|
36
|
+
}
|
|
37
|
+
};
|
|
9
38
|
}
|
|
10
39
|
exports.useReplayStorage = useReplayStorage;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-replay-storage.spec.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay-storage.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const make_test_module_1 = require("../make-test-module");
|
|
13
|
+
const storage_1 = require("../storage");
|
|
14
|
+
const use_replay_storage_1 = require("./use-replay-storage");
|
|
15
|
+
jest.mock('@lib/storage', () => (Object.assign(Object.assign({}, jest.requireActual('@lib/storage')), { useStorage: jest.fn() })));
|
|
16
|
+
describe(use_replay_storage_1.useReplayStorage.name, () => {
|
|
17
|
+
let fixtures;
|
|
18
|
+
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
fixtures = yield getFixtures();
|
|
20
|
+
}));
|
|
21
|
+
describe('query', () => {
|
|
22
|
+
test('happy path', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
yield fixtures.given.stored(fixtures.sample);
|
|
24
|
+
const sample = yield fixtures.when.queried({});
|
|
25
|
+
expect(sample).toEqual(fixtures.sample);
|
|
26
|
+
}));
|
|
27
|
+
});
|
|
28
|
+
describe('save', () => {
|
|
29
|
+
test('happy path', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
+
yield fixtures.when.saved(fixtures.sample);
|
|
31
|
+
yield fixtures.then.stored(fixtures.sample);
|
|
32
|
+
}));
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
function getFixtures() {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const { act } = yield (0, make_test_module_1.makeTestModule)([]);
|
|
38
|
+
const dependencies = ['binance:btc-usdt', 'candle', 'h1'];
|
|
39
|
+
const save = jest.fn();
|
|
40
|
+
const query = jest.fn();
|
|
41
|
+
(0, make_test_module_1.mockedFunc)(storage_1.useStorage).mockReturnValue({ save, query });
|
|
42
|
+
return {
|
|
43
|
+
sample: [
|
|
44
|
+
{ timestamp: 1, payload: { o: 1.1, h: 1.1, l: 1.1, c: 1.1 } },
|
|
45
|
+
{ timestamp: 2, payload: { o: 1.1, h: 2.2, l: 1.1, c: 2.2 } },
|
|
46
|
+
{ timestamp: 3, payload: { o: 1.1, h: 3.3, l: 1.1, c: 3.3 } }
|
|
47
|
+
],
|
|
48
|
+
given: {
|
|
49
|
+
stored(sample) {
|
|
50
|
+
return query.mockReturnValue(Promise.resolve(sample.map(it => ({
|
|
51
|
+
timestamp: it.timestamp,
|
|
52
|
+
payload: JSON.stringify(it.payload)
|
|
53
|
+
}))));
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
when: {
|
|
57
|
+
saved(sample) {
|
|
58
|
+
return act(() => (0, use_replay_storage_1.useReplayStorage)(dependencies).save(sample));
|
|
59
|
+
},
|
|
60
|
+
queried(query) {
|
|
61
|
+
return act(() => (0, use_replay_storage_1.useReplayStorage)(dependencies).query(query));
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
then: {
|
|
65
|
+
stored(sample) {
|
|
66
|
+
expect(save).toHaveBeenCalledWith(expect.anything(), sample.map(it => ({
|
|
67
|
+
timestamp: it.timestamp,
|
|
68
|
+
payload: JSON.stringify(it.payload)
|
|
69
|
+
})));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
2
|
import { dependency } from '../use-hash';
|
|
3
|
-
export declare
|
|
3
|
+
export declare function useReplay<T>(input: Observable<{
|
|
4
4
|
timestamp: number;
|
|
5
5
|
payload: T;
|
|
6
|
-
}>, dependencies: dependency[])
|
|
6
|
+
}>, dependencies: dependency[]): Observable<{
|
|
7
7
|
timestamp: number;
|
|
8
8
|
payload: T;
|
|
9
9
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-replay.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"use-replay.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAO,MAAM,MAAM,CAAC;AAGvC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAK3C,wBAAgB,SAAS,CAAC,CAAC,EACzB,KAAK,EAAE,UAAU,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,CAAC,CAAA;CAAE,CAAC,EACpD,YAAY,EAAE,UAAU,EAAE;eADK,MAAM;aAAW,CAAC;GAkBlD"}
|
|
@@ -1,32 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.useReplay = void 0;
|
|
13
4
|
const rxjs_1 = require("rxjs");
|
|
14
|
-
const use_replay_coordinator_1 = require("../replay/use-replay-coordinator");
|
|
15
5
|
const use_execution_mode_1 = require("../use-execution-mode");
|
|
16
|
-
const
|
|
17
|
-
const
|
|
6
|
+
const use_replay_manager_1 = require("./use-replay-manager");
|
|
7
|
+
const use_replay_storage_1 = require("./use-replay-storage");
|
|
8
|
+
function useReplay(input, dependencies) {
|
|
18
9
|
const { isReplay, recording } = (0, use_execution_mode_1.useExecutionMode)();
|
|
19
10
|
if (isReplay) {
|
|
20
|
-
const {
|
|
21
|
-
return
|
|
11
|
+
const { when } = (0, use_replay_manager_1.useReplayManager)();
|
|
12
|
+
return when(dependencies);
|
|
22
13
|
}
|
|
23
14
|
if (recording) {
|
|
24
|
-
const
|
|
25
|
-
return input.pipe((0, rxjs_1.
|
|
26
|
-
yield writer([it]);
|
|
27
|
-
return it;
|
|
28
|
-
})));
|
|
15
|
+
const { save } = (0, use_replay_storage_1.useReplayStorage)(dependencies);
|
|
16
|
+
return input.pipe((0, rxjs_1.tap)(it => save([it])));
|
|
29
17
|
}
|
|
30
18
|
return input;
|
|
31
|
-
}
|
|
19
|
+
}
|
|
32
20
|
exports.useReplay = useReplay;
|
|
@@ -1,106 +1,130 @@
|
|
|
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
|
-
const rxjs_1 = require("rxjs");
|
|
13
|
-
const make_test_module_1 = require("../make-test-module");
|
|
14
|
-
const use_replay_coordinator_1 = require("../replay/use-replay-coordinator");
|
|
15
|
-
const use_execution_mode_1 = require("../use-execution-mode");
|
|
16
|
-
const __1 = require("..");
|
|
17
3
|
const use_replay_1 = require("./use-replay");
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
describe.skip(use_replay_coordinator_1.useReplayCoordinator.name, () => {
|
|
22
|
-
let fixtures;
|
|
23
|
-
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
-
fixtures = yield getFixtures();
|
|
25
|
-
}));
|
|
26
|
-
test('return single data stream for single data source', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
-
fixtures.givenRecordingEnabled(false);
|
|
28
|
-
yield fixtures.givenSampleStored(fixtures.sample1, ['sample1']);
|
|
29
|
-
const sample1 = fixtures.whenUseReplayCalled(fixtures.sample1, ['sample']);
|
|
30
|
-
yield fixtures.whenUseSampleStreamerStarted();
|
|
31
|
-
expect(yield sample1).toEqual(fixtures.sample1);
|
|
32
|
-
}));
|
|
33
|
-
test('return combined data stream for multiple data sources', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
-
fixtures.givenRecordingEnabled(false);
|
|
35
|
-
yield fixtures.givenSampleStored(fixtures.sample1, ['sample1']);
|
|
36
|
-
yield fixtures.givenSampleStored(fixtures.sample2, ['sample2']);
|
|
37
|
-
const sample1 = fixtures.whenUseReplayCalled(fixtures.sample1, ['sample1']);
|
|
38
|
-
const sample2 = fixtures.whenUseReplayCalled(fixtures.sample2, ['sample2']);
|
|
39
|
-
yield fixtures.whenUseSampleStreamerStarted();
|
|
40
|
-
expect(yield sample1).toEqual(fixtures.sample1);
|
|
41
|
-
expect(yield sample2).toEqual(fixtures.sample2);
|
|
42
|
-
}));
|
|
43
|
-
test('record and write data stream into storage', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
-
fixtures.givenRecordingEnabled(true);
|
|
45
|
-
const sample1 = yield fixtures.whenUseReplayCalled(fixtures.sample1, ['sample1x']);
|
|
46
|
-
const sample2 = yield fixtures.whenUseReplayCalled(fixtures.sample2, ['sample2x']);
|
|
47
|
-
fixtures.thenReplaySampleStored(sample1, ['sample1x']);
|
|
48
|
-
fixtures.thenReplaySampleStored(sample2, ['sample2x']);
|
|
49
|
-
}));
|
|
50
|
-
});
|
|
51
|
-
function getFixtures() {
|
|
52
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
-
const executionMode = (0, use_execution_mode_1.replayExecutionMode)();
|
|
54
|
-
const { act } = yield (0, make_test_module_1.makeTestModule)([
|
|
55
|
-
executionMode,
|
|
56
|
-
(0, use_replay_options_1.replayOptions)({ from: 0, to: Number.MAX_VALUE })
|
|
57
|
-
]);
|
|
58
|
-
return {
|
|
59
|
-
sample1: [
|
|
60
|
-
{ timestamp: 1, payload: { o: 111, h: 112, l: 113, c: 114 } },
|
|
61
|
-
{ timestamp: 2, payload: { o: 121, h: 122, l: 123, c: 124 } },
|
|
62
|
-
{ timestamp: 3, payload: { o: 131, h: 132, l: 133, c: 134 } }
|
|
63
|
-
],
|
|
64
|
-
sample2: [
|
|
65
|
-
{ timestamp: 1, payload: { o: 211, h: 212, l: 213, c: 214 } },
|
|
66
|
-
{ timestamp: 2, payload: { o: 221, h: 222, l: 223, c: 224 } },
|
|
67
|
-
{ timestamp: 3, payload: { o: 231, h: 232, l: 233, c: 234 } }
|
|
68
|
-
],
|
|
69
|
-
givenRecordingEnabled(recording) {
|
|
70
|
-
executionMode.useValue.recording = recording;
|
|
71
|
-
},
|
|
72
|
-
givenSampleStored(sample, dependencies) {
|
|
73
|
-
return act(() => {
|
|
74
|
-
const writer = (0, use_replay_writer_1.useReplayWriter)(dependencies);
|
|
75
|
-
return writer(sample);
|
|
76
|
-
});
|
|
77
|
-
},
|
|
78
|
-
whenUseReplayCalled(input, dependencies) {
|
|
79
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
-
const sample = Array.of();
|
|
81
|
-
yield act(() => (0, rxjs_1.lastValueFrom)((0, use_replay_1.useReplay)((0, rxjs_1.from)(input), dependencies).pipe((0, rxjs_1.tap)(it => sample.push(it)))));
|
|
82
|
-
return sample;
|
|
83
|
-
});
|
|
84
|
-
},
|
|
85
|
-
whenUseSampleStreamerStarted() {
|
|
86
|
-
act(() => {
|
|
87
|
-
const { tryContinue } = (0, use_replay_coordinator_1.useReplayCoordinator)();
|
|
88
|
-
tryContinue();
|
|
89
|
-
});
|
|
90
|
-
},
|
|
91
|
-
thenReplaySampleStored(sample, dependencies) {
|
|
92
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
-
const stored = yield act(() => {
|
|
94
|
-
const reader = (0, use_replay_reader_1.useReplayReader)(dependencies);
|
|
95
|
-
return reader({
|
|
96
|
-
where: {
|
|
97
|
-
timestamp: (0, __1.between)(sample[0].timestamp, sample[sample.length - 1].timestamp + 1)
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
expect(stored).toEqual(sample);
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
};
|
|
4
|
+
describe(use_replay_1.useReplay.name, () => {
|
|
5
|
+
test('happy path', () => {
|
|
6
|
+
expect(true).toBe(true);
|
|
105
7
|
});
|
|
8
|
+
});
|
|
9
|
+
/*
|
|
10
|
+
|
|
11
|
+
describe.skip(useReplayCoordinator.name, () => {
|
|
12
|
+
let fixtures: Awaited<ReturnType<typeof getFixtures>>;
|
|
13
|
+
|
|
14
|
+
beforeEach(async () => {
|
|
15
|
+
fixtures = await getFixtures();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('return single data stream for single data source', async () => {
|
|
19
|
+
fixtures.givenRecordingEnabled(false);
|
|
20
|
+
await fixtures.givenSampleStored(fixtures.sample1, ['sample1']);
|
|
21
|
+
|
|
22
|
+
const sample1 = fixtures.whenUseReplayCalled(fixtures.sample1, ['sample']);
|
|
23
|
+
await fixtures.whenUseSampleStreamerStarted();
|
|
24
|
+
|
|
25
|
+
expect(await sample1).toEqual(fixtures.sample1);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('return combined data stream for multiple data sources', async () => {
|
|
29
|
+
fixtures.givenRecordingEnabled(false);
|
|
30
|
+
await fixtures.givenSampleStored(fixtures.sample1, ['sample1']);
|
|
31
|
+
await fixtures.givenSampleStored(fixtures.sample2, ['sample2']);
|
|
32
|
+
|
|
33
|
+
const sample1 = fixtures.whenUseReplayCalled(fixtures.sample1, ['sample1']);
|
|
34
|
+
const sample2 = fixtures.whenUseReplayCalled(fixtures.sample2, ['sample2']);
|
|
35
|
+
await fixtures.whenUseSampleStreamerStarted();
|
|
36
|
+
|
|
37
|
+
expect(await sample1).toEqual(fixtures.sample1);
|
|
38
|
+
expect(await sample2).toEqual(fixtures.sample2);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('record and write data stream into storage', async () => {
|
|
42
|
+
fixtures.givenRecordingEnabled(true);
|
|
43
|
+
const sample1 = await fixtures.whenUseReplayCalled(fixtures.sample1, ['sample1x']);
|
|
44
|
+
const sample2 = await fixtures.whenUseReplayCalled(fixtures.sample2, ['sample2x']);
|
|
45
|
+
|
|
46
|
+
fixtures.thenReplaySampleStored(sample1, ['sample1x']);
|
|
47
|
+
fixtures.thenReplaySampleStored(sample2, ['sample2x']);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
async function getFixtures() {
|
|
52
|
+
const executionMode = replayExecutionMode();
|
|
53
|
+
|
|
54
|
+
const { act } = await makeTestModule([
|
|
55
|
+
executionMode,
|
|
56
|
+
replayOptions({ from: 0, to: Number.MAX_VALUE })
|
|
57
|
+
]);
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
sample1: [
|
|
61
|
+
{ timestamp: 1, payload: { o: 111, h: 112, l: 113, c: 114 } },
|
|
62
|
+
{ timestamp: 2, payload: { o: 121, h: 122, l: 123, c: 124 } },
|
|
63
|
+
{ timestamp: 3, payload: { o: 131, h: 132, l: 133, c: 134 } }
|
|
64
|
+
],
|
|
65
|
+
sample2: [
|
|
66
|
+
{ timestamp: 1, payload: { o: 211, h: 212, l: 213, c: 214 } },
|
|
67
|
+
{ timestamp: 2, payload: { o: 221, h: 222, l: 223, c: 224 } },
|
|
68
|
+
{ timestamp: 3, payload: { o: 231, h: 232, l: 233, c: 234 } }
|
|
69
|
+
],
|
|
70
|
+
|
|
71
|
+
givenRecordingEnabled(recording: boolean) {
|
|
72
|
+
executionMode.useValue.recording = recording;
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
givenSampleStored<T>(
|
|
76
|
+
sample: { timestamp: number; payload: T }[],
|
|
77
|
+
dependencies: dependency[]
|
|
78
|
+
) {
|
|
79
|
+
return act(() => {
|
|
80
|
+
const writer = useReplayWriter(dependencies);
|
|
81
|
+
|
|
82
|
+
return writer(sample);
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
async whenUseReplayCalled<T>(
|
|
87
|
+
input: { timestamp: number; payload: T }[],
|
|
88
|
+
dependencies: dependency[]
|
|
89
|
+
) {
|
|
90
|
+
const sample = Array.of<{ timestamp: number; payload: T }>();
|
|
91
|
+
|
|
92
|
+
await act(() =>
|
|
93
|
+
lastValueFrom(
|
|
94
|
+
useReplay<T>(from(input), dependencies).pipe(tap(it => sample.push(it)))
|
|
95
|
+
)
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
return sample;
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
whenUseSampleStreamerStarted() {
|
|
102
|
+
act(() => {
|
|
103
|
+
const { tryContinue } = useReplayCoordinator();
|
|
104
|
+
|
|
105
|
+
tryContinue();
|
|
106
|
+
});
|
|
107
|
+
},
|
|
108
|
+
|
|
109
|
+
async thenReplaySampleStored<T extends { timestamp: number }>(
|
|
110
|
+
sample: T[],
|
|
111
|
+
dependencies: dependency[]
|
|
112
|
+
) {
|
|
113
|
+
const stored = await act(() => {
|
|
114
|
+
const reader = useReplayReader(dependencies);
|
|
115
|
+
|
|
116
|
+
return reader({
|
|
117
|
+
where: {
|
|
118
|
+
timestamp: between(
|
|
119
|
+
sample[0].timestamp,
|
|
120
|
+
sample[sample.length - 1].timestamp + 1
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
expect(stored).toEqual(sample);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
106
129
|
}
|
|
130
|
+
*/
|
package/dist/storage/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/storage/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/storage/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC"}
|
package/dist/storage/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./storage"), exports);
|
|
18
|
+
__exportStar(require("./use-cache"), exports);
|
|
18
19
|
__exportStar(require("./use-storage"), exports);
|
|
19
20
|
__exportStar(require("./use-storage-factory"), exports);
|
|
20
21
|
__exportStar(require("./in-memory"), exports);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
type ExecutionMode = {
|
|
2
|
-
mode: '
|
|
2
|
+
mode: 'replay' | 'paper' | 'live' | 'idle';
|
|
3
3
|
recording: boolean;
|
|
4
4
|
};
|
|
5
5
|
export declare function replayExecutionMode(): {
|
|
@@ -18,10 +18,15 @@ export declare function liveExecutionMode(options: {
|
|
|
18
18
|
provide: symbol;
|
|
19
19
|
useValue: ExecutionMode;
|
|
20
20
|
};
|
|
21
|
+
export declare function idleExecutionMode(): {
|
|
22
|
+
provide: symbol;
|
|
23
|
+
useValue: ExecutionMode;
|
|
24
|
+
};
|
|
21
25
|
export declare const useExecutionMode: () => {
|
|
22
26
|
isReplay: boolean;
|
|
23
27
|
isPaper: boolean;
|
|
24
28
|
isLive: boolean;
|
|
29
|
+
isIdle: boolean;
|
|
25
30
|
isSimulation: boolean;
|
|
26
31
|
recording: boolean;
|
|
27
32
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-execution-mode.d.ts","sourceRoot":"","sources":["../src/use-execution-mode.ts"],"names":[],"mappings":"AAIA,KAAK,aAAa,GAAG;IACnB,IAAI,EAAE,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"use-execution-mode.d.ts","sourceRoot":"","sources":["../src/use-execution-mode.ts"],"names":[],"mappings":"AAIA,KAAK,aAAa,GAAG;IACnB,IAAI,EAAE,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;IAC3C,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,wBAAgB,mBAAmB;;;EAKlC;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE;;;EAKjE;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE;;;EAKhE;AAED,wBAAgB,iBAAiB;;;EAKhC;AAED,eAAO,MAAM,gBAAgB;;;;;;;CAW5B,CAAC"}
|
|
@@ -1,36 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useExecutionMode = exports.liveExecutionMode = exports.paperExecutionMode = exports.replayExecutionMode = void 0;
|
|
3
|
+
exports.useExecutionMode = exports.idleExecutionMode = exports.liveExecutionMode = exports.paperExecutionMode = exports.replayExecutionMode = void 0;
|
|
4
4
|
const module_1 = require("./module");
|
|
5
5
|
const injectionToken = Symbol('execution-mode');
|
|
6
6
|
function replayExecutionMode() {
|
|
7
7
|
return {
|
|
8
8
|
provide: injectionToken,
|
|
9
|
-
useValue: { mode: '
|
|
9
|
+
useValue: { mode: 'replay', recording: false }
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
12
|
exports.replayExecutionMode = replayExecutionMode;
|
|
13
13
|
function paperExecutionMode(options) {
|
|
14
14
|
return {
|
|
15
15
|
provide: injectionToken,
|
|
16
|
-
useValue: Object.assign({ mode: '
|
|
16
|
+
useValue: Object.assign({ mode: 'paper' }, options)
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
exports.paperExecutionMode = paperExecutionMode;
|
|
20
20
|
function liveExecutionMode(options) {
|
|
21
21
|
return {
|
|
22
22
|
provide: injectionToken,
|
|
23
|
-
useValue: Object.assign({ mode: '
|
|
23
|
+
useValue: Object.assign({ mode: 'live' }, options)
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
exports.liveExecutionMode = liveExecutionMode;
|
|
27
|
+
function idleExecutionMode() {
|
|
28
|
+
return {
|
|
29
|
+
provide: injectionToken,
|
|
30
|
+
useValue: { mode: 'idle', recording: false }
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
exports.idleExecutionMode = idleExecutionMode;
|
|
27
34
|
const useExecutionMode = () => {
|
|
28
35
|
const mode = (0, module_1.useContext)(injectionToken);
|
|
29
36
|
return {
|
|
30
|
-
isReplay: mode.mode === '
|
|
31
|
-
isPaper: mode.mode === '
|
|
32
|
-
isLive: mode.mode === '
|
|
33
|
-
|
|
37
|
+
isReplay: mode.mode === 'replay',
|
|
38
|
+
isPaper: mode.mode === 'paper',
|
|
39
|
+
isLive: mode.mode === 'live',
|
|
40
|
+
isIdle: mode.mode === 'idle',
|
|
41
|
+
isSimulation: mode.mode !== 'live',
|
|
34
42
|
recording: mode.recording
|
|
35
43
|
};
|
|
36
44
|
};
|
package/dist/use-timestamp.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useTimestamp = void 0;
|
|
4
|
-
const
|
|
4
|
+
const replay_1 = require("./replay");
|
|
5
5
|
const use_execution_mode_1 = require("./use-execution-mode");
|
|
6
6
|
function useTimestamp() {
|
|
7
7
|
const { isReplay } = (0, use_execution_mode_1.useExecutionMode)();
|
|
8
8
|
if (isReplay) {
|
|
9
|
-
return (0,
|
|
9
|
+
return (0, replay_1.useReplayManager)().timestamp();
|
|
10
10
|
}
|
|
11
11
|
return Date.now();
|
|
12
12
|
}
|
package/package.json
CHANGED
package/src/cli/pull.ts
CHANGED
|
@@ -1,72 +1,15 @@
|
|
|
1
|
-
import { join } from 'path';
|
|
2
|
-
|
|
3
1
|
import build from '@lib/cli/build';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
import { paperExecutionMode } from '@lib/use-execution-mode';
|
|
2
|
+
import { idleExecutionMode } from '@lib/use-execution-mode';
|
|
3
|
+
|
|
4
|
+
import { Script } from './internal/script';
|
|
8
5
|
|
|
9
6
|
export default async function (name: string, instrument: string, options: any) {
|
|
10
7
|
if (await build()) {
|
|
11
8
|
return;
|
|
12
9
|
}
|
|
13
|
-
await import(join(buildDirectory(), 'index'));
|
|
14
|
-
|
|
15
|
-
const script = await import(join(buildDirectory(), name));
|
|
16
|
-
|
|
17
|
-
const module = new Module([
|
|
18
|
-
...core(),
|
|
19
|
-
...script.module,
|
|
20
|
-
paperExecutionMode({ recording: false })
|
|
21
|
-
]);
|
|
22
|
-
|
|
23
|
-
const { act } = await module.awake();
|
|
24
|
-
|
|
25
|
-
const output = await act(() => script.default());
|
|
26
|
-
|
|
27
|
-
/*const builder = new SessionBuilder().useSessionId(
|
|
28
|
-
options.id ? Number(options.id) : now()
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
await spawn(name, builder);
|
|
32
|
-
|
|
33
|
-
const session = builder.paper();
|
|
34
|
-
|
|
35
|
-
console.time('Pulling completed in');
|
|
36
|
-
|
|
37
|
-
await session.awake();
|
|
38
|
-
|
|
39
|
-
const bar = new SingleBar(
|
|
40
|
-
{
|
|
41
|
-
format: `Pulling ${instrument} [{bar}] {percentage}% | ETA: {eta}s | {value}/{total}`
|
|
42
|
-
},
|
|
43
|
-
Presets.rect
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
const feed = new Feed(builder.storage('feed'));
|
|
47
|
-
const from = options.from ? Date.parse(options.from) : builder.period.from;
|
|
48
|
-
const to = options.to ? Date.parse(options.to) : builder.period.to;
|
|
49
|
-
|
|
50
|
-
bar.start(100, 0);
|
|
51
|
-
|
|
52
|
-
await session.aggregate.feed(
|
|
53
|
-
instrumentOf(instrument),
|
|
54
|
-
from,
|
|
55
|
-
to,
|
|
56
|
-
async (timestamp, events) => {
|
|
57
|
-
const duration = to - from;
|
|
58
|
-
const completed = timestamp - from;
|
|
59
|
-
|
|
60
|
-
await feed.save(events);
|
|
61
|
-
|
|
62
|
-
bar.update(Math.floor((completed / duration) * 100));
|
|
63
|
-
}
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
bar.update(100);
|
|
67
|
-
bar.stop();
|
|
68
10
|
|
|
69
|
-
|
|
11
|
+
const script = new Script(name, [idleExecutionMode()]);
|
|
12
|
+
//const output = await script.run();
|
|
70
13
|
|
|
71
|
-
console.
|
|
14
|
+
//console.log(output);
|
|
72
15
|
}
|
package/src/cli/replay.ts
CHANGED
|
@@ -1,31 +1,19 @@
|
|
|
1
|
-
import { join } from 'path';
|
|
2
|
-
import { lastValueFrom } from 'rxjs';
|
|
3
|
-
|
|
4
1
|
import build from '@lib/cli/build';
|
|
5
|
-
import { buildDirectory } from '@lib/cli/internal/workspace';
|
|
6
|
-
import { core } from '@lib/core';
|
|
7
|
-
import { Dependency, Module } from '@lib/module';
|
|
8
2
|
import { replayOptions } from '@lib/replay';
|
|
9
3
|
import { replayExecutionMode } from '@lib/use-execution-mode';
|
|
10
4
|
|
|
5
|
+
import { Script } from './internal/script';
|
|
6
|
+
|
|
11
7
|
export default async function (name: string, options: any) {
|
|
12
8
|
if (await build()) {
|
|
13
9
|
return;
|
|
14
10
|
}
|
|
15
11
|
|
|
16
|
-
const script =
|
|
17
|
-
const dependencies = script.module2 as Dependency[];
|
|
18
|
-
|
|
19
|
-
const module = new Module([
|
|
20
|
-
...core(),
|
|
21
|
-
...dependencies,
|
|
12
|
+
const script = new Script(name, [
|
|
22
13
|
replayOptions({ from: 0, to: Number.MAX_VALUE }),
|
|
23
14
|
replayExecutionMode()
|
|
24
15
|
]);
|
|
25
|
-
|
|
26
|
-
const { act } = await module.awake();
|
|
27
|
-
|
|
28
|
-
const output = await act(() => lastValueFrom(script.default(options)));
|
|
16
|
+
const output = await script.run();
|
|
29
17
|
|
|
30
18
|
console.log(output);
|
|
31
19
|
}
|