arcanajs 2.4.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/package.json +1 -1
  2. package/framework/cli/index.d.ts +0 -1
  3. package/framework/cli/index.js +0 -204
  4. package/framework/cli/templates.d.ts +0 -6
  5. package/framework/cli/templates.js +0 -44
  6. package/framework/cli/webpack.config.d.ts +0 -3
  7. package/framework/cli/webpack.config.js +0 -310
  8. package/framework/lib/client/index.d.ts +0 -59
  9. package/framework/lib/client/index.js +0 -97
  10. package/framework/lib/config/index.d.ts +0 -46
  11. package/framework/lib/config/index.js +0 -115
  12. package/framework/lib/global.d.ts +0 -58
  13. package/framework/lib/index.d.ts +0 -19
  14. package/framework/lib/index.js +0 -59
  15. package/framework/lib/server/ArcanaJSMiddleware.d.ts +0 -24
  16. package/framework/lib/server/ArcanaJSMiddleware.js +0 -114
  17. package/framework/lib/server/ArcanaJSServer.d.ts +0 -23
  18. package/framework/lib/server/ArcanaJSServer.js +0 -165
  19. package/framework/lib/server/ControllerBinder.d.ts +0 -4
  20. package/framework/lib/server/ControllerBinder.js +0 -32
  21. package/framework/lib/server/CsrfMiddleware.d.ts +0 -2
  22. package/framework/lib/server/CsrfMiddleware.js +0 -34
  23. package/framework/lib/server/DynamicRouter.d.ts +0 -2
  24. package/framework/lib/server/DynamicRouter.js +0 -50
  25. package/framework/lib/server/ResponseHandlerMiddleware.d.ts +0 -27
  26. package/framework/lib/server/ResponseHandlerMiddleware.js +0 -30
  27. package/framework/lib/server/Router.d.ts +0 -94
  28. package/framework/lib/server/Router.js +0 -203
  29. package/framework/lib/server/default-index.html +0 -12
  30. package/framework/lib/server.d.ts +0 -32
  31. package/framework/lib/server.js +0 -69
  32. package/framework/lib/shared/components/Body.d.ts +0 -6
  33. package/framework/lib/shared/components/Body.js +0 -8
  34. package/framework/lib/shared/components/Head.d.ts +0 -4
  35. package/framework/lib/shared/components/Head.js +0 -125
  36. package/framework/lib/shared/components/Link.d.ts +0 -7
  37. package/framework/lib/shared/components/Link.js +0 -27
  38. package/framework/lib/shared/components/NavLink.d.ts +0 -9
  39. package/framework/lib/shared/components/NavLink.js +0 -13
  40. package/framework/lib/shared/components/Page.d.ts +0 -6
  41. package/framework/lib/shared/components/Page.js +0 -10
  42. package/framework/lib/shared/context/HeadContext.d.ts +0 -6
  43. package/framework/lib/shared/context/HeadContext.js +0 -5
  44. package/framework/lib/shared/context/PageContext.d.ts +0 -1
  45. package/framework/lib/shared/context/PageContext.js +0 -5
  46. package/framework/lib/shared/context/RouterContext.d.ts +0 -15
  47. package/framework/lib/shared/context/RouterContext.js +0 -10
  48. package/framework/lib/shared/core/ArcanaJSApp.d.ts +0 -14
  49. package/framework/lib/shared/core/ArcanaJSApp.js +0 -142
  50. package/framework/lib/shared/hooks/useHead.d.ts +0 -1
  51. package/framework/lib/shared/hooks/useHead.js +0 -7
  52. package/framework/lib/shared/hooks/useLocation.d.ts +0 -5
  53. package/framework/lib/shared/hooks/useLocation.js +0 -13
  54. package/framework/lib/shared/hooks/usePage.d.ts +0 -1
  55. package/framework/lib/shared/hooks/usePage.js +0 -7
  56. package/framework/lib/shared/hooks/useParams.d.ts +0 -1
  57. package/framework/lib/shared/hooks/useParams.js +0 -13
  58. package/framework/lib/shared/hooks/useQuery.d.ts +0 -1
  59. package/framework/lib/shared/hooks/useQuery.js +0 -9
  60. package/framework/lib/shared/hooks/useRouter.d.ts +0 -1
  61. package/framework/lib/shared/hooks/useRouter.js +0 -13
  62. package/framework/lib/shared/utils/createSingletonContext.d.ts +0 -11
  63. package/framework/lib/shared/utils/createSingletonContext.js +0 -21
  64. package/framework/lib/shared/views/ErrorPage.d.ts +0 -7
  65. package/framework/lib/shared/views/ErrorPage.js +0 -12
  66. package/framework/lib/shared/views/NotFoundPage.d.ts +0 -5
  67. package/framework/lib/shared/views/NotFoundPage.js +0 -11
  68. package/framework/lib/types.d.ts +0 -174
  69. package/framework/lib/types.js +0 -8
  70. package/framework/templates/ErrorPage.tsx +0 -136
  71. package/framework/templates/HomePage.tsx +0 -344
  72. package/framework/templates/NotFoundPage.tsx +0 -108
  73. package/framework/templates/arcanajs.config.ts +0 -44
  74. package/framework/templates/arcanajs.d.ts +0 -8
  75. package/framework/templates/arcanajs.png +0 -0
  76. package/framework/templates/arcanajs.svg +0 -12
  77. package/framework/templates/client-index.tsx +0 -7
  78. package/framework/templates/favicon.ico +0 -0
  79. package/framework/templates/globals.css +0 -198
  80. package/framework/templates/package.json +0 -15
  81. package/framework/templates/postcss.config.js +0 -6
  82. package/framework/templates/server-controller-home.ts +0 -7
  83. package/framework/templates/server-index.ts +0 -11
  84. package/framework/templates/server-routes-web.ts +0 -7
  85. package/framework/templates/tsconfig.json +0 -27
@@ -1,165 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ArcanaJSServer = void 0;
7
- const compression_1 = __importDefault(require("compression"));
8
- const cookie_parser_1 = __importDefault(require("cookie-parser"));
9
- const express_1 = __importDefault(require("express"));
10
- const fs_1 = __importDefault(require("fs"));
11
- const helmet_1 = __importDefault(require("helmet"));
12
- const path_1 = __importDefault(require("path"));
13
- const ErrorPage_1 = __importDefault(require("../shared/views/ErrorPage"));
14
- const NotFoundPage_1 = __importDefault(require("../shared/views/NotFoundPage"));
15
- const ArcanaJSMiddleware_1 = require("./ArcanaJSMiddleware");
16
- const CsrfMiddleware_1 = require("./CsrfMiddleware");
17
- const DynamicRouter_1 = require("./DynamicRouter");
18
- const ResponseHandlerMiddleware_1 = require("./ResponseHandlerMiddleware");
19
- class ArcanaJSServer {
20
- constructor(config) {
21
- this.config = config;
22
- this.app = (0, express_1.default)();
23
- this.initialize();
24
- }
25
- initialize() {
26
- let { staticDir = "public", distDir = "dist/public", indexFile = "dist/public/index.html", views, viewsContext, routes, layout, } = this.config;
27
- // 1. Load views from config or context (highest priority)
28
- if (!views && viewsContext) {
29
- views = this.loadViewsFromContext(viewsContext);
30
- }
31
- // 2. Load views from injected alias (Webpack)
32
- if (!views) {
33
- views = this.loadViewsFromAlias();
34
- }
35
- // 3. Fallback to auto-discovery (Server-side only, non-bundled)
36
- if (!views) {
37
- views = this.discoverViews();
38
- }
39
- if (!views || Object.keys(views).length === 0) {
40
- console.warn("No views found. Please check your views directory.");
41
- views = {};
42
- }
43
- // Add default error views if not already present
44
- views.NotFoundPage = views.NotFoundPage || NotFoundPage_1.default;
45
- views.ErrorPage = views.ErrorPage || ErrorPage_1.default;
46
- // Security and Performance
47
- this.app.use((0, helmet_1.default)({
48
- contentSecurityPolicy: false,
49
- }));
50
- this.app.use((0, compression_1.default)());
51
- this.app.use((0, cookie_parser_1.default)());
52
- this.app.use((0, CsrfMiddleware_1.createCsrfMiddleware)());
53
- this.app.use(ResponseHandlerMiddleware_1.responseHandler);
54
- // Static files
55
- const isProduction = process.env.NODE_ENV === "production";
56
- const staticOptions = {
57
- index: false,
58
- maxAge: isProduction ? "1y" : "0",
59
- };
60
- this.app.use(express_1.default.static(path_1.default.resolve(process.cwd(), distDir), staticOptions));
61
- this.app.use(express_1.default.static(path_1.default.resolve(process.cwd(), staticDir), staticOptions));
62
- // ArcanaJS Middleware
63
- this.app.use((0, ArcanaJSMiddleware_1.createArcanaJSMiddleware)({
64
- views,
65
- indexFile: path_1.default.resolve(process.cwd(), indexFile),
66
- layout,
67
- }));
68
- // Custom Routes
69
- if (routes) {
70
- if (Array.isArray(routes)) {
71
- routes.forEach((route) => this.app.use(route));
72
- }
73
- else {
74
- this.app.use(routes);
75
- }
76
- }
77
- // Dynamic Router
78
- this.app.use((0, DynamicRouter_1.createDynamicRouter)(views));
79
- // 404 Fallback
80
- this.app.use((req, res) => {
81
- res.status(404).renderPage("NotFoundPage");
82
- });
83
- // Error Handler
84
- this.app.use((err, req, res, next) => {
85
- console.error(err);
86
- const message = process.env.NODE_ENV === "production"
87
- ? "Internal Server Error"
88
- : err.message;
89
- res.status(500).renderPage("ErrorPage", { message });
90
- });
91
- }
92
- loadViewsFromContext(context) {
93
- const views = {};
94
- context.keys().forEach((key) => {
95
- const viewName = key.replace(/^\.\/(.*)\.tsx$/, "$1");
96
- views[viewName] = context(key).default;
97
- });
98
- return views;
99
- }
100
- loadViewsFromAlias() {
101
- try {
102
- // @ts-ignore - This alias is injected by Webpack
103
- const injectedViews = require("arcana-views");
104
- if (injectedViews) {
105
- return this.loadViewsFromContext(injectedViews);
106
- }
107
- }
108
- catch (e) {
109
- // Ignore
110
- }
111
- return undefined;
112
- }
113
- discoverViews() {
114
- const views = {};
115
- const viewsDir = this.config.viewsDir
116
- ? path_1.default.resolve(process.cwd(), this.config.viewsDir)
117
- : path_1.default.resolve(process.cwd(), "src/views");
118
- if (!fs_1.default.existsSync(viewsDir))
119
- return views;
120
- const traverse = (dir) => {
121
- const files = fs_1.default.readdirSync(dir);
122
- files.forEach((file) => {
123
- const fullPath = path_1.default.join(dir, file);
124
- const stat = fs_1.default.statSync(fullPath);
125
- if (stat.isDirectory()) {
126
- traverse(fullPath);
127
- }
128
- else if (file.endsWith(".tsx") || file.endsWith(".jsx")) {
129
- const relativePath = path_1.default.relative(viewsDir, fullPath);
130
- const viewName = relativePath.replace(/\.(tsx|jsx)$/, "");
131
- try {
132
- // Use __non_webpack_require__ if available to avoid Webpack bundling issues
133
- // or standard require if running in Node directly
134
- const requireFunc = typeof __non_webpack_require__ !== "undefined"
135
- ? __non_webpack_require__
136
- : eval("require");
137
- // Register ts-node if needed
138
- if (file.endsWith(".tsx") || file.endsWith(".ts")) {
139
- try {
140
- requireFunc("ts-node/register");
141
- }
142
- catch (e) {
143
- // Ignore
144
- }
145
- }
146
- const pageModule = requireFunc(fullPath);
147
- views[viewName] = pageModule.default || pageModule;
148
- }
149
- catch (error) {
150
- console.error(`Failed to load view ${viewName}:`, error);
151
- }
152
- }
153
- });
154
- };
155
- traverse(viewsDir);
156
- return views;
157
- }
158
- start() {
159
- const PORT = this.config.port || process.env.PORT || 3000;
160
- this.app.listen(PORT, () => {
161
- console.log(`Server is running on http://localhost:${PORT}`);
162
- });
163
- }
164
- }
165
- exports.ArcanaJSServer = ArcanaJSServer;
@@ -1,4 +0,0 @@
1
- import { NextFunction, Request, Response } from "express";
2
- export default class ControllerBinder {
3
- static handle(controller: any, method: string): (req: Request, res: Response, next: NextFunction) => Promise<void>;
4
- }
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class ControllerBinder {
4
- static handle(controller, method) {
5
- // Instantiate the controller once (Singleton pattern) for performance
6
- // This assumes controllers are stateless, which is best practice.
7
- let instance;
8
- try {
9
- instance = new controller();
10
- }
11
- catch (e) {
12
- // Fallback if controller is not a class or fails to instantiate
13
- console.warn(`Failed to instantiate controller ${controller.name}`, e);
14
- instance = controller;
15
- }
16
- return async (req, res, next) => {
17
- try {
18
- // Call the method
19
- if (typeof instance[method] === "function") {
20
- await instance[method](req, res, next);
21
- }
22
- else {
23
- throw new Error(`Method ${method} not found on controller ${controller.name}`);
24
- }
25
- }
26
- catch (error) {
27
- next(error);
28
- }
29
- };
30
- }
31
- }
32
- exports.default = ControllerBinder;
@@ -1,2 +0,0 @@
1
- import { NextFunction, Request, Response } from "express";
2
- export declare const createCsrfMiddleware: () => (req: Request, res: Response, next: NextFunction) => Response<any, Record<string, any>> | undefined;
@@ -1,34 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createCsrfMiddleware = void 0;
7
- const crypto_1 = __importDefault(require("crypto"));
8
- const CSRF_COOKIE_NAME = "_csrf";
9
- const createCsrfMiddleware = () => {
10
- return (req, res, next) => {
11
- // 1. Generate or retrieve token
12
- let token = req.cookies[CSRF_COOKIE_NAME];
13
- if (!token) {
14
- token = crypto_1.default.randomBytes(32).toString("hex");
15
- res.cookie(CSRF_COOKIE_NAME, token, {
16
- httpOnly: true,
17
- secure: process.env.NODE_ENV === "production",
18
- sameSite: "strict",
19
- });
20
- }
21
- // 2. Expose token to the response locals (for injection into the view)
22
- res.locals.csrfToken = token;
23
- // 3. Verify token on state-changing methods
24
- const method = req.method.toUpperCase();
25
- if (["POST", "PUT", "DELETE", "PATCH"].includes(method)) {
26
- const headerToken = req.headers["x-csrf-token"];
27
- if (!headerToken || headerToken !== token) {
28
- return res.status(403).json({ error: "Invalid CSRF Token" });
29
- }
30
- }
31
- next();
32
- };
33
- };
34
- exports.createCsrfMiddleware = createCsrfMiddleware;
@@ -1,2 +0,0 @@
1
- import { NextFunction, Request, Response } from "express";
2
- export declare const createDynamicRouter: (views: Record<string, any>) => (req: Request, res: Response, next: NextFunction) => Express.Response | undefined;
@@ -1,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createDynamicRouter = void 0;
4
- const createDynamicRouter = (views) => {
5
- return (req, res, next) => {
6
- // Remove leading slash
7
- let path = req.path.substring(1);
8
- // Handle root path mapping to "index" if not handled elsewhere
9
- if (path === "") {
10
- path = "index";
11
- }
12
- // 1. Exact match
13
- if (views[path]) {
14
- return res.renderPage(path, {});
15
- }
16
- // 2. Dynamic match
17
- for (const viewName of Object.keys(views)) {
18
- if (!viewName.includes("["))
19
- continue;
20
- // Convert view path to regex
21
- // e.g., "users/[id]" -> "^users/([^/]+)$"
22
- // We need to escape special regex characters first, but keep [ and ] for our logic
23
- // Actually, simpler: split by '/' and match segments
24
- const pageParts = viewName.split("/");
25
- const pathParts = path.split("/");
26
- if (pageParts.length !== pathParts.length)
27
- continue;
28
- let match = true;
29
- const params = {};
30
- for (let i = 0; i < pageParts.length; i++) {
31
- const pagePart = pageParts[i];
32
- const pathPart = pathParts[i];
33
- if (pagePart.startsWith("[") && pagePart.endsWith("]")) {
34
- const paramName = pagePart.slice(1, -1);
35
- params[paramName] = pathPart;
36
- }
37
- else if (pagePart !== pathPart) {
38
- match = false;
39
- break;
40
- }
41
- }
42
- if (match) {
43
- return res.renderPage(viewName, {}, params);
44
- }
45
- }
46
- // If not found, pass to the next middleware (usually 404 handler)
47
- next();
48
- };
49
- };
50
- exports.createDynamicRouter = createDynamicRouter;
@@ -1,27 +0,0 @@
1
- import type { NextFunction, Request, Response } from "express";
2
- declare global {
3
- namespace Express {
4
- interface Response {
5
- /**
6
- * Sends a success response with a standard format.
7
- *
8
- * @param data - The data payload to include in the response (default: {}).
9
- * @param message - A descriptive message for the success (default: "Success").
10
- * @param status - The HTTP status code to return (default: 200).
11
- * @returns The Express Response object.
12
- */
13
- success: (data?: string | object | null, message?: string, status?: number) => Response;
14
- /**
15
- * Sends an error response with a standard format.
16
- *
17
- * @param message - A descriptive message for the error (default: "Error").
18
- * @param status - The HTTP status code to return (default: 500).
19
- * @param error - Additional error details or object (default: null).
20
- * @param data - Optional data payload to include in the error response (default: null).
21
- * @returns The Express Response object.
22
- */
23
- error: (message?: string, status?: number, error?: string | object | null, data?: string | object | null) => Response;
24
- }
25
- }
26
- }
27
- export declare const responseHandler: (req: Request, res: Response, next: NextFunction) => void;
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.responseHandler = void 0;
4
- const responseHandler = (req, res, next) => {
5
- res.success = (data = {}, message = "Success", status = 200) => {
6
- return res.status(status).json({
7
- success: true,
8
- message,
9
- data,
10
- error: null,
11
- });
12
- };
13
- res.error = (message = "Error", status = 500, error = null, data = null) => {
14
- const errorResponse = error
15
- ? typeof error === "object" && error !== null
16
- ? error instanceof Error
17
- ? error.toString()
18
- : error
19
- : error.toString()
20
- : null;
21
- return res.status(status).json({
22
- success: false,
23
- message,
24
- data,
25
- error: errorResponse,
26
- });
27
- };
28
- next();
29
- };
30
- exports.responseHandler = responseHandler;
@@ -1,94 +0,0 @@
1
- import express, { Router as ExpressRouter, RequestHandler } from "express";
2
- /**
3
- * Provides Routing syntax for defining routes with prefixes, middlewares, and groups
4
- */
5
- export declare class Router {
6
- private router;
7
- private middlewareStack;
8
- private prefixStack;
9
- constructor();
10
- /**
11
- * Create a new router instance
12
- */
13
- static create(): Router;
14
- /**
15
- * Add middleware to the current stack
16
- */
17
- middleware(...middleware: RequestHandler[]): Router;
18
- /**
19
- * Add prefix to the current stack
20
- */
21
- prefix(prefix: string): Router;
22
- /**
23
- * Create a route group
24
- */
25
- group(callback: (router: Router) => void): Router;
26
- /**
27
- * Define a GET route
28
- */
29
- get(path: string, ...args: any[]): Router;
30
- /**
31
- * Define a POST route
32
- */
33
- post(path: string, ...args: any[]): Router;
34
- /**
35
- * Define a PUT route
36
- */
37
- put(path: string, ...args: any[]): Router;
38
- /**
39
- * Define a DELETE route
40
- */
41
- delete(path: string, ...args: any[]): Router;
42
- /**
43
- * Define a PATCH route
44
- */
45
- patch(path: string, ...args: any[]): Router;
46
- /**
47
- * Define an OPTIONS route
48
- */
49
- options(path: string, ...args: any[]): Router;
50
- /**
51
- * Get the underlying Express router
52
- */
53
- getRouter(): ExpressRouter;
54
- /**
55
- * Mount this router to an Express app or router
56
- */
57
- mount(app: express.Application | ExpressRouter, basePath?: string): void;
58
- /**
59
- * Clone the current router instance
60
- */
61
- private _clone;
62
- /**
63
- * Add a route to the router
64
- */
65
- private _addRoute;
66
- /**
67
- * Build the full path with prefixes
68
- */
69
- private _buildPath;
70
- /**
71
- * Build the route handler
72
- */
73
- private _buildHandler;
74
- }
75
- /**
76
- * Static Route class for ArcanaJS Routing
77
- */
78
- export declare class Route {
79
- private static _router;
80
- static create(): Router;
81
- static middleware(...middleware: RequestHandler[]): Router;
82
- static prefix(prefix: string): Router;
83
- static group(callback: (router: Router) => void): Router;
84
- static get(path: string, ...args: any[]): Router;
85
- static post(path: string, ...args: any[]): Router;
86
- static put(path: string, ...args: any[]): Router;
87
- static delete(path: string, ...args: any[]): Router;
88
- static patch(path: string, ...args: any[]): Router;
89
- static options(path: string, ...args: any[]): Router;
90
- static getRouter(): ExpressRouter;
91
- static mount(app: express.Application, basePath?: string): void;
92
- static reset(): void;
93
- }
94
- export default Route;
@@ -1,203 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Route = exports.Router = void 0;
7
- const express_1 = __importDefault(require("express"));
8
- const ControllerBinder_1 = __importDefault(require("./ControllerBinder"));
9
- /**
10
- * Provides Routing syntax for defining routes with prefixes, middlewares, and groups
11
- */
12
- class Router {
13
- constructor() {
14
- this.router = express_1.default.Router();
15
- this.middlewareStack = [];
16
- this.prefixStack = [];
17
- }
18
- /**
19
- * Create a new router instance
20
- */
21
- static create() {
22
- return new Router();
23
- }
24
- /**
25
- * Add middleware to the current stack
26
- */
27
- middleware(...middleware) {
28
- const newRouter = this._clone();
29
- newRouter.middlewareStack = [...this.middlewareStack, ...middleware];
30
- return newRouter;
31
- }
32
- /**
33
- * Add prefix to the current stack
34
- */
35
- prefix(prefix) {
36
- const newRouter = this._clone();
37
- newRouter.prefixStack = [
38
- ...this.prefixStack,
39
- prefix.replace(/^\/|\/$/g, ""),
40
- ];
41
- return newRouter;
42
- }
43
- /**
44
- * Create a route group
45
- */
46
- group(callback) {
47
- callback(this);
48
- return this;
49
- }
50
- /**
51
- * Define a GET route
52
- */
53
- get(path, ...args) {
54
- const action = args.pop();
55
- const middlewares = args;
56
- return this._addRoute("get", path, action, middlewares);
57
- }
58
- /**
59
- * Define a POST route
60
- */
61
- post(path, ...args) {
62
- const action = args.pop();
63
- const middlewares = args;
64
- return this._addRoute("post", path, action, middlewares);
65
- }
66
- /**
67
- * Define a PUT route
68
- */
69
- put(path, ...args) {
70
- const action = args.pop();
71
- const middlewares = args;
72
- return this._addRoute("put", path, action, middlewares);
73
- }
74
- /**
75
- * Define a DELETE route
76
- */
77
- delete(path, ...args) {
78
- const action = args.pop();
79
- const middlewares = args;
80
- return this._addRoute("delete", path, action, middlewares);
81
- }
82
- /**
83
- * Define a PATCH route
84
- */
85
- patch(path, ...args) {
86
- const action = args.pop();
87
- const middlewares = args;
88
- return this._addRoute("patch", path, action, middlewares);
89
- }
90
- /**
91
- * Define an OPTIONS route
92
- */
93
- options(path, ...args) {
94
- const action = args.pop();
95
- const middlewares = args;
96
- return this._addRoute("options", path, action, middlewares);
97
- }
98
- /**
99
- * Get the underlying Express router
100
- */
101
- getRouter() {
102
- return this.router;
103
- }
104
- /**
105
- * Mount this router to an Express app or router
106
- */
107
- mount(app, basePath = "/") {
108
- app.use(basePath, this.router);
109
- }
110
- /**
111
- * Clone the current router instance
112
- */
113
- _clone() {
114
- const newRouter = new Router();
115
- newRouter.router = this.router;
116
- newRouter.middlewareStack = [...this.middlewareStack];
117
- newRouter.prefixStack = [...this.prefixStack];
118
- return newRouter;
119
- }
120
- /**
121
- * Add a route to the router
122
- */
123
- _addRoute(method, path, action, routeMiddlewares = []) {
124
- const fullPath = this._buildPath(path);
125
- const handler = this._buildHandler(action);
126
- const flatMiddlewares = routeMiddlewares.flat(Infinity);
127
- const middlewares = [...this.middlewareStack, ...flatMiddlewares, handler];
128
- this.router[method](fullPath, ...middlewares);
129
- return this;
130
- }
131
- /**
132
- * Build the full path with prefixes
133
- */
134
- _buildPath(path) {
135
- const cleanPath = path.replace(/^\//, "");
136
- const prefixes = this.prefixStack.filter((p) => p !== "");
137
- if (prefixes.length === 0) {
138
- return `/${cleanPath}`;
139
- }
140
- return `/${prefixes.join("/")}/${cleanPath}`.replace(/\/+/g, "/");
141
- }
142
- /**
143
- * Build the route handler
144
- */
145
- _buildHandler(action) {
146
- if (typeof action === "function") {
147
- return action;
148
- }
149
- if (Array.isArray(action) && action.length === 2) {
150
- const [controller, method] = action;
151
- return ControllerBinder_1.default.handle(controller, method);
152
- }
153
- throw new Error('Action must be a function or array [Controller, "method"]');
154
- }
155
- }
156
- exports.Router = Router;
157
- /**
158
- * Static Route class for ArcanaJS Routing
159
- */
160
- class Route {
161
- static create() {
162
- return Router.create();
163
- }
164
- static middleware(...middleware) {
165
- return this._router.middleware(...middleware);
166
- }
167
- static prefix(prefix) {
168
- return this._router.prefix(prefix);
169
- }
170
- static group(callback) {
171
- return this._router.group(callback);
172
- }
173
- static get(path, ...args) {
174
- return this._router.get(path, ...args);
175
- }
176
- static post(path, ...args) {
177
- return this._router.post(path, ...args);
178
- }
179
- static put(path, ...args) {
180
- return this._router.put(path, ...args);
181
- }
182
- static delete(path, ...args) {
183
- return this._router.delete(path, ...args);
184
- }
185
- static patch(path, ...args) {
186
- return this._router.patch(path, ...args);
187
- }
188
- static options(path, ...args) {
189
- return this._router.options(path, ...args);
190
- }
191
- static getRouter() {
192
- return this._router.getRouter();
193
- }
194
- static mount(app, basePath = "/") {
195
- return this._router.mount(app, basePath);
196
- }
197
- static reset() {
198
- this._router = new Router();
199
- }
200
- }
201
- exports.Route = Route;
202
- Route._router = new Router();
203
- exports.default = Route;
@@ -1,12 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
- <!--HEAD_CONTENT-->
7
- </head>
8
- <body>
9
- <div id="root"><!--APP_CONTENT--></div>
10
- <!--ARCANAJS_DATA_SCRIPT-->
11
- </body>
12
- </html>