@naturalcycles/db-lib 10.3.0 → 10.4.1
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 +1 -1
- package/dist/adapter/file/file.db.d.ts +1 -1
- package/dist/adapter/file/file.db.js +2 -1
- package/dist/adapter/file/localFile.persistence.plugin.js +2 -1
- package/dist/adapter/inmemory/inMemory.db.d.ts +1 -1
- package/dist/adapter/inmemory/inMemory.db.js +3 -1
- package/dist/adapter/inmemory/inMemoryKeyValueDB.d.ts +1 -1
- package/dist/base.common.db.d.ts +1 -1
- package/dist/common.db.d.ts +1 -1
- package/dist/commondao/common.dao.d.ts +5 -4
- package/dist/commondao/common.dao.js +6 -3
- package/dist/commondao/common.dao.model.d.ts +6 -4
- package/dist/kv/commonKeyValueDB.d.ts +1 -1
- package/dist/kv/commonKeyValueDao.d.ts +1 -1
- package/dist/pipeline/dbPipelineBackup.d.ts +2 -2
- package/dist/pipeline/dbPipelineBackup.js +3 -1
- package/dist/pipeline/dbPipelineCopy.d.ts +2 -2
- package/dist/pipeline/dbPipelineCopy.js +2 -1
- package/dist/pipeline/dbPipelineRestore.d.ts +2 -2
- package/dist/pipeline/dbPipelineRestore.js +3 -1
- package/dist/query/dbQuery.d.ts +1 -1
- package/dist/testing/commonDaoTest.js +1 -1
- package/dist/testing/test.model.d.ts +1 -1
- package/dist/testing/test.model.js +1 -1
- package/dist/validation/index.d.ts +1 -1
- package/dist/validation/index.js +1 -1
- package/package.json +3 -3
- package/src/adapter/cachedb/cache.db.ts +1 -1
- package/src/adapter/file/file.db.ts +3 -2
- package/src/adapter/file/localFile.persistence.plugin.ts +2 -1
- package/src/adapter/inmemory/inMemory.db.ts +3 -2
- package/src/adapter/inmemory/inMemoryKeyValueDB.ts +1 -1
- package/src/base.common.db.ts +1 -1
- package/src/common.db.ts +1 -1
- package/src/commondao/common.dao.model.ts +8 -8
- package/src/commondao/common.dao.ts +13 -14
- package/src/kv/commonKeyValueDB.ts +1 -1
- package/src/kv/commonKeyValueDao.ts +1 -1
- package/src/pipeline/dbPipelineBackup.ts +7 -7
- package/src/pipeline/dbPipelineCopy.ts +6 -6
- package/src/pipeline/dbPipelineRestore.ts +7 -7
- package/src/query/dbQuery.ts +1 -1
- package/src/testing/commonDaoTest.ts +1 -1
- package/src/testing/test.model.ts +1 -1
- package/src/validation/index.ts +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { JsonSchemaObject, JsonSchemaRootObject, ObjectWithId } from '@naturalcycles/js-lib';
|
|
2
|
-
import type { ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
2
|
+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream';
|
|
3
3
|
import { BaseCommonDB } from '../../base.common.db.js';
|
|
4
4
|
import type { CommonDB, CommonDBSupport } from '../../common.db.js';
|
|
5
5
|
import type { RunQueryResult } from '../../db.model.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { JsonSchemaRootObject, ObjectWithId } from '@naturalcycles/js-lib';
|
|
2
|
-
import type { ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
2
|
+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream';
|
|
3
3
|
import { BaseCommonDB } from '../../base.common.db.js';
|
|
4
4
|
import type { CommonDB, CommonDBSupport } from '../../common.db.js';
|
|
5
5
|
import type { CommonDBOptions, CommonDBSaveOptions, CommonDBStreamOptions, DBSaveBatchOperation, RunQueryResult } from '../../db.model.js';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { _assert, _by, _deepEquals, _filterUndefinedValues, _since, _sortBy, _sortObjectDeep, _stringMapValues, generateJsonSchemaFromData, localTime, } from '@naturalcycles/js-lib';
|
|
2
|
-
import { dimGrey
|
|
2
|
+
import { dimGrey } from '@naturalcycles/nodejs-lib';
|
|
3
|
+
import { readableCreate } from '@naturalcycles/nodejs-lib/stream';
|
|
3
4
|
import { BaseCommonDB } from '../../base.common.db.js';
|
|
4
5
|
import { commonDBFullSupport } from '../../common.db.js';
|
|
5
6
|
import { queryInMemory } from '../inmemory/queryInMemory.js';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Readable } from 'node:stream';
|
|
2
2
|
import { pMap } from '@naturalcycles/js-lib';
|
|
3
|
-
import {
|
|
3
|
+
import { fs2 } from '@naturalcycles/nodejs-lib/fs';
|
|
4
|
+
import { _pipeline } from '@naturalcycles/nodejs-lib/stream';
|
|
4
5
|
/**
|
|
5
6
|
* Persists in local filesystem as ndjson.
|
|
6
7
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AnyObjectWithId, CommonLogger, JsonSchemaObject, JsonSchemaRootObject, ObjectWithId, StringMap } from '@naturalcycles/js-lib';
|
|
2
|
-
import type
|
|
2
|
+
import { type ReadableTyped } from '@naturalcycles/nodejs-lib/stream';
|
|
3
3
|
import type { CommonDB, CommonDBSupport } from '../../common.db.js';
|
|
4
4
|
import { CommonDBType } from '../../common.db.js';
|
|
5
5
|
import type { CommonDBCreateOptions, CommonDBOptions, CommonDBSaveOptions, CommonDBTransactionOptions, DBOperation, DBTransaction, DBTransactionFn, RunQueryResult } from '../../db.model.js';
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Readable } from 'node:stream';
|
|
2
2
|
import { _assert, _by, _deepCopy, _isEmptyObject, _since, _sortObjectDeep, _stringMapEntries, _stringMapValues, generateJsonSchemaFromData, localTime, pMap, } from '@naturalcycles/js-lib';
|
|
3
|
-
import {
|
|
3
|
+
import { dimGrey, yellow } from '@naturalcycles/nodejs-lib';
|
|
4
|
+
import { fs2 } from '@naturalcycles/nodejs-lib/fs';
|
|
5
|
+
import { _pipeline, bufferReviver } from '@naturalcycles/nodejs-lib/stream';
|
|
4
6
|
import { commonDBFullSupport, CommonDBType } from '../../common.db.js';
|
|
5
7
|
import { queryInMemory } from './queryInMemory.js';
|
|
6
8
|
export class InMemoryDB {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { StringMap } from '@naturalcycles/js-lib';
|
|
2
|
-
import type { ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
2
|
+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream';
|
|
3
3
|
import type { CommonDBCreateOptions } from '../../db.model.js';
|
|
4
4
|
import type { CommonKeyValueDB, IncrementTuple, KeyValueDBTuple } from '../../kv/commonKeyValueDB.js';
|
|
5
5
|
export interface InMemoryKeyValueDBCfg {
|
package/dist/base.common.db.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { JsonSchemaObject, JsonSchemaRootObject, ObjectWithId, StringMap } from '@naturalcycles/js-lib';
|
|
2
|
-
import type { ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
2
|
+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream';
|
|
3
3
|
import type { CommonDB, CommonDBSupport } from './common.db.js';
|
|
4
4
|
import { CommonDBType } from './common.db.js';
|
|
5
5
|
import type { CommonDBOptions, CommonDBSaveOptions, CommonDBTransactionOptions, DBTransaction, DBTransactionFn, RunQueryResult } from './db.model.js';
|
package/dist/common.db.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { JsonSchemaObject, JsonSchemaRootObject, ObjectWithId, StringMap } from '@naturalcycles/js-lib';
|
|
2
|
-
import type { ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
2
|
+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream';
|
|
3
3
|
import type { CommonDBCreateOptions, CommonDBOptions, CommonDBReadOptions, CommonDBSaveOptions, CommonDBStreamOptions, CommonDBTransactionOptions, DBTransaction, DBTransactionFn, RunQueryResult } from './db.model.js';
|
|
4
4
|
import type { DBQuery } from './query/dbQuery.js';
|
|
5
5
|
export declare enum CommonDBType {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { Transform } from 'node:stream';
|
|
2
2
|
import type { AsyncMapper, BaseDBEntity, CommonLogger, JsonSchemaObject, JsonSchemaRootObject, StringMap, UnixTimestampMillis, Unsaved } from '@naturalcycles/js-lib';
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
3
|
+
import { ZodType } from '@naturalcycles/js-lib/zod';
|
|
4
|
+
import { AjvSchema } from '@naturalcycles/nodejs-lib/ajv';
|
|
5
|
+
import { type ObjectSchema } from '@naturalcycles/nodejs-lib/joi';
|
|
6
|
+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream';
|
|
6
7
|
import type { CommonDBTransactionOptions, DBTransaction, RunQueryResult } from '../db.model.js';
|
|
7
8
|
import type { DBQuery } from '../query/dbQuery.js';
|
|
8
9
|
import { RunnableDBQuery } from '../query/dbQuery.js';
|
|
@@ -160,7 +161,7 @@ export declare class CommonDao<BM extends BaseDBEntity, DBM extends BaseDBEntity
|
|
|
160
161
|
* Does NOT mutate the object.
|
|
161
162
|
* Validates (unless `skipValidation=true` passed).
|
|
162
163
|
*/
|
|
163
|
-
validateAndConvert<T>(obj: Partial<T>, schema: ObjectSchema<T> | AjvSchema<T> |
|
|
164
|
+
validateAndConvert<T>(obj: Partial<T>, schema: ObjectSchema<T> | AjvSchema<T> | ZodType<T> | undefined, op?: 'load' | 'save', // this is to skip validation if validateOnLoad/Save is false
|
|
164
165
|
opt?: CommonDaoOptions): any;
|
|
165
166
|
getTableSchema(): Promise<JsonSchemaRootObject<DBM>>;
|
|
166
167
|
createTable(schema: JsonSchemaObject<DBM>, opt?: CommonDaoCreateOptions): Promise<void>;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { _assert, _deepCopy, _deepJsonEquals, _filterUndefinedValues, _isTruthy, _objectAssignExact, _passthroughPredicate, _since, _truncate, _typeCast, _uniqBy, AppError, ErrorMode, localTime, pMap, SKIP, } from '@naturalcycles/js-lib';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { ZodType, zSafeValidate } from '@naturalcycles/js-lib/zod';
|
|
3
|
+
import { stringId } from '@naturalcycles/nodejs-lib';
|
|
4
|
+
import { AjvSchema } from '@naturalcycles/nodejs-lib/ajv';
|
|
5
|
+
import { getValidationResult, } from '@naturalcycles/nodejs-lib/joi';
|
|
6
|
+
import { _pipeline, transformChunk, transformLogProgress, transformMap, transformNoOp, writableVoid, } from '@naturalcycles/nodejs-lib/stream';
|
|
4
7
|
import { DBLibError } from '../cnst.js';
|
|
5
8
|
import { RunnableDBQuery } from '../query/dbQuery.js';
|
|
6
9
|
import { CommonDaoLogLevel } from './common.dao.model.js';
|
|
@@ -953,7 +956,7 @@ export class CommonDao {
|
|
|
953
956
|
const objectName = table;
|
|
954
957
|
let error;
|
|
955
958
|
let convertedValue;
|
|
956
|
-
if (schema instanceof
|
|
959
|
+
if (schema instanceof ZodType) {
|
|
957
960
|
// Zod schema
|
|
958
961
|
const vr = zSafeValidate(obj, schema);
|
|
959
962
|
error = vr.error;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { BaseDBEntity, CommonLogger, ErrorMode, NumberOfMilliseconds, Promisable, UnixTimestamp } from '@naturalcycles/js-lib';
|
|
2
|
-
import type {
|
|
3
|
-
import type { AjvSchema, AjvValidationError
|
|
2
|
+
import type { ZodType, ZodValidationError } from '@naturalcycles/js-lib/zod';
|
|
3
|
+
import type { AjvSchema, AjvValidationError } from '@naturalcycles/nodejs-lib/ajv';
|
|
4
|
+
import type { JoiValidationError, ObjectSchema } from '@naturalcycles/nodejs-lib/joi';
|
|
5
|
+
import type { TransformLogProgressOptions, TransformMapOptions } from '@naturalcycles/nodejs-lib/stream';
|
|
4
6
|
import type { CommonDB } from '../common.db.js';
|
|
5
7
|
import type { CommonDBCreateOptions, CommonDBOptions, CommonDBSaveOptions } from '../db.model.js';
|
|
6
8
|
export interface CommonDaoHooks<BM extends BaseDBEntity, DBM extends BaseDBEntity, ID = BM['id']> {
|
|
@@ -74,7 +76,7 @@ export interface CommonDaoHooks<BM extends BaseDBEntity, DBM extends BaseDBEntit
|
|
|
74
76
|
* Return original `err` to pass the error through (will be thrown in CommonDao).
|
|
75
77
|
* Return modified/new `Error` if needed.
|
|
76
78
|
*/
|
|
77
|
-
onValidationError: (err: JoiValidationError | AjvValidationError |
|
|
79
|
+
onValidationError: (err: JoiValidationError | AjvValidationError | ZodValidationError) => Error | false;
|
|
78
80
|
}
|
|
79
81
|
export declare enum CommonDaoLogLevel {
|
|
80
82
|
/**
|
|
@@ -100,7 +102,7 @@ export interface CommonDaoCfg<BM extends BaseDBEntity, DBM extends BaseDBEntity
|
|
|
100
102
|
/**
|
|
101
103
|
* Joi, AjvSchema or ZodSchema is supported.
|
|
102
104
|
*/
|
|
103
|
-
bmSchema?: ObjectSchema<BM> | AjvSchema<BM> |
|
|
105
|
+
bmSchema?: ObjectSchema<BM> | AjvSchema<BM> | ZodType<BM>;
|
|
104
106
|
excludeFromIndexes?: (keyof DBM)[];
|
|
105
107
|
/**
|
|
106
108
|
* Defaults to true.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Integer, UnixTimestamp } from '@naturalcycles/js-lib';
|
|
2
|
-
import type { ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
2
|
+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream';
|
|
3
3
|
import type { CommonDBCreateOptions } from '../db.model.js';
|
|
4
4
|
/**
|
|
5
5
|
* Common interface for Key-Value database implementations.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CommonLogger, KeyValueTuple } from '@naturalcycles/js-lib';
|
|
2
|
-
import type { ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
2
|
+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream';
|
|
3
3
|
import type { CommonDaoLogLevel } from '../commondao/common.dao.model.js';
|
|
4
4
|
import type { CommonDBCreateOptions } from '../db.model.js';
|
|
5
5
|
import type { CommonKeyValueDB, CommonKeyValueDBSaveBatchOptions, IncrementTuple, KeyValueDBTuple } from './commonKeyValueDB.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AsyncMapper, StringMap, UnixTimestamp } from '@naturalcycles/js-lib';
|
|
2
2
|
import { ErrorMode } from '@naturalcycles/js-lib';
|
|
3
|
-
import type { TransformLogProgressOptions, TransformMapOptions } from '@naturalcycles/nodejs-lib';
|
|
4
|
-
import { NDJsonStats } from '@naturalcycles/nodejs-lib';
|
|
3
|
+
import type { TransformLogProgressOptions, TransformMapOptions } from '@naturalcycles/nodejs-lib/stream';
|
|
4
|
+
import { NDJsonStats } from '@naturalcycles/nodejs-lib/stream';
|
|
5
5
|
import type { CommonDB } from '../common.db.js';
|
|
6
6
|
import { DBQuery } from '../query/dbQuery.js';
|
|
7
7
|
export interface DBPipelineBackupOptions extends TransformLogProgressOptions {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { _passthroughMapper, AppError, ErrorMode, localTime, pMap } from '@naturalcycles/js-lib';
|
|
2
|
-
import {
|
|
2
|
+
import { boldWhite, dimWhite, grey, yellow } from '@naturalcycles/nodejs-lib';
|
|
3
|
+
import { fs2 } from '@naturalcycles/nodejs-lib/fs';
|
|
4
|
+
import { _pipeline, NDJsonStats, transformLogProgress, transformMap, transformTap, } from '@naturalcycles/nodejs-lib/stream';
|
|
3
5
|
import { DBQuery } from '../query/dbQuery.js';
|
|
4
6
|
/**
|
|
5
7
|
* Pipeline from input stream(s) to a NDJSON file (optionally gzipped).
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AsyncMapper, UnixTimestamp } from '@naturalcycles/js-lib';
|
|
2
2
|
import { ErrorMode } from '@naturalcycles/js-lib';
|
|
3
|
-
import type { TransformLogProgressOptions, TransformMapOptions } from '@naturalcycles/nodejs-lib';
|
|
4
|
-
import { NDJsonStats } from '@naturalcycles/nodejs-lib';
|
|
3
|
+
import type { TransformLogProgressOptions, TransformMapOptions } from '@naturalcycles/nodejs-lib/stream';
|
|
4
|
+
import { NDJsonStats } from '@naturalcycles/nodejs-lib/stream';
|
|
5
5
|
import type { CommonDB } from '../common.db.js';
|
|
6
6
|
import type { CommonDBSaveOptions } from '../db.model.js';
|
|
7
7
|
export interface DBPipelineCopyOptions extends TransformLogProgressOptions {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { _passthroughMapper, ErrorMode, localTime, pMap } from '@naturalcycles/js-lib';
|
|
2
|
-
import {
|
|
2
|
+
import { boldWhite, dimWhite, grey, yellow } from '@naturalcycles/nodejs-lib';
|
|
3
|
+
import { _pipeline, NDJsonStats, transformChunk, transformLogProgress, transformMap, transformTap, writableForEach, } from '@naturalcycles/nodejs-lib/stream';
|
|
3
4
|
import { DBQuery } from '../query/dbQuery.js';
|
|
4
5
|
/**
|
|
5
6
|
* Pipeline from input stream(s) to CommonDB .saveBatch().
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AsyncMapper, UnixTimestamp } from '@naturalcycles/js-lib';
|
|
2
2
|
import { ErrorMode } from '@naturalcycles/js-lib';
|
|
3
|
-
import type { TransformLogProgressOptions, TransformMapOptions } from '@naturalcycles/nodejs-lib';
|
|
4
|
-
import { NDJsonStats } from '@naturalcycles/nodejs-lib';
|
|
3
|
+
import type { TransformLogProgressOptions, TransformMapOptions } from '@naturalcycles/nodejs-lib/stream';
|
|
4
|
+
import { NDJsonStats } from '@naturalcycles/nodejs-lib/stream';
|
|
5
5
|
import type { CommonDB } from '../common.db.js';
|
|
6
6
|
import type { CommonDBSaveOptions } from '../db.model.js';
|
|
7
7
|
export interface DBPipelineRestoreOptions extends TransformLogProgressOptions {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { _hb, _mapValues, _passthroughMapper, ErrorMode, localTime, pMap, } from '@naturalcycles/js-lib';
|
|
2
|
-
import {
|
|
2
|
+
import { boldWhite, dimWhite, grey, yellow } from '@naturalcycles/nodejs-lib';
|
|
3
|
+
import { fs2 } from '@naturalcycles/nodejs-lib/fs';
|
|
4
|
+
import { _pipeline, NDJsonStats, transformChunk, transformFilterSync, transformLogProgress, transformMap, transformTap, writableForEach, } from '@naturalcycles/nodejs-lib/stream';
|
|
3
5
|
/**
|
|
4
6
|
* Pipeline from NDJSON files in a folder (optionally gzipped) to CommonDB.
|
|
5
7
|
* Allows to define a mapper and a predicate to map/filter objects between input and output.
|
package/dist/query/dbQuery.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AsyncMapper, BaseDBEntity, ObjectWithId } from '@naturalcycles/js-lib';
|
|
2
|
-
import type { ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
2
|
+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream';
|
|
3
3
|
import type { CommonDao } from '../commondao/common.dao.js';
|
|
4
4
|
import type { CommonDaoOptions, CommonDaoReadOptions, CommonDaoStreamDeleteOptions, CommonDaoStreamForEachOptions, CommonDaoStreamOptions } from '../commondao/common.dao.model.js';
|
|
5
5
|
import type { RunQueryResult } from '../db.model.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Readable } from 'node:stream';
|
|
2
2
|
import { _deepCopy, _filterObject, _omit, _pick, _sortBy, localTime } from '@naturalcycles/js-lib';
|
|
3
|
-
import { _pipeline } from '@naturalcycles/nodejs-lib';
|
|
3
|
+
import { _pipeline } from '@naturalcycles/nodejs-lib/stream';
|
|
4
4
|
import { CommonDao } from '../commondao/common.dao.js';
|
|
5
5
|
import { CommonDaoLogLevel } from '../commondao/common.dao.model.js';
|
|
6
6
|
import { DBQuery } from '../query/dbQuery.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BaseDBEntity, JsonSchemaObject } from '@naturalcycles/js-lib';
|
|
2
|
-
import { type ObjectSchema } from '@naturalcycles/nodejs-lib';
|
|
2
|
+
import { type ObjectSchema } from '@naturalcycles/nodejs-lib/joi';
|
|
3
3
|
export declare const TEST_TABLE = "TEST_TABLE";
|
|
4
4
|
export interface TestItemBM extends BaseDBEntity {
|
|
5
5
|
k1: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { _range, jsonSchema } from '@naturalcycles/js-lib';
|
|
2
|
-
import { baseDBEntitySchema, binarySchema, booleanSchema, numberSchema, objectSchema, stringSchema, } from '@naturalcycles/nodejs-lib';
|
|
2
|
+
import { baseDBEntitySchema, binarySchema, booleanSchema, numberSchema, objectSchema, stringSchema, } from '@naturalcycles/nodejs-lib/joi';
|
|
3
3
|
const MOCK_TS_2018_06_21 = 1529539200;
|
|
4
4
|
export const TEST_TABLE = 'TEST_TABLE';
|
|
5
5
|
export const testItemBMSchema = objectSchema({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ObjectSchema, type StringSchema } from '@naturalcycles/nodejs-lib';
|
|
1
|
+
import { type ObjectSchema, type StringSchema } from '@naturalcycles/nodejs-lib/joi';
|
|
2
2
|
import type { CommonDBOptions, CommonDBSaveOptions } from '../db.model.js';
|
|
3
3
|
import type { DBQuery, DBQueryFilter, DBQueryFilterOperator, DBQueryOrder } from '../query/dbQuery.js';
|
|
4
4
|
export declare const commonDBOptionsSchema: ObjectSchema<CommonDBOptions>;
|
package/dist/validation/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { anySchema, arraySchema, booleanSchema, integerSchema, Joi, objectSchema, stringSchema, } from '@naturalcycles/nodejs-lib';
|
|
1
|
+
import { anySchema, arraySchema, booleanSchema, integerSchema, Joi, objectSchema, stringSchema, } from '@naturalcycles/nodejs-lib/joi';
|
|
2
2
|
import { dbQueryFilterOperatorValues } from '../query/dbQuery.js';
|
|
3
3
|
export const commonDBOptionsSchema = objectSchema({
|
|
4
4
|
['onlyCache']: booleanSchema.optional(),
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/db-lib",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "10.
|
|
4
|
+
"version": "10.4.1",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@naturalcycles/js-lib": "^15",
|
|
7
|
-
"@naturalcycles/nodejs-lib": "^
|
|
7
|
+
"@naturalcycles/nodejs-lib": "^15"
|
|
8
8
|
},
|
|
9
9
|
"devDependencies": {
|
|
10
|
-
"@naturalcycles/dev-lib": "
|
|
10
|
+
"@naturalcycles/dev-lib": "19.4.5"
|
|
11
11
|
},
|
|
12
12
|
"files": [
|
|
13
13
|
"dist",
|
|
@@ -6,7 +6,7 @@ import type {
|
|
|
6
6
|
StringMap,
|
|
7
7
|
} from '@naturalcycles/js-lib'
|
|
8
8
|
import { _isTruthy } from '@naturalcycles/js-lib'
|
|
9
|
-
import type { ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
9
|
+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream'
|
|
10
10
|
import { BaseCommonDB } from '../../base.common.db.js'
|
|
11
11
|
import type { CommonDB, CommonDBSupport } from '../../common.db.js'
|
|
12
12
|
import { commonDBFullSupport } from '../../common.db.js'
|
|
@@ -11,8 +11,9 @@ import {
|
|
|
11
11
|
generateJsonSchemaFromData,
|
|
12
12
|
localTime,
|
|
13
13
|
} from '@naturalcycles/js-lib'
|
|
14
|
-
import
|
|
15
|
-
import {
|
|
14
|
+
import { dimGrey } from '@naturalcycles/nodejs-lib'
|
|
15
|
+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream'
|
|
16
|
+
import { readableCreate } from '@naturalcycles/nodejs-lib/stream'
|
|
16
17
|
import { BaseCommonDB } from '../../base.common.db.js'
|
|
17
18
|
import type { CommonDB, CommonDBSupport } from '../../common.db.js'
|
|
18
19
|
import { commonDBFullSupport } from '../../common.db.js'
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Readable } from 'node:stream'
|
|
2
2
|
import type { ObjectWithId } from '@naturalcycles/js-lib'
|
|
3
3
|
import { pMap } from '@naturalcycles/js-lib'
|
|
4
|
-
import {
|
|
4
|
+
import { fs2 } from '@naturalcycles/nodejs-lib/fs'
|
|
5
|
+
import { _pipeline } from '@naturalcycles/nodejs-lib/stream'
|
|
5
6
|
import type { DBSaveBatchOperation } from '../../db.model.js'
|
|
6
7
|
import type { FileDBPersistencePlugin } from './file.db.model.js'
|
|
7
8
|
|
|
@@ -20,8 +20,9 @@ import {
|
|
|
20
20
|
localTime,
|
|
21
21
|
pMap,
|
|
22
22
|
} from '@naturalcycles/js-lib'
|
|
23
|
-
import
|
|
24
|
-
import {
|
|
23
|
+
import { dimGrey, yellow } from '@naturalcycles/nodejs-lib'
|
|
24
|
+
import { fs2 } from '@naturalcycles/nodejs-lib/fs'
|
|
25
|
+
import { _pipeline, bufferReviver, type ReadableTyped } from '@naturalcycles/nodejs-lib/stream'
|
|
25
26
|
import type { CommonDB, CommonDBSupport } from '../../common.db.js'
|
|
26
27
|
import { commonDBFullSupport, CommonDBType } from '../../common.db.js'
|
|
27
28
|
import type {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Readable } from 'node:stream'
|
|
2
2
|
import type { StringMap } from '@naturalcycles/js-lib'
|
|
3
|
-
import type { ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
3
|
+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream'
|
|
4
4
|
import type { CommonDBCreateOptions } from '../../db.model.js'
|
|
5
5
|
import type {
|
|
6
6
|
CommonKeyValueDB,
|
package/src/base.common.db.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type {
|
|
|
4
4
|
ObjectWithId,
|
|
5
5
|
StringMap,
|
|
6
6
|
} from '@naturalcycles/js-lib'
|
|
7
|
-
import type { ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
7
|
+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream'
|
|
8
8
|
import type { CommonDB, CommonDBSupport } from './common.db.js'
|
|
9
9
|
import { CommonDBType } from './common.db.js'
|
|
10
10
|
import type {
|
package/src/common.db.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type {
|
|
|
4
4
|
ObjectWithId,
|
|
5
5
|
StringMap,
|
|
6
6
|
} from '@naturalcycles/js-lib'
|
|
7
|
-
import type { ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
7
|
+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream'
|
|
8
8
|
import type {
|
|
9
9
|
CommonDBCreateOptions,
|
|
10
10
|
CommonDBOptions,
|
|
@@ -6,15 +6,13 @@ import type {
|
|
|
6
6
|
Promisable,
|
|
7
7
|
UnixTimestamp,
|
|
8
8
|
} from '@naturalcycles/js-lib'
|
|
9
|
-
import type {
|
|
9
|
+
import type { ZodType, ZodValidationError } from '@naturalcycles/js-lib/zod'
|
|
10
|
+
import type { AjvSchema, AjvValidationError } from '@naturalcycles/nodejs-lib/ajv'
|
|
11
|
+
import type { JoiValidationError, ObjectSchema } from '@naturalcycles/nodejs-lib/joi'
|
|
10
12
|
import type {
|
|
11
|
-
AjvSchema,
|
|
12
|
-
AjvValidationError,
|
|
13
|
-
JoiValidationError,
|
|
14
|
-
ObjectSchema,
|
|
15
13
|
TransformLogProgressOptions,
|
|
16
14
|
TransformMapOptions,
|
|
17
|
-
} from '@naturalcycles/nodejs-lib'
|
|
15
|
+
} from '@naturalcycles/nodejs-lib/stream'
|
|
18
16
|
import type { CommonDB } from '../common.db.js'
|
|
19
17
|
import type { CommonDBCreateOptions, CommonDBOptions, CommonDBSaveOptions } from '../db.model.js'
|
|
20
18
|
|
|
@@ -97,7 +95,9 @@ export interface CommonDaoHooks<BM extends BaseDBEntity, DBM extends BaseDBEntit
|
|
|
97
95
|
* Return original `err` to pass the error through (will be thrown in CommonDao).
|
|
98
96
|
* Return modified/new `Error` if needed.
|
|
99
97
|
*/
|
|
100
|
-
onValidationError: (
|
|
98
|
+
onValidationError: (
|
|
99
|
+
err: JoiValidationError | AjvValidationError | ZodValidationError,
|
|
100
|
+
) => Error | false
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
export enum CommonDaoLogLevel {
|
|
@@ -130,7 +130,7 @@ export interface CommonDaoCfg<
|
|
|
130
130
|
/**
|
|
131
131
|
* Joi, AjvSchema or ZodSchema is supported.
|
|
132
132
|
*/
|
|
133
|
-
bmSchema?: ObjectSchema<BM> | AjvSchema<BM> |
|
|
133
|
+
bmSchema?: ObjectSchema<BM> | AjvSchema<BM> | ZodType<BM>
|
|
134
134
|
|
|
135
135
|
excludeFromIndexes?: (keyof DBM)[]
|
|
136
136
|
|
|
@@ -29,24 +29,23 @@ import {
|
|
|
29
29
|
SKIP,
|
|
30
30
|
} from '@naturalcycles/js-lib'
|
|
31
31
|
import type { ZodValidationError } from '@naturalcycles/js-lib/zod'
|
|
32
|
-
import {
|
|
33
|
-
import
|
|
34
|
-
|
|
35
|
-
JoiValidationError,
|
|
36
|
-
ObjectSchema,
|
|
37
|
-
ReadableTyped,
|
|
38
|
-
} from '@naturalcycles/nodejs-lib'
|
|
32
|
+
import { ZodType, zSafeValidate } from '@naturalcycles/js-lib/zod'
|
|
33
|
+
import { stringId } from '@naturalcycles/nodejs-lib'
|
|
34
|
+
import { AjvSchema, type AjvValidationError } from '@naturalcycles/nodejs-lib/ajv'
|
|
39
35
|
import {
|
|
40
|
-
_pipeline,
|
|
41
|
-
AjvSchema,
|
|
42
36
|
getValidationResult,
|
|
43
|
-
|
|
37
|
+
type JoiValidationError,
|
|
38
|
+
type ObjectSchema,
|
|
39
|
+
} from '@naturalcycles/nodejs-lib/joi'
|
|
40
|
+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream'
|
|
41
|
+
import {
|
|
42
|
+
_pipeline,
|
|
44
43
|
transformChunk,
|
|
45
44
|
transformLogProgress,
|
|
46
45
|
transformMap,
|
|
47
46
|
transformNoOp,
|
|
48
47
|
writableVoid,
|
|
49
|
-
} from '@naturalcycles/nodejs-lib'
|
|
48
|
+
} from '@naturalcycles/nodejs-lib/stream'
|
|
50
49
|
import { DBLibError } from '../cnst.js'
|
|
51
50
|
import type { CommonDBTransactionOptions, DBTransaction, RunQueryResult } from '../db.model.js'
|
|
52
51
|
import type { DBQuery } from '../query/dbQuery.js'
|
|
@@ -1216,7 +1215,7 @@ export class CommonDao<BM extends BaseDBEntity, DBM extends BaseDBEntity = BM, I
|
|
|
1216
1215
|
*/
|
|
1217
1216
|
validateAndConvert<T>(
|
|
1218
1217
|
obj: Partial<T>,
|
|
1219
|
-
schema: ObjectSchema<T> | AjvSchema<T> |
|
|
1218
|
+
schema: ObjectSchema<T> | AjvSchema<T> | ZodType<T> | undefined,
|
|
1220
1219
|
op?: 'load' | 'save', // this is to skip validation if validateOnLoad/Save is false
|
|
1221
1220
|
opt: CommonDaoOptions = {},
|
|
1222
1221
|
): any {
|
|
@@ -1245,10 +1244,10 @@ export class CommonDao<BM extends BaseDBEntity, DBM extends BaseDBEntity = BM, I
|
|
|
1245
1244
|
const table = opt.table || this.cfg.table
|
|
1246
1245
|
const objectName = table
|
|
1247
1246
|
|
|
1248
|
-
let error: JoiValidationError | AjvValidationError | ZodValidationError
|
|
1247
|
+
let error: JoiValidationError | AjvValidationError | ZodValidationError | undefined
|
|
1249
1248
|
let convertedValue: any
|
|
1250
1249
|
|
|
1251
|
-
if (schema instanceof
|
|
1250
|
+
if (schema instanceof ZodType) {
|
|
1252
1251
|
// Zod schema
|
|
1253
1252
|
const vr = zSafeValidate(obj as T, schema)
|
|
1254
1253
|
error = vr.error
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Integer, UnixTimestamp } from '@naturalcycles/js-lib'
|
|
2
|
-
import type { ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
2
|
+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream'
|
|
3
3
|
import type { CommonDBCreateOptions } from '../db.model.js'
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CommonLogger, KeyValueTuple } from '@naturalcycles/js-lib'
|
|
2
2
|
import { AppError, pMap } from '@naturalcycles/js-lib'
|
|
3
|
-
import type { ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
4
3
|
import { deflateString, inflateToString } from '@naturalcycles/nodejs-lib'
|
|
4
|
+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream'
|
|
5
5
|
import type { CommonDaoLogLevel } from '../commondao/common.dao.model.js'
|
|
6
6
|
import type { CommonDBCreateOptions } from '../db.model.js'
|
|
7
7
|
import type {
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import type { AsyncMapper, StringMap, UnixTimestamp } from '@naturalcycles/js-lib'
|
|
2
2
|
import { _passthroughMapper, AppError, ErrorMode, localTime, pMap } from '@naturalcycles/js-lib'
|
|
3
|
-
import
|
|
3
|
+
import { boldWhite, dimWhite, grey, yellow } from '@naturalcycles/nodejs-lib'
|
|
4
|
+
import { fs2 } from '@naturalcycles/nodejs-lib/fs'
|
|
5
|
+
import type {
|
|
6
|
+
TransformLogProgressOptions,
|
|
7
|
+
TransformMapOptions,
|
|
8
|
+
} from '@naturalcycles/nodejs-lib/stream'
|
|
4
9
|
import {
|
|
5
10
|
_pipeline,
|
|
6
|
-
boldWhite,
|
|
7
|
-
dimWhite,
|
|
8
|
-
fs2,
|
|
9
|
-
grey,
|
|
10
11
|
NDJsonStats,
|
|
11
12
|
transformLogProgress,
|
|
12
13
|
transformMap,
|
|
13
14
|
transformTap,
|
|
14
|
-
|
|
15
|
-
} from '@naturalcycles/nodejs-lib'
|
|
15
|
+
} from '@naturalcycles/nodejs-lib/stream'
|
|
16
16
|
import type { CommonDB } from '../common.db.js'
|
|
17
17
|
import { DBQuery } from '../query/dbQuery.js'
|
|
18
18
|
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import type { AsyncMapper, BaseDBEntity, UnixTimestamp } from '@naturalcycles/js-lib'
|
|
2
2
|
import { _passthroughMapper, ErrorMode, localTime, pMap } from '@naturalcycles/js-lib'
|
|
3
|
-
import
|
|
3
|
+
import { boldWhite, dimWhite, grey, yellow } from '@naturalcycles/nodejs-lib'
|
|
4
|
+
import type {
|
|
5
|
+
TransformLogProgressOptions,
|
|
6
|
+
TransformMapOptions,
|
|
7
|
+
} from '@naturalcycles/nodejs-lib/stream'
|
|
4
8
|
import {
|
|
5
9
|
_pipeline,
|
|
6
|
-
boldWhite,
|
|
7
|
-
dimWhite,
|
|
8
|
-
grey,
|
|
9
10
|
NDJsonStats,
|
|
10
11
|
transformChunk,
|
|
11
12
|
transformLogProgress,
|
|
12
13
|
transformMap,
|
|
13
14
|
transformTap,
|
|
14
15
|
writableForEach,
|
|
15
|
-
|
|
16
|
-
} from '@naturalcycles/nodejs-lib'
|
|
16
|
+
} from '@naturalcycles/nodejs-lib/stream'
|
|
17
17
|
import type { CommonDB } from '../common.db.js'
|
|
18
18
|
import type { CommonDBSaveOptions } from '../db.model.js'
|
|
19
19
|
import { DBQuery } from '../query/dbQuery.js'
|
|
@@ -12,13 +12,14 @@ import {
|
|
|
12
12
|
localTime,
|
|
13
13
|
pMap,
|
|
14
14
|
} from '@naturalcycles/js-lib'
|
|
15
|
-
import
|
|
15
|
+
import { boldWhite, dimWhite, grey, yellow } from '@naturalcycles/nodejs-lib'
|
|
16
|
+
import { fs2 } from '@naturalcycles/nodejs-lib/fs'
|
|
17
|
+
import type {
|
|
18
|
+
TransformLogProgressOptions,
|
|
19
|
+
TransformMapOptions,
|
|
20
|
+
} from '@naturalcycles/nodejs-lib/stream'
|
|
16
21
|
import {
|
|
17
22
|
_pipeline,
|
|
18
|
-
boldWhite,
|
|
19
|
-
dimWhite,
|
|
20
|
-
fs2,
|
|
21
|
-
grey,
|
|
22
23
|
NDJsonStats,
|
|
23
24
|
transformChunk,
|
|
24
25
|
transformFilterSync,
|
|
@@ -26,8 +27,7 @@ import {
|
|
|
26
27
|
transformMap,
|
|
27
28
|
transformTap,
|
|
28
29
|
writableForEach,
|
|
29
|
-
|
|
30
|
-
} from '@naturalcycles/nodejs-lib'
|
|
30
|
+
} from '@naturalcycles/nodejs-lib/stream'
|
|
31
31
|
import type { CommonDB } from '../common.db.js'
|
|
32
32
|
import type { CommonDBSaveOptions } from '../db.model.js'
|
|
33
33
|
|
package/src/query/dbQuery.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AsyncMapper, BaseDBEntity, ObjectWithId } from '@naturalcycles/js-lib'
|
|
2
2
|
import { _objectAssign, _truncate } from '@naturalcycles/js-lib'
|
|
3
|
-
import type { ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
3
|
+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream'
|
|
4
4
|
import type { CommonDao } from '../commondao/common.dao.js'
|
|
5
5
|
import type {
|
|
6
6
|
CommonDaoOptions,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Readable } from 'node:stream'
|
|
2
2
|
import { _deepCopy, _filterObject, _omit, _pick, _sortBy, localTime } from '@naturalcycles/js-lib'
|
|
3
|
-
import { _pipeline } from '@naturalcycles/nodejs-lib'
|
|
3
|
+
import { _pipeline } from '@naturalcycles/nodejs-lib/stream'
|
|
4
4
|
import type { CommonDB } from '../common.db.js'
|
|
5
5
|
import { CommonDao } from '../commondao/common.dao.js'
|
|
6
6
|
import { CommonDaoLogLevel } from '../commondao/common.dao.model.js'
|
package/src/validation/index.ts
CHANGED