@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.
Files changed (114) hide show
  1. package/dist/adapter/cachedb/cache.db.d.ts +7 -7
  2. package/dist/adapter/cachedb/cache.db.js +13 -16
  3. package/dist/adapter/cachedb/cache.db.model.d.ts +3 -3
  4. package/dist/adapter/cachedb/cache.db.model.js +1 -2
  5. package/dist/adapter/cachedb/index.d.ts +2 -2
  6. package/dist/adapter/cachedb/index.js +2 -5
  7. package/dist/adapter/file/file.db.d.ts +7 -7
  8. package/dist/adapter/file/file.db.js +35 -36
  9. package/dist/adapter/file/file.db.model.d.ts +3 -3
  10. package/dist/adapter/file/file.db.model.js +1 -2
  11. package/dist/adapter/file/inMemory.persistence.plugin.d.ts +3 -3
  12. package/dist/adapter/file/inMemory.persistence.plugin.js +4 -10
  13. package/dist/adapter/file/index.d.ts +3 -3
  14. package/dist/adapter/file/index.js +3 -7
  15. package/dist/adapter/file/localFile.persistence.plugin.d.ts +3 -3
  16. package/dist/adapter/file/localFile.persistence.plugin.js +12 -15
  17. package/dist/adapter/file/noop.persistence.plugin.d.ts +3 -3
  18. package/dist/adapter/file/noop.persistence.plugin.js +1 -5
  19. package/dist/adapter/inmemory/inMemory.db.d.ts +7 -5
  20. package/dist/adapter/inmemory/inMemory.db.js +54 -49
  21. package/dist/adapter/inmemory/inMemoryKeyValueDB.d.ts +4 -4
  22. package/dist/adapter/inmemory/inMemoryKeyValueDB.js +12 -15
  23. package/dist/adapter/inmemory/queryInMemory.d.ts +2 -2
  24. package/dist/adapter/inmemory/queryInMemory.js +4 -7
  25. package/dist/base.common.db.d.ts +8 -5
  26. package/dist/base.common.db.js +9 -12
  27. package/dist/cnst.js +2 -5
  28. package/dist/common.db.d.ts +9 -3
  29. package/dist/common.db.js +3 -6
  30. package/dist/commondao/common.dao.d.ts +16 -6
  31. package/dist/commondao/common.dao.js +123 -112
  32. package/dist/commondao/common.dao.model.d.ts +5 -4
  33. package/dist/commondao/common.dao.model.js +2 -5
  34. package/dist/db.model.d.ts +7 -2
  35. package/dist/db.model.js +4 -7
  36. package/dist/index.d.ts +17 -17
  37. package/dist/index.js +17 -20
  38. package/dist/kv/commonKeyValueDB.d.ts +3 -3
  39. package/dist/kv/commonKeyValueDB.js +1 -4
  40. package/dist/kv/commonKeyValueDao.d.ts +5 -5
  41. package/dist/kv/commonKeyValueDao.js +11 -14
  42. package/dist/kv/commonKeyValueDaoMemoCache.d.ts +3 -2
  43. package/dist/kv/commonKeyValueDaoMemoCache.js +5 -8
  44. package/dist/model.util.d.ts +1 -1
  45. package/dist/model.util.js +9 -15
  46. package/dist/pipeline/dbPipelineBackup.d.ts +6 -4
  47. package/dist/pipeline/dbPipelineBackup.js +27 -30
  48. package/dist/pipeline/dbPipelineCopy.d.ts +6 -4
  49. package/dist/pipeline/dbPipelineCopy.js +20 -23
  50. package/dist/pipeline/dbPipelineRestore.d.ts +6 -4
  51. package/dist/pipeline/dbPipelineRestore.js +27 -30
  52. package/dist/query/dbQuery.d.ts +5 -5
  53. package/dist/query/dbQuery.js +22 -17
  54. package/dist/testing/{dbTest.d.ts → commonDBTest.d.ts} +1 -1
  55. package/dist/testing/{dbTest.js → commonDBTest.js} +81 -62
  56. package/dist/testing/commonDaoTest.d.ts +3 -0
  57. package/dist/testing/{daoTest.js → commonDaoTest.js} +101 -38
  58. package/dist/testing/index.d.ts +7 -5
  59. package/dist/testing/index.js +6 -20
  60. package/dist/testing/keyValueDBTest.d.ts +1 -1
  61. package/dist/testing/keyValueDBTest.js +28 -31
  62. package/dist/testing/keyValueDaoTest.d.ts +1 -1
  63. package/dist/testing/keyValueDaoTest.js +8 -11
  64. package/dist/testing/test.model.d.ts +1 -1
  65. package/dist/testing/test.model.js +30 -37
  66. package/dist/testing/timeSeriesTest.util.d.ts +1 -1
  67. package/dist/testing/timeSeriesTest.util.js +3 -6
  68. package/dist/timeseries/commonTimeSeriesDao.d.ts +1 -1
  69. package/dist/timeseries/commonTimeSeriesDao.js +6 -9
  70. package/dist/timeseries/timeSeries.model.d.ts +1 -1
  71. package/dist/timeseries/timeSeries.model.js +1 -2
  72. package/dist/transaction/dbTransaction.util.d.ts +4 -3
  73. package/dist/transaction/dbTransaction.util.js +3 -5
  74. package/dist/validation/index.d.ts +2 -2
  75. package/dist/validation/index.js +25 -28
  76. package/package.json +5 -4
  77. package/src/adapter/cachedb/cache.db.model.ts +4 -4
  78. package/src/adapter/cachedb/cache.db.ts +10 -9
  79. package/src/adapter/cachedb/index.ts +3 -3
  80. package/src/adapter/file/file.db.model.ts +3 -3
  81. package/src/adapter/file/file.db.ts +12 -16
  82. package/src/adapter/file/inMemory.persistence.plugin.ts +4 -3
  83. package/src/adapter/file/index.ts +3 -3
  84. package/src/adapter/file/localFile.persistence.plugin.ts +4 -3
  85. package/src/adapter/file/noop.persistence.plugin.ts +3 -3
  86. package/src/adapter/inmemory/inMemory.db.ts +26 -27
  87. package/src/adapter/inmemory/inMemoryKeyValueDB.ts +6 -6
  88. package/src/adapter/inmemory/queryInMemory.ts +3 -2
  89. package/src/base.common.db.ts +12 -7
  90. package/src/common.db.ts +12 -4
  91. package/src/commondao/common.dao.model.ts +5 -6
  92. package/src/commondao/common.dao.ts +41 -23
  93. package/src/db.model.ts +8 -2
  94. package/src/index.ts +17 -17
  95. package/src/kv/commonKeyValueDB.ts +3 -3
  96. package/src/kv/commonKeyValueDao.ts +8 -6
  97. package/src/kv/commonKeyValueDaoMemoCache.ts +3 -8
  98. package/src/model.util.ts +2 -1
  99. package/src/pipeline/dbPipelineBackup.ts +5 -14
  100. package/src/pipeline/dbPipelineCopy.ts +6 -14
  101. package/src/pipeline/dbPipelineRestore.ts +9 -8
  102. package/src/query/dbQuery.ts +7 -12
  103. package/src/testing/{dbTest.ts → commonDBTest.ts} +34 -5
  104. package/src/testing/{daoTest.ts → commonDaoTest.ts} +89 -11
  105. package/src/testing/index.ts +7 -8
  106. package/src/testing/keyValueDBTest.ts +4 -3
  107. package/src/testing/keyValueDaoTest.ts +3 -3
  108. package/src/testing/test.model.ts +2 -7
  109. package/src/testing/timeSeriesTest.util.ts +1 -1
  110. package/src/timeseries/commonTimeSeriesDao.ts +5 -4
  111. package/src/timeseries/timeSeries.model.ts +1 -1
  112. package/src/transaction/dbTransaction.util.ts +4 -3
  113. package/src/validation/index.ts +4 -4
  114. package/dist/testing/daoTest.d.ts +0 -3
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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(js_lib_1._isTruthy);
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 = dbQuery_1.DBQuery.create(`${q.series}${_TIMESERIES_RAW}`).order('ts');
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,4 +1,4 @@
1
- import { CommonDB } from '../common.db';
1
+ import type { CommonDB } from '../common.db.js';
2
2
  export interface CommonTimeSeriesDaoCfg {
3
3
  db: CommonDB;
4
4
  }
@@ -1,2 +1 @@
1
- "use strict";
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>;
@@ -1,32 +1,29 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dbQuerySchema = exports.dbQueryOrderSchema = exports.dbQueryFilterSchema = exports.dbQueryFilterOperatorSchema = exports.commonDBSaveOptionsSchema = exports.commonDBOptionsSchema = void 0;
4
- const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
5
- const dbQuery_1 = require("../query/dbQuery");
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
- exports.commonDBSaveOptionsSchema = (0, nodejs_lib_1.objectSchema)({
11
- excludeFromIndexes: (0, nodejs_lib_1.arraySchema)(nodejs_lib_1.stringSchema).optional(),
12
- }).concat(exports.commonDBOptionsSchema);
13
- exports.dbQueryFilterOperatorSchema = nodejs_lib_1.Joi.string().valid(...dbQuery_1.dbQueryFilterOperatorValues);
14
- exports.dbQueryFilterSchema = (0, nodejs_lib_1.objectSchema)({
15
- name: nodejs_lib_1.stringSchema,
16
- op: exports.dbQueryFilterOperatorSchema,
17
- val: nodejs_lib_1.anySchema,
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
- exports.dbQueryOrderSchema = (0, nodejs_lib_1.objectSchema)({
20
- name: nodejs_lib_1.stringSchema,
21
- descending: nodejs_lib_1.booleanSchema.optional(),
16
+ export const dbQueryOrderSchema = objectSchema({
17
+ name: stringSchema,
18
+ descending: booleanSchema.optional(),
22
19
  });
23
- exports.dbQuerySchema = (0, nodejs_lib_1.objectSchema)({
24
- table: nodejs_lib_1.stringSchema,
25
- _filters: (0, nodejs_lib_1.arraySchema)(exports.dbQueryFilterSchema).optional(),
26
- _limitValue: nodejs_lib_1.integerSchema.min(0).optional(),
27
- _offsetValue: nodejs_lib_1.integerSchema.min(0).optional(),
28
- _orders: (0, nodejs_lib_1.arraySchema)(exports.dbQueryOrderSchema).optional(),
29
- _startCursor: nodejs_lib_1.stringSchema.optional(),
30
- _endCursor: nodejs_lib_1.stringSchema.optional(),
31
- _selectedFieldNames: (0, nodejs_lib_1.arraySchema)(nodejs_lib_1.stringSchema).optional(),
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": "^3",
17
- "@naturalcycles/dev-lib": "^16",
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.1",
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 { ReadableTyped } from '@naturalcycles/nodejs-lib'
10
- import { BaseCommonDB } from '../../base.common.db'
11
- import { CommonDB, commonDBFullSupport, CommonDBSupport } from '../../common.db'
12
- import { RunQueryResult } from '../../db.model'
13
- import { DBQuery } from '../../query/dbQuery'
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 { dimGrey, readableCreate, ReadableTyped } from '@naturalcycles/nodejs-lib'
17
- import {
18
- BaseCommonDB,
19
- commonDBFullSupport,
20
- CommonDBSupport,
21
- DBSaveBatchOperation,
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 { FileDBCfg } from './file.db.model'
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 { _by, ObjectWithId, StringMap } from '@naturalcycles/js-lib'
2
- import { DBSaveBatchOperation } from '../../db.model'
3
- import { FileDBPersistencePlugin } from './file.db.model'
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, pMap } from '@naturalcycles/js-lib'
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
- _pipeline,
23
- bufferReviver,
24
- dimGrey,
25
- fs2,
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 { _get, _pick, ObjectWithId } from '@naturalcycles/js-lib'
2
- import { DBQuery, DBQueryFilterOperator } from '../../query/dbQuery'
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> = {
@@ -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, CommonDBType } from './common.db'
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
  /**