@silkweave/nestjs 2.4.0 → 2.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 +139 -6
- package/build/index-C1W-O7EX.d.mts +46 -0
- package/build/index-C1W-O7EX.d.mts.map +1 -0
- package/build/index.d.mts +126 -203
- package/build/index.d.mts.map +1 -1
- package/build/index.mjs +285 -8729
- package/build/index.mjs.map +1 -1
- package/build/mcp.d.mts +35 -0
- package/build/mcp.d.mts.map +1 -0
- package/build/mcp.mjs +61 -0
- package/build/mcp.mjs.map +1 -0
- package/build/trpc.d.mts +39 -0
- package/build/trpc.d.mts.map +1 -0
- package/build/trpc.mjs +59 -0
- package/build/trpc.mjs.map +1 -0
- package/build/typegen.d.mts +32 -0
- package/build/typegen.d.mts.map +1 -0
- package/build/typegen.mjs +36 -0
- package/build/typegen.mjs.map +1 -0
- package/build/types-ByWkPWx2.d.mts +162 -0
- package/build/types-ByWkPWx2.d.mts.map +1 -0
- package/package.json +41 -6
package/README.md
CHANGED
|
@@ -1,16 +1,30 @@
|
|
|
1
1
|
# @silkweave/nestjs
|
|
2
2
|
|
|
3
|
-
NestJS adapter for [Silkweave](https://github.com/silkweave/silkweave). Expose your **existing NestJS controllers** as MCP (Model Context Protocol) tools by adding a single `@Mcp()` decorator to a route handler. The
|
|
3
|
+
NestJS adapter for [Silkweave](https://github.com/silkweave/silkweave). Expose your **existing NestJS controllers** as MCP (Model Context Protocol) tools by adding a single `@Mcp()` decorator to a route handler - or as **end-to-end-typed tRPC procedures** with the sibling `@Trpc()` decorator. The name, description, and input schema are **reflected** from the route, the `@Param`/`@Query`/`@Body` decorators, and any `@nestjs/swagger` / `class-validator` metadata the method already carries - nothing is re-declared. On a call the validated input is split back into the method's positional arguments and the handler is invoked directly, with `@UseGuards()` guards applied first.
|
|
4
4
|
|
|
5
|
-
It is **additive**: controllers keep serving HTTP exactly as before, and removing `@Mcp()`
|
|
5
|
+
It is **additive**: controllers keep serving HTTP exactly as before, and removing the decorator fully reverts a method. The same method can carry both `@Mcp()` (for agents) and `@Trpc()` (for your frontend) alongside `@UseGuards()`.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
10
|
pnpm add @silkweave/core @silkweave/nestjs @nestjs/common @nestjs/core @nestjs/platform-express reflect-metadata
|
|
11
|
+
|
|
12
|
+
# then add only the adapter packages you use (each is an optional peer):
|
|
13
|
+
pnpm add @silkweave/mcp # if you use mcp()
|
|
14
|
+
pnpm add @silkweave/trpc # if you use trpc()
|
|
15
|
+
pnpm add @silkweave/typegen # if you use typegen()
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The adapters live behind **subpath exports** and their stacks are **optional peer dependencies**, so an MCP-only app never pulls in `@trpc/server`, and a tRPC-only app never pulls in the MCP SDK / OAuth stack. The decorators and module come from the root; each adapter from its subpath:
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { Mcp, Trpc, SilkweaveModule } from '@silkweave/nestjs'
|
|
22
|
+
import { mcp } from '@silkweave/nestjs/mcp'
|
|
23
|
+
import { trpc } from '@silkweave/nestjs/trpc'
|
|
24
|
+
import { typegen } from '@silkweave/nestjs/typegen'
|
|
11
25
|
```
|
|
12
26
|
|
|
13
|
-
`@nestjs/swagger` and `class-validator` are **optional** peers - install whichever your DTOs already use; the reflector reads both and falls back to TypeScript `design:type` when neither is present.
|
|
27
|
+
`@nestjs/swagger` and `class-validator` are **optional** peers too - install whichever your DTOs already use; the reflector reads both and falls back to TypeScript `design:type` when neither is present.
|
|
14
28
|
|
|
15
29
|
> NestJS needs decorator-aware transforms with `emitDecoratorMetadata`. Use `@swc-node/register` (`node --import @swc-node/register/esm-register src/main.ts`) or the `nest start` CLI; plain `tsx` does not emit decorator metadata.
|
|
16
30
|
|
|
@@ -70,7 +84,8 @@ export class UsersController {
|
|
|
70
84
|
```ts
|
|
71
85
|
// app.module.ts
|
|
72
86
|
import { Module } from '@nestjs/common'
|
|
73
|
-
import {
|
|
87
|
+
import { SilkweaveModule } from '@silkweave/nestjs'
|
|
88
|
+
import { mcp } from '@silkweave/nestjs/mcp'
|
|
74
89
|
import { AdminGuard } from './admin.guard.js'
|
|
75
90
|
import { UsersController } from './users.controller.js'
|
|
76
91
|
|
|
@@ -183,9 +198,127 @@ Mounts the MCP Streamable HTTP transport directly at `basePath`, with sideload (
|
|
|
183
198
|
| `sideloadResources` | `boolean` | `true` | Mount `{basePath}/resource/:id` |
|
|
184
199
|
| `resourceDir` | `string` | `'resources'` | Directory the sideload route reads from |
|
|
185
200
|
|
|
201
|
+
## tRPC
|
|
202
|
+
|
|
203
|
+
`@Trpc()` is the tRPC sibling of `@Mcp()`. It exposes a controller route as a tRPC procedure, reflecting its key, input, and kind from exactly the same sources `@Mcp` uses - so a single method can serve REST, MCP, and tRPC at once. Two things differ because tRPC consumers need them: **precise output types** in the generated router, and **subscriptions** for `async *` routes.
|
|
204
|
+
|
|
205
|
+
```ts
|
|
206
|
+
import { Mcp, Trpc } from '@silkweave/nestjs'
|
|
207
|
+
import { ApiOkResponse, ApiOperation } from '@nestjs/swagger'
|
|
208
|
+
|
|
209
|
+
class ListUsersResponse {
|
|
210
|
+
@ApiProperty({ type: [UserDto] }) users!: UserDto[]
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
@Controller('users')
|
|
214
|
+
export class UsersController {
|
|
215
|
+
@Get('list-by-space')
|
|
216
|
+
@ApiOperation({ summary: 'List the users in a space' })
|
|
217
|
+
@ApiOkResponse({ type: ListUsersResponse }) // ← drives the generated output type
|
|
218
|
+
@UseGuards(AuthGuard) // ← reads the real Express request (cookies/headers)
|
|
219
|
+
@Trpc() // → query `usersListBySpace`
|
|
220
|
+
@Mcp() // → MCP tool `UsersListBySpace`
|
|
221
|
+
listBySpace(@Query() q: ListBySpaceQuery, @Req() req: AppRequest) {
|
|
222
|
+
return this.users.listForSpace(req.user, q.spaceId)
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### `@Trpc(options?)` (method decorator)
|
|
228
|
+
|
|
229
|
+
| Option | Type | Default | Description |
|
|
230
|
+
|--------|------|---------|-------------|
|
|
231
|
+
| `name` | `string` | `${ControllerBase}.${MethodName}` | Procedure-name override (before camelCasing) |
|
|
232
|
+
| `description` | `string` | `@ApiOperation` summary/description, else generated | Procedure description |
|
|
233
|
+
| `input` | `Record<string, z.ZodType>` | - | Zod raw-shape override merged over reflected fields (same as `@Mcp({ input })`) |
|
|
234
|
+
| `output` | `z.ZodType \| DtoClass \| Record<string, z.ZodType>` | reflected from `@ApiOkResponse` | Explicit output schema driving the generated output type (wins over reflection) |
|
|
235
|
+
| `chunk` | `z.ZodType \| DtoClass` | `unknown` | Element type for a subscription's `async *` stream |
|
|
236
|
+
| `kind` | `'query' \| 'mutation' \| 'subscription'` | inferred | `@Get` ⇒ query, others ⇒ mutation, `async *` ⇒ subscription |
|
|
237
|
+
| `pipes` | `'apply' \| 'skip'` | `'apply'` | Whether to run parameter-bound pipes when re-binding |
|
|
238
|
+
|
|
239
|
+
### Naming & kind
|
|
240
|
+
|
|
241
|
+
Procedure keys are `camelCase(`${ControllerBase}.${MethodName}`)` - `UsersController.listBySpace` → `usersListBySpace` - matching the dotted-name → camelCase convention of the core tRPC adapter. Pin any exception with `@Trpc({ name })`. `kind` is inferred from the HTTP verb (`@Get` ⇒ `query`, otherwise `mutation`) or the method body (`async *` ⇒ `subscription`); override with `@Trpc({ kind })`.
|
|
242
|
+
|
|
243
|
+
### Output types (the precise part)
|
|
244
|
+
|
|
245
|
+
tRPC carries output types end-to-end, so the generated `AppRouter` needs them. In preference order:
|
|
246
|
+
|
|
247
|
+
1. **`@ApiOkResponse({ type: Dto })`** (or any 2xx `@ApiResponse`) - the response DTO is flattened like an input DTO into the procedure's output type.
|
|
248
|
+
2. **`@Trpc({ output })`** - an explicit Zod schema, DTO class, or raw shape. Wins over reflection. Use it when the return shape can't be reflected losslessly (e.g. **nested** DTOs and `Dto[]` arrays degrade to `unknown`/`unknown[]` - reflection is one level deep). For a precise nested shape, hand `@Trpc({ output })` a Zod schema.
|
|
249
|
+
|
|
250
|
+
### Subscriptions (`async *` ⇒ SSE)
|
|
251
|
+
|
|
252
|
+
An `async *` method is registered as a tRPC **subscription** served over SSE. It needs no HTTP verb - a verb-less `@Trpc({ kind: 'subscription', chunk })` exposes it over tRPC **without** creating a public REST route (see [tRPC/MCP without REST](#trpcmcp-without-a-public-rest-route)). Guards run before the first chunk.
|
|
253
|
+
|
|
254
|
+
```ts
|
|
255
|
+
@Trpc({ kind: 'subscription', chunk: BoardTick }) // → subscription `usersWatch`
|
|
256
|
+
async *watch(@Query() q: WatchQuery, @Req() req: AppRequest): AsyncGenerator<BoardTick> {
|
|
257
|
+
for await (const tick of this.board.stream(req.user, q)) { yield tick }
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### `trpc(options?)` adapter
|
|
262
|
+
|
|
263
|
+
Mounts a single tRPC HTTP handler (httpBatch for queries/mutations, SSE for subscriptions) on Nest's HTTP adapter at `basePath`, built from every `@Trpc` route.
|
|
264
|
+
|
|
265
|
+
| Option | Type | Default | Description |
|
|
266
|
+
|--------|------|---------|-------------|
|
|
267
|
+
| `basePath` | `string` | `'/trpc'` | URL prefix the handler mounts on |
|
|
268
|
+
| `cors` | `CorsOptions \| boolean` | `true` | CORS. For cookie auth pass `{ origin: '<spa-origin>', credentials: true }` |
|
|
269
|
+
| `auth` | `AuthConfig` | - | Optional transport-edge bearer validation. Usually omitted - `@Trpc` routes authenticate via their own `@UseGuards()` |
|
|
270
|
+
|
|
271
|
+
**Guards + cookie auth, no separate config.** Each procedure runs the method's `@UseGuards()` first, with the guard receiving a real `ExecutionContext` whose `switchToHttp().getRequest()` is the **actual Express request** (cookies, headers, `req.user`). So an `AuthGuard` reading an HttpOnly session cookie works with no auth config - the client just sends `credentials: 'include'` / `withCredentials`. A denying guard surfaces to the client as a `TRPCError` whose `data.httpStatus` is the guard's HTTP status (e.g. `401`/`403`), so a `splitLink`/`errorLink` can react.
|
|
272
|
+
|
|
273
|
+
Reach the authenticated principal + silkweave context from a handler with `@Req() req` (read `req.user`, set by the guard - works identically over REST, tRPC, and MCP).
|
|
274
|
+
|
|
275
|
+
### `typegen(options?)` adapter
|
|
276
|
+
|
|
277
|
+
On bootstrap, writes a `.ts` file containing the tRPC `AppRouter` type covering every `@Trpc` procedure - the exact `TRPCBuiltRouter` contract `createTRPCClient<AppRouter>()` and `inferRouterInputs`/`inferRouterOutputs` consume. It only sees `@Trpc` actions (MCP tools are gated out), so the emitted router matches what `trpc()` serves.
|
|
278
|
+
|
|
279
|
+
| Option | Type | Default | Description |
|
|
280
|
+
|--------|------|---------|-------------|
|
|
281
|
+
| `path` | `string` | - | Output file path (resolved against `process.cwd()`; parent dirs created) |
|
|
282
|
+
| `format` | `'trpc-router' \| 'interfaces' \| 'all'` | `'trpc-router'` | `'trpc-router'` emits `AppRouter`; `'interfaces'` emits `{Name}Input`/`{Name}Output`; `'all'` both |
|
|
283
|
+
|
|
284
|
+
```ts
|
|
285
|
+
// app.module.ts
|
|
286
|
+
import { SilkweaveModule } from '@silkweave/nestjs'
|
|
287
|
+
import { mcp } from '@silkweave/nestjs/mcp'
|
|
288
|
+
import { trpc } from '@silkweave/nestjs/trpc'
|
|
289
|
+
import { typegen } from '@silkweave/nestjs/typegen'
|
|
290
|
+
|
|
291
|
+
SilkweaveModule.forRoot({
|
|
292
|
+
silkweave: { name: 'my-app', description: 'My App', version: '1.0.0' },
|
|
293
|
+
adapters: [
|
|
294
|
+
mcp({ basePath: '/mcp', auth: mcpAuth }), // @Mcp methods → MCP tools (bearer/OAuth)
|
|
295
|
+
trpc({ basePath: '/trpc' }), // @Trpc methods → tRPC procedures (cookie/guard auth)
|
|
296
|
+
typegen({ path: '../app/src/types/appRouter.ts' })// @Trpc procedures → AppRouter type
|
|
297
|
+
]
|
|
298
|
+
})
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
```ts
|
|
302
|
+
// client - the emitted AppRouter is the only import you need
|
|
303
|
+
import { createTRPCClient, httpBatchLink, httpSubscriptionLink, splitLink } from '@trpc/client'
|
|
304
|
+
import type { AppRouter } from './types/appRouter.js'
|
|
305
|
+
|
|
306
|
+
export const trpc = createTRPCClient<AppRouter>({
|
|
307
|
+
links: [splitLink({
|
|
308
|
+
condition: (op) => op.type === 'subscription',
|
|
309
|
+
true: httpSubscriptionLink({ url: '/trpc' }), // SSE, withCredentials for cookies
|
|
310
|
+
false: httpBatchLink({ url: '/trpc', fetch: (u, o) => fetch(u, { ...o, credentials: 'include' }) })
|
|
311
|
+
})]
|
|
312
|
+
})
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
### tRPC/MCP without a public REST route
|
|
316
|
+
|
|
317
|
+
A `@Get`/`@Post` is inherently a public REST route. To expose a method over **tRPC and/or MCP only**, omit the HTTP-verb decorator: Nest never maps it as REST, and `@Trpc({ kind })` (or `@Mcp()`) still picks it up. This is how subscriptions (which are verb-less `async *` methods) and any internal-only procedure stay off the public REST surface.
|
|
318
|
+
|
|
186
319
|
## Guards & DI
|
|
187
320
|
|
|
188
|
-
Native NestJS `@UseGuards()` on `@Mcp` methods run before the handler is invoked. Guards receive an `ExecutionContext` with the request in `switchToHttp().getRequest()`, and the `Reflector` is wired up so guards can read custom metadata.
|
|
321
|
+
Native NestJS `@UseGuards()` on `@Mcp`/`@Trpc` methods run before the handler is invoked. Guards receive an `ExecutionContext` with the request in `switchToHttp().getRequest()`, and the `Reflector` is wired up so guards can read custom metadata.
|
|
189
322
|
|
|
190
323
|
**Headers over MCP.** The inbound tool-call request is surfaced as a stand-in `{ headers, url, params, query }` object built from the MCP SDK's `extra.requestInfo`, so a header-based guard - e.g. one reading `getRequest().headers['x-api-key']` - works unchanged. `ExecutionContext.getType()` is `'http'` whenever a request is available (and `'rpc'` for transports with none, e.g. MCP stdio). Caveats:
|
|
191
324
|
|
|
@@ -217,7 +350,7 @@ Because the handler is invoked directly (not through Nest's HTTP request pipelin
|
|
|
217
350
|
|
|
218
351
|
## Notes
|
|
219
352
|
|
|
220
|
-
- **Opt-in.** Only methods carrying `@Mcp()` are exposed - controllers are never auto-published.
|
|
353
|
+
- **Opt-in.** Only methods carrying `@Mcp()`/`@Trpc()` are exposed - controllers are never auto-published.
|
|
221
354
|
- **Express only by default.** `@nestjs/platform-fastify` requires `@fastify/express` registered upfront.
|
|
222
355
|
- **`reflect-metadata`** must be imported once at the top of your entry file.
|
|
223
356
|
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { SilkweaveContext } from "@silkweave/core";
|
|
2
|
+
|
|
3
|
+
//#region ../auth/build/index.d.mts
|
|
4
|
+
//#endregion
|
|
5
|
+
//#region src/provider/types.d.ts
|
|
6
|
+
interface AuthInfo {
|
|
7
|
+
token: string;
|
|
8
|
+
clientId?: string;
|
|
9
|
+
scopes?: string[];
|
|
10
|
+
expiresAt?: number;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
interface OAuthRequest {
|
|
14
|
+
method: string;
|
|
15
|
+
url: URL;
|
|
16
|
+
headers: Record<string, string | undefined>;
|
|
17
|
+
body?: Record<string, string>;
|
|
18
|
+
}
|
|
19
|
+
interface OAuthResponse {
|
|
20
|
+
status: number;
|
|
21
|
+
headers: Record<string, string>;
|
|
22
|
+
body?: string | Record<string, unknown>;
|
|
23
|
+
}
|
|
24
|
+
interface OAuthProvider {
|
|
25
|
+
authorize(req: OAuthRequest): Promise<OAuthResponse>;
|
|
26
|
+
callback(req: OAuthRequest): Promise<OAuthResponse>;
|
|
27
|
+
token(req: OAuthRequest): Promise<OAuthResponse>;
|
|
28
|
+
register(req: OAuthRequest): Promise<OAuthResponse>;
|
|
29
|
+
metadata(): OAuthResponse;
|
|
30
|
+
verifyToken(token: string): Promise<AuthInfo | undefined>;
|
|
31
|
+
} //#endregion
|
|
32
|
+
//#region src/types.d.ts
|
|
33
|
+
type VerifyToken = (token: string, context: SilkweaveContext) => Promise<AuthInfo | undefined>;
|
|
34
|
+
interface AuthConfig {
|
|
35
|
+
verifyToken: VerifyToken;
|
|
36
|
+
required?: boolean;
|
|
37
|
+
resourceUrl?: string;
|
|
38
|
+
authorizationServers?: string[];
|
|
39
|
+
requiredScopes?: string[];
|
|
40
|
+
provider?: OAuthProvider;
|
|
41
|
+
callbackPath?: string;
|
|
42
|
+
} //#endregion
|
|
43
|
+
//#region src/provider/store.d.ts
|
|
44
|
+
//#endregion
|
|
45
|
+
export { AuthConfig as t };
|
|
46
|
+
//# sourceMappingURL=index-C1W-O7EX.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-C1W-O7EX.d.mts","names":["SilkweaveContext","AuthError","Error","code","statusCode","constructor","message","invalidToken","insufficientScope","extractBearerToken","header","buildWWWAuthenticate","error","description","resourceMetadataUrl","ProtectedResourceMetadata","resource","authorization_servers","scopes_supported","bearer_methods_supported","generateProtectedResourceMetadata","resourceUrl","authorizationServers","AuthInfo","token","clientId","scopes","expiresAt","key","OAuthRequest","URL","Record","method","url","headers","body","OAuthResponse","status","OAuthProvider","Promise","authorize","req","callback","register","metadata","verifyToken","VerifyToken","context","AuthConfig","required","requiredScopes","provider","callbackPath","AuthCodeData","redirectUri","codeChallenge","codeChallengeMethod","upstreamAccessToken","upstreamIdToken","email","sub","PendingAuthData","scope","clientState","ClientRegistration","clientSecret","redirectUris","clientName","createdAt","RefreshTokenData","OAuthStore","saveAuthCode","data","getAuthCode","deleteAuthCode","savePendingAuth","state","getPendingAuth","deletePendingAuth","savePkceVerifier","verifier","getPkceVerifier","deletePkceVerifier","saveClient","getClient","saveRefreshToken","getRefreshToken","deleteRefreshToken","GoogleOAuthOptions","signingKey","tokenTtl","store","google","options","OAuthProxyConfig","authorizeUrl","tokenUrl","userinfoUrl","createOAuthProxy","config","matchRedirectUri","uri","patterns","createJsonStore","path","createMemoryStore","RedisClient","get","set","value","ex","del","RedisStoreOptions","client","prefix","createRedisStore","ValidateResult","auth","error_description","validateToken","authorizationHeader"],"sources":["../../auth/build/index.d.mts"],"mappings":";;;;;UAyBUuB,QAAAA;EACRC,KAAAA;EACAC,QAAAA;EACAC,MAAAA;EACAC,SAAAA;EAAAA,CACCC,GAAAA;AAAAA;AAAAA,UAEOC,YAAAA;EACRG,MAAAA;EACAC,GAAAA,EAAKH,GAAAA;EACLI,OAAAA,EAASH,MAAAA;EACTI,IAAAA,GAAOJ,MAAAA;AAAAA;AAAAA,UAECK,aAAAA;EACRC,MAAAA;EACAH,OAAAA,EAASH,MAAAA;EACTI,IAAAA,YAAgBJ,MAAAA;AAAAA;AAAAA,UAERO,aAAAA;EACRE,SAAAA,CAAUC,GAAAA,EAAKZ,YAAAA,GAAeU,OAAAA,CAAQH,aAAAA;EACtCM,QAAAA,CAASD,GAAAA,EAAKZ,YAAAA,GAAeU,OAAAA,CAAQH,aAAAA;EACrCZ,KAAAA,CAAMiB,GAAAA,EAAKZ,YAAAA,GAAeU,OAAAA,CAAQH,aAAAA;EAClCO,QAAAA,CAASF,GAAAA,EAAKZ,YAAAA,GAAeU,OAAAA,CAAQH,aAAAA;EACrCQ,QAAAA,IAAYR,aAAAA;EACZS,WAAAA,CAAYrB,KAAAA,WAAgBe,OAAAA,CAAQhB,QAAAA;AAAAA;AAAAA;AAAAA,KAIjCuB,WAAAA,IAAetB,KAAAA,UAAeuB,OAAAA,EAAS/C,gBAAAA,KAAqBuC,OAAAA,CAAQhB,QAAAA;AAAAA,UAC/DyB,UAAAA;EACRH,WAAAA,EAAaC,WAAAA;EACbG,QAAAA;EACA5B,WAAAA;EACAC,oBAAAA;EACA4B,cAAAA;EACAC,QAAAA,GAAWb,aAAAA;EACXc,YAAAA;AAAAA;AAAAA"}
|
package/build/index.d.mts
CHANGED
|
@@ -1,197 +1,14 @@
|
|
|
1
|
+
import { _ as reflectDtoFields, a as OpenApiDocument, c as openApiFields, d as classValidatorToField, f as designTypeToField, g as openapiSchemaToField, h as normalizeEnum, i as SilkweaveModuleOptions, l as FieldDesc, m as mergeField, n as NestSilkweaveAdapter, o as OpenApiLookup, p as fieldToZod, r as SILKWEAVE_MODULE_OPTIONS, s as buildOpenApiLookup, t as NestAdapterRegisterContext, u as apiPropertyToField, v as swaggerParamToField, y as typeTokenToBase } from "./types-ByWkPWx2.mjs";
|
|
1
2
|
import { CanActivate, DynamicModule, MiddlewareConsumer, NestModule, Type } from "@nestjs/common";
|
|
2
3
|
import { ApplicationConfig, DiscoveryService, HttpAdapterHost, MetadataScanner, ModuleRef, Reflector } from "@nestjs/core";
|
|
3
|
-
import { Action
|
|
4
|
+
import { Action } from "@silkweave/core";
|
|
4
5
|
import { z } from "zod/v4";
|
|
5
|
-
import { AuthConfig } from "@silkweave/auth";
|
|
6
|
-
import { CorsOptions } from "cors";
|
|
7
6
|
|
|
8
|
-
//#region src/lib/reflect/schema.d.ts
|
|
9
|
-
/**
|
|
10
|
-
* A transport-neutral description of a single input field. Every metadata
|
|
11
|
-
* source (swagger decorators, class-validator, an OpenAPI document, TypeScript
|
|
12
|
-
* `design:type`) is mapped to this shape, the shapes are merged by precedence,
|
|
13
|
-
* and the result is converted to Zod once. Keeping a single intermediate keeps
|
|
14
|
-
* the per-source mappers small and the Zod construction in one place.
|
|
15
|
-
*/
|
|
16
|
-
interface FieldDesc {
|
|
17
|
-
type?: 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object' | 'unknown';
|
|
18
|
-
required?: boolean;
|
|
19
|
-
description?: string;
|
|
20
|
-
enum?: (string | number)[];
|
|
21
|
-
items?: FieldDesc;
|
|
22
|
-
min?: number;
|
|
23
|
-
max?: number;
|
|
24
|
-
minLength?: number;
|
|
25
|
-
maxLength?: number;
|
|
26
|
-
format?: string;
|
|
27
|
-
default?: unknown;
|
|
28
|
-
}
|
|
29
|
-
/** Merge `over` onto `base` - defined keys of `over` win. */
|
|
30
|
-
declare function mergeField(base: FieldDesc, over: FieldDesc): FieldDesc;
|
|
31
|
-
/** Convert a merged {@link FieldDesc} to a Zod schema. */
|
|
32
|
-
declare function fieldToZod(d: FieldDesc): z.ZodType;
|
|
33
|
-
/** Normalise a TS-enum object or an array literal to a flat value list. */
|
|
34
|
-
declare function normalizeEnum(value: unknown): (string | number)[] | undefined;
|
|
35
|
-
/** Map a swagger/`design:type` type token (constructor, `[Type]`, or string) to a base type. */
|
|
36
|
-
declare function typeTokenToBase(type: unknown): FieldDesc['type'] | undefined;
|
|
37
|
-
/** From the constructor TypeScript emits via `emitDecoratorMetadata`. */
|
|
38
|
-
declare function designTypeToField(ctor: unknown): FieldDesc;
|
|
39
|
-
/** From an `@ApiParam`/`@ApiQuery` entry stored under `swagger/apiParameters`. */
|
|
40
|
-
declare function swaggerParamToField(p: Record<string, any>): FieldDesc;
|
|
41
|
-
/** From an `@ApiProperty` options object stored under `swagger/apiModelProperties`. */
|
|
42
|
-
declare function apiPropertyToField(o: Record<string, any>): FieldDesc;
|
|
43
|
-
/** From an array of `class-validator` validation-metadata entries for one property. */
|
|
44
|
-
declare function classValidatorToField(metas: Array<{
|
|
45
|
-
type?: string;
|
|
46
|
-
name?: string;
|
|
47
|
-
constraints?: unknown[];
|
|
48
|
-
}>): FieldDesc;
|
|
49
|
-
/** From an OpenAPI Schema Object (used by both the doc and `@ApiParam({ schema })`). */
|
|
50
|
-
declare function openapiSchemaToField(schema: Record<string, any>): FieldDesc;
|
|
51
|
-
/**
|
|
52
|
-
* Reflect a whole-DTO class (`@Body() dto: CreateDto`) into per-property
|
|
53
|
-
* {@link FieldDesc}s. Property names are the union of `@ApiProperty` and
|
|
54
|
-
* `class-validator` decorated fields; each field merges `design:type` (base),
|
|
55
|
-
* then `class-validator` constraints, then `@ApiProperty` (highest). Properties
|
|
56
|
-
* default to required unless a source marks them optional.
|
|
57
|
-
*/
|
|
58
|
-
declare function reflectDtoFields(dtoType: any): Record<string, FieldDesc>;
|
|
59
|
-
//#endregion
|
|
60
|
-
//#region src/lib/reflect/openapi.d.ts
|
|
61
|
-
/**
|
|
62
|
-
* A minimal view of an OpenAPI document - the subset we read. Matches the shape
|
|
63
|
-
* `SwaggerModule.createDocument()` returns, but typed loosely so callers can
|
|
64
|
-
* pass any compatible object without a hard `@nestjs/swagger` dependency.
|
|
65
|
-
*/
|
|
66
|
-
interface OpenApiDocument {
|
|
67
|
-
paths?: Record<string, Record<string, any>>;
|
|
68
|
-
components?: {
|
|
69
|
-
schemas?: Record<string, any>;
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
interface OpenApiLookup {
|
|
73
|
-
doc: OpenApiDocument;
|
|
74
|
-
/** `${METHOD} ${path}` → operation object. */
|
|
75
|
-
operations: Map<string, any>;
|
|
76
|
-
}
|
|
77
|
-
/** Index a document's operations by `${METHOD} ${path}` for fast matching. */
|
|
78
|
-
declare function buildOpenApiLookup(doc: OpenApiDocument): OpenApiLookup;
|
|
79
|
-
/**
|
|
80
|
-
* Resolve the per-field descriptors for a route from an ingested OpenAPI
|
|
81
|
-
* document. Merges `parameters` (path/query/header) and the JSON request-body
|
|
82
|
-
* schema's properties into a single field map. Returns `{}` when the operation
|
|
83
|
-
* isn't found - callers fall back to decorator reflection.
|
|
84
|
-
*/
|
|
85
|
-
declare function openApiFields(lookup: OpenApiLookup, method: string, openapiPath: string): Record<string, FieldDesc>;
|
|
86
|
-
//#endregion
|
|
87
|
-
//#region src/lib/types.d.ts
|
|
88
|
-
/**
|
|
89
|
-
* Context passed to a Nest Silkweave adapter when `SilkweaveModule` wires it
|
|
90
|
-
* up. Adapters register their routes directly on `httpAdapter` (no
|
|
91
|
-
* placeholder middleware, no `silkweave()` builder), so they only fire
|
|
92
|
-
* `register()` once and own the rest of their lifecycle implicitly through
|
|
93
|
-
* Nest.
|
|
94
|
-
*/
|
|
95
|
-
interface NestAdapterRegisterContext {
|
|
96
|
-
/** Nest's underlying HTTP adapter (Express or Fastify). */
|
|
97
|
-
httpAdapter: NonNullable<HttpAdapterHost['httpAdapter']>;
|
|
98
|
-
/** Identity the adapter surfaces to clients (e.g. MCP server name). */
|
|
99
|
-
silkweaveOptions: SilkweaveOptions;
|
|
100
|
-
/** Per-adapter context - already forked with `{ adapter: adapter.name, ...userContext }`. */
|
|
101
|
-
baseContext: SilkweaveContext;
|
|
102
|
-
/** Actions filtered to those enabled on this adapter. */
|
|
103
|
-
actions: Action[];
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* A Silkweave Nest adapter. Each transport (REST, tRPC, MCP) implements this
|
|
107
|
-
* shape. `register()` is called from `SilkweaveModule.configure()` - which
|
|
108
|
-
* runs *before* Nest's controller routes are mapped - so adapter routes
|
|
109
|
-
* always sit ahead of any catch-all controllers in the framework's request
|
|
110
|
-
* pipeline.
|
|
111
|
-
*/
|
|
112
|
-
interface NestSilkweaveAdapter {
|
|
113
|
-
/** Adapter discriminator - set on the silkweave context as `ctx.get('adapter')`. */
|
|
114
|
-
readonly name: 'mcp';
|
|
115
|
-
/** URL prefix the adapter mounts on (e.g. `'/mcp'`). Surfaced for introspection. */
|
|
116
|
-
readonly basePath?: string;
|
|
117
|
-
/**
|
|
118
|
-
* When `true`, the adapter receives every discovered action regardless of
|
|
119
|
-
* each action's `isEnabled` gate. Reserved for non-runtime adapters that need
|
|
120
|
-
* the entire action surface.
|
|
121
|
-
*/
|
|
122
|
-
readonly allActions?: boolean;
|
|
123
|
-
/** Register this adapter's routes on Nest's HTTP server. */
|
|
124
|
-
register(ctx: NestAdapterRegisterContext): void;
|
|
125
|
-
}
|
|
126
|
-
interface SilkweaveModuleOptions {
|
|
127
|
-
/** Identity for the silkweave instance - surfaced to MCP clients, OpenAPI, etc. */
|
|
128
|
-
silkweave: SilkweaveOptions;
|
|
129
|
-
/** Adapters to mount. Currently `mcp()`. */
|
|
130
|
-
adapters: NestSilkweaveAdapter[];
|
|
131
|
-
/** Initial context keys merged into every adapter's `baseContext`. */
|
|
132
|
-
context?: Record<string, unknown>;
|
|
133
|
-
/**
|
|
134
|
-
* Optional OpenAPI document (e.g. from `SwaggerModule.createDocument(app, cfg)`)
|
|
135
|
-
* used as an authoritative source when reflecting `@Mcp` tool input schemas.
|
|
136
|
-
* Matched to each method by HTTP verb + path; falls back to decorator
|
|
137
|
-
* reflection when an operation or field isn't present.
|
|
138
|
-
*/
|
|
139
|
-
openapi?: OpenApiDocument;
|
|
140
|
-
/**
|
|
141
|
-
* Opt-in allow-list of app-global guard classes (registered via
|
|
142
|
-
* `app.useGlobalGuards()` or `{ provide: APP_GUARD, useClass }`) to run on
|
|
143
|
-
* every MCP tool call, before each method/class `@UseGuards`. Listed by
|
|
144
|
-
* class - a blanket "run all globals" is deliberately not offered, since
|
|
145
|
-
* unrelated globals (e.g. a `ThrottlerGuard` that needs a writable response)
|
|
146
|
-
* would misbehave over MCP. Empty/omitted ⇒ no global guards run.
|
|
147
|
-
*
|
|
148
|
-
* Note: over MCP the request stand-in is headers-only (`params`/`query` are
|
|
149
|
-
* empty), so per-session or IP-derived guard logic won't apply; header-based
|
|
150
|
-
* authentication still works.
|
|
151
|
-
*/
|
|
152
|
-
globalGuards?: Type<CanActivate>[];
|
|
153
|
-
/**
|
|
154
|
-
* Default MCP result format for every `@Mcp` tool - `'json'` (compact JSON,
|
|
155
|
-
* `jsonToolResult`) or `'smart'` (inline small / embedded-resource large,
|
|
156
|
-
* `smartToolResult`). Defaults to `'smart'`. A per-method `@Mcp({ result })`
|
|
157
|
-
* overrides this, and a client's per-call `_meta.disposition` overrides both.
|
|
158
|
-
*/
|
|
159
|
-
defaultResult?: 'json' | 'smart';
|
|
160
|
-
}
|
|
161
|
-
declare const SILKWEAVE_MODULE_OPTIONS = "__silkweave_module_options__";
|
|
162
|
-
//#endregion
|
|
163
|
-
//#region src/adapter/mcp.d.ts
|
|
164
|
-
interface McpAdapterOptions {
|
|
165
|
-
/** URL prefix the MCP namespace lives under - the transport itself is at this exact path. Default `'/mcp'`. */
|
|
166
|
-
basePath?: string;
|
|
167
|
-
/** Optional bearer-token / OAuth 2.1 config. */
|
|
168
|
-
auth?: AuthConfig;
|
|
169
|
-
/** CORS configuration. `false` to disable, `true`/omitted for permissive defaults, or a `CorsOptions` object. */
|
|
170
|
-
cors?: CorsOptions | boolean;
|
|
171
|
-
/** Mount the sideload resource route at `${basePath}/resource/:id`. Default `true`. */
|
|
172
|
-
sideloadResources?: boolean;
|
|
173
|
-
/** Directory the sideload route reads from. Default `'resources'`. */
|
|
174
|
-
resourceDir?: string;
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* MCP adapter for `@silkweave/nestjs`. Registers the MCP Streamable HTTP
|
|
178
|
-
* transport, sideload, well-known and OAuth routes individually on Nest's
|
|
179
|
-
* HTTP adapter at the configured `basePath` (default `/mcp`):
|
|
180
|
-
*
|
|
181
|
-
* - `POST/GET/DELETE ${basePath}` - Streamable HTTP transport
|
|
182
|
-
* - `GET ${basePath}/resource/:id` - sideload (`sideloadResources` opt-out)
|
|
183
|
-
* - `GET ${basePath}/.well-known/oauth-protected-resource` - RFC 9728 metadata (when `auth.resourceUrl`/`auth.authorizationServers` set)
|
|
184
|
-
* - `GET ${basePath}/authorize`, `POST ${basePath}/token`, `POST ${basePath}/register`, `GET ${basePath}${callbackPath}` (when `auth.provider` set)
|
|
185
|
-
*
|
|
186
|
-
* Each route is a real Nest-level route - they show up in
|
|
187
|
-
* `RoutesResolver`'s log and there is no sub-app or middleware-slot
|
|
188
|
-
* indirection.
|
|
189
|
-
*/
|
|
190
|
-
declare function mcp(options?: McpAdapterOptions): NestSilkweaveAdapter;
|
|
191
|
-
//#endregion
|
|
192
7
|
//#region src/lib/metadata.d.ts
|
|
193
8
|
/** Reflect-metadata key carrying `@Mcp` options on a controller method. */
|
|
194
9
|
declare const MCP_METADATA = "__silkweave_mcp__";
|
|
10
|
+
/** Reflect-metadata key carrying `@Trpc` options on a controller method. */
|
|
11
|
+
declare const TRPC_METADATA = "__silkweave_trpc__";
|
|
195
12
|
/**
|
|
196
13
|
* Options for the `@Mcp()` method decorator. Every field is optional - an empty
|
|
197
14
|
* `@Mcp()` exposes the decorated controller route as an MCP tool with its name,
|
|
@@ -233,6 +50,63 @@ interface McpMetadata {
|
|
|
233
50
|
*/
|
|
234
51
|
result?: 'json' | 'smart';
|
|
235
52
|
}
|
|
53
|
+
/** tRPC procedure kind for a `@Trpc`-decorated route. */
|
|
54
|
+
type TrpcKind = 'query' | 'mutation' | 'subscription';
|
|
55
|
+
/**
|
|
56
|
+
* Options for the `@Trpc()` method decorator - the tRPC sibling of `@Mcp`. An
|
|
57
|
+
* empty `@Trpc()` exposes the decorated controller route as a tRPC procedure
|
|
58
|
+
* with its key, input schema, and kind reflected from the route + parameter
|
|
59
|
+
* decorators + swagger/class-validator metadata (identically to `@Mcp`).
|
|
60
|
+
*
|
|
61
|
+
* Unlike MCP, tRPC carries precise *output* types into the generated router, so
|
|
62
|
+
* `@Trpc` adds an `output`/`chunk` hatch and a `kind` override on top of the
|
|
63
|
+
* shared reflection. The two decorators compose on the same method.
|
|
64
|
+
*/
|
|
65
|
+
interface TrpcMetadata {
|
|
66
|
+
/**
|
|
67
|
+
* Procedure-name override (before camelCasing). When unset it is derived from
|
|
68
|
+
* the controller class + method name (e.g. `UsersController.listBySpace` →
|
|
69
|
+
* `Users.listBySpace`, camelCased by the router to `usersListBySpace`).
|
|
70
|
+
*/
|
|
71
|
+
name?: string;
|
|
72
|
+
/**
|
|
73
|
+
* Procedure description override. When unset it falls back to the method's
|
|
74
|
+
* `@ApiOperation({ summary | description })`, then a generated default.
|
|
75
|
+
*/
|
|
76
|
+
description?: string;
|
|
77
|
+
/**
|
|
78
|
+
* Zod raw-shape override merged over the reflected input fields (override wins
|
|
79
|
+
* per field). Same escape hatch as `@Mcp({ input })`.
|
|
80
|
+
*/
|
|
81
|
+
input?: Record<string, z.ZodType>;
|
|
82
|
+
/**
|
|
83
|
+
* Explicit output schema driving the generated procedure's output type - a Zod
|
|
84
|
+
* type, a DTO class (reflected like `@ApiOkResponse`), or a raw shape (wrapped
|
|
85
|
+
* in `z.object`). Wins over `@ApiOkResponse` reflection. The biggest reason to
|
|
86
|
+
* set this is when the return shape can't be reflected losslessly from a DTO.
|
|
87
|
+
*/
|
|
88
|
+
output?: z.ZodType | Type | Record<string, z.ZodType>;
|
|
89
|
+
/**
|
|
90
|
+
* Chunk schema for an async-generator route exposed as a tRPC **subscription**.
|
|
91
|
+
* A Zod type or a DTO class. Drives the emitted
|
|
92
|
+
* `TRPCSubscriptionProcedure<{ output }>` type. When unset the chunk type falls
|
|
93
|
+
* back to `unknown`.
|
|
94
|
+
*/
|
|
95
|
+
chunk?: z.ZodType | Type;
|
|
96
|
+
/**
|
|
97
|
+
* Procedure kind. When unset it is inferred: an `async *` route ⇒
|
|
98
|
+
* `'subscription'`, a `@Get` route ⇒ `'query'`, anything else ⇒ `'mutation'`.
|
|
99
|
+
* Set this to expose a verb-less route (no `@Get`/`@Post`) as a query or
|
|
100
|
+
* subscription - `@Trpc({ kind })` works without an HTTP-verb decorator, so the
|
|
101
|
+
* route is served over tRPC (and/or MCP) without becoming a public REST route.
|
|
102
|
+
*/
|
|
103
|
+
kind?: TrpcKind;
|
|
104
|
+
/**
|
|
105
|
+
* Whether to apply the method's parameter-bound pipes when re-binding the call.
|
|
106
|
+
* Default `'apply'`. Same semantics as `@Mcp({ pipes })`.
|
|
107
|
+
*/
|
|
108
|
+
pipes?: 'apply' | 'skip';
|
|
109
|
+
}
|
|
236
110
|
//#endregion
|
|
237
111
|
//#region src/decorator/mcp.d.ts
|
|
238
112
|
/**
|
|
@@ -270,7 +144,48 @@ interface McpMetadata {
|
|
|
270
144
|
*/
|
|
271
145
|
declare function Mcp(options?: McpMetadata): MethodDecorator;
|
|
272
146
|
//#endregion
|
|
147
|
+
//#region src/decorator/trpc.d.ts
|
|
148
|
+
/**
|
|
149
|
+
* Method decorator that exposes a NestJS controller route as a **tRPC
|
|
150
|
+
* procedure** - the sibling of `@Mcp`. Like `@Mcp` it is additive and reflects
|
|
151
|
+
* the procedure's input from the method's own metadata (route + `@Param`/
|
|
152
|
+
* `@Query`/`@Body` + swagger/class-validator), so a single method can carry both
|
|
153
|
+
* `@Trpc()` and `@Mcp()` and `@UseGuards()`.
|
|
154
|
+
*
|
|
155
|
+
* Two things differ from MCP because tRPC consumers need them:
|
|
156
|
+
* - **kind** - inferred from the route (`@Get` ⇒ query, others ⇒ mutation) or an
|
|
157
|
+
* `async *` body (⇒ subscription); override with `@Trpc({ kind })`.
|
|
158
|
+
* - **output** - the generated `AppRouter` carries precise output types. Drive
|
|
159
|
+
* them with `@ApiOkResponse({ type: Dto })` reflection or `@Trpc({ output })`.
|
|
160
|
+
*
|
|
161
|
+
* `@Trpc()` works **without** an HTTP-verb decorator: with no `@Get`/`@Post` the
|
|
162
|
+
* route is never mapped as REST, so `@Trpc({ kind })` exposes it over tRPC (and
|
|
163
|
+
* `@Mcp` over MCP) while keeping it off the public REST surface.
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```ts
|
|
167
|
+
* @Controller('users')
|
|
168
|
+
* export class UsersController {
|
|
169
|
+
* @Get('list-by-space')
|
|
170
|
+
* @ApiOperation({ summary: 'List users in a space' })
|
|
171
|
+
* @ApiOkResponse({ type: ListUsersResponse }) // drives the output type
|
|
172
|
+
* @UseGuards(AuthGuard)
|
|
173
|
+
* @Trpc() // → procedure `usersListBySpace` (query)
|
|
174
|
+
* @Mcp() // → MCP tool `UsersListBySpace`
|
|
175
|
+
* listBySpace(@Query() q: ListBySpaceQuery, @Req() req: AppRequest) {
|
|
176
|
+
* return this.service.list(req.user, q.spaceId)
|
|
177
|
+
* }
|
|
178
|
+
* }
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
declare function Trpc(options?: TrpcMetadata): MethodDecorator;
|
|
182
|
+
//#endregion
|
|
273
183
|
//#region src/lib/controllerDiscovery.d.ts
|
|
184
|
+
interface DiscoverOptions {
|
|
185
|
+
openapi?: OpenApiDocument;
|
|
186
|
+
globalGuards?: Type<CanActivate>[];
|
|
187
|
+
defaultResult?: 'json' | 'smart';
|
|
188
|
+
}
|
|
274
189
|
declare class ControllerDiscovery {
|
|
275
190
|
private readonly discovery;
|
|
276
191
|
private readonly scanner;
|
|
@@ -279,17 +194,24 @@ declare class ControllerDiscovery {
|
|
|
279
194
|
private readonly appConfig;
|
|
280
195
|
constructor(discovery: DiscoveryService, scanner: MetadataScanner, reflector: Reflector, moduleRef: ModuleRef, appConfig: ApplicationConfig);
|
|
281
196
|
/**
|
|
282
|
-
* Walk every Nest provider/controller, find methods annotated with `@Mcp
|
|
283
|
-
* and build a core `Action` per
|
|
284
|
-
*
|
|
285
|
-
* `run` re-binds the validated input back
|
|
286
|
-
* arguments (with `@UseGuards` guards
|
|
287
|
-
*
|
|
197
|
+
* Walk every Nest provider/controller, find methods annotated with `@Mcp`
|
|
198
|
+
* and/or `@Trpc`, and build a core `Action` per decorator present on each
|
|
199
|
+
* method. The input schema is reflected from the route + parameter decorators
|
|
200
|
+
* (+ optional OpenAPI document) and the `run` re-binds the validated input back
|
|
201
|
+
* into the method's positional arguments (with `@UseGuards` guards applied
|
|
202
|
+
* first). A method carrying both decorators yields two actions - one gated to
|
|
203
|
+
* the `mcp` adapter, one to the `trpc`/`typegen` adapters - sharing the same
|
|
204
|
+
* reflected input, bindings, and guards.
|
|
288
205
|
*/
|
|
289
|
-
discover(
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
206
|
+
discover(options?: DiscoverOptions): Action[];
|
|
207
|
+
/** Compute the per-method reflection shared by the `mcp` and `trpc` builders. */
|
|
208
|
+
private reflect;
|
|
209
|
+
/** Build a guard-application closure shared by both run shapes. */
|
|
210
|
+
private guardRunner;
|
|
211
|
+
/** Synthesize the MCP-targeted action (unchanged behavior from v2.4). */
|
|
212
|
+
private mcpAction;
|
|
213
|
+
/** Synthesize the tRPC-targeted action (kind/output/subscription + httpStatus errors). */
|
|
214
|
+
private trpcAction;
|
|
293
215
|
}
|
|
294
216
|
//#endregion
|
|
295
217
|
//#region src/lib/guards.d.ts
|
|
@@ -385,11 +307,12 @@ declare function specialBinding(paramtype: number, data: string | undefined): Bi
|
|
|
385
307
|
/**
|
|
386
308
|
* Root module for `@silkweave/nestjs`.
|
|
387
309
|
*
|
|
388
|
-
* Discovers every `@Mcp`-decorated **controller method** via
|
|
389
|
-
* reflects each into a Silkweave action (input schema from
|
|
390
|
-
* decorators + optional OpenAPI document; invocation by
|
|
391
|
-
* input back into the method), and registers the
|
|
392
|
-
*
|
|
310
|
+
* Discovers every `@Mcp`/`@Trpc`-decorated **controller method** via
|
|
311
|
+
* `DiscoveryService`, reflects each into a Silkweave action (input schema from
|
|
312
|
+
* the route + parameter decorators + optional OpenAPI document; invocation by
|
|
313
|
+
* re-binding the validated input back into the method), and registers the
|
|
314
|
+
* configured adapter(s) - `mcp()`, `trpc()`, `typegen()` - directly on Nest's
|
|
315
|
+
* HTTP adapter inside `configure()`.
|
|
393
316
|
*
|
|
394
317
|
* Because `configure()` runs during `registerModules` - before Nest's
|
|
395
318
|
* `registerRouter()` step - Silkweave's routes always sit ahead of every
|
|
@@ -419,5 +342,5 @@ declare class SilkweaveModule implements NestModule {
|
|
|
419
342
|
configure(_consumer: MiddlewareConsumer): void;
|
|
420
343
|
}
|
|
421
344
|
//#endregion
|
|
422
|
-
export { Binding, ControllerDiscovery, FieldDesc, MCP_METADATA, Mcp,
|
|
345
|
+
export { Binding, ControllerDiscovery, DiscoverOptions, FieldDesc, MCP_METADATA, Mcp, McpMetadata, NestAdapterRegisterContext, NestSilkweaveAdapter, OpenApiDocument, OpenApiLookup, SILKWEAVE_MODULE_OPTIONS, SilkweaveModule, SilkweaveModuleOptions, TRPC_METADATA, Trpc, TrpcKind, TrpcMetadata, apiPropertyToField, buildOpenApiLookup, classValidatorToField, collectGlobalGuards, collectGuards, designTypeToField, fieldToZod, invokeRebound, mergeField, normalizeEnum, openApiFields, openapiSchemaToField, reflectDtoFields, runGuards, specialBinding, swaggerParamToField, typeTokenToBase };
|
|
423
346
|
//# sourceMappingURL=index.d.mts.map
|
package/build/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/lib/
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/lib/metadata.ts","../src/decorator/mcp.ts","../src/decorator/trpc.ts","../src/lib/controllerDiscovery.ts","../src/lib/guards.ts","../src/lib/rebind.ts","../src/lib/silkweave.module.ts"],"mappings":"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"}
|