@based/schema 1.1.5 → 1.1.7
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/fields/index.js +3 -0
- package/dist/set/fields/index.js.map +1 -1
- package/dist/set/fields/references.js +1 -1
- package/dist/set/fields/references.js.map +1 -1
- package/dist/set/fields/string.js +6 -2
- package/dist/set/fields/string.js.map +1 -1
- package/dist/set/index.js +5 -1
- package/dist/set/index.js.map +1 -1
- package/dist/walker/parse.js +15 -22
- package/dist/walker/parse.js.map +1 -1
- package/package.json +1 -1
- package/src/set/fields/index.ts +3 -0
- package/src/set/fields/references.ts +1 -1
- package/src/set/fields/string.ts +5 -2
- package/src/set/index.ts +5 -2
- package/src/walker/parse.ts +19 -25
- package/test/array.ts +369 -0
- package/test/number.ts +60 -0
- package/test/reference.ts +218 -159
- package/test/rest.ts +143 -113
- package/test/set.ts +80 -106
- package/test/text.ts +39 -12
- package/test/walker.ts +47 -1
package/test/rest.ts
CHANGED
|
@@ -4,161 +4,191 @@ import { errorCollect, resultCollect } from './utils'
|
|
|
4
4
|
|
|
5
5
|
const schema: BasedSchema = {
|
|
6
6
|
types: {
|
|
7
|
+
thing: {
|
|
8
|
+
prefix: 'ti',
|
|
9
|
+
fields: {
|
|
10
|
+
priority: { type: 'number' },
|
|
11
|
+
something: { type: 'string', format: 'strongPassword' },
|
|
12
|
+
},
|
|
13
|
+
},
|
|
7
14
|
bla: {
|
|
8
15
|
prefix: 'bl',
|
|
9
16
|
fields: {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
17
|
+
enum: {
|
|
18
|
+
enum: ['tony', 'jim'],
|
|
19
|
+
},
|
|
20
|
+
setOfNumbers: {
|
|
21
|
+
type: 'set',
|
|
22
|
+
items: {
|
|
13
23
|
type: 'number',
|
|
14
24
|
},
|
|
15
25
|
},
|
|
16
|
-
|
|
17
|
-
type: '
|
|
26
|
+
object: {
|
|
27
|
+
type: 'object',
|
|
28
|
+
properties: {
|
|
29
|
+
flap: { type: 'boolean' },
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
flap: {
|
|
33
|
+
type: 'boolean',
|
|
34
|
+
},
|
|
35
|
+
x: {
|
|
36
|
+
type: 'object',
|
|
37
|
+
properties: {
|
|
38
|
+
flap: {
|
|
39
|
+
type: 'boolean',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
record: {
|
|
44
|
+
type: 'record',
|
|
18
45
|
values: {
|
|
19
|
-
type: '
|
|
46
|
+
type: 'object',
|
|
47
|
+
properties: {
|
|
48
|
+
bla: {
|
|
49
|
+
type: 'array',
|
|
50
|
+
values: {
|
|
51
|
+
type: 'object',
|
|
52
|
+
properties: {
|
|
53
|
+
snux: {
|
|
54
|
+
type: 'object',
|
|
55
|
+
properties: {
|
|
56
|
+
x: {
|
|
57
|
+
type: 'number',
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
flap: { type: 'number' },
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
20
66
|
},
|
|
21
67
|
},
|
|
68
|
+
bla: {
|
|
69
|
+
type: 'set',
|
|
70
|
+
items: { type: 'string', minLength: 3, maxLength: 6 },
|
|
71
|
+
},
|
|
22
72
|
},
|
|
23
73
|
},
|
|
24
74
|
},
|
|
25
75
|
$defs: {},
|
|
26
|
-
languages: ['en'],
|
|
76
|
+
languages: ['en', 'de', 'nl', 'ro', 'za', 'ae'],
|
|
27
77
|
root: {
|
|
28
78
|
fields: {},
|
|
29
79
|
},
|
|
30
80
|
prefixToTypeMapping: {
|
|
31
81
|
bl: 'bla',
|
|
82
|
+
ti: 'thing',
|
|
32
83
|
},
|
|
33
84
|
}
|
|
34
85
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
$id: 'bla',
|
|
42
|
-
ref: 1,
|
|
86
|
+
let r
|
|
87
|
+
|
|
88
|
+
test('enum simple', async (t) => {
|
|
89
|
+
r = await setWalker(schema, {
|
|
90
|
+
$id: 'bl120',
|
|
91
|
+
enum: 'tony',
|
|
43
92
|
})
|
|
44
93
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
94
|
+
t.true(r.errors.length === 0)
|
|
95
|
+
t.deepEqual(resultCollect(r), [{ path: ['enum'], value: 0 }])
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
test('enum not exist error', async (t) => {
|
|
99
|
+
r = await setWalker(schema, {
|
|
100
|
+
$id: 'bl120',
|
|
101
|
+
enum: 'kyle',
|
|
48
102
|
})
|
|
103
|
+
t.true(r.errors.length === 1)
|
|
104
|
+
})
|
|
49
105
|
|
|
50
|
-
|
|
106
|
+
test('default enum', async (t) => {
|
|
107
|
+
r = await setWalker(schema, {
|
|
108
|
+
$id: 'bl120',
|
|
109
|
+
enum: { $default: 'tony' },
|
|
110
|
+
})
|
|
51
111
|
|
|
52
|
-
t.
|
|
53
|
-
|
|
54
|
-
{ path: ['
|
|
55
|
-
{ path: ['arrNum', 1], value: 2 },
|
|
112
|
+
t.true(r.errors.length === 0)
|
|
113
|
+
t.deepEqual(resultCollect(r), [
|
|
114
|
+
{ path: ['enum'], value: { $default: 'tony' } },
|
|
56
115
|
])
|
|
57
116
|
})
|
|
58
117
|
|
|
59
|
-
test
|
|
60
|
-
|
|
61
|
-
$id: '
|
|
62
|
-
|
|
63
|
-
})
|
|
64
|
-
const err1 = await setWalker(schema, {
|
|
65
|
-
$id: 'bla',
|
|
66
|
-
ref: { $value: 1 },
|
|
118
|
+
test('value enum ', async (t) => {
|
|
119
|
+
r = await setWalker(schema, {
|
|
120
|
+
$id: 'bl120',
|
|
121
|
+
enum: { $value: 'tony' },
|
|
67
122
|
})
|
|
68
123
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
124
|
+
console.dir(resultCollect(r), { depth: 10 })
|
|
125
|
+
console.log(r.errors)
|
|
126
|
+
t.true(r.errors.length === 0)
|
|
127
|
+
t.deepEqual(resultCollect(r), [{ path: ['enum'], value: 0 }])
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
test('value & default enum ', async (t) => {
|
|
131
|
+
r = await setWalker(schema, {
|
|
132
|
+
$id: 'bl120',
|
|
133
|
+
enum: { $default: 'jim', $value: 'tony' },
|
|
72
134
|
})
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
135
|
+
|
|
136
|
+
t.true(r.errors.length === 2)
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
test('value: default enum ', async (t) => {
|
|
140
|
+
r = await setWalker(schema, {
|
|
141
|
+
$id: 'bl120',
|
|
142
|
+
enum: { $value: { $default: 'tony' } },
|
|
76
143
|
})
|
|
77
144
|
|
|
78
|
-
t.true(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
t.deepEqual(resultCollect(res, res1), [
|
|
82
|
-
{ path: ['arrNum'], value: { $delete: true } },
|
|
83
|
-
{ path: ['arrNum', 0], value: 1 },
|
|
84
|
-
{ path: ['arrNum', 1], value: 2 },
|
|
85
|
-
{ path: ['arrNum'], value: { $delete: true } },
|
|
86
|
-
{ path: ['arrNum', 0], value: 1 },
|
|
87
|
-
{ path: ['arrNum', 1], value: 2 },
|
|
88
|
-
{ path: ['arrNum'], value: { $delete: true } },
|
|
145
|
+
t.true(r.errors === 0)
|
|
146
|
+
t.deepEqual(resultCollect(r), [
|
|
147
|
+
{ path: ['enum'], value: { $default: 'tony' } },
|
|
89
148
|
])
|
|
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 },
|
|
97
149
|
})
|
|
98
150
|
|
|
99
|
-
test('default
|
|
100
|
-
|
|
101
|
-
$id: '
|
|
102
|
-
|
|
151
|
+
test('default: value enum ', async (t) => {
|
|
152
|
+
r = await setWalker(schema, {
|
|
153
|
+
$id: 'bl120',
|
|
154
|
+
enum: { $default: { $value: 'tony' } },
|
|
103
155
|
})
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
156
|
+
|
|
157
|
+
t.true(r.errors.length === 1)
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
// ask about alias
|
|
161
|
+
test('$alias ', async (t) => {
|
|
162
|
+
r = await setWalker(schema, {
|
|
163
|
+
$id: 'bl120',
|
|
164
|
+
$alias: 'bla',
|
|
107
165
|
})
|
|
108
166
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
167
|
+
t.true(r.errors.length === 0)
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
test('$alias array', async (t) => {
|
|
171
|
+
r = await setWalker(schema, {
|
|
172
|
+
$id: 'bl120',
|
|
173
|
+
$alias: ['bla'],
|
|
112
174
|
})
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
175
|
+
|
|
176
|
+
t.true(r.errors.length === 0)
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
test('object: boolean', async (t) => {
|
|
180
|
+
r = await setWalker(schema, {
|
|
181
|
+
$id: 'bl120',
|
|
182
|
+
object: {
|
|
183
|
+
flap: true,
|
|
184
|
+
},
|
|
116
185
|
})
|
|
117
186
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
t.
|
|
121
|
-
|
|
122
|
-
{ path: ['
|
|
123
|
-
{ path: ['
|
|
124
|
-
// why are theese two different but for defaultits the same
|
|
125
|
-
{ path: ['arrNum'], value: { $default: [1, 2] } },
|
|
187
|
+
console.info(resultCollect(r))
|
|
188
|
+
|
|
189
|
+
t.true(r.errors.length === 0)
|
|
190
|
+
t.deepEqual(resultCollect(r), [
|
|
191
|
+
{ path: ['object', 'flap'], value: true },
|
|
192
|
+
{ path: ['object'], value: { flap: true } },
|
|
126
193
|
])
|
|
127
194
|
})
|
|
128
|
-
// test('arrStr', async (t) => {
|
|
129
|
-
//
|
|
130
|
-
// const err = await(
|
|
131
|
-
// setWalker(
|
|
132
|
-
// schema,
|
|
133
|
-
// {
|
|
134
|
-
// $id: 'bl1',
|
|
135
|
-
// arrStr: [1, '2'],
|
|
136
|
-
// },
|
|
137
|
-
//
|
|
138
|
-
// )
|
|
139
|
-
// )
|
|
140
|
-
// const err = await(
|
|
141
|
-
// setWalker(
|
|
142
|
-
// schema,
|
|
143
|
-
// {
|
|
144
|
-
// $id: 'bla',
|
|
145
|
-
// ref: 1,
|
|
146
|
-
// },
|
|
147
|
-
//
|
|
148
|
-
// )
|
|
149
|
-
// )
|
|
150
|
-
|
|
151
|
-
// await setWalker(
|
|
152
|
-
// schema,
|
|
153
|
-
// {
|
|
154
|
-
// $id: 'bla',
|
|
155
|
-
// arrStr: [1, 2],
|
|
156
|
-
// },
|
|
157
|
-
//
|
|
158
|
-
// )
|
|
159
|
-
// t.deepEqual(results, [
|
|
160
|
-
// { path: ['arrStr'], value: { $delete: true } },
|
|
161
|
-
// { path: ['arrStr', 0], value: 1 },
|
|
162
|
-
// { path: ['arrStr', 1], value: 2 },
|
|
163
|
-
// ])
|
|
164
|
-
// })
|
package/test/set.ts
CHANGED
|
@@ -1,116 +1,90 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import test from 'ava'
|
|
2
|
+
import { BasedSchema, setWalker, walk } from '../src/index'
|
|
3
|
+
import { wait } from '@saulx/utils'
|
|
4
|
+
import { resultCollect } from './utils'
|
|
5
|
+
let r
|
|
6
|
+
const schema: BasedSchema = {
|
|
7
|
+
types: {
|
|
8
|
+
thing: {
|
|
9
|
+
prefix: 'ti',
|
|
10
|
+
fields: {
|
|
11
|
+
something: { type: 'string', format: 'strongPassword' },
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
bla: {
|
|
15
|
+
prefix: 'bl',
|
|
16
|
+
fields: {
|
|
17
|
+
setOfNumbers: {
|
|
18
|
+
type: 'set',
|
|
19
|
+
items: {
|
|
20
|
+
type: 'number',
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
bla: {
|
|
24
|
+
type: 'set',
|
|
25
|
+
items: { type: 'string', minLength: 3, maxLength: 6 },
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
$defs: {},
|
|
31
|
+
languages: ['en', 'de', 'nl', 'ro', 'za', 'ae'],
|
|
32
|
+
root: {
|
|
33
|
+
fields: {},
|
|
34
|
+
},
|
|
35
|
+
prefixToTypeMapping: {
|
|
36
|
+
bl: 'bla',
|
|
37
|
+
ti: 'thing',
|
|
38
|
+
},
|
|
39
|
+
}
|
|
4
40
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
// }
|
|
41
|
+
test('simple setNum', async (t) => {
|
|
42
|
+
r = await setWalker(schema, {
|
|
43
|
+
$id: 'bl120',
|
|
44
|
+
setOfNumbers: [1, 2, 3, 4, 5],
|
|
45
|
+
})
|
|
69
46
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
47
|
+
t.true(r.errors.length === 0)
|
|
48
|
+
t.deepEqual(resultCollect(r), [
|
|
49
|
+
{ path: ['setOfNumbers'], value: { $value: [1, 2, 3, 4, 5] } },
|
|
50
|
+
])
|
|
51
|
+
})
|
|
75
52
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
53
|
+
test('default arr', async (t) => {
|
|
54
|
+
r = await setWalker(schema, {
|
|
55
|
+
$id: 'bl120',
|
|
56
|
+
setOfNumbers: { $add: 20 },
|
|
57
|
+
})
|
|
81
58
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
59
|
+
t.true(r.errors.length === 0)
|
|
60
|
+
t.deepEqual(resultCollect(r), [
|
|
61
|
+
{ path: ['setOfNumbers'], value: { $add: [20] } },
|
|
62
|
+
])
|
|
63
|
+
})
|
|
87
64
|
|
|
88
|
-
//
|
|
89
|
-
//
|
|
90
|
-
//
|
|
91
|
-
//
|
|
92
|
-
//
|
|
65
|
+
// test.only('default arr', async (t) => {
|
|
66
|
+
// r = await setWalker(schema, {
|
|
67
|
+
// $id: 'bl120',
|
|
68
|
+
// setOfNumbers: { $add: [1, 2, 3, 4, 5, 6] },
|
|
69
|
+
// })
|
|
93
70
|
|
|
94
|
-
//
|
|
95
|
-
//
|
|
96
|
-
//
|
|
97
|
-
//
|
|
71
|
+
// console.log(r.errors)
|
|
72
|
+
// console.dir(
|
|
73
|
+
// r.collected.map((v) => ({ path: v.path, value: v.value })),
|
|
74
|
+
// { depth: 10 }
|
|
75
|
+
// )
|
|
76
|
+
// t.true(r.errors.length === 0)
|
|
98
77
|
// })
|
|
99
78
|
|
|
100
|
-
//
|
|
101
|
-
//
|
|
102
|
-
//
|
|
103
|
-
//
|
|
104
|
-
//
|
|
79
|
+
// test.only('default arr', async (t) => {
|
|
80
|
+
// r = await setWalker(schema, {
|
|
81
|
+
// $id: 'bl120',
|
|
82
|
+
// setOfNumbers: { $remove: [1, 2, 3, 4, 5, 6] },
|
|
83
|
+
// })
|
|
105
84
|
|
|
106
|
-
//
|
|
107
|
-
//
|
|
108
|
-
//
|
|
109
|
-
//
|
|
85
|
+
// console.log(r.errors)
|
|
86
|
+
// console.dir(
|
|
87
|
+
// r.collected.map((v) => ({ path: v.path, value: v.value })),
|
|
88
|
+
// { depth: 10 }
|
|
89
|
+
// )
|
|
110
90
|
// })
|
|
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/text.ts
CHANGED
|
@@ -43,28 +43,21 @@ test('throw error no language', async (t) => {
|
|
|
43
43
|
t.true(r.errors.length > 0)
|
|
44
44
|
})
|
|
45
45
|
|
|
46
|
-
test
|
|
46
|
+
test('simple case', async (t) => {
|
|
47
47
|
let r = await setWalker(schema, {
|
|
48
48
|
$id: 'bl120',
|
|
49
49
|
text: { en: 'flap' },
|
|
50
50
|
})
|
|
51
51
|
t.deepEqual(resultCollect(r), [{ path: ['text'], value: { en: 'flap' } }])
|
|
52
|
-
t.true(r.errors.length > 0)
|
|
53
52
|
})
|
|
54
53
|
|
|
55
|
-
test('
|
|
54
|
+
test('simple case with value', async (t) => {
|
|
56
55
|
r = await setWalker(schema, {
|
|
57
56
|
$id: 'bl120',
|
|
58
57
|
$language: 'za',
|
|
59
58
|
text: { $value: 'sdsdds' },
|
|
60
59
|
})
|
|
61
|
-
|
|
62
|
-
// TPDP MAKE INTO TEST
|
|
63
|
-
console.log(
|
|
64
|
-
r.errors,
|
|
65
|
-
r.collected.map((v) => ({ path: v.path, value: v.value }))
|
|
66
|
-
)
|
|
67
|
-
|
|
60
|
+
t.deepEqual(resultCollect(r), [{ path: ['text'], value: { za: 'sdsdds' } }])
|
|
68
61
|
t.true(true)
|
|
69
62
|
})
|
|
70
63
|
|
|
@@ -173,6 +166,7 @@ test('value:lang, lang, default:lang, lang:value, lang:default', async (t) => {
|
|
|
173
166
|
path: ['text'],
|
|
174
167
|
value: {
|
|
175
168
|
nl: 'flapperonus',
|
|
169
|
+
za: 'durp',
|
|
176
170
|
$default: { ae: 'habibi', en: 'flapflap' },
|
|
177
171
|
ro: 'durp',
|
|
178
172
|
},
|
|
@@ -180,7 +174,7 @@ test('value:lang, lang, default:lang, lang:value, lang:default', async (t) => {
|
|
|
180
174
|
])
|
|
181
175
|
})
|
|
182
176
|
|
|
183
|
-
test('value:
|
|
177
|
+
test('value: wrong pattern, lang, default:lang, lang:value, lang:default', async (t) => {
|
|
184
178
|
r = await setWalker(schema, {
|
|
185
179
|
$id: 'bl120',
|
|
186
180
|
$language: 'za',
|
|
@@ -194,6 +188,39 @@ test('value:wrongpatter, lang, default:lang, lang:value, lang:default', async (t
|
|
|
194
188
|
en: { $default: 'xzxz' },
|
|
195
189
|
},
|
|
196
190
|
})
|
|
191
|
+
t.true(r.errors.length > 0)
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
test('text delete', async (t) => {
|
|
195
|
+
r = await setWalker(schema, {
|
|
196
|
+
$id: 'bl120',
|
|
197
|
+
text: {
|
|
198
|
+
$delete: true,
|
|
199
|
+
},
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
t.deepEqual(resultCollect(r), [{ path: ['text'], value: { $delete: true } }])
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
test('just delete', async (t) => {
|
|
206
|
+
r = await setWalker(schema, {
|
|
207
|
+
$id: 'bl120',
|
|
208
|
+
$delete: true,
|
|
209
|
+
})
|
|
210
|
+
t.true(r.errors.length === 1)
|
|
211
|
+
})
|
|
197
212
|
|
|
198
|
-
|
|
213
|
+
test('$default in collected path', async (t) => {
|
|
214
|
+
r = await setWalker(schema, {
|
|
215
|
+
$id: 'bl120',
|
|
216
|
+
text: {
|
|
217
|
+
en: {
|
|
218
|
+
$default: 'title',
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
})
|
|
222
|
+
t.is(r.errors.length, 0)
|
|
223
|
+
t.deepEqual(resultCollect(r), [
|
|
224
|
+
{ path: ['text'], value: { $default: { en: 'title' } } },
|
|
225
|
+
])
|
|
199
226
|
})
|
package/test/walker.ts
CHANGED
|
@@ -360,7 +360,7 @@ test.serial('perf setWalker', async (t) => {
|
|
|
360
360
|
t.true(d < 1e3)
|
|
361
361
|
})
|
|
362
362
|
|
|
363
|
-
test('string', async (t) => {
|
|
363
|
+
test.skip('string', async (t) => {
|
|
364
364
|
// for (let i = 0; i < 10; i++) {
|
|
365
365
|
// console.log(
|
|
366
366
|
// (await setWalker(schema, { $id: 'bl120', name: 'blax' })).target
|
|
@@ -1031,5 +1031,51 @@ test('string', async (t) => {
|
|
|
1031
1031
|
{ depth: 10 }
|
|
1032
1032
|
)
|
|
1033
1033
|
|
|
1034
|
+
console.info('---- doink 43 object ------')
|
|
1035
|
+
r = await setWalker(schema, {
|
|
1036
|
+
$id: 'bl120',
|
|
1037
|
+
object: {},
|
|
1038
|
+
})
|
|
1039
|
+
|
|
1040
|
+
console.dir(r.errors)
|
|
1041
|
+
console.dir(
|
|
1042
|
+
r.collected.map((v) => ({ path: v.path, value: v.value })),
|
|
1043
|
+
{ depth: 10 }
|
|
1044
|
+
)
|
|
1045
|
+
|
|
1046
|
+
console.info('---- doink 44 reference ------')
|
|
1047
|
+
r = await setWalker(
|
|
1048
|
+
schema,
|
|
1049
|
+
{
|
|
1050
|
+
$id: parent,
|
|
1051
|
+
type: 'match',
|
|
1052
|
+
children: {
|
|
1053
|
+
$add: [
|
|
1054
|
+
{
|
|
1055
|
+
type: 'match',
|
|
1056
|
+
$alias: 'maTestWithAlias',
|
|
1057
|
+
title: {
|
|
1058
|
+
nl: 'yes with alias',
|
|
1059
|
+
},
|
|
1060
|
+
},
|
|
1061
|
+
],
|
|
1062
|
+
},
|
|
1063
|
+
},
|
|
1064
|
+
async (args, type) => {
|
|
1065
|
+
console.info('GO ASYNC', args.path, args.value, type)
|
|
1066
|
+
if (args.value.type === 'thing') {
|
|
1067
|
+
return 'ti' + Math.floor(Math.random() * 10000).toString(16)
|
|
1068
|
+
} else {
|
|
1069
|
+
return 'bl1221'
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
)
|
|
1073
|
+
|
|
1074
|
+
console.dir(r.errors)
|
|
1075
|
+
console.dir(
|
|
1076
|
+
r.collected.map((v) => ({ path: v.path, value: v.value })),
|
|
1077
|
+
{ depth: 10 }
|
|
1078
|
+
)
|
|
1079
|
+
|
|
1034
1080
|
t.true(true)
|
|
1035
1081
|
})
|