@silkweave/nestjs 2.4.0 → 2.6.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 +155 -9
- package/build/index-C1W-O7EX.d.mts +46 -0
- package/build/index-C1W-O7EX.d.mts.map +1 -0
- package/build/index.d.mts +138 -208
- package/build/index.d.mts.map +1 -1
- package/build/index.mjs +348 -8725
- 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-wmI5n_7i.d.mts +172 -0
- package/build/types-wmI5n_7i.d.mts.map +1 -0
- package/package.json +41 -6
package/build/index.d.mts
CHANGED
|
@@ -1,197 +1,14 @@
|
|
|
1
|
+
import { _ as reflectDtoFields, a as OpenApiDocument, b as unreflectedFields, 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-wmI5n_7i.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,
|
|
@@ -212,11 +29,16 @@ interface McpMetadata {
|
|
|
212
29
|
*/
|
|
213
30
|
description?: string;
|
|
214
31
|
/**
|
|
215
|
-
* Zod
|
|
216
|
-
*
|
|
217
|
-
*
|
|
32
|
+
* Zod override merged over the reflected input fields (override wins per
|
|
33
|
+
* field). Accepts either a raw shape (`{ field: z.string() }`) or a whole
|
|
34
|
+
* `z.object({ ... })` - the object's `.shape` is unwrapped. The escape hatch
|
|
35
|
+
* for shapes reflection can't express losslessly - discriminated unions,
|
|
36
|
+
* custom validators, `@Transform`, etc. Note it *adds to* the reflected
|
|
37
|
+
* fields; it does not replace them, so a field reflection silently dropped
|
|
38
|
+
* (see the unreflectable-param warning) is not recovered by listing the
|
|
39
|
+
* others here.
|
|
218
40
|
*/
|
|
219
|
-
input?: Record<string, z.ZodType
|
|
41
|
+
input?: Record<string, z.ZodType> | z.ZodObject;
|
|
220
42
|
/**
|
|
221
43
|
* Whether to apply the controller method's parameter-bound pipes
|
|
222
44
|
* (`@Param('id', ParseIntPipe)`) when re-binding the call. Default `'apply'`.
|
|
@@ -233,6 +55,65 @@ interface McpMetadata {
|
|
|
233
55
|
*/
|
|
234
56
|
result?: 'json' | 'smart';
|
|
235
57
|
}
|
|
58
|
+
/** tRPC procedure kind for a `@Trpc`-decorated route. */
|
|
59
|
+
type TrpcKind = 'query' | 'mutation' | 'subscription';
|
|
60
|
+
/**
|
|
61
|
+
* Options for the `@Trpc()` method decorator - the tRPC sibling of `@Mcp`. An
|
|
62
|
+
* empty `@Trpc()` exposes the decorated controller route as a tRPC procedure
|
|
63
|
+
* with its key, input schema, and kind reflected from the route + parameter
|
|
64
|
+
* decorators + swagger/class-validator metadata (identically to `@Mcp`).
|
|
65
|
+
*
|
|
66
|
+
* Unlike MCP, tRPC carries precise *output* types into the generated router, so
|
|
67
|
+
* `@Trpc` adds an `output`/`chunk` hatch and a `kind` override on top of the
|
|
68
|
+
* shared reflection. The two decorators compose on the same method.
|
|
69
|
+
*/
|
|
70
|
+
interface TrpcMetadata {
|
|
71
|
+
/**
|
|
72
|
+
* Procedure-name override (before camelCasing). When unset it is derived from
|
|
73
|
+
* the controller class + method name (e.g. `UsersController.listBySpace` →
|
|
74
|
+
* `Users.listBySpace`, camelCased by the router to `usersListBySpace`).
|
|
75
|
+
*/
|
|
76
|
+
name?: string;
|
|
77
|
+
/**
|
|
78
|
+
* Procedure description override. When unset it falls back to the method's
|
|
79
|
+
* `@ApiOperation({ summary | description })`, then a generated default.
|
|
80
|
+
*/
|
|
81
|
+
description?: string;
|
|
82
|
+
/**
|
|
83
|
+
* Zod override merged over the reflected input fields (override wins per
|
|
84
|
+
* field). Accepts a raw shape (`{ field: z.string() }`) or a whole
|
|
85
|
+
* `z.object({ ... })` (its `.shape` is unwrapped). Same escape hatch as
|
|
86
|
+
* `@Mcp({ input })`.
|
|
87
|
+
*/
|
|
88
|
+
input?: Record<string, z.ZodType> | z.ZodObject;
|
|
89
|
+
/**
|
|
90
|
+
* Explicit output schema driving the generated procedure's output type - a Zod
|
|
91
|
+
* type, a DTO class (reflected like `@ApiOkResponse`), or a raw shape (wrapped
|
|
92
|
+
* in `z.object`). Wins over `@ApiOkResponse` reflection. The biggest reason to
|
|
93
|
+
* set this is when the return shape can't be reflected losslessly from a DTO.
|
|
94
|
+
*/
|
|
95
|
+
output?: z.ZodType | Type | Record<string, z.ZodType>;
|
|
96
|
+
/**
|
|
97
|
+
* Chunk schema for an async-generator route exposed as a tRPC **subscription**.
|
|
98
|
+
* A Zod type or a DTO class. Drives the emitted
|
|
99
|
+
* `TRPCSubscriptionProcedure<{ output }>` type. When unset the chunk type falls
|
|
100
|
+
* back to `unknown`.
|
|
101
|
+
*/
|
|
102
|
+
chunk?: z.ZodType | Type;
|
|
103
|
+
/**
|
|
104
|
+
* Procedure kind. When unset it is inferred: an `async *` route ⇒
|
|
105
|
+
* `'subscription'`, a `@Get` route ⇒ `'query'`, anything else ⇒ `'mutation'`.
|
|
106
|
+
* Set this to expose a verb-less route (no `@Get`/`@Post`) as a query or
|
|
107
|
+
* subscription - `@Trpc({ kind })` works without an HTTP-verb decorator, so the
|
|
108
|
+
* route is served over tRPC (and/or MCP) without becoming a public REST route.
|
|
109
|
+
*/
|
|
110
|
+
kind?: TrpcKind;
|
|
111
|
+
/**
|
|
112
|
+
* Whether to apply the method's parameter-bound pipes when re-binding the call.
|
|
113
|
+
* Default `'apply'`. Same semantics as `@Mcp({ pipes })`.
|
|
114
|
+
*/
|
|
115
|
+
pipes?: 'apply' | 'skip';
|
|
116
|
+
}
|
|
236
117
|
//#endregion
|
|
237
118
|
//#region src/decorator/mcp.d.ts
|
|
238
119
|
/**
|
|
@@ -270,7 +151,48 @@ interface McpMetadata {
|
|
|
270
151
|
*/
|
|
271
152
|
declare function Mcp(options?: McpMetadata): MethodDecorator;
|
|
272
153
|
//#endregion
|
|
154
|
+
//#region src/decorator/trpc.d.ts
|
|
155
|
+
/**
|
|
156
|
+
* Method decorator that exposes a NestJS controller route as a **tRPC
|
|
157
|
+
* procedure** - the sibling of `@Mcp`. Like `@Mcp` it is additive and reflects
|
|
158
|
+
* the procedure's input from the method's own metadata (route + `@Param`/
|
|
159
|
+
* `@Query`/`@Body` + swagger/class-validator), so a single method can carry both
|
|
160
|
+
* `@Trpc()` and `@Mcp()` and `@UseGuards()`.
|
|
161
|
+
*
|
|
162
|
+
* Two things differ from MCP because tRPC consumers need them:
|
|
163
|
+
* - **kind** - inferred from the route (`@Get` ⇒ query, others ⇒ mutation) or an
|
|
164
|
+
* `async *` body (⇒ subscription); override with `@Trpc({ kind })`.
|
|
165
|
+
* - **output** - the generated `AppRouter` carries precise output types. Drive
|
|
166
|
+
* them with `@ApiOkResponse({ type: Dto })` reflection or `@Trpc({ output })`.
|
|
167
|
+
*
|
|
168
|
+
* `@Trpc()` works **without** an HTTP-verb decorator: with no `@Get`/`@Post` the
|
|
169
|
+
* route is never mapped as REST, so `@Trpc({ kind })` exposes it over tRPC (and
|
|
170
|
+
* `@Mcp` over MCP) while keeping it off the public REST surface.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* @Controller('users')
|
|
175
|
+
* export class UsersController {
|
|
176
|
+
* @Get('list-by-space')
|
|
177
|
+
* @ApiOperation({ summary: 'List users in a space' })
|
|
178
|
+
* @ApiOkResponse({ type: ListUsersResponse }) // drives the output type
|
|
179
|
+
* @UseGuards(AuthGuard)
|
|
180
|
+
* @Trpc() // → procedure `usersListBySpace` (query)
|
|
181
|
+
* @Mcp() // → MCP tool `UsersListBySpace`
|
|
182
|
+
* listBySpace(@Query() q: ListBySpaceQuery, @Req() req: AppRequest) {
|
|
183
|
+
* return this.service.list(req.user, q.spaceId)
|
|
184
|
+
* }
|
|
185
|
+
* }
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
declare function Trpc(options?: TrpcMetadata): MethodDecorator;
|
|
189
|
+
//#endregion
|
|
273
190
|
//#region src/lib/controllerDiscovery.d.ts
|
|
191
|
+
interface DiscoverOptions {
|
|
192
|
+
openapi?: OpenApiDocument;
|
|
193
|
+
globalGuards?: Type<CanActivate>[];
|
|
194
|
+
defaultResult?: 'json' | 'smart';
|
|
195
|
+
}
|
|
274
196
|
declare class ControllerDiscovery {
|
|
275
197
|
private readonly discovery;
|
|
276
198
|
private readonly scanner;
|
|
@@ -279,17 +201,24 @@ declare class ControllerDiscovery {
|
|
|
279
201
|
private readonly appConfig;
|
|
280
202
|
constructor(discovery: DiscoveryService, scanner: MetadataScanner, reflector: Reflector, moduleRef: ModuleRef, appConfig: ApplicationConfig);
|
|
281
203
|
/**
|
|
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
|
-
*
|
|
204
|
+
* Walk every Nest provider/controller, find methods annotated with `@Mcp`
|
|
205
|
+
* and/or `@Trpc`, and build a core `Action` per decorator present on each
|
|
206
|
+
* method. The input schema is reflected from the route + parameter decorators
|
|
207
|
+
* (+ optional OpenAPI document) and the `run` re-binds the validated input back
|
|
208
|
+
* into the method's positional arguments (with `@UseGuards` guards applied
|
|
209
|
+
* first). A method carrying both decorators yields two actions - one gated to
|
|
210
|
+
* the `mcp` adapter, one to the `trpc`/`typegen` adapters - sharing the same
|
|
211
|
+
* reflected input, bindings, and guards.
|
|
288
212
|
*/
|
|
289
|
-
discover(
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
213
|
+
discover(options?: DiscoverOptions): Action[];
|
|
214
|
+
/** Compute the per-method reflection shared by the `mcp` and `trpc` builders. */
|
|
215
|
+
private reflect;
|
|
216
|
+
/** Build a guard-application closure shared by both run shapes. */
|
|
217
|
+
private guardRunner;
|
|
218
|
+
/** Synthesize the MCP-targeted action (unchanged behavior from v2.4). */
|
|
219
|
+
private mcpAction;
|
|
220
|
+
/** Synthesize the tRPC-targeted action (kind/output/subscription + httpStatus errors). */
|
|
221
|
+
private trpcAction;
|
|
293
222
|
}
|
|
294
223
|
//#endregion
|
|
295
224
|
//#region src/lib/guards.d.ts
|
|
@@ -377,7 +306,7 @@ interface RequestLike {
|
|
|
377
306
|
* tool `input` (and the request stand-in for `@Req`/`@Headers`/...), then call
|
|
378
307
|
* it. `applyParamPipes` controls whether parameter-bound pipes run.
|
|
379
308
|
*/
|
|
380
|
-
declare function invokeRebound(method: (...args: any[]) => any, instance: object, input: Record<string, unknown>, bindings: Binding[], request: RequestLike | undefined, applyParamPipes: boolean): Promise<unknown>;
|
|
309
|
+
declare function invokeRebound(method: (...args: any[]) => any, instance: object, input: Record<string, unknown>, bindings: Binding[], request: RequestLike | undefined, response: unknown, applyParamPipes: boolean): Promise<unknown>;
|
|
381
310
|
/** Map a non-input parameter slot (`@Req`/`@Headers`/`@Ip`/...) to its runtime binding. */
|
|
382
311
|
declare function specialBinding(paramtype: number, data: string | undefined): Binding | null;
|
|
383
312
|
//#endregion
|
|
@@ -385,11 +314,12 @@ declare function specialBinding(paramtype: number, data: string | undefined): Bi
|
|
|
385
314
|
/**
|
|
386
315
|
* Root module for `@silkweave/nestjs`.
|
|
387
316
|
*
|
|
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
|
-
*
|
|
317
|
+
* Discovers every `@Mcp`/`@Trpc`-decorated **controller method** via
|
|
318
|
+
* `DiscoveryService`, reflects each into a Silkweave action (input schema from
|
|
319
|
+
* the route + parameter decorators + optional OpenAPI document; invocation by
|
|
320
|
+
* re-binding the validated input back into the method), and registers the
|
|
321
|
+
* configured adapter(s) - `mcp()`, `trpc()`, `typegen()` - directly on Nest's
|
|
322
|
+
* HTTP adapter inside `configure()`.
|
|
393
323
|
*
|
|
394
324
|
* Because `configure()` runs during `registerModules` - before Nest's
|
|
395
325
|
* `registerRouter()` step - Silkweave's routes always sit ahead of every
|
|
@@ -419,5 +349,5 @@ declare class SilkweaveModule implements NestModule {
|
|
|
419
349
|
configure(_consumer: MiddlewareConsumer): void;
|
|
420
350
|
}
|
|
421
351
|
//#endregion
|
|
422
|
-
export { Binding, ControllerDiscovery, FieldDesc, MCP_METADATA, Mcp,
|
|
352
|
+
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, unreflectedFields };
|
|
423
353
|
//# 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":";;;;;;;;cAIa,YAAA;;cAGA,aAAA;;AAHb;;;;;AAGA;;UAUiB,WAAA;EAVS;;AAU1B;;EAKE,IAAA;EAgByB;;;;EAXzB,WAAA;EAL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