@bedrockio/model 0.1.30 → 0.1.32
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/schema.js +5 -1
- package/dist/cjs/validation.js +10 -6
- package/package.json +3 -3
- package/src/schema.js +5 -1
- package/src/validation.js +13 -6
- package/types/validation.d.ts.map +1 -1
package/dist/cjs/schema.js
CHANGED
|
@@ -258,7 +258,11 @@ function applyDateExtension(typedef) {
|
|
|
258
258
|
default: defaultValue
|
|
259
259
|
} = typedef;
|
|
260
260
|
if (type === 'Date' && defaultValue === 'now') {
|
|
261
|
-
|
|
261
|
+
// Allow mocking which would modify the global
|
|
262
|
+
// Date after the schema has been set up.
|
|
263
|
+
typedef.default = () => {
|
|
264
|
+
return Date.now();
|
|
265
|
+
};
|
|
262
266
|
}
|
|
263
267
|
}
|
|
264
268
|
|
package/dist/cjs/validation.js
CHANGED
|
@@ -85,6 +85,7 @@ function applyValidation(schema, definition) {
|
|
|
85
85
|
allowInclude,
|
|
86
86
|
stripDeleted: true,
|
|
87
87
|
stripTimestamps: true,
|
|
88
|
+
allowDefaultTags: true,
|
|
88
89
|
allowExpandedRefs: true,
|
|
89
90
|
requireWriteAccess: true,
|
|
90
91
|
...(hasUnique && {
|
|
@@ -267,12 +268,15 @@ function getSchemaForTypedef(typedef, options = {}) {
|
|
|
267
268
|
if (isRequired(typedef, options)) {
|
|
268
269
|
schema = schema.required();
|
|
269
270
|
}
|
|
270
|
-
if (typedef.default) {
|
|
271
|
-
//
|
|
272
|
-
//
|
|
273
|
-
//
|
|
274
|
-
//
|
|
275
|
-
|
|
271
|
+
if (typedef.default && options.allowDefaultTags) {
|
|
272
|
+
// Tag the default value to allow OpenAPI description
|
|
273
|
+
// of the field but do not actually set the default as it will
|
|
274
|
+
// be handled on the schema level. The tags are being appended
|
|
275
|
+
// for the create validation only as a convenience to describe
|
|
276
|
+
// the default value on creation in OpenApi.
|
|
277
|
+
schema = schema.tag({
|
|
278
|
+
default: typedef.default
|
|
279
|
+
});
|
|
276
280
|
}
|
|
277
281
|
if (typedef.validate?.schema) {
|
|
278
282
|
schema = schema.append(typedef.validate.schema);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bedrockio/model",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.32",
|
|
4
4
|
"description": "Bedrock utilities for model creation.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"lodash": "^4.17.21"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@bedrockio/yada": "^1.0.
|
|
32
|
+
"@bedrockio/yada": "^1.0.33",
|
|
33
33
|
"mongoose": ">=6.9.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@babel/core": "^7.20.12",
|
|
38
38
|
"@babel/preset-env": "^7.20.2",
|
|
39
39
|
"@bedrockio/prettier-config": "^1.0.2",
|
|
40
|
-
"@bedrockio/yada": "^1.0.
|
|
40
|
+
"@bedrockio/yada": "^1.0.33",
|
|
41
41
|
"@shelf/jest-mongodb": "^4.1.6",
|
|
42
42
|
"babel-plugin-import-replacement": "^1.0.1",
|
|
43
43
|
"eslint": "^8.33.0",
|
package/src/schema.js
CHANGED
|
@@ -262,7 +262,11 @@ function applyTupleExtension(typedef) {
|
|
|
262
262
|
function applyDateExtension(typedef) {
|
|
263
263
|
const { type, default: defaultValue } = typedef;
|
|
264
264
|
if (type === 'Date' && defaultValue === 'now') {
|
|
265
|
-
|
|
265
|
+
// Allow mocking which would modify the global
|
|
266
|
+
// Date after the schema has been set up.
|
|
267
|
+
typedef.default = () => {
|
|
268
|
+
return Date.now();
|
|
269
|
+
};
|
|
266
270
|
}
|
|
267
271
|
}
|
|
268
272
|
|
package/src/validation.js
CHANGED
|
@@ -96,6 +96,7 @@ export function applyValidation(schema, definition) {
|
|
|
96
96
|
allowInclude,
|
|
97
97
|
stripDeleted: true,
|
|
98
98
|
stripTimestamps: true,
|
|
99
|
+
allowDefaultTags: true,
|
|
99
100
|
allowExpandedRefs: true,
|
|
100
101
|
requireWriteAccess: true,
|
|
101
102
|
...(hasUnique && {
|
|
@@ -279,13 +280,18 @@ function getSchemaForTypedef(typedef, options = {}) {
|
|
|
279
280
|
if (isRequired(typedef, options)) {
|
|
280
281
|
schema = schema.required();
|
|
281
282
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
//
|
|
285
|
-
//
|
|
286
|
-
//
|
|
287
|
-
|
|
283
|
+
|
|
284
|
+
if (typedef.default && options.allowDefaultTags) {
|
|
285
|
+
// Tag the default value to allow OpenAPI description
|
|
286
|
+
// of the field but do not actually set the default as it will
|
|
287
|
+
// be handled on the schema level. The tags are being appended
|
|
288
|
+
// for the create validation only as a convenience to describe
|
|
289
|
+
// the default value on creation in OpenApi.
|
|
290
|
+
schema = schema.tag({
|
|
291
|
+
default: typedef.default,
|
|
292
|
+
});
|
|
288
293
|
}
|
|
294
|
+
|
|
289
295
|
if (typedef.validate?.schema) {
|
|
290
296
|
schema = schema.append(typedef.validate.schema);
|
|
291
297
|
} else if (typeof typedef.validate === 'function') {
|
|
@@ -304,6 +310,7 @@ function getSchemaForTypedef(typedef, options = {}) {
|
|
|
304
310
|
if (typedef.max != null || typedef.maxLength != null) {
|
|
305
311
|
schema = schema.max(typedef.max ?? typedef.maxLength);
|
|
306
312
|
}
|
|
313
|
+
|
|
307
314
|
if (options.allowSearch) {
|
|
308
315
|
schema = getSearchSchema(schema, type);
|
|
309
316
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.js"],"names":[],"mappings":"AAiFA,kDAEC;AAED,
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.js"],"names":[],"mappings":"AAiFA,kDAEC;AAED,oEAkFC;AAsBD,wEAkBC;AAuRD;;;EAEC;AAED;;;EAOC;AA/dD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAQK"}
|