@bedrockio/model 0.12.2 → 0.12.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,7 @@
1
+ ## 0.12.3
2
+
3
+ - Support for `include` with top level dynamic references.
4
+
1
5
  ## 0.12.2
2
6
 
3
7
  - Updated validators for string ranges.
package/README.md CHANGED
@@ -1050,6 +1050,10 @@ await Product.findById(id).include('shop.user.^name').
1050
1050
  }
1051
1051
  ```
1052
1052
 
1053
+ > [!WARNING] Fields that are dynamically referenced using `refPath` are unable
1054
+ > to resolve the schemas beforehand (ie. before query execution), therefore they
1055
+ > can only be populated at the top level.
1056
+
1053
1057
  #### Excluded Fields
1054
1058
 
1055
1059
  Fields can be excluded rather than included using `-`:
@@ -325,6 +325,12 @@ function setNodePath(node, options) {
325
325
  exclusive
326
326
  });
327
327
  halt = true;
328
+ } else if (field.refPath) {
329
+ // Note that dynamic references with refPath cannot "see"
330
+ // into a field for which they don't know the type yet (ie.
331
+ // before the query executes), therefore by definition
332
+ // dynamic references can only be populated one layer deep.
333
+ node[key] ||= {};
328
334
  } else if ((0, _utils.isSchemaTypedef)(field)) {
329
335
  node[key] = LEAF_NODE;
330
336
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bedrockio/model",
3
- "version": "0.12.2",
3
+ "version": "0.12.3",
4
4
  "description": "Bedrock utilities for model creation.",
5
5
  "type": "module",
6
6
  "scripts": {
package/src/include.js CHANGED
@@ -233,6 +233,7 @@ function setNodePath(node, options) {
233
233
  }
234
234
 
235
235
  const schema = mongoose.models[modelName]?.schema;
236
+
236
237
  if (!schema) {
237
238
  throw new Error(`Could not derive schema for ${modelName}.`);
238
239
  }
@@ -318,6 +319,12 @@ function setNodePath(node, options) {
318
319
  exclusive,
319
320
  });
320
321
  halt = true;
322
+ } else if (field.refPath) {
323
+ // Note that dynamic references with refPath cannot "see"
324
+ // into a field for which they don't know the type yet (ie.
325
+ // before the query executes), therefore by definition
326
+ // dynamic references can only be populated one layer deep.
327
+ node[key] ||= {};
321
328
  } else if (isSchemaTypedef(field)) {
322
329
  node[key] = LEAF_NODE;
323
330
  }