@bedrockio/model 0.18.5 → 0.19.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.19.0
2
+
3
+ - Ensure that document clone is synchronous.
4
+
5
+ ## 0.18.6
6
+
7
+ - Yada bump.
8
+
1
9
  ## 0.18.5
2
10
 
3
11
  - Moved warnings to `process.emitWarning`.
package/README.md CHANGED
@@ -1785,9 +1785,7 @@ shop.name; // Now "My New Shop"
1785
1785
 
1786
1786
  ### Clone
1787
1787
 
1788
- Adds a single `clone` method on documents. This is an async method mostly for
1789
- testing that will immediately create a copy of the document. It makes up for
1790
- some of the shortcomings of the Mongoose `$clone` method:
1788
+ Adds a single `clone` method on documents that makes up for some of the shortcomings of the Mongoose `$clone` method:
1791
1789
 
1792
1790
  - A new `id` will be generated.
1793
1791
  - Populated and self-referencing documents are handled.
package/dist/cjs/clone.js CHANGED
@@ -13,11 +13,11 @@ exports.applyClone = applyClone;
13
13
  // - Cannot deal with unique fields.
14
14
  //
15
15
  function applyClone(schema) {
16
- schema.method('clone', async function clone() {
17
- return await cloneDocument(this);
16
+ schema.method('clone', function clone() {
17
+ return cloneDocument(this);
18
18
  });
19
19
  }
20
- async function cloneDocument(doc) {
20
+ function cloneDocument(doc) {
21
21
  const Model = doc.constructor;
22
22
  const clone = new Model();
23
23
  for (let [key, typedef] of Object.entries(Model.schema.obj)) {
@@ -31,7 +31,6 @@ async function cloneDocument(doc) {
31
31
  }
32
32
  clone.set(key, value);
33
33
  }
34
- await clone.save();
35
34
  return clone;
36
35
  }
37
36
  let counter = 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bedrockio/model",
3
- "version": "0.18.5",
3
+ "version": "0.19.0",
4
4
  "description": "Bedrock utilities for model creation.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -39,7 +39,7 @@
39
39
  "@babel/preset-env": "^7.26.0",
40
40
  "@bedrockio/eslint-plugin": "^1.2.2",
41
41
  "@bedrockio/prettier-config": "^1.1.1",
42
- "@bedrockio/yada": "^1.10.0",
42
+ "@bedrockio/yada": "^1.10.3",
43
43
  "@shelf/jest-mongodb": "^5.2.2",
44
44
  "eslint": "^9.36.0",
45
45
  "jest": "^30.2.0",
package/src/clone.js CHANGED
@@ -7,12 +7,12 @@
7
7
  // - Cannot deal with unique fields.
8
8
  //
9
9
  export function applyClone(schema) {
10
- schema.method('clone', async function clone() {
11
- return await cloneDocument(this);
10
+ schema.method('clone', function clone() {
11
+ return cloneDocument(this);
12
12
  });
13
13
  }
14
14
 
15
- async function cloneDocument(doc) {
15
+ function cloneDocument(doc) {
16
16
  const Model = doc.constructor;
17
17
  const clone = new Model();
18
18
 
@@ -26,8 +26,6 @@ async function cloneDocument(doc) {
26
26
  clone.set(key, value);
27
27
  }
28
28
 
29
- await clone.save();
30
-
31
29
  return clone;
32
30
  }
33
31
 
package/types/schema.d.ts CHANGED
@@ -28,7 +28,9 @@ export function createSchema(definition: object, options?: mongoose.SchemaOption
28
28
  id?: boolean;
29
29
  _id?: boolean;
30
30
  minimize?: boolean;
31
- optimisticConcurrency?: boolean;
31
+ optimisticConcurrency?: boolean | string[] | {
32
+ exclude: string[];
33
+ };
32
34
  pluginTags?: string[];
33
35
  read?: string;
34
36
  readConcern?: {
@@ -47,16 +49,16 @@ export function createSchema(definition: object, options?: mongoose.SchemaOption
47
49
  getters: boolean;
48
50
  versionKey: boolean;
49
51
  transform: (doc: any, ret: any, options: any) => void;
50
- } | mongoose.ToObjectOptions<any>;
52
+ } | mongoose.ToObjectOptions<any, any>;
51
53
  toObject: {
52
54
  getters: boolean;
53
55
  versionKey: boolean;
54
56
  transform: (doc: any, ret: any, options: any) => void;
55
- } | mongoose.ToObjectOptions<any>;
57
+ } | mongoose.ToObjectOptions<any, any>;
56
58
  typeKey?: string;
57
59
  validateBeforeSave?: boolean;
58
60
  validateModifiedOnly?: boolean;
59
- versionKey?: string | boolean;
61
+ versionKey?: string | false;
60
62
  selectPopulatedPaths?: boolean;
61
63
  skipVersioning?: {
62
64
  [key: string]: boolean;
@@ -64,12 +66,13 @@ export function createSchema(definition: object, options?: mongoose.SchemaOption
64
66
  storeSubdocValidationError?: boolean;
65
67
  timestamps: boolean | mongoose.SchemaTimestampsConfig;
66
68
  suppressReservedKeysWarning?: boolean;
67
- statics?: mongoose.AddThisParameter<any, mongoose.Model<any, {}, {}, {}, any, any>>;
69
+ statics?: mongoose.AddThisParameter<any, mongoose.Model<any, any, any, any, any, any>>;
68
70
  methods?: mongoose.AddThisParameter<any, any> & mongoose.AnyObject;
69
71
  query?: any;
70
72
  castNonArrays?: boolean;
71
73
  virtuals?: mongoose.SchemaOptionsVirtualsPropertyType<any, any, any>;
72
74
  overwriteModels?: boolean;
75
+ encryptionType?: "csfle" | "queryableEncryption";
73
76
  }, any, any>;
74
77
  export function normalizeAttributes(arg: any, path?: any[]): any;
75
78
  import mongoose from 'mongoose';
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.js"],"names":[],"mappings":"AAyBA;;;;;;;GAOG;AACH,yCAJW,MAAM,YACN,QAAQ,CAAC,aAAa;;;;;;;YAuC/B,CAAC;WAAa,CAAC;mBACF,CAAC;;;;;;;;;;;;;;;;;;;;;SAsHkC,CAAC;gBACzC,CAAA;SAAW,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aA9GrB;AAED,iEAcC;qBA9FoB,UAAU"}
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.js"],"names":[],"mappings":"AAyBA;;;;;;;GAOG;AACH,yCAJW,MAAM,YACN,QAAQ,CAAC,aAAa;;;;;;;YA2C7B,CAAC;WAAa,CAAC;mBACH,CAAC;;;;;;;;;;;;;;;;;;;;;;;SAgIb,CAAC;gBAA4B,CAAA;SAAW,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aA3H5C;AAED,iEAcC;qBA9FoB,UAAU"}
package/types/search.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export function applySearch(schema: any, definition: any): void;
2
2
  export function searchValidation(options?: {}): {
3
+ validateInput(): void;
3
4
  setup(): void;
4
5
  get(path?: string | Array<string>): any;
5
6
  unwind(path?: string | Array<string>): any;
@@ -10,6 +11,10 @@ export function searchValidation(options?: {}): {
10
11
  transform(fn: Function, root?: boolean): /*elided*/ any;
11
12
  export(): any;
12
13
  append(arg: import("@bedrockio/yada/types/object").SchemaMap | import("@bedrockio/yada/types/Schema").default): /*elided*/ any;
14
+ stripEmpty(): /*elided*/ any;
15
+ stripUnknown(): /*elided*/ any;
16
+ allowFlatKeys(): /*elided*/ any;
17
+ expandFlatKeys(): /*elided*/ any;
13
18
  options(options?: {
14
19
  stripEmpty?: boolean;
15
20
  stripUnknown?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.js"],"names":[],"mappings":"AAuBA,gEAaC;AAED;;;;;;;;;;;;kBAmHU,CAAC;oBAGD,CAAP;qBACoB,CAAC;sBAGlB,CAAD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eA7B6B,CAAC;;;;;;;;;;;;;;EApElC;AAED;;;;;;;;;;;;;;;;mBA1BmD,CAAC;;;;;;;;;;;;qBAuBlD,CAAC;sBAGmB,CAAC;sBACrB,CAAC;wBAA8B,CAAC;wBACrB,CAAC;;;4BAwBc,CAAC;kCAK3B,CAAD;wBACc,CAAC;wBAA+B,CAAC;wCACtB,CAAC;2BAGhB,CAAC;kCAES,CAAC;2BACd,CAAC;qBACL,CAAJ;;;uBAuBgC,CAAC;6BAEjB,CAAC;8BACF,CAAC;6BAGZ,CAAH;0BACgB,CAAC;6BACZ,CAAF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAL8B,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBA5FgB,CAAC;;;;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CAAC;qBACL,CAAJ;;;uBAuBgC,CAAC;6BAEjB,CAAC;8BACF,CAAC;6BAGZ,CAAH;0BACgB,CAAC;6BACZ,CAAF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAL8B,CAAC;;;;;;;;;;;;;;;;;EArDlC"}
@@ -162,6 +162,7 @@ export const OBJECT_ID_SCHEMA: {
162
162
  runAssertion(value: any, assertion: any, options?: {}): Promise<any>;
163
163
  };
164
164
  export const NUMBER_RANGE_SCHEMA: {
165
+ validateInput(): void;
165
166
  setup(): void;
166
167
  get(path?: string | Array<string>): any;
167
168
  unwind(path?: string | Array<string>): any;
@@ -172,6 +173,10 @@ export const NUMBER_RANGE_SCHEMA: {
172
173
  transform(fn: Function, root?: boolean): /*elided*/ any;
173
174
  export(): any;
174
175
  append(arg: import("@bedrockio/yada/types/object").SchemaMap | import("@bedrockio/yada/types/Schema").default): /*elided*/ any;
176
+ stripEmpty(): /*elided*/ any;
177
+ stripUnknown(): /*elided*/ any;
178
+ allowFlatKeys(): /*elided*/ any;
179
+ expandFlatKeys(): /*elided*/ any;
175
180
  options(options?: {
176
181
  stripEmpty?: boolean;
177
182
  stripUnknown?: boolean;
@@ -221,6 +226,7 @@ export const NUMBER_RANGE_SCHEMA: {
221
226
  runAssertion(value: any, assertion: any, options?: {}): Promise<any>;
222
227
  };
223
228
  export const STRING_RANGE_SCHEMA: {
229
+ validateInput(): void;
224
230
  setup(): void;
225
231
  get(path?: string | Array<string>): any;
226
232
  unwind(path?: string | Array<string>): any;
@@ -231,6 +237,10 @@ export const STRING_RANGE_SCHEMA: {
231
237
  transform(fn: Function, root?: boolean): /*elided*/ any;
232
238
  export(): any;
233
239
  append(arg: import("@bedrockio/yada/types/object").SchemaMap | import("@bedrockio/yada/types/Schema").default): /*elided*/ any;
240
+ stripEmpty(): /*elided*/ any;
241
+ stripUnknown(): /*elided*/ any;
242
+ allowFlatKeys(): /*elided*/ any;
243
+ expandFlatKeys(): /*elided*/ any;
234
244
  options(options?: {
235
245
  stripEmpty?: boolean;
236
246
  stripUnknown?: boolean;
@@ -280,6 +290,7 @@ export const STRING_RANGE_SCHEMA: {
280
290
  runAssertion(value: any, assertion: any, options?: {}): Promise<any>;
281
291
  };
282
292
  export const DATE_RANGE_SCHEMA: {
293
+ validateInput(): void;
283
294
  setup(): void;
284
295
  get(path?: string | Array<string>): any;
285
296
  unwind(path?: string | Array<string>): any;
@@ -290,6 +301,10 @@ export const DATE_RANGE_SCHEMA: {
290
301
  transform(fn: Function, root?: boolean): /*elided*/ any;
291
302
  export(): any;
292
303
  append(arg: import("@bedrockio/yada/types/object").SchemaMap | import("@bedrockio/yada/types/Schema").default): /*elided*/ any;
304
+ stripEmpty(): /*elided*/ any;
305
+ stripUnknown(): /*elided*/ any;
306
+ allowFlatKeys(): /*elided*/ any;
307
+ expandFlatKeys(): /*elided*/ any;
293
308
  options(options?: {
294
309
  stripEmpty?: boolean;
295
310
  stripUnknown?: boolean;
@@ -340,6 +355,7 @@ export const DATE_RANGE_SCHEMA: {
340
355
  };
341
356
  export const REFERENCE_SCHEMA: import("@bedrockio/yada/types/Schema").default;
342
357
  export const INCLUDE_FIELD_SCHEMA: {
358
+ validateInput(): void;
343
359
  setup(): void;
344
360
  get(path?: string | Array<string>): any;
345
361
  unwind(path?: string | Array<string>): any;
@@ -350,6 +366,10 @@ export const INCLUDE_FIELD_SCHEMA: {
350
366
  transform(fn: Function, root?: boolean): /*elided*/ any;
351
367
  export(): any;
352
368
  append(arg: import("@bedrockio/yada/types/object").SchemaMap | import("@bedrockio/yada/types/Schema").default): /*elided*/ any;
369
+ stripEmpty(): /*elided*/ any;
370
+ stripUnknown(): /*elided*/ any;
371
+ allowFlatKeys(): /*elided*/ any;
372
+ expandFlatKeys(): /*elided*/ any;
353
373
  options(options?: {
354
374
  stripEmpty?: boolean;
355
375
  stripUnknown?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"validation-schemas.d.ts","sourceRoot":"","sources":["../src/validation-sch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