@naturalcycles/db-lib 10.12.0 → 10.14.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.
@@ -952,9 +952,9 @@ export class CommonDao {
952
952
  }
953
953
  const inputName = opt.table || this.cfg.table;
954
954
  const [error, convertedValue] = this.cfg.validateBM(input, {
955
- // Passing `mutateInput` through allows to do opt-in mutation
956
- // for individual operations, e.g `someDao.save(myObj, { mutateInput: true })`,
957
- // while still keeping safe non-mutating behavior by default
955
+ // Passing `mutateInput` through allows to opt-out of mutation
956
+ // for individual operations, e.g `someDao.save(myObj, { mutateInput: false })`
957
+ // Default is undefined (the validation function decides whether to mutate or not).
958
958
  mutateInput: opt.mutateInput,
959
959
  inputName,
960
960
  });
@@ -186,7 +186,11 @@ export interface CommonDaoOptions extends CommonDBOptions {
186
186
  */
187
187
  skipValidation?: boolean;
188
188
  /**
189
- * Default to false.
189
+ * Defaults to undefined.
190
+ *
191
+ * Undefined means that it's up for the underlying validation library (implementation)
192
+ * to mutate or not.
193
+ * E.g joi and zod would deep-clone, while ajv would MUTATE.
190
194
  *
191
195
  * False ensures that the input is not mutated by the Validation function (`validateBM`).
192
196
  *
@@ -1,5 +1,5 @@
1
1
  import { _range } from '@naturalcycles/js-lib/array/range.js';
2
- import { jsonSchema } from '@naturalcycles/js-lib/json-schema';
2
+ import { j } from '@naturalcycles/js-lib/json-schema';
3
3
  import { baseDBEntitySchema, binarySchema, booleanSchema, numberSchema, objectSchema, stringSchema, } from '@naturalcycles/nodejs-lib/joi';
4
4
  const MOCK_TS_2018_06_21 = 1529539200;
5
5
  export const TEST_TABLE = 'TEST_TABLE';
@@ -17,17 +17,17 @@ export const testItemTMSchema = objectSchema({
17
17
  k1: stringSchema,
18
18
  even: booleanSchema.optional(),
19
19
  });
20
- export const testItemBMJsonSchema = jsonSchema
20
+ export const testItemBMJsonSchema = j
21
21
  .rootObject({
22
22
  // todo: figure out how to not copy-paste these 3 fields
23
- id: jsonSchema.string(), // todo: not strictly needed here
24
- created: jsonSchema.unixTimestamp(),
25
- updated: jsonSchema.unixTimestamp(),
26
- k1: jsonSchema.string(),
27
- k2: jsonSchema.oneOf([jsonSchema.string(), jsonSchema.null()]).optional(),
28
- k3: jsonSchema.number().optional(),
29
- even: jsonSchema.boolean().optional(),
30
- b1: jsonSchema.buffer().optional(),
23
+ id: j.string(), // todo: not strictly needed here
24
+ created: j.unixTimestamp(),
25
+ updated: j.unixTimestamp(),
26
+ k1: j.string(),
27
+ k2: j.oneOf([j.string(), j.null()]).optional(),
28
+ k3: j.number().optional(),
29
+ even: j.boolean().optional(),
30
+ b1: j.buffer().optional(),
31
31
  })
32
32
  .baseDBEntity()
33
33
  .build();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/db-lib",
3
3
  "type": "module",
4
- "version": "10.12.0",
4
+ "version": "10.14.0",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@naturalcycles/nodejs-lib": "^15"
@@ -227,7 +227,11 @@ export interface CommonDaoOptions extends CommonDBOptions {
227
227
  skipValidation?: boolean
228
228
 
229
229
  /**
230
- * Default to false.
230
+ * Defaults to undefined.
231
+ *
232
+ * Undefined means that it's up for the underlying validation library (implementation)
233
+ * to mutate or not.
234
+ * E.g joi and zod would deep-clone, while ajv would MUTATE.
231
235
  *
232
236
  * False ensures that the input is not mutated by the Validation function (`validateBM`).
233
237
  *
@@ -1222,9 +1222,9 @@ export class CommonDao<BM extends BaseDBEntity, DBM extends BaseDBEntity = BM, I
1222
1222
  const inputName = opt.table || this.cfg.table
1223
1223
 
1224
1224
  const [error, convertedValue] = this.cfg.validateBM(input as BM, {
1225
- // Passing `mutateInput` through allows to do opt-in mutation
1226
- // for individual operations, e.g `someDao.save(myObj, { mutateInput: true })`,
1227
- // while still keeping safe non-mutating behavior by default
1225
+ // Passing `mutateInput` through allows to opt-out of mutation
1226
+ // for individual operations, e.g `someDao.save(myObj, { mutateInput: false })`
1227
+ // Default is undefined (the validation function decides whether to mutate or not).
1228
1228
  mutateInput: opt.mutateInput,
1229
1229
  inputName,
1230
1230
  })
@@ -1,6 +1,6 @@
1
1
  import { _range } from '@naturalcycles/js-lib/array/range.js'
2
2
  import type { JsonSchemaObject } from '@naturalcycles/js-lib/json-schema'
3
- import { jsonSchema } from '@naturalcycles/js-lib/json-schema'
3
+ import { j } from '@naturalcycles/js-lib/json-schema'
4
4
  import type { BaseDBEntity, UnixTimestamp } from '@naturalcycles/js-lib/types'
5
5
  import {
6
6
  baseDBEntitySchema,
@@ -50,17 +50,17 @@ export const testItemTMSchema: ObjectSchema<TestItemTM> = objectSchema<TestItemT
50
50
  even: booleanSchema.optional(),
51
51
  })
52
52
 
53
- export const testItemBMJsonSchema: JsonSchemaObject<TestItemBM> = jsonSchema
53
+ export const testItemBMJsonSchema: JsonSchemaObject<TestItemBM> = j
54
54
  .rootObject<TestItemBM>({
55
55
  // todo: figure out how to not copy-paste these 3 fields
56
- id: jsonSchema.string(), // todo: not strictly needed here
57
- created: jsonSchema.unixTimestamp(),
58
- updated: jsonSchema.unixTimestamp(),
59
- k1: jsonSchema.string(),
60
- k2: jsonSchema.oneOf<string | null>([jsonSchema.string(), jsonSchema.null()]).optional(),
61
- k3: jsonSchema.number().optional(),
62
- even: jsonSchema.boolean().optional(),
63
- b1: jsonSchema.buffer().optional(),
56
+ id: j.string(), // todo: not strictly needed here
57
+ created: j.unixTimestamp(),
58
+ updated: j.unixTimestamp(),
59
+ k1: j.string(),
60
+ k2: j.oneOf<string | null>([j.string(), j.null()]).optional(),
61
+ k3: j.number().optional(),
62
+ even: j.boolean().optional(),
63
+ b1: j.buffer().optional(),
64
64
  })
65
65
  .baseDBEntity()
66
66
  .build()