@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.
- package/dist/adapter/cachedb/cache.db.d.ts +6 -6
- package/dist/adapter/cachedb/cache.db.js +6 -5
- package/dist/adapter/cachedb/cache.db.model.d.ts +3 -3
- package/dist/adapter/cachedb/index.d.ts +1 -1
- package/dist/adapter/file/file.db.d.ts +8 -7
- package/dist/adapter/file/file.db.js +11 -10
- package/dist/adapter/file/file.db.model.d.ts +2 -2
- package/dist/adapter/file/inMemory.persistence.plugin.d.ts +3 -3
- package/dist/adapter/file/inMemory.persistence.plugin.js +1 -3
- package/dist/adapter/file/index.d.ts +1 -1
- package/dist/adapter/file/localFile.persistence.plugin.d.ts +3 -3
- package/dist/adapter/file/localFile.persistence.plugin.js +1 -0
- package/dist/adapter/file/noop.persistence.plugin.d.ts +3 -3
- package/dist/adapter/inmemory/inMemory.db.d.ts +6 -5
- package/dist/adapter/inmemory/inMemory.db.js +13 -10
- package/dist/adapter/inmemory/inMemoryKeyValueDB.d.ts +4 -4
- package/dist/adapter/inmemory/inMemoryKeyValueDB.js +6 -5
- package/dist/adapter/inmemory/queryInMemory.d.ts +2 -2
- package/dist/base.common.db.d.ts +6 -5
- package/dist/base.common.db.js +2 -4
- package/dist/common.db.d.ts +3 -3
- package/dist/commondao/common.dao.d.ts +9 -6
- package/dist/commondao/common.dao.js +6 -2
- package/dist/commondao/common.dao.model.d.ts +5 -4
- package/dist/db.model.d.ts +2 -2
- package/dist/kv/commonKeyValueDB.d.ts +3 -3
- package/dist/kv/commonKeyValueDao.d.ts +5 -5
- package/dist/kv/commonKeyValueDao.js +1 -0
- package/dist/kv/commonKeyValueDaoMemoCache.d.ts +3 -2
- package/dist/kv/commonKeyValueDaoMemoCache.js +1 -0
- package/dist/model.util.d.ts +1 -1
- package/dist/pipeline/dbPipelineBackup.d.ts +5 -3
- package/dist/pipeline/dbPipelineCopy.d.ts +6 -4
- package/dist/pipeline/dbPipelineRestore.d.ts +6 -4
- package/dist/query/dbQuery.d.ts +5 -5
- package/dist/query/dbQuery.js +15 -5
- package/dist/testing/daoTest.d.ts +3 -3
- package/dist/testing/daoTest.js +89 -74
- package/dist/testing/dbTest.d.ts +2 -3
- package/dist/testing/dbTest.js +68 -68
- package/dist/testing/index.d.ts +4 -2
- package/dist/testing/keyValueDBTest.d.ts +2 -2
- package/dist/testing/keyValueDBTest.js +37 -37
- package/dist/testing/keyValueDaoTest.d.ts +2 -2
- package/dist/testing/keyValueDaoTest.js +33 -33
- package/dist/testing/test.model.d.ts +1 -1
- package/dist/testing/timeSeriesTest.util.d.ts +1 -1
- package/dist/timeseries/commonTimeSeriesDao.d.ts +1 -1
- package/dist/timeseries/commonTimeSeriesDao.js +1 -0
- package/dist/timeseries/timeSeries.model.d.ts +1 -1
- package/dist/transaction/dbTransaction.util.d.ts +2 -2
- package/dist/transaction/dbTransaction.util.js +1 -0
- package/dist/validation/index.d.ts +2 -2
- package/package.json +3 -2
- package/src/adapter/cachedb/cache.db.model.ts +3 -3
- package/src/adapter/cachedb/cache.db.ts +8 -7
- package/src/adapter/cachedb/index.ts +1 -1
- package/src/adapter/file/file.db.model.ts +2 -2
- package/src/adapter/file/file.db.ts +9 -15
- package/src/adapter/file/inMemory.persistence.plugin.ts +4 -3
- package/src/adapter/file/index.ts +1 -1
- 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 +14 -20
- package/src/adapter/inmemory/inMemoryKeyValueDB.ts +5 -9
- package/src/adapter/inmemory/queryInMemory.ts +3 -2
- package/src/base.common.db.ts +6 -5
- package/src/common.db.ts +3 -3
- package/src/commondao/common.dao.model.ts +5 -6
- package/src/commondao/common.dao.ts +25 -21
- package/src/db.model.ts +2 -2
- package/src/kv/commonKeyValueDB.ts +3 -3
- package/src/kv/commonKeyValueDao.ts +7 -5
- package/src/kv/commonKeyValueDaoMemoCache.ts +3 -8
- package/src/model.util.ts +2 -1
- package/src/pipeline/dbPipelineBackup.ts +4 -13
- package/src/pipeline/dbPipelineCopy.ts +5 -13
- package/src/pipeline/dbPipelineRestore.ts +9 -8
- package/src/query/dbQuery.ts +6 -11
- package/src/testing/daoTest.ts +28 -6
- package/src/testing/dbTest.ts +24 -22
- package/src/testing/index.ts +3 -4
- package/src/testing/keyValueDBTest.ts +6 -4
- package/src/testing/keyValueDaoTest.ts +4 -3
- package/src/testing/test.model.ts +2 -7
- package/src/testing/timeSeriesTest.util.ts +1 -1
- package/src/timeseries/commonTimeSeriesDao.ts +3 -2
- package/src/timeseries/timeSeries.model.ts +1 -1
- package/src/transaction/dbTransaction.util.ts +2 -2
- package/src/validation/index.ts +3 -8
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import type { CommonLogger, KeyValueTuple } from '@naturalcycles/js-lib'
|
|
2
|
+
import { AppError, pMap } from '@naturalcycles/js-lib'
|
|
3
|
+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
4
|
+
import { deflateString, inflateToString } from '@naturalcycles/nodejs-lib'
|
|
5
|
+
import type { CommonDaoLogLevel } from '../commondao/common.dao.model'
|
|
6
|
+
import type { CommonDBCreateOptions } from '../db.model'
|
|
7
|
+
import type {
|
|
6
8
|
CommonKeyValueDB,
|
|
7
9
|
CommonKeyValueDBSaveBatchOptions,
|
|
8
10
|
IncrementTuple,
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
MISS,
|
|
5
|
-
NumberOfSeconds,
|
|
6
|
-
UnixTimestamp,
|
|
7
|
-
} from '@naturalcycles/js-lib'
|
|
8
|
-
import { CommonKeyValueDao } from './commonKeyValueDao'
|
|
1
|
+
import type { AsyncMemoCache, NumberOfSeconds, UnixTimestamp } from '@naturalcycles/js-lib'
|
|
2
|
+
import { localTime, MISS } from '@naturalcycles/js-lib'
|
|
3
|
+
import type { CommonKeyValueDao } from './commonKeyValueDao'
|
|
9
4
|
|
|
10
5
|
export interface CommonKeyValueDaoMemoCacheCfg<VALUE> {
|
|
11
6
|
dao: CommonKeyValueDao<string, VALUE>
|
package/src/model.util.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { CreatedUpdated, CreatedUpdatedId
|
|
1
|
+
import type { CreatedUpdated, CreatedUpdatedId } from '@naturalcycles/js-lib'
|
|
2
|
+
import { localTime } from '@naturalcycles/js-lib'
|
|
2
3
|
import { stringId } from '@naturalcycles/nodejs-lib'
|
|
3
4
|
|
|
4
5
|
export function createdUpdatedFields(
|
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
AsyncMapper,
|
|
5
|
-
ErrorMode,
|
|
6
|
-
localTime,
|
|
7
|
-
pMap,
|
|
8
|
-
StringMap,
|
|
9
|
-
UnixTimestamp,
|
|
10
|
-
} from '@naturalcycles/js-lib'
|
|
1
|
+
import type { AsyncMapper, StringMap, UnixTimestamp } from '@naturalcycles/js-lib'
|
|
2
|
+
import { _passthroughMapper, AppError, ErrorMode, localTime, pMap } from '@naturalcycles/js-lib'
|
|
3
|
+
import type { TransformLogProgressOptions, TransformMapOptions } from '@naturalcycles/nodejs-lib'
|
|
11
4
|
import {
|
|
12
5
|
_pipeline,
|
|
13
6
|
boldWhite,
|
|
@@ -16,13 +9,11 @@ import {
|
|
|
16
9
|
grey,
|
|
17
10
|
NDJsonStats,
|
|
18
11
|
transformLogProgress,
|
|
19
|
-
TransformLogProgressOptions,
|
|
20
12
|
transformMap,
|
|
21
|
-
TransformMapOptions,
|
|
22
13
|
transformTap,
|
|
23
14
|
yellow,
|
|
24
15
|
} from '@naturalcycles/nodejs-lib'
|
|
25
|
-
import { CommonDB } from '../common.db'
|
|
16
|
+
import type { CommonDB } from '../common.db'
|
|
26
17
|
import { DBQuery } from '../index'
|
|
27
18
|
|
|
28
19
|
export interface DBPipelineBackupOptions extends TransformLogProgressOptions {
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
BaseDBEntity,
|
|
5
|
-
ErrorMode,
|
|
6
|
-
localTime,
|
|
7
|
-
pMap,
|
|
8
|
-
UnixTimestamp,
|
|
9
|
-
} from '@naturalcycles/js-lib'
|
|
1
|
+
import type { AsyncMapper, BaseDBEntity, UnixTimestamp } from '@naturalcycles/js-lib'
|
|
2
|
+
import { _passthroughMapper, ErrorMode, localTime, pMap } from '@naturalcycles/js-lib'
|
|
3
|
+
import type { TransformLogProgressOptions, TransformMapOptions } from '@naturalcycles/nodejs-lib'
|
|
10
4
|
import {
|
|
11
5
|
_pipeline,
|
|
12
6
|
boldWhite,
|
|
@@ -15,15 +9,13 @@ import {
|
|
|
15
9
|
NDJsonStats,
|
|
16
10
|
transformChunk,
|
|
17
11
|
transformLogProgress,
|
|
18
|
-
TransformLogProgressOptions,
|
|
19
12
|
transformMap,
|
|
20
|
-
TransformMapOptions,
|
|
21
13
|
transformTap,
|
|
22
14
|
writableForEach,
|
|
23
15
|
yellow,
|
|
24
16
|
} from '@naturalcycles/nodejs-lib'
|
|
25
|
-
import { CommonDB } from '../common.db'
|
|
26
|
-
import { CommonDBSaveOptions } from '../db.model'
|
|
17
|
+
import type { CommonDB } from '../common.db'
|
|
18
|
+
import type { CommonDBSaveOptions } from '../db.model'
|
|
27
19
|
import { DBQuery } from '../query/dbQuery'
|
|
28
20
|
|
|
29
21
|
export interface DBPipelineCopyOptions extends TransformLogProgressOptions {
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AsyncMapper,
|
|
3
|
+
BaseDBEntity,
|
|
4
|
+
JsonSchemaObject,
|
|
5
|
+
UnixTimestamp,
|
|
6
|
+
} from '@naturalcycles/js-lib'
|
|
1
7
|
import {
|
|
2
8
|
_hb,
|
|
3
9
|
_mapValues,
|
|
4
10
|
_passthroughMapper,
|
|
5
|
-
AsyncMapper,
|
|
6
|
-
BaseDBEntity,
|
|
7
11
|
ErrorMode,
|
|
8
|
-
JsonSchemaObject,
|
|
9
12
|
localTime,
|
|
10
13
|
pMap,
|
|
11
|
-
UnixTimestamp,
|
|
12
14
|
} from '@naturalcycles/js-lib'
|
|
15
|
+
import type { TransformLogProgressOptions, TransformMapOptions } from '@naturalcycles/nodejs-lib'
|
|
13
16
|
import {
|
|
14
17
|
_pipeline,
|
|
15
18
|
boldWhite,
|
|
@@ -20,15 +23,13 @@ import {
|
|
|
20
23
|
transformChunk,
|
|
21
24
|
transformFilterSync,
|
|
22
25
|
transformLogProgress,
|
|
23
|
-
TransformLogProgressOptions,
|
|
24
26
|
transformMap,
|
|
25
|
-
TransformMapOptions,
|
|
26
27
|
transformTap,
|
|
27
28
|
writableForEach,
|
|
28
29
|
yellow,
|
|
29
30
|
} from '@naturalcycles/nodejs-lib'
|
|
30
|
-
import { CommonDB } from '../common.db'
|
|
31
|
-
import { CommonDBSaveOptions } from '../index'
|
|
31
|
+
import type { CommonDB } from '../common.db'
|
|
32
|
+
import type { CommonDBSaveOptions } from '../index'
|
|
32
33
|
|
|
33
34
|
export interface DBPipelineRestoreOptions extends TransformLogProgressOptions {
|
|
34
35
|
/**
|
package/src/query/dbQuery.ts
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
BaseDBEntity,
|
|
6
|
-
ObjectWithId,
|
|
7
|
-
} from '@naturalcycles/js-lib'
|
|
8
|
-
import { ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
9
|
-
import {
|
|
1
|
+
import type { AsyncMapper, BaseDBEntity, ObjectWithId } from '@naturalcycles/js-lib'
|
|
2
|
+
import { _objectAssign, _truncate } from '@naturalcycles/js-lib'
|
|
3
|
+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
4
|
+
import type {
|
|
10
5
|
CommonDaoOptions,
|
|
11
6
|
CommonDaoReadOptions,
|
|
12
7
|
CommonDaoStreamDeleteOptions,
|
|
13
8
|
CommonDaoStreamForEachOptions,
|
|
14
9
|
CommonDaoStreamOptions,
|
|
15
10
|
} from '..'
|
|
16
|
-
import { CommonDao } from '../commondao/common.dao'
|
|
17
|
-
import { RunQueryResult } from '../db.model'
|
|
11
|
+
import type { CommonDao } from '../commondao/common.dao'
|
|
12
|
+
import type { RunQueryResult } from '../db.model'
|
|
18
13
|
|
|
19
14
|
/**
|
|
20
15
|
* Modeled after Firestore operators (WhereFilterOp type)
|
package/src/testing/daoTest.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { Readable } from 'node:stream'
|
|
2
|
-
import { _deepCopy, _omit, _pick, _sortBy, localTime } from '@naturalcycles/js-lib'
|
|
2
|
+
import { _deepCopy, _filterObject, _omit, _pick, _sortBy, localTime } from '@naturalcycles/js-lib'
|
|
3
3
|
import { _pipeline } from '@naturalcycles/nodejs-lib'
|
|
4
|
-
import { expect, test } from 'vitest'
|
|
5
4
|
import { CommonDaoLogLevel, DBQuery } from '..'
|
|
6
|
-
import { CommonDB } from '../common.db'
|
|
5
|
+
import type { CommonDB } from '../common.db'
|
|
7
6
|
import { CommonDao } from '../commondao/common.dao'
|
|
8
|
-
import { TestItemBM } from '.'
|
|
9
|
-
import { CommonDBImplementationQuirks
|
|
7
|
+
import type { TestItemBM } from '.'
|
|
8
|
+
import type { CommonDBImplementationQuirks } from './dbTest'
|
|
10
9
|
import {
|
|
11
10
|
createTestItemBM,
|
|
12
11
|
createTestItemsBM,
|
|
@@ -15,7 +14,13 @@ import {
|
|
|
15
14
|
testItemBMSchema,
|
|
16
15
|
} from './test.model'
|
|
17
16
|
|
|
18
|
-
export function runCommonDaoTest(
|
|
17
|
+
export async function runCommonDaoTest(
|
|
18
|
+
db: CommonDB,
|
|
19
|
+
quirks: CommonDBImplementationQuirks = {},
|
|
20
|
+
): Promise<void> {
|
|
21
|
+
// this is because vitest cannot be "required" from cjs
|
|
22
|
+
const { test, expect } = await import('vitest')
|
|
23
|
+
|
|
19
24
|
const { support } = db
|
|
20
25
|
const dao = new CommonDao({
|
|
21
26
|
table: TEST_TABLE,
|
|
@@ -359,4 +364,21 @@ export function runCommonDaoTest(db: CommonDB, quirks: CommonDBImplementationQui
|
|
|
359
364
|
})
|
|
360
365
|
}
|
|
361
366
|
}
|
|
367
|
+
|
|
368
|
+
function expectMatch(expected: any[], actual: any[], quirks: CommonDBImplementationQuirks): void {
|
|
369
|
+
// const expectedSorted = sortObjectDeep(expected)
|
|
370
|
+
// const actualSorted = sortObjectDeep(actual)
|
|
371
|
+
|
|
372
|
+
if (quirks.allowBooleansAsUndefined) {
|
|
373
|
+
expected = expected.map(r => {
|
|
374
|
+
return typeof r !== 'object' ? r : _filterObject(r, (_k, v) => v !== false)
|
|
375
|
+
})
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
if (quirks.allowExtraPropertiesInResponse) {
|
|
379
|
+
expect(actual).toMatchObject(expected)
|
|
380
|
+
} else {
|
|
381
|
+
expect(actual).toEqual(expected)
|
|
382
|
+
}
|
|
383
|
+
}
|
|
362
384
|
}
|
package/src/testing/dbTest.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { _deepFreeze, _filterObject, _pick, _sortBy, localTime, pMap } from '@naturalcycles/js-lib'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import type { CommonDB } from '../common.db'
|
|
3
|
+
import { CommonDBType } from '../common.db'
|
|
4
4
|
import { DBQuery } from '../query/dbQuery'
|
|
5
|
+
import type { TestItemDBM } from './test.model'
|
|
5
6
|
import {
|
|
6
7
|
createTestItemDBM,
|
|
7
8
|
createTestItemsDBM,
|
|
8
9
|
TEST_TABLE,
|
|
9
10
|
testItemBMJsonSchema,
|
|
10
|
-
TestItemDBM,
|
|
11
11
|
} from './test.model'
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -25,7 +25,13 @@ export interface CommonDBImplementationQuirks {
|
|
|
25
25
|
allowBooleansAsUndefined?: boolean
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export function runCommonDBTest(
|
|
28
|
+
export async function runCommonDBTest(
|
|
29
|
+
db: CommonDB,
|
|
30
|
+
quirks: CommonDBImplementationQuirks = {},
|
|
31
|
+
): Promise<void> {
|
|
32
|
+
// this is because vitest cannot be "required" from cjs
|
|
33
|
+
const { test, expect } = await import('vitest')
|
|
34
|
+
|
|
29
35
|
const { support } = db
|
|
30
36
|
const items = createTestItemsDBM(3)
|
|
31
37
|
_deepFreeze(items)
|
|
@@ -380,25 +386,21 @@ export function runCommonDBTest(db: CommonDB, quirks: CommonDBImplementationQuir
|
|
|
380
386
|
await db.deleteByQuery(queryAll())
|
|
381
387
|
})
|
|
382
388
|
}
|
|
383
|
-
}
|
|
384
389
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
quirks: CommonDBImplementationQuirks,
|
|
389
|
-
): void {
|
|
390
|
-
// const expectedSorted = sortObjectDeep(expected)
|
|
391
|
-
// const actualSorted = sortObjectDeep(actual)
|
|
392
|
-
|
|
393
|
-
if (quirks.allowBooleansAsUndefined) {
|
|
394
|
-
expected = expected.map(r => {
|
|
395
|
-
return typeof r !== 'object' ? r : _filterObject(r, (_k, v) => v !== false)
|
|
396
|
-
})
|
|
397
|
-
}
|
|
390
|
+
function expectMatch(expected: any[], actual: any[], quirks: CommonDBImplementationQuirks): void {
|
|
391
|
+
// const expectedSorted = sortObjectDeep(expected)
|
|
392
|
+
// const actualSorted = sortObjectDeep(actual)
|
|
398
393
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
394
|
+
if (quirks.allowBooleansAsUndefined) {
|
|
395
|
+
expected = expected.map(r => {
|
|
396
|
+
return typeof r !== 'object' ? r : _filterObject(r, (_k, v) => v !== false)
|
|
397
|
+
})
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
if (quirks.allowExtraPropertiesInResponse) {
|
|
401
|
+
expect(actual).toMatchObject(expected)
|
|
402
|
+
} else {
|
|
403
|
+
expect(actual).toEqual(expected)
|
|
404
|
+
}
|
|
403
405
|
}
|
|
404
406
|
}
|
package/src/testing/index.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { runCommonDaoTest } from './daoTest'
|
|
2
|
-
import { CommonDBImplementationQuirks
|
|
2
|
+
import type { CommonDBImplementationQuirks } from './dbTest'
|
|
3
|
+
import { runCommonDBTest } from './dbTest'
|
|
3
4
|
import { runCommonKeyValueDaoTest } from './keyValueDaoTest'
|
|
4
5
|
import { runCommonKeyValueDBTest } from './keyValueDBTest'
|
|
6
|
+
import type { TestItemBM, TestItemDBM, TestItemTM } from './test.model'
|
|
5
7
|
import {
|
|
6
8
|
createTestItemBM,
|
|
7
9
|
createTestItemDBM,
|
|
8
10
|
createTestItemsBM,
|
|
9
11
|
createTestItemsDBM,
|
|
10
12
|
TEST_TABLE,
|
|
11
|
-
TestItemBM,
|
|
12
13
|
testItemBMJsonSchema,
|
|
13
14
|
testItemBMSchema,
|
|
14
|
-
TestItemDBM,
|
|
15
|
-
TestItemTM,
|
|
16
15
|
testItemTMSchema,
|
|
17
16
|
} from './test.model'
|
|
18
17
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { CommonKeyValueDB } from '../kv/commonKeyValueDB'
|
|
1
|
+
import type { KeyValueTuple } from '@naturalcycles/js-lib'
|
|
2
|
+
import { _range, _sortBy } from '@naturalcycles/js-lib'
|
|
3
|
+
import type { CommonKeyValueDB } from '../kv/commonKeyValueDB'
|
|
4
4
|
import { TEST_TABLE } from './test.model'
|
|
5
5
|
|
|
6
6
|
const testIds = _range(1, 4).map(n => `id${n}`)
|
|
@@ -10,7 +10,9 @@ const testEntries: KeyValueTuple<string, Buffer>[] = testIds.map(id => [
|
|
|
10
10
|
Buffer.from(`${id}value`),
|
|
11
11
|
])
|
|
12
12
|
|
|
13
|
-
export function runCommonKeyValueDBTest(db: CommonKeyValueDB): void {
|
|
13
|
+
export async function runCommonKeyValueDBTest(db: CommonKeyValueDB): Promise<void> {
|
|
14
|
+
const { afterAll, beforeAll, expect, test } = await import('vitest')
|
|
15
|
+
|
|
14
16
|
beforeAll(async () => {
|
|
15
17
|
// Tests in this suite are not isolated,
|
|
16
18
|
// and failing tests can leave the DB in an unexpected state for other tests,
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { _sortBy } from '@naturalcycles/js-lib'
|
|
2
|
-
import { afterAll, beforeAll, expect, test } from 'vitest'
|
|
3
2
|
import { CommonKeyValueDao } from '../kv/commonKeyValueDao'
|
|
4
|
-
import { CommonKeyValueDB, KeyValueDBTuple } from '../kv/commonKeyValueDB'
|
|
3
|
+
import type { CommonKeyValueDB, KeyValueDBTuple } from '../kv/commonKeyValueDB'
|
|
5
4
|
import { createTestItemsBM, TEST_TABLE } from './test.model'
|
|
6
5
|
|
|
7
6
|
const testItems = createTestItemsBM(4)
|
|
8
7
|
const testIds = testItems.map(e => e.id)
|
|
9
8
|
const testEntries: KeyValueDBTuple[] = testItems.map(e => [e.id, Buffer.from(`${e.id}value`)])
|
|
10
9
|
|
|
11
|
-
export function runCommonKeyValueDaoTest(db: CommonKeyValueDB): void {
|
|
10
|
+
export async function runCommonKeyValueDaoTest(db: CommonKeyValueDB): Promise<void> {
|
|
11
|
+
const { afterAll, beforeAll, expect, test } = await import('vitest')
|
|
12
|
+
|
|
12
13
|
const dao = new CommonKeyValueDao({
|
|
13
14
|
db,
|
|
14
15
|
table: TEST_TABLE,
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
BaseDBEntity,
|
|
4
|
-
jsonSchema,
|
|
5
|
-
JsonSchemaObject,
|
|
6
|
-
UnixTimestamp,
|
|
7
|
-
} from '@naturalcycles/js-lib'
|
|
1
|
+
import type { BaseDBEntity, JsonSchemaObject, UnixTimestamp } from '@naturalcycles/js-lib'
|
|
2
|
+
import { _range, jsonSchema } from '@naturalcycles/js-lib'
|
|
8
3
|
import {
|
|
9
4
|
baseDBEntitySchema,
|
|
10
5
|
binarySchema,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { _randomInt, _range } from '@naturalcycles/js-lib'
|
|
2
|
-
import { TimeSeriesDataPoint } from '../timeseries/timeSeries.model'
|
|
2
|
+
import type { TimeSeriesDataPoint } from '../timeseries/timeSeries.model'
|
|
3
3
|
|
|
4
4
|
export function createTestTimeSeries(count = 10): TimeSeriesDataPoint[] {
|
|
5
5
|
const ts = Date.now()
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ObjectWithId } from '@naturalcycles/js-lib'
|
|
2
|
+
import { _isTruthy } from '@naturalcycles/js-lib'
|
|
2
3
|
import { DBQuery } from '../query/dbQuery'
|
|
3
|
-
import {
|
|
4
|
+
import type {
|
|
4
5
|
CommonTimeSeriesDaoCfg,
|
|
5
6
|
TimeSeriesDataPoint,
|
|
6
7
|
TimeSeriesQuery,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ObjectWithId } from '@naturalcycles/js-lib'
|
|
1
|
+
import type { ObjectWithId } from '@naturalcycles/js-lib'
|
|
2
2
|
import type { CommonDB } from '../common.db'
|
|
3
|
-
import { CommonDBOptions, CommonDBSaveOptions, DBTransaction } from '../db.model'
|
|
3
|
+
import type { CommonDBOptions, CommonDBSaveOptions, DBTransaction } from '../db.model'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Optimizes the Transaction (list of DBOperations) to do less operations.
|
package/src/validation/index.ts
CHANGED
|
@@ -7,14 +7,9 @@ import {
|
|
|
7
7
|
objectSchema,
|
|
8
8
|
stringSchema,
|
|
9
9
|
} from '@naturalcycles/nodejs-lib'
|
|
10
|
-
import { CommonDBOptions, CommonDBSaveOptions } from '../db.model'
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
DBQueryFilter,
|
|
14
|
-
DBQueryFilterOperator,
|
|
15
|
-
dbQueryFilterOperatorValues,
|
|
16
|
-
DBQueryOrder,
|
|
17
|
-
} from '../query/dbQuery'
|
|
10
|
+
import type { CommonDBOptions, CommonDBSaveOptions } from '../db.model'
|
|
11
|
+
import type { DBQuery, DBQueryFilter, DBQueryFilterOperator, DBQueryOrder } from '../query/dbQuery'
|
|
12
|
+
import { dbQueryFilterOperatorValues } from '../query/dbQuery'
|
|
18
13
|
|
|
19
14
|
export const commonDBOptionsSchema = objectSchema<CommonDBOptions>({
|
|
20
15
|
['onlyCache' as any]: booleanSchema.optional(),
|