@danielfgray/pg-sourcerer 0.2.1 → 0.3.0
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/cli.js +3 -4
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -1
- package/dist/config.js.map +1 -1
- package/dist/errors.d.ts +14 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +2 -0
- package/dist/errors.js.map +1 -1
- package/dist/generate.d.ts +5 -9
- package/dist/generate.d.ts.map +1 -1
- package/dist/generate.js +27 -29
- package/dist/generate.js.map +1 -1
- package/dist/index.d.ts +19 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -13
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +39 -9
- package/dist/init.js.map +1 -1
- package/dist/ir/extensions/queries.d.ts +264 -0
- package/dist/ir/extensions/queries.d.ts.map +1 -0
- package/dist/ir/extensions/queries.js +153 -0
- package/dist/ir/extensions/queries.js.map +1 -0
- package/dist/ir/extensions/schema-builder.d.ts +61 -0
- package/dist/ir/extensions/schema-builder.d.ts.map +1 -0
- package/dist/ir/extensions/schema-builder.js +5 -0
- package/dist/ir/extensions/schema-builder.js.map +1 -0
- package/dist/lib/conjure.d.ts +66 -0
- package/dist/lib/conjure.d.ts.map +1 -1
- package/dist/lib/conjure.js +127 -29
- package/dist/lib/conjure.js.map +1 -1
- package/dist/lib/hex.d.ts +10 -3
- package/dist/lib/hex.d.ts.map +1 -1
- package/dist/lib/hex.js +18 -8
- package/dist/lib/hex.js.map +1 -1
- package/dist/plugins/arktype.d.ts +27 -14
- package/dist/plugins/arktype.d.ts.map +1 -1
- package/dist/plugins/arktype.js +166 -130
- package/dist/plugins/arktype.js.map +1 -1
- package/dist/plugins/effect.d.ts +53 -0
- package/dist/plugins/effect.d.ts.map +1 -0
- package/dist/plugins/effect.js +1074 -0
- package/dist/plugins/effect.js.map +1 -0
- package/dist/plugins/http-elysia.d.ts +32 -0
- package/dist/plugins/http-elysia.d.ts.map +1 -0
- package/dist/plugins/http-elysia.js +613 -0
- package/dist/plugins/http-elysia.js.map +1 -0
- package/dist/plugins/http-express.d.ts +36 -0
- package/dist/plugins/http-express.d.ts.map +1 -0
- package/dist/plugins/http-express.js +388 -0
- package/dist/plugins/http-express.js.map +1 -0
- package/dist/plugins/http-hono.d.ts +36 -0
- package/dist/plugins/http-hono.d.ts.map +1 -0
- package/dist/plugins/http-hono.js +453 -0
- package/dist/plugins/http-hono.js.map +1 -0
- package/dist/plugins/http-orpc.d.ts +55 -0
- package/dist/plugins/http-orpc.d.ts.map +1 -0
- package/dist/plugins/http-orpc.js +370 -0
- package/dist/plugins/http-orpc.js.map +1 -0
- package/dist/plugins/http-trpc.d.ts +59 -0
- package/dist/plugins/http-trpc.d.ts.map +1 -0
- package/dist/plugins/http-trpc.js +392 -0
- package/dist/plugins/http-trpc.js.map +1 -0
- package/dist/plugins/kysely/queries.d.ts +92 -0
- package/dist/plugins/kysely/queries.d.ts.map +1 -0
- package/dist/plugins/kysely/queries.js +1169 -0
- package/dist/plugins/kysely/queries.js.map +1 -0
- package/dist/plugins/kysely/shared.d.ts +59 -0
- package/dist/plugins/kysely/shared.d.ts.map +1 -0
- package/dist/plugins/kysely/shared.js +247 -0
- package/dist/plugins/kysely/shared.js.map +1 -0
- package/dist/plugins/kysely/types.d.ts +22 -0
- package/dist/plugins/kysely/types.d.ts.map +1 -0
- package/dist/plugins/kysely/types.js +428 -0
- package/dist/plugins/kysely/types.js.map +1 -0
- package/dist/plugins/kysely.d.ts +72 -0
- package/dist/plugins/kysely.d.ts.map +1 -0
- package/dist/plugins/kysely.js +906 -0
- package/dist/plugins/kysely.js.map +1 -0
- package/dist/plugins/sql-queries.d.ts +55 -11
- package/dist/plugins/sql-queries.d.ts.map +1 -1
- package/dist/plugins/sql-queries.js +467 -218
- package/dist/plugins/sql-queries.js.map +1 -1
- package/dist/plugins/types.d.ts +20 -14
- package/dist/plugins/types.d.ts.map +1 -1
- package/dist/plugins/types.js +90 -112
- package/dist/plugins/types.js.map +1 -1
- package/dist/plugins/valibot.d.ts +45 -0
- package/dist/plugins/valibot.d.ts.map +1 -0
- package/dist/plugins/valibot.js +422 -0
- package/dist/plugins/valibot.js.map +1 -0
- package/dist/plugins/zod.d.ts +27 -14
- package/dist/plugins/zod.d.ts.map +1 -1
- package/dist/plugins/zod.js +231 -166
- package/dist/plugins/zod.js.map +1 -1
- package/dist/services/artifact-store.d.ts +11 -1
- package/dist/services/artifact-store.d.ts.map +1 -1
- package/dist/services/artifact-store.js +9 -0
- package/dist/services/artifact-store.js.map +1 -1
- package/dist/services/core-providers.d.ts +15 -0
- package/dist/services/core-providers.d.ts.map +1 -0
- package/dist/services/core-providers.js +23 -0
- package/dist/services/core-providers.js.map +1 -0
- package/dist/services/emissions.d.ts +14 -0
- package/dist/services/emissions.d.ts.map +1 -1
- package/dist/services/emissions.js +86 -47
- package/dist/services/emissions.js.map +1 -1
- package/dist/services/execution.d.ts +35 -0
- package/dist/services/execution.d.ts.map +1 -0
- package/dist/services/execution.js +86 -0
- package/dist/services/execution.js.map +1 -0
- package/dist/services/file-builder.d.ts +4 -0
- package/dist/services/file-builder.d.ts.map +1 -1
- package/dist/services/file-builder.js.map +1 -1
- package/dist/services/inflection.d.ts +2 -2
- package/dist/services/inflection.d.ts.map +1 -1
- package/dist/services/inflection.js +4 -4
- package/dist/services/inflection.js.map +1 -1
- package/dist/services/ir-builder.d.ts.map +1 -1
- package/dist/services/ir-builder.js +10 -3
- package/dist/services/ir-builder.js.map +1 -1
- package/dist/services/pg-types.d.ts +31 -0
- package/dist/services/pg-types.d.ts.map +1 -1
- package/dist/services/pg-types.js +24 -0
- package/dist/services/pg-types.js.map +1 -1
- package/dist/services/plugin-runner.d.ts +27 -37
- package/dist/services/plugin-runner.d.ts.map +1 -1
- package/dist/services/plugin-runner.js +73 -171
- package/dist/services/plugin-runner.js.map +1 -1
- package/dist/services/plugin.d.ts +349 -217
- package/dist/services/plugin.d.ts.map +1 -1
- package/dist/services/plugin.js +182 -130
- package/dist/services/plugin.js.map +1 -1
- package/dist/services/resolution.d.ts +38 -0
- package/dist/services/resolution.d.ts.map +1 -0
- package/dist/services/resolution.js +242 -0
- package/dist/services/resolution.js.map +1 -0
- package/dist/services/service-registry.d.ts +74 -0
- package/dist/services/service-registry.d.ts.map +1 -0
- package/dist/services/service-registry.js +61 -0
- package/dist/services/service-registry.js.map +1 -0
- package/dist/services/symbols.d.ts +59 -0
- package/dist/services/symbols.d.ts.map +1 -1
- package/dist/services/symbols.js +16 -0
- package/dist/services/symbols.js.map +1 -1
- package/dist/testing.d.ts +4 -25
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +2 -23
- package/dist/testing.js.map +1 -1
- package/package.json +1 -1
- package/dist/plugins/effect-model.d.ts +0 -17
- package/dist/plugins/effect-model.d.ts.map +0 -1
- package/dist/plugins/effect-model.js +0 -409
- package/dist/plugins/effect-model.js.map +0 -1
- package/dist/plugins/kysely-queries.d.ts +0 -66
- package/dist/plugins/kysely-queries.d.ts.map +0 -1
- package/dist/plugins/kysely-queries.js +0 -951
- package/dist/plugins/kysely-queries.js.map +0 -1
- package/dist/plugins/kysely-types.d.ts +0 -35
- package/dist/plugins/kysely-types.d.ts.map +0 -1
- package/dist/plugins/kysely-types.js +0 -601
- package/dist/plugins/kysely-types.js.map +0 -1
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Valibot Plugin - Generate Valibot schemas for entities
|
|
3
|
+
*
|
|
4
|
+
* Generates Valibot schemas for Row, Insert, Update, and Patch shapes,
|
|
5
|
+
* with inferred TypeScript types.
|
|
6
|
+
*/
|
|
7
|
+
import { Array as Arr, Option, pipe, Schema as S } from "effect";
|
|
8
|
+
import { definePlugin } from "../services/plugin.js";
|
|
9
|
+
import { findEnumByPgName, TsType } from "../services/pg-types.js";
|
|
10
|
+
import { getTableEntities, getEnumEntities, getCompositeEntities } from "../ir/semantic-ir.js";
|
|
11
|
+
import { conjure } from "../lib/conjure.js";
|
|
12
|
+
import { isUuidType, isDateType, isEnumType, getPgTypeName, resolveFieldType, } from "../lib/field-utils.js";
|
|
13
|
+
import { SCHEMA_BUILDER_KIND, } from "../ir/extensions/schema-builder.js";
|
|
14
|
+
const { ts, exp, obj, b } = conjure;
|
|
15
|
+
// ============================================================================
|
|
16
|
+
// Configuration
|
|
17
|
+
// ============================================================================
|
|
18
|
+
const ValibotConfigSchema = S.Struct({
|
|
19
|
+
/** Output directory relative to main outputDir */
|
|
20
|
+
outputDir: S.optionalWith(S.String, { default: () => "valibot" }),
|
|
21
|
+
/** Export inferred types alongside schemas */
|
|
22
|
+
exportTypes: S.optionalWith(S.Boolean, { default: () => true }),
|
|
23
|
+
/** How to represent enum values: 'strings' uses v.picklist([...]), 'enum' uses v.enum(TsEnum) */
|
|
24
|
+
enumStyle: S.optionalWith(S.Union(S.Literal("strings"), S.Literal("enum")), {
|
|
25
|
+
default: () => "strings",
|
|
26
|
+
}),
|
|
27
|
+
/** Where to define enum types: 'inline' embeds at usage, 'separate' generates enum files */
|
|
28
|
+
typeReferences: S.optionalWith(S.Union(S.Literal("inline"), S.Literal("separate")), {
|
|
29
|
+
default: () => "separate",
|
|
30
|
+
}),
|
|
31
|
+
});
|
|
32
|
+
// ============================================================================
|
|
33
|
+
// Valibot Schema Builders (pure functions)
|
|
34
|
+
// ============================================================================
|
|
35
|
+
// ============================================================================
|
|
36
|
+
// Valibot Schema Builders (pure functions)
|
|
37
|
+
// ============================================================================
|
|
38
|
+
/**
|
|
39
|
+
* Build v.<method>() call
|
|
40
|
+
*/
|
|
41
|
+
const buildValibotCall = (method, args = []) => conjure
|
|
42
|
+
.id("v")
|
|
43
|
+
.method(method, [...args])
|
|
44
|
+
.build();
|
|
45
|
+
/**
|
|
46
|
+
* Build v.picklist([...values])
|
|
47
|
+
*/
|
|
48
|
+
const buildValibotPicklist = (values) => buildValibotCall("picklist", [conjure.arr(...values.map(v => conjure.str(v))).build()]);
|
|
49
|
+
/**
|
|
50
|
+
* Build v.array(<inner>)
|
|
51
|
+
*/
|
|
52
|
+
const buildValibotArray = (inner) => buildValibotCall("array", [inner]);
|
|
53
|
+
/**
|
|
54
|
+
* Wrap expression with v.nullable(...)
|
|
55
|
+
*/
|
|
56
|
+
const wrapNullable = (expr) => buildValibotCall("nullable", [expr]);
|
|
57
|
+
/**
|
|
58
|
+
* Wrap expression with v.optional(...)
|
|
59
|
+
*/
|
|
60
|
+
const wrapOptional = (expr) => buildValibotCall("optional", [expr]);
|
|
61
|
+
/**
|
|
62
|
+
* Map TypeScript type to Valibot method name
|
|
63
|
+
*/
|
|
64
|
+
const tsTypeToValibotMethod = (tsType) => {
|
|
65
|
+
switch (tsType) {
|
|
66
|
+
case TsType.String:
|
|
67
|
+
return "string";
|
|
68
|
+
case TsType.Number:
|
|
69
|
+
return "number";
|
|
70
|
+
case TsType.Boolean:
|
|
71
|
+
return "boolean";
|
|
72
|
+
case TsType.BigInt:
|
|
73
|
+
return "bigint";
|
|
74
|
+
case TsType.Date:
|
|
75
|
+
return "date";
|
|
76
|
+
case TsType.Buffer:
|
|
77
|
+
case TsType.Unknown:
|
|
78
|
+
default:
|
|
79
|
+
return "unknown";
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Apply nullable/optional/array modifiers to a base schema
|
|
84
|
+
* Order matters: array wraps first, then nullable, then optional
|
|
85
|
+
*/
|
|
86
|
+
const applyFieldModifiers = (schema, field) => {
|
|
87
|
+
let result = schema;
|
|
88
|
+
// Array wrapping first
|
|
89
|
+
if (field.isArray) {
|
|
90
|
+
result = buildValibotArray(result);
|
|
91
|
+
}
|
|
92
|
+
// Nullable wrapping
|
|
93
|
+
if (field.nullable) {
|
|
94
|
+
result = wrapNullable(result);
|
|
95
|
+
}
|
|
96
|
+
// Optional wrapping
|
|
97
|
+
if (field.optional) {
|
|
98
|
+
result = wrapOptional(result);
|
|
99
|
+
}
|
|
100
|
+
return result;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Resolve a field to its Valibot schema expression
|
|
104
|
+
*/
|
|
105
|
+
const resolveFieldValibotSchema = (field, ctx) => {
|
|
106
|
+
const resolved = resolveFieldType(field, ctx.enums, ctx.extensions);
|
|
107
|
+
// Enum handling
|
|
108
|
+
if (resolved.enumDef) {
|
|
109
|
+
let enumSchema;
|
|
110
|
+
if (ctx.typeReferences === "separate") {
|
|
111
|
+
// Reference by name - the enum schema is imported
|
|
112
|
+
enumSchema = conjure.id(resolved.enumDef.name).build();
|
|
113
|
+
}
|
|
114
|
+
else if (ctx.enumStyle === "enum") {
|
|
115
|
+
// Inline native enum: v.enum(EnumName)
|
|
116
|
+
// Note: This requires the TS enum to be generated separately
|
|
117
|
+
enumSchema = buildValibotCall("enum", [conjure.id(resolved.enumDef.name).build()]);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
// Inline strings: v.picklist(['a', 'b', 'c'])
|
|
121
|
+
enumSchema = buildValibotPicklist(resolved.enumDef.values);
|
|
122
|
+
}
|
|
123
|
+
return applyFieldModifiers(enumSchema, field);
|
|
124
|
+
}
|
|
125
|
+
// UUID → v.pipe(v.string(), v.uuid())
|
|
126
|
+
if (isUuidType(field)) {
|
|
127
|
+
const uuidSchema = buildValibotCall("pipe", [
|
|
128
|
+
buildValibotCall("string"),
|
|
129
|
+
buildValibotCall("uuid"),
|
|
130
|
+
]);
|
|
131
|
+
return applyFieldModifiers(uuidSchema, field);
|
|
132
|
+
}
|
|
133
|
+
// Date/timestamp → v.date()
|
|
134
|
+
if (isDateType(field)) {
|
|
135
|
+
return applyFieldModifiers(buildValibotCall("date"), field);
|
|
136
|
+
}
|
|
137
|
+
// Standard type mapping
|
|
138
|
+
return applyFieldModifiers(buildValibotCall(tsTypeToValibotMethod(resolved.tsType)), field);
|
|
139
|
+
};
|
|
140
|
+
// ============================================================================
|
|
141
|
+
// Shape → Statement Generation
|
|
142
|
+
// ============================================================================
|
|
143
|
+
/**
|
|
144
|
+
* Build v.object({...}) expression from shape fields
|
|
145
|
+
*/
|
|
146
|
+
const buildShapeValibotObject = (shape, ctx) => {
|
|
147
|
+
const objBuilder = shape.fields.reduce((builder, field) => builder.prop(field.name, resolveFieldValibotSchema(field, ctx)), obj());
|
|
148
|
+
return buildValibotCall("object", [objBuilder.build()]);
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* Generate schema const + optional inferred type for a shape
|
|
152
|
+
*/
|
|
153
|
+
const generateShapeStatements = (shape, entityName, shapeKind, ctx, exportTypes) => {
|
|
154
|
+
const schemaSymbolCtx = { capability: "schemas", entity: entityName, shape: shapeKind };
|
|
155
|
+
const schemaExpr = buildShapeValibotObject(shape, ctx);
|
|
156
|
+
const schemaStatement = exp.const(shape.name, schemaSymbolCtx, schemaExpr);
|
|
157
|
+
if (!exportTypes) {
|
|
158
|
+
return [schemaStatement];
|
|
159
|
+
}
|
|
160
|
+
// Generate: export type ShapeName = v.InferOutput<typeof ShapeName>
|
|
161
|
+
// Register under "types" capability so other plugins can import
|
|
162
|
+
const typeSymbolCtx = { capability: "types", entity: entityName, shape: shapeKind };
|
|
163
|
+
const inferType = ts.qualifiedRef("v", "InferOutput", [ts.typeof(shape.name)]);
|
|
164
|
+
const typeStatement = exp.type(shape.name, typeSymbolCtx, inferType);
|
|
165
|
+
return [schemaStatement, typeStatement];
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* Collect all defined shapes from an entity as [kind, shape] pairs
|
|
169
|
+
*/
|
|
170
|
+
const collectShapes = (entity) => [
|
|
171
|
+
["row", entity.shapes.row],
|
|
172
|
+
["insert", entity.shapes.insert],
|
|
173
|
+
["update", entity.shapes.update],
|
|
174
|
+
].filter((entry) => entry[1] != null);
|
|
175
|
+
/**
|
|
176
|
+
* Generate all statements for an entity's shapes
|
|
177
|
+
*/
|
|
178
|
+
const generateEntityStatements = (entity, ctx, exportTypes) => collectShapes(entity).flatMap(([kind, shape]) => generateShapeStatements(shape, entity.name, kind, ctx, exportTypes));
|
|
179
|
+
// ============================================================================
|
|
180
|
+
// Composite Type Generation
|
|
181
|
+
// ============================================================================
|
|
182
|
+
/**
|
|
183
|
+
* Build v.object({...}) expression from composite fields
|
|
184
|
+
*/
|
|
185
|
+
const buildCompositeValibotObject = (composite, ctx) => {
|
|
186
|
+
const objBuilder = composite.fields.reduce((builder, field) => builder.prop(field.name, resolveFieldValibotSchema(field, ctx)), obj());
|
|
187
|
+
return buildValibotCall("object", [objBuilder.build()]);
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* Generate schema const + optional inferred type for a composite type
|
|
191
|
+
*/
|
|
192
|
+
const generateCompositeStatements = (composite, ctx, exportTypes) => {
|
|
193
|
+
const schemaSymbolCtx = { capability: "schemas", entity: composite.name };
|
|
194
|
+
const schemaExpr = buildCompositeValibotObject(composite, ctx);
|
|
195
|
+
const schemaStatement = exp.const(composite.name, schemaSymbolCtx, schemaExpr);
|
|
196
|
+
if (!exportTypes) {
|
|
197
|
+
return [schemaStatement];
|
|
198
|
+
}
|
|
199
|
+
// Generate: export type CompositeName = v.InferOutput<typeof CompositeName>
|
|
200
|
+
// Register under "types" capability so other plugins can import
|
|
201
|
+
const typeSymbolCtx = { capability: "types", entity: composite.name };
|
|
202
|
+
const inferType = ts.qualifiedRef("v", "InferOutput", [ts.typeof(composite.name)]);
|
|
203
|
+
const typeStatement = exp.type(composite.name, typeSymbolCtx, inferType);
|
|
204
|
+
return [schemaStatement, typeStatement];
|
|
205
|
+
};
|
|
206
|
+
// ============================================================================
|
|
207
|
+
// Enum Generation
|
|
208
|
+
// ============================================================================
|
|
209
|
+
/**
|
|
210
|
+
* Generate enum schema statement: export const EnumName = v.picklist(['a', 'b', ...])
|
|
211
|
+
* or for native enums: export enum EnumName { A = 'a', ... } + schema
|
|
212
|
+
*/
|
|
213
|
+
const generateEnumStatement = (enumEntity, enumStyle, exportTypes) => {
|
|
214
|
+
const schemaSymbolCtx = { capability: "schemas", entity: enumEntity.name };
|
|
215
|
+
if (enumStyle === "enum") {
|
|
216
|
+
// Generate: export enum EnumName { A = 'a', B = 'b', ... }
|
|
217
|
+
// Then: export const EnumNameSchema = v.enum(EnumName)
|
|
218
|
+
const enumStatement = exp.tsEnum(enumEntity.name, { capability: "types", entity: enumEntity.name }, enumEntity.values);
|
|
219
|
+
const schemaName = `${enumEntity.name}Schema`;
|
|
220
|
+
const schemaExpr = buildValibotCall("enum", [conjure.id(enumEntity.name).build()]);
|
|
221
|
+
const schemaStatement = exp.const(schemaName, schemaSymbolCtx, schemaExpr);
|
|
222
|
+
return [enumStatement, schemaStatement];
|
|
223
|
+
}
|
|
224
|
+
// strings style: export const EnumName = v.picklist(['a', 'b', ...])
|
|
225
|
+
const schemaExpr = buildValibotPicklist(enumEntity.values);
|
|
226
|
+
const schemaStatement = exp.const(enumEntity.name, schemaSymbolCtx, schemaExpr);
|
|
227
|
+
if (!exportTypes) {
|
|
228
|
+
return [schemaStatement];
|
|
229
|
+
}
|
|
230
|
+
// Generate: export type EnumName = v.InferOutput<typeof EnumName>
|
|
231
|
+
// Register under "types" capability so other plugins can import
|
|
232
|
+
const typeSymbolCtx = { capability: "types", entity: enumEntity.name };
|
|
233
|
+
const inferType = ts.qualifiedRef("v", "InferOutput", [ts.typeof(enumEntity.name)]);
|
|
234
|
+
const typeStatement = exp.type(enumEntity.name, typeSymbolCtx, inferType);
|
|
235
|
+
return [schemaStatement, typeStatement];
|
|
236
|
+
};
|
|
237
|
+
/** Collect enum names used by fields */
|
|
238
|
+
const collectUsedEnums = (fields, enums) => {
|
|
239
|
+
const enumNames = fields.filter(isEnumType).flatMap(field => {
|
|
240
|
+
const pgTypeName = getPgTypeName(field);
|
|
241
|
+
if (!pgTypeName)
|
|
242
|
+
return [];
|
|
243
|
+
return pipe(findEnumByPgName(enums, pgTypeName), Option.map(e => e.name), Option.toArray);
|
|
244
|
+
});
|
|
245
|
+
return new Set(enumNames);
|
|
246
|
+
};
|
|
247
|
+
/** Build import refs for used enums */
|
|
248
|
+
const buildEnumImports = (usedEnums) => Arr.fromIterable(usedEnums).map(enumName => ({
|
|
249
|
+
kind: "symbol",
|
|
250
|
+
ref: { capability: "schemas", entity: enumName },
|
|
251
|
+
}));
|
|
252
|
+
// ============================================================================
|
|
253
|
+
// Param Schema Builder (for HTTP plugins)
|
|
254
|
+
// ============================================================================
|
|
255
|
+
/**
|
|
256
|
+
* Build Valibot schema expression for a single param.
|
|
257
|
+
* Uses v.pipe(v.string(), v.transform(...)) for type coercion since URL params are strings.
|
|
258
|
+
*/
|
|
259
|
+
const buildParamFieldSchema = (param) => {
|
|
260
|
+
const tsType = param.type.toLowerCase();
|
|
261
|
+
let fieldSchema;
|
|
262
|
+
switch (tsType) {
|
|
263
|
+
case "number":
|
|
264
|
+
// v.pipe(v.string(), v.transform(Number))
|
|
265
|
+
fieldSchema = buildValibotCall("pipe", [
|
|
266
|
+
buildValibotCall("string"),
|
|
267
|
+
buildValibotCall("transform", [conjure.id("Number").build()]),
|
|
268
|
+
]);
|
|
269
|
+
break;
|
|
270
|
+
case "boolean":
|
|
271
|
+
// v.pipe(v.string(), v.transform(v => v === 'true'))
|
|
272
|
+
fieldSchema = buildValibotCall("pipe", [
|
|
273
|
+
buildValibotCall("string"),
|
|
274
|
+
buildValibotCall("transform", [
|
|
275
|
+
b.arrowFunctionExpression([b.identifier("v")], b.binaryExpression("===", b.identifier("v"), b.stringLiteral("true"))),
|
|
276
|
+
]),
|
|
277
|
+
]);
|
|
278
|
+
break;
|
|
279
|
+
case "bigint":
|
|
280
|
+
// v.pipe(v.string(), v.transform(BigInt))
|
|
281
|
+
fieldSchema = buildValibotCall("pipe", [
|
|
282
|
+
buildValibotCall("string"),
|
|
283
|
+
buildValibotCall("transform", [conjure.id("BigInt").build()]),
|
|
284
|
+
]);
|
|
285
|
+
break;
|
|
286
|
+
case "date":
|
|
287
|
+
// v.pipe(v.string(), v.transform(s => new Date(s)))
|
|
288
|
+
fieldSchema = buildValibotCall("pipe", [
|
|
289
|
+
buildValibotCall("string"),
|
|
290
|
+
buildValibotCall("transform", [
|
|
291
|
+
b.arrowFunctionExpression([b.identifier("s")], b.newExpression(b.identifier("Date"), [b.identifier("s")])),
|
|
292
|
+
]),
|
|
293
|
+
]);
|
|
294
|
+
break;
|
|
295
|
+
case "string":
|
|
296
|
+
default:
|
|
297
|
+
// v.string()
|
|
298
|
+
fieldSchema = buildValibotCall("string");
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
// Add v.optional(...) for non-required params
|
|
302
|
+
if (!param.required) {
|
|
303
|
+
fieldSchema = wrapOptional(fieldSchema);
|
|
304
|
+
}
|
|
305
|
+
return fieldSchema;
|
|
306
|
+
};
|
|
307
|
+
/**
|
|
308
|
+
* Build v.object({ ... }) expression from QueryMethodParam[].
|
|
309
|
+
*/
|
|
310
|
+
const buildParamValibotObject = (params) => {
|
|
311
|
+
const objBuilder = params.reduce((builder, param) => builder.prop(param.name, buildParamFieldSchema(param)), obj());
|
|
312
|
+
return buildValibotCall("object", [objBuilder.build()]);
|
|
313
|
+
};
|
|
314
|
+
/**
|
|
315
|
+
* Create a SchemaBuilder implementation for Valibot.
|
|
316
|
+
*/
|
|
317
|
+
const createValibotSchemaBuilder = () => ({
|
|
318
|
+
build: (request) => {
|
|
319
|
+
if (request.params.length === 0) {
|
|
320
|
+
return undefined;
|
|
321
|
+
}
|
|
322
|
+
const ast = buildParamValibotObject(request.params);
|
|
323
|
+
return {
|
|
324
|
+
ast,
|
|
325
|
+
importSpec: {
|
|
326
|
+
namespace: "v",
|
|
327
|
+
from: "valibot",
|
|
328
|
+
},
|
|
329
|
+
};
|
|
330
|
+
},
|
|
331
|
+
});
|
|
332
|
+
// ============================================================================
|
|
333
|
+
// Provider Definition
|
|
334
|
+
// ============================================================================
|
|
335
|
+
/**
|
|
336
|
+
* Create a valibot provider that generates Valibot schemas.
|
|
337
|
+
*
|
|
338
|
+
* @example
|
|
339
|
+
* ```typescript
|
|
340
|
+
* import { valibot } from "pg-sourcerer"
|
|
341
|
+
*
|
|
342
|
+
* export default defineConfig({
|
|
343
|
+
* plugins: [
|
|
344
|
+
* valibot(),
|
|
345
|
+
* valibot({ outputDir: "schemas", exportTypes: false }),
|
|
346
|
+
* ],
|
|
347
|
+
* })
|
|
348
|
+
* ```
|
|
349
|
+
*/
|
|
350
|
+
export function valibot(config = {}) {
|
|
351
|
+
const parsed = S.decodeUnknownSync(ValibotConfigSchema)(config);
|
|
352
|
+
return definePlugin({
|
|
353
|
+
name: "valibot",
|
|
354
|
+
kind: "schemas",
|
|
355
|
+
singleton: true,
|
|
356
|
+
canProvide: () => true,
|
|
357
|
+
provide: (_params, _deps, ctx) => {
|
|
358
|
+
const { ir, inflection } = ctx;
|
|
359
|
+
const enumEntities = getEnumEntities(ir);
|
|
360
|
+
// Register schema-builder service for on-demand param/query schema generation
|
|
361
|
+
ctx.registerHandler(SCHEMA_BUILDER_KIND, createValibotSchemaBuilder().build);
|
|
362
|
+
const fieldCtx = {
|
|
363
|
+
enums: enumEntities,
|
|
364
|
+
extensions: ir.extensions,
|
|
365
|
+
enumStyle: parsed.enumStyle,
|
|
366
|
+
typeReferences: parsed.typeReferences,
|
|
367
|
+
};
|
|
368
|
+
// Helper to build file path
|
|
369
|
+
const buildFilePath = (entityName) => `${parsed.outputDir}/${entityName}.ts`;
|
|
370
|
+
// Generate separate enum files if configured
|
|
371
|
+
if (parsed.typeReferences === "separate") {
|
|
372
|
+
enumEntities
|
|
373
|
+
.filter(e => e.tags.omit !== true)
|
|
374
|
+
.forEach(enumEntity => {
|
|
375
|
+
const statements = generateEnumStatement(enumEntity, parsed.enumStyle, parsed.exportTypes);
|
|
376
|
+
ctx
|
|
377
|
+
.file(buildFilePath(enumEntity.name))
|
|
378
|
+
.import({ kind: "package", namespace: "v", from: "valibot" })
|
|
379
|
+
.ast(conjure.symbolProgram(...statements))
|
|
380
|
+
.emit();
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
getTableEntities(ir)
|
|
384
|
+
.filter(entity => entity.tags.omit !== true)
|
|
385
|
+
.forEach(entity => {
|
|
386
|
+
const statements = generateEntityStatements(entity, fieldCtx, parsed.exportTypes);
|
|
387
|
+
const entityName = inflection.entityName(entity.pgClass, entity.tags);
|
|
388
|
+
// Collect all fields for enum detection
|
|
389
|
+
const allFields = [
|
|
390
|
+
...entity.shapes.row.fields,
|
|
391
|
+
...(entity.shapes.insert?.fields ?? []),
|
|
392
|
+
...(entity.shapes.update?.fields ?? []),
|
|
393
|
+
];
|
|
394
|
+
const usedEnums = parsed.typeReferences === "separate"
|
|
395
|
+
? collectUsedEnums(allFields, Arr.fromIterable(fieldCtx.enums))
|
|
396
|
+
: new Set();
|
|
397
|
+
const fileBuilder = ctx
|
|
398
|
+
.file(buildFilePath(entityName))
|
|
399
|
+
.import({ kind: "package", namespace: "v", from: "valibot" });
|
|
400
|
+
// Add enum imports when using separate files
|
|
401
|
+
buildEnumImports(usedEnums).forEach(ref => fileBuilder.import(ref));
|
|
402
|
+
fileBuilder.ast(conjure.symbolProgram(...statements)).emit();
|
|
403
|
+
});
|
|
404
|
+
// Generate composite type schemas
|
|
405
|
+
getCompositeEntities(ir)
|
|
406
|
+
.filter(composite => composite.tags.omit !== true)
|
|
407
|
+
.forEach(composite => {
|
|
408
|
+
const statements = generateCompositeStatements(composite, fieldCtx, parsed.exportTypes);
|
|
409
|
+
// Collect enum usage for imports
|
|
410
|
+
const usedEnums = parsed.typeReferences === "separate"
|
|
411
|
+
? collectUsedEnums(composite.fields, Arr.fromIterable(fieldCtx.enums))
|
|
412
|
+
: new Set();
|
|
413
|
+
const fileBuilder = ctx
|
|
414
|
+
.file(buildFilePath(composite.name))
|
|
415
|
+
.import({ kind: "package", namespace: "v", from: "valibot" });
|
|
416
|
+
buildEnumImports(usedEnums).forEach(ref => fileBuilder.import(ref));
|
|
417
|
+
fileBuilder.ast(conjure.symbolProgram(...statements)).emit();
|
|
418
|
+
});
|
|
419
|
+
},
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
//# sourceMappingURL=valibot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"valibot.js","sourceRoot":"","sources":["../../src/plugins/valibot.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,KAAK,IAAI,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,QAAQ,CAAC;AAEjE,OAAO,EAAE,YAAY,EAAsB,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AASnE,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC/F,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAG5C,OAAO,EACL,UAAU,EACV,UAAU,EACV,UAAU,EACV,aAAa,EACb,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,mBAAmB,GAIpB,MAAM,oCAAoC,CAAC;AAG5C,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC;AAEpC,+EAA+E;AAC/E,gBAAgB;AAChB,+EAA+E;AAE/E,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,kDAAkD;IAClD,SAAS,EAAE,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS,EAAE,CAAC;IACjE,8CAA8C;IAC9C,WAAW,EAAE,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC;IAC/D,iGAAiG;IACjG,SAA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ACP,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/dist/plugins/zod.d.ts
CHANGED
|
@@ -1,18 +1,31 @@
|
|
|
1
|
+
import { definePlugin } from "../services/plugin.js";
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
+
* Configuration for the zod provider
|
|
4
|
+
*/
|
|
5
|
+
export interface ZodConfig {
|
|
6
|
+
/** Output directory relative to main outputDir */
|
|
7
|
+
readonly outputDir?: string;
|
|
8
|
+
/** Export inferred types alongside schemas */
|
|
9
|
+
readonly exportTypes?: boolean;
|
|
10
|
+
/** How to represent enum values: 'strings' uses z.enum([...]), 'enum' uses z.nativeEnum(TsEnum) */
|
|
11
|
+
readonly enumStyle?: "strings" | "enum";
|
|
12
|
+
/** Where to define enum types: 'inline' embeds at usage, 'separate' generates enum files */
|
|
13
|
+
readonly typeReferences?: "inline" | "separate";
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Create a zod provider that generates Zod schemas.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { zod } from "pg-sourcerer"
|
|
3
21
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
22
|
+
* export default defineConfig({
|
|
23
|
+
* plugins: [
|
|
24
|
+
* zod(),
|
|
25
|
+
* zod({ outputDir: "schemas", exportTypes: false }),
|
|
26
|
+
* ],
|
|
27
|
+
* })
|
|
28
|
+
* ```
|
|
6
29
|
*/
|
|
7
|
-
export declare
|
|
8
|
-
readonly outputDir: string;
|
|
9
|
-
readonly exportTypes: boolean;
|
|
10
|
-
readonly enumStyle: "enum" | "strings";
|
|
11
|
-
readonly typeReferences: "inline" | "separate";
|
|
12
|
-
}, {
|
|
13
|
-
readonly outputDir?: string | undefined;
|
|
14
|
-
readonly exportTypes?: boolean | undefined;
|
|
15
|
-
readonly enumStyle?: "enum" | "strings" | undefined;
|
|
16
|
-
readonly typeReferences?: "inline" | "separate" | undefined;
|
|
17
|
-
}>;
|
|
30
|
+
export declare function zod(config?: ZodConfig): ReturnType<typeof definePlugin>;
|
|
18
31
|
//# sourceMappingURL=zod.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../../src/plugins/zod.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../../src/plugins/zod.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,YAAY,EAAsB,MAAM,uBAAuB,CAAC;AAmCzE;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,kDAAkD;IAClD,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAC3B,8CAA8C;IAC9C,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAA;IAC9B,mGAAmG;IACnG,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,MAAM,CAAA;IACvC,4FAA4F;IAC5F,QAAQ,CAAC,cAAc,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAA;CAChD;AA2ZD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,GAAG,CAAC,MAAM,GAAE,SAAc,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CA+F3E"}
|