nesties 1.1.1 → 1.1.3

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/build.js ADDED
@@ -0,0 +1,167 @@
1
+ #!/usr/bin/env node
2
+ /* build.js - node build.js [all|cjs|esm|types|clean] */
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const { builtinModules } = require('module');
6
+
7
+ const DIST_DIR = 'dist';
8
+
9
+ /* ------------------------- utils ------------------------- */
10
+ function readJSONSafe(file, fallback = {}) {
11
+ try {
12
+ const p = path.resolve(process.cwd(), file);
13
+ const txt = fs.readFileSync(p, 'utf8');
14
+ return JSON.parse(txt);
15
+ } catch {
16
+ return fallback;
17
+ }
18
+ }
19
+ function uniq(arr) { return Array.from(new Set(arr)); }
20
+ function ensureDir(p) { fs.mkdirSync(p, { recursive: true }); }
21
+ function rimraf(p) { if (fs.existsSync(p)) fs.rmSync(p, { recursive: true, force: true }); }
22
+
23
+ function depsAsExternal(pkg) {
24
+ const dep = Object.keys(pkg.dependencies || {});
25
+ const peer = Object.keys(pkg.peerDependencies || {});
26
+ const names = uniq([...dep, ...peer]);
27
+ // 覆盖子路径导入(lodash/fp、react/jsx-runtime)
28
+ return uniq(names.flatMap((n) => [n, `${n}/*`]));
29
+ }
30
+ function nodeBuiltinsExternal() {
31
+ // 既包含 'fs' 也包含 'node:fs' 形式
32
+ return uniq([...builtinModules, ...builtinModules.map((m) => `node:${m}`)]);
33
+ }
34
+ async function loadEsbuild() {
35
+ try { return require('esbuild'); }
36
+ catch { const mod = await import('esbuild'); return mod.build ? mod : mod.default; }
37
+ }
38
+ function tsconfigPath() { return fs.existsSync('tsconfig.json') ? 'tsconfig.json' : undefined; }
39
+ function entryPointsFromPkg(/*pkg*/) { return ['index.ts']; }
40
+
41
+ /* ------------------------- esbuild builds ------------------------- */
42
+ async function buildOne(format, options) {
43
+ const esbuild = await loadEsbuild();
44
+ const { external, tsconfig, entryPoints } = options;
45
+ const isCjs = format === 'cjs';
46
+ const outfile = path.join(DIST_DIR, isCjs ? 'index.cjs' : 'index.mjs');
47
+
48
+ ensureDir(path.dirname(outfile));
49
+ console.log(`[build] ${format} -> ${outfile}`);
50
+
51
+ await esbuild.build({
52
+ entryPoints,
53
+ outfile,
54
+ bundle: true,
55
+ sourcemap: true,
56
+ format, // 'cjs' | 'esm'
57
+ platform: isCjs ? 'node' : 'neutral',
58
+ target: isCjs ? 'es2021' : 'esnext',
59
+ external, // deps + peerDeps + node builtins (含 node:*)
60
+ logLevel: 'info',
61
+ ...(tsconfig ? { tsconfig } : {}),
62
+ });
63
+ }
64
+
65
+ /* ------------------------- types via TypeScript API ------------------------- */
66
+ function buildTypesAPI(outDir = DIST_DIR) {
67
+ let ts;
68
+ try { ts = require('typescript'); }
69
+ catch {
70
+ console.error('[types] Missing dependency: typescript');
71
+ process.exit(1);
72
+ }
73
+
74
+ const cfgPath = ts.findConfigFile('./', ts.sys.fileExists, 'tsconfig.json');
75
+
76
+ let fileNames, options;
77
+ if (cfgPath) {
78
+ // 读取 tsconfig.json
79
+ const { config } = ts.readConfigFile(cfgPath, ts.sys.readFile);
80
+ const parsed = ts.parseJsonConfigFileContent(config, ts.sys, path.dirname(cfgPath));
81
+ fileNames = parsed.fileNames;
82
+ options = parsed.options;
83
+ } else {
84
+ // 没有 tsconfig 的降级:仅用 index.ts
85
+ console.warn('[types] tsconfig.json not found; fallback to index.ts with basic options.');
86
+ fileNames = ['index.ts'].filter((f) => fs.existsSync(f));
87
+ options = {
88
+ moduleResolution: 99, // NodeNext(避免引入 enum 名字,用常量值)
89
+ target: 99, // ESNext
90
+ skipLibCheck: true,
91
+ strict: true,
92
+ };
93
+ }
94
+
95
+ // 强制仅输出声明
96
+ options.declaration = true;
97
+ options.emitDeclarationOnly = true;
98
+ options.outDir = outDir;
99
+ // 为了不受 sourceMap/emit 等其它设置影响
100
+ options.noEmitOnError = false;
101
+
102
+ console.log('[types] Generating .d.ts ...');
103
+ const program = ts.createProgram(fileNames, options);
104
+ const pre = ts.getPreEmitDiagnostics(program);
105
+ const emitResult = program.emit();
106
+ const diagnostics = pre.concat(emitResult.diagnostics);
107
+
108
+ if (diagnostics.length) {
109
+ const formatHost = {
110
+ getCanonicalFileName: (p) => p,
111
+ getCurrentDirectory: ts.sys.getCurrentDirectory,
112
+ getNewLine: () => ts.sys.newLine,
113
+ };
114
+ const message = ts.formatDiagnosticsWithColorAndContext(diagnostics, formatHost);
115
+ console.error(message);
116
+ if (emitResult.emitSkipped) {
117
+ throw new Error('[types] Type generation failed.');
118
+ }
119
+ }
120
+ console.log('[types] Declarations generated.');
121
+ }
122
+
123
+ /* ------------------------- main dispatcher ------------------------- */
124
+ (async function main() {
125
+ const sub = (process.argv[2] || 'all').toLowerCase(); // all | cjs | esm | types | clean
126
+
127
+ const pkg = readJSONSafe('package.json');
128
+ const externalFromPkg = depsAsExternal(pkg);
129
+ // 统一 external:依赖 + peer + Node 内置(含 node:*)
130
+ const external = uniq([...externalFromPkg, ...nodeBuiltinsExternal()]);
131
+ const tscPath = tsconfigPath();
132
+ const entryPoints = entryPointsFromPkg(pkg);
133
+
134
+ switch (sub) {
135
+ case 'clean': {
136
+ console.log('[clean] remove dist/');
137
+ rimraf(DIST_DIR);
138
+ break;
139
+ }
140
+ case 'cjs': {
141
+ await buildOne('cjs', { external, tsconfig: tscPath, entryPoints });
142
+ break;
143
+ }
144
+ case 'esm': {
145
+ await buildOne('esm', { external, tsconfig: tscPath, entryPoints });
146
+ break;
147
+ }
148
+ case 'types': {
149
+ ensureDir(DIST_DIR);
150
+ buildTypesAPI(DIST_DIR);
151
+ break;
152
+ }
153
+ case 'all':
154
+ default: {
155
+ console.log('[clean] remove dist/');
156
+ rimraf(DIST_DIR);
157
+ await buildOne('cjs', { external, tsconfig: tscPath, entryPoints });
158
+ await buildOne('esm', { external, tsconfig: tscPath, entryPoints });
159
+ buildTypesAPI(DIST_DIR);
160
+ console.log('[build] Done.');
161
+ break;
162
+ }
163
+ }
164
+ })().catch((err) => {
165
+ console.error('[build] Failed:', err);
166
+ process.exit(1);
167
+ });
package/dist/index.cjs ADDED
@@ -0,0 +1,483 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var __decorateClass = (decorators, target, key, kind) => {
19
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
20
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
21
+ if (decorator = decorators[i])
22
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
23
+ if (kind && result) __defProp(target, key, result);
24
+ return result;
25
+ };
26
+
27
+ // index.ts
28
+ var index_exports = {};
29
+ __export(index_exports, {
30
+ ABORT_SIGNAL: () => ABORT_SIGNAL,
31
+ AbortSignalProvider: () => AbortSignalProvider,
32
+ AbortableModule: () => AbortableModule,
33
+ ApiBlankResponse: () => ApiBlankResponse,
34
+ ApiError: () => ApiError,
35
+ ApiErrorTyped: () => ApiErrorTyped,
36
+ ApiTypeResponse: () => ApiTypeResponse,
37
+ As: () => As,
38
+ BlankPaginatedReturnMessageDto: () => BlankPaginatedReturnMessageDto,
39
+ BlankReturnMessageDto: () => BlankReturnMessageDto,
40
+ DataBody: () => DataBody,
41
+ DataPipe: () => DataPipe,
42
+ DataQuery: () => DataQuery,
43
+ GenericPaginatedReturnMessageDto: () => GenericPaginatedReturnMessageDto,
44
+ GenericReturnMessageDto: () => GenericReturnMessageDto,
45
+ InjectAbortSignal: () => InjectAbortSignal,
46
+ InjectAbortable: () => InjectAbortable,
47
+ InsertField: () => InsertField,
48
+ MergeClassDecorators: () => MergeClassDecorators,
49
+ MergeClassOrMethodDecorators: () => MergeClassOrMethodDecorators,
50
+ MergeMethodDecorators: () => MergeMethodDecorators,
51
+ MergeParameterDecorators: () => MergeParameterDecorators,
52
+ MergePropertyDecorators: () => MergePropertyDecorators,
53
+ PaginatedReturnMessageDto: () => PaginatedReturnMessageDto,
54
+ RequireToken: () => RequireToken,
55
+ ReturnMessageDto: () => ReturnMessageDto,
56
+ StringReturnMessageDto: () => StringReturnMessageDto,
57
+ TokenGuard: () => TokenGuard,
58
+ abortableToken: () => abortableToken,
59
+ createAbortableProvider: () => createAbortableProvider,
60
+ fromAbortable: () => fromAbortable,
61
+ getClassFromClassOrArray: () => getClassFromClassOrArray,
62
+ takeUntilAbort: () => takeUntilAbort
63
+ });
64
+ module.exports = __toCommonJS(index_exports);
65
+
66
+ // src/insert-field.ts
67
+ var import_swagger = require("@nestjs/swagger");
68
+ function getClassFromClassOrArray(o) {
69
+ return o instanceof Array ? o[0] : o;
70
+ }
71
+ function InsertField(cl, map, newName) {
72
+ const extendedCl = class extends cl {
73
+ };
74
+ for (const key in map) {
75
+ (0, import_swagger.ApiProperty)({
76
+ type: map[key].type,
77
+ ...map[key].options || {}
78
+ })(extendedCl.prototype, key);
79
+ }
80
+ Object.defineProperty(extendedCl, "name", {
81
+ value: newName || cl.name
82
+ });
83
+ return extendedCl;
84
+ }
85
+
86
+ // src/merge.ts
87
+ function MergePropertyDecorators(decs) {
88
+ return (obj, key) => {
89
+ for (const dec of decs) {
90
+ dec(obj, key);
91
+ }
92
+ };
93
+ }
94
+ function MergeMethodDecorators(decs) {
95
+ return (obj, key, descriptor) => {
96
+ for (const dec of decs) {
97
+ dec(obj, key, descriptor);
98
+ }
99
+ };
100
+ }
101
+ function MergeClassDecorators(decs) {
102
+ return (obj) => {
103
+ for (const dec of decs) {
104
+ dec(obj);
105
+ }
106
+ };
107
+ }
108
+ function MergeParameterDecorators(decs) {
109
+ return (obj, key, index) => {
110
+ for (const dec of decs) {
111
+ dec(obj, key, index);
112
+ }
113
+ };
114
+ }
115
+ function MergeClassOrMethodDecorators(decs) {
116
+ return (obj, key, descriptor) => {
117
+ if (descriptor) {
118
+ for (const dec of decs) {
119
+ dec(obj, key, descriptor);
120
+ }
121
+ } else {
122
+ for (const dec of decs) {
123
+ dec(obj);
124
+ }
125
+ }
126
+ };
127
+ }
128
+
129
+ // src/return-message.ts
130
+ var import_swagger2 = require("@nestjs/swagger");
131
+ var import_common = require("@nestjs/common");
132
+ var BlankReturnMessageDto = class {
133
+ constructor(statusCode, message) {
134
+ this.statusCode = statusCode;
135
+ this.message = message || "success";
136
+ this.success = statusCode < 400;
137
+ this.timestamp = /* @__PURE__ */ new Date();
138
+ }
139
+ toException() {
140
+ return new import_common.HttpException(this, this.statusCode);
141
+ }
142
+ };
143
+ __decorateClass([
144
+ (0, import_swagger2.ApiProperty)({ description: "Return code", type: Number })
145
+ ], BlankReturnMessageDto.prototype, "statusCode", 2);
146
+ __decorateClass([
147
+ (0, import_swagger2.ApiProperty)({ description: "Return message", type: String })
148
+ ], BlankReturnMessageDto.prototype, "message", 2);
149
+ __decorateClass([
150
+ (0, import_swagger2.ApiProperty)({ description: "Whether success.", type: Boolean })
151
+ ], BlankReturnMessageDto.prototype, "success", 2);
152
+ __decorateClass([
153
+ (0, import_swagger2.ApiProperty)({ description: "Return timestamp", type: Date })
154
+ ], BlankReturnMessageDto.prototype, "timestamp", 2);
155
+ var BlankPaginatedReturnMessageDto = class extends BlankReturnMessageDto {
156
+ constructor(statusCode, message, total, pageSettings) {
157
+ super(statusCode, message);
158
+ this.total = total;
159
+ this.pageCount = pageSettings.pageCount;
160
+ this.recordsPerPage = pageSettings.recordsPerPage;
161
+ this.totalPages = Math.ceil(total / pageSettings.recordsPerPage);
162
+ }
163
+ };
164
+ __decorateClass([
165
+ (0, import_swagger2.ApiProperty)({ description: "Total record count.", type: Number })
166
+ ], BlankPaginatedReturnMessageDto.prototype, "total", 2);
167
+ __decorateClass([
168
+ (0, import_swagger2.ApiProperty)({ description: "Total page count.", type: Number })
169
+ ], BlankPaginatedReturnMessageDto.prototype, "totalPages", 2);
170
+ __decorateClass([
171
+ (0, import_swagger2.ApiProperty)({ description: "Current page.", type: Number })
172
+ ], BlankPaginatedReturnMessageDto.prototype, "pageCount", 2);
173
+ __decorateClass([
174
+ (0, import_swagger2.ApiProperty)({ description: "Records per page.", type: Number })
175
+ ], BlankPaginatedReturnMessageDto.prototype, "recordsPerPage", 2);
176
+ var GenericReturnMessageDto = class extends BlankReturnMessageDto {
177
+ constructor(statusCode, message, data) {
178
+ super(statusCode, message);
179
+ this.data = data;
180
+ }
181
+ };
182
+ function ReturnMessageDto(type) {
183
+ return InsertField(
184
+ GenericReturnMessageDto,
185
+ {
186
+ data: {
187
+ type,
188
+ options: {
189
+ required: false,
190
+ description: "Return data."
191
+ }
192
+ }
193
+ },
194
+ `${getClassFromClassOrArray(type).name}${Array.isArray(type) ? "Array" : ""}ReturnMessageDto`
195
+ );
196
+ }
197
+ var GenericPaginatedReturnMessageDto = class extends BlankPaginatedReturnMessageDto {
198
+ constructor(statusCode, message, data, total, pageSettings) {
199
+ super(statusCode, message, total, pageSettings);
200
+ this.data = data;
201
+ }
202
+ };
203
+ function PaginatedReturnMessageDto(type) {
204
+ return InsertField(
205
+ GenericPaginatedReturnMessageDto,
206
+ {
207
+ data: {
208
+ type: [type],
209
+ options: {
210
+ required: false,
211
+ description: "Return data."
212
+ }
213
+ }
214
+ },
215
+ `${getClassFromClassOrArray(type).name}PaginatedReturnMessageDto`
216
+ );
217
+ }
218
+ var StringReturnMessageDto = class extends GenericReturnMessageDto {
219
+ };
220
+ __decorateClass([
221
+ (0, import_swagger2.ApiProperty)({ description: "Return data.", type: String, required: false })
222
+ ], StringReturnMessageDto.prototype, "data", 2);
223
+
224
+ // src/openapi.ts
225
+ var import_swagger3 = require("@nestjs/swagger");
226
+ var ApiTypeResponse = (type, options = {}) => (0, import_swagger3.ApiResponse)({
227
+ status: 200,
228
+ type: ReturnMessageDto(type),
229
+ ...options
230
+ });
231
+ var ApiBlankResponse = (options = {}) => (0, import_swagger3.ApiResponse)({
232
+ status: 200,
233
+ type: BlankReturnMessageDto,
234
+ ...options
235
+ });
236
+ var ApiError = (status, description) => ApiBlankResponse({ status, description });
237
+ var ApiErrorTyped = (status, description, type) => ApiTypeResponse(type, {
238
+ status,
239
+ description
240
+ });
241
+
242
+ // src/pipe.ts
243
+ var import_common2 = require("@nestjs/common");
244
+ var DataPipe = () => new import_common2.ValidationPipe({
245
+ transform: true,
246
+ transformOptions: { enableImplicitConversion: true }
247
+ });
248
+ var createDataPipeDec = (nestFieldDec) => (...extraPipes) => nestFieldDec(DataPipe(), ...extraPipes);
249
+ var DataQuery = createDataPipeDec(import_common2.Query);
250
+ var DataBody = createDataPipeDec(import_common2.Body);
251
+
252
+ // src/token.guard.ts
253
+ var import_common3 = require("@nestjs/common");
254
+ var import_swagger4 = require("@nestjs/swagger");
255
+ var TokenGuard = class {
256
+ constructor(config) {
257
+ this.config = config;
258
+ this.token = this.config.get("SERVER_TOKEN");
259
+ }
260
+ async canActivate(context) {
261
+ const request = context.switchToHttp().getRequest();
262
+ const token = request.headers["x-server-token"];
263
+ if (this.token && token !== this.token) {
264
+ throw new BlankReturnMessageDto(401, "Unauthorized").toException();
265
+ }
266
+ return true;
267
+ }
268
+ };
269
+ TokenGuard = __decorateClass([
270
+ (0, import_common3.Injectable)()
271
+ ], TokenGuard);
272
+ var RequireToken = () => MergeClassOrMethodDecorators([
273
+ (0, import_common3.UseGuards)(TokenGuard),
274
+ (0, import_swagger4.ApiHeader)({
275
+ name: "x-server-token",
276
+ description: "Server token",
277
+ required: false
278
+ }),
279
+ ApiError(401, "Incorrect server token provided")
280
+ ]);
281
+
282
+ // src/abort-utils.ts
283
+ var import_rxjs = require("rxjs");
284
+ var import_common4 = require("@nestjs/common");
285
+
286
+ // src/abort-http-signal.ts
287
+ function toRawReq(req) {
288
+ if (req?.raw?.socket) return req.raw;
289
+ return req;
290
+ }
291
+ function createAbortSignalFromHttp(req) {
292
+ const rawReq = toRawReq(req);
293
+ const ac = new AbortController();
294
+ const makeReason = () => new BlankReturnMessageDto(499, "Request aborted").toException();
295
+ const abortOnce = () => {
296
+ if (!ac.signal.aborted) ac.abort(makeReason());
297
+ cleanup();
298
+ };
299
+ const onClose = () => {
300
+ abortOnce();
301
+ };
302
+ const cleanup = () => {
303
+ rawReq.off?.("close", onClose);
304
+ };
305
+ rawReq.once?.("close", onClose);
306
+ return ac.signal;
307
+ }
308
+
309
+ // src/abort-utils.ts
310
+ var fromAbortable = (fn) => {
311
+ return new import_rxjs.Observable((subscriber) => {
312
+ const ac = new AbortController();
313
+ fn(ac).then(
314
+ (value) => {
315
+ if (!ac.signal.aborted && !subscriber.closed) {
316
+ subscriber.next(value);
317
+ subscriber.complete();
318
+ }
319
+ },
320
+ (err) => {
321
+ if (ac.signal.aborted) {
322
+ if (!subscriber.closed) subscriber.complete();
323
+ return;
324
+ }
325
+ if (!subscriber.closed) subscriber.error(err);
326
+ }
327
+ );
328
+ return () => {
329
+ if (!ac.signal.aborted) ac.abort();
330
+ };
331
+ });
332
+ };
333
+ var takeUntilAbort = (signal) => {
334
+ return (source) => {
335
+ return source.pipe(
336
+ (0, import_rxjs.takeUntil)(
337
+ new import_rxjs.Observable((subscriber) => {
338
+ const onAbort = () => subscriber.next();
339
+ if (signal.aborted) {
340
+ subscriber.next();
341
+ } else {
342
+ signal.addEventListener("abort", onAbort, { once: true });
343
+ }
344
+ return () => signal.removeEventListener("abort", onAbort);
345
+ })
346
+ )
347
+ );
348
+ };
349
+ };
350
+ var As = (0, import_common4.createParamDecorator)(
351
+ (_data, ctx) => {
352
+ const req = ctx.switchToHttp().getRequest();
353
+ return createAbortSignalFromHttp(req);
354
+ }
355
+ );
356
+
357
+ // src/abortable-module/abortable.token.ts
358
+ var import_common6 = require("@nestjs/common");
359
+ var import_nfkit = require("nfkit");
360
+
361
+ // src/abortable-module/abort-signal.provider.ts
362
+ var import_common5 = require("@nestjs/common");
363
+ var import_core = require("@nestjs/core");
364
+ var ABORT_SIGNAL = Symbol("ABORT_SIGNAL");
365
+ var AbortSignalProvider = {
366
+ provide: ABORT_SIGNAL,
367
+ scope: import_common5.Scope.REQUEST,
368
+ inject: [import_core.REQUEST],
369
+ useFactory: (req) => {
370
+ return createAbortSignalFromHttp(req);
371
+ }
372
+ };
373
+ var InjectAbortSignal = () => (0, import_common5.Inject)(ABORT_SIGNAL);
374
+
375
+ // src/abortable-module/abortable.token.ts
376
+ var import_core2 = require("@nestjs/core");
377
+ var tokenMemo = /* @__PURE__ */ new Map();
378
+ var abortableToken = (token) => {
379
+ if (tokenMemo.has(token)) return tokenMemo.get(token);
380
+ const name = typeof token === "function" ? token.name : String(token);
381
+ const sym = Symbol.for(`Abortable(${name})`);
382
+ tokenMemo.set(token, sym);
383
+ return sym;
384
+ };
385
+ function InjectAbortable(token) {
386
+ return (target, propertyKey, parameterIndex) => {
387
+ let actualToken = token;
388
+ if (!actualToken) {
389
+ const paramTypes = Reflect.getMetadata("design:paramtypes", target, propertyKey) || [];
390
+ actualToken = paramTypes[parameterIndex];
391
+ if (!actualToken) {
392
+ throw new Error(
393
+ `@InjectAbortable() cannot infer type from metadata: ${target.constructor?.name}[${parameterIndex}]`
394
+ );
395
+ }
396
+ }
397
+ (0, import_common6.Inject)(abortableToken(actualToken))(target, propertyKey, parameterIndex);
398
+ };
399
+ }
400
+ function createAbortableProvider(token, opts) {
401
+ const provide = abortableToken(token);
402
+ return {
403
+ provide,
404
+ scope: import_common6.Scope.REQUEST,
405
+ inject: [import_core2.ModuleRef, import_core2.REQUEST, ABORT_SIGNAL],
406
+ // ⚠️ 注意:用 async + resolve + contextId + strict:false
407
+ useFactory: async (moduleRef, req, signal) => {
408
+ const ctxId = import_core2.ContextIdFactory.getByRequest(req);
409
+ const svc = await moduleRef.resolve(token, ctxId, { strict: false });
410
+ if (svc == null) {
411
+ throw new Error(
412
+ `Abortable: provider "${String(
413
+ token.name ?? token
414
+ )}" not found in container (even with strict:false)`
415
+ );
416
+ }
417
+ return (0, import_nfkit.abortable)(svc, signal, opts);
418
+ }
419
+ };
420
+ }
421
+
422
+ // src/abortable-module/abortable.module.ts
423
+ var import_common7 = require("@nestjs/common");
424
+ var AbortableModule = class {
425
+ static forRoot() {
426
+ return {
427
+ module: AbortableModule,
428
+ providers: [AbortSignalProvider],
429
+ exports: [AbortSignalProvider],
430
+ global: true
431
+ };
432
+ }
433
+ static forFeature(tokens, options) {
434
+ const providers = tokens.map(
435
+ (token) => createAbortableProvider(token, options?.abortableOptions)
436
+ );
437
+ return {
438
+ module: AbortableModule,
439
+ providers: [...providers],
440
+ exports: [...providers]
441
+ };
442
+ }
443
+ };
444
+ AbortableModule = __decorateClass([
445
+ (0, import_common7.Module)({})
446
+ ], AbortableModule);
447
+ // Annotate the CommonJS export names for ESM import in node:
448
+ 0 && (module.exports = {
449
+ ABORT_SIGNAL,
450
+ AbortSignalProvider,
451
+ AbortableModule,
452
+ ApiBlankResponse,
453
+ ApiError,
454
+ ApiErrorTyped,
455
+ ApiTypeResponse,
456
+ As,
457
+ BlankPaginatedReturnMessageDto,
458
+ BlankReturnMessageDto,
459
+ DataBody,
460
+ DataPipe,
461
+ DataQuery,
462
+ GenericPaginatedReturnMessageDto,
463
+ GenericReturnMessageDto,
464
+ InjectAbortSignal,
465
+ InjectAbortable,
466
+ InsertField,
467
+ MergeClassDecorators,
468
+ MergeClassOrMethodDecorators,
469
+ MergeMethodDecorators,
470
+ MergeParameterDecorators,
471
+ MergePropertyDecorators,
472
+ PaginatedReturnMessageDto,
473
+ RequireToken,
474
+ ReturnMessageDto,
475
+ StringReturnMessageDto,
476
+ TokenGuard,
477
+ abortableToken,
478
+ createAbortableProvider,
479
+ fromAbortable,
480
+ getClassFromClassOrArray,
481
+ takeUntilAbort
482
+ });
483
+ //# sourceMappingURL=index.cjs.map