@based/schema 4.1.1 → 5.0.0-alpha.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.
- package/README.md +152 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/lang.d.ts +152 -0
- package/dist/lang.js +149 -0
- package/dist/mermaid.d.ts +3 -0
- package/dist/mermaid.js +24 -0
- package/dist/parse/assert.d.ts +1 -1
- package/dist/parse/assert.js +2 -2
- package/dist/parse/errors.d.ts +2 -0
- package/dist/parse/errors.js +2 -0
- package/dist/parse/index.d.ts +5 -4
- package/dist/parse/index.js +43 -41
- package/dist/parse/props.js +159 -75
- package/dist/parse/utils.d.ts +2 -2
- package/dist/parse/utils.js +11 -2
- package/dist/types.d.ts +66 -23
- package/dist/types.js +93 -0
- package/package.json +4 -3
- package/dist/parsePayload/index.d.ts +0 -3
- package/dist/parsePayload/index.js +0 -2
- package/dist/parseSchema/assert.d.ts +0 -6
- package/dist/parseSchema/assert.js +0 -27
- package/dist/parseSchema/errors.d.ts +0 -19
- package/dist/parseSchema/errors.js +0 -19
- package/dist/parseSchema/index.d.ts +0 -20
- package/dist/parseSchema/index.js +0 -132
- package/dist/parseSchema/props.d.ts +0 -7
- package/dist/parseSchema/props.js +0 -256
- package/dist/parseSchema/utils.d.ts +0 -3
- package/dist/parseSchema/utils.js +0 -29
- package/dist/src/compat/index.d.ts +0 -6
- package/dist/src/compat/index.js +0 -217
- package/dist/src/compat/oldSchemaType.d.ts +0 -93
- package/dist/src/compat/oldSchemaType.js +0 -2
- package/dist/src/display/index.d.ts +0 -2
- package/dist/src/display/index.js +0 -16
- package/dist/src/display/number.d.ts +0 -4
- package/dist/src/display/number.js +0 -97
- package/dist/src/display/string.d.ts +0 -5
- package/dist/src/display/string.js +0 -26
- package/dist/src/display/timestamp.d.ts +0 -5
- package/dist/src/display/timestamp.js +0 -134
- package/dist/src/error.d.ts +0 -21
- package/dist/src/error.js +0 -23
- package/dist/src/index.d.ts +0 -6
- package/dist/src/index.js +0 -7
- package/dist/src/languages.d.ts +0 -188
- package/dist/src/languages.js +0 -188
- package/dist/src/set/fields/array.d.ts +0 -2
- package/dist/src/set/fields/array.js +0 -119
- package/dist/src/set/fields/index.d.ts +0 -3
- package/dist/src/set/fields/index.js +0 -85
- package/dist/src/set/fields/number.d.ts +0 -4
- package/dist/src/set/fields/number.js +0 -123
- package/dist/src/set/fields/object.d.ts +0 -3
- package/dist/src/set/fields/object.js +0 -28
- package/dist/src/set/fields/references.d.ts +0 -3
- package/dist/src/set/fields/references.js +0 -136
- package/dist/src/set/fields/set.d.ts +0 -2
- package/dist/src/set/fields/set.js +0 -59
- package/dist/src/set/fields/string.d.ts +0 -3
- package/dist/src/set/fields/string.js +0 -289
- package/dist/src/set/index.d.ts +0 -3
- package/dist/src/set/index.js +0 -205
- package/dist/src/set/isValidId.d.ts +0 -2
- package/dist/src/set/isValidId.js +0 -17
- package/dist/src/types.d.ts +0 -205
- package/dist/src/types.js +0 -113
- package/dist/src/updateSchema.d.ts +0 -2
- package/dist/src/updateSchema.js +0 -12
- package/dist/src/validateSchema/basedSchemaTypeValidator.d.ts +0 -3
- package/dist/src/validateSchema/basedSchemaTypeValidator.js +0 -45
- package/dist/src/validateSchema/fieldValidators.d.ts +0 -27
- package/dist/src/validateSchema/fieldValidators.js +0 -360
- package/dist/src/validateSchema/index.d.ts +0 -17
- package/dist/src/validateSchema/index.js +0 -109
- package/dist/src/validateSchema/utils.d.ts +0 -25
- package/dist/src/validateSchema/utils.js +0 -61
- package/dist/src/walker/args.d.ts +0 -36
- package/dist/src/walker/args.js +0 -158
- package/dist/src/walker/index.d.ts +0 -6
- package/dist/src/walker/index.js +0 -31
- package/dist/src/walker/parse.d.ts +0 -3
- package/dist/src/walker/parse.js +0 -182
- package/dist/src/walker/types.d.ts +0 -45
- package/dist/src/walker/types.js +0 -7
- package/dist/test/array.d.ts +0 -1
- package/dist/test/array.js +0 -342
- package/dist/test/compat.d.ts +0 -1
- package/dist/test/compat.js +0 -97
- package/dist/test/data/newSchemas.d.ts +0 -2
- package/dist/test/data/newSchemas.js +0 -489
- package/dist/test/data/oldSchemas.d.ts +0 -2
- package/dist/test/data/oldSchemas.js +0 -5058
- package/dist/test/display.d.ts +0 -1
- package/dist/test/display.js +0 -103
- package/dist/test/json.d.ts +0 -1
- package/dist/test/json.js +0 -40
- package/dist/test/number.d.ts +0 -1
- package/dist/test/number.js +0 -374
- package/dist/test/reference.d.ts +0 -1
- package/dist/test/reference.js +0 -188
- package/dist/test/rest.d.ts +0 -1
- package/dist/test/rest.js +0 -168
- package/dist/test/set.d.ts +0 -1
- package/dist/test/set.js +0 -95
- package/dist/test/string.d.ts +0 -1
- package/dist/test/string.js +0 -120
- package/dist/test/text.d.ts +0 -1
- package/dist/test/text.js +0 -324
- package/dist/test/utils/index.d.ts +0 -11
- package/dist/test/utils/index.js +0 -17
- package/dist/test/validateSchema/basic.d.ts +0 -1
- package/dist/test/validateSchema/basic.js +0 -94
- package/dist/test/validateSchema/fields.d.ts +0 -1
- package/dist/test/validateSchema/fields.js +0 -436
- package/dist/test/validateSchema/languages.d.ts +0 -1
- package/dist/test/validateSchema/languages.js +0 -124
- package/dist/test/validateSchema/realWorld.d.ts +0 -1
- package/dist/test/validateSchema/realWorld.js +0 -13
- package/dist/test/walker.d.ts +0 -1
- package/dist/test/walker.js +0 -289
package/dist/test/reference.js
DELETED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
import test from 'ava';
|
|
2
|
-
import { setWalker } from '../src/index.js';
|
|
3
|
-
import { resultCollect } from './utils/index.js';
|
|
4
|
-
const schema = {
|
|
5
|
-
types: {
|
|
6
|
-
thing: {
|
|
7
|
-
prefix: 'ti',
|
|
8
|
-
fields: {
|
|
9
|
-
priority: { type: 'number' },
|
|
10
|
-
something: { type: 'string', format: 'strongPassword' },
|
|
11
|
-
},
|
|
12
|
-
},
|
|
13
|
-
bla: {
|
|
14
|
-
prefix: 'bl',
|
|
15
|
-
fields: {
|
|
16
|
-
ref: {
|
|
17
|
-
type: 'reference',
|
|
18
|
-
allowedType: 'bla',
|
|
19
|
-
},
|
|
20
|
-
children: {
|
|
21
|
-
type: 'references',
|
|
22
|
-
allowedType: 'bla',
|
|
23
|
-
},
|
|
24
|
-
referencesToThings: {
|
|
25
|
-
type: 'references',
|
|
26
|
-
allowedType: 'thing',
|
|
27
|
-
},
|
|
28
|
-
referenceToThing: {
|
|
29
|
-
type: 'reference',
|
|
30
|
-
allowedType: 'thing',
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
$defs: {},
|
|
36
|
-
language: 'en',
|
|
37
|
-
translations: ['de', 'nl', 'ro', 'za', 'ae'],
|
|
38
|
-
root: {
|
|
39
|
-
fields: {},
|
|
40
|
-
},
|
|
41
|
-
prefixToTypeMapping: {
|
|
42
|
-
bl: 'bla',
|
|
43
|
-
ti: 'thing',
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
let r;
|
|
47
|
-
test('simple error', async (t) => {
|
|
48
|
-
r = await setWalker(schema, {
|
|
49
|
-
$id: 'bl120',
|
|
50
|
-
referenceToThing: 'sdfefewfewfewewffwe',
|
|
51
|
-
});
|
|
52
|
-
t.true(r.errors.length === 1);
|
|
53
|
-
});
|
|
54
|
-
test('simple case ', async (t) => {
|
|
55
|
-
r = await setWalker(schema, {
|
|
56
|
-
$id: 'bl120',
|
|
57
|
-
referenceToThing: 'tibla',
|
|
58
|
-
});
|
|
59
|
-
t.deepEqual(resultCollect(r), [
|
|
60
|
-
{ path: ['referenceToThing'], value: 'tibla' },
|
|
61
|
-
]);
|
|
62
|
-
});
|
|
63
|
-
test('reference to wrong type', async (t) => {
|
|
64
|
-
r = await setWalker(schema, {
|
|
65
|
-
$id: 'bl120',
|
|
66
|
-
referenceToThing: 'blbla',
|
|
67
|
-
});
|
|
68
|
-
t.true(r.errors.length === 1);
|
|
69
|
-
});
|
|
70
|
-
test('references with wrongly formatted ids and incorrect types ', async (t) => {
|
|
71
|
-
r = await setWalker(schema, {
|
|
72
|
-
$id: 'bl120',
|
|
73
|
-
referencesToThings: ['blbla', 'ti123', 'ewiohfdoweihfw'],
|
|
74
|
-
});
|
|
75
|
-
t.true(r.errors.length === 2);
|
|
76
|
-
});
|
|
77
|
-
test('references to empty array (clear)', async (t) => {
|
|
78
|
-
r = await setWalker(schema, {
|
|
79
|
-
$id: 'bl120',
|
|
80
|
-
referencesToThings: [],
|
|
81
|
-
});
|
|
82
|
-
t.deepEqual(resultCollect(r), [
|
|
83
|
-
{ path: ['referencesToThings'], value: { $value: [] } },
|
|
84
|
-
]);
|
|
85
|
-
t.is(r.errors.length, 0);
|
|
86
|
-
});
|
|
87
|
-
test('$remove references', async (t) => {
|
|
88
|
-
r = await setWalker(schema, {
|
|
89
|
-
$id: 'bl120',
|
|
90
|
-
referencesToThings: { $remove: ['ti123'] },
|
|
91
|
-
});
|
|
92
|
-
t.deepEqual(resultCollect(r), [
|
|
93
|
-
{ path: ['referencesToThings'], value: { $remove: ['ti123'] } },
|
|
94
|
-
]);
|
|
95
|
-
});
|
|
96
|
-
test('$add 0 2 wrong', async (t) => {
|
|
97
|
-
r = await setWalker(schema, {
|
|
98
|
-
$id: 'bl120',
|
|
99
|
-
referencesToThings: { $add: ['blbla', 'ti123', 'ewiohfdoweihfw'] },
|
|
100
|
-
});
|
|
101
|
-
t.true(r.errors.length === 2);
|
|
102
|
-
});
|
|
103
|
-
test('$add correct ', async (t) => {
|
|
104
|
-
r = await setWalker(schema, {
|
|
105
|
-
$id: 'bl120',
|
|
106
|
-
referencesToThings: { $add: 'ti123' },
|
|
107
|
-
});
|
|
108
|
-
t.deepEqual(resultCollect(r), [
|
|
109
|
-
{ path: ['referencesToThings'], value: { $add: ['ti123'] } },
|
|
110
|
-
]);
|
|
111
|
-
});
|
|
112
|
-
test('$remove $value not allowed', async (t) => {
|
|
113
|
-
r = await setWalker(schema, {
|
|
114
|
-
$id: 'bl120',
|
|
115
|
-
referencesToThings: { $remove: { $value: 'ti123' } },
|
|
116
|
-
});
|
|
117
|
-
t.true(r.errors.length > 0);
|
|
118
|
-
});
|
|
119
|
-
test('reference to an object', async (t) => {
|
|
120
|
-
r = await setWalker(schema, {
|
|
121
|
-
$id: 'bl120',
|
|
122
|
-
referenceToThing: {
|
|
123
|
-
type: 'thing',
|
|
124
|
-
priority: 9000,
|
|
125
|
-
},
|
|
126
|
-
}, async (args) => {
|
|
127
|
-
if (args.value.type === 'thing') {
|
|
128
|
-
return 'tilil';
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
return 'bl1221';
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
t.is(r.errors.length, 0);
|
|
135
|
-
t.deepEqual(resultCollect(r), [
|
|
136
|
-
{ path: ['referenceToThing'], value: 'tilil' },
|
|
137
|
-
]);
|
|
138
|
-
t.true(true);
|
|
139
|
-
});
|
|
140
|
-
test('nested references + $add (deep)', async (t) => {
|
|
141
|
-
r = await setWalker(schema, {
|
|
142
|
-
$id: 'bl1221',
|
|
143
|
-
children: {
|
|
144
|
-
$add: [
|
|
145
|
-
{
|
|
146
|
-
type: 'bla',
|
|
147
|
-
},
|
|
148
|
-
],
|
|
149
|
-
},
|
|
150
|
-
}, async (args) => {
|
|
151
|
-
if (args.value.type === 'thing') {
|
|
152
|
-
return 'tilil';
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
return 'bl1221';
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
t.is(r.errors.length, 0);
|
|
159
|
-
t.deepEqual(resultCollect(r), [
|
|
160
|
-
{ path: ['children'], value: { $add: ['bl1221'] } },
|
|
161
|
-
]);
|
|
162
|
-
});
|
|
163
|
-
test('nested ref + references', async (t) => {
|
|
164
|
-
r = await setWalker(schema, {
|
|
165
|
-
$id: 'bl1221',
|
|
166
|
-
ref: {
|
|
167
|
-
$id: 'bl1221',
|
|
168
|
-
},
|
|
169
|
-
children: [
|
|
170
|
-
{
|
|
171
|
-
$id: 'bl1221',
|
|
172
|
-
},
|
|
173
|
-
],
|
|
174
|
-
}, async (args) => {
|
|
175
|
-
if (args.value.type === 'thing') {
|
|
176
|
-
return 'tilil';
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
return 'bl1221';
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
t.is(r.errors.length, 0);
|
|
183
|
-
t.deepEqual(resultCollect(r), [
|
|
184
|
-
{ path: ['ref'], value: 'bl1221' },
|
|
185
|
-
{ path: ['children'], value: { $value: ['bl1221'] } },
|
|
186
|
-
]);
|
|
187
|
-
});
|
|
188
|
-
//# sourceMappingURL=reference.js.map
|
package/dist/test/rest.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/test/rest.js
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import test from 'ava';
|
|
2
|
-
import { setWalker } from '../src/index.js';
|
|
3
|
-
import { resultCollect } from './utils/index.js';
|
|
4
|
-
const schema = {
|
|
5
|
-
types: {
|
|
6
|
-
thing: {
|
|
7
|
-
prefix: 'ti',
|
|
8
|
-
fields: {
|
|
9
|
-
priority: { type: 'number' },
|
|
10
|
-
something: { type: 'string', format: 'strongPassword' },
|
|
11
|
-
},
|
|
12
|
-
},
|
|
13
|
-
bla: {
|
|
14
|
-
prefix: 'bl',
|
|
15
|
-
fields: {
|
|
16
|
-
enum: {
|
|
17
|
-
enum: ['tony', 'jim'],
|
|
18
|
-
},
|
|
19
|
-
setOfNumbers: {
|
|
20
|
-
type: 'set',
|
|
21
|
-
items: {
|
|
22
|
-
type: 'number',
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
object: {
|
|
26
|
-
type: 'object',
|
|
27
|
-
properties: {
|
|
28
|
-
flap: { type: 'boolean' },
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
flap: {
|
|
32
|
-
type: 'boolean',
|
|
33
|
-
},
|
|
34
|
-
x: {
|
|
35
|
-
type: 'object',
|
|
36
|
-
properties: {
|
|
37
|
-
flap: {
|
|
38
|
-
type: 'boolean',
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
record: {
|
|
43
|
-
type: 'record',
|
|
44
|
-
values: {
|
|
45
|
-
type: 'object',
|
|
46
|
-
properties: {
|
|
47
|
-
bla: {
|
|
48
|
-
type: 'array',
|
|
49
|
-
items: {
|
|
50
|
-
type: 'object',
|
|
51
|
-
properties: {
|
|
52
|
-
snux: {
|
|
53
|
-
type: 'object',
|
|
54
|
-
properties: {
|
|
55
|
-
x: {
|
|
56
|
-
type: 'number',
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
flap: { type: 'number' },
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
bla: {
|
|
68
|
-
type: 'set',
|
|
69
|
-
items: { type: 'string', minLength: 3, maxLength: 6 },
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
$defs: {},
|
|
75
|
-
language: 'en',
|
|
76
|
-
translations: ['de', 'nl', 'ro', 'za', 'ae'],
|
|
77
|
-
root: {
|
|
78
|
-
fields: {},
|
|
79
|
-
},
|
|
80
|
-
prefixToTypeMapping: {
|
|
81
|
-
bl: 'bla',
|
|
82
|
-
ti: 'thing',
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
let r;
|
|
86
|
-
test('enum simple', async (t) => {
|
|
87
|
-
r = await setWalker(schema, {
|
|
88
|
-
$id: 'bl120',
|
|
89
|
-
enum: 'tony',
|
|
90
|
-
});
|
|
91
|
-
t.true(r.errors.length === 0);
|
|
92
|
-
t.deepEqual(resultCollect(r), [{ path: ['enum'], value: 0 }]);
|
|
93
|
-
});
|
|
94
|
-
test('enum not exist error', async (t) => {
|
|
95
|
-
r = await setWalker(schema, {
|
|
96
|
-
$id: 'bl120',
|
|
97
|
-
enum: 'kyle',
|
|
98
|
-
});
|
|
99
|
-
t.true(r.errors.length === 1);
|
|
100
|
-
});
|
|
101
|
-
test('default enum', async (t) => {
|
|
102
|
-
r = await setWalker(schema, {
|
|
103
|
-
$id: 'bl120',
|
|
104
|
-
enum: { $default: 'tony' },
|
|
105
|
-
});
|
|
106
|
-
t.true(r.errors.length === 0);
|
|
107
|
-
t.deepEqual(resultCollect(r), [{ path: ['enum'], value: { $default: 0 } }]);
|
|
108
|
-
});
|
|
109
|
-
test('value enum ', async (t) => {
|
|
110
|
-
r = await setWalker(schema, {
|
|
111
|
-
$id: 'bl120',
|
|
112
|
-
enum: { $value: 'tony' },
|
|
113
|
-
});
|
|
114
|
-
t.true(r.errors.length === 0);
|
|
115
|
-
t.deepEqual(resultCollect(r), [{ path: ['enum'], value: 0 }]);
|
|
116
|
-
});
|
|
117
|
-
test('value & default enum ', async (t) => {
|
|
118
|
-
r = await setWalker(schema, {
|
|
119
|
-
$id: 'bl120',
|
|
120
|
-
enum: { $default: 'jim', $value: 'tony' },
|
|
121
|
-
});
|
|
122
|
-
t.true(r.errors.length === 2);
|
|
123
|
-
});
|
|
124
|
-
test('$value & $default enum ', async (t) => {
|
|
125
|
-
r = await setWalker(schema, {
|
|
126
|
-
$id: 'bl120',
|
|
127
|
-
enum: { $value: { $default: 'tony' } },
|
|
128
|
-
});
|
|
129
|
-
t.true(r.errors.length === 0);
|
|
130
|
-
t.deepEqual(resultCollect(r), [{ path: ['enum'], value: { $default: 0 } }]);
|
|
131
|
-
});
|
|
132
|
-
test('default: value enum ', async (t) => {
|
|
133
|
-
r = await setWalker(schema, {
|
|
134
|
-
$id: 'bl120',
|
|
135
|
-
enum: { $default: { $value: 'tony' } },
|
|
136
|
-
});
|
|
137
|
-
t.true(r.errors.length === 0);
|
|
138
|
-
t.deepEqual(resultCollect(r), [{ path: ['enum'], value: { $default: 0 } }]);
|
|
139
|
-
});
|
|
140
|
-
// ask about alias
|
|
141
|
-
test('$alias ', async (t) => {
|
|
142
|
-
r = await setWalker(schema, {
|
|
143
|
-
$id: 'bl120',
|
|
144
|
-
$alias: 'bla',
|
|
145
|
-
});
|
|
146
|
-
t.true(r.errors.length === 0);
|
|
147
|
-
});
|
|
148
|
-
test('$alias array', async (t) => {
|
|
149
|
-
r = await setWalker(schema, {
|
|
150
|
-
$id: 'bl120',
|
|
151
|
-
$alias: ['bla'],
|
|
152
|
-
});
|
|
153
|
-
t.true(r.errors.length === 0);
|
|
154
|
-
});
|
|
155
|
-
test('object: boolean', async (t) => {
|
|
156
|
-
r = await setWalker(schema, {
|
|
157
|
-
$id: 'bl120',
|
|
158
|
-
object: {
|
|
159
|
-
flap: true,
|
|
160
|
-
},
|
|
161
|
-
});
|
|
162
|
-
t.true(r.errors.length === 0);
|
|
163
|
-
t.deepEqual(resultCollect(r), [
|
|
164
|
-
{ path: ['object', 'flap'], value: true },
|
|
165
|
-
{ path: ['object'], value: { flap: true } },
|
|
166
|
-
]);
|
|
167
|
-
});
|
|
168
|
-
//# sourceMappingURL=rest.js.map
|
package/dist/test/set.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/test/set.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import test from 'ava';
|
|
2
|
-
import { setWalker } from '../src/index.js';
|
|
3
|
-
import { resultCollect } from './utils/index.js';
|
|
4
|
-
let r;
|
|
5
|
-
const schema = {
|
|
6
|
-
types: {
|
|
7
|
-
thing: {
|
|
8
|
-
prefix: 'ti',
|
|
9
|
-
fields: {
|
|
10
|
-
something: { type: 'string', format: 'strongPassword' },
|
|
11
|
-
},
|
|
12
|
-
},
|
|
13
|
-
bla: {
|
|
14
|
-
prefix: 'bl',
|
|
15
|
-
fields: {
|
|
16
|
-
x: {
|
|
17
|
-
type: 'object',
|
|
18
|
-
properties: {
|
|
19
|
-
bla: { type: 'string' },
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
setOfNumbers: {
|
|
23
|
-
type: 'set',
|
|
24
|
-
items: {
|
|
25
|
-
type: 'number',
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
bla: {
|
|
29
|
-
type: 'set',
|
|
30
|
-
items: { type: 'string', minLength: 3, maxLength: 6 },
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
$defs: {},
|
|
36
|
-
language: 'en',
|
|
37
|
-
translations: ['de', 'nl', 'ro', 'za', 'ae'],
|
|
38
|
-
root: {
|
|
39
|
-
fields: {},
|
|
40
|
-
},
|
|
41
|
-
prefixToTypeMapping: {
|
|
42
|
-
bl: 'bla',
|
|
43
|
-
ti: 'thing',
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
test('simple setNum', async (t) => {
|
|
47
|
-
r = await setWalker(schema, {
|
|
48
|
-
$id: 'bl120',
|
|
49
|
-
setOfNumbers: [1, 2, 3, 4, 5],
|
|
50
|
-
});
|
|
51
|
-
t.true(r.errors.length === 0);
|
|
52
|
-
t.deepEqual(resultCollect(r), [
|
|
53
|
-
{ path: ['setOfNumbers'], value: { $value: [1, 2, 3, 4, 5] } },
|
|
54
|
-
]);
|
|
55
|
-
});
|
|
56
|
-
test('default arr', async (t) => {
|
|
57
|
-
r = await setWalker(schema, {
|
|
58
|
-
$id: 'bl120',
|
|
59
|
-
setOfNumbers: { $add: 20 },
|
|
60
|
-
});
|
|
61
|
-
t.true(r.errors.length === 0);
|
|
62
|
-
t.deepEqual(resultCollect(r), [
|
|
63
|
-
{ path: ['setOfNumbers'], value: { $add: [20] } },
|
|
64
|
-
]);
|
|
65
|
-
});
|
|
66
|
-
test('$merge on object', async (t) => {
|
|
67
|
-
r = await setWalker(schema, {
|
|
68
|
-
$id: 'bl120',
|
|
69
|
-
x: {
|
|
70
|
-
$merge: false,
|
|
71
|
-
bla: 'x',
|
|
72
|
-
},
|
|
73
|
-
});
|
|
74
|
-
t.true(r.errors.length === 0);
|
|
75
|
-
t.deepEqual(resultCollect(r), [
|
|
76
|
-
{ path: ['x'], value: { $delete: true } },
|
|
77
|
-
{ path: ['x', 'bla'], value: 'x' },
|
|
78
|
-
{ path: ['x'], value: { $merge: false, bla: 'x' } },
|
|
79
|
-
]);
|
|
80
|
-
});
|
|
81
|
-
test('$merge on set', async (t) => {
|
|
82
|
-
r = await setWalker(schema, {
|
|
83
|
-
$id: 'bl120',
|
|
84
|
-
$merge: false,
|
|
85
|
-
x: {
|
|
86
|
-
bla: 'x',
|
|
87
|
-
},
|
|
88
|
-
});
|
|
89
|
-
t.true(r.errors.length === 0);
|
|
90
|
-
t.deepEqual(resultCollect(r), [
|
|
91
|
-
{ path: ['x', 'bla'], value: 'x' },
|
|
92
|
-
{ path: ['x'], value: { bla: 'x' } },
|
|
93
|
-
]);
|
|
94
|
-
});
|
|
95
|
-
//# sourceMappingURL=set.js.map
|
package/dist/test/string.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/test/string.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import test from 'ava';
|
|
2
|
-
import { setWalker } from '../src/index.js';
|
|
3
|
-
import { errorCollect, resultCollect } from './utils/index.js';
|
|
4
|
-
const schema = {
|
|
5
|
-
types: {
|
|
6
|
-
bla: {
|
|
7
|
-
prefix: 'bl',
|
|
8
|
-
fields: {
|
|
9
|
-
color: {
|
|
10
|
-
type: 'string',
|
|
11
|
-
format: 'rgbColor',
|
|
12
|
-
},
|
|
13
|
-
name: {
|
|
14
|
-
minLength: 3,
|
|
15
|
-
maxLength: 6,
|
|
16
|
-
type: 'string',
|
|
17
|
-
},
|
|
18
|
-
phonkName: {
|
|
19
|
-
type: 'string',
|
|
20
|
-
pattern: '\\${1,4}',
|
|
21
|
-
},
|
|
22
|
-
bla: {
|
|
23
|
-
type: 'set',
|
|
24
|
-
items: { type: 'string', minLength: 3, maxLength: 6 },
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
$defs: {},
|
|
30
|
-
language: 'en',
|
|
31
|
-
root: {
|
|
32
|
-
fields: {},
|
|
33
|
-
},
|
|
34
|
-
prefixToTypeMapping: {
|
|
35
|
-
bl: 'bla',
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
test('string max length', async (t) => {
|
|
39
|
-
const err1 = await setWalker(schema, {
|
|
40
|
-
$id: 'bl1',
|
|
41
|
-
name: 'ax',
|
|
42
|
-
});
|
|
43
|
-
const err2 = await setWalker(schema, {
|
|
44
|
-
$id: 'bl1',
|
|
45
|
-
name: 'axaxaxax',
|
|
46
|
-
});
|
|
47
|
-
const res1 = await setWalker(schema, {
|
|
48
|
-
$id: 'bl1',
|
|
49
|
-
name: 'xaxx',
|
|
50
|
-
});
|
|
51
|
-
t.assert(errorCollect(err1, err2).length > 0);
|
|
52
|
-
t.deepEqual(resultCollect(res1), [{ path: ['name'], value: 'xaxx' }]);
|
|
53
|
-
});
|
|
54
|
-
//set parser
|
|
55
|
-
test('set with strings', async (t) => {
|
|
56
|
-
const err1 = await setWalker(schema, {
|
|
57
|
-
$id: 'bl1',
|
|
58
|
-
bla: ['ax', 'axa', 'axxxxa'],
|
|
59
|
-
});
|
|
60
|
-
const res1 = await setWalker(schema, {
|
|
61
|
-
$id: 'bl1',
|
|
62
|
-
bla: ['axx', 'axxxx', 'blaaa'],
|
|
63
|
-
});
|
|
64
|
-
t.assert(errorCollect(err1).length > 0);
|
|
65
|
-
t.deepEqual(resultCollect(res1), [
|
|
66
|
-
{ path: ['bla'], value: { $value: ['axx', 'axxxx', 'blaaa'] } },
|
|
67
|
-
]);
|
|
68
|
-
});
|
|
69
|
-
// this one causes weird array lenght issue in string max length test
|
|
70
|
-
test('string pattern', async (t) => {
|
|
71
|
-
const err1 = await setWalker(schema, {
|
|
72
|
-
$id: 'bl1',
|
|
73
|
-
phonkName: 'blabla',
|
|
74
|
-
});
|
|
75
|
-
const res1 = await setWalker(schema, {
|
|
76
|
-
$id: 'bl1',
|
|
77
|
-
phonkName: 'bla$',
|
|
78
|
-
});
|
|
79
|
-
t.assert(errorCollect(err1).length > 0);
|
|
80
|
-
t.deepEqual(resultCollect(res1), [{ path: ['phonkName'], value: 'bla$' }]);
|
|
81
|
-
});
|
|
82
|
-
test('setting $default', async (t) => {
|
|
83
|
-
const err = await setWalker(schema, {
|
|
84
|
-
$id: 'bl1',
|
|
85
|
-
phonkName: { $default: 'blabla' },
|
|
86
|
-
});
|
|
87
|
-
t.assert(err.errors.length > 0);
|
|
88
|
-
const res1 = await setWalker(schema, {
|
|
89
|
-
$id: 'bl1',
|
|
90
|
-
phonkName: { $default: 'bla$' },
|
|
91
|
-
});
|
|
92
|
-
t.deepEqual(resultCollect(res1), [
|
|
93
|
-
{ path: ['phonkName'], value: { $default: 'bla$' } },
|
|
94
|
-
]);
|
|
95
|
-
});
|
|
96
|
-
test('setting $value', async (t) => {
|
|
97
|
-
const err = await setWalker(schema, {
|
|
98
|
-
$id: 'bl1',
|
|
99
|
-
phonkName: { $value: 'blabla' },
|
|
100
|
-
});
|
|
101
|
-
t.is(err.errors.length, 1);
|
|
102
|
-
const res1 = await setWalker(schema, {
|
|
103
|
-
$id: 'bl1',
|
|
104
|
-
phonkName: { $value: 'bla$' },
|
|
105
|
-
});
|
|
106
|
-
t.deepEqual(resultCollect(res1), [{ path: ['phonkName'], value: 'bla$' }]);
|
|
107
|
-
});
|
|
108
|
-
test('setting color', async (t) => {
|
|
109
|
-
const err = await setWalker(schema, {
|
|
110
|
-
$id: 'bl1',
|
|
111
|
-
color: 'rgba(255,255,255,0.1)',
|
|
112
|
-
});
|
|
113
|
-
t.is(err.errors.length, 0);
|
|
114
|
-
const err2 = await setWalker(schema, {
|
|
115
|
-
$id: 'bl1',
|
|
116
|
-
color: 'rgba(255,255,255,0.1)x',
|
|
117
|
-
});
|
|
118
|
-
t.is(err2.errors.length, 1);
|
|
119
|
-
});
|
|
120
|
-
//# sourceMappingURL=string.js.map
|
package/dist/test/text.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|