@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,43 +1,30 @@
|
|
|
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
|
const make_test_module_1 = require("../make-test-module");
|
|
13
4
|
const use_execution_mode_1 = require("../use-execution-mode");
|
|
14
5
|
const use_simulator_1 = require("./use-simulator");
|
|
15
6
|
describe(use_simulator_1.useSimulator.name, () => {
|
|
16
7
|
let fixtures;
|
|
17
|
-
beforeEach(() =>
|
|
18
|
-
fixtures =
|
|
19
|
-
})
|
|
20
|
-
test('get real value when simulator mode disabled', () =>
|
|
21
|
-
const { act } =
|
|
8
|
+
beforeEach(async () => {
|
|
9
|
+
fixtures = await getFixtures();
|
|
10
|
+
});
|
|
11
|
+
test('get real value when simulator mode disabled', async () => {
|
|
12
|
+
const { act } = await fixtures.givenModule(false);
|
|
22
13
|
const value = act(() => (0, use_simulator_1.useSimulator)('simulator', 'real'));
|
|
23
14
|
expect(value).toBe('real');
|
|
24
|
-
})
|
|
25
|
-
test('get simulation value when simulator mode enabled', () =>
|
|
26
|
-
const { act } =
|
|
15
|
+
});
|
|
16
|
+
test('get simulation value when simulator mode enabled', async () => {
|
|
17
|
+
const { act } = await fixtures.givenModule(true);
|
|
27
18
|
const value = act(() => (0, use_simulator_1.useSimulator)('simulator', 'real'));
|
|
28
19
|
expect(value).toBe('simulator');
|
|
29
|
-
}));
|
|
30
|
-
});
|
|
31
|
-
function getFixtures() {
|
|
32
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
return {
|
|
34
|
-
givenModule(isSimulation) {
|
|
35
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
return isSimulation
|
|
37
|
-
? yield (0, make_test_module_1.makeTestModule)([use_execution_mode_1.useExecutionMode.paperOptions({ recording: false })])
|
|
38
|
-
: yield (0, make_test_module_1.makeTestModule)([use_execution_mode_1.useExecutionMode.liveOptions({ recording: false })]);
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
20
|
});
|
|
21
|
+
});
|
|
22
|
+
async function getFixtures() {
|
|
23
|
+
return {
|
|
24
|
+
async givenModule(isSimulation) {
|
|
25
|
+
return isSimulation
|
|
26
|
+
? await (0, make_test_module_1.makeTestModule)([use_execution_mode_1.useExecutionMode.paperOptions({ recording: false })])
|
|
27
|
+
: await (0, make_test_module_1.makeTestModule)([use_execution_mode_1.useExecutionMode.liveOptions({ recording: false })]);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
43
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"in-memory-storage.d.ts","sourceRoot":"","sources":["../../../src/storage/in-memory/in-memory-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,KAAK,EACL,WAAW,EACX,eAAe,EACf,OAAO,EACR,MAAM,cAAc,CAAC;AAEtB,qBAAa,eAAgB,YAAW,OAAO;IAC7C,OAAO,CAAC,MAAM,CAAqC;IAE7C,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAI/B,KAAK,CAAC,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,EAC7D,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,GAChC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"in-memory-storage.d.ts","sourceRoot":"","sources":["../../../src/storage/in-memory/in-memory-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,KAAK,EACL,WAAW,EACX,eAAe,EACf,OAAO,EACR,MAAM,cAAc,CAAC;AAEtB,qBAAa,eAAgB,YAAW,OAAO;IAC7C,OAAO,CAAC,MAAM,CAAqC;IAE7C,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAI/B,KAAK,CAAC,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,EAC7D,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,GAChC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC;IA0D3B,IAAI,CAAC,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,EAC5D,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAAE,GAC7B,OAAO,CAAC,IAAI,CAAC;IAchB,KAAK;CAGN"}
|
|
@@ -12,8 +12,8 @@ const module_1 = require("../../module");
|
|
|
12
12
|
const in_memory_storage_1 = require("./in-memory-storage");
|
|
13
13
|
let InMemoryStorageFactory = InMemoryStorageFactory_1 = class InMemoryStorageFactory {
|
|
14
14
|
for(key) {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
return (InMemoryStorageFactory_1.storage[key] ??
|
|
16
|
+
(InMemoryStorageFactory_1.storage[key] = new in_memory_storage_1.InMemoryStorage()));
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
19
|
InMemoryStorageFactory.storage = {};
|
|
@@ -1,69 +1,70 @@
|
|
|
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.InMemoryStorage = void 0;
|
|
13
4
|
class InMemoryStorage {
|
|
14
5
|
constructor() {
|
|
15
6
|
this.tables = {};
|
|
16
7
|
}
|
|
17
|
-
index() {
|
|
18
|
-
return
|
|
19
|
-
return Object.keys(this.tables);
|
|
20
|
-
});
|
|
8
|
+
async index() {
|
|
9
|
+
return Object.keys(this.tables);
|
|
21
10
|
}
|
|
22
|
-
query(type, query) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
11
|
+
async query(type, query) {
|
|
12
|
+
if (!this.tables[type.discriminator]) {
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
let set = this.tables[type.discriminator];
|
|
16
|
+
if (query.where) {
|
|
17
|
+
for (const prop of Object.keys(query.where)) {
|
|
18
|
+
const expression = query.where[prop];
|
|
19
|
+
switch (expression?.type) {
|
|
20
|
+
case 'eq':
|
|
21
|
+
set = set.filter(it => it[prop] == expression.value);
|
|
22
|
+
break;
|
|
23
|
+
case 'gt':
|
|
24
|
+
set = set.filter(it => {
|
|
25
|
+
const value = it[prop];
|
|
26
|
+
return typeof value === 'bigint'
|
|
27
|
+
? BigInt(value) > expression.value
|
|
28
|
+
: Number(value) > Number(expression.value);
|
|
29
|
+
});
|
|
30
|
+
break;
|
|
31
|
+
case 'lt':
|
|
32
|
+
set = set.filter(it => {
|
|
33
|
+
const value = it[prop];
|
|
34
|
+
return typeof value === 'bigint'
|
|
35
|
+
? BigInt(value) < expression.value
|
|
36
|
+
: Number(value) < Number(expression.value);
|
|
37
|
+
});
|
|
38
|
+
break;
|
|
39
|
+
case 'between':
|
|
40
|
+
set = set.filter(it => {
|
|
41
|
+
const value = it[prop];
|
|
42
|
+
return typeof value === 'bigint'
|
|
43
|
+
? BigInt(value) > expression.min && BigInt(value) < expression.max
|
|
44
|
+
: Number(value) > Number(expression.min) &&
|
|
45
|
+
Number(value) < Number(expression.max);
|
|
46
|
+
});
|
|
47
|
+
break;
|
|
45
48
|
}
|
|
46
49
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
}
|
|
51
|
+
if (query.limit) {
|
|
52
|
+
set = set.slice(0, query.limit);
|
|
53
|
+
}
|
|
54
|
+
if (query.orderBy === 'DESC') {
|
|
55
|
+
set = set.reverse();
|
|
56
|
+
}
|
|
57
|
+
return set;
|
|
55
58
|
}
|
|
56
|
-
save(type, objects) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
buffer.sort((lhs, rhs) => lhs.timestamp - rhs.timestamp);
|
|
66
|
-
});
|
|
59
|
+
async save(type, objects) {
|
|
60
|
+
if (!this.tables[type.discriminator]) {
|
|
61
|
+
this.tables[type.discriminator] = [];
|
|
62
|
+
}
|
|
63
|
+
const buffer = this.tables[type.discriminator];
|
|
64
|
+
for (const document of objects) {
|
|
65
|
+
buffer.push(document);
|
|
66
|
+
}
|
|
67
|
+
buffer.sort((lhs, rhs) => Number(lhs.timestamp - rhs.timestamp));
|
|
67
68
|
}
|
|
68
69
|
clear() {
|
|
69
70
|
this.tables = {};
|
|
@@ -1,167 +1,157 @@
|
|
|
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
|
const shared_1 = require("../../shared");
|
|
13
4
|
const storage_1 = require("../../storage");
|
|
5
|
+
const use_timestamp_1 = require("../../use-timestamp");
|
|
14
6
|
const in_memory_storage_1 = require("./in-memory-storage");
|
|
15
7
|
describe(in_memory_storage_1.InMemoryStorage.name, () => {
|
|
16
8
|
let fixtures;
|
|
17
|
-
beforeEach(() =>
|
|
18
|
-
fixtures =
|
|
19
|
-
})
|
|
20
|
-
test('read empty storage', () =>
|
|
9
|
+
beforeEach(async () => {
|
|
10
|
+
fixtures = await getFixtures();
|
|
11
|
+
});
|
|
12
|
+
test('read empty storage', async () => {
|
|
21
13
|
const { sut } = fixtures;
|
|
22
14
|
const pricing = storage_1.Storage.createObject('pricing', {
|
|
23
15
|
timestamp: 'number',
|
|
24
16
|
rate: 'decimal'
|
|
25
17
|
});
|
|
26
|
-
const set =
|
|
18
|
+
const set = await sut.query(pricing, {});
|
|
27
19
|
expect(set).toEqual([]);
|
|
28
|
-
})
|
|
29
|
-
test('save and read full data', () =>
|
|
20
|
+
});
|
|
21
|
+
test('save and read full data', async () => {
|
|
30
22
|
const { sut } = fixtures;
|
|
31
23
|
const pricing = storage_1.Storage.createObject('pricing', {
|
|
32
|
-
timestamp: '
|
|
24
|
+
timestamp: 'bigint',
|
|
33
25
|
rate: 'decimal'
|
|
34
26
|
});
|
|
35
|
-
|
|
36
|
-
{ timestamp: 1, rate: (0, shared_1.d)(1) },
|
|
37
|
-
{ timestamp: 2, rate: (0, shared_1.d)(2) },
|
|
38
|
-
{ timestamp: 3, rate: (0, shared_1.d)(3) },
|
|
39
|
-
{ timestamp: 4, rate: (0, shared_1.d)(4) },
|
|
40
|
-
{ timestamp: 5, rate: (0, shared_1.d)(5) }
|
|
27
|
+
await sut.save(pricing, [
|
|
28
|
+
{ timestamp: (0, use_timestamp_1.ns)(1), rate: (0, shared_1.d)(1) },
|
|
29
|
+
{ timestamp: (0, use_timestamp_1.ns)(2), rate: (0, shared_1.d)(2) },
|
|
30
|
+
{ timestamp: (0, use_timestamp_1.ns)(3), rate: (0, shared_1.d)(3) },
|
|
31
|
+
{ timestamp: (0, use_timestamp_1.ns)(4), rate: (0, shared_1.d)(4) },
|
|
32
|
+
{ timestamp: (0, use_timestamp_1.ns)(5), rate: (0, shared_1.d)(5) }
|
|
41
33
|
]);
|
|
42
|
-
const set =
|
|
34
|
+
const set = await sut.query(pricing, {});
|
|
43
35
|
expect(set).toEqual([
|
|
44
|
-
{ timestamp: 1, rate: (0, shared_1.d)(1) },
|
|
45
|
-
{ timestamp: 2, rate: (0, shared_1.d)(2) },
|
|
46
|
-
{ timestamp: 3, rate: (0, shared_1.d)(3) },
|
|
47
|
-
{ timestamp: 4, rate: (0, shared_1.d)(4) },
|
|
48
|
-
{ timestamp: 5, rate: (0, shared_1.d)(5) }
|
|
36
|
+
{ timestamp: (0, use_timestamp_1.ns)(1), rate: (0, shared_1.d)(1) },
|
|
37
|
+
{ timestamp: (0, use_timestamp_1.ns)(2), rate: (0, shared_1.d)(2) },
|
|
38
|
+
{ timestamp: (0, use_timestamp_1.ns)(3), rate: (0, shared_1.d)(3) },
|
|
39
|
+
{ timestamp: (0, use_timestamp_1.ns)(4), rate: (0, shared_1.d)(4) },
|
|
40
|
+
{ timestamp: (0, use_timestamp_1.ns)(5), rate: (0, shared_1.d)(5) }
|
|
49
41
|
]);
|
|
50
|
-
})
|
|
51
|
-
test('save and read limited data', () =>
|
|
42
|
+
});
|
|
43
|
+
test('save and read limited data', async () => {
|
|
52
44
|
const { sut } = fixtures;
|
|
53
45
|
const pricing = storage_1.Storage.createObject('pricing', {
|
|
54
|
-
timestamp: '
|
|
46
|
+
timestamp: 'bigint',
|
|
55
47
|
rate: 'decimal'
|
|
56
48
|
});
|
|
57
|
-
|
|
58
|
-
{ timestamp: 1, rate: (0, shared_1.d)(1) },
|
|
59
|
-
{ timestamp: 2, rate: (0, shared_1.d)(2) },
|
|
60
|
-
{ timestamp: 3, rate: (0, shared_1.d)(3) },
|
|
61
|
-
{ timestamp: 4, rate: (0, shared_1.d)(4) },
|
|
62
|
-
{ timestamp: 5, rate: (0, shared_1.d)(5) }
|
|
49
|
+
await sut.save(pricing, [
|
|
50
|
+
{ timestamp: (0, use_timestamp_1.ns)(1), rate: (0, shared_1.d)(1) },
|
|
51
|
+
{ timestamp: (0, use_timestamp_1.ns)(2), rate: (0, shared_1.d)(2) },
|
|
52
|
+
{ timestamp: (0, use_timestamp_1.ns)(3), rate: (0, shared_1.d)(3) },
|
|
53
|
+
{ timestamp: (0, use_timestamp_1.ns)(4), rate: (0, shared_1.d)(4) },
|
|
54
|
+
{ timestamp: (0, use_timestamp_1.ns)(5), rate: (0, shared_1.d)(5) }
|
|
63
55
|
]);
|
|
64
|
-
const set =
|
|
56
|
+
const set = await sut.query(pricing, { limit: 3 });
|
|
65
57
|
expect(set).toEqual([
|
|
66
|
-
{ timestamp: 1, rate: (0, shared_1.d)(1) },
|
|
67
|
-
{ timestamp: 2, rate: (0, shared_1.d)(2) },
|
|
68
|
-
{ timestamp: 3, rate: (0, shared_1.d)(3) }
|
|
58
|
+
{ timestamp: (0, use_timestamp_1.ns)(1), rate: (0, shared_1.d)(1) },
|
|
59
|
+
{ timestamp: (0, use_timestamp_1.ns)(2), rate: (0, shared_1.d)(2) },
|
|
60
|
+
{ timestamp: (0, use_timestamp_1.ns)(3), rate: (0, shared_1.d)(3) }
|
|
69
61
|
]);
|
|
70
|
-
})
|
|
71
|
-
test('save and read desc ordered data', () =>
|
|
62
|
+
});
|
|
63
|
+
test('save and read desc ordered data', async () => {
|
|
72
64
|
const { sut } = fixtures;
|
|
73
65
|
const pricing = storage_1.Storage.createObject('pricing', {
|
|
74
|
-
timestamp: '
|
|
66
|
+
timestamp: 'bigint',
|
|
75
67
|
rate: 'decimal'
|
|
76
68
|
});
|
|
77
|
-
|
|
78
|
-
{ timestamp: 1, rate: (0, shared_1.d)(1) },
|
|
79
|
-
{ timestamp: 2, rate: (0, shared_1.d)(2) },
|
|
80
|
-
{ timestamp: 3, rate: (0, shared_1.d)(3) },
|
|
81
|
-
{ timestamp: 4, rate: (0, shared_1.d)(4) },
|
|
82
|
-
{ timestamp: 5, rate: (0, shared_1.d)(5) }
|
|
69
|
+
await sut.save(pricing, [
|
|
70
|
+
{ timestamp: (0, use_timestamp_1.ns)(1), rate: (0, shared_1.d)(1) },
|
|
71
|
+
{ timestamp: (0, use_timestamp_1.ns)(2), rate: (0, shared_1.d)(2) },
|
|
72
|
+
{ timestamp: (0, use_timestamp_1.ns)(3), rate: (0, shared_1.d)(3) },
|
|
73
|
+
{ timestamp: (0, use_timestamp_1.ns)(4), rate: (0, shared_1.d)(4) },
|
|
74
|
+
{ timestamp: (0, use_timestamp_1.ns)(5), rate: (0, shared_1.d)(5) }
|
|
83
75
|
]);
|
|
84
|
-
const set =
|
|
76
|
+
const set = await sut.query(pricing, { orderBy: 'DESC' });
|
|
85
77
|
expect(set).toEqual([
|
|
86
|
-
{ timestamp: 5, rate: (0, shared_1.d)(5) },
|
|
87
|
-
{ timestamp: 4, rate: (0, shared_1.d)(4) },
|
|
88
|
-
{ timestamp: 3, rate: (0, shared_1.d)(3) },
|
|
89
|
-
{ timestamp: 2, rate: (0, shared_1.d)(2) },
|
|
90
|
-
{ timestamp: 1, rate: (0, shared_1.d)(1) }
|
|
78
|
+
{ timestamp: (0, use_timestamp_1.ns)(5), rate: (0, shared_1.d)(5) },
|
|
79
|
+
{ timestamp: (0, use_timestamp_1.ns)(4), rate: (0, shared_1.d)(4) },
|
|
80
|
+
{ timestamp: (0, use_timestamp_1.ns)(3), rate: (0, shared_1.d)(3) },
|
|
81
|
+
{ timestamp: (0, use_timestamp_1.ns)(2), rate: (0, shared_1.d)(2) },
|
|
82
|
+
{ timestamp: (0, use_timestamp_1.ns)(1), rate: (0, shared_1.d)(1) }
|
|
91
83
|
]);
|
|
92
|
-
})
|
|
93
|
-
test('save and read filtered eq data', () =>
|
|
84
|
+
});
|
|
85
|
+
test('save and read filtered eq data', async () => {
|
|
94
86
|
const { sut } = fixtures;
|
|
95
87
|
const pricing = storage_1.Storage.createObject('pricing', {
|
|
96
|
-
timestamp: '
|
|
88
|
+
timestamp: 'bigint',
|
|
97
89
|
rate: 'decimal'
|
|
98
90
|
});
|
|
99
|
-
|
|
100
|
-
{ timestamp: 1, rate: (0, shared_1.d)(1) },
|
|
101
|
-
{ timestamp: 2, rate: (0, shared_1.d)(2) },
|
|
102
|
-
{ timestamp: 3, rate: (0, shared_1.d)(3) },
|
|
103
|
-
{ timestamp: 4, rate: (0, shared_1.d)(4) },
|
|
104
|
-
{ timestamp: 5, rate: (0, shared_1.d)(5) }
|
|
91
|
+
await sut.save(pricing, [
|
|
92
|
+
{ timestamp: (0, use_timestamp_1.ns)(1), rate: (0, shared_1.d)(1) },
|
|
93
|
+
{ timestamp: (0, use_timestamp_1.ns)(2), rate: (0, shared_1.d)(2) },
|
|
94
|
+
{ timestamp: (0, use_timestamp_1.ns)(3), rate: (0, shared_1.d)(3) },
|
|
95
|
+
{ timestamp: (0, use_timestamp_1.ns)(4), rate: (0, shared_1.d)(4) },
|
|
96
|
+
{ timestamp: (0, use_timestamp_1.ns)(5), rate: (0, shared_1.d)(5) }
|
|
105
97
|
]);
|
|
106
|
-
const set =
|
|
98
|
+
const set = await sut.query(pricing, {
|
|
107
99
|
where: {
|
|
108
100
|
timestamp: (0, storage_1.eq)(4)
|
|
109
101
|
}
|
|
110
102
|
});
|
|
111
|
-
expect(set).toEqual([{ timestamp: 4, rate: (0, shared_1.d)(4) }]);
|
|
112
|
-
})
|
|
113
|
-
test('save and read filtered lt data', () =>
|
|
103
|
+
expect(set).toEqual([{ timestamp: (0, use_timestamp_1.ns)(4), rate: (0, shared_1.d)(4) }]);
|
|
104
|
+
});
|
|
105
|
+
test('save and read filtered lt data', async () => {
|
|
114
106
|
const { sut } = fixtures;
|
|
115
107
|
const pricing = storage_1.Storage.createObject('pricing', {
|
|
116
|
-
timestamp: '
|
|
108
|
+
timestamp: 'bigint',
|
|
117
109
|
rate: 'decimal'
|
|
118
110
|
});
|
|
119
|
-
|
|
120
|
-
{ timestamp: 1, rate: (0, shared_1.d)(1) },
|
|
121
|
-
{ timestamp: 2, rate: (0, shared_1.d)(2) },
|
|
122
|
-
{ timestamp: 3, rate: (0, shared_1.d)(3) },
|
|
123
|
-
{ timestamp: 4, rate: (0, shared_1.d)(4) },
|
|
124
|
-
{ timestamp: 5, rate: (0, shared_1.d)(5) }
|
|
111
|
+
await sut.save(pricing, [
|
|
112
|
+
{ timestamp: (0, use_timestamp_1.ns)(1), rate: (0, shared_1.d)(1) },
|
|
113
|
+
{ timestamp: (0, use_timestamp_1.ns)(2), rate: (0, shared_1.d)(2) },
|
|
114
|
+
{ timestamp: (0, use_timestamp_1.ns)(3), rate: (0, shared_1.d)(3) },
|
|
115
|
+
{ timestamp: (0, use_timestamp_1.ns)(4), rate: (0, shared_1.d)(4) },
|
|
116
|
+
{ timestamp: (0, use_timestamp_1.ns)(5), rate: (0, shared_1.d)(5) }
|
|
125
117
|
]);
|
|
126
|
-
const set =
|
|
118
|
+
const set = await sut.query(pricing, {
|
|
127
119
|
where: {
|
|
128
120
|
timestamp: (0, storage_1.lt)(3)
|
|
129
121
|
}
|
|
130
122
|
});
|
|
131
123
|
expect(set).toEqual([
|
|
132
|
-
{ timestamp: 1, rate: (0, shared_1.d)(1) },
|
|
133
|
-
{ timestamp: 2, rate: (0, shared_1.d)(2) }
|
|
124
|
+
{ timestamp: (0, use_timestamp_1.ns)(1), rate: (0, shared_1.d)(1) },
|
|
125
|
+
{ timestamp: (0, use_timestamp_1.ns)(2), rate: (0, shared_1.d)(2) }
|
|
134
126
|
]);
|
|
135
|
-
})
|
|
136
|
-
test('save and read filtered gt data', () =>
|
|
127
|
+
});
|
|
128
|
+
test('save and read filtered gt data', async () => {
|
|
137
129
|
const { sut } = fixtures;
|
|
138
130
|
const pricing = storage_1.Storage.createObject('pricing', {
|
|
139
|
-
timestamp: '
|
|
131
|
+
timestamp: 'bigint',
|
|
140
132
|
rate: 'decimal'
|
|
141
133
|
});
|
|
142
|
-
|
|
143
|
-
{ timestamp: 1, rate: (0, shared_1.d)(1) },
|
|
144
|
-
{ timestamp: 2, rate: (0, shared_1.d)(2) },
|
|
145
|
-
{ timestamp: 3, rate: (0, shared_1.d)(3) },
|
|
146
|
-
{ timestamp: 4, rate: (0, shared_1.d)(4) },
|
|
147
|
-
{ timestamp: 5, rate: (0, shared_1.d)(5) }
|
|
134
|
+
await sut.save(pricing, [
|
|
135
|
+
{ timestamp: (0, use_timestamp_1.ns)(1), rate: (0, shared_1.d)(1) },
|
|
136
|
+
{ timestamp: (0, use_timestamp_1.ns)(2), rate: (0, shared_1.d)(2) },
|
|
137
|
+
{ timestamp: (0, use_timestamp_1.ns)(3), rate: (0, shared_1.d)(3) },
|
|
138
|
+
{ timestamp: (0, use_timestamp_1.ns)(4), rate: (0, shared_1.d)(4) },
|
|
139
|
+
{ timestamp: (0, use_timestamp_1.ns)(5), rate: (0, shared_1.d)(5) }
|
|
148
140
|
]);
|
|
149
|
-
const set =
|
|
141
|
+
const set = await sut.query(pricing, {
|
|
150
142
|
where: {
|
|
151
143
|
timestamp: (0, storage_1.gt)(3)
|
|
152
144
|
}
|
|
153
145
|
});
|
|
154
146
|
expect(set).toEqual([
|
|
155
|
-
{ timestamp: 4, rate: (0, shared_1.d)(4) },
|
|
156
|
-
{ timestamp: 5, rate: (0, shared_1.d)(5) }
|
|
147
|
+
{ timestamp: (0, use_timestamp_1.ns)(4), rate: (0, shared_1.d)(4) },
|
|
148
|
+
{ timestamp: (0, use_timestamp_1.ns)(5), rate: (0, shared_1.d)(5) }
|
|
157
149
|
]);
|
|
158
|
-
}));
|
|
159
|
-
});
|
|
160
|
-
function getFixtures() {
|
|
161
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
162
|
-
const sut = new in_memory_storage_1.InMemoryStorage();
|
|
163
|
-
return {
|
|
164
|
-
sut
|
|
165
|
-
};
|
|
166
150
|
});
|
|
151
|
+
});
|
|
152
|
+
async function getFixtures() {
|
|
153
|
+
const sut = new in_memory_storage_1.InMemoryStorage();
|
|
154
|
+
return {
|
|
155
|
+
sut
|
|
156
|
+
};
|
|
167
157
|
}
|
package/lib/storage/storage.d.ts
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
import { decimal } from '../shared';
|
|
2
|
-
|
|
2
|
+
import { Timestamp } from '../use-timestamp';
|
|
3
|
+
type Types = string | number | bigint | decimal;
|
|
3
4
|
export declare const eq: <T extends Types>(value: T) => {
|
|
4
5
|
type: "eq";
|
|
5
6
|
value: T;
|
|
6
7
|
};
|
|
7
|
-
export declare const gt: <T extends number>(value: T) => {
|
|
8
|
+
export declare const gt: <T extends number | bigint>(value: T) => {
|
|
8
9
|
type: "gt";
|
|
9
10
|
value: T;
|
|
10
11
|
};
|
|
11
|
-
export declare const lt: <T extends number>(value: T) => {
|
|
12
|
+
export declare const lt: <T extends number | bigint>(value: T) => {
|
|
12
13
|
type: "lt";
|
|
13
14
|
value: T;
|
|
14
15
|
};
|
|
15
|
-
export declare const between: <T extends number>(min: T, max: T) => {
|
|
16
|
+
export declare const between: <T extends number | bigint>(min: T, max: T) => {
|
|
16
17
|
type: "between";
|
|
17
18
|
min: T;
|
|
18
19
|
max: T;
|
|
19
20
|
};
|
|
20
21
|
export type QueryObject = Record<string, Types> & {
|
|
21
|
-
timestamp:
|
|
22
|
+
timestamp: Timestamp<'ns'>;
|
|
22
23
|
};
|
|
23
24
|
export type QueryObjectType<T extends QueryObject> = {
|
|
24
25
|
discriminator: string;
|
|
@@ -35,11 +36,11 @@ export type Query<T extends QueryObject> = {
|
|
|
35
36
|
limit?: number;
|
|
36
37
|
offset?: number;
|
|
37
38
|
};
|
|
38
|
-
export type QueryMappingType = 'number' | 'string' | 'decimal';
|
|
39
|
+
export type QueryMappingType = 'number' | 'bigint' | 'string' | 'decimal';
|
|
39
40
|
export type InferQueryObject<T> = T extends QueryObjectType<infer U> ? {
|
|
40
|
-
[key in keyof T['type']]: T['type'][key] extends 'number' ? number : T['type'][key] extends 'string' ? string : T['type'][key] extends 'decimal' ? decimal : never;
|
|
41
|
+
[key in keyof T['type']]: T['type'][key] extends 'number' ? number : T['type'][key] extends 'bigint' ? bigint : T['type'][key] extends 'string' ? string : T['type'][key] extends 'decimal' ? decimal : never;
|
|
41
42
|
} & {
|
|
42
|
-
timestamp:
|
|
43
|
+
timestamp: Timestamp<'ns'>;
|
|
43
44
|
} : never;
|
|
44
45
|
export declare abstract class Storage {
|
|
45
46
|
static createObject<K extends QueryObject, T extends {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/storage/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/storage/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,KAAK,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAEhD,eAAO,MAAM,EAAE;;;CAAkE,CAAC;AAClF,eAAO,MAAM,EAAE;;;CAGb,CAAC;AACH,eAAO,MAAM,EAAE;;;CAGb,CAAC;AACH,eAAO,MAAM,OAAO;;;;CAIlB,CAAC;AAEH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG;IAAE,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,CAAA;CAAE,CAAC;AACjF,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,WAAW,IAAI;IACnD,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE;SACH,GAAG,IAAI,MAAM,CAAC,GAAG,gBAAgB;KACnC,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,UAAU,GAClB,UAAU,CAAC,OAAO,EAAE,CAAC,GACrB,UAAU,CAAC,OAAO,EAAE,CAAC,GACrB,UAAU,CAAC,OAAO,EAAE,CAAC,GACrB,UAAU,CAAC,OAAO,OAAO,CAAC,CAAC;AAE/B,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,WAAW,IAAI;IACzC,KAAK,CAAC,EAAE,OAAO,CAAC;SACb,GAAG,IAAI,MAAM,CAAC,GAAG,UAAU;KAC7B,CAAC,CAAC;IACH,OAAO,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC;AAC1E,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,CAAC,SAAS,eAAe,CAAC,MAAM,CAAC,CAAC,GAChE;KACG,GAAG,IAAI,MAAM,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,SAAS,QAAQ,GACrD,MAAM,GACN,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,SAAS,QAAQ,GAC/B,MAAM,GACN,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,SAAS,QAAQ,GAC/B,MAAM,GACN,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,SAAS,SAAS,GAChC,OAAO,GACP,KAAK;CACV,GAAG;IAAE,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,CAAA;CAAE,GAClC,KAAK,CAAC;AAEV,8BAAsB,OAAO;IAC3B,MAAM,CAAC,YAAY,CACjB,CAAC,SAAS,WAAW,EACrB,CAAC,SAAS;SAAG,GAAG,IAAI,MAAM,CAAC,GAAG,gBAAgB;KAAE,EAChD,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;;;;IAOhC,QAAQ,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACxC,QAAQ,CAAC,IAAI,CAAC,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,EAC/D,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAAE,GAC7B,OAAO,CAAC,IAAI,CAAC;IAChB,QAAQ,CAAC,KAAK,CAAC,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,EAChE,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,GAChC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC;CAClC"}
|
package/lib/storage/storage.js
CHANGED
|
@@ -3,9 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Storage = exports.between = exports.lt = exports.gt = exports.eq = void 0;
|
|
4
4
|
const eq = (value) => ({ type: 'eq', value });
|
|
5
5
|
exports.eq = eq;
|
|
6
|
-
const gt = (value) => ({
|
|
6
|
+
const gt = (value) => ({
|
|
7
|
+
type: 'gt',
|
|
8
|
+
value
|
|
9
|
+
});
|
|
7
10
|
exports.gt = gt;
|
|
8
|
-
const lt = (value) => ({
|
|
11
|
+
const lt = (value) => ({
|
|
12
|
+
type: 'lt',
|
|
13
|
+
value
|
|
14
|
+
});
|
|
9
15
|
exports.lt = lt;
|
|
10
16
|
const between = (min, max) => ({
|
|
11
17
|
type: 'between',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
2
|
import { dependency } from '../use-hash';
|
|
3
|
-
export declare const useCache: <T>(calculateValue: Observable<T>, dependencies: dependency[], ttl?:
|
|
3
|
+
export declare const useCache: <T>(calculateValue: Observable<T>, dependencies: dependency[], ttl?: bigint) => Observable<T>;
|
|
4
4
|
//# sourceMappingURL=use-cache.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-cache.d.ts","sourceRoot":"","sources":["../../src/storage/use-cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,UAAU,EAAiB,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"use-cache.d.ts","sourceRoot":"","sources":["../../src/storage/use-cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,UAAU,EAAiB,MAAM,MAAM,CAAC;AAG5D,OAAO,EAAE,UAAU,EAAW,MAAM,eAAe,CAAC;AAWpD,eAAO,MAAM,QAAQ,mDAEL,UAAU,EAAE,gCAiC3B,CAAC"}
|
package/lib/storage/use-cache.js
CHANGED
|
@@ -2,22 +2,22 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useCache = void 0;
|
|
4
4
|
const rxjs_1 = require("rxjs");
|
|
5
|
-
const shared_1 = require("../shared");
|
|
6
5
|
const use_storage_1 = require("../storage/use-storage");
|
|
7
6
|
const use_hash_1 = require("../use-hash");
|
|
7
|
+
const use_timestamp_1 = require("../use-timestamp");
|
|
8
8
|
const storage_1 = require("./storage");
|
|
9
9
|
const object = storage_1.Storage.createObject('keyValue', {
|
|
10
|
-
timestamp: '
|
|
10
|
+
timestamp: 'bigint',
|
|
11
11
|
forKey: 'string',
|
|
12
12
|
rawJson: 'string'
|
|
13
13
|
});
|
|
14
|
-
const useCache = (calculateValue, dependencies, ttl = 60 * 60 * 24 *
|
|
14
|
+
const useCache = (calculateValue, dependencies, ttl = BigInt(60 * 60 * 24 * 1000000)) => {
|
|
15
15
|
const storage = (0, use_storage_1.useStorage)(['cache']);
|
|
16
16
|
const key = (0, use_hash_1.useHash)(dependencies);
|
|
17
|
-
const timestamp = (0,
|
|
17
|
+
const timestamp = (0, use_timestamp_1.now)();
|
|
18
18
|
return (0, rxjs_1.from)(storage.query(object, {
|
|
19
19
|
where: {
|
|
20
|
-
timestamp: (0, storage_1.gt)(timestamp - ttl),
|
|
20
|
+
timestamp: (0, storage_1.gt)(timestamp - BigInt(ttl)),
|
|
21
21
|
forKey: (0, storage_1.eq)(key)
|
|
22
22
|
},
|
|
23
23
|
limit: 1,
|
|
@@ -1,36 +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
|
const rxjs_1 = require("rxjs");
|
|
13
4
|
const make_test_module_1 = require("../make-test-module");
|
|
14
5
|
const use_cache_1 = require("../storage/use-cache");
|
|
15
6
|
describe(use_cache_1.useCache.name, () => {
|
|
16
7
|
let fixtures;
|
|
17
|
-
beforeEach(() =>
|
|
18
|
-
fixtures =
|
|
19
|
-
})
|
|
20
|
-
test('cache value for dependencies', () =>
|
|
21
|
-
const value1 =
|
|
22
|
-
const value2 =
|
|
8
|
+
beforeEach(async () => {
|
|
9
|
+
fixtures = await getFixtures();
|
|
10
|
+
});
|
|
11
|
+
test('cache value for dependencies', async () => {
|
|
12
|
+
const value1 = await (0, rxjs_1.firstValueFrom)(fixtures.givenCacheValue((0, rxjs_1.of)(1), ['val']));
|
|
13
|
+
const value2 = await (0, rxjs_1.firstValueFrom)(fixtures.givenCacheValue((0, rxjs_1.of)(2), ['val']));
|
|
23
14
|
expect(value1).toEqual(1);
|
|
24
15
|
expect(value2).toEqual(1);
|
|
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
|
-
givenCacheValue(value, dependencies) {
|
|
32
|
-
return act(() => (0, use_cache_1.useCache)(value, dependencies));
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
16
|
});
|
|
17
|
+
});
|
|
18
|
+
async function getFixtures() {
|
|
19
|
+
const { act } = await (0, make_test_module_1.makeTestModule)([]);
|
|
20
|
+
return {
|
|
21
|
+
givenCacheValue(value, dependencies) {
|
|
22
|
+
return act(() => (0, use_cache_1.useCache)(value, dependencies));
|
|
23
|
+
}
|
|
24
|
+
};
|
|
36
25
|
}
|