From 997ea4a95b4c062aaf73600ac576e39bcaaf2c77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Sat, 24 Feb 2024 23:48:09 +0100 Subject: [PATCH] ZodSchemaClassBuilder --- .../ZodSchemaClassBuilder.ts} | 15 +++-- src/tests.ts | 56 +++++++++---------- 2 files changed, 36 insertions(+), 35 deletions(-) rename src/{ZodSchemaClass.ts => builders/ZodSchemaClassBuilder.ts} (92%) diff --git a/src/ZodSchemaClass.ts b/src/builders/ZodSchemaClassBuilder.ts similarity index 92% rename from src/ZodSchemaClass.ts rename to src/builders/ZodSchemaClassBuilder.ts index bb9e065..75b85f1 100644 --- a/src/ZodSchemaClass.ts +++ b/src/builders/ZodSchemaClassBuilder.ts @@ -2,12 +2,12 @@ import { Trait, TraitExpression, TraitExpressionBuilder } from "@thilawyn/traiti import { AbstractClass } from "type-fest" import { JsonifiableObject } from "type-fest/source/jsonifiable" import { z } from "zod" -import { ZodSchemaAbstractClass } from "./shapes/ZodSchemaClass" -import { DejsonifiableZodSchemaObject } from "./traits/DejsonifiableZodSchemaObject" -import { ExtendableZodSchemaObject } from "./traits/ExtendableZodSchemaObject" -import { InstantiableZodSchemaObject } from "./traits/InstantiableZodSchemaObject" -import { JsonifiableZodSchemaObject } from "./traits/JsonifiableZodSchemaObject" -import { StaticMembers } from "./util" +import { ZodSchemaAbstractClass } from "../shapes/ZodSchemaClass" +import { DejsonifiableZodSchemaObject } from "../traits/DejsonifiableZodSchemaObject" +import { ExtendableZodSchemaObject } from "../traits/ExtendableZodSchemaObject" +import { InstantiableZodSchemaObject } from "../traits/InstantiableZodSchemaObject" +import { JsonifiableZodSchemaObject } from "../traits/JsonifiableZodSchemaObject" +import { StaticMembers } from "../util" export class ZodSchemaClassBuilder< @@ -176,3 +176,6 @@ export interface ZodSchemaClassBuilder< TraitExpressionBuilder.ExpressesFirstReturnTypeTraits > } + + +export const zodSchemaClass = new ZodSchemaClassBuilder(TraitExpression.NullSuperclass, []) diff --git a/src/tests.ts b/src/tests.ts index ac09859..8183320 100644 --- a/src/tests.ts +++ b/src/tests.ts @@ -1,13 +1,11 @@ -import { Implements, TraitExpression } from "@thilawyn/traitify-ts" +import { Implements } from "@thilawyn/traitify-ts" import { z } from "zod" -import { ZodSchemaClassBuilder } from "./ZodSchemaClass" +import { zodSchemaClass } from "./builders/ZodSchemaClassBuilder" import { dejsonify, jsonify } from "./schema/jsonify" import { ObservableZodSchemaObject } from "./traits/ObservableZodSchemaObject" -import { AbstractClass, Class } from "type-fest" -const exp = new ZodSchemaClassBuilder(TraitExpression.NullSuperclass, []) - .extends(class {}) +const exp = zodSchemaClass .schema({ schema: z.object({ /** User ID */ @@ -52,32 +50,32 @@ const subInst = await SubTest.createPromise({ name: "", prout: "" }) // console.log(subInst) -class Box { - declare ["constructor"]: typeof Box - constructor(public value: T) {} +// class Box { +// declare ["constructor"]: typeof Box +// constructor(public value: T) {} - otherMethod() { - return "prout" as const - } +// otherMethod() { +// return "prout" as const +// } - newBox< - C extends Class>, - I extends Box, - T, - >( - // this: Omit, "constructor"> & { ["constructor"]: Class } - this: { ["constructor"]: C | Class> }, - value: T, - ) { - // this.otherMethod() - return new this.constructor(value) - } -} +// newBox< +// C extends Class>, +// I extends Box, +// T, +// >( +// // this: Omit, "constructor"> & { ["constructor"]: Class } +// this: { ["constructor"]: C | Class> }, +// value: T, +// ) { +// // this.otherMethod() +// return new this.constructor(value) +// } +// } -class UnrelatedClass {} +// class UnrelatedClass {} -class SuperBox extends Box { - declare ["constructor"]: typeof SuperBox -} +// class SuperBox extends Box { +// declare ["constructor"]: typeof SuperBox +// } -const value = new SuperBox(69).newBox(69) +// const value = new SuperBox(69).newBox(69)