baraqex 1.0.47 → 1.0.49

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 (28) hide show
  1. package/dist/index.js +236 -189
  2. package/dist/index.js.map +4 -4
  3. package/dist/server.js +1282 -864
  4. package/dist/server.js.map +4 -4
  5. package/package.json +1 -1
  6. package/templates/fullstack-template/package-lock.json +931 -4
  7. package/templates/fullstack-template/package.json +7 -5
  8. package/templates/fullstack-template/server.js +548 -15
  9. package/templates/fullstack-template/src/api/hello.js +9 -11
  10. package/templates/fullstack-template/src/pages/index.js +196 -114
  11. package/templates/fullstack-app/package-lock.json +0 -3683
  12. package/templates/fullstack-app/package.json +0 -26
  13. package/templates/fullstack-app/public/client.js +0 -139
  14. package/templates/fullstack-app/public/fullstack-styles.css +0 -445
  15. package/templates/fullstack-app/server.js +0 -32
  16. package/templates/fullstack-app/src/api/auth.js +0 -48
  17. package/templates/fullstack-app/src/api/users.js +0 -85
  18. package/templates/fullstack-app/src/pages/index.js +0 -0
  19. package/templates/fullstack-app/src/pages/index.jsx +0 -181
  20. package/templates/fullstack-app/src/pages/login.js +0 -139
  21. package/templates/fullstack-app/src/pages/login.jsx +0 -150
  22. package/templates/fullstack-template/public/client.js +0 -17
  23. package/templates/fullstack-template/src/api/users/index.js +0 -43
  24. package/templates/go-wasm-app/package.json +0 -24
  25. package/templates/go-wasm-app/public/wasm-styles.css +0 -184
  26. package/templates/go-wasm-app/server.js +0 -36
  27. package/templates/go-wasm-app/src/pages/index.jsx +0 -161
  28. package/templates/go-wasm-app/src/wasm/main.go +0 -164
@@ -1,85 +0,0 @@
1
- // GET /api/users - Get all users
2
- export async function get(req, res) {
3
- try {
4
- // Mock data - replace with actual database query
5
- const users = [
6
- { id: 1, name: 'John Doe', email: 'john@example.com', role: 'admin' },
7
- { id: 2, name: 'Jane Smith', email: 'jane@example.com', role: 'user' },
8
- { id: 3, name: 'Bob Johnson', email: 'bob@example.com', role: 'user' }
9
- ];
10
-
11
- const { page, limit, skip } = req.pagination || { page: 1, limit: 10, skip: 0 };
12
- const total = users.length;
13
- const paginatedUsers = users.slice(skip, skip + limit);
14
-
15
- res.json({
16
- success: true,
17
- data: {
18
- users: paginatedUsers,
19
- pagination: {
20
- page,
21
- limit,
22
- total,
23
- pages: Math.ceil(total / limit)
24
- }
25
- }
26
- });
27
- } catch (error) {
28
- res.status(500).json({
29
- success: false,
30
- message: 'Failed to fetch users',
31
- error: error.message
32
- });
33
- }
34
- }
35
-
36
- // POST /api/users - Create a new user
37
- export async function post(req, res) {
38
- try {
39
- const { name, email, password, role = 'user' } = req.body;
40
-
41
- // Validate required fields
42
- if (!name || !email || !password) {
43
- return res.status(400).json({
44
- success: false,
45
- message: 'Name, email, and password are required'
46
- });
47
- }
48
-
49
- // Mock user creation - replace with actual database logic
50
- const newUser = {
51
- id: Date.now(),
52
- name,
53
- email,
54
- role,
55
- createdAt: new Date().toISOString()
56
- };
57
-
58
- res.status(201).json({
59
- success: true,
60
- message: 'User created successfully',
61
- data: { user: newUser }
62
- });
63
- } catch (error) {
64
- res.status(500).json({
65
- success: false,
66
- message: 'Failed to create user',
67
- error: error.message
68
- });
69
- }
70
- }
71
-
72
- // Middleware for this route
73
- export const middleware = [
74
- // Add authentication middleware here if needed
75
- // auth.requireAuth(),
76
- // Add pagination middleware
77
- (req, res, next) => {
78
- const page = Math.max(1, parseInt(req.query.page) || 1);
79
- const limit = Math.max(1, Math.min(100, parseInt(req.query.limit) || 10));
80
- const skip = (page - 1) * limit;
81
-
82
- req.pagination = { page, limit, skip };
83
- next();
84
- }
85
- ];
File without changes
@@ -1,181 +0,0 @@
1
- // Simple template string component for server-side rendering
2
- export default function HomePage(props) {
3
- return `
4
- <!DOCTYPE html>
5
- <html lang="en">
6
- <head>
7
- <title>Baraqex Fullstack App</title>
8
- <meta name="description" content="A complete fullstack application built with Baraqex framework" />
9
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
10
- <link rel="stylesheet" href="/fullstack-styles.css" />
11
- </head>
12
- <body>
13
- <div class="fullstack-app">
14
- <header class="header">
15
- <div class="container">
16
- <h1>⚡ Baraqex Fullstack App</h1>
17
- <nav>
18
- <a href="/">Home</a>
19
- <a href="/api-docs">API Docs</a>
20
- <a href="/login">Login</a>
21
- </nav>
22
- </div>
23
- </header>
24
-
25
- <main class="main-content">
26
- <div class="container">
27
- <section class="hero">
28
- <h2>Welcome to Your Fullstack Application!</h2>
29
- <p>This template includes everything you need for a complete web application:</p>
30
- <div class="features">
31
- <div class="feature">
32
- <h3>🔌 RESTful API</h3>
33
- <p>Pre-built API routes with authentication and CRUD operations</p>
34
- </div>
35
- <div class="feature">
36
- <h3>🗄️ Database Ready</h3>
37
- <p>Supports MongoDB, MySQL, and PostgreSQL out of the box</p>
38
- </div>
39
- <div class="feature">
40
- <h3>🔐 Authentication</h3>
41
- <p>JWT-based authentication with role-based access control</p>
42
- </div>
43
- <div class="feature">
44
- <h3>🌐 SSR + SPA</h3>
45
- <p>Server-side rendering with client-side hydration</p>
46
- </div>
47
- </div>
48
- </section>
49
-
50
- <section class="api-demo">
51
- <h3>🚀 Live API Demo</h3>
52
- <p>Server time: <strong>${props.api.serverTime}</strong></p>
53
-
54
- <div class="users-section">
55
- <div class="section-header">
56
- <h4>👥 Users API Demo</h4>
57
- <button onclick="fetchUsers()" class="btn btn-primary">
58
- Refresh Users
59
- </button>
60
- </div>
61
-
62
- <div id="users-container">
63
- <div class="users-grid" id="users-grid">
64
- <!-- Users will be loaded here -->
65
- </div>
66
- </div>
67
- </div>
68
-
69
- <div class="api-endpoints">
70
- <h4>🔌 Available API Endpoints</h4>
71
- <div class="endpoints-list">
72
- <div class="endpoint">
73
- <span class="method get">GET</span>
74
- <span class="path">/api/users</span>
75
- <span class="desc">Get all users</span>
76
- </div>
77
- <div class="endpoint">
78
- <span class="method post">POST</span>
79
- <span class="path">/api/users</span>
80
- <span class="desc">Create a new user</span>
81
- </div>
82
- <div class="endpoint">
83
- <span class="method post">POST</span>
84
- <span class="path">/api/auth</span>
85
- <span class="desc">User authentication</span>
86
- </div>
87
- <div class="endpoint">
88
- <span class="method get">GET</span>
89
- <span class="path">/api-docs</span>
90
- <span class="desc">API documentation</span>
91
- </div>
92
- </div>
93
- </div>
94
- </section>
95
-
96
- <section class="getting-started">
97
- <h3>🎯 Getting Started</h3>
98
- <div class="steps">
99
- <div class="step">
100
- <h4>1. Configure Database</h4>
101
- <p>Uncomment the database configuration in <code>server.js</code></p>
102
- <pre><code>// Uncomment in server.js
103
- db: {
104
- type: 'mongodb',
105
- url: process.env.DATABASE_URL || 'mongodb://localhost:27017/baraqex'
106
- }</code></pre>
107
- </div>
108
- <div class="step">
109
- <h4>2. Enable Authentication</h4>
110
- <p>Uncomment the auth configuration for JWT-based authentication</p>
111
- <pre><code>// Uncomment in server.js
112
- auth: {
113
- secret: process.env.JWT_SECRET || 'your-secret-key',
114
- expiresIn: '7d'
115
- }</code></pre>
116
- </div>
117
- <div class="step">
118
- <h4>3. Add Your API Routes</h4>
119
- <p>Create new files in <code>src/api/</code> directory</p>
120
- <pre><code>// src/api/posts.js
121
- export async function get(req, res) {
122
- res.json({ posts: [] });
123
- }</code></pre>
124
- </div>
125
- </div>
126
- </section>
127
- </div>
128
- </main>
129
-
130
- <footer class="footer">
131
- <div class="container">
132
- <p>Built with ❤️ using Baraqex Framework • Server Time: ${props.api.serverTime}</p>
133
- </div>
134
- </footer>
135
- </div>
136
-
137
- <script>
138
- async function fetchUsers() {
139
- const container = document.getElementById('users-grid');
140
- container.innerHTML = '<div class="loading">Loading users...</div>';
141
-
142
- try {
143
- const response = await fetch('/api/users');
144
- if (!response.ok) {
145
- throw new Error('Failed to fetch users');
146
- }
147
- const data = await response.json();
148
- const users = data.data.users || [];
149
-
150
- if (users.length > 0) {
151
- container.innerHTML = users.map(user => \`
152
- <div class="user-card">
153
- <h5>\${user.name}</h5>
154
- <p>\${user.email}</p>
155
- <span class="role \${user.role}">\${user.role}</span>
156
- </div>
157
- \`).join('');
158
- } else {
159
- container.innerHTML = '<div class="no-users">No users found</div>';
160
- }
161
- } catch (error) {
162
- container.innerHTML = \`<div class="error-message">❌ Error: \${error.message}</div>\`;
163
- }
164
- }
165
-
166
- // Load users on page load
167
- document.addEventListener('DOMContentLoaded', fetchUsers);
168
- </script>
169
- </body>
170
- </html>
171
- `;
172
- }
173
-
174
- // Static methods for SSR
175
- HomePage.getTitle = (props) => 'Baraqex Fullstack App';
176
- HomePage.getDescription = (props) => 'A complete fullstack application built with Baraqex framework';
177
- HomePage.getMeta = (props) => ({
178
- 'og:title': 'Baraqex Fullstack App',
179
- 'og:description': 'Complete solution with API routes, authentication, and database integration',
180
- 'og:type': 'website'
181
- });
@@ -1,139 +0,0 @@
1
- export default function LoginPage(props) {
2
- return `
3
- <div class="fullstack-app">
4
- <header class="header">
5
- <div class="container">
6
- <h1>⚡ Baraqex Fullstack App</h1>
7
- <nav>
8
- <a href="/">Home</a>
9
- <a href="/api-docs">API Docs</a>
10
- <a href="/login" class="active">Login</a>
11
- </nav>
12
- </div>
13
- </header>
14
-
15
- <main class="main-content">
16
- <div class="container">
17
- <div class="login-container">
18
- <div class="login-card">
19
- <h2>🔐 Login</h2>
20
- <p>Demo authentication with JWT tokens</p>
21
-
22
- <div id="message-container"></div>
23
-
24
- <form id="login-form" class="login-form">
25
- <div class="form-group">
26
- <label for="email">Email:</label>
27
- <input
28
- type="email"
29
- id="email"
30
- name="email"
31
- value="john@example.com"
32
- required
33
- placeholder="Enter your email"
34
- />
35
- </div>
36
-
37
- <div class="form-group">
38
- <label for="password">Password:</label>
39
- <input
40
- type="password"
41
- id="password"
42
- name="password"
43
- value="password123"
44
- required
45
- placeholder="Enter your password"
46
- />
47
- </div>
48
-
49
- <button type="submit" class="btn btn-primary btn-full">
50
- Sign In
51
- </button>
52
- </form>
53
-
54
- <div class="demo-credentials">
55
- <h4>Demo Credentials:</h4>
56
- <p><strong>Email:</strong> john@example.com</p>
57
- <p><strong>Password:</strong> password123</p>
58
- </div>
59
- </div>
60
- </div>
61
- </div>
62
- </main>
63
-
64
- <footer class="footer">
65
- <div class="container">
66
- <p>Built with ❤️ using Baraqex Framework</p>
67
- </div>
68
- </footer>
69
- </div>
70
-
71
- <script>
72
- document.addEventListener('DOMContentLoaded', () => {
73
- const form = document.getElementById('login-form');
74
- const messageContainer = document.getElementById('message-container');
75
-
76
- form.addEventListener('submit', async (e) => {
77
- e.preventDefault();
78
-
79
- const submitBtn = form.querySelector('button[type="submit"]');
80
- const originalText = submitBtn.textContent;
81
- submitBtn.disabled = true;
82
- submitBtn.textContent = 'Signing In...';
83
-
84
- messageContainer.innerHTML = '';
85
-
86
- const formData = {
87
- email: form.email.value,
88
- password: form.password.value
89
- };
90
-
91
- try {
92
- const response = await fetch('/api/auth', {
93
- method: 'POST',
94
- headers: {
95
- 'Content-Type': 'application/json',
96
- },
97
- body: JSON.stringify(formData)
98
- });
99
-
100
- const data = await response.json();
101
-
102
- if (response.ok) {
103
- messageContainer.innerHTML = \`
104
- <div class="success-message">
105
- ✅ Login successful! Welcome \${data.data.user.name}
106
- </div>
107
- \`;
108
- // Store token (in a real app, use secure storage)
109
- localStorage.setItem('token', data.data.token);
110
-
111
- // Redirect to home after 2 seconds
112
- setTimeout(() => {
113
- window.location.href = '/';
114
- }, 2000);
115
- } else {
116
- messageContainer.innerHTML = \`
117
- <div class="error-message">
118
- ❌ \${data.message || 'Login failed'}
119
- </div>
120
- \`;
121
- }
122
- } catch (err) {
123
- messageContainer.innerHTML = \`
124
- <div class="error-message">
125
- ❌ Network error occurred
126
- </div>
127
- \`;
128
- } finally {
129
- submitBtn.disabled = false;
130
- submitBtn.textContent = originalText;
131
- }
132
- });
133
- });
134
- </script>
135
- `;
136
- }
137
-
138
- LoginPage.getTitle = () => 'Login - Baraqex Fullstack App';
139
- LoginPage.getDescription = () => 'Login to your Baraqex application';
@@ -1,150 +0,0 @@
1
- import { jsx, useState } from 'baraqex';
2
-
3
- export default function LoginPage(props) {
4
- const [formData, setFormData] = useState({
5
- email: 'john@example.com',
6
- password: 'password123'
7
- });
8
- const [loading, setLoading] = useState(false);
9
- const [message, setMessage] = useState('');
10
- const [error, setError] = useState('');
11
-
12
- const handleSubmit = async (e) => {
13
- e.preventDefault();
14
- setLoading(true);
15
- setError('');
16
- setMessage('');
17
-
18
- try {
19
- const response = await fetch('/api/auth', {
20
- method: 'POST',
21
- headers: {
22
- 'Content-Type': 'application/json',
23
- },
24
- body: JSON.stringify(formData)
25
- });
26
-
27
- const data = await response.json();
28
-
29
- if (response.ok) {
30
- setMessage(`Login successful! Welcome ${data.data.user.name}`);
31
- // Store token (in a real app, use secure storage)
32
- localStorage.setItem('token', data.data.token);
33
- } else {
34
- setError(data.message || 'Login failed');
35
- }
36
- } catch (err) {
37
- setError('Network error occurred');
38
- } finally {
39
- setLoading(false);
40
- }
41
- };
42
-
43
- const handleInputChange = (e) => {
44
- setFormData({
45
- ...formData,
46
- [e.target.name]: e.target.value
47
- });
48
- };
49
-
50
- return (
51
- <html lang="en">
52
- <head>
53
- <title>Login - Baraqex Fullstack App</title>
54
- <meta name="description" content="Login to your Baraqex application" />
55
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
56
- <link rel="stylesheet" href="/fullstack-styles.css" />
57
- </head>
58
- <body>
59
- <div className="fullstack-app">
60
- <header className="header">
61
- <div className="container">
62
- <h1>⚡ Baraqex Fullstack App</h1>
63
- <nav>
64
- <a href="/">Home</a>
65
- <a href="/api-docs">API Docs</a>
66
- <a href="/login" className="active">Login</a>
67
- </nav>
68
- </div>
69
- </header>
70
-
71
- <main className="main-content">
72
- <div className="container">
73
- <div className="login-container">
74
- <div className="login-card">
75
- <h2>🔐 Login</h2>
76
- <p>Demo authentication with JWT tokens</p>
77
-
78
- {message && (
79
- <div className="success-message">
80
- ✅ {message}
81
- </div>
82
- )}
83
-
84
- {error && (
85
- <div className="error-message">
86
- ❌ {error}
87
- </div>
88
- )}
89
-
90
- <form onSubmit={handleSubmit} className="login-form">
91
- <div className="form-group">
92
- <label htmlFor="email">Email:</label>
93
- <input
94
- type="email"
95
- id="email"
96
- name="email"
97
- value={formData.email}
98
- onChange={handleInputChange}
99
- required
100
- placeholder="Enter your email"
101
- />
102
- </div>
103
-
104
- <div className="form-group">
105
- <label htmlFor="password">Password:</label>
106
- <input
107
- type="password"
108
- id="password"
109
- name="password"
110
- value={formData.password}
111
- onChange={handleInputChange}
112
- required
113
- placeholder="Enter your password"
114
- />
115
- </div>
116
-
117
- <button
118
- type="submit"
119
- className="btn btn-primary btn-full"
120
- disabled={loading}
121
- >
122
- {loading ? 'Signing In...' : 'Sign In'}
123
- </button>
124
- </form>
125
-
126
- <div className="demo-credentials">
127
- <h4>Demo Credentials:</h4>
128
- <p><strong>Email:</strong> john@example.com</p>
129
- <p><strong>Password:</strong> password123</p>
130
- </div>
131
- </div>
132
- </div>
133
- </div>
134
- </main>
135
-
136
- <footer className="footer">
137
- <div className="container">
138
- <p>Built with ❤️ using Baraqex Framework</p>
139
- </div>
140
- </footer>
141
- </div>
142
-
143
- <script src="/client.js" type="module"></script>
144
- </body>
145
- </html>
146
- );
147
- }
148
-
149
- LoginPage.getTitle = () => 'Login - Baraqex Fullstack App';
150
- LoginPage.getDescription = () => 'Login to your Baraqex application';
@@ -1,17 +0,0 @@
1
-
2
- // Auto-generated hydration script
3
- import { hydrate } from 'frontend-hamroun';
4
-
5
- // Find SSR content and hydrate it
6
- document.addEventListener('DOMContentLoaded', () => {
7
- const ssrRoots = document.querySelectorAll('[data-ssr-root]');
8
- ssrRoots.forEach(root => {
9
- const componentPath = root.getAttribute('data-component');
10
- if (componentPath) {
11
- import(componentPath).then(module => {
12
- hydrate(module.default, root);
13
- });
14
- }
15
- });
16
- });
17
-
@@ -1,43 +0,0 @@
1
- // Example API route: /api/users
2
-
3
- // Mock user data
4
- const users = [
5
- { id: 1, name: 'John Doe', email: 'john@example.com' },
6
- { id: 2, name: 'Jane Smith', email: 'jane@example.com' },
7
- { id: 3, name: 'Bob Johnson', email: 'bob@example.com' }
8
- ];
9
-
10
- export async function get(req, res) {
11
- // GET /api/users - Get all users
12
- res.json({
13
- success: true,
14
- data: users,
15
- count: users.length
16
- });
17
- }
18
-
19
- export async function post(req, res) {
20
- // POST /api/users - Create a new user
21
- const { name, email } = req.body;
22
-
23
- if (!name || !email) {
24
- return res.status(400).json({
25
- success: false,
26
- message: 'Name and email are required'
27
- });
28
- }
29
-
30
- const newUser = {
31
- id: users.length + 1,
32
- name,
33
- email
34
- };
35
-
36
- users.push(newUser);
37
-
38
- res.status(201).json({
39
- success: true,
40
- message: 'User created successfully',
41
- data: newUser
42
- });
43
- }
@@ -1,24 +0,0 @@
1
- {
2
- "name": "baraqex-go-wasm-app",
3
- "version": "1.0.0",
4
- "type": "module",
5
- "description": "Baraqex application with Go WebAssembly integration",
6
- "main": "server.js",
7
- "scripts": {
8
- "dev": "npm run build:wasm && node server.js",
9
- "build": "npm run build:wasm && npm run build:server && npm run build:client",
10
- "build:wasm": "cd src/wasm && GOOS=js GOARCH=wasm go build -o ../../public/app.wasm main.go",
11
- "build:server": "echo 'Building server...'",
12
- "build:client": "echo 'Building client...'",
13
- "start": "NODE_ENV=production node server.js",
14
- "test": "node test.js",
15
- "test:wasm": "node test-wasm.js"
16
- },
17
- "dependencies": {
18
- "baraqex": "^1.0.0",
19
- "express": "^4.18.2"
20
- },
21
- "devDependencies": {
22
- "typescript": "^5.0.0"
23
- }
24
- }