cogsbox-shape 0.5.146 → 0.5.148
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/dist/schema.d.ts +4 -72
- package/dist/schema.js +8 -6
- package/package.json +1 -1
package/dist/schema.d.ts
CHANGED
|
@@ -53,7 +53,8 @@ export interface IBuilderMethods<T extends DbConfig, TSql extends z.ZodTypeAny,
|
|
|
53
53
|
value: TValue | (() => TValue);
|
|
54
54
|
schema: TSchema | ((base: ZodTypeFromPrimitive<TValue extends () => infer R ? R : TValue>) => TSchema);
|
|
55
55
|
clientPk?: boolean;
|
|
56
|
-
}): Prettify<Builder<"new", T, TSql, TSchema,
|
|
56
|
+
}): Prettify<Builder<"new", T, TSql, TSchema, z.infer<TSchema>, // <-- THIS IS THE FIX: Use schema's type, not literal value
|
|
57
|
+
CollapsedUnion<TSql, TSchema>, CollapsedUnion<TSql, TSchema>>>;
|
|
57
58
|
reference: <TRefSchema extends {
|
|
58
59
|
_tableName: string;
|
|
59
60
|
}>(fieldGetter: () => any) => Builder<"sql", T & {
|
|
@@ -204,12 +205,8 @@ export declare function createSchema<T extends {
|
|
|
204
205
|
_tableName: string;
|
|
205
206
|
[SchemaWrapperBrand]?: true;
|
|
206
207
|
}, R extends Record<string, any> = {}, TActualSchema extends Omit<T & R, typeof SchemaWrapperBrand> = Omit<T & R, typeof SchemaWrapperBrand>>(schema: T, relations?: R): {
|
|
207
|
-
pk: string[];
|
|
208
|
-
clientPk: string[];
|
|
209
|
-
resolvePKs?: (record: any) => {
|
|
210
|
-
clientPk: any[];
|
|
211
|
-
dbPk: any[];
|
|
212
|
-
};
|
|
208
|
+
pk: string[] | null;
|
|
209
|
+
clientPk: string[] | null;
|
|
213
210
|
sqlSchema: z.ZodObject<Prettify<DeriveSchemaByKey<TActualSchema, "zodSqlSchema">>>;
|
|
214
211
|
clientSchema: z.ZodObject<Prettify<DeriveSchemaByKey<TActualSchema, "zodClientSchema">>>;
|
|
215
212
|
validationSchema: z.ZodObject<Prettify<DeriveSchemaByKey<TActualSchema, "zodValidationSchema">>>;
|
|
@@ -339,63 +336,6 @@ type DeriveViewDefaults<TTableName extends keyof TRegistry, TSelection, TRegistr
|
|
|
339
336
|
1
|
|
340
337
|
]> | null : never : never : never;
|
|
341
338
|
} : {})>;
|
|
342
|
-
export type DeriveViewResultFromBox<TBox extends CreateSchemaBoxReturn<any, any>, TTableName extends keyof TBox, TSelection extends TBox[TTableName]["RelationSelection"]> = {
|
|
343
|
-
definition: TBox[TTableName]["definition"];
|
|
344
|
-
schemaKey: TTableName;
|
|
345
|
-
schemas: {
|
|
346
|
-
sql: TBox[TTableName]["schemas"]["sql"];
|
|
347
|
-
client: z.ZodObject<_DeriveViewShape<TTableName, TSelection, {
|
|
348
|
-
[K in keyof TBox]: {
|
|
349
|
-
rawSchema: TBox[K]["definition"];
|
|
350
|
-
zodSchemas: {
|
|
351
|
-
sqlSchema: TBox[K]["schemas"]["sql"];
|
|
352
|
-
clientSchema: TBox[K]["schemas"]["client"];
|
|
353
|
-
validationSchema: TBox[K]["schemas"]["server"];
|
|
354
|
-
defaultValues: TBox[K]["defaults"];
|
|
355
|
-
toClient: TBox[K]["transforms"]["toClient"];
|
|
356
|
-
toDb: TBox[K]["transforms"]["toDb"];
|
|
357
|
-
};
|
|
358
|
-
};
|
|
359
|
-
}, "clientSchema">>;
|
|
360
|
-
server: z.ZodObject<_DeriveViewShape<TTableName, TSelection, {
|
|
361
|
-
[K in keyof TBox]: {
|
|
362
|
-
rawSchema: TBox[K]["definition"];
|
|
363
|
-
zodSchemas: {
|
|
364
|
-
sqlSchema: TBox[K]["schemas"]["sql"];
|
|
365
|
-
clientSchema: TBox[K]["schemas"]["client"];
|
|
366
|
-
validationSchema: TBox[K]["schemas"]["server"];
|
|
367
|
-
defaultValues: TBox[K]["defaults"];
|
|
368
|
-
toClient: TBox[K]["transforms"]["toClient"];
|
|
369
|
-
toDb: TBox[K]["transforms"]["toDb"];
|
|
370
|
-
};
|
|
371
|
-
};
|
|
372
|
-
}, "validationSchema">>;
|
|
373
|
-
};
|
|
374
|
-
transforms: {
|
|
375
|
-
toClient: TBox[TTableName]["transforms"]["toClient"];
|
|
376
|
-
toDb: TBox[TTableName]["transforms"]["toDb"];
|
|
377
|
-
};
|
|
378
|
-
defaults: DeriveViewDefaults<TTableName, TSelection, {
|
|
379
|
-
[K in keyof TBox]: {
|
|
380
|
-
rawSchema: TBox[K]["definition"];
|
|
381
|
-
zodSchemas: {
|
|
382
|
-
sqlSchema: TBox[K]["schemas"]["sql"];
|
|
383
|
-
clientSchema: TBox[K]["schemas"]["client"];
|
|
384
|
-
validationSchema: TBox[K]["schemas"]["server"];
|
|
385
|
-
defaultValues: TBox[K]["defaults"];
|
|
386
|
-
toClient: TBox[K]["transforms"]["toClient"];
|
|
387
|
-
toDb: TBox[K]["transforms"]["toDb"];
|
|
388
|
-
};
|
|
389
|
-
};
|
|
390
|
-
}>;
|
|
391
|
-
isView: true;
|
|
392
|
-
viewSelection: TSelection;
|
|
393
|
-
baseTable: TTableName;
|
|
394
|
-
nav?: undefined;
|
|
395
|
-
createView?: undefined;
|
|
396
|
-
RelationSelection?: undefined;
|
|
397
|
-
__registry: TBox;
|
|
398
|
-
};
|
|
399
339
|
export type DeriveViewResult<TTableName extends keyof TRegistry, TSelection, TRegistry extends RegistryShape> = {
|
|
400
340
|
definition: TRegistry[TTableName]["rawSchema"];
|
|
401
341
|
schemaKey: TTableName;
|
|
@@ -417,14 +357,6 @@ export type DeriveViewResult<TTableName extends keyof TRegistry, TSelection, TRe
|
|
|
417
357
|
RelationSelection?: undefined;
|
|
418
358
|
__registry: TRegistry;
|
|
419
359
|
};
|
|
420
|
-
export type DeriveViewFromSchema<TSchema extends {
|
|
421
|
-
schemaKey: string;
|
|
422
|
-
__registry: RegistryShape;
|
|
423
|
-
RelationSelection: any;
|
|
424
|
-
}, TSelection extends TSchema["RelationSelection"]> = TSchema extends {
|
|
425
|
-
schemaKey: infer TKey;
|
|
426
|
-
__registry: infer TRegistry;
|
|
427
|
-
} ? TKey extends keyof TRegistry ? TRegistry extends RegistryShape ? DeriveViewResult<TKey, TSelection, TRegistry> : never : never : never;
|
|
428
360
|
type RelationKeysOf<Cur extends string, Reg extends RegistryShape> = Cur extends keyof Reg ? {
|
|
429
361
|
[K in keyof Reg[Cur]["rawSchema"]]: IsRelationField<Reg[Cur]["rawSchema"][K]> extends true ? K : never;
|
|
430
362
|
}[keyof Reg[Cur]["rawSchema"]] : never;
|
package/dist/schema.js
CHANGED
|
@@ -456,12 +456,14 @@ export function createSchema(schema, relations) {
|
|
|
456
456
|
const fullSchema = { ...schema, ...(relations || {}) };
|
|
457
457
|
let pkKeys = [];
|
|
458
458
|
let clientPkKeys = [];
|
|
459
|
-
const pkResolver = schema.__pkResolver;
|
|
460
459
|
for (const key in fullSchema) {
|
|
460
|
+
const value = fullSchema[key];
|
|
461
461
|
if (key === "_tableName" ||
|
|
462
462
|
key.startsWith("__") ||
|
|
463
463
|
key === String(SchemaWrapperBrand) ||
|
|
464
|
-
key === "
|
|
464
|
+
key === "isClient" ||
|
|
465
|
+
key === "primaryKeySQL" ||
|
|
466
|
+
typeof value === "function")
|
|
465
467
|
continue;
|
|
466
468
|
const definition = fullSchema[key];
|
|
467
469
|
// Handle new-style references
|
|
@@ -546,9 +548,8 @@ export function createSchema(schema, relations) {
|
|
|
546
548
|
return dbObject;
|
|
547
549
|
};
|
|
548
550
|
return {
|
|
549
|
-
pk: pkKeys,
|
|
550
|
-
clientPk: clientPkKeys,
|
|
551
|
-
resolvePKs: pkResolver,
|
|
551
|
+
pk: pkKeys?.length ? pkKeys : null,
|
|
552
|
+
clientPk: clientPkKeys ? clientPkKeys : null,
|
|
552
553
|
sqlSchema: z.object(sqlFields),
|
|
553
554
|
clientSchema: z.object(clientFields),
|
|
554
555
|
validationSchema: z.object(serverFields),
|
|
@@ -765,7 +766,6 @@ export function createSchemaBox(schemas, resolver) {
|
|
|
765
766
|
// ADD: Expose PK info and resolver
|
|
766
767
|
pk: entry.zodSchemas.pk,
|
|
767
768
|
clientPk: entry.zodSchemas.clientPk,
|
|
768
|
-
resolvePKs: entry.zodSchemas.resolvePKs,
|
|
769
769
|
nav: createNavProxy(tableName, finalRegistry),
|
|
770
770
|
// Add this
|
|
771
771
|
createView: (selection) => {
|
|
@@ -784,6 +784,8 @@ export function createSchemaBox(schemas, resolver) {
|
|
|
784
784
|
toClient: entry.zodSchemas.toClient, // May need composition for nested
|
|
785
785
|
toDb: entry.zodSchemas.toDb,
|
|
786
786
|
},
|
|
787
|
+
pk: entry.zodSchemas.pk,
|
|
788
|
+
clientPk: entry.zodSchemas.clientPk,
|
|
787
789
|
defaults: defaults,
|
|
788
790
|
isView: true, // Discriminator
|
|
789
791
|
viewSelection: selection, // Store what was selected
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cogsbox-shape",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.148",
|
|
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",
|