From 6ee9337426b266131348bb8e2c5b02df5bb2a10c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Tue, 6 Feb 2024 05:24:00 +0100 Subject: [PATCH] Trait work --- bun.lockb | Bin 160800 -> 160800 bytes package.json | 2 +- src/ZodSchemaClass.ts | 51 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/bun.lockb b/bun.lockb index 9deffd24124341322b68eff9f5b8e66aa557f043..c13519a2388570810df42e364bd8b2bfd96b2ec2 100755 GIT binary patch delta 162 zcmV;T0A2r}=n0_c36L%zT0O=jmEX#*4I4zzR`CmS>woH9yceyGVh;mmh|R^1u}(@H zlUOYx>nJDnf`ib zDA#fy^a^wX#bM`%D!sx;TrwG6eX)bRptrrC0q7M0F}J3+0WLrjF)ws-VQF+}W_c}i Qb1g6~F)lH;=k@_PeSWYcWpq`d&{>5I, +>() => trait( + abstract(), + + Super => class InstantiableZodSchemaObject extends Super { + static create( + ...[values, params]: NewZodSchemaInstanceArgs< + NewZodSchemaInstanceInput + > + ) { + return new this( + this.schema.parse({ ...this.defaultValues, ...values }, params) + ) + } + + static async createPromise( + ...[values, params]: NewZodSchemaInstanceArgs< + NewZodSchemaInstanceInput + > + ) { + return new this( + await this.schema.parseAsync({ ...this.defaultValues, ...values }, params) + ) + } + + static createEffect( + ...[values, params]: NewZodSchemaInstanceArgs< + NewZodSchemaInstanceInput + > + ) { + return pipe( + parseZodTypeEffect( + this.schema, + { ...this.defaultValues, ...values }, + params, + ), + + Effect.map(values => new this(values)), + ) + } + }, +) export function ZodSchemaClassOf<