0.1.0 #1

Merged
Thilawyn merged 24 commits from next into master 2024-01-05 00:39:33 +01:00
2 changed files with 62 additions and 11 deletions
Showing only changes of commit 176057d77a - Show all commits

View File

@@ -1,11 +0,0 @@
import { trait } from "@thilawyn/thilatrait"
export const JsonifiableSchemable = () =>
trait(Parent => {
abstract class JsonifiableSchemable extends Parent {
}
return JsonifiableSchemable
})

View 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 {
}
}