@silkweave/nestjs 1.10.0 → 1.12.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/.turbo/turbo-build.log +16 -17
- package/.turbo/turbo-prepack.log +7 -8
- package/README.md +43 -8
- package/build/index.d.mts +93 -13
- package/build/index.d.mts.map +1 -1
- package/build/index.mjs +197 -20
- package/build/index.mjs.map +1 -1
- package/package.json +15 -8
- package/src/adapter/rest.ts +25 -13
- package/src/index.ts +2 -0
- package/src/lib/discovery.ts +19 -5
- package/src/lib/guards.ts +9 -3
- package/src/lib/metadata.ts +7 -1
- package/src/lib/openapi.ts +116 -0
- package/src/lib/swagger.ts +74 -0
- package/src/lib/types.ts +6 -0
- package/tsconfig.tsbuildinfo +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
$ tsdown
|
|
2
|
-
[34mℹ[39m [34mtsdown v0.21.10[39m powered by [38;2;255;126;23mrolldown v1.0.0-rc.17[39m
|
|
3
|
-
[34mℹ[39m config file: [4m/Users/atomic/projects/silkweave/silkweave/packages/nestjs/tsdown.config.ts[24m
|
|
4
|
-
[34mℹ[39m entry: [34msrc/index.ts[39m
|
|
5
|
-
[34mℹ[39m tsconfig: [34mtsconfig.json[39m
|
|
6
|
-
[34mℹ[39m Build start
|
|
7
|
-
[34mℹ[39m
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
[34mℹ[39m [2mbuild/[
|
|
13
|
-
[34mℹ[39m [2mbuild/[22mindex.
|
|
14
|
-
[34mℹ[39m [2mbuild/[
|
|
15
|
-
[34mℹ[39m
|
|
16
|
-
[
|
|
17
|
-
[32m✔[39m Build complete in [32m1110ms[39m
|
|
1
|
+
[2m$ tsdown[22m
|
|
2
|
+
[34mℹ[39m [34mtsdown v0.21.10[39m powered by [38;2;255;126;23mrolldown v1.0.0-rc.17[39m
|
|
3
|
+
[34mℹ[39m config file: [4m/Users/atomic/projects/silkweave/silkweave/packages/nestjs/tsdown.config.ts[24m
|
|
4
|
+
[34mℹ[39m entry: [34msrc/index.ts[39m
|
|
5
|
+
[34mℹ[39m tsconfig: [34mtsconfig.json[39m
|
|
6
|
+
[34mℹ[39m Build start
|
|
7
|
+
[34mℹ[39m Hint: consider adding [34mdeps.onlyBundle[39m option to avoid unintended bundling of dependencies, or set [34mdeps.onlyBundle: false[39m to disable this hint.
|
|
8
|
+
See more at [4mhttps://tsdown.dev/options/dependencies#deps-onlybundle[24m
|
|
9
|
+
Detected dependencies in bundle:
|
|
10
|
+
- [34mrxjs[39m
|
|
11
|
+
[34mℹ[39m [2mbuild/[22m[1mindex.mjs[22m [2m339.14 kB[22m [2m│ gzip: 49.99 kB[22m
|
|
12
|
+
[34mℹ[39m [2mbuild/[22mindex.mjs.map [2m579.22 kB[22m [2m│ gzip: 88.28 kB[22m
|
|
13
|
+
[34mℹ[39m [2mbuild/[22mindex.d.mts.map [2m 3.06 kB[22m [2m│ gzip: 1.10 kB[22m
|
|
14
|
+
[34mℹ[39m [2mbuild/[22m[32m[1mindex.d.mts[22m[39m [2m 17.08 kB[22m [2m│ gzip: 6.02 kB[22m
|
|
15
|
+
[34mℹ[39m 4 files, total: 938.50 kB
|
|
16
|
+
[32m✔[39m Build complete in [32m1034ms[39m
|
package/.turbo/turbo-prepack.log
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
[2m$ pnpm clean && pnpm build[22m
|
|
1
|
+
[2m$ pnpm clean && pnpm build[22m
|
|
3
2
|
[2m$ rimraf build[22m
|
|
4
3
|
[2m$ tsdown[22m
|
|
5
4
|
[34mℹ[39m [34mtsdown v0.21.10[39m powered by [38;2;255;126;23mrolldown v1.0.0-rc.17[39m
|
|
@@ -11,9 +10,9 @@
|
|
|
11
10
|
See more at [4mhttps://tsdown.dev/options/dependencies#deps-onlybundle[24m
|
|
12
11
|
Detected dependencies in bundle:
|
|
13
12
|
- [34mrxjs[39m
|
|
14
|
-
[34mℹ[39m [2mbuild/[22m[1mindex.mjs[22m [
|
|
15
|
-
[34mℹ[39m [2mbuild/[22mindex.mjs.map [
|
|
16
|
-
[34mℹ[39m [2mbuild/[22mindex.d.mts.map [2m
|
|
17
|
-
[34mℹ[39m [2mbuild/[22m[32m[1mindex.d.mts[22m[39m [2m
|
|
18
|
-
[34mℹ[39m 4 files, total:
|
|
19
|
-
[32m✔[39m Build complete in [
|
|
13
|
+
[34mℹ[39m [2mbuild/[22m[1mindex.mjs[22m [2m344.18 kB[22m [2m│ gzip: 51.78 kB[22m
|
|
14
|
+
[34mℹ[39m [2mbuild/[22mindex.mjs.map [2m589.05 kB[22m [2m│ gzip: 91.22 kB[22m
|
|
15
|
+
[34mℹ[39m [2mbuild/[22mindex.d.mts.map [2m 3.45 kB[22m [2m│ gzip: 1.22 kB[22m
|
|
16
|
+
[34mℹ[39m [2mbuild/[22m[32m[1mindex.d.mts[22m[39m [2m 20.10 kB[22m [2m│ gzip: 6.89 kB[22m
|
|
17
|
+
[34mℹ[39m 4 files, total: 956.79 kB
|
|
18
|
+
[32m✔[39m Build complete in [32m822ms[39m
|
package/README.md
CHANGED
|
@@ -47,11 +47,10 @@ export class UserActions {
|
|
|
47
47
|
return this.db.getUser(input.id)
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
@UseGuards(AdminGuard)
|
|
50
|
+
@UseGuards(AdminGuard) // guard reads the request header on every transport, MCP included
|
|
51
51
|
@Action({
|
|
52
52
|
description: 'Ban a user',
|
|
53
|
-
input: BanInput
|
|
54
|
-
transports: ['rest', 'trpc'] // exclude from MCP tools
|
|
53
|
+
input: BanInput
|
|
55
54
|
})
|
|
56
55
|
ban(input: z.infer<typeof BanInput>) {
|
|
57
56
|
return this.db.banUser(input.id, input.reason)
|
|
@@ -94,11 +93,11 @@ await app.listen(8080)
|
|
|
94
93
|
|
|
95
94
|
The `users.list` and `users.get` actions are now reachable via:
|
|
96
95
|
|
|
97
|
-
- **REST:** `GET /api/users/list?activeOnly=true` and `GET /api/users/
|
|
96
|
+
- **REST:** `GET /api/users/list?activeOnly=true` (query param) and `GET /api/users/1` (path param, via `path: 'users/:id'`)
|
|
98
97
|
- **tRPC:** `client.usersList.query({ activeOnly: true })` and `client.usersGet.query({ id: '1' })`
|
|
99
98
|
- **MCP:** tools `UsersList` and `UsersGet`
|
|
100
99
|
|
|
101
|
-
`users.ban`
|
|
100
|
+
`users.ban` is guarded by `@UseGuards(AdminGuard)` on **every** transport - REST, tRPC, **and** MCP. The guard reads its credential from the request header (`switchToHttp().getRequest().headers`); over MCP the inbound tool-call headers are surfaced the same way (see [Guards & DI](#guards--di)).
|
|
102
101
|
|
|
103
102
|
## Decorators
|
|
104
103
|
|
|
@@ -112,6 +111,9 @@ The `users.list` and `users.get` actions are now reachable via:
|
|
|
112
111
|
| `output` | `z.ZodObject` | - | Optional output schema (used by tRPC type inference) |
|
|
113
112
|
| `chunk` | `z.ZodType` | - | Schema for chunks yielded by a streaming (`async function*`) method. **Required** when the method is an async generator |
|
|
114
113
|
| `kind` | `'query' \| 'mutation'` | `'mutation'` | `'query'` → GET in REST, `.query()` in tRPC. `'mutation'` → POST / `.mutation()` |
|
|
114
|
+
| `method` | `'GET' \| 'POST' \| 'PUT' \| 'DELETE'` | `POST` (or `GET` when `kind: 'query'`) | REST HTTP verb. Overrides the `kind`-derived default |
|
|
115
|
+
| `path` | `string` | action name with dots as slashes | REST route, optionally with `:param` placeholders (e.g. `'spaces/:spaceId/users'`). Each placeholder must be a key of `input` and is resolved from the URL path |
|
|
116
|
+
| `queryParams` | `(keyof input)[]` | - | Input fields read from the URL query string instead of the body (e.g. `['offset', 'limit']`). On a bodyless GET every non-path field is read from the query string automatically |
|
|
115
117
|
| `transports` | `('rest' \| 'trpc' \| 'mcp')[]` | all | Allowlist of transports that expose this action |
|
|
116
118
|
| `isEnabled` | `(ctx) => boolean` | - | Dynamic gate (AND-combined with `transports`) |
|
|
117
119
|
| `toolResult` | `(response, ctx) => CallToolResult` | - | Custom MCP `CallToolResult` formatter |
|
|
@@ -141,12 +143,39 @@ Maps actions to REST routes on the Nest HTTP server.
|
|
|
141
143
|
| `basePath` | `string` | `'/api'` | URL prefix joined to each action's path |
|
|
142
144
|
| `auth` | `AuthConfig` | - | `@silkweave/auth` bearer-token config |
|
|
143
145
|
|
|
144
|
-
|
|
146
|
+
By default routes follow `{basePath}/{action-name-with-slashes}` where dots in action names become slashes, and the verb comes from `kind`:
|
|
145
147
|
|
|
146
148
|
- `users.list` (query) → `GET /api/users/list`
|
|
147
149
|
- `users.ban` (mutation) → `POST /api/users/ban`
|
|
148
150
|
|
|
149
|
-
|
|
151
|
+
The action's `method`, `path`, and `queryParams` fields override this (see the `@Action` options table above):
|
|
152
|
+
|
|
153
|
+
- `path: 'users/:id'`, `kind: 'query'` → `GET /api/users/:id` (`id` from the path)
|
|
154
|
+
- `queryParams: ['activeOnly']`, `kind: 'query'` → `GET /api/users/list?activeOnly=true`
|
|
155
|
+
|
|
156
|
+
Each action is registered as an individual route on Nest's HTTP adapter (not a sub-app). Input is merged from the request body, `queryParams` query-string fields, and `:param` path placeholders (path/query strings are coerced to the schema's primitive), then validated against the action's Zod schema; validation failures return HTTP 400 with the Zod issues.
|
|
157
|
+
|
|
158
|
+
#### Swagger / OpenAPI
|
|
159
|
+
|
|
160
|
+
`@nestjs/swagger` builds its document by scanning **controllers**, but Silkweave registers action routes directly on the HTTP adapter - so the scanner never sees them. `addSilkweaveActions(app, document, options?)` closes the gap: it discovers the actions through the same `ActionDiscovery` provider the `rest()` adapter uses, builds OpenAPI paths with the same routing logic, and merges them into the document. The result stays in sync with the live routes without any dynamic controllers. Call it between `createDocument()` and `setup()`:
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'
|
|
164
|
+
import { addSilkweaveActions } from '@silkweave/nestjs'
|
|
165
|
+
|
|
166
|
+
const config = new DocumentBuilder().setTitle('My API').setVersion('1.0.0').build()
|
|
167
|
+
const document = SwaggerModule.createDocument(app, config) // your controllers
|
|
168
|
+
addSilkweaveActions(app, document) // + silkweave actions
|
|
169
|
+
SwaggerModule.setup('api/docs', app, document)
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
| Option | Type | Default | Description |
|
|
173
|
+
|--------|------|---------|-------------|
|
|
174
|
+
| `basePath` | `string` | the `rest()` adapter's `basePath`, else `'/api'` | URL prefix the action routes are mounted on |
|
|
175
|
+
| `tag` | `string` | `'Actions'` | OpenAPI tag the actions are grouped under |
|
|
176
|
+
| `includeDisabled` | `boolean` | `false` | Include actions gated off the REST transport (via `transports` / `isEnabled`) |
|
|
177
|
+
|
|
178
|
+
`@nestjs/swagger` is an **optional** peer dependency - install it alongside `@silkweave/nestjs` to use this helper. Path params, `queryParams`, request bodies, and `output`/`chunk` response schemas are all derived from the action's Zod schemas.
|
|
150
179
|
|
|
151
180
|
### `trpc(options?)`
|
|
152
181
|
|
|
@@ -191,7 +220,13 @@ Mounts the MCP Streamable HTTP transport directly at `basePath`, with sideload (
|
|
|
191
220
|
|
|
192
221
|
## Guards & DI
|
|
193
222
|
|
|
194
|
-
Native NestJS `@UseGuards()` and `@UseInterceptors()` on `@Action` methods run for every
|
|
223
|
+
Native NestJS `@UseGuards()` and `@UseInterceptors()` on `@Action` methods run for **every** transport - REST, tRPC, and MCP. Guards receive an `ExecutionContext` with the request in `switchToHttp().getRequest()`. The `Reflector` is also wired up so guards can read custom metadata.
|
|
224
|
+
|
|
225
|
+
**Headers over MCP.** REST and tRPC pass the raw HTTP request to the guard. For MCP (Streamable HTTP), 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:
|
|
226
|
+
|
|
227
|
+
- Only **headers** (and the request `url`) cross the MCP boundary. There are no path `params` or `query` on an MCP tool call, so `getRequest().params` / `.query` are empty objects - guards relying on them degrade to "deny" rather than crash.
|
|
228
|
+
- A guard that denies (returns `false` or throws) produces a clean MCP tool error (`ForbiddenException`), not an HTTP 500.
|
|
229
|
+
- For OAuth 2.1 / bearer-token MCP auth, prefer `mcp({ auth })` and read the resolved identity from the silkweave context (`ctx.get('auth')`) inside the action; the header stand-in is for custom request-reading guards.
|
|
195
230
|
|
|
196
231
|
Action methods are normal Nest provider methods - inject services via the constructor as usual.
|
|
197
232
|
|
package/build/index.d.mts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { CanActivate, DynamicModule, MiddlewareConsumer, NestModule, Type } from "@nestjs/common";
|
|
1
|
+
import { CanActivate, DynamicModule, INestApplication, MiddlewareConsumer, NestModule, Type } from "@nestjs/common";
|
|
2
2
|
import { AuthConfig } from "@silkweave/auth";
|
|
3
|
-
import { Action as Action$1, ActionKind, SilkweaveContext, SilkweaveOptions } from "@silkweave/core";
|
|
3
|
+
import { Action as Action$1, ActionKind, HttpMethod, SilkweaveContext, SilkweaveOptions } from "@silkweave/core";
|
|
4
4
|
import z$1 from "zod/v4";
|
|
5
5
|
import { InferTrpcRouter } from "@silkweave/trpc";
|
|
6
6
|
import { TypegenFormat } from "@silkweave/typegen";
|
|
7
7
|
import { DiscoveryService, HttpAdapterHost, MetadataScanner, ModuleRef, Reflector } from "@nestjs/core";
|
|
8
8
|
import { CorsOptions } from "cors";
|
|
9
|
+
import { OpenAPIObject } from "@nestjs/swagger";
|
|
9
10
|
|
|
10
11
|
//#region src/lib/types.d.ts
|
|
11
12
|
/**
|
|
@@ -35,6 +36,12 @@ interface NestAdapterRegisterContext {
|
|
|
35
36
|
interface NestSilkweaveAdapter {
|
|
36
37
|
/** Adapter discriminator - set on the silkweave context as `ctx.get('adapter')`. */
|
|
37
38
|
readonly name: 'rest' | 'trpc' | 'mcp' | 'typegen';
|
|
39
|
+
/**
|
|
40
|
+
* URL prefix the adapter mounts on (e.g. `'/api'`). Surfaced for introspection
|
|
41
|
+
* tooling such as `addSilkweaveActions()` (OpenAPI/Swagger), which reads it to
|
|
42
|
+
* keep generated docs aligned with the live routes.
|
|
43
|
+
*/
|
|
44
|
+
readonly basePath?: string;
|
|
38
45
|
/**
|
|
39
46
|
* When `true`, the adapter receives every discovered action regardless of
|
|
40
47
|
* each action's `transports` allowlist / `isEnabled` gate. Used by
|
|
@@ -95,12 +102,17 @@ interface RestAdapterOptions {
|
|
|
95
102
|
* REST adapter for `@silkweave/nestjs`. Registers each discovered `@Action`
|
|
96
103
|
* as an individual route on Nest's HTTP adapter:
|
|
97
104
|
*
|
|
98
|
-
* -
|
|
99
|
-
* -
|
|
105
|
+
* - HTTP verb comes from `method`, else `GET` for `kind: 'query'`, else `POST`.
|
|
106
|
+
* - Path comes from `path` (joined to `basePath`, may contain `:param`
|
|
107
|
+
* placeholders), else `${basePath}/${actionName-with-slashes}`.
|
|
108
|
+
* - Input is merged from the request body, the `queryParams` query-string
|
|
109
|
+
* fields, and any `:param` path placeholders (see `resolveActionInput`).
|
|
100
110
|
*
|
|
101
|
-
* Routes show up in Nest's `RoutesResolver` logger
|
|
102
|
-
*
|
|
103
|
-
*
|
|
111
|
+
* Routes show up in Nest's `RoutesResolver` logger. They are registered
|
|
112
|
+
* directly on the HTTP adapter (not as Nest controllers), so `@nestjs/swagger`'s
|
|
113
|
+
* controller scanner does not see them - use `addSilkweaveActions()` to add them
|
|
114
|
+
* to the OpenAPI document. Works on `@nestjs/platform-express` out of the box.
|
|
115
|
+
* For `@nestjs/platform-fastify`, register `@fastify/express` first.
|
|
104
116
|
*/
|
|
105
117
|
declare function rest(options?: RestAdapterOptions): NestSilkweaveAdapter;
|
|
106
118
|
//#endregion
|
|
@@ -179,6 +191,12 @@ interface ActionMetadata<I extends object = object, O extends object = object, C
|
|
|
179
191
|
chunk?: z$1.ZodType<C>;
|
|
180
192
|
/** `'query'` (GET in REST, `.query()` in tRPC) or `'mutation'` (POST in REST, `.mutation()` in tRPC). Default: `'mutation'`. */
|
|
181
193
|
kind?: ActionKind;
|
|
194
|
+
/** HTTP verb for the REST route. Defaults to `POST` (or `GET` when `kind` is `'query'`). Overrides the `kind`-derived default. */
|
|
195
|
+
method?: HttpMethod;
|
|
196
|
+
/** REST route path, optionally with `:param` placeholders (e.g. `'spaces/:spaceId/users'`). Each placeholder must be a key of `input`. Defaults to the action name with dots as slashes. */
|
|
197
|
+
path?: string;
|
|
198
|
+
/** Input fields read from the URL query string instead of the request body (e.g. `['offset', 'limit']`). Each must be a key of `input`. */
|
|
199
|
+
queryParams?: (keyof I)[];
|
|
182
200
|
/** Allowlist of transports that should expose this action. Default: all registered transports. */
|
|
183
201
|
transports?: Transport[];
|
|
184
202
|
/** Dynamic enable check (in addition to `transports`). AND-combined with the transports filter. */
|
|
@@ -264,9 +282,10 @@ declare class ActionDiscovery {
|
|
|
264
282
|
* a list of core `Action` objects ready to feed into `silkweave().actions()`.
|
|
265
283
|
*
|
|
266
284
|
* Action invocation is wrapped to (a) run `@UseGuards` guards declared on the
|
|
267
|
-
* method or its class against the incoming
|
|
268
|
-
* `ctx.get('request')
|
|
269
|
-
*
|
|
285
|
+
* method or its class against the incoming request (read from
|
|
286
|
+
* `ctx.get('request')`, populated by REST/tRPC and by MCP-over-HTTP from the
|
|
287
|
+
* SDK's `extra.requestInfo`) and (b) bind `this` to the resolved Nest provider
|
|
288
|
+
* so DI-injected dependencies remain available.
|
|
270
289
|
*/
|
|
271
290
|
discover(): Action$1[];
|
|
272
291
|
private toAction;
|
|
@@ -294,14 +313,35 @@ type GuardRef = Type<CanActivate> | CanActivate;
|
|
|
294
313
|
*/
|
|
295
314
|
declare function collectGuards(reflector: Reflector, classRef: Type<unknown>, handler: (...args: unknown[]) => unknown): GuardRef[];
|
|
296
315
|
/**
|
|
297
|
-
* Run the configured guards against
|
|
316
|
+
* Run the configured guards against a request. Throws `ForbiddenException`
|
|
298
317
|
* if any guard rejects, mirroring Nest's HTTP request-pipeline behavior.
|
|
299
318
|
*
|
|
300
319
|
* Pass `null` for `response` when running on top of a tRPC or MCP request that
|
|
301
320
|
* doesn't surface a raw response object; guards that introspect the response
|
|
302
321
|
* will receive `null`.
|
|
322
|
+
*
|
|
323
|
+
* `contextType` is reflected through `ExecutionContext.getType()` so guards can
|
|
324
|
+
* branch on the transport. It is `'http'` for REST/tRPC and for MCP-over-HTTP
|
|
325
|
+
* (where a header-bearing request stand-in is available); transports without any
|
|
326
|
+
* HTTP request (e.g. MCP stdio) pass `'rpc'`.
|
|
327
|
+
*/
|
|
328
|
+
declare function runGuards(guards: GuardRef[], moduleRef: ModuleRef, reflector: Reflector, classRef: Type<unknown>, handler: (...args: unknown[]) => unknown, request: unknown, response: unknown, contextType?: 'http' | 'rpc'): Promise<void>;
|
|
329
|
+
//#endregion
|
|
330
|
+
//#region src/lib/openapi.d.ts
|
|
331
|
+
interface ActionPathsOptions {
|
|
332
|
+
/** URL prefix the `rest()` adapter mounts on. Default `'/api'`. */
|
|
333
|
+
basePath?: string;
|
|
334
|
+
/** OpenAPI tag the actions are grouped under. Default `'Actions'`. */
|
|
335
|
+
tag?: string;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Build an OpenAPI `paths` fragment for a set of Silkweave actions, mirroring
|
|
339
|
+
* exactly how the `rest()` adapter routes them: the same HTTP verb (`method` ??
|
|
340
|
+
* `kind`), the same `path`/`name`-derived route, and the same path/query/body
|
|
341
|
+
* field split (`pathParamNames` + `queryParams`). Schemas are inlined from the
|
|
342
|
+
* Zod input/output via `z.toJSONSchema`; no shared components are emitted.
|
|
303
343
|
*/
|
|
304
|
-
declare function
|
|
344
|
+
declare function buildActionPaths(actions: Action$1[], options?: ActionPathsOptions): Record<string, Record<string, unknown>>;
|
|
305
345
|
//#endregion
|
|
306
346
|
//#region src/lib/silkweave.module.d.ts
|
|
307
347
|
/**
|
|
@@ -341,5 +381,45 @@ declare class SilkweaveModule implements NestModule {
|
|
|
341
381
|
configure(_consumer: MiddlewareConsumer): void;
|
|
342
382
|
}
|
|
343
383
|
//#endregion
|
|
344
|
-
|
|
384
|
+
//#region src/lib/swagger.d.ts
|
|
385
|
+
interface SilkweaveSwaggerOptions {
|
|
386
|
+
/**
|
|
387
|
+
* URL prefix the `rest()` adapter mounts on. Defaults to the configured
|
|
388
|
+
* `rest()` adapter's `basePath`, falling back to `'/api'`.
|
|
389
|
+
*/
|
|
390
|
+
basePath?: string;
|
|
391
|
+
/** OpenAPI tag the actions are grouped under. Default `'Actions'`. */
|
|
392
|
+
tag?: string;
|
|
393
|
+
/**
|
|
394
|
+
* Include actions that are *not* enabled on the REST transport (gated out via
|
|
395
|
+
* `transports` / `isEnabled`). Default `false` - the document mirrors the
|
|
396
|
+
* routes the `rest()` adapter actually registers.
|
|
397
|
+
*/
|
|
398
|
+
includeDisabled?: boolean;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Merge every REST-exposed Silkweave `@Action` into a NestJS Swagger
|
|
402
|
+
* `OpenAPIObject`.
|
|
403
|
+
*
|
|
404
|
+
* `@nestjs/swagger` builds its document by scanning **controllers**, but
|
|
405
|
+
* Silkweave registers action routes directly on the HTTP adapter (so they sit
|
|
406
|
+
* ahead of controllers in the request pipeline) - which means the scanner never
|
|
407
|
+
* sees them. This helper closes that gap: it discovers the actions through the
|
|
408
|
+
* same `ActionDiscovery` provider the `rest()` adapter uses, builds OpenAPI
|
|
409
|
+
* paths with the same routing logic (`buildActionPaths`), and merges them into
|
|
410
|
+
* the document. The result stays in sync with the live routes without any
|
|
411
|
+
* dynamic controllers.
|
|
412
|
+
*
|
|
413
|
+
* Call it between `SwaggerModule.createDocument()` and `SwaggerModule.setup()`:
|
|
414
|
+
*
|
|
415
|
+
* @example
|
|
416
|
+
* ```ts
|
|
417
|
+
* const document = SwaggerModule.createDocument(app, config)
|
|
418
|
+
* addSilkweaveActions(app, document)
|
|
419
|
+
* SwaggerModule.setup('api/docs', app, document)
|
|
420
|
+
* ```
|
|
421
|
+
*/
|
|
422
|
+
declare function addSilkweaveActions(app: INestApplication, document: OpenAPIObject, options?: SilkweaveSwaggerOptions): OpenAPIObject;
|
|
423
|
+
//#endregion
|
|
424
|
+
export { ACTIONS_METADATA, ACTION_METADATA, ACTION_RESPONSE_KEY, Action, ActionDiscovery, ActionMetadata, ActionPathsOptions, Actions, type ActionsClassMetadata, AnyActionMetadata, type InferTrpcRouter, McpAdapterOptions, NestAdapterRegisterContext, NestSilkweaveAdapter, RestAdapterOptions, ResultToolResult, SILKWEAVE_MODULE_OPTIONS, SilkweaveModule, SilkweaveModuleOptions, SilkweaveSwaggerOptions, type Transport, TrpcAdapterOptions, TypegenAdapterOptions, addSilkweaveActions, buildActionPaths, buildIsEnabled, collectGuards, mcp, rest, runGuards, trpc, typegen };
|
|
345
425
|
//# 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/types.ts","../src/adapter/mcp.ts","../src/adapter/rest.ts","../src/adapter/trpc.ts","../src/adapter/typegen.ts","../src/lib/metadata.ts","../src/decorator/action.ts","../src/decorator/actions.ts","../src/lib/discovery.ts","../src/lib/filter.ts","../src/lib/guards.ts","../src/lib/silkweave.module.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/lib/types.ts","../src/adapter/mcp.ts","../src/adapter/rest.ts","../src/adapter/trpc.ts","../src/adapter/typegen.ts","../src/lib/metadata.ts","../src/decorator/action.ts","../src/decorator/actions.ts","../src/lib/discovery.ts","../src/lib/filter.ts","../src/lib/guards.ts","../src/lib/openapi.ts","../src/lib/silkweave.module.ts","../src/lib/swagger.ts"],"mappings":";;;;;;;;;;;;;;;;;;UAUiB,0BAAA;;EAEf,WAAA,EAAa,WAAA,CAAY,eAAA;EAFgB;EAIzC,gBAAA,EAAkB,gBAAA;EAFO;EAIzB,WAAA,EAAa,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