@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.
- package/README.md +200 -0
- package/dist/constants.d.ts +7 -0
- package/dist/constants.js +11 -0
- package/dist/constants.js.map +1 -0
- package/dist/context/trpc-context-creator.d.ts +93 -0
- package/dist/context/trpc-context-creator.js +260 -0
- package/dist/context/trpc-context-creator.js.map +1 -0
- package/dist/context/trpc-enhancer-runtime.factory.d.ts +10 -0
- package/dist/context/trpc-enhancer-runtime.factory.js +31 -0
- package/dist/context/trpc-enhancer-runtime.factory.js.map +1 -0
- package/dist/decorators/ctx.decorator.d.ts +9 -0
- package/dist/decorators/ctx.decorator.js +19 -0
- package/dist/decorators/ctx.decorator.js.map +1 -0
- package/dist/decorators/input.decorator.d.ts +9 -0
- package/dist/decorators/input.decorator.js +19 -0
- package/dist/decorators/input.decorator.js.map +1 -0
- package/dist/decorators/param-metadata.util.d.ts +7 -0
- package/dist/decorators/param-metadata.util.js +22 -0
- package/dist/decorators/param-metadata.util.js.map +1 -0
- package/dist/decorators/procedure.decorator.d.ts +34 -0
- package/dist/decorators/procedure.decorator.js +58 -0
- package/dist/decorators/procedure.decorator.js.map +1 -0
- package/dist/decorators/router.decorator.d.ts +11 -0
- package/dist/decorators/router.decorator.js +23 -0
- package/dist/decorators/router.decorator.js.map +1 -0
- package/dist/enums.d.ts +9 -0
- package/dist/enums.js +15 -0
- package/dist/enums.js.map +1 -0
- package/dist/generators/schema-generator.d.ts +29 -0
- package/dist/generators/schema-generator.js +171 -0
- package/dist/generators/schema-generator.js.map +1 -0
- package/dist/generators/zod-serializer.d.ts +9 -0
- package/dist/generators/zod-serializer.js +137 -0
- package/dist/generators/zod-serializer.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces.d.ts +58 -0
- package/dist/interfaces.js +3 -0
- package/dist/interfaces.js.map +1 -0
- package/dist/trpc-http-adapter.d.ts +27 -0
- package/dist/trpc-http-adapter.js +209 -0
- package/dist/trpc-http-adapter.js.map +1 -0
- package/dist/trpc-request-storage.d.ts +12 -0
- package/dist/trpc-request-storage.js +6 -0
- package/dist/trpc-request-storage.js.map +1 -0
- package/dist/trpc-router.d.ts +40 -0
- package/dist/trpc-router.js +346 -0
- package/dist/trpc-router.js.map +1 -0
- package/dist/trpc.module.d.ts +24 -0
- package/dist/trpc.module.js +72 -0
- package/dist/trpc.module.js.map +1 -0
- package/package.json +74 -0
package/README.md
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
<p align="center">Decorator-first tRPC integration for NestJS with full Nest enhancer lifecycle support.</p>
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://www.npmjs.com/package/@nest-native/trpc"><img src="https://img.shields.io/npm/v/@nest-native/trpc.svg" alt="NPM Version" /></a>
|
|
5
|
+
<a href="https://www.npmjs.com/package/@nest-native/trpc"><img src="https://img.shields.io/npm/dm/@nest-native/trpc.svg" alt="NPM Downloads" /></a>
|
|
6
|
+
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/license-MIT-green.svg" alt="Package License" /></a>
|
|
7
|
+
<img src="https://img.shields.io/badge/coverage-100%25-brightgreen.svg" alt="Test Coverage" />
|
|
8
|
+
<a href="https://nest-native.github.io/trpc/"><img src="https://img.shields.io/badge/docs-%40nest--native%2Ftrpc-e0234e.svg" alt="Documentation" /></a>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
> [!IMPORTANT]
|
|
12
|
+
> **Renamed package.** This project was previously published as `nest-trpc-native`.
|
|
13
|
+
> It is now **`@nest-native/trpc`** (repo: [`nest-native/trpc`](https://github.com/nest-native/trpc)).
|
|
14
|
+
>
|
|
15
|
+
> ```bash
|
|
16
|
+
> npm uninstall nest-trpc-native
|
|
17
|
+
> npm install @nest-native/trpc
|
|
18
|
+
> ```
|
|
19
|
+
>
|
|
20
|
+
> Update imports from `nest-trpc-native` to `@nest-native/trpc`. The old package is frozen at `0.4.3` and is no longer maintained.
|
|
21
|
+
|
|
22
|
+
## What This Is
|
|
23
|
+
|
|
24
|
+
`@nest-native/trpc` is a community NestJS integration for building tRPC APIs with Nest-style modules, decorators, DI, enhancers, and request scope.
|
|
25
|
+
|
|
26
|
+
It makes tRPC feel native in Nest applications:
|
|
27
|
+
|
|
28
|
+
- Module setup via `TrpcModule.forRoot()` / `TrpcModule.forRootAsync()`
|
|
29
|
+
- Decorator-based routers with `@Router()`, `@Query()`, `@Mutation()`, `@Subscription()`
|
|
30
|
+
- Explicit parameter extraction via `@Input()` and `@TrpcContext()`
|
|
31
|
+
- Nest enhancer support for guards, interceptors, pipes, filters, and request scope
|
|
32
|
+
- Adapter-agnostic behavior across Express and Fastify
|
|
33
|
+
- Zod or `class-validator` validation, without forcing either style on every project
|
|
34
|
+
- Generated `AppRouter` types for fully typed tRPC clients
|
|
35
|
+
|
|
36
|
+
## Documentation
|
|
37
|
+
|
|
38
|
+
The documentation site is the canonical source of truth for guides and support policy:
|
|
39
|
+
|
|
40
|
+
- [Introduction](https://nest-native.github.io/trpc/docs/introduction)
|
|
41
|
+
- [Quick Start](https://nest-native.github.io/trpc/docs/quick-start)
|
|
42
|
+
- [Samples](https://nest-native.github.io/trpc/docs/samples)
|
|
43
|
+
- [Support Policy](https://nest-native.github.io/trpc/docs/support-policy)
|
|
44
|
+
|
|
45
|
+
See the showcase sample for a full end-to-end application:
|
|
46
|
+
|
|
47
|
+
- https://github.com/nest-native/trpc/tree/main/sample/00-showcase
|
|
48
|
+
|
|
49
|
+
## Compatibility
|
|
50
|
+
|
|
51
|
+
| Runtime | Supported line |
|
|
52
|
+
| --- | --- |
|
|
53
|
+
| Node.js | `>=20` |
|
|
54
|
+
| NestJS | `11.x` |
|
|
55
|
+
| tRPC | `11.x` |
|
|
56
|
+
| Zod | `4.x`, optional peer |
|
|
57
|
+
| Adapters | Express, Fastify |
|
|
58
|
+
|
|
59
|
+
## Installation
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
npm i @nest-native/trpc @trpc/server
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Peer dependencies:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
npm i @nestjs/common @nestjs/core reflect-metadata rxjs
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Optional (recommended for schema inference and validation, Zod v4):
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
npm i zod@^4
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Zero Runtime Dependency Design
|
|
78
|
+
|
|
79
|
+
`@nest-native/trpc` intentionally keeps its runtime dependency block empty (`"dependencies": {}`).
|
|
80
|
+
|
|
81
|
+
Why this is intentional:
|
|
82
|
+
|
|
83
|
+
- This package is an integration layer (NestJS <-> tRPC), not a standalone runtime.
|
|
84
|
+
- NestJS and tRPC should come from the host application to avoid version duplication and container mismatches.
|
|
85
|
+
- Core features here rely on peer/runtime primitives already present in Nest apps:
|
|
86
|
+
- metadata reflection (`reflect-metadata`)
|
|
87
|
+
- Nest DI/discovery (`@nestjs/common`, `@nestjs/core`)
|
|
88
|
+
- tRPC adapters (`@trpc/server`)
|
|
89
|
+
- Node built-ins for file generation (`fs`, `path`)
|
|
90
|
+
|
|
91
|
+
## Why Zod Is Optional (and When You Need It)
|
|
92
|
+
|
|
93
|
+
Short answer: **Zod is not mandatory** for the package to work.
|
|
94
|
+
|
|
95
|
+
- If you prefer classic Nest validation (`class-validator` + `ValidationPipe`), you can use this package without Zod-specific decorators/schemas.
|
|
96
|
+
- If you use tRPC-style schema definitions (`@Query({ input: z.object(...) })`, `@Mutation({ output: ... })`) and `autoSchemaFile` generation for those schemas, then Zod v4 is required by your app code.
|
|
97
|
+
|
|
98
|
+
Should we remove Zod support entirely?
|
|
99
|
+
|
|
100
|
+
- We should **not** remove it: Zod support is a core part of the tRPC-first DX and one of the main interoperability goals.
|
|
101
|
+
- Keeping `zod@^4` as an **optional peer dependency** is the best balance:
|
|
102
|
+
- no forced runtime dependency
|
|
103
|
+
- clear compatibility contract when users choose Zod
|
|
104
|
+
- full support for mixed validation strategies in the same project
|
|
105
|
+
|
|
106
|
+
## Quick Start
|
|
107
|
+
|
|
108
|
+
### Non-Zod (class-validator + ValidationPipe)
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
import { Module, UsePipes, ValidationPipe } from '@nestjs/common';
|
|
112
|
+
import { IsString, MinLength } from 'class-validator';
|
|
113
|
+
import { Input, Mutation, Query, Router, TrpcModule } from '@nest-native/trpc';
|
|
114
|
+
|
|
115
|
+
class CreateUserDto {
|
|
116
|
+
@IsString()
|
|
117
|
+
@MinLength(1)
|
|
118
|
+
name!: string;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
@Router('users')
|
|
122
|
+
class UsersRouter {
|
|
123
|
+
@Query()
|
|
124
|
+
list() {
|
|
125
|
+
return [{ id: '1', name: 'Ada' }];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
@Mutation()
|
|
129
|
+
@UsePipes(new ValidationPipe({ whitelist: true }))
|
|
130
|
+
create(@Input() input: CreateUserDto) {
|
|
131
|
+
return { id: '2', ...input };
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
@Module({
|
|
136
|
+
imports: [
|
|
137
|
+
TrpcModule.forRoot({
|
|
138
|
+
path: '/trpc',
|
|
139
|
+
autoSchemaFile: 'src/@generated/server.ts',
|
|
140
|
+
}),
|
|
141
|
+
],
|
|
142
|
+
providers: [UsersRouter],
|
|
143
|
+
})
|
|
144
|
+
export class AppModule {}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Zod
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
import { Module } from '@nestjs/common';
|
|
151
|
+
import {
|
|
152
|
+
Input,
|
|
153
|
+
Mutation,
|
|
154
|
+
Query,
|
|
155
|
+
Router,
|
|
156
|
+
TrpcContext,
|
|
157
|
+
TrpcModule,
|
|
158
|
+
} from '@nest-native/trpc';
|
|
159
|
+
import { z } from 'zod';
|
|
160
|
+
|
|
161
|
+
const CreateUserSchema = z.object({ name: z.string().min(1) });
|
|
162
|
+
|
|
163
|
+
@Router('users')
|
|
164
|
+
class UsersRouter {
|
|
165
|
+
@Query({ output: z.array(z.object({ id: z.string(), name: z.string() })) })
|
|
166
|
+
list(@TrpcContext('requestId') requestId: string) {
|
|
167
|
+
return [{ id: requestId, name: 'Ada' }];
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
@Mutation({ input: CreateUserSchema })
|
|
171
|
+
create(@Input() input: { name: string }) {
|
|
172
|
+
return { id: '1', ...input };
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
@Module({
|
|
177
|
+
imports: [
|
|
178
|
+
TrpcModule.forRoot({
|
|
179
|
+
path: '/trpc',
|
|
180
|
+
autoSchemaFile: 'src/@generated/server.ts',
|
|
181
|
+
}),
|
|
182
|
+
],
|
|
183
|
+
providers: [UsersRouter],
|
|
184
|
+
})
|
|
185
|
+
export class AppModule {}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Sample
|
|
189
|
+
|
|
190
|
+
The full production-style sample lives in `sample/00-showcase` and demonstrates:
|
|
191
|
+
|
|
192
|
+
- Modular router composition with constructor DI
|
|
193
|
+
- Mixed validation (`zod` + `class-validator`)
|
|
194
|
+
- Guards, pipes, interceptors, and filters on procedures
|
|
195
|
+
- Typed client generation and compile-time checks
|
|
196
|
+
- Express and Fastify runtime entrypoints
|
|
197
|
+
|
|
198
|
+
## License
|
|
199
|
+
|
|
200
|
+
This project is MIT licensed.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const TRPC_MODULE_OPTIONS = "TRPC_MODULE_OPTIONS";
|
|
2
|
+
export declare const TRPC_ROUTER_METADATA = "trpc:router";
|
|
3
|
+
export declare const TRPC_PROCEDURE_METADATA = "trpc:procedure";
|
|
4
|
+
export declare const TRPC_PROCEDURE_TYPE_METADATA = "trpc:procedure_type";
|
|
5
|
+
export declare const TRPC_INPUT_METADATA = "trpc:input";
|
|
6
|
+
export declare const TRPC_OUTPUT_METADATA = "trpc:output";
|
|
7
|
+
export declare const TRPC_PARAM_ARGS_METADATA = "__trpcParamArgs__";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TRPC_PARAM_ARGS_METADATA = exports.TRPC_OUTPUT_METADATA = exports.TRPC_INPUT_METADATA = exports.TRPC_PROCEDURE_TYPE_METADATA = exports.TRPC_PROCEDURE_METADATA = exports.TRPC_ROUTER_METADATA = exports.TRPC_MODULE_OPTIONS = void 0;
|
|
4
|
+
exports.TRPC_MODULE_OPTIONS = 'TRPC_MODULE_OPTIONS';
|
|
5
|
+
exports.TRPC_ROUTER_METADATA = 'trpc:router';
|
|
6
|
+
exports.TRPC_PROCEDURE_METADATA = 'trpc:procedure';
|
|
7
|
+
exports.TRPC_PROCEDURE_TYPE_METADATA = 'trpc:procedure_type';
|
|
8
|
+
exports.TRPC_INPUT_METADATA = 'trpc:input';
|
|
9
|
+
exports.TRPC_OUTPUT_METADATA = 'trpc:output';
|
|
10
|
+
exports.TRPC_PARAM_ARGS_METADATA = '__trpcParamArgs__';
|
|
11
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,mBAAmB,GAAG,qBAAqB,CAAC;AAC5C,QAAA,oBAAoB,GAAG,aAAa,CAAC;AACrC,QAAA,uBAAuB,GAAG,gBAAgB,CAAC;AAC3C,QAAA,4BAA4B,GAAG,qBAAqB,CAAC;AACrD,QAAA,mBAAmB,GAAG,YAAY,CAAC;AACnC,QAAA,oBAAoB,GAAG,aAAa,CAAC;AACrC,QAAA,wBAAwB,GAAG,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { ContextType, PipeTransform } from '@nestjs/common';
|
|
2
|
+
import { Controller } from '@nestjs/common/interfaces';
|
|
3
|
+
import { ExecutionContextHost } from '@nestjs/core/helpers/execution-context-host';
|
|
4
|
+
interface TrpcHandlerOptions {
|
|
5
|
+
callback: (...args: any[]) => any;
|
|
6
|
+
methodName: string;
|
|
7
|
+
moduleKey: string;
|
|
8
|
+
paramTypes?: unknown[];
|
|
9
|
+
inquirerId?: string;
|
|
10
|
+
resolveContextId?: () => {
|
|
11
|
+
id: number;
|
|
12
|
+
};
|
|
13
|
+
resolveInstance: (contextId: {
|
|
14
|
+
id: number;
|
|
15
|
+
}) => Promise<Controller>;
|
|
16
|
+
}
|
|
17
|
+
type TrpcCallback = (...args: any[]) => any;
|
|
18
|
+
type TrpcContextId = {
|
|
19
|
+
id: number;
|
|
20
|
+
};
|
|
21
|
+
interface TrpcGuardsContextCreatorLike {
|
|
22
|
+
create(instance: Controller, callback: TrpcCallback, moduleKey: string, contextId: TrpcContextId, inquirerId?: string): unknown[];
|
|
23
|
+
}
|
|
24
|
+
interface TrpcGuardsConsumerLike {
|
|
25
|
+
tryActivate(guards: unknown[], args: unknown[], instance: Controller, callback: TrpcCallback, type: ContextType): Promise<boolean>;
|
|
26
|
+
}
|
|
27
|
+
interface TrpcInterceptorsContextCreatorLike {
|
|
28
|
+
create(instance: Controller, callback: TrpcCallback, moduleKey: string, contextId: TrpcContextId, inquirerId?: string): unknown[];
|
|
29
|
+
}
|
|
30
|
+
interface TrpcInterceptorsConsumerLike {
|
|
31
|
+
intercept(interceptors: unknown[], args: unknown[], instance: Controller, callback: TrpcCallback, next: () => Promise<unknown>, type: ContextType): Promise<unknown>;
|
|
32
|
+
}
|
|
33
|
+
interface TrpcPipesContextCreatorLike {
|
|
34
|
+
create(instance: Controller, callback: TrpcCallback, moduleKey: string, contextId: TrpcContextId, inquirerId?: string): PipeTransform[];
|
|
35
|
+
}
|
|
36
|
+
interface TrpcPipesConsumerLike {
|
|
37
|
+
apply(value: unknown, metadata: {
|
|
38
|
+
type: unknown;
|
|
39
|
+
metatype?: unknown;
|
|
40
|
+
data?: string;
|
|
41
|
+
}, pipes: PipeTransform[]): Promise<unknown>;
|
|
42
|
+
}
|
|
43
|
+
interface TrpcExceptionHandlerLike {
|
|
44
|
+
next(error: Error, executionContext: ExecutionContextHost): Promise<unknown>;
|
|
45
|
+
}
|
|
46
|
+
interface TrpcExceptionFiltersContextLike {
|
|
47
|
+
create(instance: Controller, callback: TrpcCallback, moduleKey: string, contextId: TrpcContextId, inquirerId?: string): TrpcExceptionHandlerLike;
|
|
48
|
+
}
|
|
49
|
+
export interface TrpcEnhancerRuntime {
|
|
50
|
+
guardsContextCreator: TrpcGuardsContextCreatorLike;
|
|
51
|
+
guardsConsumer: TrpcGuardsConsumerLike;
|
|
52
|
+
interceptorsContextCreator: TrpcInterceptorsContextCreatorLike;
|
|
53
|
+
interceptorsConsumer: TrpcInterceptorsConsumerLike;
|
|
54
|
+
pipesContextCreator: TrpcPipesContextCreatorLike;
|
|
55
|
+
pipesConsumer: TrpcPipesConsumerLike;
|
|
56
|
+
exceptionFiltersContext: TrpcExceptionFiltersContextLike;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Creates execution-context-aware wrappers for tRPC procedure handlers.
|
|
60
|
+
*
|
|
61
|
+
* Integrates NestJS guards, interceptors, pipes, and exception filters
|
|
62
|
+
* into the tRPC request lifecycle, mirroring Nest external context handling.
|
|
63
|
+
*
|
|
64
|
+
* @internal
|
|
65
|
+
*/
|
|
66
|
+
export declare class TrpcContextCreator {
|
|
67
|
+
private readonly runtime;
|
|
68
|
+
constructor(runtime: TrpcEnhancerRuntime);
|
|
69
|
+
constructor(guardsContextCreator: TrpcGuardsContextCreatorLike, guardsConsumer: TrpcGuardsConsumerLike, interceptorsContextCreator: TrpcInterceptorsContextCreatorLike, interceptorsConsumer: TrpcInterceptorsConsumerLike, pipesContextCreator: TrpcPipesContextCreatorLike, pipesConsumer: TrpcPipesConsumerLike, exceptionFiltersContext: TrpcExceptionFiltersContextLike);
|
|
70
|
+
private isEnhancerRuntime;
|
|
71
|
+
/**
|
|
72
|
+
* Backward-compatible overload for existing unit tests and internal callers.
|
|
73
|
+
*/
|
|
74
|
+
create(instance: Controller, callback: (...args: any[]) => any, moduleKey: string, contextId?: {
|
|
75
|
+
id: number;
|
|
76
|
+
}, inquirerId?: string): (input: unknown, ctx: unknown) => Promise<unknown>;
|
|
77
|
+
/**
|
|
78
|
+
* Preferred overload used by TrpcRouter for request-scoped resolution.
|
|
79
|
+
*/
|
|
80
|
+
create(options: TrpcHandlerOptions): (input: unknown, ctx: unknown) => Promise<unknown>;
|
|
81
|
+
private createHandler;
|
|
82
|
+
private handleException;
|
|
83
|
+
private applyPipes;
|
|
84
|
+
private getPipeTargets;
|
|
85
|
+
private resolveHandlerArgs;
|
|
86
|
+
private extractParamValue;
|
|
87
|
+
private pickField;
|
|
88
|
+
private transformToResult;
|
|
89
|
+
private toTrpcError;
|
|
90
|
+
private extractHttpExceptionMessage;
|
|
91
|
+
private mapHttpStatusToTrpcCode;
|
|
92
|
+
}
|
|
93
|
+
export {};
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.TrpcContextCreator = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const route_paramtypes_enum_1 = require("@nestjs/common/enums/route-paramtypes.enum");
|
|
15
|
+
const execution_context_host_1 = require("@nestjs/core/helpers/execution-context-host");
|
|
16
|
+
const constants_1 = require("@nestjs/core/injector/constants");
|
|
17
|
+
const server_1 = require("@trpc/server");
|
|
18
|
+
const rxjs_1 = require("rxjs");
|
|
19
|
+
const constants_2 = require("../constants");
|
|
20
|
+
const enums_1 = require("../enums");
|
|
21
|
+
const TRPC_CONTEXT_TYPE = 'rpc';
|
|
22
|
+
/**
|
|
23
|
+
* Creates execution-context-aware wrappers for tRPC procedure handlers.
|
|
24
|
+
*
|
|
25
|
+
* Integrates NestJS guards, interceptors, pipes, and exception filters
|
|
26
|
+
* into the tRPC request lifecycle, mirroring Nest external context handling.
|
|
27
|
+
*
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
let TrpcContextCreator = class TrpcContextCreator {
|
|
31
|
+
constructor(runtimeOrGuardsContextCreator, guardsConsumer, interceptorsContextCreator, interceptorsConsumer, pipesContextCreator, pipesConsumer, exceptionFiltersContext) {
|
|
32
|
+
if (this.isEnhancerRuntime(runtimeOrGuardsContextCreator)) {
|
|
33
|
+
this.runtime = runtimeOrGuardsContextCreator;
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (!guardsConsumer ||
|
|
37
|
+
!interceptorsContextCreator ||
|
|
38
|
+
!interceptorsConsumer ||
|
|
39
|
+
!pipesContextCreator ||
|
|
40
|
+
!pipesConsumer ||
|
|
41
|
+
!exceptionFiltersContext) {
|
|
42
|
+
throw new Error('Invalid TrpcContextCreator configuration');
|
|
43
|
+
}
|
|
44
|
+
this.runtime = {
|
|
45
|
+
guardsContextCreator: runtimeOrGuardsContextCreator,
|
|
46
|
+
guardsConsumer,
|
|
47
|
+
interceptorsContextCreator,
|
|
48
|
+
interceptorsConsumer,
|
|
49
|
+
pipesContextCreator,
|
|
50
|
+
pipesConsumer,
|
|
51
|
+
exceptionFiltersContext,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
isEnhancerRuntime(value) {
|
|
55
|
+
return (typeof value === 'object' &&
|
|
56
|
+
value !== null &&
|
|
57
|
+
'guardsContextCreator' in value &&
|
|
58
|
+
'guardsConsumer' in value &&
|
|
59
|
+
'interceptorsContextCreator' in value &&
|
|
60
|
+
'interceptorsConsumer' in value &&
|
|
61
|
+
'pipesContextCreator' in value &&
|
|
62
|
+
'pipesConsumer' in value &&
|
|
63
|
+
'exceptionFiltersContext' in value);
|
|
64
|
+
}
|
|
65
|
+
create(instanceOrOptions, callback, moduleKey, contextId = constants_1.STATIC_CONTEXT, inquirerId) {
|
|
66
|
+
if (typeof callback === 'function' && moduleKey !== undefined) {
|
|
67
|
+
const instance = instanceOrOptions;
|
|
68
|
+
return this.createHandler({
|
|
69
|
+
callback,
|
|
70
|
+
methodName: callback.name,
|
|
71
|
+
moduleKey,
|
|
72
|
+
inquirerId,
|
|
73
|
+
resolveContextId: () => contextId,
|
|
74
|
+
resolveInstance: async () => instance,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return this.createHandler(instanceOrOptions);
|
|
78
|
+
}
|
|
79
|
+
createHandler(options) {
|
|
80
|
+
const paramMetadata = Reflect.getMetadata(constants_2.TRPC_PARAM_ARGS_METADATA, options.callback) ?? [];
|
|
81
|
+
const paramTypes = options.paramTypes ?? [];
|
|
82
|
+
return async (input, trpcCtx) => {
|
|
83
|
+
const currentContextId = options.resolveContextId?.() ?? constants_1.STATIC_CONTEXT;
|
|
84
|
+
const instance = await options.resolveInstance(currentContextId);
|
|
85
|
+
const callbackCandidate = instance[options.methodName] ??
|
|
86
|
+
options.callback;
|
|
87
|
+
if (typeof callbackCandidate !== 'function') {
|
|
88
|
+
throw new server_1.TRPCError({
|
|
89
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
90
|
+
message: `Unable to resolve tRPC handler "${options.methodName}"`,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
const callback = callbackCandidate;
|
|
94
|
+
const guards = this.runtime.guardsContextCreator.create(instance, callback, options.moduleKey, currentContextId, options.inquirerId);
|
|
95
|
+
const interceptors = this.runtime.interceptorsContextCreator.create(instance, callback, options.moduleKey, currentContextId, options.inquirerId);
|
|
96
|
+
const pipes = this.runtime.pipesContextCreator.create(instance, callback, options.moduleKey, currentContextId, options.inquirerId);
|
|
97
|
+
const exceptionHandler = this.runtime.exceptionFiltersContext.create(instance, callback, options.moduleKey, currentContextId, options.inquirerId);
|
|
98
|
+
const contextArgs = [input, trpcCtx];
|
|
99
|
+
const executionContext = new execution_context_host_1.ExecutionContextHost(contextArgs, instance.constructor, callback);
|
|
100
|
+
executionContext.setType(TRPC_CONTEXT_TYPE);
|
|
101
|
+
try {
|
|
102
|
+
if (guards.length) {
|
|
103
|
+
const canActivate = await this.runtime.guardsConsumer.tryActivate(guards, contextArgs, instance, callback, TRPC_CONTEXT_TYPE);
|
|
104
|
+
if (!canActivate) {
|
|
105
|
+
throw new common_1.ForbiddenException('Forbidden');
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const handler = async () => {
|
|
109
|
+
const handlerArgs = this.resolveHandlerArgs(input, trpcCtx, paramMetadata);
|
|
110
|
+
if (pipes.length) {
|
|
111
|
+
await this.applyPipes(handlerArgs, pipes, paramMetadata, paramTypes);
|
|
112
|
+
}
|
|
113
|
+
return callback.call(instance, ...handlerArgs);
|
|
114
|
+
};
|
|
115
|
+
const result = interceptors.length > 0
|
|
116
|
+
? await this.runtime.interceptorsConsumer.intercept(interceptors, contextArgs, instance, callback, handler, TRPC_CONTEXT_TYPE)
|
|
117
|
+
: await handler();
|
|
118
|
+
// `return await` is required (not just `return`): when an interceptor
|
|
119
|
+
// returns a deferred Observable, `transformToResult` yields a Promise
|
|
120
|
+
// that may reject after subscription. Without `await`, the rejection
|
|
121
|
+
// escapes this try/catch and HttpExceptions are mis-mapped to
|
|
122
|
+
// INTERNAL_SERVER_ERROR by the @trpc/server boundary.
|
|
123
|
+
return await this.transformToResult(result);
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
return this.handleException(error, exceptionHandler, executionContext);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
async handleException(error, exceptionHandler, executionContext) {
|
|
131
|
+
try {
|
|
132
|
+
return await exceptionHandler.next(error, executionContext);
|
|
133
|
+
}
|
|
134
|
+
catch (filteredError) {
|
|
135
|
+
throw this.toTrpcError(filteredError);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async applyPipes(args, pipes, metadata, paramTypes) {
|
|
139
|
+
const targets = this.getPipeTargets(metadata);
|
|
140
|
+
for (const target of targets) {
|
|
141
|
+
args[target.index] = await this.runtime.pipesConsumer.apply(args[target.index], {
|
|
142
|
+
type: route_paramtypes_enum_1.RouteParamtypes.BODY,
|
|
143
|
+
metatype: paramTypes[target.index],
|
|
144
|
+
data: target.data,
|
|
145
|
+
}, pipes);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
getPipeTargets(metadata) {
|
|
149
|
+
if (!metadata.length) {
|
|
150
|
+
return [{ index: 0 }];
|
|
151
|
+
}
|
|
152
|
+
return metadata
|
|
153
|
+
.filter(param => param.type === enums_1.TrpcParamtype.INPUT)
|
|
154
|
+
.map(param => ({ index: param.index, data: param.data }));
|
|
155
|
+
}
|
|
156
|
+
resolveHandlerArgs(input, trpcCtx, metadata) {
|
|
157
|
+
if (!metadata.length) {
|
|
158
|
+
return [input, trpcCtx];
|
|
159
|
+
}
|
|
160
|
+
const size = Math.max(...metadata.map(param => param.index)) + 1;
|
|
161
|
+
const args = new Array(size).fill(undefined);
|
|
162
|
+
for (const param of metadata) {
|
|
163
|
+
args[param.index] = this.extractParamValue(param, input, trpcCtx);
|
|
164
|
+
}
|
|
165
|
+
return args;
|
|
166
|
+
}
|
|
167
|
+
extractParamValue(param, input, trpcCtx) {
|
|
168
|
+
if (param.type === enums_1.TrpcParamtype.INPUT) {
|
|
169
|
+
return this.pickField(input, param.data);
|
|
170
|
+
}
|
|
171
|
+
return this.pickField(trpcCtx, param.data);
|
|
172
|
+
}
|
|
173
|
+
pickField(value, field) {
|
|
174
|
+
if (!field) {
|
|
175
|
+
return value;
|
|
176
|
+
}
|
|
177
|
+
if (!value || typeof value !== 'object') {
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
return value[field];
|
|
181
|
+
}
|
|
182
|
+
async transformToResult(resultOrDeferred) {
|
|
183
|
+
if ((0, rxjs_1.isObservable)(resultOrDeferred)) {
|
|
184
|
+
return (0, rxjs_1.lastValueFrom)(resultOrDeferred);
|
|
185
|
+
}
|
|
186
|
+
return resultOrDeferred;
|
|
187
|
+
}
|
|
188
|
+
toTrpcError(error) {
|
|
189
|
+
if (error instanceof server_1.TRPCError) {
|
|
190
|
+
return error;
|
|
191
|
+
}
|
|
192
|
+
if (error instanceof common_1.HttpException) {
|
|
193
|
+
return new server_1.TRPCError({
|
|
194
|
+
code: this.mapHttpStatusToTrpcCode(error.getStatus()),
|
|
195
|
+
message: this.extractHttpExceptionMessage(error),
|
|
196
|
+
cause: error,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
if (error instanceof Error) {
|
|
200
|
+
return new server_1.TRPCError({
|
|
201
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
202
|
+
message: error.message,
|
|
203
|
+
cause: error,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
return new server_1.TRPCError({
|
|
207
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
208
|
+
message: 'Internal server error',
|
|
209
|
+
cause: error,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
extractHttpExceptionMessage(exception) {
|
|
213
|
+
const response = exception.getResponse();
|
|
214
|
+
if (typeof response === 'string') {
|
|
215
|
+
return response;
|
|
216
|
+
}
|
|
217
|
+
if (response &&
|
|
218
|
+
typeof response === 'object' &&
|
|
219
|
+
'message' in response &&
|
|
220
|
+
response.message) {
|
|
221
|
+
if (Array.isArray(response.message)) {
|
|
222
|
+
return response.message.join(', ');
|
|
223
|
+
}
|
|
224
|
+
if (typeof response.message === 'string') {
|
|
225
|
+
return response.message;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return exception.message;
|
|
229
|
+
}
|
|
230
|
+
mapHttpStatusToTrpcCode(status) {
|
|
231
|
+
const codeByStatus = {
|
|
232
|
+
400: 'BAD_REQUEST',
|
|
233
|
+
401: 'UNAUTHORIZED',
|
|
234
|
+
402: 'PAYMENT_REQUIRED',
|
|
235
|
+
403: 'FORBIDDEN',
|
|
236
|
+
404: 'NOT_FOUND',
|
|
237
|
+
405: 'METHOD_NOT_SUPPORTED',
|
|
238
|
+
408: 'TIMEOUT',
|
|
239
|
+
409: 'CONFLICT',
|
|
240
|
+
412: 'PRECONDITION_FAILED',
|
|
241
|
+
413: 'PAYLOAD_TOO_LARGE',
|
|
242
|
+
415: 'UNSUPPORTED_MEDIA_TYPE',
|
|
243
|
+
422: 'UNPROCESSABLE_CONTENT',
|
|
244
|
+
428: 'PRECONDITION_REQUIRED',
|
|
245
|
+
429: 'TOO_MANY_REQUESTS',
|
|
246
|
+
499: 'CLIENT_CLOSED_REQUEST',
|
|
247
|
+
501: 'NOT_IMPLEMENTED',
|
|
248
|
+
502: 'BAD_GATEWAY',
|
|
249
|
+
503: 'SERVICE_UNAVAILABLE',
|
|
250
|
+
504: 'GATEWAY_TIMEOUT',
|
|
251
|
+
};
|
|
252
|
+
return codeByStatus[status] ?? 'INTERNAL_SERVER_ERROR';
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
exports.TrpcContextCreator = TrpcContextCreator;
|
|
256
|
+
exports.TrpcContextCreator = TrpcContextCreator = __decorate([
|
|
257
|
+
(0, common_1.Injectable)(),
|
|
258
|
+
__metadata("design:paramtypes", [Object, Object, Object, Object, Object, Object, Object])
|
|
259
|
+
], TrpcContextCreator);
|
|
260
|
+
//# sourceMappingURL=trpc-context-creator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trpc-context-creator.js","sourceRoot":"","sources":["../../context/trpc-context-creator.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAMwB;AACxB,sFAA6E;AAE7E,wFAAmF;AACnF,+DAAiE;AACjE,yCAA8D;AAC9D,+BAAmD;AACnD,4CAAwD;AAExD,oCAAyC;AAEzC,MAAM,iBAAiB,GAAgB,KAAK,CAAC;AAsG7C;;;;;;;GAOG;AAEI,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAa7B,YACE,6BAEgC,EAChC,cAAuC,EACvC,0BAA+D,EAC/D,oBAAmD,EACnD,mBAAiD,EACjD,aAAqC,EACrC,uBAAyD;QAEzD,IAAI,IAAI,CAAC,iBAAiB,CAAC,6BAA6B,CAAC,EAAE,CAAC;YAC1D,IAAI,CAAC,OAAO,GAAG,6BAA6B,CAAC;YAC7C,OAAO;QACT,CAAC;QAED,IACE,CAAC,cAAc;YACf,CAAC,0BAA0B;YAC3B,CAAC,oBAAoB;YACrB,CAAC,mBAAmB;YACpB,CAAC,aAAa;YACd,CAAC,uBAAuB,EACxB,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;QAC9D,CAAC;QAED,IAAI,CAAC,OAAO,GAAG;YACb,oBAAoB,EAAE,6BAA6B;YACnD,cAAc;YACd,0BAA0B;YAC1B,oBAAoB;YACpB,mBAAmB;YACnB,aAAa;YACb,uBAAuB;SACxB,CAAC;IACJ,CAAC;IAEO,iBAAiB,CACvB,KAAyD;QAEzD,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;YACzB,KAAK,KAAK,IAAI;Y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Q,CAAC,OAAO,CAAC;YAC1B,CAAC;QACH,CAAC;QACD,OAAO,SAAS,CAAC,OAAO,CAAC;IAC3B,CAAC;IAEO,uBAAuB,CAAC,MAAc;QAC5C,MAAM,YAAY,GAAiD;YACjE,GAAG,EAAE,aAAa;YAClB,GAAG,EAAE,cAAc;YACnB,GAAG,EAAE,kBAAkB;YACvB,GAAG,EAAE,WAAW;YAChB,GAAG,EAAE,WAAW;YAChB,GAAG,EAAE,sBAAsB;YAC3B,GAAG,EAAE,SAAS;YACd,GAAG,EAAE,UAAU;YACf,GAAG,EAAE,qBAAqB;YAC1B,GAAG,EAAE,mBAAmB;YACxB,GAAG,EAAE,wBAAwB;YAC7B,GAAG,EAAE,uBAAuB;YAC5B,GAAG,EAAE,uBAAuB;YAC5B,GAAG,EAAE,mBAAmB;YACxB,GAAG,EAAE,uBAAuB;YAC5B,GAAG,EAAE,iBAAiB;YACtB,GAAG,EAAE,aAAa;YAClB,GAAG,EAAE,qBAAqB;YAC1B,GAAG,EAAE,iBAAiB;SACvB,CAAC;QAEF,OAAO,YAAY,CAAC,MAAM,CAAC,IAAI,uBAAuB,CAAC;IACzD,CAAC;CACF,CAAA;AAhYY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;;GACA,kBAAkB,CAgY9B"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ApplicationConfig } from '@nestjs/core';
|
|
2
|
+
import { ModulesContainer } from '@nestjs/core/injector/modules-container';
|
|
3
|
+
import { TrpcEnhancerRuntime } from './trpc-context-creator';
|
|
4
|
+
/**
|
|
5
|
+
* Isolates Nest internal enhancer creator wiring to a single boundary.
|
|
6
|
+
*
|
|
7
|
+
* This keeps TrpcContextCreator focused on orchestration logic and makes
|
|
8
|
+
* future Nest major upgrades cheaper to validate and patch.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createTrpcEnhancerRuntime(modulesContainer: ModulesContainer, applicationConfig: ApplicationConfig): TrpcEnhancerRuntime;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTrpcEnhancerRuntime = createTrpcEnhancerRuntime;
|
|
4
|
+
const external_exception_filter_context_1 = require("@nestjs/core/exceptions/external-exception-filter-context");
|
|
5
|
+
const guards_consumer_1 = require("@nestjs/core/guards/guards-consumer");
|
|
6
|
+
const guards_context_creator_1 = require("@nestjs/core/guards/guards-context-creator");
|
|
7
|
+
const interceptors_consumer_1 = require("@nestjs/core/interceptors/interceptors-consumer");
|
|
8
|
+
const interceptors_context_creator_1 = require("@nestjs/core/interceptors/interceptors-context-creator");
|
|
9
|
+
const pipes_consumer_1 = require("@nestjs/core/pipes/pipes-consumer");
|
|
10
|
+
const pipes_context_creator_1 = require("@nestjs/core/pipes/pipes-context-creator");
|
|
11
|
+
/**
|
|
12
|
+
* Isolates Nest internal enhancer creator wiring to a single boundary.
|
|
13
|
+
*
|
|
14
|
+
* This keeps TrpcContextCreator focused on orchestration logic and makes
|
|
15
|
+
* future Nest major upgrades cheaper to validate and patch.
|
|
16
|
+
*/
|
|
17
|
+
function createTrpcEnhancerRuntime(modulesContainer, applicationConfig) {
|
|
18
|
+
const containerRef = {
|
|
19
|
+
getModules: () => modulesContainer,
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
guardsContextCreator: new guards_context_creator_1.GuardsContextCreator(containerRef, applicationConfig),
|
|
23
|
+
guardsConsumer: new guards_consumer_1.GuardsConsumer(),
|
|
24
|
+
interceptorsContextCreator: new interceptors_context_creator_1.InterceptorsContextCreator(containerRef, applicationConfig),
|
|
25
|
+
interceptorsConsumer: new interceptors_consumer_1.InterceptorsConsumer(),
|
|
26
|
+
pipesContextCreator: new pipes_context_creator_1.PipesContextCreator(containerRef, applicationConfig),
|
|
27
|
+
pipesConsumer: new pipes_consumer_1.PipesConsumer(),
|
|
28
|
+
exceptionFiltersContext: new external_exception_filter_context_1.ExternalExceptionFilterContext(containerRef, applicationConfig),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=trpc-enhancer-runtime.factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trpc-enhancer-runtime.factory.js","sourceRoot":"","sources":["../../context/trpc-enhancer-runtime.factory.ts"],"names":[],"mappings":";;AAqBA,8DA6BC;AAjDD,iHAA2G;AAC3G,yEAAqE;AACrE,uFAAkF;AAClF,2FAAuF;AACvF,yGAAoG;AAEpG,sEAAkE;AAClE,oFAA+E;AAO/E;;;;;GAKG;AACH,SAAgB,yBAAyB,CACvC,gBAAkC,EAClC,iBAAoC;IAEpC,MAAM,YAAY,GAAqB;QACrC,UAAU,EAAE,GAAG,EAAE,CAAC,gBAAgB;KACnC,CAAC;IAEF,OAAO;QACL,oBAAoB,EAAE,IAAI,6CAAoB,CAC5C,YAAmB,EACnB,iBAAiB,CAClB;QACD,cAAc,EAAE,IAAI,gCAAc,EAAE;QACpC,0BAA0B,EAAE,IAAI,yDAA0B,CACxD,YAAmB,EACnB,iBAAiB,CAClB;QACD,oBAAoB,EAAE,IAAI,4CAAoB,EAAE;QAChD,mBAAmB,EAAE,IAAI,2CAAmB,CAC1C,YAAmB,EACnB,iBAAiB,CAClB;QACD,aAAa,EAAE,IAAI,8BAAa,EAAE;QAClC,uBAAuB,EAAE,IAAI,kEAA8B,CACzD,YAAmB,EACnB,iBAAiB,CAClB;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts request context data from a tRPC procedure call.
|
|
3
|
+
*
|
|
4
|
+
* - `@TrpcContext()` injects the full tRPC context object.
|
|
5
|
+
* - `@TrpcContext('field')` injects a field from the context object.
|
|
6
|
+
*
|
|
7
|
+
* @publicApi
|
|
8
|
+
*/
|
|
9
|
+
export declare function TrpcContext(data?: string): ParameterDecorator;
|