@silkweave/nestjs 1.9.0 → 1.9.1
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 +17 -17
- package/.turbo/turbo-check.log +1 -2
- package/.turbo/turbo-lint.log +2 -0
- package/.turbo/turbo-prepack.log +19 -0
- package/README.md +17 -15
- package/build/index.d.mts +110 -87
- package/build/index.d.mts.map +1 -1
- package/build/index.mjs +171 -195
- package/build/index.mjs.map +1 -1
- package/package.json +12 -6
- package/src/adapter/mcp.ts +84 -37
- package/src/adapter/rest.ts +39 -57
- package/src/adapter/trpc.ts +27 -51
- package/src/adapter/typegen.ts +55 -0
- package/src/decorator/actions.ts +1 -1
- package/src/index.ts +1 -1
- package/src/lib/discovery.ts +8 -8
- package/src/lib/executionContext.ts +3 -3
- package/src/lib/guards.ts +2 -2
- package/src/lib/silkweave.module.ts +40 -17
- package/src/lib/types.ts +35 -20
- package/tsconfig.tsbuildinfo +1 -1
- package/src/lib/silkweave.service.ts +0 -58
- package/src/lib/slot.ts +0 -51
package/build/index.mjs
CHANGED
|
@@ -1,84 +1,73 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { authMiddleware, mcpCors, mcpTransport, oauthRoutes, protectedResourceMetadata, sideloadResource } from "@silkweave/mcp";
|
|
2
|
+
import express from "express";
|
|
2
3
|
import { ForbiddenException, HttpException, Inject, Injectable, Module, SetMetadata } from "@nestjs/common";
|
|
3
4
|
import { validateToken } from "@silkweave/auth";
|
|
4
|
-
import { SilkweaveError, createAction,
|
|
5
|
+
import { SilkweaveError, createAction, createContext } from "@silkweave/core";
|
|
5
6
|
import { buildLogLevels } from "@silkweave/logger";
|
|
6
7
|
import { z } from "zod/v4";
|
|
7
8
|
import { buildRouter, createActionLogger, resolveAuth } from "@silkweave/trpc";
|
|
8
9
|
import { createExpressMiddleware } from "@trpc/server/adapters/express";
|
|
10
|
+
import { renderTypegen } from "@silkweave/typegen";
|
|
11
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
12
|
+
import { dirname, resolve } from "node:path";
|
|
9
13
|
import { DiscoveryModule, DiscoveryService, HttpAdapterHost, MetadataScanner, ModuleRef, Reflector } from "@nestjs/core";
|
|
10
14
|
import { kebabCase } from "change-case";
|
|
11
15
|
import { GUARDS_METADATA } from "@nestjs/common/constants.js";
|
|
12
16
|
//#region \0rolldown/runtime.js
|
|
13
|
-
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
14
|
-
//#endregion
|
|
15
|
-
//#region src/lib/slot.ts
|
|
16
|
-
function createMiddlewareSlot(label) {
|
|
17
|
-
let handler = (_req, res) => {
|
|
18
|
-
res.statusCode = 503;
|
|
19
|
-
res.setHeader("Content-Type", "application/json");
|
|
20
|
-
res.end(JSON.stringify({
|
|
21
|
-
error: "not_ready",
|
|
22
|
-
message: `${label} adapter has not started yet`
|
|
23
|
-
}));
|
|
24
|
-
};
|
|
25
|
-
return {
|
|
26
|
-
middleware: (req, res, next) => handler(req, res, next),
|
|
27
|
-
set: (h) => {
|
|
28
|
-
handler = h;
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Mount a middleware slot at the given base path on Nest's HTTP adapter and
|
|
34
|
-
* return the slot's `set()` callback. The slot middleware is installed
|
|
35
|
-
* synchronously so it sits in the Express stack before Nest's later-installed
|
|
36
|
-
* 404 catch-all.
|
|
37
|
-
*/
|
|
38
|
-
function reserveSlot(httpAdapter, basePath, label) {
|
|
39
|
-
const slot = createMiddlewareSlot(label);
|
|
40
|
-
httpAdapter.use(basePath, slot.middleware);
|
|
41
|
-
return slot.set;
|
|
42
|
-
}
|
|
17
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
43
18
|
//#endregion
|
|
44
19
|
//#region src/adapter/mcp.ts
|
|
20
|
+
function compose(...handlers) {
|
|
21
|
+
return (req, res, next) => {
|
|
22
|
+
let i = 0;
|
|
23
|
+
const dispatch = () => {
|
|
24
|
+
const h = handlers[i++];
|
|
25
|
+
if (!h) return next();
|
|
26
|
+
h(req, res, (err) => err ? next(err) : dispatch());
|
|
27
|
+
};
|
|
28
|
+
dispatch();
|
|
29
|
+
};
|
|
30
|
+
}
|
|
45
31
|
/**
|
|
46
|
-
* MCP
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* the configured base path.
|
|
32
|
+
* MCP adapter for `@silkweave/nestjs`. Registers the MCP Streamable HTTP
|
|
33
|
+
* transport, sideload, well-known and OAuth routes individually on Nest's
|
|
34
|
+
* HTTP adapter at the configured `basePath` (default `/mcp`):
|
|
50
35
|
*
|
|
51
|
-
*
|
|
52
|
-
* - `
|
|
53
|
-
* - `GET /resource
|
|
54
|
-
* - `GET
|
|
55
|
-
* - `GET /authorize`, `POST /token`, `POST /register`, `GET /auth/callback` (when `auth.provider` set)
|
|
36
|
+
* - `POST/GET/DELETE ${basePath}` - Streamable HTTP transport
|
|
37
|
+
* - `GET ${basePath}/resource/:id` - sideload (`sideloadResources` opt-out)
|
|
38
|
+
* - `GET ${basePath}/.well-known/oauth-protected-resource` - RFC 9728 metadata (when `auth.resourceUrl`/`auth.authorizationServers` set)
|
|
39
|
+
* - `GET ${basePath}/authorize`, `POST ${basePath}/token`, `POST ${basePath}/register`, `GET ${basePath}${callbackPath}` (when `auth.provider` set)
|
|
56
40
|
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
41
|
+
* Each route is a real Nest-level route - they show up in
|
|
42
|
+
* `RoutesResolver`'s log and there is no sub-app or middleware-slot
|
|
43
|
+
* indirection.
|
|
60
44
|
*/
|
|
61
45
|
function mcp(options = {}) {
|
|
62
46
|
return {
|
|
63
47
|
name: "mcp",
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
if (!
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
48
|
+
register({ httpAdapter, silkweaveOptions, baseContext, actions }) {
|
|
49
|
+
const basePath = (options.basePath ?? "/mcp").replace(/\/$/, "");
|
|
50
|
+
if (!basePath) throw new Error("@silkweave/nestjs mcp(): basePath cannot be empty or \"/\" - pick a path like \"/mcp\".");
|
|
51
|
+
const adapter = httpAdapter;
|
|
52
|
+
const corsHandler = mcpCors(options.cors ?? true);
|
|
53
|
+
const auth = options.auth;
|
|
54
|
+
const guard = auth ? authMiddleware(auth, baseContext) : null;
|
|
55
|
+
const prefix = (...handlers) => handlers.filter((h) => Boolean(h));
|
|
56
|
+
if (auth?.authorizationServers?.length && auth.resourceUrl) adapter.get(`${basePath}/.well-known/oauth-protected-resource`, ...prefix(corsHandler, protectedResourceMetadata(auth)));
|
|
57
|
+
if (auth?.provider) {
|
|
58
|
+
const oauth = oauthRoutes(auth);
|
|
59
|
+
adapter.get(`${basePath}/.well-known/oauth-authorization-server`, ...prefix(corsHandler, oauth.wellKnownAuthServer));
|
|
60
|
+
adapter.get(`${basePath}/authorize`, ...prefix(corsHandler, oauth.authorize));
|
|
61
|
+
adapter.get(`${basePath}${oauth.callbackPath}`, ...prefix(corsHandler, oauth.callback));
|
|
62
|
+
adapter.post(`${basePath}/token`, ...prefix(corsHandler, ...oauth.token));
|
|
63
|
+
adapter.post(`${basePath}/register`, ...prefix(corsHandler, ...oauth.register));
|
|
64
|
+
}
|
|
65
|
+
const protect = guard ? (h) => compose(guard, h) : (h) => h;
|
|
66
|
+
if (options.sideloadResources !== false) adapter.get(`${basePath}/resource/:id`, ...prefix(corsHandler, protect(sideloadResource({ resourceDir: options.resourceDir }))));
|
|
67
|
+
const transport = mcpTransport(silkweaveOptions, baseContext, actions);
|
|
68
|
+
adapter.post(basePath, ...prefix(corsHandler, express.json(), protect(transport.post)));
|
|
69
|
+
adapter.get(basePath, ...prefix(corsHandler, protect(transport.stream)));
|
|
70
|
+
adapter.delete(basePath, ...prefix(corsHandler, protect(transport.stream)));
|
|
82
71
|
}
|
|
83
72
|
};
|
|
84
73
|
}
|
|
@@ -114,7 +103,7 @@ async function readJsonBody(req) {
|
|
|
114
103
|
try {
|
|
115
104
|
resolve(JSON.parse(Buffer.concat(chunks).toString("utf-8")));
|
|
116
105
|
} catch (err) {
|
|
117
|
-
reject(err);
|
|
106
|
+
reject(err instanceof Error ? err : /* @__PURE__ */ new Error("Unable to parse JSON body"));
|
|
118
107
|
}
|
|
119
108
|
});
|
|
120
109
|
req.on("error", reject);
|
|
@@ -164,25 +153,8 @@ function handleRestError(err, res) {
|
|
|
164
153
|
message: "Internal error"
|
|
165
154
|
}, 500);
|
|
166
155
|
}
|
|
167
|
-
function
|
|
168
|
-
|
|
169
|
-
for (const action of actions) {
|
|
170
|
-
const method = action.kind === "query" ? "GET" : "POST";
|
|
171
|
-
routes.set(`${method} ${actionNameToPath(action.name)}`, action);
|
|
172
|
-
}
|
|
173
|
-
const logger = createRestLogger();
|
|
174
|
-
return async (req, res, next) => {
|
|
175
|
-
const pathOnly = (req.url ?? "/").split("?")[0];
|
|
176
|
-
const key = `${req.method ?? ""} ${pathOnly}`;
|
|
177
|
-
const action = routes.get(key);
|
|
178
|
-
if (!action) {
|
|
179
|
-
if (next) return next();
|
|
180
|
-
sendJson(res, {
|
|
181
|
-
error: "not_found",
|
|
182
|
-
message: `No route for ${req.method} ${pathOnly}`
|
|
183
|
-
}, 404);
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
156
|
+
function createActionHandler(action, context, auth, logger) {
|
|
157
|
+
return async (req, res) => {
|
|
186
158
|
try {
|
|
187
159
|
const reqLike = req;
|
|
188
160
|
let authInfo;
|
|
@@ -209,33 +181,28 @@ function buildHandler(actions, context, auth) {
|
|
|
209
181
|
};
|
|
210
182
|
}
|
|
211
183
|
/**
|
|
212
|
-
* REST adapter for `@silkweave/nestjs`.
|
|
213
|
-
* route on Nest's
|
|
184
|
+
* REST adapter for `@silkweave/nestjs`. Registers each discovered `@Action`
|
|
185
|
+
* as an individual route on Nest's HTTP adapter:
|
|
214
186
|
*
|
|
215
|
-
* - `kind: 'query'` → `GET ${basePath}/${actionName-with-slashes}` (input
|
|
216
|
-
* - `kind: 'mutation'` → `POST ${basePath}/${actionName-with-slashes}` (input
|
|
187
|
+
* - `kind: 'query'` → `GET ${basePath}/${actionName-with-slashes}` (input from query string)
|
|
188
|
+
* - `kind: 'mutation'` → `POST ${basePath}/${actionName-with-slashes}` (input from JSON body)
|
|
217
189
|
*
|
|
218
|
-
*
|
|
219
|
-
* `@nestjs/
|
|
220
|
-
*
|
|
190
|
+
* Routes show up in Nest's `RoutesResolver` logger and are eligible for
|
|
191
|
+
* `@nestjs/swagger` scanning. Works on `@nestjs/platform-express` out of the
|
|
192
|
+
* box. For `@nestjs/platform-fastify`, register `@fastify/express` first.
|
|
221
193
|
*/
|
|
222
194
|
function rest(options = {}) {
|
|
223
195
|
return {
|
|
224
196
|
name: "rest",
|
|
225
|
-
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
const
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
setHandler(buildHandler(actions, context, options.auth));
|
|
235
|
-
},
|
|
236
|
-
stop: async () => {}
|
|
237
|
-
};
|
|
238
|
-
};
|
|
197
|
+
register({ httpAdapter, baseContext, actions }) {
|
|
198
|
+
const basePath = (options.basePath ?? "/api").replace(/\/$/, "");
|
|
199
|
+
const logger = createRestLogger();
|
|
200
|
+
for (const action of actions) {
|
|
201
|
+
const path = `${basePath}${actionNameToPath(action.name)}`;
|
|
202
|
+
const method = action.kind === "query" ? "get" : "post";
|
|
203
|
+
const handler = createActionHandler(action, baseContext, options.auth, logger);
|
|
204
|
+
httpAdapter[method](path, handler);
|
|
205
|
+
}
|
|
239
206
|
}
|
|
240
207
|
};
|
|
241
208
|
}
|
|
@@ -243,54 +210,75 @@ function rest(options = {}) {
|
|
|
243
210
|
//#region src/adapter/trpc.ts
|
|
244
211
|
/**
|
|
245
212
|
* tRPC adapter for `@silkweave/nestjs`. Builds a tRPC router from discovered
|
|
246
|
-
* `@Action` methods
|
|
247
|
-
*
|
|
248
|
-
* underlying HTTP server.
|
|
213
|
+
* `@Action` methods and mounts the resulting express middleware at
|
|
214
|
+
* `basePath` on Nest's HTTP adapter.
|
|
249
215
|
*
|
|
250
216
|
* Action names with dots (e.g. `users.list` from `@Actions('users')`) collapse
|
|
251
|
-
* to camelCase procedure keys (`usersList`)
|
|
217
|
+
* to camelCase procedure keys (`usersList`).
|
|
252
218
|
*
|
|
253
219
|
* Works on `@nestjs/platform-express`. On `@nestjs/platform-fastify`, register
|
|
254
|
-
* `@fastify/express` first so Nest can
|
|
220
|
+
* `@fastify/express` first so Nest can serve Express-style middleware.
|
|
255
221
|
*/
|
|
256
222
|
function trpc(options = {}) {
|
|
257
223
|
return {
|
|
258
224
|
name: "trpc",
|
|
259
|
-
|
|
260
|
-
const
|
|
261
|
-
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
}
|
|
279
|
-
return { silkweaveContext: context.fork({
|
|
280
|
-
logger,
|
|
281
|
-
request: opts.req,
|
|
282
|
-
response: opts.res,
|
|
283
|
-
...resolved.authInfo ? { auth: resolved.authInfo } : {}
|
|
284
|
-
}) };
|
|
285
|
-
};
|
|
286
|
-
setHandler(createExpressMiddleware({
|
|
287
|
-
router,
|
|
288
|
-
createContext
|
|
289
|
-
}));
|
|
290
|
-
},
|
|
291
|
-
stop: async () => {}
|
|
292
|
-
};
|
|
225
|
+
register({ httpAdapter, baseContext, actions }) {
|
|
226
|
+
const basePath = (options.basePath ?? "/trpc").replace(/\/$/, "") || "/";
|
|
227
|
+
const router = buildRouter(actions);
|
|
228
|
+
const logger = createActionLogger();
|
|
229
|
+
const createContext = async (opts) => {
|
|
230
|
+
const resolved = await resolveAuth(options.auth, opts.req.headers.authorization, baseContext.fork({ request: opts.req }));
|
|
231
|
+
if (resolved.kind === "error") {
|
|
232
|
+
for (const [key, value] of Object.entries(resolved.error.headers)) opts.res.setHeader(key, value);
|
|
233
|
+
opts.res.statusCode = resolved.error.statusCode;
|
|
234
|
+
opts.res.setHeader("Content-Type", "application/json");
|
|
235
|
+
opts.res.end(JSON.stringify(resolved.error.body));
|
|
236
|
+
throw new Error("Unauthorized");
|
|
237
|
+
}
|
|
238
|
+
return { silkweaveContext: baseContext.fork({
|
|
239
|
+
logger,
|
|
240
|
+
request: opts.req,
|
|
241
|
+
response: opts.res,
|
|
242
|
+
...resolved.authInfo ? { auth: resolved.authInfo } : {}
|
|
243
|
+
}) };
|
|
293
244
|
};
|
|
245
|
+
const middleware = createExpressMiddleware({
|
|
246
|
+
router,
|
|
247
|
+
createContext
|
|
248
|
+
});
|
|
249
|
+
httpAdapter.use(basePath, middleware);
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
//#endregion
|
|
254
|
+
//#region src/adapter/typegen.ts
|
|
255
|
+
/**
|
|
256
|
+
* Typegen adapter for `@silkweave/nestjs`. Discovers every `@Action`-decorated
|
|
257
|
+
* method (regardless of `transports` filtering) and writes a single `.d.ts`
|
|
258
|
+
* file with REST input/output interfaces and/or a tRPC `AppRouter` type alias.
|
|
259
|
+
*
|
|
260
|
+
* Designed for the monorepo pattern where the server (this app) is the source
|
|
261
|
+
* of truth for types and consumer apps import from `path` - e.g.
|
|
262
|
+
* `path: '../app/src/types/silkweave.ts'`.
|
|
263
|
+
*/
|
|
264
|
+
function typegen(options) {
|
|
265
|
+
const enabled = options.enabled ?? process.env["NODE_ENV"] !== "production";
|
|
266
|
+
return {
|
|
267
|
+
name: "typegen",
|
|
268
|
+
allActions: true,
|
|
269
|
+
register({ actions }) {
|
|
270
|
+
if (!enabled) return;
|
|
271
|
+
const output = renderTypegen(actions, options.format ?? "all");
|
|
272
|
+
const target = resolve(options.path);
|
|
273
|
+
(async () => {
|
|
274
|
+
try {
|
|
275
|
+
await mkdir(dirname(target), { recursive: true });
|
|
276
|
+
await writeFile(target, output, "utf-8");
|
|
277
|
+
console.info(`@silkweave/nestjs typegen: wrote ${actions.length} action types to ${target}`);
|
|
278
|
+
} catch (err) {
|
|
279
|
+
console.error("@silkweave/nestjs typegen:", err);
|
|
280
|
+
}
|
|
281
|
+
})();
|
|
294
282
|
}
|
|
295
283
|
};
|
|
296
284
|
}
|
|
@@ -341,7 +329,7 @@ function Action(options) {
|
|
|
341
329
|
* prefix. The prefix is joined to each method's action name with a dot
|
|
342
330
|
* (e.g. `@Actions('users')` + method `list` → action name `users.list`).
|
|
343
331
|
*
|
|
344
|
-
* The class itself remains a normal Nest provider
|
|
332
|
+
* The class itself remains a normal Nest provider - add `@Injectable()`
|
|
345
333
|
* separately so it can be resolved by the DI container.
|
|
346
334
|
*
|
|
347
335
|
* Accepts either a prefix string (shorthand) or a full options object:
|
|
@@ -9040,7 +9028,7 @@ function collectGuards(reflector, classRef, handler) {
|
|
|
9040
9028
|
}
|
|
9041
9029
|
async function resolveGuard(ref, moduleRef) {
|
|
9042
9030
|
if (typeof ref === "function") try {
|
|
9043
|
-
return moduleRef.get(ref, { strict: false });
|
|
9031
|
+
return await moduleRef.get(ref, { strict: false });
|
|
9044
9032
|
} catch {
|
|
9045
9033
|
return moduleRef.create(ref);
|
|
9046
9034
|
}
|
|
@@ -9063,12 +9051,12 @@ async function runGuards(guards, moduleRef, reflector, classRef, handler, reques
|
|
|
9063
9051
|
}
|
|
9064
9052
|
}
|
|
9065
9053
|
//#endregion
|
|
9066
|
-
//#region \0@oxc-project+runtime@0.
|
|
9054
|
+
//#region \0@oxc-project+runtime@0.127.0/helpers/decorateMetadata.js
|
|
9067
9055
|
function __decorateMetadata(k, v) {
|
|
9068
9056
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9069
9057
|
}
|
|
9070
9058
|
//#endregion
|
|
9071
|
-
//#region \0@oxc-project+runtime@0.
|
|
9059
|
+
//#region \0@oxc-project+runtime@0.127.0/helpers/decorate.js
|
|
9072
9060
|
function __decorate(decorators, target, key, desc) {
|
|
9073
9061
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
9074
9062
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -9158,74 +9146,62 @@ ActionDiscovery = __decorate([Injectable(), __decorateMetadata("design:paramtype
|
|
|
9158
9146
|
//#region src/lib/types.ts
|
|
9159
9147
|
const SILKWEAVE_MODULE_OPTIONS = "__silkweave_module_options__";
|
|
9160
9148
|
//#endregion
|
|
9161
|
-
//#region \0@oxc-project+runtime@0.
|
|
9149
|
+
//#region \0@oxc-project+runtime@0.127.0/helpers/decorateParam.js
|
|
9162
9150
|
function __decorateParam(paramIndex, decorator) {
|
|
9163
9151
|
return function(target, key) {
|
|
9164
9152
|
decorator(target, key, paramIndex);
|
|
9165
9153
|
};
|
|
9166
9154
|
}
|
|
9167
9155
|
//#endregion
|
|
9168
|
-
//#region src/lib/silkweave.
|
|
9169
|
-
var _ref, _ref2;
|
|
9170
|
-
let
|
|
9156
|
+
//#region src/lib/silkweave.module.ts
|
|
9157
|
+
var _ref, _ref2, _SilkweaveModule;
|
|
9158
|
+
let SilkweaveModule = _SilkweaveModule = class SilkweaveModule {
|
|
9171
9159
|
constructor(options, discovery, httpAdapterHost) {
|
|
9172
9160
|
this.options = options;
|
|
9173
9161
|
this.discovery = discovery;
|
|
9174
9162
|
this.httpAdapterHost = httpAdapterHost;
|
|
9175
|
-
this.generators = [];
|
|
9176
|
-
}
|
|
9177
|
-
onModuleInit() {
|
|
9178
|
-
for (const adapter of this.options.adapters) this.generators.push(adapter.install(this.httpAdapterHost));
|
|
9179
|
-
}
|
|
9180
|
-
async onApplicationBootstrap() {
|
|
9181
|
-
const actions = this.discovery.discover();
|
|
9182
|
-
const builder = silkweave(this.options.silkweave);
|
|
9183
|
-
for (const [key, value] of Object.entries(this.options.context ?? {})) builder.set(key, value);
|
|
9184
|
-
for (const gen of this.generators) builder.adapter(gen);
|
|
9185
|
-
builder.actions(actions);
|
|
9186
|
-
await builder.start();
|
|
9187
|
-
this.builder = builder;
|
|
9188
9163
|
}
|
|
9189
|
-
|
|
9190
|
-
|
|
9191
|
-
|
|
9192
|
-
|
|
9193
|
-
|
|
9194
|
-
|
|
9164
|
+
static forRoot(options) {
|
|
9165
|
+
return {
|
|
9166
|
+
module: _SilkweaveModule,
|
|
9167
|
+
global: true,
|
|
9168
|
+
imports: [DiscoveryModule],
|
|
9169
|
+
providers: [{
|
|
9170
|
+
provide: SILKWEAVE_MODULE_OPTIONS,
|
|
9171
|
+
useValue: options
|
|
9172
|
+
}, ActionDiscovery],
|
|
9173
|
+
exports: []
|
|
9174
|
+
};
|
|
9175
|
+
}
|
|
9176
|
+
configure(_consumer) {
|
|
9177
|
+
const httpAdapter = this.httpAdapterHost.httpAdapter;
|
|
9178
|
+
if (!httpAdapter) throw new Error("@silkweave/nestjs: HttpAdapterHost.httpAdapter is not available.");
|
|
9179
|
+
const allActions = this.discovery.discover();
|
|
9180
|
+
for (const adapter of this.options.adapters) {
|
|
9181
|
+
const baseContext = createContext({
|
|
9182
|
+
...this.options.context ?? {},
|
|
9183
|
+
adapter: adapter.name
|
|
9184
|
+
});
|
|
9185
|
+
const actions = adapter.allActions ? allActions : allActions.filter((a) => !a.isEnabled || a.isEnabled(baseContext));
|
|
9186
|
+
adapter.register({
|
|
9187
|
+
httpAdapter,
|
|
9188
|
+
silkweaveOptions: this.options.silkweave,
|
|
9189
|
+
baseContext,
|
|
9190
|
+
actions
|
|
9191
|
+
});
|
|
9192
|
+
}
|
|
9195
9193
|
}
|
|
9196
9194
|
};
|
|
9197
|
-
|
|
9198
|
-
|
|
9195
|
+
SilkweaveModule = _SilkweaveModule = __decorate([
|
|
9196
|
+
Module({}),
|
|
9199
9197
|
__decorateParam(0, Inject(SILKWEAVE_MODULE_OPTIONS)),
|
|
9200
9198
|
__decorateMetadata("design:paramtypes", [
|
|
9201
9199
|
Object,
|
|
9202
9200
|
typeof (_ref = typeof ActionDiscovery !== "undefined" && ActionDiscovery) === "function" ? _ref : Object,
|
|
9203
9201
|
typeof (_ref2 = typeof HttpAdapterHost !== "undefined" && HttpAdapterHost) === "function" ? _ref2 : Object
|
|
9204
9202
|
])
|
|
9205
|
-
],
|
|
9206
|
-
//#endregion
|
|
9207
|
-
//#region src/lib/silkweave.module.ts
|
|
9208
|
-
var _SilkweaveModule;
|
|
9209
|
-
let SilkweaveModule = _SilkweaveModule = class SilkweaveModule {
|
|
9210
|
-
static forRoot(options) {
|
|
9211
|
-
return {
|
|
9212
|
-
module: _SilkweaveModule,
|
|
9213
|
-
global: true,
|
|
9214
|
-
imports: [DiscoveryModule],
|
|
9215
|
-
providers: [
|
|
9216
|
-
{
|
|
9217
|
-
provide: SILKWEAVE_MODULE_OPTIONS,
|
|
9218
|
-
useValue: options
|
|
9219
|
-
},
|
|
9220
|
-
ActionDiscovery,
|
|
9221
|
-
SilkweaveService
|
|
9222
|
-
],
|
|
9223
|
-
exports: [SilkweaveService]
|
|
9224
|
-
};
|
|
9225
|
-
}
|
|
9226
|
-
};
|
|
9227
|
-
SilkweaveModule = _SilkweaveModule = __decorate([Module({})], SilkweaveModule);
|
|
9203
|
+
], SilkweaveModule);
|
|
9228
9204
|
//#endregion
|
|
9229
|
-
export { ACTIONS_METADATA, ACTION_METADATA, ACTION_RESPONSE_KEY, Action, ActionDiscovery, Actions, SILKWEAVE_MODULE_OPTIONS, SilkweaveModule,
|
|
9205
|
+
export { ACTIONS_METADATA, ACTION_METADATA, ACTION_RESPONSE_KEY, Action, ActionDiscovery, Actions, SILKWEAVE_MODULE_OPTIONS, SilkweaveModule, buildIsEnabled, collectGuards, mcp, rest, runGuards, trpc, typegen };
|
|
9230
9206
|
|
|
9231
9207
|
//# sourceMappingURL=index.mjs.map
|