@bedrockio/model 0.22.1 → 0.22.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.22.3
2
+
3
+ - Package bump
4
+
5
+ ## 0.22.2
6
+
7
+ - Small fixes around upsert reporting.
8
+
1
9
  ## 0.22.1
2
10
 
3
11
  - Indicate whether document was created or not in upsert.
@@ -15,11 +15,17 @@ function applyUpsert(schema) {
15
15
  let doc = await this.findOne(query);
16
16
  if (doc) {
17
17
  doc.assign(fields);
18
- await doc.save();
18
+ if (doc.isModified()) {
19
+ await doc.save();
20
+ doc.$locals.updated = true;
21
+ } else {
22
+ doc.$locals.updated = false;
23
+ }
19
24
  doc.$locals.created = false;
20
25
  } else {
21
26
  doc = await this.create(fields);
22
27
  doc.$locals.created = true;
28
+ doc.$locals.updated = false;
23
29
  }
24
30
  return doc;
25
31
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bedrockio/model",
3
- "version": "0.22.1",
3
+ "version": "0.22.3",
4
4
  "description": "Bedrock utilities for model creation.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -26,7 +26,7 @@
26
26
  "url": "https://github.com/bedrockio/model"
27
27
  },
28
28
  "dependencies": {
29
- "@bedrockio/logger": "^1.1.1",
29
+ "@bedrockio/logger": "^1.1.5",
30
30
  "jsonc-parser": "^3.3.1",
31
31
  "lodash": "^4.17.21"
32
32
  },
@@ -38,9 +38,9 @@
38
38
  "@babel/cli": "^7.26.4",
39
39
  "@babel/core": "^7.26.0",
40
40
  "@babel/preset-env": "^7.26.0",
41
- "@bedrockio/eslint-plugin": "^1.2.2",
41
+ "@bedrockio/eslint-plugin": "^1.3.1",
42
42
  "@bedrockio/prettier-config": "^1.1.1",
43
- "@bedrockio/yada": "^1.10.6",
43
+ "@bedrockio/yada": "^1.11.0",
44
44
  "@shelf/jest-mongodb": "^5.2.2",
45
45
  "eslint": "^9.36.0",
46
46
  "jest": "^30.2.0",
package/src/upsert.js CHANGED
@@ -11,11 +11,18 @@ export function applyUpsert(schema) {
11
11
 
12
12
  if (doc) {
13
13
  doc.assign(fields);
14
- await doc.save();
14
+
15
+ if (doc.isModified()) {
16
+ await doc.save();
17
+ doc.$locals.updated = true;
18
+ } else {
19
+ doc.$locals.updated = false;
20
+ }
15
21
  doc.$locals.created = false;
16
22
  } else {
17
23
  doc = await this.create(fields);
18
24
  doc.$locals.created = true;
25
+ doc.$locals.updated = false;
19
26
  }
20
27
 
21
28
  return doc;
@@ -3,6 +3,7 @@ export function searchValidation(options?: {}): {
3
3
  validateInput(): void;
4
4
  setup(): void;
5
5
  get(path?: string | Array<string>): any;
6
+ set(path: string | Array<string>, fn: Function): /*elided*/ any;
6
7
  unwind(path?: string | Array<string>): any;
7
8
  pick(...names: string[]): /*elided*/ any;
8
9
  omit(...names: string[]): /*elided*/ any;
@@ -40,11 +41,12 @@ export function searchValidation(options?: {}): {
40
41
  validate(value: any, options?: {}): Promise<any>;
41
42
  clone(meta: any): /*elided*/ any;
42
43
  toOpenApi(options: any): any;
44
+ toOpenAi(): /*elided*/ any;
43
45
  toJSON(): any;
44
46
  getType(): {
45
47
  type: any;
46
48
  };
47
- getFormat(options: any): {
49
+ getFormat(): {
48
50
  format: any;
49
51
  };
50
52
  getDefault(): {
@@ -144,11 +146,12 @@ export function exportValidation(options?: {}): {
144
146
  clone(meta: any): /*elided*/ any;
145
147
  append(schema: any): import("@bedrockio/yada/types/Schema").default;
146
148
  toOpenApi(options: any): any;
149
+ toOpenAi(): /*elided*/ any;
147
150
  toJSON(): any;
148
151
  getType(): {
149
152
  type: any;
150
153
  };
151
- getFormat(options: any): {
154
+ getFormat(): {
152
155
  format: any;
153
156
  };
154
157
  getDefault(): {
@@ -249,11 +252,12 @@ export function exportValidation(options?: {}): {
249
252
  clone(meta: any): /*elided*/ any;
250
253
  append(schema: any): import("@bedrockio/yada/types/Schema").default;
251
254
  toOpenApi(options: any): any;
255
+ toOpenAi(): /*elided*/ any;
252
256
  toJSON(): any;
253
257
  getType(): {
254
258
  type: any;
255
259
  };
256
- getFormat(options: any): {
260
+ getFormat(): {
257
261
  format: any;
258
262
  };
259
263
  getDefault(): {
@@ -1 +1 @@
1
- {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/search.js"],"names":[],"mappings":"AAuBA,gEAaC;AAED;;;;;;;;;;;;;;;;;kBAwIQ,CAAJ;oBAEE,CAAA;qBAKO,CAAC;sBACG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eAnDkB,CAAA;;;;;;;;;;;;;;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;6BACD,CAAC;0BAIZ,CAAA;6BACmB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBANW,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBA5FgB,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;6BACD,CAAC;0BAIZ,CAAA;6BACmB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBANW,CAAA;;;;;;;;;;;;;;;;;EArDlC"}
1
+ {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/search.js"],"names":[],"mappings":"AAuBA,gEAaC;AAED;;;;;;;;;;;;;;;;;;kBA0JiB,CAAC;oBACX,CAAC;qBAEc,CAAC;sBAAiC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eAhElD,CAAA;;;;;;;;;;;;;;EApEN;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;6BACD,CAAC;0BAIZ,CAAA;6BACmB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBANjB,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBA5F4C,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;6BACD,CAAC;0BAIZ,CAAA;6BACmB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBANjB,CAAA;;;;;;;;;;;;;;;;;EArDN"}
@@ -1 +1 @@
1
- {"version":3,"file":"upsert.d.ts","sourceRoot":"","sources":["../../src/upsert.js"],"names":[],"mappings":"AAAA,+CAkCC"}
1
+ {"version":3,"file":"upsert.d.ts","sourceRoot":"","sources":["../../src/upsert.js"],"names":[],"mappings":"AAAA,+CAyCC"}
@@ -27,15 +27,15 @@ export const DATE_SCHEMA: {
27
27
  append(schema: any): import("@bedrockio/yada/types/Schema").default;
28
28
  toJsonSchema(options?: {
29
29
  tag?: Function;
30
- style?: "openai";
31
30
  stripExtensions?: boolean;
32
31
  }): any;
33
32
  toOpenApi(options: any): any;
33
+ toOpenAi(): /*elided*/ any;
34
34
  toJSON(): any;
35
35
  getType(): {
36
36
  type: any;
37
37
  };
38
- getFormat(options: any): {
38
+ getFormat(): {
39
39
  format: any;
40
40
  };
41
41
  getDefault(): {
@@ -136,11 +136,12 @@ export const OBJECT_ID_SCHEMA: {
136
136
  clone(meta: any): /*elided*/ any;
137
137
  append(schema: any): import("@bedrockio/yada/types/Schema").default;
138
138
  toOpenApi(options: any): any;
139
+ toOpenAi(): /*elided*/ any;
139
140
  toJSON(): any;
140
141
  getType(): {
141
142
  type: any;
142
143
  };
143
- getFormat(options: any): {
144
+ getFormat(): {
144
145
  format: any;
145
146
  };
146
147
  getDefault(): {
@@ -165,6 +166,7 @@ export const NUMBER_RANGE_SCHEMA: {
165
166
  validateInput(): void;
166
167
  setup(): void;
167
168
  get(path?: string | Array<string>): any;
169
+ set(path: string | Array<string>, fn: Function): /*elided*/ any;
168
170
  unwind(path?: string | Array<string>): any;
169
171
  pick(...names: string[]): /*elided*/ any;
170
172
  omit(...names: string[]): /*elided*/ any;
@@ -202,11 +204,12 @@ export const NUMBER_RANGE_SCHEMA: {
202
204
  validate(value: any, options?: {}): Promise<any>;
203
205
  clone(meta: any): /*elided*/ any;
204
206
  toOpenApi(options: any): any;
207
+ toOpenAi(): /*elided*/ any;
205
208
  toJSON(): any;
206
209
  getType(): {
207
210
  type: any;
208
211
  };
209
- getFormat(options: any): {
212
+ getFormat(): {
210
213
  format: any;
211
214
  };
212
215
  getDefault(): {
@@ -229,6 +232,7 @@ export const STRING_RANGE_SCHEMA: {
229
232
  validateInput(): void;
230
233
  setup(): void;
231
234
  get(path?: string | Array<string>): any;
235
+ set(path: string | Array<string>, fn: Function): /*elided*/ any;
232
236
  unwind(path?: string | Array<string>): any;
233
237
  pick(...names: string[]): /*elided*/ any;
234
238
  omit(...names: string[]): /*elided*/ any;
@@ -266,11 +270,12 @@ export const STRING_RANGE_SCHEMA: {
266
270
  validate(value: any, options?: {}): Promise<any>;
267
271
  clone(meta: any): /*elided*/ any;
268
272
  toOpenApi(options: any): any;
273
+ toOpenAi(): /*elided*/ any;
269
274
  toJSON(): any;
270
275
  getType(): {
271
276
  type: any;
272
277
  };
273
- getFormat(options: any): {
278
+ getFormat(): {
274
279
  format: any;
275
280
  };
276
281
  getDefault(): {
@@ -293,6 +298,7 @@ export const DATE_RANGE_SCHEMA: {
293
298
  validateInput(): void;
294
299
  setup(): void;
295
300
  get(path?: string | Array<string>): any;
301
+ set(path: string | Array<string>, fn: Function): /*elided*/ any;
296
302
  unwind(path?: string | Array<string>): any;
297
303
  pick(...names: string[]): /*elided*/ any;
298
304
  omit(...names: string[]): /*elided*/ any;
@@ -330,11 +336,12 @@ export const DATE_RANGE_SCHEMA: {
330
336
  validate(value: any, options?: {}): Promise<any>;
331
337
  clone(meta: any): /*elided*/ any;
332
338
  toOpenApi(options: any): any;
339
+ toOpenAi(): /*elided*/ any;
333
340
  toJSON(): any;
334
341
  getType(): {
335
342
  type: any;
336
343
  };
337
- getFormat(options: any): {
344
+ getFormat(): {
338
345
  format: any;
339
346
  };
340
347
  getDefault(): {
@@ -358,6 +365,7 @@ export const INCLUDE_FIELD_SCHEMA: {
358
365
  validateInput(): void;
359
366
  setup(): void;
360
367
  get(path?: string | Array<string>): any;
368
+ set(path: string | Array<string>, fn: Function): /*elided*/ any;
361
369
  unwind(path?: string | Array<string>): any;
362
370
  pick(...names: string[]): /*elided*/ any;
363
371
  omit(...names: string[]): /*elided*/ any;
@@ -395,11 +403,12 @@ export const INCLUDE_FIELD_SCHEMA: {
395
403
  validate(value: any, options?: {}): Promise<any>;
396
404
  clone(meta: any): /*elided*/ any;
397
405
  toOpenApi(options: any): any;
406
+ toOpenAi(): /*elided*/ any;
398
407
  toJSON(): any;
399
408
  getType(): {
400
409
  type: any;
401
410
  };
402
- getFormat(options: any): {
411
+ getFormat(): {
403
412
  format: any;
404
413
  };
405
414
  getDefault(): {
@@ -1 +1 @@
1
- {"version":3,"file":"validation-schemas.d.ts","sourceRoot":"","sources":["../../src/validation-schemas.js"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;;;;;;;;;;;;;;;WA2FwE,CAAC;aACjE,CAAC;uBAGc,CAAC;;;;;;;;;;;eAO2H,CAAC;;;;;;;;;;;;;;;;EAtG1F;AAE1D;;;;;;;;;;;;;;;eAwBwB,CAAC;;;;;;;;;;;;iBAoBjB,CAAC;kBAEC,CAAC;kBAEH,CAAH;oBAA8B,CAAC;oBAEhC,CAAD;;;wBA4BW,CAAC;8BAEK,CAAA;oBAEd,CAAF;oBAEiB,CAAC;oCACjB,CAAC;uBAEF,CAAD;8BACkB,CAAC;uBAAkC,CAAC;iBAA4B,CAAC;;;mBAYjC,CAAC;yBAAoC,CAAC;0BAAqC,CAAC;yBAAoC,CAAC;sBAAiC,CAAC;yBAAoC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eAA1F,CAAC;;;;;;;;;;;;;;;;EA5F/I;AAEL;;;;;;;;;;;;;;;;;kBA0Fo4B,CAAC;oBAA+B,CAAC;qBAAgC,CAAC;sBAAiC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eAAr1B,CAAC;;;;;;;;;;;;;;EAhF/I;AAEL;;;;;;;;;;;;;;;;;kBA8Eo4B,CAAC;oBAA+B,CAAC;qBAAgC,CAAC;sBAAiC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eAAr1B,CAAC;;;;;;;;;;;;;;EApE/I;AAEL;;;;;;;;;;;;;;;;;kBAkEo4B,CAAC;oBAA+B,CAAC;qBAAgC,CAAC;sBAAiC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eAAr1B,CAAC;;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