tezx 1.0.51 → 1.0.53
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/adapter/bun.d.ts +1 -1
- package/cjs/index.js +1 -1
- package/cjs/middleware/lazyLoadModules.js +9 -10
- package/cjs/ws/index.js +1 -1
- package/index.js +1 -1
- package/middleware/lazyLoadModules.d.ts +1 -5
- package/middleware/lazyLoadModules.js +9 -10
- package/package.json +1 -1
- package/ws/index.js +1 -1
package/adapter/bun.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { TezX } from "../core/server.js";
|
|
2
2
|
export declare function bunAdapter<T extends Record<string, any> = {}>(TezX: TezX<T>): {
|
|
3
|
-
listen: (port: number, callback?: (message: string) => void) =>
|
|
3
|
+
listen: (port: number, callback?: (message: string) => void) => any;
|
|
4
4
|
};
|
package/cjs/index.js
CHANGED
|
@@ -7,4 +7,4 @@ var server_js_1 = require("./core/server.js");
|
|
|
7
7
|
Object.defineProperty(exports, "TezX", { enumerable: true, get: function () { return server_js_1.TezX; } });
|
|
8
8
|
var params_js_1 = require("./utils/params.js");
|
|
9
9
|
Object.defineProperty(exports, "useParams", { enumerable: true, get: function () { return params_js_1.useParams; } });
|
|
10
|
-
exports.version = "1.0.
|
|
10
|
+
exports.version = "1.0.53";
|
|
@@ -3,7 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.lazyLoadModules = void 0;
|
|
4
4
|
const config_js_1 = require("../core/config.js");
|
|
5
5
|
const lazyLoadModules = (options) => {
|
|
6
|
-
const { moduleKey = (ctx) => ctx.req.params[queryKeyModule] || ctx.req.query[queryKeyModule], getModuleLoader, queryKeyModule = "module", moduleContextKey = "module", cacheTTL = 3600000,
|
|
6
|
+
const { moduleKey = (ctx) => ctx.req.params[queryKeyModule] || ctx.req.query[queryKeyModule], getModuleLoader, queryKeyModule = "module", moduleContextKey = "module", cacheTTL = 3600000, enableCache = true, cacheStorage, lifecycleHooks = {}, validateModule, } = options;
|
|
7
|
+
let storage = cacheStorage;
|
|
8
|
+
if (enableCache && !cacheStorage) {
|
|
9
|
+
storage = new Map();
|
|
10
|
+
}
|
|
7
11
|
return async (ctx, next) => {
|
|
8
12
|
let moduleName = moduleKey(ctx) ||
|
|
9
13
|
ctx.req.params[queryKeyModule] ||
|
|
@@ -12,15 +16,11 @@ const lazyLoadModules = (options) => {
|
|
|
12
16
|
config_js_1.GlobalConfig.debugging.warn("No module specified for lazy loading.");
|
|
13
17
|
return await next();
|
|
14
18
|
}
|
|
15
|
-
let storage = cacheStorage;
|
|
16
|
-
if (enableCache && !cacheStorage) {
|
|
17
|
-
storage = new Map();
|
|
18
|
-
}
|
|
19
19
|
try {
|
|
20
20
|
if (enableCache) {
|
|
21
21
|
const cached = storage.get(moduleName);
|
|
22
22
|
if (cached) {
|
|
23
|
-
if (cached.expiresAt
|
|
23
|
+
if (cached.expiresAt < Date.now()) {
|
|
24
24
|
storage.delete(moduleName);
|
|
25
25
|
}
|
|
26
26
|
else {
|
|
@@ -35,7 +35,7 @@ const lazyLoadModules = (options) => {
|
|
|
35
35
|
if (!getModuleLoader) {
|
|
36
36
|
throw new Error(`No module loader found for module: ${moduleName}`);
|
|
37
37
|
}
|
|
38
|
-
const moduleLoader = getModuleLoader(ctx);
|
|
38
|
+
const moduleLoader = await getModuleLoader(ctx);
|
|
39
39
|
if (!moduleLoader) {
|
|
40
40
|
throw new Error(`No loader found for module: ${moduleName}`);
|
|
41
41
|
}
|
|
@@ -44,7 +44,6 @@ const lazyLoadModules = (options) => {
|
|
|
44
44
|
if (validateModule && !validateModule(module)) {
|
|
45
45
|
throw new Error(`Module validation failed for: ${moduleName}`);
|
|
46
46
|
}
|
|
47
|
-
ctx.dependencies = dependencies;
|
|
48
47
|
if (enableCache) {
|
|
49
48
|
storage.set(moduleName, {
|
|
50
49
|
module,
|
|
@@ -54,8 +53,8 @@ const lazyLoadModules = (options) => {
|
|
|
54
53
|
}
|
|
55
54
|
ctx[moduleContextKey] = module;
|
|
56
55
|
if (module.init && typeof module.init === "function") {
|
|
57
|
-
const initResult = await module.init(
|
|
58
|
-
if (initResult
|
|
56
|
+
const initResult = await module.init(ctx);
|
|
57
|
+
if (initResult) {
|
|
59
58
|
return initResult;
|
|
60
59
|
}
|
|
61
60
|
}
|
package/cjs/ws/index.js
CHANGED
package/index.js
CHANGED
|
@@ -14,7 +14,7 @@ interface LazyLoadOptions<T> {
|
|
|
14
14
|
* 🛠️ Function that returns a loader function for the specified module, used to dynamically load the module.
|
|
15
15
|
* If this function returns null, it indicates no loader is available for the module.
|
|
16
16
|
*/
|
|
17
|
-
getModuleLoader: (ctx: Context) => LazyModuleLoader<T> | null
|
|
17
|
+
getModuleLoader: (ctx: Context) => Promise<LazyModuleLoader<T> | null> | null | LazyModuleLoader<T>;
|
|
18
18
|
/**
|
|
19
19
|
* 🔍 Query parameter name to select which module to load (e.g., "module").
|
|
20
20
|
* @default "module"
|
|
@@ -25,10 +25,6 @@ interface LazyLoadOptions<T> {
|
|
|
25
25
|
* @default "module"
|
|
26
26
|
*/
|
|
27
27
|
moduleContextKey?: string;
|
|
28
|
-
/**
|
|
29
|
-
* ⚙️ Dependencies to inject into the module during initialization.
|
|
30
|
-
*/
|
|
31
|
-
dependencies?: Record<string, any>;
|
|
32
28
|
/**
|
|
33
29
|
* 🔄 Enable caching of loaded modules to avoid re-loading them repeatedly.
|
|
34
30
|
* @default true
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { GlobalConfig } from "../core/config.js";
|
|
2
2
|
export const lazyLoadModules = (options) => {
|
|
3
|
-
const { moduleKey = (ctx) => ctx.req.params[queryKeyModule] || ctx.req.query[queryKeyModule], getModuleLoader, queryKeyModule = "module", moduleContextKey = "module", cacheTTL = 3600000,
|
|
3
|
+
const { moduleKey = (ctx) => ctx.req.params[queryKeyModule] || ctx.req.query[queryKeyModule], getModuleLoader, queryKeyModule = "module", moduleContextKey = "module", cacheTTL = 3600000, enableCache = true, cacheStorage, lifecycleHooks = {}, validateModule, } = options;
|
|
4
|
+
let storage = cacheStorage;
|
|
5
|
+
if (enableCache && !cacheStorage) {
|
|
6
|
+
storage = new Map();
|
|
7
|
+
}
|
|
4
8
|
return async (ctx, next) => {
|
|
5
9
|
let moduleName = moduleKey(ctx) ||
|
|
6
10
|
ctx.req.params[queryKeyModule] ||
|
|
@@ -9,15 +13,11 @@ export const lazyLoadModules = (options) => {
|
|
|
9
13
|
GlobalConfig.debugging.warn("No module specified for lazy loading.");
|
|
10
14
|
return await next();
|
|
11
15
|
}
|
|
12
|
-
let storage = cacheStorage;
|
|
13
|
-
if (enableCache && !cacheStorage) {
|
|
14
|
-
storage = new Map();
|
|
15
|
-
}
|
|
16
16
|
try {
|
|
17
17
|
if (enableCache) {
|
|
18
18
|
const cached = storage.get(moduleName);
|
|
19
19
|
if (cached) {
|
|
20
|
-
if (cached.expiresAt
|
|
20
|
+
if (cached.expiresAt < Date.now()) {
|
|
21
21
|
storage.delete(moduleName);
|
|
22
22
|
}
|
|
23
23
|
else {
|
|
@@ -32,7 +32,7 @@ export const lazyLoadModules = (options) => {
|
|
|
32
32
|
if (!getModuleLoader) {
|
|
33
33
|
throw new Error(`No module loader found for module: ${moduleName}`);
|
|
34
34
|
}
|
|
35
|
-
const moduleLoader = getModuleLoader(ctx);
|
|
35
|
+
const moduleLoader = await getModuleLoader(ctx);
|
|
36
36
|
if (!moduleLoader) {
|
|
37
37
|
throw new Error(`No loader found for module: ${moduleName}`);
|
|
38
38
|
}
|
|
@@ -41,7 +41,6 @@ export const lazyLoadModules = (options) => {
|
|
|
41
41
|
if (validateModule && !validateModule(module)) {
|
|
42
42
|
throw new Error(`Module validation failed for: ${moduleName}`);
|
|
43
43
|
}
|
|
44
|
-
ctx.dependencies = dependencies;
|
|
45
44
|
if (enableCache) {
|
|
46
45
|
storage.set(moduleName, {
|
|
47
46
|
module,
|
|
@@ -51,8 +50,8 @@ export const lazyLoadModules = (options) => {
|
|
|
51
50
|
}
|
|
52
51
|
ctx[moduleContextKey] = module;
|
|
53
52
|
if (module.init && typeof module.init === "function") {
|
|
54
|
-
const initResult = await module.init(
|
|
55
|
-
if (initResult
|
|
53
|
+
const initResult = await module.init(ctx);
|
|
54
|
+
if (initResult) {
|
|
56
55
|
return initResult;
|
|
57
56
|
}
|
|
58
57
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tezx",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.53",
|
|
4
4
|
"description": "TezX is a high-performance, lightweight JavaScript framework designed for speed, scalability, and flexibility. It enables efficient routing, middleware management, and static file serving with minimal configuration. Fully compatible with Node.js, Deno, and Bun.",
|
|
5
5
|
"main": "cjs/index.js",
|
|
6
6
|
"module": "index.js",
|
package/ws/index.js
CHANGED