ZodSchemaClassBuilder
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Julien Valverdé
2024-02-24 23:48:09 +01:00
parent af279116bc
commit 997ea4a95b
2 changed files with 36 additions and 35 deletions

View File

@@ -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<Traits, T>
>
}
export const zodSchemaClass = new ZodSchemaClassBuilder(TraitExpression.NullSuperclass, [])

View File

@@ -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<T> {
declare ["constructor"]: typeof Box
constructor(public value: T) {}
// class Box<T> {
// declare ["constructor"]: typeof Box
// constructor(public value: T) {}
otherMethod() {
return "prout" as const
}
// otherMethod() {
// return "prout" as const
// }
newBox<
C extends Class<I, ConstructorParameters<typeof Box>>,
I extends Box<any>,
T,
>(
// this: Omit<BaseClass<T>, "constructor"> & { ["constructor"]: Class<I> }
this: { ["constructor"]: C | Class<I, ConstructorParameters<typeof Box>> },
value: T,
) {
// this.otherMethod()
return new this.constructor(value)
}
}
// newBox<
// C extends Class<I, ConstructorParameters<typeof Box>>,
// I extends Box<any>,
// T,
// >(
// // this: Omit<BaseClass<T>, "constructor"> & { ["constructor"]: Class<I> }
// this: { ["constructor"]: C | Class<I, ConstructorParameters<typeof Box>> },
// value: T,
// ) {
// // this.otherMethod()
// return new this.constructor(value)
// }
// }
class UnrelatedClass {}
// class UnrelatedClass {}
class SuperBox<T> extends Box<T> {
declare ["constructor"]: typeof SuperBox
}
// class SuperBox<T> extends Box<T> {
// declare ["constructor"]: typeof SuperBox
// }
const value = new SuperBox(69).newBox(69)
// const value = new SuperBox(69).newBox(69)