@naturalcycles/db-lib 10.0.1 → 10.1.0
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/cache.db.d.ts +7 -7
- package/dist/adapter/cachedb/cache.db.js +13 -16
- package/dist/adapter/cachedb/cache.db.model.d.ts +3 -3
- package/dist/adapter/cachedb/cache.db.model.js +1 -2
- package/dist/adapter/cachedb/index.d.ts +2 -2
- package/dist/adapter/cachedb/index.js +2 -5
- package/dist/adapter/file/file.db.d.ts +7 -7
- package/dist/adapter/file/file.db.js +35 -36
- package/dist/adapter/file/file.db.model.d.ts +3 -3
- package/dist/adapter/file/file.db.model.js +1 -2
- package/dist/adapter/file/inMemory.persistence.plugin.d.ts +3 -3
- package/dist/adapter/file/inMemory.persistence.plugin.js +4 -10
- package/dist/adapter/file/index.d.ts +3 -3
- package/dist/adapter/file/index.js +3 -7
- package/dist/adapter/file/localFile.persistence.plugin.d.ts +3 -3
- package/dist/adapter/file/localFile.persistence.plugin.js +12 -15
- package/dist/adapter/file/noop.persistence.plugin.d.ts +3 -3
- package/dist/adapter/file/noop.persistence.plugin.js +1 -5
- package/dist/adapter/inmemory/inMemory.db.d.ts +7 -5
- package/dist/adapter/inmemory/inMemory.db.js +54 -49
- package/dist/adapter/inmemory/inMemoryKeyValueDB.d.ts +4 -4
- package/dist/adapter/inmemory/inMemoryKeyValueDB.js +12 -15
- package/dist/adapter/inmemory/queryInMemory.d.ts +2 -2
- package/dist/adapter/inmemory/queryInMemory.js +4 -7
- package/dist/base.common.db.d.ts +8 -5
- package/dist/base.common.db.js +9 -12
- package/dist/cnst.js +2 -5
- package/dist/common.db.d.ts +9 -3
- package/dist/common.db.js +3 -6
- package/dist/commondao/common.dao.d.ts +16 -6
- package/dist/commondao/common.dao.js +123 -112
- package/dist/commondao/common.dao.model.d.ts +5 -4
- package/dist/commondao/common.dao.model.js +2 -5
- package/dist/db.model.d.ts +7 -2
- package/dist/db.model.js +4 -7
- package/dist/index.d.ts +17 -17
- package/dist/index.js +17 -20
- package/dist/kv/commonKeyValueDB.d.ts +3 -3
- package/dist/kv/commonKeyValueDB.js +1 -4
- package/dist/kv/commonKeyValueDao.d.ts +5 -5
- package/dist/kv/commonKeyValueDao.js +11 -14
- package/dist/kv/commonKeyValueDaoMemoCache.d.ts +3 -2
- package/dist/kv/commonKeyValueDaoMemoCache.js +5 -8
- package/dist/model.util.d.ts +1 -1
- package/dist/model.util.js +9 -15
- package/dist/pipeline/dbPipelineBackup.d.ts +6 -4
- package/dist/pipeline/dbPipelineBackup.js +27 -30
- package/dist/pipeline/dbPipelineCopy.d.ts +6 -4
- package/dist/pipeline/dbPipelineCopy.js +20 -23
- package/dist/pipeline/dbPipelineRestore.d.ts +6 -4
- package/dist/pipeline/dbPipelineRestore.js +27 -30
- package/dist/query/dbQuery.d.ts +5 -5
- package/dist/query/dbQuery.js +22 -17
- package/dist/testing/{dbTest.d.ts → commonDBTest.d.ts} +1 -1
- package/dist/testing/{dbTest.js → commonDBTest.js} +81 -62
- package/dist/testing/commonDaoTest.d.ts +3 -0
- package/dist/testing/{daoTest.js → commonDaoTest.js} +101 -38
- package/dist/testing/index.d.ts +7 -5
- package/dist/testing/index.js +6 -20
- package/dist/testing/keyValueDBTest.d.ts +1 -1
- package/dist/testing/keyValueDBTest.js +28 -31
- package/dist/testing/keyValueDaoTest.d.ts +1 -1
- package/dist/testing/keyValueDaoTest.js +8 -11
- package/dist/testing/test.model.d.ts +1 -1
- package/dist/testing/test.model.js +30 -37
- package/dist/testing/timeSeriesTest.util.d.ts +1 -1
- package/dist/testing/timeSeriesTest.util.js +3 -6
- package/dist/timeseries/commonTimeSeriesDao.d.ts +1 -1
- package/dist/timeseries/commonTimeSeriesDao.js +6 -9
- package/dist/timeseries/timeSeries.model.d.ts +1 -1
- package/dist/timeseries/timeSeries.model.js +1 -2
- package/dist/transaction/dbTransaction.util.d.ts +4 -3
- package/dist/transaction/dbTransaction.util.js +3 -5
- package/dist/validation/index.d.ts +2 -2
- package/dist/validation/index.js +25 -28
- package/package.json +5 -4
- package/src/adapter/cachedb/cache.db.model.ts +4 -4
- package/src/adapter/cachedb/cache.db.ts +10 -9
- package/src/adapter/cachedb/index.ts +3 -3
- package/src/adapter/file/file.db.model.ts +3 -3
- package/src/adapter/file/file.db.ts +12 -16
- package/src/adapter/file/inMemory.persistence.plugin.ts +4 -3
- package/src/adapter/file/index.ts +3 -3
- package/src/adapter/file/localFile.persistence.plugin.ts +4 -3
- package/src/adapter/file/noop.persistence.plugin.ts +3 -3
- package/src/adapter/inmemory/inMemory.db.ts +26 -27
- package/src/adapter/inmemory/inMemoryKeyValueDB.ts +6 -6
- package/src/adapter/inmemory/queryInMemory.ts +3 -2
- package/src/base.common.db.ts +12 -7
- package/src/common.db.ts +12 -4
- package/src/commondao/common.dao.model.ts +5 -6
- package/src/commondao/common.dao.ts +41 -23
- package/src/db.model.ts +8 -2
- package/src/index.ts +17 -17
- package/src/kv/commonKeyValueDB.ts +3 -3
- package/src/kv/commonKeyValueDao.ts +8 -6
- package/src/kv/commonKeyValueDaoMemoCache.ts +3 -8
- package/src/model.util.ts +2 -1
- package/src/pipeline/dbPipelineBackup.ts +5 -14
- package/src/pipeline/dbPipelineCopy.ts +6 -14
- package/src/pipeline/dbPipelineRestore.ts +9 -8
- package/src/query/dbQuery.ts +7 -12
- package/src/testing/{dbTest.ts → commonDBTest.ts} +34 -5
- package/src/testing/{daoTest.ts → commonDaoTest.ts} +89 -11
- package/src/testing/index.ts +7 -8
- package/src/testing/keyValueDBTest.ts +4 -3
- package/src/testing/keyValueDaoTest.ts +3 -3
- package/src/testing/test.model.ts +2 -7
- package/src/testing/timeSeriesTest.util.ts +1 -1
- package/src/timeseries/commonTimeSeriesDao.ts +5 -4
- package/src/timeseries/timeSeries.model.ts +1 -1
- package/src/transaction/dbTransaction.util.ts +4 -3
- package/src/validation/index.ts +4 -4
- package/dist/testing/daoTest.d.ts +0 -3
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.CommonTimeSeriesDao = void 0;
|
|
4
|
-
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
5
|
-
const dbQuery_1 = require("../query/dbQuery");
|
|
1
|
+
import { _isTruthy } from '@naturalcycles/js-lib';
|
|
2
|
+
import { DBQuery } from '../query/dbQuery.js';
|
|
6
3
|
const _TIMESERIES_RAW = '_TIMESERIES_RAW';
|
|
7
4
|
/**
|
|
8
5
|
* TimeSeries DB implementation based on provided CommonDB database.
|
|
@@ -10,7 +7,8 @@ const _TIMESERIES_RAW = '_TIMESERIES_RAW';
|
|
|
10
7
|
*
|
|
11
8
|
* @experimental
|
|
12
9
|
*/
|
|
13
|
-
class CommonTimeSeriesDao {
|
|
10
|
+
export class CommonTimeSeriesDao {
|
|
11
|
+
cfg;
|
|
14
12
|
constructor(cfg) {
|
|
15
13
|
this.cfg = cfg;
|
|
16
14
|
}
|
|
@@ -20,7 +18,7 @@ class CommonTimeSeriesDao {
|
|
|
20
18
|
async getSeries() {
|
|
21
19
|
return (await this.cfg.db.getTables())
|
|
22
20
|
.map(t => /^(.*)_TIMESERIES_RAW$/.exec(t)?.[1])
|
|
23
|
-
.filter(
|
|
21
|
+
.filter(_isTruthy);
|
|
24
22
|
}
|
|
25
23
|
// convenience method
|
|
26
24
|
async save(series, tsMillis, value) {
|
|
@@ -61,7 +59,7 @@ class CommonTimeSeriesDao {
|
|
|
61
59
|
await this.saveBatch(series, ids.map(id => [id, null]));
|
|
62
60
|
}
|
|
63
61
|
async query(q) {
|
|
64
|
-
const dbq =
|
|
62
|
+
const dbq = DBQuery.create(`${q.series}${_TIMESERIES_RAW}`).order('ts');
|
|
65
63
|
if (q.fromIncl)
|
|
66
64
|
dbq.filter('ts', '>=', q.fromIncl);
|
|
67
65
|
if (q.toExcl)
|
|
@@ -76,4 +74,3 @@ class CommonTimeSeriesDao {
|
|
|
76
74
|
// todo
|
|
77
75
|
}
|
|
78
76
|
}
|
|
79
|
-
exports.CommonTimeSeriesDao = CommonTimeSeriesDao;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ObjectWithId } from '@naturalcycles/js-lib';
|
|
2
|
-
import type { CommonDB } from '../common.db';
|
|
3
|
-
import { CommonDBOptions, CommonDBSaveOptions, DBTransaction } from '../db.model';
|
|
1
|
+
import type { ObjectWithId } from '@naturalcycles/js-lib';
|
|
2
|
+
import type { CommonDB } from '../common.db.js';
|
|
3
|
+
import type { CommonDBOptions, CommonDBSaveOptions, DBTransaction } from '../db.model.js';
|
|
4
4
|
/**
|
|
5
5
|
* Optimizes the Transaction (list of DBOperations) to do less operations.
|
|
6
6
|
* E.g if you save id1 first and then delete it - this function will turn it into a no-op (self-eliminate).
|
|
@@ -21,6 +21,7 @@ import { CommonDBOptions, CommonDBSaveOptions, DBTransaction } from '../db.model
|
|
|
21
21
|
export declare class FakeDBTransaction implements DBTransaction {
|
|
22
22
|
protected db: CommonDB;
|
|
23
23
|
constructor(db: CommonDB);
|
|
24
|
+
commit(): Promise<void>;
|
|
24
25
|
rollback(): Promise<void>;
|
|
25
26
|
getByIds<ROW extends ObjectWithId>(table: string, ids: string[], opt?: CommonDBOptions): Promise<ROW[]>;
|
|
26
27
|
saveBatch<ROW extends ObjectWithId>(table: string, rows: ROW[], opt?: CommonDBSaveOptions<ROW>): Promise<void>;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FakeDBTransaction = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Optimizes the Transaction (list of DBOperations) to do less operations.
|
|
6
3
|
* E.g if you save id1 first and then delete it - this function will turn it into a no-op (self-eliminate).
|
|
@@ -90,11 +87,13 @@ export function mergeDBOperations(ops: DBOperation[]): DBOperation[] {
|
|
|
90
87
|
* Fake implementation of DBTransactionContext,
|
|
91
88
|
* which executes all operations instantly, without any Transaction involved.
|
|
92
89
|
*/
|
|
93
|
-
class FakeDBTransaction {
|
|
90
|
+
export class FakeDBTransaction {
|
|
91
|
+
db;
|
|
94
92
|
constructor(db) {
|
|
95
93
|
this.db = db;
|
|
96
94
|
}
|
|
97
95
|
// no-op
|
|
96
|
+
async commit() { }
|
|
98
97
|
async rollback() { }
|
|
99
98
|
async getByIds(table, ids, opt) {
|
|
100
99
|
return await this.db.getByIds(table, ids, opt);
|
|
@@ -112,4 +111,3 @@ class FakeDBTransaction {
|
|
|
112
111
|
return await this.db.deleteByIds(table, ids, opt);
|
|
113
112
|
}
|
|
114
113
|
}
|
|
115
|
-
exports.FakeDBTransaction = FakeDBTransaction;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CommonDBOptions, CommonDBSaveOptions } from '../db.model';
|
|
2
|
-
import { DBQuery, DBQueryFilter, DBQueryFilterOperator, DBQueryOrder } from '../query/dbQuery';
|
|
1
|
+
import type { CommonDBOptions, CommonDBSaveOptions } from '../db.model.js';
|
|
2
|
+
import type { DBQuery, DBQueryFilter, DBQueryFilterOperator, DBQueryOrder } from '../query/dbQuery.js';
|
|
3
3
|
export declare const commonDBOptionsSchema: import("joi").ObjectSchema<CommonDBOptions>;
|
|
4
4
|
export declare const commonDBSaveOptionsSchema: import("joi").ObjectSchema<CommonDBSaveOptions<any>>;
|
|
5
5
|
export declare const dbQueryFilterOperatorSchema: import("@naturalcycles/nodejs-lib").StringSchema<DBQueryFilterOperator>;
|
package/dist/validation/index.js
CHANGED
|
@@ -1,32 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.commonDBOptionsSchema = (0, nodejs_lib_1.objectSchema)({
|
|
7
|
-
['onlyCache']: nodejs_lib_1.booleanSchema.optional(),
|
|
8
|
-
['skipCache']: nodejs_lib_1.booleanSchema.optional(),
|
|
1
|
+
import { anySchema, arraySchema, booleanSchema, integerSchema, Joi, objectSchema, stringSchema, } from '@naturalcycles/nodejs-lib';
|
|
2
|
+
import { dbQueryFilterOperatorValues } from '../query/dbQuery.js';
|
|
3
|
+
export const commonDBOptionsSchema = objectSchema({
|
|
4
|
+
['onlyCache']: booleanSchema.optional(),
|
|
5
|
+
['skipCache']: booleanSchema.optional(),
|
|
9
6
|
});
|
|
10
|
-
|
|
11
|
-
excludeFromIndexes:
|
|
12
|
-
}).concat(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
name:
|
|
16
|
-
op:
|
|
17
|
-
val:
|
|
7
|
+
export const commonDBSaveOptionsSchema = objectSchema({
|
|
8
|
+
excludeFromIndexes: arraySchema(stringSchema).optional(),
|
|
9
|
+
}).concat(commonDBOptionsSchema);
|
|
10
|
+
export const dbQueryFilterOperatorSchema = Joi.string().valid(...dbQueryFilterOperatorValues);
|
|
11
|
+
export const dbQueryFilterSchema = objectSchema({
|
|
12
|
+
name: stringSchema,
|
|
13
|
+
op: dbQueryFilterOperatorSchema,
|
|
14
|
+
val: anySchema,
|
|
18
15
|
});
|
|
19
|
-
|
|
20
|
-
name:
|
|
21
|
-
descending:
|
|
16
|
+
export const dbQueryOrderSchema = objectSchema({
|
|
17
|
+
name: stringSchema,
|
|
18
|
+
descending: booleanSchema.optional(),
|
|
22
19
|
});
|
|
23
|
-
|
|
24
|
-
table:
|
|
25
|
-
_filters:
|
|
26
|
-
_limitValue:
|
|
27
|
-
_offsetValue:
|
|
28
|
-
_orders:
|
|
29
|
-
_startCursor:
|
|
30
|
-
_endCursor:
|
|
31
|
-
_selectedFieldNames:
|
|
20
|
+
export const dbQuerySchema = objectSchema({
|
|
21
|
+
table: stringSchema,
|
|
22
|
+
_filters: arraySchema(dbQueryFilterSchema).optional(),
|
|
23
|
+
_limitValue: integerSchema.min(0).optional(),
|
|
24
|
+
_offsetValue: integerSchema.min(0).optional(),
|
|
25
|
+
_orders: arraySchema(dbQueryOrderSchema).optional(),
|
|
26
|
+
_startCursor: stringSchema.optional(),
|
|
27
|
+
_endCursor: stringSchema.optional(),
|
|
28
|
+
_selectedFieldNames: arraySchema(stringSchema).optional(),
|
|
32
29
|
});
|
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/db-lib",
|
|
3
|
+
"type": "module",
|
|
3
4
|
"scripts": {
|
|
4
5
|
"prepare": "husky",
|
|
5
6
|
"build": "dev-lib build",
|
|
@@ -13,10 +14,11 @@
|
|
|
13
14
|
"@naturalcycles/nodejs-lib": "^13"
|
|
14
15
|
},
|
|
15
16
|
"devDependencies": {
|
|
16
|
-
"@naturalcycles/bench-lib": "^
|
|
17
|
-
"@naturalcycles/dev-lib": "^
|
|
17
|
+
"@naturalcycles/bench-lib": "^4",
|
|
18
|
+
"@naturalcycles/dev-lib": "^17",
|
|
18
19
|
"@types/node": "^22",
|
|
19
20
|
"@vitest/coverage-v8": "^3",
|
|
21
|
+
"tsx": "^4",
|
|
20
22
|
"vitest": "^3"
|
|
21
23
|
},
|
|
22
24
|
"files": [
|
|
@@ -46,7 +48,7 @@
|
|
|
46
48
|
"engines": {
|
|
47
49
|
"node": ">=22.12.0"
|
|
48
50
|
},
|
|
49
|
-
"version": "10.0
|
|
51
|
+
"version": "10.1.0",
|
|
50
52
|
"description": "Lowest Common Denominator API to supported Databases",
|
|
51
53
|
"keywords": [
|
|
52
54
|
"db",
|
|
@@ -60,7 +62,6 @@
|
|
|
60
62
|
"firestore",
|
|
61
63
|
"mysql"
|
|
62
64
|
],
|
|
63
|
-
"type": "commonjs",
|
|
64
65
|
"author": "Natural Cycles Team",
|
|
65
66
|
"license": "MIT"
|
|
66
67
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { CommonLogger, ObjectWithId } from '@naturalcycles/js-lib'
|
|
2
|
-
import { CommonDB } from '../../common.db'
|
|
3
|
-
import {
|
|
1
|
+
import type { CommonLogger, ObjectWithId } from '@naturalcycles/js-lib'
|
|
2
|
+
import type { CommonDB } from '../../common.db.js'
|
|
3
|
+
import type {
|
|
4
4
|
CommonDBCreateOptions,
|
|
5
5
|
CommonDBOptions,
|
|
6
6
|
CommonDBSaveOptions,
|
|
7
7
|
CommonDBStreamOptions,
|
|
8
|
-
} from '../../db.model'
|
|
8
|
+
} from '../../db.model.js'
|
|
9
9
|
|
|
10
10
|
export interface CacheDBCfg {
|
|
11
11
|
name: string
|
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import { Readable } from 'node:stream'
|
|
2
|
-
import {
|
|
3
|
-
_isTruthy,
|
|
2
|
+
import type {
|
|
4
3
|
JsonSchemaObject,
|
|
5
4
|
JsonSchemaRootObject,
|
|
6
5
|
ObjectWithId,
|
|
7
6
|
StringMap,
|
|
8
7
|
} from '@naturalcycles/js-lib'
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
8
|
+
import { _isTruthy } from '@naturalcycles/js-lib'
|
|
9
|
+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
10
|
+
import { BaseCommonDB } from '../../base.common.db.js'
|
|
11
|
+
import type { CommonDB, CommonDBSupport } from '../../common.db.js'
|
|
12
|
+
import { commonDBFullSupport } from '../../common.db.js'
|
|
13
|
+
import type { RunQueryResult } from '../../db.model.js'
|
|
14
|
+
import type { DBQuery } from '../../query/dbQuery.js'
|
|
15
|
+
import type {
|
|
15
16
|
CacheDBCfg,
|
|
16
17
|
CacheDBCreateOptions,
|
|
17
18
|
CacheDBOptions,
|
|
18
19
|
CacheDBSaveOptions,
|
|
19
20
|
CacheDBStreamOptions,
|
|
20
|
-
} from './cache.db.model'
|
|
21
|
+
} from './cache.db.model.js'
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* CommonDB implementation that proxies requests to downstream CommonDB
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { CacheDB } from './cache.db'
|
|
2
|
-
import {
|
|
1
|
+
import { CacheDB } from './cache.db.js'
|
|
2
|
+
import type {
|
|
3
3
|
CacheDBCfg,
|
|
4
4
|
CacheDBCreateOptions,
|
|
5
5
|
CacheDBOptions,
|
|
6
6
|
CacheDBStreamOptions,
|
|
7
|
-
} from './cache.db.model'
|
|
7
|
+
} from './cache.db.model.js'
|
|
8
8
|
|
|
9
9
|
export type { CacheDBCfg, CacheDBCreateOptions, CacheDBOptions, CacheDBStreamOptions }
|
|
10
10
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CommonLogger, ObjectWithId } from '@naturalcycles/js-lib'
|
|
2
|
-
import { DBSaveBatchOperation } from '../../db.model'
|
|
3
|
-
import type { DBQueryOrder } from '../../query/dbQuery'
|
|
1
|
+
import type { CommonLogger, ObjectWithId } from '@naturalcycles/js-lib'
|
|
2
|
+
import type { DBSaveBatchOperation } from '../../db.model.js'
|
|
3
|
+
import type { DBQueryOrder } from '../../query/dbQuery.js'
|
|
4
4
|
|
|
5
5
|
export interface FileDBPersistencePlugin {
|
|
6
6
|
ping: () => Promise<void>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { JsonSchemaRootObject, ObjectWithId, UnixTimestampMillis } from '@naturalcycles/js-lib'
|
|
1
2
|
import {
|
|
2
3
|
_assert,
|
|
3
4
|
_by,
|
|
@@ -8,28 +9,23 @@ import {
|
|
|
8
9
|
_sortObjectDeep,
|
|
9
10
|
_stringMapValues,
|
|
10
11
|
generateJsonSchemaFromData,
|
|
11
|
-
JsonSchemaRootObject,
|
|
12
12
|
localTime,
|
|
13
|
-
ObjectWithId,
|
|
14
|
-
UnixTimestampMillis,
|
|
15
13
|
} from '@naturalcycles/js-lib'
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
queryInMemory,
|
|
23
|
-
} from '../..'
|
|
24
|
-
import { CommonDB } from '../../common.db'
|
|
25
|
-
import {
|
|
14
|
+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
15
|
+
import { dimGrey, readableCreate } from '@naturalcycles/nodejs-lib'
|
|
16
|
+
import { BaseCommonDB } from '../../base.common.db.js'
|
|
17
|
+
import type { CommonDB, CommonDBSupport } from '../../common.db.js'
|
|
18
|
+
import { commonDBFullSupport } from '../../common.db.js'
|
|
19
|
+
import type {
|
|
26
20
|
CommonDBOptions,
|
|
27
21
|
CommonDBSaveOptions,
|
|
28
22
|
CommonDBStreamOptions,
|
|
23
|
+
DBSaveBatchOperation,
|
|
29
24
|
RunQueryResult,
|
|
30
|
-
} from '../../db.model'
|
|
31
|
-
import { DBQuery } from '../../query/dbQuery'
|
|
32
|
-
import {
|
|
25
|
+
} from '../../db.model.js'
|
|
26
|
+
import type { DBQuery } from '../../query/dbQuery.js'
|
|
27
|
+
import { queryInMemory } from '../inmemory/queryInMemory.js'
|
|
28
|
+
import type { FileDBCfg } from './file.db.model.js'
|
|
33
29
|
|
|
34
30
|
/**
|
|
35
31
|
* Provides barebone implementation for "whole file" based CommonDB.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { ObjectWithId, StringMap } from '@naturalcycles/js-lib'
|
|
2
|
+
import { _by } from '@naturalcycles/js-lib'
|
|
3
|
+
import type { DBSaveBatchOperation } from '../../db.model.js'
|
|
4
|
+
import type { FileDBPersistencePlugin } from './file.db.model.js'
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Mostly useful for testing.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { FileDB } from './file.db'
|
|
2
|
-
import { FileDBCfg, FileDBPersistencePlugin } from './file.db.model'
|
|
3
|
-
import { LocalFilePersistencePlugin } from './localFile.persistence.plugin'
|
|
1
|
+
import { FileDB } from './file.db.js'
|
|
2
|
+
import type { FileDBCfg, FileDBPersistencePlugin } from './file.db.model.js'
|
|
3
|
+
import { LocalFilePersistencePlugin } from './localFile.persistence.plugin.js'
|
|
4
4
|
|
|
5
5
|
export type { FileDBCfg, FileDBPersistencePlugin }
|
|
6
6
|
export { FileDB, LocalFilePersistencePlugin }
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Readable } from 'node:stream'
|
|
2
|
-
import { ObjectWithId
|
|
2
|
+
import type { ObjectWithId } from '@naturalcycles/js-lib'
|
|
3
|
+
import { pMap } from '@naturalcycles/js-lib'
|
|
3
4
|
import { _pipeline, fs2 } from '@naturalcycles/nodejs-lib'
|
|
4
|
-
import { DBSaveBatchOperation } from '../../db.model'
|
|
5
|
-
import { FileDBPersistencePlugin } from './file.db.model'
|
|
5
|
+
import type { DBSaveBatchOperation } from '../../db.model.js'
|
|
6
|
+
import type { FileDBPersistencePlugin } from './file.db.model.js'
|
|
6
7
|
|
|
7
8
|
export interface LocalFilePersistencePluginCfg {
|
|
8
9
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ObjectWithId } from '@naturalcycles/js-lib'
|
|
2
|
-
import { DBSaveBatchOperation } from '../../db.model'
|
|
3
|
-
import { FileDBPersistencePlugin } from './file.db.model'
|
|
1
|
+
import type { ObjectWithId } from '@naturalcycles/js-lib'
|
|
2
|
+
import type { DBSaveBatchOperation } from '../../db.model.js'
|
|
3
|
+
import type { FileDBPersistencePlugin } from './file.db.model.js'
|
|
4
4
|
|
|
5
5
|
export class NoopPersistencePlugin implements FileDBPersistencePlugin {
|
|
6
6
|
async ping(): Promise<void> {}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import { Readable } from 'node:stream'
|
|
2
|
+
import type {
|
|
3
|
+
AnyObjectWithId,
|
|
4
|
+
CommonLogger,
|
|
5
|
+
JsonSchemaObject,
|
|
6
|
+
JsonSchemaRootObject,
|
|
7
|
+
ObjectWithId,
|
|
8
|
+
StringMap,
|
|
9
|
+
} from '@naturalcycles/js-lib'
|
|
2
10
|
import {
|
|
3
11
|
_assert,
|
|
4
12
|
_by,
|
|
@@ -8,42 +16,26 @@ import {
|
|
|
8
16
|
_sortObjectDeep,
|
|
9
17
|
_stringMapEntries,
|
|
10
18
|
_stringMapValues,
|
|
11
|
-
AnyObjectWithId,
|
|
12
|
-
CommonLogger,
|
|
13
19
|
generateJsonSchemaFromData,
|
|
14
|
-
JsonSchemaObject,
|
|
15
|
-
JsonSchemaRootObject,
|
|
16
20
|
localTime,
|
|
17
|
-
ObjectWithId,
|
|
18
21
|
pMap,
|
|
19
|
-
StringMap,
|
|
20
22
|
} from '@naturalcycles/js-lib'
|
|
21
|
-
import {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
ReadableTyped,
|
|
27
|
-
yellow,
|
|
28
|
-
} from '@naturalcycles/nodejs-lib'
|
|
29
|
-
import {
|
|
30
|
-
CommonDB,
|
|
31
|
-
commonDBFullSupport,
|
|
32
|
-
CommonDBSupport,
|
|
33
|
-
CommonDBTransactionOptions,
|
|
34
|
-
CommonDBType,
|
|
35
|
-
DBOperation,
|
|
36
|
-
DBTransactionFn,
|
|
37
|
-
queryInMemory,
|
|
38
|
-
} from '../..'
|
|
39
|
-
import {
|
|
23
|
+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
24
|
+
import { _pipeline, bufferReviver, dimGrey, fs2, yellow } from '@naturalcycles/nodejs-lib'
|
|
25
|
+
import type { CommonDB, CommonDBSupport } from '../../common.db.js'
|
|
26
|
+
import { commonDBFullSupport, CommonDBType } from '../../common.db.js'
|
|
27
|
+
import type {
|
|
40
28
|
CommonDBCreateOptions,
|
|
41
29
|
CommonDBOptions,
|
|
42
30
|
CommonDBSaveOptions,
|
|
31
|
+
CommonDBTransactionOptions,
|
|
32
|
+
DBOperation,
|
|
43
33
|
DBTransaction,
|
|
34
|
+
DBTransactionFn,
|
|
44
35
|
RunQueryResult,
|
|
45
|
-
} from '../../db.model'
|
|
46
|
-
import { DBQuery } from '../../query/dbQuery'
|
|
36
|
+
} from '../../db.model.js'
|
|
37
|
+
import type { DBQuery } from '../../query/dbQuery.js'
|
|
38
|
+
import { queryInMemory } from './queryInMemory.js'
|
|
47
39
|
|
|
48
40
|
export interface InMemoryDBCfg {
|
|
49
41
|
/**
|
|
@@ -287,6 +279,13 @@ export class InMemoryDB implements CommonDB {
|
|
|
287
279
|
}
|
|
288
280
|
}
|
|
289
281
|
|
|
282
|
+
async createTransaction(opt: CommonDBTransactionOptions = {}): Promise<DBTransaction> {
|
|
283
|
+
return new InMemoryDBTransaction(this, {
|
|
284
|
+
readOnly: false,
|
|
285
|
+
...opt,
|
|
286
|
+
})
|
|
287
|
+
}
|
|
288
|
+
|
|
290
289
|
async incrementBatch(
|
|
291
290
|
table: string,
|
|
292
291
|
prop: string,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Readable } from 'node:stream'
|
|
2
|
-
import { StringMap } from '@naturalcycles/js-lib'
|
|
3
|
-
import { ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
4
|
-
import { CommonDBCreateOptions } from '../../db.model'
|
|
5
|
-
import {
|
|
2
|
+
import type { StringMap } from '@naturalcycles/js-lib'
|
|
3
|
+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
4
|
+
import type { CommonDBCreateOptions } from '../../db.model.js'
|
|
5
|
+
import type {
|
|
6
6
|
CommonKeyValueDB,
|
|
7
|
-
commonKeyValueDBFullSupport,
|
|
8
7
|
IncrementTuple,
|
|
9
8
|
KeyValueDBTuple,
|
|
10
|
-
} from '../../kv/commonKeyValueDB'
|
|
9
|
+
} from '../../kv/commonKeyValueDB.js'
|
|
10
|
+
import { commonKeyValueDBFullSupport } from '../../kv/commonKeyValueDB.js'
|
|
11
11
|
|
|
12
12
|
export interface InMemoryKeyValueDBCfg {}
|
|
13
13
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { ObjectWithId } from '@naturalcycles/js-lib'
|
|
2
|
+
import { _get, _pick } from '@naturalcycles/js-lib'
|
|
3
|
+
import type { DBQuery, DBQueryFilterOperator } from '../../query/dbQuery.js'
|
|
3
4
|
|
|
4
5
|
type FilterFn = (v: any, val: any) => boolean
|
|
5
6
|
const FILTER_FNS: Record<DBQueryFilterOperator, FilterFn> = {
|
package/src/base.common.db.ts
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
JsonSchemaObject,
|
|
3
3
|
JsonSchemaRootObject,
|
|
4
4
|
ObjectWithId,
|
|
5
5
|
StringMap,
|
|
6
6
|
} from '@naturalcycles/js-lib'
|
|
7
|
-
import { ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
8
|
-
import { CommonDB, CommonDBSupport
|
|
9
|
-
import {
|
|
7
|
+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
8
|
+
import type { CommonDB, CommonDBSupport } from './common.db.js'
|
|
9
|
+
import { CommonDBType } from './common.db.js'
|
|
10
|
+
import type {
|
|
10
11
|
CommonDBOptions,
|
|
11
12
|
CommonDBSaveOptions,
|
|
12
13
|
CommonDBTransactionOptions,
|
|
13
14
|
DBTransactionFn,
|
|
14
15
|
RunQueryResult,
|
|
15
|
-
} from './db.model'
|
|
16
|
-
import { DBQuery } from './query/dbQuery'
|
|
17
|
-
import { FakeDBTransaction } from './transaction/dbTransaction.util'
|
|
16
|
+
} from './db.model.js'
|
|
17
|
+
import type { DBQuery } from './query/dbQuery.js'
|
|
18
|
+
import { FakeDBTransaction } from './transaction/dbTransaction.util.js'
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* No-op implementation of CommonDB interface.
|
|
@@ -92,6 +93,10 @@ export class BaseCommonDB implements CommonDB {
|
|
|
92
93
|
// there's no try/catch and rollback, as there's nothing to rollback
|
|
93
94
|
}
|
|
94
95
|
|
|
96
|
+
async createTransaction(_opt?: CommonDBTransactionOptions): Promise<FakeDBTransaction> {
|
|
97
|
+
return new FakeDBTransaction(this)
|
|
98
|
+
}
|
|
99
|
+
|
|
95
100
|
async incrementBatch(
|
|
96
101
|
_table: string,
|
|
97
102
|
_prop: string,
|
package/src/common.db.ts
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
JsonSchemaObject,
|
|
3
3
|
JsonSchemaRootObject,
|
|
4
4
|
ObjectWithId,
|
|
5
5
|
StringMap,
|
|
6
6
|
} from '@naturalcycles/js-lib'
|
|
7
7
|
import type { ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
8
|
-
import {
|
|
8
|
+
import type {
|
|
9
9
|
CommonDBCreateOptions,
|
|
10
10
|
CommonDBOptions,
|
|
11
11
|
CommonDBReadOptions,
|
|
12
12
|
CommonDBSaveOptions,
|
|
13
13
|
CommonDBStreamOptions,
|
|
14
14
|
CommonDBTransactionOptions,
|
|
15
|
+
DBTransaction,
|
|
15
16
|
DBTransactionFn,
|
|
16
17
|
RunQueryResult,
|
|
17
|
-
} from './db.model'
|
|
18
|
-
import { DBQuery } from './query/dbQuery'
|
|
18
|
+
} from './db.model.js'
|
|
19
|
+
import type { DBQuery } from './query/dbQuery.js'
|
|
19
20
|
|
|
20
21
|
export enum CommonDBType {
|
|
21
22
|
'document' = 'document',
|
|
@@ -151,6 +152,13 @@ export interface CommonDB {
|
|
|
151
152
|
*/
|
|
152
153
|
runInTransaction: (fn: DBTransactionFn, opt?: CommonDBTransactionOptions) => Promise<void>
|
|
153
154
|
|
|
155
|
+
/**
|
|
156
|
+
* Experimental API to support more manual transaction control.
|
|
157
|
+
*
|
|
158
|
+
* @experimental
|
|
159
|
+
*/
|
|
160
|
+
createTransaction: (opt?: CommonDBTransactionOptions) => Promise<DBTransaction>
|
|
161
|
+
|
|
154
162
|
/**
|
|
155
163
|
* Increments a value of a property by a given amount.
|
|
156
164
|
* This is a batch operation, so it allows to increment multiple rows at once.
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
BaseDBEntity,
|
|
3
3
|
CommonLogger,
|
|
4
4
|
ErrorMode,
|
|
5
5
|
NumberOfMilliseconds,
|
|
6
6
|
Promisable,
|
|
7
7
|
UnixTimestamp,
|
|
8
|
-
ZodError,
|
|
9
|
-
ZodSchema,
|
|
10
8
|
} from '@naturalcycles/js-lib'
|
|
11
|
-
import {
|
|
9
|
+
import type { ZodError, ZodSchema } from '@naturalcycles/js-lib/dist/zod/index.js'
|
|
10
|
+
import type {
|
|
12
11
|
AjvSchema,
|
|
13
12
|
AjvValidationError,
|
|
14
13
|
JoiValidationError,
|
|
@@ -16,8 +15,8 @@ import {
|
|
|
16
15
|
TransformLogProgressOptions,
|
|
17
16
|
TransformMapOptions,
|
|
18
17
|
} from '@naturalcycles/nodejs-lib'
|
|
19
|
-
import { CommonDB } from '../common.db'
|
|
20
|
-
import { CommonDBCreateOptions, CommonDBOptions, CommonDBSaveOptions } from '../db.model'
|
|
18
|
+
import type { CommonDB } from '../common.db.js'
|
|
19
|
+
import type { CommonDBCreateOptions, CommonDBOptions, CommonDBSaveOptions } from '../db.model.js'
|
|
21
20
|
|
|
22
21
|
export interface CommonDaoHooks<BM extends BaseDBEntity, DBM extends BaseDBEntity, ID = BM['id']> {
|
|
23
22
|
/**
|