@based/schema 0.0.10 → 0.0.11
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/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/set/collections.js +39 -17
- package/dist/set/collections.js.map +1 -1
- package/dist/set/error.d.ts +4 -2
- package/dist/set/error.js +9 -3
- package/dist/set/error.js.map +1 -1
- package/dist/set/index.d.ts +2 -2
- package/dist/set/index.js +48 -8
- package/dist/set/index.js.map +1 -1
- package/dist/set/number.js +37 -23
- package/dist/set/number.js.map +1 -1
- package/dist/set/parseDefaultAndValue.js +5 -3
- package/dist/set/parseDefaultAndValue.js.map +1 -1
- package/dist/set/references.js +12 -5
- package/dist/set/references.js.map +1 -1
- package/dist/set/rest.js +4 -4
- package/dist/set/rest.js.map +1 -1
- package/dist/set/string.js +38 -34
- package/dist/set/string.js.map +1 -1
- package/dist/set2/index.js +1 -0
- package/dist/set2/index.js.map +1 -0
- package/dist/types.d.ts +8 -2
- package/dist/types.js.map +1 -1
- package/dist/walker.d.ts +50 -0
- package/dist/walker.js +83 -0
- package/dist/walker.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/set/collections.ts +42 -17
- package/src/set/error.ts +13 -3
- package/src/set/index.ts +65 -8
- package/src/set/number.ts +39 -22
- package/src/set/parseDefaultAndValue.ts +13 -3
- package/src/set/references.ts +11 -5
- package/src/set/rest.ts +4 -4
- package/src/set/string.ts +48 -36
- package/src/set2/index.ts +0 -0
- package/src/types.ts +16 -7
- package/src/walker.ts +152 -0
- package/test/number.ts +646 -0
- package/test/reference.ts +207 -0
- package/test/setWalker.ts +101 -21
- package/test/string.ts +183 -0
- package/test/text.ts +171 -0
- package/test/validateSchema.ts +0 -1
- package/test/walker.ts +99 -0
- package/dist/deepPartial.js +0 -3
- package/dist/deepPartial.js.map +0 -1
- package/dist/schema.d.ts +0 -1
- package/dist/schema.js +0 -3
- package/dist/schema.js.map +0 -1
- package/dist/set/checkDefaultAndValue.d.ts +0 -3
- package/dist/set/checkDefaultAndValue.js +0 -33
- package/dist/set/checkDefaultAndValue.js.map +0 -1
- package/dist/set/enum.d.ts +0 -2
- package/dist/set/enum.js +0 -15
- package/dist/set/enum.js.map +0 -1
- package/dist/set/fieldValidator.d.ts +0 -6
- package/dist/set/fieldValidator.js +0 -144
- package/dist/set/fieldValidator.js.map +0 -1
- package/dist/set/handleError.d.ts +0 -1
- package/dist/set/handleError.js +0 -9
- package/dist/set/handleError.js.map +0 -1
- package/dist/set/number copy.d.ts +0 -4
- package/dist/set/number copy.js +0 -57
- package/dist/set/number copy.js.map +0 -1
- package/dist/set/rest copy.d.ts +0 -5
- package/dist/set/rest copy.js +0 -53
- package/dist/set/rest copy.js.map +0 -1
- package/dist/setWalker.d.ts +0 -11
- package/dist/setWalker.js +0 -189
- package/dist/setWalker.js.map +0 -1
- package/dist/transformers.d.ts +0 -3
- package/dist/transformers.js +0 -18
- package/dist/transformers.js.map +0 -1
- package/dist/typeWalker.d.ts +0 -3
- package/dist/typeWalker.js +0 -18
- package/dist/typeWalker.js.map +0 -1
- package/dist/validate.d.ts +0 -4
- package/dist/validate.js +0 -34
- package/dist/validate.js.map +0 -1
- package/dist/validateFields.d.ts +0 -4
- package/dist/validateFields.js +0 -34
- package/dist/validateFields.js.map +0 -1
- package/dist/validateSchema copy.d.ts +0 -4
- package/dist/validateSchema copy.js +0 -34
- package/dist/validateSchema copy.js.map +0 -1
- /package/dist/{deepPartial.d.ts → set2/index.d.ts} +0 -0
|
@@ -0,0 +1,207 @@
|
|
|
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
|
+
ref: {
|
|
10
|
+
type: 'reference',
|
|
11
|
+
allowedTypes: ['bla'],
|
|
12
|
+
},
|
|
13
|
+
ref2: {
|
|
14
|
+
type: 'references',
|
|
15
|
+
allowedTypes: ['bla'],
|
|
16
|
+
},
|
|
17
|
+
arr: {
|
|
18
|
+
type: 'array',
|
|
19
|
+
title: '',
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
$defs: {},
|
|
25
|
+
languages: ['en'],
|
|
26
|
+
root: {
|
|
27
|
+
fields: {},
|
|
28
|
+
},
|
|
29
|
+
prefixToTypeMapping: {
|
|
30
|
+
bl: 'bla',
|
|
31
|
+
},
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const createHandlers = (): {
|
|
35
|
+
results: { path: (number | string)[]; value: any }[]
|
|
36
|
+
handlers: BasedSetOptionalHandlers
|
|
37
|
+
} => {
|
|
38
|
+
const results: { path: (number | string)[]; value: any }[] = []
|
|
39
|
+
const handlers = {
|
|
40
|
+
collect: ({ path, value, typeSchema, fieldSchema, target }) => {
|
|
41
|
+
results.push({ path, value })
|
|
42
|
+
},
|
|
43
|
+
checkRequiredFields: async (paths) => {
|
|
44
|
+
return true
|
|
45
|
+
},
|
|
46
|
+
referenceFilterCondition: async (id, filter) => {
|
|
47
|
+
return true
|
|
48
|
+
},
|
|
49
|
+
}
|
|
50
|
+
return { results, handlers }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
test('reference', async (t) => {
|
|
54
|
+
const { handlers, results } = createHandlers()
|
|
55
|
+
await t.throwsAsync(
|
|
56
|
+
setWalker(
|
|
57
|
+
schema,
|
|
58
|
+
{
|
|
59
|
+
$id: 'bl1',
|
|
60
|
+
ref: ['1', '2'],
|
|
61
|
+
},
|
|
62
|
+
handlers
|
|
63
|
+
)
|
|
64
|
+
)
|
|
65
|
+
await t.throwsAsync(
|
|
66
|
+
setWalker(
|
|
67
|
+
schema,
|
|
68
|
+
{
|
|
69
|
+
$id: 'bl1',
|
|
70
|
+
ref: 1,
|
|
71
|
+
},
|
|
72
|
+
handlers
|
|
73
|
+
)
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
await setWalker(
|
|
77
|
+
schema,
|
|
78
|
+
{
|
|
79
|
+
$id: 'bl1',
|
|
80
|
+
ref: 'asdasdasdasdasd',
|
|
81
|
+
},
|
|
82
|
+
handlers
|
|
83
|
+
)
|
|
84
|
+
t.deepEqual(results, [{ path: ['ref'], value: 'asdasdasdasdasd' }])
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
test('multiple references', async (t) => {
|
|
88
|
+
const { handlers, results } = createHandlers()
|
|
89
|
+
|
|
90
|
+
// await t.throwsAsync(
|
|
91
|
+
// setWalker(
|
|
92
|
+
// schema,
|
|
93
|
+
// {
|
|
94
|
+
// $id: 'bl1',
|
|
95
|
+
// ref2: 0.5,
|
|
96
|
+
// },
|
|
97
|
+
// handlers
|
|
98
|
+
// )
|
|
99
|
+
// )
|
|
100
|
+
// await t.throwsAsync(
|
|
101
|
+
// setWalker(
|
|
102
|
+
// schema,
|
|
103
|
+
// {
|
|
104
|
+
// $id: 'bl1',
|
|
105
|
+
// ref2: 1,
|
|
106
|
+
// },
|
|
107
|
+
// handlers
|
|
108
|
+
// )
|
|
109
|
+
// )
|
|
110
|
+
// these should throw, array of refs doesnt
|
|
111
|
+
//??? todo?
|
|
112
|
+
await t.throwsAsync(
|
|
113
|
+
setWalker(
|
|
114
|
+
schema,
|
|
115
|
+
{
|
|
116
|
+
$id: 'bl1',
|
|
117
|
+
ref2: [1, 1, 1, 1, 1, 1, 1],
|
|
118
|
+
},
|
|
119
|
+
handlers
|
|
120
|
+
)
|
|
121
|
+
)
|
|
122
|
+
console.log(results)
|
|
123
|
+
await setWalker(
|
|
124
|
+
schema,
|
|
125
|
+
{
|
|
126
|
+
$id: 'bl1',
|
|
127
|
+
ref2: ['1', '2', '3'],
|
|
128
|
+
},
|
|
129
|
+
handlers
|
|
130
|
+
)
|
|
131
|
+
t.deepEqual(results, [{ path: ['ref2'], value: { $value: ['1', '2', '3'] } }])
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
test('value of references', async (t) => {
|
|
135
|
+
const { handlers, results } = createHandlers()
|
|
136
|
+
await t.throwsAsync(
|
|
137
|
+
setWalker(
|
|
138
|
+
schema,
|
|
139
|
+
{
|
|
140
|
+
$id: 'bl1',
|
|
141
|
+
ref: { $value: ['1', '2'] },
|
|
142
|
+
},
|
|
143
|
+
handlers
|
|
144
|
+
)
|
|
145
|
+
)
|
|
146
|
+
await t.throwsAsync(
|
|
147
|
+
setWalker(
|
|
148
|
+
schema,
|
|
149
|
+
{
|
|
150
|
+
$id: 'bl1',
|
|
151
|
+
ref: { $value: 1 },
|
|
152
|
+
},
|
|
153
|
+
handlers
|
|
154
|
+
)
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
await setWalker(
|
|
158
|
+
schema,
|
|
159
|
+
{
|
|
160
|
+
$id: 'bl1',
|
|
161
|
+
ref: { $value: 'asdasdasdasdasd' },
|
|
162
|
+
},
|
|
163
|
+
handlers
|
|
164
|
+
)
|
|
165
|
+
console.log('------------>', results)
|
|
166
|
+
//error here?
|
|
167
|
+
t.deepEqual(results, [
|
|
168
|
+
{ path: ['ref'], value: { $value: 'asdasdasdasdasd' } },
|
|
169
|
+
])
|
|
170
|
+
})
|
|
171
|
+
test.only('default of references', async (t) => {
|
|
172
|
+
const { handlers, results } = createHandlers()
|
|
173
|
+
await t.throwsAsync(
|
|
174
|
+
setWalker(
|
|
175
|
+
schema,
|
|
176
|
+
{
|
|
177
|
+
$id: 'bl1',
|
|
178
|
+
ref: { $default: ['1', '2'] },
|
|
179
|
+
},
|
|
180
|
+
handlers
|
|
181
|
+
)
|
|
182
|
+
)
|
|
183
|
+
await t.throwsAsync(
|
|
184
|
+
setWalker(
|
|
185
|
+
schema,
|
|
186
|
+
{
|
|
187
|
+
$id: 'bl1',
|
|
188
|
+
ref: { $default: 1 },
|
|
189
|
+
},
|
|
190
|
+
handlers
|
|
191
|
+
)
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
// await setWalker(
|
|
195
|
+
// schema,
|
|
196
|
+
// {
|
|
197
|
+
// $id: 'bl1',
|
|
198
|
+
// ref: { $default: 'asdasdasdasdasd' },
|
|
199
|
+
// },
|
|
200
|
+
// handlers
|
|
201
|
+
// )
|
|
202
|
+
// console.log('------------>', results)
|
|
203
|
+
// //error here?
|
|
204
|
+
// t.deepEqual(results, [
|
|
205
|
+
// { path: ['ref'], value: { $default: 'asdasdasdasdasd' } },
|
|
206
|
+
// ])
|
|
207
|
+
})
|
package/test/setWalker.ts
CHANGED
|
@@ -15,6 +15,14 @@ const schema: BasedSchema = {
|
|
|
15
15
|
flap: {
|
|
16
16
|
type: 'number',
|
|
17
17
|
},
|
|
18
|
+
snurpobject: {
|
|
19
|
+
type: 'object',
|
|
20
|
+
properties: {
|
|
21
|
+
x: {
|
|
22
|
+
type: 'string',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
},
|
|
18
26
|
snurp: {
|
|
19
27
|
type: 'array',
|
|
20
28
|
values: {
|
|
@@ -121,18 +129,7 @@ const schema: BasedSchema = {
|
|
|
121
129
|
},
|
|
122
130
|
}
|
|
123
131
|
|
|
124
|
-
|
|
125
|
-
// $delete -> change for set / references
|
|
126
|
-
// $merge: false,
|
|
127
|
-
// $assign
|
|
128
|
-
// $insert
|
|
129
|
-
// $remove
|
|
130
|
-
// $alias: 'maTestWithAlias',
|
|
131
|
-
// aliases (set
|
|
132
|
-
|
|
133
|
-
// parse push and unshift
|
|
134
|
-
|
|
135
|
-
test.serial('collect correctly', async (t) => {
|
|
132
|
+
test('collect correctly', async (t) => {
|
|
136
133
|
const results: { path: (string | number)[]; value: any }[] = []
|
|
137
134
|
const now = Date.now()
|
|
138
135
|
await setWalker(
|
|
@@ -179,15 +176,10 @@ test.serial('collect correctly', async (t) => {
|
|
|
179
176
|
],
|
|
180
177
|
},
|
|
181
178
|
{
|
|
179
|
+
collectErrors: (info) => {
|
|
180
|
+
// fix fields (too heavy)
|
|
181
|
+
},
|
|
182
182
|
collect: ({ path, value, typeSchema, fieldSchema, target }) => {
|
|
183
|
-
console.dir(
|
|
184
|
-
{
|
|
185
|
-
path,
|
|
186
|
-
value,
|
|
187
|
-
},
|
|
188
|
-
{ depth: 10 }
|
|
189
|
-
)
|
|
190
|
-
|
|
191
183
|
results.push({
|
|
192
184
|
path,
|
|
193
185
|
value,
|
|
@@ -246,6 +238,20 @@ test.serial('collect correctly', async (t) => {
|
|
|
246
238
|
},
|
|
247
239
|
},
|
|
248
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
|
+
},
|
|
249
255
|
collect: ({ path, value, typeSchema, fieldSchema, target }) => {
|
|
250
256
|
results2.push({
|
|
251
257
|
path,
|
|
@@ -279,6 +285,20 @@ test.serial('collect correctly', async (t) => {
|
|
|
279
285
|
},
|
|
280
286
|
},
|
|
281
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
|
+
},
|
|
282
302
|
collect: ({ path, value, typeSchema, fieldSchema, target }) => {
|
|
283
303
|
results3.push({
|
|
284
304
|
path,
|
|
@@ -364,6 +384,20 @@ test('required', async (t) => {
|
|
|
364
384
|
},
|
|
365
385
|
},
|
|
366
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
|
+
},
|
|
367
401
|
collect: ({ path, value, typeSchema, fieldSchema, target }) => {},
|
|
368
402
|
checkRequiredFields: async (paths) => {
|
|
369
403
|
return true
|
|
@@ -390,10 +424,23 @@ test('required', async (t) => {
|
|
|
390
424
|
],
|
|
391
425
|
},
|
|
392
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
|
+
},
|
|
393
441
|
collect: ({ path, value, typeSchema, fieldSchema, target }) => {},
|
|
394
442
|
checkRequiredFields: async (paths) => {
|
|
395
443
|
// should be [snurp.x.b, snurp.x.c]
|
|
396
|
-
console.log(paths)
|
|
397
444
|
return true
|
|
398
445
|
},
|
|
399
446
|
referenceFilterCondition: async (id, filter) => {
|
|
@@ -412,3 +459,36 @@ test('required', async (t) => {
|
|
|
412
459
|
|
|
413
460
|
t.true(true)
|
|
414
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/string.ts
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import test from 'ava'
|
|
2
|
+
import { BasedSchema, setWalker, BasedSetHandlers } 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: 'string',
|
|
13
|
+
},
|
|
14
|
+
phonkName: {
|
|
15
|
+
type: 'string',
|
|
16
|
+
pattern: '\\${1,4}',
|
|
17
|
+
},
|
|
18
|
+
bla: {
|
|
19
|
+
type: 'set',
|
|
20
|
+
items: { type: 'string', minLength: 3, maxLength: 6 },
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
$defs: {},
|
|
26
|
+
languages: ['en'],
|
|
27
|
+
root: {
|
|
28
|
+
fields: {},
|
|
29
|
+
},
|
|
30
|
+
prefixToTypeMapping: {
|
|
31
|
+
bl: 'bla',
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const createHandlers = (): {
|
|
36
|
+
results: { path: (number | string)[]; value: any }[]
|
|
37
|
+
handlers: BasedSetHandlers
|
|
38
|
+
} => {
|
|
39
|
+
const results: { path: (number | string)[]; value: any }[] = []
|
|
40
|
+
const handlers = {
|
|
41
|
+
collect: ({ path, value, typeSchema, fieldSchema, target }) => {
|
|
42
|
+
results.push({ path, value })
|
|
43
|
+
},
|
|
44
|
+
checkRequiredFields: async (paths) => {
|
|
45
|
+
return true
|
|
46
|
+
},
|
|
47
|
+
referenceFilterCondition: async (id, filter) => {
|
|
48
|
+
return true
|
|
49
|
+
},
|
|
50
|
+
}
|
|
51
|
+
return { results, handlers }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
test('string max length', async (t) => {
|
|
55
|
+
const { handlers, results } = createHandlers()
|
|
56
|
+
await t.throwsAsync(
|
|
57
|
+
setWalker(
|
|
58
|
+
schema,
|
|
59
|
+
{
|
|
60
|
+
$id: 'bl1',
|
|
61
|
+
name: 'ax',
|
|
62
|
+
},
|
|
63
|
+
handlers
|
|
64
|
+
)
|
|
65
|
+
)
|
|
66
|
+
await t.throwsAsync(
|
|
67
|
+
setWalker(
|
|
68
|
+
schema,
|
|
69
|
+
{
|
|
70
|
+
$id: 'bl1',
|
|
71
|
+
name: 'axaxaxax',
|
|
72
|
+
},
|
|
73
|
+
handlers
|
|
74
|
+
)
|
|
75
|
+
)
|
|
76
|
+
await setWalker(
|
|
77
|
+
schema,
|
|
78
|
+
{
|
|
79
|
+
$id: 'bl1',
|
|
80
|
+
name: 'xaxx',
|
|
81
|
+
},
|
|
82
|
+
handlers
|
|
83
|
+
)
|
|
84
|
+
t.deepEqual(results, [{ path: ['name'], value: 'xaxx' }])
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
test('set with strings', async (t) => {
|
|
88
|
+
const { handlers, results } = createHandlers()
|
|
89
|
+
await t.throwsAsync(
|
|
90
|
+
setWalker(
|
|
91
|
+
schema,
|
|
92
|
+
{
|
|
93
|
+
$id: 'bl1',
|
|
94
|
+
bla: ['ax', 'axa', 'axxxxa'],
|
|
95
|
+
},
|
|
96
|
+
handlers
|
|
97
|
+
)
|
|
98
|
+
)
|
|
99
|
+
t.deepEqual(results, [])
|
|
100
|
+
await setWalker(
|
|
101
|
+
schema,
|
|
102
|
+
{
|
|
103
|
+
$id: 'bl1',
|
|
104
|
+
bla: ['axx', 'axxxx', 'blaaa'],
|
|
105
|
+
},
|
|
106
|
+
handlers
|
|
107
|
+
)
|
|
108
|
+
t.deepEqual(results, [
|
|
109
|
+
{ path: ['bla'], value: { $value: ['axx', 'axxxx', 'blaaa'] } },
|
|
110
|
+
])
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
test('string pattern', async (t) => {
|
|
114
|
+
const { handlers, results } = createHandlers()
|
|
115
|
+
await t.throwsAsync(
|
|
116
|
+
setWalker(
|
|
117
|
+
schema,
|
|
118
|
+
{
|
|
119
|
+
$id: 'bl1',
|
|
120
|
+
phonkName: 'blabla',
|
|
121
|
+
},
|
|
122
|
+
handlers
|
|
123
|
+
)
|
|
124
|
+
)
|
|
125
|
+
t.deepEqual(results, [])
|
|
126
|
+
await setWalker(
|
|
127
|
+
schema,
|
|
128
|
+
{
|
|
129
|
+
$id: 'bl1',
|
|
130
|
+
phonkName: 'bla$',
|
|
131
|
+
},
|
|
132
|
+
handlers
|
|
133
|
+
)
|
|
134
|
+
t.deepEqual(results, [{ path: ['phonkName'], value: 'bla$' }])
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
test('setting $default', async (t) => {
|
|
138
|
+
const { handlers, results } = createHandlers()
|
|
139
|
+
await t.throwsAsync(
|
|
140
|
+
setWalker(
|
|
141
|
+
schema,
|
|
142
|
+
{
|
|
143
|
+
$id: 'bl1',
|
|
144
|
+
phonkName: { $default: 'blabla' },
|
|
145
|
+
},
|
|
146
|
+
handlers
|
|
147
|
+
)
|
|
148
|
+
)
|
|
149
|
+
t.deepEqual(results, [])
|
|
150
|
+
await setWalker(
|
|
151
|
+
schema,
|
|
152
|
+
{
|
|
153
|
+
$id: 'bl1',
|
|
154
|
+
phonkName: { $default: 'bla$' },
|
|
155
|
+
},
|
|
156
|
+
handlers
|
|
157
|
+
)
|
|
158
|
+
t.deepEqual(results, [{ path: ['phonkName'], value: { $default: 'bla$' } }])
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
test('setting $value', async (t) => {
|
|
162
|
+
const { handlers, results } = createHandlers()
|
|
163
|
+
await t.throwsAsync(
|
|
164
|
+
setWalker(
|
|
165
|
+
schema,
|
|
166
|
+
{
|
|
167
|
+
$id: 'bl1',
|
|
168
|
+
phonkName: { $value: 'blabla' },
|
|
169
|
+
},
|
|
170
|
+
handlers
|
|
171
|
+
)
|
|
172
|
+
)
|
|
173
|
+
t.deepEqual(results, [])
|
|
174
|
+
await setWalker(
|
|
175
|
+
schema,
|
|
176
|
+
{
|
|
177
|
+
$id: 'bl1',
|
|
178
|
+
phonkName: { $value: 'bla$' },
|
|
179
|
+
},
|
|
180
|
+
handlers
|
|
181
|
+
)
|
|
182
|
+
t.deepEqual(results, [{ path: ['phonkName'], value: { $value: 'bla$' } }])
|
|
183
|
+
})
|