@mahameru/diatrema 0.0.1 → 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.
- package/diatrema-Bk12jngx.d.ts +93 -0
- package/diatrema-CyKJKZv_.d.cts +93 -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 +109 -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 +85 -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 -382
- 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 -359
- 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
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { EventEmitter } from './event-emitter.js';
|
|
2
|
+
import { Instances } from './types.js';
|
|
3
|
+
import { Logger } from './logger.js';
|
|
4
|
+
|
|
5
|
+
interface BasePluginOptions {
|
|
6
|
+
debug?: boolean;
|
|
7
|
+
}
|
|
8
|
+
declare abstract class MahameruPlugin<O extends BasePluginOptions = BasePluginOptions> {
|
|
9
|
+
abstract readonly name: string;
|
|
10
|
+
abstract readonly slugName: string;
|
|
11
|
+
protected logger: Logger;
|
|
12
|
+
protected diatrema: Diatrema;
|
|
13
|
+
protected _options: O;
|
|
14
|
+
protected _initialized: boolean;
|
|
15
|
+
protected _isShuttingDown: boolean;
|
|
16
|
+
protected _typesGenerator?: TypesGenerator;
|
|
17
|
+
constructor(options: Partial<O>);
|
|
18
|
+
get initialized(): boolean;
|
|
19
|
+
get options(): O;
|
|
20
|
+
get typesGenerator(): TypesGenerator<BaseTypesGeneratorOptions> | undefined;
|
|
21
|
+
set outputTypesDirPath(outputTypesDirPath: string);
|
|
22
|
+
setDiatrema(diatrema: Diatrema): void;
|
|
23
|
+
initialize(): Promise<void>;
|
|
24
|
+
destroy(): Promise<void>;
|
|
25
|
+
protected abstract boot(options?: Partial<O>): Promise<void> | void;
|
|
26
|
+
protected abstract terminate(): Promise<void> | void;
|
|
27
|
+
}
|
|
28
|
+
interface BaseTypesGeneratorOptions {
|
|
29
|
+
debug?: boolean;
|
|
30
|
+
}
|
|
31
|
+
declare abstract class TypesGenerator<O extends BaseTypesGeneratorOptions = BaseTypesGeneratorOptions> {
|
|
32
|
+
protected logger: Logger;
|
|
33
|
+
protected _diatrema: Diatrema;
|
|
34
|
+
protected _options: O;
|
|
35
|
+
protected _outputTypesDirPath: string;
|
|
36
|
+
constructor(options: Partial<O>);
|
|
37
|
+
set diatrema(diatrema: Diatrema);
|
|
38
|
+
set outputTypesDirPath(outputTypesDirPath: string);
|
|
39
|
+
generate(): Promise<void>;
|
|
40
|
+
protected abstract _generate(): Promise<Record<string, any>>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
type DiatremaEvents = {
|
|
44
|
+
ready: [data: {
|
|
45
|
+
mode: "development" | "production";
|
|
46
|
+
port?: number;
|
|
47
|
+
host?: string;
|
|
48
|
+
}];
|
|
49
|
+
};
|
|
50
|
+
type DiatremaOptions = {
|
|
51
|
+
dev: boolean;
|
|
52
|
+
debug: boolean;
|
|
53
|
+
rootPath: string;
|
|
54
|
+
appPath: string;
|
|
55
|
+
productionDir: string;
|
|
56
|
+
developmentDir: string;
|
|
57
|
+
initiatorFilePath?: string;
|
|
58
|
+
moduleType: "commonjs" | "esm";
|
|
59
|
+
};
|
|
60
|
+
declare const diatremaDefaultConfig: DiatremaOptions;
|
|
61
|
+
/**
|
|
62
|
+
* Main Diatrema class that orchestrates the application lifecycle.
|
|
63
|
+
*/
|
|
64
|
+
declare class Diatrema extends EventEmitter<DiatremaEvents> {
|
|
65
|
+
protected _initialized: boolean;
|
|
66
|
+
protected _isShuttingDown: boolean;
|
|
67
|
+
protected _plugins: Map<string, MahameruPlugin<any>>;
|
|
68
|
+
protected logger: Logger;
|
|
69
|
+
instances: Instances;
|
|
70
|
+
readonly options: DiatremaOptions;
|
|
71
|
+
constructor(options?: Partial<DiatremaOptions>);
|
|
72
|
+
/**
|
|
73
|
+
* Indicates whether the Mahameru server has been initialized or not.
|
|
74
|
+
* @returns {boolean}
|
|
75
|
+
*/
|
|
76
|
+
get initialized(): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Indicates whether the Mahameru server is shutting down or not.
|
|
79
|
+
* @returns {boolean}
|
|
80
|
+
*/
|
|
81
|
+
get isShuttingDown(): boolean;
|
|
82
|
+
get plugins(): Record<string, MahameruPlugin<any>>;
|
|
83
|
+
initialize(): Promise<void>;
|
|
84
|
+
setPlugin<T extends MahameruPlugin<any>>(pluginName: string, plugin: T): void;
|
|
85
|
+
getPlugin<T extends MahameruPlugin<any>>(pluginName: string): T | undefined;
|
|
86
|
+
devHRM(changedFile?: string): Promise<void>;
|
|
87
|
+
shutdown(): Promise<void>;
|
|
88
|
+
protected loadInitiator(): Promise<void>;
|
|
89
|
+
protected require<T extends Record<string, unknown> = Record<string, unknown>>(type: "commonjs" | "esm", resolvedFilePath: string): Promise<T | undefined>;
|
|
90
|
+
protected getDefaultExport<T>(module: Record<string, T>, filePath: string): T;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { type BasePluginOptions as B, Diatrema as D, MahameruPlugin as M, TypesGenerator as T, type BaseTypesGeneratorOptions as a, type DiatremaEvents as b, type DiatremaOptions as c, diatremaDefaultConfig as d };
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { EventEmitter } from './event-emitter.cjs';
|
|
2
|
+
import { Instances } from './types.cjs';
|
|
3
|
+
import { Logger } from './logger.cjs';
|
|
4
|
+
|
|
5
|
+
interface BasePluginOptions {
|
|
6
|
+
debug?: boolean;
|
|
7
|
+
}
|
|
8
|
+
declare abstract class MahameruPlugin<O extends BasePluginOptions = BasePluginOptions> {
|
|
9
|
+
abstract readonly name: string;
|
|
10
|
+
abstract readonly slugName: string;
|
|
11
|
+
protected logger: Logger;
|
|
12
|
+
protected diatrema: Diatrema;
|
|
13
|
+
protected _options: O;
|
|
14
|
+
protected _initialized: boolean;
|
|
15
|
+
protected _isShuttingDown: boolean;
|
|
16
|
+
protected _typesGenerator?: TypesGenerator;
|
|
17
|
+
constructor(options: Partial<O>);
|
|
18
|
+
get initialized(): boolean;
|
|
19
|
+
get options(): O;
|
|
20
|
+
get typesGenerator(): TypesGenerator<BaseTypesGeneratorOptions> | undefined;
|
|
21
|
+
set outputTypesDirPath(outputTypesDirPath: string);
|
|
22
|
+
setDiatrema(diatrema: Diatrema): void;
|
|
23
|
+
initialize(): Promise<void>;
|
|
24
|
+
destroy(): Promise<void>;
|
|
25
|
+
protected abstract boot(options?: Partial<O>): Promise<void> | void;
|
|
26
|
+
protected abstract terminate(): Promise<void> | void;
|
|
27
|
+
}
|
|
28
|
+
interface BaseTypesGeneratorOptions {
|
|
29
|
+
debug?: boolean;
|
|
30
|
+
}
|
|
31
|
+
declare abstract class TypesGenerator<O extends BaseTypesGeneratorOptions = BaseTypesGeneratorOptions> {
|
|
32
|
+
protected logger: Logger;
|
|
33
|
+
protected _diatrema: Diatrema;
|
|
34
|
+
protected _options: O;
|
|
35
|
+
protected _outputTypesDirPath: string;
|
|
36
|
+
constructor(options: Partial<O>);
|
|
37
|
+
set diatrema(diatrema: Diatrema);
|
|
38
|
+
set outputTypesDirPath(outputTypesDirPath: string);
|
|
39
|
+
generate(): Promise<void>;
|
|
40
|
+
protected abstract _generate(): Promise<Record<string, any>>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
type DiatremaEvents = {
|
|
44
|
+
ready: [data: {
|
|
45
|
+
mode: "development" | "production";
|
|
46
|
+
port?: number;
|
|
47
|
+
host?: string;
|
|
48
|
+
}];
|
|
49
|
+
};
|
|
50
|
+
type DiatremaOptions = {
|
|
51
|
+
dev: boolean;
|
|
52
|
+
debug: boolean;
|
|
53
|
+
rootPath: string;
|
|
54
|
+
appPath: string;
|
|
55
|
+
productionDir: string;
|
|
56
|
+
developmentDir: string;
|
|
57
|
+
initiatorFilePath?: string;
|
|
58
|
+
moduleType: "commonjs" | "esm";
|
|
59
|
+
};
|
|
60
|
+
declare const diatremaDefaultConfig: DiatremaOptions;
|
|
61
|
+
/**
|
|
62
|
+
* Main Diatrema class that orchestrates the application lifecycle.
|
|
63
|
+
*/
|
|
64
|
+
declare class Diatrema extends EventEmitter<DiatremaEvents> {
|
|
65
|
+
protected _initialized: boolean;
|
|
66
|
+
protected _isShuttingDown: boolean;
|
|
67
|
+
protected _plugins: Map<string, MahameruPlugin<any>>;
|
|
68
|
+
protected logger: Logger;
|
|
69
|
+
instances: Instances;
|
|
70
|
+
readonly options: DiatremaOptions;
|
|
71
|
+
constructor(options?: Partial<DiatremaOptions>);
|
|
72
|
+
/**
|
|
73
|
+
* Indicates whether the Mahameru server has been initialized or not.
|
|
74
|
+
* @returns {boolean}
|
|
75
|
+
*/
|
|
76
|
+
get initialized(): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Indicates whether the Mahameru server is shutting down or not.
|
|
79
|
+
* @returns {boolean}
|
|
80
|
+
*/
|
|
81
|
+
get isShuttingDown(): boolean;
|
|
82
|
+
get plugins(): Record<string, MahameruPlugin<any>>;
|
|
83
|
+
initialize(): Promise<void>;
|
|
84
|
+
setPlugin<T extends MahameruPlugin<any>>(pluginName: string, plugin: T): void;
|
|
85
|
+
getPlugin<T extends MahameruPlugin<any>>(pluginName: string): T | undefined;
|
|
86
|
+
devHRM(changedFile?: string): Promise<void>;
|
|
87
|
+
shutdown(): Promise<void>;
|
|
88
|
+
protected loadInitiator(): Promise<void>;
|
|
89
|
+
protected require<T extends Record<string, unknown> = Record<string, unknown>>(type: "commonjs" | "esm", resolvedFilePath: string): Promise<T | undefined>;
|
|
90
|
+
protected getDefaultExport<T>(module: Record<string, T>, filePath: string): T;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { type BasePluginOptions as B, Diatrema as D, MahameruPlugin as M, TypesGenerator as T, type BaseTypesGeneratorOptions as a, type DiatremaEvents as b, type DiatremaOptions as c, diatremaDefaultConfig as d };
|
package/diatrema.cjs
CHANGED
|
@@ -24,103 +24,121 @@ __export(diatrema_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(diatrema_exports);
|
|
26
26
|
var import_node_path = require("node:path");
|
|
27
|
-
var import_http_server = require('./http-server.cjs');
|
|
28
27
|
var import_event_emitter = require('./event-emitter.cjs');
|
|
28
|
+
var import_node_fs = require("node:fs");
|
|
29
|
+
var import_node_url = require("node:url");
|
|
30
|
+
var import_logger = require('./logger.cjs');
|
|
29
31
|
const diatremaDefaultConfig = {
|
|
30
32
|
dev: false,
|
|
31
|
-
|
|
33
|
+
debug: false,
|
|
32
34
|
rootPath: process.cwd(),
|
|
33
35
|
get appPath() {
|
|
34
|
-
if (this.isStandalone)
|
|
35
|
-
return this.rootPath;
|
|
36
36
|
return (0, import_node_path.join)(this.rootPath, this.dev ? this.developmentDir : this.productionDir);
|
|
37
37
|
},
|
|
38
38
|
productionDir: ".mahameru",
|
|
39
39
|
developmentDir: ".mahameru",
|
|
40
|
-
|
|
40
|
+
moduleType: "esm"
|
|
41
41
|
};
|
|
42
42
|
class Diatrema extends import_event_emitter.EventEmitter {
|
|
43
43
|
static {
|
|
44
44
|
__name(this, "Diatrema");
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
_initialized = false;
|
|
47
|
+
_isShuttingDown = false;
|
|
48
|
+
_plugins = /* @__PURE__ */ new Map();
|
|
49
|
+
logger;
|
|
50
|
+
instances = {};
|
|
51
|
+
options;
|
|
52
|
+
constructor(options) {
|
|
51
53
|
super();
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (typeof arg2 !== "undefined") {
|
|
55
|
-
this.dependencies = arg2;
|
|
56
|
-
} else {
|
|
57
|
-
this.dependencies = arg1;
|
|
58
|
-
}
|
|
54
|
+
this.options = { ...diatremaDefaultConfig, ...options };
|
|
55
|
+
this.logger = (0, import_logger.createLogger)("Diatrema", this.options.debug);
|
|
59
56
|
}
|
|
60
57
|
/**
|
|
61
58
|
* Indicates whether the Mahameru server has been initialized or not.
|
|
62
59
|
* @returns {boolean}
|
|
63
60
|
*/
|
|
64
61
|
get initialized() {
|
|
65
|
-
return this
|
|
62
|
+
return this._initialized;
|
|
66
63
|
}
|
|
67
64
|
/**
|
|
68
65
|
* Indicates whether the Mahameru server is shutting down or not.
|
|
69
66
|
* @returns {boolean}
|
|
70
67
|
*/
|
|
71
68
|
get isShuttingDown() {
|
|
72
|
-
return this
|
|
69
|
+
return this._isShuttingDown;
|
|
70
|
+
}
|
|
71
|
+
get plugins() {
|
|
72
|
+
return Object.fromEntries(this._plugins);
|
|
73
73
|
}
|
|
74
|
-
/**
|
|
75
|
-
* Initialize the Mahameru server.
|
|
76
|
-
*/
|
|
77
74
|
async initialize() {
|
|
78
75
|
try {
|
|
79
|
-
if (this
|
|
76
|
+
if (this._initialized)
|
|
80
77
|
return;
|
|
81
|
-
await this.
|
|
78
|
+
await this.loadInitiator();
|
|
79
|
+
for (const plugin of this._plugins.values()) {
|
|
80
|
+
plugin.setDiatrema(this);
|
|
81
|
+
await plugin.initialize();
|
|
82
|
+
}
|
|
82
83
|
} catch (error) {
|
|
83
84
|
throw error;
|
|
84
85
|
}
|
|
85
|
-
|
|
86
|
-
this
|
|
87
|
-
|
|
86
|
+
this._initialized = true;
|
|
87
|
+
this.emit("ready", { mode: this.options.dev ? "development" : "production" });
|
|
88
|
+
}
|
|
89
|
+
setPlugin(pluginName, plugin) {
|
|
90
|
+
this._plugins.set(pluginName, plugin);
|
|
91
|
+
}
|
|
92
|
+
getPlugin(pluginName) {
|
|
93
|
+
return this._plugins.get(pluginName);
|
|
88
94
|
}
|
|
89
|
-
/**
|
|
90
|
-
* Hot reload the middleware and routes when a file changes in development mode.
|
|
91
|
-
*/
|
|
92
95
|
async devHRM(changedFile) {
|
|
93
|
-
if (!this
|
|
96
|
+
if (!this._initialized)
|
|
94
97
|
return;
|
|
95
98
|
if (changedFile) {
|
|
96
|
-
if (await this.dependencies.container.onFileChanged(changedFile))
|
|
97
|
-
this.dependencies.logger.debug(`File changed: ${changedFile}`);
|
|
98
99
|
}
|
|
99
100
|
}
|
|
100
|
-
/**
|
|
101
|
-
* Shut down the Mahameru server gracefully.
|
|
102
|
-
* @returns {Promise<void>}
|
|
103
|
-
*/
|
|
104
101
|
async shutdown() {
|
|
105
|
-
if (this
|
|
102
|
+
if (this._isShuttingDown)
|
|
106
103
|
return;
|
|
107
|
-
this
|
|
108
|
-
this.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
} catch (error) {
|
|
112
|
-
this.dependencies.logger.error("Error destroying databases", error);
|
|
104
|
+
this._isShuttingDown = true;
|
|
105
|
+
this.logger.debug("Shutting down...");
|
|
106
|
+
for (const plugin of this._plugins.values()) {
|
|
107
|
+
await plugin.destroy();
|
|
113
108
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
109
|
+
this._initialized = false;
|
|
110
|
+
this.logger.debug("Shutting down... Done");
|
|
111
|
+
}
|
|
112
|
+
async loadInitiator() {
|
|
113
|
+
if (!this.options.initiatorFilePath)
|
|
114
|
+
return;
|
|
115
|
+
const result = await this.require(this.options.moduleType, this.options.initiatorFilePath);
|
|
116
|
+
if (result) {
|
|
117
|
+
const handler = this.getDefaultExport(result, this.options.initiatorFilePath);
|
|
118
|
+
this.instances = await handler();
|
|
119
|
+
this.logger.debug(`Initiator loaded successfully. Found ${Object.keys(this.instances).length} instances.`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
async require(type, resolvedFilePath) {
|
|
123
|
+
const noCache = this.options.dev;
|
|
124
|
+
if (!(0, import_node_fs.existsSync)(resolvedFilePath))
|
|
125
|
+
return;
|
|
126
|
+
if (type === "commonjs") {
|
|
127
|
+
if (noCache) {
|
|
128
|
+
delete require.cache[resolvedFilePath];
|
|
120
129
|
}
|
|
130
|
+
return require(resolvedFilePath);
|
|
121
131
|
}
|
|
122
|
-
|
|
123
|
-
|
|
132
|
+
let fileUrl = (0, import_node_url.pathToFileURL)(resolvedFilePath).href;
|
|
133
|
+
if (noCache)
|
|
134
|
+
fileUrl += `?update=${Date.now()}`;
|
|
135
|
+
return await import(fileUrl);
|
|
136
|
+
}
|
|
137
|
+
getDefaultExport(module2, filePath) {
|
|
138
|
+
const defaultExportName = Object.keys(module2).find((key) => key === "default");
|
|
139
|
+
if (!defaultExportName)
|
|
140
|
+
throw new Error(`Module in file '${filePath}' does not have a default export.`);
|
|
141
|
+
return module2[defaultExportName];
|
|
124
142
|
}
|
|
125
143
|
}
|
|
126
144
|
// Annotate the CommonJS export names for ESM import in node:
|
package/diatrema.cjs.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":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAqB;AAEr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ACzB;AAAA,EAEU,iBAAoBA,SAA2B,UAAkB;AACvE,UAAM,oBAAoB,OAAO,KAAKA,OAAM,EAAE,KAAK,CAAC,QAAQ,QAAQ,SAAS;AAE7E,QAAI,CAAC;AACD,YAAM,IAAI,MAAM,mBAAmB,QAAQ,mCAAmC;AAElF,WAAOA,QAAO,iBAAiB;AAAA,EACnC;AACJ;","names":["module"]}
|
package/diatrema.d.cts
CHANGED
|
@@ -1,73 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { Route } from './route.cjs';
|
|
5
|
-
import { Logger } from './logger.cjs';
|
|
6
|
-
import 'node:http';
|
|
7
|
-
import './mahameru-response.cjs';
|
|
8
|
-
import './types-Cd6Gkoxx.cjs';
|
|
9
|
-
import './http-server-error.cjs';
|
|
10
|
-
import './mahameru-server-error.cjs';
|
|
11
|
-
import './container-error.cjs';
|
|
12
|
-
import './module-error.cjs';
|
|
13
|
-
|
|
14
|
-
type DiatremaEvents = {
|
|
15
|
-
ready: [data: {
|
|
16
|
-
mode: "development" | "production";
|
|
17
|
-
port: number;
|
|
18
|
-
host: string;
|
|
19
|
-
}];
|
|
20
|
-
};
|
|
21
|
-
type DiatremaOptions = {
|
|
22
|
-
dev: boolean;
|
|
23
|
-
isStandalone: boolean;
|
|
24
|
-
rootPath: string;
|
|
25
|
-
appPath: string;
|
|
26
|
-
routesDir: string;
|
|
27
|
-
productionDir: string;
|
|
28
|
-
developmentDir: string;
|
|
29
|
-
};
|
|
30
|
-
type DiatremaDependencies = {
|
|
31
|
-
container: Container;
|
|
32
|
-
route: Route;
|
|
33
|
-
httpServer: HttpServer;
|
|
34
|
-
logger: Logger;
|
|
35
|
-
};
|
|
36
|
-
declare const diatremaDefaultConfig: DiatremaOptions;
|
|
37
|
-
/**
|
|
38
|
-
* Main Diatrema class that orchestrates the application lifecycle.
|
|
39
|
-
*/
|
|
40
|
-
declare class Diatrema extends EventEmitter<DiatremaEvents> {
|
|
41
|
-
#private;
|
|
42
|
-
readonly options: DiatremaOptions;
|
|
43
|
-
protected readonly dependencies: DiatremaDependencies;
|
|
44
|
-
constructor(dependencies: DiatremaDependencies);
|
|
45
|
-
constructor(initialOptions: Partial<DiatremaOptions>, dependencies: DiatremaDependencies);
|
|
46
|
-
/**
|
|
47
|
-
* Indicates whether the Mahameru server has been initialized or not.
|
|
48
|
-
* @returns {boolean}
|
|
49
|
-
*/
|
|
50
|
-
get initialized(): boolean;
|
|
51
|
-
/**
|
|
52
|
-
* Indicates whether the Mahameru server is shutting down or not.
|
|
53
|
-
* @returns {boolean}
|
|
54
|
-
*/
|
|
55
|
-
get isShuttingDown(): boolean;
|
|
56
|
-
/**
|
|
57
|
-
* Initialize the Mahameru server.
|
|
58
|
-
*/
|
|
59
|
-
initialize(): Promise<void>;
|
|
60
|
-
/**
|
|
61
|
-
* Hot reload the middleware and routes when a file changes in development mode.
|
|
62
|
-
*/
|
|
63
|
-
devHRM(changedFile?: string): Promise<void>;
|
|
64
|
-
/**
|
|
65
|
-
* Shut down the Mahameru server gracefully.
|
|
66
|
-
* @returns {Promise<void>}
|
|
67
|
-
*/
|
|
68
|
-
shutdown(): Promise<void>;
|
|
69
|
-
}
|
|
70
|
-
|
|
1
|
+
import _default from './diatrema-CyKJKZv_.cjs';
|
|
2
|
+
import './event-emitter.cjs';
|
|
3
|
+
import './types.cjs';
|
|
71
4
|
// @ts-ignore
|
|
72
|
-
export =
|
|
73
|
-
export {
|
|
5
|
+
export = _default;
|
|
6
|
+
export { b as DiatremaEvents, c as DiatremaOptions, d as diatremaDefaultConfig } from './diatrema-CyKJKZv_.cjs';
|
|
7
|
+
import './logger.cjs';
|
package/diatrema.d.ts
CHANGED
|
@@ -1,71 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import { Logger } from './logger.js';
|
|
6
|
-
import 'node:http';
|
|
7
|
-
import './mahameru-response.js';
|
|
8
|
-
import './types-BmFqDpSs.js';
|
|
9
|
-
import './http-server-error.js';
|
|
10
|
-
import './mahameru-server-error.js';
|
|
11
|
-
import './container-error.js';
|
|
12
|
-
import './module-error.js';
|
|
13
|
-
|
|
14
|
-
type DiatremaEvents = {
|
|
15
|
-
ready: [data: {
|
|
16
|
-
mode: "development" | "production";
|
|
17
|
-
port: number;
|
|
18
|
-
host: string;
|
|
19
|
-
}];
|
|
20
|
-
};
|
|
21
|
-
type DiatremaOptions = {
|
|
22
|
-
dev: boolean;
|
|
23
|
-
isStandalone: boolean;
|
|
24
|
-
rootPath: string;
|
|
25
|
-
appPath: string;
|
|
26
|
-
routesDir: string;
|
|
27
|
-
productionDir: string;
|
|
28
|
-
developmentDir: string;
|
|
29
|
-
};
|
|
30
|
-
type DiatremaDependencies = {
|
|
31
|
-
container: Container;
|
|
32
|
-
route: Route;
|
|
33
|
-
httpServer: HttpServer;
|
|
34
|
-
logger: Logger;
|
|
35
|
-
};
|
|
36
|
-
declare const diatremaDefaultConfig: DiatremaOptions;
|
|
37
|
-
/**
|
|
38
|
-
* Main Diatrema class that orchestrates the application lifecycle.
|
|
39
|
-
*/
|
|
40
|
-
declare class Diatrema extends EventEmitter<DiatremaEvents> {
|
|
41
|
-
#private;
|
|
42
|
-
readonly options: DiatremaOptions;
|
|
43
|
-
protected readonly dependencies: DiatremaDependencies;
|
|
44
|
-
constructor(dependencies: DiatremaDependencies);
|
|
45
|
-
constructor(initialOptions: Partial<DiatremaOptions>, dependencies: DiatremaDependencies);
|
|
46
|
-
/**
|
|
47
|
-
* Indicates whether the Mahameru server has been initialized or not.
|
|
48
|
-
* @returns {boolean}
|
|
49
|
-
*/
|
|
50
|
-
get initialized(): boolean;
|
|
51
|
-
/**
|
|
52
|
-
* Indicates whether the Mahameru server is shutting down or not.
|
|
53
|
-
* @returns {boolean}
|
|
54
|
-
*/
|
|
55
|
-
get isShuttingDown(): boolean;
|
|
56
|
-
/**
|
|
57
|
-
* Initialize the Mahameru server.
|
|
58
|
-
*/
|
|
59
|
-
initialize(): Promise<void>;
|
|
60
|
-
/**
|
|
61
|
-
* Hot reload the middleware and routes when a file changes in development mode.
|
|
62
|
-
*/
|
|
63
|
-
devHRM(changedFile?: string): Promise<void>;
|
|
64
|
-
/**
|
|
65
|
-
* Shut down the Mahameru server gracefully.
|
|
66
|
-
* @returns {Promise<void>}
|
|
67
|
-
*/
|
|
68
|
-
shutdown(): Promise<void>;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export { type DiatremaDependencies, type DiatremaEvents, type DiatremaOptions, Diatrema as default, diatremaDefaultConfig };
|
|
1
|
+
import './event-emitter.js';
|
|
2
|
+
import './types.js';
|
|
3
|
+
export { b as DiatremaEvents, c as DiatremaOptions, D as default, d as diatremaDefaultConfig } from './diatrema-Bk12jngx.js';
|
|
4
|
+
import './logger.js';
|