@mahameru/diatrema 0.0.2 → 0.0.4
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/diatrema-DBO4yaCD.d.ts +95 -0
- package/diatrema-Fd7aehcd.d.cts +95 -0
- package/diatrema.cjs +70 -52
- package/diatrema.cjs.map +1 -1
- package/diatrema.d.cts +6 -72
- package/diatrema.d.ts +4 -71
- package/diatrema.js +70 -52
- package/diatrema.js.map +1 -1
- package/helpers.cjs +2 -18
- package/helpers.cjs.map +1 -1
- package/helpers.d.cts +1 -6
- package/helpers.d.ts +1 -6
- package/helpers.js +1 -16
- package/helpers.js.map +1 -1
- package/index.cjs +4 -18
- package/index.cjs.map +1 -1
- package/index.d.cts +4 -13
- package/index.d.ts +4 -13
- package/index.js +2 -9
- package/index.js.map +1 -1
- package/logger.cjs +10 -5
- package/logger.cjs.map +1 -1
- package/logger.d.cts +1 -1
- package/logger.d.ts +1 -1
- package/logger.js +10 -5
- package/logger.js.map +1 -1
- package/mahameru-plugin.cjs +113 -0
- package/mahameru-plugin.cjs.map +1 -0
- package/mahameru-plugin.d.cts +4 -0
- package/mahameru-plugin.d.ts +4 -0
- package/mahameru-plugin.js +89 -0
- package/mahameru-plugin.js.map +1 -0
- package/package.json +4 -3
- package/scripts/preinstall.cjs +10 -0
- package/scripts/preinstall.cjs.map +1 -0
- package/scripts/preinstall.d.cts +2 -0
- package/scripts/preinstall.d.ts +2 -0
- package/scripts/preinstall.js +9 -9
- package/scripts/preinstall.js.map +1 -0
- package/types.cjs +0 -23
- package/types.cjs.map +1 -1
- package/types.d.cts +5 -3
- package/types.d.ts +5 -3
- package/types.js +0 -15
- package/types.js.map +1 -1
- package/container-error.cjs +0 -45
- package/container-error.cjs.map +0 -1
- package/container-error.d.cts +0 -7
- package/container-error.d.ts +0 -7
- package/container-error.js +0 -22
- package/container-error.js.map +0 -1
- package/container.cjs +0 -318
- package/container.cjs.map +0 -1
- package/container.d.cts +0 -60
- package/container.d.ts +0 -60
- package/container.js +0 -285
- package/container.js.map +0 -1
- package/http-server-error.cjs +0 -44
- package/http-server-error.cjs.map +0 -1
- package/http-server-error.d.cts +0 -7
- package/http-server-error.d.ts +0 -7
- package/http-server-error.js +0 -21
- package/http-server-error.js.map +0 -1
- package/http-server.cjs +0 -384
- package/http-server.cjs.map +0 -1
- package/http-server.d.cts +0 -81
- package/http-server.d.ts +0 -81
- package/http-server.js +0 -361
- package/http-server.js.map +0 -1
- package/mahameru-request.cjs +0 -79
- package/mahameru-request.cjs.map +0 -1
- package/mahameru-request.d.cts +0 -3
- package/mahameru-request.d.ts +0 -3
- package/mahameru-request.js +0 -56
- package/mahameru-request.js.map +0 -1
- package/mahameru-response.cjs +0 -71
- package/mahameru-response.cjs.map +0 -1
- package/mahameru-response.d.cts +0 -17
- package/mahameru-response.d.ts +0 -17
- package/mahameru-response.js +0 -48
- package/mahameru-response.js.map +0 -1
- package/mahameru-server-error.cjs +0 -54
- package/mahameru-server-error.cjs.map +0 -1
- package/mahameru-server-error.d.cts +0 -19
- package/mahameru-server-error.d.ts +0 -19
- package/mahameru-server-error.js +0 -31
- package/mahameru-server-error.js.map +0 -1
- package/module-error.cjs +0 -46
- package/module-error.cjs.map +0 -1
- package/module-error.d.cts +0 -12
- package/module-error.d.ts +0 -12
- package/module-error.js +0 -23
- package/module-error.js.map +0 -1
- package/route.cjs +0 -128
- package/route.cjs.map +0 -1
- package/route.d.cts +0 -46
- package/route.d.ts +0 -46
- package/route.js +0 -105
- package/route.js.map +0 -1
- package/types-BmFqDpSs.d.ts +0 -113
- package/types-Cd6Gkoxx.d.cts +0 -113
package/route.js
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
class Route {
|
|
5
|
-
static {
|
|
6
|
-
__name(this, "Route");
|
|
7
|
-
}
|
|
8
|
-
options = {
|
|
9
|
-
dev: false,
|
|
10
|
-
routesPath: join(process.cwd(), ".mahameru", "routes")
|
|
11
|
-
};
|
|
12
|
-
dependencies;
|
|
13
|
-
constructor(arg1, arg2) {
|
|
14
|
-
if (typeof arg2 !== "undefined")
|
|
15
|
-
this.options = { ...this.options, ...arg1 };
|
|
16
|
-
if (typeof arg2 !== "undefined") {
|
|
17
|
-
this.dependencies = arg2;
|
|
18
|
-
} else {
|
|
19
|
-
this.dependencies = arg1;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
normalizePathForMatching(path) {
|
|
23
|
-
if (path.length > 1 && path.endsWith("/")) {
|
|
24
|
-
return path.slice(0, -1);
|
|
25
|
-
}
|
|
26
|
-
return path;
|
|
27
|
-
}
|
|
28
|
-
findMatchedRoute(matchUrl) {
|
|
29
|
-
let matchedRoute = null;
|
|
30
|
-
let matchResult = null;
|
|
31
|
-
for (const route of this.dependencies.container.getRouteItems()) {
|
|
32
|
-
const result = route.regex.exec(matchUrl);
|
|
33
|
-
if (result) {
|
|
34
|
-
matchedRoute = route;
|
|
35
|
-
matchResult = result;
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return { matchedRoute, matchResult };
|
|
40
|
-
}
|
|
41
|
-
async runNotFoundHandler(request, method) {
|
|
42
|
-
if (!this.dependencies.container.notFoundHandler)
|
|
43
|
-
return void 0;
|
|
44
|
-
const handler = this.dependencies.container.notFoundHandler[method];
|
|
45
|
-
if (typeof handler !== "function") {
|
|
46
|
-
return void 0;
|
|
47
|
-
}
|
|
48
|
-
const response = await handler(request, this.dependencies.container, { params: {} });
|
|
49
|
-
return this.normalizeMahameruResponse(
|
|
50
|
-
response,
|
|
51
|
-
`Not found handler for method '${method}' must return a MahameruResponse instance.`
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
async resolveRoute(request) {
|
|
55
|
-
const rawReqPath = request.url.split("?")[0] || "/";
|
|
56
|
-
const rawReqUrl = rawReqPath.replace(/\/+/g, "/");
|
|
57
|
-
const matchUrl = this.normalizePathForMatching(rawReqUrl);
|
|
58
|
-
let { matchedRoute, matchResult } = this.findMatchedRoute(matchUrl);
|
|
59
|
-
if (!matchedRoute || !matchResult)
|
|
60
|
-
return {
|
|
61
|
-
matchedRoute: null,
|
|
62
|
-
matchResult: null,
|
|
63
|
-
notFoundResponse: await this.runNotFoundHandler(request, request.method) || this.dependencies.MahameruResponse.json(
|
|
64
|
-
{ error: "Not Found" },
|
|
65
|
-
{ status: 404 }
|
|
66
|
-
)
|
|
67
|
-
};
|
|
68
|
-
return { matchedRoute, matchResult };
|
|
69
|
-
}
|
|
70
|
-
isMahameruResponseLike(value) {
|
|
71
|
-
if (!value || typeof value !== "object") {
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
if (!("status" in value) || typeof value.status !== "number") {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
if (!("body" in value)) {
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
if (!("headers" in value) || value.headers === void 0) {
|
|
81
|
-
return true;
|
|
82
|
-
}
|
|
83
|
-
if (value.headers instanceof Headers) {
|
|
84
|
-
return true;
|
|
85
|
-
}
|
|
86
|
-
return typeof value.headers === "object" && value.headers !== null && !Array.isArray(value.headers);
|
|
87
|
-
}
|
|
88
|
-
normalizeMahameruResponse(value, errorMessage) {
|
|
89
|
-
if (value instanceof this.dependencies.MahameruResponse) {
|
|
90
|
-
return value;
|
|
91
|
-
}
|
|
92
|
-
if (!this.isMahameruResponseLike(value)) {
|
|
93
|
-
throw new this.dependencies.HttpServerError(errorMessage);
|
|
94
|
-
}
|
|
95
|
-
const normalizedHeaders = value.headers instanceof Headers ? Object.fromEntries(value.headers.entries()) : value.headers;
|
|
96
|
-
return new this.dependencies.MahameruResponse(value.body, {
|
|
97
|
-
status: value.status,
|
|
98
|
-
headers: normalizedHeaders
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
export {
|
|
103
|
-
Route
|
|
104
|
-
};
|
|
105
|
-
//# sourceMappingURL=route.js.map
|
package/route.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/route.ts"],"sourcesContent":["import { join } from 'node:path';\n\nimport type { MahameruRequest } from './mahameru-request';\nimport type { MahameruResponse } from './mahameru-response';\nimport type { Container } from './container';\nimport type { HttpServerError } from './http-server-error';\nimport type { HTTPMethod, RouteHandlerContext, RouteItem } from './types';\n\nexport type RouteOptions = {\n dev: boolean;\n routesPath: string;\n};\n\nexport type RouteDependencies = {\n container: Container;\n HttpServerError: typeof HttpServerError;\n MahameruResponse: typeof MahameruResponse;\n};\n\nexport class Route {\n public readonly options: RouteOptions = {\n dev: false,\n routesPath: join(process.cwd(), '.mahameru', 'routes')\n }\n protected dependencies: RouteDependencies;\n\n constructor(\n dependencies: RouteDependencies\n )\n constructor(\n options: Partial<RouteOptions>,\n dependencies: RouteDependencies\n )\n constructor(\n arg1: Partial<RouteOptions> | RouteDependencies,\n arg2?: RouteDependencies\n ) {\n if (typeof arg2 !== 'undefined')\n this.options = { ...this.options, ...arg1 as Partial<RouteOptions> };\n\n if (typeof arg2 !== 'undefined') {\n this.dependencies = arg2;\n } else {\n this.dependencies = arg1 as RouteDependencies;\n }\n }\n\n normalizePathForMatching(path: string): string {\n if (path.length > 1 && path.endsWith('/')) {\n return path.slice(0, -1);\n }\n\n return path;\n }\n\n findMatchedRoute(matchUrl: string) {\n let matchedRoute: RouteItem | null = null;\n let matchResult: RegExpExecArray | null = null;\n\n for (const route of this.dependencies.container.getRouteItems()) {\n const result = route.regex.exec(matchUrl);\n\n if (result) {\n matchedRoute = route;\n matchResult = result;\n\n break;\n }\n }\n\n return { matchedRoute, matchResult };\n }\n\n async runNotFoundHandler(request: MahameruRequest, method: HTTPMethod): Promise<MahameruResponse | undefined> {\n if (!this.dependencies.container.notFoundHandler)\n return undefined;\n\n const handler = this.dependencies.container.notFoundHandler[method];\n\n if (typeof handler !== 'function') {\n return undefined;\n }\n\n const response = await handler(request, this.dependencies.container, { params: {} } satisfies RouteHandlerContext);\n\n return this.normalizeMahameruResponse(\n response,\n `Not found handler for method '${method}' must return a MahameruResponse instance.`\n );\n }\n\n async resolveRoute(request: MahameruRequest) {\n const rawReqPath = request.url.split('?')[0] || '/';\n const rawReqUrl = rawReqPath.replace(/\\/+/g, '/');\n const matchUrl = this.normalizePathForMatching(rawReqUrl);\n\n let { matchedRoute, matchResult } = this.findMatchedRoute(matchUrl);\n\n if (!matchedRoute || !matchResult)\n return {\n matchedRoute: null,\n matchResult: null,\n notFoundResponse: await this.runNotFoundHandler(request, request.method) || this.dependencies.MahameruResponse.json(\n { error: 'Not Found' },\n { status: 404 }\n )\n };\n\n return { matchedRoute, matchResult };\n }\n\n protected isMahameruResponseLike(value: unknown): value is { body: unknown; status: number; headers?: Headers | Record<string, string> } {\n if (!value || typeof value !== 'object') {\n return false;\n }\n\n if (!('status' in value) || typeof value.status !== 'number') {\n return false;\n }\n\n if (!('body' in value)) {\n return false;\n }\n\n if (!('headers' in value) || value.headers === undefined) {\n return true;\n }\n\n if (value.headers instanceof Headers) {\n return true;\n }\n\n return typeof value.headers === 'object' && value.headers !== null && !Array.isArray(value.headers);\n }\n\n protected normalizeMahameruResponse(value: unknown, errorMessage: string): MahameruResponse {\n if (value instanceof this.dependencies.MahameruResponse) {\n return value;\n }\n\n if (!this.isMahameruResponseLike(value)) {\n throw new this.dependencies.HttpServerError(errorMessage);\n }\n\n const normalizedHeaders = value.headers instanceof Headers\n ? Object.fromEntries(value.headers.entries())\n : value.headers;\n\n return new this.dependencies.MahameruResponse(value.body, {\n status: value.status,\n headers: normalizedHeaders\n });\n }\n}\n"],"mappings":";;AAAA,SAAS,YAAY;AAmBd,MAAM,MAAM;AAAA,EAnBnB,OAmBmB;AAAA;AAAA;AAAA,EACC,UAAwB;AAAA,IACpC,KAAK;AAAA,IACL,YAAY,KAAK,QAAQ,IAAI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/types-BmFqDpSs.d.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { IncomingHttpHeaders, IncomingMessage } from 'node:http';
|
|
2
|
-
import { MahameruResponse } from './mahameru-response.js';
|
|
3
|
-
|
|
4
|
-
declare class MahameruRequest {
|
|
5
|
-
method: HTTPMethod;
|
|
6
|
-
url: string;
|
|
7
|
-
headers: IncomingHttpHeaders;
|
|
8
|
-
query: URLSearchParams;
|
|
9
|
-
path: string;
|
|
10
|
-
ipAddress?: string;
|
|
11
|
-
/**
|
|
12
|
-
* Parsed Authorization Bearer header
|
|
13
|
-
* @returns {string | undefined}
|
|
14
|
-
*/
|
|
15
|
-
authorization?: string;
|
|
16
|
-
protected rawRequest: IncomingMessage;
|
|
17
|
-
constructor(request: IncomingMessage);
|
|
18
|
-
json(): Promise<any>;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
declare enum HTTPMethodEnum {
|
|
22
|
-
GET = "GET",
|
|
23
|
-
HEAD = "HEAD",
|
|
24
|
-
POST = "POST",
|
|
25
|
-
PUT = "PUT",
|
|
26
|
-
DELETE = "DELETE",
|
|
27
|
-
CONNECT = "CONNECT",
|
|
28
|
-
OPTIONS = "OPTIONS",
|
|
29
|
-
TRACE = "TRACE",
|
|
30
|
-
PATCH = "PATCH"
|
|
31
|
-
}
|
|
32
|
-
type HTTPMethod = `${HTTPMethodEnum}`;
|
|
33
|
-
type RouteObject<T extends string = string> = {
|
|
34
|
-
path: T;
|
|
35
|
-
methods: HTTPMethod[];
|
|
36
|
-
};
|
|
37
|
-
interface RegisterRoutes {
|
|
38
|
-
}
|
|
39
|
-
type ProtectedRoute = RegisterRoutes extends {
|
|
40
|
-
routes: infer R;
|
|
41
|
-
} ? R[] : (string | RouteObject<string>)[];
|
|
42
|
-
type RequestParams = {
|
|
43
|
-
[key: string]: string;
|
|
44
|
-
};
|
|
45
|
-
type RouteHandlerContext = {
|
|
46
|
-
params: RequestParams;
|
|
47
|
-
};
|
|
48
|
-
type RouteHandler = (request: MahameruRequest, container: MahameruContainer, context: RouteHandlerContext) => Promise<MahameruResponse> | MahameruResponse;
|
|
49
|
-
interface RouteItem {
|
|
50
|
-
path: string;
|
|
51
|
-
regex: RegExp;
|
|
52
|
-
paramNames: (keyof RequestParams)[];
|
|
53
|
-
routeHandlers: RouteHandlers;
|
|
54
|
-
pathFS: string;
|
|
55
|
-
}
|
|
56
|
-
type RouteHandlers = Record<HTTPMethod, RouteHandler>;
|
|
57
|
-
type MahameruNext = () => Promise<MahameruResponse>;
|
|
58
|
-
interface MahameruMiddlewareContext {
|
|
59
|
-
request: MahameruRequest;
|
|
60
|
-
container: MahameruContainer;
|
|
61
|
-
params: Record<string, string>;
|
|
62
|
-
path: string;
|
|
63
|
-
method: HTTPMethod;
|
|
64
|
-
status: number;
|
|
65
|
-
}
|
|
66
|
-
type MahameruMiddleware = (context: MahameruMiddlewareContext, isProtectedRoute: boolean, next: MahameruNext) => Promise<MahameruResponse> | MahameruResponse;
|
|
67
|
-
type ErrorHandlerContext = MahameruMiddlewareContext & {
|
|
68
|
-
error: unknown;
|
|
69
|
-
};
|
|
70
|
-
type ErrorHandler = (context: ErrorHandlerContext, next: MahameruNext) => Promise<MahameruResponse> | MahameruResponse;
|
|
71
|
-
interface Modules {
|
|
72
|
-
}
|
|
73
|
-
interface Instances {
|
|
74
|
-
}
|
|
75
|
-
interface MahameruContainer extends Modules, Instances {
|
|
76
|
-
}
|
|
77
|
-
type ClassConstructor<T = unknown> = new (mahameruContainer: MahameruContainer) => T;
|
|
78
|
-
type ContainerItemID = string;
|
|
79
|
-
type ContainerItem = {
|
|
80
|
-
name: string;
|
|
81
|
-
path: string;
|
|
82
|
-
type: 'module-service';
|
|
83
|
-
item: unknown;
|
|
84
|
-
} | {
|
|
85
|
-
name: string;
|
|
86
|
-
path: string;
|
|
87
|
-
type: 'module-controller';
|
|
88
|
-
item: unknown;
|
|
89
|
-
} | {
|
|
90
|
-
name: string;
|
|
91
|
-
path: string;
|
|
92
|
-
type: 'route';
|
|
93
|
-
item: RouteItem;
|
|
94
|
-
} | {
|
|
95
|
-
name: string;
|
|
96
|
-
path: string;
|
|
97
|
-
type: 'instance';
|
|
98
|
-
item: Instances;
|
|
99
|
-
} | {
|
|
100
|
-
name: string;
|
|
101
|
-
path: string;
|
|
102
|
-
type: 'middleware';
|
|
103
|
-
item: MahameruMiddleware;
|
|
104
|
-
} | {
|
|
105
|
-
name: string;
|
|
106
|
-
path: string;
|
|
107
|
-
type: 'protected-route';
|
|
108
|
-
item: ProtectedRoute;
|
|
109
|
-
};
|
|
110
|
-
type ContainerRegistry = Map<ContainerItemID, ContainerItem>;
|
|
111
|
-
type InitiatorHandler = () => Promise<Instances>;
|
|
112
|
-
|
|
113
|
-
export { type ClassConstructor as C, type ErrorHandler as E, type HTTPMethod as H, type InitiatorHandler as I, type MahameruContainer as M, type ProtectedRoute as P, type RegisterRoutes as R, type ContainerItem as a, type ContainerItemID as b, type ContainerRegistry as c, type ErrorHandlerContext as d, HTTPMethodEnum as e, type Instances as f, type MahameruMiddleware as g, type MahameruMiddlewareContext as h, type MahameruNext as i, MahameruRequest as j, type Modules as k, type RequestParams as l, type RouteHandler as m, type RouteHandlerContext as n, type RouteHandlers as o, type RouteItem as p, type RouteObject as q };
|
package/types-Cd6Gkoxx.d.cts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { IncomingHttpHeaders, IncomingMessage } from 'node:http';
|
|
2
|
-
import { MahameruResponse } from './mahameru-response.cjs';
|
|
3
|
-
|
|
4
|
-
declare class MahameruRequest {
|
|
5
|
-
method: HTTPMethod;
|
|
6
|
-
url: string;
|
|
7
|
-
headers: IncomingHttpHeaders;
|
|
8
|
-
query: URLSearchParams;
|
|
9
|
-
path: string;
|
|
10
|
-
ipAddress?: string;
|
|
11
|
-
/**
|
|
12
|
-
* Parsed Authorization Bearer header
|
|
13
|
-
* @returns {string | undefined}
|
|
14
|
-
*/
|
|
15
|
-
authorization?: string;
|
|
16
|
-
protected rawRequest: IncomingMessage;
|
|
17
|
-
constructor(request: IncomingMessage);
|
|
18
|
-
json(): Promise<any>;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
declare enum HTTPMethodEnum {
|
|
22
|
-
GET = "GET",
|
|
23
|
-
HEAD = "HEAD",
|
|
24
|
-
POST = "POST",
|
|
25
|
-
PUT = "PUT",
|
|
26
|
-
DELETE = "DELETE",
|
|
27
|
-
CONNECT = "CONNECT",
|
|
28
|
-
OPTIONS = "OPTIONS",
|
|
29
|
-
TRACE = "TRACE",
|
|
30
|
-
PATCH = "PATCH"
|
|
31
|
-
}
|
|
32
|
-
type HTTPMethod = `${HTTPMethodEnum}`;
|
|
33
|
-
type RouteObject<T extends string = string> = {
|
|
34
|
-
path: T;
|
|
35
|
-
methods: HTTPMethod[];
|
|
36
|
-
};
|
|
37
|
-
interface RegisterRoutes {
|
|
38
|
-
}
|
|
39
|
-
type ProtectedRoute = RegisterRoutes extends {
|
|
40
|
-
routes: infer R;
|
|
41
|
-
} ? R[] : (string | RouteObject<string>)[];
|
|
42
|
-
type RequestParams = {
|
|
43
|
-
[key: string]: string;
|
|
44
|
-
};
|
|
45
|
-
type RouteHandlerContext = {
|
|
46
|
-
params: RequestParams;
|
|
47
|
-
};
|
|
48
|
-
type RouteHandler = (request: MahameruRequest, container: MahameruContainer, context: RouteHandlerContext) => Promise<MahameruResponse> | MahameruResponse;
|
|
49
|
-
interface RouteItem {
|
|
50
|
-
path: string;
|
|
51
|
-
regex: RegExp;
|
|
52
|
-
paramNames: (keyof RequestParams)[];
|
|
53
|
-
routeHandlers: RouteHandlers;
|
|
54
|
-
pathFS: string;
|
|
55
|
-
}
|
|
56
|
-
type RouteHandlers = Record<HTTPMethod, RouteHandler>;
|
|
57
|
-
type MahameruNext = () => Promise<MahameruResponse>;
|
|
58
|
-
interface MahameruMiddlewareContext {
|
|
59
|
-
request: MahameruRequest;
|
|
60
|
-
container: MahameruContainer;
|
|
61
|
-
params: Record<string, string>;
|
|
62
|
-
path: string;
|
|
63
|
-
method: HTTPMethod;
|
|
64
|
-
status: number;
|
|
65
|
-
}
|
|
66
|
-
type MahameruMiddleware = (context: MahameruMiddlewareContext, isProtectedRoute: boolean, next: MahameruNext) => Promise<MahameruResponse> | MahameruResponse;
|
|
67
|
-
type ErrorHandlerContext = MahameruMiddlewareContext & {
|
|
68
|
-
error: unknown;
|
|
69
|
-
};
|
|
70
|
-
type ErrorHandler = (context: ErrorHandlerContext, next: MahameruNext) => Promise<MahameruResponse> | MahameruResponse;
|
|
71
|
-
interface Modules {
|
|
72
|
-
}
|
|
73
|
-
interface Instances {
|
|
74
|
-
}
|
|
75
|
-
interface MahameruContainer extends Modules, Instances {
|
|
76
|
-
}
|
|
77
|
-
type ClassConstructor<T = unknown> = new (mahameruContainer: MahameruContainer) => T;
|
|
78
|
-
type ContainerItemID = string;
|
|
79
|
-
type ContainerItem = {
|
|
80
|
-
name: string;
|
|
81
|
-
path: string;
|
|
82
|
-
type: 'module-service';
|
|
83
|
-
item: unknown;
|
|
84
|
-
} | {
|
|
85
|
-
name: string;
|
|
86
|
-
path: string;
|
|
87
|
-
type: 'module-controller';
|
|
88
|
-
item: unknown;
|
|
89
|
-
} | {
|
|
90
|
-
name: string;
|
|
91
|
-
path: string;
|
|
92
|
-
type: 'route';
|
|
93
|
-
item: RouteItem;
|
|
94
|
-
} | {
|
|
95
|
-
name: string;
|
|
96
|
-
path: string;
|
|
97
|
-
type: 'instance';
|
|
98
|
-
item: Instances;
|
|
99
|
-
} | {
|
|
100
|
-
name: string;
|
|
101
|
-
path: string;
|
|
102
|
-
type: 'middleware';
|
|
103
|
-
item: MahameruMiddleware;
|
|
104
|
-
} | {
|
|
105
|
-
name: string;
|
|
106
|
-
path: string;
|
|
107
|
-
type: 'protected-route';
|
|
108
|
-
item: ProtectedRoute;
|
|
109
|
-
};
|
|
110
|
-
type ContainerRegistry = Map<ContainerItemID, ContainerItem>;
|
|
111
|
-
type InitiatorHandler = () => Promise<Instances>;
|
|
112
|
-
|
|
113
|
-
export { type ClassConstructor as C, type ErrorHandler as E, type HTTPMethod as H, type InitiatorHandler as I, type MahameruContainer as M, type ProtectedRoute as P, type RegisterRoutes as R, type ContainerItem as a, type ContainerItemID as b, type ContainerRegistry as c, type ErrorHandlerContext as d, HTTPMethodEnum as e, type Instances as f, type MahameruMiddleware as g, type MahameruMiddlewareContext as h, type MahameruNext as i, MahameruRequest as j, type Modules as k, type RequestParams as l, type RouteHandler as m, type RouteHandlerContext as n, type RouteHandlers as o, type RouteItem as p, type RouteObject as q };
|