0.1.2 #3
@@ -7,10 +7,10 @@ export const jsonify = {
|
||||
bigint: jsonifyBigIntSchema,
|
||||
date: jsonifyDateSchema,
|
||||
decimal: jsonifyDecimalSchema,
|
||||
}
|
||||
} as const
|
||||
|
||||
export const dejsonify = {
|
||||
bigint: dejsonifyBigIntSchema,
|
||||
date: dejsonifyDateSchema,
|
||||
decimal: dejsonifyDecimalSchema,
|
||||
}
|
||||
} as const
|
||||
|
||||
37
src/tests.ts
37
src/tests.ts
@@ -5,11 +5,13 @@ import { dejsonify, jsonify } from "./schema/jsonify"
|
||||
import { ObservableZodSchemaObject } from "./traits/ObservableZodSchemaObject"
|
||||
|
||||
|
||||
const newTestExp = new ZodSchemaClassBuilder(TraitExpression.NullSuperclass, [])
|
||||
const exp = new ZodSchemaClassBuilder(TraitExpression.NullSuperclass, [])
|
||||
.schema({
|
||||
schema: z.object({
|
||||
/** Object ID */
|
||||
/** User ID */
|
||||
id: z.bigint(),
|
||||
|
||||
/** Username */
|
||||
name: z.string(),
|
||||
}),
|
||||
|
||||
@@ -27,40 +29,21 @@ const newTestExp = new ZodSchemaClassBuilder(TraitExpression.NullSuperclass, [])
|
||||
.expresses(ObservableZodSchemaObject)
|
||||
.build()
|
||||
|
||||
@newTestExp.staticImplements
|
||||
class Test extends newTestExp.extends implements Implements<typeof newTestExp> {}
|
||||
@exp.staticImplements
|
||||
class User extends exp.extends implements Implements<typeof exp> {}
|
||||
|
||||
Test.defaultValues
|
||||
const inst = Test.create({ id: 1n, name: "" })
|
||||
User.defaultValues
|
||||
const inst = User.create({ id: 1n, name: "" })
|
||||
console.log(inst)
|
||||
Test.dejsonify({ id: 1n })
|
||||
|
||||
|
||||
class SubTest extends Test.extend({
|
||||
class SubTest extends User.extend({
|
||||
schema: ({ schema }) => schema.extend({
|
||||
prout: z.string()
|
||||
}),
|
||||
|
||||
defaultValues: defaultValues => ({
|
||||
...defaultValues
|
||||
}),
|
||||
defaultValues: v => v,
|
||||
}) {}
|
||||
|
||||
const subInst = await SubTest.createPromise({ name: "", prout: "" })
|
||||
console.log(subInst)
|
||||
|
||||
// class ChildTest extends Test {}
|
||||
|
||||
// ChildTest.instantiate({ name: "" })
|
||||
|
||||
const testSchema = { schema: Test.schema }
|
||||
|
||||
declare const testGenericSchema: {
|
||||
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, object, object>
|
||||
}
|
||||
|
||||
type U<T> = T
|
||||
|
||||
interface ExtendTest extends U<typeof testSchema> {
|
||||
schema: z.ZodObject<any, any, any, any, any>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user