@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/diatrema.js
CHANGED
|
@@ -1,103 +1,121 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
import { join } from "node:path";
|
|
4
|
-
import { HttpServer } from "./http-server.js";
|
|
5
4
|
import { EventEmitter } from "./event-emitter.js";
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
import { pathToFileURL } from "node:url";
|
|
7
|
+
import { createLogger } from "./logger.js";
|
|
6
8
|
const diatremaDefaultConfig = {
|
|
7
9
|
dev: false,
|
|
8
|
-
|
|
10
|
+
debug: false,
|
|
9
11
|
rootPath: process.cwd(),
|
|
10
12
|
get appPath() {
|
|
11
|
-
if (this.isStandalone)
|
|
12
|
-
return this.rootPath;
|
|
13
13
|
return join(this.rootPath, this.dev ? this.developmentDir : this.productionDir);
|
|
14
14
|
},
|
|
15
15
|
productionDir: ".mahameru",
|
|
16
16
|
developmentDir: ".mahameru",
|
|
17
|
-
|
|
17
|
+
moduleType: "esm"
|
|
18
18
|
};
|
|
19
19
|
class Diatrema extends EventEmitter {
|
|
20
20
|
static {
|
|
21
21
|
__name(this, "Diatrema");
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
_initialized = false;
|
|
24
|
+
_isShuttingDown = false;
|
|
25
|
+
_plugins = /* @__PURE__ */ new Map();
|
|
26
|
+
logger;
|
|
27
|
+
instances = {};
|
|
28
|
+
options;
|
|
29
|
+
constructor(options) {
|
|
28
30
|
super();
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (typeof arg2 !== "undefined") {
|
|
32
|
-
this.dependencies = arg2;
|
|
33
|
-
} else {
|
|
34
|
-
this.dependencies = arg1;
|
|
35
|
-
}
|
|
31
|
+
this.options = { ...diatremaDefaultConfig, ...options };
|
|
32
|
+
this.logger = createLogger("Diatrema", this.options.debug);
|
|
36
33
|
}
|
|
37
34
|
/**
|
|
38
35
|
* Indicates whether the Mahameru server has been initialized or not.
|
|
39
36
|
* @returns {boolean}
|
|
40
37
|
*/
|
|
41
38
|
get initialized() {
|
|
42
|
-
return this
|
|
39
|
+
return this._initialized;
|
|
43
40
|
}
|
|
44
41
|
/**
|
|
45
42
|
* Indicates whether the Mahameru server is shutting down or not.
|
|
46
43
|
* @returns {boolean}
|
|
47
44
|
*/
|
|
48
45
|
get isShuttingDown() {
|
|
49
|
-
return this
|
|
46
|
+
return this._isShuttingDown;
|
|
47
|
+
}
|
|
48
|
+
get plugins() {
|
|
49
|
+
return Object.fromEntries(this._plugins);
|
|
50
50
|
}
|
|
51
|
-
/**
|
|
52
|
-
* Initialize the Mahameru server.
|
|
53
|
-
*/
|
|
54
51
|
async initialize() {
|
|
55
52
|
try {
|
|
56
|
-
if (this
|
|
53
|
+
if (this._initialized)
|
|
57
54
|
return;
|
|
58
|
-
await this.
|
|
55
|
+
await this.loadInitiator();
|
|
56
|
+
for (const plugin of this._plugins.values()) {
|
|
57
|
+
plugin.setDiatrema(this);
|
|
58
|
+
await plugin.initialize();
|
|
59
|
+
}
|
|
59
60
|
} catch (error) {
|
|
60
61
|
throw error;
|
|
61
62
|
}
|
|
62
|
-
|
|
63
|
-
this
|
|
64
|
-
|
|
63
|
+
this._initialized = true;
|
|
64
|
+
this.emit("ready", { mode: this.options.dev ? "development" : "production" });
|
|
65
|
+
}
|
|
66
|
+
setPlugin(pluginName, plugin) {
|
|
67
|
+
this._plugins.set(pluginName, plugin);
|
|
68
|
+
}
|
|
69
|
+
getPlugin(pluginName) {
|
|
70
|
+
return this._plugins.get(pluginName);
|
|
65
71
|
}
|
|
66
|
-
/**
|
|
67
|
-
* Hot reload the middleware and routes when a file changes in development mode.
|
|
68
|
-
*/
|
|
69
72
|
async devHRM(changedFile) {
|
|
70
|
-
if (!this
|
|
73
|
+
if (!this._initialized)
|
|
71
74
|
return;
|
|
72
75
|
if (changedFile) {
|
|
73
|
-
if (await this.dependencies.container.onFileChanged(changedFile))
|
|
74
|
-
this.dependencies.logger.debug(`File changed: ${changedFile}`);
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
|
-
/**
|
|
78
|
-
* Shut down the Mahameru server gracefully.
|
|
79
|
-
* @returns {Promise<void>}
|
|
80
|
-
*/
|
|
81
78
|
async shutdown() {
|
|
82
|
-
if (this
|
|
79
|
+
if (this._isShuttingDown)
|
|
83
80
|
return;
|
|
84
|
-
this
|
|
85
|
-
this.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
} catch (error) {
|
|
89
|
-
this.dependencies.logger.error("Error destroying databases", error);
|
|
81
|
+
this._isShuttingDown = true;
|
|
82
|
+
this.logger.debug("Shutting down...");
|
|
83
|
+
for (const plugin of this._plugins.values()) {
|
|
84
|
+
await plugin.destroy();
|
|
90
85
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
86
|
+
this._initialized = false;
|
|
87
|
+
this.logger.debug("Shutting down... Done");
|
|
88
|
+
}
|
|
89
|
+
async loadInitiator() {
|
|
90
|
+
if (!this.options.initiatorFilePath)
|
|
91
|
+
return;
|
|
92
|
+
const result = await this.require(this.options.moduleType, this.options.initiatorFilePath);
|
|
93
|
+
if (result) {
|
|
94
|
+
const handler = this.getDefaultExport(result, this.options.initiatorFilePath);
|
|
95
|
+
this.instances = await handler();
|
|
96
|
+
this.logger.debug(`Initiator loaded successfully. Found ${Object.keys(this.instances).length} instances.`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async require(type, resolvedFilePath) {
|
|
100
|
+
const noCache = this.options.dev;
|
|
101
|
+
if (!existsSync(resolvedFilePath))
|
|
102
|
+
return;
|
|
103
|
+
if (type === "commonjs") {
|
|
104
|
+
if (noCache) {
|
|
105
|
+
delete require.cache[resolvedFilePath];
|
|
97
106
|
}
|
|
107
|
+
return require(resolvedFilePath);
|
|
98
108
|
}
|
|
99
|
-
|
|
100
|
-
|
|
109
|
+
let fileUrl = pathToFileURL(resolvedFilePath).href;
|
|
110
|
+
if (noCache)
|
|
111
|
+
fileUrl += `?update=${Date.now()}`;
|
|
112
|
+
return await import(fileUrl);
|
|
113
|
+
}
|
|
114
|
+
getDefaultExport(module, filePath) {
|
|
115
|
+
const defaultExportName = Object.keys(module).find((key) => key === "default");
|
|
116
|
+
if (!defaultExportName)
|
|
117
|
+
throw new Error(`Module in file '${filePath}' does not have a default export.`);
|
|
118
|
+
return module[defaultExportName];
|
|
101
119
|
}
|
|
102
120
|
}
|
|
103
121
|
export {
|
package/diatrema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/diatrema.ts"],"sourcesContent":["import { join } from 'node:path';\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/diatrema.ts"],"sourcesContent":["import { join } from 'node:path';\n\nimport { EventEmitter } from \"./event-emitter\";\nimport { existsSync } from 'node:fs';\nimport { pathToFileURL } from 'node:url';\nimport type { InitiatorHandler, Instances } from './types';\nimport type { MahameruPlugin } from './mahameru-plugin';\nimport { createLogger, type Logger } from './logger';\n\nexport type DiatremaEvents = {\n ready: [data: { mode: \"development\" | \"production\"; port?: number; host?: string; }];\n};\n\nexport type DiatremaOptions = {\n dev: boolean;\n debug: boolean;\n rootPath: string;\n appPath: string;\n productionDir: string;\n developmentDir: string;\n initiatorFilePath?: string;\n moduleType: \"commonjs\" | \"esm\";\n}\n\nexport const diatremaDefaultConfig: DiatremaOptions = {\n dev: false,\n debug: false,\n rootPath: process.cwd(),\n get appPath(): string {\n return join(this.rootPath, this.dev ? this.developmentDir : this.productionDir);\n },\n productionDir: '.mahameru',\n developmentDir: '.mahameru',\n moduleType: 'esm'\n}\n\n/**\n * Main Diatrema class that orchestrates the application lifecycle.\n */\nexport default class Diatrema extends EventEmitter<DiatremaEvents> {\n protected _initialized = false;\n protected _isShuttingDown = false;\n protected _plugins = new Map<string, MahameruPlugin<any>>();\n protected logger: Logger;\n public instances: Instances = {};\n public readonly options: DiatremaOptions;\n\n constructor(options?: Partial<DiatremaOptions>) {\n super();\n\n this.options = { ...diatremaDefaultConfig, ...options };\n this.logger = createLogger('Diatrema', this.options.debug);\n }\n\n /**\n * Indicates whether the Mahameru server has been initialized or not.\n * @returns {boolean}\n */\n get initialized() {\n return this._initialized;\n }\n\n /**\n * Indicates whether the Mahameru server is shutting down or not.\n * @returns {boolean}\n */\n get isShuttingDown() {\n return this._isShuttingDown;\n }\n\n get plugins(): Record<string, MahameruPlugin<any>> {\n return Object.fromEntries(this._plugins);\n }\n\n public async initialize(): Promise<void> {\n try {\n if (this._initialized)\n return;\n\n await this.loadInitiator();\n\n for (const plugin of this._plugins.values()) {\n plugin.setDiatrema(this);\n\n await plugin.initialize();\n }\n } catch (error) {\n throw error;\n }\n\n this._initialized = true;\n\n this.emit('ready', { mode: this.options.dev ? 'development' : 'production' });\n }\n\n public setPlugin<T extends MahameruPlugin<any>>(pluginName: string, plugin: T) {\n this._plugins.set(pluginName, plugin);\n }\n\n public getPlugin<T extends MahameruPlugin<any>>(pluginName: string): T | undefined {\n return this._plugins.get(pluginName) as T | undefined;\n }\n\n public async devHRM(changedFile?: string) {\n if (!this._initialized)\n return\n\n if (changedFile) {\n // if (await this.dependencies.container.onFileChanged(changedFile))\n // this.logger.debug(`File changed: ${changedFile}`);\n }\n }\n\n public async shutdown(): Promise<void> {\n if (this._isShuttingDown)\n return\n\n this._isShuttingDown = true;\n\n this.logger.debug('Shutting down...');\n\n for (const plugin of this._plugins.values()) {\n await plugin.destroy();\n }\n\n this._initialized = false;\n this.logger.debug('Shutting down... Done');\n }\n\n protected async loadInitiator() {\n if (!this.options.initiatorFilePath)\n return;\n\n const result = await this.require<Record<'default', InitiatorHandler>>(this.options.moduleType, this.options.initiatorFilePath);\n\n if (result) {\n const handler = this.getDefaultExport<InitiatorHandler>(result, this.options.initiatorFilePath);\n\n this.instances = await handler();\n this.logger.debug(`Initiator loaded successfully. Found ${Object.keys(this.instances).length} instances.`);\n }\n }\n\n protected async require<T extends Record<string, unknown> = Record<string, unknown>>(type: \"commonjs\" | \"esm\", resolvedFilePath: string): Promise<T | undefined> {\n const noCache = this.options.dev;\n\n if (!existsSync(resolvedFilePath))\n return;\n\n if (type === \"commonjs\") {\n if (noCache) {\n delete require.cache[resolvedFilePath];\n }\n\n return require(resolvedFilePath) as T;\n }\n\n let fileUrl = pathToFileURL(resolvedFilePath).href;\n\n if (noCache)\n fileUrl += `?update=${Date.now()}`;\n\n return (await import(fileUrl)) as T;\n }\n\n protected getDefaultExport<T>(module: Record<string, T>, filePath: string) {\n const defaultExportName = Object.keys(module).find((key) => key === 'default');\n\n if (!defaultExportName)\n throw new Error(`Module in file '${filePath}' does not have a default export.`);\n\n return module[defaultExportName];\n }\n}\n"],"mappings":"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","names":[]}
|
package/helpers.cjs
CHANGED
|
@@ -21,27 +21,12 @@ var helpers_exports = {};
|
|
|
21
21
|
__export(helpers_exports, {
|
|
22
22
|
dynamicRequire: () => dynamicRequire,
|
|
23
23
|
exists: () => exists,
|
|
24
|
-
resolveWithinBase: () => resolveWithinBase
|
|
25
|
-
validateProtectedRoute: () => validateProtectedRoute
|
|
24
|
+
resolveWithinBase: () => resolveWithinBase
|
|
26
25
|
});
|
|
27
26
|
module.exports = __toCommonJS(helpers_exports);
|
|
28
27
|
var import_promises = require("node:fs/promises");
|
|
29
28
|
var import_node_path = require("node:path");
|
|
30
29
|
var import_node_url = require("node:url");
|
|
31
|
-
const matchRoutePattern = /* @__PURE__ */ __name((currentPath, routePattern) => {
|
|
32
|
-
const regexPattern = routePattern.replace(/\//g, "\\/").replace(/:[^/]+/g, "[^/]+");
|
|
33
|
-
const regex = new RegExp(`^${regexPattern}$`);
|
|
34
|
-
return regex.test(currentPath);
|
|
35
|
-
}, "matchRoutePattern");
|
|
36
|
-
const validateProtectedRoute = /* @__PURE__ */ __name((protectedRoutes, method, path) => {
|
|
37
|
-
return protectedRoutes.some((route) => {
|
|
38
|
-
if (typeof route === "string")
|
|
39
|
-
return matchRoutePattern(path, route);
|
|
40
|
-
const isPathMatch = matchRoutePattern(path, route.path);
|
|
41
|
-
const isMethodMatch = route.methods.includes(method);
|
|
42
|
-
return isPathMatch && isMethodMatch;
|
|
43
|
-
});
|
|
44
|
-
}, "validateProtectedRoute");
|
|
45
30
|
const exists = /* @__PURE__ */ __name(async (target) => {
|
|
46
31
|
try {
|
|
47
32
|
await (0, import_promises.access)(target, import_promises.constants.R_OK);
|
|
@@ -87,7 +72,6 @@ __name(dynamicRequire, "dynamicRequire");
|
|
|
87
72
|
0 && (module.exports = {
|
|
88
73
|
dynamicRequire,
|
|
89
74
|
exists,
|
|
90
|
-
resolveWithinBase
|
|
91
|
-
validateProtectedRoute
|
|
75
|
+
resolveWithinBase
|
|
92
76
|
});
|
|
93
77
|
//# sourceMappingURL=helpers.cjs.map
|
package/helpers.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/helpers.ts"],"sourcesContent":["import { access, constants } from \"node:fs/promises\";\nimport
|
|
1
|
+
{"version":3,"sources":["../src/helpers.ts"],"sourcesContent":["import { access, constants } from \"node:fs/promises\";\nimport { resolve, sep } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\n\nexport const exists = async (target: string): Promise<boolean> => {\n try {\n await access(target, constants.R_OK);\n return true;\n } catch {\n return false;\n }\n};\n\n/**\n * Checks if the target path is within the base path.\n * @param base The base directory (absolute path)\n * @param target The target path (absolute path) to check\n * @returns true if target is within base, false otherwise\n */\nfunction isWithin(base: string, target: string): boolean {\n if (target === base)\n return true;\n\n if (target.startsWith(base)) {\n const nextChar = target.charAt(base.length);\n\n return nextChar === sep;\n }\n\n return false;\n}\n\n/**\n * Resolves a target path relative to a base directory, ensuring the result is within the base.\n * Returns null if the resolved path would be outside the base.\n * @param base The base directory (absolute path)\n * @param target The target path (relative to base) to resolve\n * @returns The resolved absolute path if within base, null otherwise\n */\nexport function resolveWithinBase(base: string, target: string): string | null {\n const baseResolved = resolve(base);\n const targetResolved = resolve(base, target);\n\n if (isWithin(baseResolved, targetResolved))\n return targetResolved;\n\n return null;\n}\n\n/**\n * \n * @param type \"commonjs\" | \"esm\"\n * @param filePath string - path to resolved file: require.resolve(\"./path/to/file\")\n */\nexport async function dynamicRequire<T extends Record<string, unknown> = Record<string, unknown>>(type: \"commonjs\" | \"esm\", resolvedFilePath: string, noCache: boolean = false): Promise<T | undefined> {\n if (!(await exists(resolvedFilePath)))\n return;\n\n if (type === \"commonjs\") {\n if (noCache) {\n delete require.cache[resolvedFilePath];\n }\n\n return require(resolvedFilePath) as T;\n }\n\n let fileUrl = pathToFileURL(resolvedFilePath).href;\n\n if (noCache)\n fileUrl += `?update=${Date.now()}`;\n\n return (await import(fileUrl)) as T;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAkC;AAClC,uBAA6B;AAC7B,sBAA8B;AAEvB,MAAM,SAAS,8BAAO,WAAqC;AAC9D,MAAI;AACA,cAAM,wBAAO,QAAQ,0BAAU,IAAI;AACnC,WAAO;AAAA,EACX,QAAQ;AACJ,WAAO;AAAA,EACX;AACJ,GAPsB;AAetB,SAAS,SAAS,MAAc,QAAyB;AACrD,MAAI,WAAW;AACX,WAAO;AAEX,MAAI,OAAO,WAAW,IAAI,GAAG;AACzB,UAAM,WAAW,OAAO,OAAO,KAAK,MAAM;AAE1C,WAAO,aAAa;AAAA,EACxB;AAEA,SAAO;AACX;AAXS;AAoBF,SAAS,kBAAkB,MAAc,QAA+B;AAC3E,QAAM,mBAAe,0BAAQ,IAAI;AACjC,QAAM,qBAAiB,0BAAQ,MAAM,MAAM;AAE3C,MAAI,SAAS,cAAc,cAAc;AACrC,WAAO;AAEX,SAAO;AACX;AARgB;AAehB,eAAsB,eAA4E,MAA0B,kBAA0B,UAAmB,OAA+B;AACpM,MAAI,CAAE,MAAM,OAAO,gBAAgB;AAC/B;AAEJ,MAAI,SAAS,YAAY;AACrB,QAAI,SAAS;AACT,aAAO,QAAQ,MAAM,gBAAgB;AAAA,IACzC;AAEA,WAAO,QAAQ,gBAAgB;AAAA,EACnC;AAEA,MAAI,cAAU,+BAAc,gBAAgB,EAAE;AAE9C,MAAI;AACA,eAAW,WAAW,KAAK,IAAI,CAAC;AAEpC,SAAQ,MAAM,OAAO;AACzB;AAlBsB;","names":[]}
|
package/helpers.d.cts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import { P as ProtectedRoute } from './types-Cd6Gkoxx.cjs';
|
|
2
|
-
import 'node:http';
|
|
3
|
-
import './mahameru-response.cjs';
|
|
4
|
-
|
|
5
|
-
declare const validateProtectedRoute: (protectedRoutes: ProtectedRoute, method: string, path: string) => boolean;
|
|
6
1
|
declare const exists: (target: string) => Promise<boolean>;
|
|
7
2
|
/**
|
|
8
3
|
* Resolves a target path relative to a base directory, ensuring the result is within the base.
|
|
@@ -19,4 +14,4 @@ declare function resolveWithinBase(base: string, target: string): string | null;
|
|
|
19
14
|
*/
|
|
20
15
|
declare function dynamicRequire<T extends Record<string, unknown> = Record<string, unknown>>(type: "commonjs" | "esm", resolvedFilePath: string, noCache?: boolean): Promise<T | undefined>;
|
|
21
16
|
|
|
22
|
-
export { dynamicRequire, exists, resolveWithinBase
|
|
17
|
+
export { dynamicRequire, exists, resolveWithinBase };
|
package/helpers.d.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import { P as ProtectedRoute } from './types-BmFqDpSs.js';
|
|
2
|
-
import 'node:http';
|
|
3
|
-
import './mahameru-response.js';
|
|
4
|
-
|
|
5
|
-
declare const validateProtectedRoute: (protectedRoutes: ProtectedRoute, method: string, path: string) => boolean;
|
|
6
1
|
declare const exists: (target: string) => Promise<boolean>;
|
|
7
2
|
/**
|
|
8
3
|
* Resolves a target path relative to a base directory, ensuring the result is within the base.
|
|
@@ -19,4 +14,4 @@ declare function resolveWithinBase(base: string, target: string): string | null;
|
|
|
19
14
|
*/
|
|
20
15
|
declare function dynamicRequire<T extends Record<string, unknown> = Record<string, unknown>>(type: "commonjs" | "esm", resolvedFilePath: string, noCache?: boolean): Promise<T | undefined>;
|
|
21
16
|
|
|
22
|
-
export { dynamicRequire, exists, resolveWithinBase
|
|
17
|
+
export { dynamicRequire, exists, resolveWithinBase };
|
package/helpers.js
CHANGED
|
@@ -3,20 +3,6 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
3
3
|
import { access, constants } from "node:fs/promises";
|
|
4
4
|
import { resolve, sep } from "node:path";
|
|
5
5
|
import { pathToFileURL } from "node:url";
|
|
6
|
-
const matchRoutePattern = /* @__PURE__ */ __name((currentPath, routePattern) => {
|
|
7
|
-
const regexPattern = routePattern.replace(/\//g, "\\/").replace(/:[^/]+/g, "[^/]+");
|
|
8
|
-
const regex = new RegExp(`^${regexPattern}$`);
|
|
9
|
-
return regex.test(currentPath);
|
|
10
|
-
}, "matchRoutePattern");
|
|
11
|
-
const validateProtectedRoute = /* @__PURE__ */ __name((protectedRoutes, method, path) => {
|
|
12
|
-
return protectedRoutes.some((route) => {
|
|
13
|
-
if (typeof route === "string")
|
|
14
|
-
return matchRoutePattern(path, route);
|
|
15
|
-
const isPathMatch = matchRoutePattern(path, route.path);
|
|
16
|
-
const isMethodMatch = route.methods.includes(method);
|
|
17
|
-
return isPathMatch && isMethodMatch;
|
|
18
|
-
});
|
|
19
|
-
}, "validateProtectedRoute");
|
|
20
6
|
const exists = /* @__PURE__ */ __name(async (target) => {
|
|
21
7
|
try {
|
|
22
8
|
await access(target, constants.R_OK);
|
|
@@ -61,7 +47,6 @@ __name(dynamicRequire, "dynamicRequire");
|
|
|
61
47
|
export {
|
|
62
48
|
dynamicRequire,
|
|
63
49
|
exists,
|
|
64
|
-
resolveWithinBase
|
|
65
|
-
validateProtectedRoute
|
|
50
|
+
resolveWithinBase
|
|
66
51
|
};
|
|
67
52
|
//# sourceMappingURL=helpers.js.map
|
package/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/helpers.ts"],"sourcesContent":["import { access, constants } from \"node:fs/promises\";\nimport
|
|
1
|
+
{"version":3,"sources":["../src/helpers.ts"],"sourcesContent":["import { access, constants } from \"node:fs/promises\";\nimport { resolve, sep } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\n\nexport const exists = async (target: string): Promise<boolean> => {\n try {\n await access(target, constants.R_OK);\n return true;\n } catch {\n return false;\n }\n};\n\n/**\n * Checks if the target path is within the base path.\n * @param base The base directory (absolute path)\n * @param target The target path (absolute path) to check\n * @returns true if target is within base, false otherwise\n */\nfunction isWithin(base: string, target: string): boolean {\n if (target === base)\n return true;\n\n if (target.startsWith(base)) {\n const nextChar = target.charAt(base.length);\n\n return nextChar === sep;\n }\n\n return false;\n}\n\n/**\n * Resolves a target path relative to a base directory, ensuring the result is within the base.\n * Returns null if the resolved path would be outside the base.\n * @param base The base directory (absolute path)\n * @param target The target path (relative to base) to resolve\n * @returns The resolved absolute path if within base, null otherwise\n */\nexport function resolveWithinBase(base: string, target: string): string | null {\n const baseResolved = resolve(base);\n const targetResolved = resolve(base, target);\n\n if (isWithin(baseResolved, targetResolved))\n return targetResolved;\n\n return null;\n}\n\n/**\n * \n * @param type \"commonjs\" | \"esm\"\n * @param filePath string - path to resolved file: require.resolve(\"./path/to/file\")\n */\nexport async function dynamicRequire<T extends Record<string, unknown> = Record<string, unknown>>(type: \"commonjs\" | \"esm\", resolvedFilePath: string, noCache: boolean = false): Promise<T | undefined> {\n if (!(await exists(resolvedFilePath)))\n return;\n\n if (type === \"commonjs\") {\n if (noCache) {\n delete require.cache[resolvedFilePath];\n }\n\n return require(resolvedFilePath) as T;\n }\n\n let fileUrl = pathToFileURL(resolvedFilePath).href;\n\n if (noCache)\n fileUrl += `?update=${Date.now()}`;\n\n return (await import(fileUrl)) as T;\n}\n"],"mappings":";;AAAA,SAAS,QAAQ,iBAAiB;AAClC,SAAS,SAAS,WAAW;AAC7B,SAAS,qBAAqB;AAEvB,MAAM,SAAS,8BAAO,WAAqC;AAC9D,MAAI;AACA,UAAM,OAAO,QAAQ,UAAU,IAAI;AACnC,WAAO;AAAA,EACX,QAAQ;AACJ,WAAO;AAAA,EACX;AACJ,GAPsB;AAetB,SAAS,SAAS,MAAc,QAAyB;AACrD,MAAI,WAAW;AACX,WAAO;AAEX,MAAI,OAAO,WAAW,IAAI,GAAG;AACzB,UAAM,WAAW,OAAO,OAAO,KAAK,MAAM;AAE1C,WAAO,aAAa;AAAA,EACxB;AAEA,SAAO;AACX;AAXS;AAoBF,SAAS,kBAAkB,MAAc,QAA+B;AAC3E,QAAM,eAAe,QAAQ,IAAI;AACjC,QAAM,iBAAiB,QAAQ,MAAM,MAAM;AAE3C,MAAI,SAAS,cAAc,cAAc;AACrC,WAAO;AAEX,SAAO;AACX;AARgB;AAehB,eAAsB,eAA4E,MAA0B,kBAA0B,UAAmB,OAA+B;AACpM,MAAI,CAAE,MAAM,OAAO,gBAAgB;AAC/B;AAEJ,MAAI,SAAS,YAAY;AACrB,QAAI,SAAS;AACT,aAAO,QAAQ,MAAM,gBAAgB;AAAA,IACzC;AAEA,WAAO,QAAQ,gBAAgB;AAAA,EACnC;AAEA,MAAI,UAAU,cAAc,gBAAgB,EAAE;AAE9C,MAAI;AACA,eAAW,WAAW,KAAK,IAAI,CAAC;AAEpC,SAAQ,MAAM,OAAO;AACzB;AAlBsB;","names":[]}
|
package/index.cjs
CHANGED
|
@@ -32,35 +32,21 @@ __export(index_exports, {
|
|
|
32
32
|
default: () => index_default
|
|
33
33
|
});
|
|
34
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
35
|
__reExport(index_exports, require('./diatrema.cjs'), module.exports);
|
|
38
|
-
__reExport(index_exports, require('./
|
|
39
|
-
__reExport(index_exports, require('./http-server.cjs'), module.exports);
|
|
36
|
+
__reExport(index_exports, require('./event-emitter.cjs'), module.exports);
|
|
40
37
|
__reExport(index_exports, require('./logger.cjs'), module.exports);
|
|
41
38
|
__reExport(index_exports, require('./mahameru-error.cjs'), module.exports);
|
|
42
|
-
__reExport(index_exports, require('./mahameru-
|
|
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);
|
|
39
|
+
__reExport(index_exports, require('./mahameru-plugin.cjs'), module.exports);
|
|
47
40
|
__reExport(index_exports, require('./types.cjs'), module.exports);
|
|
48
41
|
var import_diatrema = __toESM(require('./diatrema.cjs'), 1);
|
|
49
42
|
var index_default = import_diatrema.default;
|
|
50
43
|
// Annotate the CommonJS export names for ESM import in node:
|
|
51
44
|
0 && (module.exports = {
|
|
52
|
-
...require('./container-error.cjs'),
|
|
53
|
-
...require('./container.cjs'),
|
|
54
45
|
...require('./diatrema.cjs'),
|
|
55
|
-
...require('./
|
|
56
|
-
...require('./http-server.cjs'),
|
|
46
|
+
...require('./event-emitter.cjs'),
|
|
57
47
|
...require('./logger.cjs'),
|
|
58
48
|
...require('./mahameru-error.cjs'),
|
|
59
|
-
...require('./mahameru-
|
|
60
|
-
...require('./mahameru-response.cjs'),
|
|
61
|
-
...require('./mahameru-server-error.cjs'),
|
|
62
|
-
...require('./module-error.cjs'),
|
|
63
|
-
...require('./route.cjs'),
|
|
49
|
+
...require('./mahameru-plugin.cjs'),
|
|
64
50
|
...require('./types.cjs')
|
|
65
51
|
});
|
|
66
52
|
//# sourceMappingURL=index.cjs.map
|
package/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './diatrema'\r\nexport * from './event-emitter'\r\nexport * from './logger'\r\nexport * from './mahameru-error'\r\nexport * from './mahameru-plugin'\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,uBAAd;AACA,0BAAc,4BADd;AAEA,0BAAc,qBAFd;AAGA,0BAAc,6BAHd;AAIA,0BAAc,8BAJd;AAKA,0BAAc,oBALd;AAOA,sBAAqB;AAErB,IAAO,gBAAQ,gBAAAA;","names":["Diatrema"]}
|
package/index.d.cts
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
|
|
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';
|
|
1
|
+
import { D as Diatrema } from './diatrema-Fd7aehcd.cjs';
|
|
2
|
+
export { B as BaseGeneratorOptions, a as BasePluginOptions, b as DiatremaEvents, c as DiatremaOptions, G as Generator, M as MahameruPlugin, d as diatremaDefaultConfig } from './diatrema-Fd7aehcd.cjs';
|
|
3
|
+
export { EventEmitter } from './event-emitter.cjs';
|
|
7
4
|
export { Logger, createLogger } from './logger.cjs';
|
|
8
5
|
export { MahameruError } from './mahameru-error.cjs';
|
|
9
|
-
export {
|
|
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';
|
|
6
|
+
export { InitiatorHandler, Instances } from './types.cjs';
|
|
16
7
|
|
|
17
8
|
|
|
18
9
|
|
package/index.d.ts
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
|
|
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';
|
|
1
|
+
import { D as Diatrema } from './diatrema-DBO4yaCD.js';
|
|
2
|
+
export { B as BaseGeneratorOptions, a as BasePluginOptions, b as DiatremaEvents, c as DiatremaOptions, G as Generator, M as MahameruPlugin, d as diatremaDefaultConfig } from './diatrema-DBO4yaCD.js';
|
|
3
|
+
export { EventEmitter } from './event-emitter.js';
|
|
7
4
|
export { Logger, createLogger } from './logger.js';
|
|
8
5
|
export { MahameruError } from './mahameru-error.js';
|
|
9
|
-
export {
|
|
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';
|
|
6
|
+
export { InitiatorHandler, Instances } from './types.js';
|
|
16
7
|
|
|
17
8
|
|
|
18
9
|
|
package/index.js
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
export * from "./container-error.js";
|
|
2
|
-
export * from "./container.js";
|
|
3
1
|
export * from "./diatrema.js";
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./http-server.js";
|
|
2
|
+
export * from "./event-emitter.js";
|
|
6
3
|
export * from "./logger.js";
|
|
7
4
|
export * from "./mahameru-error.js";
|
|
8
|
-
export * from "./mahameru-
|
|
9
|
-
export * from "./mahameru-response.js";
|
|
10
|
-
export * from "./mahameru-server-error.js";
|
|
11
|
-
export * from "./module-error.js";
|
|
12
|
-
export * from "./route.js";
|
|
5
|
+
export * from "./mahameru-plugin.js";
|
|
13
6
|
export * from "./types.js";
|
|
14
7
|
import Diatrema from "./diatrema.js";
|
|
15
8
|
var index_default = Diatrema;
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './diatrema'\r\nexport * from './event-emitter'\r\nexport * from './logger'\r\nexport * from './mahameru-error'\r\nexport * from './mahameru-plugin'\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;AAEd,OAAO,cAAc;AAErB,IAAO,gBAAQ;","names":[]}
|
package/logger.cjs
CHANGED
|
@@ -22,25 +22,30 @@ __export(logger_exports, {
|
|
|
22
22
|
createLogger: () => createLogger
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(logger_exports);
|
|
25
|
-
const createLogger = /* @__PURE__ */ __name((debug = false) => {
|
|
25
|
+
const createLogger = /* @__PURE__ */ __name((name, debug = false) => {
|
|
26
|
+
if (typeof name === "string") {
|
|
27
|
+
name = [`[${name}]`];
|
|
28
|
+
} else {
|
|
29
|
+
name = name.map((item) => `[${item}]`);
|
|
30
|
+
}
|
|
26
31
|
return {
|
|
27
32
|
info: /* @__PURE__ */ __name((...data) => {
|
|
28
33
|
if (debug) {
|
|
29
|
-
console.log("[Info]", ...data);
|
|
34
|
+
console.log(...name, "[Info]", ...data);
|
|
30
35
|
return;
|
|
31
36
|
}
|
|
32
37
|
}, "info"),
|
|
33
38
|
error: /* @__PURE__ */ __name((message, error) => {
|
|
34
|
-
console.error(`[Error] ${message}`, error);
|
|
39
|
+
console.error(...name, `[Error] ${message}`, error);
|
|
35
40
|
}, "error"),
|
|
36
41
|
warn: /* @__PURE__ */ __name((...data) => {
|
|
37
42
|
if (debug) {
|
|
38
|
-
console.warn("[Warn]", ...data);
|
|
43
|
+
console.warn(...name, "[Warn]", ...data);
|
|
39
44
|
}
|
|
40
45
|
}, "warn"),
|
|
41
46
|
debug: /* @__PURE__ */ __name((...data) => {
|
|
42
47
|
if (debug) {
|
|
43
|
-
console.debug("[Debug]", ...data);
|
|
48
|
+
console.debug(...name, "[Debug]", ...data);
|
|
44
49
|
}
|
|
45
50
|
}, "debug")
|
|
46
51
|
};
|
package/logger.cjs.map
CHANGED
|
@@ -1 +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;
|
|
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 = (name: string | string[], debug: boolean = false): Logger => {\r\n if (typeof name === 'string') {\r\n name = [`[${name}]`];\r\n } else {\r\n name = name.map(item => `[${item}]`);\r\n }\r\n return {\r\n info: (...data: any[]) => {\r\n if (debug) {\r\n console.log(...name, '[Info]', ...data)\r\n\r\n return\r\n }\r\n },\r\n error: (message, error) => {\r\n console.error(...name, `[Error] ${message}`, error);\r\n },\r\n warn: (...data: any[]) => {\r\n if (debug) {\r\n console.warn(...name, '[Warn]', ...data)\r\n }\r\n },\r\n debug: (...data: any[]) => {\r\n if (debug) {\r\n console.debug(...name, '[Debug]', ...data)\r\n }\r\n }\r\n };\r\n};\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOO,MAAM,eAAe,wBAAC,MAAyB,QAAiB,UAAkB;AACrF,MAAI,OAAO,SAAS,UAAU;AAC1B,WAAO,CAAC,IAAI,IAAI,GAAG;AAAA,EACvB,OAAO;AACH,WAAO,KAAK,IAAI,UAAQ,IAAI,IAAI,GAAG;AAAA,EACvC;AACA,SAAO;AAAA,IACH,MAAM,2BAAI,SAAgB;AACtB,UAAI,OAAO;AACP,gBAAQ,IAAI,GAAG,MAAM,UAAU,GAAG,IAAI;AAEtC;AAAA,MACJ;AAAA,IACJ,GANM;AAAA,IAON,OAAO,wBAAC,SAAS,UAAU;AACvB,cAAQ,MAAM,GAAG,MAAM,WAAW,OAAO,IAAI,KAAK;AAAA,IACtD,GAFO;AAAA,IAGP,MAAM,2BAAI,SAAgB;AACtB,UAAI,OAAO;AACP,gBAAQ,KAAK,GAAG,MAAM,UAAU,GAAG,IAAI;AAAA,MAC3C;AAAA,IACJ,GAJM;AAAA,IAKN,OAAO,2BAAI,SAAgB;AACvB,UAAI,OAAO;AACP,gBAAQ,MAAM,GAAG,MAAM,WAAW,GAAG,IAAI;AAAA,MAC7C;AAAA,IACJ,GAJO;AAAA,EAKX;AACJ,GA5B4B;","names":[]}
|
package/logger.d.cts
CHANGED
package/logger.d.ts
CHANGED
package/logger.js
CHANGED
|
@@ -1,24 +1,29 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
const createLogger = /* @__PURE__ */ __name((debug = false) => {
|
|
3
|
+
const createLogger = /* @__PURE__ */ __name((name, debug = false) => {
|
|
4
|
+
if (typeof name === "string") {
|
|
5
|
+
name = [`[${name}]`];
|
|
6
|
+
} else {
|
|
7
|
+
name = name.map((item) => `[${item}]`);
|
|
8
|
+
}
|
|
4
9
|
return {
|
|
5
10
|
info: /* @__PURE__ */ __name((...data) => {
|
|
6
11
|
if (debug) {
|
|
7
|
-
console.log("[Info]", ...data);
|
|
12
|
+
console.log(...name, "[Info]", ...data);
|
|
8
13
|
return;
|
|
9
14
|
}
|
|
10
15
|
}, "info"),
|
|
11
16
|
error: /* @__PURE__ */ __name((message, error) => {
|
|
12
|
-
console.error(`[Error] ${message}`, error);
|
|
17
|
+
console.error(...name, `[Error] ${message}`, error);
|
|
13
18
|
}, "error"),
|
|
14
19
|
warn: /* @__PURE__ */ __name((...data) => {
|
|
15
20
|
if (debug) {
|
|
16
|
-
console.warn("[Warn]", ...data);
|
|
21
|
+
console.warn(...name, "[Warn]", ...data);
|
|
17
22
|
}
|
|
18
23
|
}, "warn"),
|
|
19
24
|
debug: /* @__PURE__ */ __name((...data) => {
|
|
20
25
|
if (debug) {
|
|
21
|
-
console.debug("[Debug]", ...data);
|
|
26
|
+
console.debug(...name, "[Debug]", ...data);
|
|
22
27
|
}
|
|
23
28
|
}, "debug")
|
|
24
29
|
};
|
package/logger.js.map
CHANGED
|
@@ -1 +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":";;AAOO,MAAM,eAAe,wBAAC,QAAiB,UAAkB;
|
|
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 = (name: string | string[], debug: boolean = false): Logger => {\r\n if (typeof name === 'string') {\r\n name = [`[${name}]`];\r\n } else {\r\n name = name.map(item => `[${item}]`);\r\n }\r\n return {\r\n info: (...data: any[]) => {\r\n if (debug) {\r\n console.log(...name, '[Info]', ...data)\r\n\r\n return\r\n }\r\n },\r\n error: (message, error) => {\r\n console.error(...name, `[Error] ${message}`, error);\r\n },\r\n warn: (...data: any[]) => {\r\n if (debug) {\r\n console.warn(...name, '[Warn]', ...data)\r\n }\r\n },\r\n debug: (...data: any[]) => {\r\n if (debug) {\r\n console.debug(...name, '[Debug]', ...data)\r\n }\r\n }\r\n };\r\n};\r\n"],"mappings":";;AAOO,MAAM,eAAe,wBAAC,MAAyB,QAAiB,UAAkB;AACrF,MAAI,OAAO,SAAS,UAAU;AAC1B,WAAO,CAAC,IAAI,IAAI,GAAG;AAAA,EACvB,OAAO;AACH,WAAO,KAAK,IAAI,UAAQ,IAAI,IAAI,GAAG;AAAA,EACvC;AACA,SAAO;AAAA,IACH,MAAM,2BAAI,SAAgB;AACtB,UAAI,OAAO;AACP,gBAAQ,IAAI,GAAG,MAAM,UAAU,GAAG,IAAI;AAEtC;AAAA,MACJ;AAAA,IACJ,GANM;AAAA,IAON,OAAO,wBAAC,SAAS,UAAU;AACvB,cAAQ,MAAM,GAAG,MAAM,WAAW,OAAO,IAAI,KAAK;AAAA,IACtD,GAFO;AAAA,IAGP,MAAM,2BAAI,SAAgB;AACtB,UAAI,OAAO;AACP,gBAAQ,KAAK,GAAG,MAAM,UAAU,GAAG,IAAI;AAAA,MAC3C;AAAA,IACJ,GAJM;AAAA,IAKN,OAAO,2BAAI,SAAgB;AACvB,UAAI,OAAO;AACP,gBAAQ,MAAM,GAAG,MAAM,WAAW,GAAG,IAAI;AAAA,MAC7C;AAAA,IACJ,GAJO;AAAA,EAKX;AACJ,GA5B4B;","names":[]}
|