@dzeio/schema 0.0.5 → 0.0.6
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/Schema.d.mts +2 -2
- package/dist/Schema.d.ts +2 -2
- package/dist/Schema.js +7 -6
- package/dist/Schema.mjs +7 -6
- package/package.json +1 -1
package/dist/Schema.d.mts
CHANGED
|
@@ -285,8 +285,8 @@ declare class SchemaUnion<T extends Array<SchemaItem>> extends SchemaItem<ItemTy
|
|
|
285
285
|
|
|
286
286
|
declare function isNull(value: unknown): value is undefined | null;
|
|
287
287
|
declare function parseQuery<T extends SchemaItem>(model: T, query: URLSearchParams, opts?: Parameters<T['parse']>[1]): ReturnType<T['parse']>;
|
|
288
|
-
declare function parseFormData<T extends
|
|
289
|
-
declare function parseForm<T extends
|
|
288
|
+
declare function parseFormData<T extends SchemaItem>(model: T, data: FormData, opts?: Parameters<T['parse']>[1]): ReturnType<T['parse']>;
|
|
289
|
+
declare function parseForm<T extends SchemaItem>(model: T, form: HTMLFormElement, opts?: Parameters<T['parse']>[1]): ReturnType<T['parse']>;
|
|
290
290
|
|
|
291
291
|
declare function parceable(): (target: object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<any>) => TypedPropertyDescriptor<any>;
|
|
292
292
|
type SchemaItemStatic = new (...args: Array<any>) => SchemaItem;
|
package/dist/Schema.d.ts
CHANGED
|
@@ -285,8 +285,8 @@ declare class SchemaUnion<T extends Array<SchemaItem>> extends SchemaItem<ItemTy
|
|
|
285
285
|
|
|
286
286
|
declare function isNull(value: unknown): value is undefined | null;
|
|
287
287
|
declare function parseQuery<T extends SchemaItem>(model: T, query: URLSearchParams, opts?: Parameters<T['parse']>[1]): ReturnType<T['parse']>;
|
|
288
|
-
declare function parseFormData<T extends
|
|
289
|
-
declare function parseForm<T extends
|
|
288
|
+
declare function parseFormData<T extends SchemaItem>(model: T, data: FormData, opts?: Parameters<T['parse']>[1]): ReturnType<T['parse']>;
|
|
289
|
+
declare function parseForm<T extends SchemaItem>(model: T, form: HTMLFormElement, opts?: Parameters<T['parse']>[1]): ReturnType<T['parse']>;
|
|
290
290
|
|
|
291
291
|
declare function parceable(): (target: object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<any>) => TypedPropertyDescriptor<any>;
|
|
292
292
|
type SchemaItemStatic = new (...args: Array<any>) => SchemaItem;
|
package/dist/Schema.js
CHANGED
|
@@ -375,20 +375,19 @@ function parseQuery(model, query, opts) {
|
|
|
375
375
|
return model.parse(record, opts);
|
|
376
376
|
}
|
|
377
377
|
function parseFormData(model, data, opts) {
|
|
378
|
-
var _a;
|
|
379
378
|
const record = {};
|
|
380
379
|
for (const [key, value] of data) {
|
|
381
|
-
const
|
|
382
|
-
(0, import_object_util3.objectSet)(record, key.split(".").map((it) => /^\d+$/g.test(it) ? parseInt(it, 10) : it),
|
|
380
|
+
const hasMultipleValues = data.getAll(key).length > 1;
|
|
381
|
+
(0, import_object_util3.objectSet)(record, key.split(".").map((it) => /^\d+$/g.test(it) ? parseInt(it, 10) : it), hasMultipleValues ? data.getAll(key) : value);
|
|
383
382
|
}
|
|
384
383
|
const handleBoolean = (value, keys) => {
|
|
385
|
-
var
|
|
384
|
+
var _a;
|
|
386
385
|
if (value instanceof SchemaNullable) {
|
|
387
386
|
handleBoolean(value.unwrap(), keys);
|
|
388
387
|
}
|
|
389
388
|
if (value instanceof SchemaArray) {
|
|
390
389
|
const elements = (0, import_object_util3.objectGet)(record, keys);
|
|
391
|
-
for (let it = 0; it < ((
|
|
390
|
+
for (let it = 0; it < ((_a = elements == null ? void 0 : elements.length) != null ? _a : 0); it++) {
|
|
392
391
|
handleBoolean(value.unwrap(), [...keys, it]);
|
|
393
392
|
}
|
|
394
393
|
}
|
|
@@ -404,7 +403,9 @@ function parseFormData(model, data, opts) {
|
|
|
404
403
|
handleBoolean(value, [...keys, key]);
|
|
405
404
|
});
|
|
406
405
|
};
|
|
407
|
-
|
|
406
|
+
if (model instanceof SchemaObject) {
|
|
407
|
+
handleSchemaForBoolean(model.model);
|
|
408
|
+
}
|
|
408
409
|
return model.parse(record, opts);
|
|
409
410
|
}
|
|
410
411
|
function parseForm(model, form, opts) {
|
package/dist/Schema.mjs
CHANGED
|
@@ -332,20 +332,19 @@ function parseQuery(model, query, opts) {
|
|
|
332
332
|
return model.parse(record, opts);
|
|
333
333
|
}
|
|
334
334
|
function parseFormData(model, data, opts) {
|
|
335
|
-
var _a;
|
|
336
335
|
const record = {};
|
|
337
336
|
for (const [key, value] of data) {
|
|
338
|
-
const
|
|
339
|
-
objectSet(record, key.split(".").map((it) => /^\d+$/g.test(it) ? parseInt(it, 10) : it),
|
|
337
|
+
const hasMultipleValues = data.getAll(key).length > 1;
|
|
338
|
+
objectSet(record, key.split(".").map((it) => /^\d+$/g.test(it) ? parseInt(it, 10) : it), hasMultipleValues ? data.getAll(key) : value);
|
|
340
339
|
}
|
|
341
340
|
const handleBoolean = (value, keys) => {
|
|
342
|
-
var
|
|
341
|
+
var _a;
|
|
343
342
|
if (value instanceof SchemaNullable) {
|
|
344
343
|
handleBoolean(value.unwrap(), keys);
|
|
345
344
|
}
|
|
346
345
|
if (value instanceof SchemaArray) {
|
|
347
346
|
const elements = objectGet(record, keys);
|
|
348
|
-
for (let it = 0; it < ((
|
|
347
|
+
for (let it = 0; it < ((_a = elements == null ? void 0 : elements.length) != null ? _a : 0); it++) {
|
|
349
348
|
handleBoolean(value.unwrap(), [...keys, it]);
|
|
350
349
|
}
|
|
351
350
|
}
|
|
@@ -361,7 +360,9 @@ function parseFormData(model, data, opts) {
|
|
|
361
360
|
handleBoolean(value, [...keys, key]);
|
|
362
361
|
});
|
|
363
362
|
};
|
|
364
|
-
|
|
363
|
+
if (model instanceof SchemaObject) {
|
|
364
|
+
handleSchemaForBoolean(model.model);
|
|
365
|
+
}
|
|
365
366
|
return model.parse(record, opts);
|
|
366
367
|
}
|
|
367
368
|
function parseForm(model, form, opts) {
|