@based/schema 0.0.9 → 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 +52 -19
- package/dist/set/collections.js.map +1 -1
- package/dist/set/error.d.ts +5 -2
- package/dist/set/error.js +10 -3
- package/dist/set/error.js.map +1 -1
- package/dist/set/index.d.ts +2 -2
- package/dist/set/index.js +67 -12
- 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 +48 -31
- 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 +10 -2
- package/dist/types.js.map +1 -1
- package/dist/updateSchema.d.ts +2 -0
- package/dist/updateSchema.js +16 -0
- package/dist/updateSchema.js.map +1 -0
- package/dist/validateSchema.js +5 -1
- package/dist/validateSchema.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 +56 -21
- package/src/set/error.ts +14 -3
- package/src/set/index.ts +87 -12
- 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 +78 -35
- package/src/set2/index.ts +0 -0
- package/src/types.ts +18 -11
- package/src/updateSchema.ts +18 -0
- package/src/validateSchema.ts +6 -1
- package/src/walker.ts +152 -0
- package/test/number.ts +646 -0
- package/test/reference.ts +207 -0
- package/test/setWalker.ts +223 -53
- 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,29 +129,7 @@ const schema: BasedSchema = {
|
|
|
121
129
|
},
|
|
122
130
|
}
|
|
123
131
|
|
|
124
|
-
|
|
125
|
-
// $default
|
|
126
|
-
|
|
127
|
-
// $noRoot
|
|
128
|
-
|
|
129
|
-
// $delete -> change for set / references
|
|
130
|
-
|
|
131
|
-
// $merge: false,
|
|
132
|
-
|
|
133
|
-
// $increment
|
|
134
|
-
// $decrement
|
|
135
|
-
|
|
136
|
-
// $assign
|
|
137
|
-
// $insert
|
|
138
|
-
// $remove
|
|
139
|
-
// $push: 7,
|
|
140
|
-
// $unshift ( $unshift: {$value: 123,$maxLen: 10,},)
|
|
141
|
-
// $alias: 'maTestWithAlias',
|
|
142
|
-
// aliases (set
|
|
143
|
-
|
|
144
|
-
// parse formats for string e.g. uri / email etc
|
|
145
|
-
|
|
146
|
-
test.serial('collect correctly', async (t) => {
|
|
132
|
+
test('collect correctly', async (t) => {
|
|
147
133
|
const results: { path: (string | number)[]; value: any }[] = []
|
|
148
134
|
const now = Date.now()
|
|
149
135
|
await setWalker(
|
|
@@ -159,7 +145,7 @@ test.serial('collect correctly', async (t) => {
|
|
|
159
145
|
$increment: 1,
|
|
160
146
|
},
|
|
161
147
|
bla: false,
|
|
162
|
-
time: now,
|
|
148
|
+
time: now,
|
|
163
149
|
setje: [1, 2, 3],
|
|
164
150
|
form: {
|
|
165
151
|
lastName: 'de beer',
|
|
@@ -190,20 +176,18 @@ test.serial('collect correctly', async (t) => {
|
|
|
190
176
|
],
|
|
191
177
|
},
|
|
192
178
|
{
|
|
179
|
+
collectErrors: (info) => {
|
|
180
|
+
// fix fields (too heavy)
|
|
181
|
+
},
|
|
193
182
|
collect: ({ path, value, typeSchema, fieldSchema, target }) => {
|
|
194
|
-
console.dir(
|
|
195
|
-
{
|
|
196
|
-
path,
|
|
197
|
-
value,
|
|
198
|
-
},
|
|
199
|
-
{ depth: 10 }
|
|
200
|
-
)
|
|
201
|
-
|
|
202
183
|
results.push({
|
|
203
184
|
path,
|
|
204
185
|
value,
|
|
205
186
|
})
|
|
206
187
|
},
|
|
188
|
+
checkRequiredFields: async (path) => {
|
|
189
|
+
return true
|
|
190
|
+
},
|
|
207
191
|
referenceFilterCondition: async (id, filter) => {
|
|
208
192
|
return true
|
|
209
193
|
},
|
|
@@ -219,7 +203,6 @@ test.serial('collect correctly', async (t) => {
|
|
|
219
203
|
path: ['snurpArray', 0],
|
|
220
204
|
value: 100,
|
|
221
205
|
},
|
|
222
|
-
|
|
223
206
|
{ path: ['bla'], value: false },
|
|
224
207
|
{ path: ['form', 'lastName'], value: 'de beer' },
|
|
225
208
|
{ path: ['form', 'json'], value: '{"bla":1,"x":2,"y":3}' },
|
|
@@ -227,14 +210,12 @@ test.serial('collect correctly', async (t) => {
|
|
|
227
210
|
{ path: ['form', 'password'], value: 'mypassword!' },
|
|
228
211
|
{ path: ['form', 'bla'], value: { $value: ['bl123', 'bl234'] } },
|
|
229
212
|
{ path: ['form', 'blab'], value: { $add: ['bl456'] } },
|
|
230
|
-
|
|
231
213
|
{ path: ['setje'], value: { $value: [1, 2, 3] } },
|
|
232
214
|
{ path: ['form', 'blub'], value: { $value: ['x'] } },
|
|
233
215
|
{
|
|
234
216
|
path: ['specialArray'],
|
|
235
217
|
value: { $insert: { $value: ['a', 'b', 'c'], $idx: 0 } },
|
|
236
218
|
},
|
|
237
|
-
|
|
238
219
|
{ path: ['snurp'], value: { $delete: true } },
|
|
239
220
|
{ path: ['snurp', 0, 'x'], value: { $delete: true } },
|
|
240
221
|
{ path: ['snurp', 0, 'x', 0], value: 1 },
|
|
@@ -242,12 +223,8 @@ test.serial('collect correctly', async (t) => {
|
|
|
242
223
|
{ path: ['snurp', 0, 'x', 2], value: 3 },
|
|
243
224
|
]
|
|
244
225
|
|
|
245
|
-
console.log(results)
|
|
246
|
-
|
|
247
226
|
t.deepEqual(results, result)
|
|
248
227
|
|
|
249
|
-
console.info('DID COMPARSION!')
|
|
250
|
-
|
|
251
228
|
const results2: any[] = []
|
|
252
229
|
await setWalker(
|
|
253
230
|
schema,
|
|
@@ -261,19 +238,29 @@ test.serial('collect correctly', async (t) => {
|
|
|
261
238
|
},
|
|
262
239
|
},
|
|
263
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
|
+
},
|
|
264
255
|
collect: ({ path, value, typeSchema, fieldSchema, target }) => {
|
|
265
|
-
console.dir(
|
|
266
|
-
{
|
|
267
|
-
path,
|
|
268
|
-
value,
|
|
269
|
-
},
|
|
270
|
-
{ depth: 10 }
|
|
271
|
-
)
|
|
272
256
|
results2.push({
|
|
273
257
|
path,
|
|
274
258
|
value,
|
|
275
259
|
})
|
|
276
260
|
},
|
|
261
|
+
checkRequiredFields: async (path) => {
|
|
262
|
+
return false
|
|
263
|
+
},
|
|
277
264
|
referenceFilterCondition: async (id, filter) => {
|
|
278
265
|
return true
|
|
279
266
|
},
|
|
@@ -298,19 +285,29 @@ test.serial('collect correctly', async (t) => {
|
|
|
298
285
|
},
|
|
299
286
|
},
|
|
300
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
|
+
},
|
|
301
302
|
collect: ({ path, value, typeSchema, fieldSchema, target }) => {
|
|
302
|
-
console.dir(
|
|
303
|
-
{
|
|
304
|
-
path,
|
|
305
|
-
value,
|
|
306
|
-
},
|
|
307
|
-
{ depth: 10 }
|
|
308
|
-
)
|
|
309
303
|
results3.push({
|
|
310
304
|
path,
|
|
311
305
|
value,
|
|
312
306
|
})
|
|
313
307
|
},
|
|
308
|
+
checkRequiredFields: async (path) => {
|
|
309
|
+
return false
|
|
310
|
+
},
|
|
314
311
|
referenceFilterCondition: async (id, filter) => {
|
|
315
312
|
return true
|
|
316
313
|
},
|
|
@@ -322,3 +319,176 @@ test.serial('collect correctly', async (t) => {
|
|
|
322
319
|
{ path: ['specialArray'], value: { $push: [{ $value: 'flap' }] } },
|
|
323
320
|
])
|
|
324
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
|
+
})
|