@bedrockio/model 0.1.18 → 0.1.19
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/dist/cjs/include.js +15 -2
- package/dist/cjs/utils.js +3 -1
- package/package.json +1 -1
- package/src/include.js +16 -2
- package/src/utils.js +3 -1
package/dist/cjs/include.js
CHANGED
|
@@ -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 =
|
|
260
|
-
return
|
|
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
|
}
|
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
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 =
|
|
246
|
-
return
|
|
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/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;
|