@naturalcycles/db-lib 9.24.0 → 9.24.2
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/commondao/common.dao.d.ts +5 -5
- package/dist/commondao/common.dao.model.d.ts +2 -2
- package/dist/db.model.d.ts +2 -2
- package/dist/kv/commonKeyValueDB.d.ts +2 -2
- package/dist/kv/commonKeyValueDaoMemoCache.js +3 -1
- package/dist/pipeline/dbPipelineBackup.d.ts +3 -3
- package/dist/pipeline/dbPipelineCopy.d.ts +2 -2
- package/dist/pipeline/dbPipelineRestore.d.ts +2 -2
- package/dist/testing/daoTest.js +8 -0
- package/package.json +1 -1
- package/src/adapter/file/file.db.ts +4 -3
- package/src/adapter/inmemory/inMemory.db.ts +3 -2
- package/src/commondao/common.dao.model.ts +2 -2
- package/src/commondao/common.dao.ts +7 -7
- package/src/db.model.ts +2 -2
- package/src/kv/commonKeyValueDB.ts +2 -2
- package/src/kv/commonKeyValueDaoMemoCache.ts +10 -2
- package/src/pipeline/dbPipelineBackup.ts +3 -3
- package/src/pipeline/dbPipelineCopy.ts +2 -1
- package/src/pipeline/dbPipelineRestore.ts +2 -1
- package/src/testing/daoTest.ts +11 -0
- package/src/testing/test.model.ts +8 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Transform } from 'node:stream';
|
|
2
|
-
import { AsyncMapper, BaseDBEntity, CommonLogger, JsonSchemaObject, JsonSchemaRootObject, StringMap,
|
|
2
|
+
import { AsyncMapper, BaseDBEntity, CommonLogger, JsonSchemaObject, JsonSchemaRootObject, StringMap, UnixTimestampMillis, Unsaved, ZodSchema } from '@naturalcycles/js-lib';
|
|
3
3
|
import { AjvSchema, ObjectSchema, ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
4
4
|
import { CommonDBTransactionOptions, DBTransaction, RunQueryResult } from '../db.model';
|
|
5
5
|
import { DBQuery, RunnableDBQuery } from '../query/dbQuery';
|
|
@@ -170,10 +170,10 @@ export declare class CommonDao<BM extends BaseDBEntity, DBM extends BaseDBEntity
|
|
|
170
170
|
* Throws if query uses a property that is in `excludeFromIndexes` list.
|
|
171
171
|
*/
|
|
172
172
|
private validateQueryIndexes;
|
|
173
|
-
protected logResult(started:
|
|
174
|
-
protected logSaveResult(started:
|
|
175
|
-
protected logStarted(op: string, table: string, force?: boolean):
|
|
176
|
-
protected logSaveStarted(op: string, items: any, table: string):
|
|
173
|
+
protected logResult(started: UnixTimestampMillis, op: string, res: any, table: string): void;
|
|
174
|
+
protected logSaveResult(started: UnixTimestampMillis, op: string, table: string): void;
|
|
175
|
+
protected logStarted(op: string, table: string, force?: boolean): UnixTimestampMillis;
|
|
176
|
+
protected logSaveStarted(op: string, items: any, table: string): UnixTimestampMillis;
|
|
177
177
|
}
|
|
178
178
|
/**
|
|
179
179
|
* Transaction is committed when the function returns resolved Promise (aka "returns normally").
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseDBEntity, CommonLogger, ErrorMode, Promisable,
|
|
1
|
+
import { BaseDBEntity, CommonLogger, ErrorMode, Promisable, UnixTimestamp, ZodError, ZodSchema } from '@naturalcycles/js-lib';
|
|
2
2
|
import { AjvSchema, AjvValidationError, JoiValidationError, ObjectSchema, TransformLogProgressOptions, TransformMapOptions } from '@naturalcycles/nodejs-lib';
|
|
3
3
|
import { CommonDB } from '../common.db';
|
|
4
4
|
import { CommonDBCreateOptions, CommonDBOptions, CommonDBSaveOptions } from '../db.model';
|
|
@@ -205,7 +205,7 @@ export interface CommonDaoReadOptions extends CommonDaoOptions {
|
|
|
205
205
|
* If provided (and supported by the DB) - will read the data at that point in time (aka "Time machine" feature).
|
|
206
206
|
* This feature is named PITR (point-in-time-recovery) query in Datastore.
|
|
207
207
|
*/
|
|
208
|
-
readAt?:
|
|
208
|
+
readAt?: UnixTimestamp;
|
|
209
209
|
}
|
|
210
210
|
export interface CommonDaoSaveOptions<BM extends BaseDBEntity, DBM extends BaseDBEntity> extends CommonDaoSaveBatchOptions<DBM> {
|
|
211
211
|
/**
|
package/dist/db.model.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ObjectWithId,
|
|
1
|
+
import { ObjectWithId, UnixTimestamp } from '@naturalcycles/js-lib';
|
|
2
2
|
import { CommonDB } from './common.db';
|
|
3
3
|
/**
|
|
4
4
|
* Similar to SQL INSERT, UPDATE.
|
|
@@ -50,7 +50,7 @@ export interface CommonDBReadOptions extends CommonDBOptions {
|
|
|
50
50
|
* If provided (and supported by the DB) - will read the data at that point in time (aka "Time machine" feature).
|
|
51
51
|
* This feature is named PITR (point-in-time-recovery) query in Datastore.
|
|
52
52
|
*/
|
|
53
|
-
readAt?:
|
|
53
|
+
readAt?: UnixTimestamp;
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
56
56
|
* All properties default to undefined.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Integer,
|
|
1
|
+
import { Integer, UnixTimestamp } from '@naturalcycles/js-lib';
|
|
2
2
|
import { ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
3
3
|
import { CommonDBCreateOptions } from '../db.model';
|
|
4
4
|
/**
|
|
@@ -56,7 +56,7 @@ export interface CommonKeyValueDBSaveBatchOptions {
|
|
|
56
56
|
* If set (and if it's implemented by the driver) - will set expiry TTL for each key of the batch.
|
|
57
57
|
* E.g EXAT in Redis.
|
|
58
58
|
*/
|
|
59
|
-
expireAt?:
|
|
59
|
+
expireAt?: UnixTimestamp;
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
62
|
* Manifest of supported features.
|
|
@@ -18,7 +18,9 @@ class CommonKeyValueDaoMemoCache {
|
|
|
18
18
|
return (await this.cfg.dao.getById(k)) || js_lib_1.MISS;
|
|
19
19
|
}
|
|
20
20
|
async set(k, v) {
|
|
21
|
-
const opt = this.cfg.ttl
|
|
21
|
+
const opt = this.cfg.ttl
|
|
22
|
+
? { expireAt: (js_lib_1.localTime.nowUnix() + this.cfg.ttl) }
|
|
23
|
+
: undefined;
|
|
22
24
|
await this.cfg.dao.save(k, v, opt);
|
|
23
25
|
}
|
|
24
26
|
async clear() {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AsyncMapper, ErrorMode, StringMap,
|
|
1
|
+
import { AsyncMapper, ErrorMode, StringMap, UnixTimestamp } from '@naturalcycles/js-lib';
|
|
2
2
|
import { NDJsonStats, TransformLogProgressOptions, TransformMapOptions } from '@naturalcycles/nodejs-lib';
|
|
3
3
|
import { CommonDB } from '../common.db';
|
|
4
4
|
import { DBQuery } from '../index';
|
|
@@ -33,12 +33,12 @@ export interface DBPipelineBackupOptions extends TransformLogProgressOptions {
|
|
|
33
33
|
/**
|
|
34
34
|
* If set - will do "incremental backup" (not full), only for entities that updated >= `sinceUpdated`
|
|
35
35
|
*/
|
|
36
|
-
sinceUpdated?:
|
|
36
|
+
sinceUpdated?: UnixTimestamp;
|
|
37
37
|
/**
|
|
38
38
|
* Map for each table a `sinceUpdated` timestamp, or `undefined`.
|
|
39
39
|
* If set - will do "incremental backup" (not full), only for entities that updated >= `sinceUpdated` (on a per table basis)
|
|
40
40
|
*/
|
|
41
|
-
sinceUpdatedPerTable?: StringMap<
|
|
41
|
+
sinceUpdatedPerTable?: StringMap<UnixTimestamp>;
|
|
42
42
|
/**
|
|
43
43
|
* By default, dbPipelineBackup creates a Query based on sinceUpdated.
|
|
44
44
|
* But if queryPerTable is set for a table - it will override the Query that is ran for that table
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AsyncMapper, ErrorMode } from '@naturalcycles/js-lib';
|
|
1
|
+
import { AsyncMapper, ErrorMode, UnixTimestamp } from '@naturalcycles/js-lib';
|
|
2
2
|
import { NDJsonStats, TransformLogProgressOptions, TransformMapOptions } from '@naturalcycles/nodejs-lib';
|
|
3
3
|
import { CommonDB } from '../common.db';
|
|
4
4
|
import { CommonDBSaveOptions } from '../db.model';
|
|
@@ -39,7 +39,7 @@ export interface DBPipelineCopyOptions extends TransformLogProgressOptions {
|
|
|
39
39
|
*
|
|
40
40
|
* @default undefined
|
|
41
41
|
*/
|
|
42
|
-
sinceUpdated?:
|
|
42
|
+
sinceUpdated?: UnixTimestamp;
|
|
43
43
|
/**
|
|
44
44
|
* Optionally you can provide mapper that is going to run for each table.
|
|
45
45
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AsyncMapper, ErrorMode } from '@naturalcycles/js-lib';
|
|
1
|
+
import { AsyncMapper, ErrorMode, UnixTimestamp } from '@naturalcycles/js-lib';
|
|
2
2
|
import { NDJsonStats, TransformLogProgressOptions, TransformMapOptions } from '@naturalcycles/nodejs-lib';
|
|
3
3
|
import { CommonDB } from '../common.db';
|
|
4
4
|
import { CommonDBSaveOptions } from '../index';
|
|
@@ -46,7 +46,7 @@ export interface DBPipelineRestoreOptions extends TransformLogProgressOptions {
|
|
|
46
46
|
*
|
|
47
47
|
* @default undefined
|
|
48
48
|
*/
|
|
49
|
-
sinceUpdated?:
|
|
49
|
+
sinceUpdated?: UnixTimestamp;
|
|
50
50
|
/**
|
|
51
51
|
* @default false
|
|
52
52
|
* If true - will read ${table}.schema.json files and recreate tables before importing.
|
package/dist/testing/daoTest.js
CHANGED
|
@@ -58,6 +58,14 @@ function runCommonDaoTest(db, quirks = {}) {
|
|
|
58
58
|
test('getByIds(...) should return empty', async () => {
|
|
59
59
|
expect(await dao.getByIds(['abc', 'abcd'])).toEqual([]);
|
|
60
60
|
});
|
|
61
|
+
// TimeMachine
|
|
62
|
+
if (support.timeMachine) {
|
|
63
|
+
test('getByIds(...) 10 minutes ago should return []', async () => {
|
|
64
|
+
expect(await dao.getByIds([item1.id, 'abc'], {
|
|
65
|
+
readAt: js_lib_1.localTime.now().minus(10, 'minute').unix,
|
|
66
|
+
})).toEqual([]);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
61
69
|
// SAVE
|
|
62
70
|
if (support.nullValues) {
|
|
63
71
|
test('should allow to save and load null values', async () => {
|
package/package.json
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
generateJsonSchemaFromData,
|
|
11
11
|
JsonSchemaRootObject,
|
|
12
12
|
ObjectWithId,
|
|
13
|
+
UnixTimestampMillis,
|
|
13
14
|
} from '@naturalcycles/js-lib'
|
|
14
15
|
import { dimGrey, readableCreate, ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
15
16
|
import {
|
|
@@ -240,14 +241,14 @@ export class FileDB extends BaseCommonDB implements CommonDB {
|
|
|
240
241
|
return rows
|
|
241
242
|
}
|
|
242
243
|
|
|
243
|
-
private logStarted(op: string):
|
|
244
|
+
private logStarted(op: string): UnixTimestampMillis {
|
|
244
245
|
if (this.cfg.logStarted) {
|
|
245
246
|
this.cfg.logger?.log(`>> ${op}`)
|
|
246
247
|
}
|
|
247
|
-
return Date.now()
|
|
248
|
+
return Date.now() as UnixTimestampMillis
|
|
248
249
|
}
|
|
249
250
|
|
|
250
|
-
private logFinished(started:
|
|
251
|
+
private logFinished(started: UnixTimestampMillis, op: string): void {
|
|
251
252
|
if (!this.cfg.logFinished) return
|
|
252
253
|
this.cfg.logger?.log(`<< ${op} ${dimGrey(`in ${_since(started)}`)}`)
|
|
253
254
|
}
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
ObjectWithId,
|
|
17
17
|
pMap,
|
|
18
18
|
StringMap,
|
|
19
|
+
UnixTimestampMillis,
|
|
19
20
|
} from '@naturalcycles/js-lib'
|
|
20
21
|
import {
|
|
21
22
|
_pipeline,
|
|
@@ -314,7 +315,7 @@ export class InMemoryDB implements CommonDB {
|
|
|
314
315
|
_assert(this.cfg.persistenceEnabled, 'flushToDisk() called but persistenceEnabled=false')
|
|
315
316
|
const { persistentStoragePath, persistZip } = this.cfg
|
|
316
317
|
|
|
317
|
-
const started = Date.now()
|
|
318
|
+
const started = Date.now() as UnixTimestampMillis
|
|
318
319
|
|
|
319
320
|
await fs2.emptyDirAsync(persistentStoragePath)
|
|
320
321
|
|
|
@@ -343,7 +344,7 @@ export class InMemoryDB implements CommonDB {
|
|
|
343
344
|
_assert(this.cfg.persistenceEnabled, 'restoreFromDisk() called but persistenceEnabled=false')
|
|
344
345
|
const { persistentStoragePath } = this.cfg
|
|
345
346
|
|
|
346
|
-
const started = Date.now()
|
|
347
|
+
const started = Date.now() as UnixTimestampMillis
|
|
347
348
|
|
|
348
349
|
await fs2.ensureDirAsync(persistentStoragePath)
|
|
349
350
|
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
CommonLogger,
|
|
4
4
|
ErrorMode,
|
|
5
5
|
Promisable,
|
|
6
|
-
|
|
6
|
+
UnixTimestamp,
|
|
7
7
|
ZodError,
|
|
8
8
|
ZodSchema,
|
|
9
9
|
} from '@naturalcycles/js-lib'
|
|
@@ -257,7 +257,7 @@ export interface CommonDaoReadOptions extends CommonDaoOptions {
|
|
|
257
257
|
* If provided (and supported by the DB) - will read the data at that point in time (aka "Time machine" feature).
|
|
258
258
|
* This feature is named PITR (point-in-time-recovery) query in Datastore.
|
|
259
259
|
*/
|
|
260
|
-
readAt?:
|
|
260
|
+
readAt?: UnixTimestamp
|
|
261
261
|
}
|
|
262
262
|
|
|
263
263
|
export interface CommonDaoSaveOptions<BM extends BaseDBEntity, DBM extends BaseDBEntity>
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
pMap,
|
|
24
24
|
SKIP,
|
|
25
25
|
StringMap,
|
|
26
|
-
|
|
26
|
+
UnixTimestampMillis,
|
|
27
27
|
Unsaved,
|
|
28
28
|
ZodSchema,
|
|
29
29
|
ZodValidationError,
|
|
@@ -1326,7 +1326,7 @@ export class CommonDao<BM extends BaseDBEntity, DBM extends BaseDBEntity = BM, I
|
|
|
1326
1326
|
}
|
|
1327
1327
|
}
|
|
1328
1328
|
|
|
1329
|
-
protected logResult(started:
|
|
1329
|
+
protected logResult(started: UnixTimestampMillis, op: string, res: any, table: string): void {
|
|
1330
1330
|
if (!this.cfg.logLevel) return
|
|
1331
1331
|
|
|
1332
1332
|
let logRes: any
|
|
@@ -1349,19 +1349,19 @@ export class CommonDao<BM extends BaseDBEntity, DBM extends BaseDBEntity = BM, I
|
|
|
1349
1349
|
this.cfg.logger?.log(`<< ${table}.${op}: ${logRes} in ${_since(started)}`, ...args)
|
|
1350
1350
|
}
|
|
1351
1351
|
|
|
1352
|
-
protected logSaveResult(started:
|
|
1352
|
+
protected logSaveResult(started: UnixTimestampMillis, op: string, table: string): void {
|
|
1353
1353
|
if (!this.cfg.logLevel) return
|
|
1354
1354
|
this.cfg.logger?.log(`<< ${table}.${op} in ${_since(started)}`)
|
|
1355
1355
|
}
|
|
1356
1356
|
|
|
1357
|
-
protected logStarted(op: string, table: string, force = false):
|
|
1357
|
+
protected logStarted(op: string, table: string, force = false): UnixTimestampMillis {
|
|
1358
1358
|
if (this.cfg.logStarted || force) {
|
|
1359
1359
|
this.cfg.logger?.log(`>> ${table}.${op}`)
|
|
1360
1360
|
}
|
|
1361
|
-
return Date.now()
|
|
1361
|
+
return Date.now() as UnixTimestampMillis
|
|
1362
1362
|
}
|
|
1363
1363
|
|
|
1364
|
-
protected logSaveStarted(op: string, items: any, table: string):
|
|
1364
|
+
protected logSaveStarted(op: string, items: any, table: string): UnixTimestampMillis {
|
|
1365
1365
|
if (this.cfg.logStarted) {
|
|
1366
1366
|
const args: any[] = [`>> ${table}.${op}`]
|
|
1367
1367
|
if (Array.isArray(items)) {
|
|
@@ -1379,7 +1379,7 @@ export class CommonDao<BM extends BaseDBEntity, DBM extends BaseDBEntity = BM, I
|
|
|
1379
1379
|
this.cfg.logger?.log(...args)
|
|
1380
1380
|
}
|
|
1381
1381
|
|
|
1382
|
-
return Date.now()
|
|
1382
|
+
return Date.now() as UnixTimestampMillis
|
|
1383
1383
|
}
|
|
1384
1384
|
}
|
|
1385
1385
|
|
package/src/db.model.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ObjectWithId,
|
|
1
|
+
import { ObjectWithId, UnixTimestamp } from '@naturalcycles/js-lib'
|
|
2
2
|
import { CommonDB } from './common.db'
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -57,7 +57,7 @@ export interface CommonDBReadOptions extends CommonDBOptions {
|
|
|
57
57
|
* If provided (and supported by the DB) - will read the data at that point in time (aka "Time machine" feature).
|
|
58
58
|
* This feature is named PITR (point-in-time-recovery) query in Datastore.
|
|
59
59
|
*/
|
|
60
|
-
readAt?:
|
|
60
|
+
readAt?: UnixTimestamp
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Integer,
|
|
1
|
+
import { Integer, UnixTimestamp } from '@naturalcycles/js-lib'
|
|
2
2
|
import { ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
3
3
|
import { CommonDBCreateOptions } from '../db.model'
|
|
4
4
|
|
|
@@ -72,7 +72,7 @@ export interface CommonKeyValueDBSaveBatchOptions {
|
|
|
72
72
|
* If set (and if it's implemented by the driver) - will set expiry TTL for each key of the batch.
|
|
73
73
|
* E.g EXAT in Redis.
|
|
74
74
|
*/
|
|
75
|
-
expireAt?:
|
|
75
|
+
expireAt?: UnixTimestamp
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
/**
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
AsyncMemoCache,
|
|
3
|
+
localTime,
|
|
4
|
+
MISS,
|
|
5
|
+
NumberOfSeconds,
|
|
6
|
+
UnixTimestamp,
|
|
7
|
+
} from '@naturalcycles/js-lib'
|
|
2
8
|
import { CommonKeyValueDao } from './commonKeyValueDao'
|
|
3
9
|
|
|
4
10
|
export interface CommonKeyValueDaoMemoCacheCfg<VALUE> {
|
|
@@ -26,7 +32,9 @@ export class CommonKeyValueDaoMemoCache<VALUE> implements AsyncMemoCache<string,
|
|
|
26
32
|
}
|
|
27
33
|
|
|
28
34
|
async set(k: string, v: VALUE): Promise<void> {
|
|
29
|
-
const opt = this.cfg.ttl
|
|
35
|
+
const opt = this.cfg.ttl
|
|
36
|
+
? { expireAt: (localTime.nowUnix() + this.cfg.ttl) as UnixTimestamp }
|
|
37
|
+
: undefined
|
|
30
38
|
|
|
31
39
|
await this.cfg.dao.save(k, v, opt)
|
|
32
40
|
}
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
localTime,
|
|
7
7
|
pMap,
|
|
8
8
|
StringMap,
|
|
9
|
-
|
|
9
|
+
UnixTimestamp,
|
|
10
10
|
} from '@naturalcycles/js-lib'
|
|
11
11
|
import {
|
|
12
12
|
_pipeline,
|
|
@@ -61,13 +61,13 @@ export interface DBPipelineBackupOptions extends TransformLogProgressOptions {
|
|
|
61
61
|
/**
|
|
62
62
|
* If set - will do "incremental backup" (not full), only for entities that updated >= `sinceUpdated`
|
|
63
63
|
*/
|
|
64
|
-
sinceUpdated?:
|
|
64
|
+
sinceUpdated?: UnixTimestamp
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* Map for each table a `sinceUpdated` timestamp, or `undefined`.
|
|
68
68
|
* If set - will do "incremental backup" (not full), only for entities that updated >= `sinceUpdated` (on a per table basis)
|
|
69
69
|
*/
|
|
70
|
-
sinceUpdatedPerTable?: StringMap<
|
|
70
|
+
sinceUpdatedPerTable?: StringMap<UnixTimestamp>
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
73
|
* By default, dbPipelineBackup creates a Query based on sinceUpdated.
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
ErrorMode,
|
|
6
6
|
localTime,
|
|
7
7
|
pMap,
|
|
8
|
+
UnixTimestamp,
|
|
8
9
|
} from '@naturalcycles/js-lib'
|
|
9
10
|
import {
|
|
10
11
|
_pipeline,
|
|
@@ -68,7 +69,7 @@ export interface DBPipelineCopyOptions extends TransformLogProgressOptions {
|
|
|
68
69
|
*
|
|
69
70
|
* @default undefined
|
|
70
71
|
*/
|
|
71
|
-
sinceUpdated?:
|
|
72
|
+
sinceUpdated?: UnixTimestamp
|
|
72
73
|
|
|
73
74
|
/**
|
|
74
75
|
* Optionally you can provide mapper that is going to run for each table.
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
JsonSchemaObject,
|
|
9
9
|
localTime,
|
|
10
10
|
pMap,
|
|
11
|
+
UnixTimestamp,
|
|
11
12
|
} from '@naturalcycles/js-lib'
|
|
12
13
|
import {
|
|
13
14
|
_pipeline,
|
|
@@ -80,7 +81,7 @@ export interface DBPipelineRestoreOptions extends TransformLogProgressOptions {
|
|
|
80
81
|
*
|
|
81
82
|
* @default undefined
|
|
82
83
|
*/
|
|
83
|
-
sinceUpdated?:
|
|
84
|
+
sinceUpdated?: UnixTimestamp
|
|
84
85
|
|
|
85
86
|
/**
|
|
86
87
|
* @default false
|
package/src/testing/daoTest.ts
CHANGED
|
@@ -80,6 +80,17 @@ export function runCommonDaoTest(db: CommonDB, quirks: CommonDBImplementationQui
|
|
|
80
80
|
expect(await dao.getByIds(['abc', 'abcd'])).toEqual([])
|
|
81
81
|
})
|
|
82
82
|
|
|
83
|
+
// TimeMachine
|
|
84
|
+
if (support.timeMachine) {
|
|
85
|
+
test('getByIds(...) 10 minutes ago should return []', async () => {
|
|
86
|
+
expect(
|
|
87
|
+
await dao.getByIds([item1.id, 'abc'], {
|
|
88
|
+
readAt: localTime.now().minus(10, 'minute').unix,
|
|
89
|
+
}),
|
|
90
|
+
).toEqual([])
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
|
|
83
94
|
// SAVE
|
|
84
95
|
if (support.nullValues) {
|
|
85
96
|
test('should allow to save and load null values', async () => {
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
_range,
|
|
3
|
+
BaseDBEntity,
|
|
4
|
+
jsonSchema,
|
|
5
|
+
JsonSchemaObject,
|
|
6
|
+
UnixTimestamp,
|
|
7
|
+
} from '@naturalcycles/js-lib'
|
|
2
8
|
import {
|
|
3
9
|
baseDBEntitySchema,
|
|
4
10
|
binarySchema,
|
|
@@ -8,7 +14,7 @@ import {
|
|
|
8
14
|
stringSchema,
|
|
9
15
|
} from '@naturalcycles/nodejs-lib'
|
|
10
16
|
|
|
11
|
-
const MOCK_TS_2018_06_21 = 1529539200
|
|
17
|
+
const MOCK_TS_2018_06_21 = 1529539200 as UnixTimestamp
|
|
12
18
|
|
|
13
19
|
export const TEST_TABLE = 'TEST_TABLE'
|
|
14
20
|
|