@mahameru/diatrema 0.0.2 → 0.0.3

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/diatrema-Bk12jngx.d.ts +93 -0
  2. package/diatrema-CyKJKZv_.d.cts +93 -0
  3. package/diatrema.cjs +70 -52
  4. package/diatrema.cjs.map +1 -1
  5. package/diatrema.d.cts +6 -72
  6. package/diatrema.d.ts +4 -71
  7. package/diatrema.js +70 -52
  8. package/diatrema.js.map +1 -1
  9. package/helpers.cjs +2 -18
  10. package/helpers.cjs.map +1 -1
  11. package/helpers.d.cts +1 -6
  12. package/helpers.d.ts +1 -6
  13. package/helpers.js +1 -16
  14. package/helpers.js.map +1 -1
  15. package/index.cjs +4 -18
  16. package/index.cjs.map +1 -1
  17. package/index.d.cts +4 -13
  18. package/index.d.ts +4 -13
  19. package/index.js +2 -9
  20. package/index.js.map +1 -1
  21. package/logger.cjs +10 -5
  22. package/logger.cjs.map +1 -1
  23. package/logger.d.cts +1 -1
  24. package/logger.d.ts +1 -1
  25. package/logger.js +10 -5
  26. package/logger.js.map +1 -1
  27. package/mahameru-plugin.cjs +109 -0
  28. package/mahameru-plugin.cjs.map +1 -0
  29. package/mahameru-plugin.d.cts +4 -0
  30. package/mahameru-plugin.d.ts +4 -0
  31. package/mahameru-plugin.js +85 -0
  32. package/mahameru-plugin.js.map +1 -0
  33. package/package.json +4 -3
  34. package/scripts/preinstall.cjs +10 -0
  35. package/scripts/preinstall.cjs.map +1 -0
  36. package/scripts/preinstall.d.cts +2 -0
  37. package/scripts/preinstall.d.ts +2 -0
  38. package/scripts/preinstall.js +9 -9
  39. package/scripts/preinstall.js.map +1 -0
  40. package/types.cjs +0 -23
  41. package/types.cjs.map +1 -1
  42. package/types.d.cts +5 -3
  43. package/types.d.ts +5 -3
  44. package/types.js +0 -15
  45. package/types.js.map +1 -1
  46. package/container-error.cjs +0 -45
  47. package/container-error.cjs.map +0 -1
  48. package/container-error.d.cts +0 -7
  49. package/container-error.d.ts +0 -7
  50. package/container-error.js +0 -22
  51. package/container-error.js.map +0 -1
  52. package/container.cjs +0 -318
  53. package/container.cjs.map +0 -1
  54. package/container.d.cts +0 -60
  55. package/container.d.ts +0 -60
  56. package/container.js +0 -285
  57. package/container.js.map +0 -1
  58. package/http-server-error.cjs +0 -44
  59. package/http-server-error.cjs.map +0 -1
  60. package/http-server-error.d.cts +0 -7
  61. package/http-server-error.d.ts +0 -7
  62. package/http-server-error.js +0 -21
  63. package/http-server-error.js.map +0 -1
  64. package/http-server.cjs +0 -384
  65. package/http-server.cjs.map +0 -1
  66. package/http-server.d.cts +0 -81
  67. package/http-server.d.ts +0 -81
  68. package/http-server.js +0 -361
  69. package/http-server.js.map +0 -1
  70. package/mahameru-request.cjs +0 -79
  71. package/mahameru-request.cjs.map +0 -1
  72. package/mahameru-request.d.cts +0 -3
  73. package/mahameru-request.d.ts +0 -3
  74. package/mahameru-request.js +0 -56
  75. package/mahameru-request.js.map +0 -1
  76. package/mahameru-response.cjs +0 -71
  77. package/mahameru-response.cjs.map +0 -1
  78. package/mahameru-response.d.cts +0 -17
  79. package/mahameru-response.d.ts +0 -17
  80. package/mahameru-response.js +0 -48
  81. package/mahameru-response.js.map +0 -1
  82. package/mahameru-server-error.cjs +0 -54
  83. package/mahameru-server-error.cjs.map +0 -1
  84. package/mahameru-server-error.d.cts +0 -19
  85. package/mahameru-server-error.d.ts +0 -19
  86. package/mahameru-server-error.js +0 -31
  87. package/mahameru-server-error.js.map +0 -1
  88. package/module-error.cjs +0 -46
  89. package/module-error.cjs.map +0 -1
  90. package/module-error.d.cts +0 -12
  91. package/module-error.d.ts +0 -12
  92. package/module-error.js +0 -23
  93. package/module-error.js.map +0 -1
  94. package/route.cjs +0 -128
  95. package/route.cjs.map +0 -1
  96. package/route.d.cts +0 -46
  97. package/route.d.ts +0 -46
  98. package/route.js +0 -105
  99. package/route.js.map +0 -1
  100. package/types-BmFqDpSs.d.ts +0 -113
  101. package/types-Cd6Gkoxx.d.cts +0 -113
package/container.cjs DELETED
@@ -1,318 +0,0 @@
1
- "use strict";
2
- 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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
- var __export = (target, all) => {
10
- for (var name in all)
11
- __defProp(target, name, { get: all[name], enumerable: true });
12
- };
13
- var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(to, key) && key !== except)
17
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
- }
19
- return to;
20
- };
21
- var __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 container_exports = {};
31
- __export(container_exports, {
32
- Container: () => Container
33
- });
34
- module.exports = __toCommonJS(container_exports);
35
- var import_node_path = __toESM(require("node:path"), 1);
36
- var import_promises = require("node:fs/promises");
37
- var import_helpers = require('./helpers.cjs');
38
- class Container {
39
- static {
40
- __name(this, "Container");
41
- }
42
- #initialized = false;
43
- classes = /* @__PURE__ */ new Map();
44
- _modules = /* @__PURE__ */ new Map();
45
- _errorHandler;
46
- _notFoundHandler;
47
- dependencies;
48
- _initiatorHandler;
49
- options;
50
- containerRegistry = /* @__PURE__ */ new Map();
51
- constructor(arg1, arg2) {
52
- if (typeof arg2 !== "undefined") {
53
- this.options = this.buildOptions(arg1);
54
- this.dependencies = arg2;
55
- } else {
56
- this.dependencies = arg1;
57
- this.options = this.buildOptions();
58
- }
59
- }
60
- get notFoundHandler() {
61
- return this._notFoundHandler;
62
- }
63
- getRouteItems() {
64
- return Array.from(this.containerRegistry.values()).filter((item) => item.type === "route").map((item) => item.item);
65
- }
66
- get middlewareHandler() {
67
- return this.containerRegistry.values().find((item) => item.type === "middleware")?.item;
68
- }
69
- get errorHandler() {
70
- return this._errorHandler;
71
- }
72
- get protectedRoutes() {
73
- return this.containerRegistry.values().find((item) => item.type === "protected-route")?.item || [];
74
- }
75
- get initialized() {
76
- return this.#initialized;
77
- }
78
- get mahameruContainer() {
79
- const camelCaseName = /* @__PURE__ */ __name((name) => name.charAt(0).toLowerCase() + name.slice(1), "camelCaseName");
80
- return new Proxy({}, {
81
- get: /* @__PURE__ */ __name((_target, prop) => {
82
- if (typeof prop !== "string")
83
- return void 0;
84
- for (const registry of this.containerRegistry.values()) {
85
- if (registry.type === "module-service" || registry.type === "module-controller" || registry.type === "instance") {
86
- const key = camelCaseName(registry.name);
87
- if (key === prop) {
88
- return registry.item;
89
- }
90
- }
91
- }
92
- return void 0;
93
- }, "get")
94
- });
95
- }
96
- async discover() {
97
- await this.loadRoutes();
98
- await this.loadInitiator();
99
- await this.loadModules();
100
- await this.loadMiddlewareHandler();
101
- await this.loadNotFoundHandlers();
102
- await this.loadErrorHandler();
103
- this.#initialized = true;
104
- }
105
- async loadRoutes(currentDir) {
106
- const baseDir = this.options.routesPath;
107
- if (!currentDir)
108
- currentDir = baseDir;
109
- const items = await (0, import_promises.readdir)(currentDir, { withFileTypes: true }).catch((error) => {
110
- if (error.code === "ENOENT")
111
- return [];
112
- throw error;
113
- });
114
- for (const item of items) {
115
- const fullPath = (0, import_node_path.join)(currentDir, item.name);
116
- if (item.isDirectory()) {
117
- await this.loadRoutes(fullPath);
118
- continue;
119
- }
120
- if (!item.isFile() || !["route.js", "route.ts"].includes(item.name))
121
- continue;
122
- await this.loadSingleRoute(fullPath, currentDir, baseDir, { parentPath: item.parentPath, name: item.name });
123
- }
124
- }
125
- async loadSingleRoute(fullPath, currentDir, baseDir, item) {
126
- const relativePath = (0, import_node_path.relative)(baseDir, currentDir);
127
- let path2 = "/" + relativePath.replace(/\\/g, "/");
128
- path2 = path2.replace(/\/+/g, "/");
129
- if (path2.length > 1 && path2.endsWith("/"))
130
- path2 = path2.slice(0, -1);
131
- const paramNames = [];
132
- const paramMatches = path2.match(/\[([^\]]+)\]/g);
133
- if (paramMatches)
134
- paramMatches.forEach((match) => {
135
- paramNames.push(match.slice(1, -1));
136
- });
137
- const escaped = path2.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
138
- const regexPattern = escaped.replace(/\\\[([^\\\]]+)\\\]/g, "([^/]+)");
139
- const regex = new RegExp(`^${regexPattern}$`);
140
- const pathFS = (0, import_node_path.resolve)(fullPath);
141
- const routeHandlers = await (0, import_helpers.dynamicRequire)(this.options.moduleType, fullPath, this.options.dev);
142
- if (routeHandlers) {
143
- this.containerRegistry.set(fullPath, {
144
- name: (0, import_node_path.dirname)(item.parentPath),
145
- path: fullPath,
146
- type: "route",
147
- item: {
148
- paramNames: [...paramNames],
149
- path: path2,
150
- pathFS,
151
- regex,
152
- routeHandlers
153
- }
154
- });
155
- return true;
156
- }
157
- return false;
158
- }
159
- async loadModules() {
160
- const items = await (0, import_promises.readdir)(this.options.modulesPath, { withFileTypes: true }).catch((error) => {
161
- if (error.code === "ENOENT")
162
- return [];
163
- throw error;
164
- });
165
- for (const item of items) {
166
- if (!item.isDirectory())
167
- continue;
168
- const directory = item;
169
- let controllerPath;
170
- const controllerPathCandidate = [
171
- import_node_path.default.join(this.options.modulesPath, directory.name, `controller.js`),
172
- import_node_path.default.join(this.options.modulesPath, directory.name, `controller.ts`)
173
- ];
174
- for (const candidate of controllerPathCandidate) {
175
- if (await (0, import_helpers.exists)(candidate)) {
176
- controllerPath = candidate;
177
- break;
178
- }
179
- }
180
- if (controllerPath && await (0, import_helpers.exists)(controllerPath)) {
181
- const controllerModule = await (0, import_helpers.dynamicRequire)(this.options.moduleType, controllerPath, this.options.dev);
182
- if (controllerModule) {
183
- const { name, clazz } = this.getDefaultExportClass(controllerModule, controllerPath);
184
- const item2 = new clazz(this.mahameruContainer);
185
- const containerRegistryID = `${controllerPath}:${name}`;
186
- if (!this.containerRegistry.has(containerRegistryID))
187
- this.containerRegistry.set(containerRegistryID, {
188
- name,
189
- path: controllerPath,
190
- type: "module-controller",
191
- item: item2
192
- });
193
- }
194
- }
195
- let servicePath;
196
- const servicePathCandidate = [
197
- import_node_path.default.join(this.options.modulesPath, directory.name, `service.js`),
198
- import_node_path.default.join(this.options.modulesPath, directory.name, `service.ts`)
199
- ];
200
- for (const candidate of servicePathCandidate) {
201
- if (await (0, import_helpers.exists)(candidate)) {
202
- servicePath = candidate;
203
- break;
204
- }
205
- }
206
- if (servicePath && await (0, import_helpers.exists)(servicePath)) {
207
- const serviceModule = await (0, import_helpers.dynamicRequire)(this.options.moduleType, servicePath, this.options.dev);
208
- if (serviceModule) {
209
- const { name, clazz } = this.getDefaultExportClass(serviceModule, servicePath);
210
- const item2 = new clazz(this.mahameruContainer);
211
- const containerRegistryID = `${controllerPath}:${name}`;
212
- if (!this.containerRegistry.has(containerRegistryID))
213
- this.containerRegistry.set(containerRegistryID, {
214
- name,
215
- path: servicePath,
216
- type: "module-service",
217
- item: item2
218
- });
219
- }
220
- }
221
- }
222
- }
223
- async loadMiddlewareHandler() {
224
- const middlawareHandlerPath = (0, import_node_path.join)(this.options.appPath, "middleware.js");
225
- const result = await (0, import_helpers.dynamicRequire)(this.options.moduleType, middlawareHandlerPath, this.options.dev);
226
- let success = false;
227
- if (result?.default && !Array.isArray(result.default)) {
228
- this.containerRegistry.set(`${middlawareHandlerPath}:default`, {
229
- name: "default",
230
- path: middlawareHandlerPath,
231
- type: "middleware",
232
- item: result.default
233
- });
234
- success = true;
235
- }
236
- if (result?.protectedRoutes && Array.isArray(result.protectedRoutes)) {
237
- this.containerRegistry.set(`${middlawareHandlerPath}:protectedRoutes`, {
238
- name: "protectedRoutes",
239
- path: middlawareHandlerPath,
240
- type: "protected-route",
241
- item: result.protectedRoutes
242
- });
243
- success = true;
244
- }
245
- return success;
246
- }
247
- async loadNotFoundHandlers() {
248
- const notFoundHandlerPath = (0, import_node_path.join)(this.options.appPath, "routes", "not-found.js");
249
- this._notFoundHandler = await (0, import_helpers.dynamicRequire)(this.options.moduleType, notFoundHandlerPath, this.options.dev);
250
- }
251
- async loadErrorHandler() {
252
- const errorHandlerPath = (0, import_node_path.join)(this.options.appPath, "error.js");
253
- const result = await (0, import_helpers.dynamicRequire)(this.options.moduleType, errorHandlerPath, this.options.dev);
254
- this._errorHandler = result?.default;
255
- }
256
- async loadInitiator() {
257
- const initiatorPath = (0, import_node_path.join)(this.options.appPath, "initiator.js");
258
- const result = await (0, import_helpers.dynamicRequire)(this.options.moduleType, initiatorPath, this.options.dev);
259
- const handler = result?.default;
260
- if (handler) {
261
- this._initiatorHandler = handler;
262
- const instances = await this._initiatorHandler();
263
- Object.keys(instances).forEach((key) => {
264
- this.containerRegistry.set(`${initiatorPath}:${key}`, {
265
- name: key,
266
- path: initiatorPath,
267
- type: "instance",
268
- item: instances[key]
269
- });
270
- });
271
- }
272
- }
273
- async onFileChanged(filePath) {
274
- filePath = filePath.endsWith(".ts") ? filePath.replace(".ts", ".js") : filePath;
275
- if (filePath.includes("\\src\\"))
276
- filePath = filePath.replace("\\src\\", `\\.mahameru\\`);
277
- const found = this.containerRegistry.values().find((containerItem) => containerItem.path === filePath);
278
- if (found) {
279
- if (found.type === "route") {
280
- return await this.loadSingleRoute(filePath, (0, import_node_path.dirname)(filePath), this.options.routesPath, { parentPath: (0, import_node_path.dirname)(filePath), name: (0, import_node_path.basename)(filePath) });
281
- } else if (found.type === "middleware" || found.type === "protected-route") {
282
- return await this.loadMiddlewareHandler();
283
- }
284
- }
285
- return false;
286
- }
287
- getDefaultExportClass(module2, filePath) {
288
- const defaultExportName = Object.keys(module2).find((key) => key === "default");
289
- if (!defaultExportName)
290
- throw new this.dependencies.ModuleError(`Module in file '${filePath}' does not have a default export.`, { path: filePath, moduleName: Object.keys(module2)[0] });
291
- return {
292
- name: module2[defaultExportName].name,
293
- clazz: module2[defaultExportName]
294
- };
295
- }
296
- buildOptions(initialOptions) {
297
- const appPath = (0, import_node_path.join)(process.cwd(), ".mahameru");
298
- const defaultOptions = {
299
- appPath,
300
- modulesPath: (0, import_node_path.join)(appPath, "modules"),
301
- moduleType: "esm",
302
- dev: initialOptions?.dev ? true : false,
303
- routesPath: (0, import_node_path.join)(appPath, "routes")
304
- };
305
- if (!initialOptions)
306
- return defaultOptions;
307
- return {
308
- ...defaultOptions,
309
- appPath,
310
- ...initialOptions
311
- };
312
- }
313
- }
314
- // Annotate the CommonJS export names for ESM import in node:
315
- 0 && (module.exports = {
316
- Container
317
- });
318
- //# sourceMappingURL=container.cjs.map
package/container.cjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/container.ts"],"sourcesContent":["import path, { basename, dirname, join, relative, resolve } from 'node:path';\nimport { readdir } from 'node:fs/promises';\n\nimport { dynamicRequire, exists } from './helpers';\nimport type { ContainerError } from './container-error';\nimport type { ClassConstructor, ContainerRegistry, ErrorHandler, HTTPMethod, InitiatorHandler, MahameruContainer, MahameruMiddleware, ProtectedRoute, RouteHandler, RouteItem } from './types';\nimport type { ModuleError } from './module-error';\n\n/**\n * Container options\n */\nexport type ContainerOptions = {\n modulesPath: string;\n routesPath: string;\n appPath: string;\n dev: boolean;\n moduleType: \"commonjs\" | \"esm\";\n}\n\nexport type ContainerDependencies = {\n dataSources?: Record<string, any>;\n ContainerError: typeof ContainerError;\n ModuleError: typeof ModuleError;\n}\n\nexport class Container {\n #initialized = false;\n protected classes = new Map<string, ClassConstructor>();\n protected _modules = new Map<ClassConstructor, any>();\n protected _errorHandler?: ErrorHandler;\n protected _notFoundHandler?: Record<HTTPMethod, RouteHandler>;\n protected dependencies: ContainerDependencies;\n protected _initiatorHandler?: InitiatorHandler;\n public readonly options: ContainerOptions;\n public containerRegistry: ContainerRegistry = new Map();\n\n constructor(dependencies: ContainerDependencies);\n constructor(initialOptions: Partial<ContainerOptions>, dependencies: ContainerDependencies);\n constructor(arg1: Partial<ContainerOptions> | ContainerDependencies, arg2?: ContainerDependencies) {\n if (typeof arg2 !== 'undefined') {\n this.options = this.buildOptions(arg1 as Partial<ContainerOptions>);\n this.dependencies = arg2;\n } else {\n this.dependencies = arg1 as ContainerDependencies;\n this.options = this.buildOptions();\n }\n }\n\n get notFoundHandler() {\n return this._notFoundHandler;\n }\n\n getRouteItems(): RouteItem[] {\n return Array.from(this.containerRegistry.values()).filter((item) => item.type === 'route').map((item) => item.item);\n }\n\n get middlewareHandler(): MahameruMiddleware | undefined {\n return this.containerRegistry.values().find((item) => item.type === 'middleware')?.item;\n }\n\n get errorHandler() {\n return this._errorHandler;\n }\n\n get protectedRoutes(): ProtectedRoute {\n return this.containerRegistry.values().find((item) => item.type === 'protected-route')?.item || [];\n }\n\n get initialized() {\n return this.#initialized;\n }\n\n get mahameruContainer(): MahameruContainer {\n const camelCaseName = (name: string) => name.charAt(0).toLowerCase() + name.slice(1);\n\n return new Proxy({} as Record<string, unknown>, {\n get: (_target, prop) => {\n if (typeof prop !== 'string')\n return undefined;\n\n for (const registry of this.containerRegistry.values()) {\n if (registry.type === 'module-service' || registry.type === 'module-controller' || registry.type === 'instance') {\n const key = camelCaseName(registry.name);\n\n if (key === prop) {\n return registry.item;\n }\n }\n }\n\n return undefined;\n }\n }) as MahameruContainer;\n\n\n // const instances = this.containerRegistry.values().find((item) => item.type === 'instance');\n\n // if (instances) {\n // (result as any) = {\n // ...result,\n // ...instances.item\n // };\n // }\n\n // return result;\n }\n\n async discover() {\n await this.loadRoutes();\n await this.loadInitiator();\n await this.loadModules();\n await this.loadMiddlewareHandler();\n await this.loadNotFoundHandlers();\n await this.loadErrorHandler();\n\n this.#initialized = true;\n }\n\n protected async loadRoutes(currentDir?: string) {\n const baseDir = this.options.routesPath;\n\n if (!currentDir)\n currentDir = baseDir;\n\n const items = await readdir(currentDir, { withFileTypes: true }).catch(error => {\n if (error.code === 'ENOENT')\n return [];\n\n throw error;\n });\n\n for (const item of items) {\n const fullPath = join(currentDir, item.name);\n\n if (item.isDirectory()) {\n await this.loadRoutes(fullPath);\n\n continue;\n }\n\n if (!item.isFile() || (!['route.js', 'route.ts'].includes(item.name)))\n continue;\n\n await this.loadSingleRoute(fullPath, currentDir, baseDir, { parentPath: item.parentPath, name: item.name })\n }\n }\n\n protected async loadSingleRoute(fullPath: string, currentDir: string, baseDir: string, item: { parentPath: string, name: string }): Promise<boolean> {\n const relativePath = relative(baseDir, currentDir);\n\n let path = '/' + relativePath.replace(/\\\\/g, '/');\n path = path.replace(/\\/+/g, '/');\n\n if (path.length > 1 && path.endsWith('/'))\n path = path.slice(0, -1);\n\n const paramNames: RouteItem['paramNames'] = [];\n const paramMatches = path.match(/\\[([^\\]]+)\\]/g);\n\n if (paramMatches)\n paramMatches.forEach((match) => {\n paramNames.push(match.slice(1, -1));\n });\n\n const escaped = path.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n const regexPattern = escaped.replace(/\\\\\\[([^\\\\\\]]+)\\\\\\]/g, '([^/]+)');\n const regex = new RegExp(`^${regexPattern}$`);\n const pathFS = resolve(fullPath);\n const routeHandlers = await dynamicRequire<Record<HTTPMethod, RouteHandler>>(this.options.moduleType, fullPath, this.options.dev);\n\n if (routeHandlers) {\n this.containerRegistry.set(fullPath, {\n name: dirname(item.parentPath),\n path: fullPath,\n type: 'route',\n item: {\n paramNames: [...paramNames],\n path,\n pathFS,\n regex,\n routeHandlers\n }\n });\n\n return true;\n }\n\n return false;\n }\n\n protected async loadModules() {\n const items = await readdir(this.options.modulesPath, { withFileTypes: true }).catch(error => {\n if (error.code === 'ENOENT')\n return [];\n\n throw error;\n });\n\n for (const item of items) {\n if (!item.isDirectory())\n continue;\n\n const directory = item;\n\n let controllerPath;\n const controllerPathCandidate = [\n path.join(this.options.modulesPath, directory.name, `controller.js`),\n path.join(this.options.modulesPath, directory.name, `controller.ts`)\n ];\n\n for (const candidate of controllerPathCandidate) {\n if (await exists(candidate)) {\n controllerPath = candidate;\n break;\n }\n }\n\n if (controllerPath && await exists(controllerPath)) {\n const controllerModule = await dynamicRequire<Record<string, ClassConstructor>>(this.options.moduleType, controllerPath, this.options.dev);\n\n if (controllerModule) {\n const { name, clazz } = this.getDefaultExportClass(controllerModule, controllerPath);\n const item = new clazz(this.mahameruContainer);\n const containerRegistryID = `${controllerPath}:${name}`;\n\n if (!this.containerRegistry.has(containerRegistryID))\n this.containerRegistry.set(containerRegistryID, {\n name,\n path: controllerPath,\n type: 'module-controller',\n item\n })\n }\n }\n\n let servicePath;\n const servicePathCandidate = [\n path.join(this.options.modulesPath, directory.name, `service.js`),\n path.join(this.options.modulesPath, directory.name, `service.ts`)\n ];\n\n for (const candidate of servicePathCandidate) {\n if (await exists(candidate)) {\n servicePath = candidate;\n break;\n }\n }\n\n if (servicePath && await exists(servicePath)) {\n const serviceModule = await dynamicRequire<Record<string, ClassConstructor>>(this.options.moduleType, servicePath, this.options.dev);\n\n if (serviceModule) {\n const { name, clazz } = this.getDefaultExportClass(serviceModule, servicePath);\n const item = new clazz(this.mahameruContainer);\n const containerRegistryID = `${controllerPath}:${name}`;\n\n if (!this.containerRegistry.has(containerRegistryID))\n this.containerRegistry.set(containerRegistryID, {\n name,\n path: servicePath,\n type: 'module-service',\n item\n })\n }\n }\n }\n }\n\n protected async loadMiddlewareHandler(): Promise<boolean> {\n const middlawareHandlerPath = join(this.options.appPath, 'middleware.js');\n const result = await dynamicRequire<Record<'default' | 'protectedRoutes', MahameruMiddleware | ProtectedRoute>>(this.options.moduleType, middlawareHandlerPath, this.options.dev);\n let success = false;\n\n if (result?.default && !Array.isArray(result.default)) {\n this.containerRegistry.set(`${middlawareHandlerPath}:default`, {\n name: 'default',\n path: middlawareHandlerPath,\n type: 'middleware',\n item: result.default\n });\n\n success = true\n }\n\n if (result?.protectedRoutes && Array.isArray(result.protectedRoutes)) {\n this.containerRegistry.set(`${middlawareHandlerPath}:protectedRoutes`, {\n name: 'protectedRoutes',\n path: middlawareHandlerPath,\n type: 'protected-route',\n item: result.protectedRoutes\n });\n\n success = true\n }\n\n return success;\n }\n\n protected async loadNotFoundHandlers() {\n const notFoundHandlerPath = join(this.options.appPath, 'routes', 'not-found.js');\n\n this._notFoundHandler = await dynamicRequire<Record<HTTPMethod, RouteHandler>>(this.options.moduleType, notFoundHandlerPath, this.options.dev);\n }\n\n protected async loadErrorHandler() {\n const errorHandlerPath = join(this.options.appPath, 'error.js');\n const result = await dynamicRequire<Record<'default', ErrorHandler>>(this.options.moduleType, errorHandlerPath, this.options.dev);\n\n this._errorHandler = result?.default;\n }\n\n protected async loadInitiator() {\n const initiatorPath = join(this.options.appPath, 'initiator.js');\n const result = await dynamicRequire<Record<'default', InitiatorHandler>>(this.options.moduleType, initiatorPath, this.options.dev);\n const handler = result?.default;\n\n if (handler) {\n this._initiatorHandler = handler;\n const instances = await this._initiatorHandler();\n\n Object.keys(instances).forEach((key) => {\n this.containerRegistry.set(`${initiatorPath}:${key}`, {\n name: key,\n path: initiatorPath,\n type: 'instance',\n item: (instances as any)[key]\n })\n })\n }\n }\n\n public async onFileChanged(filePath: string): Promise<boolean> {\n filePath = filePath.endsWith('.ts') ? filePath.replace('.ts', '.js') : filePath;\n\n if (filePath.includes('\\\\src\\\\'))\n filePath = filePath.replace('\\\\src\\\\', `\\\\.mahameru\\\\`);\n\n const found = this.containerRegistry.values().find((containerItem) => containerItem.path === filePath);\n\n if (found) {\n if (found.type === 'route') {\n return await this.loadSingleRoute(filePath, dirname(filePath), this.options.routesPath, { parentPath: dirname(filePath), name: basename(filePath) });\n } else if (found.type === 'middleware' || found.type === 'protected-route') {\n return await this.loadMiddlewareHandler();\n }\n }\n\n return false;\n }\n\n protected getDefaultExportClass(module: Record<string, ClassConstructor<unknown>>, filePath: string) {\n const defaultExportName = Object.keys(module).find((key) => key === 'default');\n\n if (!defaultExportName)\n throw new this.dependencies.ModuleError(`Module in file '${filePath}' does not have a default export.`, { path: filePath, moduleName: Object.keys(module)[0] });\n\n return {\n name: module[defaultExportName].name,\n clazz: module[defaultExportName]\n };\n }\n\n protected buildOptions(initialOptions?: Partial<ContainerOptions>): ContainerOptions {\n const appPath = join(process.cwd(), '.mahameru');\n const defaultOptions: ContainerOptions = {\n appPath,\n modulesPath: join(appPath, 'modules'),\n moduleType: 'esm',\n dev: initialOptions?.dev ? true : false,\n routesPath: join(appPath, 'routes')\n };\n\n if (!initialOptions)\n return defaultOptions;\n\n return {\n ...defaultOptions,\n appPath,\n ...initialOptions\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAiE;AACjE,sBAAwB;AAExB,qBAAuC;AAsBhC,MAAM,UAAU;AAAA,EAzBvB,OAyBuB;AAAA;AAAA;AAAA,EACnB,eAAe;AAAA,EACL,UAAU,oBAAI,IAA8B;AAAA,EAC5C,WAAW,oBAAI,IAA2B;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACM;AAAA,EACT,oBAAuC,oBAAI,IAAI;AAAA,EAItD,YAAY,MAAyD,MAA8B;AAC/F,QAAI,OAAO,SAAS,aAAa;AAC7B,WAAK,UAAU,KAAK,aAAa,IAAiC;AAClE,WAAK,eAAe;AAAA,IACxB,OAAO;AACH,WAAK,eAAe;AACpB,WAAK,UAAU,KAAK,aAAa;AAAA,IACrC;AAAA,EACJ;AAAA,EAEA,IAAI,kBAAkB;AAClB,WAAO,KAAK;AAAA,EAChB;AAAA,EAEA,gBAA6B;AACzB,WAAO,MAAM,KAAK,KAAK,kBA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,YAAY;AAAA,MACZ,KAAK,gBAAgB,MAAM,OAAO;AAAA,MAClC,gBAAY,uBAAK,SAAS,QAAQ;AAAA,IACtC;AAEA,QAAI,CAAC;AACD,aAAO;AAEX,WAAO;AAAA,MACH,GAAG;AAAA,MACH;AAAA,MACA,GAAG;AAAA,IACP;AAAA,EACJ;AACJ;","names":["path","item","module"]}
package/container.d.cts DELETED
@@ -1,60 +0,0 @@
1
- import { ContainerError } from './container-error.cjs';
2
- import { C as ClassConstructor, E as ErrorHandler, H as HTTPMethod, m as RouteHandler, I as InitiatorHandler, c as ContainerRegistry, p as RouteItem, g as MahameruMiddleware, P as ProtectedRoute, M as MahameruContainer } from './types-Cd6Gkoxx.cjs';
3
- import { ModuleError } from './module-error.cjs';
4
- import 'node:http';
5
- import './mahameru-response.cjs';
6
-
7
- /**
8
- * Container options
9
- */
10
- type ContainerOptions = {
11
- modulesPath: string;
12
- routesPath: string;
13
- appPath: string;
14
- dev: boolean;
15
- moduleType: "commonjs" | "esm";
16
- };
17
- type ContainerDependencies = {
18
- dataSources?: Record<string, any>;
19
- ContainerError: typeof ContainerError;
20
- ModuleError: typeof ModuleError;
21
- };
22
- declare class Container {
23
- #private;
24
- protected classes: Map<string, ClassConstructor>;
25
- protected _modules: Map<ClassConstructor, any>;
26
- protected _errorHandler?: ErrorHandler;
27
- protected _notFoundHandler?: Record<HTTPMethod, RouteHandler>;
28
- protected dependencies: ContainerDependencies;
29
- protected _initiatorHandler?: InitiatorHandler;
30
- readonly options: ContainerOptions;
31
- containerRegistry: ContainerRegistry;
32
- constructor(dependencies: ContainerDependencies);
33
- constructor(initialOptions: Partial<ContainerOptions>, dependencies: ContainerDependencies);
34
- get notFoundHandler(): Record<"GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "CONNECT" | "OPTIONS" | "TRACE" | "PATCH", RouteHandler> | undefined;
35
- getRouteItems(): RouteItem[];
36
- get middlewareHandler(): MahameruMiddleware | undefined;
37
- get errorHandler(): ErrorHandler | undefined;
38
- get protectedRoutes(): ProtectedRoute;
39
- get initialized(): boolean;
40
- get mahameruContainer(): MahameruContainer;
41
- discover(): Promise<void>;
42
- protected loadRoutes(currentDir?: string): Promise<void>;
43
- protected loadSingleRoute(fullPath: string, currentDir: string, baseDir: string, item: {
44
- parentPath: string;
45
- name: string;
46
- }): Promise<boolean>;
47
- protected loadModules(): Promise<void>;
48
- protected loadMiddlewareHandler(): Promise<boolean>;
49
- protected loadNotFoundHandlers(): Promise<void>;
50
- protected loadErrorHandler(): Promise<void>;
51
- protected loadInitiator(): Promise<void>;
52
- onFileChanged(filePath: string): Promise<boolean>;
53
- protected getDefaultExportClass(module: Record<string, ClassConstructor<unknown>>, filePath: string): {
54
- name: string;
55
- clazz: ClassConstructor<unknown>;
56
- };
57
- protected buildOptions(initialOptions?: Partial<ContainerOptions>): ContainerOptions;
58
- }
59
-
60
- export { Container, type ContainerDependencies, type ContainerOptions };
package/container.d.ts DELETED
@@ -1,60 +0,0 @@
1
- import { ContainerError } from './container-error.js';
2
- import { C as ClassConstructor, E as ErrorHandler, H as HTTPMethod, m as RouteHandler, I as InitiatorHandler, c as ContainerRegistry, p as RouteItem, g as MahameruMiddleware, P as ProtectedRoute, M as MahameruContainer } from './types-BmFqDpSs.js';
3
- import { ModuleError } from './module-error.js';
4
- import 'node:http';
5
- import './mahameru-response.js';
6
-
7
- /**
8
- * Container options
9
- */
10
- type ContainerOptions = {
11
- modulesPath: string;
12
- routesPath: string;
13
- appPath: string;
14
- dev: boolean;
15
- moduleType: "commonjs" | "esm";
16
- };
17
- type ContainerDependencies = {
18
- dataSources?: Record<string, any>;
19
- ContainerError: typeof ContainerError;
20
- ModuleError: typeof ModuleError;
21
- };
22
- declare class Container {
23
- #private;
24
- protected classes: Map<string, ClassConstructor>;
25
- protected _modules: Map<ClassConstructor, any>;
26
- protected _errorHandler?: ErrorHandler;
27
- protected _notFoundHandler?: Record<HTTPMethod, RouteHandler>;
28
- protected dependencies: ContainerDependencies;
29
- protected _initiatorHandler?: InitiatorHandler;
30
- readonly options: ContainerOptions;
31
- containerRegistry: ContainerRegistry;
32
- constructor(dependencies: ContainerDependencies);
33
- constructor(initialOptions: Partial<ContainerOptions>, dependencies: ContainerDependencies);
34
- get notFoundHandler(): Record<"GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "CONNECT" | "OPTIONS" | "TRACE" | "PATCH", RouteHandler> | undefined;
35
- getRouteItems(): RouteItem[];
36
- get middlewareHandler(): MahameruMiddleware | undefined;
37
- get errorHandler(): ErrorHandler | undefined;
38
- get protectedRoutes(): ProtectedRoute;
39
- get initialized(): boolean;
40
- get mahameruContainer(): MahameruContainer;
41
- discover(): Promise<void>;
42
- protected loadRoutes(currentDir?: string): Promise<void>;
43
- protected loadSingleRoute(fullPath: string, currentDir: string, baseDir: string, item: {
44
- parentPath: string;
45
- name: string;
46
- }): Promise<boolean>;
47
- protected loadModules(): Promise<void>;
48
- protected loadMiddlewareHandler(): Promise<boolean>;
49
- protected loadNotFoundHandlers(): Promise<void>;
50
- protected loadErrorHandler(): Promise<void>;
51
- protected loadInitiator(): Promise<void>;
52
- onFileChanged(filePath: string): Promise<boolean>;
53
- protected getDefaultExportClass(module: Record<string, ClassConstructor<unknown>>, filePath: string): {
54
- name: string;
55
- clazz: ClassConstructor<unknown>;
56
- };
57
- protected buildOptions(initialOptions?: Partial<ContainerOptions>): ContainerOptions;
58
- }
59
-
60
- export { Container, type ContainerDependencies, type ContainerOptions };