arcanajs 2.6.0 → 3.0.1
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/README.md +7 -22
- package/bin/arcanajs.js +1 -1
- package/dist/arcanajs.client.js +2 -0
- package/dist/arcanajs.client.js.map +1 -0
- package/dist/arcanajs.js +2 -0
- package/dist/arcanajs.js.map +1 -0
- package/dist/cli/index.js +2 -0
- package/dist/cli/index.js.map +1 -0
- package/{framework → dist}/lib/client/index.d.ts +6 -26
- package/{framework → dist}/lib/global.d.ts +6 -10
- package/dist/lib/index.client.d.ts +11 -0
- package/dist/lib/index.d.ts +38 -0
- package/{framework → dist}/lib/server/ArcanaJSServer.d.ts +4 -4
- package/dist/lib/server/DefaultTemplate.d.ts +1 -0
- package/{framework → dist}/lib/shared/components/Body.d.ts +2 -2
- package/{framework → dist}/lib/shared/components/Head.d.ts +2 -1
- package/{framework → dist}/lib/shared/components/Link.d.ts +2 -2
- package/{framework → dist}/lib/shared/components/NavLink.d.ts +2 -2
- package/{framework → dist}/lib/shared/components/Page.d.ts +2 -1
- package/{framework → dist}/lib/shared/hooks/useLocation.d.ts +2 -1
- package/dist/lib/shared/hooks/usePage.d.ts +2 -0
- package/dist/lib/shared/hooks/useParams.d.ts +2 -0
- package/dist/lib/shared/hooks/useQuery.d.ts +2 -0
- package/dist/lib/shared/hooks/useRouter.d.ts +2 -0
- package/package.json +26 -23
- package/framework/cli/index.js +0 -204
- package/framework/cli/templates.d.ts +0 -6
- package/framework/cli/templates.js +0 -62
- package/framework/cli/webpack.config.js +0 -310
- package/framework/lib/client/index.js +0 -97
- package/framework/lib/config/index.d.ts +0 -46
- package/framework/lib/config/index.js +0 -115
- package/framework/lib/index.d.ts +0 -19
- package/framework/lib/index.js +0 -59
- package/framework/lib/server/ArcanaJSMiddleware.js +0 -114
- package/framework/lib/server/ArcanaJSServer.js +0 -441
- package/framework/lib/server/ControllerBinder.js +0 -32
- package/framework/lib/server/CsrfMiddleware.js +0 -34
- package/framework/lib/server/DynamicRouter.js +0 -50
- package/framework/lib/server/ResponseHandlerMiddleware.js +0 -30
- package/framework/lib/server/Router.js +0 -203
- package/framework/lib/server/default-index.html +0 -12
- package/framework/lib/server.d.ts +0 -33
- package/framework/lib/server.js +0 -69
- package/framework/lib/shared/components/Body.js +0 -8
- package/framework/lib/shared/components/Head.js +0 -125
- package/framework/lib/shared/components/Link.js +0 -30
- package/framework/lib/shared/components/NavLink.js +0 -13
- package/framework/lib/shared/components/Page.js +0 -10
- package/framework/lib/shared/context/HeadContext.js +0 -5
- package/framework/lib/shared/context/PageContext.js +0 -6
- package/framework/lib/shared/context/RouterContext.js +0 -10
- package/framework/lib/shared/core/ArcanaJSApp.js +0 -194
- package/framework/lib/shared/hooks/useHead.js +0 -7
- package/framework/lib/shared/hooks/useLocation.js +0 -13
- package/framework/lib/shared/hooks/usePage.d.ts +0 -1
- package/framework/lib/shared/hooks/usePage.js +0 -7
- package/framework/lib/shared/hooks/useParams.d.ts +0 -1
- package/framework/lib/shared/hooks/useParams.js +0 -13
- package/framework/lib/shared/hooks/useQuery.d.ts +0 -1
- package/framework/lib/shared/hooks/useQuery.js +0 -9
- package/framework/lib/shared/hooks/useRouter.d.ts +0 -1
- package/framework/lib/shared/hooks/useRouter.js +0 -13
- package/framework/lib/shared/utils/createSingletonContext.js +0 -21
- package/framework/lib/shared/views/ErrorPage.js +0 -12
- package/framework/lib/shared/views/NotFoundPage.js +0 -11
- package/framework/lib/types.d.ts +0 -174
- package/framework/lib/types.js +0 -8
- package/framework/templates/arcanajs.config.ts +0 -44
- package/framework/templates/package.json +0 -15
- package/framework/templates/postcss.config.js +0 -6
- package/framework/templates/public/arcanajs.png +0 -0
- package/framework/templates/public/arcanajs.svg +0 -12
- package/framework/templates/public/favicon.ico +0 -0
- package/framework/templates/src/arcanajs.d.ts +0 -8
- package/framework/templates/src/client/globals.css +0 -199
- package/framework/templates/src/client/index.tsx +0 -7
- package/framework/templates/src/db/mongo.ts +0 -10
- package/framework/templates/src/db/mongoose.ts +0 -12
- package/framework/templates/src/db/mysql.ts +0 -15
- package/framework/templates/src/db/postgres.ts +0 -8
- package/framework/templates/src/server/controllers/HomeController.ts +0 -19
- package/framework/templates/src/server/controllers/UsersController.ts +0 -37
- package/framework/templates/src/server/index.ts +0 -38
- package/framework/templates/src/server/routes/api.ts +0 -6
- package/framework/templates/src/server/routes/web.ts +0 -7
- package/framework/templates/src/types/HomePageData.ts +0 -11
- package/framework/templates/src/views/ErrorPage.tsx +0 -136
- package/framework/templates/src/views/HomePage.tsx +0 -369
- package/framework/templates/src/views/NotFoundPage.tsx +0 -108
- package/framework/templates/tsconfig.json +0 -27
- /package/{framework → dist}/cli/index.d.ts +0 -0
- /package/{framework → dist}/cli/webpack.config.d.ts +0 -0
- /package/{framework → dist}/lib/server/ArcanaJSMiddleware.d.ts +0 -0
- /package/{framework → dist}/lib/server/ControllerBinder.d.ts +0 -0
- /package/{framework → dist}/lib/server/CsrfMiddleware.d.ts +0 -0
- /package/{framework → dist}/lib/server/DynamicRouter.d.ts +0 -0
- /package/{framework → dist}/lib/server/ResponseHandlerMiddleware.d.ts +0 -0
- /package/{framework → dist}/lib/server/Router.d.ts +0 -0
- /package/{framework → dist}/lib/shared/context/HeadContext.d.ts +0 -0
- /package/{framework → dist}/lib/shared/context/PageContext.d.ts +0 -0
- /package/{framework → dist}/lib/shared/context/RouterContext.d.ts +0 -0
- /package/{framework → dist}/lib/shared/core/ArcanaJSApp.d.ts +0 -0
- /package/{framework → dist}/lib/shared/hooks/useHead.d.ts +0 -0
- /package/{framework → dist}/lib/shared/utils/createSingletonContext.d.ts +0 -0
- /package/{framework → dist}/lib/shared/views/ErrorPage.d.ts +0 -0
- /package/{framework → dist}/lib/shared/views/NotFoundPage.d.ts +0 -0
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export default async function dbConnect() {
|
|
2
|
-
// Example MongoDB connection using the official driver
|
|
3
|
-
const { MongoClient } = await import("mongodb");
|
|
4
|
-
const url = process.env.MONGO_URL || "mongodb://localhost:27017";
|
|
5
|
-
const dbName = process.env.MONGO_DB || "mydb";
|
|
6
|
-
const client = new MongoClient(url);
|
|
7
|
-
await client.connect();
|
|
8
|
-
const db = client.db(dbName);
|
|
9
|
-
return { client, db };
|
|
10
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import mongoose from "mongoose";
|
|
2
|
-
|
|
3
|
-
export default async function dbConnect() {
|
|
4
|
-
const uri =
|
|
5
|
-
process.env.MONGOOSE_URI ||
|
|
6
|
-
process.env.MONGO_URL ||
|
|
7
|
-
"mongodb://localhost:27017/mydb";
|
|
8
|
-
const options = {} as mongoose.ConnectOptions;
|
|
9
|
-
|
|
10
|
-
await mongoose.connect(uri, options);
|
|
11
|
-
return mongoose;
|
|
12
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export default async function dbConnect() {
|
|
2
|
-
const mysql = await import("mysql2/promise");
|
|
3
|
-
const uri = process.env.MYSQL_URL;
|
|
4
|
-
if (uri) {
|
|
5
|
-
return await mysql.createConnection(uri as any);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const connection = await mysql.createConnection({
|
|
9
|
-
host: process.env.MYSQL_HOST || "localhost",
|
|
10
|
-
user: process.env.MYSQL_USER || "root",
|
|
11
|
-
database: process.env.MYSQL_DB || "mydb",
|
|
12
|
-
password: process.env.MYSQL_PASSWORD || undefined,
|
|
13
|
-
});
|
|
14
|
-
return connection;
|
|
15
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export default async function dbConnect() {
|
|
2
|
-
const { Client } = await import("pg");
|
|
3
|
-
const connectionString =
|
|
4
|
-
process.env.PG_CONNECTION || process.env.DATABASE_URL;
|
|
5
|
-
const client = new Client({ connectionString });
|
|
6
|
-
await client.connect();
|
|
7
|
-
return client;
|
|
8
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Request, Response } from "arcanajs/server";
|
|
2
|
-
import type { HomePageData } from "../../types/HomePageData";
|
|
3
|
-
|
|
4
|
-
export default class HomeController {
|
|
5
|
-
home(_req: Request, res: Response) {
|
|
6
|
-
// Provide example page data to demonstrate passing data to the view
|
|
7
|
-
const data: HomePageData = {
|
|
8
|
-
welcome: "Welcome to ArcanaJS",
|
|
9
|
-
subtitle: "A modern React framework with server-side rendering",
|
|
10
|
-
time: new Date().toISOString(),
|
|
11
|
-
posts: [
|
|
12
|
-
{ id: 1, title: "Getting started with ArcanaJS" },
|
|
13
|
-
{ id: 2, title: "Building fast apps with SSR" },
|
|
14
|
-
],
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
res.renderPage("HomePage", data);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Request, Response } from "arcanajs/server";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* UsersController - example controller for users endpoints.
|
|
5
|
-
*/
|
|
6
|
-
export default class UsersController {
|
|
7
|
-
async users(req: Request, res: Response) {
|
|
8
|
-
try {
|
|
9
|
-
const normalized: any = (req as any).db || req.app?.locals?.db;
|
|
10
|
-
if (!normalized) return res.error("No DB connection", 500, null, null);
|
|
11
|
-
|
|
12
|
-
const client: any = normalized.client || normalized;
|
|
13
|
-
const db: any = normalized.db || normalized;
|
|
14
|
-
|
|
15
|
-
if (db && typeof db.collection === "function") {
|
|
16
|
-
const users = await db.collection("users").find().toArray();
|
|
17
|
-
return res.success(users, "Users retrieved successfully", 200);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (client && typeof client.query === "function") {
|
|
21
|
-
const result = await client.query("SELECT * FROM users LIMIT 100");
|
|
22
|
-
const rows = result.rows || result[0] || result;
|
|
23
|
-
return res.success(rows, "Users retrieved successfully", 200);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return res.error(
|
|
27
|
-
"Unsupported DB client in template example",
|
|
28
|
-
400,
|
|
29
|
-
null,
|
|
30
|
-
null
|
|
31
|
-
);
|
|
32
|
-
} catch (err) {
|
|
33
|
-
console.error(err);
|
|
34
|
-
return res.error("Query failed", 500, err as any, null);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { ArcanaJSServer } from "arcanajs/server";
|
|
2
|
-
import apiRoutes from "./routes/api";
|
|
3
|
-
import webRoutes from "./routes/web";
|
|
4
|
-
|
|
5
|
-
// Example DB connectors included in templates:
|
|
6
|
-
// import mongoDb from '../db/mongo';
|
|
7
|
-
// import mongooseDb from '../db/mongoose';
|
|
8
|
-
// import pgDb from '../db/postgres';
|
|
9
|
-
// import mysqlDb from '../db/mysql';
|
|
10
|
-
|
|
11
|
-
const PORT = process.env.PORT || 3000;
|
|
12
|
-
|
|
13
|
-
const server = new ArcanaJSServer({
|
|
14
|
-
port: PORT,
|
|
15
|
-
routes: webRoutes,
|
|
16
|
-
// Separate API routes (mounted under /api by default)
|
|
17
|
-
apiRoutes: apiRoutes,
|
|
18
|
-
// To change the base path, set apiBase: '/v1' for example or similar
|
|
19
|
-
apiBase: "/api",
|
|
20
|
-
// Example: provide a dbConnect function that returns the DB client/connection.
|
|
21
|
-
// You can connect to MySQL/Postgres/MongoDB here and return the client.
|
|
22
|
-
// dbConnect: async () => {
|
|
23
|
-
// const { MongoClient } = await import("mongodb");
|
|
24
|
-
// const url = process.env.MONGO_URL || "mongodb://localhost:27017";
|
|
25
|
-
// const dbName = process.env.MONGO_DB || "mydb";
|
|
26
|
-
// const client = new MongoClient(url);
|
|
27
|
-
// await client.connect();
|
|
28
|
-
// const db = client.db(dbName);
|
|
29
|
-
// return { client, db };
|
|
30
|
-
// },
|
|
31
|
-
// Or use one of the provided DB templates (uncomment one):
|
|
32
|
-
// dbConnect: mongoDb,
|
|
33
|
-
// dbConnect: mongooseDb,
|
|
34
|
-
// dbConnect: pgDb,
|
|
35
|
-
// dbConnect: mysqlDb,
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
server.start();
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { Body, Head, Link, Page } from "arcanajs";
|
|
2
|
-
|
|
3
|
-
interface ErrorPageProps {
|
|
4
|
-
message?: string;
|
|
5
|
-
statusCode?: number;
|
|
6
|
-
stack?: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export default function ErrorPage({
|
|
10
|
-
message = "Something went wrong",
|
|
11
|
-
statusCode = 500,
|
|
12
|
-
stack,
|
|
13
|
-
}: ErrorPageProps) {
|
|
14
|
-
const isDevelopment = process.env.NODE_ENV === "development";
|
|
15
|
-
|
|
16
|
-
return (
|
|
17
|
-
<Page>
|
|
18
|
-
<Head>
|
|
19
|
-
<title>{statusCode} - Server Error</title>
|
|
20
|
-
<meta name="description" content="An error occurred on the server" />
|
|
21
|
-
</Head>
|
|
22
|
-
<Body>
|
|
23
|
-
<div className="relative min-h-screen overflow-hidden bg-black text-white flex flex-col justify-center items-center px-4 font-sans">
|
|
24
|
-
{/* Animated Background */}
|
|
25
|
-
<div className="fixed inset-0 z-0 overflow-hidden pointer-events-none">
|
|
26
|
-
<div className="absolute inset-0 grid-pattern opacity-30"></div>
|
|
27
|
-
<div className="absolute top-1/4 right-1/4 w-96 h-96 bg-red-600 rounded-full opacity-20 blur-3xl animate-glow"></div>
|
|
28
|
-
<div
|
|
29
|
-
className="absolute bottom-1/4 left-1/4 w-96 h-96 bg-orange-600 rounded-full opacity-10 blur-3xl animate-glow"
|
|
30
|
-
style={{ animationDelay: "2s" }}
|
|
31
|
-
></div>
|
|
32
|
-
<div className="absolute inset-0 hero-gradient"></div>
|
|
33
|
-
</div>
|
|
34
|
-
|
|
35
|
-
<div className="relative z-10 max-w-2xl w-full text-center animate-scale-in">
|
|
36
|
-
<div className="glass-card rounded-3xl p-12 border border-white/10 shadow-2xl">
|
|
37
|
-
<div className="mb-8">
|
|
38
|
-
<div className="text-6xl mb-6 animate-float">
|
|
39
|
-
<span className="text-red-500 drop-shadow-lg filter">⚠️</span>
|
|
40
|
-
</div>
|
|
41
|
-
<h1 className="text-8xl font-bold text-transparent bg-clip-text bg-gradient-to-br from-red-500 to-orange-500 mb-4">
|
|
42
|
-
{statusCode}
|
|
43
|
-
</h1>
|
|
44
|
-
<h2 className="text-3xl font-bold text-white mb-4">
|
|
45
|
-
Server Error
|
|
46
|
-
</h2>
|
|
47
|
-
<p className="text-gray-400 text-lg leading-relaxed">
|
|
48
|
-
{message}
|
|
49
|
-
</p>
|
|
50
|
-
</div>
|
|
51
|
-
|
|
52
|
-
<div className="flex flex-col sm:flex-row gap-4 justify-center mb-8">
|
|
53
|
-
<Link
|
|
54
|
-
href="/"
|
|
55
|
-
className="btn-primary px-8 py-3.5 text-white font-semibold rounded-xl inline-flex items-center justify-center gap-2 w-full sm:w-auto bg-gradient-to-r from-red-600 to-orange-600 hover:from-red-500 hover:to-orange-500 border-none shadow-red-900/20"
|
|
56
|
-
>
|
|
57
|
-
<svg
|
|
58
|
-
className="w-5 h-5"
|
|
59
|
-
fill="none"
|
|
60
|
-
stroke="currentColor"
|
|
61
|
-
viewBox="0 0 24 24"
|
|
62
|
-
>
|
|
63
|
-
<path
|
|
64
|
-
strokeLinecap="round"
|
|
65
|
-
strokeLinejoin="round"
|
|
66
|
-
strokeWidth={2}
|
|
67
|
-
d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"
|
|
68
|
-
/>
|
|
69
|
-
</svg>
|
|
70
|
-
Go Home
|
|
71
|
-
</Link>
|
|
72
|
-
|
|
73
|
-
<button
|
|
74
|
-
onClick={() => window.location.reload()}
|
|
75
|
-
className="btn-secondary px-8 py-3.5 text-white font-semibold rounded-xl inline-flex items-center justify-center gap-2 w-full sm:w-auto"
|
|
76
|
-
>
|
|
77
|
-
<svg
|
|
78
|
-
className="w-5 h-5"
|
|
79
|
-
fill="none"
|
|
80
|
-
stroke="currentColor"
|
|
81
|
-
viewBox="0 0 24 24"
|
|
82
|
-
>
|
|
83
|
-
<path
|
|
84
|
-
strokeLinecap="round"
|
|
85
|
-
strokeLinejoin="round"
|
|
86
|
-
strokeWidth={2}
|
|
87
|
-
d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"
|
|
88
|
-
/>
|
|
89
|
-
</svg>
|
|
90
|
-
Try Again
|
|
91
|
-
</button>
|
|
92
|
-
</div>
|
|
93
|
-
|
|
94
|
-
{isDevelopment && stack && (
|
|
95
|
-
<div className="mt-8 text-left animate-slide-up">
|
|
96
|
-
<details className="bg-black/40 border border-white/10 rounded-xl overflow-hidden group">
|
|
97
|
-
<summary className="cursor-pointer font-medium text-gray-300 p-4 hover:bg-white/5 transition-colors flex items-center justify-between select-none">
|
|
98
|
-
<span>Stack Trace (Development Only)</span>
|
|
99
|
-
<svg
|
|
100
|
-
className="w-5 h-5 text-gray-500 group-open:rotate-180 transition-transform"
|
|
101
|
-
fill="none"
|
|
102
|
-
stroke="currentColor"
|
|
103
|
-
viewBox="0 0 24 24"
|
|
104
|
-
>
|
|
105
|
-
<path
|
|
106
|
-
strokeLinecap="round"
|
|
107
|
-
strokeLinejoin="round"
|
|
108
|
-
strokeWidth={2}
|
|
109
|
-
d="M19 9l-7 7-7-7"
|
|
110
|
-
/>
|
|
111
|
-
</svg>
|
|
112
|
-
</summary>
|
|
113
|
-
<pre className="text-xs text-red-300/80 p-4 overflow-x-auto whitespace-pre-wrap font-mono border-t border-white/5 bg-black/20">
|
|
114
|
-
{stack}
|
|
115
|
-
</pre>
|
|
116
|
-
</details>
|
|
117
|
-
</div>
|
|
118
|
-
)}
|
|
119
|
-
</div>
|
|
120
|
-
|
|
121
|
-
<div className="mt-8 text-gray-500 text-sm">
|
|
122
|
-
If this problem persists, please{" "}
|
|
123
|
-
<Link
|
|
124
|
-
href="/contact"
|
|
125
|
-
className="text-red-400 hover:text-red-300 underline transition-colors"
|
|
126
|
-
>
|
|
127
|
-
contact support
|
|
128
|
-
</Link>
|
|
129
|
-
.
|
|
130
|
-
</div>
|
|
131
|
-
</div>
|
|
132
|
-
</div>
|
|
133
|
-
</Body>
|
|
134
|
-
</Page>
|
|
135
|
-
);
|
|
136
|
-
}
|