@naturalcycles/db-lib 8.24.2 → 8.24.3

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.
@@ -137,7 +137,7 @@ export declare class CommonDao<BM extends Partial<ObjectWithId>, DBM extends Obj
137
137
  *
138
138
  * Does NOT mutate the object.
139
139
  */
140
- validateAndConvert<IN, OUT = IN>(obj: IN, schema?: ObjectSchemaTyped<IN> | AjvSchema<IN>, modelType?: DBModelType, opt?: CommonDaoOptions): OUT;
140
+ validateAndConvert<IN, OUT = IN>(obj: Partial<IN>, schema: ObjectSchemaTyped<IN> | AjvSchema<IN> | undefined, modelType: DBModelType, opt?: CommonDaoOptions): OUT;
141
141
  getTableSchema(): Promise<JsonSchemaRootObject<DBM>>;
142
142
  createTable(schema: JsonSchemaObject<DBM>, opt?: CommonDaoCreateOptions): Promise<void>;
143
143
  /**
@@ -1,4 +1,4 @@
1
- import { CommonLogger, ErrorMode, ObjectWithId } from '@naturalcycles/js-lib';
1
+ import { CommonLogger, ErrorMode, ObjectWithId, Saved } from '@naturalcycles/js-lib';
2
2
  import { AjvSchema, AjvValidationError, JoiValidationError, ObjectSchemaTyped, TransformLogProgressOptions, TransformMapOptions } from '@naturalcycles/nodejs-lib';
3
3
  import { CommonDB } from '../common.db';
4
4
  import { CommonDBCreateOptions, CommonDBOptions, CommonDBSaveOptions } from '../db.model';
@@ -47,7 +47,7 @@ export declare enum CommonDaoLogLevel {
47
47
  */
48
48
  DATA_FULL = 30
49
49
  }
50
- export interface CommonDaoCfg<BM extends Partial<ObjectWithId>, DBM extends ObjectWithId, TM> {
50
+ export interface CommonDaoCfg<BM extends Partial<ObjectWithId>, DBM extends ObjectWithId = Saved<BM>, TM = BM> {
51
51
  db: CommonDB;
52
52
  table: string;
53
53
  /**
@@ -78,7 +78,7 @@ async function dbPipelineRestore(opt) {
78
78
  ...opt,
79
79
  metric: table,
80
80
  }),
81
- (0, nodejs_lib_1.transformLimit)(limit),
81
+ (0, nodejs_lib_1.transformLimit)({ limit }),
82
82
  ...(sinceUpdated
83
83
  ? [(0, nodejs_lib_1.transformFilterSync)(r => r.updated >= sinceUpdated)]
84
84
  : []),
package/package.json CHANGED
@@ -42,7 +42,7 @@
42
42
  "engines": {
43
43
  "node": ">=14.15"
44
44
  },
45
- "version": "8.24.2",
45
+ "version": "8.24.3",
46
46
  "description": "Lowest Common Denominator API to supported Databases",
47
47
  "keywords": [
48
48
  "db",
@@ -1,4 +1,4 @@
1
- import { CommonLogger, ErrorMode, ObjectWithId } from '@naturalcycles/js-lib'
1
+ import { CommonLogger, ErrorMode, ObjectWithId, Saved } from '@naturalcycles/js-lib'
2
2
  import {
3
3
  AjvSchema,
4
4
  AjvValidationError,
@@ -60,7 +60,11 @@ export enum CommonDaoLogLevel {
60
60
  DATA_FULL = 30,
61
61
  }
62
62
 
63
- export interface CommonDaoCfg<BM extends Partial<ObjectWithId>, DBM extends ObjectWithId, TM> {
63
+ export interface CommonDaoCfg<
64
+ BM extends Partial<ObjectWithId>,
65
+ DBM extends ObjectWithId = Saved<BM>,
66
+ TM = BM,
67
+ > {
64
68
  db: CommonDB
65
69
  table: string
66
70
 
@@ -903,9 +903,9 @@ export class CommonDao<
903
903
  * Does NOT mutate the object.
904
904
  */
905
905
  validateAndConvert<IN, OUT = IN>(
906
- obj: IN,
907
- schema?: ObjectSchemaTyped<IN> | AjvSchema<IN>,
908
- modelType?: DBModelType,
906
+ obj: Partial<IN>,
907
+ schema: ObjectSchemaTyped<IN> | AjvSchema<IN> | undefined,
908
+ modelType: DBModelType,
909
909
  opt: CommonDaoOptions = {},
910
910
  ): OUT {
911
911
  // `raw` option completely bypasses any processing
@@ -928,12 +928,12 @@ export class CommonDao<
928
928
 
929
929
  // Pre-validation hooks
930
930
  if (modelType === DBModelType.DBM) {
931
- obj = this.cfg.hooks!.beforeDBMValidate!(obj as any) as any
931
+ obj = this.cfg.hooks!.beforeDBMValidate!(obj as any) as IN
932
932
  }
933
933
 
934
934
  // Return as is if no schema is passed or if `skipConversion` is set
935
935
  if (!schema || opt.skipConversion) {
936
- return obj as any
936
+ return obj as OUT
937
937
  }
938
938
 
939
939
  // This will Convert and Validate
@@ -947,12 +947,12 @@ export class CommonDao<
947
947
  // Ajv schema
948
948
  convertedValue = obj // because Ajv mutates original object
949
949
 
950
- error = schema.getValidationError(obj, {
950
+ error = schema.getValidationError(obj as IN, {
951
951
  objectName,
952
952
  })
953
953
  } else {
954
954
  // Joi
955
- const vr = getValidationResult<IN, OUT>(obj, schema, objectName)
955
+ const vr = getValidationResult<IN, OUT>(obj as IN, schema, objectName)
956
956
  error = vr.error
957
957
  convertedValue = vr.value
958
958
  }
@@ -209,7 +209,7 @@ export async function dbPipelineRestore(opt: DBPipelineRestoreOptions): Promise<
209
209
  ...opt,
210
210
  metric: table,
211
211
  }),
212
- transformLimit(limit),
212
+ transformLimit({ limit }),
213
213
  ...(sinceUpdated
214
214
  ? [transformFilterSync<SavedDBEntity>(r => r.updated >= sinceUpdated)]
215
215
  : []),