0.1.0 #1
@@ -1,11 +0,0 @@
|
|||||||
import { trait } from "@thilawyn/thilatrait"
|
|
||||||
|
|
||||||
|
|
||||||
export const JsonifiableSchemable = () =>
|
|
||||||
trait(Parent => {
|
|
||||||
abstract class JsonifiableSchemable extends Parent {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return JsonifiableSchemable
|
|
||||||
})
|
|
||||||
62
src/makeJsonifiableSchemableClass.ts
Normal file
62
src/makeJsonifiableSchemableClass.ts
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
import { JsonifiableObject } from "type-fest/source/jsonifiable"
|
||||||
|
import { z } from "zod"
|
||||||
|
import { SchemableClass, SchemableConfig } from "."
|
||||||
|
|
||||||
|
|
||||||
|
export function makeJsonifiableSchemableClass<
|
||||||
|
C extends SchemableClass<$Config>,
|
||||||
|
$Config extends SchemableConfig,
|
||||||
|
|
||||||
|
JsonifiedValues extends JsonifiableObject,
|
||||||
|
|
||||||
|
JsonifySchemaT extends z.ZodRawShape,
|
||||||
|
JsonifySchemaUnknownKeys extends z.UnknownKeysParam,
|
||||||
|
JsonifySchemaCatchall extends z.ZodTypeAny,
|
||||||
|
|
||||||
|
DejsonifySchemaT extends z.ZodRawShape,
|
||||||
|
DejsonifySchemaUnknownKeys extends z.UnknownKeysParam,
|
||||||
|
DejsonifySchemaCatchall extends z.ZodTypeAny,
|
||||||
|
>(
|
||||||
|
class_: C | SchemableClass<$Config>,
|
||||||
|
|
||||||
|
props: {
|
||||||
|
jsonifySchema: (props: {
|
||||||
|
schema: $Config["schema"]
|
||||||
|
s: $Config["schema"]["shape"]
|
||||||
|
}) => z.ZodObject<
|
||||||
|
JsonifySchemaT,
|
||||||
|
JsonifySchemaUnknownKeys,
|
||||||
|
JsonifySchemaCatchall,
|
||||||
|
JsonifiedValues,
|
||||||
|
$Config["values"]
|
||||||
|
>
|
||||||
|
|
||||||
|
dejsonifySchema: (props: {
|
||||||
|
schema: $Config["schema"]
|
||||||
|
s: $Config["schema"]["shape"]
|
||||||
|
}) => z.ZodObject<
|
||||||
|
DejsonifySchemaT,
|
||||||
|
DejsonifySchemaUnknownKeys,
|
||||||
|
DejsonifySchemaCatchall,
|
||||||
|
$Config["values"],
|
||||||
|
JsonifiedValues
|
||||||
|
>
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
|
||||||
|
const jsonifySchema = props.jsonifySchema({
|
||||||
|
schema: class_.schema,
|
||||||
|
s: class_.schema.shape,
|
||||||
|
})
|
||||||
|
|
||||||
|
const dejsonifySchema = props.dejsonifySchema({
|
||||||
|
schema: class_.schema,
|
||||||
|
s: class_.schema.shape,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
return class JsonifiableSchemableObject {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user