Compare commits
4 Commits
740c597f3c
...
24b4bf1a74
Author | SHA1 | Date | |
---|---|---|---|
24b4bf1a74 | |||
bd9e0bcffe | |||
5851f7779a | |||
512d5817f2 |
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@dzeio/schema",
|
"name": "@dzeio/schema",
|
||||||
"version": "0.3.0",
|
"version": "0.3.2",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@dzeio/schema",
|
"name": "@dzeio/schema",
|
||||||
"version": "0.3.0",
|
"version": "0.3.2",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@dzeio/object-util": "^1.8.3",
|
"@dzeio/object-util": "^1.8.3",
|
||||||
"@standard-schema/spec": "^1.0.0",
|
"@standard-schema/spec": "^1.0.0",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@dzeio/schema",
|
"name": "@dzeio/schema",
|
||||||
"version": "0.3.0",
|
"version": "0.3.2",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@dzeio/object-util": "^1.8.3"
|
"@dzeio/object-util": "^1.8.3"
|
||||||
},
|
},
|
||||||
|
@ -19,8 +19,11 @@ export default class SchemaArray<Type extends SchemaItem> extends SchemaItem<Arr
|
|||||||
* split a string into an array
|
* split a string into an array
|
||||||
* @param [separator] default:`,` the separator to use
|
* @param [separator] default:`,` the separator to use
|
||||||
*/
|
*/
|
||||||
|
@parceable()
|
||||||
public split(separator = ',') {
|
public split(separator = ',') {
|
||||||
this.addPreProcess((it) => typeof it === 'string' ? it.split(separator) : it)
|
this.addPreProcess((it) => typeof it === 'string' ? it.split(separator) : it)
|
||||||
|
|
||||||
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
public parse(input: unknown, options?: { fast?: boolean }): ValidationResult<Array<SchemaInfer<Type>>> {
|
public parse(input: unknown, options?: { fast?: boolean }): ValidationResult<Array<SchemaInfer<Type>>> {
|
||||||
|
@ -27,6 +27,7 @@ export default class SchemaObject<T extends Record<string, SchemaItem> = any> ex
|
|||||||
}
|
}
|
||||||
|
|
||||||
const clone = objectClone(object)
|
const clone = objectClone(object)
|
||||||
|
const res: ModelInfer<T> = {} as ModelInfer<T>
|
||||||
|
|
||||||
// loop through the childs
|
// loop through the childs
|
||||||
objectLoop(this.model, (childSchema, key) => {
|
objectLoop(this.model, (childSchema, key) => {
|
||||||
@ -45,7 +46,7 @@ export default class SchemaObject<T extends Record<string, SchemaItem> = any> ex
|
|||||||
|
|
||||||
// @ts-expect-error while it's a generic we know by proof above that it's valid !
|
// @ts-expect-error while it's a generic we know by proof above that it's valid !
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||||
clone[key] = child.object
|
res[key] = child.object
|
||||||
|
|
||||||
// skip rest of items if current one is invalid
|
// skip rest of items if current one is invalid
|
||||||
return child.valid || !options?.fast
|
return child.valid || !options?.fast
|
||||||
@ -55,7 +56,7 @@ export default class SchemaObject<T extends Record<string, SchemaItem> = any> ex
|
|||||||
return {
|
return {
|
||||||
valid: errors.length === 0,
|
valid: errors.length === 0,
|
||||||
errors: errors,
|
errors: errors,
|
||||||
object: clone
|
object: res
|
||||||
} as ValidationResult<ModelInfer<T>>
|
} as ValidationResult<ModelInfer<T>>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user