cogsbox-shape 0.5.198 → 0.5.200
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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createShapePlugin } from "./plugin.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createShapePlugin } from "./plugin.js";
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function createShapePlugin<const TBox extends Record<string, {
|
|
2
|
+
generateDefaults: () => unknown;
|
|
3
|
+
}>>(box: TBox): import("cogsbox-state").CogsPluginBuilder<"shape", undefined, unknown, unknown, never, {}, false, false, false, false, false, true, { [K in keyof TBox]: ReturnType<TBox[K]["generateDefaults"]>; }>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createPluginContext } from "cogsbox-state";
|
|
2
|
+
const { createPlugin } = createPluginContext();
|
|
3
|
+
export function createShapePlugin(box) {
|
|
4
|
+
return createPlugin("shape").initialState(() => {
|
|
5
|
+
const state = {};
|
|
6
|
+
for (const key of Object.keys(box)) {
|
|
7
|
+
state[key] = box[key].generateDefaults();
|
|
8
|
+
}
|
|
9
|
+
return state;
|
|
10
|
+
});
|
|
11
|
+
}
|
package/dist/schema.d.ts
CHANGED
|
@@ -64,6 +64,13 @@ type SQLToZodType<T extends SQLTypeInput, TDefault extends boolean> = T["pk"] ex
|
|
|
64
64
|
type ZodTypeFromPrimitive<T> = T extends string ? z.ZodString : T extends number ? z.ZodNumber : T extends boolean ? z.ZodBoolean : T extends Date ? z.ZodDate : z.ZodAny;
|
|
65
65
|
type CollapsedUnion<A extends z.ZodTypeAny, B extends z.ZodTypeAny> = A extends B ? (B extends A ? A : z.ZodUnion<[A, B]>) : z.ZodUnion<[A, B]>;
|
|
66
66
|
export interface IBuilderMethods<T extends DbConfig, TSql extends z.ZodTypeAny, TInitialValue, TClient extends z.ZodTypeAny, TValidation extends z.ZodTypeAny> {
|
|
67
|
+
clientInput<const TValue, const TSchema extends z.ZodTypeAny>(options: {
|
|
68
|
+
value: TValue | ((tools: {
|
|
69
|
+
uuid: () => string;
|
|
70
|
+
}) => TValue);
|
|
71
|
+
schema: TSchema | ((base: ZodTypeFromPrimitive<TValue extends () => infer R ? R : TValue>) => TSchema);
|
|
72
|
+
clientPk?: boolean | ((val: any) => boolean);
|
|
73
|
+
}): Prettify<Builder<"clientInput", T, TSql, TValue extends () => infer R ? R : TValue, TSchema, CollapsedUnion<TSql, TSchema>>>;
|
|
67
74
|
clientInput<const TValue>(options: {
|
|
68
75
|
value: TValue | ((tools: {
|
|
69
76
|
uuid: () => string;
|
|
@@ -92,13 +99,6 @@ export interface IBuilderMethods<T extends DbConfig, TSql extends z.ZodTypeAny,
|
|
|
92
99
|
value?: never;
|
|
93
100
|
schema: (tools: any) => z.ZodTypeAny;
|
|
94
101
|
}): Prettify<Builder<"clientInput", T, TSql, unknown, z.ZodTypeAny, z.ZodTypeAny>>;
|
|
95
|
-
clientInput<const TValue, const TSchema extends z.ZodTypeAny>(options: {
|
|
96
|
-
value: TValue | ((tools: {
|
|
97
|
-
uuid: () => string;
|
|
98
|
-
}) => TValue);
|
|
99
|
-
schema: TSchema | ((base: ZodTypeFromPrimitive<TValue extends () => infer R ? R : TValue>) => TSchema);
|
|
100
|
-
clientPk?: boolean | ((val: any) => boolean);
|
|
101
|
-
}): Prettify<Builder<"clientInput", T, TSql, TValue extends () => infer R ? R : TValue, TSchema, CollapsedUnion<TSql, TSchema>>>;
|
|
102
102
|
clientInput<TClientNext extends z.ZodTypeAny>(schema: ((tools: {
|
|
103
103
|
sql: TSql;
|
|
104
104
|
}) => TClientNext) | TClientNext): Prettify<Builder<"clientInput", T, TSql, z.infer<TClientNext>, TClientNext, CollapsedUnion<TSql, TClientNext>>>;
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cogsbox-shape",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.200",
|
|
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",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist",
|
|
9
|
-
"cogsbox-shape-db/dist"
|
|
9
|
+
"cogsbox-shape-db/dist",
|
|
10
|
+
"cogsbox-shape-state/dist"
|
|
10
11
|
],
|
|
11
12
|
"repository": "github:cogsbox/cogsbox-shape",
|
|
12
13
|
"scripts": {
|
|
13
|
-
"build": "tsc && pnpm --dir cogsbox-shape-db run build",
|
|
14
|
+
"build": "tsc && pnpm --dir cogsbox-shape-db run build && pnpm --dir cogsbox-shape-state run build",
|
|
14
15
|
"lint": "eslint src --ext .ts",
|
|
15
16
|
"format": "prettier --write \"src/**/*.ts\"",
|
|
16
17
|
"test": "vitest ",
|
|
@@ -36,6 +37,11 @@
|
|
|
36
37
|
"import": "./cogsbox-shape-db/dist/sqlite/index.js",
|
|
37
38
|
"default": "./cogsbox-shape-db/dist/sqlite/index.js"
|
|
38
39
|
},
|
|
40
|
+
"./state": {
|
|
41
|
+
"types": "./cogsbox-shape-state/dist/index.d.ts",
|
|
42
|
+
"import": "./cogsbox-shape-state/dist/index.js",
|
|
43
|
+
"default": "./cogsbox-shape-state/dist/index.js"
|
|
44
|
+
},
|
|
39
45
|
"./package.json": "./package.json"
|
|
40
46
|
},
|
|
41
47
|
"keywords": [
|
|
@@ -54,6 +60,7 @@
|
|
|
54
60
|
"author": "",
|
|
55
61
|
"license": "MIT",
|
|
56
62
|
"dependencies": {
|
|
63
|
+
"cogsbox-state": "^0.5.481",
|
|
57
64
|
"commander": "^13.1.0",
|
|
58
65
|
"kysely": "^0.29.2",
|
|
59
66
|
"tsx": "^4.19.3",
|
|
@@ -64,6 +71,7 @@
|
|
|
64
71
|
},
|
|
65
72
|
"devDependencies": {
|
|
66
73
|
"@types/node": "^20.10.5",
|
|
74
|
+
"@types/react": "^19.2.14",
|
|
67
75
|
"@types/uuid": "^11.0.0",
|
|
68
76
|
"@typescript-eslint/eslint-plugin": "^6.15.0",
|
|
69
77
|
"@typescript-eslint/parser": "^6.15.0",
|