baraqex 1.0.68 → 1.0.69

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "baraqex",
3
- "version": "1.0.68",
3
+ "version": "1.0.69",
4
4
  "description": "A powerful full-stack framework for modern web development",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -9,9 +9,9 @@
9
9
  "version": "0.1.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
- "baraqex": "^1.0.67",
12
+ "baraqex": "^1.0.68",
13
13
  "dotenv": "^16.0.0",
14
- "express": "^4.18.0"
14
+ "express": "^4.21.2"
15
15
  },
16
16
  "devDependencies": {
17
17
  "@types/express": "^4.17.0",
@@ -699,9 +699,9 @@
699
699
  }
700
700
  },
701
701
  "node_modules/baraqex": {
702
- "version": "1.0.67",
703
- "resolved": "https://registry.npmjs.org/baraqex/-/baraqex-1.0.67.tgz",
704
- "integrity": "sha512-9s6N9069xXqrUPx/9qm/IbcddnzNbU0uau1Rpawukes6vTBBEktdfPieUy+xrDJQqiDs651wnF1EAuoLuRmsdQ==",
702
+ "version": "1.0.68",
703
+ "resolved": "https://registry.npmjs.org/baraqex/-/baraqex-1.0.68.tgz",
704
+ "integrity": "sha512-S9YqZw4a/h0atirvgyZQpXr8fR+XyOje3UAOQtewl2c2G19K01BJG0kCKKshQziV0o7dw7RO1P3iHkpZ3OL1eA==",
705
705
  "license": "MIT",
706
706
  "dependencies": {
707
707
  "chokidar": "^4.0.3",
@@ -12,15 +12,15 @@
12
12
  "test": "echo \"Error: no test specified\" && exit 1"
13
13
  },
14
14
  "dependencies": {
15
- "baraqex": "^1.0.67",
16
- "express": "^4.18.0",
17
- "dotenv": "^16.0.0"
15
+ "baraqex": "^1.0.68",
16
+ "dotenv": "^16.0.0",
17
+ "express": "^4.21.2"
18
18
  },
19
19
  "devDependencies": {
20
20
  "@types/express": "^4.17.0",
21
21
  "@types/node": "^20.0.0",
22
- "typescript": "^5.0.0",
23
- "tsx": "^4.0.0"
22
+ "tsx": "^4.0.0",
23
+ "typescript": "^5.0.0"
24
24
  },
25
25
  "engines": {
26
26
  "node": ">=16.0.0"
@@ -1,7 +1,13 @@
1
1
  import { useState, useEffect } from 'baraqex';
2
2
 
3
+ interface User {
4
+ id: number;
5
+ name: string;
6
+ email: string;
7
+ }
8
+
3
9
  export default function HomePage() {
4
- const [users, setUsers] = useState([]);
10
+ const [users, setUsers] = useState<User[]>([]);
5
11
  const [newUser, setNewUser] = useState({ name: '', email: '' });
6
12
  const [loading, setLoading] = useState(false);
7
13
 
@@ -22,7 +28,7 @@ export default function HomePage() {
22
28
  }
23
29
  };
24
30
 
25
- const handleSubmit = async (e) => {
31
+ const handleSubmit = async (e: React.FormEvent) => {
26
32
  e.preventDefault();
27
33
  setLoading(true);
28
34
 
@@ -1,4 +1,3 @@
1
- import { createServer } from 'baraqex/server';
2
1
  import dotenv from 'dotenv';
3
2
 
4
3
  // Load environment variables
@@ -27,89 +26,195 @@ const config = {
27
26
  }
28
27
  };
29
28
 
30
- // Create server instance
31
- const server = createServer(config);
32
-
33
- // Health check endpoint
34
- const app = server.getExpressApp();
35
- app.get('/health', (req, res) => {
36
- res.json({
37
- status: 'ok',
38
- timestamp: new Date().toISOString(),
39
- version: process.env.npm_package_version || '1.0.0',
40
- environment: process.env.NODE_ENV || 'development'
41
- });
42
- });
43
-
44
- // API status endpoint
45
- app.get('/api/status', (req, res) => {
46
- const db = server.getDatabase();
47
- res.json({
48
- api: 'online',
49
- database: db ? 'connected' : 'not configured',
50
- authentication: server.getAuth() ? 'enabled' : 'disabled',
51
- timestamp: new Date().toISOString()
52
- });
53
- });
54
-
55
- // Database connection
56
- async function connectDatabase() {
57
- const db = server.getDatabase();
58
- if (db) {
29
+ // Wait for baraqex to be ready
30
+ async function waitForBaraqex() {
31
+ const maxWait = 10000;
32
+ const interval = 100;
33
+ let waited = 0;
34
+
35
+ while (waited < maxWait) {
59
36
  try {
60
- await db.connect();
61
- console.log('✅ Database connected successfully');
62
- } catch (error) {
63
- console.error('❌ Database connection failed:', error);
64
- if (process.env.NODE_ENV === 'production') {
65
- process.exit(1);
37
+ const baraqex = await import('baraqex');
38
+ if (baraqex.createServer && typeof baraqex.createServer === 'function') {
39
+ return baraqex;
66
40
  }
41
+ } catch (error) {
42
+ // Continue waiting
67
43
  }
68
- } else {
69
- console.log('⚠️ No database configured');
44
+
45
+ await new Promise(resolve => setTimeout(resolve, interval));
46
+ waited += interval;
70
47
  }
48
+
49
+ throw new Error('Baraqex failed to initialize within timeout period');
71
50
  }
72
51
 
73
- // Graceful shutdown
74
- process.on('SIGTERM', async () => {
75
- console.log('🔄 SIGTERM received, shutting down gracefully...');
76
-
52
+ // Async function to start server
53
+ async function startServer() {
77
54
  try {
78
- await server.stop();
79
- const db = server.getDatabase();
80
- if (db) {
81
- await db.disconnect();
55
+ console.log('🔄 Waiting for Baraqex to initialize...');
56
+
57
+ // Wait for baraqex to be ready
58
+ const baraqex = await waitForBaraqex();
59
+ const { createServer } = baraqex;
60
+
61
+ console.log('✅ Baraqex initialized successfully');
62
+
63
+ if (!createServer || typeof createServer !== 'function') {
64
+ throw new Error('createServer function not available from baraqex package');
82
65
  }
83
- console.log('✅ Server shut down complete');
84
- process.exit(0);
85
- } catch (error) {
86
- console.error('❌ Error during shutdown:', error);
87
- process.exit(1);
88
- }
89
- });
90
66
 
91
- // Start server
92
- async function startServer() {
93
- try {
94
- // Connect to database first
95
- await connectDatabase();
67
+ // Create server instance
68
+ const server = createServer(config);
96
69
 
97
- // Start the server
70
+ // Wait for server initialization
71
+ await new Promise(resolve => setTimeout(resolve, 1000));
72
+
73
+ // Start the server first
74
+ console.log('🚀 Starting server...');
98
75
  await server.start();
99
76
 
77
+ // Then try to set up additional endpoints after server is running
78
+ try {
79
+ if (typeof server.getExpressApp === 'function') {
80
+ const app = server.getExpressApp();
81
+
82
+ if (app) {
83
+ // Health check endpoint
84
+ app.get('/health', (req, res) => {
85
+ res.json({
86
+ status: 'ok',
87
+ timestamp: new Date().toISOString(),
88
+ version: process.env.npm_package_version || '1.0.0',
89
+ environment: process.env.NODE_ENV || 'development'
90
+ });
91
+ });
92
+
93
+ // API status endpoint
94
+ app.get('/api/status', (req, res) => {
95
+ let db = null;
96
+ let auth = null;
97
+
98
+ try {
99
+ if (typeof server.getDatabase === 'function') {
100
+ db = server.getDatabase();
101
+ }
102
+ } catch (e) {
103
+ // Database method not available
104
+ }
105
+
106
+ try {
107
+ if (typeof server.getAuth === 'function') {
108
+ auth = server.getAuth();
109
+ }
110
+ } catch (e) {
111
+ // Auth method not available
112
+ }
113
+
114
+ res.json({
115
+ api: 'online',
116
+ database: db ? 'connected' : 'not configured',
117
+ authentication: auth ? 'enabled' : 'disabled',
118
+ timestamp: new Date().toISOString()
119
+ });
120
+ });
121
+ }
122
+ }
123
+ } catch (setupError) {
124
+ console.warn('⚠️ Could not set up additional endpoints:', setupError.message);
125
+ }
126
+
127
+ // Database connection (if configured)
128
+ await connectDatabase(server);
129
+
100
130
  console.log(`🚀 Fullstack server running on http://localhost:${config.port}`);
101
131
  console.log(`📊 Environment: ${process.env.NODE_ENV || 'development'}`);
102
- console.log(`🔑 Auth: ${server.getAuth() ? 'enabled' : 'disabled'}`);
103
- console.log(`💾 Database: ${server.getDatabase() ? 'connected' : 'not configured'}`);
132
+
133
+ // Safely check auth status
134
+ let authStatus = 'disabled';
135
+ try {
136
+ if (typeof server.getAuth === 'function') {
137
+ authStatus = server.getAuth() ? 'enabled' : 'disabled';
138
+ }
139
+ } catch (e) {
140
+ // Auth check failed
141
+ }
142
+ console.log(`🔑 Auth: ${authStatus}`);
143
+
144
+ // Safely check database status
145
+ let dbStatus = 'not configured';
146
+ try {
147
+ if (typeof server.getDatabase === 'function') {
148
+ dbStatus = server.getDatabase() ? 'connected' : 'not configured';
149
+ }
150
+ } catch (e) {
151
+ // Database check failed
152
+ }
153
+ console.log(`💾 Database: ${dbStatus}`);
154
+
104
155
  console.log(`🌐 API docs: http://localhost:${config.port}/api-docs`);
105
156
  console.log(`❤️ Health check: http://localhost:${config.port}/health`);
106
157
 
158
+ return server;
159
+
107
160
  } catch (error) {
108
161
  console.error('❌ Failed to start server:', error);
162
+
163
+ if (error.message.includes('Express not installed')) {
164
+ console.log('\n💡 To fix this, run:');
165
+ console.log(' npm install express @types/express');
166
+ } else if (error.message.includes('createServer function not available')) {
167
+ console.log('\n💡 To fix this, make sure baraqex is properly installed:');
168
+ console.log(' npm install baraqex');
169
+ console.log(' npm install express @types/express');
170
+ } else if (error.message.includes('timeout')) {
171
+ console.log('\n💡 Baraqex is taking longer than expected to initialize.');
172
+ console.log(' This might be due to missing dependencies.');
173
+ console.log(' Try installing: npm install express @types/express');
174
+ }
175
+
109
176
  process.exit(1);
110
177
  }
111
178
  }
112
179
 
180
+ // Database connection helper
181
+ async function connectDatabase(server) {
182
+ let db = null;
183
+ try {
184
+ if (typeof server.getDatabase === 'function') {
185
+ db = server.getDatabase();
186
+ }
187
+ } catch (e) {
188
+ console.log('⚠️ Database functionality not available');
189
+ return;
190
+ }
191
+
192
+ if (db && typeof db.connect === 'function') {
193
+ try {
194
+ await db.connect();
195
+ console.log('✅ Database connected successfully');
196
+ } catch (error) {
197
+ console.error('❌ Database connection failed:', error);
198
+ if (process.env.NODE_ENV === 'production') {
199
+ process.exit(1);
200
+ }
201
+ }
202
+ } else {
203
+ console.log('⚠️ No database configured');
204
+ }
205
+ }
206
+
207
+ // Graceful shutdown
208
+ process.on('SIGTERM', async () => {
209
+ console.log('🔄 SIGTERM received, shutting down gracefully...');
210
+ process.exit(0);
211
+ });
212
+
213
+ process.on('SIGINT', async () => {
214
+ console.log('🔄 SIGINT received, shutting down gracefully...');
215
+ process.exit(0);
216
+ });
217
+
113
218
  // Handle unhandled promise rejections
114
219
  process.on('unhandledRejection', (reason, promise) => {
115
220
  console.error('Unhandled Rejection at:', promise, 'reason:', reason);
@@ -124,5 +229,3 @@ process.on('uncaughtException', (error) => {
124
229
 
125
230
  // Start the server
126
231
  startServer();
127
-
128
- export default server;