-
-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathMixedSchema.js
More file actions
62 lines (57 loc) · 1.85 KB
/
MixedSchema.js
File metadata and controls
62 lines (57 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
'use strict'
const { NullSchema } = require('./NullSchema')
const { BooleanSchema } = require('./BooleanSchema')
const { StringSchema } = require('./StringSchema')
const { NumberSchema } = require('./NumberSchema')
const { IntegerSchema } = require('./IntegerSchema')
const { ObjectSchema } = require('./ObjectSchema')
const { ArraySchema } = require('./ArraySchema')
const { TYPES, FLUENT_SCHEMA } = require('./utils')
const initialState = {
type: [],
definitions: [],
properties: [],
required: []
}
/**
* Represents a MixedSchema.
* @param {Object} [options] - Options
* @param {MixedSchema} [options.schema] - Default schema
* @param {boolean} [options.generateIds = false] - generate the id automatically e.g. #properties.foo
* @returns {StringSchema}
*/
const MixedSchema = ({ schema = initialState, ...options } = {}) => {
options = {
generateIds: false,
factory: MixedSchema,
...options
}
return {
[FLUENT_SCHEMA]: true,
...(schema.type.includes(TYPES.STRING)
? StringSchema({ ...options, schema, factory: MixedSchema })
: {}),
...(schema.type.includes(TYPES.NUMBER)
? NumberSchema({ ...options, schema, factory: MixedSchema })
: {}),
...(schema.type.includes(TYPES.BOOLEAN)
? BooleanSchema({ ...options, schema, factory: MixedSchema })
: {}),
...(schema.type.includes(TYPES.INTEGER)
? IntegerSchema({ ...options, schema, factory: MixedSchema })
: {}),
...(schema.type.includes(TYPES.OBJECT)
? ObjectSchema({ ...options, schema, factory: MixedSchema })
: {}),
...(schema.type.includes(TYPES.ARRAY)
? ArraySchema({ ...options, schema, factory: MixedSchema })
: {}),
...(schema.type.includes(TYPES.NULL)
? NullSchema({ ...options, schema, factory: MixedSchema })
: {})
}
}
module.exports = {
MixedSchema,
default: MixedSchema
}