cogsbox-shape 0.5.143 → 0.5.144
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 +15 -3
- package/dist/schema.js +20 -43
- package/package.json +1 -1
package/dist/schema.d.ts
CHANGED
|
@@ -348,10 +348,22 @@ export type DeriveViewResultFromBox<TBox extends CreateSchemaBoxReturn<any, any>
|
|
|
348
348
|
}>;
|
|
349
349
|
};
|
|
350
350
|
export type DeriveViewResult<TTableName extends keyof TRegistry, TSelection, TRegistry extends RegistryShape> = {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
351
|
+
definition: TRegistry[TTableName]["rawSchema"];
|
|
352
|
+
schemaKey: TTableName;
|
|
353
|
+
schemas: {
|
|
354
|
+
sql: TRegistry[TTableName]["zodSchemas"]["sqlSchema"];
|
|
355
|
+
client: z.ZodObject<_DeriveViewShape<TTableName, TSelection, TRegistry, "clientSchema">>;
|
|
356
|
+
validation: z.ZodObject<_DeriveViewShape<TTableName, TSelection, TRegistry, "validationSchema">>;
|
|
357
|
+
};
|
|
358
|
+
transforms: {
|
|
359
|
+
toClient: TRegistry[TTableName]["zodSchemas"]["toClient"];
|
|
360
|
+
toDb: TRegistry[TTableName]["zodSchemas"]["toDb"];
|
|
361
|
+
};
|
|
354
362
|
defaults: DeriveViewDefaults<TTableName, TSelection, TRegistry>;
|
|
363
|
+
isView: true;
|
|
364
|
+
viewSelection: TSelection;
|
|
365
|
+
baseTable: TTableName;
|
|
366
|
+
__registry: TRegistry;
|
|
355
367
|
};
|
|
356
368
|
export type DeriveViewFromSchema<TSchema extends {
|
|
357
369
|
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
|
-
|
|
715
|
+
// Return the same shape as regular entries, but with isView marker
|
|
757
716
|
return {
|
|
758
|
-
|
|
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.
|
|
3
|
+
"version": "0.5.144",
|
|
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",
|