cogsbox-shape 0.5.75 → 0.5.77
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 +0 -39
- package/dist/schema.js +40 -32
- package/package.json +5 -3
package/dist/schema.d.ts
CHANGED
|
@@ -30,25 +30,6 @@ export type SQLType = ({
|
|
|
30
30
|
}) & {
|
|
31
31
|
pk?: true;
|
|
32
32
|
};
|
|
33
|
-
type BaseConfig = {
|
|
34
|
-
nullable?: boolean;
|
|
35
|
-
pk?: true;
|
|
36
|
-
field?: string;
|
|
37
|
-
};
|
|
38
|
-
type IntConfig = BaseConfig & {
|
|
39
|
-
default?: number;
|
|
40
|
-
};
|
|
41
|
-
type BooleanConfig = BaseConfig & {
|
|
42
|
-
default?: boolean;
|
|
43
|
-
};
|
|
44
|
-
type DateConfig = BaseConfig & {
|
|
45
|
-
type?: "date" | "datetime";
|
|
46
|
-
default?: Date;
|
|
47
|
-
};
|
|
48
|
-
type StringConfig = BaseConfig & {
|
|
49
|
-
length?: number;
|
|
50
|
-
default?: string;
|
|
51
|
-
};
|
|
52
33
|
type SQLToZodType<T extends SQLType, TDefault extends boolean> = T["pk"] extends true ? TDefault extends true ? z.ZodString : z.ZodNumber : T["nullable"] extends true ? T["type"] extends "varchar" | "char" | "text" | "longtext" ? z.ZodNullable<z.ZodString> : T["type"] extends "int" ? z.ZodNullable<z.ZodNumber> : T["type"] extends "boolean" ? z.ZodNullable<z.ZodBoolean> : T["type"] extends "date" | "datetime" ? T extends {
|
|
53
34
|
default: "CURRENT_TIMESTAMP";
|
|
54
35
|
} ? TDefault extends true ? never : z.ZodNullable<z.ZodDate> : z.ZodNullable<z.ZodDate> : never : T["type"] extends "varchar" | "char" | "text" | "longtext" ? z.ZodString : T["type"] extends "int" ? z.ZodNumber : T["type"] extends "boolean" ? z.ZodBoolean : T["type"] extends "date" | "datetime" ? T extends {
|
|
@@ -138,14 +119,6 @@ export type Builder<TStage extends Stage, T extends SQLType | RelationConfig<any
|
|
|
138
119
|
};
|
|
139
120
|
} & Pick<IBuilderMethods<T, TSql, TNew, TInitialValue, TClient, TValidation>, StageMethods[TStage]>;
|
|
140
121
|
interface ShapeAPI {
|
|
141
|
-
int: (config?: IntConfig) => ReturnType<typeof createBuilder>;
|
|
142
|
-
varchar: (config?: Omit<StringConfig, "type">) => ReturnType<typeof createBuilder>;
|
|
143
|
-
char: (config?: Omit<StringConfig, "type">) => ReturnType<typeof createBuilder>;
|
|
144
|
-
text: (config?: Omit<StringConfig, "type" | "length">) => ReturnType<typeof createBuilder>;
|
|
145
|
-
longtext: (config?: Omit<StringConfig, "type" | "length">) => ReturnType<typeof createBuilder>;
|
|
146
|
-
boolean: (config?: BooleanConfig) => ReturnType<typeof createBuilder>;
|
|
147
|
-
date: (config?: Omit<DateConfig, "type">) => ReturnType<typeof createBuilder>;
|
|
148
|
-
datetime: (config?: Omit<DateConfig, "type">) => ReturnType<typeof createBuilder>;
|
|
149
122
|
sql: <T extends SQLType>(sqlConfig: T) => Builder<"sql", T, SQLToZodType<T, false>, SQLToZodType<T, false>, z.infer<SQLToZodType<T, false>>, SQLToZodType<T, false>, SQLToZodType<T, false>>;
|
|
150
123
|
hasMany: <T extends Schema<any>, CreateSchema extends ReturnType<typeof createSchema<T>>>(config: {
|
|
151
124
|
fromKey: string;
|
|
@@ -166,18 +139,6 @@ interface ShapeAPI {
|
|
|
166
139
|
}) => Builder<"relation", RelationConfig<T>, z.ZodOptional<z.ZodArray<z.ZodAny>>, z.ZodOptional<z.ZodArray<z.ZodAny>>, any[], z.ZodOptional<z.ZodArray<z.ZodAny>>, z.ZodOptional<z.ZodArray<z.ZodAny>>>;
|
|
167
140
|
}
|
|
168
141
|
export declare const s: ShapeAPI;
|
|
169
|
-
declare function createBuilder<TStage extends "sql" | "relation" | "new" | "client" | "validation", T extends SQLType | RelationConfig<any>, TSql extends z.ZodTypeAny, TNew extends z.ZodTypeAny, TInitialValue, TClient extends z.ZodTypeAny, TValidation extends z.ZodTypeAny>(config: {
|
|
170
|
-
stage: TStage;
|
|
171
|
-
sqlConfig: T;
|
|
172
|
-
sqlZod: TSql;
|
|
173
|
-
newZod: TNew;
|
|
174
|
-
initialValue: TInitialValue;
|
|
175
|
-
clientZod: TClient;
|
|
176
|
-
validationZod: TValidation;
|
|
177
|
-
completedStages?: Set<string>;
|
|
178
|
-
clientTransform?: (schema: z.ZodTypeAny) => z.ZodTypeAny;
|
|
179
|
-
validationTransform?: (schema: z.ZodTypeAny) => z.ZodTypeAny;
|
|
180
|
-
}): Builder<TStage, T, TSql, TNew, TInitialValue, TClient, TValidation>;
|
|
181
142
|
type EnrichedField<K extends string, V, TSchema extends ShapeSchema> = V & {
|
|
182
143
|
__meta: {
|
|
183
144
|
_key: K;
|
package/dist/schema.js
CHANGED
|
@@ -9,38 +9,46 @@ export function currentTimeStamp() {
|
|
|
9
9
|
}
|
|
10
10
|
// Now define the shape object with the explicit type annotation
|
|
11
11
|
export const s = {
|
|
12
|
-
int: (config = {}) =>
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}),
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
+
// }),
|
|
44
52
|
sql: (sqlConfig) => {
|
|
45
53
|
const sqlZodType = (() => {
|
|
46
54
|
let baseType;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cogsbox-shape",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.77",
|
|
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",
|
|
@@ -17,6 +17,9 @@
|
|
|
17
17
|
"bin": {
|
|
18
18
|
"cogsbox-shape": "tsx ./dist/cli.js"
|
|
19
19
|
},
|
|
20
|
+
"exports": {
|
|
21
|
+
".": "./dist/index.js"
|
|
22
|
+
},
|
|
20
23
|
"keywords": [
|
|
21
24
|
"typescript",
|
|
22
25
|
"orm",
|
|
@@ -36,7 +39,6 @@
|
|
|
36
39
|
"commander": "^13.1.0",
|
|
37
40
|
"tsx": "^4.19.3",
|
|
38
41
|
"uuid": "^9.0.0",
|
|
39
|
-
"zod": "^3.22.4",
|
|
40
42
|
"zod-to-json-schema": "^3.22.3"
|
|
41
43
|
},
|
|
42
44
|
"devDependencies": {
|
|
@@ -49,7 +51,7 @@
|
|
|
49
51
|
"prettier": "^3.1.1",
|
|
50
52
|
"typescript": "^5.3.3",
|
|
51
53
|
"vitest": "^3.2.0",
|
|
52
|
-
"zod": "^
|
|
54
|
+
"zod": "^3.25.0 || ^4.0.0"
|
|
53
55
|
},
|
|
54
56
|
"peerDependencies": {
|
|
55
57
|
"zod": "^3.22.4"
|