@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.
- package/lib/app.d.ts +12 -0
- package/lib/app.d.ts.map +1 -0
- package/lib/app.js +35 -0
- package/lib/cli/build.d.ts.map +1 -1
- package/lib/cli/build.js +8 -18
- package/lib/cli/index.js +3 -12
- package/lib/cli/internal/script.d.ts +1 -1
- package/lib/cli/internal/script.d.ts.map +1 -1
- package/lib/cli/internal/script.js +8 -28
- package/lib/cli/live.js +10 -22
- package/lib/cli/paper.js +10 -22
- package/lib/cli/replay.d.ts.map +1 -1
- package/lib/cli/replay.js +15 -26
- package/lib/index.d.ts +1 -6
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -6
- package/lib/make-test-module.d.ts +1 -6
- package/lib/make-test-module.d.ts.map +1 -1
- package/lib/make-test-module.js +19 -30
- package/lib/module.d.ts.map +1 -1
- package/lib/module.js +9 -24
- package/lib/module.spec.js +8 -17
- package/lib/replay/use-replay-options.d.ts +5 -4
- package/lib/replay/use-replay-options.d.ts.map +1 -1
- package/lib/replay/use-replay-options.js +5 -1
- package/lib/replay/use-replay-scheduler.d.ts +7 -6
- package/lib/replay/use-replay-scheduler.d.ts.map +1 -1
- package/lib/replay/use-replay-scheduler.js +64 -70
- package/lib/replay/use-replay-storage-buffer.d.ts +3 -2
- package/lib/replay/use-replay-storage-buffer.d.ts.map +1 -1
- package/lib/replay/use-replay-storage-buffer.js +12 -23
- package/lib/replay/use-replay-storage-cursor.d.ts +9 -8
- package/lib/replay/use-replay-storage-cursor.d.ts.map +1 -1
- package/lib/replay/use-replay-storage-cursor.js +17 -25
- package/lib/replay/use-replay-storage.d.ts +5 -4
- package/lib/replay/use-replay-storage.d.ts.map +1 -1
- package/lib/replay/use-replay-storage.js +32 -39
- package/lib/session/use-session-storage.d.ts +1 -1
- package/lib/session/use-session-storage.d.ts.map +1 -1
- package/lib/session/use-session-storage.js +8 -5
- package/lib/shared/environment.js +1 -1
- package/lib/shared/index.d.ts +0 -1
- package/lib/shared/index.d.ts.map +1 -1
- package/lib/shared/index.js +0 -1
- package/lib/simulator/use-simulator.spec.js +17 -30
- package/lib/storage/in-memory/in-memory-storage.d.ts.map +1 -1
- package/lib/storage/in-memory/in-memory-storage.factory.js +2 -2
- package/lib/storage/in-memory/in-memory-storage.js +56 -55
- package/lib/storage/in-memory/in-memory-storage.spec.js +90 -100
- package/lib/storage/storage.d.ts +9 -8
- package/lib/storage/storage.d.ts.map +1 -1
- package/lib/storage/storage.js +8 -2
- package/lib/storage/use-cache.d.ts +1 -1
- package/lib/storage/use-cache.d.ts.map +1 -1
- package/lib/storage/use-cache.js +5 -5
- package/lib/storage/use-cache.spec.js +14 -25
- package/lib/storage/use-storage.d.ts +1 -1
- package/lib/storage/use-storage.d.ts.map +1 -1
- package/lib/storage/use-storage.js +9 -6
- package/lib/use-execution-mode.js +2 -2
- package/lib/use-hash.spec.js +3 -6
- package/lib/use-logger.d.ts +1 -1
- package/lib/use-logger.d.ts.map +1 -1
- package/lib/use-logger.js +10 -7
- package/lib/use-memo.spec.js +14 -25
- package/lib/use-socket.d.ts +3 -2
- package/lib/use-socket.d.ts.map +1 -1
- package/lib/use-socket.js +2 -2
- package/lib/use-timestamp.d.ts +14 -1
- package/lib/use-timestamp.d.ts.map +1 -1
- package/lib/use-timestamp.js +30 -3
- package/lib/with-request.d.ts +2 -1
- package/lib/with-request.d.ts.map +1 -1
- package/lib/with-request.js +4 -13
- package/package.json +6 -10
- package/src/app.ts +52 -0
- package/src/cli/build.ts +11 -6
- package/src/cli/internal/script.ts +25 -54
- package/src/cli/replay.ts +13 -2
- package/src/index.ts +1 -6
- package/src/make-test-module.ts +13 -21
- package/src/module.ts +0 -3
- package/src/replay/use-replay-options.ts +7 -3
- package/src/replay/use-replay-scheduler.ts +75 -67
- package/src/replay/use-replay-storage-buffer.ts +2 -1
- package/src/replay/use-replay-storage-cursor.ts +33 -28
- package/src/replay/use-replay-storage.ts +36 -27
- package/src/session/use-session-storage.ts +7 -5
- package/src/shared/index.ts +0 -1
- package/src/storage/in-memory/in-memory-storage.spec.ts +55 -54
- package/src/storage/in-memory/in-memory-storage.ts +24 -7
- package/src/storage/storage.ts +16 -7
- package/src/storage/use-cache.ts +4 -4
- package/src/storage/use-storage.ts +8 -6
- package/src/use-hash.spec.ts +3 -6
- package/src/use-logger.ts +9 -6
- package/src/use-socket.ts +5 -5
- package/src/use-timestamp.ts +41 -3
- package/src/with-request.ts +3 -3
- package/lib/asset/asset.d.ts +0 -41
- package/lib/asset/asset.d.ts.map +0 -1
- package/lib/asset/asset.js +0 -76
- package/lib/asset/asset.spec.d.ts +0 -2
- package/lib/asset/asset.spec.d.ts.map +0 -1
- package/lib/asset/asset.spec.js +0 -54
- package/lib/asset/index.d.ts +0 -2
- package/lib/asset/index.d.ts.map +0 -1
- package/lib/asset/index.js +0 -17
- package/lib/component/distinct-until-timesamp-changed.d.ts +0 -5
- package/lib/component/distinct-until-timesamp-changed.d.ts.map +0 -1
- package/lib/component/distinct-until-timesamp-changed.js +0 -9
- package/lib/component/error.d.ts +0 -17
- package/lib/component/error.d.ts.map +0 -1
- package/lib/component/error.js +0 -33
- package/lib/component/index.d.ts +0 -8
- package/lib/component/index.d.ts.map +0 -1
- package/lib/component/index.js +0 -23
- package/lib/component/ohlc-operator.d.ts +0 -11
- package/lib/component/ohlc-operator.d.ts.map +0 -1
- package/lib/component/ohlc-operator.js +0 -69
- package/lib/component/ohlc-operator.spec.d.ts +0 -2
- package/lib/component/ohlc-operator.spec.d.ts.map +0 -1
- package/lib/component/ohlc-operator.spec.js +0 -110
- package/lib/component/ohlc.d.ts +0 -12
- package/lib/component/ohlc.d.ts.map +0 -1
- package/lib/component/ohlc.js +0 -20
- package/lib/component/ohlc.spec.d.ts +0 -2
- package/lib/component/ohlc.spec.d.ts.map +0 -1
- package/lib/component/ohlc.spec.js +0 -25
- package/lib/component/timeframe.d.ts +0 -15
- package/lib/component/timeframe.d.ts.map +0 -1
- package/lib/component/timeframe.js +0 -21
- package/lib/core.d.ts +0 -3
- package/lib/core.d.ts.map +0 -1
- package/lib/core.js +0 -17
- package/lib/instrument/commission/commission.d.ts +0 -16
- package/lib/instrument/commission/commission.d.ts.map +0 -1
- package/lib/instrument/commission/commission.js +0 -28
- package/lib/instrument/commission/commission.spec.d.ts +0 -2
- package/lib/instrument/commission/commission.spec.d.ts.map +0 -1
- package/lib/instrument/commission/commission.spec.js +0 -30
- package/lib/instrument/index.d.ts +0 -3
- package/lib/instrument/index.d.ts.map +0 -1
- package/lib/instrument/index.js +0 -18
- package/lib/instrument/instrument.d.ts +0 -28
- package/lib/instrument/instrument.d.ts.map +0 -1
- package/lib/instrument/instrument.js +0 -53
- package/lib/instrument/instrument.spec.d.ts +0 -2
- package/lib/instrument/instrument.spec.d.ts.map +0 -1
- package/lib/instrument/instrument.spec.js +0 -51
- package/lib/operators.d.ts +0 -5
- package/lib/operators.d.ts.map +0 -1
- package/lib/operators.js +0 -16
- package/lib/shared/datetime.d.ts +0 -3
- package/lib/shared/datetime.d.ts.map +0 -1
- package/lib/shared/datetime.js +0 -7
- package/lib/strategy.d.ts +0 -15
- package/lib/strategy.d.ts.map +0 -1
- package/lib/strategy.js +0 -26
- package/lib/strategy.spec.d.ts +0 -2
- package/lib/strategy.spec.d.ts.map +0 -1
- package/lib/strategy.spec.js +0 -34
- package/lib/when-socket.d.ts +0 -8
- package/lib/when-socket.d.ts.map +0 -1
- package/lib/when-socket.js +0 -53
- package/lib/with-memo.d.ts +0 -5
- package/lib/with-memo.d.ts.map +0 -1
- package/lib/with-memo.js +0 -20
- package/lib/with-memo.spec.d.ts +0 -2
- package/lib/with-memo.spec.d.ts.map +0 -1
- package/lib/with-memo.spec.js +0 -47
- package/src/asset/asset.spec.ts +0 -70
- package/src/asset/asset.ts +0 -89
- package/src/asset/index.ts +0 -1
- package/src/component/distinct-until-timesamp-changed.ts +0 -11
- package/src/component/error.ts +0 -32
- package/src/component/index.ts +0 -7
- package/src/component/ohlc-operator.spec.ts +0 -125
- package/src/component/ohlc-operator.ts +0 -122
- package/src/component/ohlc.spec.ts +0 -30
- package/src/component/ohlc.ts +0 -18
- package/src/component/timeframe.ts +0 -17
- package/src/core.ts +0 -16
- package/src/instrument/commission/commission.spec.ts +0 -35
- package/src/instrument/commission/commission.ts +0 -27
- package/src/instrument/index.ts +0 -2
- package/src/instrument/instrument.spec.ts +0 -76
- package/src/instrument/instrument.ts +0 -65
- package/src/operators.ts +0 -18
- package/src/shared/datetime.ts +0 -5
- package/src/strategy.spec.ts +0 -42
- package/src/strategy.ts +0 -36
- package/src/when-socket.ts +0 -61
- package/src/with-memo.spec.ts +0 -46
- 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:
|
|
4
|
-
to:
|
|
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:
|
|
13
|
-
to:
|
|
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;
|
|
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:
|
|
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
|
|
4
|
+
export declare function useReplayScheduler(): {
|
|
4
5
|
stream: Observable<[{
|
|
5
6
|
size(): number;
|
|
6
7
|
peek(): {
|
|
7
|
-
timestamp:
|
|
8
|
+
timestamp: Timestamp<"ns">;
|
|
8
9
|
payload: any;
|
|
9
10
|
};
|
|
10
11
|
dequeue(): {
|
|
11
|
-
timestamp:
|
|
12
|
+
timestamp: Timestamp<"ns">;
|
|
12
13
|
payload: any;
|
|
13
14
|
};
|
|
14
15
|
completed(): boolean;
|
|
15
16
|
fetchNextPage(): Promise<void>;
|
|
16
17
|
}, {
|
|
17
|
-
timestamp:
|
|
18
|
+
timestamp: Timestamp<'ns'>;
|
|
18
19
|
payload: any;
|
|
19
20
|
}]>;
|
|
20
|
-
timestamp():
|
|
21
|
+
timestamp(): Timestamp<"ns">;
|
|
21
22
|
stop(): void;
|
|
22
23
|
tryContinue: () => void;
|
|
23
24
|
watch<T>(query: ReplayQuery<T>): Observable<{
|
|
24
|
-
timestamp:
|
|
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;
|
|
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
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
stopAcquire
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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:
|
|
6
|
+
timestamp: Timestamp<'ns'>;
|
|
6
7
|
payload: T;
|
|
7
8
|
};
|
|
8
9
|
dequeue(): {
|
|
9
|
-
timestamp:
|
|
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":"
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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:
|
|
8
|
-
max:
|
|
8
|
+
min: Timestamp<'ns'>;
|
|
9
|
+
max: Timestamp<'ns'>;
|
|
9
10
|
};
|
|
10
11
|
};
|
|
11
12
|
}): Promise<{
|
|
12
|
-
timestamp:
|
|
13
|
+
timestamp: Timestamp<'ns'>;
|
|
13
14
|
payload: V;
|
|
14
15
|
}[]>;
|
|
15
16
|
}
|
|
16
|
-
export declare
|
|
17
|
+
export declare function useReplayStorageCursor(): {
|
|
17
18
|
get<T>(query: ReplayQuery<T>): {
|
|
18
19
|
size(): number;
|
|
19
20
|
peek(): {
|
|
20
|
-
timestamp:
|
|
21
|
+
timestamp: Timestamp<"ns">;
|
|
21
22
|
payload: T;
|
|
22
23
|
};
|
|
23
24
|
dequeue(): {
|
|
24
|
-
timestamp:
|
|
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:
|
|
34
|
+
timestamp: Timestamp<"ns">;
|
|
34
35
|
payload: any;
|
|
35
36
|
};
|
|
36
37
|
dequeue(): {
|
|
37
|
-
timestamp:
|
|
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;
|
|
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
|
|
4
|
+
const use_memo_1 = require("../use-memo");
|
|
14
5
|
const use_replay_storage_buffer_1 = require("./use-replay-storage-buffer");
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
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:
|
|
9
|
-
max:
|
|
9
|
+
min: Timestamp<'ns'>;
|
|
10
|
+
max: Timestamp<'ns'>;
|
|
10
11
|
};
|
|
11
12
|
};
|
|
12
13
|
}, storage: {
|
|
13
14
|
save: (objects: {
|
|
14
|
-
timestamp:
|
|
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:
|
|
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;
|
|
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: '
|
|
13
|
+
timestamp: 'bigint',
|
|
22
14
|
uri: 'string',
|
|
23
|
-
min: '
|
|
24
|
-
max: '
|
|
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: '
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
save(objects) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
|
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,
|
|
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
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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;
|
package/lib/shared/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC"}
|
package/lib/shared/index.js
CHANGED
|
@@ -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);
|