@reqray/nestjs 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +77 -2
- package/dist/index.cjs +163 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +64 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.js +141 -0
- package/dist/index.js.map +1 -0
- package/package.json +75 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ruslan Kryklyvyi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,78 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @reqray/nestjs
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Reqray for NestJS: every request as a waterfall — SQL, outgoing HTTP, cache,
|
|
4
|
+
bodies after masking — and N+1 queries pointed at the file and the line.
|
|
5
|
+
|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
## Use
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @reqray/nestjs @reqray/register
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { Module } from '@nestjs/common';
|
|
16
|
+
import { ReqrayModule } from '@reqray/nestjs';
|
|
17
|
+
|
|
18
|
+
@Module({
|
|
19
|
+
imports: [ReqrayModule.forRoot()],
|
|
20
|
+
})
|
|
21
|
+
export class AppModule {}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
node --import @reqray/register dist/main.js
|
|
26
|
+
# open http://localhost:3000/_reqray/
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
One module in `imports`, nothing else. The platform — Express or Fastify — is
|
|
30
|
+
detected on its own. Exceptions are observed, not handled: your own exception
|
|
31
|
+
filters keep deciding the response, and Reqray records what was thrown.
|
|
32
|
+
|
|
33
|
+
`--import @reqray/register` is what instruments the database driver, the cache
|
|
34
|
+
client and `fetch`.
|
|
35
|
+
|
|
36
|
+
NestJS 10 and 11. Node 20 or newer.
|
|
37
|
+
|
|
38
|
+
## Options
|
|
39
|
+
|
|
40
|
+
`forRoot` takes the same options as the other adapters:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
ReqrayModule.forRoot({
|
|
44
|
+
panel: { gate: ({ headers }) => headers['x-admin'] === process.env.ADMIN_KEY },
|
|
45
|
+
redact: { headers: ['x-api-key'] },
|
|
46
|
+
})
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
| Option | Default | What it does |
|
|
50
|
+
|---|---|---|
|
|
51
|
+
| `enabled` | `NODE_ENV !== 'production'` | Off means off: nothing is recorded and nothing is mounted |
|
|
52
|
+
| `mode` | from `NODE_ENV` | `'development'` keeps every request; `'production'` samples |
|
|
53
|
+
| `panel` | `{ path: '/_reqray' }` | `false` to not mount it; `{ gate }` decides who gets in |
|
|
54
|
+
| `transport` | memory, last 500 requests | Where records go — see `@reqray/store-sqlite`, `@reqray/transport-http`, `@reqray/transport-file` |
|
|
55
|
+
| `redact` | see below | `{ headers: [...], body: [...] }` extend the masked names |
|
|
56
|
+
| `detect` | all on | `{ nPlusOne: { threshold: 10 }, slowBudget: false }` |
|
|
57
|
+
| `sampling` | 100% locally, 1% in production | `{ rate, slowMs, alwaysOnError, alwaysOnFinding }` |
|
|
58
|
+
| `replay`, `explain`, `blame` | local development only | Opt-in anywhere else |
|
|
59
|
+
| `collectSqlValues` | `false` | SQL parameter values are never recorded unless you ask |
|
|
60
|
+
|
|
61
|
+
Masked before anything is stored: `authorization`, `cookie`, `set-cookie` in
|
|
62
|
+
headers; `password`, `token`, `secret`, `cardNumber`, `cvv`, `apiKey`,
|
|
63
|
+
`signature` in bodies and query strings.
|
|
64
|
+
|
|
65
|
+
Outside local development the panel does not mount without an explicit gate —
|
|
66
|
+
the application fails at startup with an explanation rather than opening
|
|
67
|
+
access. `panel: { gate: 'open' }` if open is what you mean, or a function:
|
|
68
|
+
`gate: ({ headers, ip }) => headers['x-admin'] === process.env.ADMIN_KEY`.
|
|
69
|
+
|
|
70
|
+
## More
|
|
71
|
+
|
|
72
|
+
Everything else — the detectors, security defaults, measured overhead and a
|
|
73
|
+
demo that runs with one command — is in the
|
|
74
|
+
[main README](https://github.com/reqray/reqray#readme).
|
|
75
|
+
|
|
76
|
+
## License
|
|
77
|
+
|
|
78
|
+
[MIT](https://github.com/reqray/reqray/blob/main/LICENSE)
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __typeError = (msg) => {
|
|
7
|
+
throw TypeError(msg);
|
|
8
|
+
};
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
23
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
24
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
25
|
+
if (decorator = decorators[i])
|
|
26
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
27
|
+
if (kind && result) __defProp(target, key, result);
|
|
28
|
+
return result;
|
|
29
|
+
};
|
|
30
|
+
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
31
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
32
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
33
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
34
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
35
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
36
|
+
|
|
37
|
+
// src/index.ts
|
|
38
|
+
var index_exports = {};
|
|
39
|
+
__export(index_exports, {
|
|
40
|
+
REQRAY_OPTIONS: () => REQRAY_OPTIONS,
|
|
41
|
+
ReqrayErrorInterceptor: () => ReqrayErrorInterceptor,
|
|
42
|
+
ReqrayModule: () => ReqrayModule
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(index_exports);
|
|
45
|
+
|
|
46
|
+
// ../../node_modules/.pnpm/tsup@8.5.1_postcss@8.5.26_supports-color@7.2.0_typescript@6.0.3_yaml@2.9.0/node_modules/tsup/assets/cjs_shims.js
|
|
47
|
+
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
|
|
48
|
+
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
49
|
+
|
|
50
|
+
// src/index.ts
|
|
51
|
+
var import_node_module = require("module");
|
|
52
|
+
var import_common = require("@nestjs/common");
|
|
53
|
+
var import_core = require("@nestjs/core");
|
|
54
|
+
var import_core2 = require("@reqray/core");
|
|
55
|
+
var import_express = require("@reqray/express");
|
|
56
|
+
var import_fastify = require("@reqray/fastify");
|
|
57
|
+
var import_rxjs = require("rxjs");
|
|
58
|
+
var REQRAY_OPTIONS = /* @__PURE__ */ Symbol.for("reqray.nestjs.options");
|
|
59
|
+
function nestVersion() {
|
|
60
|
+
try {
|
|
61
|
+
const manifest = (0, import_node_module.createRequire)(importMetaUrl)("@nestjs/core/package.json");
|
|
62
|
+
return typeof manifest.version === "string" ? manifest.version : void 0;
|
|
63
|
+
} catch {
|
|
64
|
+
return void 0;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function allRoutes() {
|
|
68
|
+
const version = nestVersion();
|
|
69
|
+
const major = version ? Number.parseInt(version, 10) : 11;
|
|
70
|
+
return major >= 11 ? "{*splat}" : "*";
|
|
71
|
+
}
|
|
72
|
+
var ReqrayErrorInterceptor = class {
|
|
73
|
+
intercept(context, next) {
|
|
74
|
+
if (context.getType() !== "http") return next.handle();
|
|
75
|
+
return next.handle().pipe(
|
|
76
|
+
(0, import_rxjs.tap)({
|
|
77
|
+
error: (exception) => {
|
|
78
|
+
if (exception instanceof import_common.HttpException) return;
|
|
79
|
+
try {
|
|
80
|
+
const http = context.switchToHttp();
|
|
81
|
+
(0, import_express.recordFailure)(http.getResponse(), exception);
|
|
82
|
+
(0, import_fastify.recordFailure)(http.getRequest(), exception);
|
|
83
|
+
} catch {
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
ReqrayErrorInterceptor = __decorateClass([
|
|
91
|
+
(0, import_common.Injectable)()
|
|
92
|
+
], ReqrayErrorInterceptor);
|
|
93
|
+
var _express, _adapterHost, _options, _ReqrayModule_instances, platform_fn;
|
|
94
|
+
var ReqrayModule = class {
|
|
95
|
+
constructor(adapterHost, options) {
|
|
96
|
+
__privateAdd(this, _ReqrayModule_instances);
|
|
97
|
+
/** The Express inspector, when the platform is Express. */
|
|
98
|
+
__privateAdd(this, _express, null);
|
|
99
|
+
__privateAdd(this, _adapterHost);
|
|
100
|
+
__privateAdd(this, _options);
|
|
101
|
+
__privateSet(this, _adapterHost, adapterHost);
|
|
102
|
+
__privateSet(this, _options, options);
|
|
103
|
+
}
|
|
104
|
+
static forRoot(options = {}) {
|
|
105
|
+
return {
|
|
106
|
+
module: ReqrayModule,
|
|
107
|
+
providers: [
|
|
108
|
+
{ provide: REQRAY_OPTIONS, useValue: options },
|
|
109
|
+
{ provide: import_core.APP_INTERCEPTOR, useClass: ReqrayErrorInterceptor }
|
|
110
|
+
]
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/** Runtime of the platform adapter — for tests and manual access. */
|
|
114
|
+
get reqray() {
|
|
115
|
+
if (__privateGet(this, _express)) return __privateGet(this, _express).runtime;
|
|
116
|
+
if (__privateMethod(this, _ReqrayModule_instances, platform_fn).call(this) === "fastify") {
|
|
117
|
+
const instance = __privateGet(this, _adapterHost).httpAdapter?.getInstance();
|
|
118
|
+
return instance?.reqray ?? null;
|
|
119
|
+
}
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
configure(consumer) {
|
|
123
|
+
if (__privateMethod(this, _ReqrayModule_instances, platform_fn).call(this) !== "express") return;
|
|
124
|
+
(0, import_core2.reportInstrumentation)({
|
|
125
|
+
name: "nestjs",
|
|
126
|
+
version: nestVersion(),
|
|
127
|
+
captures: "requests (express platform)",
|
|
128
|
+
ok: true
|
|
129
|
+
});
|
|
130
|
+
__privateSet(this, _express, (0, import_express.reqray)(__privateGet(this, _options)));
|
|
131
|
+
consumer.apply(__privateGet(this, _express).middleware).forRoutes(allRoutes());
|
|
132
|
+
}
|
|
133
|
+
async onModuleInit() {
|
|
134
|
+
if (__privateMethod(this, _ReqrayModule_instances, platform_fn).call(this) !== "fastify") return;
|
|
135
|
+
(0, import_core2.reportInstrumentation)({
|
|
136
|
+
name: "nestjs",
|
|
137
|
+
version: nestVersion(),
|
|
138
|
+
captures: "requests (fastify platform)",
|
|
139
|
+
ok: true
|
|
140
|
+
});
|
|
141
|
+
const instance = __privateGet(this, _adapterHost).httpAdapter.getInstance();
|
|
142
|
+
await instance.register(import_fastify.reqray, __privateGet(this, _options));
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
_express = new WeakMap();
|
|
146
|
+
_adapterHost = new WeakMap();
|
|
147
|
+
_options = new WeakMap();
|
|
148
|
+
_ReqrayModule_instances = new WeakSet();
|
|
149
|
+
platform_fn = function() {
|
|
150
|
+
return __privateGet(this, _adapterHost).httpAdapter?.getType() ?? "express";
|
|
151
|
+
};
|
|
152
|
+
ReqrayModule = __decorateClass([
|
|
153
|
+
(0, import_common.Module)({}),
|
|
154
|
+
__decorateParam(0, (0, import_common.Inject)(import_core.HttpAdapterHost)),
|
|
155
|
+
__decorateParam(1, (0, import_common.Inject)(REQRAY_OPTIONS))
|
|
156
|
+
], ReqrayModule);
|
|
157
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
158
|
+
0 && (module.exports = {
|
|
159
|
+
REQRAY_OPTIONS,
|
|
160
|
+
ReqrayErrorInterceptor,
|
|
161
|
+
ReqrayModule
|
|
162
|
+
});
|
|
163
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../../../node_modules/.pnpm/tsup@8.5.1_postcss@8.5.26_supports-color@7.2.0_typescript@6.0.3_yaml@2.9.0/node_modules/tsup/assets/cjs_shims.js"],"sourcesContent":["/**\n * `@reqray/nestjs` — NestJS adapter.\n *\n * One module in `imports`, nothing else. Underneath it defers to the existing\n * platform adapters: on Express (the Nest default) the `@reqray/express`\n * middleware goes through the middleware consumer, on Fastify the\n * `@reqray/fastify` plugin is registered on the underlying instance.\n *\n * The one thing neither platform adapter can see under Nest is the exception:\n * Nest intercepts it before Express error middleware or Fastify's `onError`\n * ever run. A global interceptor stamps it onto the request/response as it\n * passes, and passes it on: handling stays with whichever filter the\n * application has, or with Nest's default.\n *\n * Injection note: everything is an explicit `@Inject(token)` — this package\n * is built without decorator metadata emission.\n */\n\nimport { createRequire } from 'node:module';\nimport {\n type CallHandler,\n type DynamicModule,\n type ExecutionContext,\n HttpException,\n Inject,\n Injectable,\n type MiddlewareConsumer,\n Module,\n type NestInterceptor,\n type NestModule,\n type OnModuleInit,\n} from '@nestjs/common';\nimport { APP_INTERCEPTOR, HttpAdapterHost } from '@nestjs/core';\nimport type { Reqray, ReqrayInit } from '@reqray/core';\nimport { reportInstrumentation } from '@reqray/core';\nimport {\n recordFailure as expressFailure,\n reqray as expressReqray,\n type ReqrayExpress,\n} from '@reqray/express';\nimport { recordFailure as fastifyFailure, reqray as fastifyReqray } from '@reqray/fastify';\nimport type { FastifyInstance } from 'fastify';\nimport { type Observable, tap } from 'rxjs';\n\n/** Token the Reqray options travel under inside the Nest container. */\nexport const REQRAY_OPTIONS = Symbol.for('reqray.nestjs.options');\n\nfunction nestVersion(): string | undefined {\n try {\n const manifest = createRequire(import.meta.url)('@nestjs/core/package.json') as {\n version?: unknown;\n };\n return typeof manifest.version === 'string' ? manifest.version : undefined;\n } catch {\n return undefined;\n }\n}\n\n/**\n * The middleware wildcard changed with the Express 5 router: Nest 11 wants\n * `{*splat}` where Nest 10 wanted `*`.\n */\nfunction allRoutes(): string {\n const version = nestVersion();\n const major = version ? Number.parseInt(version, 10) : 11;\n return major >= 11 ? '{*splat}' : '*';\n}\n\n/**\n * Global interceptor: records the exception on its way past, and does nothing\n * else with it.\n *\n * An observer rather than a filter. A catch-all filter registered by an\n * imported module is picked over the application's own, so the first version\n * of this — a filter deferring to Nest's default handling — replaced whatever\n * error responses the application had written with Nest's. An interceptor\n * never decides what the client is told.\n *\n * `HttpException` is Nest control flow (404, validation), not a crash — those\n * requests are recorded with their status anyway, like in every adapter. So\n * is an error thrown by a guard, which runs before any interceptor does.\n */\n@Injectable()\nexport class ReqrayErrorInterceptor implements NestInterceptor {\n intercept(context: ExecutionContext, next: CallHandler): Observable<unknown> {\n if (context.getType() !== 'http') return next.handle();\n\n return next.handle().pipe(\n tap({\n error: (exception: unknown) => {\n if (exception instanceof HttpException) return;\n try {\n const http = context.switchToHttp();\n // One of the two matches the platform; the other is a safe no-op.\n expressFailure(http.getResponse(), exception);\n fastifyFailure(http.getRequest(), exception);\n } catch {\n // Recording must never interfere with error handling itself.\n }\n },\n }),\n );\n }\n}\n\n/**\n * Reqray module for NestJS.\n *\n * @example\n * ```ts\n * @Module({\n * imports: [ReqrayModule.forRoot()],\n * })\n * export class AppModule {}\n * ```\n */\n@Module({})\nexport class ReqrayModule implements NestModule, OnModuleInit {\n static forRoot(options: ReqrayInit = {}): DynamicModule {\n return {\n module: ReqrayModule,\n providers: [\n { provide: REQRAY_OPTIONS, useValue: options },\n { provide: APP_INTERCEPTOR, useClass: ReqrayErrorInterceptor },\n ],\n };\n }\n\n /** The Express inspector, when the platform is Express. */\n #express: ReqrayExpress | null = null;\n\n readonly #adapterHost: HttpAdapterHost;\n readonly #options: ReqrayInit;\n\n constructor(\n @Inject(HttpAdapterHost) adapterHost: HttpAdapterHost,\n @Inject(REQRAY_OPTIONS) options: ReqrayInit,\n ) {\n this.#adapterHost = adapterHost;\n this.#options = options;\n }\n\n /** Runtime of the platform adapter — for tests and manual access. */\n get reqray(): Reqray | null {\n if (this.#express) return this.#express.runtime;\n if (this.#platform() === 'fastify') {\n const instance = this.#adapterHost.httpAdapter?.getInstance<FastifyInstance>();\n return (instance as FastifyInstance & { reqray?: Reqray })?.reqray ?? null;\n }\n return null;\n }\n\n #platform(): string {\n return this.#adapterHost.httpAdapter?.getType() ?? 'express';\n }\n\n configure(consumer: MiddlewareConsumer): void {\n if (this.#platform() !== 'express') return;\n\n reportInstrumentation({\n name: 'nestjs',\n version: nestVersion(),\n captures: 'requests (express platform)',\n ok: true,\n });\n\n this.#express = expressReqray(this.#options);\n consumer.apply(this.#express.middleware).forRoutes(allRoutes());\n }\n\n async onModuleInit(): Promise<void> {\n if (this.#platform() !== 'fastify') return;\n\n reportInstrumentation({\n name: 'nestjs',\n version: nestVersion(),\n captures: 'requests (fastify platform)',\n ok: true,\n });\n\n const instance = this.#adapterHost.httpAdapter.getInstance<FastifyInstance>();\n await instance.register(fastifyReqray, this.#options);\n }\n}\n","// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () => \n typeof document === \"undefined\" \n ? new URL(`file:${__filename}`).href \n : (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT') \n ?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,cAAa,YAAY,YAA6B;AAC5E,UAAM,SAAS,SAAS,eAAAC,QAAe,mBAAK,SAAQ;AAAA,EACtD;AACF;AAtDE;AAES;AACA;AAfJ;AAmCL,cAAS,WAAW;AAClB,SAAO,mBAAK,cAAa,aAAa,QAAQ,KAAK;AACrD;AArCW,eAAN;AAAA,MADN,sBAAO,CAAC,CAAC;AAAA,EAmBL,6CAAO,2BAAe;AAAA,EACtB,6CAAO,cAAc;AAAA,GAnBb;","names":["import_core","expressFailure","fastifyFailure","expressReqray","fastifyReqray"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { NestInterceptor, ExecutionContext, CallHandler, NestModule, OnModuleInit, DynamicModule, MiddlewareConsumer } from '@nestjs/common';
|
|
2
|
+
import { HttpAdapterHost } from '@nestjs/core';
|
|
3
|
+
import { ReqrayInit, Reqray } from '@reqray/core';
|
|
4
|
+
import { Observable } from 'rxjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* `@reqray/nestjs` — NestJS adapter.
|
|
8
|
+
*
|
|
9
|
+
* One module in `imports`, nothing else. Underneath it defers to the existing
|
|
10
|
+
* platform adapters: on Express (the Nest default) the `@reqray/express`
|
|
11
|
+
* middleware goes through the middleware consumer, on Fastify the
|
|
12
|
+
* `@reqray/fastify` plugin is registered on the underlying instance.
|
|
13
|
+
*
|
|
14
|
+
* The one thing neither platform adapter can see under Nest is the exception:
|
|
15
|
+
* Nest intercepts it before Express error middleware or Fastify's `onError`
|
|
16
|
+
* ever run. A global interceptor stamps it onto the request/response as it
|
|
17
|
+
* passes, and passes it on: handling stays with whichever filter the
|
|
18
|
+
* application has, or with Nest's default.
|
|
19
|
+
*
|
|
20
|
+
* Injection note: everything is an explicit `@Inject(token)` — this package
|
|
21
|
+
* is built without decorator metadata emission.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/** Token the Reqray options travel under inside the Nest container. */
|
|
25
|
+
declare const REQRAY_OPTIONS: unique symbol;
|
|
26
|
+
/**
|
|
27
|
+
* Global interceptor: records the exception on its way past, and does nothing
|
|
28
|
+
* else with it.
|
|
29
|
+
*
|
|
30
|
+
* An observer rather than a filter. A catch-all filter registered by an
|
|
31
|
+
* imported module is picked over the application's own, so the first version
|
|
32
|
+
* of this — a filter deferring to Nest's default handling — replaced whatever
|
|
33
|
+
* error responses the application had written with Nest's. An interceptor
|
|
34
|
+
* never decides what the client is told.
|
|
35
|
+
*
|
|
36
|
+
* `HttpException` is Nest control flow (404, validation), not a crash — those
|
|
37
|
+
* requests are recorded with their status anyway, like in every adapter. So
|
|
38
|
+
* is an error thrown by a guard, which runs before any interceptor does.
|
|
39
|
+
*/
|
|
40
|
+
declare class ReqrayErrorInterceptor implements NestInterceptor {
|
|
41
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Reqray module for NestJS.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* @Module({
|
|
49
|
+
* imports: [ReqrayModule.forRoot()],
|
|
50
|
+
* })
|
|
51
|
+
* export class AppModule {}
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
declare class ReqrayModule implements NestModule, OnModuleInit {
|
|
55
|
+
#private;
|
|
56
|
+
static forRoot(options?: ReqrayInit): DynamicModule;
|
|
57
|
+
constructor(adapterHost: HttpAdapterHost, options: ReqrayInit);
|
|
58
|
+
/** Runtime of the platform adapter — for tests and manual access. */
|
|
59
|
+
get reqray(): Reqray | null;
|
|
60
|
+
configure(consumer: MiddlewareConsumer): void;
|
|
61
|
+
onModuleInit(): Promise<void>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { REQRAY_OPTIONS, ReqrayErrorInterceptor, ReqrayModule };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { NestInterceptor, ExecutionContext, CallHandler, NestModule, OnModuleInit, DynamicModule, MiddlewareConsumer } from '@nestjs/common';
|
|
2
|
+
import { HttpAdapterHost } from '@nestjs/core';
|
|
3
|
+
import { ReqrayInit, Reqray } from '@reqray/core';
|
|
4
|
+
import { Observable } from 'rxjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* `@reqray/nestjs` — NestJS adapter.
|
|
8
|
+
*
|
|
9
|
+
* One module in `imports`, nothing else. Underneath it defers to the existing
|
|
10
|
+
* platform adapters: on Express (the Nest default) the `@reqray/express`
|
|
11
|
+
* middleware goes through the middleware consumer, on Fastify the
|
|
12
|
+
* `@reqray/fastify` plugin is registered on the underlying instance.
|
|
13
|
+
*
|
|
14
|
+
* The one thing neither platform adapter can see under Nest is the exception:
|
|
15
|
+
* Nest intercepts it before Express error middleware or Fastify's `onError`
|
|
16
|
+
* ever run. A global interceptor stamps it onto the request/response as it
|
|
17
|
+
* passes, and passes it on: handling stays with whichever filter the
|
|
18
|
+
* application has, or with Nest's default.
|
|
19
|
+
*
|
|
20
|
+
* Injection note: everything is an explicit `@Inject(token)` — this package
|
|
21
|
+
* is built without decorator metadata emission.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/** Token the Reqray options travel under inside the Nest container. */
|
|
25
|
+
declare const REQRAY_OPTIONS: unique symbol;
|
|
26
|
+
/**
|
|
27
|
+
* Global interceptor: records the exception on its way past, and does nothing
|
|
28
|
+
* else with it.
|
|
29
|
+
*
|
|
30
|
+
* An observer rather than a filter. A catch-all filter registered by an
|
|
31
|
+
* imported module is picked over the application's own, so the first version
|
|
32
|
+
* of this — a filter deferring to Nest's default handling — replaced whatever
|
|
33
|
+
* error responses the application had written with Nest's. An interceptor
|
|
34
|
+
* never decides what the client is told.
|
|
35
|
+
*
|
|
36
|
+
* `HttpException` is Nest control flow (404, validation), not a crash — those
|
|
37
|
+
* requests are recorded with their status anyway, like in every adapter. So
|
|
38
|
+
* is an error thrown by a guard, which runs before any interceptor does.
|
|
39
|
+
*/
|
|
40
|
+
declare class ReqrayErrorInterceptor implements NestInterceptor {
|
|
41
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Reqray module for NestJS.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* @Module({
|
|
49
|
+
* imports: [ReqrayModule.forRoot()],
|
|
50
|
+
* })
|
|
51
|
+
* export class AppModule {}
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
declare class ReqrayModule implements NestModule, OnModuleInit {
|
|
55
|
+
#private;
|
|
56
|
+
static forRoot(options?: ReqrayInit): DynamicModule;
|
|
57
|
+
constructor(adapterHost: HttpAdapterHost, options: ReqrayInit);
|
|
58
|
+
/** Runtime of the platform adapter — for tests and manual access. */
|
|
59
|
+
get reqray(): Reqray | null;
|
|
60
|
+
configure(consumer: MiddlewareConsumer): void;
|
|
61
|
+
onModuleInit(): Promise<void>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { REQRAY_OPTIONS, ReqrayErrorInterceptor, ReqrayModule };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __typeError = (msg) => {
|
|
4
|
+
throw TypeError(msg);
|
|
5
|
+
};
|
|
6
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
7
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
8
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
9
|
+
if (decorator = decorators[i])
|
|
10
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
11
|
+
if (kind && result) __defProp(target, key, result);
|
|
12
|
+
return result;
|
|
13
|
+
};
|
|
14
|
+
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
15
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
16
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
17
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
18
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
19
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
20
|
+
|
|
21
|
+
// src/index.ts
|
|
22
|
+
import { createRequire } from "module";
|
|
23
|
+
import {
|
|
24
|
+
HttpException,
|
|
25
|
+
Inject,
|
|
26
|
+
Injectable,
|
|
27
|
+
Module
|
|
28
|
+
} from "@nestjs/common";
|
|
29
|
+
import { APP_INTERCEPTOR, HttpAdapterHost } from "@nestjs/core";
|
|
30
|
+
import { reportInstrumentation } from "@reqray/core";
|
|
31
|
+
import {
|
|
32
|
+
recordFailure as expressFailure,
|
|
33
|
+
reqray as expressReqray
|
|
34
|
+
} from "@reqray/express";
|
|
35
|
+
import { recordFailure as fastifyFailure, reqray as fastifyReqray } from "@reqray/fastify";
|
|
36
|
+
import { tap } from "rxjs";
|
|
37
|
+
var REQRAY_OPTIONS = /* @__PURE__ */ Symbol.for("reqray.nestjs.options");
|
|
38
|
+
function nestVersion() {
|
|
39
|
+
try {
|
|
40
|
+
const manifest = createRequire(import.meta.url)("@nestjs/core/package.json");
|
|
41
|
+
return typeof manifest.version === "string" ? manifest.version : void 0;
|
|
42
|
+
} catch {
|
|
43
|
+
return void 0;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function allRoutes() {
|
|
47
|
+
const version = nestVersion();
|
|
48
|
+
const major = version ? Number.parseInt(version, 10) : 11;
|
|
49
|
+
return major >= 11 ? "{*splat}" : "*";
|
|
50
|
+
}
|
|
51
|
+
var ReqrayErrorInterceptor = class {
|
|
52
|
+
intercept(context, next) {
|
|
53
|
+
if (context.getType() !== "http") return next.handle();
|
|
54
|
+
return next.handle().pipe(
|
|
55
|
+
tap({
|
|
56
|
+
error: (exception) => {
|
|
57
|
+
if (exception instanceof HttpException) return;
|
|
58
|
+
try {
|
|
59
|
+
const http = context.switchToHttp();
|
|
60
|
+
expressFailure(http.getResponse(), exception);
|
|
61
|
+
fastifyFailure(http.getRequest(), exception);
|
|
62
|
+
} catch {
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
ReqrayErrorInterceptor = __decorateClass([
|
|
70
|
+
Injectable()
|
|
71
|
+
], ReqrayErrorInterceptor);
|
|
72
|
+
var _express, _adapterHost, _options, _ReqrayModule_instances, platform_fn;
|
|
73
|
+
var ReqrayModule = class {
|
|
74
|
+
constructor(adapterHost, options) {
|
|
75
|
+
__privateAdd(this, _ReqrayModule_instances);
|
|
76
|
+
/** The Express inspector, when the platform is Express. */
|
|
77
|
+
__privateAdd(this, _express, null);
|
|
78
|
+
__privateAdd(this, _adapterHost);
|
|
79
|
+
__privateAdd(this, _options);
|
|
80
|
+
__privateSet(this, _adapterHost, adapterHost);
|
|
81
|
+
__privateSet(this, _options, options);
|
|
82
|
+
}
|
|
83
|
+
static forRoot(options = {}) {
|
|
84
|
+
return {
|
|
85
|
+
module: ReqrayModule,
|
|
86
|
+
providers: [
|
|
87
|
+
{ provide: REQRAY_OPTIONS, useValue: options },
|
|
88
|
+
{ provide: APP_INTERCEPTOR, useClass: ReqrayErrorInterceptor }
|
|
89
|
+
]
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/** Runtime of the platform adapter — for tests and manual access. */
|
|
93
|
+
get reqray() {
|
|
94
|
+
if (__privateGet(this, _express)) return __privateGet(this, _express).runtime;
|
|
95
|
+
if (__privateMethod(this, _ReqrayModule_instances, platform_fn).call(this) === "fastify") {
|
|
96
|
+
const instance = __privateGet(this, _adapterHost).httpAdapter?.getInstance();
|
|
97
|
+
return instance?.reqray ?? null;
|
|
98
|
+
}
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
configure(consumer) {
|
|
102
|
+
if (__privateMethod(this, _ReqrayModule_instances, platform_fn).call(this) !== "express") return;
|
|
103
|
+
reportInstrumentation({
|
|
104
|
+
name: "nestjs",
|
|
105
|
+
version: nestVersion(),
|
|
106
|
+
captures: "requests (express platform)",
|
|
107
|
+
ok: true
|
|
108
|
+
});
|
|
109
|
+
__privateSet(this, _express, expressReqray(__privateGet(this, _options)));
|
|
110
|
+
consumer.apply(__privateGet(this, _express).middleware).forRoutes(allRoutes());
|
|
111
|
+
}
|
|
112
|
+
async onModuleInit() {
|
|
113
|
+
if (__privateMethod(this, _ReqrayModule_instances, platform_fn).call(this) !== "fastify") return;
|
|
114
|
+
reportInstrumentation({
|
|
115
|
+
name: "nestjs",
|
|
116
|
+
version: nestVersion(),
|
|
117
|
+
captures: "requests (fastify platform)",
|
|
118
|
+
ok: true
|
|
119
|
+
});
|
|
120
|
+
const instance = __privateGet(this, _adapterHost).httpAdapter.getInstance();
|
|
121
|
+
await instance.register(fastifyReqray, __privateGet(this, _options));
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
_express = new WeakMap();
|
|
125
|
+
_adapterHost = new WeakMap();
|
|
126
|
+
_options = new WeakMap();
|
|
127
|
+
_ReqrayModule_instances = new WeakSet();
|
|
128
|
+
platform_fn = function() {
|
|
129
|
+
return __privateGet(this, _adapterHost).httpAdapter?.getType() ?? "express";
|
|
130
|
+
};
|
|
131
|
+
ReqrayModule = __decorateClass([
|
|
132
|
+
Module({}),
|
|
133
|
+
__decorateParam(0, Inject(HttpAdapterHost)),
|
|
134
|
+
__decorateParam(1, Inject(REQRAY_OPTIONS))
|
|
135
|
+
], ReqrayModule);
|
|
136
|
+
export {
|
|
137
|
+
REQRAY_OPTIONS,
|
|
138
|
+
ReqrayErrorInterceptor,
|
|
139
|
+
ReqrayModule
|
|
140
|
+
};
|
|
141
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * `@reqray/nestjs` — NestJS adapter.\n *\n * One module in `imports`, nothing else. Underneath it defers to the existing\n * platform adapters: on Express (the Nest default) the `@reqray/express`\n * middleware goes through the middleware consumer, on Fastify the\n * `@reqray/fastify` plugin is registered on the underlying instance.\n *\n * The one thing neither platform adapter can see under Nest is the exception:\n * Nest intercepts it before Express error middleware or Fastify's `onError`\n * ever run. A global interceptor stamps it onto the request/response as it\n * passes, and passes it on: handling stays with whichever filter the\n * application has, or with Nest's default.\n *\n * Injection note: everything is an explicit `@Inject(token)` — this package\n * is built without decorator metadata emission.\n */\n\nimport { createRequire } from 'node:module';\nimport {\n type CallHandler,\n type DynamicModule,\n type ExecutionContext,\n HttpException,\n Inject,\n Injectable,\n type MiddlewareConsumer,\n Module,\n type NestInterceptor,\n type NestModule,\n type OnModuleInit,\n} from '@nestjs/common';\nimport { APP_INTERCEPTOR, HttpAdapterHost } from '@nestjs/core';\nimport type { Reqray, ReqrayInit } from '@reqray/core';\nimport { reportInstrumentation } from '@reqray/core';\nimport {\n recordFailure as expressFailure,\n reqray as expressReqray,\n type ReqrayExpress,\n} from '@reqray/express';\nimport { recordFailure as fastifyFailure, reqray as fastifyReqray } from '@reqray/fastify';\nimport type { FastifyInstance } from 'fastify';\nimport { type Observable, tap } from 'rxjs';\n\n/** Token the Reqray options travel under inside the Nest container. */\nexport const REQRAY_OPTIONS = Symbol.for('reqray.nestjs.options');\n\nfunction nestVersion(): string | undefined {\n try {\n const manifest = createRequire(import.meta.url)('@nestjs/core/package.json') as {\n version?: unknown;\n };\n return typeof manifest.version === 'string' ? manifest.version : undefined;\n } catch {\n return undefined;\n }\n}\n\n/**\n * The middleware wildcard changed with the Express 5 router: Nest 11 wants\n * `{*splat}` where Nest 10 wanted `*`.\n */\nfunction allRoutes(): string {\n const version = nestVersion();\n const major = version ? Number.parseInt(version, 10) : 11;\n return major >= 11 ? '{*splat}' : '*';\n}\n\n/**\n * Global interceptor: records the exception on its way past, and does nothing\n * else with it.\n *\n * An observer rather than a filter. A catch-all filter registered by an\n * imported module is picked over the application's own, so the first version\n * of this — a filter deferring to Nest's default handling — replaced whatever\n * error responses the application had written with Nest's. An interceptor\n * never decides what the client is told.\n *\n * `HttpException` is Nest control flow (404, validation), not a crash — those\n * requests are recorded with their status anyway, like in every adapter. So\n * is an error thrown by a guard, which runs before any interceptor does.\n */\n@Injectable()\nexport class ReqrayErrorInterceptor implements NestInterceptor {\n intercept(context: ExecutionContext, next: CallHandler): Observable<unknown> {\n if (context.getType() !== 'http') return next.handle();\n\n return next.handle().pipe(\n tap({\n error: (exception: unknown) => {\n if (exception instanceof HttpException) return;\n try {\n const http = context.switchToHttp();\n // One of the two matches the platform; the other is a safe no-op.\n expressFailure(http.getResponse(), exception);\n fastifyFailure(http.getRequest(), exception);\n } catch {\n // Recording must never interfere with error handling itself.\n }\n },\n }),\n );\n }\n}\n\n/**\n * Reqray module for NestJS.\n *\n * @example\n * ```ts\n * @Module({\n * imports: [ReqrayModule.forRoot()],\n * })\n * export class AppModule {}\n * ```\n */\n@Module({})\nexport class ReqrayModule implements NestModule, OnModuleInit {\n static forRoot(options: ReqrayInit = {}): DynamicModule {\n return {\n module: ReqrayModule,\n providers: [\n { provide: REQRAY_OPTIONS, useValue: options },\n { provide: APP_INTERCEPTOR, useClass: ReqrayErrorInterceptor },\n ],\n };\n }\n\n /** The Express inspector, when the platform is Express. */\n #express: ReqrayExpress | null = null;\n\n readonly #adapterHost: HttpAdapterHost;\n readonly #options: ReqrayInit;\n\n constructor(\n @Inject(HttpAdapterHost) adapterHost: HttpAdapterHost,\n @Inject(REQRAY_OPTIONS) options: ReqrayInit,\n ) {\n this.#adapterHost = adapterHost;\n this.#options = options;\n }\n\n /** Runtime of the platform adapter — for tests and manual access. */\n get reqray(): Reqray | null {\n if (this.#express) return this.#express.runtime;\n if (this.#platform() === 'fastify') {\n const instance = this.#adapterHost.httpAdapter?.getInstance<FastifyInstance>();\n return (instance as FastifyInstance & { reqray?: Reqray })?.reqray ?? null;\n }\n return null;\n }\n\n #platform(): string {\n return this.#adapterHost.httpAdapter?.getType() ?? 'express';\n }\n\n configure(consumer: MiddlewareConsumer): void {\n if (this.#platform() !== 'express') return;\n\n reportInstrumentation({\n name: 'nestjs',\n version: nestVersion(),\n captures: 'requests (express platform)',\n ok: true,\n });\n\n this.#express = expressReqray(this.#options);\n consumer.apply(this.#express.middleware).forRoutes(allRoutes());\n }\n\n async onModuleInit(): Promise<void> {\n if (this.#platform() !== 'fastify') return;\n\n reportInstrumentation({\n name: 'nestjs',\n version: nestVersion(),\n captures: 'requests (fastify platform)',\n ok: true,\n });\n\n const instance = this.#adapterHost.httpAdapter.getInstance<FastifyInstance>();\n await instance.register(fastifyReqray, this.#options);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAkBA,SAAS,qBAAqB;AAC9B;AAAA,EAIE;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,OAIK;AACP,SAAS,iBAAiB,uBAAuB;AAEjD,SAAS,6BAA6B;AACtC;AAAA,EACE,iBAAiB;AAAA,EACjB,UAAU;AAAA,OAEL;AACP,SAAS,iBAAiB,gBAAgB,UAAU,qBAAqB;AAEzE,SAA0B,WAAW;AAG9B,IAAM,iBAAiB,uBAAO,IAAI,uBAAuB;AAEhE,SAAS,cAAkC;AACzC,MAAI;AACF,UAAM,WAAW,cAAc,YAAY,GAAG,EAAE,2BAA2B;AAG3E,WAAO,OAAO,SAAS,YAAY,WAAW,SAAS,UAAU;AAAA,EACnE,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAMA,SAAS,YAAoB;AAC3B,QAAM,UAAU,YAAY;AAC5B,QAAM,QAAQ,UAAU,OAAO,SAAS,SAAS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AM;AAAA,MACN,SAAS,YAAY;AAAA,MACrB,UAAU;AAAA,MACV,IAAI;AAAA,IACN,CAAC;AAED,uBAAK,UAAW,cAAc,mBAAK,SAAQ;AAC3C,aAAS,MAAM,mBAAK,UAAS,UAAU,EAAE,UAAU,UAAU,CAAC;AAAA,EAChE;AAAA,EAEA,MAAM,eAA8B;AAClC,QAAI,sBAAK,sCAAL,eAAqB,UAAW;AAEpC,0BAAsB;AAAA,MACpB,MAAM;AAAA,MACN,SAAS,YAAY;AAAA,MACrB,UAAU;AAAA,MACV,IAAI;AAAA,IACN,CAAC;AAED,UAAM,WAAW,mBAAK,cAAa,YAAY,YAA6B;AAC5E,UAAM,SAAS,SAAS,eAAe,mBAAK,SAAQ;AAAA,EACtD;AACF;AAtDE;AAES;AACA;AAfJ;AAmCL,cAAS,WAAW;AAClB,SAAO,mBAAK,cAAa,aAAa,QAAQ,KAAK;AACrD;AArCW,eAAN;AAAA,EADN,OAAO,CAAC,CAAC;AAAA,EAmBL,0BAAO,eAAe;AAAA,EACtB,0BAAO,cAAc;AAAA,GAnBb;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,78 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reqray/nestjs",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Reqray for NestJS: one module in imports, and every request is a waterfall with its SQL, cache and outgoing calls. Finds N+1 down to the line.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"nodejs",
|
|
8
|
+
"debugging",
|
|
9
|
+
"profiling",
|
|
10
|
+
"n+1",
|
|
11
|
+
"sql",
|
|
12
|
+
"observability",
|
|
13
|
+
"devtools",
|
|
14
|
+
"fastify",
|
|
15
|
+
"express",
|
|
16
|
+
"nestjs"
|
|
17
|
+
],
|
|
18
|
+
"homepage": "https://github.com/reqray/reqray#readme",
|
|
19
|
+
"bugs": "https://github.com/reqray/reqray/issues",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/reqray/reqray.git",
|
|
23
|
+
"directory": "packages/nestjs"
|
|
24
|
+
},
|
|
25
|
+
"type": "module",
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=20"
|
|
28
|
+
},
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"import": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"default": "./dist/index.js"
|
|
34
|
+
},
|
|
35
|
+
"require": {
|
|
36
|
+
"types": "./dist/index.d.cts",
|
|
37
|
+
"default": "./dist/index.cjs"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"main": "./dist/index.cjs",
|
|
42
|
+
"module": "./dist/index.js",
|
|
43
|
+
"types": "./dist/index.d.ts",
|
|
44
|
+
"files": [
|
|
45
|
+
"dist"
|
|
46
|
+
],
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@reqray/core": "^0.1.1",
|
|
52
|
+
"@reqray/fastify": "^0.1.1",
|
|
53
|
+
"@reqray/express": "^0.1.1"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"@nestjs/common": "^10 || ^11",
|
|
57
|
+
"@nestjs/core": "^10 || ^11",
|
|
58
|
+
"rxjs": "^7"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@nestjs/common": "^11.2.1",
|
|
62
|
+
"@nestjs/core": "^11.2.1",
|
|
63
|
+
"@nestjs/platform-express": "^11.2.1",
|
|
64
|
+
"@nestjs/platform-fastify": "^11.2.1",
|
|
65
|
+
"@nestjs/testing": "^11.2.1",
|
|
66
|
+
"@types/node": "^26.2.0",
|
|
67
|
+
"fastify": "^5.7.4",
|
|
68
|
+
"reflect-metadata": "^0.2.2",
|
|
69
|
+
"rxjs": "^7.8.2",
|
|
70
|
+
"tsup": "^8.5.1",
|
|
71
|
+
"typescript": "^6.0.3",
|
|
72
|
+
"@reqray/store-memory": "^0.1.1"
|
|
73
|
+
},
|
|
74
|
+
"scripts": {
|
|
75
|
+
"build": "tsup",
|
|
76
|
+
"typecheck": "tsc --noEmit"
|
|
77
|
+
}
|
|
6
78
|
}
|