cogsbox-shape 0.5.160 → 0.5.161

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.
Files changed (2) hide show
  1. package/dist/schema.js +16 -7
  2. package/package.json +1 -1
package/dist/schema.js CHANGED
@@ -171,16 +171,25 @@ function createBuilder(config) {
171
171
  }
172
172
  const newCompletedStages = new Set(completedStages);
173
173
  newCompletedStages.add("new");
174
- // Create union of the SQL type and the new client type
175
- const hasProvidedSchema = !!schemaOrModifier;
176
- const clientAndServerSchema = hasProvidedSchema
177
- ? finalSchema
178
- : z.union([config.sqlZod, finalSchema]);
179
174
  const newConfig = { ...config.sqlConfig };
180
175
  if (clientPk) {
181
- // Add our metadata flag to the config
182
176
  newConfig.isClientPk = true;
183
177
  }
178
+ // When clientPk is true, ALWAYS union the SQL type with the client type
179
+ // because records can be either DB-sourced (number) or client-created (string)
180
+ let clientAndServerSchema;
181
+ if (clientPk) {
182
+ // Always union for clientPk fields
183
+ clientAndServerSchema = z.union([config.sqlZod, finalSchema]);
184
+ }
185
+ else if (schemaOrModifier) {
186
+ // Schema provided without clientPk — use as-is
187
+ clientAndServerSchema = finalSchema;
188
+ }
189
+ else {
190
+ // No schema provided — union with SQL type
191
+ clientAndServerSchema = z.union([config.sqlZod, finalSchema]);
192
+ }
184
193
  return createBuilder({
185
194
  ...config,
186
195
  stage: "new",
@@ -188,7 +197,7 @@ function createBuilder(config) {
188
197
  newZod: finalSchema,
189
198
  initialValue: actualValue,
190
199
  clientZod: clientAndServerSchema,
191
- validationZod: clientAndServerSchema, // Our internal name
200
+ validationZod: clientAndServerSchema,
192
201
  completedStages: newCompletedStages,
193
202
  });
194
203
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cogsbox-shape",
3
- "version": "0.5.160",
3
+ "version": "0.5.161",
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",