@ir-kit/openapi-ts-orpc 0.1.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.
Files changed (84) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +234 -0
  3. package/dist/config.d.ts +7 -0
  4. package/dist/config.d.ts.map +1 -0
  5. package/dist/config.js +101 -0
  6. package/dist/config.js.map +1 -0
  7. package/dist/generators/client.d.ts +7 -0
  8. package/dist/generators/client.d.ts.map +1 -0
  9. package/dist/generators/client.js +113 -0
  10. package/dist/generators/client.js.map +1 -0
  11. package/dist/generators/contract-validator.d.ts +21 -0
  12. package/dist/generators/contract-validator.d.ts.map +1 -0
  13. package/dist/generators/contract-validator.js +250 -0
  14. package/dist/generators/contract-validator.js.map +1 -0
  15. package/dist/generators/contract.d.ts +9 -0
  16. package/dist/generators/contract.d.ts.map +1 -0
  17. package/dist/generators/contract.js +159 -0
  18. package/dist/generators/contract.js.map +1 -0
  19. package/dist/generators/faker.d.ts +15 -0
  20. package/dist/generators/faker.d.ts.map +1 -0
  21. package/dist/generators/faker.js +61 -0
  22. package/dist/generators/faker.js.map +1 -0
  23. package/dist/generators/handlers/ast.d.ts +65 -0
  24. package/dist/generators/handlers/ast.d.ts.map +1 -0
  25. package/dist/generators/handlers/ast.js +262 -0
  26. package/dist/generators/handlers/ast.js.map +1 -0
  27. package/dist/generators/handlers/index.d.ts +37 -0
  28. package/dist/generators/handlers/index.d.ts.map +1 -0
  29. package/dist/generators/handlers/index.js +48 -0
  30. package/dist/generators/handlers/index.js.map +1 -0
  31. package/dist/generators/index.d.ts +14 -0
  32. package/dist/generators/index.d.ts.map +1 -0
  33. package/dist/generators/index.js +13 -0
  34. package/dist/generators/index.js.map +1 -0
  35. package/dist/generators/router.d.ts +7 -0
  36. package/dist/generators/router.d.ts.map +1 -0
  37. package/dist/generators/router.js +21 -0
  38. package/dist/generators/router.js.map +1 -0
  39. package/dist/generators/server.d.ts +7 -0
  40. package/dist/generators/server.d.ts.map +1 -0
  41. package/dist/generators/server.js +22 -0
  42. package/dist/generators/server.js.map +1 -0
  43. package/dist/generators/tanstack.d.ts +7 -0
  44. package/dist/generators/tanstack.d.ts.map +1 -0
  45. package/dist/generators/tanstack.js +27 -0
  46. package/dist/generators/tanstack.js.map +1 -0
  47. package/dist/generators/types.d.ts +74 -0
  48. package/dist/generators/types.d.ts.map +1 -0
  49. package/dist/generators/types.js +2 -0
  50. package/dist/generators/types.js.map +1 -0
  51. package/dist/index.d.ts +4 -0
  52. package/dist/index.d.ts.map +1 -0
  53. package/dist/index.js +3 -0
  54. package/dist/index.js.map +1 -0
  55. package/dist/plugin.d.ts +7 -0
  56. package/dist/plugin.d.ts.map +1 -0
  57. package/dist/plugin.js +124 -0
  58. package/dist/plugin.js.map +1 -0
  59. package/dist/router-organizer.d.ts +13 -0
  60. package/dist/router-organizer.d.ts.map +1 -0
  61. package/dist/router-organizer.js +42 -0
  62. package/dist/router-organizer.js.map +1 -0
  63. package/dist/schema/extractor.d.ts +16 -0
  64. package/dist/schema/extractor.d.ts.map +1 -0
  65. package/dist/schema/extractor.js +133 -0
  66. package/dist/schema/extractor.js.map +1 -0
  67. package/dist/schema/index.d.ts +2 -0
  68. package/dist/schema/index.d.ts.map +1 -0
  69. package/dist/schema/index.js +2 -0
  70. package/dist/schema/index.js.map +1 -0
  71. package/dist/symbols/external.d.ts +8 -0
  72. package/dist/symbols/external.d.ts.map +1 -0
  73. package/dist/symbols/external.js +67 -0
  74. package/dist/symbols/external.js.map +1 -0
  75. package/dist/types.d.ts +238 -0
  76. package/dist/types.d.ts.map +1 -0
  77. package/dist/types.js +2 -0
  78. package/dist/types.js.map +1 -0
  79. package/dist/utils.d.ts +4 -0
  80. package/dist/utils.d.ts.map +1 -0
  81. package/dist/utils.js +13 -0
  82. package/dist/utils.js.map +1 -0
  83. package/docs/typia.md +152 -0
  84. package/package.json +101 -0
@@ -0,0 +1,262 @@
1
+ /**
2
+ * TypeScript AST builders for handler file generation.
3
+ * Constructs import declarations, handler property assignments, and
4
+ * complete handler file ASTs using the TypeScript compiler API.
5
+ */
6
+ import ts from "typescript";
7
+ // ============================================================================
8
+ // Constants
9
+ // ============================================================================
10
+ /** JS reserved words that cannot be used as variable names. */
11
+ const JS_RESERVED = new Set([
12
+ "break",
13
+ "case",
14
+ "catch",
15
+ "class",
16
+ "const",
17
+ "continue",
18
+ "debugger",
19
+ "default",
20
+ "delete",
21
+ "do",
22
+ "else",
23
+ "enum",
24
+ "export",
25
+ "extends",
26
+ "false",
27
+ "finally",
28
+ "for",
29
+ "function",
30
+ "if",
31
+ "import",
32
+ "in",
33
+ "instanceof",
34
+ "let",
35
+ "new",
36
+ "null",
37
+ "return",
38
+ "static",
39
+ "super",
40
+ "switch",
41
+ "this",
42
+ "throw",
43
+ "true",
44
+ "try",
45
+ "typeof",
46
+ "var",
47
+ "void",
48
+ "while",
49
+ "with",
50
+ "yield",
51
+ "implements",
52
+ "interface",
53
+ "package",
54
+ "private",
55
+ "protected",
56
+ "public",
57
+ ]);
58
+ /** Returns a safe variable/export name — appends `Handlers` when tag is reserved. */
59
+ export function safeVarName(tag) {
60
+ return JS_RESERVED.has(tag) ? `${tag}Handlers` : tag;
61
+ }
62
+ const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
63
+ /**
64
+ * Empty source file used as printer context when printing individual nodes.
65
+ * `updateSourceFile` returns a new node — this one is never mutated.
66
+ */
67
+ const emptySourceFile = ts.createSourceFile("_.ts", "", ts.ScriptTarget.Latest, false, ts.ScriptKind.TS);
68
+ // ============================================================================
69
+ // AST node builders
70
+ // ============================================================================
71
+ export function makeImport(names, from) {
72
+ return ts.factory.createImportDeclaration(undefined, ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports(names.map((n) => ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier(n))))), ts.factory.createStringLiteral(from), undefined);
73
+ }
74
+ // ============================================================================
75
+ // Handler body builders — one per mode
76
+ // ============================================================================
77
+ /** Stub mode: `async () => { throw new ORPCError('NOT_IMPLEMENTED'); }` */
78
+ function makeStubBody() {
79
+ const throwStmt = ts.factory.createThrowStatement(ts.factory.createNewExpression(ts.factory.createIdentifier("ORPCError"), undefined, [ts.factory.createStringLiteral("NOT_IMPLEMENTED")]));
80
+ return ts.factory.createBlock([throwStmt], true);
81
+ }
82
+ /** Faker mode: `async () => mockProcedure()` */
83
+ function makeFakerBody(factoryName) {
84
+ return ts.factory.createCallExpression(ts.factory.createIdentifier(factoryName), undefined, []);
85
+ }
86
+ /** Proxy mode: `async ({ input }) => client.tag.procedure(input)` */
87
+ function makeProxyBody(tag, procedure, clientName) {
88
+ return ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(clientName), ts.factory.createIdentifier(tag)), ts.factory.createIdentifier(procedure)), undefined, [ts.factory.createIdentifier("input")]);
89
+ }
90
+ export function makeHandlerProperty({ tag, procedure, implementerName, mode, clientName, factoryName, }) {
91
+ let body;
92
+ let params;
93
+ switch (mode) {
94
+ case "faker":
95
+ body = makeFakerBody(factoryName ??
96
+ `mock${procedure.charAt(0).toUpperCase()}${procedure.slice(1)}`);
97
+ params = [];
98
+ break;
99
+ case "proxy":
100
+ body = makeProxyBody(tag, procedure, clientName);
101
+ params = [
102
+ ts.factory.createParameterDeclaration(undefined, undefined, ts.factory.createObjectBindingPattern([
103
+ ts.factory.createBindingElement(undefined, undefined, ts.factory.createIdentifier("input")),
104
+ ])),
105
+ ];
106
+ break;
107
+ default: // stub
108
+ body = makeStubBody();
109
+ params = [];
110
+ break;
111
+ }
112
+ const asyncArrow = ts.factory.createArrowFunction([ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword)], undefined, params, undefined, ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), body);
113
+ const handlerCall = ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createPropertyAccessExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(implementerName), ts.factory.createIdentifier(tag)), ts.factory.createIdentifier(procedure)), ts.factory.createIdentifier("handler")), undefined, [asyncArrow]);
114
+ return ts.factory.createPropertyAssignment(ts.factory.createIdentifier(procedure), handlerCall);
115
+ }
116
+ // ============================================================================
117
+ // Import builder
118
+ // ============================================================================
119
+ export function getImports(ctx) {
120
+ const imports = [];
121
+ switch (ctx.mode) {
122
+ case "stub":
123
+ imports.push(makeImport(["ORPCError"], "@orpc/server"));
124
+ imports.push(makeImport([ctx.implementer.name], ctx.implementer.from));
125
+ break;
126
+ case "faker": {
127
+ const factoryNames = ctx.procedures
128
+ .map((p) => ctx.fakerFactoryNames?.get(p))
129
+ .filter((n) => !!n);
130
+ if (factoryNames.length > 0 && ctx.fakerGenImport) {
131
+ imports.push(makeImport(factoryNames, ctx.fakerGenImport));
132
+ }
133
+ imports.push(makeImport([ctx.implementer.name], ctx.implementer.from));
134
+ break;
135
+ }
136
+ case "proxy": {
137
+ const clientImport = ctx.proxyConfig?.clientImport;
138
+ if (clientImport) {
139
+ imports.push(makeImport([clientImport.name], clientImport.from));
140
+ }
141
+ imports.push(makeImport([ctx.implementer.name], ctx.implementer.from));
142
+ break;
143
+ }
144
+ }
145
+ return imports;
146
+ }
147
+ // ============================================================================
148
+ // File builders
149
+ // ============================================================================
150
+ /**
151
+ * Generates a complete handler file.
152
+ * The full source file is constructed as a TypeScript AST and printed with
153
+ * `ts.createPrinter` — no template strings involved.
154
+ */
155
+ export function buildFile(ctx) {
156
+ const varName = safeVarName(ctx.tag);
157
+ const statements = [
158
+ ...getImports(ctx),
159
+ ts.factory.createVariableStatement(undefined, ts.factory.createVariableDeclarationList([
160
+ ts.factory.createVariableDeclaration(ts.factory.createIdentifier(varName), undefined, undefined, ts.factory.createObjectLiteralExpression(ctx.procedures.map((p) => makeHandlerProperty({
161
+ tag: ctx.tag,
162
+ procedure: p,
163
+ implementerName: ctx.implementer.name,
164
+ mode: ctx.mode,
165
+ clientName: ctx.clientName,
166
+ factoryName: ctx.fakerFactoryNames?.get(p),
167
+ })),
168
+ /* multiLine */ true)),
169
+ ], ts.NodeFlags.Const)),
170
+ ts.factory.createExportAssignment(undefined,
171
+ /* isExportEquals */ false, ts.factory.createIdentifier(varName)),
172
+ ];
173
+ const sf = ts.factory.updateSourceFile(emptySourceFile, statements);
174
+ return printer.printFile(sf);
175
+ }
176
+ /**
177
+ * Parses the source file and locates the top-level handler object
178
+ * (`const <tag> = { ... }`), returning the existing property names
179
+ * and the insertion position for new properties.
180
+ */
181
+ export function analyzeHandlerFile(source, varName) {
182
+ const sf = ts.createSourceFile("handler.ts", source, ts.ScriptTarget.Latest, true);
183
+ for (const stmt of sf.statements) {
184
+ if (!ts.isVariableStatement(stmt))
185
+ continue;
186
+ const decl = stmt.declarationList.declarations[0];
187
+ if (!decl || !ts.isIdentifier(decl.name) || decl.name.text !== varName)
188
+ continue;
189
+ const init = decl.initializer;
190
+ if (!init || !ts.isObjectLiteralExpression(init))
191
+ continue;
192
+ const existingNames = new Set();
193
+ for (const prop of init.properties) {
194
+ if (ts.isPropertyAssignment(prop) || ts.isMethodDeclaration(prop)) {
195
+ const name = prop.name;
196
+ if (ts.isIdentifier(name) || ts.isStringLiteral(name)) {
197
+ existingNames.add(name.text);
198
+ }
199
+ }
200
+ }
201
+ return { existingNames, closingBracePos: init.getEnd() - 1 };
202
+ }
203
+ return null;
204
+ }
205
+ /**
206
+ * Detects the indentation unit (tabs or N spaces) used in a source file.
207
+ * Falls back to two spaces.
208
+ */
209
+ function detectIndent(source) {
210
+ const m = source.match(/^([ \t]+)\S/m);
211
+ return m ? m[1] : " ";
212
+ }
213
+ /**
214
+ * Prints a single handler property assignment, re-indented to match the
215
+ * surrounding file's style.
216
+ *
217
+ * `ts.createPrinter` uses 4-space indentation internally. This function
218
+ * converts that to the file's detected indent unit, then prepends the outer
219
+ * indent (one level) to every line.
220
+ */
221
+ function printProperty(ctx, procedure, indent) {
222
+ const node = makeHandlerProperty({
223
+ tag: ctx.tag,
224
+ procedure,
225
+ implementerName: ctx.implementer.name,
226
+ mode: ctx.mode,
227
+ clientName: ctx.clientName,
228
+ factoryName: ctx.fakerFactoryNames?.get(procedure),
229
+ });
230
+ const raw = printer.printNode(ts.EmitHint.Unspecified, node, emptySourceFile);
231
+ const normalized = raw
232
+ .split("\n")
233
+ .map((line) => {
234
+ if (!line)
235
+ return line;
236
+ // Count leading 4-space groups emitted by the printer.
237
+ const leading = line.match(/^( {4})+/)?.[0] ?? "";
238
+ const depth = leading.length / 4;
239
+ return indent + indent.repeat(depth) + line.slice(leading.length);
240
+ })
241
+ .join("\n");
242
+ return normalized + ",";
243
+ }
244
+ /**
245
+ * Inserts missing procedure stubs into an existing handler file.
246
+ *
247
+ * Detection is AST-based (TypeScript compiler API) — property names are
248
+ * extracted from the parsed object literal, not by string search.
249
+ * The original file content is preserved for all existing code; only the
250
+ * new stubs are spliced in at the exact character position of the closing `}`.
251
+ */
252
+ export function patchFile(source, ctx, missing) {
253
+ const info = analyzeHandlerFile(source, safeVarName(ctx.tag));
254
+ if (!info)
255
+ return source; // can't locate the object — leave the file untouched
256
+ const indent = detectIndent(source);
257
+ const insertion = missing.map((p) => `\n${printProperty(ctx, p, indent)}`).join("\n") + "\n";
258
+ return (source.slice(0, info.closingBracePos) +
259
+ insertion +
260
+ source.slice(info.closingBracePos));
261
+ }
262
+ //# sourceMappingURL=ast.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ast.js","sourceRoot":"","sources":["../../../src/generators/handlers/ast.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,YAAY,CAAC;AAwB5B,+EAA+E;AAC/E,YAAY;AACZ,+EAA+E;AAE/E,+DAA+D;AAC/D,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC;IAC1B,OAAO;IACP,MAAM;IACN,OAAO;IACP,OAAO;IACP,OAAO;IACP,UAAU;IACV,UAAU;IACV,SAAS;IACT,QAAQ;IACR,IAAI;IACJ,MAA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AAE,EAAE,CAAC,KAAK,aAAa,CAAC,GAAG,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAE7E,OAAO,CACL,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,eAAe,CAAC;QACrC,SAAS;QACT,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CACnC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Handler file scaffolding — generates handler files on disk.
3
+ * Supports three modes: stub (NOT_IMPLEMENTED), faker (mock data), proxy (client forwarding).
4
+ */
5
+ import type { RouterNode } from "../../router-organizer";
6
+ import type { HandlerMode, ProxyHandlerConfig } from "../../types";
7
+ export type { PropertyInfo, ResponseSchemaInfo } from "./ast";
8
+ export interface HandlersGeneratorInput {
9
+ /** Absolute path to the handlers directory. */
10
+ handlersDir: string;
11
+ /** Relative import path from a handler file to server.gen.js. */
12
+ serverGenImport: string;
13
+ routerStructure: Map<string, RouterNode[]>;
14
+ /** Override the implementer used in stubs (default: { name: 'os', from: serverGenImport }). */
15
+ implementer?: {
16
+ name: string;
17
+ from: string;
18
+ };
19
+ /** Handler body generation mode. @default 'stub' */
20
+ mode?: HandlerMode;
21
+ /** When true, existing handler files are completely rewritten. @default false */
22
+ override?: boolean;
23
+ /** Proxy-specific config. */
24
+ proxyConfig?: ProxyHandlerConfig;
25
+ /**
26
+ * Faker mode: map of operationName → factory function name.
27
+ * Provided by plugin.ts after calling generateFakerFactories().
28
+ */
29
+ fakerFactoryNames?: Map<string, string>;
30
+ /**
31
+ * Faker mode: base import path for faker.gen files.
32
+ * e.g. "#/generated/@ir-kit/orpc" — tag is appended: `${base}/${tag}/faker.gen`
33
+ */
34
+ fakerGenImportBase?: string;
35
+ }
36
+ export declare function generateHandlers({ handlersDir, serverGenImport, routerStructure, implementer, mode, override, proxyConfig, fakerFactoryNames, fakerGenImportBase, }: HandlersGeneratorInput): void;
37
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/generators/handlers/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAMnE,YAAY,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAE9D,MAAM,WAAW,sBAAsB;IACrC,+CAA+C;IAC/C,WAAW,EAAE,MAAM,CAAC;IACpB,iEAAiE;IACjE,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC;IAC3C,+FAA+F;IAC/F,WAAW,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7C,oDAAoD;IACpD,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,iFAAiF;IACjF,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,6BAA6B;IAC7B,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC;;;OAGG;IACH,iBAAiB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,wBAAgB,gBAAgB,CAAC,EAC/B,WAAW,EACX,eAAe,EACf,eAAe,EACf,WAAW,EACX,IAAa,EACb,QAAgB,EAChB,WAAW,EACX,iBAAiB,EACjB,kBAAkB,GACnB,EAAE,sBAAsB,GAAG,IAAI,CA4C/B"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Handler file scaffolding — generates handler files on disk.
3
+ * Supports three modes: stub (NOT_IMPLEMENTED), faker (mock data), proxy (client forwarding).
4
+ */
5
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
6
+ import { join } from "node:path";
7
+ import { operationName } from "../../utils";
8
+ import { analyzeHandlerFile, buildFile, patchFile, safeVarName } from "./ast";
9
+ export function generateHandlers({ handlersDir, serverGenImport, routerStructure, implementer, mode = "stub", override = false, proxyConfig, fakerFactoryNames, fakerGenImportBase, }) {
10
+ if (!existsSync(handlersDir)) {
11
+ mkdirSync(handlersDir, { recursive: true });
12
+ }
13
+ const impl = implementer ?? { name: "os", from: serverGenImport };
14
+ const clientName = proxyConfig?.clientImport?.name ?? "client";
15
+ for (const [group, nodes] of routerStructure) {
16
+ const tag = operationName(group);
17
+ const procedures = nodes.map((n) => operationName(n.operationName));
18
+ const filePath = join(handlersDir, `${tag}.ts`);
19
+ const fakerGenImport = fakerGenImportBase
20
+ ? `${fakerGenImportBase}/${group}/faker.gen`
21
+ : undefined;
22
+ const ctx = {
23
+ tag,
24
+ procedures,
25
+ implementer: impl,
26
+ mode,
27
+ clientName,
28
+ proxyConfig,
29
+ fakerFactoryNames,
30
+ fakerGenImport,
31
+ };
32
+ // Override mode: always rewrite the file from scratch
33
+ if (override || !existsSync(filePath)) {
34
+ writeFileSync(filePath, buildFile(ctx));
35
+ continue;
36
+ }
37
+ // Patch mode (default): only append missing procedures
38
+ const source = readFileSync(filePath, "utf-8");
39
+ const info = analyzeHandlerFile(source, safeVarName(tag));
40
+ if (!info)
41
+ continue; // malformed file — skip
42
+ const missing = procedures.filter((p) => !info.existingNames.has(p));
43
+ if (missing.length > 0) {
44
+ writeFileSync(filePath, patchFile(source, ctx, missing));
45
+ }
46
+ }
47
+ }
48
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/generators/handlers/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,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ACX,iBAAiB;YACjB,cAAc;SACf,CAAC;QAEF,sDAAsD;QACtD,IAAI,QAAQ,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;YACtC,aAAa,CAAC,QAAQ,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACxC,SAAS;QACX,CAAC;QAED,uDAAuD;QACvD,MAAM,MAAM,GAAG,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAC/C,MAAM,IAAI,GAAG,kBAAkB,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;QAC1D,IAAI,CAAC,IAAI;YAAE,SAAS,CAAC,wBAAwB;QAE7C,MAAM,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACrE,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvB,aAAa,CAAC,QAAQ,EAAE,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * oRPC Generator Modules
3
+ *
4
+ * Each generator handles a specific responsibility in the code generation pipeline.
5
+ */
6
+ export { generateClients } from "./client";
7
+ export { generateContracts } from "./contract";
8
+ export { generateFakerFactories } from "./faker";
9
+ export { generateHandlers, type HandlersGeneratorInput } from "./handlers";
10
+ export { generateRouter } from "./router";
11
+ export { generateServer } from "./server";
12
+ export { generateTanstack } from "./tanstack";
13
+ export type { ClientGeneratorInput, ClientTypeConfig, ContractGeneratorInput, ContractGeneratorOutput, GeneratorContext, RouterGeneratorInput, RouterGeneratorOutput, ServerGeneratorInput, } from "./types";
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/generators/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,KAAK,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,YAAY,EACV,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,EACtB,uBAAuB,EACvB,gBAAgB,EAChB,oBAAoB,EACpB,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,SAAS,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * oRPC Generator Modules
3
+ *
4
+ * Each generator handles a specific responsibility in the code generation pipeline.
5
+ */
6
+ export { generateClients } from "./client";
7
+ export { generateContracts } from "./contract";
8
+ export { generateFakerFactories } from "./faker";
9
+ export { generateHandlers } from "./handlers";
10
+ export { generateRouter } from "./router";
11
+ export { generateServer } from "./server";
12
+ export { generateTanstack } from "./tanstack";
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/generators/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAA+B,MAAM,YAAY,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { RouterGeneratorInput, RouterGeneratorOutput } from "./types";
2
+ /**
3
+ * Generates the oRPC router from the contract structure.
4
+ * Creates a router symbol and exports the router object.
5
+ */
6
+ export declare const generateRouter: ({ plugin, routerFile, routerStructure, }: RouterGeneratorInput) => RouterGeneratorOutput;
7
+ //# sourceMappingURL=router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/generators/router.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAE3E;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAI,0CAI5B,oBAAoB,KAAG,qBAoBzB,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { $ } from "@hey-api/openapi-ts";
2
+ import { buildRouterObject } from "../router-organizer";
3
+ /**
4
+ * Generates the oRPC router from the contract structure.
5
+ * Creates a router symbol and exports the router object.
6
+ */
7
+ export const generateRouter = ({ plugin, routerFile, routerStructure, }) => {
8
+ const routerSymbol = plugin.symbol("router", {
9
+ getFilePath: () => routerFile,
10
+ meta: {
11
+ category: "router",
12
+ resource: "router",
13
+ tool: "orpc",
14
+ },
15
+ });
16
+ const routerObj = buildRouterObject(routerStructure, plugin.config.group, plugin.config.naming.operation);
17
+ const routerStatement = $.const(routerSymbol).export().assign(routerObj);
18
+ plugin.node(routerStatement);
19
+ return { routerSymbol };
20
+ };
21
+ //# sourceMappingURL=router.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/generators/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGxD;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,EAC7B,MAAM,EACN,UAAU,EACV,eAAe,GACM,EAAyB,EAAE;IAChD,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE;QAC3C,WAAW,EAAE,GAAG,EAAE,CAAC,UAAU;QAC7B,IAAI,EAAE;YACJ,QAAQ,EAAE,QAAQ;YAClB,QAAQ,EAAE,QAAQ;YAClB,IAAI,EAAE,MAAM;SACb;KACF,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,iBAAiB,CACjC,eAAe,EACf,MAAM,CAAC,MAAM,CAAC,KAAK,EACnB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAC/B,CAAC;IAEF,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACzE,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IAE7B,OAAO,EAAE,YAAY,EAAE,CAAC;AAC1B,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { ServerGeneratorInput } from "./types";
2
+ /**
3
+ * Generates server implementation skeleton.
4
+ * Creates an implementer instance that backend developers can use to implement handlers.
5
+ */
6
+ export declare const generateServer: ({ plugin, routerSymbol, serverFile, }: ServerGeneratorInput) => void;
7
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/generators/server.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAEpD;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAI,uCAI5B,oBAAoB,KAAG,IAkBzB,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { $ } from "@hey-api/openapi-ts";
2
+ /**
3
+ * Generates server implementation skeleton.
4
+ * Creates an implementer instance that backend developers can use to implement handlers.
5
+ */
6
+ export const generateServer = ({ plugin, routerSymbol, serverFile, }) => {
7
+ const implementSymbol = plugin.external("@orpc/server.implement");
8
+ // Export server implementer: os = implement(router)
9
+ const osSymbol = plugin.symbol("os", {
10
+ getFilePath: () => serverFile,
11
+ meta: {
12
+ category: "server",
13
+ resource: "implementer",
14
+ tool: "orpc",
15
+ },
16
+ });
17
+ const osStatement = $.const(osSymbol)
18
+ .export()
19
+ .assign($.call(implementSymbol, $(routerSymbol)));
20
+ plugin.node(osStatement);
21
+ };
22
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/generators/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAC;AAGxC;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,EAC7B,MAAM,EACN,YAAY,EACZ,UAAU,GACW,EAAQ,EAAE;IAC/B,MAAM,eAAe,GAAG,MAAM,CAAC,QAAQ,CAAC,wBAAwB,CAAC,CAAC;IAElE,oDAAoD;IACpD,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE;QACnC,WAAW,EAAE,GAAG,EAAE,CAAC,UAAU;QAC7B,IAAI,EAAE;YACJ,QAAQ,EAAE,QAAQ;YAClB,QAAQ,EAAE,aAAa;YACvB,IAAI,EAAE,MAAM;SACb;KACF,CAAC,CAAC;IAEH,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC;SAClC,MAAM,EAAE;SACR,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAEpD,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAC3B,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { GeneratorContext } from "./types";
2
+ /**
3
+ * Generates TanStack Query utilities for oRPC.
4
+ * Creates a factory function that wraps the oRPC TanStack Query integration.
5
+ */
6
+ export declare const generateTanstack: (context: GeneratorContext) => void;
7
+ //# sourceMappingURL=tanstack.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tanstack.d.ts","sourceRoot":"","sources":["../../src/generators/tanstack.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD;;;GAGG;AACH,eAAO,MAAM,gBAAgB,GAAI,SAAS,gBAAgB,KAAG,IAkC5D,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { $ } from "@hey-api/openapi-ts";
2
+ /**
3
+ * Generates TanStack Query utilities for oRPC.
4
+ * Creates a factory function that wraps the oRPC TanStack Query integration.
5
+ */
6
+ export const generateTanstack = (context) => {
7
+ const { plugin, routerSymbol, tanstackFile } = context;
8
+ const contractRouterClientSymbol = plugin.external("@orpc/contract.ContractRouterClient");
9
+ const createTanstackQueryUtilsSymbol = plugin.external("@orpc/tanstack-query.createTanstackQueryUtils");
10
+ const createOrpcUtilsSymbol = plugin.symbol("createOrpcUtils", {
11
+ getFilePath: () => tanstackFile,
12
+ meta: {
13
+ category: "tanstack",
14
+ resource: "createOrpcUtils",
15
+ tool: "orpc",
16
+ },
17
+ });
18
+ const createOrpcUtilsFunc = $.const(createOrpcUtilsSymbol)
19
+ .export()
20
+ .assign($.func()
21
+ .param("client", (p) => p.type($.type
22
+ .expr(contractRouterClientSymbol)
23
+ .generic($.type.query($(routerSymbol)))))
24
+ .do($.return($.call(createTanstackQueryUtilsSymbol, $.id("client")))));
25
+ plugin.node(createOrpcUtilsFunc);
26
+ };
27
+ //# sourceMappingURL=tanstack.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tanstack.js","sourceRoot":"","sources":["../../src/generators/tanstack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAC;AAGxC;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAAyB,EAAQ,EAAE;IAClE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAEvD,MAAM,0BAA0B,GAAG,MAAM,CAAC,QAAQ,CAChD,qCAAqC,CACtC,CAAC;IACF,MAAM,8BAA8B,GAAG,MAAM,CAAC,QAAQ,CACpD,+CAA+C,CAChD,CAAC;IAEF,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,CAAC,iBAAiB,EAAE;QAC7D,WAAW,EAAE,GAAG,EAAE,CAAC,YAAY;QAC/B,IAAI,EAAE;YACJ,QAAQ,EAAE,UAAU;YACpB,QAAQ,EAAE,iBAAiB;YAC3B,IAAI,EAAE,MAAM;SACb;KACF,CAAC,CAAC;IAEH,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,qBAAqB,CAAC;SACvD,MAAM,EAAE;SACR,MAAM,CACL,CAAC,CAAC,IAAI,EAAE;SACL,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CACrB,CAAC,CAAC,IAAI,CACJ,CAAC,CAAC,IAAI;SACH,IAAI,CAAC,0BAA0B,CAAC;SAChC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAC1C,CACF;SACA,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,8BAA8B,EAAE,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CACxE,CAAC;IAEJ,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;AACnC,CAAC,CAAC"}
@@ -0,0 +1,74 @@
1
+ import type { RouterNode } from "../router-organizer";
2
+ import type { ClientType, ORPCPlugin } from "../types";
3
+ /**
4
+ * Plugin instance type for ORPC generators
5
+ */
6
+ type ORPCPluginInstance = Parameters<ORPCPlugin["Handler"]>[0]["plugin"];
7
+ /**
8
+ * Common context passed to all generators
9
+ */
10
+ export interface GeneratorContext {
11
+ clientFile: string;
12
+ contractFile: string;
13
+ plugin: ORPCPluginInstance;
14
+ routerFile: string;
15
+ routerSymbol: ReturnType<ORPCPluginInstance["symbol"]>;
16
+ tanstackFile: string;
17
+ }
18
+ /**
19
+ * Input for contract generator
20
+ */
21
+ export interface ContractGeneratorInput {
22
+ contractFile: string;
23
+ plugin: ORPCPluginInstance;
24
+ }
25
+ /**
26
+ * Output from contract generator
27
+ */
28
+ export interface ContractGeneratorOutput {
29
+ routerStructure: Map<string, RouterNode[]>;
30
+ }
31
+ /**
32
+ * Input for router generator
33
+ */
34
+ export interface RouterGeneratorInput {
35
+ plugin: ORPCPluginInstance;
36
+ routerFile: string;
37
+ routerStructure: Map<string, RouterNode[]>;
38
+ }
39
+ /**
40
+ * Output from router generator
41
+ */
42
+ export interface RouterGeneratorOutput {
43
+ routerSymbol: ReturnType<ORPCPluginInstance["symbol"]>;
44
+ }
45
+ /**
46
+ * Configuration for a single client type
47
+ */
48
+ export interface ClientTypeConfig {
49
+ /** TypeScript type name for config (e.g., 'RpcLinkClientConfig') */
50
+ configTypeName: string;
51
+ /** Client creation function name (e.g., 'createRpcLinkClient') */
52
+ functionName: string;
53
+ /** External package path (e.g., '@orpc/client/fetch.RPCLink') */
54
+ linkSymbolResource: string;
55
+ /** Whether the Link constructor requires router as first arg (OpenAPILink) */
56
+ needsRouter?: boolean;
57
+ }
58
+ /**
59
+ * Input for client generator
60
+ */
61
+ export interface ClientGeneratorInput {
62
+ clientTypes: ReadonlyArray<ClientType>;
63
+ context: GeneratorContext;
64
+ }
65
+ /**
66
+ * Input for server generator
67
+ */
68
+ export interface ServerGeneratorInput {
69
+ plugin: ORPCPluginInstance;
70
+ routerSymbol: ReturnType<ORPCPluginInstance["symbol"]>;
71
+ serverFile: string;
72
+ }
73
+ export {};
74
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","source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,CAAC;IAC3B,8EAA8E;IAC9E,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;IACvC,OAAO,EAAE,gBAAgB,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,kBAAkB,CAAC;IAC3B,YAAY,EAAE,UAAU,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC;IACvD,UAAU,EAAE,MAAM,CAAC;CACpB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/generators/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import "./types";
2
+ export { defaultConfig, defineConfig } from "./config";
3
+ export type { ORPCPlugin } from "./types";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,CAAC;AAEjB,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACvD,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ import "./types";
2
+ export { defaultConfig, defineConfig } from "./config";
3
+ //# sourceMappingURL=index.js.map