@naturalcycles/db-lib 9.2.0 → 9.3.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 (36) hide show
  1. package/dist/adapter/cachedb/cache.db.d.ts +11 -12
  2. package/dist/adapter/cachedb/cache.db.model.d.ts +2 -2
  3. package/dist/adapter/file/file.db.d.ts +12 -12
  4. package/dist/adapter/file/file.db.model.d.ts +2 -2
  5. package/dist/adapter/file/localFile.persistence.plugin.d.ts +3 -3
  6. package/dist/adapter/file/noop.persistence.plugin.d.ts +2 -2
  7. package/dist/adapter/inmemory/inMemory.db.d.ts +12 -12
  8. package/dist/adapter/inmemory/queryInMemory.d.ts +2 -2
  9. package/dist/base.common.db.d.ts +10 -10
  10. package/dist/common.db.d.ts +10 -10
  11. package/dist/commondao/common.dao.d.ts +26 -27
  12. package/dist/commondao/common.dao.js +12 -12
  13. package/dist/commondao/common.dao.model.d.ts +13 -13
  14. package/dist/db.model.d.ts +4 -4
  15. package/dist/query/dbQuery.d.ts +9 -9
  16. package/dist/testing/test.model.d.ts +3 -4
  17. package/dist/testing/test.model.js +1 -1
  18. package/dist/transaction/dbTransaction.util.d.ts +3 -3
  19. package/dist/validation/index.d.ts +2 -2
  20. package/package.json +1 -1
  21. package/src/adapter/cachedb/cache.db.model.ts +2 -2
  22. package/src/adapter/cachedb/cache.db.ts +18 -16
  23. package/src/adapter/file/file.db.model.ts +2 -2
  24. package/src/adapter/file/file.db.ts +17 -15
  25. package/src/adapter/file/localFile.persistence.plugin.ts +4 -4
  26. package/src/adapter/file/noop.persistence.plugin.ts +2 -2
  27. package/src/adapter/inmemory/inMemory.db.ts +20 -18
  28. package/src/adapter/inmemory/queryInMemory.ts +5 -2
  29. package/src/base.common.db.ts +20 -10
  30. package/src/common.db.ts +20 -13
  31. package/src/commondao/common.dao.model.ts +21 -15
  32. package/src/commondao/common.dao.ts +80 -69
  33. package/src/db.model.ts +4 -4
  34. package/src/query/dbQuery.ts +13 -11
  35. package/src/testing/test.model.ts +4 -6
  36. package/src/transaction/dbTransaction.util.ts +3 -3
package/src/db.model.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ObjectWithId } from '@naturalcycles/js-lib'
1
+ import type { PartialObjectWithId } from '@naturalcycles/js-lib'
2
2
  import { CommonDB } from './common.db'
3
3
 
4
4
  /**
@@ -55,7 +55,7 @@ export interface CommonDBOptions {
55
55
  /**
56
56
  * All properties default to undefined.
57
57
  */
58
- export interface CommonDBSaveOptions<ROW extends Partial<ObjectWithId> = any>
58
+ export interface CommonDBSaveOptions<ROW extends PartialObjectWithId = any>
59
59
  extends CommonDBOptions {
60
60
  excludeFromIndexes?: (keyof ROW)[]
61
61
 
@@ -91,7 +91,7 @@ export interface RunQueryResult<T> {
91
91
 
92
92
  export type DBOperation = DBSaveBatchOperation | DBDeleteByIdsOperation
93
93
 
94
- export interface DBSaveBatchOperation<ROW extends Partial<ObjectWithId> = any> {
94
+ export interface DBSaveBatchOperation<ROW extends PartialObjectWithId = any> {
95
95
  type: 'saveBatch'
96
96
  table: string
97
97
  rows: ROW[]
@@ -131,6 +131,6 @@ export class DBIncrement {
131
131
  }
132
132
  }
133
133
 
134
- export type DBPatch<ROW extends Partial<ObjectWithId>> = Partial<
134
+ export type DBPatch<ROW extends PartialObjectWithId> = Partial<
135
135
  Record<keyof ROW, ROW[keyof ROW] | DBIncrement>
136
136
  >
@@ -1,11 +1,11 @@
1
1
  import {
2
- AnyObjectWithId,
3
- ObjectWithId,
4
2
  AsyncMapper,
5
3
  _truncate,
6
4
  Saved,
7
5
  AnyObject,
8
6
  _objectAssign,
7
+ PartialObjectWithId,
8
+ AnyPartialObjectWithId,
9
9
  } from '@naturalcycles/js-lib'
10
10
  import { ReadableTyped } from '@naturalcycles/nodejs-lib'
11
11
  import {
@@ -62,13 +62,13 @@ export const dbQueryFilterOperatorValues: DBQueryFilterOperator[] = [
62
62
  'array-contains-any',
63
63
  ]
64
64
 
65
- export interface DBQueryFilter<ROW extends ObjectWithId = AnyObjectWithId> {
65
+ export interface DBQueryFilter<ROW extends PartialObjectWithId = AnyPartialObjectWithId> {
66
66
  name: keyof ROW
67
67
  op: DBQueryFilterOperator
68
68
  val: any
69
69
  }
70
70
 
71
- export interface DBQueryOrder<ROW extends ObjectWithId = AnyObjectWithId> {
71
+ export interface DBQueryOrder<ROW extends PartialObjectWithId = AnyPartialObjectWithId> {
72
72
  name: keyof ROW
73
73
  descending?: boolean
74
74
  }
@@ -83,17 +83,19 @@ export interface DBQueryOrder<ROW extends ObjectWithId = AnyObjectWithId> {
83
83
  *
84
84
  * <DBM> is the type of **queried** object (so e.g `key of DBM` can be used), not **returned** object.
85
85
  */
86
- export class DBQuery<ROW extends ObjectWithId = AnyObjectWithId> {
86
+ export class DBQuery<ROW extends PartialObjectWithId = AnyPartialObjectWithId> {
87
87
  constructor(public table: string) {}
88
88
 
89
89
  /**
90
90
  * Convenience method.
91
91
  */
92
- static create<ROW extends ObjectWithId = AnyObjectWithId>(table: string): DBQuery<ROW> {
92
+ static create<ROW extends PartialObjectWithId = AnyPartialObjectWithId>(
93
+ table: string,
94
+ ): DBQuery<ROW> {
93
95
  return new DBQuery(table)
94
96
  }
95
97
 
96
- static fromPlainObject<ROW extends ObjectWithId = AnyObjectWithId>(
98
+ static fromPlainObject<ROW extends PartialObjectWithId = AnyPartialObjectWithId>(
97
99
  obj: Partial<DBQuery<ROW>> & { table: string },
98
100
  ): DBQuery<ROW> {
99
101
  return Object.assign(new DBQuery<ROW>(obj.table), obj)
@@ -237,8 +239,8 @@ export class DBQuery<ROW extends ObjectWithId = AnyObjectWithId> {
237
239
  * DBQuery that has additional method to support Fluent API style.
238
240
  */
239
241
  export class RunnableDBQuery<
240
- BM extends Partial<ObjectWithId>,
241
- DBM extends ObjectWithId = Saved<BM>,
242
+ BM extends PartialObjectWithId,
243
+ DBM extends PartialObjectWithId = BM,
242
244
  TM extends AnyObject = BM,
243
245
  > extends DBQuery<DBM> {
244
246
  /**
@@ -259,7 +261,7 @@ export class RunnableDBQuery<
259
261
  return await this.dao.runQuerySingleColumn<T>(this, opt)
260
262
  }
261
263
 
262
- async runQueryAsDBM(opt?: CommonDaoOptions): Promise<DBM[]> {
264
+ async runQueryAsDBM(opt?: CommonDaoOptions): Promise<Saved<DBM>[]> {
263
265
  return await this.dao.runQueryAsDBM(this, opt)
264
266
  }
265
267
 
@@ -271,7 +273,7 @@ export class RunnableDBQuery<
271
273
  return await this.dao.runQueryExtended(this, opt)
272
274
  }
273
275
 
274
- async runQueryExtendedAsDBM(opt?: CommonDaoOptions): Promise<RunQueryResult<DBM>> {
276
+ async runQueryExtendedAsDBM(opt?: CommonDaoOptions): Promise<RunQueryResult<Saved<DBM>>> {
275
277
  return await this.dao.runQueryExtendedAsDBM(this, opt)
276
278
  }
277
279
 
@@ -5,7 +5,6 @@ import {
5
5
  booleanSchema,
6
6
  numberSchema,
7
7
  objectSchema,
8
- savedDBEntitySchema,
9
8
  stringSchema,
10
9
  } from '@naturalcycles/nodejs-lib'
11
10
 
@@ -14,7 +13,6 @@ const MOCK_TS_2018_06_21 = 1529539200
14
13
  export const TEST_TABLE = 'TEST_TABLE'
15
14
 
16
15
  export interface TestItemBM extends BaseDBEntity {
17
- id: string
18
16
  k1: string
19
17
  k2?: string | null
20
18
  k3?: number
@@ -22,7 +20,7 @@ export interface TestItemBM extends BaseDBEntity {
22
20
  b1?: Buffer
23
21
  }
24
22
 
25
- export interface TestItemDBM extends Saved<TestItemBM> {}
23
+ export interface TestItemDBM extends TestItemBM {}
26
24
 
27
25
  export interface TestItemTM {
28
26
  k1: string
@@ -43,7 +41,7 @@ export const testItemDBMSchema = objectSchema<TestItemDBM>({
43
41
  k3: numberSchema.optional(),
44
42
  even: booleanSchema.optional(),
45
43
  b1: binarySchema.optional(),
46
- }).concat(savedDBEntitySchema as any)
44
+ }).concat(baseDBEntitySchema as any)
47
45
 
48
46
  export const testItemTMSchema = objectSchema<TestItemTM>({
49
47
  k1: stringSchema,
@@ -76,7 +74,7 @@ export const testItemDBMJsonSchema: JsonSchemaObject<TestItemDBM> = jsonSchema
76
74
  })
77
75
  .build()
78
76
 
79
- export function createTestItemDBM(num = 1): TestItemDBM {
77
+ export function createTestItemDBM(num = 1): Saved<TestItemDBM> {
80
78
  return {
81
79
  id: `id${num}`,
82
80
  k1: `v${num}`,
@@ -92,7 +90,7 @@ export function createTestItemBM(num = 1): Saved<TestItemBM> {
92
90
  return createTestItemDBM(num)
93
91
  }
94
92
 
95
- export function createTestItemsDBM(count = 1): TestItemDBM[] {
93
+ export function createTestItemsDBM(count = 1): Saved<TestItemDBM>[] {
96
94
  return _range(1, count + 1).map(num => createTestItemDBM(num))
97
95
  }
98
96
 
@@ -1,4 +1,4 @@
1
- import { ObjectWithId } from '@naturalcycles/js-lib'
1
+ import { PartialObjectWithId } from '@naturalcycles/js-lib'
2
2
  import type { CommonDB } from '../common.db'
3
3
  import { CommonDBOptions, CommonDBSaveOptions, DBTransaction } from '../db.model'
4
4
 
@@ -100,7 +100,7 @@ export class FakeDBTransaction implements DBTransaction {
100
100
  // no-op
101
101
  async rollback(): Promise<void> {}
102
102
 
103
- async getByIds<ROW extends ObjectWithId>(
103
+ async getByIds<ROW extends PartialObjectWithId>(
104
104
  table: string,
105
105
  ids: string[],
106
106
  opt?: CommonDBOptions,
@@ -113,7 +113,7 @@ export class FakeDBTransaction implements DBTransaction {
113
113
  // ): Promise<RunQueryResult<ROW>> {
114
114
  // return await this.db.runQuery(q, opt)
115
115
  // }
116
- async saveBatch<ROW extends Partial<ObjectWithId>>(
116
+ async saveBatch<ROW extends PartialObjectWithId>(
117
117
  table: string,
118
118
  rows: ROW[],
119
119
  opt?: CommonDBSaveOptions<ROW>,