@bedrockio/model 0.3.1 → 0.3.2

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.
@@ -5,14 +5,15 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.applyAssign = applyAssign;
7
7
  var _lodash = require("lodash");
8
+ var _mongoose = _interopRequireDefault(require("mongoose"));
8
9
  var _utils = require("./utils");
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
11
  function applyAssign(schema) {
10
12
  schema.method('assign', function assign(fields) {
11
13
  unsetReferenceFields(fields, schema.obj);
12
14
  for (let [path, value] of Object.entries(flattenObject(fields))) {
13
15
  if (value === null) {
14
16
  this.set(path, undefined);
15
- this.markModified(path);
16
17
  } else {
17
18
  this.set(path, value);
18
19
  }
@@ -27,6 +28,8 @@ function unsetReferenceFields(fields, schema = {}) {
27
28
  for (let [key, value] of Object.entries(fields)) {
28
29
  if (!value && (0, _utils.isReferenceField)(schema, key)) {
29
30
  fields[key] = undefined;
31
+ } else if (value instanceof _mongoose.default.Document) {
32
+ fields[key] = value;
30
33
  } else if (value && typeof value === 'object') {
31
34
  unsetReferenceFields(value, (0, _utils.getField)(schema, key));
32
35
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bedrockio/model",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
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.20.2",
40
40
  "@bedrockio/prettier-config": "^1.0.2",
41
41
  "@bedrockio/yada": "^1.0.40",
42
- "@shelf/jest-mongodb": "^4.2.0",
42
+ "@shelf/jest-mongodb": "^4.3.2",
43
43
  "eslint": "^8.33.0",
44
44
  "eslint-plugin-bedrock": "^1.0.26",
45
45
  "jest": "^29.4.1",
package/src/assign.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { isPlainObject } from 'lodash';
2
+ import mongoose from 'mongoose';
2
3
 
3
4
  import { isReferenceField, getField } from './utils';
4
5
 
@@ -8,7 +9,6 @@ export function applyAssign(schema) {
8
9
  for (let [path, value] of Object.entries(flattenObject(fields))) {
9
10
  if (value === null) {
10
11
  this.set(path, undefined);
11
- this.markModified(path);
12
12
  } else {
13
13
  this.set(path, value);
14
14
  }
@@ -23,6 +23,8 @@ function unsetReferenceFields(fields, schema = {}) {
23
23
  for (let [key, value] of Object.entries(fields)) {
24
24
  if (!value && isReferenceField(schema, key)) {
25
25
  fields[key] = undefined;
26
+ } else if (value instanceof mongoose.Document) {
27
+ fields[key] = value;
26
28
  } else if (value && typeof value === 'object') {
27
29
  unsetReferenceFields(value, getField(schema, key));
28
30
  }
@@ -1 +1 @@
1
- {"version":3,"file":"assign.d.ts","sourceRoot":"","sources":["../src/assign.js"],"names":[],"mappings":"AAIA,+CAYC"}
1
+ {"version":3,"file":"assign.d.ts","sourceRoot":"","sources":["../src/assign.js"],"names":[],"mappings":"AAKA,+CAWC"}
@@ -14,7 +14,7 @@ export const INCLUDE_FIELD_SCHEMA: {
14
14
  meta: {};
15
15
  required(): any;
16
16
  default(arg: any): any;
17
- custom(...args: import("@bedrockio/yada/types/Schema").CustomSignature): any;
17
+ custom(fn: Function): any;
18
18
  strip(strip: any): any;
19
19
  allow(...set: any[]): any;
20
20
  reject(...set: any[]): any;
package/types/schema.d.ts CHANGED
@@ -31,6 +31,9 @@ export function createSchema(definition: object, options?: mongoose.SchemaOption
31
31
  optimisticConcurrency?: boolean;
32
32
  pluginTags?: string[];
33
33
  read?: string;
34
+ readConcern?: {
35
+ level: "local" | "available" | "majority" | "snapshot" | "linearizable";
36
+ };
34
37
  writeConcern?: mongoose.mongo.WriteConcern;
35
38
  safe?: boolean | {
36
39
  w?: string | number;
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.js"],"names":[],"mappings":"AAoBA;;;;;;;GAOG;AACH,yCAJW,MAAM,YACN,SAAS,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAuChC;AAED,iEAsBC"}
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.js"],"names":[],"mappings":"AAoBA;;;;;;;GAOG;AACH,yCAJW,MAAM,YACN,SAAS,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAuChC;AAED,iEAsBC"}
package/types/search.d.ts CHANGED
@@ -11,7 +11,7 @@ export function searchValidation(options?: {}): {
11
11
  meta: {};
12
12
  required(): any;
13
13
  default(arg: any): any;
14
- custom(...args: import("@bedrockio/yada/types/Schema").CustomSignature): any;
14
+ custom(fn: Function): any;
15
15
  strip(strip: any): any;
16
16
  allow(...set: any[]): any;
17
17
  reject(...set: any[]): any;
@@ -73,7 +73,7 @@ export const OBJECT_ID_SCHEMA: {
73
73
  assertions: any[];
74
74
  meta: {};
75
75
  default(arg: any): any;
76
- custom(...args: import("@bedrockio/yada/types/Schema").CustomSignature): any;
76
+ custom(fn: Function): any;
77
77
  strip(strip: any): any;
78
78
  allow(...set: any[]): any;
79
79
  reject(...set: any[]): any;