@mahameru/diatrema 0.0.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 +1 -0
- package/container-error.cjs +45 -0
- package/container-error.cjs.map +1 -0
- package/container-error.d.cts +7 -0
- package/container-error.d.ts +7 -0
- package/container-error.js +22 -0
- package/container-error.js.map +1 -0
- package/container.cjs +322 -0
- package/container.cjs.map +1 -0
- package/container.d.cts +62 -0
- package/container.d.ts +62 -0
- package/container.js +289 -0
- package/container.js.map +1 -0
- package/diatrema.cjs +130 -0
- package/diatrema.cjs.map +1 -0
- package/diatrema.d.cts +73 -0
- package/diatrema.d.ts +71 -0
- package/diatrema.js +107 -0
- package/diatrema.js.map +1 -0
- package/event-emitter.cjs +68 -0
- package/event-emitter.cjs.map +1 -0
- package/event-emitter.d.cts +11 -0
- package/event-emitter.d.ts +11 -0
- package/event-emitter.js +45 -0
- package/event-emitter.js.map +1 -0
- package/helpers.cjs +93 -0
- package/helpers.cjs.map +1 -0
- package/helpers.d.cts +22 -0
- package/helpers.d.ts +22 -0
- package/helpers.js +67 -0
- package/helpers.js.map +1 -0
- package/http-server-error.cjs +44 -0
- package/http-server-error.cjs.map +1 -0
- package/http-server-error.d.cts +7 -0
- package/http-server-error.d.ts +7 -0
- package/http-server-error.js +21 -0
- package/http-server-error.js.map +1 -0
- package/http-server.cjs +382 -0
- package/http-server.cjs.map +1 -0
- package/http-server.d.cts +81 -0
- package/http-server.d.ts +81 -0
- package/http-server.js +359 -0
- package/http-server.js.map +1 -0
- package/index.cjs +66 -0
- package/index.cjs.map +1 -0
- package/index.d.cts +19 -0
- package/index.d.ts +19 -0
- package/index.js +19 -0
- package/index.js.map +1 -0
- package/logger.cjs +52 -0
- package/logger.cjs.map +1 -0
- package/logger.d.cts +9 -0
- package/logger.d.ts +9 -0
- package/logger.js +29 -0
- package/logger.js.map +1 -0
- package/mahameru-error.cjs +42 -0
- package/mahameru-error.cjs.map +1 -0
- package/mahameru-error.d.cts +5 -0
- package/mahameru-error.d.ts +5 -0
- package/mahameru-error.js +19 -0
- package/mahameru-error.js.map +1 -0
- package/mahameru-request.cjs +79 -0
- package/mahameru-request.cjs.map +1 -0
- package/mahameru-request.d.cts +3 -0
- package/mahameru-request.d.ts +3 -0
- package/mahameru-request.js +56 -0
- package/mahameru-request.js.map +1 -0
- package/mahameru-response.cjs +71 -0
- package/mahameru-response.cjs.map +1 -0
- package/mahameru-response.d.cts +17 -0
- package/mahameru-response.d.ts +17 -0
- package/mahameru-response.js +48 -0
- package/mahameru-response.js.map +1 -0
- package/mahameru-server-error.cjs +54 -0
- package/mahameru-server-error.cjs.map +1 -0
- package/mahameru-server-error.d.cts +19 -0
- package/mahameru-server-error.d.ts +19 -0
- package/mahameru-server-error.js +31 -0
- package/mahameru-server-error.js.map +1 -0
- package/module-error.cjs +46 -0
- package/module-error.cjs.map +1 -0
- package/module-error.d.cts +12 -0
- package/module-error.d.ts +12 -0
- package/module-error.js +23 -0
- package/module-error.js.map +1 -0
- package/package.json +40 -0
- package/route.cjs +128 -0
- package/route.cjs.map +1 -0
- package/route.d.cts +46 -0
- package/route.d.ts +46 -0
- package/route.js +105 -0
- package/route.js.map +1 -0
- package/scripts/preinstall.js +9 -0
- package/types-BRwWYiUN.d.ts +108 -0
- package/types-CipcRmc9.d.cts +108 -0
- package/types.cjs +40 -0
- package/types.cjs.map +1 -0
- package/types.d.cts +3 -0
- package/types.d.ts +3 -0
- package/types.js +16 -0
- package/types.js.map +1 -0
package/http-server.js
ADDED
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { createServer, IncomingMessage, Server, ServerResponse } from "node:http";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { readFile } from "node:fs/promises";
|
|
6
|
+
import { exists } from "./helpers.js";
|
|
7
|
+
class HttpServer {
|
|
8
|
+
static {
|
|
9
|
+
__name(this, "HttpServer");
|
|
10
|
+
}
|
|
11
|
+
#options;
|
|
12
|
+
defaultOptions = {
|
|
13
|
+
host: "127.0.0.1",
|
|
14
|
+
port: 3e3,
|
|
15
|
+
dev: false,
|
|
16
|
+
keepAliveTimeout: 6e4,
|
|
17
|
+
disableHttpSignature: false,
|
|
18
|
+
httpServerSignature: "MahameruJS",
|
|
19
|
+
httpServerMessage: "Indonesia Bisa!",
|
|
20
|
+
allowedOrigins: void 0,
|
|
21
|
+
allowedIps: void 0,
|
|
22
|
+
allowedHosts: void 0,
|
|
23
|
+
trailingSlash: true,
|
|
24
|
+
rootPath: process.cwd(),
|
|
25
|
+
get faviconFilePath() {
|
|
26
|
+
return join(this.rootPath, "node_modules", "mahameru", "favicon.ico");
|
|
27
|
+
},
|
|
28
|
+
suportedHTTPMethods: ["DELETE", "GET", "OPTIONS", "PATCH", "POST", "PUT"]
|
|
29
|
+
};
|
|
30
|
+
httpServer;
|
|
31
|
+
isShuttingDown = false;
|
|
32
|
+
dependencies;
|
|
33
|
+
constructor(arg1, arg2) {
|
|
34
|
+
if (typeof arg2 === "undefined") {
|
|
35
|
+
this.dependencies = arg1;
|
|
36
|
+
this.#options = this.defaultOptions;
|
|
37
|
+
} else {
|
|
38
|
+
this.#options = {
|
|
39
|
+
...this.defaultOptions,
|
|
40
|
+
...arg1
|
|
41
|
+
};
|
|
42
|
+
this.dependencies = arg2;
|
|
43
|
+
}
|
|
44
|
+
this.httpServer = this.create();
|
|
45
|
+
this.httpServer.on("error", (error) => {
|
|
46
|
+
if (error instanceof Error && "code" in error && error.code === "EADDRINUSE") {
|
|
47
|
+
const newError = error;
|
|
48
|
+
throw new this.dependencies.MahameruServerError(`Port ${newError.port} is already in use`, {
|
|
49
|
+
code: newError.code,
|
|
50
|
+
address: newError.address,
|
|
51
|
+
port: newError.port
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
throw error;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
listen() {
|
|
58
|
+
return new Promise((resolve) => {
|
|
59
|
+
this.httpServer.listen(this.#options.port, this.#options.host, () => {
|
|
60
|
+
const address = this.httpServer.address();
|
|
61
|
+
resolve({
|
|
62
|
+
port: address && typeof address !== "string" ? address.port : this.#options.port,
|
|
63
|
+
host: address && typeof address !== "string" ? address.address : this.#options.host
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
close() {
|
|
69
|
+
return new Promise((resolve, reject) => {
|
|
70
|
+
if (!this.httpServer.listening) {
|
|
71
|
+
resolve();
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
this.httpServer.close((error) => {
|
|
75
|
+
if (error) {
|
|
76
|
+
reject(error);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
resolve();
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
setIsShuttingDown(isShuttingDown) {
|
|
84
|
+
this.isShuttingDown = isShuttingDown;
|
|
85
|
+
}
|
|
86
|
+
get listening() {
|
|
87
|
+
return this.httpServer.listening;
|
|
88
|
+
}
|
|
89
|
+
get options() {
|
|
90
|
+
return this.#options;
|
|
91
|
+
}
|
|
92
|
+
setOptions(options) {
|
|
93
|
+
this.#options = {
|
|
94
|
+
...this.defaultOptions,
|
|
95
|
+
...options
|
|
96
|
+
};
|
|
97
|
+
if (options.rootPath) {
|
|
98
|
+
this.#options.rootPath = options.rootPath;
|
|
99
|
+
if (!options.faviconFilePath)
|
|
100
|
+
this.#options.faviconFilePath = join(this.#options.rootPath, "node_modules", "mahameru", "favicon.ico");
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
create() {
|
|
104
|
+
const httpServer = createServer(async (request, response) => await this.handleRequest(request, response));
|
|
105
|
+
httpServer.keepAliveTimeout = this.#options.keepAliveTimeout;
|
|
106
|
+
httpServer.headersTimeout = httpServer.keepAliveTimeout + 1e3;
|
|
107
|
+
return httpServer;
|
|
108
|
+
}
|
|
109
|
+
async handleRequest(request, response) {
|
|
110
|
+
const mahameruRequest = new this.dependencies.MahameruRequest(request);
|
|
111
|
+
const rawReqPath = mahameruRequest.url.split("?")[0] || "/";
|
|
112
|
+
const rawReqUrl = rawReqPath.replace(/\/+/g, "/");
|
|
113
|
+
const matchUrl = this.dependencies.route.normalizePathForMatching(rawReqUrl);
|
|
114
|
+
const method = mahameruRequest.method;
|
|
115
|
+
try {
|
|
116
|
+
if (this.isShuttingDown)
|
|
117
|
+
response.setHeader("Connection", "close");
|
|
118
|
+
if (typeof this.#options.allowedIps !== "undefined" && mahameruRequest.ipAddress) {
|
|
119
|
+
if (!this.#options.allowedIps.includes(mahameruRequest.ipAddress))
|
|
120
|
+
return this.sendResponse(response, new this.dependencies.MahameruResponse(JSON.stringify({ error: "Forbidden" }), { status: 403 }));
|
|
121
|
+
}
|
|
122
|
+
if (typeof this.#options.allowedHosts !== "undefined" && Array.isArray(this.#options.allowedHosts)) {
|
|
123
|
+
if (!this.#options.allowedHosts.includes(mahameruRequest.headers.host))
|
|
124
|
+
return this.sendResponse(response, new this.dependencies.MahameruResponse(JSON.stringify({ error: "Forbidden" }), { status: 403 }));
|
|
125
|
+
}
|
|
126
|
+
if (mahameruRequest.url === "/favicon.ico")
|
|
127
|
+
return await this.handleFaviconRequest(mahameruRequest, response);
|
|
128
|
+
if (mahameruRequest.headers.origin && this.#options.allowedOrigins && !this.#options.allowedOrigins.includes(mahameruRequest.headers.origin))
|
|
129
|
+
return this.sendResponse(response, new this.dependencies.MahameruResponse(JSON.stringify({ error: "Forbidden" }), { status: 403 }));
|
|
130
|
+
if (this.#options.trailingSlash === false && rawReqUrl.length > 1 && rawReqUrl.endsWith("/")) {
|
|
131
|
+
const cleanUrl = matchUrl;
|
|
132
|
+
const queryStr = mahameruRequest.url?.split("?")[1];
|
|
133
|
+
const redirectPath = cleanUrl + (queryStr ? `?${queryStr}` : "");
|
|
134
|
+
return this.sendResponse(response, new this.dependencies.MahameruResponse(JSON.stringify({ message: "Redirecting to non-trailing slash URL" }), { status: 301, headers: { Location: redirectPath } }));
|
|
135
|
+
}
|
|
136
|
+
if (rawReqPath !== rawReqUrl) {
|
|
137
|
+
const queryStr = mahameruRequest.url?.includes("?") ? "?" + mahameruRequest.url.split("?")[1] : "";
|
|
138
|
+
const redirectPath = rawReqUrl + queryStr;
|
|
139
|
+
return this.sendResponse(response, new this.dependencies.MahameruResponse(JSON.stringify({ message: "Redirecting to normalized URL" }), { status: 301, headers: { Location: redirectPath } }));
|
|
140
|
+
}
|
|
141
|
+
const { matchedRoute, matchResult, notFoundResponse } = await this.dependencies.route.resolveRoute(mahameruRequest);
|
|
142
|
+
const middlewareHandler = this.dependencies.container.middlewareHandler;
|
|
143
|
+
if (!matchedRoute || !matchResult) {
|
|
144
|
+
const routeHandler = /* @__PURE__ */ __name(async () => notFoundResponse, "routeHandler");
|
|
145
|
+
const rawResponse = middlewareHandler ? await middlewareHandler({
|
|
146
|
+
request: mahameruRequest,
|
|
147
|
+
container: this.dependencies.container.mahameruContainer,
|
|
148
|
+
method,
|
|
149
|
+
params: {},
|
|
150
|
+
path: rawReqUrl,
|
|
151
|
+
status: 404
|
|
152
|
+
}, false, routeHandler) : await routeHandler();
|
|
153
|
+
const mahameruResponse2 = this.normalizeMahameruResponse(rawResponse, "Middleware must return a MahameruResponse instance.");
|
|
154
|
+
return this.sendResponse(response, mahameruResponse2);
|
|
155
|
+
}
|
|
156
|
+
const handler = matchedRoute.routeHandlers[method];
|
|
157
|
+
if (!handler) {
|
|
158
|
+
response.writeHead(405);
|
|
159
|
+
return response.end(JSON.stringify({ error: `Method ${method} Not Allowed` }));
|
|
160
|
+
}
|
|
161
|
+
const params = {};
|
|
162
|
+
if (matchResult && matchedRoute.paramNames.length > 0)
|
|
163
|
+
matchedRoute.paramNames.forEach((name, index) => {
|
|
164
|
+
params[name] = matchResult[index + 1];
|
|
165
|
+
});
|
|
166
|
+
const mahameruResponse = middlewareHandler ? await this.runMiddlewarePipeline(
|
|
167
|
+
middlewareHandler,
|
|
168
|
+
{
|
|
169
|
+
request: mahameruRequest,
|
|
170
|
+
container: this.dependencies.container.mahameruContainer,
|
|
171
|
+
params,
|
|
172
|
+
path: rawReqUrl,
|
|
173
|
+
method,
|
|
174
|
+
status: 200
|
|
175
|
+
},
|
|
176
|
+
() => handler(mahameruRequest, this.dependencies.container.mahameruContainer, { params })
|
|
177
|
+
) : await handler(
|
|
178
|
+
mahameruRequest,
|
|
179
|
+
this.dependencies.container.mahameruContainer,
|
|
180
|
+
{ params }
|
|
181
|
+
);
|
|
182
|
+
return this.sendResponse(response, mahameruResponse);
|
|
183
|
+
} catch (error) {
|
|
184
|
+
console.error(error);
|
|
185
|
+
const errorResponse = await this.runErrorHandler(
|
|
186
|
+
error,
|
|
187
|
+
{
|
|
188
|
+
request: mahameruRequest,
|
|
189
|
+
container: this.dependencies.container.mahameruContainer,
|
|
190
|
+
path: rawReqUrl,
|
|
191
|
+
method,
|
|
192
|
+
params: {},
|
|
193
|
+
status: 200
|
|
194
|
+
}
|
|
195
|
+
);
|
|
196
|
+
return this.sendResponse(response, errorResponse);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
async handleFaviconRequest(request, response) {
|
|
200
|
+
let targetFaviconPath = void 0;
|
|
201
|
+
const customFaviconPath = join(this.#options.rootPath, "favicon.ico");
|
|
202
|
+
if (await exists(customFaviconPath)) {
|
|
203
|
+
targetFaviconPath = customFaviconPath;
|
|
204
|
+
} else if (this.#options.faviconFilePath && await exists(this.#options.faviconFilePath)) {
|
|
205
|
+
targetFaviconPath = this.#options.faviconFilePath;
|
|
206
|
+
}
|
|
207
|
+
if (targetFaviconPath === void 0) {
|
|
208
|
+
return this.sendResponse(
|
|
209
|
+
response,
|
|
210
|
+
new this.dependencies.MahameruResponse("Not Found", { status: 404, headers: { "Content-Type": "text/plain" } })
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
const favicon = await readFile(targetFaviconPath);
|
|
214
|
+
const middlewareHandler = this.dependencies.container.middlewareHandler;
|
|
215
|
+
if (middlewareHandler) {
|
|
216
|
+
const middlewareResponse = await middlewareHandler({
|
|
217
|
+
request,
|
|
218
|
+
container: this.dependencies.container.mahameruContainer,
|
|
219
|
+
method: request.method,
|
|
220
|
+
params: {},
|
|
221
|
+
path: request.path,
|
|
222
|
+
status: 200
|
|
223
|
+
}, false, async () => new this.dependencies.MahameruResponse(favicon, { status: 200 }));
|
|
224
|
+
const normalized = this.normalizeMahameruResponse(middlewareResponse, "Middleware error");
|
|
225
|
+
const headers = new Headers(normalized.headers);
|
|
226
|
+
if (normalized.status === 200) {
|
|
227
|
+
headers.set("Content-Type", "image/x-icon");
|
|
228
|
+
if (!headers.has("Cache-Control")) {
|
|
229
|
+
headers.set("Cache-Control", "public, max-age=31536000");
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return this.sendResponse(response, new this.dependencies.MahameruResponse(normalized.body, {
|
|
233
|
+
status: normalized.status,
|
|
234
|
+
headers
|
|
235
|
+
}));
|
|
236
|
+
}
|
|
237
|
+
const faviconResponse = new this.dependencies.MahameruResponse(favicon, {
|
|
238
|
+
status: 200,
|
|
239
|
+
headers: {
|
|
240
|
+
"Content-Type": "image/x-icon",
|
|
241
|
+
"Cache-Control": "public, max-age=31536000"
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
return this.sendResponse(response, faviconResponse);
|
|
245
|
+
}
|
|
246
|
+
sendResponse(response, mahameruResponse) {
|
|
247
|
+
if (!mahameruResponse)
|
|
248
|
+
mahameruResponse = new this.dependencies.MahameruResponse(void 0, { status: 204 });
|
|
249
|
+
mahameruResponse.headers.forEach((value, key) => {
|
|
250
|
+
response.setHeader(key, value);
|
|
251
|
+
});
|
|
252
|
+
if (!this.#options.disableHttpSignature) {
|
|
253
|
+
response.setHeader("X-Powered-By", this.#options.httpServerSignature);
|
|
254
|
+
response.setHeader("X-Message", this.#options.httpServerMessage);
|
|
255
|
+
}
|
|
256
|
+
response.writeHead(mahameruResponse.status);
|
|
257
|
+
let responseBody;
|
|
258
|
+
if (typeof mahameruResponse.body === "string" || mahameruResponse.body instanceof Uint8Array || Buffer.isBuffer(mahameruResponse.body) || mahameruResponse.body === void 0 || mahameruResponse.body === null) {
|
|
259
|
+
responseBody = mahameruResponse.body;
|
|
260
|
+
} else {
|
|
261
|
+
responseBody = JSON.stringify(mahameruResponse.body);
|
|
262
|
+
}
|
|
263
|
+
response.end(responseBody);
|
|
264
|
+
this.dependencies.logger.info(response.req.method, response.statusCode, response.req.url);
|
|
265
|
+
}
|
|
266
|
+
async runMiddlewarePipeline(middleware, context, handler) {
|
|
267
|
+
const isProtectedRoute = this.validateProtectedRoute(context.method, context.path);
|
|
268
|
+
const response = await middleware(context, isProtectedRoute, async () => {
|
|
269
|
+
const nextResponse = await handler();
|
|
270
|
+
return this.normalizeMahameruResponse(
|
|
271
|
+
nextResponse,
|
|
272
|
+
"Route handlers and next() must resolve to MahameruResponse."
|
|
273
|
+
);
|
|
274
|
+
});
|
|
275
|
+
return this.normalizeMahameruResponse(
|
|
276
|
+
response,
|
|
277
|
+
"Global middleware must return a MahameruResponse instance."
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
async runErrorHandler(error, context) {
|
|
281
|
+
const fallbackResponse = this.createInternalServerErrorResponse(error);
|
|
282
|
+
if (!this.dependencies.container.errorHandler)
|
|
283
|
+
return fallbackResponse;
|
|
284
|
+
try {
|
|
285
|
+
const handlerResponse = await this.dependencies.container.errorHandler(
|
|
286
|
+
{
|
|
287
|
+
...context,
|
|
288
|
+
error
|
|
289
|
+
},
|
|
290
|
+
async () => fallbackResponse
|
|
291
|
+
);
|
|
292
|
+
return this.normalizeMahameruResponse(
|
|
293
|
+
handlerResponse,
|
|
294
|
+
"Error handler must return a MahameruResponse instance."
|
|
295
|
+
);
|
|
296
|
+
} catch (handlerError) {
|
|
297
|
+
return fallbackResponse;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
createInternalServerErrorResponse(error) {
|
|
301
|
+
const serverError = error instanceof this.dependencies.HttpServerError ? error : new this.dependencies.HttpServerError(error instanceof Error ? error.message : void 0);
|
|
302
|
+
return this.dependencies.MahameruResponse.json(
|
|
303
|
+
{ error: serverError.message },
|
|
304
|
+
{ status: serverError.statusCode }
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
isMahameruResponseLike(value) {
|
|
308
|
+
if (!value || typeof value !== "object") {
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
if (!("status" in value) || typeof value.status !== "number") {
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
if (!("body" in value)) {
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
if (!("headers" in value) || value.headers === void 0) {
|
|
318
|
+
return true;
|
|
319
|
+
}
|
|
320
|
+
if (value.headers instanceof Headers) {
|
|
321
|
+
return true;
|
|
322
|
+
}
|
|
323
|
+
return typeof value.headers === "object" && value.headers !== null && !Array.isArray(value.headers);
|
|
324
|
+
}
|
|
325
|
+
normalizeMahameruResponse(value, errorMessage) {
|
|
326
|
+
if (value instanceof this.dependencies.MahameruResponse)
|
|
327
|
+
return value;
|
|
328
|
+
if (!this.isMahameruResponseLike(value))
|
|
329
|
+
throw new this.dependencies.HttpServerError(errorMessage);
|
|
330
|
+
const normalizedHeaders = value.headers instanceof Headers ? Object.fromEntries(value.headers.entries()) : value.headers;
|
|
331
|
+
return new this.dependencies.MahameruResponse(value.body, {
|
|
332
|
+
status: value.status,
|
|
333
|
+
headers: normalizedHeaders
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
matchRoutePattern(currentPath, routePattern) {
|
|
337
|
+
const regexPattern = routePattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\//g, "\\/").replace(/:[^/]+/g, "[^/]+");
|
|
338
|
+
const regex = new RegExp(`^${regexPattern}$`);
|
|
339
|
+
return regex.test(currentPath);
|
|
340
|
+
}
|
|
341
|
+
validateProtectedRoute(method, path) {
|
|
342
|
+
return this.dependencies.container.protectedRoutes.some((route) => {
|
|
343
|
+
if (typeof route === "string")
|
|
344
|
+
return this.matchRoutePattern(path, route);
|
|
345
|
+
const isPathMatch = this.matchRoutePattern(path, route.path);
|
|
346
|
+
const isMethodMatch = route.methods.includes(method);
|
|
347
|
+
return isPathMatch && isMethodMatch;
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
requestLogger(response) {
|
|
351
|
+
if (!this.#options.dev)
|
|
352
|
+
return;
|
|
353
|
+
this.dependencies.logger.info(`${response.req.method} ${response.statusCode} ${response.req.url}`);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
export {
|
|
357
|
+
HttpServer
|
|
358
|
+
};
|
|
359
|
+
//# sourceMappingURL=http-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/http-server.ts"],"sourcesContent":["import { createServer, IncomingMessage, Server, ServerResponse } from \"node:http\";\r\nimport { join } from \"node:path\";\r\nimport { readFile } from \"node:fs/promises\";\r\nimport { exists } from \"./helpers\";\r\nimport type { Route } from \"./route\";\r\nimport type { Container } from \"./container\";\r\nimport type { MahameruResponse } from \"./mahameru-response\";\r\nimport type { MahameruRequest } from \"./mahameru-request\";\r\nimport type { HTTPMethod, MahameruMiddleware, MahameruMiddlewareContext, MahameruNext, RequestParams } from \"./types\";\r\nimport type { HttpServerError } from \"./http-server-error\";\r\nimport type { Logger } from \"./logger\";\r\nimport type { MahameruServerError } from \"./mahameru-server-error\";\r\n\r\nexport type HttpServerDependencies = {\r\n route: Route;\r\n container: Container;\r\n logger: Logger;\r\n MahameruServerError: typeof MahameruServerError;\r\n HttpServerError: typeof HttpServerError;\r\n MahameruResponse: typeof MahameruResponse;\r\n MahameruRequest: typeof MahameruRequest;\r\n}\r\n\r\ntype DefaultHTTPResponse = ServerResponse<IncomingMessage> & {\r\n req: IncomingMessage;\r\n}\r\n\r\ntype HTTPServerInstance = Server<typeof IncomingMessage, typeof ServerResponse>\r\n\r\ninterface MahameruResponseLike {\r\n body: unknown;\r\n status: number;\r\n headers?: Headers | Record<string, string>;\r\n}\r\n\r\nexport type HttpServerOptions = {\r\n host: string;\r\n port: number;\r\n dev: boolean;\r\n keepAliveTimeout: number;\r\n disableHttpSignature: boolean;\r\n httpServerSignature: string;\r\n httpServerMessage: string;\r\n allowedOrigins?: string[];\r\n allowedIps?: string[];\r\n allowedHosts?: string[]\r\n trailingSlash: boolean;\r\n rootPath: string;\r\n faviconFilePath?: string;\r\n suportedHTTPMethods: HTTPMethod[]\r\n}\r\n\r\nexport class HttpServer {\r\n #options: HttpServerOptions;\r\n protected readonly defaultOptions: HttpServerOptions = {\r\n host: '127.0.0.1',\r\n port: 3000,\r\n dev: false,\r\n keepAliveTimeout: 60000,\r\n disableHttpSignature: false,\r\n httpServerSignature: 'MahameruJS',\r\n httpServerMessage: 'Indonesia Bisa!',\r\n allowedOrigins: undefined,\r\n allowedIps: undefined,\r\n allowedHosts: undefined,\r\n trailingSlash: true,\r\n rootPath: process.cwd(),\r\n get faviconFilePath(): string {\r\n return join(this.rootPath, 'node_modules', 'mahameru', 'favicon.ico');\r\n },\r\n suportedHTTPMethods: ['DELETE', 'GET', 'OPTIONS', 'PATCH', 'POST', 'PUT']\r\n }\r\n protected httpServer: HTTPServerInstance\r\n protected isShuttingDown = false\r\n protected dependencies: HttpServerDependencies;\r\n\r\n constructor(dependencies: HttpServerDependencies)\r\n constructor(options: Partial<HttpServerOptions>, dependencies: HttpServerDependencies)\r\n constructor(arg1: Partial<HttpServerOptions> | HttpServerDependencies, arg2?: HttpServerDependencies) {\r\n if (typeof arg2 === 'undefined') {\r\n this.dependencies = arg1 as HttpServerDependencies;\r\n this.#options = this.defaultOptions\r\n } else {\r\n this.#options = {\r\n ...this.defaultOptions,\r\n ...arg1 as Partial<HttpServerOptions>\r\n };\r\n this.dependencies = arg2;\r\n }\r\n\r\n this.httpServer = this.create();\r\n this.httpServer.on('error', (error: unknown) => {\r\n if (error instanceof Error && 'code' in error && error.code === 'EADDRINUSE') {\r\n const newError = error as any;\r\n\r\n throw new this.dependencies.MahameruServerError(`Port ${newError.port} is already in use`, {\r\n code: newError.code,\r\n address: newError.address,\r\n port: newError.port\r\n });\r\n }\r\n\r\n throw error;\r\n })\r\n }\r\n\r\n listen() {\r\n return new Promise<{ port: number; host: string }>((resolve) => {\r\n this.httpServer.listen(this.#options.port, this.#options.host, () => {\r\n const address = this.httpServer.address();\r\n\r\n resolve({\r\n port: address && typeof address !== \"string\" ? address.port : this.#options.port,\r\n host: address && typeof address !== \"string\" ? address.address : this.#options.host,\r\n });\r\n });\r\n });\r\n }\r\n\r\n close(): Promise<void> {\r\n return new Promise((resolve, reject) => {\r\n if (!this.httpServer.listening) {\r\n resolve();\r\n\r\n return;\r\n }\r\n\r\n this.httpServer.close((error) => {\r\n if (error) {\r\n reject(error);\r\n\r\n return;\r\n }\r\n\r\n resolve();\r\n });\r\n });\r\n }\r\n\r\n setIsShuttingDown(isShuttingDown: boolean) {\r\n this.isShuttingDown = isShuttingDown;\r\n }\r\n\r\n get listening(): boolean {\r\n return this.httpServer.listening\r\n }\r\n\r\n get options(): HttpServerOptions {\r\n return this.#options\r\n }\r\n\r\n public setOptions(options: Partial<HttpServerOptions>): void {\r\n this.#options = {\r\n ...this.defaultOptions,\r\n ...options\r\n }\r\n\r\n if (options.rootPath) {\r\n this.#options.rootPath = options.rootPath\r\n\r\n if (!options.faviconFilePath)\r\n this.#options.faviconFilePath = join(this.#options.rootPath, 'node_modules', 'mahameru', 'favicon.ico');\r\n }\r\n }\r\n\r\n protected create(): HTTPServerInstance {\r\n const httpServer = createServer(async (request, response) => await this.handleRequest(request, response));\r\n\r\n httpServer.keepAliveTimeout = this.#options.keepAliveTimeout;\r\n httpServer.headersTimeout = httpServer.keepAliveTimeout + 1000\r\n\r\n return httpServer;\r\n }\r\n\r\n protected async handleRequest(request: IncomingMessage, response: ServerResponse<IncomingMessage> & { req: IncomingMessage; }) {\r\n const mahameruRequest = new this.dependencies.MahameruRequest(request);\r\n const rawReqPath = mahameruRequest.url.split('?')[0] || '/';\r\n const rawReqUrl = rawReqPath.replace(/\\/+/g, '/');\r\n const matchUrl = this.dependencies.route.normalizePathForMatching(rawReqUrl);\r\n const method = mahameruRequest.method;\r\n\r\n try {\r\n if (this.isShuttingDown)\r\n response.setHeader('Connection', 'close');\r\n\r\n if (\r\n typeof this.#options.allowedIps !== 'undefined' &&\r\n mahameruRequest.ipAddress\r\n ) {\r\n if (!this.#options.allowedIps.includes(mahameruRequest.ipAddress))\r\n return this.sendResponse(response, new this.dependencies.MahameruResponse(JSON.stringify({ error: 'Forbidden' }), { status: 403 }));\r\n }\r\n\r\n if (typeof this.#options.allowedHosts !== 'undefined' && Array.isArray(this.#options.allowedHosts))\r\n if (!this.#options.allowedHosts.includes(mahameruRequest.headers.host as string))\r\n return this.sendResponse(response, new this.dependencies.MahameruResponse(JSON.stringify({ error: 'Forbidden' }), { status: 403 }));\r\n\r\n if (mahameruRequest.url === '/favicon.ico')\r\n return await this.handleFaviconRequest(mahameruRequest, response);\r\n\r\n if (\r\n mahameruRequest.headers.origin &&\r\n this.#options.allowedOrigins &&\r\n !this.#options.allowedOrigins.includes(mahameruRequest.headers.origin)\r\n )\r\n return this.sendResponse(response, new this.dependencies.MahameruResponse(JSON.stringify({ error: 'Forbidden' }), { status: 403 }));\r\n\r\n if (this.#options.trailingSlash === false && rawReqUrl.length > 1 && rawReqUrl.endsWith('/')) {\r\n const cleanUrl = matchUrl;\r\n const queryStr = mahameruRequest.url?.split('?')[1];\r\n const redirectPath = cleanUrl + (queryStr ? `?${queryStr}` : '');\r\n\r\n return this.sendResponse(response, new this.dependencies.MahameruResponse(JSON.stringify({ message: 'Redirecting to non-trailing slash URL' }), { status: 301, headers: { Location: redirectPath } }));\r\n }\r\n\r\n if (rawReqPath !== rawReqUrl) {\r\n const queryStr = mahameruRequest.url?.includes('?') ? '?' + mahameruRequest.url.split('?')[1] : '';\r\n const redirectPath = rawReqUrl + queryStr;\r\n\r\n return this.sendResponse(response, new this.dependencies.MahameruResponse(JSON.stringify({ message: 'Redirecting to normalized URL' }), { status: 301, headers: { Location: redirectPath } }));\r\n }\r\n\r\n const { matchedRoute, matchResult, notFoundResponse } = await this.dependencies.route.resolveRoute(mahameruRequest);\r\n const middlewareHandler = this.dependencies.container.middlewareHandler;\r\n\r\n if (!matchedRoute || !matchResult) {\r\n const routeHandler: MahameruNext = async () => notFoundResponse;\r\n const rawResponse = middlewareHandler\r\n ? await middlewareHandler({\r\n request: mahameruRequest,\r\n container: this.dependencies.container.mahameruContainer,\r\n method,\r\n params: {},\r\n path: rawReqUrl,\r\n status: 404\r\n }, false, routeHandler)\r\n : await routeHandler();\r\n\r\n const mahameruResponse = this.normalizeMahameruResponse(rawResponse, 'Middleware must return a MahameruResponse instance.');\r\n\r\n return this.sendResponse(response, mahameruResponse);\r\n }\r\n\r\n const handler = matchedRoute.routeHandlers[method];\r\n\r\n if (!handler) {\r\n response.writeHead(405);\r\n\r\n return response.end(JSON.stringify({ error: `Method ${method} Not Allowed` }));\r\n }\r\n\r\n const params: RequestParams = {};\r\n\r\n if (matchResult && matchedRoute.paramNames.length > 0)\r\n matchedRoute.paramNames.forEach((name, index) => {\r\n params[name] = matchResult[index + 1];\r\n });\r\n\r\n const mahameruResponse = middlewareHandler\r\n ? await this.runMiddlewarePipeline(\r\n middlewareHandler,\r\n {\r\n request: mahameruRequest,\r\n container: this.dependencies.container.mahameruContainer,\r\n params,\r\n path: rawReqUrl,\r\n method,\r\n status: 200\r\n },\r\n () => handler(mahameruRequest, this.dependencies.container.mahameruContainer, { params })\r\n )\r\n : await handler(\r\n mahameruRequest,\r\n this.dependencies.container.mahameruContainer,\r\n { params }\r\n );\r\n\r\n return this.sendResponse(response, mahameruResponse);\r\n } catch (error: unknown) {\r\n console.error(error);\r\n const errorResponse = await this.runErrorHandler(\r\n error,\r\n {\r\n request: mahameruRequest,\r\n container: this.dependencies.container.mahameruContainer,\r\n path: rawReqUrl,\r\n method,\r\n params: {},\r\n status: 200\r\n }\r\n );\r\n\r\n return this.sendResponse(response, errorResponse);\r\n }\r\n }\r\n\r\n protected async handleFaviconRequest(request: MahameruRequest, response: DefaultHTTPResponse) {\r\n let targetFaviconPath: string | undefined = undefined;\r\n const customFaviconPath = join(this.#options.rootPath, 'favicon.ico');\r\n\r\n if (await exists(customFaviconPath)) {\r\n targetFaviconPath = customFaviconPath;\r\n } else if (this.#options.faviconFilePath && await exists(this.#options.faviconFilePath)) {\r\n targetFaviconPath = this.#options.faviconFilePath;\r\n }\r\n\r\n if (targetFaviconPath === undefined) {\r\n return this.sendResponse(\r\n response,\r\n new this.dependencies.MahameruResponse('Not Found', { status: 404, headers: { 'Content-Type': 'text/plain' } })\r\n );\r\n }\r\n\r\n const favicon = await readFile(targetFaviconPath);\r\n const middlewareHandler = this.dependencies.container.middlewareHandler;\r\n\r\n if (middlewareHandler) {\r\n const middlewareResponse = await middlewareHandler({\r\n request,\r\n container: this.dependencies.container.mahameruContainer,\r\n method: request.method,\r\n params: {},\r\n path: request.path,\r\n status: 200\r\n }, false, async () => new this.dependencies.MahameruResponse(favicon, { status: 200 }));\r\n\r\n const normalized = this.normalizeMahameruResponse(middlewareResponse, 'Middleware error');\r\n const headers = new Headers(normalized.headers);\r\n\r\n if (normalized.status === 200) {\r\n headers.set('Content-Type', 'image/x-icon');\r\n\r\n if (!headers.has('Cache-Control')) {\r\n headers.set('Cache-Control', 'public, max-age=31536000');\r\n }\r\n }\r\n\r\n return this.sendResponse(response, new this.dependencies.MahameruResponse(normalized.body, {\r\n status: normalized.status,\r\n headers\r\n }));\r\n }\r\n\r\n const faviconResponse = new this.dependencies.MahameruResponse(favicon, {\r\n status: 200,\r\n headers: {\r\n 'Content-Type': 'image/x-icon',\r\n 'Cache-Control': 'public, max-age=31536000'\r\n }\r\n });\r\n\r\n return this.sendResponse(response, faviconResponse);\r\n }\r\n\r\n protected sendResponse(response: DefaultHTTPResponse, mahameruResponse?: MahameruResponse) {\r\n if (!mahameruResponse)\r\n mahameruResponse = new this.dependencies.MahameruResponse(undefined, { status: 204 });\r\n\r\n mahameruResponse.headers.forEach((value, key) => {\r\n response.setHeader(key, value);\r\n });\r\n\r\n if (!this.#options.disableHttpSignature) {\r\n response.setHeader('X-Powered-By', this.#options.httpServerSignature);\r\n response.setHeader('X-Message', this.#options.httpServerMessage);\r\n }\r\n\r\n response.writeHead(mahameruResponse.status);\r\n\r\n let responseBody: any;\r\n\r\n if (typeof mahameruResponse.body === 'string' ||\r\n mahameruResponse.body instanceof Uint8Array ||\r\n Buffer.isBuffer(mahameruResponse.body) ||\r\n mahameruResponse.body === undefined ||\r\n mahameruResponse.body === null) {\r\n\r\n responseBody = mahameruResponse.body;\r\n } else {\r\n responseBody = JSON.stringify(mahameruResponse.body);\r\n }\r\n\r\n response.end(responseBody);\r\n this.dependencies.logger.info(response.req.method, response.statusCode, response.req.url);\r\n }\r\n\r\n protected async runMiddlewarePipeline(\r\n middleware: MahameruMiddleware,\r\n context: MahameruMiddlewareContext,\r\n handler: () => Promise<MahameruResponse> | MahameruResponse\r\n ) {\r\n const isProtectedRoute = this.validateProtectedRoute(context.method, context.path);\r\n const response = await middleware(context, isProtectedRoute, async () => {\r\n const nextResponse = await handler();\r\n\r\n return this.normalizeMahameruResponse(\r\n nextResponse,\r\n 'Route handlers and next() must resolve to MahameruResponse.'\r\n );\r\n });\r\n\r\n return this.normalizeMahameruResponse(\r\n response,\r\n 'Global middleware must return a MahameruResponse instance.'\r\n );\r\n }\r\n\r\n protected async runErrorHandler(error: unknown, context: MahameruMiddlewareContext): Promise<MahameruResponse> {\r\n const fallbackResponse = this.createInternalServerErrorResponse(error);\r\n\r\n if (!this.dependencies.container.errorHandler)\r\n return fallbackResponse;\r\n\r\n try {\r\n const handlerResponse = await this.dependencies.container.errorHandler(\r\n {\r\n ...context,\r\n error\r\n },\r\n async () => fallbackResponse\r\n );\r\n\r\n return this.normalizeMahameruResponse(\r\n handlerResponse,\r\n 'Error handler must return a MahameruResponse instance.'\r\n );\r\n } catch (handlerError: unknown) {\r\n return fallbackResponse;\r\n }\r\n }\r\n\r\n protected createInternalServerErrorResponse(error: unknown): MahameruResponse {\r\n const serverError = error instanceof this.dependencies.HttpServerError\r\n ? error\r\n : new this.dependencies.HttpServerError(error instanceof Error ? error.message : undefined);\r\n\r\n return this.dependencies.MahameruResponse.json(\r\n { error: serverError.message },\r\n { status: serverError.statusCode }\r\n );\r\n }\r\n\r\n protected isMahameruResponseLike(value: unknown): value is MahameruResponseLike {\r\n if (!value || typeof value !== 'object') {\r\n return false;\r\n }\r\n\r\n if (!('status' in value) || typeof value.status !== 'number') {\r\n return false;\r\n }\r\n\r\n if (!('body' in value)) {\r\n return false;\r\n }\r\n\r\n if (!('headers' in value) || value.headers === undefined) {\r\n return true;\r\n }\r\n\r\n if (value.headers instanceof Headers) {\r\n return true;\r\n }\r\n\r\n return typeof value.headers === 'object' && value.headers !== null && !Array.isArray(value.headers);\r\n }\r\n\r\n protected normalizeMahameruResponse(value: unknown, errorMessage: string): MahameruResponse {\r\n if (value instanceof this.dependencies.MahameruResponse)\r\n return value;\r\n\r\n if (!this.isMahameruResponseLike(value))\r\n throw new this.dependencies.HttpServerError(errorMessage);\r\n\r\n const normalizedHeaders = value.headers instanceof Headers\r\n ? Object.fromEntries(value.headers.entries())\r\n : value.headers;\r\n\r\n return new this.dependencies.MahameruResponse(value.body, {\r\n status: value.status,\r\n headers: normalizedHeaders\r\n });\r\n }\r\n\r\n protected matchRoutePattern(currentPath: string, routePattern: string): boolean {\r\n const regexPattern = routePattern\r\n .replace(/[.+^${}()|[\\]\\\\]/g, '\\\\$&')\r\n .replace(/\\//g, '\\\\/')\r\n .replace(/:[^/]+/g, '[^/]+');\r\n\r\n const regex = new RegExp(`^${regexPattern}$`);\r\n return regex.test(currentPath);\r\n }\r\n\r\n protected validateProtectedRoute(method: HTTPMethod, path: string): boolean {\r\n return this.dependencies.container.protectedRoutes.some(route => {\r\n if (typeof route === 'string')\r\n return this.matchRoutePattern(path, route);\r\n\r\n const isPathMatch = this.matchRoutePattern(path, route.path);\r\n const isMethodMatch = route.methods.includes(method);\r\n\r\n return isPathMatch && isMethodMatch;\r\n });\r\n }\r\n\r\n protected requestLogger(response: DefaultHTTPResponse) {\r\n if (!this.#options.dev)\r\n return\r\n\r\n this.dependencies.logger.info(`${response.req.method} ${response.statusCode} ${response.req.url}`);\r\n }\r\n}\r\n"],"mappings":";;AAAA,SAAS,cAAc,iBAAiB,QAAQ,sBAAsB;AACtE,SAAS,YAAY;AACrB,SAAS,gBAAgB;AACzB,SAAS,cAAc;AAiDhB,MAAM,WAAW;AAAA,EApDxB,OAoDwB;AAAA;AAAA;AAAA,EACpB;AAAA,EACmB,iBAAoC;AAAA,IACnD,MAAM;AAAA,IACN,MAAM;AAAA,IACN,KAAK;AAAA,IACL,kBAAkB;AAAA,IAClB,sBAAsB;AAAA,IACtB,qBAAqB;AAAA,IACrB,mBAAmB;AAAA,IACnB,gBAAgB;AAAA,IAChB,YAAY;AAAA,IACZ,cAAc;AAAA,IACd,eAAe;AAAA,IACf,UAAU,QAAQ,IAAI;AAAA,IACtB,IAAI,kBAA0B;AAC1B,aAAO,KAAK,KAAK,UAAU,gBAAgB,YAAY,aAAa;AAAA,IACxE;AAAA,IACA,qBAAqB,CAAC,UAAU,OAAO,WAAW,SAAS,QAAQ,KAAK;AAAA,EAC5E;AAAA,EACU;AAAA,EACA,iBAAiB;AAAA,EACjB;AAAA,EAIV,YAAY,MAA2D,MAA+B;AAClG,QAAI,OAAO,SAAS,aAAa;AAC7B,WAAK,eAAe;AACpB,WAAK,WAAW,KAAK;AAAA,IACzB,OAAO;AACH,WAAK,WAAW;AAAA,QACZ,GAAG,KAAK;AAAA,QACR,GAAG;AAAA,MACP;AACA,WAAK,eAAe;AAAA,IACxB;AAEA,SAAK,aAAa,KAAK,OAAO;AAC9B,SAAK,WAAW,GAAG,SAAS,CAAC,UAA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
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var index_exports = {};
|
|
31
|
+
__export(index_exports, {
|
|
32
|
+
default: () => index_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(index_exports);
|
|
35
|
+
__reExport(index_exports, require('./container-error.cjs'), module.exports);
|
|
36
|
+
__reExport(index_exports, require('./container.cjs'), module.exports);
|
|
37
|
+
__reExport(index_exports, require('./diatrema.cjs'), module.exports);
|
|
38
|
+
__reExport(index_exports, require('./http-server-error.cjs'), module.exports);
|
|
39
|
+
__reExport(index_exports, require('./http-server.cjs'), module.exports);
|
|
40
|
+
__reExport(index_exports, require('./logger.cjs'), module.exports);
|
|
41
|
+
__reExport(index_exports, require('./mahameru-error.cjs'), module.exports);
|
|
42
|
+
__reExport(index_exports, require('./mahameru-request.cjs'), module.exports);
|
|
43
|
+
__reExport(index_exports, require('./mahameru-response.cjs'), module.exports);
|
|
44
|
+
__reExport(index_exports, require('./mahameru-server-error.cjs'), module.exports);
|
|
45
|
+
__reExport(index_exports, require('./module-error.cjs'), module.exports);
|
|
46
|
+
__reExport(index_exports, require('./route.cjs'), module.exports);
|
|
47
|
+
__reExport(index_exports, require('./types.cjs'), module.exports);
|
|
48
|
+
var import_diatrema = __toESM(require('./diatrema.cjs'), 1);
|
|
49
|
+
var index_default = import_diatrema.default;
|
|
50
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
+
0 && (module.exports = {
|
|
52
|
+
...require('./container-error.cjs'),
|
|
53
|
+
...require('./container.cjs'),
|
|
54
|
+
...require('./diatrema.cjs'),
|
|
55
|
+
...require('./http-server-error.cjs'),
|
|
56
|
+
...require('./http-server.cjs'),
|
|
57
|
+
...require('./logger.cjs'),
|
|
58
|
+
...require('./mahameru-error.cjs'),
|
|
59
|
+
...require('./mahameru-request.cjs'),
|
|
60
|
+
...require('./mahameru-response.cjs'),
|
|
61
|
+
...require('./mahameru-server-error.cjs'),
|
|
62
|
+
...require('./module-error.cjs'),
|
|
63
|
+
...require('./route.cjs'),
|
|
64
|
+
...require('./types.cjs')
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=index.cjs.map
|
package/index.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './container-error'\r\nexport * from './container'\r\nexport * from './diatrema'\r\nexport * from './http-server-error'\r\nexport * from './http-server'\r\nexport * from './logger'\r\nexport * from './mahameru-error'\r\nexport * from './mahameru-request'\r\nexport * from './mahameru-response'\r\nexport * from './mahameru-server-error'\r\nexport * from './module-error'\r\nexport * from './route'\r\nexport * from './types'\r\n\r\nimport Diatrema from './diatrema'\r\n\r\nexport default Diatrema;\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAc,8BAAd;AACA,0BAAc,wBADd;AAEA,0BAAc,uBAFd;AAGA,0BAAc,gCAHd;AAIA,0BAAc,0BAJd;AAKA,0BAAc,qBALd;AAMA,0BAAc,6BANd;AAOA,0BAAc,+BAPd;AAQA,0BAAc,gCARd;AASA,0BAAc,oCATd;AAUA,0BAAc,2BAVd;AAWA,0BAAc,oBAXd;AAYA,0BAAc,oBAZd;AAcA,sBAAqB;AAErB,IAAO,gBAAQ,gBAAAA;","names":["Diatrema"]}
|
package/index.d.cts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { ContainerError } from './container-error.cjs';
|
|
2
|
+
export { Container, ContainerDependencies, ContainerOptions } from './container.cjs';
|
|
3
|
+
import Diatrema from './diatrema.cjs';
|
|
4
|
+
export { DiatremaDependencies, DiatremaEvents, DiatremaOptions, diatremaDefaultConfig } from './diatrema.cjs';
|
|
5
|
+
export { HttpServerError } from './http-server-error.cjs';
|
|
6
|
+
export { HttpServer, HttpServerDependencies, HttpServerOptions } from './http-server.cjs';
|
|
7
|
+
export { Logger, createLogger } from './logger.cjs';
|
|
8
|
+
export { MahameruError } from './mahameru-error.cjs';
|
|
9
|
+
export { C as ClassConstructor, a as ContainerItem, b as ContainerItemID, c as ContainerRegistry, E as ErrorHandler, d as ErrorHandlerContext, H as HTTPMethod, e as HTTPMethodEnum, I as InitiatorHandler, f as Instances, M as MahameruContainer, g as MahameruMiddleware, h as MahameruMiddlewareContext, i as MahameruNext, j as MahameruRequest, k as Modules, P as ProtectedRoute, R as RegisterRoutes, l as RequestParams, m as RouteHandler, n as RouteHandlerContext, o as RouteHandlers, p as RouteItem, q as RouteObject } from './types-CipcRmc9.cjs';
|
|
10
|
+
export { MahameruResponse } from './mahameru-response.cjs';
|
|
11
|
+
export { MahameruServerError } from './mahameru-server-error.cjs';
|
|
12
|
+
export { ModuleError } from './module-error.cjs';
|
|
13
|
+
export { Route, RouteDependencies, RouteOptions } from './route.cjs';
|
|
14
|
+
import './event-emitter.cjs';
|
|
15
|
+
import 'node:http';
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
export = Diatrema;
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { ContainerError } from './container-error.js';
|
|
2
|
+
export { Container, ContainerDependencies, ContainerOptions } from './container.js';
|
|
3
|
+
import Diatrema from './diatrema.js';
|
|
4
|
+
export { DiatremaDependencies, DiatremaEvents, DiatremaOptions, diatremaDefaultConfig } from './diatrema.js';
|
|
5
|
+
export { HttpServerError } from './http-server-error.js';
|
|
6
|
+
export { HttpServer, HttpServerDependencies, HttpServerOptions } from './http-server.js';
|
|
7
|
+
export { Logger, createLogger } from './logger.js';
|
|
8
|
+
export { MahameruError } from './mahameru-error.js';
|
|
9
|
+
export { C as ClassConstructor, a as ContainerItem, b as ContainerItemID, c as ContainerRegistry, E as ErrorHandler, d as ErrorHandlerContext, H as HTTPMethod, e as HTTPMethodEnum, I as InitiatorHandler, f as Instances, M as MahameruContainer, g as MahameruMiddleware, h as MahameruMiddlewareContext, i as MahameruNext, j as MahameruRequest, k as Modules, P as ProtectedRoute, R as RegisterRoutes, l as RequestParams, m as RouteHandler, n as RouteHandlerContext, o as RouteHandlers, p as RouteItem, q as RouteObject } from './types-BRwWYiUN.js';
|
|
10
|
+
export { MahameruResponse } from './mahameru-response.js';
|
|
11
|
+
export { MahameruServerError } from './mahameru-server-error.js';
|
|
12
|
+
export { ModuleError } from './module-error.js';
|
|
13
|
+
export { Route, RouteDependencies, RouteOptions } from './route.js';
|
|
14
|
+
import './event-emitter.js';
|
|
15
|
+
import 'node:http';
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
export { Diatrema as default };
|
package/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export * from "./container-error.js";
|
|
2
|
+
export * from "./container.js";
|
|
3
|
+
export * from "./diatrema.js";
|
|
4
|
+
export * from "./http-server-error.js";
|
|
5
|
+
export * from "./http-server.js";
|
|
6
|
+
export * from "./logger.js";
|
|
7
|
+
export * from "./mahameru-error.js";
|
|
8
|
+
export * from "./mahameru-request.js";
|
|
9
|
+
export * from "./mahameru-response.js";
|
|
10
|
+
export * from "./mahameru-server-error.js";
|
|
11
|
+
export * from "./module-error.js";
|
|
12
|
+
export * from "./route.js";
|
|
13
|
+
export * from "./types.js";
|
|
14
|
+
import Diatrema from "./diatrema.js";
|
|
15
|
+
var index_default = Diatrema;
|
|
16
|
+
export {
|
|
17
|
+
index_default as default
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './container-error'\r\nexport * from './container'\r\nexport * from './diatrema'\r\nexport * from './http-server-error'\r\nexport * from './http-server'\r\nexport * from './logger'\r\nexport * from './mahameru-error'\r\nexport * from './mahameru-request'\r\nexport * from './mahameru-response'\r\nexport * from './mahameru-server-error'\r\nexport * from './module-error'\r\nexport * from './route'\r\nexport * from './types'\r\n\r\nimport Diatrema from './diatrema'\r\n\r\nexport default Diatrema;\r\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAEd,OAAO,cAAc;AAErB,IAAO,gBAAQ;","names":[]}
|
package/logger.cjs
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var logger_exports = {};
|
|
21
|
+
__export(logger_exports, {
|
|
22
|
+
createLogger: () => createLogger
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(logger_exports);
|
|
25
|
+
const createLogger = /* @__PURE__ */ __name((debug = false) => {
|
|
26
|
+
return {
|
|
27
|
+
info: /* @__PURE__ */ __name((...data) => {
|
|
28
|
+
if (debug) {
|
|
29
|
+
console.log("[Info]", ...data);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
}, "info"),
|
|
33
|
+
error: /* @__PURE__ */ __name((message, error) => {
|
|
34
|
+
console.error(`[Error] ${message}`, error);
|
|
35
|
+
}, "error"),
|
|
36
|
+
warn: /* @__PURE__ */ __name((...data) => {
|
|
37
|
+
if (debug) {
|
|
38
|
+
console.warn("[Warn]", ...data);
|
|
39
|
+
}
|
|
40
|
+
}, "warn"),
|
|
41
|
+
debug: /* @__PURE__ */ __name((...data) => {
|
|
42
|
+
if (debug) {
|
|
43
|
+
console.debug("[Debug]", ...data);
|
|
44
|
+
}
|
|
45
|
+
}, "debug")
|
|
46
|
+
};
|
|
47
|
+
}, "createLogger");
|
|
48
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
49
|
+
0 && (module.exports = {
|
|
50
|
+
createLogger
|
|
51
|
+
});
|
|
52
|
+
//# sourceMappingURL=logger.cjs.map
|
package/logger.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/logger.ts"],"sourcesContent":["export interface Logger {\r\n info(...data: any[]): void;\r\n error(message: string, error?: unknown): void;\r\n warn(...data: any[]): void;\r\n debug(...data: any[]): void;\r\n}\r\n\r\nexport const createLogger = (debug: boolean = false): Logger => {\r\n return {\r\n info: (...data: any[]) => {\r\n if (debug) {\r\n console.log('[Info]', ...data)\r\n\r\n return\r\n }\r\n },\r\n error: (message, error) => {\r\n console.error(`[Error] ${message}`, error);\r\n },\r\n warn: (...data: any[]) => {\r\n if (debug) {\r\n console.warn('[Warn]', ...data)\r\n }\r\n },\r\n debug: (...data: any[]) => {\r\n if (debug) {\r\n console.debug('[Debug]', ...data)\r\n }\r\n }\r\n };\r\n};\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOO,MAAM,eAAe,wBAAC,QAAiB,UAAkB;AAC5D,SAAO;AAAA,IACH,MAAM,2BAAI,SAAgB;AACtB,UAAI,OAAO;AACP,gBAAQ,IAAI,UAAU,GAAG,IAAI;AAE7B;AAAA,MACJ;AAAA,IACJ,GANM;AAAA,IAON,OAAO,wBAAC,SAAS,UAAU;AACvB,cAAQ,MAAM,WAAW,OAAO,IAAI,KAAK;AAAA,IAC7C,GAFO;AAAA,IAGP,MAAM,2BAAI,SAAgB;AACtB,UAAI,OAAO;AACP,gBAAQ,KAAK,UAAU,GAAG,IAAI;AAAA,MAClC;AAAA,IACJ,GAJM;AAAA,IAKN,OAAO,2BAAI,SAAgB;AACvB,UAAI,OAAO;AACP,gBAAQ,MAAM,WAAW,GAAG,IAAI;AAAA,MACpC;AAAA,IACJ,GAJO;AAAA,EAKX;AACJ,GAvB4B;","names":[]}
|
package/logger.d.cts
ADDED
package/logger.d.ts
ADDED