@empyria/common 0.1.3 → 0.1.4
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/lib/Ata.js +20 -3
- package/package.json +3 -3
package/lib/Ata.js
CHANGED
|
@@ -46,13 +46,30 @@ export function cloneBySchema(schema) {
|
|
|
46
46
|
* @param {Object} schemaDef - Map of property name to its JSON schema.
|
|
47
47
|
* @param {Object} [options={}]
|
|
48
48
|
* @param {boolean} [options.strict] - If true, disallows properties not listed in `schemaDef`.
|
|
49
|
-
* @
|
|
49
|
+
* @param {boolean} [options.optional] - If true, a property whose own schema carries
|
|
50
|
+
* `optional: true` is excluded from `required` (that marker is then stripped from the
|
|
51
|
+
* property itself — never leaked into the resulting schema, since it isn't a real JSON
|
|
52
|
+
* Schema keyword). Off by default: every declared property is required, exactly as before —
|
|
53
|
+
* a caller that never sets `optional: true` on any property sees no difference either way.
|
|
54
|
+
* @returns {Object} A JSON schema: `{ type: 'object', properties, required, additionalProperties }`.
|
|
50
55
|
*/
|
|
51
56
|
export function defineSchema(schemaDef, options = {}) {
|
|
57
|
+
const properties = {}
|
|
58
|
+
const required = []
|
|
59
|
+
|
|
60
|
+
for (const [key, propertySchema] of Object.entries(schemaDef)) {
|
|
61
|
+
if (options.optional && propertySchema?.optional) {
|
|
62
|
+
const { optional, ...rest } = propertySchema
|
|
63
|
+
properties[key] = rest
|
|
64
|
+
} else {
|
|
65
|
+
properties[key] = propertySchema
|
|
66
|
+
required.push(key)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
52
69
|
const schema = {
|
|
53
70
|
type: 'object',
|
|
54
|
-
properties
|
|
55
|
-
required
|
|
71
|
+
properties,
|
|
72
|
+
required,
|
|
56
73
|
additionalProperties: !options.strict,
|
|
57
74
|
}
|
|
58
75
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@empyria/common",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Shared backend goodies for Empyria",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Imre Fazekas <imre.fazekas@icloud.com>",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"test:watch": "bun test --watch"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@empyria/classification": "0.1.
|
|
23
|
-
"ata-validator": "1.7.
|
|
22
|
+
"@empyria/classification": "0.1.3",
|
|
23
|
+
"ata-validator": "1.7.4",
|
|
24
24
|
"clerobee": "1.0.8",
|
|
25
25
|
"ms": "2.1.3"
|
|
26
26
|
},
|