@bedrockio/yada 1.8.2 → 1.8.3
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/CHANGELOG.md +4 -0
- package/README.md +4 -4
- package/dist/cjs/Schema.js +12 -5
- package/dist/cjs/TypeSchema.js +2 -2
- package/dist/cjs/array.js +4 -4
- package/dist/cjs/date.js +2 -2
- package/dist/cjs/number.js +2 -2
- package/dist/cjs/object.js +3 -3
- package/dist/cjs/string.js +2 -2
- package/dist/cjs/tuple.js +3 -3
- package/package.json +1 -1
- package/src/Schema.js +12 -5
- package/src/TypeSchema.js +2 -2
- package/src/array.js +4 -4
- package/src/date.js +2 -2
- package/src/number.js +2 -2
- package/src/object.js +3 -3
- package/src/string.js +2 -2
- package/src/tuple.js +3 -3
- package/types/Schema.d.ts +6 -2
- package/types/Schema.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -905,14 +905,14 @@ integration. Any schema can describe itself in JSON Schema format including
|
|
|
905
905
|
complex nested schemas.
|
|
906
906
|
|
|
907
907
|
```js
|
|
908
|
-
yd.string().allow('foo', 'bar').
|
|
908
|
+
yd.string().allow('foo', 'bar').toJsonSchema();
|
|
909
909
|
// {
|
|
910
910
|
// type: 'string',
|
|
911
911
|
// enum: ['foo', 'bar'],
|
|
912
912
|
// }
|
|
913
913
|
```
|
|
914
914
|
|
|
915
|
-
This also means schemas work with JSON
|
|
915
|
+
This also means schemas work with JSON serializers:
|
|
916
916
|
|
|
917
917
|
```js
|
|
918
918
|
const schema = yd.string().allow('foo', 'bar');
|
|
@@ -929,7 +929,7 @@ The `tag` method allows tagging custom fields:
|
|
|
929
929
|
yd.string().tag({
|
|
930
930
|
description: 'my description!',
|
|
931
931
|
x-field: 'my custom field!',
|
|
932
|
-
}).
|
|
932
|
+
}).toJsonSchema();
|
|
933
933
|
// {
|
|
934
934
|
// type: 'string',
|
|
935
935
|
// description: 'my description!',
|
|
@@ -940,7 +940,7 @@ yd.string().tag({
|
|
|
940
940
|
The `description` method is a shortcut:
|
|
941
941
|
|
|
942
942
|
```js
|
|
943
|
-
yd.string().description('my description!').
|
|
943
|
+
yd.string().description('my description!').toJsonSchema();
|
|
944
944
|
// {
|
|
945
945
|
// type: 'string',
|
|
946
946
|
// description: 'my description!',
|
package/dist/cjs/Schema.js
CHANGED
|
@@ -221,7 +221,7 @@ class Schema {
|
|
|
221
221
|
* custom (code-based) assertions will not be output.
|
|
222
222
|
* @param {Object} [extra]
|
|
223
223
|
*/
|
|
224
|
-
|
|
224
|
+
toJsonSchema(extra) {
|
|
225
225
|
const {
|
|
226
226
|
tags
|
|
227
227
|
} = this.meta;
|
|
@@ -238,10 +238,17 @@ class Schema {
|
|
|
238
238
|
|
|
239
239
|
/**
|
|
240
240
|
* Exports the schema in [JSON Schema](https://json-schema.org/) format.
|
|
241
|
-
* @alias
|
|
241
|
+
* @alias toJsonSchema.
|
|
242
242
|
*/
|
|
243
243
|
toOpenApi(...extra) {
|
|
244
|
-
return this.
|
|
244
|
+
return this.toJsonSchema(...extra);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Export JSON schema when invoked by JSON serializer.
|
|
249
|
+
*/
|
|
250
|
+
toJSON() {
|
|
251
|
+
return this.toJsonSchema();
|
|
245
252
|
}
|
|
246
253
|
getAnyType() {
|
|
247
254
|
const {
|
|
@@ -311,7 +318,7 @@ class Schema {
|
|
|
311
318
|
const anyOf = [];
|
|
312
319
|
for (let entry of allowed) {
|
|
313
320
|
if (isSchema(entry)) {
|
|
314
|
-
anyOf.push(entry.
|
|
321
|
+
anyOf.push(entry.toJsonSchema());
|
|
315
322
|
} else if (entry === null) {
|
|
316
323
|
anyOf.push({
|
|
317
324
|
type: 'null'
|
|
@@ -375,7 +382,7 @@ class Schema {
|
|
|
375
382
|
return rest;
|
|
376
383
|
}
|
|
377
384
|
inspect() {
|
|
378
|
-
return JSON.stringify(this
|
|
385
|
+
return JSON.stringify(this, null, 2);
|
|
379
386
|
}
|
|
380
387
|
get() {
|
|
381
388
|
const {
|
package/dist/cjs/TypeSchema.js
CHANGED
package/dist/cjs/array.js
CHANGED
|
@@ -129,7 +129,7 @@ class ArraySchema extends _TypeSchema.default {
|
|
|
129
129
|
toString() {
|
|
130
130
|
return 'array';
|
|
131
131
|
}
|
|
132
|
-
|
|
132
|
+
toJsonSchema(extra) {
|
|
133
133
|
let other;
|
|
134
134
|
const {
|
|
135
135
|
schemas
|
|
@@ -137,16 +137,16 @@ class ArraySchema extends _TypeSchema.default {
|
|
|
137
137
|
if (schemas.length > 1) {
|
|
138
138
|
other = {
|
|
139
139
|
anyOf: schemas.map(schema => {
|
|
140
|
-
return schema.
|
|
140
|
+
return schema.toJsonSchema();
|
|
141
141
|
})
|
|
142
142
|
};
|
|
143
143
|
} else if (schemas.length === 1) {
|
|
144
144
|
other = {
|
|
145
|
-
items: schemas[0].
|
|
145
|
+
items: schemas[0].toJsonSchema()
|
|
146
146
|
};
|
|
147
147
|
}
|
|
148
148
|
return {
|
|
149
|
-
...super.
|
|
149
|
+
...super.toJsonSchema(extra),
|
|
150
150
|
...other,
|
|
151
151
|
type: 'array'
|
|
152
152
|
};
|
package/dist/cjs/date.js
CHANGED
|
@@ -142,12 +142,12 @@ class DateSchema extends _Schema.default {
|
|
|
142
142
|
toString() {
|
|
143
143
|
return 'date';
|
|
144
144
|
}
|
|
145
|
-
|
|
145
|
+
toJsonSchema(extra) {
|
|
146
146
|
const {
|
|
147
147
|
format
|
|
148
148
|
} = this.meta;
|
|
149
149
|
return {
|
|
150
|
-
...super.
|
|
150
|
+
...super.toJsonSchema(extra),
|
|
151
151
|
type: format.includes('timestamp') ? 'number' : 'string'
|
|
152
152
|
};
|
|
153
153
|
}
|
package/dist/cjs/number.js
CHANGED
|
@@ -79,14 +79,14 @@ class NumberSchema extends _TypeSchema.default {
|
|
|
79
79
|
|
|
80
80
|
// Private
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
toJsonSchema(extra) {
|
|
83
83
|
const {
|
|
84
84
|
min,
|
|
85
85
|
max,
|
|
86
86
|
multiple
|
|
87
87
|
} = this.meta;
|
|
88
88
|
return {
|
|
89
|
-
...super.
|
|
89
|
+
...super.toJsonSchema(extra),
|
|
90
90
|
...(min != null && {
|
|
91
91
|
minimum: min
|
|
92
92
|
}),
|
package/dist/cjs/object.js
CHANGED
|
@@ -300,20 +300,20 @@ class ObjectSchema extends _TypeSchema.default {
|
|
|
300
300
|
|
|
301
301
|
// Private
|
|
302
302
|
|
|
303
|
-
|
|
303
|
+
toJsonSchema(extra) {
|
|
304
304
|
const {
|
|
305
305
|
stripUnknown = false
|
|
306
306
|
} = this.meta;
|
|
307
307
|
const required = [];
|
|
308
308
|
const properties = {};
|
|
309
309
|
for (let [key, schema] of Object.entries(this.export())) {
|
|
310
|
-
properties[key] = schema.
|
|
310
|
+
properties[key] = schema.toJsonSchema(extra);
|
|
311
311
|
if (schema.meta.required) {
|
|
312
312
|
required.push(key);
|
|
313
313
|
}
|
|
314
314
|
}
|
|
315
315
|
return {
|
|
316
|
-
...super.
|
|
316
|
+
...super.toJsonSchema(extra),
|
|
317
317
|
...(Object.keys(properties).length > 0 && {
|
|
318
318
|
properties,
|
|
319
319
|
required,
|
package/dist/cjs/string.js
CHANGED
|
@@ -417,13 +417,13 @@ class StringSchema extends _TypeSchema.default {
|
|
|
417
417
|
|
|
418
418
|
// Private
|
|
419
419
|
|
|
420
|
-
|
|
420
|
+
toJsonSchema(extra) {
|
|
421
421
|
const {
|
|
422
422
|
min,
|
|
423
423
|
max
|
|
424
424
|
} = this.meta;
|
|
425
425
|
return {
|
|
426
|
-
...super.
|
|
426
|
+
...super.toJsonSchema(extra),
|
|
427
427
|
...(min && {
|
|
428
428
|
minLength: min
|
|
429
429
|
}),
|
package/dist/cjs/tuple.js
CHANGED
|
@@ -79,15 +79,15 @@ class TupleSchema extends _Schema.default {
|
|
|
79
79
|
toString() {
|
|
80
80
|
return 'tuple';
|
|
81
81
|
}
|
|
82
|
-
|
|
82
|
+
toJsonSchema(extra) {
|
|
83
83
|
const {
|
|
84
84
|
schemas
|
|
85
85
|
} = this.meta;
|
|
86
86
|
return {
|
|
87
|
-
...super.
|
|
87
|
+
...super.toJsonSchema(extra),
|
|
88
88
|
type: 'array',
|
|
89
89
|
prefixItems: schemas.map(schema => {
|
|
90
|
-
return schema.
|
|
90
|
+
return schema.toJsonSchema();
|
|
91
91
|
})
|
|
92
92
|
};
|
|
93
93
|
}
|
package/package.json
CHANGED
package/src/Schema.js
CHANGED
|
@@ -214,7 +214,7 @@ export default class Schema {
|
|
|
214
214
|
* custom (code-based) assertions will not be output.
|
|
215
215
|
* @param {Object} [extra]
|
|
216
216
|
*/
|
|
217
|
-
|
|
217
|
+
toJsonSchema(extra) {
|
|
218
218
|
const { tags } = this.meta;
|
|
219
219
|
return {
|
|
220
220
|
...tags,
|
|
@@ -229,10 +229,17 @@ export default class Schema {
|
|
|
229
229
|
|
|
230
230
|
/**
|
|
231
231
|
* Exports the schema in [JSON Schema](https://json-schema.org/) format.
|
|
232
|
-
* @alias
|
|
232
|
+
* @alias toJsonSchema.
|
|
233
233
|
*/
|
|
234
234
|
toOpenApi(...extra) {
|
|
235
|
-
return this.
|
|
235
|
+
return this.toJsonSchema(...extra);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Export JSON schema when invoked by JSON serializer.
|
|
240
|
+
*/
|
|
241
|
+
toJSON() {
|
|
242
|
+
return this.toJsonSchema();
|
|
236
243
|
}
|
|
237
244
|
|
|
238
245
|
getAnyType() {
|
|
@@ -294,7 +301,7 @@ export default class Schema {
|
|
|
294
301
|
const anyOf = [];
|
|
295
302
|
for (let entry of allowed) {
|
|
296
303
|
if (isSchema(entry)) {
|
|
297
|
-
anyOf.push(entry.
|
|
304
|
+
anyOf.push(entry.toJsonSchema());
|
|
298
305
|
} else if (entry === null) {
|
|
299
306
|
anyOf.push({
|
|
300
307
|
type: 'null',
|
|
@@ -351,7 +358,7 @@ export default class Schema {
|
|
|
351
358
|
}
|
|
352
359
|
|
|
353
360
|
inspect() {
|
|
354
|
-
return JSON.stringify(this
|
|
361
|
+
return JSON.stringify(this, null, 2);
|
|
355
362
|
}
|
|
356
363
|
|
|
357
364
|
get() {
|
package/src/TypeSchema.js
CHANGED
package/src/array.js
CHANGED
|
@@ -125,23 +125,23 @@ class ArraySchema extends TypeSchema {
|
|
|
125
125
|
return 'array';
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
|
|
128
|
+
toJsonSchema(extra) {
|
|
129
129
|
let other;
|
|
130
130
|
const { schemas } = this.meta;
|
|
131
131
|
if (schemas.length > 1) {
|
|
132
132
|
other = {
|
|
133
133
|
anyOf: schemas.map((schema) => {
|
|
134
|
-
return schema.
|
|
134
|
+
return schema.toJsonSchema();
|
|
135
135
|
}),
|
|
136
136
|
};
|
|
137
137
|
} else if (schemas.length === 1) {
|
|
138
138
|
other = {
|
|
139
|
-
items: schemas[0].
|
|
139
|
+
items: schemas[0].toJsonSchema(),
|
|
140
140
|
};
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
return {
|
|
144
|
-
...super.
|
|
144
|
+
...super.toJsonSchema(extra),
|
|
145
145
|
...other,
|
|
146
146
|
type: 'array',
|
|
147
147
|
};
|
package/src/date.js
CHANGED
|
@@ -138,10 +138,10 @@ class DateSchema extends Schema {
|
|
|
138
138
|
return 'date';
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
|
|
141
|
+
toJsonSchema(extra) {
|
|
142
142
|
const { format } = this.meta;
|
|
143
143
|
return {
|
|
144
|
-
...super.
|
|
144
|
+
...super.toJsonSchema(extra),
|
|
145
145
|
type: format.includes('timestamp') ? 'number' : 'string',
|
|
146
146
|
};
|
|
147
147
|
}
|
package/src/number.js
CHANGED
|
@@ -71,10 +71,10 @@ class NumberSchema extends TypeSchema {
|
|
|
71
71
|
|
|
72
72
|
// Private
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
toJsonSchema(extra) {
|
|
75
75
|
const { min, max, multiple } = this.meta;
|
|
76
76
|
return {
|
|
77
|
-
...super.
|
|
77
|
+
...super.toJsonSchema(extra),
|
|
78
78
|
...(min != null && {
|
|
79
79
|
minimum: min,
|
|
80
80
|
}),
|
package/src/object.js
CHANGED
|
@@ -300,19 +300,19 @@ class ObjectSchema extends TypeSchema {
|
|
|
300
300
|
|
|
301
301
|
// Private
|
|
302
302
|
|
|
303
|
-
|
|
303
|
+
toJsonSchema(extra) {
|
|
304
304
|
const { stripUnknown = false } = this.meta;
|
|
305
305
|
|
|
306
306
|
const required = [];
|
|
307
307
|
const properties = {};
|
|
308
308
|
for (let [key, schema] of Object.entries(this.export())) {
|
|
309
|
-
properties[key] = schema.
|
|
309
|
+
properties[key] = schema.toJsonSchema(extra);
|
|
310
310
|
if (schema.meta.required) {
|
|
311
311
|
required.push(key);
|
|
312
312
|
}
|
|
313
313
|
}
|
|
314
314
|
return {
|
|
315
|
-
...super.
|
|
315
|
+
...super.toJsonSchema(extra),
|
|
316
316
|
...(Object.keys(properties).length > 0 && {
|
|
317
317
|
properties,
|
|
318
318
|
required,
|
package/src/string.js
CHANGED
|
@@ -441,10 +441,10 @@ class StringSchema extends TypeSchema {
|
|
|
441
441
|
|
|
442
442
|
// Private
|
|
443
443
|
|
|
444
|
-
|
|
444
|
+
toJsonSchema(extra) {
|
|
445
445
|
const { min, max } = this.meta;
|
|
446
446
|
return {
|
|
447
|
-
...super.
|
|
447
|
+
...super.toJsonSchema(extra),
|
|
448
448
|
...(min && {
|
|
449
449
|
minLength: min,
|
|
450
450
|
}),
|
package/src/tuple.js
CHANGED
|
@@ -69,13 +69,13 @@ class TupleSchema extends Schema {
|
|
|
69
69
|
return 'tuple';
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
toJsonSchema(extra) {
|
|
73
73
|
const { schemas } = this.meta;
|
|
74
74
|
return {
|
|
75
|
-
...super.
|
|
75
|
+
...super.toJsonSchema(extra),
|
|
76
76
|
type: 'array',
|
|
77
77
|
prefixItems: schemas.map((schema) => {
|
|
78
|
-
return schema.
|
|
78
|
+
return schema.toJsonSchema();
|
|
79
79
|
}),
|
|
80
80
|
};
|
|
81
81
|
}
|
package/types/Schema.d.ts
CHANGED
|
@@ -77,12 +77,16 @@ export default class Schema {
|
|
|
77
77
|
* custom (code-based) assertions will not be output.
|
|
78
78
|
* @param {Object} [extra]
|
|
79
79
|
*/
|
|
80
|
-
|
|
80
|
+
toJsonSchema(extra?: any): any;
|
|
81
81
|
/**
|
|
82
82
|
* Exports the schema in [JSON Schema](https://json-schema.org/) format.
|
|
83
|
-
* @alias
|
|
83
|
+
* @alias toJsonSchema.
|
|
84
84
|
*/
|
|
85
85
|
toOpenApi(...extra: any[]): any;
|
|
86
|
+
/**
|
|
87
|
+
* Export JSON schema when invoked by JSON serializer.
|
|
88
|
+
*/
|
|
89
|
+
toJSON(): any;
|
|
86
90
|
getAnyType(): {
|
|
87
91
|
type: string[];
|
|
88
92
|
};
|
package/types/Schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../src/Schema.js"],"names":[],"mappings":"AAgBA,kDAEC;AAED;IACE,uBAGC;IAFC,kBAAoB;IACpB,SAAgB;IAKlB;;OAEG;IACH,YAFa,IAAI,CAQhB;IAED;;;OAGG;IACH,mBAFa,IAAI,CAShB;IAED;;;;OAIG;IACH,sBAFa,IAAI,CAShB;IAED;;;;OAIG;IACH,uBAFa,IAAI,CAShB;IAED;;;;OAIG;IACH,mBAFa,IAAI,CAIhB;IAED;;;OAGG;IACH,sBAFa,IAAI,CAIhB;IAED;;;OAGG;IACH,uBAFa,IAAI,CAIhB;IAED;;;OAGG;IACH,YAFa,IAAI,CAIhB;IAED;;OAEG;IACH,uBAFa,IAAI,CAIhB;IAED;;OAEG;IACH,gBAFa,IAAI,CAShB;IAED;;OAEG;IACH,+BAFa,IAAI,CAMhB;IAED;;OAEG;IACH,uBAFa,IAAI,CAIhB;IAED,iDAwCC;IAED;;OAEG;IACH,kBAFa,IAAI,CAOhB;IAED;;;OAGG;IACH,qBAFa,MAAM,CAMlB;IAED;;;;;OAKG;IACH
|
|
1
|
+
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../src/Schema.js"],"names":[],"mappings":"AAgBA,kDAEC;AAED;IACE,uBAGC;IAFC,kBAAoB;IACpB,SAAgB;IAKlB;;OAEG;IACH,YAFa,IAAI,CAQhB;IAED;;;OAGG;IACH,mBAFa,IAAI,CAShB;IAED;;;;OAIG;IACH,sBAFa,IAAI,CAShB;IAED;;;;OAIG;IACH,uBAFa,IAAI,CAShB;IAED;;;;OAIG;IACH,mBAFa,IAAI,CAIhB;IAED;;;OAGG;IACH,sBAFa,IAAI,CAIhB;IAED;;;OAGG;IACH,uBAFa,IAAI,CAIhB;IAED;;;OAGG;IACH,YAFa,IAAI,CAIhB;IAED;;OAEG;IACH,uBAFa,IAAI,CAIhB;IAED;;OAEG;IACH,gBAFa,IAAI,CAShB;IAED;;OAEG;IACH,+BAFa,IAAI,CAMhB;IAED;;OAEG;IACH,uBAFa,IAAI,CAIhB;IAED,iDAwCC;IAED;;OAEG;IACH,kBAFa,IAAI,CAOhB;IAED;;;OAGG;IACH,qBAFa,MAAM,CAMlB;IAED;;;;;OAKG;IACH,+BAWC;IAED;;;OAGG;IACH,gCAEC;IAED;;OAEG;IACH,cAEC;IAED;;MAOC;IAED;;MAKC;IAED;;;;MASC;IAED;;MAOC;IAED,eAgDC;IAED;;;;OAIG;IACH,oBAFa,IAAI,CAgBhB;IAED,4BAMC;IAED,kBAEC;IAED,YAGC;IAID;;OAEG;IACH,kCAFa,IAAI,CAsDhB;IAED;;OAEG;IACH,4BAFa,IAAI,CAUhB;IAED,oCAKC;IAED,gEAQC;IAED;;OAEG;IACH,oBAFa,IAAI,CAShB;IAED,gCAGC;IAED,qEAYC;CACF"}
|