@based/schema 0.0.8 → 0.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/set/collections.js +43 -10
- package/dist/set/collections.js.map +1 -1
- package/package.json +1 -1
- package/src/set/collections.ts +55 -21
- package/test/setWalker.ts +12 -7
package/dist/set/collections.js
CHANGED
|
@@ -66,12 +66,23 @@ const object = async (path, value, fieldSchema, typeSchema, target, handlers, no
|
|
|
66
66
|
exports.object = object;
|
|
67
67
|
// unshift // only allow 1 command
|
|
68
68
|
const array = async (path, value, fieldSchema, typeSchema, target, handlers, noCollect) => {
|
|
69
|
-
|
|
69
|
+
// $value
|
|
70
|
+
let isArray = Array.isArray(value);
|
|
70
71
|
let parsedValue = value;
|
|
71
72
|
let opCount = 0;
|
|
72
|
-
|
|
73
|
+
let has$Value = false;
|
|
74
|
+
if (typeof parsedValue === 'object' && !isArray) {
|
|
75
|
+
if (value.$value) {
|
|
76
|
+
opCount++;
|
|
77
|
+
has$Value = true;
|
|
78
|
+
parsedValue = value.$value;
|
|
79
|
+
isArray = Array.isArray(parsedValue);
|
|
80
|
+
}
|
|
73
81
|
if (value.$insert) {
|
|
74
82
|
opCount++;
|
|
83
|
+
if (opCount > 1) {
|
|
84
|
+
(0, error_1.error)(path, error_1.ParseError.multipleOperationsNotAllowed);
|
|
85
|
+
}
|
|
75
86
|
if (typeof value.$insert !== 'object' ||
|
|
76
87
|
value.$insert.$idx === undefined) {
|
|
77
88
|
(0, error_1.error)(path, error_1.ParseError.incorrectFormat);
|
|
@@ -130,14 +141,13 @@ const array = async (path, value, fieldSchema, typeSchema, target, handlers, noC
|
|
|
130
141
|
(0, error_1.error)(path, error_1.ParseError.multipleOperationsNotAllowed);
|
|
131
142
|
}
|
|
132
143
|
if (typeof value.$assign !== 'object' ||
|
|
133
|
-
value.$assign.$idx
|
|
144
|
+
typeof value.$assign.$idx !== 'number') {
|
|
134
145
|
(0, error_1.error)(path, error_1.ParseError.incorrectFormat);
|
|
135
146
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
147
|
+
await (0, _1.fieldWalker)([...path, value.$assign.$idx], value.$assign.$value, fieldSchema.values, typeSchema, target, handlers, noCollect);
|
|
148
|
+
return;
|
|
139
149
|
}
|
|
140
|
-
if (!noCollect) {
|
|
150
|
+
if (!has$Value && !noCollect) {
|
|
141
151
|
handlers.collect({
|
|
142
152
|
path,
|
|
143
153
|
value: parsedValue,
|
|
@@ -146,16 +156,39 @@ const array = async (path, value, fieldSchema, typeSchema, target, handlers, noC
|
|
|
146
156
|
target,
|
|
147
157
|
});
|
|
148
158
|
}
|
|
149
|
-
|
|
159
|
+
if (!has$Value) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
150
162
|
}
|
|
151
163
|
if (!isArray) {
|
|
152
164
|
(0, error_1.error)(path, error_1.ParseError.incorrectFieldType);
|
|
153
165
|
}
|
|
154
166
|
const q = [];
|
|
155
|
-
|
|
156
|
-
|
|
167
|
+
const collector = [];
|
|
168
|
+
const nHandler = noCollect
|
|
169
|
+
? handlers
|
|
170
|
+
: {
|
|
171
|
+
...handlers,
|
|
172
|
+
collect: (collect) => {
|
|
173
|
+
collector.push(collect);
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
for (let i = 0; i < parsedValue.length; i++) {
|
|
177
|
+
q.push((0, _1.fieldWalker)([...path, i], parsedValue[i], fieldSchema.values, typeSchema, target, nHandler, noCollect));
|
|
157
178
|
}
|
|
158
179
|
await Promise.all(q);
|
|
180
|
+
if (!noCollect) {
|
|
181
|
+
handlers.collect({
|
|
182
|
+
path,
|
|
183
|
+
typeSchema,
|
|
184
|
+
fieldSchema,
|
|
185
|
+
target,
|
|
186
|
+
value: { $delete: true },
|
|
187
|
+
});
|
|
188
|
+
for (const c of collector) {
|
|
189
|
+
handlers.collect(c);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
159
192
|
};
|
|
160
193
|
exports.array = array;
|
|
161
194
|
const record = async (path, value, fieldSchema) => { };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collections.js","sourceRoot":"","sources":["../../src/set/collections.ts"],"names":[],"mappings":";;;AACA,mCAA2C;AAC3C,wBAA+B;AAExB,MAAM,GAAG,GAAkB,KAAK,EACrC,IAAI,EACJ,KAAK,EACL,WAAW,EACX,UAAU,EACV,MAAM,EACN,QAAQ,EACR,SAAS,EACT,EAAE;IACF,MAAM,CAAC,GAAoB,EAAE,CAAA;IAC7B,MAAM,QAAQ,GAAG,WAAW,CAAC,KAAK,CAAA;IAClC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACxB,MAAM,WAAW,GAAG,EAAE,CAAA;QACtB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACrC,CAAC,CAAC,IAAI,CACJ,IAAA,cAAW,EAAC,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE;gBAChE,GAAG,QAAQ;gBACX,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;oBACrB,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;gBACzB,CAAC;aACF,CAAC,CACH,CAAA;SACF;QACD,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;QACpB,IAAI,CAAC,SAAS,EAAE;YACd,QAAQ,CAAC,OAAO,CAAC;gBACf,IAAI;gBACJ,KAAK,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE;gBAC9B,UAAU;gBACV,WAAW;gBACX,MAAM;aACP,CAAC,CAAA;SACH;KACF;SAAM;QACL,IAAI,KAAK,CAAC,IAAI,EAAE;YACd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,MA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AAG,IAAI,KAAK,EAAE;QACvB,MAAM,OAAO,GAAG,WAAW,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;QAC3C,IAAI,CAAC,OAAO,EAAE;YACZ,IAAA,aAAK,EAAC,CAAC,GAAG,IAAI,EAAE,GAAG,CAAC,EAAE,kBAAU,CAAC,iBAAiB,CAAC,CAAA;SACpD;QACD,CAAC,CAAC,IAAI,CACJ,IAAA,cAAW,EACT,CAAC,GAAG,IAAI,EAAE,GAAG,CAAC,EACd,KAAK,CAAC,GAAG,CAAC,EACV,OAAO,EACP,UAAU,EACV,MAAM,EACN,QAAQ,EACR,SAAS,CACV,CACF,CAAA;KACF;IACD,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;AACtB,CAAC,CAAA;AAnCY,QAAA,MAAM,UAmClB;AAED,kCAAkC;AAC3B,MAAM,KAAK,GAAoB,KAAK,EACzC,IAAI,EACJ,KAAK,EACL,WAAW,EACX,UAAU,EACV,MAAM,EACN,QAAQ,EACR,SAAS,EACT,EAAE;IACF,
|
|
1
|
+
{"version":3,"file":"collections.js","sourceRoot":"","sources":["../../src/set/collections.ts"],"names":[],"mappings":";;;AACA,mCAA2C;AAC3C,wBAA+B;AAExB,MAAM,GAAG,GAAkB,KAAK,EACrC,IAAI,EACJ,KAAK,EACL,WAAW,EACX,UAAU,EACV,MAAM,EACN,QAAQ,EACR,SAAS,EACT,EAAE;IACF,MAAM,CAAC,GAAoB,EAAE,CAAA;IAC7B,MAAM,QAAQ,GAAG,WAAW,CAAC,KAAK,CAAA;IAClC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACxB,MAAM,WAAW,GAAG,EAAE,CAAA;QACtB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACrC,CAAC,CAAC,IAAI,CACJ,IAAA,cAAW,EAAC,CAAC,GAAG,IAAI,EAAE,CAAC,C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,MAAM,CAAC,IAAI,SAAS,EAAE;YACzB,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;SACpB;KACF;AACH,CAAC,CAAA;AA3LY,QAAA,KAAK,SA2LjB;AAEM,MAAM,MAAM,GAAqB,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,GAAE,CAAC,CAAA;AAAjE,QAAA,MAAM,UAA2D"}
|
package/package.json
CHANGED
package/src/set/collections.ts
CHANGED
|
@@ -120,12 +120,25 @@ export const array: Parser<'array'> = async (
|
|
|
120
120
|
handlers,
|
|
121
121
|
noCollect
|
|
122
122
|
) => {
|
|
123
|
-
|
|
123
|
+
// $value
|
|
124
|
+
|
|
125
|
+
let isArray = Array.isArray(value)
|
|
124
126
|
let parsedValue = value
|
|
125
127
|
let opCount = 0
|
|
126
|
-
|
|
128
|
+
let has$Value = false
|
|
129
|
+
|
|
130
|
+
if (typeof parsedValue === 'object' && !isArray) {
|
|
131
|
+
if (value.$value) {
|
|
132
|
+
opCount++
|
|
133
|
+
has$Value = true
|
|
134
|
+
parsedValue = value.$value
|
|
135
|
+
isArray = Array.isArray(parsedValue)
|
|
136
|
+
}
|
|
127
137
|
if (value.$insert) {
|
|
128
138
|
opCount++
|
|
139
|
+
if (opCount > 1) {
|
|
140
|
+
error(path, ParseError.multipleOperationsNotAllowed)
|
|
141
|
+
}
|
|
129
142
|
if (
|
|
130
143
|
typeof value.$insert !== 'object' ||
|
|
131
144
|
value.$insert.$idx === undefined
|
|
@@ -190,7 +203,6 @@ export const array: Parser<'array'> = async (
|
|
|
190
203
|
if (opCount > 1) {
|
|
191
204
|
error(path, ParseError.multipleOperationsNotAllowed)
|
|
192
205
|
}
|
|
193
|
-
|
|
194
206
|
const q: Promise<void>[] = []
|
|
195
207
|
const unshift = Array.isArray(value.$unshift)
|
|
196
208
|
? value.$unshift
|
|
@@ -216,26 +228,24 @@ export const array: Parser<'array'> = async (
|
|
|
216
228
|
if (opCount > 1) {
|
|
217
229
|
error(path, ParseError.multipleOperationsNotAllowed)
|
|
218
230
|
}
|
|
219
|
-
|
|
220
231
|
if (
|
|
221
232
|
typeof value.$assign !== 'object' ||
|
|
222
|
-
value.$assign.$idx
|
|
233
|
+
typeof value.$assign.$idx !== 'number'
|
|
223
234
|
) {
|
|
224
235
|
error(path, ParseError.incorrectFormat)
|
|
225
|
-
} else {
|
|
226
|
-
await fieldWalker(
|
|
227
|
-
path,
|
|
228
|
-
value.$assign.$value,
|
|
229
|
-
fieldSchema.values,
|
|
230
|
-
typeSchema,
|
|
231
|
-
target,
|
|
232
|
-
handlers,
|
|
233
|
-
true
|
|
234
|
-
)
|
|
235
236
|
}
|
|
237
|
+
await fieldWalker(
|
|
238
|
+
[...path, value.$assign.$idx],
|
|
239
|
+
value.$assign.$value,
|
|
240
|
+
fieldSchema.values,
|
|
241
|
+
typeSchema,
|
|
242
|
+
target,
|
|
243
|
+
handlers,
|
|
244
|
+
noCollect
|
|
245
|
+
)
|
|
246
|
+
return
|
|
236
247
|
}
|
|
237
|
-
|
|
238
|
-
if (!noCollect) {
|
|
248
|
+
if (!has$Value && !noCollect) {
|
|
239
249
|
handlers.collect({
|
|
240
250
|
path,
|
|
241
251
|
value: parsedValue,
|
|
@@ -244,26 +254,50 @@ export const array: Parser<'array'> = async (
|
|
|
244
254
|
target,
|
|
245
255
|
})
|
|
246
256
|
}
|
|
247
|
-
|
|
257
|
+
if (!has$Value) {
|
|
258
|
+
return
|
|
259
|
+
}
|
|
248
260
|
}
|
|
249
261
|
if (!isArray) {
|
|
250
262
|
error(path, ParseError.incorrectFieldType)
|
|
251
263
|
}
|
|
252
264
|
const q: Promise<void>[] = []
|
|
253
|
-
|
|
265
|
+
const collector: any[] = []
|
|
266
|
+
const nHandler = noCollect
|
|
267
|
+
? handlers
|
|
268
|
+
: {
|
|
269
|
+
...handlers,
|
|
270
|
+
collect: (collect) => {
|
|
271
|
+
collector.push(collect)
|
|
272
|
+
},
|
|
273
|
+
}
|
|
274
|
+
for (let i = 0; i < parsedValue.length; i++) {
|
|
254
275
|
q.push(
|
|
255
276
|
fieldWalker(
|
|
256
277
|
[...path, i],
|
|
257
|
-
|
|
278
|
+
parsedValue[i],
|
|
258
279
|
fieldSchema.values,
|
|
259
280
|
typeSchema,
|
|
260
281
|
target,
|
|
261
|
-
|
|
282
|
+
nHandler,
|
|
262
283
|
noCollect
|
|
263
284
|
)
|
|
264
285
|
)
|
|
265
286
|
}
|
|
266
287
|
await Promise.all(q)
|
|
288
|
+
|
|
289
|
+
if (!noCollect) {
|
|
290
|
+
handlers.collect({
|
|
291
|
+
path,
|
|
292
|
+
typeSchema,
|
|
293
|
+
fieldSchema,
|
|
294
|
+
target,
|
|
295
|
+
value: { $delete: true },
|
|
296
|
+
})
|
|
297
|
+
for (const c of collector) {
|
|
298
|
+
handlers.collect(c)
|
|
299
|
+
}
|
|
300
|
+
}
|
|
267
301
|
}
|
|
268
302
|
|
|
269
303
|
export const record: Parser<'record'> = async (path, value, fieldSchema) => {}
|
package/test/setWalker.ts
CHANGED
|
@@ -215,9 +215,11 @@ test.serial('collect correctly', async (t) => {
|
|
|
215
215
|
{ path: ['blub'], value: { $increment: 1 } },
|
|
216
216
|
{ path: ['time'], value: now },
|
|
217
217
|
{ path: ['form', 'snurp'], value: 'blx12' },
|
|
218
|
-
{
|
|
219
|
-
|
|
220
|
-
|
|
218
|
+
{
|
|
219
|
+
path: ['snurpArray', 0],
|
|
220
|
+
value: 100,
|
|
221
|
+
},
|
|
222
|
+
|
|
221
223
|
{ path: ['bla'], value: false },
|
|
222
224
|
{ path: ['form', 'lastName'], value: 'de beer' },
|
|
223
225
|
{ path: ['form', 'json'], value: '{"bla":1,"x":2,"y":3}' },
|
|
@@ -225,16 +227,19 @@ test.serial('collect correctly', async (t) => {
|
|
|
225
227
|
{ path: ['form', 'password'], value: 'mypassword!' },
|
|
226
228
|
{ path: ['form', 'bla'], value: { $value: ['bl123', 'bl234'] } },
|
|
227
229
|
{ path: ['form', 'blab'], value: { $add: ['bl456'] } },
|
|
228
|
-
|
|
229
|
-
path: ['snurpArray'],
|
|
230
|
-
value: { $assign: { $idx: 0, $value: 100 } },
|
|
231
|
-
},
|
|
230
|
+
|
|
232
231
|
{ path: ['setje'], value: { $value: [1, 2, 3] } },
|
|
233
232
|
{ path: ['form', 'blub'], value: { $value: ['x'] } },
|
|
234
233
|
{
|
|
235
234
|
path: ['specialArray'],
|
|
236
235
|
value: { $insert: { $value: ['a', 'b', 'c'], $idx: 0 } },
|
|
237
236
|
},
|
|
237
|
+
|
|
238
|
+
{ path: ['snurp'], value: { $delete: true } },
|
|
239
|
+
{ path: ['snurp', 0, 'x'], value: { $delete: true } },
|
|
240
|
+
{ path: ['snurp', 0, 'x', 0], value: 1 },
|
|
241
|
+
{ path: ['snurp', 0, 'x', 1], value: 2 },
|
|
242
|
+
{ path: ['snurp', 0, 'x', 2], value: 3 },
|
|
238
243
|
]
|
|
239
244
|
|
|
240
245
|
console.log(results)
|