-
Notifications
You must be signed in to change notification settings - Fork 2
/
type-attributes.js
54 lines (49 loc) · 1.41 KB
/
type-attributes.js
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
const { types } = require('./constants');
const typeAttributes = {
required: 'required',
optional: 'optional',
fixed: 'fixed',
'fixed-type': 'fixedType',
nullable: 'nullable',
};
const parameterizedTypeAttributes = {
pattern: { alias: 'pattern', dataType: 'string' },
format: { alias: 'format', dataType: 'string' },
'min-length': { alias: 'minLength', dataType: 'number' },
'max-length': { alias: 'maxLength', dataType: 'number' },
minimum: { alias: 'minimum', dataType: 'number' },
maximum: { alias: 'maximum', dataType: 'number' },
};
const permittedValueTypeAttributes = {
[types.object]: [
typeAttributes.fixed,
typeAttributes['fixed-type'],
typeAttributes.nullable,
],
[types.array]: [
typeAttributes.fixed,
typeAttributes['fixed-type'],
typeAttributes.nullable,
parameterizedTypeAttributes['min-length'].alias,
parameterizedTypeAttributes['max-length'].alias,
],
[types.enum]: [
typeAttributes.fixed,
typeAttributes.nullable,
],
...(types.primitiveTypes.reduce((acc, type) => {
acc[type] = [
typeAttributes.fixed,
typeAttributes.nullable,
...Object.values(parameterizedTypeAttributes).map(v => v.alias),
];
return acc;
}, {})),
};
const fakeTypeAttributes = { sample: 'sample', default: 'default' };
module.exports = {
typeAttributes,
parameterizedTypeAttributes,
permittedValueTypeAttributes,
fakeTypeAttributes,
};