@cleverbrush/schema 1.0.0-beta.5 → 1.0.0

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.
Files changed (76) hide show
  1. package/README.md +118 -320
  2. package/dist/builders/AnySchemaBuilder.d.ts +76 -0
  3. package/dist/builders/AnySchemaBuilder.js +112 -0
  4. package/dist/builders/ArraySchemaBuilder.d.ts +112 -14
  5. package/dist/builders/ArraySchemaBuilder.js +254 -111
  6. package/dist/builders/BooleanSchemaBuilder.d.ts +69 -29
  7. package/dist/builders/BooleanSchemaBuilder.js +134 -74
  8. package/dist/builders/DateSchemaBuilder.d.ts +177 -0
  9. package/dist/builders/DateSchemaBuilder.js +433 -0
  10. package/dist/builders/FunctionSchemaBuilder.d.ts +59 -25
  11. package/dist/builders/FunctionSchemaBuilder.js +102 -58
  12. package/dist/builders/NumberSchemaBuilder.d.ts +159 -59
  13. package/dist/builders/NumberSchemaBuilder.js +345 -165
  14. package/dist/builders/ObjectSchemaBuilder.d.ts +357 -81
  15. package/dist/builders/ObjectSchemaBuilder.js +519 -283
  16. package/dist/builders/SchemaBuilder.d.ts +158 -34
  17. package/dist/builders/SchemaBuilder.js +258 -71
  18. package/dist/builders/StringSchemaBuilder.d.ts +138 -13
  19. package/dist/builders/StringSchemaBuilder.js +261 -115
  20. package/dist/builders/UnionSchemaBuilder.d.ts +129 -9
  21. package/dist/builders/UnionSchemaBuilder.js +196 -75
  22. package/dist/index.d.ts +20 -40
  23. package/dist/index.js +19 -32
  24. package/dist/utils/transaction.d.ts +46 -0
  25. package/dist/utils/transaction.js +178 -0
  26. package/package.json +27 -14
  27. package/dist/defaultSchemas.d.ts +0 -4
  28. package/dist/defaultSchemas.js +0 -45
  29. package/dist/schema.d.ts +0 -231
  30. package/dist/schema.js +0 -2
  31. package/dist/schemaRegistry.d.ts +0 -49
  32. package/dist/schemaRegistry.js +0 -278
  33. package/dist/validators/validateArray.d.ts +0 -3
  34. package/dist/validators/validateArray.js +0 -60
  35. package/dist/validators/validateBoolean.d.ts +0 -2
  36. package/dist/validators/validateBoolean.js +0 -30
  37. package/dist/validators/validateFunction.d.ts +0 -2
  38. package/dist/validators/validateFunction.js +0 -21
  39. package/dist/validators/validateNumber.d.ts +0 -2
  40. package/dist/validators/validateNumber.js +0 -69
  41. package/dist/validators/validateObject.d.ts +0 -3
  42. package/dist/validators/validateObject.js +0 -95
  43. package/dist/validators/validateString.d.ts +0 -2
  44. package/dist/validators/validateString.js +0 -50
  45. package/dist/validators/validateUnion.d.ts +0 -3
  46. package/dist/validators/validateUnion.js +0 -30
  47. package/src/builders/ArraySchemaBuilder.test.ts +0 -270
  48. package/src/builders/ArraySchemaBuilder.ts +0 -381
  49. package/src/builders/BooleanSchemaBuilder.test.ts +0 -196
  50. package/src/builders/BooleanSchemaBuilder.ts +0 -155
  51. package/src/builders/FunctionSchemaBuilder.test.ts +0 -145
  52. package/src/builders/FunctionSchemaBuilder.ts +0 -117
  53. package/src/builders/NumberSchemaBuilder.test.ts +0 -493
  54. package/src/builders/NumberSchemaBuilder.ts +0 -789
  55. package/src/builders/ObjectSchemaBuilder.test.ts +0 -657
  56. package/src/builders/ObjectSchemaBuilder.ts +0 -794
  57. package/src/builders/SchemaBuilder.test.ts +0 -73
  58. package/src/builders/SchemaBuilder.ts +0 -135
  59. package/src/builders/StringSchemaBuilder.test.ts +0 -318
  60. package/src/builders/StringSchemaBuilder.ts +0 -392
  61. package/src/builders/UnionSchemaBuilder.test.ts +0 -162
  62. package/src/builders/UnionSchemaBuilder.ts +0 -154
  63. package/src/defaultSchemas.ts +0 -44
  64. package/src/index.ts +0 -66
  65. package/src/schema.ts +0 -849
  66. package/src/schemaRegistry.builders.test.ts +0 -1393
  67. package/src/schemaRegistry.test.ts +0 -118
  68. package/src/schemaRegistry.ts +0 -461
  69. package/src/validators/validateArray.ts +0 -76
  70. package/src/validators/validateBoolean.ts +0 -36
  71. package/src/validators/validateFunction.ts +0 -25
  72. package/src/validators/validateNumber.ts +0 -82
  73. package/src/validators/validateObject.ts +0 -119
  74. package/src/validators/validateString.ts +0 -59
  75. package/src/validators/validateUnion.ts +0 -36
  76. package/tsconfig.json +0 -16
package/README.md CHANGED
@@ -1,354 +1,152 @@
1
- # Object Schema Validator
1
+ This package resides in `@cleverbrush/schema` and contains utilities to define object schemas. Once created a Schema can be used to infer type and validate objects for satisfaction of the Schema.
2
2
 
3
- This package contains utilities to validate the JavaScript object's schema. There is only one class exported - `SchemaValidator`
3
+ The library is covered with unit-tests to make sure it works correctly.
4
4
 
5
- ## Schema Types
6
-
7
- There are several schema types available:
8
-
9
- - object
10
- - string
11
- - number
12
- - array
13
- - function (_TBD_)
14
-
15
- Schemas could be either described by shortcusts (string value from the list above) or by more detailed specification.
16
-
17
- ## Schema Definitions
18
-
19
- ### Common for all types
20
-
21
- Any schema defined by object can contain the following fields:
22
-
23
- - `type` - schema type (see the list above)
24
- - `isRequired` - defines if `undefined` value is considered valid
25
- - `isNullable` - defines if `null` value is considered valid
26
- - `validators` - optional array of custom validation functions (see Examples section at the bottom of this page)
5
+ ## Installation
27
6
 
28
- ### Number
29
-
30
- `number` schema can be defined as follows:
31
-
32
- ```typescript
33
- import { SchemaValidator } from '@cleverbrush/schema';
34
- const validator = new SchemaValidator();
35
-
36
- // validates for integer number between 1 and 100
37
- let result = await validator.validate(
38
- {
39
- type: 'number',
40
- isInteger: true,
41
- min: 1,
42
- max: 100
43
- },
44
- 10
45
- );
7
+ ```bash
8
+ npm install @cleverbrush/schema
46
9
  ```
47
10
 
48
- All fields available (apart of common fields for all schemas) are:
49
-
50
- - `isInteger` - ensures that number is integer
51
- - `ensureIsFinite` - ensures that nubmer is finite
52
- - `ensureNotNaN` - ensures that number is not NaN
53
- - `equals` - checks if a value is equal to provided number
54
- - `min` - checks if a value is bigger or equal than a provided lower bound
55
- - `max` - checks if a value is lower or equal than a provided upper bound
56
-
57
- Also it can be defined either by shortcut:
11
+ ### An example:
58
12
 
59
13
  ```typescript
60
- import { SchemaValidator } from '@cleverbrush/schema';
61
-
62
- const validator = new SchemaValidator();
63
- let result = await validator.validate('number', 10);
64
- // { valid: true }
65
- result = await validator.validate('number', 'some string');
66
- // { valid: false, errors: [ 'expected type number, but saw string' ] }
67
- ```
68
-
69
- which is equal to:
14
+ import { InferType, object, number, string, date } from '@cleverbrush/schema';
70
15
 
71
- ```typescript
72
- import { SchemaValidator } from '@cleverbrush/schema';
73
-
74
- const validator = new SchemaValidator();
75
-
76
- let result = await validator.validate(
77
- {
78
- type: 'number',
79
- isRequired: true,
80
- isNullable: false,
81
- ensureNotNaN: true,
82
- ensureIsFinite: true
83
- },
84
- 0 / 0
85
- );
86
- // { valid: false }
87
- ```
88
-
89
- ### String
90
-
91
- `string` schema can be defined as follows:
92
-
93
- ```typescript
94
- import { SchemaValidator } from '@cleverbrush/schema';
95
-
96
- const validator = new SchemaValidator();
97
-
98
- // validates for non empty string no longer than 100 chars
99
- let result = await validator.validate(
100
- {
101
- type: 'string',
102
- minLength: 1,
103
- maxLength: 100
104
- },
105
- 'some value here'
106
- );
107
- // { valid: true }
108
- ```
109
-
110
- All fields available (apart of common fields for all schemas) are:
111
-
112
- - `equals` - checks if value is equal to provided string
113
- - `minLength` - checks if value is at least `minLength` characters long
114
- - `maxLength` - checks if value is at most `maxLength` characters long
115
-
116
- Also it can be defined either by shortcut:
117
-
118
- ```typescript
119
- import { SchemaValidator } from '@cleverbrush/schema';
120
-
121
- const validator = new SchemaValidator();
122
-
123
- let result = await validator.validate('string', 'something');
124
- // { valid: true }
125
- result = await validator.validate('string', 10);
126
- // { valid: false, errors: [ 'expected type string, but saw number' ] }
127
- ```
16
+ const UserSchema = object({
17
+ id: number(),
18
+ name: string(),
19
+ dateOfBirth: date().optional()
20
+ });
128
21
 
129
- or by detailed descriptor:
22
+ // user has { id: number; name: string; dateOfBirth?: Date } type
23
+ const user: InferType<typeof UserSchema> = {
24
+ //...
25
+ };
130
26
 
131
- ```typescript
132
- import { SchemaValidator } from '@cleverbrush/schema';
133
-
134
- const validator = new SchemaValidator();
135
-
136
- let result = await validator.validate(
137
- {
138
- type: 'string',
139
- isNullable: false,
140
- isRequired: true
141
- },
142
- 1230
143
- );
144
- // { valid: false }
27
+ const { valid, object: result, errors } = await UserSchema.validate(user);
145
28
  ```
146
29
 
147
- ### Array
30
+ Type inference can be used even on clean JavaScript (without TypeScript):
148
31
 
149
- `array` schema can be defined as follows:
32
+ ```javascript
33
+ const { valid, object, errors } = await UserSchema.validate(someObject);
150
34
 
151
- ```typescript
152
- import { SchemaValidator } from '@cleverbrush/schema';
153
- const validator = new SchemaValidator();
154
-
155
- // validates for non empty string no longer than 100 chars
156
- let result = await validator.validate(
157
- {
158
- type: 'array',
159
- minLength: 5,
160
- maxLength: 10,
161
- ofType: {
162
- type: 'number',
163
- min: 1,
164
- max: 10
165
- }
166
- },
167
- [5, 6, 7, 8, 9]
168
- );
169
- // { valid: true }
35
+ if (valid) {
36
+ // someObject satisfies UserSchema.
37
+ // And `object` has { id: number; name: string; dateOfBirth: Date; } type.
38
+ } else {
39
+ // someObject does not satisfy UserSchema which means that
40
+ // `errors` contains a list of errors.
41
+ }
170
42
  ```
171
43
 
172
- All fields available (apart of common fields for all schemas) are:
173
-
174
- - `ofType` - here you can pass the `schema` and all array elements will be checked to match this schema
175
- - `minLength` - checks if array is at least `minLength` elements long
176
- - `maxLength` - checks if array is at most `maxLength` elements long
177
-
178
- Also it can be defined either by shortcut:
179
-
180
- ```typescript
181
- import { SchemaValidator } from '@cleverbrush/schema';
182
-
183
- const validator = new SchemaValidator();
44
+ Another way to have types using just Javascript is to make use of JSDoc:
184
45
 
185
- let result = await validator.validate('array', []);
186
- // { valid: true }
187
- result = await validator.validate('array', 10);
188
- // { valid: false, errors: [ 'expected array' ] }
46
+ ```javascript
47
+ /**
48
+ * @type {import('@cleverbrush/schema').InferType<typeof UserSchema>}
49
+ */
50
+ const user = {
51
+ // inferred type is { id: number; name: string; dateOfBirth?: Date }
52
+ };
189
53
  ```
190
54
 
191
- or by detailed descriptor:
55
+ See [Documentation](https://docs.cleverbrush.com/v1.0/modules/Schema_Definition_And_Validation.html) or `docs` folder for more information.
192
56
 
193
- ```typescript
194
- import { SchemaValidator } from '@cleverbrush/schema';
195
-
196
- const validator = new SchemaValidator();
197
-
198
- let result = await validator.validate(
199
- {
200
- type: 'array'
201
- },
202
- 1230
203
- );
204
- // { valid: false, errors: [ 'expected array' ] }
205
- ```
206
-
207
- ### Object
57
+ ## Schema Types
208
58
 
209
- `object` type allows to define a complex object schema. For example:
59
+ There are several schema types available out of the box:
60
+
61
+ - `any` - any object. Similar to the `any` type in TypeScript.
62
+ - `string` - string value.
63
+ - `number` - number value.
64
+ - `boolean` - boolean value.
65
+ - `func` - function value.
66
+ - `object` - object schema (you can define list of properties, along with schemas for every property).
67
+ - `date` - defines object of JavaScript `Date` class.
68
+ - `array` - defines array, you can define a schema for Array emelement.
69
+ - `union` - allows to define unions. e.g. `string | number` types (or any combination off schema types from this list).
70
+ - custom schema types. You just need to inherit `SchemaBuilder` abstract class to implement your own schema type.
71
+
72
+ ## What is exported from the library?
73
+
74
+ Library exports several functions used to define schemas:
75
+
76
+ - `any`
77
+ - `string`
78
+ - `number`
79
+ - `boolean`
80
+ - `func`
81
+ - `object`
82
+ - `date`
83
+ - `array`
84
+ - `union`
85
+
86
+ All these functions returns so called schema builders.
87
+ Schema builder classes are also exported (in case if you want to develop your own schema builder based on it):
88
+
89
+ - `AnySchemaBuilder`
90
+ - `ArraySchemaBuilder`
91
+ - `BooleanSchemaBuilder`
92
+ - `DateSchemaBuilder`
93
+ - `FunctionSchemaBuilder`
94
+ - `ObjectSchemaBuilder`
95
+ - `NumberSchemaBuilder`
96
+ - `SchemaBuilder` - abstract class.
97
+ - `StringSchemaBuilder`
98
+ - `UnionSchemaBuilder`
99
+
100
+ ## Schema Builders Are Immutable
101
+
102
+ All schema builders listed above are immutable, which means that every call of it's methods should return a new Schema builder.
103
+ For example in the example below call to the `.optional()` method will not affect `UserSchema` or any other schemas using it. Instead it will return a new schema builder:
104
+
105
+ ```ts
106
+ const UserSchema = object({
107
+ id: number(),
108
+ email: string()
109
+ });
210
110
 
211
- ```typescript
212
- await validator.validate(
213
- {
214
- type: 'object',
215
- properties: {
216
- id: 'number',
217
- name: {
218
- type: 'string',
219
- minLength: 1,
220
- maxLength: 100
221
- },
222
- address: {
223
- type: 'object',
224
- properties: {
225
- city: 'string',
226
- street: {
227
- type: 'string',
228
- isRequired: false
229
- }
230
- }
231
- }
232
- }
233
- },
234
- {
235
- id: 10,
236
- name: 'Andrew',
237
- address: {
238
- city: 'Madrid'
239
- }
240
- }
241
- );
242
- // {valid: true}
111
+ const OrderSchema = object({
112
+ id: number(),
113
+ createdByUser: UserSchema.optional()
114
+ });
243
115
  ```
244
116
 
245
- All fields available are:
246
-
247
- - `noUnknownProperties` - Validator will return an error if this field is set to `true` and validated objects contain fields not defined in the object schema. Equals to `false` by default.
248
- - `properties` - the list of properties, every property has corresponding schema definition (see example above).
117
+ By combining immutable schema builders with TypeScript type inference you can create very powerful schemas
118
+ which can be used to validate objects and infer their types.
249
119
 
250
- ## Alternative schema
120
+ Every schema is built using a chain/superposition of calls to the schema builder methods. For example:
251
121
 
252
- Everywhere you pass a `schema` object to the library, you may pass an array of `schema` objects which will validate the object to match at least one schema from this list.
253
- For example, if you want to check that array is consisting either from number or from `{ name: string, value: number }` objects, you can do the following:
254
-
255
- ```typescript
256
- await validator.validate(
257
- {
258
- type: 'array',
259
- ofType: [
260
- 'number',
261
- {
262
- type: 'object',
263
- properties: {
264
- name: 'string',
265
- value: 'number'
266
- }
267
- }
268
- ]
269
- },
270
- [
271
- 10,
272
- { name: 'something', value: 1 },
273
- 100,
274
- { name: 'another string', value: 1 }
275
- ]
276
- );
277
- // {valid: true}
122
+ ```ts
123
+ const UserSchema = object({
124
+ id: number(),
125
+ email: string()
126
+ })
127
+ .optional()
128
+ .addProps({
129
+ name: string()
130
+ });
278
131
  ```
279
132
 
280
- ## Named schemas
281
-
282
- There is a possibility to register a schema, give it a name and then reuse it:
133
+ In the example above `UserSchema` is an object schema with two properties: `id` and `email`. It is also optional and has an additional property `name`.
283
134
 
284
- ```typescript
285
- const validator = new SchemaValidator().addSchemaType('Address', {
286
- properties: {
287
- id: {
288
- type: 'number',
289
- min: 1
290
- },
291
- street: 'string',
292
- zip: 'number'
293
- }
294
- });
135
+ There is also a way to define union schemas. For example example below defines an array of strings or numbers
136
+ having at least two elements, but not more than 5:
295
137
 
296
- await validator.validate(
297
- {
298
- type: 'object',
299
- properties: {
300
- name: 'string',
301
- address1: 'Address',
302
- address2: 'Address'
303
- }
304
- },
305
- {
306
- name: 'Andrew',
307
- address1: {
308
- id: 1,
309
- street: 'some street',
310
- zip: 12345
311
- },
312
- address2: {
313
- id: 2,
314
- street: 'some street 2',
315
- zip: 3456
316
- }
317
- }
318
- );
319
-
320
- // { valid: true }
138
+ ```ts
139
+ const StringOrNumberArraySchema = array()
140
+ .minLength(2)
141
+ .maxLength(5)
142
+ .of(union(string()).or(number()));
321
143
  ```
322
144
 
323
- Also there is a possibility to organize schemas in modules (or even submodules):
145
+ You can go further and restrict number to be in the range of 0 to 100 by adding more constraints:
324
146
 
325
- ```typescript
326
- const validator = new SchemaValidator()
327
- .addSchemaType('Module1.DTOs.Address', {
328
- properties: {
329
- id: {
330
- type: 'number',
331
- min: 1
332
- },
333
- street: 'string',
334
- zip: 'number'
335
- }
336
- })
337
- .addSchemaType('Module1.Models.Person', {
338
- properties: {
339
- firstName: 'string',
340
- lastName: 'string'
341
- }
342
- });
343
-
344
- const resultPerson = await validator.schemas.Module1.Models.Person.validate({
345
- fistName: 'John',
346
- lastName: 'Smith'
347
- });
348
-
349
- const resultAddress = await validator.schemas.Module1.DTOs.Address.validate({});
147
+ ```ts
148
+ const StringOrNumberArraySchema = array()
149
+ .minLength(2)
150
+ .maxLength(5)
151
+ .of(union(string()).or(number().min(0).max(100)));
350
152
  ```
351
-
352
- ## Examples
353
-
354
- For Examples see unit tests in the schemaValidator.tests.ts
@@ -0,0 +1,76 @@
1
+ import { SchemaBuilder, ValidationResult, ValidationContext } from './SchemaBuilder.js';
2
+ type AnySchemaBuilderCreateProps<R extends boolean = true> = Partial<ReturnType<AnySchemaBuilder<R>['introspect']>>;
3
+ /**
4
+ * Any schema builder class. Similar to the `any` type
5
+ * in TypeScript. Allows to define a schema for `any` value.
6
+ * Use it when you don't know the type of the value.
7
+ *
8
+ * **NOTE** this class is exported only to give opportunity to extend it
9
+ * by inheriting. It is not recommended to create an instance of this class
10
+ * directly. Use `any()` function instead.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const schema = any();
15
+ * const result = await schema.validate(123);
16
+ * // result.valid === true
17
+ * // result.object === 123
18
+ * ```
19
+ */
20
+ export declare class AnySchemaBuilder<TRequired extends boolean = true, TExplicitType = undefined, TResult = TExplicitType extends undefined ? any : TExplicitType> extends SchemaBuilder<TResult, TRequired> {
21
+ /**
22
+ * @hidden
23
+ */
24
+ static create(props: AnySchemaBuilderCreateProps<any>): AnySchemaBuilder<true, undefined, any>;
25
+ private constructor();
26
+ /**
27
+ * @hidden
28
+ */
29
+ hasType<T>(notUsed?: T): AnySchemaBuilder<true, T>;
30
+ /**
31
+ * @hidden
32
+ */
33
+ clearHasType(): AnySchemaBuilder<TRequired, undefined>;
34
+ /**
35
+ * Performs validation of the schema over `object`. Basically runs
36
+ * validators, preprocessors and checks for required (if schema is not optional).
37
+ * @param context Optional `ValidationContext` settings.
38
+ */
39
+ validate(object: TResult, context?: ValidationContext): Promise<ValidationResult<TResult>>;
40
+ protected createFromProps<TReq extends boolean>(props: AnySchemaBuilderCreateProps<TReq>): this;
41
+ /**
42
+ * @hidden
43
+ */
44
+ required(): AnySchemaBuilder<true, TExplicitType>;
45
+ /**
46
+ * @hidden
47
+ */
48
+ optional(): AnySchemaBuilder<false, TExplicitType>;
49
+ }
50
+ /**
51
+ * Creates a `any` schema.
52
+ * @example
53
+ * ```
54
+ * const anyObject = any();
55
+ *
56
+ * // null - invalid
57
+ * // undefined - invalid
58
+ * // string - valid
59
+ * // {} - valid
60
+ * // Date -valid
61
+ * // { someProp: 123 } - valid
62
+ * // etc
63
+ * ```
64
+ * @example
65
+ * ```
66
+ * const anyObject = any().optional();
67
+ * // null - valid
68
+ * // undefined - valid
69
+ * // string - valid
70
+ * // {} - valid
71
+ * // Date -valid
72
+ * // { someProp: 123 } - valid
73
+ * ```
74
+ */
75
+ export declare const any: () => AnySchemaBuilder<true, undefined, any>;
76
+ export {};
@@ -0,0 +1,112 @@
1
+ import { SchemaBuilder } from './SchemaBuilder.js';
2
+ /**
3
+ * Any schema builder class. Similar to the `any` type
4
+ * in TypeScript. Allows to define a schema for `any` value.
5
+ * Use it when you don't know the type of the value.
6
+ *
7
+ * **NOTE** this class is exported only to give opportunity to extend it
8
+ * by inheriting. It is not recommended to create an instance of this class
9
+ * directly. Use `any()` function instead.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const schema = any();
14
+ * const result = await schema.validate(123);
15
+ * // result.valid === true
16
+ * // result.object === 123
17
+ * ```
18
+ */
19
+ export class AnySchemaBuilder extends SchemaBuilder {
20
+ /**
21
+ * @hidden
22
+ */
23
+ static create(props) {
24
+ return new AnySchemaBuilder({
25
+ type: 'any',
26
+ ...props
27
+ });
28
+ }
29
+ constructor(props) {
30
+ super(props);
31
+ }
32
+ /**
33
+ * @hidden
34
+ */
35
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
36
+ hasType(notUsed) {
37
+ return this.createFromProps({
38
+ ...this.introspect()
39
+ });
40
+ }
41
+ /**
42
+ * @hidden
43
+ */
44
+ clearHasType() {
45
+ return this.createFromProps({
46
+ ...this.introspect()
47
+ });
48
+ }
49
+ /**
50
+ * Performs validation of the schema over `object`. Basically runs
51
+ * validators, preprocessors and checks for required (if schema is not optional).
52
+ * @param context Optional `ValidationContext` settings.
53
+ */
54
+ async validate(object, context) {
55
+ const superResult = await super.preValidate(object, context);
56
+ const { valid, transaction: preValidationTransaction, errors } = superResult;
57
+ if (!valid) {
58
+ return {
59
+ valid,
60
+ errors
61
+ };
62
+ }
63
+ const { object: { validatedObject: objToValidate } } = preValidationTransaction;
64
+ return {
65
+ valid: true,
66
+ object: objToValidate
67
+ };
68
+ }
69
+ createFromProps(props) {
70
+ return AnySchemaBuilder.create(props);
71
+ }
72
+ /**
73
+ * @hidden
74
+ */
75
+ required() {
76
+ return super.required();
77
+ }
78
+ /**
79
+ * @hidden
80
+ */
81
+ optional() {
82
+ return super.optional();
83
+ }
84
+ }
85
+ /**
86
+ * Creates a `any` schema.
87
+ * @example
88
+ * ```
89
+ * const anyObject = any();
90
+ *
91
+ * // null - invalid
92
+ * // undefined - invalid
93
+ * // string - valid
94
+ * // {} - valid
95
+ * // Date -valid
96
+ * // { someProp: 123 } - valid
97
+ * // etc
98
+ * ```
99
+ * @example
100
+ * ```
101
+ * const anyObject = any().optional();
102
+ * // null - valid
103
+ * // undefined - valid
104
+ * // string - valid
105
+ * // {} - valid
106
+ * // Date -valid
107
+ * // { someProp: 123 } - valid
108
+ * ```
109
+ */
110
+ export const any = () => AnySchemaBuilder.create({
111
+ isRequired: true
112
+ });