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 66 additions and 64 deletions
Showing only changes of commit 0e956c0c78 - Show all commits

View File

@@ -7,6 +7,7 @@ import { DejsonifiableZodSchemaObject } from "../traits/DejsonifiableZodSchemaOb
import { ExtendableZodSchemaObject } from "../traits/ExtendableZodSchemaObject"
import { InstantiableZodSchemaObject } from "../traits/InstantiableZodSchemaObject"
import { JsonifiableZodSchemaObject } from "../traits/JsonifiableZodSchemaObject"
import { ZodSchemaObjectInstantiationSchemas } from "../traits/ZodSchemaObjectInstantiationSchemas"
import { StaticMembers } from "../util"
@@ -63,7 +64,7 @@ extends TraitExpressionBuilder<Superclass, Traits> {
[
...this.expressionTraits,
// ZodSchemaObjectInstantiationSchemas,
ZodSchemaObjectInstantiationSchemas,
InstantiableZodSchemaObject,
ExtendableZodSchemaObject,
],

View File

@@ -41,6 +41,8 @@ const test = User.schema.extend({
)
const inst = User.create({ id: 1n, name: "" })
const instEffect = User.createEffect({ id: 1n, name: "" })
// console.log(inst)
const jsonifiedUser = await inst.jsonifyPromise()

View File

@@ -1,4 +1,4 @@
import { TraitStaticMembers, expression } from "@thilawyn/traitify-ts"
import { TraitStaticMembers, trait } from "@thilawyn/traitify-ts"
import { HasRequiredKeys } from "type-fest"
import { z } from "zod"
import { ZodSchemaClass } from "../shapes/ZodSchemaClass"
@@ -6,6 +6,8 @@ import { parseZodTypeEffect } from "../util"
import { ZodSchemaObjectInstantiationSchemas } from "./ZodSchemaObjectInstantiationSchemas"
type ZodSchemaObjectInstantiationSchemasStaticMembers = TraitStaticMembers<typeof ZodSchemaObjectInstantiationSchemas>
type NewZodSchemaInstanceInput<
Values extends object,
DefaultValues extends Partial<Values>,
@@ -26,10 +28,7 @@ type NewZodSchemaInstanceArgs<Input extends object> = (
)
export const InstantiableZodSchemaObject = expression
.expresses(ZodSchemaObjectInstantiationSchemas)
.build()
.subtrait()
export const InstantiableZodSchemaObject = trait
.implement(Super => class InstantiableZodSchemaObject extends Super {
static create<
Instance extends Values,
@@ -43,7 +42,7 @@ export const InstantiableZodSchemaObject = expression
>(
this: (
ZodSchemaClass<Instance, any, any, any, SchemaWithDefaultValuesT, SchemaWithDefaultValuesUnknownKeys, SchemaWithDefaultValuesCatchall, Values, PartialValues> &
TraitStaticMembers<typeof ZodSchemaObjectInstantiationSchemas>
ZodSchemaObjectInstantiationSchemasStaticMembers
),
...[values, params]: NewZodSchemaInstanceArgs<PartialValues>
) {
@@ -62,7 +61,7 @@ export const InstantiableZodSchemaObject = expression
>(
this: (
ZodSchemaClass<Instance, any, any, any, SchemaWithDefaultValuesT, SchemaWithDefaultValuesUnknownKeys, SchemaWithDefaultValuesCatchall, Values, PartialValues> &
TraitStaticMembers<typeof ZodSchemaObjectInstantiationSchemas>
ZodSchemaObjectInstantiationSchemasStaticMembers
),
...[values, params]: NewZodSchemaInstanceArgs<PartialValues>
) {
@@ -81,7 +80,7 @@ export const InstantiableZodSchemaObject = expression
>(
this: (
ZodSchemaClass<Instance, any, any, any, SchemaWithDefaultValuesT, SchemaWithDefaultValuesUnknownKeys, SchemaWithDefaultValuesCatchall, Values, PartialValues> &
TraitStaticMembers<typeof ZodSchemaObjectInstantiationSchemas>
ZodSchemaObjectInstantiationSchemasStaticMembers
),
...[values, params]: NewZodSchemaInstanceArgs<PartialValues>
) {