@naturalcycles/db-lib 10.0.0 → 10.0.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.
Files changed (90) hide show
  1. package/dist/adapter/cachedb/cache.db.d.ts +6 -6
  2. package/dist/adapter/cachedb/cache.db.js +6 -5
  3. package/dist/adapter/cachedb/cache.db.model.d.ts +3 -3
  4. package/dist/adapter/cachedb/index.d.ts +1 -1
  5. package/dist/adapter/file/file.db.d.ts +8 -7
  6. package/dist/adapter/file/file.db.js +11 -10
  7. package/dist/adapter/file/file.db.model.d.ts +2 -2
  8. package/dist/adapter/file/inMemory.persistence.plugin.d.ts +3 -3
  9. package/dist/adapter/file/inMemory.persistence.plugin.js +1 -3
  10. package/dist/adapter/file/index.d.ts +1 -1
  11. package/dist/adapter/file/localFile.persistence.plugin.d.ts +3 -3
  12. package/dist/adapter/file/localFile.persistence.plugin.js +1 -0
  13. package/dist/adapter/file/noop.persistence.plugin.d.ts +3 -3
  14. package/dist/adapter/inmemory/inMemory.db.d.ts +6 -5
  15. package/dist/adapter/inmemory/inMemory.db.js +13 -10
  16. package/dist/adapter/inmemory/inMemoryKeyValueDB.d.ts +4 -4
  17. package/dist/adapter/inmemory/inMemoryKeyValueDB.js +6 -5
  18. package/dist/adapter/inmemory/queryInMemory.d.ts +2 -2
  19. package/dist/base.common.db.d.ts +6 -5
  20. package/dist/base.common.db.js +2 -4
  21. package/dist/common.db.d.ts +3 -3
  22. package/dist/commondao/common.dao.d.ts +9 -6
  23. package/dist/commondao/common.dao.js +6 -2
  24. package/dist/commondao/common.dao.model.d.ts +5 -4
  25. package/dist/db.model.d.ts +2 -2
  26. package/dist/kv/commonKeyValueDB.d.ts +3 -3
  27. package/dist/kv/commonKeyValueDao.d.ts +5 -5
  28. package/dist/kv/commonKeyValueDao.js +1 -0
  29. package/dist/kv/commonKeyValueDaoMemoCache.d.ts +3 -2
  30. package/dist/kv/commonKeyValueDaoMemoCache.js +1 -0
  31. package/dist/model.util.d.ts +1 -1
  32. package/dist/pipeline/dbPipelineBackup.d.ts +5 -3
  33. package/dist/pipeline/dbPipelineCopy.d.ts +6 -4
  34. package/dist/pipeline/dbPipelineRestore.d.ts +6 -4
  35. package/dist/query/dbQuery.d.ts +5 -5
  36. package/dist/query/dbQuery.js +15 -5
  37. package/dist/testing/daoTest.d.ts +3 -3
  38. package/dist/testing/daoTest.js +89 -74
  39. package/dist/testing/dbTest.d.ts +2 -3
  40. package/dist/testing/dbTest.js +68 -68
  41. package/dist/testing/index.d.ts +4 -2
  42. package/dist/testing/keyValueDBTest.d.ts +2 -2
  43. package/dist/testing/keyValueDBTest.js +37 -37
  44. package/dist/testing/keyValueDaoTest.d.ts +2 -2
  45. package/dist/testing/keyValueDaoTest.js +33 -33
  46. package/dist/testing/test.model.d.ts +1 -1
  47. package/dist/testing/timeSeriesTest.util.d.ts +1 -1
  48. package/dist/timeseries/commonTimeSeriesDao.d.ts +1 -1
  49. package/dist/timeseries/commonTimeSeriesDao.js +1 -0
  50. package/dist/timeseries/timeSeries.model.d.ts +1 -1
  51. package/dist/transaction/dbTransaction.util.d.ts +2 -2
  52. package/dist/transaction/dbTransaction.util.js +1 -0
  53. package/dist/validation/index.d.ts +2 -2
  54. package/package.json +3 -2
  55. package/src/adapter/cachedb/cache.db.model.ts +3 -3
  56. package/src/adapter/cachedb/cache.db.ts +8 -7
  57. package/src/adapter/cachedb/index.ts +1 -1
  58. package/src/adapter/file/file.db.model.ts +2 -2
  59. package/src/adapter/file/file.db.ts +9 -15
  60. package/src/adapter/file/inMemory.persistence.plugin.ts +4 -3
  61. package/src/adapter/file/index.ts +1 -1
  62. package/src/adapter/file/localFile.persistence.plugin.ts +4 -3
  63. package/src/adapter/file/noop.persistence.plugin.ts +3 -3
  64. package/src/adapter/inmemory/inMemory.db.ts +14 -20
  65. package/src/adapter/inmemory/inMemoryKeyValueDB.ts +5 -9
  66. package/src/adapter/inmemory/queryInMemory.ts +3 -2
  67. package/src/base.common.db.ts +6 -5
  68. package/src/common.db.ts +3 -3
  69. package/src/commondao/common.dao.model.ts +5 -6
  70. package/src/commondao/common.dao.ts +25 -21
  71. package/src/db.model.ts +2 -2
  72. package/src/kv/commonKeyValueDB.ts +3 -3
  73. package/src/kv/commonKeyValueDao.ts +7 -5
  74. package/src/kv/commonKeyValueDaoMemoCache.ts +3 -8
  75. package/src/model.util.ts +2 -1
  76. package/src/pipeline/dbPipelineBackup.ts +4 -13
  77. package/src/pipeline/dbPipelineCopy.ts +5 -13
  78. package/src/pipeline/dbPipelineRestore.ts +9 -8
  79. package/src/query/dbQuery.ts +6 -11
  80. package/src/testing/daoTest.ts +28 -6
  81. package/src/testing/dbTest.ts +24 -22
  82. package/src/testing/index.ts +3 -4
  83. package/src/testing/keyValueDBTest.ts +6 -4
  84. package/src/testing/keyValueDaoTest.ts +4 -3
  85. package/src/testing/test.model.ts +2 -7
  86. package/src/testing/timeSeriesTest.util.ts +1 -1
  87. package/src/timeseries/commonTimeSeriesDao.ts +3 -2
  88. package/src/timeseries/timeSeries.model.ts +1 -1
  89. package/src/transaction/dbTransaction.util.ts +2 -2
  90. package/src/validation/index.ts +3 -8
@@ -1,10 +1,10 @@
1
- import { JsonSchemaObject, JsonSchemaRootObject, ObjectWithId } from '@naturalcycles/js-lib';
2
- import { ReadableTyped } from '@naturalcycles/nodejs-lib';
1
+ import type { JsonSchemaObject, JsonSchemaRootObject, ObjectWithId } from '@naturalcycles/js-lib';
2
+ import type { ReadableTyped } from '@naturalcycles/nodejs-lib';
3
3
  import { BaseCommonDB } from '../../base.common.db';
4
- import { CommonDB, CommonDBSupport } from '../../common.db';
5
- import { RunQueryResult } from '../../db.model';
6
- import { DBQuery } from '../../query/dbQuery';
7
- import { CacheDBCfg, CacheDBCreateOptions, CacheDBOptions, CacheDBSaveOptions, CacheDBStreamOptions } from './cache.db.model';
4
+ import type { CommonDB, CommonDBSupport } from '../../common.db';
5
+ import type { RunQueryResult } from '../../db.model';
6
+ import type { DBQuery } from '../../query/dbQuery';
7
+ import type { CacheDBCfg, CacheDBCreateOptions, CacheDBOptions, CacheDBSaveOptions, CacheDBStreamOptions } from './cache.db.model';
8
8
  /**
9
9
  * CommonDB implementation that proxies requests to downstream CommonDB
10
10
  * and does in-memory caching.
@@ -12,18 +12,19 @@ const common_db_1 = require("../../common.db");
12
12
  * Queries always hit downstream (unless `onlyCache` is passed)
13
13
  */
14
14
  class CacheDB extends base_common_db_1.BaseCommonDB {
15
+ support = {
16
+ ...common_db_1.commonDBFullSupport,
17
+ transactions: false,
18
+ increment: false,
19
+ };
15
20
  constructor(cfg) {
16
21
  super();
17
- this.support = {
18
- ...common_db_1.commonDBFullSupport,
19
- transactions: false,
20
- increment: false,
21
- };
22
22
  this.cfg = {
23
23
  logger: console,
24
24
  ...cfg,
25
25
  };
26
26
  }
27
+ cfg;
27
28
  async ping() {
28
29
  await Promise.all([this.cfg.cacheDB.ping(), this.cfg.downstreamDB.ping()]);
29
30
  }
@@ -1,6 +1,6 @@
1
- import { CommonLogger, ObjectWithId } from '@naturalcycles/js-lib';
2
- import { CommonDB } from '../../common.db';
3
- import { CommonDBCreateOptions, CommonDBOptions, CommonDBSaveOptions, CommonDBStreamOptions } from '../../db.model';
1
+ import type { CommonLogger, ObjectWithId } from '@naturalcycles/js-lib';
2
+ import type { CommonDB } from '../../common.db';
3
+ import type { CommonDBCreateOptions, CommonDBOptions, CommonDBSaveOptions, CommonDBStreamOptions } from '../../db.model';
4
4
  export interface CacheDBCfg {
5
5
  name: string;
6
6
  cacheDB: CommonDB;
@@ -1,4 +1,4 @@
1
1
  import { CacheDB } from './cache.db';
2
- import { CacheDBCfg, CacheDBCreateOptions, CacheDBOptions, CacheDBStreamOptions } from './cache.db.model';
2
+ import type { CacheDBCfg, CacheDBCreateOptions, CacheDBOptions, CacheDBStreamOptions } from './cache.db.model';
3
3
  export type { CacheDBCfg, CacheDBCreateOptions, CacheDBOptions, CacheDBStreamOptions };
4
4
  export { CacheDB };
@@ -1,10 +1,11 @@
1
- import { JsonSchemaRootObject, ObjectWithId } from '@naturalcycles/js-lib';
2
- import { ReadableTyped } from '@naturalcycles/nodejs-lib';
3
- import { BaseCommonDB, CommonDBSupport, DBSaveBatchOperation } from '../..';
4
- import { CommonDB } from '../../common.db';
5
- import { CommonDBOptions, CommonDBSaveOptions, CommonDBStreamOptions, RunQueryResult } from '../../db.model';
6
- import { DBQuery } from '../../query/dbQuery';
7
- import { FileDBCfg } from './file.db.model';
1
+ import type { JsonSchemaRootObject, ObjectWithId } from '@naturalcycles/js-lib';
2
+ import type { ReadableTyped } from '@naturalcycles/nodejs-lib';
3
+ import type { CommonDBSupport, DBSaveBatchOperation } from '../..';
4
+ import { BaseCommonDB } from '../..';
5
+ import type { CommonDB } from '../../common.db';
6
+ import type { CommonDBOptions, CommonDBSaveOptions, CommonDBStreamOptions, RunQueryResult } from '../../db.model';
7
+ import type { DBQuery } from '../../query/dbQuery';
8
+ import type { FileDBCfg } from './file.db.model';
8
9
  /**
9
10
  * Provides barebone implementation for "whole file" based CommonDB.
10
11
  * "whole file" means that the persistence layer doesn't allow any querying,
@@ -15,18 +15,18 @@ const __1 = require("../..");
15
15
  * Each save operation saves *whole* file to the persistence layer.
16
16
  */
17
17
  class FileDB extends __1.BaseCommonDB {
18
+ support = {
19
+ ...__1.commonDBFullSupport,
20
+ bufferValues: false, // todo: implement
21
+ insertSaveMethod: false,
22
+ updateSaveMethod: false,
23
+ patchByQuery: false,
24
+ createTable: false,
25
+ transactions: false, // todo
26
+ increment: false,
27
+ };
18
28
  constructor(cfg) {
19
29
  super();
20
- this.support = {
21
- ...__1.commonDBFullSupport,
22
- bufferValues: false, // todo: implement
23
- insertSaveMethod: false,
24
- updateSaveMethod: false,
25
- patchByQuery: false,
26
- createTable: false,
27
- transactions: false, // todo
28
- increment: false,
29
- };
30
30
  this.cfg = {
31
31
  sortObjects: true,
32
32
  logFinished: true,
@@ -34,6 +34,7 @@ class FileDB extends __1.BaseCommonDB {
34
34
  ...cfg,
35
35
  };
36
36
  }
37
+ cfg;
37
38
  async ping() {
38
39
  await this.cfg.plugin.ping();
39
40
  }
@@ -1,5 +1,5 @@
1
- import { CommonLogger, ObjectWithId } from '@naturalcycles/js-lib';
2
- import { DBSaveBatchOperation } from '../../db.model';
1
+ import type { CommonLogger, ObjectWithId } from '@naturalcycles/js-lib';
2
+ import type { DBSaveBatchOperation } from '../../db.model';
3
3
  import type { DBQueryOrder } from '../../query/dbQuery';
4
4
  export interface FileDBPersistencePlugin {
5
5
  ping: () => Promise<void>;
@@ -1,6 +1,6 @@
1
- import { 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 type { DBSaveBatchOperation } from '../../db.model';
3
+ import type { FileDBPersistencePlugin } from './file.db.model';
4
4
  /**
5
5
  * Mostly useful for testing.
6
6
  */
@@ -6,9 +6,7 @@ const js_lib_1 = require("@naturalcycles/js-lib");
6
6
  * Mostly useful for testing.
7
7
  */
8
8
  class InMemoryPersistencePlugin {
9
- constructor() {
10
- this.data = {};
11
- }
9
+ data = {};
12
10
  async ping() { }
13
11
  async getTables() {
14
12
  return Object.keys(this.data);
@@ -1,5 +1,5 @@
1
1
  import { FileDB } from './file.db';
2
- import { FileDBCfg, FileDBPersistencePlugin } from './file.db.model';
2
+ import type { FileDBCfg, FileDBPersistencePlugin } from './file.db.model';
3
3
  import { LocalFilePersistencePlugin } from './localFile.persistence.plugin';
4
4
  export type { FileDBCfg, FileDBPersistencePlugin };
5
5
  export { FileDB, LocalFilePersistencePlugin };
@@ -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';
3
+ import type { FileDBPersistencePlugin } from './file.db.model';
4
4
  export interface LocalFilePersistencePluginCfg {
5
5
  /**
6
6
  * @default ./tmp/localdb
@@ -15,6 +15,7 @@ class LocalFilePersistencePlugin {
15
15
  ...cfg,
16
16
  };
17
17
  }
18
+ cfg;
18
19
  async ping() { }
19
20
  async getTables() {
20
21
  return (await nodejs_lib_1.fs2.readdirAsync(this.cfg.storagePath))
@@ -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';
3
+ import type { FileDBPersistencePlugin } from './file.db.model';
4
4
  export declare class NoopPersistencePlugin implements FileDBPersistencePlugin {
5
5
  ping(): Promise<void>;
6
6
  getTables(): Promise<string[]>;
@@ -1,8 +1,9 @@
1
- import { AnyObjectWithId, CommonLogger, JsonSchemaObject, JsonSchemaRootObject, ObjectWithId, StringMap } from '@naturalcycles/js-lib';
2
- import { ReadableTyped } from '@naturalcycles/nodejs-lib';
3
- import { CommonDB, CommonDBSupport, CommonDBTransactionOptions, CommonDBType, DBOperation, DBTransactionFn } from '../..';
4
- import { CommonDBCreateOptions, CommonDBOptions, CommonDBSaveOptions, DBTransaction, RunQueryResult } from '../../db.model';
5
- import { DBQuery } from '../../query/dbQuery';
1
+ import type { AnyObjectWithId, CommonLogger, JsonSchemaObject, JsonSchemaRootObject, ObjectWithId, StringMap } from '@naturalcycles/js-lib';
2
+ import type { ReadableTyped } from '@naturalcycles/nodejs-lib';
3
+ import type { CommonDB, CommonDBSupport, CommonDBTransactionOptions, DBOperation, DBTransactionFn } from '../..';
4
+ import { CommonDBType } from '../..';
5
+ import type { CommonDBCreateOptions, CommonDBOptions, CommonDBSaveOptions, DBTransaction, RunQueryResult } from '../../db.model';
6
+ import type { DBQuery } from '../../query/dbQuery';
6
7
  export interface InMemoryDBCfg {
7
8
  /**
8
9
  * @default ''
@@ -6,14 +6,12 @@ const js_lib_1 = require("@naturalcycles/js-lib");
6
6
  const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
7
7
  const __1 = require("../..");
8
8
  class InMemoryDB {
9
+ dbType = __1.CommonDBType.document;
10
+ support = {
11
+ ...__1.commonDBFullSupport,
12
+ timeMachine: false,
13
+ };
9
14
  constructor(cfg) {
10
- this.dbType = __1.CommonDBType.document;
11
- this.support = {
12
- ...__1.commonDBFullSupport,
13
- timeMachine: false,
14
- };
15
- // data[table][id] > {id: 'a', created: ... }
16
- this.data = {};
17
15
  this.cfg = {
18
16
  // defaults
19
17
  tablesPrefix: '',
@@ -25,6 +23,9 @@ class InMemoryDB {
25
23
  ...cfg,
26
24
  };
27
25
  }
26
+ cfg;
27
+ // data[table][id] > {id: 'a', created: ... }
28
+ data = {};
28
29
  /**
29
30
  * Returns internal "Data snapshot".
30
31
  * Deterministic - jsonSorted.
@@ -202,13 +203,15 @@ class InMemoryDB {
202
203
  }
203
204
  exports.InMemoryDB = InMemoryDB;
204
205
  class InMemoryDBTransaction {
206
+ db;
207
+ opt;
205
208
  constructor(db, opt) {
206
209
  this.db = db;
207
210
  this.opt = opt;
208
- this.ops = [];
209
- // used to enforce forbidReadAfterWrite setting
210
- this.writeOperationHappened = false;
211
211
  }
212
+ ops = [];
213
+ // used to enforce forbidReadAfterWrite setting
214
+ writeOperationHappened = false;
212
215
  async getByIds(table, ids, opt) {
213
216
  if (this.db.cfg.forbidTransactionReadAfterWrite) {
214
217
  (0, js_lib_1._assert)(!this.writeOperationHappened, `InMemoryDBTransaction: read operation attempted after write operation`);
@@ -1,7 +1,7 @@
1
- import { StringMap } from '@naturalcycles/js-lib';
2
- import { ReadableTyped } from '@naturalcycles/nodejs-lib';
3
- import { CommonDBCreateOptions } from '../../db.model';
4
- import { CommonKeyValueDB, IncrementTuple, KeyValueDBTuple } from '../../kv/commonKeyValueDB';
1
+ import type { StringMap } from '@naturalcycles/js-lib';
2
+ import type { ReadableTyped } from '@naturalcycles/nodejs-lib';
3
+ import type { CommonDBCreateOptions } from '../../db.model';
4
+ import type { CommonKeyValueDB, IncrementTuple, KeyValueDBTuple } from '../../kv/commonKeyValueDB';
5
5
  export interface InMemoryKeyValueDBCfg {
6
6
  }
7
7
  export declare class InMemoryKeyValueDB implements CommonKeyValueDB {
@@ -4,14 +4,15 @@ exports.InMemoryKeyValueDB = void 0;
4
4
  const node_stream_1 = require("node:stream");
5
5
  const commonKeyValueDB_1 = require("../../kv/commonKeyValueDB");
6
6
  class InMemoryKeyValueDB {
7
+ cfg;
7
8
  constructor(cfg = {}) {
8
9
  this.cfg = cfg;
9
- this.support = {
10
- ...commonKeyValueDB_1.commonKeyValueDBFullSupport,
11
- };
12
- // data[table][id] => any (can be Buffer, or number)
13
- this.data = {};
14
10
  }
11
+ support = {
12
+ ...commonKeyValueDB_1.commonKeyValueDBFullSupport,
13
+ };
14
+ // data[table][id] => any (can be Buffer, or number)
15
+ data = {};
15
16
  async ping() { }
16
17
  async createTable(_table, _opt) { }
17
18
  async deleteByIds(table, ids) {
@@ -1,3 +1,3 @@
1
- import { ObjectWithId } from '@naturalcycles/js-lib';
2
- import { DBQuery } from '../../query/dbQuery';
1
+ import type { ObjectWithId } from '@naturalcycles/js-lib';
2
+ import type { DBQuery } from '../../query/dbQuery';
3
3
  export declare function queryInMemory<ROW extends ObjectWithId>(q: DBQuery<ROW>, rows?: ROW[]): ROW[];
@@ -1,8 +1,9 @@
1
- import { JsonSchemaObject, JsonSchemaRootObject, ObjectWithId, StringMap } from '@naturalcycles/js-lib';
2
- import { ReadableTyped } from '@naturalcycles/nodejs-lib';
3
- import { CommonDB, CommonDBSupport, CommonDBType } from './common.db';
4
- import { CommonDBOptions, CommonDBSaveOptions, CommonDBTransactionOptions, DBTransactionFn, RunQueryResult } from './db.model';
5
- import { DBQuery } from './query/dbQuery';
1
+ import type { JsonSchemaObject, JsonSchemaRootObject, ObjectWithId, StringMap } from '@naturalcycles/js-lib';
2
+ import type { ReadableTyped } from '@naturalcycles/nodejs-lib';
3
+ import type { CommonDB, CommonDBSupport } from './common.db';
4
+ import { CommonDBType } from './common.db';
5
+ import type { CommonDBOptions, CommonDBSaveOptions, CommonDBTransactionOptions, DBTransactionFn, RunQueryResult } from './db.model';
6
+ import type { DBQuery } from './query/dbQuery';
6
7
  /**
7
8
  * No-op implementation of CommonDB interface.
8
9
  * To be extended by actual implementations.
@@ -8,10 +8,8 @@ const dbTransaction_util_1 = require("./transaction/dbTransaction.util");
8
8
  * To be extended by actual implementations.
9
9
  */
10
10
  class BaseCommonDB {
11
- constructor() {
12
- this.dbType = common_db_1.CommonDBType.document;
13
- this.support = {};
14
- }
11
+ dbType = common_db_1.CommonDBType.document;
12
+ support = {};
15
13
  async ping() {
16
14
  throw new Error('ping is not implemented');
17
15
  }
@@ -1,7 +1,7 @@
1
- import { JsonSchemaObject, JsonSchemaRootObject, ObjectWithId, StringMap } from '@naturalcycles/js-lib';
1
+ import type { JsonSchemaObject, JsonSchemaRootObject, ObjectWithId, StringMap } from '@naturalcycles/js-lib';
2
2
  import type { ReadableTyped } from '@naturalcycles/nodejs-lib';
3
- import { CommonDBCreateOptions, CommonDBOptions, CommonDBReadOptions, CommonDBSaveOptions, CommonDBStreamOptions, CommonDBTransactionOptions, DBTransactionFn, RunQueryResult } from './db.model';
4
- import { DBQuery } from './query/dbQuery';
3
+ import type { CommonDBCreateOptions, CommonDBOptions, CommonDBReadOptions, CommonDBSaveOptions, CommonDBStreamOptions, CommonDBTransactionOptions, DBTransactionFn, RunQueryResult } from './db.model';
4
+ import type { DBQuery } from './query/dbQuery';
5
5
  export declare enum CommonDBType {
6
6
  'document' = "document",
7
7
  'relational' = "relational"
@@ -1,9 +1,12 @@
1
- import { Transform } from 'node:stream';
2
- import { AsyncMapper, BaseDBEntity, CommonLogger, JsonSchemaObject, JsonSchemaRootObject, StringMap, UnixTimestampMillis, Unsaved, ZodSchema } from '@naturalcycles/js-lib';
3
- import { AjvSchema, ObjectSchema, ReadableTyped } from '@naturalcycles/nodejs-lib';
4
- import { CommonDBTransactionOptions, DBTransaction, RunQueryResult } from '../db.model';
5
- import { DBQuery, RunnableDBQuery } from '../query/dbQuery';
6
- import { CommonDaoCfg, CommonDaoCreateOptions, CommonDaoOptions, CommonDaoPatchByIdOptions, CommonDaoPatchOptions, CommonDaoReadOptions, CommonDaoSaveBatchOptions, CommonDaoSaveOptions, CommonDaoStreamDeleteOptions, CommonDaoStreamForEachOptions, CommonDaoStreamOptions, CommonDaoStreamSaveOptions } from './common.dao.model';
1
+ import type { Transform } from 'node:stream';
2
+ import type { AsyncMapper, BaseDBEntity, CommonLogger, JsonSchemaObject, JsonSchemaRootObject, StringMap, UnixTimestampMillis, Unsaved } from '@naturalcycles/js-lib';
3
+ import { ZodSchema } from '@naturalcycles/js-lib/dist/zod/index.js';
4
+ import type { ObjectSchema, ReadableTyped } from '@naturalcycles/nodejs-lib';
5
+ import { AjvSchema } from '@naturalcycles/nodejs-lib';
6
+ import type { CommonDBTransactionOptions, DBTransaction, RunQueryResult } from '../db.model';
7
+ import type { DBQuery } from '../query/dbQuery';
8
+ import { RunnableDBQuery } from '../query/dbQuery';
9
+ import type { CommonDaoCfg, CommonDaoCreateOptions, CommonDaoOptions, CommonDaoPatchByIdOptions, CommonDaoPatchOptions, CommonDaoReadOptions, CommonDaoSaveBatchOptions, CommonDaoSaveOptions, CommonDaoStreamDeleteOptions, CommonDaoStreamForEachOptions, CommonDaoStreamOptions, CommonDaoStreamSaveOptions } from './common.dao.model';
7
10
  /**
8
11
  * Lowest common denominator API between supported Databases.
9
12
  *
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CommonDaoTransaction = exports.CommonDao = void 0;
4
4
  const js_lib_1 = require("@naturalcycles/js-lib");
5
+ const index_js_1 = require("@naturalcycles/js-lib/dist/zod/index.js");
5
6
  const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
6
7
  const cnst_1 = require("../cnst");
7
8
  const dbQuery_1 = require("../query/dbQuery");
@@ -16,6 +17,7 @@ const isCI = !!process.env['CI'];
16
17
  * TM = Transport model (optimized to be sent over the wire)
17
18
  */
18
19
  class CommonDao {
20
+ cfg;
19
21
  constructor(cfg) {
20
22
  this.cfg = cfg;
21
23
  this.cfg = {
@@ -958,9 +960,9 @@ class CommonDao {
958
960
  const objectName = table;
959
961
  let error;
960
962
  let convertedValue;
961
- if (schema instanceof js_lib_1.ZodSchema) {
963
+ if (schema instanceof index_js_1.ZodSchema) {
962
964
  // Zod schema
963
- const vr = (0, js_lib_1.zSafeValidate)(obj, schema);
965
+ const vr = (0, index_js_1.zSafeValidate)(obj, schema);
964
966
  error = vr.error;
965
967
  convertedValue = vr.data;
966
968
  }
@@ -1092,6 +1094,8 @@ exports.CommonDao = CommonDao;
1092
1094
  * Has similar API than CommonDao, but all operations are performed in the context of the transaction.
1093
1095
  */
1094
1096
  class CommonDaoTransaction {
1097
+ tx;
1098
+ logger;
1095
1099
  constructor(tx, logger) {
1096
1100
  this.tx = tx;
1097
1101
  this.logger = logger;
@@ -1,7 +1,8 @@
1
- import { BaseDBEntity, CommonLogger, ErrorMode, NumberOfMilliseconds, Promisable, UnixTimestamp, ZodError, ZodSchema } from '@naturalcycles/js-lib';
2
- import { AjvSchema, AjvValidationError, JoiValidationError, ObjectSchema, TransformLogProgressOptions, TransformMapOptions } from '@naturalcycles/nodejs-lib';
3
- import { CommonDB } from '../common.db';
4
- import { CommonDBCreateOptions, CommonDBOptions, CommonDBSaveOptions } from '../db.model';
1
+ import type { BaseDBEntity, CommonLogger, ErrorMode, NumberOfMilliseconds, Promisable, UnixTimestamp } from '@naturalcycles/js-lib';
2
+ import type { ZodError, ZodSchema } from '@naturalcycles/js-lib/dist/zod/index.js';
3
+ import type { AjvSchema, AjvValidationError, JoiValidationError, ObjectSchema, TransformLogProgressOptions, TransformMapOptions } from '@naturalcycles/nodejs-lib';
4
+ import type { CommonDB } from '../common.db';
5
+ import type { CommonDBCreateOptions, CommonDBOptions, CommonDBSaveOptions } from '../db.model';
5
6
  export interface CommonDaoHooks<BM extends BaseDBEntity, DBM extends BaseDBEntity, ID = BM['id']> {
6
7
  /**
7
8
  * Allows to override the id generation function.
@@ -1,5 +1,5 @@
1
- import { ObjectWithId, UnixTimestamp } from '@naturalcycles/js-lib';
2
- import { CommonDB } from './common.db';
1
+ import type { ObjectWithId, UnixTimestamp } from '@naturalcycles/js-lib';
2
+ import type { CommonDB } from './common.db';
3
3
  /**
4
4
  * Similar to SQL INSERT, UPDATE.
5
5
  * Insert will fail if row already exists.
@@ -1,6 +1,6 @@
1
- import { Integer, UnixTimestamp } from '@naturalcycles/js-lib';
2
- import { ReadableTyped } from '@naturalcycles/nodejs-lib';
3
- import { CommonDBCreateOptions } from '../db.model';
1
+ import type { Integer, UnixTimestamp } from '@naturalcycles/js-lib';
2
+ import type { ReadableTyped } from '@naturalcycles/nodejs-lib';
3
+ import type { CommonDBCreateOptions } from '../db.model';
4
4
  /**
5
5
  * Common interface for Key-Value database implementations.
6
6
  *
@@ -1,8 +1,8 @@
1
- import { CommonLogger, KeyValueTuple } from '@naturalcycles/js-lib';
2
- import { ReadableTyped } from '@naturalcycles/nodejs-lib';
3
- import { CommonDaoLogLevel } from '../commondao/common.dao.model';
4
- import { CommonDBCreateOptions } from '../db.model';
5
- import { CommonKeyValueDB, CommonKeyValueDBSaveBatchOptions, IncrementTuple, KeyValueDBTuple } from './commonKeyValueDB';
1
+ import type { CommonLogger, KeyValueTuple } from '@naturalcycles/js-lib';
2
+ import type { ReadableTyped } from '@naturalcycles/nodejs-lib';
3
+ import type { CommonDaoLogLevel } from '../commondao/common.dao.model';
4
+ import type { CommonDBCreateOptions } from '../db.model';
5
+ import type { CommonKeyValueDB, CommonKeyValueDBSaveBatchOptions, IncrementTuple, KeyValueDBTuple } from './commonKeyValueDB';
6
6
  export interface CommonKeyValueDaoCfg<V> {
7
7
  db: CommonKeyValueDB;
8
8
  table: string;
@@ -16,6 +16,7 @@ class CommonKeyValueDao {
16
16
  ...cfg,
17
17
  };
18
18
  }
19
+ cfg;
19
20
  async ping() {
20
21
  await this.cfg.db.ping();
21
22
  }
@@ -1,5 +1,6 @@
1
- import { AsyncMemoCache, MISS, NumberOfSeconds } from '@naturalcycles/js-lib';
2
- import { CommonKeyValueDao } from './commonKeyValueDao';
1
+ import type { AsyncMemoCache, NumberOfSeconds } from '@naturalcycles/js-lib';
2
+ import { MISS } from '@naturalcycles/js-lib';
3
+ import type { CommonKeyValueDao } from './commonKeyValueDao';
3
4
  export interface CommonKeyValueDaoMemoCacheCfg<VALUE> {
4
5
  dao: CommonKeyValueDao<string, VALUE>;
5
6
  /**
@@ -11,6 +11,7 @@ const js_lib_1 = require("@naturalcycles/js-lib");
11
11
  * clear the whole table/cache.
12
12
  */
13
13
  class CommonKeyValueDaoMemoCache {
14
+ cfg;
14
15
  constructor(cfg) {
15
16
  this.cfg = cfg;
16
17
  }
@@ -1,4 +1,4 @@
1
- import { CreatedUpdated, CreatedUpdatedId } from '@naturalcycles/js-lib';
1
+ import type { CreatedUpdated, CreatedUpdatedId } from '@naturalcycles/js-lib';
2
2
  export declare function createdUpdatedFields(existingObject?: Partial<CreatedUpdated> | null): CreatedUpdated;
3
3
  export declare function createdUpdatedIdFields(existingObject?: Partial<CreatedUpdatedId> | null): CreatedUpdatedId;
4
4
  export declare function deserializeJsonField<T = any>(f?: string): T;
@@ -1,6 +1,8 @@
1
- import { AsyncMapper, ErrorMode, StringMap, UnixTimestamp } from '@naturalcycles/js-lib';
2
- import { NDJsonStats, TransformLogProgressOptions, TransformMapOptions } from '@naturalcycles/nodejs-lib';
3
- import { CommonDB } from '../common.db';
1
+ import type { AsyncMapper, StringMap, UnixTimestamp } from '@naturalcycles/js-lib';
2
+ import { ErrorMode } from '@naturalcycles/js-lib';
3
+ import type { TransformLogProgressOptions, TransformMapOptions } from '@naturalcycles/nodejs-lib';
4
+ import { NDJsonStats } from '@naturalcycles/nodejs-lib';
5
+ import type { CommonDB } from '../common.db';
4
6
  import { DBQuery } from '../index';
5
7
  export interface DBPipelineBackupOptions extends TransformLogProgressOptions {
6
8
  /**
@@ -1,7 +1,9 @@
1
- import { AsyncMapper, ErrorMode, UnixTimestamp } from '@naturalcycles/js-lib';
2
- import { NDJsonStats, TransformLogProgressOptions, TransformMapOptions } from '@naturalcycles/nodejs-lib';
3
- import { CommonDB } from '../common.db';
4
- import { CommonDBSaveOptions } from '../db.model';
1
+ import type { AsyncMapper, UnixTimestamp } from '@naturalcycles/js-lib';
2
+ import { ErrorMode } from '@naturalcycles/js-lib';
3
+ import type { TransformLogProgressOptions, TransformMapOptions } from '@naturalcycles/nodejs-lib';
4
+ import { NDJsonStats } from '@naturalcycles/nodejs-lib';
5
+ import type { CommonDB } from '../common.db';
6
+ import type { CommonDBSaveOptions } from '../db.model';
5
7
  export interface DBPipelineCopyOptions extends TransformLogProgressOptions {
6
8
  dbInput: CommonDB;
7
9
  dbOutput: CommonDB;
@@ -1,7 +1,9 @@
1
- import { AsyncMapper, ErrorMode, UnixTimestamp } from '@naturalcycles/js-lib';
2
- import { NDJsonStats, TransformLogProgressOptions, TransformMapOptions } from '@naturalcycles/nodejs-lib';
3
- import { CommonDB } from '../common.db';
4
- import { CommonDBSaveOptions } from '../index';
1
+ import type { AsyncMapper, UnixTimestamp } from '@naturalcycles/js-lib';
2
+ import { ErrorMode } from '@naturalcycles/js-lib';
3
+ import type { TransformLogProgressOptions, TransformMapOptions } from '@naturalcycles/nodejs-lib';
4
+ import { NDJsonStats } from '@naturalcycles/nodejs-lib';
5
+ import type { CommonDB } from '../common.db';
6
+ import type { CommonDBSaveOptions } from '../index';
5
7
  export interface DBPipelineRestoreOptions extends TransformLogProgressOptions {
6
8
  /**
7
9
  * DB to save data to.
@@ -1,8 +1,8 @@
1
- import { AsyncMapper, BaseDBEntity, ObjectWithId } from '@naturalcycles/js-lib';
2
- import { ReadableTyped } from '@naturalcycles/nodejs-lib';
3
- import { CommonDaoOptions, CommonDaoReadOptions, CommonDaoStreamDeleteOptions, CommonDaoStreamForEachOptions, CommonDaoStreamOptions } from '..';
4
- import { CommonDao } from '../commondao/common.dao';
5
- import { RunQueryResult } from '../db.model';
1
+ import type { AsyncMapper, BaseDBEntity, ObjectWithId } from '@naturalcycles/js-lib';
2
+ import type { ReadableTyped } from '@naturalcycles/nodejs-lib';
3
+ import type { CommonDaoOptions, CommonDaoReadOptions, CommonDaoStreamDeleteOptions, CommonDaoStreamForEachOptions, CommonDaoStreamOptions } from '..';
4
+ import type { CommonDao } from '../commondao/common.dao';
5
+ import type { RunQueryResult } from '../db.model';
6
6
  /**
7
7
  * Modeled after Firestore operators (WhereFilterOp type)
8
8
  *
@@ -25,13 +25,9 @@ exports.dbQueryFilterOperatorValues = [
25
25
  * <DBM> is the type of **queried** object (so e.g `key of DBM` can be used), not **returned** object.
26
26
  */
27
27
  class DBQuery {
28
+ table;
28
29
  constructor(table) {
29
30
  this.table = table;
30
- this._filters = [];
31
- this._limitValue = 0; // 0 means "no limit"
32
- this._offsetValue = 0; // 0 means "no offset"
33
- this._orders = [];
34
- this._distinct = false;
35
31
  }
36
32
  /**
37
33
  * Convenience method.
@@ -42,6 +38,19 @@ class DBQuery {
42
38
  static fromPlainObject(obj) {
43
39
  return Object.assign(new DBQuery(obj.table), obj);
44
40
  }
41
+ _filters = [];
42
+ _limitValue = 0; // 0 means "no limit"
43
+ _offsetValue = 0; // 0 means "no offset"
44
+ _orders = [];
45
+ _startCursor;
46
+ _endCursor;
47
+ /**
48
+ * If defined - only those fields will be selected.
49
+ * In undefined - all fields (*) will be returned.
50
+ */
51
+ _selectedFieldNames;
52
+ _groupByFieldNames;
53
+ _distinct = false;
45
54
  filter(name, op, val) {
46
55
  this._filters.push({ name, op, val });
47
56
  return this;
@@ -140,6 +149,7 @@ exports.DBQuery = DBQuery;
140
149
  * DBQuery that has additional method to support Fluent API style.
141
150
  */
142
151
  class RunnableDBQuery extends DBQuery {
152
+ dao;
143
153
  /**
144
154
  * Pass `table` to override table.
145
155
  */
@@ -1,3 +1,3 @@
1
- import { CommonDB } from '../common.db';
2
- import { CommonDBImplementationQuirks } from './dbTest';
3
- export declare function runCommonDaoTest(db: CommonDB, quirks?: CommonDBImplementationQuirks): void;
1
+ import type { CommonDB } from '../common.db';
2
+ import type { CommonDBImplementationQuirks } from './dbTest';
3
+ export declare function runCommonDaoTest(db: CommonDB, quirks?: CommonDBImplementationQuirks): Promise<void>;