tezx 4.0.1 → 4.0.2

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.
@@ -12,7 +12,6 @@ class Context {
12
12
  params = {};
13
13
  rawRequest;
14
14
  #server;
15
- #body;
16
15
  url;
17
16
  res;
18
17
  pathname;
@@ -44,12 +43,6 @@ class Context {
44
43
  get req() {
45
44
  return (this.#req ??= new request_js_1.TezXRequest(this.rawRequest, this.method, this.pathname, this.params));
46
45
  }
47
- get body() {
48
- return this.#body;
49
- }
50
- set body(value) {
51
- this.#body = value;
52
- }
53
46
  status(status) {
54
47
  this.#status = status;
55
48
  return this;
@@ -4,23 +4,18 @@ exports.TezX = void 0;
4
4
  const RadixRouter_js_1 = require("../registry/RadixRouter.js");
5
5
  const response_js_1 = require("../utils/response.js");
6
6
  const url_js_1 = require("../utils/url.js");
7
- const index_js_1 = require("../config/index.js");
8
7
  const context_js_1 = require("./context.js");
9
8
  const router_js_1 = require("./router.js");
10
9
  class TezX extends router_js_1.Router {
11
10
  #pathResolver;
12
11
  #notFound = response_js_1.notFoundResponse;
13
12
  #errorHandler = response_js_1.handleErrorResponse;
14
- constructor({ basePath = "/", debugMode = false, onPathResolve, routeRegistry = new RadixRouter_js_1.RadixRouter(), } = {}) {
15
- if (debugMode) {
16
- index_js_1.Config.debugMode = debugMode;
17
- }
13
+ constructor({ basePath = "/", routeRegistry = new RadixRouter_js_1.RadixRouter(), } = {}) {
18
14
  super({ basePath });
19
15
  if (!routeRegistry) {
20
16
  throw new Error("routeRegistry is required for TezX initialization");
21
17
  }
22
18
  this.router = routeRegistry;
23
- this.#pathResolver = onPathResolve;
24
19
  this.serve = this.serve.bind(this);
25
20
  }
26
21
  notFound(callback) {
@@ -31,64 +26,49 @@ class TezX extends router_js_1.Router {
31
26
  this.#errorHandler = callback;
32
27
  return this;
33
28
  }
34
- async #chain(ctx, mLen, middlewares, hLen, handlers) {
29
+ #composeChain(ctx, stack) {
35
30
  let index = -1;
36
- let res;
37
- async function dispatch(i) {
31
+ const dispatch = (i) => {
38
32
  if (i <= index)
39
33
  throw new Error("next() called multiple times");
40
34
  index = i;
41
- if (i < mLen) {
42
- const fn = middlewares[i];
43
- if (typeof fn !== "function")
44
- throw new TypeError(`Middleware[${i}] must be a function`);
45
- res = (await fn(ctx, () => dispatch(i + 1)));
46
- if (res !== undefined) {
47
- ctx.res = res;
48
- }
35
+ const fn = stack[i];
36
+ if (!fn)
37
+ return ctx.res;
38
+ const result = fn(ctx, () => dispatch(i + 1));
39
+ if (!(result instanceof Promise)) {
40
+ if (result instanceof Response)
41
+ ctx.res = result;
49
42
  return ctx.res;
50
43
  }
51
- const hi = i - mLen;
52
- if (hi < hLen) {
53
- const fn = handlers[hi];
54
- if (typeof fn !== "function")
55
- throw new TypeError(`Handler[${hi}] must be a function`);
56
- res = (await fn(ctx, () => dispatch(i + 1)));
57
- if (res !== undefined) {
44
+ return result.then((res) => {
45
+ if (res instanceof Response)
58
46
  ctx.res = res;
59
- }
60
47
  return ctx.res;
61
- }
62
- }
63
- await dispatch(0);
64
- return (ctx.res ??
65
- (ctx.body !== undefined ? ctx.send(ctx.body) : this.#notFound(ctx)));
48
+ }, (err) => {
49
+ throw err;
50
+ });
51
+ };
52
+ return dispatch(0);
66
53
  }
67
54
  async #handleRequest(req, method, server) {
68
- if (!(req instanceof Request))
69
- throw new Error("Invalid request object provided to tezX server.");
70
- const rawPath = (0, url_js_1.getPathname)(req.url);
71
- const pathname = this.#pathResolver
72
- ? await this.#pathResolver(rawPath)
73
- : rawPath;
55
+ const pathname = (0, url_js_1.getPathname)(req.url);
74
56
  const ctx = new context_js_1.Context(req, pathname, method, server);
75
57
  try {
76
58
  const staticHandler = this.staticFile?.[`${method} ${pathname}`];
77
- if (staticHandler) {
59
+ if (staticHandler)
78
60
  return staticHandler(ctx);
79
- }
80
- const route = this.router?.search(method, pathname);
81
- const mLen = route?.middlewares?.length;
82
- const hLen = route?.handlers?.length;
83
- if (!route || (hLen === 0 && mLen === 0)) {
61
+ const result = this.router?.search(method, pathname);
62
+ if (!result)
84
63
  return this.#notFound(ctx);
85
- }
86
- ctx.params = route.params;
87
- if (hLen === 1 && mLen === 0) {
88
- return ((await route.handlers[0](ctx)) ??
89
- (ctx.body !== undefined ? ctx.send(ctx.body) : this.#notFound(ctx)));
90
- }
91
- return await this.#chain(ctx, mLen, route.middlewares, hLen, route.handlers);
64
+ const { match: middlewares, params } = result;
65
+ const mLen = middlewares.length;
66
+ if (mLen === 0)
67
+ return this.#notFound(ctx);
68
+ ctx.params = params;
69
+ if (mLen === 1)
70
+ return await middlewares[0](ctx) ?? this.#notFound(ctx);
71
+ return await this.#composeChain(ctx, middlewares) ?? this.#notFound(ctx);
92
72
  }
93
73
  catch (err) {
94
74
  let error = err instanceof Error ? err : new Error(String(err));
@@ -96,20 +76,17 @@ class TezX extends router_js_1.Router {
96
76
  }
97
77
  }
98
78
  async serve(req, server) {
99
- const method = (req.method ?? "GET").toUpperCase();
79
+ const method = req.method || "GET";
100
80
  if (method === "HEAD") {
101
- const getRequest = new Request(req.url, { ...req, method: "GET" });
102
- const headResponse = await this.#handleRequest(getRequest, method, server);
81
+ const headReq = new Request(req, { method: "GET" });
82
+ const res = await this.#handleRequest(headReq, "GET", server);
103
83
  return new Response(null, {
104
- status: headResponse.status,
105
- statusText: headResponse.statusText,
106
- headers: headResponse.headers,
84
+ status: res.status,
85
+ statusText: res.statusText,
86
+ headers: res.headers,
107
87
  });
108
88
  }
109
89
  return this.#handleRequest(req, method, server);
110
90
  }
111
91
  }
112
92
  exports.TezX = TezX;
113
- if (!globalThis.TezX) {
114
- globalThis.TezX = TezX;
115
- }
package/cjs/index.js CHANGED
@@ -5,7 +5,7 @@ const router_js_1 = require("./core/router.js");
5
5
  Object.defineProperty(exports, "Router", { enumerable: true, get: function () { return router_js_1.Router; } });
6
6
  const server_js_1 = require("./core/server.js");
7
7
  Object.defineProperty(exports, "TezX", { enumerable: true, get: function () { return server_js_1.TezX; } });
8
- exports.version = "4.0.1";
8
+ exports.version = "4.0.2";
9
9
  exports.default = {
10
10
  Router: router_js_1.Router,
11
11
  TezX: server_js_1.TezX,
@@ -39,12 +39,18 @@ class RadixRouter {
39
39
  search(method, path) {
40
40
  let params = {};
41
41
  let middlewares = [];
42
- const { success, node } = this._match(method, this.root, path?.split("/")?.filter(Boolean), 0, params, middlewares);
43
- if (success && node) {
44
- const handlers = node.handlers?.[method] ?? [];
45
- return { method, params, handlers, middlewares };
42
+ const segments = path?.split("/")?.filter(Boolean);
43
+ const { success, node } = this._match(method, this.root, segments, 0, params, middlewares);
44
+ if (!success || !node) {
45
+ return { method, params: {}, match: [] };
46
46
  }
47
- return { method, params: {}, handlers: [], middlewares };
47
+ const list = node.handlers?.[method];
48
+ if (list) {
49
+ for (let i = 0; i < list.length; i++) {
50
+ middlewares.push(list[i]);
51
+ }
52
+ }
53
+ return { method, params, match: middlewares };
48
54
  }
49
55
  _match(method, node, segments, index, params, middlewares) {
50
56
  if (node?.handlers?.ALL) {
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.notFoundResponse = void 0;
4
4
  exports.mergeHeaders = mergeHeaders;
5
5
  exports.handleErrorResponse = handleErrorResponse;
6
- const index_js_1 = require("../config/index.js");
7
6
  let notFoundResponse = (ctx) => {
8
7
  const { method, pathname } = ctx;
9
8
  return ctx.text(`${method}: '${pathname}' could not find\n`, {
@@ -11,24 +10,25 @@ let notFoundResponse = (ctx) => {
11
10
  });
12
11
  };
13
12
  exports.notFoundResponse = notFoundResponse;
14
- function mergeHeaders(existing, initHeaders) {
13
+ function mergeHeaders(existing, init) {
15
14
  if (!existing)
16
- return new Headers(initHeaders);
17
- if (!initHeaders)
15
+ return new Headers(init);
16
+ if (!init)
18
17
  return existing;
19
18
  const out = new Headers(existing);
20
- const tmp = new Headers(initHeaders);
21
- for (const [k, v] of tmp) {
22
- if (k.toLowerCase() === "set-cookie")
23
- out.append(k, v);
24
- else
25
- out.set(k, v);
19
+ for (const key in init) {
20
+ const val = init[key];
21
+ if (val && key.toLowerCase() === "set-cookie") {
22
+ out.append(key, val);
23
+ }
24
+ else if (val) {
25
+ out.set(key, val);
26
+ }
26
27
  }
27
28
  return out;
28
29
  }
29
30
  async function handleErrorResponse(err = new Error("Internal Server Error"), ctx) {
30
31
  if (err instanceof Error) {
31
- index_js_1.Config.debugging.error(err?.message);
32
32
  return ctx.status(500).send(err.message ?? "Internal Server Error");
33
33
  }
34
34
  return await handleErrorResponse(new Error(err), ctx);
package/core/context.d.ts CHANGED
@@ -102,16 +102,6 @@ export declare class Context<TPath extends string = any> {
102
102
  * @returns {TezXRequest<TPath>} The wrapped request.
103
103
  */
104
104
  get req(): TezXRequest<TPath>;
105
- /**
106
- * Gets the response body.
107
- * @returns {*} The response body.
108
- */
109
- get body(): any;
110
- /**
111
- * Sets the response body.
112
- * @param {*} value - The response body.
113
- */
114
- set body(value: any);
115
105
  /**
116
106
  * Sets the HTTP response status code.
117
107
  *
package/core/context.js CHANGED
@@ -9,7 +9,6 @@ export class Context {
9
9
  params = {};
10
10
  rawRequest;
11
11
  #server;
12
- #body;
13
12
  url;
14
13
  res;
15
14
  pathname;
@@ -41,12 +40,6 @@ export class Context {
41
40
  get req() {
42
41
  return (this.#req ??= new TezXRequest(this.rawRequest, this.method, this.pathname, this.params));
43
42
  }
44
- get body() {
45
- return this.#body;
46
- }
47
- set body(value) {
48
- this.#body = value;
49
- }
50
43
  status(status) {
51
44
  this.#status = status;
52
45
  return this;
package/core/server.d.ts CHANGED
@@ -1,38 +1,11 @@
1
1
  import { Callback, ErrorHandler, RouteRegistry } from "../types/index.js";
2
2
  import { Router, RouterConfig } from "./router.js";
3
3
  export type TezXConfig = {
4
- /**
5
- * 🔄 Hook to transform or normalize the incoming request pathname before routing.
6
- *
7
- * This function allows you to customize how incoming paths are handled.
8
- * You can use it to:
9
- * - Remove trailing slashes
10
- * - Normalize casing
11
- * - Rewrite certain paths dynamically
12
- * - Add localization or versioning prefixes
13
- *
14
- * @example
15
- * ```ts
16
- * onPathResolve: (pathname) => pathname.replace(/\/+$/, "").toLowerCase()
17
- * ```
18
- *
19
- * @param pathname - The raw incoming request path (e.g., `/Api/Users/`)
20
- * @returns The transformed or resolved path used for routing (e.g., `/api/users`)
21
- */
22
- onPathResolve?: (pathname: string) => string;
23
4
  /**
24
5
  * Custom route registry instance used internally to store routes.
25
6
  * If not provided, the router will use the default CombineRouteRegistry.
26
7
  */
27
8
  routeRegistry?: RouteRegistry;
28
- /**
29
- * Enables or disables debugging for the middleware.
30
- * When set to `true`, detailed debug logs will be output,
31
- * useful for tracking the flow of requests and identifying issues.
32
- *
33
- * @default false
34
- */
35
- debugMode?: boolean;
36
9
  } & RouterConfig;
37
10
  /**
38
11
  * TezX is an ultra-fast, flexible request router and server handler.
@@ -52,7 +25,7 @@ export declare class TezX<T extends Record<string, any> = {}> extends Router<T>
52
25
  #private;
53
26
  /** Internal route registry to hold all routes */
54
27
  protected router?: RouteRegistry;
55
- constructor({ basePath, debugMode, onPathResolve, routeRegistry, }?: TezXConfig);
28
+ constructor({ basePath, routeRegistry, }?: TezXConfig);
56
29
  /**
57
30
  * Register a custom 404 (not found) handler.
58
31
  *
package/core/server.js CHANGED
@@ -1,23 +1,18 @@
1
1
  import { RadixRouter } from "../registry/RadixRouter.js";
2
2
  import { handleErrorResponse, notFoundResponse } from "../utils/response.js";
3
3
  import { getPathname } from "../utils/url.js";
4
- import { Config } from "../config/index.js";
5
4
  import { Context } from "./context.js";
6
5
  import { Router } from "./router.js";
7
6
  export class TezX extends Router {
8
7
  #pathResolver;
9
8
  #notFound = notFoundResponse;
10
9
  #errorHandler = handleErrorResponse;
11
- constructor({ basePath = "/", debugMode = false, onPathResolve, routeRegistry = new RadixRouter(), } = {}) {
12
- if (debugMode) {
13
- Config.debugMode = debugMode;
14
- }
10
+ constructor({ basePath = "/", routeRegistry = new RadixRouter(), } = {}) {
15
11
  super({ basePath });
16
12
  if (!routeRegistry) {
17
13
  throw new Error("routeRegistry is required for TezX initialization");
18
14
  }
19
15
  this.router = routeRegistry;
20
- this.#pathResolver = onPathResolve;
21
16
  this.serve = this.serve.bind(this);
22
17
  }
23
18
  notFound(callback) {
@@ -28,64 +23,49 @@ export class TezX extends Router {
28
23
  this.#errorHandler = callback;
29
24
  return this;
30
25
  }
31
- async #chain(ctx, mLen, middlewares, hLen, handlers) {
26
+ #composeChain(ctx, stack) {
32
27
  let index = -1;
33
- let res;
34
- async function dispatch(i) {
28
+ const dispatch = (i) => {
35
29
  if (i <= index)
36
30
  throw new Error("next() called multiple times");
37
31
  index = i;
38
- if (i < mLen) {
39
- const fn = middlewares[i];
40
- if (typeof fn !== "function")
41
- throw new TypeError(`Middleware[${i}] must be a function`);
42
- res = (await fn(ctx, () => dispatch(i + 1)));
43
- if (res !== undefined) {
44
- ctx.res = res;
45
- }
32
+ const fn = stack[i];
33
+ if (!fn)
34
+ return ctx.res;
35
+ const result = fn(ctx, () => dispatch(i + 1));
36
+ if (!(result instanceof Promise)) {
37
+ if (result instanceof Response)
38
+ ctx.res = result;
46
39
  return ctx.res;
47
40
  }
48
- const hi = i - mLen;
49
- if (hi < hLen) {
50
- const fn = handlers[hi];
51
- if (typeof fn !== "function")
52
- throw new TypeError(`Handler[${hi}] must be a function`);
53
- res = (await fn(ctx, () => dispatch(i + 1)));
54
- if (res !== undefined) {
41
+ return result.then((res) => {
42
+ if (res instanceof Response)
55
43
  ctx.res = res;
56
- }
57
44
  return ctx.res;
58
- }
59
- }
60
- await dispatch(0);
61
- return (ctx.res ??
62
- (ctx.body !== undefined ? ctx.send(ctx.body) : this.#notFound(ctx)));
45
+ }, (err) => {
46
+ throw err;
47
+ });
48
+ };
49
+ return dispatch(0);
63
50
  }
64
51
  async #handleRequest(req, method, server) {
65
- if (!(req instanceof Request))
66
- throw new Error("Invalid request object provided to tezX server.");
67
- const rawPath = getPathname(req.url);
68
- const pathname = this.#pathResolver
69
- ? await this.#pathResolver(rawPath)
70
- : rawPath;
52
+ const pathname = getPathname(req.url);
71
53
  const ctx = new Context(req, pathname, method, server);
72
54
  try {
73
55
  const staticHandler = this.staticFile?.[`${method} ${pathname}`];
74
- if (staticHandler) {
56
+ if (staticHandler)
75
57
  return staticHandler(ctx);
76
- }
77
- const route = this.router?.search(method, pathname);
78
- const mLen = route?.middlewares?.length;
79
- const hLen = route?.handlers?.length;
80
- if (!route || (hLen === 0 && mLen === 0)) {
58
+ const result = this.router?.search(method, pathname);
59
+ if (!result)
81
60
  return this.#notFound(ctx);
82
- }
83
- ctx.params = route.params;
84
- if (hLen === 1 && mLen === 0) {
85
- return ((await route.handlers[0](ctx)) ??
86
- (ctx.body !== undefined ? ctx.send(ctx.body) : this.#notFound(ctx)));
87
- }
88
- return await this.#chain(ctx, mLen, route.middlewares, hLen, route.handlers);
61
+ const { match: middlewares, params } = result;
62
+ const mLen = middlewares.length;
63
+ if (mLen === 0)
64
+ return this.#notFound(ctx);
65
+ ctx.params = params;
66
+ if (mLen === 1)
67
+ return await middlewares[0](ctx) ?? this.#notFound(ctx);
68
+ return await this.#composeChain(ctx, middlewares) ?? this.#notFound(ctx);
89
69
  }
90
70
  catch (err) {
91
71
  let error = err instanceof Error ? err : new Error(String(err));
@@ -93,19 +73,16 @@ export class TezX extends Router {
93
73
  }
94
74
  }
95
75
  async serve(req, server) {
96
- const method = (req.method ?? "GET").toUpperCase();
76
+ const method = req.method || "GET";
97
77
  if (method === "HEAD") {
98
- const getRequest = new Request(req.url, { ...req, method: "GET" });
99
- const headResponse = await this.#handleRequest(getRequest, method, server);
78
+ const headReq = new Request(req, { method: "GET" });
79
+ const res = await this.#handleRequest(headReq, "GET", server);
100
80
  return new Response(null, {
101
- status: headResponse.status,
102
- statusText: headResponse.statusText,
103
- headers: headResponse.headers,
81
+ status: res.status,
82
+ statusText: res.statusText,
83
+ headers: res.headers,
104
84
  });
105
85
  }
106
86
  return this.#handleRequest(req, method, server);
107
87
  }
108
88
  }
109
- if (!globalThis.TezX) {
110
- globalThis.TezX = TezX;
111
- }
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Router } from "./core/router.js";
2
- import { TezX, TezX as TezXBase } from "./core/server.js";
2
+ import { TezX } from "./core/server.js";
3
3
  export type { Context as BaseContext } from "./core/context.js";
4
4
  export type { TezXRequest } from "./core/request.js";
5
5
  export type { RouterConfig } from "./core/router.js";
@@ -13,6 +13,3 @@ declare const _default: {
13
13
  version: string;
14
14
  };
15
15
  export default _default;
16
- declare global {
17
- var TezX: typeof TezXBase;
18
- }
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Router } from "./core/router.js";
2
2
  import { TezX } from "./core/server.js";
3
3
  export { Router, TezX };
4
- export let version = "4.0.1";
4
+ export let version = "4.0.2";
5
5
  export default {
6
6
  Router,
7
7
  TezX,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tezx",
3
- "version": "4.0.1",
3
+ "version": "4.0.2",
4
4
  "description": "TezX is a modern, ultra-lightweight, and high-performance JavaScript framework built specifically for Bun. It provides a minimal yet powerful API, seamless environment management, and a high-concurrency HTTP engine for building fast, scalable web applications.",
5
5
  "type": "module",
6
6
  "main": "cjs/index.js",
@@ -36,12 +36,18 @@ export class RadixRouter {
36
36
  search(method, path) {
37
37
  let params = {};
38
38
  let middlewares = [];
39
- const { success, node } = this._match(method, this.root, path?.split("/")?.filter(Boolean), 0, params, middlewares);
40
- if (success && node) {
41
- const handlers = node.handlers?.[method] ?? [];
42
- return { method, params, handlers, middlewares };
39
+ const segments = path?.split("/")?.filter(Boolean);
40
+ const { success, node } = this._match(method, this.root, segments, 0, params, middlewares);
41
+ if (!success || !node) {
42
+ return { method, params: {}, match: [] };
43
43
  }
44
- return { method, params: {}, handlers: [], middlewares };
44
+ const list = node.handlers?.[method];
45
+ if (list) {
46
+ for (let i = 0; i < list.length; i++) {
47
+ middlewares.push(list[i]);
48
+ }
49
+ }
50
+ return { method, params, match: middlewares };
45
51
  }
46
52
  _match(method, node, segments, index, params, middlewares) {
47
53
  if (node?.handlers?.ALL) {
package/types/index.d.ts CHANGED
@@ -238,6 +238,12 @@ export type HttpBaseResponse = Response | Promise<Response>;
238
238
  */
239
239
  export type Ctx<T extends Record<string, any> = {}, Path extends string = any> = Context<Path> & T & {
240
240
  [key: string]: any;
241
+ /**
242
+ * Response body, can be string, Buffer, stream, etc. like context propagation.
243
+ * @private
244
+ * @type {*}
245
+ */
246
+ body: any;
241
247
  };
242
248
  /**
243
249
  * A callback (handler) for a route.
@@ -348,11 +354,7 @@ export type RouteMatchResult<T extends Record<string, any> = any> = {
348
354
  /**
349
355
  * The middleware functions that will be executed for this route.
350
356
  */
351
- middlewares: Middleware<T>[];
352
- /**
353
- * The final route handlers (callbacks or middlewares) to be executed.
354
- */
355
- handlers: HandlerType<T>;
357
+ match: Middleware<T>[];
356
358
  /**
357
359
  * An object containing route parameters extracted from the URL.
358
360
  * The values can be strings, null (for optional params), or undefined.
@@ -1,5 +1,5 @@
1
1
  import { Context } from "../core/context.js";
2
2
  import { HttpBaseResponse, ResponseHeaders } from "../types/index.js";
3
3
  export declare let notFoundResponse: (ctx: Context) => HttpBaseResponse;
4
- export declare function mergeHeaders(existing?: Headers, initHeaders?: ResponseHeaders): Headers;
4
+ export declare function mergeHeaders(existing?: Headers, init?: ResponseHeaders): Headers;
5
5
  export declare function handleErrorResponse(err: Error | undefined, ctx: Context): Promise<HttpBaseResponse>;
package/utils/response.js CHANGED
@@ -1,28 +1,28 @@
1
- import { Config } from "../config/index.js";
2
1
  export let notFoundResponse = (ctx) => {
3
2
  const { method, pathname } = ctx;
4
3
  return ctx.text(`${method}: '${pathname}' could not find\n`, {
5
4
  status: 404,
6
5
  });
7
6
  };
8
- export function mergeHeaders(existing, initHeaders) {
7
+ export function mergeHeaders(existing, init) {
9
8
  if (!existing)
10
- return new Headers(initHeaders);
11
- if (!initHeaders)
9
+ return new Headers(init);
10
+ if (!init)
12
11
  return existing;
13
12
  const out = new Headers(existing);
14
- const tmp = new Headers(initHeaders);
15
- for (const [k, v] of tmp) {
16
- if (k.toLowerCase() === "set-cookie")
17
- out.append(k, v);
18
- else
19
- out.set(k, v);
13
+ for (const key in init) {
14
+ const val = init[key];
15
+ if (val && key.toLowerCase() === "set-cookie") {
16
+ out.append(key, val);
17
+ }
18
+ else if (val) {
19
+ out.set(key, val);
20
+ }
20
21
  }
21
22
  return out;
22
23
  }
23
24
  export async function handleErrorResponse(err = new Error("Internal Server Error"), ctx) {
24
25
  if (err instanceof Error) {
25
- Config.debugging.error(err?.message);
26
26
  return ctx.status(500).send(err.message ?? "Internal Server Error");
27
27
  }
28
28
  return await handleErrorResponse(new Error(err), ctx);
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Config = void 0;
4
- const debugging_js_1 = require("../utils/debugging.js");
5
- let Config = class {
6
- static debugMode = false;
7
- static get debugging() {
8
- return this.debugMode
9
- ? {
10
- info: (msg, ...args) => (0, debugging_js_1.loggerOutput)("info", msg, ...args),
11
- warn: (msg, ...args) => (0, debugging_js_1.loggerOutput)("warn", msg, ...args),
12
- error: (msg, ...args) => (0, debugging_js_1.loggerOutput)("error", msg, ...args),
13
- debug: (msg, ...args) => (0, debugging_js_1.loggerOutput)("debug", msg, ...args),
14
- success: (msg, ...args) => (0, debugging_js_1.loggerOutput)("success", msg, ...args),
15
- }
16
- : {
17
- info: (msg, ...args) => { },
18
- warn: (msg, ...args) => { },
19
- error: (msg, ...args) => { },
20
- debug: (msg, ...args) => { },
21
- success: (msg, ...args) => { },
22
- };
23
- }
24
- };
25
- exports.Config = Config;
package/config/index.d.ts DELETED
@@ -1,11 +0,0 @@
1
- export declare let Config: {
2
- new (): {};
3
- debugMode?: boolean;
4
- readonly debugging: {
5
- info: (msg: string, ...args: unknown[]) => void;
6
- warn: (msg: string, ...args: unknown[]) => void;
7
- error: (msg: string, ...args: unknown[]) => void;
8
- debug: (msg: string, ...args: unknown[]) => void;
9
- success: (msg: string, ...args: unknown[]) => void;
10
- };
11
- };
package/config/index.js DELETED
@@ -1,21 +0,0 @@
1
- import { loggerOutput } from "../utils/debugging.js";
2
- export let Config = class {
3
- static debugMode = false;
4
- static get debugging() {
5
- return this.debugMode
6
- ? {
7
- info: (msg, ...args) => loggerOutput("info", msg, ...args),
8
- warn: (msg, ...args) => loggerOutput("warn", msg, ...args),
9
- error: (msg, ...args) => loggerOutput("error", msg, ...args),
10
- debug: (msg, ...args) => loggerOutput("debug", msg, ...args),
11
- success: (msg, ...args) => loggerOutput("success", msg, ...args),
12
- }
13
- : {
14
- info: (msg, ...args) => { },
15
- warn: (msg, ...args) => { },
16
- error: (msg, ...args) => { },
17
- debug: (msg, ...args) => { },
18
- success: (msg, ...args) => { },
19
- };
20
- }
21
- };