@based/schema 0.0.16 → 1.0.1
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/error.d.ts → error.d.ts} +4 -2
- package/dist/{set/error.js → error.js} +2 -0
- package/dist/error.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/set/fields/array.d.ts +2 -0
- package/dist/set/fields/array.js +96 -0
- package/dist/set/fields/array.js.map +1 -0
- package/dist/set/fields/index.d.ts +3 -0
- package/dist/set/fields/index.js +72 -0
- package/dist/set/fields/index.js.map +1 -0
- package/dist/set/fields/number.d.ts +4 -0
- package/dist/set/fields/number.js +121 -0
- package/dist/set/fields/number.js.map +1 -0
- package/dist/set/fields/object.d.ts +3 -0
- package/dist/set/fields/object.js +33 -0
- package/dist/set/fields/object.js.map +1 -0
- package/dist/set/fields/references.d.ts +3 -0
- package/dist/set/fields/references.js +106 -0
- package/dist/set/fields/references.js.map +1 -0
- package/dist/set/fields/set.d.ts +2 -0
- package/dist/set/fields/set.js +63 -0
- package/dist/set/fields/set.js.map +1 -0
- package/dist/set/fields/string.d.ts +3 -0
- package/dist/set/fields/string.js +190 -0
- package/dist/set/fields/string.js.map +1 -0
- package/dist/set/index.d.ts +2 -5
- package/dist/set/index.js +98 -126
- package/dist/set/index.js.map +1 -1
- package/dist/set/isValidId.d.ts +2 -0
- package/dist/set/isValidId.js +21 -0
- package/dist/set/isValidId.js.map +1 -0
- package/dist/set/types.d.ts +0 -5
- package/dist/set/types.js +0 -2
- package/dist/types.d.ts +7 -1
- package/dist/types.js.map +1 -1
- package/dist/walker/args.d.ts +31 -0
- package/dist/walker/args.js +120 -0
- package/dist/walker/args.js.map +1 -0
- package/dist/walker/index.d.ts +6 -0
- package/dist/walker/index.js +40 -0
- package/dist/walker/index.js.map +1 -0
- package/dist/walker/parse.d.ts +2 -0
- package/dist/walker/parse.js +157 -0
- package/dist/walker/parse.js.map +1 -0
- package/dist/walker/types.d.ts +44 -0
- package/dist/walker/types.js +9 -0
- package/dist/walker/types.js.map +1 -0
- package/package.json +2 -2
- package/src/{set/error.ts → error.ts} +3 -1
- package/src/index.ts +2 -2
- package/src/set/fields/array.ts +111 -0
- package/src/set/fields/index.ts +69 -0
- package/src/set/fields/number.ts +134 -0
- package/src/set/fields/object.ts +30 -0
- package/src/set/fields/references.ts +114 -0
- package/src/set/fields/set.ts +63 -0
- package/src/set/fields/string.ts +199 -0
- package/src/set/index.ts +103 -188
- package/src/set/isValidId.ts +23 -0
- package/src/set/types.ts +0 -20
- package/src/types.ts +4 -2
- package/src/walker/args.ts +159 -0
- package/src/walker/index.ts +35 -0
- package/src/walker/parse.ts +193 -0
- package/src/walker/types.ts +75 -0
- package/test/number.ts +289 -543
- package/test/reference.ts +150 -198
- package/test/rest.ts +227 -0
- package/test/string.ts +139 -183
- package/test/utils/index.ts +23 -0
- package/test/walker.ts +558 -3
- package/dist/set/collections.d.ts +0 -5
- package/dist/set/collections.js +0 -229
- package/dist/set/collections.js.map +0 -1
- package/dist/set/error.js.map +0 -1
- package/dist/set/number.d.ts +0 -4
- package/dist/set/number.js +0 -124
- package/dist/set/number.js.map +0 -1
- package/dist/set/parseDefaultAndValue.d.ts +0 -3
- package/dist/set/parseDefaultAndValue.js +0 -35
- 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 -84
- 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/dist/set2/index.d.ts +0 -0
- package/dist/set2/index.js +0 -71
- package/dist/set2/index.js.map +0 -1
- package/dist/walker.d.ts +0 -51
- package/dist/walker.js +0 -120
- package/dist/walker.js.map +0 -1
- package/src/set/collections.ts +0 -338
- package/src/set/number.ts +0 -167
- package/src/set/parseDefaultAndValue.ts +0 -54
- package/src/set/parsers.ts +0 -20
- package/src/set/references.ts +0 -113
- package/src/set/rest.ts +0 -135
- package/src/set/string.ts +0 -254
- package/src/set2/index.ts +0 -71
- package/src/walker.ts +0 -201
- package/test/setWalker.ts +0 -494
- package/test/text.ts +0 -171
package/test/setWalker.ts
DELETED
|
@@ -1,494 +0,0 @@
|
|
|
1
|
-
import test from 'ava'
|
|
2
|
-
import { BasedSchema, setWalker } from '../src/index'
|
|
3
|
-
|
|
4
|
-
const schema: BasedSchema = {
|
|
5
|
-
types: {
|
|
6
|
-
bla: {
|
|
7
|
-
prefix: 'bl',
|
|
8
|
-
fields: {
|
|
9
|
-
visits: {
|
|
10
|
-
type: 'cardinality',
|
|
11
|
-
},
|
|
12
|
-
blub: {
|
|
13
|
-
type: 'number',
|
|
14
|
-
},
|
|
15
|
-
flap: {
|
|
16
|
-
type: 'number',
|
|
17
|
-
},
|
|
18
|
-
snurpobject: {
|
|
19
|
-
type: 'object',
|
|
20
|
-
properties: {
|
|
21
|
-
x: {
|
|
22
|
-
type: 'string',
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
snurp: {
|
|
27
|
-
type: 'array',
|
|
28
|
-
values: {
|
|
29
|
-
type: 'object',
|
|
30
|
-
properties: {
|
|
31
|
-
x: {
|
|
32
|
-
type: 'array',
|
|
33
|
-
values: {
|
|
34
|
-
type: 'number',
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
setje: {
|
|
41
|
-
type: 'set',
|
|
42
|
-
items: { type: 'number' },
|
|
43
|
-
},
|
|
44
|
-
specialArray: {
|
|
45
|
-
type: 'array',
|
|
46
|
-
values: {
|
|
47
|
-
type: 'string',
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
snurpArray: {
|
|
51
|
-
type: 'array',
|
|
52
|
-
values: {
|
|
53
|
-
type: 'number',
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
powerLevel: {
|
|
57
|
-
type: 'integer',
|
|
58
|
-
},
|
|
59
|
-
bla: {
|
|
60
|
-
type: 'boolean',
|
|
61
|
-
},
|
|
62
|
-
time: {
|
|
63
|
-
type: 'timestamp',
|
|
64
|
-
},
|
|
65
|
-
form: {
|
|
66
|
-
title: 'A registration form',
|
|
67
|
-
description: 'A simple form example.',
|
|
68
|
-
type: 'object',
|
|
69
|
-
required: ['firstName', 'lastName'],
|
|
70
|
-
properties: {
|
|
71
|
-
bla: {
|
|
72
|
-
type: 'references',
|
|
73
|
-
},
|
|
74
|
-
blab: {
|
|
75
|
-
type: 'references',
|
|
76
|
-
},
|
|
77
|
-
snurp: {
|
|
78
|
-
type: 'reference',
|
|
79
|
-
},
|
|
80
|
-
things: {
|
|
81
|
-
enum: ['yuzi', 'jux', 'mr tony', 9000],
|
|
82
|
-
},
|
|
83
|
-
blub: {
|
|
84
|
-
type: 'set',
|
|
85
|
-
items: { type: 'string' },
|
|
86
|
-
},
|
|
87
|
-
json: {
|
|
88
|
-
type: 'json',
|
|
89
|
-
},
|
|
90
|
-
firstName: {
|
|
91
|
-
type: 'string',
|
|
92
|
-
title: 'First name',
|
|
93
|
-
default: 'Chuck',
|
|
94
|
-
},
|
|
95
|
-
lastName: {
|
|
96
|
-
type: 'string',
|
|
97
|
-
title: 'Last name',
|
|
98
|
-
},
|
|
99
|
-
age: {
|
|
100
|
-
type: 'integer',
|
|
101
|
-
title: 'Age',
|
|
102
|
-
},
|
|
103
|
-
bio: {
|
|
104
|
-
type: 'string',
|
|
105
|
-
title: 'Bio',
|
|
106
|
-
},
|
|
107
|
-
password: {
|
|
108
|
-
type: 'string',
|
|
109
|
-
title: 'Password',
|
|
110
|
-
minLength: 3,
|
|
111
|
-
},
|
|
112
|
-
telephone: {
|
|
113
|
-
type: 'string',
|
|
114
|
-
title: 'Telephone',
|
|
115
|
-
minLength: 10,
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
$defs: {},
|
|
123
|
-
languages: ['en'],
|
|
124
|
-
root: {
|
|
125
|
-
fields: {},
|
|
126
|
-
},
|
|
127
|
-
prefixToTypeMapping: {
|
|
128
|
-
bl: 'bla',
|
|
129
|
-
},
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
test('collect correctly', async (t) => {
|
|
133
|
-
const results: { path: (string | number)[]; value: any }[] = []
|
|
134
|
-
const now = Date.now()
|
|
135
|
-
await setWalker(
|
|
136
|
-
schema,
|
|
137
|
-
{
|
|
138
|
-
$id: 'bl1',
|
|
139
|
-
visits: {
|
|
140
|
-
flap: true,
|
|
141
|
-
snurp: false,
|
|
142
|
-
ua: '123435',
|
|
143
|
-
},
|
|
144
|
-
blub: {
|
|
145
|
-
$increment: 1,
|
|
146
|
-
},
|
|
147
|
-
bla: false,
|
|
148
|
-
time: now,
|
|
149
|
-
setje: [1, 2, 3],
|
|
150
|
-
form: {
|
|
151
|
-
lastName: 'de beer',
|
|
152
|
-
bla: ['bl123', 'bl234'],
|
|
153
|
-
blab: { $add: ['bl456'] },
|
|
154
|
-
blub: ['x'],
|
|
155
|
-
json: { bla: 1, x: 2, y: 3 },
|
|
156
|
-
snurp: 'blx12',
|
|
157
|
-
things: 'mr tony',
|
|
158
|
-
password: 'mypassword!',
|
|
159
|
-
},
|
|
160
|
-
snurpArray: {
|
|
161
|
-
$assign: {
|
|
162
|
-
$idx: 0,
|
|
163
|
-
$value: 100,
|
|
164
|
-
},
|
|
165
|
-
},
|
|
166
|
-
specialArray: {
|
|
167
|
-
$insert: {
|
|
168
|
-
$value: ['a', 'b', 'c'],
|
|
169
|
-
$idx: 0,
|
|
170
|
-
},
|
|
171
|
-
},
|
|
172
|
-
snurp: [
|
|
173
|
-
{
|
|
174
|
-
x: [1, 2, 3],
|
|
175
|
-
},
|
|
176
|
-
],
|
|
177
|
-
},
|
|
178
|
-
{
|
|
179
|
-
collectErrors: (info) => {
|
|
180
|
-
// fix fields (too heavy)
|
|
181
|
-
},
|
|
182
|
-
collect: ({ path, value, typeSchema, fieldSchema, target }) => {
|
|
183
|
-
results.push({
|
|
184
|
-
path,
|
|
185
|
-
value,
|
|
186
|
-
})
|
|
187
|
-
},
|
|
188
|
-
checkRequiredFields: async (path) => {
|
|
189
|
-
return true
|
|
190
|
-
},
|
|
191
|
-
referenceFilterCondition: async (id, filter) => {
|
|
192
|
-
return true
|
|
193
|
-
},
|
|
194
|
-
}
|
|
195
|
-
)
|
|
196
|
-
|
|
197
|
-
const result = [
|
|
198
|
-
{ path: ['visits'], value: '3a9009740ee' },
|
|
199
|
-
{ path: ['blub'], value: { $increment: 1 } },
|
|
200
|
-
{ path: ['time'], value: now },
|
|
201
|
-
{ path: ['form', 'snurp'], value: 'blx12' },
|
|
202
|
-
{
|
|
203
|
-
path: ['snurpArray', 0],
|
|
204
|
-
value: 100,
|
|
205
|
-
},
|
|
206
|
-
{ path: ['bla'], value: false },
|
|
207
|
-
{ path: ['form', 'lastName'], value: 'de beer' },
|
|
208
|
-
{ path: ['form', 'json'], value: '{"bla":1,"x":2,"y":3}' },
|
|
209
|
-
{ path: ['form', 'things'], value: 2 },
|
|
210
|
-
{ path: ['form', 'password'], value: 'mypassword!' },
|
|
211
|
-
{ path: ['form', 'bla'], value: { $value: ['bl123', 'bl234'] } },
|
|
212
|
-
{ path: ['form', 'blab'], value: { $add: ['bl456'] } },
|
|
213
|
-
{ path: ['setje'], value: { $value: [1, 2, 3] } },
|
|
214
|
-
{ path: ['form', 'blub'], value: { $value: ['x'] } },
|
|
215
|
-
{
|
|
216
|
-
path: ['specialArray'],
|
|
217
|
-
value: { $insert: { $value: ['a', 'b', 'c'], $idx: 0 } },
|
|
218
|
-
},
|
|
219
|
-
{ path: ['snurp'], value: { $delete: true } },
|
|
220
|
-
{ path: ['snurp', 0, 'x'], value: { $delete: true } },
|
|
221
|
-
{ path: ['snurp', 0, 'x', 0], value: 1 },
|
|
222
|
-
{ path: ['snurp', 0, 'x', 1], value: 2 },
|
|
223
|
-
{ path: ['snurp', 0, 'x', 2], value: 3 },
|
|
224
|
-
]
|
|
225
|
-
|
|
226
|
-
t.deepEqual(results, result)
|
|
227
|
-
|
|
228
|
-
const results2: any[] = []
|
|
229
|
-
await setWalker(
|
|
230
|
-
schema,
|
|
231
|
-
{
|
|
232
|
-
$id: 'bl1',
|
|
233
|
-
blub: {
|
|
234
|
-
$value: 4,
|
|
235
|
-
},
|
|
236
|
-
flap: {
|
|
237
|
-
$default: 1,
|
|
238
|
-
},
|
|
239
|
-
},
|
|
240
|
-
{
|
|
241
|
-
collectErrors: (info) => {
|
|
242
|
-
// {
|
|
243
|
-
// path,
|
|
244
|
-
// value,
|
|
245
|
-
// typeSchema,
|
|
246
|
-
// fieldSchema,
|
|
247
|
-
// target,
|
|
248
|
-
// code,
|
|
249
|
-
// message,
|
|
250
|
-
// }
|
|
251
|
-
|
|
252
|
-
console.error(info.message)
|
|
253
|
-
// fix fields (too heavy)
|
|
254
|
-
},
|
|
255
|
-
collect: ({ path, value, typeSchema, fieldSchema, target }) => {
|
|
256
|
-
results2.push({
|
|
257
|
-
path,
|
|
258
|
-
value,
|
|
259
|
-
})
|
|
260
|
-
},
|
|
261
|
-
checkRequiredFields: async (path) => {
|
|
262
|
-
return false
|
|
263
|
-
},
|
|
264
|
-
referenceFilterCondition: async (id, filter) => {
|
|
265
|
-
return true
|
|
266
|
-
},
|
|
267
|
-
}
|
|
268
|
-
)
|
|
269
|
-
|
|
270
|
-
t.deepEqual(results2, [
|
|
271
|
-
{ path: ['blub'], value: { $value: 4 } },
|
|
272
|
-
{ path: ['flap'], value: { $default: 1 } },
|
|
273
|
-
])
|
|
274
|
-
|
|
275
|
-
const results3: any[] = []
|
|
276
|
-
await setWalker(
|
|
277
|
-
schema,
|
|
278
|
-
{
|
|
279
|
-
$id: 'bl1',
|
|
280
|
-
snurpArray: {
|
|
281
|
-
$push: 1,
|
|
282
|
-
},
|
|
283
|
-
specialArray: {
|
|
284
|
-
$push: { $value: 'flap' },
|
|
285
|
-
},
|
|
286
|
-
},
|
|
287
|
-
{
|
|
288
|
-
collectErrors: (info) => {
|
|
289
|
-
// {
|
|
290
|
-
// path,
|
|
291
|
-
// value,
|
|
292
|
-
// typeSchema,
|
|
293
|
-
// fieldSchema,
|
|
294
|
-
// target,
|
|
295
|
-
// code,
|
|
296
|
-
// message,
|
|
297
|
-
// }
|
|
298
|
-
|
|
299
|
-
console.error(info.message)
|
|
300
|
-
// fix fields (too heavy)
|
|
301
|
-
},
|
|
302
|
-
collect: ({ path, value, typeSchema, fieldSchema, target }) => {
|
|
303
|
-
results3.push({
|
|
304
|
-
path,
|
|
305
|
-
value,
|
|
306
|
-
})
|
|
307
|
-
},
|
|
308
|
-
checkRequiredFields: async (path) => {
|
|
309
|
-
return false
|
|
310
|
-
},
|
|
311
|
-
referenceFilterCondition: async (id, filter) => {
|
|
312
|
-
return true
|
|
313
|
-
},
|
|
314
|
-
}
|
|
315
|
-
)
|
|
316
|
-
|
|
317
|
-
t.deepEqual(results3, [
|
|
318
|
-
{ path: ['snurpArray'], value: { $push: [1] } },
|
|
319
|
-
{ path: ['specialArray'], value: { $push: [{ $value: 'flap' }] } },
|
|
320
|
-
])
|
|
321
|
-
})
|
|
322
|
-
|
|
323
|
-
test('required', async (t) => {
|
|
324
|
-
const schema: BasedSchema = {
|
|
325
|
-
types: {
|
|
326
|
-
bla: {
|
|
327
|
-
prefix: 'bl',
|
|
328
|
-
required: ['blub', 'flap', 'snurp'],
|
|
329
|
-
fields: {
|
|
330
|
-
blub: {
|
|
331
|
-
type: 'number',
|
|
332
|
-
},
|
|
333
|
-
flap: {
|
|
334
|
-
type: 'number',
|
|
335
|
-
},
|
|
336
|
-
snurp: {
|
|
337
|
-
type: 'object',
|
|
338
|
-
required: ['x'],
|
|
339
|
-
properties: {
|
|
340
|
-
x: {
|
|
341
|
-
type: 'object',
|
|
342
|
-
required: ['a', 'b', 'c'],
|
|
343
|
-
properties: {
|
|
344
|
-
a: { type: 'string' },
|
|
345
|
-
b: { type: 'string' },
|
|
346
|
-
c: { type: 'string' },
|
|
347
|
-
},
|
|
348
|
-
},
|
|
349
|
-
},
|
|
350
|
-
},
|
|
351
|
-
array: {
|
|
352
|
-
type: 'array',
|
|
353
|
-
values: {
|
|
354
|
-
type: 'object',
|
|
355
|
-
required: ['a', 'b', 'c'],
|
|
356
|
-
properties: {
|
|
357
|
-
a: { type: 'string' },
|
|
358
|
-
b: { type: 'string' },
|
|
359
|
-
c: { type: 'string' },
|
|
360
|
-
},
|
|
361
|
-
},
|
|
362
|
-
},
|
|
363
|
-
},
|
|
364
|
-
},
|
|
365
|
-
},
|
|
366
|
-
$defs: {},
|
|
367
|
-
languages: ['en'],
|
|
368
|
-
root: {
|
|
369
|
-
fields: {},
|
|
370
|
-
},
|
|
371
|
-
prefixToTypeMapping: {
|
|
372
|
-
bl: 'bla',
|
|
373
|
-
},
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
const t1 = await setWalker(
|
|
377
|
-
schema,
|
|
378
|
-
{
|
|
379
|
-
type: 'bla',
|
|
380
|
-
blub: 1,
|
|
381
|
-
flap: 1,
|
|
382
|
-
snurp: {
|
|
383
|
-
x: { a: 'b' },
|
|
384
|
-
},
|
|
385
|
-
},
|
|
386
|
-
{
|
|
387
|
-
collectErrors: (info) => {
|
|
388
|
-
// {
|
|
389
|
-
// path,
|
|
390
|
-
// value,
|
|
391
|
-
// typeSchema,
|
|
392
|
-
// fieldSchema,
|
|
393
|
-
// target,
|
|
394
|
-
// code,
|
|
395
|
-
// message,
|
|
396
|
-
// }
|
|
397
|
-
|
|
398
|
-
console.error(info.message)
|
|
399
|
-
// fix fields (too heavy)
|
|
400
|
-
},
|
|
401
|
-
collect: ({ path, value, typeSchema, fieldSchema, target }) => {},
|
|
402
|
-
checkRequiredFields: async (paths) => {
|
|
403
|
-
return true
|
|
404
|
-
},
|
|
405
|
-
referenceFilterCondition: async (id, filter) => {
|
|
406
|
-
return true
|
|
407
|
-
},
|
|
408
|
-
}
|
|
409
|
-
)
|
|
410
|
-
|
|
411
|
-
t.deepEqual(t1.required, [
|
|
412
|
-
['snurp', 'x', 'b'],
|
|
413
|
-
['snurp', 'x', 'c'],
|
|
414
|
-
])
|
|
415
|
-
|
|
416
|
-
const t2 = await setWalker(
|
|
417
|
-
schema,
|
|
418
|
-
{
|
|
419
|
-
type: 'bla',
|
|
420
|
-
array: [
|
|
421
|
-
{
|
|
422
|
-
a: 'hello', // say cant set non existing field
|
|
423
|
-
},
|
|
424
|
-
],
|
|
425
|
-
},
|
|
426
|
-
{
|
|
427
|
-
collectErrors: (info) => {
|
|
428
|
-
// {
|
|
429
|
-
// path,
|
|
430
|
-
// value,
|
|
431
|
-
// typeSchema,
|
|
432
|
-
// fieldSchema,
|
|
433
|
-
// target,
|
|
434
|
-
// code,
|
|
435
|
-
// message,
|
|
436
|
-
// }
|
|
437
|
-
|
|
438
|
-
console.error(info.message)
|
|
439
|
-
// fix fields (too heavy)
|
|
440
|
-
},
|
|
441
|
-
collect: ({ path, value, typeSchema, fieldSchema, target }) => {},
|
|
442
|
-
checkRequiredFields: async (paths) => {
|
|
443
|
-
// should be [snurp.x.b, snurp.x.c]
|
|
444
|
-
return true
|
|
445
|
-
},
|
|
446
|
-
referenceFilterCondition: async (id, filter) => {
|
|
447
|
-
return true
|
|
448
|
-
},
|
|
449
|
-
}
|
|
450
|
-
)
|
|
451
|
-
|
|
452
|
-
t.deepEqual(t2.required, [
|
|
453
|
-
['array', 0, 'b'],
|
|
454
|
-
['array', 0, 'c'],
|
|
455
|
-
['blub'],
|
|
456
|
-
['flap'],
|
|
457
|
-
['snurp'],
|
|
458
|
-
])
|
|
459
|
-
|
|
460
|
-
t.true(true)
|
|
461
|
-
})
|
|
462
|
-
|
|
463
|
-
test.only('collect all errors', async (t) => {
|
|
464
|
-
try {
|
|
465
|
-
await setWalker(
|
|
466
|
-
schema,
|
|
467
|
-
{
|
|
468
|
-
type: 'bla',
|
|
469
|
-
blub: 'snux',
|
|
470
|
-
flap: 'gurt',
|
|
471
|
-
snurpobject: {
|
|
472
|
-
x: 1,
|
|
473
|
-
},
|
|
474
|
-
// wrong validate total objects
|
|
475
|
-
snurp: {
|
|
476
|
-
// checking non formatted objects
|
|
477
|
-
x: { a: 20220 },
|
|
478
|
-
},
|
|
479
|
-
},
|
|
480
|
-
{
|
|
481
|
-
checkRequiredFields: async (paths) => {
|
|
482
|
-
return true
|
|
483
|
-
},
|
|
484
|
-
referenceFilterCondition: async (id, filter) => {
|
|
485
|
-
return true
|
|
486
|
-
},
|
|
487
|
-
}
|
|
488
|
-
)
|
|
489
|
-
} catch (err) {
|
|
490
|
-
console.info(err)
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
t.true(true)
|
|
494
|
-
})
|
package/test/text.ts
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import test from 'ava'
|
|
2
|
-
import { BasedSchema, setWalker, BasedSetOptionalHandlers } from '../src/index'
|
|
3
|
-
|
|
4
|
-
const schema: BasedSchema = {
|
|
5
|
-
types: {
|
|
6
|
-
bla: {
|
|
7
|
-
prefix: 'bl',
|
|
8
|
-
fields: {
|
|
9
|
-
name: {
|
|
10
|
-
minLength: 3,
|
|
11
|
-
maxLength: 6,
|
|
12
|
-
type: 'text',
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
$defs: {},
|
|
18
|
-
languages: ['en', 'de'],
|
|
19
|
-
root: {
|
|
20
|
-
fields: {},
|
|
21
|
-
},
|
|
22
|
-
prefixToTypeMapping: {
|
|
23
|
-
bl: 'bla',
|
|
24
|
-
},
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const createHandlers = (): {
|
|
28
|
-
results: { path: (number | string)[]; value: any }[]
|
|
29
|
-
handlers: BasedSetOptionalHandlers
|
|
30
|
-
} => {
|
|
31
|
-
const results: { path: (number | string)[]; value: any }[] = []
|
|
32
|
-
const handlers = {
|
|
33
|
-
collect: ({ path, value, typeSchema, fieldSchema, target }) => {
|
|
34
|
-
console.log('collect', path)
|
|
35
|
-
results.push({ path, value })
|
|
36
|
-
},
|
|
37
|
-
checkRequiredFields: async (paths) => {
|
|
38
|
-
return true
|
|
39
|
-
},
|
|
40
|
-
referenceFilterCondition: async (id, filter) => {
|
|
41
|
-
return true
|
|
42
|
-
},
|
|
43
|
-
}
|
|
44
|
-
return { results, handlers }
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
test('text max length', async (t) => {
|
|
48
|
-
const { handlers, results } = createHandlers()
|
|
49
|
-
await t.throwsAsync(
|
|
50
|
-
setWalker(
|
|
51
|
-
schema,
|
|
52
|
-
{
|
|
53
|
-
$id: 'bl1',
|
|
54
|
-
name: {
|
|
55
|
-
de: 'ax',
|
|
56
|
-
nl: 'axa',
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
handlers
|
|
60
|
-
)
|
|
61
|
-
)
|
|
62
|
-
await t.throwsAsync(
|
|
63
|
-
setWalker(
|
|
64
|
-
schema,
|
|
65
|
-
{
|
|
66
|
-
$id: 'bl1',
|
|
67
|
-
$language: 'de',
|
|
68
|
-
name: 'axaxaxax',
|
|
69
|
-
},
|
|
70
|
-
handlers
|
|
71
|
-
)
|
|
72
|
-
)
|
|
73
|
-
await setWalker(
|
|
74
|
-
schema,
|
|
75
|
-
{
|
|
76
|
-
$id: 'bl1',
|
|
77
|
-
$language: 'en',
|
|
78
|
-
name: 'xaxx',
|
|
79
|
-
},
|
|
80
|
-
handlers
|
|
81
|
-
)
|
|
82
|
-
t.deepEqual(results, [{ path: ['name'], value: { en: 'xaxx' } }])
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
test('text wrong language', async (t) => {
|
|
86
|
-
const { handlers, results } = createHandlers()
|
|
87
|
-
await t.throwsAsync(
|
|
88
|
-
setWalker(
|
|
89
|
-
schema,
|
|
90
|
-
{
|
|
91
|
-
$id: 'bl1',
|
|
92
|
-
name: {
|
|
93
|
-
de: 'xaxx',
|
|
94
|
-
nl: 'xaxx',
|
|
95
|
-
es: 'flap',
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
handlers
|
|
99
|
-
)
|
|
100
|
-
)
|
|
101
|
-
|
|
102
|
-
await setWalker(
|
|
103
|
-
schema,
|
|
104
|
-
{
|
|
105
|
-
$id: 'bl1',
|
|
106
|
-
$language: 'de',
|
|
107
|
-
name: 'blabla',
|
|
108
|
-
},
|
|
109
|
-
handlers
|
|
110
|
-
)
|
|
111
|
-
|
|
112
|
-
//TODO fix
|
|
113
|
-
t.deepEqual(results, [
|
|
114
|
-
{ path: ['name', 'de'], value: 'blabla' },
|
|
115
|
-
{ path: ['name'], value: { de: 'blabla' } },
|
|
116
|
-
])
|
|
117
|
-
})
|
|
118
|
-
|
|
119
|
-
test('default', async (t) => {
|
|
120
|
-
const { handlers, results } = createHandlers()
|
|
121
|
-
await setWalker(
|
|
122
|
-
schema,
|
|
123
|
-
{
|
|
124
|
-
$id: 'bl1',
|
|
125
|
-
$language: 'de',
|
|
126
|
-
name: { $default: 'xaxx' },
|
|
127
|
-
},
|
|
128
|
-
handlers
|
|
129
|
-
)
|
|
130
|
-
await setWalker(
|
|
131
|
-
schema,
|
|
132
|
-
{
|
|
133
|
-
$id: 'bl1',
|
|
134
|
-
$language: 'de',
|
|
135
|
-
name: { de: { $default: 'xaxx' } },
|
|
136
|
-
},
|
|
137
|
-
handlers
|
|
138
|
-
)
|
|
139
|
-
t.deepEqual(results, [
|
|
140
|
-
{ path: ['name'], value: { de: { $default: 'xaxx' } } },
|
|
141
|
-
{ path: ['name'], value: { de: { $default: 'xaxx' } } },
|
|
142
|
-
])
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
test('value', async (t) => {
|
|
146
|
-
const { handlers, results } = createHandlers()
|
|
147
|
-
await t.throwsAsync(
|
|
148
|
-
setWalker(
|
|
149
|
-
schema,
|
|
150
|
-
{
|
|
151
|
-
$id: 'bl1',
|
|
152
|
-
$language: 'de',
|
|
153
|
-
name: { $value: 'xaxx' },
|
|
154
|
-
},
|
|
155
|
-
handlers
|
|
156
|
-
)
|
|
157
|
-
)
|
|
158
|
-
t.deepEqual(results, [])
|
|
159
|
-
|
|
160
|
-
await setWalker(
|
|
161
|
-
schema,
|
|
162
|
-
{
|
|
163
|
-
$id: 'bl1',
|
|
164
|
-
$language: 'de',
|
|
165
|
-
name: { de: { $value: 'xaxx' } },
|
|
166
|
-
},
|
|
167
|
-
handlers
|
|
168
|
-
)
|
|
169
|
-
console.log('-------------->', results)
|
|
170
|
-
t.deepEqual(results, [{ path: ['name', 'de'], value: { $value: 'xaxx' } }])
|
|
171
|
-
})
|