cogsbox-shape 0.5.103 → 0.5.104
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.
- package/README.md +0 -1
- package/dist/schema.d.ts +13 -8
- package/dist/schema.js +0 -11
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/schema.d.ts
CHANGED
|
@@ -193,14 +193,19 @@ type SchemaWithPlaceholders = {
|
|
|
193
193
|
[key: string]: any | PlaceholderReference | PlaceholderRelation<any>;
|
|
194
194
|
};
|
|
195
195
|
type ResolutionConfig<S extends Record<string, SchemaWithPlaceholders>> = {
|
|
196
|
-
[TableName in keyof S]
|
|
197
|
-
[FieldName in keyof S[TableName] as S[TableName][FieldName] extends PlaceholderReference | PlaceholderRelation<any> ? FieldName : never]
|
|
196
|
+
[TableName in keyof S]?: {
|
|
197
|
+
[FieldName in keyof S[TableName] as S[TableName][FieldName] extends PlaceholderReference | PlaceholderRelation<any> ? FieldName : never]?: S[TableName][FieldName] extends PlaceholderReference ? any : S[TableName][FieldName] extends PlaceholderRelation<any> ? {
|
|
198
198
|
fromKey: string;
|
|
199
199
|
toKey: any;
|
|
200
200
|
defaultCount?: number;
|
|
201
201
|
} : never;
|
|
202
202
|
};
|
|
203
203
|
};
|
|
204
|
+
type ValidateResolution<T, S extends Record<string, SchemaWithPlaceholders>> = {
|
|
205
|
+
[K in keyof T]: K extends keyof S ? T[K] extends object ? {
|
|
206
|
+
[F in keyof T[K]]: F extends keyof NonNullable<ResolutionConfig<S>[K]> ? T[K][F] : never;
|
|
207
|
+
} : never : never;
|
|
208
|
+
};
|
|
204
209
|
type ResolveField<Field, Resolution, AllSchemas extends Record<string, any>> = Field extends PlaceholderReference ? Resolution : Field extends PlaceholderRelation<infer RelType> ? Resolution extends {
|
|
205
210
|
toKey: infer ToKey;
|
|
206
211
|
} ? ToKey extends {
|
|
@@ -219,18 +224,18 @@ type ResolveSchema<Schema extends SchemaWithPlaceholders, Resolutions extends Re
|
|
|
219
224
|
};
|
|
220
225
|
type ResolvedRegistryWithSchemas<S extends Record<string, SchemaWithPlaceholders>, R extends ResolutionConfig<S>> = {
|
|
221
226
|
[K in keyof S]: {
|
|
222
|
-
rawSchema: ResolveSchema<S[K], K extends keyof R ? R[K] : {}, S>;
|
|
227
|
+
rawSchema: ResolveSchema<S[K], K extends keyof R ? (R[K] extends object ? R[K] : {}) : {}, S>;
|
|
223
228
|
zodSchemas: {
|
|
224
|
-
sqlSchema: z.ZodObject<Prettify<DeriveSchemaByKey<ResolveSchema<S[K], K extends keyof R ? R[K] : {}, S>, "zodSqlSchema">>>;
|
|
225
|
-
clientSchema: z.ZodObject<Prettify<DeriveSchemaByKey<ResolveSchema<S[K], K extends keyof R ? R[K] : {}, S>, "zodClientSchema">>>;
|
|
226
|
-
validationSchema: z.ZodObject<Prettify<DeriveSchemaByKey<ResolveSchema<S[K], K extends keyof R ? R[K] : {}, S>, "zodValidationSchema">>>;
|
|
227
|
-
defaultValues: Prettify<DeriveDefaults<ResolveSchema<S[K], K extends keyof R ? R[K] : {}, S>>>;
|
|
229
|
+
sqlSchema: z.ZodObject<Prettify<DeriveSchemaByKey<ResolveSchema<S[K], K extends keyof R ? (R[K] extends object ? R[K] : {}) : {}, S>, "zodSqlSchema">>>;
|
|
230
|
+
clientSchema: z.ZodObject<Prettify<DeriveSchemaByKey<ResolveSchema<S[K], K extends keyof R ? (R[K] extends object ? R[K] : {}) : {}, S>, "zodClientSchema">>>;
|
|
231
|
+
validationSchema: z.ZodObject<Prettify<DeriveSchemaByKey<ResolveSchema<S[K], K extends keyof R ? (R[K] extends object ? R[K] : {}) : {}, S>, "zodValidationSchema">>>;
|
|
232
|
+
defaultValues: Prettify<DeriveDefaults<ResolveSchema<S[K], K extends keyof R ? (R[K] extends object ? R[K] : {}) : {}, S>>>;
|
|
228
233
|
toClient: (dbObject: any) => any;
|
|
229
234
|
toDb: (clientObject: any) => any;
|
|
230
235
|
};
|
|
231
236
|
};
|
|
232
237
|
};
|
|
233
|
-
export declare function createSchemaBox<S extends Record<string, SchemaWithPlaceholders>, R extends ResolutionConfig<S>>(schemas: S, resolver: (proxy: SchemaProxy<S>) => R): { [key in keyof ResolvedRegistryWithSchemas<S, R>]: {
|
|
238
|
+
export declare function createSchemaBox<S extends Record<string, SchemaWithPlaceholders>, R extends ResolutionConfig<S>>(schemas: S, resolver: (proxy: SchemaProxy<S>) => R & ValidateResolution<R, S>): { [key in keyof ResolvedRegistryWithSchemas<S, R>]: {
|
|
234
239
|
rawSchema: ResolvedRegistryWithSchemas<S, R>[key]["rawSchema"];
|
|
235
240
|
zodSchemas: ResolvedRegistryWithSchemas<S, R>[key]["zodSchemas"];
|
|
236
241
|
test: S;
|
package/dist/schema.js
CHANGED
|
@@ -293,10 +293,7 @@ export function schema(schema) {
|
|
|
293
293
|
}
|
|
294
294
|
function inferDefaultFromZod(zodType, sqlConfig) {
|
|
295
295
|
if (sqlConfig && typeof sqlConfig === "object" && "type" in sqlConfig) {
|
|
296
|
-
// --- PRIORITY 1: Check for an explicit `default` on the SQL config ---
|
|
297
296
|
if ("default" in sqlConfig && sqlConfig.default !== undefined) {
|
|
298
|
-
// FIX #1: If the default is CURRENT_TIMESTAMP, it's a DB responsibility.
|
|
299
|
-
// Return undefined so no client-side default is generated.
|
|
300
297
|
if (sqlConfig.default === "CURRENT_TIMESTAMP") {
|
|
301
298
|
return undefined;
|
|
302
299
|
}
|
|
@@ -347,20 +344,12 @@ function inferDefaultFromZod(zodType, sqlConfig) {
|
|
|
347
344
|
? zodType._def.defaultValue()
|
|
348
345
|
: zodType._def.defaultValue;
|
|
349
346
|
}
|
|
350
|
-
// --- FIX #2: Add intelligent fallback for unrecognized Zod types ---
|
|
351
|
-
// This handles z.email(), z.url(), etc., by checking the base type.
|
|
352
347
|
if (zodType instanceof z.ZodString) {
|
|
353
348
|
return "";
|
|
354
349
|
}
|
|
355
350
|
// Return undefined if no other default can be determined.
|
|
356
351
|
return undefined;
|
|
357
352
|
}
|
|
358
|
-
// export function reference<TField extends object>(config: TField) {
|
|
359
|
-
// return {
|
|
360
|
-
// type: "reference" as const,
|
|
361
|
-
// to: config,
|
|
362
|
-
// };
|
|
363
|
-
// }
|
|
364
353
|
export function createMixedValidationSchema(schema, clientSchema, dbSchema) {
|
|
365
354
|
// If schemas are provided, use them (to avoid circular calls)
|
|
366
355
|
if (clientSchema && dbSchema) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cogsbox-shape",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.104",
|
|
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",
|