@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.
Files changed (101) hide show
  1. package/README.md +1 -0
  2. package/container-error.cjs +45 -0
  3. package/container-error.cjs.map +1 -0
  4. package/container-error.d.cts +7 -0
  5. package/container-error.d.ts +7 -0
  6. package/container-error.js +22 -0
  7. package/container-error.js.map +1 -0
  8. package/container.cjs +322 -0
  9. package/container.cjs.map +1 -0
  10. package/container.d.cts +62 -0
  11. package/container.d.ts +62 -0
  12. package/container.js +289 -0
  13. package/container.js.map +1 -0
  14. package/diatrema.cjs +130 -0
  15. package/diatrema.cjs.map +1 -0
  16. package/diatrema.d.cts +73 -0
  17. package/diatrema.d.ts +71 -0
  18. package/diatrema.js +107 -0
  19. package/diatrema.js.map +1 -0
  20. package/event-emitter.cjs +68 -0
  21. package/event-emitter.cjs.map +1 -0
  22. package/event-emitter.d.cts +11 -0
  23. package/event-emitter.d.ts +11 -0
  24. package/event-emitter.js +45 -0
  25. package/event-emitter.js.map +1 -0
  26. package/helpers.cjs +93 -0
  27. package/helpers.cjs.map +1 -0
  28. package/helpers.d.cts +22 -0
  29. package/helpers.d.ts +22 -0
  30. package/helpers.js +67 -0
  31. package/helpers.js.map +1 -0
  32. package/http-server-error.cjs +44 -0
  33. package/http-server-error.cjs.map +1 -0
  34. package/http-server-error.d.cts +7 -0
  35. package/http-server-error.d.ts +7 -0
  36. package/http-server-error.js +21 -0
  37. package/http-server-error.js.map +1 -0
  38. package/http-server.cjs +382 -0
  39. package/http-server.cjs.map +1 -0
  40. package/http-server.d.cts +81 -0
  41. package/http-server.d.ts +81 -0
  42. package/http-server.js +359 -0
  43. package/http-server.js.map +1 -0
  44. package/index.cjs +66 -0
  45. package/index.cjs.map +1 -0
  46. package/index.d.cts +19 -0
  47. package/index.d.ts +19 -0
  48. package/index.js +19 -0
  49. package/index.js.map +1 -0
  50. package/logger.cjs +52 -0
  51. package/logger.cjs.map +1 -0
  52. package/logger.d.cts +9 -0
  53. package/logger.d.ts +9 -0
  54. package/logger.js +29 -0
  55. package/logger.js.map +1 -0
  56. package/mahameru-error.cjs +42 -0
  57. package/mahameru-error.cjs.map +1 -0
  58. package/mahameru-error.d.cts +5 -0
  59. package/mahameru-error.d.ts +5 -0
  60. package/mahameru-error.js +19 -0
  61. package/mahameru-error.js.map +1 -0
  62. package/mahameru-request.cjs +79 -0
  63. package/mahameru-request.cjs.map +1 -0
  64. package/mahameru-request.d.cts +3 -0
  65. package/mahameru-request.d.ts +3 -0
  66. package/mahameru-request.js +56 -0
  67. package/mahameru-request.js.map +1 -0
  68. package/mahameru-response.cjs +71 -0
  69. package/mahameru-response.cjs.map +1 -0
  70. package/mahameru-response.d.cts +17 -0
  71. package/mahameru-response.d.ts +17 -0
  72. package/mahameru-response.js +48 -0
  73. package/mahameru-response.js.map +1 -0
  74. package/mahameru-server-error.cjs +54 -0
  75. package/mahameru-server-error.cjs.map +1 -0
  76. package/mahameru-server-error.d.cts +19 -0
  77. package/mahameru-server-error.d.ts +19 -0
  78. package/mahameru-server-error.js +31 -0
  79. package/mahameru-server-error.js.map +1 -0
  80. package/module-error.cjs +46 -0
  81. package/module-error.cjs.map +1 -0
  82. package/module-error.d.cts +12 -0
  83. package/module-error.d.ts +12 -0
  84. package/module-error.js +23 -0
  85. package/module-error.js.map +1 -0
  86. package/package.json +40 -0
  87. package/route.cjs +128 -0
  88. package/route.cjs.map +1 -0
  89. package/route.d.cts +46 -0
  90. package/route.d.ts +46 -0
  91. package/route.js +105 -0
  92. package/route.js.map +1 -0
  93. package/scripts/preinstall.js +9 -0
  94. package/types-BRwWYiUN.d.ts +108 -0
  95. package/types-CipcRmc9.d.cts +108 -0
  96. package/types.cjs +40 -0
  97. package/types.cjs.map +1 -0
  98. package/types.d.cts +3 -0
  99. package/types.d.ts +3 -0
  100. package/types.js +16 -0
  101. package/types.js.map +1 -0
@@ -0,0 +1,108 @@
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
+ type ContainerRegistry = Map<ContainerItemID, ContainerItem>;
106
+ type InitiatorHandler = () => Promise<Instances>;
107
+
108
+ 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.cjs ADDED
@@ -0,0 +1,40 @@
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 __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var types_exports = {};
20
+ __export(types_exports, {
21
+ HTTPMethodEnum: () => HTTPMethodEnum
22
+ });
23
+ module.exports = __toCommonJS(types_exports);
24
+ var HTTPMethodEnum = /* @__PURE__ */ ((HTTPMethodEnum2) => {
25
+ HTTPMethodEnum2["GET"] = "GET";
26
+ HTTPMethodEnum2["HEAD"] = "HEAD";
27
+ HTTPMethodEnum2["POST"] = "POST";
28
+ HTTPMethodEnum2["PUT"] = "PUT";
29
+ HTTPMethodEnum2["DELETE"] = "DELETE";
30
+ HTTPMethodEnum2["CONNECT"] = "CONNECT";
31
+ HTTPMethodEnum2["OPTIONS"] = "OPTIONS";
32
+ HTTPMethodEnum2["TRACE"] = "TRACE";
33
+ HTTPMethodEnum2["PATCH"] = "PATCH";
34
+ return HTTPMethodEnum2;
35
+ })(HTTPMethodEnum || {});
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ HTTPMethodEnum
39
+ });
40
+ //# sourceMappingURL=types.cjs.map
package/types.cjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { MahameruRequest } from \"./mahameru-request\";\r\nimport type { MahameruResponse } from \"./mahameru-response\";\r\n\r\nexport enum HTTPMethodEnum {\r\n GET = 'GET',\r\n HEAD = 'HEAD',\r\n POST = 'POST',\r\n PUT = 'PUT',\r\n DELETE = 'DELETE',\r\n CONNECT = 'CONNECT',\r\n OPTIONS = 'OPTIONS',\r\n TRACE = 'TRACE',\r\n PATCH = 'PATCH'\r\n}\r\n\r\nexport type HTTPMethod = `${HTTPMethodEnum}`\r\n\r\nexport type RouteObject<T extends string = string> = {\r\n path: T;\r\n methods: HTTPMethod[];\r\n};\r\n\r\nexport interface RegisterRoutes { }\r\n\r\nexport type ProtectedRoute = RegisterRoutes extends { routes: infer R }\r\n ? R[]\r\n : (string | RouteObject<string>)[];\r\n\r\nexport type RequestParams = {\r\n [key: string]: string;\r\n};\r\nexport type RouteHandlerContext = { params: RequestParams };\r\n\r\nexport type RouteHandler = (\r\n request: MahameruRequest,\r\n container: MahameruContainer,\r\n context: RouteHandlerContext\r\n) => Promise<MahameruResponse> | MahameruResponse;\r\n\r\nexport interface RouteItem {\r\n path: string;\r\n regex: RegExp;\r\n paramNames: (keyof RequestParams)[];\r\n routeHandlers: RouteHandlers;\r\n pathFS: string;\r\n}\r\n\r\nexport type RouteHandlers = Record<HTTPMethod, RouteHandler>;\r\n\r\nexport type MahameruNext = () => Promise<MahameruResponse>;\r\n\r\nexport interface MahameruMiddlewareContext {\r\n request: MahameruRequest;\r\n container: MahameruContainer;\r\n params: Record<string, string>;\r\n path: string;\r\n method: HTTPMethod;\r\n status: number;\r\n}\r\n\r\nexport type MahameruMiddleware = (context: MahameruMiddlewareContext, isProtectedRoute: boolean, next: MahameruNext) =>\r\n Promise<MahameruResponse> | MahameruResponse;\r\n\r\nexport type ErrorHandlerContext = MahameruMiddlewareContext & { error: unknown };\r\n\r\nexport type ErrorHandler = (context: ErrorHandlerContext, next: MahameruNext) =>\r\n Promise<MahameruResponse> | MahameruResponse;\r\n\r\nexport interface Modules { }\r\nexport interface Instances { }\r\nexport interface MahameruContainer extends Modules, Instances { }\r\n\r\nexport type ClassConstructor<T = unknown> = new (mahameruContainer: MahameruContainer) => T;\r\n\r\nexport type ContainerItemID = string\r\nexport type ContainerItem =\r\n | { name: string; path: string; type: 'module-service'; item: unknown }\r\n | { name: string; path: string; type: 'module-controller'; item: unknown }\r\n | { name: string; path: string; type: 'route'; item: RouteItem }\r\n | { name: string; path: string; type: 'instance'; item: Instances }\r\n | { name: string; path: string; type: 'middleware'; item: MahameruMiddleware };\r\n\r\nexport type ContainerRegistry = Map<ContainerItemID, ContainerItem>;\r\nexport type InitiatorHandler = () => Promise<Instances>;\r\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,IAAK,iBAAL,kBAAKA,oBAAL;AACH,EAAAA,gBAAA,SAAM;AACN,EAAAA,gBAAA,UAAO;AACP,EAAAA,gBAAA,UAAO;AACP,EAAAA,gBAAA,SAAM;AACN,EAAAA,gBAAA,YAAS;AACT,EAAAA,gBAAA,aAAU;AACV,EAAAA,gBAAA,aAAU;AACV,EAAAA,gBAAA,WAAQ;AACR,EAAAA,gBAAA,WAAQ;AATA,SAAAA;AAAA,GAAA;","names":["HTTPMethodEnum"]}
package/types.d.cts ADDED
@@ -0,0 +1,3 @@
1
+ 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, 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';
2
+ import './mahameru-response.cjs';
3
+ import 'node:http';
package/types.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ 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, 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';
2
+ import './mahameru-response.js';
3
+ import 'node:http';
package/types.js ADDED
@@ -0,0 +1,16 @@
1
+ var HTTPMethodEnum = /* @__PURE__ */ ((HTTPMethodEnum2) => {
2
+ HTTPMethodEnum2["GET"] = "GET";
3
+ HTTPMethodEnum2["HEAD"] = "HEAD";
4
+ HTTPMethodEnum2["POST"] = "POST";
5
+ HTTPMethodEnum2["PUT"] = "PUT";
6
+ HTTPMethodEnum2["DELETE"] = "DELETE";
7
+ HTTPMethodEnum2["CONNECT"] = "CONNECT";
8
+ HTTPMethodEnum2["OPTIONS"] = "OPTIONS";
9
+ HTTPMethodEnum2["TRACE"] = "TRACE";
10
+ HTTPMethodEnum2["PATCH"] = "PATCH";
11
+ return HTTPMethodEnum2;
12
+ })(HTTPMethodEnum || {});
13
+ export {
14
+ HTTPMethodEnum
15
+ };
16
+ //# sourceMappingURL=types.js.map
package/types.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { MahameruRequest } from \"./mahameru-request\";\r\nimport type { MahameruResponse } from \"./mahameru-response\";\r\n\r\nexport enum HTTPMethodEnum {\r\n GET = 'GET',\r\n HEAD = 'HEAD',\r\n POST = 'POST',\r\n PUT = 'PUT',\r\n DELETE = 'DELETE',\r\n CONNECT = 'CONNECT',\r\n OPTIONS = 'OPTIONS',\r\n TRACE = 'TRACE',\r\n PATCH = 'PATCH'\r\n}\r\n\r\nexport type HTTPMethod = `${HTTPMethodEnum}`\r\n\r\nexport type RouteObject<T extends string = string> = {\r\n path: T;\r\n methods: HTTPMethod[];\r\n};\r\n\r\nexport interface RegisterRoutes { }\r\n\r\nexport type ProtectedRoute = RegisterRoutes extends { routes: infer R }\r\n ? R[]\r\n : (string | RouteObject<string>)[];\r\n\r\nexport type RequestParams = {\r\n [key: string]: string;\r\n};\r\nexport type RouteHandlerContext = { params: RequestParams };\r\n\r\nexport type RouteHandler = (\r\n request: MahameruRequest,\r\n container: MahameruContainer,\r\n context: RouteHandlerContext\r\n) => Promise<MahameruResponse> | MahameruResponse;\r\n\r\nexport interface RouteItem {\r\n path: string;\r\n regex: RegExp;\r\n paramNames: (keyof RequestParams)[];\r\n routeHandlers: RouteHandlers;\r\n pathFS: string;\r\n}\r\n\r\nexport type RouteHandlers = Record<HTTPMethod, RouteHandler>;\r\n\r\nexport type MahameruNext = () => Promise<MahameruResponse>;\r\n\r\nexport interface MahameruMiddlewareContext {\r\n request: MahameruRequest;\r\n container: MahameruContainer;\r\n params: Record<string, string>;\r\n path: string;\r\n method: HTTPMethod;\r\n status: number;\r\n}\r\n\r\nexport type MahameruMiddleware = (context: MahameruMiddlewareContext, isProtectedRoute: boolean, next: MahameruNext) =>\r\n Promise<MahameruResponse> | MahameruResponse;\r\n\r\nexport type ErrorHandlerContext = MahameruMiddlewareContext & { error: unknown };\r\n\r\nexport type ErrorHandler = (context: ErrorHandlerContext, next: MahameruNext) =>\r\n Promise<MahameruResponse> | MahameruResponse;\r\n\r\nexport interface Modules { }\r\nexport interface Instances { }\r\nexport interface MahameruContainer extends Modules, Instances { }\r\n\r\nexport type ClassConstructor<T = unknown> = new (mahameruContainer: MahameruContainer) => T;\r\n\r\nexport type ContainerItemID = string\r\nexport type ContainerItem =\r\n | { name: string; path: string; type: 'module-service'; item: unknown }\r\n | { name: string; path: string; type: 'module-controller'; item: unknown }\r\n | { name: string; path: string; type: 'route'; item: RouteItem }\r\n | { name: string; path: string; type: 'instance'; item: Instances }\r\n | { name: string; path: string; type: 'middleware'; item: MahameruMiddleware };\r\n\r\nexport type ContainerRegistry = Map<ContainerItemID, ContainerItem>;\r\nexport type InitiatorHandler = () => Promise<Instances>;\r\n"],"mappings":"AAGO,IAAK,iBAAL,kBAAKA,oBAAL;AACH,EAAAA,gBAAA,SAAM;AACN,EAAAA,gBAAA,UAAO;AACP,EAAAA,gBAAA,UAAO;AACP,EAAAA,gBAAA,SAAM;AACN,EAAAA,gBAAA,YAAS;AACT,EAAAA,gBAAA,aAAU;AACV,EAAAA,gBAAA,aAAU;AACV,EAAAA,gBAAA,WAAQ;AACR,EAAAA,gBAAA,WAAQ;AATA,SAAAA;AAAA,GAAA;","names":["HTTPMethodEnum"]}