@bedrockio/model 0.1.18 → 0.1.20

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.
@@ -256,8 +256,8 @@ function resolvePaths(schema, str) {
256
256
  source = source.replaceAll('\\*', '[^.]+');
257
257
  source = `^${source}$`;
258
258
  const reg = RegExp(source);
259
- paths = Object.keys(schema.paths || {}).filter(path => {
260
- return !path.startsWith('_') && reg.test(path);
259
+ paths = getSchemaPaths(schema).filter(path => {
260
+ return reg.test(path);
261
261
  });
262
262
  } else {
263
263
  paths = [str];
@@ -265,4 +265,17 @@ function resolvePaths(schema, str) {
265
265
  return paths.map(path => {
266
266
  return [path, schema.pathType(path)];
267
267
  });
268
+ }
269
+ function getSchemaPaths(schema) {
270
+ return Object.entries(schema.paths || {}).flatMap(([key, schema]) => {
271
+ if (key.startsWith('_')) {
272
+ return [];
273
+ } else if (schema.schema) {
274
+ return getSchemaPaths(schema.schema).map(path => {
275
+ return [key, path].join('.');
276
+ });
277
+ } else {
278
+ return [key];
279
+ }
280
+ });
268
281
  }
@@ -118,6 +118,8 @@ function attributesToMongoose(attributes) {
118
118
  } else if (key === 'validate' && type === 'string') {
119
119
  // Allow custom mongoose validation function that derives from the schema.
120
120
  val = (0, _validation.getNamedValidator)(val);
121
+ } else if (key === 'attributes' && type === 'object') {
122
+ val = attributesToMongoose(val);
121
123
  }
122
124
  } else if ((0, _lodash.isPlainObject)(val)) {
123
125
  if (isScopeExtension(val)) {
package/dist/cjs/utils.js CHANGED
@@ -80,7 +80,9 @@ function resolveInnerField(field) {
80
80
  if (Array.isArray(field?.type)) {
81
81
  field = field.type[0];
82
82
  }
83
- if (field instanceof _mongoose.default.Schema) {
83
+ if (field?.type instanceof _mongoose.default.Schema) {
84
+ field = field.type.obj;
85
+ } else if (field instanceof _mongoose.default.Schema) {
84
86
  field = field.obj;
85
87
  }
86
88
  return field;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bedrockio/model",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "description": "Bedrock utilities for model creation.",
5
5
  "type": "module",
6
6
  "scripts": {
package/src/include.js CHANGED
@@ -242,8 +242,8 @@ function resolvePaths(schema, str) {
242
242
  source = source.replaceAll('\\*', '[^.]+');
243
243
  source = `^${source}$`;
244
244
  const reg = RegExp(source);
245
- paths = Object.keys(schema.paths || {}).filter((path) => {
246
- return !path.startsWith('_') && reg.test(path);
245
+ paths = getSchemaPaths(schema).filter((path) => {
246
+ return reg.test(path);
247
247
  });
248
248
  } else {
249
249
  paths = [str];
@@ -252,3 +252,17 @@ function resolvePaths(schema, str) {
252
252
  return [path, schema.pathType(path)];
253
253
  });
254
254
  }
255
+
256
+ function getSchemaPaths(schema) {
257
+ return Object.entries(schema.paths || {}).flatMap(([key, schema]) => {
258
+ if (key.startsWith('_')) {
259
+ return [];
260
+ } else if (schema.schema) {
261
+ return getSchemaPaths(schema.schema).map((path) => {
262
+ return [key, path].join('.');
263
+ });
264
+ } else {
265
+ return [key];
266
+ }
267
+ });
268
+ }
package/src/schema.js CHANGED
@@ -128,6 +128,8 @@ function attributesToMongoose(attributes) {
128
128
  } else if (key === 'validate' && type === 'string') {
129
129
  // Allow custom mongoose validation function that derives from the schema.
130
130
  val = getNamedValidator(val);
131
+ } else if (key === 'attributes' && type === 'object') {
132
+ val = attributesToMongoose(val);
131
133
  }
132
134
  } else if (isPlainObject(val)) {
133
135
  if (isScopeExtension(val)) {
package/src/utils.js CHANGED
@@ -72,7 +72,9 @@ function resolveInnerField(field) {
72
72
  if (Array.isArray(field?.type)) {
73
73
  field = field.type[0];
74
74
  }
75
- if (field instanceof mongoose.Schema) {
75
+ if (field?.type instanceof mongoose.Schema) {
76
+ field = field.type.obj;
77
+ } else if (field instanceof mongoose.Schema) {
76
78
  field = field.obj;
77
79
  }
78
80
  return field;