This commit is contained in:
@@ -7,10 +7,10 @@ export const jsonify = {
|
|||||||
bigint: jsonifyBigIntSchema,
|
bigint: jsonifyBigIntSchema,
|
||||||
date: jsonifyDateSchema,
|
date: jsonifyDateSchema,
|
||||||
decimal: jsonifyDecimalSchema,
|
decimal: jsonifyDecimalSchema,
|
||||||
}
|
} as const
|
||||||
|
|
||||||
export const dejsonify = {
|
export const dejsonify = {
|
||||||
bigint: dejsonifyBigIntSchema,
|
bigint: dejsonifyBigIntSchema,
|
||||||
date: dejsonifyDateSchema,
|
date: dejsonifyDateSchema,
|
||||||
decimal: dejsonifyDecimalSchema,
|
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"
|
import { ObservableZodSchemaObject } from "./traits/ObservableZodSchemaObject"
|
||||||
|
|
||||||
|
|
||||||
const newTestExp = new ZodSchemaClassBuilder(TraitExpression.NullSuperclass, [])
|
const exp = new ZodSchemaClassBuilder(TraitExpression.NullSuperclass, [])
|
||||||
.schema({
|
.schema({
|
||||||
schema: z.object({
|
schema: z.object({
|
||||||
/** Object ID */
|
/** User ID */
|
||||||
id: z.bigint(),
|
id: z.bigint(),
|
||||||
|
|
||||||
|
/** Username */
|
||||||
name: z.string(),
|
name: z.string(),
|
||||||
}),
|
}),
|
||||||
|
|
||||||
@@ -27,40 +29,21 @@ const newTestExp = new ZodSchemaClassBuilder(TraitExpression.NullSuperclass, [])
|
|||||||
.expresses(ObservableZodSchemaObject)
|
.expresses(ObservableZodSchemaObject)
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
@newTestExp.staticImplements
|
@exp.staticImplements
|
||||||
class Test extends newTestExp.extends implements Implements<typeof newTestExp> {}
|
class User extends exp.extends implements Implements<typeof exp> {}
|
||||||
|
|
||||||
Test.defaultValues
|
User.defaultValues
|
||||||
const inst = Test.create({ id: 1n, name: "" })
|
const inst = User.create({ id: 1n, name: "" })
|
||||||
console.log(inst)
|
console.log(inst)
|
||||||
Test.dejsonify({ id: 1n })
|
|
||||||
|
|
||||||
|
|
||||||
class SubTest extends Test.extend({
|
class SubTest extends User.extend({
|
||||||
schema: ({ schema }) => schema.extend({
|
schema: ({ schema }) => schema.extend({
|
||||||
prout: z.string()
|
prout: z.string()
|
||||||
}),
|
}),
|
||||||
|
|
||||||
defaultValues: defaultValues => ({
|
defaultValues: v => v,
|
||||||
...defaultValues
|
|
||||||
}),
|
|
||||||
}) {}
|
}) {}
|
||||||
|
|
||||||
const subInst = await SubTest.createPromise({ name: "", prout: "" })
|
const subInst = await SubTest.createPromise({ name: "", prout: "" })
|
||||||
console.log(subInst)
|
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