@naturalcycles/db-lib 9.14.1 → 9.14.3
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/adapter/cachedb/index.d.ts +1 -1
- package/dist/adapter/file/inMemory.persistence.plugin.d.ts +1 -1
- package/dist/adapter/inmemory/inMemory.db.d.ts +16 -16
- package/dist/adapter/inmemory/inMemoryKeyValueDB.d.ts +0 -1
- package/dist/adapter/inmemory/queryInMemory.js +1 -2
- package/dist/commondao/common.dao.d.ts +0 -1
- package/dist/commondao/common.dao.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/kv/commonKeyValueDB.d.ts +0 -1
- package/dist/kv/commonKeyValueDao.d.ts +0 -1
- package/dist/kv/commonKeyValueDaoMemoCache.js +1 -1
- package/dist/model.util.js +6 -7
- package/dist/pipeline/dbPipelineBackup.d.ts +1 -1
- package/dist/pipeline/dbPipelineBackup.js +1 -2
- package/dist/pipeline/dbPipelineCopy.js +1 -2
- package/dist/pipeline/dbPipelineRestore.js +1 -2
- package/dist/testing/daoTest.js +2 -3
- package/dist/testing/dbTest.js +2 -3
- package/dist/testing/index.d.ts +3 -3
- package/dist/testing/index.js +2 -2
- package/dist/testing/keyValueDBTest.js +1 -2
- package/dist/testing/keyValueDaoTest.d.ts +0 -1
- package/dist/testing/keyValueDaoTest.js +1 -2
- package/dist/testing/test.model.d.ts +0 -1
- package/dist/testing/test.model.js +5 -5
- package/dist/testing/test.util.js +1 -2
- package/dist/testing/timeSeriesTest.util.js +1 -2
- package/package.json +1 -1
- package/src/adapter/cachedb/index.ts +1 -1
- package/src/adapter/file/file.db.ts +4 -4
- package/src/adapter/file/inMemory.persistence.plugin.ts +1 -1
- package/src/adapter/inmemory/inMemory.db.ts +12 -12
- package/src/adapter/inmemory/inMemoryKeyValueDB.ts +1 -1
- package/src/commondao/common.dao.ts +2 -2
- package/src/index.ts +1 -1
- package/src/kv/commonKeyValueDaoMemoCache.ts +2 -2
- package/src/model.util.ts +3 -3
- package/src/pipeline/dbPipelineBackup.ts +8 -8
- package/src/pipeline/dbPipelineCopy.ts +7 -7
- package/src/pipeline/dbPipelineRestore.ts +10 -10
- package/src/query/dbQuery.ts +2 -2
- package/src/testing/daoTest.ts +5 -5
- package/src/testing/index.ts +9 -9
- package/src/testing/keyValueDaoTest.ts +1 -1
- package/src/testing/test.model.ts +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { CacheDB } from './cache.db';
|
|
2
2
|
import { CacheDBCfg, CacheDBCreateOptions, CacheDBOptions, CacheDBStreamOptions } from './cache.db.model';
|
|
3
|
-
export type { CacheDBCfg,
|
|
3
|
+
export type { CacheDBCfg, CacheDBCreateOptions, CacheDBOptions, CacheDBStreamOptions };
|
|
4
4
|
export { CacheDB };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CommonLogger, JsonSchemaObject, JsonSchemaRootObject, ObjectWithId, StringMap } from '@naturalcycles/js-lib';
|
|
2
2
|
import { ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
3
3
|
import { CommonDB, CommonDBTransactionOptions, CommonDBType, DBOperation, DBPatch, DBTransactionFn } from '../..';
|
|
4
4
|
import { CommonDBCreateOptions, CommonDBOptions, CommonDBSaveOptions, DBTransaction, RunQueryResult } from '../../db.model';
|
|
@@ -48,21 +48,21 @@ export interface InMemoryDBCfg {
|
|
|
48
48
|
export declare class InMemoryDB implements CommonDB {
|
|
49
49
|
dbType: CommonDBType;
|
|
50
50
|
support: {
|
|
51
|
-
queries?: boolean
|
|
52
|
-
dbQueryFilter?: boolean
|
|
53
|
-
dbQueryFilterIn?: boolean
|
|
54
|
-
dbQueryOrder?: boolean
|
|
55
|
-
dbQuerySelectFields?: boolean
|
|
56
|
-
insertSaveMethod?: boolean
|
|
57
|
-
updateSaveMethod?: boolean
|
|
58
|
-
updateByQuery?: boolean
|
|
59
|
-
dbIncrement?: boolean
|
|
60
|
-
createTable?: boolean
|
|
61
|
-
tableSchemas?: boolean
|
|
62
|
-
streaming?: boolean
|
|
63
|
-
bufferValues?: boolean
|
|
64
|
-
nullValues?: boolean
|
|
65
|
-
transactions?: boolean
|
|
51
|
+
queries?: boolean;
|
|
52
|
+
dbQueryFilter?: boolean;
|
|
53
|
+
dbQueryFilterIn?: boolean;
|
|
54
|
+
dbQueryOrder?: boolean;
|
|
55
|
+
dbQuerySelectFields?: boolean;
|
|
56
|
+
insertSaveMethod?: boolean;
|
|
57
|
+
updateSaveMethod?: boolean;
|
|
58
|
+
updateByQuery?: boolean;
|
|
59
|
+
dbIncrement?: boolean;
|
|
60
|
+
createTable?: boolean;
|
|
61
|
+
tableSchemas?: boolean;
|
|
62
|
+
streaming?: boolean;
|
|
63
|
+
bufferValues?: boolean;
|
|
64
|
+
nullValues?: boolean;
|
|
65
|
+
transactions?: boolean;
|
|
66
66
|
};
|
|
67
67
|
constructor(cfg?: Partial<InMemoryDBCfg>);
|
|
68
68
|
cfg: InMemoryDBCfg;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.queryInMemory =
|
|
3
|
+
exports.queryInMemory = queryInMemory;
|
|
4
4
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
5
5
|
const FILTER_FNS = {
|
|
6
6
|
'==': (v, val) => v === val,
|
|
@@ -49,4 +49,3 @@ function queryInMemory(q, rows = []) {
|
|
|
49
49
|
}
|
|
50
50
|
return rows;
|
|
51
51
|
}
|
|
52
|
-
exports.queryInMemory = queryInMemory;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { Transform } from 'node:stream';
|
|
3
2
|
import { AsyncMapper, BaseDBEntity, CommonLogger, JsonSchemaObject, JsonSchemaRootObject, UnixTimestampMillisNumber, Unsaved, ZodSchema } from '@naturalcycles/js-lib';
|
|
4
3
|
import { AjvSchema, ObjectSchema, ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
@@ -447,7 +447,7 @@ class CommonDao {
|
|
|
447
447
|
* "Returns", just to have a type of "Saved"
|
|
448
448
|
*/
|
|
449
449
|
assignIdCreatedUpdated(obj, opt = {}) {
|
|
450
|
-
const now =
|
|
450
|
+
const now = js_lib_1.localTime.nowUnix();
|
|
451
451
|
if (this.cfg.useCreatedProperty) {
|
|
452
452
|
obj.created ||= obj.updated || now;
|
|
453
453
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from './commondao/common.dao';
|
|
|
7
7
|
export * from './commondao/common.dao.model';
|
|
8
8
|
export * from './db.model';
|
|
9
9
|
export * from './kv/commonKeyValueDao';
|
|
10
|
+
export * from './kv/commonKeyValueDaoMemoCache';
|
|
10
11
|
export * from './kv/commonKeyValueDB';
|
|
11
12
|
export * from './model.util';
|
|
12
13
|
export * from './pipeline/dbPipelineBackup';
|
|
@@ -14,4 +15,3 @@ export * from './pipeline/dbPipelineCopy';
|
|
|
14
15
|
export * from './pipeline/dbPipelineRestore';
|
|
15
16
|
export * from './query/dbQuery';
|
|
16
17
|
export * from './transaction/dbTransaction.util';
|
|
17
|
-
export * from './kv/commonKeyValueDaoMemoCache';
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,7 @@ tslib_1.__exportStar(require("./commondao/common.dao"), exports);
|
|
|
10
10
|
tslib_1.__exportStar(require("./commondao/common.dao.model"), exports);
|
|
11
11
|
tslib_1.__exportStar(require("./db.model"), exports);
|
|
12
12
|
tslib_1.__exportStar(require("./kv/commonKeyValueDao"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./kv/commonKeyValueDaoMemoCache"), exports);
|
|
13
14
|
tslib_1.__exportStar(require("./kv/commonKeyValueDB"), exports);
|
|
14
15
|
tslib_1.__exportStar(require("./model.util"), exports);
|
|
15
16
|
tslib_1.__exportStar(require("./pipeline/dbPipelineBackup"), exports);
|
|
@@ -17,4 +18,3 @@ tslib_1.__exportStar(require("./pipeline/dbPipelineCopy"), exports);
|
|
|
17
18
|
tslib_1.__exportStar(require("./pipeline/dbPipelineRestore"), exports);
|
|
18
19
|
tslib_1.__exportStar(require("./query/dbQuery"), exports);
|
|
19
20
|
tslib_1.__exportStar(require("./transaction/dbTransaction.util"), exports);
|
|
20
|
-
tslib_1.__exportStar(require("./kv/commonKeyValueDaoMemoCache"), exports);
|
|
@@ -18,7 +18,7 @@ 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 ? { expireAt:
|
|
21
|
+
const opt = this.cfg.ttl ? { expireAt: js_lib_1.localTime.nowUnix() + this.cfg.ttl } : undefined;
|
|
22
22
|
await this.cfg.dao.save(k, v, opt);
|
|
23
23
|
}
|
|
24
24
|
async clear() {
|
package/dist/model.util.js
CHANGED
|
@@ -1,32 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.createdUpdatedFields = createdUpdatedFields;
|
|
4
|
+
exports.createdUpdatedIdFields = createdUpdatedIdFields;
|
|
5
|
+
exports.deserializeJsonField = deserializeJsonField;
|
|
6
|
+
exports.serializeJsonField = serializeJsonField;
|
|
4
7
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
5
8
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
6
9
|
function createdUpdatedFields(existingObject) {
|
|
7
|
-
const now =
|
|
10
|
+
const now = js_lib_1.localTime.nowUnix();
|
|
8
11
|
return {
|
|
9
12
|
created: existingObject?.created || now,
|
|
10
13
|
updated: now,
|
|
11
14
|
};
|
|
12
15
|
}
|
|
13
|
-
exports.createdUpdatedFields = createdUpdatedFields;
|
|
14
16
|
function createdUpdatedIdFields(existingObject) {
|
|
15
|
-
const now =
|
|
17
|
+
const now = js_lib_1.localTime.nowUnix();
|
|
16
18
|
return {
|
|
17
19
|
created: existingObject?.created || now,
|
|
18
20
|
id: existingObject?.id || (0, nodejs_lib_1.stringId)(),
|
|
19
21
|
updated: now,
|
|
20
22
|
};
|
|
21
23
|
}
|
|
22
|
-
exports.createdUpdatedIdFields = createdUpdatedIdFields;
|
|
23
24
|
function deserializeJsonField(f) {
|
|
24
25
|
return JSON.parse(f || '{}');
|
|
25
26
|
}
|
|
26
|
-
exports.deserializeJsonField = deserializeJsonField;
|
|
27
27
|
function serializeJsonField(f) {
|
|
28
28
|
if (f === undefined)
|
|
29
29
|
return;
|
|
30
30
|
return JSON.stringify(f);
|
|
31
31
|
}
|
|
32
|
-
exports.serializeJsonField = serializeJsonField;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AsyncMapper, ErrorMode,
|
|
1
|
+
import { AsyncMapper, ErrorMode, StringMap, UnixTimestampNumber } 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';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.dbPipelineBackup =
|
|
3
|
+
exports.dbPipelineBackup = dbPipelineBackup;
|
|
4
4
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
5
5
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
6
6
|
const index_1 = require("../index");
|
|
@@ -84,4 +84,3 @@ async function dbPipelineBackup(opt) {
|
|
|
84
84
|
console.log(statsTotal.toPretty('total'));
|
|
85
85
|
return statsTotal;
|
|
86
86
|
}
|
|
87
|
-
exports.dbPipelineBackup = dbPipelineBackup;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.dbPipelineCopy =
|
|
3
|
+
exports.dbPipelineCopy = dbPipelineCopy;
|
|
4
4
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
5
5
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
6
6
|
const dbQuery_1 = require("../query/dbQuery");
|
|
@@ -59,4 +59,3 @@ async function dbPipelineCopy(opt) {
|
|
|
59
59
|
console.log(statsTotal.toPretty('total'));
|
|
60
60
|
return statsTotal;
|
|
61
61
|
}
|
|
62
|
-
exports.dbPipelineCopy = dbPipelineCopy;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.dbPipelineRestore =
|
|
3
|
+
exports.dbPipelineRestore = dbPipelineRestore;
|
|
4
4
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
5
5
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
6
6
|
/**
|
|
@@ -96,4 +96,3 @@ async function dbPipelineRestore(opt) {
|
|
|
96
96
|
console.log(statsTotal.toPretty('total'));
|
|
97
97
|
return statsTotal;
|
|
98
98
|
}
|
|
99
|
-
exports.dbPipelineRestore = dbPipelineRestore;
|
package/dist/testing/daoTest.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runCommonDaoTest =
|
|
3
|
+
exports.runCommonDaoTest = runCommonDaoTest;
|
|
4
4
|
const node_stream_1 = require("node:stream");
|
|
5
5
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
6
6
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
@@ -186,7 +186,7 @@ function runCommonDaoTest(db, quirks = {}) {
|
|
|
186
186
|
// cleanup
|
|
187
187
|
await dao.query().deleteByQuery();
|
|
188
188
|
// Test that id, created, updated are created
|
|
189
|
-
const now =
|
|
189
|
+
const now = js_lib_1.localTime.nowUnix();
|
|
190
190
|
await dao.runInTransaction(async (tx) => {
|
|
191
191
|
const row = (0, js_lib_1._omit)(item1, ['id', 'created', 'updated']);
|
|
192
192
|
await tx.save(dao, row);
|
|
@@ -228,4 +228,3 @@ function runCommonDaoTest(db, quirks = {}) {
|
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
|
-
exports.runCommonDaoTest = runCommonDaoTest;
|
package/dist/testing/dbTest.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.runCommonDBTest = runCommonDBTest;
|
|
4
|
+
exports.expectMatch = expectMatch;
|
|
4
5
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
5
6
|
const common_db_1 = require("../common.db");
|
|
6
7
|
const db_model_1 = require("../db.model");
|
|
@@ -283,7 +284,6 @@ function runCommonDBTest(db, quirks = {}) {
|
|
|
283
284
|
});
|
|
284
285
|
}
|
|
285
286
|
}
|
|
286
|
-
exports.runCommonDBTest = runCommonDBTest;
|
|
287
287
|
function expectMatch(expected, actual, quirks) {
|
|
288
288
|
// const expectedSorted = sortObjectDeep(expected)
|
|
289
289
|
// const actualSorted = sortObjectDeep(actual)
|
|
@@ -299,4 +299,3 @@ function expectMatch(expected, actual, quirks) {
|
|
|
299
299
|
expect(actual).toEqual(expected);
|
|
300
300
|
}
|
|
301
301
|
}
|
|
302
|
-
exports.expectMatch = expectMatch;
|
package/dist/testing/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { runCommonDaoTest } from './daoTest';
|
|
2
2
|
import { CommonDBImplementationQuirks, runCommonDBTest } from './dbTest';
|
|
3
3
|
import { runCommonKeyValueDBTest } from './keyValueDBTest';
|
|
4
|
-
import { createTestItemBM, createTestItemDBM, createTestItemsBM, createTestItemsDBM, TestItemBM, testItemBMJsonSchema, testItemBMSchema, TestItemDBM, TestItemTM, testItemTMSchema
|
|
5
|
-
export type {
|
|
6
|
-
export {
|
|
4
|
+
import { createTestItemBM, createTestItemDBM, createTestItemsBM, createTestItemsDBM, TEST_TABLE, TestItemBM, testItemBMJsonSchema, testItemBMSchema, TestItemDBM, TestItemTM, testItemTMSchema } from './test.model';
|
|
5
|
+
export type { CommonDBImplementationQuirks, TestItemBM, TestItemDBM, TestItemTM };
|
|
6
|
+
export { createTestItemBM, createTestItemDBM, createTestItemsBM, createTestItemsDBM, runCommonDaoTest, runCommonDBTest, runCommonKeyValueDBTest, TEST_TABLE, testItemBMJsonSchema, testItemBMSchema, testItemTMSchema, };
|
package/dist/testing/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.testItemTMSchema = exports.testItemBMSchema = exports.testItemBMJsonSchema = exports.TEST_TABLE = exports.runCommonKeyValueDBTest = exports.runCommonDBTest = exports.runCommonDaoTest = exports.createTestItemsDBM = exports.createTestItemsBM = exports.createTestItemDBM = exports.createTestItemBM = void 0;
|
|
4
4
|
const daoTest_1 = require("./daoTest");
|
|
5
5
|
Object.defineProperty(exports, "runCommonDaoTest", { enumerable: true, get: function () { return daoTest_1.runCommonDaoTest; } });
|
|
6
6
|
const dbTest_1 = require("./dbTest");
|
|
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "createTestItemBM", { enumerable: true, get: func
|
|
|
12
12
|
Object.defineProperty(exports, "createTestItemDBM", { enumerable: true, get: function () { return test_model_1.createTestItemDBM; } });
|
|
13
13
|
Object.defineProperty(exports, "createTestItemsBM", { enumerable: true, get: function () { return test_model_1.createTestItemsBM; } });
|
|
14
14
|
Object.defineProperty(exports, "createTestItemsDBM", { enumerable: true, get: function () { return test_model_1.createTestItemsDBM; } });
|
|
15
|
+
Object.defineProperty(exports, "TEST_TABLE", { enumerable: true, get: function () { return test_model_1.TEST_TABLE; } });
|
|
15
16
|
Object.defineProperty(exports, "testItemBMJsonSchema", { enumerable: true, get: function () { return test_model_1.testItemBMJsonSchema; } });
|
|
16
17
|
Object.defineProperty(exports, "testItemBMSchema", { enumerable: true, get: function () { return test_model_1.testItemBMSchema; } });
|
|
17
18
|
Object.defineProperty(exports, "testItemTMSchema", { enumerable: true, get: function () { return test_model_1.testItemTMSchema; } });
|
|
18
|
-
Object.defineProperty(exports, "TEST_TABLE", { enumerable: true, get: function () { return test_model_1.TEST_TABLE; } });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runCommonKeyValueDBTest =
|
|
3
|
+
exports.runCommonKeyValueDBTest = runCommonKeyValueDBTest;
|
|
4
4
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
5
5
|
const test_model_1 = require("./test.model");
|
|
6
6
|
const testIds = (0, js_lib_1._range)(1, 4).map(n => `id${n}`);
|
|
@@ -71,4 +71,3 @@ function runCommonKeyValueDBTest(db) {
|
|
|
71
71
|
expect(results).toEqual([]);
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
|
-
exports.runCommonKeyValueDBTest = runCommonKeyValueDBTest;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runCommonKeyValueDaoTest =
|
|
3
|
+
exports.runCommonKeyValueDaoTest = runCommonKeyValueDaoTest;
|
|
4
4
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
5
5
|
const testIds = (0, js_lib_1._range)(1, 4).map(n => `id${n}`);
|
|
6
6
|
const testEntries = testIds.map(id => [id, Buffer.from(`${id}value`)]);
|
|
@@ -64,4 +64,3 @@ function runCommonKeyValueDaoTest(dao) {
|
|
|
64
64
|
expect(results).toEqual([]);
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
|
-
exports.runCommonKeyValueDaoTest = runCommonKeyValueDaoTest;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.testItemBMJsonSchema = exports.testItemTMSchema = exports.testItemBMSchema = exports.TEST_TABLE = void 0;
|
|
4
|
+
exports.createTestItemDBM = createTestItemDBM;
|
|
5
|
+
exports.createTestItemBM = createTestItemBM;
|
|
6
|
+
exports.createTestItemsDBM = createTestItemsDBM;
|
|
7
|
+
exports.createTestItemsBM = createTestItemsBM;
|
|
4
8
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
5
9
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
6
10
|
const MOCK_TS_2018_06_21 = 1529539200;
|
|
@@ -41,16 +45,12 @@ function createTestItemDBM(num = 1) {
|
|
|
41
45
|
updated: MOCK_TS_2018_06_21,
|
|
42
46
|
};
|
|
43
47
|
}
|
|
44
|
-
exports.createTestItemDBM = createTestItemDBM;
|
|
45
48
|
function createTestItemBM(num = 1) {
|
|
46
49
|
return createTestItemDBM(num);
|
|
47
50
|
}
|
|
48
|
-
exports.createTestItemBM = createTestItemBM;
|
|
49
51
|
function createTestItemsDBM(count = 1) {
|
|
50
52
|
return (0, js_lib_1._range)(1, count + 1).map(num => createTestItemDBM(num));
|
|
51
53
|
}
|
|
52
|
-
exports.createTestItemsDBM = createTestItemsDBM;
|
|
53
54
|
function createTestItemsBM(count = 1) {
|
|
54
55
|
return (0, js_lib_1._range)(1, count + 1).map(num => createTestItemBM(num));
|
|
55
56
|
}
|
|
56
|
-
exports.createTestItemsBM = createTestItemsBM;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// copy-pasted from test-lib to be able to not include devDependecies there
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.deepFreeze =
|
|
4
|
+
exports.deepFreeze = deepFreeze;
|
|
5
5
|
/**
|
|
6
6
|
* Does Object.freeze recursively for given object.
|
|
7
7
|
*
|
|
@@ -21,4 +21,3 @@ function deepFreeze(o) {
|
|
|
21
21
|
});
|
|
22
22
|
return o;
|
|
23
23
|
}
|
|
24
|
-
exports.deepFreeze = deepFreeze;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createTestTimeSeries =
|
|
3
|
+
exports.createTestTimeSeries = createTestTimeSeries;
|
|
4
4
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
5
5
|
function createTestTimeSeries(count = 10) {
|
|
6
6
|
const ts = Date.now();
|
|
7
7
|
return (0, js_lib_1._range)(1, count + 1).map(i => [ts - i * 60_000, (0, js_lib_1._randomInt)(10, 20)]);
|
|
8
8
|
}
|
|
9
|
-
exports.createTestTimeSeries = createTestTimeSeries;
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
_assert,
|
|
3
3
|
_by,
|
|
4
4
|
_deepEquals,
|
|
5
|
+
_filterUndefinedValues,
|
|
5
6
|
_since,
|
|
6
7
|
_sortBy,
|
|
7
8
|
_sortObjectDeep,
|
|
8
9
|
_stringMapValues,
|
|
10
|
+
generateJsonSchemaFromData,
|
|
9
11
|
JsonSchemaRootObject,
|
|
10
|
-
_filterUndefinedValues,
|
|
11
|
-
_assert,
|
|
12
12
|
ObjectWithId,
|
|
13
13
|
} from '@naturalcycles/js-lib'
|
|
14
|
-
import { readableCreate, ReadableTyped
|
|
14
|
+
import { dimGrey, readableCreate, ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
15
15
|
import {
|
|
16
16
|
BaseCommonDB,
|
|
17
17
|
commonDBFullSupport,
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import { Readable } from 'node:stream'
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
JsonSchemaObject,
|
|
5
|
-
pMap,
|
|
6
|
-
StringMap,
|
|
3
|
+
_assert,
|
|
7
4
|
_by,
|
|
5
|
+
_deepCopy,
|
|
8
6
|
_since,
|
|
9
7
|
_sortObjectDeep,
|
|
10
|
-
JsonSchemaRootObject,
|
|
11
|
-
ObjectWithId,
|
|
12
8
|
_stringMapValues,
|
|
13
9
|
CommonLogger,
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
generateJsonSchemaFromData,
|
|
11
|
+
JsonSchemaObject,
|
|
12
|
+
JsonSchemaRootObject,
|
|
13
|
+
ObjectWithId,
|
|
14
|
+
pMap,
|
|
15
|
+
StringMap,
|
|
16
16
|
} from '@naturalcycles/js-lib'
|
|
17
17
|
import {
|
|
18
|
-
bufferReviver,
|
|
19
|
-
ReadableTyped,
|
|
20
18
|
_pipeline,
|
|
19
|
+
bufferReviver,
|
|
21
20
|
dimGrey,
|
|
22
|
-
yellow,
|
|
23
21
|
fs2,
|
|
22
|
+
ReadableTyped,
|
|
23
|
+
yellow,
|
|
24
24
|
} from '@naturalcycles/nodejs-lib'
|
|
25
25
|
import {
|
|
26
26
|
CommonDB,
|
|
@@ -215,7 +215,7 @@ export class InMemoryDB implements CommonDB {
|
|
|
215
215
|
): Promise<number> {
|
|
216
216
|
const table = this.cfg.tablesPrefix + q.table
|
|
217
217
|
if (!this.data[table]) return 0
|
|
218
|
-
const ids = queryInMemory(q, Object.values(this.data[table]
|
|
218
|
+
const ids = queryInMemory(q, Object.values(this.data[table]) as ROW[]).map(r => r.id)
|
|
219
219
|
return await this.deleteByIds(q.table, ids)
|
|
220
220
|
}
|
|
221
221
|
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
ErrorMode,
|
|
19
19
|
JsonSchemaObject,
|
|
20
20
|
JsonSchemaRootObject,
|
|
21
|
-
|
|
21
|
+
localTime,
|
|
22
22
|
ObjectWithId,
|
|
23
23
|
pMap,
|
|
24
24
|
SKIP,
|
|
@@ -605,7 +605,7 @@ export class CommonDao<BM extends BaseDBEntity, DBM extends BaseDBEntity = BM> {
|
|
|
605
605
|
* "Returns", just to have a type of "Saved"
|
|
606
606
|
*/
|
|
607
607
|
assignIdCreatedUpdated<T extends BaseDBEntity>(obj: Partial<T>, opt: CommonDaoOptions = {}): T {
|
|
608
|
-
const now = nowUnix()
|
|
608
|
+
const now = localTime.nowUnix()
|
|
609
609
|
|
|
610
610
|
if (this.cfg.useCreatedProperty) {
|
|
611
611
|
obj.created ||= obj.updated || now
|
package/src/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from './commondao/common.dao'
|
|
|
7
7
|
export * from './commondao/common.dao.model'
|
|
8
8
|
export * from './db.model'
|
|
9
9
|
export * from './kv/commonKeyValueDao'
|
|
10
|
+
export * from './kv/commonKeyValueDaoMemoCache'
|
|
10
11
|
export * from './kv/commonKeyValueDB'
|
|
11
12
|
export * from './model.util'
|
|
12
13
|
export * from './pipeline/dbPipelineBackup'
|
|
@@ -14,4 +15,3 @@ export * from './pipeline/dbPipelineCopy'
|
|
|
14
15
|
export * from './pipeline/dbPipelineRestore'
|
|
15
16
|
export * from './query/dbQuery'
|
|
16
17
|
export * from './transaction/dbTransaction.util'
|
|
17
|
-
export * from './kv/commonKeyValueDaoMemoCache'
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AsyncMemoCache,
|
|
1
|
+
import { AsyncMemoCache, localTime, MISS, NumberOfSeconds } from '@naturalcycles/js-lib'
|
|
2
2
|
import { CommonKeyValueDao } from './commonKeyValueDao'
|
|
3
3
|
|
|
4
4
|
export interface CommonKeyValueDaoMemoCacheCfg<VALUE> {
|
|
@@ -26,7 +26,7 @@ export class CommonKeyValueDaoMemoCache<VALUE = any> implements AsyncMemoCache<s
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
async set(k: string, v: VALUE): Promise<void> {
|
|
29
|
-
const opt = this.cfg.ttl ? { expireAt: nowUnix() + this.cfg.ttl } : undefined
|
|
29
|
+
const opt = this.cfg.ttl ? { expireAt: localTime.nowUnix() + this.cfg.ttl } : undefined
|
|
30
30
|
|
|
31
31
|
await this.cfg.dao.save(k, v, opt)
|
|
32
32
|
}
|
package/src/model.util.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { CreatedUpdated, CreatedUpdatedId,
|
|
1
|
+
import { CreatedUpdated, CreatedUpdatedId, localTime } from '@naturalcycles/js-lib'
|
|
2
2
|
import { stringId } from '@naturalcycles/nodejs-lib'
|
|
3
3
|
|
|
4
4
|
export function createdUpdatedFields(
|
|
5
5
|
existingObject?: Partial<CreatedUpdated> | null,
|
|
6
6
|
): CreatedUpdated {
|
|
7
|
-
const now = nowUnix()
|
|
7
|
+
const now = localTime.nowUnix()
|
|
8
8
|
return {
|
|
9
9
|
created: existingObject?.created || now,
|
|
10
10
|
updated: now,
|
|
@@ -14,7 +14,7 @@ export function createdUpdatedFields(
|
|
|
14
14
|
export function createdUpdatedIdFields(
|
|
15
15
|
existingObject?: Partial<CreatedUpdatedId> | null,
|
|
16
16
|
): CreatedUpdatedId {
|
|
17
|
-
const now = nowUnix()
|
|
17
|
+
const now = localTime.nowUnix()
|
|
18
18
|
return {
|
|
19
19
|
created: existingObject?.created || now,
|
|
20
20
|
id: existingObject?.id || stringId(),
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
|
+
_passthroughMapper,
|
|
2
3
|
AppError,
|
|
3
4
|
AsyncMapper,
|
|
4
5
|
ErrorMode,
|
|
5
|
-
pMap,
|
|
6
|
-
_passthroughMapper,
|
|
7
6
|
localTime,
|
|
8
|
-
|
|
7
|
+
pMap,
|
|
9
8
|
StringMap,
|
|
9
|
+
UnixTimestampNumber,
|
|
10
10
|
} from '@naturalcycles/js-lib'
|
|
11
11
|
import {
|
|
12
|
+
_pipeline,
|
|
13
|
+
boldWhite,
|
|
14
|
+
dimWhite,
|
|
15
|
+
fs2,
|
|
16
|
+
grey,
|
|
12
17
|
NDJsonStats,
|
|
13
18
|
transformLogProgress,
|
|
14
19
|
TransformLogProgressOptions,
|
|
15
20
|
transformMap,
|
|
16
21
|
TransformMapOptions,
|
|
17
22
|
transformTap,
|
|
18
|
-
_pipeline,
|
|
19
|
-
boldWhite,
|
|
20
|
-
dimWhite,
|
|
21
|
-
grey,
|
|
22
23
|
yellow,
|
|
23
|
-
fs2,
|
|
24
24
|
} from '@naturalcycles/nodejs-lib'
|
|
25
25
|
import { CommonDB } from '../common.db'
|
|
26
26
|
import { DBQuery } from '../index'
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
|
+
_passthroughMapper,
|
|
2
3
|
AsyncMapper,
|
|
4
|
+
BaseDBEntity,
|
|
3
5
|
ErrorMode,
|
|
4
|
-
pMap,
|
|
5
|
-
_passthroughMapper,
|
|
6
6
|
localTime,
|
|
7
|
-
|
|
7
|
+
pMap,
|
|
8
8
|
} from '@naturalcycles/js-lib'
|
|
9
9
|
import {
|
|
10
|
+
_pipeline,
|
|
11
|
+
boldWhite,
|
|
12
|
+
dimWhite,
|
|
13
|
+
grey,
|
|
10
14
|
NDJsonStats,
|
|
11
15
|
transformChunk,
|
|
12
16
|
transformLogProgress,
|
|
@@ -15,10 +19,6 @@ import {
|
|
|
15
19
|
TransformMapOptions,
|
|
16
20
|
transformTap,
|
|
17
21
|
writableForEach,
|
|
18
|
-
_pipeline,
|
|
19
|
-
boldWhite,
|
|
20
|
-
dimWhite,
|
|
21
|
-
grey,
|
|
22
22
|
yellow,
|
|
23
23
|
} from '@naturalcycles/nodejs-lib'
|
|
24
24
|
import { CommonDB } from '../common.db'
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
|
-
AsyncMapper,
|
|
3
|
-
ErrorMode,
|
|
4
|
-
pMap,
|
|
5
2
|
_hb,
|
|
6
3
|
_mapValues,
|
|
7
4
|
_passthroughMapper,
|
|
8
|
-
|
|
9
|
-
JsonSchemaObject,
|
|
5
|
+
AsyncMapper,
|
|
10
6
|
BaseDBEntity,
|
|
7
|
+
ErrorMode,
|
|
8
|
+
JsonSchemaObject,
|
|
9
|
+
localTime,
|
|
10
|
+
pMap,
|
|
11
11
|
} from '@naturalcycles/js-lib'
|
|
12
12
|
import {
|
|
13
|
+
_pipeline,
|
|
14
|
+
boldWhite,
|
|
15
|
+
dimWhite,
|
|
16
|
+
fs2,
|
|
17
|
+
grey,
|
|
13
18
|
NDJsonStats,
|
|
14
19
|
transformChunk,
|
|
15
20
|
transformFilterSync,
|
|
@@ -19,12 +24,7 @@ import {
|
|
|
19
24
|
TransformMapOptions,
|
|
20
25
|
transformTap,
|
|
21
26
|
writableForEach,
|
|
22
|
-
_pipeline,
|
|
23
|
-
boldWhite,
|
|
24
|
-
dimWhite,
|
|
25
|
-
grey,
|
|
26
27
|
yellow,
|
|
27
|
-
fs2,
|
|
28
28
|
} from '@naturalcycles/nodejs-lib'
|
|
29
29
|
import { CommonDB } from '../common.db'
|
|
30
30
|
import { CommonDBSaveOptions } from '../index'
|
package/src/query/dbQuery.ts
CHANGED
package/src/testing/daoTest.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { Readable } from 'node:stream'
|
|
2
|
-
import { _deepCopy, _pick, _sortBy,
|
|
2
|
+
import { _deepCopy, _omit, _pick, _sortBy, localTime } from '@naturalcycles/js-lib'
|
|
3
3
|
import { _pipeline } from '@naturalcycles/nodejs-lib'
|
|
4
4
|
import { CommonDaoLogLevel, DBQuery } from '..'
|
|
5
5
|
import { CommonDB } from '../common.db'
|
|
6
6
|
import { CommonDao } from '../commondao/common.dao'
|
|
7
|
+
import { TestItemBM } from '.'
|
|
7
8
|
import { CommonDBImplementationQuirks, expectMatch } from './dbTest'
|
|
8
9
|
import {
|
|
10
|
+
createTestItemBM,
|
|
9
11
|
createTestItemsBM,
|
|
10
|
-
testItemBMSchema,
|
|
11
12
|
TEST_TABLE,
|
|
12
|
-
createTestItemBM,
|
|
13
13
|
testItemBMJsonSchema,
|
|
14
|
+
testItemBMSchema,
|
|
14
15
|
} from './test.model'
|
|
15
|
-
import { TestItemBM } from '.'
|
|
16
16
|
|
|
17
17
|
export function runCommonDaoTest(db: CommonDB, quirks: CommonDBImplementationQuirks = {}): void {
|
|
18
18
|
const { support } = db
|
|
@@ -255,7 +255,7 @@ export function runCommonDaoTest(db: CommonDB, quirks: CommonDBImplementationQui
|
|
|
255
255
|
await dao.query().deleteByQuery()
|
|
256
256
|
|
|
257
257
|
// Test that id, created, updated are created
|
|
258
|
-
const now = nowUnix()
|
|
258
|
+
const now = localTime.nowUnix()
|
|
259
259
|
|
|
260
260
|
await dao.runInTransaction(async tx => {
|
|
261
261
|
const row = _omit(item1, ['id', 'created', 'updated'])
|
package/src/testing/index.ts
CHANGED
|
@@ -6,27 +6,27 @@ import {
|
|
|
6
6
|
createTestItemDBM,
|
|
7
7
|
createTestItemsBM,
|
|
8
8
|
createTestItemsDBM,
|
|
9
|
+
TEST_TABLE,
|
|
9
10
|
TestItemBM,
|
|
10
11
|
testItemBMJsonSchema,
|
|
11
12
|
testItemBMSchema,
|
|
12
13
|
TestItemDBM,
|
|
13
14
|
TestItemTM,
|
|
14
15
|
testItemTMSchema,
|
|
15
|
-
TEST_TABLE,
|
|
16
16
|
} from './test.model'
|
|
17
17
|
|
|
18
|
-
export type {
|
|
18
|
+
export type { CommonDBImplementationQuirks, TestItemBM, TestItemDBM, TestItemTM }
|
|
19
19
|
|
|
20
20
|
export {
|
|
21
|
-
TEST_TABLE,
|
|
22
|
-
createTestItemDBM,
|
|
23
21
|
createTestItemBM,
|
|
24
|
-
|
|
22
|
+
createTestItemDBM,
|
|
25
23
|
createTestItemsBM,
|
|
26
|
-
|
|
27
|
-
testItemTMSchema,
|
|
28
|
-
testItemBMJsonSchema,
|
|
29
|
-
runCommonDBTest,
|
|
24
|
+
createTestItemsDBM,
|
|
30
25
|
runCommonDaoTest,
|
|
26
|
+
runCommonDBTest,
|
|
31
27
|
runCommonKeyValueDBTest,
|
|
28
|
+
TEST_TABLE,
|
|
29
|
+
testItemBMJsonSchema,
|
|
30
|
+
testItemBMSchema,
|
|
31
|
+
testItemTMSchema,
|
|
32
32
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { _range, _sortBy } from '@naturalcycles/js-lib'
|
|
2
|
-
import { KeyValueDBTuple } from '../kv/commonKeyValueDB'
|
|
3
2
|
import { CommonKeyValueDao } from '../kv/commonKeyValueDao'
|
|
3
|
+
import { KeyValueDBTuple } from '../kv/commonKeyValueDB'
|
|
4
4
|
|
|
5
5
|
const testIds = _range(1, 4).map(n => `id${n}`)
|
|
6
6
|
const testEntries: KeyValueDBTuple[] = testIds.map(id => [id, Buffer.from(`${id}value`)])
|