cogsbox-shape 0.5.88 → 0.5.90

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 +23 -7
  2. package/package.json +1 -1
package/dist/schema.js CHANGED
@@ -163,13 +163,29 @@ function createBuilder(config) {
163
163
  ? schemaOrDefault({ sql: config.sqlZod })
164
164
  : schemaOrDefault
165
165
  : config.sqlZod; // If only a primitive is passed, the "new" schema is still the SQL one.
166
- const finalDefaultValue = hasSchemaArg
167
- ? isFunction(defaultValue)
168
- ? defaultValue() // If it's a function, call it
169
- : defaultValue // If it's a direct value, use it as-is
170
- : isFunction(schemaOrDefault)
171
- ? schemaOrDefault()
172
- : schemaOrDefault;
166
+ let finalDefaultValue;
167
+ if (hasSchemaArg) {
168
+ // Handles two arguments: .initialState(schema, defaultValue)
169
+ finalDefaultValue = isFunction(defaultValue)
170
+ ? defaultValue()
171
+ : defaultValue;
172
+ }
173
+ else {
174
+ // Handles one argument: .initialState(z.email()) OR .initialState(() => uuid())
175
+ const singleArg = schemaOrDefault;
176
+ if (singleArg &&
177
+ typeof singleArg === "object" &&
178
+ singleArg._def) {
179
+ // THIS IS THE FIX: If it's a Zod schema, INFER the value.
180
+ finalDefaultValue = inferDefaultFromZod(singleArg, config.sqlConfig);
181
+ }
182
+ else {
183
+ // Otherwise, it's a function or primitive value.
184
+ finalDefaultValue = isFunction(singleArg)
185
+ ? singleArg({ sql: config.sqlZod })
186
+ : singleArg;
187
+ }
188
+ }
173
189
  const newCompletedStages = new Set(completedStages);
174
190
  newCompletedStages.add("new");
175
191
  // ---- THIS IS THE RUNTIME FIX THAT MATCHES YOUR INTERFACE ----
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cogsbox-shape",
3
- "version": "0.5.88",
3
+ "version": "0.5.90",
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",