@bedrockio/model 0.1.15 → 0.1.16
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/validation.js +4 -2
- package/package.json +2 -2
- package/src/validation.js +13 -5
- package/types/validation.d.ts.map +1 -1
package/dist/cjs/validation.js
CHANGED
|
@@ -23,16 +23,18 @@ const DATE_TAGS = {
|
|
|
23
23
|
'x-schema': 'DateTime',
|
|
24
24
|
'x-description': 'A `string` in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format.'
|
|
25
25
|
};
|
|
26
|
-
const OBJECT_ID_SCHEMA = _yada.default.string().mongo().tag({
|
|
26
|
+
const OBJECT_ID_SCHEMA = _yada.default.string().mongo().message('Must be an ObjectId.').tag({
|
|
27
27
|
'x-schema': 'ObjectId',
|
|
28
28
|
'x-description': 'A 24 character hexadecimal string representing a Mongo [ObjectId](https://bit.ly/3YPtGlU).'
|
|
29
29
|
});
|
|
30
30
|
exports.OBJECT_ID_SCHEMA = OBJECT_ID_SCHEMA;
|
|
31
31
|
const REFERENCE_SCHEMA = _yada.default.allow(OBJECT_ID_SCHEMA, _yada.default.object({
|
|
32
32
|
id: OBJECT_ID_SCHEMA.required()
|
|
33
|
+
}).options({
|
|
34
|
+
stripUnknown: true
|
|
33
35
|
}).custom(obj => {
|
|
34
36
|
return obj.id;
|
|
35
|
-
})).tag({
|
|
37
|
+
})).message('Must be an ObjectId or object containing "id" field.').tag({
|
|
36
38
|
'x-schema': 'Reference',
|
|
37
39
|
'x-description': `
|
|
38
40
|
A 24 character hexadecimal string representing a Mongo [ObjectId](https://bit.ly/3YPtGlU).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bedrockio/model",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
4
4
|
"description": "Bedrock utilities for model creation.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -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.28",
|
|
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/validation.js
CHANGED
|
@@ -16,11 +16,15 @@ const DATE_TAGS = {
|
|
|
16
16
|
'A `string` in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format.',
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
export const OBJECT_ID_SCHEMA = yd
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
export const OBJECT_ID_SCHEMA = yd
|
|
20
|
+
.string()
|
|
21
|
+
.mongo()
|
|
22
|
+
.message('Must be an ObjectId.')
|
|
23
|
+
.tag({
|
|
24
|
+
'x-schema': 'ObjectId',
|
|
25
|
+
'x-description':
|
|
26
|
+
'A 24 character hexadecimal string representing a Mongo [ObjectId](https://bit.ly/3YPtGlU).',
|
|
27
|
+
});
|
|
24
28
|
|
|
25
29
|
const REFERENCE_SCHEMA = yd
|
|
26
30
|
.allow(
|
|
@@ -29,10 +33,14 @@ const REFERENCE_SCHEMA = yd
|
|
|
29
33
|
.object({
|
|
30
34
|
id: OBJECT_ID_SCHEMA.required(),
|
|
31
35
|
})
|
|
36
|
+
.options({
|
|
37
|
+
stripUnknown: true,
|
|
38
|
+
})
|
|
32
39
|
.custom((obj) => {
|
|
33
40
|
return obj.id;
|
|
34
41
|
})
|
|
35
42
|
)
|
|
43
|
+
.message('Must be an ObjectId or object containing "id" field.')
|
|
36
44
|
.tag({
|
|
37
45
|
'x-schema': 'Reference',
|
|
38
46
|
'x-description': `
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.js"],"names":[],"mappings":"AAiFA,kDAEC;AAED,oEA8EC;AAsBD,wEAkBC;AA6QD;;;EAEC;AAED;;;EAOC;AAjdD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAQK"}
|