@bedrockio/model 0.19.3 → 0.20.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.
Files changed (95) hide show
  1. package/.claude/settings.local.json +22 -1
  2. package/CHANGELOG.md +4 -0
  3. package/README.md +29 -0
  4. package/dist/cjs/schema.js +2 -2
  5. package/package.json +3 -3
  6. package/src/schema.js +2 -2
  7. package/tsconfig.validate.json +8 -0
  8. package/types/generated/access.d.ts.map +1 -0
  9. package/types/{assign.d.ts.map → generated/assign.d.ts.map} +1 -1
  10. package/types/{cache.d.ts.map → generated/cache.d.ts.map} +1 -1
  11. package/types/{clone.d.ts.map → generated/clone.d.ts.map} +1 -1
  12. package/types/generated/const.d.ts.map +1 -0
  13. package/types/generated/delete-hooks.d.ts.map +1 -0
  14. package/types/{disallowed.d.ts.map → generated/disallowed.d.ts.map} +1 -1
  15. package/types/generated/env.d.ts.map +1 -0
  16. package/types/generated/errors.d.ts.map +1 -0
  17. package/types/{export.d.ts.map → generated/export.d.ts.map} +1 -1
  18. package/types/{hydrate.d.ts.map → generated/hydrate.d.ts.map} +1 -1
  19. package/types/generated/include.d.ts.map +1 -0
  20. package/types/generated/index.d.ts +7 -0
  21. package/types/{index.d.ts.map → generated/index.d.ts.map} +1 -1
  22. package/types/generated/load.d.ts.map +1 -0
  23. package/types/{query.d.ts.map → generated/query.d.ts.map} +1 -1
  24. package/types/{reload.d.ts.map → generated/reload.d.ts.map} +1 -1
  25. package/types/generated/schema.d.ts +12 -0
  26. package/types/generated/schema.d.ts.map +1 -0
  27. package/types/{search.d.ts → generated/search.d.ts} +7 -2
  28. package/types/generated/search.d.ts.map +1 -0
  29. package/types/generated/serialization.d.ts.map +1 -0
  30. package/types/generated/slug.d.ts.map +1 -0
  31. package/types/generated/soft-delete.d.ts.map +1 -0
  32. package/types/generated/testing.d.ts.map +1 -0
  33. package/types/{upsert.d.ts.map → generated/upsert.d.ts.map} +1 -1
  34. package/types/generated/utils.d.ts.map +1 -0
  35. package/types/{validation-schemas.d.ts → generated/validation-schemas.d.ts} +28 -8
  36. package/types/generated/validation-schemas.d.ts.map +1 -0
  37. package/types/generated/validation.d.ts.map +1 -0
  38. package/types/generated/warn.d.ts.map +1 -0
  39. package/types/index.d.ts +22 -7
  40. package/types/modules/assign.d.ts +22 -0
  41. package/types/modules/cache.d.ts +31 -0
  42. package/types/modules/clone.d.ts +18 -0
  43. package/types/modules/delete-hooks.d.ts +33 -0
  44. package/types/modules/export.d.ts +17 -0
  45. package/types/modules/hydrate.d.ts +37 -0
  46. package/types/modules/include.d.ts +92 -0
  47. package/types/modules/reload.d.ts +17 -0
  48. package/types/modules/search.d.ts +137 -0
  49. package/types/modules/slug.d.ts +80 -0
  50. package/types/modules/soft-delete.d.ts +458 -0
  51. package/types/modules/upsert.d.ts +67 -0
  52. package/types/modules/validation.d.ts +145 -0
  53. package/types/access.d.ts.map +0 -1
  54. package/types/const.d.ts.map +0 -1
  55. package/types/delete-hooks.d.ts.map +0 -1
  56. package/types/env.d.ts.map +0 -1
  57. package/types/errors.d.ts.map +0 -1
  58. package/types/include.d.ts.map +0 -1
  59. package/types/load.d.ts.map +0 -1
  60. package/types/references.d.ts +0 -2
  61. package/types/references.d.ts.map +0 -1
  62. package/types/schema.d.ts +0 -76
  63. package/types/schema.d.ts.map +0 -1
  64. package/types/search.d.ts.map +0 -1
  65. package/types/serialization.d.ts.map +0 -1
  66. package/types/slug.d.ts.map +0 -1
  67. package/types/soft-delete.d.ts.map +0 -1
  68. package/types/testing.d.ts.map +0 -1
  69. package/types/utils.d.ts.map +0 -1
  70. package/types/validation-schemas.d.ts.map +0 -1
  71. package/types/validation.d.ts.map +0 -1
  72. package/types/warn.d.ts.map +0 -1
  73. /package/types/{access.d.ts → generated/access.d.ts} +0 -0
  74. /package/types/{assign.d.ts → generated/assign.d.ts} +0 -0
  75. /package/types/{cache.d.ts → generated/cache.d.ts} +0 -0
  76. /package/types/{clone.d.ts → generated/clone.d.ts} +0 -0
  77. /package/types/{const.d.ts → generated/const.d.ts} +0 -0
  78. /package/types/{delete-hooks.d.ts → generated/delete-hooks.d.ts} +0 -0
  79. /package/types/{disallowed.d.ts → generated/disallowed.d.ts} +0 -0
  80. /package/types/{env.d.ts → generated/env.d.ts} +0 -0
  81. /package/types/{errors.d.ts → generated/errors.d.ts} +0 -0
  82. /package/types/{export.d.ts → generated/export.d.ts} +0 -0
  83. /package/types/{hydrate.d.ts → generated/hydrate.d.ts} +0 -0
  84. /package/types/{include.d.ts → generated/include.d.ts} +0 -0
  85. /package/types/{load.d.ts → generated/load.d.ts} +0 -0
  86. /package/types/{query.d.ts → generated/query.d.ts} +0 -0
  87. /package/types/{reload.d.ts → generated/reload.d.ts} +0 -0
  88. /package/types/{serialization.d.ts → generated/serialization.d.ts} +0 -0
  89. /package/types/{slug.d.ts → generated/slug.d.ts} +0 -0
  90. /package/types/{soft-delete.d.ts → generated/soft-delete.d.ts} +0 -0
  91. /package/types/{testing.d.ts → generated/testing.d.ts} +0 -0
  92. /package/types/{upsert.d.ts → generated/upsert.d.ts} +0 -0
  93. /package/types/{utils.d.ts → generated/utils.d.ts} +0 -0
  94. /package/types/{validation.d.ts → generated/validation.d.ts} +0 -0
  95. /package/types/{warn.d.ts → generated/warn.d.ts} +0 -0
@@ -7,7 +7,28 @@
7
7
  "WebFetch(domain:www.npmjs.com)",
8
8
  "WebFetch(domain:gist.github.com)",
9
9
  "WebFetch(domain:mongoosejs.com)",
10
- "WebFetch(domain:github.com)"
10
+ "WebFetch(domain:github.com)",
11
+ "Bash(yarn types)",
12
+ "Bash(chmod:*)",
13
+ "Bash(find:*)",
14
+ "Read(//Users/andrew/Bedrock/core/services/api/**)",
15
+ "Bash(cat:*)",
16
+ "Bash(npx tsc:*)",
17
+ "Bash(npm install:*)",
18
+ "Bash(yarn add:*)",
19
+ "Bash(yarn tsc:*)",
20
+ "Bash(/dev/null)",
21
+ "Bash(echo \"Exit code: $?\")",
22
+ "Bash(tsc:*)",
23
+ "Read(//Users/andrew/Bedrock/yada/**)",
24
+ "Bash(scripts/types:*)",
25
+ "Bash(tree:*)",
26
+ "Bash(awk:*)",
27
+ "Bash(grep:*)",
28
+ "Bash(for file in types/modules/{clone,delete-hooks,export,include,soft-delete}.d.ts)",
29
+ "Bash(do)",
30
+ "Bash(done)",
31
+ "Bash(node_modules/.bin/prettier:*)"
11
32
  ],
12
33
  "deny": [],
13
34
  "ask": []
package/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.20.0
2
+
3
+ - Added types and documentation to all augmented methods.
4
+
1
5
  ## 0.19.3
2
6
 
3
7
  - Fixed issue with unknown sort fields throwing in aggregations.
package/README.md CHANGED
@@ -26,6 +26,8 @@ Bedrock utilities for model creation.
26
26
  - [Reload](#reload)
27
27
  - [Clone](#clone)
28
28
  - [Slugs](#slugs)
29
+ - [Hydrate](#hydrate)
30
+ - [Export](#export)
29
31
  - [Testing](#testing)
30
32
  - [Troubleshooting](#troubleshooting)
31
33
 
@@ -1814,6 +1816,33 @@ is possible:
1814
1816
 
1815
1817
  However the likelyhood of such collisions on a slug are acceptably small.
1816
1818
 
1819
+ ### Hydrate
1820
+
1821
+ Overrides the default Mongoose `hydrate` method to only include fields defined
1822
+ in the schema. This prevents leaking extra data from aggregations:
1823
+
1824
+ ```js
1825
+ const user = User.hydrate({
1826
+ _id: '507f1f77bcf86cd799439011',
1827
+ name: 'John Doe',
1828
+ email: 'john@example.com',
1829
+ extraField: 'This will be excluded',
1830
+ });
1831
+ ```
1832
+
1833
+ ### Export
1834
+
1835
+ Adds an `export` method to documents that exports all defined schema paths into
1836
+ a plain object, excluding undefined values:
1837
+
1838
+ ```js
1839
+ const data = user.export();
1840
+ ```
1841
+
1842
+ > [!WARNING]
1843
+ > Note that this method is for internal use only. It bypasses all access control and may include sensitive data. Typical serialization of documents uses `toObject` or simply relies on the `toJSON` method of documents.
1844
+
1845
+
1817
1846
  ## Testing
1818
1847
 
1819
1848
  A helper `createTestModel` is exported to allow quickly building models for
@@ -29,8 +29,8 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
29
29
  * applied. For more about syntax and functionality see
30
30
  * [the documentation](https://github.com/bedrockio/model#schemas).
31
31
  * @param {object} definition
32
- * @param {mongoose.SchemaOptions} options
33
- * @returns mongoose.Schema
32
+ * @param {mongoose.SchemaOptions} [options]
33
+ * @returns {mongoose.Schema}
34
34
  */
35
35
  function createSchema(definition, options = {}) {
36
36
  (0, _cache.addCacheFields)(definition);
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@bedrockio/model",
3
- "version": "0.19.3",
3
+ "version": "0.20.0",
4
4
  "description": "Bedrock utilities for model creation.",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "test": "jest",
8
- "types": "tsc",
8
+ "types": "scripts/types",
9
9
  "lint": "eslint",
10
10
  "build": "scripts/build",
11
11
  "eject": "scripts/eject.js",
@@ -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.3",
42
+ "@bedrockio/yada": "^1.10.6",
43
43
  "@shelf/jest-mongodb": "^5.2.2",
44
44
  "eslint": "^9.36.0",
45
45
  "jest": "^30.2.0",
package/src/schema.js CHANGED
@@ -28,8 +28,8 @@ import {
28
28
  * applied. For more about syntax and functionality see
29
29
  * [the documentation](https://github.com/bedrockio/model#schemas).
30
30
  * @param {object} definition
31
- * @param {mongoose.SchemaOptions} options
32
- * @returns mongoose.Schema
31
+ * @param {mongoose.SchemaOptions} [options]
32
+ * @returns {mongoose.Schema}
33
33
  */
34
34
  export function createSchema(definition, options = {}) {
35
35
  addCacheFields(definition);
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "include": ["types/index.d.ts"],
4
+ "compilerOptions": {
5
+ "noEmit": true,
6
+ "skipLibCheck": false
7
+ }
8
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"access.d.ts","sourceRoot":"","sources":["../../src/access.js"],"names":[],"mappings":"AAIA;;GAEG;AACH,oCAFW,MAAM,GAAC,MAAM,EAAE,yBA2BzB"}
@@ -1 +1 @@
1
- {"version":3,"file":"assign.d.ts","sourceRoot":"","sources":["../src/assign.js"],"names":[],"mappings":"AAEA,+CAKC"}
1
+ {"version":3,"file":"assign.d.ts","sourceRoot":"","sources":["../../src/assign.js"],"names":[],"mappings":"AAEA,+CAKC"}
@@ -1 +1 @@
1
- {"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.js"],"names":[],"mappings":"AASA,sDAeC;AAED,+DASC"}
1
+ {"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/cache.js"],"names":[],"mappings":"AASA,sDAeC;AAED,+DASC"}
@@ -1 +1 @@
1
- {"version":3,"file":"clone.d.ts","sourceRoot":"","sources":["../src/clone.js"],"names":[],"mappings":"AAQA,8CAIC"}
1
+ {"version":3,"file":"clone.d.ts","sourceRoot":"","sources":["../../src/clone.js"],"names":[],"mappings":"AAQA,8CAIC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../../src/const.js"],"names":[],"mappings":";;;;;;;;AASA,iCAAkC,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delete-hooks.d.ts","sourceRoot":"","sources":["../../src/delete-hooks.js"],"names":[],"mappings":"AASA,wDAgBC;AAED,qEAqCC"}
@@ -1 +1 @@
1
- {"version":3,"file":"disallowed.d.ts","sourceRoot":"","sources":["../src/disallowed.js"],"names":[],"mappings":"AAEA,mDA+BC"}
1
+ {"version":3,"file":"disallowed.d.ts","sourceRoot":"","sources":["../../src/disallowed.js"],"names":[],"mappings":"AAEA,mDA+BC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/env.js"],"names":[],"mappings":"AAAA,4BAAyC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.js"],"names":[],"mappings":"AAAA;CAA8C;AAE9C;IACE,uBAGC;IADC,UAAgB;CAEnB;AAED;IACE,wCAGC;IADC,aAAsB;CAEzB;AAED;IACE,wCAGC;IADC,aAAsB;IAGxB;;;MAKC;CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"export.d.ts","sourceRoot":"","sources":["../src/export.js"],"names":[],"mappings":"AAEA,+CAWC"}
1
+ {"version":3,"file":"export.d.ts","sourceRoot":"","sources":["../../src/export.js"],"names":[],"mappings":"AAEA,+CAWC"}
@@ -1 +1 @@
1
- {"version":3,"file":"hydrate.d.ts","sourceRoot":"","sources":["../src/hydrate.js"],"names":[],"mappings":"AAUA,gDAIC"}
1
+ {"version":3,"file":"hydrate.d.ts","sourceRoot":"","sources":["../../src/hydrate.js"],"names":[],"mappings":"AAUA,gDAIC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"include.d.ts","sourceRoot":"","sources":["../../src/include.js"],"names":[],"mappings":"AAkBA,gDAuEC;AAMD,uDA4BC;AAGD,yDAIC;AAaD,yEAUC"}
@@ -0,0 +1,7 @@
1
+ export { createSchema } from "./schema";
2
+ export { addValidators } from "./validation";
3
+ export { isEqual } from "./utils";
4
+ export * from "./testing";
5
+ export * from "./errors";
6
+ export { loadModel, loadModelDir } from "./load";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.js"],"names":[],"mappings":""}
@@ -0,0 +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;qBA3CoB,UAAU"}
@@ -1 +1 @@
1
- {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.js"],"names":[],"mappings":"AAIA,oDAUC;AAED,0DAWC"}
1
+ {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/query.js"],"names":[],"mappings":"AAIA,oDAUC;AAED,0DAWC"}
@@ -1 +1 @@
1
- {"version":3,"file":"reload.d.ts","sourceRoot":"","sources":["../src/reload.js"],"names":[],"mappings":"AAKA,+CAwBC"}
1
+ {"version":3,"file":"reload.d.ts","sourceRoot":"","sources":["../../src/reload.js"],"names":[],"mappings":"AAKA,+CAwBC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Creates a new Mongoose schema with Bedrock extensions
3
+ * applied. For more about syntax and functionality see
4
+ * [the documentation](https://github.com/bedrockio/model#schemas).
5
+ * @param {object} definition
6
+ * @param {mongoose.SchemaOptions} [options]
7
+ * @returns {mongoose.Schema}
8
+ */
9
+ export function createSchema(definition: object, options?: mongoose.SchemaOptions): mongoose.Schema;
10
+ export function normalizeAttributes(arg: any, path?: any[]): any;
11
+ import mongoose from 'mongoose';
12
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/schema.js"],"names":[],"mappings":"AAyBA;;;;;;;GAOG;AACH,yCAJW,MAAM,YACN,QAAQ,CAAC,aAAa,GACpB,QAAQ,CAAC,MAAM,CAgD3B;AAED,iEAcC;qBA9FoB,UAAU"}
@@ -1,15 +1,20 @@
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;
6
- pick(...names?: string[]): /*elided*/ any;
7
- omit(...names?: string[]): /*elided*/ any;
7
+ pick(...names: string[]): /*elided*/ any;
8
+ omit(...names: string[]): /*elided*/ any;
8
9
  require(...fields: string[]): /*elided*/ any;
9
10
  requireAll(): /*elided*/ any;
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;
@@ -0,0 +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"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialization.d.ts","sourceRoot":"","sources":["../../src/serialization.js"],"names":[],"mappings":";;;IAWa,2DAIV"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slug.d.ts","sourceRoot":"","sources":["../../src/slug.js"],"names":[],"mappings":"AAIA,6CAsBC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"soft-delete.d.ts","sourceRoot":"","sources":["../../src/soft-delete.js"],"names":[],"mappings":"AAMA,mDAIC;AAED,0DAwBC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../src/testing.js"],"names":[],"mappings":"AAOA;;;;;;GAMG;AACH,qDAiBC;AAED,2CAEC"}
@@ -1 +1 @@
1
- {"version":3,"file":"upsert.d.ts","sourceRoot":"","sources":["../src/upsert.js"],"names":[],"mappings":"AAAA,+CAgCC"}
1
+ {"version":3,"file":"upsert.d.ts","sourceRoot":"","sources":["../../src/upsert.js"],"names":[],"mappings":"AAAA,+CAgCC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.js"],"names":[],"mappings":"AAQA,iDAcC;AAED,gHAEC;AAED,+DAEC;AAED,0DAEC;AAED,4DAEC;AAED,4DAEC;AAED,2DAGC;AAOD,mDAGC;AAuBD,mDAgBC;AAKD;;;;EAoBC;AAKD,wDAEC;AAsBD,iDAYC;qBAlKoB,UAAU"}
@@ -162,16 +162,21 @@ 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;
168
- pick(...names?: string[]): /*elided*/ any;
169
- omit(...names?: string[]): /*elided*/ any;
169
+ pick(...names: string[]): /*elided*/ any;
170
+ omit(...names: string[]): /*elided*/ any;
170
171
  require(...fields: string[]): /*elided*/ any;
171
172
  requireAll(): /*elided*/ any;
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,16 +226,21 @@ 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;
227
- pick(...names?: string[]): /*elided*/ any;
228
- omit(...names?: string[]): /*elided*/ any;
233
+ pick(...names: string[]): /*elided*/ any;
234
+ omit(...names: string[]): /*elided*/ any;
229
235
  require(...fields: string[]): /*elided*/ any;
230
236
  requireAll(): /*elided*/ any;
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,16 +290,21 @@ 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;
286
- pick(...names?: string[]): /*elided*/ any;
287
- omit(...names?: string[]): /*elided*/ any;
297
+ pick(...names: string[]): /*elided*/ any;
298
+ omit(...names: string[]): /*elided*/ any;
288
299
  require(...fields: string[]): /*elided*/ any;
289
300
  requireAll(): /*elided*/ any;
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,16 +355,21 @@ 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;
346
- pick(...names?: string[]): /*elided*/ any;
347
- omit(...names?: string[]): /*elided*/ any;
362
+ pick(...names: string[]): /*elided*/ any;
363
+ omit(...names: string[]): /*elided*/ any;
348
364
  require(...fields: string[]): /*elided*/ any;
349
365
  requireAll(): /*elided*/ any;
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;
@@ -0,0 +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;;;;;;;;;;;;;;EAhC/I;AAEL,8EAqBK;AAEL;;;;;;;;;;;;;;;;;kBAOo4B,CAAC;oBAA+B,CAAC;qBAAgC,CAAC;sBAAiC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eAAr1B,CAAC;;;;;;;;;;;;;;EADjJ"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/validation.js"],"names":[],"mappings":"AA6DA,kDAEC;AAED,oEA4FC;AAsBD,wEAiBC;AAmUD;;;EAEC;AAED;;;EAOC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"warn.d.ts","sourceRoot":"","sources":["../../src/warn.js"],"names":[],"mappings":"AAAA,oDAKC"}
package/types/index.d.ts CHANGED
@@ -1,7 +1,22 @@
1
- export { createSchema } from "./schema";
2
- export { addValidators } from "./validation";
3
- export { isEqual } from "./utils";
4
- export * from "./testing";
5
- export * from "./errors";
6
- export { loadModel, loadModelDir } from "./load";
7
- //# sourceMappingURL=index.d.ts.map
1
+ /**
2
+ * Mongoose Model interface augmentations.
3
+ * Note that signatures inside these files must match mongoose
4
+ * 8.19.2 Model interface. Types script will fail if this package
5
+ * is bumped and that signature does not match.
6
+ */
7
+
8
+ import './modules/search';
9
+ import './modules/validation';
10
+ import './modules/soft-delete';
11
+ import './modules/upsert';
12
+ import './modules/slug';
13
+ import './modules/cache';
14
+ import './modules/include';
15
+ import './modules/hydrate';
16
+ import './modules/assign';
17
+ import './modules/clone';
18
+ import './modules/reload';
19
+ import './modules/export';
20
+ import './modules/delete-hooks';
21
+
22
+ export * from './generated/index';
@@ -0,0 +1,22 @@
1
+ declare module 'mongoose' {
2
+ interface Document {
3
+ /**
4
+ * Assigns fields to this document, converting falsy values (null, empty string) to undefined to ensure they are unset.
5
+ *
6
+ * @param {Object} fields - Object of fields to assign to the document
7
+ *
8
+ * @returns {void}
9
+ *
10
+ * @example
11
+ * ```js
12
+ * user.assign({
13
+ * name: 'Jane Doe',
14
+ * email: null
15
+ * });
16
+ * ```
17
+ *
18
+ * @see {@link https://github.com/bedrockio/model#assign}
19
+ */
20
+ assign(fields: any): void;
21
+ }
22
+ }
@@ -0,0 +1,31 @@
1
+ import type { HydratedDocument } from 'mongoose';
2
+
3
+ declare module 'mongoose' {
4
+ interface Model<
5
+ TRawDocType,
6
+ TQueryHelpers = {},
7
+ TInstanceMethods = {},
8
+ TVirtuals = {},
9
+ THydratedDocumentType = HydratedDocument<
10
+ TRawDocType,
11
+ TVirtuals & TInstanceMethods,
12
+ TQueryHelpers,
13
+ TVirtuals
14
+ >,
15
+ TSchema = any,
16
+ > {
17
+ /**
18
+ * Synchronizes cached fields across documents. Finds documents with null cached fields and updates them with values from related documents.
19
+ *
20
+ * @returns {Promise<Object>} - Bulk write result
21
+ *
22
+ * @example
23
+ * ```js
24
+ * const result = await User.syncCacheFields();
25
+ * ```
26
+ *
27
+ * @see {@link https://github.com/bedrockio/model#cache}
28
+ */
29
+ syncCacheFields(): Promise<any>;
30
+ }
31
+ }
@@ -0,0 +1,18 @@
1
+ declare module 'mongoose' {
2
+ interface Document {
3
+ /**
4
+ * Creates a new instance of this document with the same field values, generating new values for unique fields by appending a counter.
5
+ *
6
+ * @returns {Document} - A new document instance
7
+ *
8
+ * @example
9
+ * ```js
10
+ * const clone = user.clone();
11
+ * await clone.save();
12
+ * ```
13
+ *
14
+ * @see {@link https://github.com/bedrockio/model#clone}
15
+ */
16
+ clone(): this;
17
+ }
18
+ }
@@ -0,0 +1,33 @@
1
+ declare module 'mongoose' {
2
+ interface Document {
3
+ /**
4
+ * Enhanced version of delete() that validates foreign references and deletes related documents based on clean hooks.
5
+ * Handles rollback if deletion fails. Only available when delete hooks are configured on the model.
6
+ *
7
+ * @returns {Promise<Document>} - The saved document
8
+ *
9
+ * @example
10
+ * ```js
11
+ * await user.delete();
12
+ * ```
13
+ *
14
+ * @see {@link https://github.com/bedrockio/model#delete-hooks}
15
+ */
16
+ delete(): Promise<this>;
17
+
18
+ /**
19
+ * Enhanced version of restore() that also restores related documents that were deleted via clean hooks.
20
+ * Only available when delete hooks are configured on the model.
21
+ *
22
+ * @returns {Promise<Document>} - The saved document
23
+ *
24
+ * @example
25
+ * ```js
26
+ * await user.restore();
27
+ * ```
28
+ *
29
+ * @see {@link https://github.com/bedrockio/model#delete-hooks}
30
+ */
31
+ restore(): Promise<this>;
32
+ }
33
+ }
@@ -0,0 +1,17 @@
1
+ declare module 'mongoose' {
2
+ interface Document {
3
+ /**
4
+ * Exports all defined schema paths from this document into a plain object, excluding undefined values.
5
+ *
6
+ * @returns {Object} - Plain object with document data
7
+ *
8
+ * @example
9
+ * ```js
10
+ * const data = user.export();
11
+ * ```
12
+ *
13
+ * @see {@link https://github.com/bedrockio/model#export}
14
+ */
15
+ export(): any;
16
+ }
17
+ }
@@ -0,0 +1,37 @@
1
+ import type { HydratedDocument } from 'mongoose';
2
+
3
+ declare module 'mongoose' {
4
+ interface Model<
5
+ TRawDocType,
6
+ TQueryHelpers = {},
7
+ TInstanceMethods = {},
8
+ TVirtuals = {},
9
+ THydratedDocumentType = HydratedDocument<
10
+ TRawDocType,
11
+ TVirtuals & TInstanceMethods,
12
+ TQueryHelpers,
13
+ TVirtuals
14
+ >,
15
+ TSchema = any,
16
+ > {
17
+ /**
18
+ * Creates a Mongoose document from a plain object, but only includes fields defined in the schema. Prevents leaking extra data from aggregations.
19
+ *
20
+ * @param {Object} obj - Plain object to hydrate into a model instance
21
+ *
22
+ * @returns {Document} - Hydrated Mongoose document
23
+ *
24
+ * @example
25
+ * ```js
26
+ * const user = User.hydrate({
27
+ * _id: '507f1f77bcf86cd799439011',
28
+ * name: 'John Doe',
29
+ * email: 'john@example.com'
30
+ * });
31
+ * ```
32
+ *
33
+ * @see {@link https://github.com/bedrockio/model#hydrate}
34
+ */
35
+ hydrate(obj: any): any;
36
+ }
37
+ }