fullstx 1.0.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 (83) hide show
  1. package/README.md +86 -0
  2. package/bin/create.js +68 -0
  3. package/bin/generate.js +78 -0
  4. package/coverage/clover.xml +1356 -0
  5. package/coverage/coverage-final.json +30 -0
  6. package/coverage/lcov-report/base.css +224 -0
  7. package/coverage/lcov-report/block-navigation.js +87 -0
  8. package/coverage/lcov-report/favicon.png +0 -0
  9. package/coverage/lcov-report/fullstx/index.html +146 -0
  10. package/coverage/lcov-report/fullstx/index.js.html +379 -0
  11. package/coverage/lcov-report/fullstx/lib/application.js.html +1840 -0
  12. package/coverage/lcov-report/fullstx/lib/browser-sync.js.html +199 -0
  13. package/coverage/lcov-report/fullstx/lib/database.js.html +535 -0
  14. package/coverage/lcov-report/fullstx/lib/errors.js.html +154 -0
  15. package/coverage/lcov-report/fullstx/lib/features/hooks.js.html +151 -0
  16. package/coverage/lcov-report/fullstx/lib/features/index.html +176 -0
  17. package/coverage/lcov-report/fullstx/lib/features/jwt.js.html +214 -0
  18. package/coverage/lcov-report/fullstx/lib/features/plugins.js.html +172 -0
  19. package/coverage/lcov-report/fullstx/lib/features/routing.js.html +211 -0
  20. package/coverage/lcov-report/fullstx/lib/features/utils.js.html +1216 -0
  21. package/coverage/lcov-report/fullstx/lib/index.html +236 -0
  22. package/coverage/lcov-report/fullstx/lib/middlewares/apiKey.js.html +127 -0
  23. package/coverage/lcov-report/fullstx/lib/middlewares/authorize.js.html +115 -0
  24. package/coverage/lcov-report/fullstx/lib/middlewares/basicAuth.js.html +148 -0
  25. package/coverage/lcov-report/fullstx/lib/middlewares/csp.js.html +124 -0
  26. package/coverage/lcov-report/fullstx/lib/middlewares/csrf.js.html +178 -0
  27. package/coverage/lcov-report/fullstx/lib/middlewares/htmx.js.html +157 -0
  28. package/coverage/lcov-report/fullstx/lib/middlewares/i18n.js.html +175 -0
  29. package/coverage/lcov-report/fullstx/lib/middlewares/index.html +281 -0
  30. package/coverage/lcov-report/fullstx/lib/middlewares/rateLimit.js.html +169 -0
  31. package/coverage/lcov-report/fullstx/lib/middlewares/redisCache.js.html +154 -0
  32. package/coverage/lcov-report/fullstx/lib/middlewares/requirePermission.js.html +118 -0
  33. package/coverage/lcov-report/fullstx/lib/middlewares/routeLocalization.js.html +118 -0
  34. package/coverage/lcov-report/fullstx/lib/middlewares/session.js.html +133 -0
  35. package/coverage/lcov-report/fullstx/lib/middlewares.js.html +340 -0
  36. package/coverage/lcov-report/fullstx/lib/radix-router.js.html +418 -0
  37. package/coverage/lcov-report/fullstx/lib/request.js.html +328 -0
  38. package/coverage/lcov-report/fullstx/lib/response.js.html +610 -0
  39. package/coverage/lcov-report/fullstx/lib/websocket.js.html +166 -0
  40. package/coverage/lcov-report/fullstx/router.js.html +226 -0
  41. package/coverage/lcov-report/fullstx/server.js.html +664 -0
  42. package/coverage/lcov-report/index.html +161 -0
  43. package/coverage/lcov-report/prettify.css +1 -0
  44. package/coverage/lcov-report/prettify.js +2 -0
  45. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  46. package/coverage/lcov-report/sorter.js +210 -0
  47. package/coverage/lcov.info +2753 -0
  48. package/dist/index.js +238 -0
  49. package/dist/index.js.map +1 -0
  50. package/dist/index.mjs +238 -0
  51. package/dist/index.mjs.map +1 -0
  52. package/index.d.ts +115 -0
  53. package/index.js +98 -0
  54. package/lib/application.js +585 -0
  55. package/lib/browser-sync.js +38 -0
  56. package/lib/database.js +150 -0
  57. package/lib/errors.js +23 -0
  58. package/lib/features/hooks.js +22 -0
  59. package/lib/features/jwt.js +43 -0
  60. package/lib/features/plugins.js +29 -0
  61. package/lib/features/routing.js +42 -0
  62. package/lib/features/utils.js +377 -0
  63. package/lib/middlewares/apiKey.js +14 -0
  64. package/lib/middlewares/authorize.js +10 -0
  65. package/lib/middlewares/basicAuth.js +21 -0
  66. package/lib/middlewares/csp.js +13 -0
  67. package/lib/middlewares/csrf.js +31 -0
  68. package/lib/middlewares/htmx.js +24 -0
  69. package/lib/middlewares/i18n.js +30 -0
  70. package/lib/middlewares/rateLimit.js +28 -0
  71. package/lib/middlewares/redisCache.js +23 -0
  72. package/lib/middlewares/requirePermission.js +11 -0
  73. package/lib/middlewares/routeLocalization.js +11 -0
  74. package/lib/middlewares/session.js +16 -0
  75. package/lib/middlewares.js +85 -0
  76. package/lib/radix-router.js +111 -0
  77. package/lib/request.js +81 -0
  78. package/lib/response.js +175 -0
  79. package/lib/websocket.js +27 -0
  80. package/package.json +61 -0
  81. package/router.js +47 -0
  82. package/server.js +193 -0
  83. package/session.js +109 -0
package/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # fullstx
2
+
3
+ A high-performance, custom backend framework with a static file frontend. Equipped with built-in **browser-sync** for automatic hot-reload during development.
4
+
5
+ ## Features
6
+
7
+ - **🚀 Radix Trie Router**: O(1) routing performance for maximum speed.
8
+ - **🔄 Built-in Hot-Reloading**: Seamless development with integrated `browser-sync`. Proxies your app and reloads the browser when static files or server code changes.
9
+ - **🛡️ Secure by Default**: Helmet (security headers), CORS, XSS protection, and rate-limiting built-in.
10
+ - **🗜️ Auto-Compression**: Gzip and Brotli compression out of the box.
11
+ - **🧩 Extensible**: Built-in support for Sessions, SQLite, Knex, WebSockets, HTMX, and Sentry.
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install fullstx
17
+ ```
18
+
19
+ ## Configuration
20
+
21
+ Pass options when creating the Framework instance:
22
+
23
+ ```js
24
+ const Framework = require('fullstx');
25
+
26
+ const app = Framework({
27
+ // --- Development & Server ---
28
+ port: 3000, // Public port (default: 3000)
29
+ internalPort: undefined, // Override internal port manually
30
+ internalPortOffset: 1000, // Offset for internal server when liveReload is true
31
+ liveReload: true, // Enable/disable browser-sync hot-reload
32
+ staticDir: "public", // Directory for static files (default: "public")
33
+
34
+ // --- Core Middlewares ---
35
+ logger: true, // Enable HTTP request logging
36
+ cors: true, // Enable Cross-Origin Resource Sharing
37
+ helmet: true, // Enable Security Headers (Helmet)
38
+ xss: true, // Enable XSS Protection / Sanitization
39
+ compression: true, // Enable Gzip/Brotli Compression
40
+ healthCheck: true, // Enable /api/health endpoint
41
+
42
+ // --- Features ---
43
+ session: false, // Enable Sessions (requires Redis/Memory config)
44
+ htmx: true, // Enable HTMX helpers (req.htmx, res.hxRedirect, etc)
45
+ jwtSecret: process.env.JWT_SECRET || "supersecret", // Secret for JWT signing
46
+
47
+ // --- Integrations ---
48
+ db: null, // Database configuration (Knex)
49
+ ws: null, // WebSocket / Redis PubSub config
50
+ sqlite: null, // SQLite specific config
51
+ sentry: null // Sentry error tracking config
52
+ });
53
+
54
+ app.listen(3000);
55
+ ```
56
+
57
+ Example: server directly on port 3000 (without browser-sync proxy):
58
+ ```js
59
+ const app = Framework({ liveReload: false });
60
+ app.listen(3000);
61
+ ```
62
+
63
+ ## Troubleshooting
64
+
65
+ - **Port already in use** — another process is using port 3000 or 4000. Stop that process, or reset the port:
66
+ ```js
67
+ const app = Framework({ internalPort: 4100 }); // force internal port
68
+ app.listen(3000);
69
+ ```
70
+
71
+ - **File changes but browser doesn't reload** — ensure the file is in the `watch` list in the Framework options.
72
+
73
+ ## Notes
74
+
75
+ - The framework automatically handles browser-sync internally — no need to install/configure browser-sync separately.
76
+ - Production mode: set `liveReload: false` so there is no browser-sync overhead.
77
+ - Static files are served by the `serveStaticFile` middleware in `app.js`.
78
+
79
+ ## Testing
80
+
81
+ ### Internal Framework Testing
82
+ The framework's internal engine is tested using Jest to maintain stability and performance.
83
+
84
+ ```bash
85
+ npm run test
86
+ ```
package/bin/create.js ADDED
@@ -0,0 +1,68 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ const projectName = process.argv[2];
5
+
6
+ if (!projectName) {
7
+ console.log('Usage: create-fullstx <project-name>');
8
+ process.exit(1);
9
+ }
10
+
11
+ const projectPath = path.join(process.cwd(), projectName);
12
+
13
+ if (fs.existsSync(projectPath)) {
14
+ console.log(`Folder ${projectName} already exists.`);
15
+ process.exit(1);
16
+ }
17
+
18
+ console.log('Creating Project...');
19
+
20
+ fs.mkdirSync(projectPath);
21
+ fs.mkdirSync(path.join(projectPath, 'pages'));
22
+ fs.mkdirSync(path.join(projectPath, 'public'));
23
+
24
+ const packageJson = {
25
+ name: projectName,
26
+ version: '1.0.0',
27
+ main: 'app.js',
28
+ scripts: {
29
+ start: 'node app.js'
30
+ },
31
+ dependencies: {
32
+ fullstx: '*'
33
+ }
34
+ };
35
+
36
+ fs.writeFileSync(path.join(projectPath, 'package.json'), JSON.stringify(packageJson, null, 4));
37
+
38
+ const appJs = `const Framework = require("fullstx");
39
+
40
+ const app = Framework();
41
+
42
+ app.get("/", (req, res) => {
43
+ res.end("Hello World");
44
+ });
45
+
46
+ app.listen(3000);
47
+ `;
48
+
49
+ fs.writeFileSync(path.join(projectPath, 'app.js'), appJs);
50
+
51
+ const indexPage = `module.exports = () => \`
52
+ <html>
53
+ <body>
54
+ <h1>Hello from fullstx</h1>
55
+ </body>
56
+ </html>
57
+ \`;
58
+ `;
59
+
60
+ fs.writeFileSync(path.join(projectPath, 'pages', 'index.js'), indexPage);
61
+
62
+ console.log(`Project ${projectName} created successfully.`);
63
+ console.log('Run:');
64
+ console.log(` cd ${projectName}`);
65
+ console.log(' npm install');
66
+ console.log(' npm start');
67
+ console.log('');
68
+ console.log('Hot-reload (browser-sync) otomatis aktif via framework fullstx.');
@@ -0,0 +1,78 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ const type = process.argv[2];
5
+ const name = process.argv[3];
6
+
7
+ if (!type || !name) {
8
+ console.error('Usage: fullstx-generate <type> <name>');
9
+ console.error('Types: controller, service, module');
10
+ process.exit(1);
11
+ }
12
+
13
+ const targetDir = path.join(process.cwd(), 'src', type + 's');
14
+ if (!fs.existsSync(targetDir)) {
15
+ fs.mkdirSync(targetDir, { recursive: true });
16
+ }
17
+
18
+ const upperName = name.charAt(0).toUpperCase() + name.slice(1);
19
+ const fileName = `${upperName}${type.charAt(0).toUpperCase() + type.slice(1)}.js`;
20
+ const targetPath = path.join(targetDir, fileName);
21
+
22
+ if (fs.existsSync(targetPath)) {
23
+ console.error(`[!] File already exists: ${targetPath}`);
24
+ process.exit(1);
25
+ }
26
+
27
+ let content = '';
28
+
29
+ if (type === 'controller') {
30
+ content = `module.exports = {
31
+ index(req, res) {
32
+ if (res.json) return res.json({ message: "List ${name}s" });
33
+ res.end("List ${name}s");
34
+ },
35
+ show(req, res) {
36
+ if (res.json) return res.json({ message: "Show ${name}" });
37
+ res.end("Show ${name}");
38
+ },
39
+ create(req, res) {
40
+ if (res.json) return res.json({ message: "Create ${name}" });
41
+ res.end("Create ${name}");
42
+ },
43
+ update(req, res) {
44
+ if (res.json) return res.json({ message: "Update ${name}" });
45
+ res.end("Update ${name}");
46
+ },
47
+ destroy(req, res) {
48
+ if (res.json) return res.json({ message: "Delete ${name}" });
49
+ res.end("Delete ${name}");
50
+ }
51
+ };
52
+ `;
53
+ } else if (type === 'service') {
54
+ content = `class ${upperName}Service {
55
+ constructor() {}
56
+
57
+ async findAll() {
58
+ return [];
59
+ }
60
+ }
61
+
62
+ module.exports = ${upperName}Service;
63
+ `;
64
+ } else if (type === 'module') {
65
+ content = `module.exports = function(app) {
66
+ app.get('/${name.toLowerCase()}s', (req, res) => {
67
+ if (res.json) return res.json({ message: "${upperName} module works!" });
68
+ res.end("${upperName} module works!");
69
+ });
70
+ };
71
+ `;
72
+ } else {
73
+ console.error('Unknown type: ' + type);
74
+ process.exit(1);
75
+ }
76
+
77
+ fs.writeFileSync(targetPath, content);
78
+ console.log(`[fullstx] Successfully created ${type} at src/${type}s/${fileName}`);