0.1.2 #3

Merged
Thilawyn merged 136 commits from next into master 2024-03-11 19:44:21 +01:00
3 changed files with 52 additions and 1 deletions
Showing only changes of commit 6ee9337426 - Show all commits

BIN
bun.lockb

Binary file not shown.

View File

@@ -48,7 +48,7 @@
"clean:node": "rm -rf node_modules"
},
"dependencies": {
"@thilawyn/traitify-ts": "^0.1.0",
"@thilawyn/traitify-ts": "^0.1.1",
"decimal.js": "^10.4.3",
"effect": "^2.2.3",
"lodash-es": "^4.17.21",

View File

@@ -3,6 +3,57 @@ import { AbstractClass, Class as ConcreteClass, Opaque } from "type-fest"
import { z } from "zod"
import { DefinedDefaultValuesTag, NewZodSchemaInstanceArgs, NewZodSchemaInstanceInput, TZodSchemaClass } from "."
import { Class, ClassesInstances, ClassesStaticMembers, GetClassType, MergeInheritanceTree, MergeInheritanceTreeWithoutOverriding, parseZodTypeEffect } from "./util"
import { abstract, trait } from "@thilawyn/traitify-ts"
export const InstantiableZodSchemaObject = <
SchemaT extends z.ZodRawShape,
SchemaUnknownKeys extends z.UnknownKeysParam,
SchemaCatchall extends z.ZodTypeAny,
Values extends {},
DefaultValues extends Partial<Values>,
>() => trait(
abstract(),
Super => class InstantiableZodSchemaObject extends Super {
static create(
...[values, params]: NewZodSchemaInstanceArgs<
NewZodSchemaInstanceInput<Values, DefaultValues>
>
) {
return new this(
this.schema.parse({ ...this.defaultValues, ...values }, params)
)
}
static async createPromise(
...[values, params]: NewZodSchemaInstanceArgs<
NewZodSchemaInstanceInput<Values, DefaultValues>
>
) {
return new this(
await this.schema.parseAsync({ ...this.defaultValues, ...values }, params)
)
}
static createEffect(
...[values, params]: NewZodSchemaInstanceArgs<
NewZodSchemaInstanceInput<Values, DefaultValues>
>
) {
return pipe(
parseZodTypeEffect(
this.schema,
{ ...this.defaultValues, ...values },
params,
),
Effect.map(values => new this(values)),
)
}
},
)
export function ZodSchemaClassOf<