aabad_ankit
aabad_ankit
Aarktype
Created by aabad_ankit on 10/3/2024 in #questions
Partial Application of the validator
Is there any way to partially apply the validator for eg:
const test = type({
name: "string",
info: { email: "string.email & string.lower", age: "number" }
});
const test = type({
name: "string",
info: { email: "string.email & string.lower", age: "number" }
});
Now I want to partially use test.info.email or apply the validator based on the partial object I pass. Usecase: I will use an arktype to represent the schema in my db. Now I want to allow to partially update the db. but still apply the transformation and validation specified in the schema.
25 replies
Aarktype
Created by aabad_ankit on 9/4/2024 in #questions
Is there a way to rename the key in parse result
const t = type({name:"string"}) const result = t({name:"ankit"}) i want the result to be {alias:"ankit"} how can i replace the key "name" with "alias"
3 replies
Aarktype
Created by aabad_ankit on 9/4/2024 in #questions
Can I add a default value to a type if everything other satisfies in a union type
const type1 = type({name: "string"}) const type2 = type({city: "string"}) const union = type1.or(type2) const result1 = union({name:"ankit"}) const result2 = union({city:"Ajmer"}) I want result1 to be {name: "ankit",kind:"name"} I want result2 to be {city:"Ajmer",kind:"city"} or better const [kind,result] = union({name:"ankit"}) here kind will be "name" and result will be {name:"ankit"} and kind type will be "name"| "city" can I add these default value of kind in the type definitions so that if parsed with that validator from the union the kind is added
66 replies