nest-graph-inspector 0.2.9 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -11
- package/package.json +1 -1
- package/src/{drivers/file-output.driver.d.ts → adapters/file-output.adapter.d.ts} +17 -2
- package/src/adapters/file-output.adapter.js +284 -0
- package/src/adapters/file-output.adapter.js.map +1 -0
- package/src/adapters/http-output.adapter.d.ts +25 -0
- package/src/adapters/http-output.adapter.js +94 -0
- package/src/adapters/http-output.adapter.js.map +1 -0
- package/src/adapters/http-serve.adapter.d.ts +58 -0
- package/src/adapters/http-serve.adapter.js +298 -0
- package/src/adapters/http-serve.adapter.js.map +1 -0
- package/src/{drivers/json-output.driver.d.ts → adapters/json-output.adapter.d.ts} +1 -1
- package/src/{drivers/json-output.driver.js → adapters/json-output.adapter.js} +6 -6
- package/src/adapters/json-output.adapter.js.map +1 -0
- package/src/adapters/proxy.adapter.d.ts +21 -0
- package/src/adapters/proxy.adapter.js +153 -0
- package/src/adapters/proxy.adapter.js.map +1 -0
- package/src/adapters/viewer-output.adapter.d.ts +22 -0
- package/src/adapters/viewer-output.adapter.js +82 -0
- package/src/adapters/viewer-output.adapter.js.map +1 -0
- package/src/nest-graph-inspector.module.js +22 -9
- package/src/nest-graph-inspector.module.js.map +1 -1
- package/src/nest-graph-inspector.setup.d.ts +19 -5
- package/src/nest-graph-inspector.setup.js +217 -9
- package/src/nest-graph-inspector.setup.js.map +1 -1
- package/src/nest-graph-inspector.type.d.ts +10 -0
- package/src/ports/proxy.gateway.d.ts +15 -0
- package/src/ports/proxy.gateway.js +3 -0
- package/src/ports/proxy.gateway.js.map +1 -0
- package/src/types/graph-output.type.d.ts +27 -0
- package/src/drivers/file-output.driver.js +0 -187
- package/src/drivers/file-output.driver.js.map +0 -1
- package/src/drivers/http-output.driver.d.ts +0 -19
- package/src/drivers/http-output.driver.js +0 -62
- package/src/drivers/http-output.driver.js.map +0 -1
- package/src/drivers/json-output.driver.js.map +0 -1
- package/src/drivers/viewer-output.driver.d.ts +0 -16
- package/src/drivers/viewer-output.driver.js +0 -42
- package/src/drivers/viewer-output.driver.js.map +0 -1
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.HttpServeAdapter = void 0;
|
|
13
|
+
const node_http_1 = __importDefault(require("node:http"));
|
|
14
|
+
const node_url_1 = require("node:url");
|
|
15
|
+
const common_1 = require("@nestjs/common");
|
|
16
|
+
let HttpServeAdapter = class HttpServeAdapter {
|
|
17
|
+
servers = new Map();
|
|
18
|
+
register(options, routes) {
|
|
19
|
+
const originUrl = this.normalizeOrigin(options);
|
|
20
|
+
const state = this.serverState(originUrl);
|
|
21
|
+
for (const route of routes) {
|
|
22
|
+
const key = this.routeKey(route.type, this.normalizePath(route.path));
|
|
23
|
+
const routeGroup = state.routes.get(key) ?? [];
|
|
24
|
+
routeGroup.push(route);
|
|
25
|
+
state.routes.set(key, routeGroup);
|
|
26
|
+
}
|
|
27
|
+
return { origin: state.originUrl.origin };
|
|
28
|
+
}
|
|
29
|
+
get(path, callback, options = {}) {
|
|
30
|
+
return { type: 'GET', path, callback, ...options };
|
|
31
|
+
}
|
|
32
|
+
post(path, callback, options = {}) {
|
|
33
|
+
return { type: 'POST', path, callback, ...options };
|
|
34
|
+
}
|
|
35
|
+
all(path, rawCallback, options = {}) {
|
|
36
|
+
return { type: '*', path, rawCallback, ...options };
|
|
37
|
+
}
|
|
38
|
+
async serve() {
|
|
39
|
+
await Promise.all([...this.servers.values()].map((state) => this.serveState(state)));
|
|
40
|
+
}
|
|
41
|
+
close(origin) {
|
|
42
|
+
if (!origin) {
|
|
43
|
+
for (const state of this.servers.values()) {
|
|
44
|
+
state.server?.close();
|
|
45
|
+
}
|
|
46
|
+
this.servers.clear();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const originUrl = this.normalizeOrigin({ origin });
|
|
50
|
+
const state = this.servers.get(originUrl.origin);
|
|
51
|
+
state?.server?.close();
|
|
52
|
+
this.servers.delete(originUrl.origin);
|
|
53
|
+
}
|
|
54
|
+
onModuleDestroy() {
|
|
55
|
+
this.close();
|
|
56
|
+
}
|
|
57
|
+
serverState(originUrl) {
|
|
58
|
+
const existing = this.servers.get(originUrl.origin);
|
|
59
|
+
if (existing) {
|
|
60
|
+
return existing;
|
|
61
|
+
}
|
|
62
|
+
const state = {
|
|
63
|
+
originUrl,
|
|
64
|
+
routes: new Map(),
|
|
65
|
+
};
|
|
66
|
+
this.servers.set(originUrl.origin, state);
|
|
67
|
+
return state;
|
|
68
|
+
}
|
|
69
|
+
serveState(state) {
|
|
70
|
+
if (state.listenPromise) {
|
|
71
|
+
return state.listenPromise;
|
|
72
|
+
}
|
|
73
|
+
state.server = node_http_1.default.createServer((req, res) => {
|
|
74
|
+
void this.handleRequest(state.originUrl, state.routes, req, res);
|
|
75
|
+
});
|
|
76
|
+
state.listenPromise = this.listen(state);
|
|
77
|
+
return state.listenPromise;
|
|
78
|
+
}
|
|
79
|
+
listen(state) {
|
|
80
|
+
return new Promise((resolve, reject) => {
|
|
81
|
+
const onError = (error) => {
|
|
82
|
+
reject(error);
|
|
83
|
+
};
|
|
84
|
+
state.server?.once('error', onError);
|
|
85
|
+
state.server?.listen(Number(state.originUrl.port || 80), state.originUrl.hostname, () => {
|
|
86
|
+
state.server?.off('error', onError);
|
|
87
|
+
this.resolveDynamicPort(state);
|
|
88
|
+
resolve();
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
async handleRequest(originUrl, routes, req, res) {
|
|
93
|
+
this.setCorsHeaders(res);
|
|
94
|
+
const route = this.route(originUrl, routes, req);
|
|
95
|
+
if (!route) {
|
|
96
|
+
this.sendText(res, 404, 'Not Found');
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
if (route.rawCallback) {
|
|
101
|
+
await route.rawCallback(req, res);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const result = await route.callback?.({
|
|
105
|
+
request: req,
|
|
106
|
+
headers: req.headers,
|
|
107
|
+
});
|
|
108
|
+
this.sendResult(res, route, result);
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
if (!res.headersSent) {
|
|
112
|
+
this.sendText(res, 500, err instanceof Error ? err.message : 'Error');
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
res.destroy(err instanceof Error ? err : undefined);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
route(originUrl, routes, req) {
|
|
119
|
+
const method = req.method ?? 'GET';
|
|
120
|
+
const path = new node_url_1.URL(req.url ?? '/', originUrl).pathname;
|
|
121
|
+
const candidates = [
|
|
122
|
+
...(routes.get(this.routeKey(method, path)) ?? []),
|
|
123
|
+
...this.wildcardPathCandidates(routes, method, path),
|
|
124
|
+
...(routes.get(this.routeKey(method, '*')) ?? []),
|
|
125
|
+
...(routes.get(this.routeKey('*', path)) ?? []),
|
|
126
|
+
...this.wildcardPathCandidates(routes, '*', path),
|
|
127
|
+
...(routes.get(this.routeKey('*', '*')) ?? []),
|
|
128
|
+
];
|
|
129
|
+
return candidates.find((route) => this.requestHeadersMatch(route.requestHeaders, req));
|
|
130
|
+
}
|
|
131
|
+
wildcardPathCandidates(routes, method, path) {
|
|
132
|
+
const methodPrefix = `${method.toUpperCase()} `;
|
|
133
|
+
const candidates = [];
|
|
134
|
+
for (const [key, routeGroup] of routes) {
|
|
135
|
+
if (!key.startsWith(methodPrefix)) {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
const routePath = key.slice(methodPrefix.length);
|
|
139
|
+
if (!routePath.endsWith('/*')) {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
const prefix = routePath.slice(0, -1);
|
|
143
|
+
if (path === prefix.slice(0, -1) || path.startsWith(prefix)) {
|
|
144
|
+
candidates.push(...routeGroup);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return candidates;
|
|
148
|
+
}
|
|
149
|
+
routeKey(method, path) {
|
|
150
|
+
return `${method.toUpperCase()} ${path}`;
|
|
151
|
+
}
|
|
152
|
+
sendResult(res, route, result) {
|
|
153
|
+
if (res.writableEnded) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const response = this.normalizeResponse(route, result);
|
|
157
|
+
const { body, contentType } = this.serializeBody(response.body, response.contentType);
|
|
158
|
+
res.writeHead(response.statusCode ?? 200, {
|
|
159
|
+
...response.headers,
|
|
160
|
+
'content-type': contentType,
|
|
161
|
+
'content-length': Buffer.byteLength(body),
|
|
162
|
+
});
|
|
163
|
+
res.end(body);
|
|
164
|
+
}
|
|
165
|
+
normalizeResponse(route, result) {
|
|
166
|
+
const defaults = {
|
|
167
|
+
statusCode: route.statusCode,
|
|
168
|
+
contentType: route.contentType ?? this.contentTypeHeader(route.responseHeaders),
|
|
169
|
+
headers: route.responseHeaders,
|
|
170
|
+
};
|
|
171
|
+
if (this.isHttpServeResponse(result)) {
|
|
172
|
+
return {
|
|
173
|
+
...defaults,
|
|
174
|
+
...result,
|
|
175
|
+
contentType: result.contentType ??
|
|
176
|
+
this.contentTypeHeader(result.headers) ??
|
|
177
|
+
defaults.contentType,
|
|
178
|
+
headers: {
|
|
179
|
+
...defaults.headers,
|
|
180
|
+
...result.headers,
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
return { ...defaults, body: result };
|
|
185
|
+
}
|
|
186
|
+
isHttpServeResponse(result) {
|
|
187
|
+
if (!result || typeof result !== 'object' || Buffer.isBuffer(result)) {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
return ('body' in result ||
|
|
191
|
+
'headers' in result ||
|
|
192
|
+
'contentType' in result ||
|
|
193
|
+
'statusCode' in result);
|
|
194
|
+
}
|
|
195
|
+
serializeBody(body, contentType) {
|
|
196
|
+
if (body === undefined || body === null) {
|
|
197
|
+
return {
|
|
198
|
+
body: '',
|
|
199
|
+
contentType: contentType ?? 'text/plain; charset=utf-8',
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
if (Buffer.isBuffer(body)) {
|
|
203
|
+
return {
|
|
204
|
+
body: body.toString(),
|
|
205
|
+
contentType: contentType ?? 'application/octet-stream',
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
if (typeof body === 'string') {
|
|
209
|
+
return {
|
|
210
|
+
body,
|
|
211
|
+
contentType: contentType ?? 'text/plain; charset=utf-8',
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
return {
|
|
215
|
+
body: JSON.stringify(body),
|
|
216
|
+
contentType: contentType ?? 'application/json; charset=utf-8',
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
sendText(res, statusCode, body) {
|
|
220
|
+
res.writeHead(statusCode, {
|
|
221
|
+
'content-type': 'text/plain; charset=utf-8',
|
|
222
|
+
'content-length': Buffer.byteLength(body),
|
|
223
|
+
});
|
|
224
|
+
res.end(body);
|
|
225
|
+
}
|
|
226
|
+
requestHeadersMatch(expectedHeaders, req) {
|
|
227
|
+
if (!expectedHeaders) {
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
230
|
+
return Object.entries(expectedHeaders).every(([name, expectedValue]) => {
|
|
231
|
+
const actualValue = req.headers[name.toLowerCase()];
|
|
232
|
+
if (Array.isArray(expectedValue)) {
|
|
233
|
+
return expectedValue.join(',') === this.headerValue(actualValue);
|
|
234
|
+
}
|
|
235
|
+
return String(expectedValue) === this.headerValue(actualValue);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
headerValue(value) {
|
|
239
|
+
if (Array.isArray(value)) {
|
|
240
|
+
return value.join(',');
|
|
241
|
+
}
|
|
242
|
+
return value ?? '';
|
|
243
|
+
}
|
|
244
|
+
contentTypeHeader(headers) {
|
|
245
|
+
const value = headers?.['content-type'] ?? headers?.['Content-Type'];
|
|
246
|
+
if (Array.isArray(value)) {
|
|
247
|
+
return value[0];
|
|
248
|
+
}
|
|
249
|
+
return typeof value === 'number' ? String(value) : value;
|
|
250
|
+
}
|
|
251
|
+
setCorsHeaders(res) {
|
|
252
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
253
|
+
res.setHeader('Access-Control-Allow-Headers', '*');
|
|
254
|
+
}
|
|
255
|
+
resolveDynamicPort(state) {
|
|
256
|
+
if (state.originUrl.port !== '0') {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
const originalOrigin = state.originUrl.origin;
|
|
260
|
+
const address = state.server?.address();
|
|
261
|
+
if (address && typeof address !== 'string') {
|
|
262
|
+
state.originUrl.port = String(address.port);
|
|
263
|
+
this.servers.delete(originalOrigin);
|
|
264
|
+
this.servers.set(state.originUrl.origin, state);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
normalizeOrigin(options) {
|
|
268
|
+
const origin = options.origin ?? 'http://localhost';
|
|
269
|
+
const normalizedOrigin = origin.startsWith('http://') || origin.startsWith('https://')
|
|
270
|
+
? origin
|
|
271
|
+
: `http://${origin}`;
|
|
272
|
+
const originUrl = new node_url_1.URL(normalizedOrigin);
|
|
273
|
+
if (originUrl.protocol !== 'http:') {
|
|
274
|
+
throw new Error(`Graph inspector native HTTP server only supports http origins: ${origin}`);
|
|
275
|
+
}
|
|
276
|
+
if (options.host) {
|
|
277
|
+
originUrl.hostname = options.host;
|
|
278
|
+
}
|
|
279
|
+
if (options.port !== undefined) {
|
|
280
|
+
originUrl.port = String(options.port);
|
|
281
|
+
}
|
|
282
|
+
if (!originUrl.port) {
|
|
283
|
+
originUrl.port = '80';
|
|
284
|
+
}
|
|
285
|
+
return originUrl;
|
|
286
|
+
}
|
|
287
|
+
normalizePath(path) {
|
|
288
|
+
if (path === '*') {
|
|
289
|
+
return path;
|
|
290
|
+
}
|
|
291
|
+
return path.startsWith('/') ? path : `/${path}`;
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
exports.HttpServeAdapter = HttpServeAdapter;
|
|
295
|
+
exports.HttpServeAdapter = HttpServeAdapter = __decorate([
|
|
296
|
+
(0, common_1.Injectable)()
|
|
297
|
+
], HttpServeAdapter);
|
|
298
|
+
//# sourceMappingURL=http-serve.adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-serve.adapter.js","sourceRoot":"","sources":["../../../../../libs/nest-graph-inspector/src/adapters/http-serve.adapter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0DAA6B;AAC7B,uCAA+B;AAC/B,2CAA6D;AA0CtD,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IACV,OAAO,GAAG,IAAI,GAAG,EAA2B,CAAC;IAE9D,QAAQ,CACN,OAAyB,EACzB,MAAwB;QAExB,MAAM,SAAS,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QAChD,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;QAE1C,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,aAAa,C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AQ,GAAG,OAAO,CAAC,IAAI,CAAC;QACpC,CAAC;QAED,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC/B,SAAS,CAAC,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACxC,CAAC;QAED,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;YACpB,SAAS,CAAC,IAAI,GAAG,IAAI,CAAC;QACxB,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAEO,aAAa,CAAC,IAAY;QAChC,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;YACjB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC;IAClD,CAAC;CACF,CAAA;AApZY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;GACA,gBAAgB,CAoZ5B"}
|
|
@@ -4,7 +4,7 @@ import type { GraphOutput } from '../types/graph-output.type';
|
|
|
4
4
|
type JsonOutputConfig = Extract<NestGraphInspectorOutput, {
|
|
5
5
|
type: 'json';
|
|
6
6
|
}>;
|
|
7
|
-
export declare class
|
|
7
|
+
export declare class JsonOutputAdapter implements OutputAdapter<JsonOutputConfig> {
|
|
8
8
|
execute(graphOutput: GraphOutput, config: JsonOutputConfig): Promise<{
|
|
9
9
|
message: string;
|
|
10
10
|
}>;
|
|
@@ -6,11 +6,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
9
|
+
exports.JsonOutputAdapter = void 0;
|
|
10
10
|
const promises_1 = require("node:fs/promises");
|
|
11
11
|
const common_1 = require("@nestjs/common");
|
|
12
12
|
const node_path_1 = require("node:path");
|
|
13
|
-
let
|
|
13
|
+
let JsonOutputAdapter = class JsonOutputAdapter {
|
|
14
14
|
async execute(graphOutput, config) {
|
|
15
15
|
const filePath = (0, node_path_1.join)(process.cwd(), config.path);
|
|
16
16
|
const json = JSON.stringify(graphOutput, null, 2);
|
|
@@ -21,8 +21,8 @@ let JsonOutputDriver = class JsonOutputDriver {
|
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
|
-
exports.
|
|
25
|
-
exports.
|
|
24
|
+
exports.JsonOutputAdapter = JsonOutputAdapter;
|
|
25
|
+
exports.JsonOutputAdapter = JsonOutputAdapter = __decorate([
|
|
26
26
|
(0, common_1.Injectable)()
|
|
27
|
-
],
|
|
28
|
-
//# sourceMappingURL=json-output.
|
|
27
|
+
], JsonOutputAdapter);
|
|
28
|
+
//# sourceMappingURL=json-output.adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-output.adapter.js","sourceRoot":"","sources":["../../../../../libs/nest-graph-inspector/src/adapters/json-output.adapter.ts"],"names":[],"mappings":";;;;;;;;;AAAA,+CAAoD;AACpD,2CAA4C;AAC5C,yCAA0C;AAQnC,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAC5B,KAAK,CAAC,OAAO,CACX,WAAwB,EACxB,MAAwB;QAExB,MAAM,QAAQ,GAAG,IAAA,gBAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;QAClD,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QAElD,MAAM,IAAA,gBAAK,EAAC,IAAA,mBAAO,EAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACpD,MAAM,IAAA,oBAAS,EAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAEhC,OAAO;YACL,OAAO,EAAE,8CAA8C,QAAQ,EAAE;SAClE,CAAC;IACJ,CAAC;CACF,CAAA;AAfY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;GACA,iBAAiB,CAe7B"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { HttpServeAdapter } from './http-serve.adapter';
|
|
2
|
+
import type { ProxyGateway, ProxyGatewayOptions } from '../ports/proxy.gateway';
|
|
3
|
+
export declare class ProxyAdapter implements ProxyGateway {
|
|
4
|
+
private readonly httpServeAdapters;
|
|
5
|
+
serve(options: ProxyGatewayOptions, internalOptions?: {
|
|
6
|
+
httpAdapter?: HttpServeAdapter;
|
|
7
|
+
pathPrefix?: string;
|
|
8
|
+
}): Promise<void>;
|
|
9
|
+
close(): void;
|
|
10
|
+
private forwardRequest;
|
|
11
|
+
private targetUrl;
|
|
12
|
+
private forwardResponse;
|
|
13
|
+
private createProxyRequestOptions;
|
|
14
|
+
private handleProxyError;
|
|
15
|
+
private getRequestModule;
|
|
16
|
+
private getCorsHeaders;
|
|
17
|
+
private applyCors;
|
|
18
|
+
private isAllowedOrigin;
|
|
19
|
+
private normalizeUrl;
|
|
20
|
+
private normalizePath;
|
|
21
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ProxyAdapter = void 0;
|
|
13
|
+
const node_http_1 = __importDefault(require("node:http"));
|
|
14
|
+
const node_https_1 = __importDefault(require("node:https"));
|
|
15
|
+
const node_url_1 = require("node:url");
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const http_serve_adapter_1 = require("./http-serve.adapter");
|
|
18
|
+
let ProxyAdapter = class ProxyAdapter {
|
|
19
|
+
httpServeAdapters = [];
|
|
20
|
+
async serve(options, internalOptions = {}) {
|
|
21
|
+
const fromUrl = this.normalizeUrl(options.from);
|
|
22
|
+
const toUrl = this.normalizeUrl(options.to);
|
|
23
|
+
const cors = options.cors === false ? undefined : options.cors;
|
|
24
|
+
const isReuseHttpAdapter = !!internalOptions.httpAdapter;
|
|
25
|
+
const httpServeAdapter = internalOptions.httpAdapter ?? new http_serve_adapter_1.HttpServeAdapter();
|
|
26
|
+
const pathPrefix = internalOptions.pathPrefix
|
|
27
|
+
? this.normalizePath(internalOptions.pathPrefix)
|
|
28
|
+
: undefined;
|
|
29
|
+
httpServeAdapter.register({ origin: fromUrl.origin }, (pathPrefix ? [pathPrefix, `${pathPrefix}/*`] : ['*']).map((path) => ({
|
|
30
|
+
type: '*',
|
|
31
|
+
path,
|
|
32
|
+
rawCallback: (clientReq, clientRes) => {
|
|
33
|
+
this.applyCors(cors, clientReq, clientRes);
|
|
34
|
+
this.forwardRequest(toUrl, cors, clientReq, clientRes, pathPrefix);
|
|
35
|
+
},
|
|
36
|
+
})));
|
|
37
|
+
if (isReuseHttpAdapter) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
await httpServeAdapter.serve();
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
httpServeAdapter.close();
|
|
45
|
+
throw err;
|
|
46
|
+
}
|
|
47
|
+
this.httpServeAdapters.push(httpServeAdapter);
|
|
48
|
+
}
|
|
49
|
+
close() {
|
|
50
|
+
for (const httpServeAdapter of this.httpServeAdapters) {
|
|
51
|
+
httpServeAdapter.close();
|
|
52
|
+
}
|
|
53
|
+
this.httpServeAdapters.length = 0;
|
|
54
|
+
}
|
|
55
|
+
forwardRequest(toUrl, cors, clientReq, clientRes, pathPrefix) {
|
|
56
|
+
const targetUrl = this.targetUrl(clientReq.url ?? '/', toUrl, pathPrefix);
|
|
57
|
+
const requestModule = this.getRequestModule(targetUrl);
|
|
58
|
+
const proxyReq = requestModule.request(targetUrl, this.createProxyRequestOptions(clientReq, targetUrl), (proxyRes) => this.forwardResponse(cors, proxyRes, clientReq, clientRes));
|
|
59
|
+
proxyReq.on('error', (error) => {
|
|
60
|
+
this.handleProxyError(error, clientRes);
|
|
61
|
+
});
|
|
62
|
+
clientReq.pipe(proxyReq);
|
|
63
|
+
}
|
|
64
|
+
targetUrl(requestUrl, toUrl, pathPrefix) {
|
|
65
|
+
const targetUrl = new node_url_1.URL(requestUrl, toUrl);
|
|
66
|
+
if (!pathPrefix) {
|
|
67
|
+
return targetUrl;
|
|
68
|
+
}
|
|
69
|
+
if (targetUrl.pathname === pathPrefix ||
|
|
70
|
+
targetUrl.pathname.startsWith(`${pathPrefix}/`)) {
|
|
71
|
+
targetUrl.pathname = targetUrl.pathname.slice(pathPrefix.length) || '/';
|
|
72
|
+
}
|
|
73
|
+
return targetUrl;
|
|
74
|
+
}
|
|
75
|
+
forwardResponse(cors, proxyRes, clientReq, clientRes) {
|
|
76
|
+
clientRes.writeHead(proxyRes.statusCode ?? 500, {
|
|
77
|
+
...proxyRes.headers,
|
|
78
|
+
...this.getCorsHeaders(cors, clientReq),
|
|
79
|
+
});
|
|
80
|
+
proxyRes.pipe(clientRes);
|
|
81
|
+
}
|
|
82
|
+
createProxyRequestOptions(clientReq, targetUrl) {
|
|
83
|
+
return {
|
|
84
|
+
method: clientReq.method,
|
|
85
|
+
headers: {
|
|
86
|
+
...clientReq.headers,
|
|
87
|
+
host: targetUrl.host,
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
handleProxyError(error, res) {
|
|
92
|
+
if (res.headersSent) {
|
|
93
|
+
res.destroy(error);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
res.statusCode = 502;
|
|
97
|
+
res.end(`Proxy error: ${error.message}`);
|
|
98
|
+
}
|
|
99
|
+
getRequestModule(targetUrl) {
|
|
100
|
+
return targetUrl.protocol === 'https:' ? node_https_1.default : node_http_1.default;
|
|
101
|
+
}
|
|
102
|
+
getCorsHeaders(cors, req) {
|
|
103
|
+
if (!cors)
|
|
104
|
+
return {};
|
|
105
|
+
const origin = req.headers.origin;
|
|
106
|
+
if (!this.isAllowedOrigin(cors, origin)) {
|
|
107
|
+
return {};
|
|
108
|
+
}
|
|
109
|
+
const allowHeaders = Array.isArray(cors.allowHeaders)
|
|
110
|
+
? cors.allowHeaders.join(',')
|
|
111
|
+
: cors.allowHeaders;
|
|
112
|
+
return {
|
|
113
|
+
'access-control-allow-origin': origin,
|
|
114
|
+
'access-control-allow-methods': (cors.methods ?? ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS']).join(','),
|
|
115
|
+
'access-control-allow-headers': allowHeaders ?? req.headers['access-control-request-headers'] ?? '*',
|
|
116
|
+
'access-control-allow-credentials': String(cors.credentials ?? true),
|
|
117
|
+
vary: 'Origin',
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
applyCors(cors, req, res) {
|
|
121
|
+
const headers = this.getCorsHeaders(cors, req);
|
|
122
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
123
|
+
if (value !== undefined) {
|
|
124
|
+
res.setHeader(key, value);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
isAllowedOrigin(cors, origin) {
|
|
129
|
+
if (typeof origin !== 'string')
|
|
130
|
+
return false;
|
|
131
|
+
return cors.origins.some((allowedOrigin) => {
|
|
132
|
+
if (typeof allowedOrigin === 'string') {
|
|
133
|
+
return allowedOrigin === origin;
|
|
134
|
+
}
|
|
135
|
+
return allowedOrigin.test(origin);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
normalizeUrl(value) {
|
|
139
|
+
if (!value.startsWith('http://') && !value.startsWith('https://')) {
|
|
140
|
+
return new node_url_1.URL(`http://${value}`);
|
|
141
|
+
}
|
|
142
|
+
return new node_url_1.URL(value);
|
|
143
|
+
}
|
|
144
|
+
normalizePath(path) {
|
|
145
|
+
const normalizedPath = path.startsWith('/') ? path : `/${path}`;
|
|
146
|
+
return normalizedPath.replace(/\/$/, '');
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
exports.ProxyAdapter = ProxyAdapter;
|
|
150
|
+
exports.ProxyAdapter = ProxyAdapter = __decorate([
|
|
151
|
+
(0, common_1.Injectable)()
|
|
152
|
+
], ProxyAdapter);
|
|
153
|
+
//# sourceMappingURL=proxy.adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy.adapter.js","sourceRoot":"","sources":["../../../../../libs/nest-graph-inspector/src/adapters/proxy.adapter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0DAA6B;AAC7B,4DAA+B;AAC/B,uCAA+B;AAC/B,2CAA4C;AAC5C,6DAAwD;AAQjD,IAAM,YAAY,GAAlB,MAAM,YAAY;IACN,iBAAiB,GAAuB,EAAE,CAAC;IAE5D,KAAK,CAAC,KAAK,CACT,OAA4B,EAC5B,kBAGI,EAAE;QAEN,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAChD,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC5C,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,C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AAO,aAAa,KAAK,MAAM,CAAC;YAClC,CAAC;YAED,OAAO,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACpC,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,YAAY,CAAC,KAAa;QAChC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YAClE,OAAO,IAAI,cAAG,CAAC,UAAU,KAAK,EAAE,CAAC,CAAC;QACpC,CAAC;QAED,OAAO,IAAI,cAAG,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC;IAEO,aAAa,CAAC,IAAY;QAChC,MAAM,cAAc,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC;QAEhE,OAAO,cAAc,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC3C,CAAC;CACF,CAAA;AAxMY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,mBAAU,GAAE;GACA,YAAY,CAwMxB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { OutputAdapter } from '../ports/output.adapter';
|
|
2
|
+
import { NestGraphInspectorOutput } from '../nest-graph-inspector.type';
|
|
3
|
+
import type { GraphOutput } from '../types/graph-output.type';
|
|
4
|
+
import { HttpOutputAdapter } from './http-output.adapter';
|
|
5
|
+
import { ProxyAdapter } from './proxy.adapter';
|
|
6
|
+
import { HttpServeAdapter } from './http-serve.adapter';
|
|
7
|
+
type ViewerOutputConfig = Extract<NestGraphInspectorOutput, {
|
|
8
|
+
type: 'viewer';
|
|
9
|
+
}>;
|
|
10
|
+
export declare class ViewerOutputAdapter implements OutputAdapter<ViewerOutputConfig> {
|
|
11
|
+
private readonly httpOutputAdapter;
|
|
12
|
+
private readonly proxyAdapter;
|
|
13
|
+
private readonly httpServeAdapter;
|
|
14
|
+
private readonly viewerBaseUrl;
|
|
15
|
+
constructor(httpOutputAdapter: HttpOutputAdapter, proxyAdapter: ProxyAdapter, httpServeAdapter: HttpServeAdapter);
|
|
16
|
+
execute(graphOutput: GraphOutput, config: ViewerOutputConfig): Promise<{
|
|
17
|
+
message: string;
|
|
18
|
+
}>;
|
|
19
|
+
private httpOrigin;
|
|
20
|
+
private ollamaProxyOptions;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ViewerOutputAdapter = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const http_output_adapter_1 = require("./http-output.adapter");
|
|
15
|
+
const proxy_adapter_1 = require("./proxy.adapter");
|
|
16
|
+
const http_serve_adapter_1 = require("./http-serve.adapter");
|
|
17
|
+
let ViewerOutputAdapter = class ViewerOutputAdapter {
|
|
18
|
+
httpOutputAdapter;
|
|
19
|
+
proxyAdapter;
|
|
20
|
+
httpServeAdapter;
|
|
21
|
+
viewerBaseUrl = process.env.____DEV_VIEWER_BASE_URL ||
|
|
22
|
+
'https://albasyir.github.io/nest-graph-inspector';
|
|
23
|
+
constructor(httpOutputAdapter, proxyAdapter, httpServeAdapter) {
|
|
24
|
+
this.httpOutputAdapter = httpOutputAdapter;
|
|
25
|
+
this.proxyAdapter = proxyAdapter;
|
|
26
|
+
this.httpServeAdapter = httpServeAdapter;
|
|
27
|
+
}
|
|
28
|
+
async execute(graphOutput, config) {
|
|
29
|
+
const path = this.httpOutputAdapter.normalizePath(config.path ?? '/__graph-inspector');
|
|
30
|
+
const ollama = this.ollamaProxyOptions(config);
|
|
31
|
+
await this.httpOutputAdapter.execute(graphOutput, {
|
|
32
|
+
type: 'http',
|
|
33
|
+
origin: config.origin,
|
|
34
|
+
host: config.host,
|
|
35
|
+
port: config.port,
|
|
36
|
+
path,
|
|
37
|
+
httpAdapter: this.httpServeAdapter,
|
|
38
|
+
});
|
|
39
|
+
await this.proxyAdapter.serve({
|
|
40
|
+
from: this.httpOrigin(config),
|
|
41
|
+
to: ollama.origin,
|
|
42
|
+
cors: false,
|
|
43
|
+
}, {
|
|
44
|
+
httpAdapter: this.httpServeAdapter,
|
|
45
|
+
pathPrefix: ollama.path,
|
|
46
|
+
});
|
|
47
|
+
try {
|
|
48
|
+
await this.httpServeAdapter.serve();
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
this.httpServeAdapter.close();
|
|
52
|
+
throw err;
|
|
53
|
+
}
|
|
54
|
+
const graphEndpoint = new URL(path, this.httpOrigin(config)).toString();
|
|
55
|
+
const base64Origin = Buffer.from(graphEndpoint).toString('base64url');
|
|
56
|
+
const viewerLink = `${this.viewerBaseUrl}/view/${base64Origin}`;
|
|
57
|
+
return {
|
|
58
|
+
message: `Graph Viewer is available at ${viewerLink}`,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
httpOrigin(config) {
|
|
62
|
+
const { host, port } = http_output_adapter_1.HttpOutputAdapter.defaultConfig;
|
|
63
|
+
return (config.origin ??
|
|
64
|
+
`http://${config.host ?? host}:${config.port ?? port}`);
|
|
65
|
+
}
|
|
66
|
+
ollamaProxyOptions(config) {
|
|
67
|
+
const origin = config.ollama?.origin;
|
|
68
|
+
const path = config.ollama?.path;
|
|
69
|
+
if (!origin || !path) {
|
|
70
|
+
throw new Error('Viewer output requires Ollama proxy origin and path');
|
|
71
|
+
}
|
|
72
|
+
return { origin, path };
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
exports.ViewerOutputAdapter = ViewerOutputAdapter;
|
|
76
|
+
exports.ViewerOutputAdapter = ViewerOutputAdapter = __decorate([
|
|
77
|
+
(0, common_1.Injectable)(),
|
|
78
|
+
__metadata("design:paramtypes", [http_output_adapter_1.HttpOutputAdapter,
|
|
79
|
+
proxy_adapter_1.ProxyAdapter,
|
|
80
|
+
http_serve_adapter_1.HttpServeAdapter])
|
|
81
|
+
], ViewerOutputAdapter);
|
|
82
|
+
//# sourceMappingURL=viewer-output.adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"viewer-output.adapter.js","sourceRoot":"","sources":["../../../../../libs/nest-graph-inspector/src/adapters/viewer-output.adapter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAI5C,+DAA0D;AAC1D,mDAA+C;AAC/C,6DAAwD;AAKjD,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAMX;IACA;IACA;IAPF,aAAa,GAC5B,OAAO,CAAC,GAAG,CAAC,uBAAuB;QACnC,iDAAiD,CAAC;IAEpD,YACmB,iBAAoC,EACpC,YAA0B,EAC1B,gBAAkC;QAFlC,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,iBAAY,GAAZ,YAAY,CAAc;QAC1B,qBAAgB,GAAhB,gBAAgB,CAAkB;IAClD,CAAC;IAEJ,KAAK,CAAC,OAAO,CACX,WAAwB,EACxB,MAA0B;QAE1B,MAAM,IAAI,GAAG,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAC/C,MAAM,CAAC,IAAI,IAAI,oB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