cogsbox-shape 0.5.64 → 0.5.66

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,77 +0,0 @@
1
- import { z } from "zod";
2
- import { createSchema, hasMany, reference, shape, } from "../schema.js";
3
- export const petSchema = {
4
- _tableName: "pets",
5
- id: shape
6
- .sql({ type: "int", pk: true })
7
- .initialState(() => "uuidexample")
8
- .client(({ sql, initialState }) => z.union([sql, initialState]))
9
- .validation(z.string())
10
- .transform({
11
- toClient: (dbValue) => dbValue,
12
- toDb: (clientValue) => Number(clientValue),
13
- }),
14
- name: shape.sql({ type: "varchar", length: 255 }),
15
- userId: reference(() => userSchema.id),
16
- fluffynessScale: shape
17
- .sql({ type: "text" })
18
- .client(({ sql }) => z.array(z.enum(["bald", "fuzzy", "fluffy", "poof"])))
19
- .transform({
20
- toClient: (value) => value.split(",").filter(Boolean),
21
- toDb: (value) => value.join(","),
22
- }),
23
- favourite: shape
24
- .sql({ type: "int" })
25
- .client(({ sql }) => z.boolean())
26
- .transform({
27
- toClient: (dbValue) => dbValue === 1,
28
- toDb: (clientValue) => (clientValue ? 1 : 0),
29
- }),
30
- };
31
- export const userSchema = {
32
- //The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.
33
- _tableName: "users",
34
- id: shape.sql({ type: "int", pk: true }),
35
- firstname: shape
36
- .sql({ type: "varchar", length: 255 })
37
- .initialState(() => "test")
38
- .validation(({ sql }) => sql.min(1)),
39
- surname: shape
40
- .sql({ type: "varchar", length: 255 })
41
- .validation(({ sql }) => sql.min(1)),
42
- email: shape
43
- .sql({ type: "varchar", length: 255 })
44
- .validation(({ sql }) => sql.email()),
45
- pets: shape
46
- .hasMany({
47
- fromKey: "id",
48
- toKey: () => petSchema.userId,
49
- schema: () => petSchema,
50
- defaultCount: 1,
51
- })
52
- .validation(({ sql }) => sql.min(1)),
53
- };
54
- const testPets = {
55
- _tableName: "users",
56
- id: shape
57
- .sql({ type: "int", pk: true })
58
- .initialState(z.string().uuid(), () => "sdasdsad")
59
- .client(({ sql, initialState }) => z.union([sql, initialState]))
60
- .validation(({ sql }) => sql)
61
- .transform({
62
- toClient: (dbValue) => dbValue,
63
- toDb: (clientValue) => Number(clientValue),
64
- }),
65
- email: shape
66
- .sql({ type: "varchar", length: 255 })
67
- .validation(({ sql }) => sql),
68
- createdAt: shape
69
- .sql({ type: "datetime" })
70
- .client(({ sql }) => z.string())
71
- .validation(({ sql }) => sql.optional())
72
- .transform({
73
- toClient: (date) => date.toISOString(),
74
- toDb: (str) => new Date(str),
75
- }),
76
- };
77
- const { sqlSchema, clientSchema: clSchema, defaultValues, validationSchema, } = createSchema(userSchema);