cogsbox-shape 0.5.205 → 0.5.206

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.
@@ -6,11 +6,15 @@ describe("refine runtime behavior", () => {
6
6
  const rules = schema({
7
7
  _tableName: "rules",
8
8
  id: s.sqlite({ type: "int", pk: true }),
9
- min: s.sqlite({ type: "int", nullable: true }).clientInput({ value: null, schema: z.number().nullable() }),
10
- max: s.sqlite({ type: "int", nullable: true }).clientInput({ value: null, schema: z.number().nullable() }),
11
- label: s.sqlite({ type: "varchar" }).clientInput({ value: "" }),
9
+ min: s
10
+ .sqlite({ type: "int", nullable: true })
11
+ .client({ value: null, schema: z.number().nullable() }),
12
+ max: s
13
+ .sqlite({ type: "int", nullable: true })
14
+ .client({ value: null, schema: z.number().nullable() }),
15
+ label: s.sqlite({ type: "varchar" }).client({ value: "" }),
12
16
  }).refine((r) => [
13
- r(["clientInput", "client"], (row) => {
17
+ r(["client", "clientCheck"], (row) => {
14
18
  if (row.min !== null && row.max !== null && row.min >= row.max) {
15
19
  return { path: ["max"], message: "Max must be > min" };
16
20
  }
@@ -28,19 +32,34 @@ describe("refine runtime behavior", () => {
28
32
  ]);
29
33
  return createSchemaBox({ rules }, { rules: {} });
30
34
  }
31
- it("schemas.clientInput catches client refine", () => {
35
+ it("schemas.client catches client refine", () => {
32
36
  const box = makeRefinedBox();
33
- const good = box.rules.schemas.clientInput.safeParse({ id: 1, min: 1, max: 10, label: "x" });
37
+ const good = box.rules.schemas.client.safeParse({
38
+ id: 1,
39
+ min: 1,
40
+ max: 10,
41
+ label: "x",
42
+ });
34
43
  expect(good.success).toBe(true);
35
- const bad = box.rules.schemas.clientInput.safeParse({ id: 1, min: 10, max: 1, label: "x" });
44
+ const bad = box.rules.schemas.client.safeParse({
45
+ id: 1,
46
+ min: 10,
47
+ max: 1,
48
+ label: "x",
49
+ });
36
50
  expect(bad.success).toBe(false);
37
51
  if (!bad.success) {
38
52
  expect(bad.error.issues[0].message).toBe("Max must be > min");
39
53
  }
40
54
  });
41
- it("schemas.client catches client refine", () => {
55
+ it("schemas.clientChecked catches client refine", () => {
42
56
  const box = makeRefinedBox();
43
- const bad = box.rules.schemas.client.safeParse({ id: 1, min: 10, max: 1, label: "x" });
57
+ const bad = box.rules.schemas.clientChecked.safeParse({
58
+ id: 1,
59
+ min: 10,
60
+ max: 1,
61
+ label: "x",
62
+ });
44
63
  expect(bad.success).toBe(false);
45
64
  if (!bad.success) {
46
65
  expect(bad.error.issues[0].message).toBe("Max must be > min");
@@ -48,7 +67,12 @@ describe("refine runtime behavior", () => {
48
67
  });
49
68
  it("schemas.server catches server refine", () => {
50
69
  const box = makeRefinedBox();
51
- const bad = box.rules.schemas.server.safeParse({ id: 1, min: 1, max: 10, label: "" });
70
+ const bad = box.rules.schemas.server.safeParse({
71
+ id: 1,
72
+ min: 1,
73
+ max: 10,
74
+ label: "",
75
+ });
52
76
  expect(bad.success).toBe(false);
53
77
  if (!bad.success) {
54
78
  expect(bad.error.issues[0].message).toBe("Label required");
@@ -56,7 +80,12 @@ describe("refine runtime behavior", () => {
56
80
  });
57
81
  it("schemas.sql catches server refine", () => {
58
82
  const box = makeRefinedBox();
59
- const bad = box.rules.schemas.sql.safeParse({ id: 1, min: 1, max: 10, label: "" });
83
+ const bad = box.rules.schemas.sql.safeParse({
84
+ id: 1,
85
+ min: 1,
86
+ max: 10,
87
+ label: "",
88
+ });
60
89
  expect(bad.success).toBe(false);
61
90
  if (!bad.success) {
62
91
  expect(bad.error.issues[0].message).toBe("Label required");
@@ -78,21 +107,31 @@ describe("refine runtime behavior", () => {
78
107
  const rules = schema({
79
108
  _tableName: "rules",
80
109
  id: s.sqlite({ type: "int", pk: true }),
81
- min: s.sqlite({ type: "int", nullable: true }).clientInput({ value: null, schema: z.number().nullable() }),
82
- max: s.sqlite({ type: "int", nullable: true }).clientInput({ value: null, schema: z.number().nullable() }),
110
+ min: s
111
+ .sqlite({ type: "int", nullable: true })
112
+ .client({ value: null, schema: z.number().nullable() }),
113
+ max: s
114
+ .sqlite({ type: "int", nullable: true })
115
+ .client({ value: null, schema: z.number().nullable() }),
83
116
  });
84
117
  const box = createSchemaBox({ rules }, { rules: {} });
85
- const good = box.rules.schemas.clientInput.safeParse({ id: 1, min: 10, max: 1 });
118
+ const good = box.rules.schemas.client.safeParse({
119
+ id: 1,
120
+ min: 10,
121
+ max: 1,
122
+ });
86
123
  expect(good.success).toBe(true);
87
124
  });
88
125
  it("view keeps leaf refines and prefixes issue paths", () => {
89
126
  const rules = schema({
90
127
  _tableName: "rules",
91
128
  id: s.sqlite({ type: "int", pk: true }),
92
- min: s.sqlite({ type: "int" }).clientInput({ value: 0 }),
93
- max: s.sqlite({ type: "int" }).clientInput({ value: 0 }),
129
+ min: s
130
+ .sqlite({ type: "int", field: "minField" })
131
+ .client({ value: 0 }),
132
+ max: s.sqlite({ type: "int" }).client({ value: 0 }),
94
133
  }).refine((r) => [
95
- r("client", (row) => row.min >= row.max
134
+ r("clientCheck", (row) => row.min >= row.max
96
135
  ? { path: ["max"], message: "Max must be > min" }
97
136
  : undefined, ["min", "max"]),
98
137
  ]);
@@ -105,7 +144,7 @@ describe("refine runtime behavior", () => {
105
144
  journal: { rules: { fromKey: "id", toKey: rules.id } },
106
145
  });
107
146
  const view = box.journal.createView({ rules: true });
108
- const bad = view.schemas.client.safeParse({
147
+ const bad = view.schemas.clientChecked.safeParse({
109
148
  id: 1,
110
149
  rules: { id: 1, min: 10, max: 1 },
111
150
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cogsbox-shape",
3
- "version": "0.5.205",
3
+ "version": "0.5.206",
4
4
  "description": "A TypeScript library for creating type-safe database schemas with Zod validation, SQL type definitions, and automatic client/server transformations. Unifies client, server, and database types through a single schema definition, with built-in support for relationships and serialization.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",