@based/schema 1.3.2 → 2.1.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/dist/set/fields/string.d.ts.map +1 -1
- package/dist/set/fields/string.js +3 -1
- package/dist/set/fields/string.js.map +1 -1
- package/dist/set/index.d.ts.map +1 -1
- package/dist/set/index.js +3 -1
- package/dist/set/index.js.map +1 -1
- package/dist/types.d.ts +5 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +17 -1
- package/dist/types.js.map +1 -1
- package/dist/updateSchema.js +1 -1
- package/dist/updateSchema.js.map +1 -1
- package/dist/validateSchema.d.ts.map +1 -1
- package/dist/validateSchema.js +5 -2
- package/dist/validateSchema.js.map +1 -1
- package/package.json +1 -1
- package/dist/set/collections.d.ts +0 -5
- package/dist/set/collections.js +0 -211
- package/dist/set/collections.js.map +0 -1
- package/dist/set/error.d.ts +0 -15
- package/dist/set/error.js +0 -24
- package/dist/set/error.js.map +0 -1
- package/dist/set/number.d.ts +0 -4
- package/dist/set/number.js +0 -111
- package/dist/set/number.js.map +0 -1
- package/dist/set/parseDefaultAndValue.d.ts +0 -3
- package/dist/set/parseDefaultAndValue.js +0 -33
- package/dist/set/parseDefaultAndValue.js.map +0 -1
- package/dist/set/parsers.d.ts +0 -3
- package/dist/set/parsers.js +0 -42
- package/dist/set/parsers.js.map +0 -1
- package/dist/set/references.d.ts +0 -3
- package/dist/set/references.js +0 -77
- package/dist/set/references.js.map +0 -1
- package/dist/set/rest.d.ts +0 -5
- package/dist/set/rest.js +0 -76
- package/dist/set/rest.js.map +0 -1
- package/dist/set/string.d.ts +0 -3
- package/dist/set/string.js +0 -173
- package/dist/set/string.js.map +0 -1
- package/src/error.ts +0 -19
- package/src/index.ts +0 -7
- package/src/languages.ts +0 -188
- package/src/set/fields/array.ts +0 -155
- package/src/set/fields/index.ts +0 -70
- package/src/set/fields/number.ts +0 -144
- package/src/set/fields/object.ts +0 -31
- package/src/set/fields/references.ts +0 -140
- package/src/set/fields/set.ts +0 -63
- package/src/set/fields/string.ts +0 -287
- package/src/set/index.ts +0 -182
- package/src/set/isValidId.ts +0 -23
- package/src/set/types.ts +0 -0
- package/src/types.ts +0 -361
- package/src/updateSchema.ts +0 -18
- package/src/validateSchema.ts +0 -61
- package/src/walker/args.ts +0 -209
- package/src/walker/index.ts +0 -48
- package/src/walker/parse.ts +0 -233
- package/src/walker/types.ts +0 -81
- package/test/array.ts +0 -388
- package/test/number.ts +0 -435
- package/test/reference.ts +0 -218
- package/test/rest.ts +0 -184
- package/test/set.ts +0 -103
- package/test/string.ts +0 -118
- package/test/text.ts +0 -342
- package/test/utils/index.ts +0 -23
- package/test/validateSchema.ts +0 -41
- package/test/walker.ts +0 -318
- package/tsconfig.json +0 -9
package/test/number.ts
DELETED
|
@@ -1,435 +0,0 @@
|
|
|
1
|
-
import test from 'ava'
|
|
2
|
-
import {
|
|
3
|
-
ArgsClass,
|
|
4
|
-
BasedSchema,
|
|
5
|
-
BasedSchemaCollectProps,
|
|
6
|
-
BasedSetTarget,
|
|
7
|
-
setWalker,
|
|
8
|
-
} from '../src/index'
|
|
9
|
-
import { ParseError } from '../src/error'
|
|
10
|
-
import { resultCollect, errorCollect } from './utils'
|
|
11
|
-
type NumberTypes = 'number' | 'timestamp' | 'integer'
|
|
12
|
-
|
|
13
|
-
const schema: BasedSchema = {
|
|
14
|
-
types: {
|
|
15
|
-
bla: {
|
|
16
|
-
prefix: 'bl',
|
|
17
|
-
fields: {
|
|
18
|
-
number: {
|
|
19
|
-
type: 'number',
|
|
20
|
-
maximum: 6,
|
|
21
|
-
minimum: 3,
|
|
22
|
-
},
|
|
23
|
-
infiniteNum: {
|
|
24
|
-
type: 'number',
|
|
25
|
-
},
|
|
26
|
-
infiniteInt: {
|
|
27
|
-
type: 'integer',
|
|
28
|
-
},
|
|
29
|
-
exclusiveminmax: {
|
|
30
|
-
type: 'number',
|
|
31
|
-
minimum: 3,
|
|
32
|
-
exclusiveMinimum: true,
|
|
33
|
-
maximum: 6,
|
|
34
|
-
exclusiveMaximum: true,
|
|
35
|
-
},
|
|
36
|
-
integer: {
|
|
37
|
-
type: 'integer',
|
|
38
|
-
},
|
|
39
|
-
multipleOf: {
|
|
40
|
-
type: 'integer',
|
|
41
|
-
multipleOf: 3,
|
|
42
|
-
},
|
|
43
|
-
set: {
|
|
44
|
-
type: 'set',
|
|
45
|
-
items: { type: 'number', minimum: 3, maximum: 6 },
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
$defs: {},
|
|
51
|
-
languages: ['en'],
|
|
52
|
-
root: {
|
|
53
|
-
fields: {},
|
|
54
|
-
},
|
|
55
|
-
prefixToTypeMapping: {
|
|
56
|
-
bl: 'bla',
|
|
57
|
-
},
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
//todo need help typing this maybe
|
|
61
|
-
|
|
62
|
-
test('min-max', async (t) => {
|
|
63
|
-
const e1 = await setWalker(schema, {
|
|
64
|
-
$id: 'bl1',
|
|
65
|
-
number: 1,
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
const e2 = await setWalker(schema, {
|
|
69
|
-
$id: 'bl1',
|
|
70
|
-
number: 10,
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
const res1 = await setWalker(schema, {
|
|
74
|
-
$id: 'bl1',
|
|
75
|
-
number: 3,
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
const res2 = await setWalker(schema, {
|
|
79
|
-
$id: 'bl1',
|
|
80
|
-
number: 6,
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
t.true(errorCollect(e1, e2).length > 0)
|
|
84
|
-
|
|
85
|
-
t.deepEqual(resultCollect(res1, res2), [
|
|
86
|
-
{ path: ['number'], value: 3 },
|
|
87
|
-
{ path: ['number'], value: 6 },
|
|
88
|
-
])
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
test('min-max exclusive', async (t) => {
|
|
92
|
-
const e1 = await setWalker(schema, {
|
|
93
|
-
$id: 'bl1',
|
|
94
|
-
exclusiveminmax: 3,
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
const e2 = await setWalker(schema, {
|
|
98
|
-
$id: 'bl1',
|
|
99
|
-
exclusiveminmax: 6,
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
const res1 = await setWalker(schema, {
|
|
103
|
-
$id: 'bl1',
|
|
104
|
-
exclusiveminmax: 4,
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
const res2 = await setWalker(schema, {
|
|
108
|
-
$id: 'bl1',
|
|
109
|
-
exclusiveminmax: 5,
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
t.assert(errorCollect(e1, e2).length > 0)
|
|
113
|
-
|
|
114
|
-
t.deepEqual(resultCollect(res1, res2), [
|
|
115
|
-
{ path: ['exclusiveminmax'], value: 4 },
|
|
116
|
-
{ path: ['exclusiveminmax'], value: 5 },
|
|
117
|
-
])
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
test('isInteger', async (t) => {
|
|
121
|
-
const e1 = await setWalker(schema, {
|
|
122
|
-
$id: 'bl1',
|
|
123
|
-
integer: 6.5,
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
const res1 = await setWalker(schema, {
|
|
127
|
-
$id: 'bl1',
|
|
128
|
-
integer: 5,
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
t.assert(errorCollect(e1).length > 0)
|
|
132
|
-
t.deepEqual(resultCollect(res1), [{ path: ['integer'], value: 5 }])
|
|
133
|
-
})
|
|
134
|
-
|
|
135
|
-
test('isMultiple', async (t) => {
|
|
136
|
-
const e1 = await setWalker(schema, {
|
|
137
|
-
$id: 'bl1',
|
|
138
|
-
multipleOf: 7,
|
|
139
|
-
})
|
|
140
|
-
|
|
141
|
-
const res1 = await setWalker(schema, {
|
|
142
|
-
$id: 'bl1',
|
|
143
|
-
multipleOf: 9,
|
|
144
|
-
})
|
|
145
|
-
|
|
146
|
-
t.assert(errorCollect(e1).length > 0)
|
|
147
|
-
t.deepEqual(resultCollect(res1), [{ path: ['multipleOf'], value: 9 }])
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
//TODO fix
|
|
151
|
-
test('numbers in a set', async (t) => {
|
|
152
|
-
const e1 = await setWalker(schema, {
|
|
153
|
-
$id: 'bl1',
|
|
154
|
-
set: [9, 4, 5, 2],
|
|
155
|
-
})
|
|
156
|
-
const res1 = await setWalker(schema, { $id: 'bl1', set: [3, 3, 3, 3] })
|
|
157
|
-
|
|
158
|
-
t.assert(errorCollect(e1).length > 0)
|
|
159
|
-
t.deepEqual(resultCollect(res1), [
|
|
160
|
-
{ path: ['set'], value: { $value: [3, 3, 3, 3] } },
|
|
161
|
-
])
|
|
162
|
-
})
|
|
163
|
-
//TODO fix
|
|
164
|
-
test('value', async (t) => {
|
|
165
|
-
const e1 = await setWalker(schema, {
|
|
166
|
-
$id: 'bl1',
|
|
167
|
-
number: { $value: 7 },
|
|
168
|
-
})
|
|
169
|
-
const e2 = await setWalker(schema, {
|
|
170
|
-
$id: 'bl1',
|
|
171
|
-
exclusiveminmax: { $value: 3 },
|
|
172
|
-
})
|
|
173
|
-
const e3 = await setWalker(schema, {
|
|
174
|
-
$id: 'bl1',
|
|
175
|
-
integer: { value: 3.5 },
|
|
176
|
-
})
|
|
177
|
-
|
|
178
|
-
const e4 = await setWalker(schema, {
|
|
179
|
-
$id: 'bl1',
|
|
180
|
-
set: { $value: [1, 3, 3, 4] },
|
|
181
|
-
})
|
|
182
|
-
|
|
183
|
-
const e5 = await setWalker(schema, {
|
|
184
|
-
$id: 'bl1',
|
|
185
|
-
multipleOf: { $value: 2 },
|
|
186
|
-
})
|
|
187
|
-
|
|
188
|
-
const res1 = await setWalker(schema, {
|
|
189
|
-
$id: 'bl1',
|
|
190
|
-
number: { $value: 4 },
|
|
191
|
-
})
|
|
192
|
-
const res2 = await setWalker(schema, {
|
|
193
|
-
$id: 'bl1',
|
|
194
|
-
integer: { $value: 4 },
|
|
195
|
-
})
|
|
196
|
-
const res3 = await setWalker(schema, {
|
|
197
|
-
$id: 'bl1',
|
|
198
|
-
exclusiveminmax: { $value: 4 },
|
|
199
|
-
})
|
|
200
|
-
const res4 = await setWalker(schema, {
|
|
201
|
-
$id: 'bl1',
|
|
202
|
-
multipleOf: { $value: 6 },
|
|
203
|
-
})
|
|
204
|
-
|
|
205
|
-
const res5 = await setWalker(schema, {
|
|
206
|
-
$id: 'bl1',
|
|
207
|
-
set: { $value: [3, 3, 3, 4] },
|
|
208
|
-
})
|
|
209
|
-
|
|
210
|
-
t.assert(errorCollect(e1, e2, e3, e4, e5).length > 0)
|
|
211
|
-
t.deepEqual(resultCollect(res1, res2, res3, res4), [
|
|
212
|
-
{ path: ['number'], value: 4 },
|
|
213
|
-
{ path: ['integer'], value: 4 },
|
|
214
|
-
{ path: ['exclusiveminmax'], value: 4 },
|
|
215
|
-
{ path: ['multipleOf'], value: 6 },
|
|
216
|
-
])
|
|
217
|
-
})
|
|
218
|
-
|
|
219
|
-
test('default', async (t) => {
|
|
220
|
-
const e1 = await setWalker(schema, {
|
|
221
|
-
$id: 'bl1',
|
|
222
|
-
number: { $default: 7 },
|
|
223
|
-
})
|
|
224
|
-
const e2 = await setWalker(schema, {
|
|
225
|
-
$id: 'bl1',
|
|
226
|
-
exclusiveminmax: { $default: 3 },
|
|
227
|
-
})
|
|
228
|
-
const e3 = await setWalker(schema, {
|
|
229
|
-
$id: 'bl1',
|
|
230
|
-
integer: { default: 3.5 },
|
|
231
|
-
})
|
|
232
|
-
|
|
233
|
-
const e4 = await setWalker(schema, {
|
|
234
|
-
$id: 'bl1',
|
|
235
|
-
set: { $default: [1, 3, 3, 4] },
|
|
236
|
-
})
|
|
237
|
-
|
|
238
|
-
const e5 = await setWalker(schema, {
|
|
239
|
-
$id: 'bl1',
|
|
240
|
-
multipleOf: { $default: 2 },
|
|
241
|
-
})
|
|
242
|
-
|
|
243
|
-
const res1 = await setWalker(schema, {
|
|
244
|
-
$id: 'bl1',
|
|
245
|
-
number: { $default: 4 },
|
|
246
|
-
})
|
|
247
|
-
const res2 = await setWalker(schema, {
|
|
248
|
-
$id: 'bl1',
|
|
249
|
-
integer: { $default: 4 },
|
|
250
|
-
})
|
|
251
|
-
const res3 = await setWalker(schema, {
|
|
252
|
-
$id: 'bl1',
|
|
253
|
-
exclusiveminmax: { $default: 4 },
|
|
254
|
-
})
|
|
255
|
-
const res4 = await setWalker(schema, {
|
|
256
|
-
$id: 'bl1',
|
|
257
|
-
multipleOf: { $default: 6 },
|
|
258
|
-
})
|
|
259
|
-
|
|
260
|
-
const res5 = await setWalker(schema, {
|
|
261
|
-
$id: 'bl1',
|
|
262
|
-
set: { $default: [3, 3, 3, 4] },
|
|
263
|
-
})
|
|
264
|
-
|
|
265
|
-
t.assert(errorCollect(e1, e2, e3, e4, e5).length > 0)
|
|
266
|
-
t.deepEqual(resultCollect(res1, res2, res3, res4, res5), [
|
|
267
|
-
{ path: ['number'], value: { $default: 4 } },
|
|
268
|
-
{ path: ['integer'], value: { $default: 4 } },
|
|
269
|
-
{ path: ['exclusiveminmax'], value: { $default: 4 } },
|
|
270
|
-
{ path: ['multipleOf'], value: { $default: 6 } },
|
|
271
|
-
{ path: ['set'], value: { $default: { $value: [3, 3, 3, 4] } } },
|
|
272
|
-
])
|
|
273
|
-
})
|
|
274
|
-
|
|
275
|
-
test('decrement', async (t) => {
|
|
276
|
-
//maxmin
|
|
277
|
-
const e1 = await setWalker(schema, {
|
|
278
|
-
$id: 'bl1',
|
|
279
|
-
number: { $decrement: 2 },
|
|
280
|
-
})
|
|
281
|
-
const e2 = await setWalker(schema, {
|
|
282
|
-
$id: 'bl1',
|
|
283
|
-
number: { $decrement: 7 },
|
|
284
|
-
})
|
|
285
|
-
|
|
286
|
-
const res1 = await setWalker(schema, {
|
|
287
|
-
$id: 'bl1',
|
|
288
|
-
number: { $decrement: 3 },
|
|
289
|
-
})
|
|
290
|
-
//exclusiveminmax
|
|
291
|
-
const e3 = await setWalker(schema, {
|
|
292
|
-
$id: 'bl1',
|
|
293
|
-
exclusiveminmax: { $decrement: 3 },
|
|
294
|
-
})
|
|
295
|
-
const e4 = await setWalker(schema, {
|
|
296
|
-
$id: 'bl1',
|
|
297
|
-
exclusiveminmax: { $decrement: 6 },
|
|
298
|
-
})
|
|
299
|
-
|
|
300
|
-
const res2 = await setWalker(schema, {
|
|
301
|
-
$id: 'bl1',
|
|
302
|
-
exclusiveminmax: { $decrement: 4 },
|
|
303
|
-
})
|
|
304
|
-
|
|
305
|
-
//integer
|
|
306
|
-
const e5 = await setWalker(schema, {
|
|
307
|
-
$id: 'bl1',
|
|
308
|
-
integer: { $decrement: 3.5 },
|
|
309
|
-
})
|
|
310
|
-
|
|
311
|
-
const res3 = await setWalker(schema, {
|
|
312
|
-
$id: 'bl1',
|
|
313
|
-
integer: { $decrement: 3 },
|
|
314
|
-
})
|
|
315
|
-
//multiple of
|
|
316
|
-
|
|
317
|
-
const e6 = await setWalker(schema, {
|
|
318
|
-
$id: 'bl1',
|
|
319
|
-
multipleOf: { $decrement: 7 },
|
|
320
|
-
})
|
|
321
|
-
|
|
322
|
-
const res4 = await setWalker(schema, {
|
|
323
|
-
$id: 'bl1',
|
|
324
|
-
multipleOf: { $decrement: 9 },
|
|
325
|
-
})
|
|
326
|
-
|
|
327
|
-
t.assert(errorCollect(e1, e2, e3, e4, e5, e6).length > 0)
|
|
328
|
-
t.deepEqual(resultCollect(res1, res2, res3, res4), [
|
|
329
|
-
{ path: ['number'], value: { $decrement: 3 } },
|
|
330
|
-
{ path: ['exclusiveminmax'], value: { $decrement: 4 } },
|
|
331
|
-
{ path: ['integer'], value: { $decrement: 3 } },
|
|
332
|
-
{ path: ['multipleOf'], value: { $decrement: 9 } },
|
|
333
|
-
])
|
|
334
|
-
})
|
|
335
|
-
|
|
336
|
-
test('increment', async (t) => {
|
|
337
|
-
//maxmin
|
|
338
|
-
const e1 = await setWalker(schema, {
|
|
339
|
-
$id: 'bl1',
|
|
340
|
-
number: { $increment: 2 },
|
|
341
|
-
})
|
|
342
|
-
const e2 = await setWalker(schema, {
|
|
343
|
-
$id: 'bl1',
|
|
344
|
-
number: { $increment: 7 },
|
|
345
|
-
})
|
|
346
|
-
|
|
347
|
-
const res1 = await setWalker(schema, {
|
|
348
|
-
$id: 'bl1',
|
|
349
|
-
number: { $increment: 3 },
|
|
350
|
-
})
|
|
351
|
-
//exclusiveminmax
|
|
352
|
-
const e3 = await setWalker(schema, {
|
|
353
|
-
$id: 'bl1',
|
|
354
|
-
exclusiveminmax: { $increment: 3 },
|
|
355
|
-
})
|
|
356
|
-
const e4 = await setWalker(schema, {
|
|
357
|
-
$id: 'bl1',
|
|
358
|
-
exclusiveminmax: { $increment: 6 },
|
|
359
|
-
})
|
|
360
|
-
|
|
361
|
-
const res2 = await setWalker(schema, {
|
|
362
|
-
$id: 'bl1',
|
|
363
|
-
exclusiveminmax: { $increment: 4 },
|
|
364
|
-
})
|
|
365
|
-
|
|
366
|
-
//integer
|
|
367
|
-
const e5 = await setWalker(schema, {
|
|
368
|
-
$id: 'bl1',
|
|
369
|
-
integer: { $increment: 3.5 },
|
|
370
|
-
})
|
|
371
|
-
|
|
372
|
-
const res3 = await setWalker(schema, {
|
|
373
|
-
$id: 'bl1',
|
|
374
|
-
integer: { $increment: 3 },
|
|
375
|
-
})
|
|
376
|
-
//multiple of
|
|
377
|
-
|
|
378
|
-
const e6 = await setWalker(schema, {
|
|
379
|
-
$id: 'bl1',
|
|
380
|
-
multipleOf: { $increment: 7 },
|
|
381
|
-
})
|
|
382
|
-
|
|
383
|
-
const res4 = await setWalker(schema, {
|
|
384
|
-
$id: 'bl1',
|
|
385
|
-
multipleOf: { $increment: 9 },
|
|
386
|
-
})
|
|
387
|
-
|
|
388
|
-
t.assert(errorCollect(e1, e2, e3, e4, e5, e6).length > 0)
|
|
389
|
-
t.deepEqual(resultCollect(res1, res2, res3, res4), [
|
|
390
|
-
{ path: ['number'], value: { $increment: 3 } },
|
|
391
|
-
{ path: ['exclusiveminmax'], value: { $increment: 4 } },
|
|
392
|
-
{ path: ['integer'], value: { $increment: 3 } },
|
|
393
|
-
{ path: ['multipleOf'], value: { $increment: 9 } },
|
|
394
|
-
])
|
|
395
|
-
})
|
|
396
|
-
|
|
397
|
-
test('NaN', async (t) => {
|
|
398
|
-
const r = await setWalker(schema, {
|
|
399
|
-
$id: 'bl120',
|
|
400
|
-
integer: NaN,
|
|
401
|
-
})
|
|
402
|
-
t.is(r.errors.length, 1)
|
|
403
|
-
})
|
|
404
|
-
|
|
405
|
-
test('Infinity (integer)', async (t) => {
|
|
406
|
-
const r = await setWalker(schema, {
|
|
407
|
-
$id: 'bl120',
|
|
408
|
-
integer: Infinity,
|
|
409
|
-
})
|
|
410
|
-
t.is(r.errors.length, 1)
|
|
411
|
-
})
|
|
412
|
-
|
|
413
|
-
test('Infinity (number)', async (t) => {
|
|
414
|
-
const r = await setWalker(schema, {
|
|
415
|
-
$id: 'bl120',
|
|
416
|
-
infiniteNum: Infinity,
|
|
417
|
-
})
|
|
418
|
-
t.is(r.errors.length, 1)
|
|
419
|
-
})
|
|
420
|
-
|
|
421
|
-
test('number -infinity', async (t) => {
|
|
422
|
-
const r = await setWalker(schema, {
|
|
423
|
-
$id: 'bl120',
|
|
424
|
-
infiniteNum: -Infinity,
|
|
425
|
-
})
|
|
426
|
-
t.is(r.errors.length, 1)
|
|
427
|
-
})
|
|
428
|
-
|
|
429
|
-
test('number with max infinity', async (t) => {
|
|
430
|
-
const r = await setWalker(schema, {
|
|
431
|
-
$id: 'bl120',
|
|
432
|
-
number: Infinity,
|
|
433
|
-
})
|
|
434
|
-
t.is(r.errors.length, 1)
|
|
435
|
-
})
|
package/test/reference.ts
DELETED
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
import test from 'ava'
|
|
2
|
-
import { BasedSchema, setWalker } from '../src/index'
|
|
3
|
-
import { resultCollect } from './utils'
|
|
4
|
-
|
|
5
|
-
const schema: BasedSchema = {
|
|
6
|
-
types: {
|
|
7
|
-
thing: {
|
|
8
|
-
prefix: 'ti',
|
|
9
|
-
fields: {
|
|
10
|
-
priority: { type: 'number' },
|
|
11
|
-
something: { type: 'string', format: 'strongPassword' },
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
bla: {
|
|
15
|
-
prefix: 'bl',
|
|
16
|
-
fields: {
|
|
17
|
-
ref: {
|
|
18
|
-
type: 'reference',
|
|
19
|
-
},
|
|
20
|
-
children: {
|
|
21
|
-
type: 'references',
|
|
22
|
-
},
|
|
23
|
-
referencesToThings: {
|
|
24
|
-
type: 'references',
|
|
25
|
-
allowedTypes: ['thing'],
|
|
26
|
-
},
|
|
27
|
-
referenceToThing: {
|
|
28
|
-
type: 'reference',
|
|
29
|
-
allowedTypes: ['thing'],
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
$defs: {},
|
|
35
|
-
languages: ['en', 'de', 'nl', 'ro', 'za', 'ae'],
|
|
36
|
-
root: {
|
|
37
|
-
fields: {},
|
|
38
|
-
},
|
|
39
|
-
prefixToTypeMapping: {
|
|
40
|
-
bl: 'bla',
|
|
41
|
-
ti: 'thing',
|
|
42
|
-
},
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
let r
|
|
46
|
-
|
|
47
|
-
test('simple error', async (t) => {
|
|
48
|
-
r = await setWalker(schema, {
|
|
49
|
-
$id: 'bl120',
|
|
50
|
-
referenceToThing: 'sdfefewfewfewewffwe',
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
t.true(r.errors.length === 1)
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
test('simple case ', async (t) => {
|
|
57
|
-
r = await setWalker(schema, {
|
|
58
|
-
$id: 'bl120',
|
|
59
|
-
referenceToThing: 'tibla',
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
t.deepEqual(resultCollect(r), [
|
|
63
|
-
{ path: ['referenceToThing'], value: 'tibla' },
|
|
64
|
-
])
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
test('reference to wrong type', async (t) => {
|
|
68
|
-
r = await setWalker(schema, {
|
|
69
|
-
$id: 'bl120',
|
|
70
|
-
referenceToThing: 'blbla',
|
|
71
|
-
})
|
|
72
|
-
t.true(r.errors.length === 1)
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
test('references with wrongly formatted ids and incorrect types ', async (t) => {
|
|
76
|
-
r = await setWalker(schema, {
|
|
77
|
-
$id: 'bl120',
|
|
78
|
-
referencesToThings: ['blbla', 'ti123', 'ewiohfdoweihfw'],
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
t.true(r.errors.length === 2)
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
test('references to empty array (clear)', async (t) => {
|
|
85
|
-
r = await setWalker(schema, {
|
|
86
|
-
$id: 'bl120',
|
|
87
|
-
referencesToThings: [],
|
|
88
|
-
})
|
|
89
|
-
t.deepEqual(resultCollect(r), [
|
|
90
|
-
{ path: ['referencesToThings'], value: { $value: [] } },
|
|
91
|
-
])
|
|
92
|
-
t.is(r.errors.length, 0)
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
test('$remove references', async (t) => {
|
|
96
|
-
r = await setWalker(schema, {
|
|
97
|
-
$id: 'bl120',
|
|
98
|
-
referencesToThings: { $remove: ['ti123'] },
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
t.deepEqual(resultCollect(r), [
|
|
102
|
-
{ path: ['referencesToThings'], value: { $remove: ['ti123'] } },
|
|
103
|
-
])
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
test('$add 0 2 wrong', async (t) => {
|
|
107
|
-
r = await setWalker(schema, {
|
|
108
|
-
$id: 'bl120',
|
|
109
|
-
referencesToThings: { $add: ['blbla', 'ti123', 'ewiohfdoweihfw'] },
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
t.true(r.errors.length === 2)
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
test('$add correct ', async (t) => {
|
|
116
|
-
r = await setWalker(schema, {
|
|
117
|
-
$id: 'bl120',
|
|
118
|
-
referencesToThings: { $add: 'ti123' },
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
t.deepEqual(resultCollect(r), [
|
|
122
|
-
{ path: ['referencesToThings'], value: { $add: ['ti123'] } },
|
|
123
|
-
])
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
test('$remove $value not allowed', async (t) => {
|
|
127
|
-
r = await setWalker(schema, {
|
|
128
|
-
$id: 'bl120',
|
|
129
|
-
referencesToThings: { $remove: { $value: 'ti123' } },
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
t.true(r.errors.length > 0)
|
|
133
|
-
})
|
|
134
|
-
|
|
135
|
-
test('reference to an object', async (t) => {
|
|
136
|
-
r = await setWalker(
|
|
137
|
-
schema,
|
|
138
|
-
{
|
|
139
|
-
$id: 'bl120',
|
|
140
|
-
referenceToThing: {
|
|
141
|
-
type: 'thing',
|
|
142
|
-
priority: 9000,
|
|
143
|
-
},
|
|
144
|
-
},
|
|
145
|
-
async (args) => {
|
|
146
|
-
if (args.value.type === 'thing') {
|
|
147
|
-
return 'tilil'
|
|
148
|
-
} else {
|
|
149
|
-
return 'bl1221'
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
)
|
|
153
|
-
|
|
154
|
-
t.is(r.errors.length, 0)
|
|
155
|
-
|
|
156
|
-
t.deepEqual(resultCollect(r), [
|
|
157
|
-
{ path: ['referenceToThing'], value: 'tilil' },
|
|
158
|
-
])
|
|
159
|
-
|
|
160
|
-
t.true(true)
|
|
161
|
-
})
|
|
162
|
-
|
|
163
|
-
test('nested references + $add (deep)', async (t) => {
|
|
164
|
-
r = await setWalker(
|
|
165
|
-
schema,
|
|
166
|
-
{
|
|
167
|
-
$id: 'bl1221',
|
|
168
|
-
children: {
|
|
169
|
-
$add: [
|
|
170
|
-
{
|
|
171
|
-
type: 'bla',
|
|
172
|
-
},
|
|
173
|
-
],
|
|
174
|
-
},
|
|
175
|
-
},
|
|
176
|
-
async (args) => {
|
|
177
|
-
if (args.value.type === 'thing') {
|
|
178
|
-
return 'tilil'
|
|
179
|
-
} else {
|
|
180
|
-
return 'bl1221'
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
)
|
|
184
|
-
t.is(r.errors.length, 0)
|
|
185
|
-
t.deepEqual(resultCollect(r), [
|
|
186
|
-
{ path: ['children'], value: { $add: ['bl1221'] } },
|
|
187
|
-
])
|
|
188
|
-
})
|
|
189
|
-
|
|
190
|
-
test('nested ref + references', async (t) => {
|
|
191
|
-
r = await setWalker(
|
|
192
|
-
schema,
|
|
193
|
-
{
|
|
194
|
-
$id: 'bl1221',
|
|
195
|
-
ref: {
|
|
196
|
-
$id: 'bl1221',
|
|
197
|
-
},
|
|
198
|
-
children: [
|
|
199
|
-
{
|
|
200
|
-
$id: 'bl1221',
|
|
201
|
-
},
|
|
202
|
-
],
|
|
203
|
-
},
|
|
204
|
-
async (args) => {
|
|
205
|
-
if (args.value.type === 'thing') {
|
|
206
|
-
return 'tilil'
|
|
207
|
-
} else {
|
|
208
|
-
return 'bl1221'
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
)
|
|
212
|
-
t.is(r.errors.length, 0)
|
|
213
|
-
|
|
214
|
-
t.deepEqual(resultCollect(r), [
|
|
215
|
-
{ path: ['ref'], value: 'bl1221' },
|
|
216
|
-
{ path: ['children'], value: { $value: ['bl1221'] } },
|
|
217
|
-
])
|
|
218
|
-
})
|