@based/schema 1.0.7 → 1.0.9
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/error.d.ts +2 -1
- package/dist/error.js +1 -0
- package/dist/error.js.map +1 -1
- package/dist/set/fields/array.js +3 -3
- package/dist/set/fields/array.js.map +1 -1
- package/dist/set/fields/index.js +2 -0
- package/dist/set/fields/index.js.map +1 -1
- package/dist/set/index.js +26 -0
- package/dist/set/index.js.map +1 -1
- package/dist/set/isValidId.js +1 -1
- package/dist/walker/args.d.ts +4 -0
- package/dist/walker/args.js +48 -2
- package/dist/walker/args.js.map +1 -1
- package/dist/walker/parse.d.ts +1 -0
- package/dist/walker/parse.js +31 -6
- package/dist/walker/parse.js.map +1 -1
- package/package.json +1 -1
- package/src/error.ts +1 -0
- package/src/set/fields/array.ts +3 -3
- package/src/set/fields/index.ts +2 -1
- package/src/set/index.ts +27 -0
- package/src/set/isValidId.ts +1 -1
- package/src/walker/args.ts +56 -2
- package/src/walker/parse.ts +39 -7
- package/test/number.ts +74 -69
- package/test/rest.ts +73 -136
- package/test/set.ts +116 -0
- package/test/string.ts +121 -139
- package/test/text.ts +199 -0
- package/test/walker.ts +189 -51
package/test/rest.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import test from 'ava'
|
|
2
|
-
import { BasedSchema, setWalker
|
|
2
|
+
import { BasedSchema, setWalker } from '../src/index'
|
|
3
|
+
import { errorCollect, resultCollect } from './utils'
|
|
3
4
|
|
|
4
5
|
const schema: BasedSchema = {
|
|
5
6
|
types: {
|
|
@@ -31,57 +32,24 @@ const schema: BasedSchema = {
|
|
|
31
32
|
},
|
|
32
33
|
}
|
|
33
34
|
|
|
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
35
|
test('arrayNum', async (t) => {
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
handlers
|
|
63
|
-
)
|
|
64
|
-
)
|
|
65
|
-
await t.throwsAsync(
|
|
66
|
-
setWalker(
|
|
67
|
-
schema,
|
|
68
|
-
{
|
|
69
|
-
$id: 'bla',
|
|
70
|
-
ref: 1,
|
|
71
|
-
},
|
|
72
|
-
handlers
|
|
73
|
-
)
|
|
74
|
-
)
|
|
36
|
+
const err = await setWalker(schema, {
|
|
37
|
+
$id: 'bl1',
|
|
38
|
+
arrNum: ['1', '2'],
|
|
39
|
+
})
|
|
40
|
+
const err1 = await setWalker(schema, {
|
|
41
|
+
$id: 'bla',
|
|
42
|
+
ref: 1,
|
|
43
|
+
})
|
|
75
44
|
|
|
76
|
-
await setWalker(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
)
|
|
84
|
-
t.deepEqual(results, [
|
|
45
|
+
const res = await setWalker(schema, {
|
|
46
|
+
$id: 'bla',
|
|
47
|
+
arrNum: [1, 2],
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
t.true(errorCollect(err, err1).length > 0)
|
|
51
|
+
|
|
52
|
+
t.deepEqual(resultCollect(res), [
|
|
85
53
|
{ path: ['arrNum'], value: { $delete: true } },
|
|
86
54
|
{ path: ['arrNum', 0], value: 1 },
|
|
87
55
|
{ path: ['arrNum', 1], value: 2 },
|
|
@@ -89,98 +57,67 @@ test('arrayNum', async (t) => {
|
|
|
89
57
|
})
|
|
90
58
|
|
|
91
59
|
test.only('value arr', async (t) => {
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
handlers
|
|
101
|
-
)
|
|
102
|
-
)
|
|
103
|
-
await t.throwsAsync(
|
|
104
|
-
setWalker(
|
|
105
|
-
schema,
|
|
106
|
-
{
|
|
107
|
-
$id: 'bla',
|
|
108
|
-
ref: { $value: 1 },
|
|
109
|
-
},
|
|
110
|
-
handlers
|
|
111
|
-
)
|
|
112
|
-
)
|
|
60
|
+
const err = await setWalker(schema, {
|
|
61
|
+
$id: 'bl1',
|
|
62
|
+
arrNum: { $value: ['1', '2'] },
|
|
63
|
+
})
|
|
64
|
+
const err1 = await setWalker(schema, {
|
|
65
|
+
$id: 'bla',
|
|
66
|
+
ref: { $value: 1 },
|
|
67
|
+
})
|
|
113
68
|
|
|
114
|
-
await setWalker(
|
|
115
|
-
|
|
116
|
-
{
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
},
|
|
128
|
-
handlers
|
|
129
|
-
)
|
|
130
|
-
console.log(results)
|
|
131
|
-
t.deepEqual(results, [
|
|
69
|
+
const res = await setWalker(schema, {
|
|
70
|
+
$id: 'bla',
|
|
71
|
+
arrNum: [{ $value: 1 }, { $value: 2 }],
|
|
72
|
+
})
|
|
73
|
+
const res1 = await setWalker(schema, {
|
|
74
|
+
$id: 'bla',
|
|
75
|
+
arrNum: { $value: [1, 2] },
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
t.true(errorCollect(err, err1).length > 0)
|
|
79
|
+
console.log(resultCollect(res, res1))
|
|
80
|
+
|
|
81
|
+
t.deepEqual(resultCollect(res, res1), [
|
|
132
82
|
{ path: ['arrNum'], value: { $delete: true } },
|
|
133
|
-
{ path: ['arrNum', 0], value:
|
|
134
|
-
{ path: ['arrNum', 1], value:
|
|
83
|
+
{ path: ['arrNum', 0], value: 1 },
|
|
84
|
+
{ path: ['arrNum', 1], value: 2 },
|
|
135
85
|
{ path: ['arrNum'], value: { $delete: true } },
|
|
136
86
|
{ path: ['arrNum', 0], value: 1 },
|
|
137
87
|
{ path: ['arrNum', 1], value: 2 },
|
|
88
|
+
{ path: ['arrNum'], value: { $delete: true } },
|
|
138
89
|
])
|
|
90
|
+
|
|
91
|
+
// { path: ['arrNum'], value: { $delete: true } },
|
|
92
|
+
// { path: ['arrNum', 0], value: { $value: 1 } }, // just 1
|
|
93
|
+
// { path: ['arrNum', 1], value: { $value: 2 } }, // just 2
|
|
94
|
+
// { path: ['arrNum'], value: { $delete: true } },
|
|
95
|
+
// { path: ['arrNum', 0], value: 1 },
|
|
96
|
+
// { path: ['arrNum', 1], value: 2 },
|
|
139
97
|
})
|
|
140
98
|
|
|
141
99
|
test('default arr', async (t) => {
|
|
142
|
-
const
|
|
100
|
+
const err = await setWalker(schema, {
|
|
101
|
+
$id: 'bl1',
|
|
102
|
+
arrNum: ['1', '2'],
|
|
103
|
+
})
|
|
104
|
+
const err1 = await setWalker(schema, {
|
|
105
|
+
$id: 'bla',
|
|
106
|
+
ref: 1,
|
|
107
|
+
})
|
|
143
108
|
|
|
144
|
-
await
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
)
|
|
153
|
-
)
|
|
154
|
-
await t.throwsAsync(
|
|
155
|
-
setWalker(
|
|
156
|
-
schema,
|
|
157
|
-
{
|
|
158
|
-
$id: 'bla',
|
|
159
|
-
ref: 1,
|
|
160
|
-
},
|
|
161
|
-
handlers
|
|
162
|
-
)
|
|
163
|
-
)
|
|
109
|
+
const res = await setWalker(schema, {
|
|
110
|
+
$id: 'bla',
|
|
111
|
+
arrNum: [{ $default: 1 }, { $default: 2 }],
|
|
112
|
+
})
|
|
113
|
+
const res1 = await setWalker(schema, {
|
|
114
|
+
$id: 'bla',
|
|
115
|
+
arrNum: { $default: [1, 2] },
|
|
116
|
+
})
|
|
164
117
|
|
|
165
|
-
|
|
166
|
-
schema,
|
|
167
|
-
{
|
|
168
|
-
$id: 'bla',
|
|
169
|
-
arrNum: [{ $default: 1 }, { $default: 2 }],
|
|
170
|
-
},
|
|
171
|
-
handlers
|
|
172
|
-
)
|
|
173
|
-
await setWalker(
|
|
174
|
-
schema,
|
|
175
|
-
{
|
|
176
|
-
$id: 'bla',
|
|
177
|
-
arrNum: { $default: [1, 2] },
|
|
178
|
-
},
|
|
179
|
-
handlers
|
|
180
|
-
)
|
|
181
|
-
console.log(results)
|
|
118
|
+
t.true(errorCollect(err, err1).length > 0)
|
|
182
119
|
//is this correct? is it supposed to be different
|
|
183
|
-
t.deepEqual(
|
|
120
|
+
t.deepEqual(resultCollect(res, res1), [
|
|
184
121
|
{ path: ['arrNum'], value: { $delete: true } },
|
|
185
122
|
{ path: ['arrNum', 0], value: { $default: 1 } },
|
|
186
123
|
{ path: ['arrNum', 1], value: { $default: 2 } },
|
|
@@ -189,25 +126,25 @@ test('default arr', async (t) => {
|
|
|
189
126
|
])
|
|
190
127
|
})
|
|
191
128
|
// test('arrStr', async (t) => {
|
|
192
|
-
//
|
|
193
|
-
// await
|
|
129
|
+
//
|
|
130
|
+
// const err = await(
|
|
194
131
|
// setWalker(
|
|
195
132
|
// schema,
|
|
196
133
|
// {
|
|
197
134
|
// $id: 'bl1',
|
|
198
135
|
// arrStr: [1, '2'],
|
|
199
136
|
// },
|
|
200
|
-
//
|
|
137
|
+
//
|
|
201
138
|
// )
|
|
202
139
|
// )
|
|
203
|
-
// await
|
|
140
|
+
// const err = await(
|
|
204
141
|
// setWalker(
|
|
205
142
|
// schema,
|
|
206
143
|
// {
|
|
207
144
|
// $id: 'bla',
|
|
208
145
|
// ref: 1,
|
|
209
146
|
// },
|
|
210
|
-
//
|
|
147
|
+
//
|
|
211
148
|
// )
|
|
212
149
|
// )
|
|
213
150
|
|
|
@@ -217,7 +154,7 @@ test('default arr', async (t) => {
|
|
|
217
154
|
// $id: 'bla',
|
|
218
155
|
// arrStr: [1, 2],
|
|
219
156
|
// },
|
|
220
|
-
//
|
|
157
|
+
//
|
|
221
158
|
// )
|
|
222
159
|
// t.deepEqual(results, [
|
|
223
160
|
// { path: ['arrStr'], value: { $delete: true } },
|
package/test/set.ts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// import test from 'ava'
|
|
2
|
+
// import { BasedSchema, setWalker, walk } from '../src/index'
|
|
3
|
+
// import { wait } from '@saulx/utils'
|
|
4
|
+
|
|
5
|
+
// const schema: BasedSchema = {
|
|
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
|
+
// referencesToThings: {
|
|
17
|
+
// type: 'references',
|
|
18
|
+
// allowedTypes: ['thing'],
|
|
19
|
+
// },
|
|
20
|
+
// referenceToThing: {
|
|
21
|
+
// type: 'reference',
|
|
22
|
+
// allowedTypes: ['thing'],
|
|
23
|
+
// },
|
|
24
|
+
// exclusiveminmax: {
|
|
25
|
+
// type: 'number',
|
|
26
|
+
// minimum: 3,
|
|
27
|
+
// exclusiveMinimum: true,
|
|
28
|
+
// maximum: 6,
|
|
29
|
+
// exclusiveMaximum: true,
|
|
30
|
+
// },
|
|
31
|
+
// text: {
|
|
32
|
+
// type: 'text',
|
|
33
|
+
// pattern: '[^xz]{1,10}',
|
|
34
|
+
// },
|
|
35
|
+
// timestamp: {
|
|
36
|
+
// type: 'timestamp',
|
|
37
|
+
// },
|
|
38
|
+
// setOfNumbers: {
|
|
39
|
+
// type: 'set',
|
|
40
|
+
// items: {
|
|
41
|
+
// type: 'number',
|
|
42
|
+
// },
|
|
43
|
+
// },
|
|
44
|
+
// x: {
|
|
45
|
+
// type: 'object',
|
|
46
|
+
// properties: {
|
|
47
|
+
// flap: {
|
|
48
|
+
// type: 'boolean',
|
|
49
|
+
// },
|
|
50
|
+
// },
|
|
51
|
+
// },
|
|
52
|
+
// bla: {
|
|
53
|
+
// type: 'set',
|
|
54
|
+
// items: { type: 'string', minLength: 3, maxLength: 6 },
|
|
55
|
+
// },
|
|
56
|
+
// },
|
|
57
|
+
// },
|
|
58
|
+
// },
|
|
59
|
+
// $defs: {},
|
|
60
|
+
// languages: ['en', 'de', 'nl', 'ro', 'za', 'ae'],
|
|
61
|
+
// root: {
|
|
62
|
+
// fields: {},
|
|
63
|
+
// },
|
|
64
|
+
// prefixToTypeMapping: {
|
|
65
|
+
// bl: 'bla',
|
|
66
|
+
// ti: 'thing',
|
|
67
|
+
// },
|
|
68
|
+
// }
|
|
69
|
+
|
|
70
|
+
// console.info('---- doink 15 ------')
|
|
71
|
+
// r = await setWalker(schema, {
|
|
72
|
+
// $id: 'bl120',
|
|
73
|
+
// setOfNumbers: [1, 2, 3, 4, 5],
|
|
74
|
+
// })
|
|
75
|
+
|
|
76
|
+
// console.log(r.errors)
|
|
77
|
+
// console.dir(
|
|
78
|
+
// r.collected.map((v) => ({ path: v.path, value: v.value })),
|
|
79
|
+
// { depth: 10 }
|
|
80
|
+
// )
|
|
81
|
+
|
|
82
|
+
// console.info('---- doink 16 ------')
|
|
83
|
+
// r = await setWalker(schema, {
|
|
84
|
+
// $id: 'bl120',
|
|
85
|
+
// setOfNumbers: { $add: 20 },
|
|
86
|
+
// })
|
|
87
|
+
|
|
88
|
+
// console.log(r.errors)
|
|
89
|
+
// console.dir(
|
|
90
|
+
// r.collected.map((v) => ({ path: v.path, value: v.value })),
|
|
91
|
+
// { depth: 10 }
|
|
92
|
+
// )
|
|
93
|
+
|
|
94
|
+
// console.info('---- doink 17 ------')
|
|
95
|
+
// r = await setWalker(schema, {
|
|
96
|
+
// $id: 'bl120',
|
|
97
|
+
// setOfNumbers: { $add: [1, 2, 3, 4, 5, 6] },
|
|
98
|
+
// })
|
|
99
|
+
|
|
100
|
+
// console.log(r.errors)
|
|
101
|
+
// console.dir(
|
|
102
|
+
// r.collected.map((v) => ({ path: v.path, value: v.value })),
|
|
103
|
+
// { depth: 10 }
|
|
104
|
+
// )
|
|
105
|
+
|
|
106
|
+
// console.info('---- doink 18 ------')
|
|
107
|
+
// r = await setWalker(schema, {
|
|
108
|
+
// $id: 'bl120',
|
|
109
|
+
// setOfNumbers: { $remove: [1, 2, 3, 4, 5, 6] },
|
|
110
|
+
// })
|
|
111
|
+
|
|
112
|
+
// console.log(r.errors)
|
|
113
|
+
// console.dir(
|
|
114
|
+
// r.collected.map((v) => ({ path: v.path, value: v.value })),
|
|
115
|
+
// { depth: 10 }
|
|
116
|
+
// )
|
package/test/string.ts
CHANGED
|
@@ -1,139 +1,121 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
// $id: 'bl1',
|
|
123
|
-
// phonkName: { $value: 'blabla' },
|
|
124
|
-
// })
|
|
125
|
-
// t.assert(err.errors.length > 1)
|
|
126
|
-
|
|
127
|
-
// const res1 = await setWalker2(schema, {
|
|
128
|
-
// $id: 'bl1',
|
|
129
|
-
// phonkName: { $value: 'bla$' },
|
|
130
|
-
// })
|
|
131
|
-
|
|
132
|
-
// const res = [res1]
|
|
133
|
-
// console.log(res) // is ok
|
|
134
|
-
// console.log(res1) // isnt ok???
|
|
135
|
-
|
|
136
|
-
// t.deepEqual(res[0].target.collected, [
|
|
137
|
-
// { path: ['phonkName'], value: { $value: 'bla$' } },
|
|
138
|
-
// ])
|
|
139
|
-
// })
|
|
1
|
+
import test from 'ava'
|
|
2
|
+
import { BasedSchema, setWalker } from '../src/index'
|
|
3
|
+
import { errorCollect, resultCollect } from './utils'
|
|
4
|
+
|
|
5
|
+
const schema: BasedSchema = {
|
|
6
|
+
types: {
|
|
7
|
+
bla: {
|
|
8
|
+
prefix: 'bl',
|
|
9
|
+
fields: {
|
|
10
|
+
name: {
|
|
11
|
+
minLength: 3,
|
|
12
|
+
maxLength: 6,
|
|
13
|
+
type: 'string',
|
|
14
|
+
},
|
|
15
|
+
phonkName: {
|
|
16
|
+
type: 'string',
|
|
17
|
+
pattern: '\\${1,4}',
|
|
18
|
+
},
|
|
19
|
+
bla: {
|
|
20
|
+
type: 'set',
|
|
21
|
+
items: { type: 'string', minLength: 3, maxLength: 6 },
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
$defs: {},
|
|
27
|
+
languages: ['en'],
|
|
28
|
+
root: {
|
|
29
|
+
fields: {},
|
|
30
|
+
},
|
|
31
|
+
prefixToTypeMapping: {
|
|
32
|
+
bl: 'bla',
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
test('string max length', async (t) => {
|
|
37
|
+
const err1 = await setWalker(schema, {
|
|
38
|
+
$id: 'bl1',
|
|
39
|
+
name: 'ax',
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const err2 = await setWalker(schema, {
|
|
43
|
+
$id: 'bl1',
|
|
44
|
+
name: 'axaxaxax',
|
|
45
|
+
})
|
|
46
|
+
const res1 = await setWalker(schema, {
|
|
47
|
+
$id: 'bl1',
|
|
48
|
+
name: 'xaxx',
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
t.assert(errorCollect(err1, err2).length > 0)
|
|
52
|
+
t.deepEqual(resultCollect(res1), [{ path: ['name'], value: 'xaxx' }])
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
//set parser
|
|
56
|
+
test('set with strings', async (t) => {
|
|
57
|
+
const err1 = await setWalker(schema, {
|
|
58
|
+
$id: 'bl1',
|
|
59
|
+
bla: ['ax', 'axa', 'axxxxa'],
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
const res1 = await setWalker(schema, {
|
|
63
|
+
$id: 'bl1',
|
|
64
|
+
bla: ['axx', 'axxxx', 'blaaa'],
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
t.assert(errorCollect(err1).length > 0)
|
|
68
|
+
t.deepEqual(resultCollect(res1), [
|
|
69
|
+
{ path: ['bla'], value: { $value: ['axx', 'axxxx', 'blaaa'] } },
|
|
70
|
+
])
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
// this one causes weird array lenght issue in string max length test
|
|
74
|
+
test('string pattern', async (t) => {
|
|
75
|
+
const err1 = await setWalker(schema, {
|
|
76
|
+
$id: 'bl1',
|
|
77
|
+
phonkName: 'blabla',
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
const res1 = await setWalker(schema, {
|
|
81
|
+
$id: 'bl1',
|
|
82
|
+
phonkName: 'bla$',
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
t.assert(errorCollect(err1).length > 0)
|
|
86
|
+
t.deepEqual(resultCollect(res1), [{ path: ['phonkName'], value: 'bla$' }])
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
test('setting $default', async (t) => {
|
|
90
|
+
const err = await setWalker(schema, {
|
|
91
|
+
$id: 'bl1',
|
|
92
|
+
phonkName: { $default: 'blabla' },
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
t.assert(err.errors.length > 0)
|
|
96
|
+
|
|
97
|
+
const res1 = await setWalker(schema, {
|
|
98
|
+
$id: 'bl1',
|
|
99
|
+
phonkName: { $default: 'bla$' },
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
t.deepEqual(resultCollect(res1), [
|
|
103
|
+
{ path: ['phonkName'], value: { $default: 'bla$' } },
|
|
104
|
+
])
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
test('setting $value', async (t) => {
|
|
108
|
+
const err = await setWalker(schema, {
|
|
109
|
+
$id: 'bl1',
|
|
110
|
+
phonkName: { $value: 'blabla' },
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
t.assert(err.errors.length > 1)
|
|
114
|
+
|
|
115
|
+
const res1 = await setWalker(schema, {
|
|
116
|
+
$id: 'bl1',
|
|
117
|
+
phonkName: { $value: 'bla$' },
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
t.deepEqual(resultCollect(res1), [{ path: ['phonkName'], value: 'bla$' }])
|
|
121
|
+
})
|