@bedrockio/model 0.13.3 → 0.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.14.0
2
+
3
+ - More clearly defined assign behavior on nested fields.
4
+ - Flat syntax will be equivalent to PATCH behavior.
5
+ - Nested syntax will be equivalent to PUT behavior.
6
+ - Both types are consistent across objects and arrays.
7
+ - Version bumps.
8
+
1
9
  ## 0.13.3
2
10
 
3
11
  - Bumped yada version.
@@ -5,62 +5,31 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.applyAssign = applyAssign;
7
7
  var _lodash = require("lodash");
8
- var _mongoose = _interopRequireDefault(require("mongoose"));
9
- var _utils = require("./utils");
10
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
8
  function applyAssign(schema) {
12
9
  schema.method('assign', function assign(fields) {
13
- unsetReferenceFields(fields, schema.obj);
14
- for (let [path, value] of Object.entries(flattenObject(fields))) {
15
- if (value === null || value === '') {
16
- this.set(path, undefined);
17
- } else {
18
- this.set(path, value);
19
- }
20
- }
10
+ fields = unsetFalsyValues(fields);
11
+ this.set(fields);
21
12
  });
22
13
  }
23
14
 
24
- // Sets falsy reference fields to undefined to signal
25
- // removal. Passing attributes through this function
26
- // normalizes falsy values so they are not saved to the db.
27
- function unsetReferenceFields(fields, schema = {}) {
28
- for (let [key, value] of Object.entries(fields)) {
29
- if (!value && (0, _utils.isReferenceField)(schema, key)) {
30
- fields[key] = undefined;
31
- } else if (value instanceof _mongoose.default.Document) {
32
- fields[key] = value;
33
- } else if (hasEnumerableFields(value)) {
34
- unsetReferenceFields(value, (0, _utils.getField)(schema, key));
35
- }
36
- }
37
- }
38
-
39
- // Flattens nested objects to a dot syntax.
40
- // Effectively the inverse of lodash get:
41
- // { foo: { bar: 3 } } -> { 'foo.bar': 3 }
42
- function flattenObject(obj, root = {}, rootPath = []) {
43
- for (let [key, val] of Object.entries(obj)) {
44
- const path = [...rootPath, key];
45
- if (hasEnumerableFields(val)) {
46
- flattenObject(val, root, path);
47
- } else {
48
- root[path.join('.')] = val;
15
+ // Force falsy fields to undefined to unset then instead of
16
+ // saving to the db (null, empty string, etc).
17
+ // Note that as of version 8.18.2 Mongoose will still happily
18
+ // set `null` or empty string directly in the db. However note
19
+ // that in mongodb querying on `null` will match both `null` and
20
+ // unset fields.
21
+ function unsetFalsyValues(arg) {
22
+ if ((0, _lodash.isPlainObject)(arg)) {
23
+ const result = {};
24
+ for (let [key, value] of Object.entries(arg)) {
25
+ result[key] = unsetFalsyValues(value);
49
26
  }
27
+ return result;
28
+ } else if (Array.isArray(arg)) {
29
+ return arg.map(unsetFalsyValues);
30
+ } else if (arg === '' || arg === null) {
31
+ return undefined;
32
+ } else {
33
+ return arg;
50
34
  }
51
- return root;
52
- }
53
-
54
- // Only plain objects and arrays with fields should
55
- // be enumerated to allow setting of their inner fields.
56
- // Note that mongoose documents etc should NOT be enumerated
57
- // over as their value should be set directly for the field.
58
- // Additionally if an array is empty it should not have its
59
- // fields enumerated but instead directly set the empty array
60
- // for the field.
61
- function hasEnumerableFields(arg) {
62
- if ((0, _lodash.isPlainObject)(arg) || Array.isArray(arg)) {
63
- return Object.keys(arg).length > 0;
64
- }
65
- return false;
66
35
  }
package/dist/cjs/cache.js CHANGED
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.applyCache = applyCache;
7
- var _mongoose = _interopRequireDefault(require("mongoose"));
8
7
  var _lodash = require("lodash");
8
+ var _mongoose = _interopRequireDefault(require("mongoose"));
9
9
  var _utils = require("./utils");
10
10
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
11
  const definitionMap = new Map();
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.applyDeleteHooks = applyDeleteHooks;
7
- var _mongoose = _interopRequireDefault(require("mongoose"));
8
7
  var _lodash = require("lodash");
8
+ var _mongoose = _interopRequireDefault(require("mongoose"));
9
9
  var _errors = require("./errors");
10
10
  var _utils = require("./utils");
11
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -8,11 +8,11 @@ exports.applyInclude = applyInclude;
8
8
  exports.checkSelects = checkSelects;
9
9
  exports.getDocumentParams = getDocumentParams;
10
10
  exports.getParams = getParams;
11
- var _mongoose = _interopRequireDefault(require("mongoose"));
12
- var _lodash = require("lodash");
13
11
  var _yada = _interopRequireDefault(require("@bedrockio/yada"));
14
- var _utils = require("./utils");
12
+ var _lodash = require("lodash");
13
+ var _mongoose = _interopRequireDefault(require("mongoose"));
15
14
  var _const = require("./const");
15
+ var _utils = require("./utils");
16
16
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
17
17
  // @ts-ignore
18
18
  // Overloading mongoose Query prototype to
package/dist/cjs/load.js CHANGED
@@ -7,8 +7,8 @@ exports.loadModel = loadModel;
7
7
  exports.loadModelDir = loadModelDir;
8
8
  var _fs = _interopRequireDefault(require("fs"));
9
9
  var _path = _interopRequireDefault(require("path"));
10
- var _mongoose = _interopRequireDefault(require("mongoose"));
11
10
  var _lodash = require("lodash");
11
+ var _mongoose = _interopRequireDefault(require("mongoose"));
12
12
  var _schema = require("./schema");
13
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
14
  /**
@@ -5,21 +5,21 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.createSchema = createSchema;
7
7
  exports.normalizeAttributes = normalizeAttributes;
8
- var _mongoose = _interopRequireDefault(require("mongoose"));
9
8
  var _lodash = require("lodash");
10
- var _utils = require("./utils");
11
- var _serialization = require("./serialization");
12
- var _slug = require("./slug");
9
+ var _mongoose = _interopRequireDefault(require("mongoose"));
10
+ var _assign = require("./assign");
13
11
  var _cache = require("./cache");
14
12
  var _clone = require("./clone");
15
- var _search = require("./search");
16
- var _assign = require("./assign");
17
- var _upsert = require("./upsert");
13
+ var _deleteHooks = require("./delete-hooks");
14
+ var _disallowed = require("./disallowed");
18
15
  var _hydrate = require("./hydrate");
19
16
  var _include = require("./include");
17
+ var _search = require("./search");
18
+ var _serialization = require("./serialization");
19
+ var _slug = require("./slug");
20
20
  var _softDelete = require("./soft-delete");
21
- var _deleteHooks = require("./delete-hooks");
22
- var _disallowed = require("./disallowed");
21
+ var _upsert = require("./upsert");
22
+ var _utils = require("./utils");
23
23
  var _validation = require("./validation");
24
24
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
25
25
  /**
@@ -6,15 +6,15 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.applySearch = applySearch;
7
7
  exports.exportValidation = exportValidation;
8
8
  exports.searchValidation = searchValidation;
9
- var _yada = _interopRequireDefault(require("@bedrockio/yada"));
10
9
  var _logger = _interopRequireDefault(require("@bedrockio/logger"));
11
- var _mongoose = _interopRequireDefault(require("mongoose"));
10
+ var _yada = _interopRequireDefault(require("@bedrockio/yada"));
12
11
  var _lodash = require("lodash");
13
- var _utils = require("./utils");
12
+ var _mongoose = _interopRequireDefault(require("mongoose"));
14
13
  var _const = require("./const");
15
- var _validationSchemas = require("./validation-schemas");
16
14
  var _env = require("./env");
17
15
  var _query = require("./query");
16
+ var _utils = require("./utils");
17
+ var _validationSchemas = require("./validation-schemas");
18
18
  var _warn = _interopRequireDefault(require("./warn"));
19
19
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
20
20
  const {
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.serializeOptions = void 0;
7
7
  var _lodash = require("lodash");
8
+ var _access = require("./access");
8
9
  var _include = require("./include");
9
10
  var _utils = require("./utils");
10
- var _access = require("./access");
11
11
  const DISALLOWED_FIELDS = ['deleted', 'deletedRefs'];
12
12
  const serializeOptions = exports.serializeOptions = {
13
13
  getters: true,
@@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.applySoftDelete = applySoftDelete;
7
7
  exports.assertUnique = assertUnique;
8
8
  var _lodash = require("lodash");
9
- var _warn = _interopRequireDefault(require("./warn"));
10
- var _query = require("./query");
11
9
  var _errors = require("./errors");
10
+ var _query = require("./query");
11
+ var _warn = _interopRequireDefault(require("./warn"));
12
12
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
13
  function applySoftDelete(schema) {
14
14
  applyQueries(schema);
@@ -8,15 +8,15 @@ exports.applyValidation = applyValidation;
8
8
  exports.getNamedValidator = getNamedValidator;
9
9
  exports.getTupleValidator = getTupleValidator;
10
10
  exports.getValidationSchema = getValidationSchema;
11
- var _mongoose = _interopRequireDefault(require("mongoose"));
12
11
  var _yada = _interopRequireDefault(require("@bedrockio/yada"));
13
12
  var _lodash = require("lodash");
13
+ var _mongoose = _interopRequireDefault(require("mongoose"));
14
14
  var _access = require("./access");
15
+ var _errors = require("./errors");
16
+ var _include = require("./include");
15
17
  var _search = require("./search");
16
18
  var _softDelete = require("./soft-delete");
17
- var _errors = require("./errors");
18
19
  var _utils = require("./utils");
19
- var _include = require("./include");
20
20
  var _validationSchemas = require("./validation-schemas");
21
21
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
22
22
  const NAMED_SCHEMAS = {
@@ -80,6 +80,7 @@ function applyValidation(schema, definition) {
80
80
  skipRequired: true,
81
81
  stripUnknown: true,
82
82
  stripDeleted: true,
83
+ allowFlatKeys: true,
83
84
  allowInclude: false,
84
85
  stripTimestamps: true,
85
86
  allowExpandedRefs: true,
@@ -103,6 +104,7 @@ function applyValidation(schema, definition) {
103
104
  skipRequired: true,
104
105
  allowInclude: true,
105
106
  stripDeleted: true,
107
+ allowFlatKeys: true,
106
108
  unwindArrayFields: true,
107
109
  requireReadAccess: true,
108
110
  ...rest
@@ -187,7 +189,8 @@ function getObjectSchema(arg, options) {
187
189
  } else if (typeof arg === 'object') {
188
190
  const {
189
191
  stripUnknown,
190
- stripEmpty
192
+ stripEmpty,
193
+ allowFlatKeys
191
194
  } = options;
192
195
  const map = {};
193
196
  for (let [key, field] of Object.entries(arg)) {
@@ -206,6 +209,11 @@ function getObjectSchema(arg, options) {
206
209
  stripEmpty: true
207
210
  });
208
211
  }
212
+ if (allowFlatKeys) {
213
+ schema = schema.options({
214
+ allowFlatKeys: true
215
+ });
216
+ }
209
217
  return schema;
210
218
  } else {
211
219
  return getSchemaForType(arg, options);
package/eslint.config.js CHANGED
@@ -1,2 +1,2 @@
1
- import { jest, recommended, nodeImports } from '@bedrockio/eslint-plugin';
1
+ import { jest, nodeImports, recommended } from '@bedrockio/eslint-plugin';
2
2
  export default [jest, recommended, nodeImports];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bedrockio/model",
3
- "version": "0.13.3",
3
+ "version": "0.14.0",
4
4
  "description": "Bedrock utilities for model creation.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -31,23 +31,23 @@
31
31
  },
32
32
  "peerDependencies": {
33
33
  "@bedrockio/yada": "^1.6.1",
34
- "mongoose": "^8.13.1"
34
+ "mongoose": "^8.18.2"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@babel/cli": "^7.26.4",
38
38
  "@babel/core": "^7.26.0",
39
39
  "@babel/preset-env": "^7.26.0",
40
- "@bedrockio/eslint-plugin": "^1.1.7",
41
- "@bedrockio/prettier-config": "^1.0.2",
40
+ "@bedrockio/eslint-plugin": "^1.2.2",
41
+ "@bedrockio/prettier-config": "^1.1.1",
42
42
  "@bedrockio/yada": "^1.6.1",
43
- "@shelf/jest-mongodb": "^5.1.0",
44
- "eslint": "^9.19.0",
45
- "jest": "^29.7.0",
46
- "jest-environment-node": "^29.7.0",
47
- "mongodb": "^6.15.0",
48
- "mongoose": "^8.13.1",
49
- "prettier": "^3.4.2",
50
- "typescript": "^5.7.2"
43
+ "@shelf/jest-mongodb": "^5.2.2",
44
+ "eslint": "^9.36.0",
45
+ "jest": "^30.2.0",
46
+ "jest-environment-node": "^30.2.0",
47
+ "mongodb": "^6.20.0",
48
+ "mongoose": "^8.18.2",
49
+ "prettier": "^3.6.2",
50
+ "typescript": "^5.9.2"
51
51
  },
52
52
  "prettier": "@bedrockio/prettier-config",
53
53
  "volta": {
package/src/assign.js CHANGED
@@ -1,61 +1,30 @@
1
1
  import { isPlainObject } from 'lodash';
2
- import mongoose from 'mongoose';
3
-
4
- import { isReferenceField, getField } from './utils';
5
2
 
6
3
  export function applyAssign(schema) {
7
4
  schema.method('assign', function assign(fields) {
8
- unsetReferenceFields(fields, schema.obj);
9
- for (let [path, value] of Object.entries(flattenObject(fields))) {
10
- if (value === null || value === '') {
11
- this.set(path, undefined);
12
- } else {
13
- this.set(path, value);
14
- }
15
- }
5
+ fields = unsetFalsyValues(fields);
6
+ this.set(fields);
16
7
  });
17
8
  }
18
9
 
19
- // Sets falsy reference fields to undefined to signal
20
- // removal. Passing attributes through this function
21
- // normalizes falsy values so they are not saved to the db.
22
- function unsetReferenceFields(fields, schema = {}) {
23
- for (let [key, value] of Object.entries(fields)) {
24
- if (!value && isReferenceField(schema, key)) {
25
- fields[key] = undefined;
26
- } else if (value instanceof mongoose.Document) {
27
- fields[key] = value;
28
- } else if (hasEnumerableFields(value)) {
29
- unsetReferenceFields(value, getField(schema, key));
10
+ // Force falsy fields to undefined to unset then instead of
11
+ // saving to the db (null, empty string, etc).
12
+ // Note that as of version 8.18.2 Mongoose will still happily
13
+ // set `null` or empty string directly in the db. However note
14
+ // that in mongodb querying on `null` will match both `null` and
15
+ // unset fields.
16
+ function unsetFalsyValues(arg) {
17
+ if (isPlainObject(arg)) {
18
+ const result = {};
19
+ for (let [key, value] of Object.entries(arg)) {
20
+ result[key] = unsetFalsyValues(value);
30
21
  }
22
+ return result;
23
+ } else if (Array.isArray(arg)) {
24
+ return arg.map(unsetFalsyValues);
25
+ } else if (arg === '' || arg === null) {
26
+ return undefined;
27
+ } else {
28
+ return arg;
31
29
  }
32
30
  }
33
-
34
- // Flattens nested objects to a dot syntax.
35
- // Effectively the inverse of lodash get:
36
- // { foo: { bar: 3 } } -> { 'foo.bar': 3 }
37
- function flattenObject(obj, root = {}, rootPath = []) {
38
- for (let [key, val] of Object.entries(obj)) {
39
- const path = [...rootPath, key];
40
- if (hasEnumerableFields(val)) {
41
- flattenObject(val, root, path);
42
- } else {
43
- root[path.join('.')] = val;
44
- }
45
- }
46
- return root;
47
- }
48
-
49
- // Only plain objects and arrays with fields should
50
- // be enumerated to allow setting of their inner fields.
51
- // Note that mongoose documents etc should NOT be enumerated
52
- // over as their value should be set directly for the field.
53
- // Additionally if an array is empty it should not have its
54
- // fields enumerated but instead directly set the empty array
55
- // for the field.
56
- function hasEnumerableFields(arg) {
57
- if (isPlainObject(arg) || Array.isArray(arg)) {
58
- return Object.keys(arg).length > 0;
59
- }
60
- return false;
61
- }
package/src/cache.js CHANGED
@@ -1,5 +1,5 @@
1
+ import { get, groupBy, once } from 'lodash';
1
2
  import mongoose from 'mongoose';
2
- import { get, once, groupBy } from 'lodash';
3
3
 
4
4
  import { resolveRefPath } from './utils';
5
5
 
@@ -1,5 +1,5 @@
1
- import mongoose from 'mongoose';
2
1
  import { groupBy } from 'lodash';
2
+ import mongoose from 'mongoose';
3
3
 
4
4
  import { ReferenceError } from './errors';
5
5
  import { getInnerField } from './utils';
package/src/include.js CHANGED
@@ -1,9 +1,9 @@
1
- import mongoose from 'mongoose';
2
- import { escapeRegExp } from 'lodash';
3
1
  import yd from '@bedrockio/yada';
2
+ import { escapeRegExp } from 'lodash';
3
+ import mongoose from 'mongoose';
4
4
 
5
- import { getInnerField, isSchemaTypedef } from './utils';
6
5
  import { POPULATE_MAX_DEPTH } from './const';
6
+ import { getInnerField, isSchemaTypedef } from './utils';
7
7
 
8
8
  // @ts-ignore
9
9
  // Overloading mongoose Query prototype to
package/src/load.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
3
 
4
- import mongoose from 'mongoose';
5
4
  import { startCase } from 'lodash';
5
+ import mongoose from 'mongoose';
6
6
 
7
7
  import { createSchema } from './schema';
8
8
 
package/src/schema.js CHANGED
@@ -1,20 +1,19 @@
1
+ import { camelCase, capitalize, isPlainObject, pick } from 'lodash';
1
2
  import mongoose from 'mongoose';
2
- import { pick, isPlainObject, capitalize, camelCase } from 'lodash';
3
3
 
4
- import { isSchemaTypedef } from './utils';
5
-
6
- import { serializeOptions } from './serialization';
7
- import { applySlug } from './slug';
4
+ import { applyAssign } from './assign';
8
5
  import { applyCache } from './cache';
9
6
  import { applyClone } from './clone';
10
- import { applySearch } from './search';
11
- import { applyAssign } from './assign';
12
- import { applyUpsert } from './upsert';
7
+ import { applyDeleteHooks } from './delete-hooks';
8
+ import { applyDisallowed } from './disallowed';
13
9
  import { applyHydrate } from './hydrate';
14
10
  import { applyInclude } from './include';
11
+ import { applySearch } from './search';
12
+ import { serializeOptions } from './serialization';
13
+ import { applySlug } from './slug';
15
14
  import { applySoftDelete } from './soft-delete';
16
- import { applyDeleteHooks } from './delete-hooks';
17
- import { applyDisallowed } from './disallowed';
15
+ import { applyUpsert } from './upsert';
16
+ import { isSchemaTypedef } from './utils';
18
17
 
19
18
  import {
20
19
  applyValidation,
package/src/search.js CHANGED
@@ -1,7 +1,11 @@
1
- import yd from '@bedrockio/yada';
2
1
  import logger from '@bedrockio/logger';
2
+ import yd from '@bedrockio/yada';
3
+ import { escapeRegExp, isEmpty, isPlainObject, memoize, pick } from 'lodash';
3
4
  import mongoose from 'mongoose';
4
- import { pick, isEmpty, memoize, escapeRegExp, isPlainObject } from 'lodash';
5
+
6
+ import { SEARCH_DEFAULTS } from './const';
7
+ import { debug } from './env';
8
+ import { mergeQuery, wrapQuery } from './query';
5
9
 
6
10
  import {
7
11
  getField,
@@ -12,11 +16,7 @@ import {
12
16
  resolveRefPath,
13
17
  } from './utils';
14
18
 
15
- import { SEARCH_DEFAULTS } from './const';
16
19
  import { OBJECT_ID_SCHEMA } from './validation-schemas';
17
- import { debug } from './env';
18
- import { mergeQuery, wrapQuery } from './query';
19
-
20
20
  import warn from './warn';
21
21
 
22
22
  const { ObjectId } = mongoose.Types;
@@ -1,8 +1,8 @@
1
1
  import { isPlainObject } from 'lodash';
2
2
 
3
+ import { hasAccess } from './access';
3
4
  import { checkSelects } from './include';
4
5
  import { getField, getInnerField } from './utils';
5
- import { hasAccess } from './access';
6
6
 
7
7
  const DISALLOWED_FIELDS = ['deleted', 'deletedRefs'];
8
8
 
@@ -1,9 +1,8 @@
1
1
  import { isEqual } from 'lodash';
2
2
 
3
- import warn from './warn';
4
-
5
- import { wrapQuery } from './query';
6
3
  import { UniqueConstraintError } from './errors';
4
+ import { wrapQuery } from './query';
5
+ import warn from './warn';
7
6
 
8
7
  export function applySoftDelete(schema) {
9
8
  applyQueries(schema);
package/src/validation.js CHANGED
@@ -1,21 +1,21 @@
1
- import mongoose from 'mongoose';
2
1
  import yd from '@bedrockio/yada';
3
-
4
- import { get, omit, lowerFirst } from 'lodash';
2
+ import { get, lowerFirst, omit } from 'lodash';
3
+ import mongoose from 'mongoose';
5
4
 
6
5
  import { hasAccess } from './access';
7
- import { searchValidation, exportValidation } from './search';
6
+ import { ImplementationError, PermissionsError } from './errors';
7
+ import { INCLUDE_FIELD_SCHEMA } from './include';
8
+ import { exportValidation, searchValidation } from './search';
8
9
  import { assertUnique } from './soft-delete';
9
- import { PermissionsError, ImplementationError } from './errors';
10
10
  import { isMongooseSchema, isSchemaTypedef } from './utils';
11
- import { INCLUDE_FIELD_SCHEMA } from './include';
11
+
12
12
  import {
13
+ DATE_RANGE_SCHEMA,
13
14
  DATE_SCHEMA,
14
- REFERENCE_SCHEMA,
15
- OBJECT_ID_SCHEMA,
16
15
  NUMBER_RANGE_SCHEMA,
16
+ OBJECT_ID_SCHEMA,
17
+ REFERENCE_SCHEMA,
17
18
  STRING_RANGE_SCHEMA,
18
- DATE_RANGE_SCHEMA,
19
19
  } from './validation-schemas';
20
20
 
21
21
  const NAMED_SCHEMAS = {
@@ -84,6 +84,7 @@ export function applyValidation(schema, definition) {
84
84
  skipRequired: true,
85
85
  stripUnknown: true,
86
86
  stripDeleted: true,
87
+ allowFlatKeys: true,
87
88
  allowInclude: false,
88
89
  stripTimestamps: true,
89
90
  allowExpandedRefs: true,
@@ -106,6 +107,7 @@ export function applyValidation(schema, definition) {
106
107
  skipRequired: true,
107
108
  allowInclude: true,
108
109
  stripDeleted: true,
110
+ allowFlatKeys: true,
109
111
  unwindArrayFields: true,
110
112
  requireReadAccess: true,
111
113
  ...rest,
@@ -199,7 +201,7 @@ function getObjectSchema(arg, options) {
199
201
  } else if (Array.isArray(arg)) {
200
202
  return getArraySchema(arg, options);
201
203
  } else if (typeof arg === 'object') {
202
- const { stripUnknown, stripEmpty } = options;
204
+ const { stripUnknown, stripEmpty, allowFlatKeys } = options;
203
205
  const map = {};
204
206
  for (let [key, field] of Object.entries(arg)) {
205
207
  if (!isExcludedField(field, options)) {
@@ -221,6 +223,12 @@ function getObjectSchema(arg, options) {
221
223
  });
222
224
  }
223
225
 
226
+ if (allowFlatKeys) {
227
+ schema = schema.options({
228
+ allowFlatKeys: true,
229
+ });
230
+ }
231
+
224
232
  return schema;
225
233
  } else {
226
234
  return getSchemaForType(arg, options);
@@ -1 +1 @@
1
- {"version":3,"file":"assign.d.ts","sourceRoot":"","sources":["../src/assign.js"],"names":[],"mappings":"AAKA,+CAWC"}
1
+ {"version":3,"file":"assign.d.ts","sourceRoot":"","sources":["../src/assign.js"],"names":[],"mappings":"AAEA,+CAKC"}
@@ -14,7 +14,8 @@ export const INCLUDE_FIELD_SCHEMA: {
14
14
  options(options?: {
15
15
  stripEmpty?: boolean;
16
16
  stripUnknown?: boolean;
17
- preserveKeys?: boolean;
17
+ allowFlatKeys?: boolean;
18
+ expandFlatKeys?: boolean;
18
19
  }): /*elided*/ any;
19
20
  format(name: any, fn: any): /*elided*/ any;
20
21
  toString(): any;
@@ -1 +1 @@
1
- {"version":3,"file":"include.d.ts","sourceRoot":"","sources":["../src/include.js"],"names":[],"mappings":"AA2BA,gDAuEC;AAMD,uDA4BC;AAGD,yDAIC;AAaD,yEAUC;AA9ID;;;;;;;;;;kBAyFsB,CAAC;oBACD,CAAC;oBACE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;eApBT,CAAC;;;;;;;;;;;;;;;;;EAlEf"}
1
+ {"version":3,"file":"include.d.ts","sourceRoot":"","sources":["../src/include.js"],"names":[],"mappings":"AA2BA,gDAuEC;AAMD,uDA4BC;AAGD,yDAIC;AAaD,yEAUC;AA9ID;;;;;;;;;;kBA6FQ,CAAL;oBAA+B,CAAC;qBAE7B,CAAN;sBACkB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;eAzBF,CAAC;;;;;;;;;;;;;;;;;EAlEf"}
@@ -1 +1 @@
1
- {"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../src/load.js"],"names":[],"mappings":"AAQA;;;;;GAKG;AACH,sCAJW,MAAM,QACN,MAAM,OAahB;AAED;;;;GAIG;AACH,sCAFW,MAAM,mBAkBhB;qBA5CoB,UAAU"}
1
+ {"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../src/load.js"],"names":[],"mappings":"AAQA;;;;;GAKG;AACH,sCAJW,MAAM,QACN,MAAM,OAahB;AAED;;;;GAIG;AACH,sCAFW,MAAM,mBAkBhB;qBA3CoB,UAAU"}
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":"AAwBA;;;;;;;GAOG;AACH,yCAJW,MAAM,YACN,QAAQ,CAAC,aAAa;;;;;;;YA6CM,CAAC;WACtC,CAAF;mBAAqB,CAAC;;;;;;;;;;;;;;;;;;;;;SAiHV,CAAA;gBAA2B,CAAC;SAAW,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aApHnD;AAED,iEAsBC;qBAhGoB,UAAU"}
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.js"],"names":[],"mappings":"AAuBA;;;;;;;GAOG;AACH,yCAJW,MAAM,YACN,QAAQ,CAAC,aAAa;;;;;;;YAgDJ,CAAC;WAC1B,CAAF;mBAAqB,CAAC;;;;;;;;;;;;;;;;;;;;;;;SA2HlB,CAAC;gBACL,CAAC;SAAW,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAlId;AAED,iEAsBC;qBA9FoB,UAAU"}
package/types/search.d.ts CHANGED
@@ -11,7 +11,8 @@ export function searchValidation(options?: {}): {
11
11
  options(options?: {
12
12
  stripEmpty?: boolean;
13
13
  stripUnknown?: boolean;
14
- preserveKeys?: boolean;
14
+ allowFlatKeys?: boolean;
15
+ expandFlatKeys?: boolean;
15
16
  }): /*elided*/ any;
16
17
  format(name: any, fn: any): /*elided*/ any;
17
18
  toString(): any;
@@ -1 +1 @@
1
- {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.js"],"names":[],"mappings":"AAuBA,gEAaC;AAED;;;;;;;;;;kBA0Fe,CAAC;oBAA+B,CAAC;oBAEtB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;eAhCvB,CAAF;;;;;;;;;;;;;;;;;EAnCD;AAED;;;;;;;;;;;;;;;;;mBAtBI,CAAA;;;;;;;;;;;;qBAuBC,CAAC;sBAA4B,CAAC;sBACvB,CAAC;wBAA8B,CAAC;wBAEnC,CAAC;;;4BA2BK,CAAC;kCACwB,CAAC;wBACrC,CAAA;wBAA+B,CAAC;wCAK9B,CAAJ;2BAAkC,CAAC;kCACP,CAAC;2BAIhB,CAAC;qBAA4B,CAAC;;;uBAsBT,CAAC;6BACH,CAAC;8BAI7B,CAAF;6BAAoC,CAAC;0BAClB,CAAC;6BAIhB,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBA1CJ,CAAF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAvDE,CAAA;;;;;;;;;;;;qBAuBC,CAAC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;uBAsBT,CAAC;6BACH,CAAC;8BAI7B,CAAF;6BAAoC,CAAC;0BAClB,CAAC;6BAIhB,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBA1CJ,CAAF;;;;;;;;;;;;;;;;;;;EApBD"}
@@ -1 +1 @@
1
- {"version":3,"file":"soft-delete.d.ts","sourceRoot":"","sources":["../src/soft-delete.js"],"names":[],"mappings":"AAOA,mDAIC;AAED,0DAwBC"}
1
+ {"version":3,"file":"soft-delete.d.ts","sourceRoot":"","sources":["../src/soft-delete.js"],"names":[],"mappings":"AAMA,mDAIC;AAED,0DAwBC"}
@@ -164,7 +164,8 @@ export const NUMBER_RANGE_SCHEMA: {
164
164
  options(options?: {
165
165
  stripEmpty?: boolean;
166
166
  stripUnknown?: boolean;
167
- preserveKeys?: boolean;
167
+ allowFlatKeys?: boolean;
168
+ expandFlatKeys?: boolean;
168
169
  }): /*elided*/ any;
169
170
  format(name: any, fn: any): /*elided*/ any;
170
171
  toString(): any;
@@ -219,7 +220,8 @@ export const STRING_RANGE_SCHEMA: {
219
220
  options(options?: {
220
221
  stripEmpty?: boolean;
221
222
  stripUnknown?: boolean;
222
- preserveKeys?: boolean;
223
+ allowFlatKeys?: boolean;
224
+ expandFlatKeys?: boolean;
223
225
  }): /*elided*/ any;
224
226
  format(name: any, fn: any): /*elided*/ any;
225
227
  toString(): any;
@@ -274,7 +276,8 @@ export const DATE_RANGE_SCHEMA: {
274
276
  options(options?: {
275
277
  stripEmpty?: boolean;
276
278
  stripUnknown?: boolean;
277
- preserveKeys?: boolean;
279
+ allowFlatKeys?: boolean;
280
+ expandFlatKeys?: boolean;
278
281
  }): /*elided*/ any;
279
282
  format(name: any, fn: any): /*elided*/ any;
280
283
  toString(): any;
@@ -1 +1 @@
1
- {"version":3,"file":"validation-schemas.d.ts","sourceRoot":"","sources":["../src/validation-schemas.js"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eAsFgD,CAAC;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AyC,CAAC;uBACzD,CAAC;iBAA4B,CAAC;;;mBAG0V,CAAC;yBAAoC,CAAC;0BAAqC,CAAC;yBAAoC,CAAC;sBAAiC,CAAC;yBAAoC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eAR1hB,CAAC;;;;;;;;;;;;;;;;;;EA5E5C;AAEL;;;;;;;;;;kBAkFkb,CAAC;oBAA+B,CAAC;qBAAgC,CAAC;sBAAiC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;eARte,CAAC;;;;;;;;;;;;;;;;;EAhE5C;AAEL;;;;;;;;;;kBAsEkb,CAAC;oBAA+B,CAAC;qBAAgC,CAAC;sBAAiC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;eARte,CAAC;;;;;;;;;;;;;;;;;EApD5C;AAEL;;;;;;;;;;kBA0Dkb,CAAC;oBAA+B,CAAC;qBAAgC,CAAC;sBAAiC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;eARte,CAAC;;;;;;;;;;;;;;;;;EAhB5C;AAEL,8EAqBK"}
@@ -1 +1 @@
1
- {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.js"],"names":[],"mappings":"AA0DA,kDAEC;AAED,oEA0FC;AAsBD,wEAiBC;AAwSD;;;EAEC;AAED;;;EAOC"}
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.js"],"names":[],"mappings":"AA0DA,kDAEC;AAED,oEA4FC;AAsBD,wEAiBC;AA8SD;;;EAEC;AAED;;;EAOC"}