@danielfgray/pg-sourcerer 0.2.0 → 0.2.2
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 +25 -19
- 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 +31 -21
- package/dist/generate.d.ts.map +1 -1
- package/dist/generate.js +53 -43
- package/dist/generate.js.map +1 -1
- package/dist/index.d.ts +20 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -13
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +0 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +90 -35
- 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 +101 -0
- package/dist/lib/conjure.d.ts.map +1 -1
- package/dist/lib/conjure.js +204 -26
- package/dist/lib/conjure.js.map +1 -1
- package/dist/lib/hex.d.ts +10 -8
- package/dist/lib/hex.d.ts.map +1 -1
- package/dist/lib/hex.js +18 -15
- 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 -7
- package/dist/plugins/sql-queries.d.ts.map +1 -1
- package/dist/plugins/sql-queries.js +747 -121
- 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/config-loader.d.ts +4 -0
- package/dist/services/config-loader.d.ts.map +1 -1
- package/dist/services/config-loader.js +1 -1
- package/dist/services/config-loader.js.map +1 -1
- package/dist/services/config.d.ts +57 -0
- package/dist/services/config.d.ts.map +1 -0
- package/dist/services/config.js +66 -0
- package/dist/services/config.js.map +1 -0
- 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 +350 -215
- 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 -960
- 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,370 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP oRPC Plugin - Generate oRPC routers from query plugins
|
|
3
|
+
*
|
|
4
|
+
* Consumes method symbols from sql-queries or kysely-queries via the symbol registry
|
|
5
|
+
* and generates type-safe oRPC procedures using @orpc/server.
|
|
6
|
+
*
|
|
7
|
+
* Uses oRPC's `type()` utility for simple params (type-only, no runtime validation)
|
|
8
|
+
* and imports body schemas from whatever plugin provides the "schemas" capability
|
|
9
|
+
* (zod, arktype, valibot, etc.) for runtime validation.
|
|
10
|
+
*/
|
|
11
|
+
import { Schema as S } from "effect";
|
|
12
|
+
import { definePlugin } from "../services/plugin.js";
|
|
13
|
+
import { conjure, cast } from "../lib/conjure.js";
|
|
14
|
+
import { inflect } from "../services/inflection.js";
|
|
15
|
+
const { b } = conjure;
|
|
16
|
+
// ============================================================================
|
|
17
|
+
// Configuration Schema
|
|
18
|
+
// ============================================================================
|
|
19
|
+
const HttpOrpcConfigSchema = S.Struct({
|
|
20
|
+
/** Output directory for generated router files. Default: "orpc" */
|
|
21
|
+
outputDir: S.optionalWith(S.String, { default: () => "orpc" }),
|
|
22
|
+
/**
|
|
23
|
+
* Header content to prepend to each generated file.
|
|
24
|
+
* MUST import `os` from @orpc/server.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* header: `import { os } from "@orpc/server";`
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
header: S.String,
|
|
32
|
+
/** Name of the aggregated router export. Default: "appRouter" */
|
|
33
|
+
aggregatorName: S.optionalWith(S.String, { default: () => "appRouter" }),
|
|
34
|
+
});
|
|
35
|
+
// ============================================================================
|
|
36
|
+
// Type String Builders (for oRPC type<>() utility)
|
|
37
|
+
// ============================================================================
|
|
38
|
+
/**
|
|
39
|
+
* Convert a QueryMethodParam to a TypeScript type string for use in type<>().
|
|
40
|
+
*/
|
|
41
|
+
const paramToTypeString = (param) => {
|
|
42
|
+
const baseType = param.type.replace(/\[\]$/, "").replace(/\?$/, "").toLowerCase();
|
|
43
|
+
let tsType;
|
|
44
|
+
switch (baseType) {
|
|
45
|
+
case "number":
|
|
46
|
+
case "int":
|
|
47
|
+
case "integer":
|
|
48
|
+
case "float":
|
|
49
|
+
case "double":
|
|
50
|
+
tsType = "number";
|
|
51
|
+
break;
|
|
52
|
+
case "boolean":
|
|
53
|
+
case "bool":
|
|
54
|
+
tsType = "boolean";
|
|
55
|
+
break;
|
|
56
|
+
case "date":
|
|
57
|
+
tsType = "Date";
|
|
58
|
+
break;
|
|
59
|
+
case "string":
|
|
60
|
+
default:
|
|
61
|
+
tsType = "string";
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
// Handle arrays
|
|
65
|
+
if (param.type.endsWith("[]")) {
|
|
66
|
+
tsType = `${tsType}[]`;
|
|
67
|
+
}
|
|
68
|
+
// Handle optionality
|
|
69
|
+
if (!param.required) {
|
|
70
|
+
tsType = `${tsType} | undefined`;
|
|
71
|
+
}
|
|
72
|
+
return tsType;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Build a TypeScript object type literal string for type<>().
|
|
76
|
+
* Returns something like "{ id: number; name?: string }"
|
|
77
|
+
*/
|
|
78
|
+
const buildTypeObjectString = (params) => {
|
|
79
|
+
if (params.length === 0)
|
|
80
|
+
return "{}";
|
|
81
|
+
const fields = params.map((param) => {
|
|
82
|
+
const typeStr = paramToTypeString(param);
|
|
83
|
+
const optional = !param.required ? "?" : "";
|
|
84
|
+
return `${param.name}${optional}: ${typeStr.replace(" | undefined", "")}`;
|
|
85
|
+
});
|
|
86
|
+
return `{ ${fields.join("; ")} }`;
|
|
87
|
+
};
|
|
88
|
+
// ============================================================================
|
|
89
|
+
// Procedure Builders
|
|
90
|
+
// ============================================================================
|
|
91
|
+
/**
|
|
92
|
+
* Build the handler function body for a procedure.
|
|
93
|
+
* oRPC handlers receive { input, context } and return data directly.
|
|
94
|
+
*/
|
|
95
|
+
const buildProcedureBody = (queryFnName, method) => {
|
|
96
|
+
const callSig = method.callSignature ?? { style: "named" };
|
|
97
|
+
const statements = [];
|
|
98
|
+
// Build the function call arguments based on callSignature
|
|
99
|
+
const args = [];
|
|
100
|
+
if (callSig.style === "positional") {
|
|
101
|
+
// Positional: fn(a, b, c)
|
|
102
|
+
for (const param of method.params) {
|
|
103
|
+
args.push(b.memberExpression(b.identifier("input"), b.identifier(param.name)));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
// Named: fn({ a, b, c }) or fn(input) for body
|
|
108
|
+
const bodyParam = method.params.find((p) => p.source === "body");
|
|
109
|
+
if (bodyParam && callSig.bodyStyle === "spread") {
|
|
110
|
+
// Body fields spread directly: fn(input)
|
|
111
|
+
args.push(b.identifier("input"));
|
|
112
|
+
}
|
|
113
|
+
else if (bodyParam && callSig.bodyStyle === "property") {
|
|
114
|
+
// Body wrapped in property: fn({ id, data })
|
|
115
|
+
// Collect non-body params that need to be extracted from input
|
|
116
|
+
const nonBodyParams = method.params.filter((p) => p.source === "pk" || p.source === "fk" || p.source === "lookup" || p.source === "pagination");
|
|
117
|
+
if (nonBodyParams.length > 0) {
|
|
118
|
+
// Generate: const { id, ...data } = input;
|
|
119
|
+
const destructureProps = nonBodyParams.map((p) => b.property.from({ kind: "init", key: b.identifier(p.name), value: b.identifier(p.name), shorthand: true }));
|
|
120
|
+
const restId = b.identifier(bodyParam.name);
|
|
121
|
+
const restElem = b.restElement(restId);
|
|
122
|
+
const pattern = b.objectPattern([...destructureProps, restElem]);
|
|
123
|
+
const destructureDecl = b.variableDeclaration("const", [
|
|
124
|
+
b.variableDeclarator(pattern, b.identifier("input")),
|
|
125
|
+
]);
|
|
126
|
+
statements.push(destructureDecl);
|
|
127
|
+
// Build: { id, data } using the destructured variables
|
|
128
|
+
let objBuilder = conjure.obj();
|
|
129
|
+
for (const param of nonBodyParams) {
|
|
130
|
+
objBuilder = objBuilder.shorthand(param.name);
|
|
131
|
+
}
|
|
132
|
+
objBuilder = objBuilder.shorthand(bodyParam.name);
|
|
133
|
+
args.push(objBuilder.build());
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
// No non-body params, just wrap input: fn({ data: input })
|
|
137
|
+
args.push(conjure.obj().prop(bodyParam.name, b.identifier("input")).build());
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
else if (method.params.length > 0) {
|
|
141
|
+
// Simple named params: fn(input) since input matches the shape
|
|
142
|
+
args.push(b.identifier("input"));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// Build: return await queryFn(args)
|
|
146
|
+
const queryCall = b.callExpression(b.identifier(queryFnName), args.map(cast.toExpr));
|
|
147
|
+
const awaitExpr = b.awaitExpression(queryCall);
|
|
148
|
+
if (method.kind === "delete") {
|
|
149
|
+
statements.push(b.expressionStatement(awaitExpr));
|
|
150
|
+
statements.push(b.returnStatement(conjure.obj().prop("success", b.booleanLiteral(true)).build()));
|
|
151
|
+
return statements;
|
|
152
|
+
}
|
|
153
|
+
statements.push(b.returnStatement(awaitExpr));
|
|
154
|
+
return statements;
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* Determine if a method needs body validation and which schema to use.
|
|
158
|
+
*/
|
|
159
|
+
const getBodySchemaImport = (method, entityName) => {
|
|
160
|
+
if (method.kind === "create") {
|
|
161
|
+
return { entity: entityName, shape: "insert", schemaName: `${entityName}Insert` };
|
|
162
|
+
}
|
|
163
|
+
if (method.kind === "update") {
|
|
164
|
+
return { entity: entityName, shape: "update", schemaName: `${entityName}Update` };
|
|
165
|
+
}
|
|
166
|
+
return null;
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* Build Zod type expression for a param.
|
|
170
|
+
*/
|
|
171
|
+
const buildZodParamType = (param) => {
|
|
172
|
+
const baseType = param.type.toLowerCase();
|
|
173
|
+
let zodCall;
|
|
174
|
+
switch (baseType) {
|
|
175
|
+
case "number":
|
|
176
|
+
zodCall = b.callExpression(b.memberExpression(b.memberExpression(b.identifier("z"), b.identifier("coerce")), b.identifier("number")), []);
|
|
177
|
+
break;
|
|
178
|
+
case "boolean":
|
|
179
|
+
zodCall = b.callExpression(b.memberExpression(b.identifier("z"), b.identifier("boolean")), []);
|
|
180
|
+
break;
|
|
181
|
+
case "date":
|
|
182
|
+
zodCall = b.callExpression(b.memberExpression(b.memberExpression(b.identifier("z"), b.identifier("coerce")), b.identifier("date")), []);
|
|
183
|
+
break;
|
|
184
|
+
case "string":
|
|
185
|
+
default:
|
|
186
|
+
zodCall = b.callExpression(b.memberExpression(b.identifier("z"), b.identifier("string")), []);
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
if (!param.required) {
|
|
190
|
+
zodCall = b.callExpression(b.memberExpression(cast.toExpr(zodCall), b.identifier("optional")), []);
|
|
191
|
+
}
|
|
192
|
+
return zodCall;
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* Build a single oRPC procedure.
|
|
196
|
+
* Returns: os.input(type<InputType>()).handler(async ({ input }) => { ... })
|
|
197
|
+
* Or for body schemas: os.input(BodySchema).handler(...)
|
|
198
|
+
*/
|
|
199
|
+
const buildProcedure = (method, entityName, queryFnName) => {
|
|
200
|
+
const bodySchema = getBodySchemaImport(method, entityName);
|
|
201
|
+
let needsType = false;
|
|
202
|
+
let needsZMerge = false;
|
|
203
|
+
let chainExpr = b.identifier("os");
|
|
204
|
+
if (method.params.length > 0) {
|
|
205
|
+
let inputSchema;
|
|
206
|
+
// Check for non-body params (PK, FK, lookup, pagination)
|
|
207
|
+
const nonBodyParams = method.params.filter(p => p.source !== "body");
|
|
208
|
+
const callSig = method.callSignature ?? { style: "named" };
|
|
209
|
+
if (bodySchema && nonBodyParams.length > 0 && callSig.bodyStyle === "property") {
|
|
210
|
+
// For update-style operations with bodyStyle: "property", we need to merge
|
|
211
|
+
// the PK/FK params with the body schema: z.object({ id: z.number() }).merge(PostUpdate)
|
|
212
|
+
needsZMerge = true;
|
|
213
|
+
// Build: z.object({ id: z.coerce.number() })
|
|
214
|
+
let objBuilder = conjure.obj();
|
|
215
|
+
for (const p of nonBodyParams) {
|
|
216
|
+
objBuilder = objBuilder.prop(p.name, buildZodParamType(p));
|
|
217
|
+
}
|
|
218
|
+
const zodObject = b.callExpression(b.memberExpression(b.identifier("z"), b.identifier("object")), [cast.toExpr(objBuilder.build())]);
|
|
219
|
+
// Build: z.object({ id: ... }).merge(PostUpdate)
|
|
220
|
+
inputSchema = b.callExpression(b.memberExpression(zodObject, b.identifier("merge")), [b.identifier(bodySchema.schemaName)]);
|
|
221
|
+
}
|
|
222
|
+
else if (bodySchema) {
|
|
223
|
+
inputSchema = b.identifier(bodySchema.schemaName);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
needsType = true;
|
|
227
|
+
const typeStr = buildTypeObjectString(method.params);
|
|
228
|
+
inputSchema = b.identifier(`type<${typeStr}>()`);
|
|
229
|
+
}
|
|
230
|
+
chainExpr = b.callExpression(b.memberExpression(cast.toExpr(chainExpr), b.identifier("input")), [cast.toExpr(inputSchema)]);
|
|
231
|
+
}
|
|
232
|
+
const handlerParams = [];
|
|
233
|
+
if (method.params.length > 0) {
|
|
234
|
+
const inputProp = b.objectProperty(b.identifier("input"), b.identifier("input"));
|
|
235
|
+
inputProp.shorthand = true;
|
|
236
|
+
handlerParams.push(inputProp);
|
|
237
|
+
}
|
|
238
|
+
const handlerBody = buildProcedureBody(queryFnName, method);
|
|
239
|
+
const handler = b.arrowFunctionExpression([b.objectPattern(handlerParams)], b.blockStatement(handlerBody.map(cast.toStmt)));
|
|
240
|
+
handler.async = true;
|
|
241
|
+
chainExpr = b.callExpression(b.memberExpression(cast.toExpr(chainExpr), b.identifier("handler")), [handler]);
|
|
242
|
+
return { procedureExpr: chainExpr, bodySchema, needsType, needsZMerge };
|
|
243
|
+
};
|
|
244
|
+
// ============================================================================
|
|
245
|
+
// Plugin Definition
|
|
246
|
+
// ============================================================================
|
|
247
|
+
/**
|
|
248
|
+
* Create an http-orpc provider that generates oRPC routers.
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```typescript
|
|
252
|
+
* import { httpOrpc } from "pg-sourcerer"
|
|
253
|
+
*
|
|
254
|
+
* export default defineConfig({
|
|
255
|
+
* plugins: [
|
|
256
|
+
* zod(),
|
|
257
|
+
* sqlQueries(),
|
|
258
|
+
* httpOrpc({
|
|
259
|
+
* header: `import { os } from "@orpc/server";`,
|
|
260
|
+
* }),
|
|
261
|
+
* ],
|
|
262
|
+
* })
|
|
263
|
+
* ```
|
|
264
|
+
*/
|
|
265
|
+
export function httpOrpc(config) {
|
|
266
|
+
const parsed = S.decodeUnknownSync(HttpOrpcConfigSchema)(config);
|
|
267
|
+
return definePlugin({
|
|
268
|
+
name: "http-orpc",
|
|
269
|
+
kind: "http-routes",
|
|
270
|
+
singleton: true,
|
|
271
|
+
canProvide: () => true,
|
|
272
|
+
requires: () => [
|
|
273
|
+
{ kind: "queries", params: {} },
|
|
274
|
+
{ kind: "schemas", params: {} },
|
|
275
|
+
],
|
|
276
|
+
provide: (_params, _deps, ctx) => {
|
|
277
|
+
const { outputDir, header, aggregatorName } = parsed;
|
|
278
|
+
// Get all entities with registered query methods
|
|
279
|
+
const entityNames = ctx.symbols.getEntitiesWithMethods();
|
|
280
|
+
if (entityNames.length === 0) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
// Track generated routers for aggregator
|
|
284
|
+
const generatedRouters = [];
|
|
285
|
+
// Generate router for each entity
|
|
286
|
+
for (const entityName of entityNames) {
|
|
287
|
+
const entityMethods = ctx.symbols.getEntityMethods(entityName);
|
|
288
|
+
if (!entityMethods || entityMethods.methods.length === 0)
|
|
289
|
+
continue;
|
|
290
|
+
const filePath = `${outputDir}/${inflect.uncapitalize(entityName)}.ts`;
|
|
291
|
+
const routerName = `${inflect.uncapitalize(entityName)}Router`;
|
|
292
|
+
const file = ctx.file(filePath);
|
|
293
|
+
// Header provides os import
|
|
294
|
+
file.header(header);
|
|
295
|
+
const queriesImportPath = `../${entityMethods.importPath.replace(/\.ts$/, ".js")}`;
|
|
296
|
+
file.import({
|
|
297
|
+
kind: "relative",
|
|
298
|
+
namespace: "Queries",
|
|
299
|
+
from: queriesImportPath,
|
|
300
|
+
});
|
|
301
|
+
const bodySchemaImports = [];
|
|
302
|
+
let fileNeedsType = false;
|
|
303
|
+
let fileNeedsZod = false;
|
|
304
|
+
let routerObjBuilder = conjure.obj();
|
|
305
|
+
for (const method of entityMethods.methods) {
|
|
306
|
+
const queryFnName = `Queries.${method.name}`;
|
|
307
|
+
const { procedureExpr, bodySchema, needsType, needsZMerge } = buildProcedure(method, entityName, queryFnName);
|
|
308
|
+
if (bodySchema)
|
|
309
|
+
bodySchemaImports.push(bodySchema);
|
|
310
|
+
if (needsType)
|
|
311
|
+
fileNeedsType = true;
|
|
312
|
+
if (needsZMerge)
|
|
313
|
+
fileNeedsZod = true;
|
|
314
|
+
routerObjBuilder = routerObjBuilder.prop(method.name, procedureExpr);
|
|
315
|
+
}
|
|
316
|
+
// Import type utility if needed
|
|
317
|
+
if (fileNeedsType) {
|
|
318
|
+
file.import({ kind: "package", names: ["type"], from: "@orpc/server" });
|
|
319
|
+
}
|
|
320
|
+
// Import zod if needed for merged schemas
|
|
321
|
+
if (fileNeedsZod) {
|
|
322
|
+
file.import({ kind: "package", names: ["z"], from: "zod" });
|
|
323
|
+
}
|
|
324
|
+
// Import body schemas
|
|
325
|
+
for (const schemaImport of bodySchemaImports) {
|
|
326
|
+
file.import({
|
|
327
|
+
kind: "symbol",
|
|
328
|
+
ref: {
|
|
329
|
+
capability: "schemas",
|
|
330
|
+
entity: schemaImport.entity,
|
|
331
|
+
shape: schemaImport.shape,
|
|
332
|
+
},
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
const routerExport = conjure.export.const(routerName, routerObjBuilder.build());
|
|
336
|
+
// Emit router export
|
|
337
|
+
file.ast(conjure.program(routerExport)).emit();
|
|
338
|
+
generatedRouters.push({
|
|
339
|
+
fileName: `${inflect.uncapitalize(entityName)}.js`,
|
|
340
|
+
routerName,
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
// Generate aggregator index.ts
|
|
344
|
+
if (generatedRouters.length > 0) {
|
|
345
|
+
const indexPath = `${outputDir}/index.ts`;
|
|
346
|
+
const indexFile = ctx.file(indexPath);
|
|
347
|
+
// Header provides os import
|
|
348
|
+
indexFile.header(header);
|
|
349
|
+
for (const route of generatedRouters) {
|
|
350
|
+
indexFile.import({
|
|
351
|
+
kind: "relative",
|
|
352
|
+
names: [route.routerName],
|
|
353
|
+
from: `./${route.fileName}`,
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
// Build: export const appRouter = { user: userRouter, ... }
|
|
357
|
+
let routerObjBuilder = conjure.obj();
|
|
358
|
+
for (const route of generatedRouters) {
|
|
359
|
+
const key = route.routerName.replace(/Router$/, "");
|
|
360
|
+
routerObjBuilder = routerObjBuilder.prop(key, b.identifier(route.routerName));
|
|
361
|
+
}
|
|
362
|
+
const routerExport = conjure.export.const(aggregatorName, routerObjBuilder.build());
|
|
363
|
+
// Also export the type
|
|
364
|
+
const typeExport = b.exportNamedDeclaration(b.tsTypeAliasDeclaration(b.identifier("AppRouter"), b.tsTypeQuery(b.identifier(aggregatorName))));
|
|
365
|
+
indexFile.ast(conjure.program(routerExport, typeExport)).emit();
|
|
366
|
+
}
|
|
367
|
+
},
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
//# sourceMappingURL=http-orpc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-orpc.js","sourceRoot":"","sources":["../../src/plugins/http-orpc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,EAAE,YAAY,EAAsB,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;A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GAAG,EAAE,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;gBAChF,CAAC;gBAED,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,EAAE,gBAAgB,CAAC,KAAK,EAAE,CAAC,CAAC;gBAEpF,uBAAuB;gBACvB,MAAM,UAAU,GAAG,CAAC,CAAC,sBAAsB,CACzC,CAAC,CAAC,sBAAsB,CACtB,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC,EACzB,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,CAC5C,CACF,CAAC;gBAEF,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YAClE,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP tRPC Plugin - Generate tRPC routers from query plugins
|
|
3
|
+
*
|
|
4
|
+
* Consumes method symbols from sql-queries or kysely-queries via the symbol registry
|
|
5
|
+
* and generates type-safe tRPC routers with schema validation.
|
|
6
|
+
*/
|
|
7
|
+
import { Schema as S } from "effect";
|
|
8
|
+
import { definePlugin } from "../services/plugin.js";
|
|
9
|
+
declare const HttpTrpcConfigSchema: S.Struct<{
|
|
10
|
+
/** Output directory for generated router files. Default: "trpc" */
|
|
11
|
+
outputDir: S.optionalWith<typeof S.String, {
|
|
12
|
+
default: () => string;
|
|
13
|
+
}>;
|
|
14
|
+
/**
|
|
15
|
+
* Header content to prepend to each generated file.
|
|
16
|
+
* MUST import `router` and a base procedure (e.g., `publicProcedure`).
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* header: `import { router, publicProcedure } from "../trpc.js";`
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
header: typeof S.String;
|
|
24
|
+
/**
|
|
25
|
+
* Name of the base procedure to use in generated code.
|
|
26
|
+
* Must match an import from your header.
|
|
27
|
+
* Default: "publicProcedure"
|
|
28
|
+
*/
|
|
29
|
+
baseProcedure: S.optionalWith<typeof S.String, {
|
|
30
|
+
default: () => string;
|
|
31
|
+
}>;
|
|
32
|
+
/** Name of the aggregated router export. Default: "appRouter" */
|
|
33
|
+
aggregatorName: S.optionalWith<typeof S.String, {
|
|
34
|
+
default: () => string;
|
|
35
|
+
}>;
|
|
36
|
+
}>;
|
|
37
|
+
/** Input config type (with optional fields) */
|
|
38
|
+
export type HttpTrpcConfig = S.Schema.Encoded<typeof HttpTrpcConfigSchema>;
|
|
39
|
+
/**
|
|
40
|
+
* Create an http-trpc provider that generates tRPC routers.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* import { httpTrpc } from "pg-sourcerer"
|
|
45
|
+
*
|
|
46
|
+
* export default defineConfig({
|
|
47
|
+
* plugins: [
|
|
48
|
+
* zod(),
|
|
49
|
+
* sqlQueries(),
|
|
50
|
+
* httpTrpc({
|
|
51
|
+
* header: `import { router, publicProcedure } from "../trpc.js";`,
|
|
52
|
+
* }),
|
|
53
|
+
* ],
|
|
54
|
+
* })
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function httpTrpc(config: HttpTrpcConfig): ReturnType<typeof definePlugin>;
|
|
58
|
+
export {};
|
|
59
|
+
//# sourceMappingURL=http-trpc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-trpc.d.ts","sourceRoot":"","sources":["../../src/plugins/http-trpc.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,EAAE,YAAY,EAAsB,MAAM,uBAAuB,CAAC;AAiBzE,QAAA,MAAM,oBAAoB;IACxB,mEAAmE;;;;IAGnE;;;;;;;;OAQG;;IAGH;;;;OAIG;;;;IAGH,iEAAiE;;;;EAEjE,CAAC;AAEH,+CAA+C;AAC/C,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAqU3E;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CA8JhF"}
|