cogsbox-shape 0.5.143 → 0.5.145

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
@@ -306,33 +306,41 @@ type DeriveViewDefaults<TTableName extends keyof TRegistry, TSelection, TRegistr
306
306
  ]> | null : never : never : never;
307
307
  } : {})>;
308
308
  export type DeriveViewResultFromBox<TBox extends CreateSchemaBoxReturn<any, any>, TTableName extends keyof TBox, TSelection extends TBox[TTableName]["RelationSelection"]> = {
309
- sql: TBox[TTableName]["schemas"]["sql"];
310
- client: z.ZodObject<_DeriveViewShape<TTableName, TSelection, {
311
- [K in keyof TBox]: {
312
- rawSchema: TBox[K]["definition"];
313
- zodSchemas: {
314
- sqlSchema: TBox[K]["schemas"]["sql"];
315
- clientSchema: TBox[K]["schemas"]["client"];
316
- validationSchema: TBox[K]["schemas"]["validation"];
317
- defaultValues: TBox[K]["defaults"];
318
- toClient: TBox[K]["transforms"]["toClient"];
319
- toDb: TBox[K]["transforms"]["toDb"];
309
+ definition: TBox[TTableName]["definition"];
310
+ schemaKey: TTableName;
311
+ schemas: {
312
+ sql: TBox[TTableName]["schemas"]["sql"];
313
+ client: z.ZodObject<_DeriveViewShape<TTableName, TSelection, {
314
+ [K in keyof TBox]: {
315
+ rawSchema: TBox[K]["definition"];
316
+ zodSchemas: {
317
+ sqlSchema: TBox[K]["schemas"]["sql"];
318
+ clientSchema: TBox[K]["schemas"]["client"];
319
+ validationSchema: TBox[K]["schemas"]["validation"];
320
+ defaultValues: TBox[K]["defaults"];
321
+ toClient: TBox[K]["transforms"]["toClient"];
322
+ toDb: TBox[K]["transforms"]["toDb"];
323
+ };
320
324
  };
321
- };
322
- }, "clientSchema">>;
323
- validation: z.ZodObject<_DeriveViewShape<TTableName, TSelection, {
324
- [K in keyof TBox]: {
325
- rawSchema: TBox[K]["definition"];
326
- zodSchemas: {
327
- sqlSchema: TBox[K]["schemas"]["sql"];
328
- clientSchema: TBox[K]["schemas"]["client"];
329
- validationSchema: TBox[K]["schemas"]["validation"];
330
- defaultValues: TBox[K]["defaults"];
331
- toClient: TBox[K]["transforms"]["toClient"];
332
- toDb: TBox[K]["transforms"]["toDb"];
325
+ }, "clientSchema">>;
326
+ validation: z.ZodObject<_DeriveViewShape<TTableName, TSelection, {
327
+ [K in keyof TBox]: {
328
+ rawSchema: TBox[K]["definition"];
329
+ zodSchemas: {
330
+ sqlSchema: TBox[K]["schemas"]["sql"];
331
+ clientSchema: TBox[K]["schemas"]["client"];
332
+ validationSchema: TBox[K]["schemas"]["validation"];
333
+ defaultValues: TBox[K]["defaults"];
334
+ toClient: TBox[K]["transforms"]["toClient"];
335
+ toDb: TBox[K]["transforms"]["toDb"];
336
+ };
333
337
  };
334
- };
335
- }, "validationSchema">>;
338
+ }, "validationSchema">>;
339
+ };
340
+ transforms: {
341
+ toClient: TBox[TTableName]["transforms"]["toClient"];
342
+ toDb: TBox[TTableName]["transforms"]["toDb"];
343
+ };
336
344
  defaults: DeriveViewDefaults<TTableName, TSelection, {
337
345
  [K in keyof TBox]: {
338
346
  rawSchema: TBox[K]["definition"];
@@ -346,12 +354,34 @@ export type DeriveViewResultFromBox<TBox extends CreateSchemaBoxReturn<any, any>
346
354
  };
347
355
  };
348
356
  }>;
357
+ isView: true;
358
+ viewSelection: TSelection;
359
+ baseTable: TTableName;
360
+ nav?: undefined;
361
+ createView?: undefined;
362
+ RelationSelection?: undefined;
363
+ __registry: TBox;
349
364
  };
350
365
  export type DeriveViewResult<TTableName extends keyof TRegistry, TSelection, TRegistry extends RegistryShape> = {
351
- sql: TRegistry[TTableName]["zodSchemas"]["sqlSchema"];
352
- client: z.ZodObject<_DeriveViewShape<TTableName, TSelection, TRegistry, "clientSchema">>;
353
- validation: z.ZodObject<_DeriveViewShape<TTableName, TSelection, TRegistry, "validationSchema">>;
366
+ definition: TRegistry[TTableName]["rawSchema"];
367
+ schemaKey: TTableName;
368
+ schemas: {
369
+ sql: TRegistry[TTableName]["zodSchemas"]["sqlSchema"];
370
+ client: z.ZodObject<_DeriveViewShape<TTableName, TSelection, TRegistry, "clientSchema">>;
371
+ validation: z.ZodObject<_DeriveViewShape<TTableName, TSelection, TRegistry, "validationSchema">>;
372
+ };
373
+ transforms: {
374
+ toClient: TRegistry[TTableName]["zodSchemas"]["toClient"];
375
+ toDb: TRegistry[TTableName]["zodSchemas"]["toDb"];
376
+ };
354
377
  defaults: DeriveViewDefaults<TTableName, TSelection, TRegistry>;
378
+ isView: true;
379
+ viewSelection: TSelection;
380
+ baseTable: TTableName;
381
+ nav?: undefined;
382
+ createView?: undefined;
383
+ RelationSelection?: undefined;
384
+ __registry: TRegistry;
355
385
  };
356
386
  export type DeriveViewFromSchema<TSchema extends {
357
387
  schemaKey: string;
package/dist/schema.js CHANGED
@@ -7,48 +7,7 @@ export function currentTimeStamp() {
7
7
  defaultValue: new Date(),
8
8
  };
9
9
  }
10
- // Now define the shape object with the explicit type annotation
11
10
  export const s = {
12
- // int: (config: IntConfig = {}) =>
13
- // s.sql({
14
- // type: "int",
15
- // ...config,
16
- // }),
17
- // varchar: (config: Omit<StringConfig, "type"> = {}) =>
18
- // s.sql({
19
- // type: "varchar",
20
- // ...config,
21
- // }),
22
- // char: (config: Omit<StringConfig, "type"> = {}) =>
23
- // s.sql({
24
- // type: "char",
25
- // ...config,
26
- // }),
27
- // text: (config: Omit<StringConfig, "type" | "length"> = {}) =>
28
- // s.sql({
29
- // type: "text",
30
- // ...config,
31
- // }),
32
- // longtext: (config: Omit<StringConfig, "type" | "length"> = {}) =>
33
- // s.sql({
34
- // type: "longtext",
35
- // ...config,
36
- // }),
37
- // boolean: (config: BooleanConfig = {}) =>
38
- // s.sql({
39
- // type: "boolean",
40
- // ...config,
41
- // }),
42
- // date: (config: Omit<DateConfig, "type"> = {}) =>
43
- // s.sql({
44
- // type: "date",
45
- // ...config,
46
- // }),
47
- // datetime: (config: Omit<DateConfig, "type"> = {}) =>
48
- // s.sql({
49
- // type: "datetime",
50
- // ...config,
51
- // }),
52
11
  reference: (getter) => ({
53
12
  __type: "reference",
54
13
  getter: getter,
@@ -753,10 +712,28 @@ export function createSchemaBox(schemas, resolver) {
753
712
  createView: (selection) => {
754
713
  const view = createViewObject(tableName, selection, finalRegistry, tableNameToRegistryKeyMap);
755
714
  const defaults = computeViewDefaults(tableName, selection, finalRegistry, tableNameToRegistryKeyMap);
756
- console.log("View defaults:", defaults); // ADD THIS
715
+ // Return the same shape as regular entries, but with isView marker
757
716
  return {
758
- ...view,
717
+ definition: entry.rawSchema, // Could be enhanced with selection info
718
+ schemaKey: tableName,
719
+ schemas: {
720
+ sql: view.sql,
721
+ client: view.client,
722
+ validation: view.validation,
723
+ },
724
+ transforms: {
725
+ toClient: entry.zodSchemas.toClient, // May need composition for nested
726
+ toDb: entry.zodSchemas.toDb,
727
+ },
759
728
  defaults: defaults,
729
+ isView: true, // Discriminator
730
+ viewSelection: selection, // Store what was selected
731
+ baseTable: tableName,
732
+ // Optionally exclude these for views:
733
+ // nav: undefined,
734
+ // createView: undefined,
735
+ // RelationSelection: undefined,
736
+ __registry: finalRegistry,
760
737
  };
761
738
  },
762
739
  RelationSelection: {},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cogsbox-shape",
3
- "version": "0.5.143",
3
+ "version": "0.5.145",
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",