@bedrockio/yada 1.8.0 → 1.8.2

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 CHANGED
@@ -1,3 +1,11 @@
1
+ ## 1.8.2
2
+
3
+ - Fixed array schemas not passing through `requireAllWithin`.
4
+
5
+ ## 1.8.1
6
+
7
+ - Fixed bug with tagging in `toOpenApi`.
8
+
1
9
  ## 1.8.0
2
10
 
3
11
  - Removed undefined `format` field.
@@ -241,7 +241,7 @@ class Schema {
241
241
  * @alias toJSON.
242
242
  */
243
243
  toOpenApi(...extra) {
244
- return this.toJSON(extra);
244
+ return this.toJSON(...extra);
245
245
  }
246
246
  getAnyType() {
247
247
  const {
package/dist/cjs/array.js CHANGED
@@ -10,8 +10,9 @@ var _TypeSchema = _interopRequireDefault(require("./TypeSchema"));
10
10
  var _errors = require("./errors");
11
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
12
  class ArraySchema extends _TypeSchema.default {
13
- constructor(schemas) {
13
+ constructor(schemas, meta) {
14
14
  super(Array, {
15
+ ...meta,
15
16
  schemas
16
17
  });
17
18
  this.setup();
@@ -106,6 +107,23 @@ class ArraySchema extends _TypeSchema.default {
106
107
  });
107
108
  }
108
109
 
110
+ /**
111
+ * Augments the array schema to make all nested fields required.
112
+ * @returns {this}
113
+ */
114
+ requireAllWithin() {
115
+ const {
116
+ schemas,
117
+ ...rest
118
+ } = this.meta;
119
+ const newSchemas = schemas.map(schema => {
120
+ return schema.requireAllWithin();
121
+ });
122
+
123
+ // @ts-ignore
124
+ return new ArraySchema(newSchemas, rest).required();
125
+ }
126
+
109
127
  // Private
110
128
 
111
129
  toString() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bedrockio/yada",
3
- "version": "1.8.0",
3
+ "version": "1.8.2",
4
4
  "description": "Validation library inspired by Joi.",
5
5
  "scripts": {
6
6
  "test": "jest",
package/src/Schema.js CHANGED
@@ -232,7 +232,7 @@ export default class Schema {
232
232
  * @alias toJSON.
233
233
  */
234
234
  toOpenApi(...extra) {
235
- return this.toJSON(extra);
235
+ return this.toJSON(...extra);
236
236
  }
237
237
 
238
238
  getAnyType() {
package/src/array.js CHANGED
@@ -5,8 +5,8 @@ import TypeSchema from './TypeSchema';
5
5
  import { ArrayError, ElementError, LocalizedError } from './errors';
6
6
 
7
7
  class ArraySchema extends TypeSchema {
8
- constructor(schemas) {
9
- super(Array, { schemas });
8
+ constructor(schemas, meta) {
9
+ super(Array, { ...meta, schemas });
10
10
  this.setup();
11
11
  }
12
12
 
@@ -104,6 +104,21 @@ class ArraySchema extends TypeSchema {
104
104
  });
105
105
  }
106
106
 
107
+ /**
108
+ * Augments the array schema to make all nested fields required.
109
+ * @returns {this}
110
+ */
111
+ requireAllWithin() {
112
+ const { schemas, ...rest } = this.meta;
113
+
114
+ const newSchemas = schemas.map((schema) => {
115
+ return schema.requireAllWithin();
116
+ });
117
+
118
+ // @ts-ignore
119
+ return new ArraySchema(newSchemas, rest).required();
120
+ }
121
+
107
122
  // Private
108
123
 
109
124
  toString() {
package/types/array.d.ts CHANGED
@@ -9,12 +9,16 @@
9
9
  export default function _default(...schemas?: Schema[]): ArraySchema;
10
10
  import Schema from './Schema';
11
11
  declare class ArraySchema extends TypeSchema {
12
- constructor(schemas: any);
13
12
  setup(): void;
14
13
  length(length: any): this;
15
14
  min(length: any): this;
16
15
  max(length: any): this;
17
16
  latlng(): this;
17
+ /**
18
+ * Augments the array schema to make all nested fields required.
19
+ * @returns {this}
20
+ */
21
+ requireAllWithin(): this;
18
22
  toString(): string;
19
23
  }
20
24
  import TypeSchema from './TypeSchema';
@@ -1 +1 @@
1
- {"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../src/array.js"],"names":[],"mappings":"AAuIA;;;;;;;GAOG;AACH,8CALc,MAAM,EAAA,eAUnB;mBAlJkB,UAAU;AAI7B;IACE,0BAGC;IAED,cAsCC;IAED,0BAUC;IAED,uBAUC;IAED,uBAaC;IAED,eAaC;IAID,mBAEC;CAuBF;uBAlIsB,cAAc"}
1
+ {"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../src/array.js"],"names":[],"mappings":"AAsJA;;;;;;;GAOG;AACH,8CALc,MAAM,EAAA,eAUnB;mBAjKkB,UAAU;AAI7B;IAME,cAsCC;IAED,0BAUC;IAED,uBAUC;IAED,uBAaC;IAED,eAaC;IAED;;;OAGG;IACH,oBAFa,IAAI,CAWhB;IAID,mBAEC;CAuBF;uBAjJsB,cAAc"}