cogsbox-shape 0.5.146 → 0.5.147

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 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, TValue extends () => infer R ? R : TValue, CollapsedUnion<TSql, TSchema>, CollapsedUnion<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
@@ -460,8 +460,7 @@ export function createSchema(schema, relations) {
460
460
  for (const key in fullSchema) {
461
461
  if (key === "_tableName" ||
462
462
  key.startsWith("__") ||
463
- key === String(SchemaWrapperBrand) ||
464
- key === "resolvePKs")
463
+ key === String(SchemaWrapperBrand))
465
464
  continue;
466
465
  const definition = fullSchema[key];
467
466
  // Handle new-style references
@@ -546,9 +545,8 @@ export function createSchema(schema, relations) {
546
545
  return dbObject;
547
546
  };
548
547
  return {
549
- pk: pkKeys,
550
- clientPk: clientPkKeys,
551
- resolvePKs: pkResolver,
548
+ pk: pkKeys?.length ? pkKeys : null,
549
+ clientPk: clientPkKeys ? clientPkKeys : null,
552
550
  sqlSchema: z.object(sqlFields),
553
551
  clientSchema: z.object(clientFields),
554
552
  validationSchema: z.object(serverFields),
@@ -765,7 +763,6 @@ export function createSchemaBox(schemas, resolver) {
765
763
  // ADD: Expose PK info and resolver
766
764
  pk: entry.zodSchemas.pk,
767
765
  clientPk: entry.zodSchemas.clientPk,
768
- resolvePKs: entry.zodSchemas.resolvePKs,
769
766
  nav: createNavProxy(tableName, finalRegistry),
770
767
  // Add this
771
768
  createView: (selection) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cogsbox-shape",
3
- "version": "0.5.146",
3
+ "version": "0.5.147",
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",