cogsbox-shape 0.5.32 → 0.5.34

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,29 +1,10 @@
1
1
  import { z } from "zod";
2
2
  import { createSchema, hasMany, reference, shape, } from "../schema.js";
3
- export const userSchema = {
4
- _tableName: "users",
5
- id: shape.sql({ type: "int", pk: true }),
6
- firstname: shape
7
- .sql({ type: "varchar", length: 255 })
8
- .validation(({ sql }) => sql.min(1)),
9
- surname: shape
10
- .sql({ type: "varchar", length: 255 })
11
- .validation(({ sql }) => sql.min(1)),
12
- email: shape
13
- .sql({ type: "varchar", length: 255 })
14
- .validation(({ sql }) => sql.email()),
15
- pets: hasMany({
16
- fromKey: "id",
17
- toKey: () => petSchema.userId,
18
- schema: () => petSchema,
19
- defaultCount: 1,
20
- }),
21
- };
22
3
  export const petSchema = {
23
4
  _tableName: "pets",
24
5
  id: shape
25
6
  .sql({ type: "int", pk: true })
26
- .initialState(z.string(), () => "uuidexample")
7
+ .initialState(() => "uuidexample")
27
8
  .client(({ sql, initialState }) => z.union([sql, initialState]))
28
9
  .validation(z.string())
29
10
  .transform({
@@ -31,7 +12,7 @@ export const petSchema = {
31
12
  toDb: (clientValue) => Number(clientValue),
32
13
  }),
33
14
  name: shape.sql({ type: "varchar", length: 255 }),
34
- userId: reference({ to: () => userSchema.id, field: z.number() }),
15
+ userId: reference(() => userSchema.id),
35
16
  fluffynessScale: shape
36
17
  .sql({ type: "text" })
37
18
  .client(({ sql }) => z.array(z.enum(["bald", "fuzzy", "fluffy", "poof"])))
@@ -49,6 +30,26 @@ export const petSchema = {
49
30
  };
50
31
  // export const { dbSchema, clientSchema, initialValues, serialized } =
51
32
  // createSchema(userSchema);
33
+ export const userSchema = {
34
+ _tableName: "users",
35
+ id: shape.sql({ type: "int", pk: true }),
36
+ firstname: shape
37
+ .sql({ type: "varchar", length: 255 })
38
+ .initialState(() => "test")
39
+ .validation(({ sql }) => sql.min(1)),
40
+ surname: shape
41
+ .sql({ type: "varchar", length: 255 })
42
+ .validation(({ sql }) => sql.min(1)),
43
+ email: shape
44
+ .sql({ type: "varchar", length: 255 })
45
+ .validation(({ sql }) => sql.email()),
46
+ pets: hasMany({
47
+ fromKey: "id",
48
+ toKey: () => petSchema.userId,
49
+ schema: () => petSchema,
50
+ defaultCount: 1,
51
+ }),
52
+ };
52
53
  const testPets = {
53
54
  _tableName: "users",
54
55
  id: shape