import { Implements } from "@thilawyn/traitify-ts" import { z } from "zod" import { zodSchemaClass } from "./builders/ZodSchemaClassBuilder" import { dejsonify, jsonify } from "./schema/jsonify" import { MobXObservableZodSchemaObject } from "./traits/MobXObservableZodSchemaObject" const exp = zodSchemaClass .schema({ schema: z.object({ /** User ID */ id: z.bigint(), /** Username */ name: z.string(), }), schemaWithDefaultValues: s => s.extend({ id: s.shape.id.default(-1n), }), }) .jsonifiable({ jsonifySchema: s => s.extend({ id: jsonify.bigint(s.shape.id) }), dejsonifySchema: s => s.extend({ id: dejsonify.bigint(s.shape.id) }), }) .expresses(MobXObservableZodSchemaObject) .build() @exp.staticImplements class User extends exp.extends implements Implements {} const test = User.schema.extend({ prout: z.string() }).merge( User.schemaWithDefaultValues ) const inst = User.create({ id: 1n, name: "" }) const instEffect = User.createEffect({ id: 1n, name: "" }) // console.log(inst) const jsonifiedUser = await inst.jsonifyPromise() const AdminUserProto = User.extend() .schema({ schema: s => s.extend({ name: z.literal("Admin"), prout: z.string(), }), defaultValues: v => ({ ...v, name: "Admin" as const }), }) .jsonifiable({ jsonifySchema: (s, json) => json.extend({ prout: s.shape.prout }) }) class AdminUser extends AdminUserProto.toClass() {} const subInst = await AdminUser.createPromise({ id: 2n, prout: "" }) console.log(subInst) // class Box { // declare ["constructor"]: typeof Box // constructor(public value: T) {} // 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) // } // } // class UnrelatedClass {} // class SuperBox extends Box { // declare ["constructor"]: typeof SuperBox // } // const value = new SuperBox(69).newBox(69)