@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/reference.ts
CHANGED
|
@@ -1,207 +1,159 @@
|
|
|
1
|
-
import test from 'ava'
|
|
2
|
-
import { BasedSchema,
|
|
1
|
+
// import test from 'ava'
|
|
2
|
+
// import { BasedSchema, setWalker2 } from '../src/index'
|
|
3
|
+
// import { resultCollect, errorCollect } from './utils'
|
|
3
4
|
|
|
4
|
-
const schema: BasedSchema = {
|
|
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
|
-
}
|
|
5
|
+
// const schema: BasedSchema = {
|
|
6
|
+
// types: {
|
|
7
|
+
// bla: {
|
|
8
|
+
// prefix: 'bl',
|
|
9
|
+
// fields: {
|
|
10
|
+
// ref: {
|
|
11
|
+
// type: 'reference',
|
|
12
|
+
// allowedTypes: ['bl', 'bl1'],
|
|
13
|
+
// },
|
|
14
|
+
// ref2: {
|
|
15
|
+
// type: 'references',
|
|
16
|
+
// allowedTypes: ['bl'],
|
|
17
|
+
// },
|
|
18
|
+
// arr: {
|
|
19
|
+
// type: 'array',
|
|
20
|
+
// title: '',
|
|
21
|
+
// },
|
|
22
|
+
// },
|
|
23
|
+
// },
|
|
24
|
+
// },
|
|
25
|
+
// $defs: {},
|
|
26
|
+
// languages: ['en'],
|
|
27
|
+
// root: {
|
|
28
|
+
// fields: {},
|
|
29
|
+
// },
|
|
30
|
+
// prefixToTypeMapping: {
|
|
31
|
+
// bl: 'bla',
|
|
32
|
+
// },
|
|
33
|
+
// }
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
checkRequiredFields: async (paths) => {
|
|
44
|
-
return true
|
|
45
|
-
},
|
|
46
|
-
referenceFilterCondition: async (id, filter) => {
|
|
47
|
-
return true
|
|
48
|
-
},
|
|
49
|
-
}
|
|
50
|
-
return { results, handlers }
|
|
51
|
-
}
|
|
35
|
+
// test('reference', async (t) => {
|
|
36
|
+
// const e1 = await setWalker2(schema, {
|
|
37
|
+
// $id: 'bl1',
|
|
38
|
+
// ref: ['1', '2'],
|
|
39
|
+
// })
|
|
40
|
+
// const e2 = await setWalker2(schema, {
|
|
41
|
+
// $id: 'bl1',
|
|
42
|
+
// ref: 1,
|
|
43
|
+
// })
|
|
52
44
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
)
|
|
45
|
+
// const res = await setWalker2(schema, {
|
|
46
|
+
// $id: 'bl1',
|
|
47
|
+
// ref: 'asdasdasdasdasd',
|
|
48
|
+
// })
|
|
75
49
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
},
|
|
82
|
-
handlers
|
|
83
|
-
)
|
|
84
|
-
t.deepEqual(results, [{ path: ['ref'], value: 'asdasdasdasdasd' }])
|
|
85
|
-
})
|
|
50
|
+
// t.assert(errorCollect([e1, e2]).length > 0)
|
|
51
|
+
// t.deepEqual(resultCollect([res]), [
|
|
52
|
+
// { path: ['ref'], value: 'asdasdasdasdasd' },
|
|
53
|
+
// ])
|
|
54
|
+
// })
|
|
86
55
|
|
|
87
|
-
test('multiple references', async (t) => {
|
|
88
|
-
|
|
56
|
+
// test('multiple references', async (t) => {
|
|
57
|
+
// // const e = await (
|
|
58
|
+
// // setWalker2(
|
|
59
|
+
// // schema,
|
|
60
|
+
// // {
|
|
61
|
+
// // $id: 'bl1',
|
|
62
|
+
// // ref2: 0.5,
|
|
63
|
+
// // },
|
|
64
|
+
// //
|
|
65
|
+
// // )
|
|
66
|
+
// // )
|
|
67
|
+
// // const e = await (
|
|
68
|
+
// // setWalker2(
|
|
69
|
+
// // schema,
|
|
70
|
+
// // {
|
|
71
|
+
// // $id: 'bl1',
|
|
72
|
+
// // ref2: 1,
|
|
73
|
+
// // },
|
|
74
|
+
// //
|
|
75
|
+
// // )
|
|
76
|
+
// // )
|
|
77
|
+
// // these should throw, array of refs doesnt
|
|
78
|
+
// //??? todo?
|
|
79
|
+
// const e = await setWalker2(schema, {
|
|
80
|
+
// $id: 'bl1',
|
|
81
|
+
// ref2: [1, 1, 1, 1, 1, 1, 1],
|
|
82
|
+
// })
|
|
83
|
+
// const res1 = await setWalker2(schema, {
|
|
84
|
+
// $id: 'bl1',
|
|
85
|
+
// ref2: ['1', '2', '3'],
|
|
86
|
+
// })
|
|
89
87
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
})
|
|
88
|
+
// t.assert(errorCollect([e]).length === 1)
|
|
89
|
+
// t.deepEqual(resultCollect([res1]), [
|
|
90
|
+
// { path: ['ref2'], value: { $value: ['1', '2', '3'] } },
|
|
91
|
+
// ])
|
|
92
|
+
// })
|
|
133
93
|
|
|
134
|
-
test('value of references', async (t) => {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
-
)
|
|
94
|
+
// test('value of references', async (t) => {
|
|
95
|
+
// const e = await setWalker2(schema, {
|
|
96
|
+
// $id: 'bl1',
|
|
97
|
+
// ref: { $value: ['1', '2'] },
|
|
98
|
+
// })
|
|
99
|
+
// const e1 = await setWalker2(schema, {
|
|
100
|
+
// $id: 'bl1',
|
|
101
|
+
// ref: { $value: 1 },
|
|
102
|
+
// })
|
|
156
103
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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
|
-
)
|
|
104
|
+
// const res1 = await setWalker2(schema, {
|
|
105
|
+
// $id: 'bl1',
|
|
106
|
+
// ref: { $value: 'asdasdasdasdasd' },
|
|
107
|
+
// })
|
|
193
108
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
109
|
+
// //error here?
|
|
110
|
+
// t.assert(errorCollect([e, e1]).length === 2)
|
|
111
|
+
// t.deepEqual(resultCollect([res1]), [
|
|
112
|
+
// { path: ['ref'], value: { $value: 'asdasdasdasdasd' } },
|
|
113
|
+
// ])
|
|
114
|
+
// })
|
|
115
|
+
|
|
116
|
+
// test('default of references', async (t) => {
|
|
117
|
+
// const e2 = await setWalker2(schema, {
|
|
118
|
+
// $id: 'bl1',
|
|
119
|
+
// ref: { $default: ['1', '2'] },
|
|
120
|
+
// })
|
|
121
|
+
// const e1 = await setWalker2(schema, {
|
|
122
|
+
// $id: 'bl1',
|
|
123
|
+
// ref: { $default: 1 },
|
|
124
|
+
// })
|
|
125
|
+
|
|
126
|
+
// // await setWalker2(
|
|
127
|
+
// // schema,
|
|
128
|
+
// // {
|
|
129
|
+
// // $id: 'bl1',
|
|
130
|
+
// // ref: { $default: 'asdasdasdasdasd' },
|
|
131
|
+
// // },
|
|
132
|
+
// //
|
|
133
|
+
// // )
|
|
134
|
+
// // console.log('----:XX', resultCollect)
|
|
135
|
+
// // //error here?
|
|
136
|
+
// // t.deepEqual(resultCollect, [
|
|
137
|
+
// // { path: ['ref'], value: { $default: 'asdasdasdasdasd' } },
|
|
138
|
+
// // ])
|
|
139
|
+
// t.assert(errorCollect([e2, e1]).length === 2)
|
|
140
|
+
// })
|
|
141
|
+
|
|
142
|
+
// test.only('allowedTypes', async (t) => {
|
|
143
|
+
// const e1 = await setWalker2(schema, {
|
|
144
|
+
// $id: 'bl1',
|
|
145
|
+
// ref: ['1', '2'],
|
|
146
|
+
// })
|
|
147
|
+
// const e2 = await setWalker2(schema, {
|
|
148
|
+
// $id: 'bs1',
|
|
149
|
+
// ref: 1,
|
|
150
|
+
// })
|
|
151
|
+
// const res1 = await setWalker2(schema, {
|
|
152
|
+
// $id: 'bl1',
|
|
153
|
+
// ref: 'blastuff',
|
|
154
|
+
// })
|
|
155
|
+
|
|
156
|
+
// t.assert(errorCollect([e2, e1]).length === 2)
|
|
157
|
+
// t.deepEqual(resultCollect([res1]), [{ path: ['ref'], value: 'bl1stuff' }])
|
|
158
|
+
// // is this wrong or am i wrong
|
|
159
|
+
// })
|
package/test/rest.ts
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
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
|
+
arrNum: {
|
|
10
|
+
type: 'array',
|
|
11
|
+
values: {
|
|
12
|
+
type: 'number',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
arrStr: {
|
|
16
|
+
type: 'array',
|
|
17
|
+
values: {
|
|
18
|
+
type: 'string',
|
|
19
|
+
},
|
|
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('arrayNum', async (t) => {
|
|
54
|
+
const { handlers, results } = createHandlers()
|
|
55
|
+
await t.throwsAsync(
|
|
56
|
+
setWalker(
|
|
57
|
+
schema,
|
|
58
|
+
{
|
|
59
|
+
$id: 'bl1',
|
|
60
|
+
arrNum: ['1', '2'],
|
|
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
|
+
)
|
|
75
|
+
|
|
76
|
+
await setWalker(
|
|
77
|
+
schema,
|
|
78
|
+
{
|
|
79
|
+
$id: 'bla',
|
|
80
|
+
arrNum: [1, 2],
|
|
81
|
+
},
|
|
82
|
+
handlers
|
|
83
|
+
)
|
|
84
|
+
t.deepEqual(results, [
|
|
85
|
+
{ path: ['arrNum'], value: { $delete: true } },
|
|
86
|
+
{ path: ['arrNum', 0], value: 1 },
|
|
87
|
+
{ path: ['arrNum', 1], value: 2 },
|
|
88
|
+
])
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
test.only('value arr', async (t) => {
|
|
92
|
+
const { handlers, results } = createHandlers()
|
|
93
|
+
await t.throwsAsync(
|
|
94
|
+
setWalker(
|
|
95
|
+
schema,
|
|
96
|
+
{
|
|
97
|
+
$id: 'bl1',
|
|
98
|
+
arrNum: { $value: ['1', '2'] },
|
|
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
|
+
)
|
|
113
|
+
|
|
114
|
+
await setWalker(
|
|
115
|
+
schema,
|
|
116
|
+
{
|
|
117
|
+
$id: 'bla',
|
|
118
|
+
arrNum: [{ $value: 1 }, { $value: 2 }],
|
|
119
|
+
},
|
|
120
|
+
handlers
|
|
121
|
+
)
|
|
122
|
+
await setWalker(
|
|
123
|
+
schema,
|
|
124
|
+
{
|
|
125
|
+
$id: 'bla',
|
|
126
|
+
arrNum: { $value: [1, 2] },
|
|
127
|
+
},
|
|
128
|
+
handlers
|
|
129
|
+
)
|
|
130
|
+
console.log(results)
|
|
131
|
+
t.deepEqual(results, [
|
|
132
|
+
{ path: ['arrNum'], value: { $delete: true } },
|
|
133
|
+
{ path: ['arrNum', 0], value: { $value: 1 } }, // just 1
|
|
134
|
+
{ path: ['arrNum', 1], value: { $value: 2 } }, // just 2
|
|
135
|
+
{ path: ['arrNum'], value: { $delete: true } },
|
|
136
|
+
{ path: ['arrNum', 0], value: 1 },
|
|
137
|
+
{ path: ['arrNum', 1], value: 2 },
|
|
138
|
+
])
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
test('default arr', async (t) => {
|
|
142
|
+
const { handlers, results } = createHandlers()
|
|
143
|
+
|
|
144
|
+
await t.throwsAsync(
|
|
145
|
+
setWalker(
|
|
146
|
+
schema,
|
|
147
|
+
{
|
|
148
|
+
$id: 'bl1',
|
|
149
|
+
arrNum: ['1', '2'],
|
|
150
|
+
},
|
|
151
|
+
handlers
|
|
152
|
+
)
|
|
153
|
+
)
|
|
154
|
+
await t.throwsAsync(
|
|
155
|
+
setWalker(
|
|
156
|
+
schema,
|
|
157
|
+
{
|
|
158
|
+
$id: 'bla',
|
|
159
|
+
ref: 1,
|
|
160
|
+
},
|
|
161
|
+
handlers
|
|
162
|
+
)
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
await setWalker(
|
|
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)
|
|
182
|
+
//is this correct? is it supposed to be different
|
|
183
|
+
t.deepEqual(results, [
|
|
184
|
+
{ path: ['arrNum'], value: { $delete: true } },
|
|
185
|
+
{ path: ['arrNum', 0], value: { $default: 1 } },
|
|
186
|
+
{ path: ['arrNum', 1], value: { $default: 2 } },
|
|
187
|
+
// why are theese two different but for defaultits the same
|
|
188
|
+
{ path: ['arrNum'], value: { $default: [1, 2] } },
|
|
189
|
+
])
|
|
190
|
+
})
|
|
191
|
+
// test('arrStr', async (t) => {
|
|
192
|
+
// const { handlers, results } = createHandlers()
|
|
193
|
+
// await t.throwsAsync(
|
|
194
|
+
// setWalker(
|
|
195
|
+
// schema,
|
|
196
|
+
// {
|
|
197
|
+
// $id: 'bl1',
|
|
198
|
+
// arrStr: [1, '2'],
|
|
199
|
+
// },
|
|
200
|
+
// handlers
|
|
201
|
+
// )
|
|
202
|
+
// )
|
|
203
|
+
// await t.throwsAsync(
|
|
204
|
+
// setWalker(
|
|
205
|
+
// schema,
|
|
206
|
+
// {
|
|
207
|
+
// $id: 'bla',
|
|
208
|
+
// ref: 1,
|
|
209
|
+
// },
|
|
210
|
+
// handlers
|
|
211
|
+
// )
|
|
212
|
+
// )
|
|
213
|
+
|
|
214
|
+
// await setWalker(
|
|
215
|
+
// schema,
|
|
216
|
+
// {
|
|
217
|
+
// $id: 'bla',
|
|
218
|
+
// arrStr: [1, 2],
|
|
219
|
+
// },
|
|
220
|
+
// handlers
|
|
221
|
+
// )
|
|
222
|
+
// t.deepEqual(results, [
|
|
223
|
+
// { path: ['arrStr'], value: { $delete: true } },
|
|
224
|
+
// { path: ['arrStr', 0], value: 1 },
|
|
225
|
+
// { path: ['arrStr', 1], value: 2 },
|
|
226
|
+
// ])
|
|
227
|
+
// })
|