@nest-native/trpc 0.5.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 (53) hide show
  1. package/README.md +200 -0
  2. package/dist/constants.d.ts +7 -0
  3. package/dist/constants.js +11 -0
  4. package/dist/constants.js.map +1 -0
  5. package/dist/context/trpc-context-creator.d.ts +93 -0
  6. package/dist/context/trpc-context-creator.js +260 -0
  7. package/dist/context/trpc-context-creator.js.map +1 -0
  8. package/dist/context/trpc-enhancer-runtime.factory.d.ts +10 -0
  9. package/dist/context/trpc-enhancer-runtime.factory.js +31 -0
  10. package/dist/context/trpc-enhancer-runtime.factory.js.map +1 -0
  11. package/dist/decorators/ctx.decorator.d.ts +9 -0
  12. package/dist/decorators/ctx.decorator.js +19 -0
  13. package/dist/decorators/ctx.decorator.js.map +1 -0
  14. package/dist/decorators/input.decorator.d.ts +9 -0
  15. package/dist/decorators/input.decorator.js +19 -0
  16. package/dist/decorators/input.decorator.js.map +1 -0
  17. package/dist/decorators/param-metadata.util.d.ts +7 -0
  18. package/dist/decorators/param-metadata.util.js +22 -0
  19. package/dist/decorators/param-metadata.util.js.map +1 -0
  20. package/dist/decorators/procedure.decorator.d.ts +34 -0
  21. package/dist/decorators/procedure.decorator.js +58 -0
  22. package/dist/decorators/procedure.decorator.js.map +1 -0
  23. package/dist/decorators/router.decorator.d.ts +11 -0
  24. package/dist/decorators/router.decorator.js +23 -0
  25. package/dist/decorators/router.decorator.js.map +1 -0
  26. package/dist/enums.d.ts +9 -0
  27. package/dist/enums.js +15 -0
  28. package/dist/enums.js.map +1 -0
  29. package/dist/generators/schema-generator.d.ts +29 -0
  30. package/dist/generators/schema-generator.js +171 -0
  31. package/dist/generators/schema-generator.js.map +1 -0
  32. package/dist/generators/zod-serializer.d.ts +9 -0
  33. package/dist/generators/zod-serializer.js +137 -0
  34. package/dist/generators/zod-serializer.js.map +1 -0
  35. package/dist/index.d.ts +9 -0
  36. package/dist/index.js +27 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/interfaces.d.ts +58 -0
  39. package/dist/interfaces.js +3 -0
  40. package/dist/interfaces.js.map +1 -0
  41. package/dist/trpc-http-adapter.d.ts +27 -0
  42. package/dist/trpc-http-adapter.js +209 -0
  43. package/dist/trpc-http-adapter.js.map +1 -0
  44. package/dist/trpc-request-storage.d.ts +12 -0
  45. package/dist/trpc-request-storage.js +6 -0
  46. package/dist/trpc-request-storage.js.map +1 -0
  47. package/dist/trpc-router.d.ts +40 -0
  48. package/dist/trpc-router.js +346 -0
  49. package/dist/trpc-router.js.map +1 -0
  50. package/dist/trpc.module.d.ts +24 -0
  51. package/dist/trpc.module.js +72 -0
  52. package/dist/trpc.module.js.map +1 -0
  53. package/package.json +74 -0
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TrpcContext = TrpcContext;
4
+ const enums_1 = require("../enums");
5
+ const param_metadata_util_1 = require("./param-metadata.util");
6
+ /**
7
+ * Extracts request context data from a tRPC procedure call.
8
+ *
9
+ * - `@TrpcContext()` injects the full tRPC context object.
10
+ * - `@TrpcContext('field')` injects a field from the context object.
11
+ *
12
+ * @publicApi
13
+ */
14
+ function TrpcContext(data) {
15
+ return (target, propertyKey, index) => {
16
+ (0, param_metadata_util_1.addTrpcParamMetadata)(target, propertyKey, index, enums_1.TrpcParamtype.CONTEXT, data);
17
+ };
18
+ }
19
+ //# sourceMappingURL=ctx.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ctx.decorator.js","sourceRoot":"","sources":["../../decorators/ctx.decorator.ts"],"names":[],"mappings":";;AAWA,kCAUC;AArBD,oCAAyC;AACzC,+DAA6D;AAE7D;;;;;;;GAOG;AACH,SAAgB,WAAW,CAAC,IAAa;IACvC,OAAO,CAAC,MAAc,EAAE,WAAwC,EAAE,KAAK,EAAE,EAAE;QACzE,IAAA,0CAAoB,EAClB,MAAM,EACN,WAAW,EACX,KAAK,EACL,qBAAa,CAAC,OAAO,EACrB,IAAI,CACL,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Extracts input data from a tRPC procedure call.
3
+ *
4
+ * - `@Input()` injects the full input object.
5
+ * - `@Input('field')` injects a field from the input object.
6
+ *
7
+ * @publicApi
8
+ */
9
+ export declare function Input(data?: string): ParameterDecorator;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Input = Input;
4
+ const enums_1 = require("../enums");
5
+ const param_metadata_util_1 = require("./param-metadata.util");
6
+ /**
7
+ * Extracts input data from a tRPC procedure call.
8
+ *
9
+ * - `@Input()` injects the full input object.
10
+ * - `@Input('field')` injects a field from the input object.
11
+ *
12
+ * @publicApi
13
+ */
14
+ function Input(data) {
15
+ return (target, propertyKey, index) => {
16
+ (0, param_metadata_util_1.addTrpcParamMetadata)(target, propertyKey, index, enums_1.TrpcParamtype.INPUT, data);
17
+ };
18
+ }
19
+ //# sourceMappingURL=input.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input.decorator.js","sourceRoot":"","sources":["../../decorators/input.decorator.ts"],"names":[],"mappings":";;AAWA,sBAIC;AAfD,oCAAyC;AACzC,+DAA6D;AAE7D;;;;;;;GAOG;AACH,SAAgB,KAAK,CAAC,IAAa;IACjC,OAAO,CAAC,MAAc,EAAE,WAAwC,EAAE,KAAK,EAAE,EAAE;QACzE,IAAA,0CAAoB,EAAC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,qBAAa,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC9E,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { TrpcParamtype } from '../enums';
2
+ export interface TrpcParamMetadata {
3
+ index: number;
4
+ type: TrpcParamtype;
5
+ data?: string;
6
+ }
7
+ export declare function addTrpcParamMetadata(target: object, propertyKey: string | symbol | undefined, parameterIndex: number, paramtype: TrpcParamtype, data?: string): void;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addTrpcParamMetadata = addTrpcParamMetadata;
4
+ const constants_1 = require("../constants");
5
+ function addTrpcParamMetadata(target, propertyKey, parameterIndex, paramtype, data) {
6
+ if (propertyKey == null) {
7
+ return;
8
+ }
9
+ const callback = target[propertyKey];
10
+ if (typeof callback !== 'function') {
11
+ return;
12
+ }
13
+ const metadata = Reflect.getMetadata(constants_1.TRPC_PARAM_ARGS_METADATA, callback) ?? [];
14
+ metadata.push({
15
+ index: parameterIndex,
16
+ type: paramtype,
17
+ data,
18
+ });
19
+ metadata.sort((a, b) => a.index - b.index);
20
+ Reflect.defineMetadata(constants_1.TRPC_PARAM_ARGS_METADATA, metadata, callback);
21
+ }
22
+ //# sourceMappingURL=param-metadata.util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"param-metadata.util.js","sourceRoot":"","sources":["../../decorators/param-metadata.util.ts"],"names":[],"mappings":";;AASA,oDA0BC;AAnCD,4CAAwD;AASxD,SAAgB,oBAAoB,CAClC,MAAc,EACd,WAAwC,EACxC,cAAsB,EACtB,SAAwB,EACxB,IAAa;IAEb,IAAI,WAAW,IAAI,IAAI,EAAE,CAAC;QACxB,OAAO;IACT,CAAC;IACD,MAAM,QAAQ,GAAI,MAA2C,CAAC,WAAW,CAAC,CAAC;IAC3E,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;QACnC,OAAO;IACT,CAAC;IAED,MAAM,QAAQ,GACZ,OAAO,CAAC,WAAW,CAAC,oCAAwB,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;IAEhE,QAAQ,CAAC,IAAI,CAAC;QACZ,KAAK,EAAE,cAAc;QACrB,IAAI,EAAE,SAAS;QACf,IAAI;KACL,CAAC,CAAC;IACH,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;IAE3C,OAAO,CAAC,cAAc,CAAC,oCAAwB,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;AACvE,CAAC"}
@@ -0,0 +1,34 @@
1
+ interface ProcedureOptions {
2
+ /** Custom tRPC input schema (e.g. a Zod schema). Applied via `.input()`. */
3
+ input?: any;
4
+ /** Custom tRPC output schema (e.g. a Zod schema). Applied via `.output()`. */
5
+ output?: any;
6
+ }
7
+ /**
8
+ * Marks a method as a tRPC query procedure.
9
+ *
10
+ * @param name - Optional procedure name (defaults to the method name).
11
+ * @param options - Optional input/output schemas.
12
+ *
13
+ * @publicApi
14
+ */
15
+ export declare const Query: (nameOrOptions?: string | ProcedureOptions, options?: ProcedureOptions) => MethodDecorator;
16
+ /**
17
+ * Marks a method as a tRPC mutation procedure.
18
+ *
19
+ * @param name - Optional procedure name (defaults to the method name).
20
+ * @param options - Optional input/output schemas.
21
+ *
22
+ * @publicApi
23
+ */
24
+ export declare const Mutation: (nameOrOptions?: string | ProcedureOptions, options?: ProcedureOptions) => MethodDecorator;
25
+ /**
26
+ * Marks a method as a tRPC subscription procedure.
27
+ *
28
+ * @param name - Optional procedure name (defaults to the method name).
29
+ * @param options - Optional input/output schemas.
30
+ *
31
+ * @publicApi
32
+ */
33
+ export declare const Subscription: (nameOrOptions?: string | ProcedureOptions, options?: ProcedureOptions) => MethodDecorator;
34
+ export {};
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Subscription = exports.Mutation = exports.Query = void 0;
4
+ const constants_1 = require("../constants");
5
+ const enums_1 = require("../enums");
6
+ function createProcedureDecorator(type) {
7
+ return (nameOrOptions, options) => {
8
+ let procedureName;
9
+ let opts = {};
10
+ if (typeof nameOrOptions === 'string') {
11
+ procedureName = nameOrOptions;
12
+ opts = options ?? {};
13
+ }
14
+ else if (typeof nameOrOptions === 'object') {
15
+ opts = nameOrOptions;
16
+ }
17
+ return (target, key, descriptor) => {
18
+ const name = procedureName ?? String(key);
19
+ Reflect.defineMetadata(constants_1.TRPC_PROCEDURE_METADATA, name, descriptor.value);
20
+ Reflect.defineMetadata(constants_1.TRPC_PROCEDURE_TYPE_METADATA, type, descriptor.value);
21
+ if (opts.input) {
22
+ Reflect.defineMetadata(constants_1.TRPC_INPUT_METADATA, opts.input, descriptor.value);
23
+ }
24
+ if (opts.output) {
25
+ Reflect.defineMetadata(constants_1.TRPC_OUTPUT_METADATA, opts.output, descriptor.value);
26
+ }
27
+ return descriptor;
28
+ };
29
+ };
30
+ }
31
+ /**
32
+ * Marks a method as a tRPC query procedure.
33
+ *
34
+ * @param name - Optional procedure name (defaults to the method name).
35
+ * @param options - Optional input/output schemas.
36
+ *
37
+ * @publicApi
38
+ */
39
+ exports.Query = createProcedureDecorator(enums_1.ProcedureType.QUERY);
40
+ /**
41
+ * Marks a method as a tRPC mutation procedure.
42
+ *
43
+ * @param name - Optional procedure name (defaults to the method name).
44
+ * @param options - Optional input/output schemas.
45
+ *
46
+ * @publicApi
47
+ */
48
+ exports.Mutation = createProcedureDecorator(enums_1.ProcedureType.MUTATION);
49
+ /**
50
+ * Marks a method as a tRPC subscription procedure.
51
+ *
52
+ * @param name - Optional procedure name (defaults to the method name).
53
+ * @param options - Optional input/output schemas.
54
+ *
55
+ * @publicApi
56
+ */
57
+ exports.Subscription = createProcedureDecorator(enums_1.ProcedureType.SUBSCRIPTION);
58
+ //# sourceMappingURL=procedure.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"procedure.decorator.js","sourceRoot":"","sources":["../../decorators/procedure.decorator.ts"],"names":[],"mappings":";;;AAAA,4CAKsB;AACtB,oCAAyC;AASzC,SAAS,wBAAwB,CAAC,IAAmB;IACnD,OAAO,CACL,aAAyC,EACzC,OAA0B,EACT,EAAE;QACnB,IAAI,aAAiC,CAAC;QACtC,IAAI,IAAI,GAAqB,EAAE,CAAC;QAEhC,IAAI,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for `@Query()`, `@Mutation()`, and `@Subscription()` methods,
5
+ * which become tRPC procedures on the merged router.
6
+ *
7
+ * @param alias - Optional prefix that nests all procedures under a sub-router.
8
+ *
9
+ * @publicApi
10
+ */
11
+ export declare function Router(alias?: string): ClassDecorator;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Router = Router;
4
+ const common_1 = require("@nestjs/common");
5
+ const constants_1 = require("../constants");
6
+ /**
7
+ * Marks a class as a tRPC router.
8
+ *
9
+ * The class will be scanned for `@Query()`, `@Mutation()`, and `@Subscription()` methods,
10
+ * which become tRPC procedures on the merged router.
11
+ *
12
+ * @param alias - Optional prefix that nests all procedures under a sub-router.
13
+ *
14
+ * @publicApi
15
+ */
16
+ function Router(alias) {
17
+ const metadata = { alias };
18
+ return (target) => {
19
+ (0, common_1.Injectable)()(target);
20
+ (0, common_1.SetMetadata)(constants_1.TRPC_ROUTER_METADATA, metadata)(target);
21
+ };
22
+ }
23
+ //# sourceMappingURL=router.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router.decorator.js","sourceRoot":"","sources":["../../decorators/router.decorator.ts"],"names":[],"mappings":";;AAcA,wBAMC;AApBD,2CAAyD;AACzD,4CAAoD;AAGpD;;;;;;;;;GASG;AACH,SAAgB,MAAM,CAAC,KAAc;IACnC,MAAM,QAAQ,GAAuB,EAAE,KAAK,EAAE,CAAC;IAC/C,OAAO,CAAC,MAAgB,EAAE,EAAE;QAC1B,IAAA,mBAAU,GAAE,CAAC,MAAM,CAAC,CAAC;QACrB,IAAA,oBAAW,EAAC,gCAAoB,EAAE,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC;IACtD,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,9 @@
1
+ export declare enum ProcedureType {
2
+ QUERY = "query",
3
+ MUTATION = "mutation",
4
+ SUBSCRIPTION = "subscription"
5
+ }
6
+ export declare enum TrpcParamtype {
7
+ INPUT = 0,
8
+ CONTEXT = 1
9
+ }
package/dist/enums.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TrpcParamtype = exports.ProcedureType = void 0;
4
+ var ProcedureType;
5
+ (function (ProcedureType) {
6
+ ProcedureType["QUERY"] = "query";
7
+ ProcedureType["MUTATION"] = "mutation";
8
+ ProcedureType["SUBSCRIPTION"] = "subscription";
9
+ })(ProcedureType || (exports.ProcedureType = ProcedureType = {}));
10
+ var TrpcParamtype;
11
+ (function (TrpcParamtype) {
12
+ TrpcParamtype[TrpcParamtype["INPUT"] = 0] = "INPUT";
13
+ TrpcParamtype[TrpcParamtype["CONTEXT"] = 1] = "CONTEXT";
14
+ })(TrpcParamtype || (exports.TrpcParamtype = TrpcParamtype = {}));
15
+ //# sourceMappingURL=enums.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enums.js","sourceRoot":"","sources":["../enums.ts"],"names":[],"mappings":";;;AAAA,IAAY,aAIX;AAJD,WAAY,aAAa;IACvB,gCAAe,CAAA;IACf,sCAAqB,CAAA;IACrB,8CAA6B,CAAA;AAC/B,CAAC,EAJW,aAAa,6BAAb,aAAa,QAIxB;AAED,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,mDAAS,CAAA;IACT,uDAAW,CAAA;AACb,CAAC,EAHW,aAAa,6BAAb,aAAa,QAGxB"}
@@ -0,0 +1,29 @@
1
+ import { ProcedureType } from '../enums';
2
+ export interface ProcedureInfo {
3
+ name: string;
4
+ type: ProcedureType;
5
+ inputSchema?: any;
6
+ outputSchema?: any;
7
+ }
8
+ export interface RouterInfo {
9
+ alias?: string;
10
+ procedures: ProcedureInfo[];
11
+ }
12
+ /**
13
+ * Generates a TypeScript file containing the typed `AppRouter`
14
+ * for tRPC client consumption.
15
+ *
16
+ * The generated file is for **type inference only** — it uses placeholder
17
+ * handlers that are never executed at runtime. This mirrors the
18
+ * `autoSchemaFile` pattern from `@nestjs/graphql`.
19
+ *
20
+ * @internal
21
+ */
22
+ export declare function generateSchema(routers: RouterInfo[], filePath: string): void;
23
+ /**
24
+ * Produces the TypeScript source for the generated AppRouter file.
25
+ * Exported separately for testing.
26
+ *
27
+ * @internal
28
+ */
29
+ export declare function generateSchemaContent(routers: RouterInfo[]): string;
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateSchema = generateSchema;
4
+ exports.generateSchemaContent = generateSchemaContent;
5
+ const fs_1 = require("fs");
6
+ const path_1 = require("path");
7
+ const enums_1 = require("../enums");
8
+ const zod_serializer_1 = require("./zod-serializer");
9
+ /**
10
+ * Generates a TypeScript file containing the typed `AppRouter`
11
+ * for tRPC client consumption.
12
+ *
13
+ * The generated file is for **type inference only** — it uses placeholder
14
+ * handlers that are never executed at runtime. This mirrors the
15
+ * `autoSchemaFile` pattern from `@nestjs/graphql`.
16
+ *
17
+ * @internal
18
+ */
19
+ function generateSchema(routers, filePath) {
20
+ const content = generateSchemaContent(routers);
21
+ (0, fs_1.mkdirSync)((0, path_1.dirname)(filePath), { recursive: true });
22
+ (0, fs_1.writeFileSync)(filePath, content, 'utf-8');
23
+ }
24
+ /**
25
+ * Produces the TypeScript source for the generated AppRouter file.
26
+ * Exported separately for testing.
27
+ *
28
+ * @internal
29
+ */
30
+ function generateSchemaContent(routers) {
31
+ const lines = [
32
+ '// ------------------------------------------------------',
33
+ '// THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY)',
34
+ '// @nest-native/trpc',
35
+ '// ------------------------------------------------------',
36
+ '',
37
+ "import { initTRPC } from '@trpc/server';",
38
+ ];
39
+ const usesZod = routers.some(r => r.procedures.some(p => p.inputSchema || p.outputSchema));
40
+ if (usesZod) {
41
+ lines.push("import { z } from 'zod';");
42
+ }
43
+ lines.push('');
44
+ lines.push('const t = initTRPC.create();');
45
+ lines.push('');
46
+ // Group procedures: aliased → sub-routers, un-aliased → root
47
+ const schemaDeclarations = [];
48
+ const rootProcedures = [];
49
+ const aliasedGroups = new Map();
50
+ let schemaDeclarationIndex = 0;
51
+ for (const router of routers) {
52
+ const scope = router.alias ?? 'root';
53
+ const mapProcedure = (procedure) => {
54
+ const renderable = { ...procedure };
55
+ if (procedure.inputSchema) {
56
+ renderable.inputSchemaVarName = createSchemaVariableName(scope, procedure.name, 'input', schemaDeclarationIndex++);
57
+ schemaDeclarations.push(`const ${renderable.inputSchemaVarName} = ${(0, zod_serializer_1.serializeZodSchema)(procedure.inputSchema)};`);
58
+ }
59
+ if (procedure.outputSchema) {
60
+ renderable.outputSchemaVarName = createSchemaVariableName(scope, procedure.name, 'output', schemaDeclarationIndex++);
61
+ schemaDeclarations.push(`const ${renderable.outputSchemaVarName} = ${(0, zod_serializer_1.serializeZodSchema)(procedure.outputSchema)};`);
62
+ }
63
+ return renderable;
64
+ };
65
+ if (router.alias) {
66
+ const existing = aliasedGroups.get(router.alias) ?? [];
67
+ existing.push(...router.procedures.map(mapProcedure));
68
+ aliasedGroups.set(router.alias, existing);
69
+ }
70
+ else {
71
+ rootProcedures.push(...router.procedures.map(mapProcedure));
72
+ }
73
+ }
74
+ if (schemaDeclarations.length > 0) {
75
+ lines.push(...schemaDeclarations);
76
+ lines.push('');
77
+ }
78
+ const nestedRouterMap = {};
79
+ for (const [alias, procedures] of aliasedGroups) {
80
+ const procedureLines = procedures.map(p => ` ${formatProcedure(p)},`);
81
+ const routerBlock = `t.router({\n${procedureLines.join('\n')}\n })`;
82
+ assignNestedAliasEntry(nestedRouterMap, alias, routerBlock);
83
+ }
84
+ const nestedEntries = renderNestedMapEntries(nestedRouterMap, 1);
85
+ const rootEntries = rootProcedures.map(proc => ` ${formatProcedure(proc)}`);
86
+ const routerEntries = [...nestedEntries, ...rootEntries];
87
+ lines.push('const appRouter = t.router({');
88
+ lines.push(routerEntries.join(',\n'));
89
+ lines.push('});');
90
+ lines.push('');
91
+ lines.push('export type AppRouter = typeof appRouter;');
92
+ lines.push('');
93
+ return lines.join('\n');
94
+ }
95
+ function assignNestedAliasEntry(target, alias, routerBlock) {
96
+ const segments = alias
97
+ .split('.')
98
+ .map(segment => segment.trim())
99
+ .filter(Boolean);
100
+ if (segments.length === 0) {
101
+ return;
102
+ }
103
+ let cursor = target;
104
+ for (let index = 0; index < segments.length - 1; index += 1) {
105
+ const segment = segments[index];
106
+ const existing = cursor[segment];
107
+ if (!existing || typeof existing !== 'object') {
108
+ cursor[segment] = {};
109
+ }
110
+ cursor = cursor[segment];
111
+ }
112
+ cursor[segments[segments.length - 1]] = routerBlock;
113
+ }
114
+ function renderNestedMapEntries(node, depth) {
115
+ const indent = ' '.repeat(depth);
116
+ const childIndent = ' '.repeat(depth + 1);
117
+ const entries = [];
118
+ for (const [key, value] of Object.entries(node)) {
119
+ if (typeof value === 'string') {
120
+ entries.push(`${indent}${key}: ${value}`);
121
+ continue;
122
+ }
123
+ const children = renderNestedMapEntries(value, depth + 1);
124
+ entries.push(`${indent}${key}: {\n${children.join(',\n')}\n${indent}}`);
125
+ }
126
+ return entries;
127
+ }
128
+ function formatProcedure(proc) {
129
+ let chain = 't.procedure';
130
+ if (proc.inputSchemaVarName) {
131
+ chain += `.input(${proc.inputSchemaVarName})`;
132
+ }
133
+ if (proc.outputSchemaVarName && proc.type !== enums_1.ProcedureType.SUBSCRIPTION) {
134
+ chain += `.output(${proc.outputSchemaVarName})`;
135
+ }
136
+ const placeholder = getTypedPlaceholder(proc.outputSchemaVarName);
137
+ switch (proc.type) {
138
+ case enums_1.ProcedureType.QUERY:
139
+ chain += `.query(() => ${placeholder})`;
140
+ break;
141
+ case enums_1.ProcedureType.MUTATION:
142
+ chain += `.mutation(() => ${placeholder})`;
143
+ break;
144
+ case enums_1.ProcedureType.SUBSCRIPTION:
145
+ chain += `.subscription(async function* () { yield ${placeholder}; })`;
146
+ break;
147
+ }
148
+ return `${proc.name}: ${chain}`;
149
+ }
150
+ function getTypedPlaceholder(outputSchemaVarName) {
151
+ if (!outputSchemaVarName) {
152
+ return 'undefined as unknown';
153
+ }
154
+ return `null as unknown as z.infer<typeof ${outputSchemaVarName}>`;
155
+ }
156
+ function createSchemaVariableName(scope, procedureName, kind, index) {
157
+ const safeScope = sanitizeIdentifier(scope);
158
+ const safeProcedureName = sanitizeIdentifier(procedureName);
159
+ return `schema_${safeScope}_${safeProcedureName}_${kind}_${index}`;
160
+ }
161
+ function sanitizeIdentifier(value) {
162
+ const sanitized = value.replace(/[^a-zA-Z0-9_]/g, '_');
163
+ if (!sanitized) {
164
+ return 'unknown';
165
+ }
166
+ if (/^[0-9]/.test(sanitized)) {
167
+ return `_${sanitized}`;
168
+ }
169
+ return sanitized;
170
+ }
171
+ //# sourceMappingURL=schema-generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema-generator.js","sourceRoot":"","sources":["../../generators/schema-generator.ts"],"names":[],"mappings":";;AAgCA,wCAIC;AAQD,sDA2FC;AAvID,2BAA8C;AAC9C,+BAA+B;AAC/B,oCAAyC;AACzC,qDAAsD;AAmBtD;;;;;;;;;GASG;AACH,SAAgB,cAAc,CAAC,OAAqB,EAAE,QAAgB;IACpE,MAAM,OAAO,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;IAC/C,IAAA,cAAS,EAAC,IAAA,cAAO,EAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAClD,IAAA,kBAAa,EAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC;AAED;;;;;GAKG;AACH,SAAgB,qBAAqB,CAAC,OAAqB;IACzD,MAAM,KAAK,GAAa;QACtB,2DAA2D;QAC3D,0DAA0D;QAC1D,sBAAsB;QACtB,2DAA2D;QAC3D,EAAE;QACF,0CAA0C;KAC3C,CAAC;IAEF,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAC/B,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAA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;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Serializes a Zod schema runtime object back to its source-code representation.
3
+ *
4
+ * This is used by the schema generator to reconstruct `z.xxx()` calls
5
+ * in the auto-generated AppRouter file.
6
+ *
7
+ * @internal
8
+ */
9
+ export declare function serializeZodSchema(schema: any): string;
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.serializeZodSchema = serializeZodSchema;
4
+ /**
5
+ * Serializes a Zod schema runtime object back to its source-code representation.
6
+ *
7
+ * This is used by the schema generator to reconstruct `z.xxx()` calls
8
+ * in the auto-generated AppRouter file.
9
+ *
10
+ * @internal
11
+ */
12
+ function serializeZodSchema(schema) {
13
+ if (!schema || !schema._def) {
14
+ return 'z.any()';
15
+ }
16
+ const { type } = schema._def;
17
+ switch (type) {
18
+ case 'string':
19
+ return 'z.string()';
20
+ case 'number':
21
+ return 'z.number()';
22
+ case 'boolean':
23
+ return 'z.boolean()';
24
+ case 'bigint':
25
+ return 'z.bigint()';
26
+ case 'date':
27
+ return 'z.date()';
28
+ case 'undefined':
29
+ return 'z.undefined()';
30
+ case 'null':
31
+ return 'z.null()';
32
+ case 'void':
33
+ return 'z.void()';
34
+ case 'any':
35
+ return 'z.any()';
36
+ case 'unknown':
37
+ return 'z.unknown()';
38
+ case 'never':
39
+ return 'z.never()';
40
+ case 'object': {
41
+ const shape = typeof schema._def.shape === 'function'
42
+ ? schema._def.shape()
43
+ : schema._def.shape;
44
+ const entries = Object.entries(shape)
45
+ .map(([key, value]) => {
46
+ const serialized = serializeZodSchema(value);
47
+ const safeKey = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key)
48
+ ? key
49
+ : JSON.stringify(key);
50
+ return `${safeKey}: ${serialized}`;
51
+ })
52
+ .join(', ');
53
+ return `z.object({ ${entries} })`;
54
+ }
55
+ case 'array':
56
+ return `z.array(${serializeZodSchema(schema._def.element)})`;
57
+ case 'optional':
58
+ return `${serializeZodSchema(schema._def.innerType)}.optional()`;
59
+ case 'nullable':
60
+ return `${serializeZodSchema(schema._def.innerType)}.nullable()`;
61
+ case 'default': {
62
+ const defaultValue = schema._def.defaultValue;
63
+ return `${serializeZodSchema(schema._def.innerType)}.default(${JSON.stringify(defaultValue)})`;
64
+ }
65
+ case 'enum':
66
+ return `z.enum(${JSON.stringify(Object.values(schema._def.entries))})`;
67
+ case 'literal': {
68
+ const values = schema._def.values;
69
+ return `z.literal(${JSON.stringify(values.length > 1 ? values : values[0])})`;
70
+ }
71
+ case 'union': {
72
+ const options = schema._def.options
73
+ .map((opt) => serializeZodSchema(opt))
74
+ .join(', ');
75
+ if (schema._def.discriminator !== undefined) {
76
+ const discriminator = JSON.stringify(schema._def.discriminator);
77
+ return `z.discriminatedUnion(${discriminator}, [${options}])`;
78
+ }
79
+ return `z.union([${options}])`;
80
+ }
81
+ case 'discriminatedUnion': {
82
+ const discriminator = JSON.stringify(schema._def.discriminator);
83
+ const options = schema._def.options
84
+ .map((opt) => serializeZodSchema(opt))
85
+ .join(', ');
86
+ return `z.discriminatedUnion(${discriminator}, [${options}])`;
87
+ }
88
+ case 'intersection':
89
+ return `z.intersection(${serializeZodSchema(schema._def.left)}, ${serializeZodSchema(schema._def.right)})`;
90
+ case 'tuple': {
91
+ const items = schema._def.items
92
+ .map((item) => serializeZodSchema(item))
93
+ .join(', ');
94
+ const rest = schema._def.rest
95
+ ? `.rest(${serializeZodSchema(schema._def.rest)})`
96
+ : '';
97
+ return `z.tuple([${items}])${rest}`;
98
+ }
99
+ case 'record':
100
+ return `z.record(${serializeZodSchema(schema._def.keyType)}, ${serializeZodSchema(schema._def.valueType)})`;
101
+ case 'map':
102
+ return `z.map(${serializeZodSchema(schema._def.keyType)}, ${serializeZodSchema(schema._def.valueType)})`;
103
+ case 'set':
104
+ return `z.set(${serializeZodSchema(schema._def.valueType)})`;
105
+ case 'promise':
106
+ return `z.promise(${serializeZodSchema(schema._def.innerType)})`;
107
+ case 'effects':
108
+ // Effects (transform, refine, preprocess) — serialize the inner schema.
109
+ // The effect itself is runtime-only and doesn't affect the type used for inference.
110
+ return serializeZodSchema(schema._def.schema);
111
+ case 'lazy':
112
+ // Lazy schemas can't be serialized; fall back.
113
+ return 'z.any()';
114
+ case 'pipeline':
115
+ case 'pipe':
116
+ // For type inference, use the output schema.
117
+ // If the output side is a pure transform, preserve the input type schema.
118
+ const outSchema = schema._def.out;
119
+ const outDef = outSchema?._def ?? outSchema?.def;
120
+ if (outDef?.type === 'transform') {
121
+ return serializeZodSchema(schema._def.in);
122
+ }
123
+ return serializeZodSchema(outSchema);
124
+ case 'branded':
125
+ return serializeZodSchema(schema._def.innerType ?? schema._def.schema ?? schema._def.type);
126
+ case 'catch':
127
+ return serializeZodSchema(schema._def.innerType);
128
+ case 'readonly':
129
+ return `${serializeZodSchema(schema._def.innerType)}.readonly()`;
130
+ case 'nativeEnum':
131
+ // Native enums reference runtime values that can't be reconstructed.
132
+ return 'z.any()';
133
+ default:
134
+ return 'z.any()';
135
+ }
136
+ }
137
+ //# sourceMappingURL=zod-serializer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zod-serializer.js","sourceRoot":"","sources":["../../generators/zod-serializer.ts"],"names":[],"mappings":";;AAQA,gDA6JC;AArKD;;;;;;;GAOG;AACH,SAAgB,kBAAkB,CAAC,MAAW;IAC5C,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QAC5B,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC;IAE7B,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,QAAQ;YACX,OAAO,YAAY,CAAC;QACtB,KAAK,QAAQ;YACX,OAAO,YAAY,CAAC;QACtB,KAAK,SAAS;YACZ,OAAO,aAAa,CAAC;QACvB,KAAK,QAAQ;YACX,OAAO,YAAY,CAAC;QACtB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Module } from './trpc.module';
3
+ export { TrpcRouter } from './trpc-router';
4
+ export { Router } from './decorators/router.decorator';
5
+ export { Query, Mutation, Subscription, } from './decorators/procedure.decorator';
6
+ export { Input } from './decorators/input.decorator';
7
+ export { TrpcContext } from './decorators/ctx.decorator';
8
+ export { ProcedureType, TrpcParamtype } from './enums';
9
+ export type { TrpcModuleOptions, TrpcModuleAsyncOptions } from './interfaces';