@fuzionx/framework 0.1.43 → 0.1.45

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 (80) hide show
  1. package/README.md +501 -501
  2. package/bin/fx.js +12 -12
  3. package/cli/db-sync.js +100 -100
  4. package/cli/index.js +494 -494
  5. package/cli/templates/make/app/controllers/HomeController.js +14 -14
  6. package/cli/templates/make/app/routes/api.js +7 -7
  7. package/cli/templates/make/app/routes/web.js +5 -5
  8. package/cli/templates/make/app/views/default/errors/404.html +11 -11
  9. package/cli/templates/make/app/views/default/errors/500.html +14 -14
  10. package/cli/templates/make/app/views/default/layouts/main.html +22 -22
  11. package/cli/templates/make/app/views/default/pages/home.html +11 -11
  12. package/cli/templates/make/controller.js.tpl +40 -40
  13. package/cli/templates/make/event.js.tpl +8 -8
  14. package/cli/templates/make/job.js.tpl +10 -10
  15. package/cli/templates/make/middleware.js.tpl +10 -10
  16. package/cli/templates/make/model.js.tpl +15 -15
  17. package/cli/templates/make/service.js.tpl +15 -15
  18. package/cli/templates/make/task.js.tpl +15 -15
  19. package/cli/templates/make/test.js.tpl +7 -7
  20. package/cli/templates/make/worker.js.tpl +14 -14
  21. package/cli/templates/make/ws.js.tpl +18 -18
  22. package/index.js +67 -67
  23. package/lib/core/AppError.js +46 -46
  24. package/lib/core/Application.js +1006 -1006
  25. package/lib/core/AutoLoader.js +227 -227
  26. package/lib/core/Base.js +64 -64
  27. package/lib/core/Config.js +331 -331
  28. package/lib/core/Context.js +484 -484
  29. package/lib/database/ConnectionManager.js +208 -208
  30. package/lib/database/MariaModel.js +29 -29
  31. package/lib/database/Model.js +247 -247
  32. package/lib/database/ModelRegistry.js +72 -72
  33. package/lib/database/MongoModel.js +232 -232
  34. package/lib/database/Pagination.js +37 -37
  35. package/lib/database/PostgreModel.js +29 -29
  36. package/lib/database/QueryBuilder.js +172 -172
  37. package/lib/database/SQLiteModel.js +27 -27
  38. package/lib/database/SqlModel.js +257 -257
  39. package/lib/database/SqlQueryBuilder.js +332 -332
  40. package/lib/helpers/CryptoHelper.js +48 -48
  41. package/lib/helpers/FileHelper.js +61 -61
  42. package/lib/helpers/HashHelper.js +39 -39
  43. package/lib/helpers/I18nHelper.js +174 -174
  44. package/lib/helpers/Logger.js +108 -108
  45. package/lib/helpers/MediaHelper.js +84 -84
  46. package/lib/http/Controller.js +34 -34
  47. package/lib/http/ErrorHandler.js +136 -136
  48. package/lib/http/Middleware.js +43 -43
  49. package/lib/http/Router.js +109 -109
  50. package/lib/http/Validation.js +125 -125
  51. package/lib/middleware/apiAuth.js +79 -79
  52. package/lib/middleware/auth.js +42 -42
  53. package/lib/middleware/bodyParser.js +19 -19
  54. package/lib/middleware/cors.js +47 -47
  55. package/lib/middleware/csrf.js +32 -32
  56. package/lib/middleware/index.js +13 -13
  57. package/lib/middleware/session.js +27 -27
  58. package/lib/middleware/theme.js +20 -20
  59. package/lib/realtime/RoomManager.js +85 -85
  60. package/lib/realtime/WsHandler.js +107 -107
  61. package/lib/schedule/Job.js +38 -38
  62. package/lib/schedule/Queue.js +103 -103
  63. package/lib/schedule/Scheduler.js +171 -171
  64. package/lib/schedule/Task.js +39 -39
  65. package/lib/schedule/WorkerPool.js +225 -225
  66. package/lib/services/EventBus.js +94 -94
  67. package/lib/services/Service.js +261 -261
  68. package/lib/services/Storage.js +112 -112
  69. package/lib/utilities/ArrUtil.js +112 -112
  70. package/lib/utilities/DateUtil.js +98 -98
  71. package/lib/utilities/FunctionUtil.js +119 -119
  72. package/lib/utilities/NumUtil.js +75 -75
  73. package/lib/utilities/ObjectUtil.js +170 -170
  74. package/lib/utilities/PaginationUtil.js +81 -81
  75. package/lib/utilities/StrUtil.js +105 -105
  76. package/lib/utilities/index.js +18 -18
  77. package/lib/view/OpenAPI.js +231 -231
  78. package/lib/view/View.js +83 -83
  79. package/package.json +2 -2
  80. package/testing/index.js +232 -232
package/bin/fx.js CHANGED
@@ -1,12 +1,12 @@
1
- #!/usr/bin/env node
2
- /**
3
- * fx CLI — @fuzionx/framework 내장 명령줄 도구.
4
- *
5
- * @see docs/framework/16-cli.md
6
- */
7
- import { run } from '../cli/index.js';
8
-
9
- run(process.argv.slice(2)).catch((err) => {
10
- console.error(err.message || err);
11
- process.exit(1);
12
- });
1
+ #!/usr/bin/env node
2
+ /**
3
+ * fx CLI — @fuzionx/framework 내장 명령줄 도구.
4
+ *
5
+ * @see docs/framework/16-cli.md
6
+ */
7
+ import { run } from '../cli/index.js';
8
+
9
+ run(process.argv.slice(2)).catch((err) => {
10
+ console.error(err.message || err);
11
+ process.exit(1);
12
+ });
package/cli/db-sync.js CHANGED
@@ -1,100 +1,100 @@
1
- /**
2
- * db:sync — 모델 기반 스키마 SQL 생성
3
- *
4
- * 사용: fx db:sync [--dry-run]
5
- *
6
- * 모델의 static 멤버(table, primaryKey, timestamps, softDelete)에서
7
- * CREATE TABLE SQL을 생성합니다. 실제 마이그레이션 시스템이 아닌
8
- * 빠른 프로토타이핑용 도구입니다.
9
- *
10
- * @see docs/framework/02-database-orm.md
11
- */
12
- import { promises as fs } from 'node:fs';
13
- import path from 'node:path';
14
- import { pathToFileURL } from 'node:url';
15
-
16
- /**
17
- * 모델 클래스에서 CREATE TABLE SQL 생성
18
- * @param {typeof import('../lib/Model.js').default} ModelClass
19
- * @returns {string}
20
- */
21
- export function generateCreateTable(ModelClass) {
22
- const table = ModelClass.table;
23
- const pk = ModelClass.primaryKey || 'id';
24
- const timestamps = ModelClass.timestamps !== false;
25
- const softDelete = ModelClass.softDelete || false;
26
-
27
- if (!table) return '';
28
-
29
- const columns = [];
30
-
31
- // 기본키
32
- columns.push(` \`${pk}\` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY`);
33
-
34
- // timestamps
35
- if (timestamps) {
36
- columns.push(` \`created_at\` DATETIME DEFAULT CURRENT_TIMESTAMP`);
37
- columns.push(` \`updated_at\` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP`);
38
- }
39
-
40
- // softDelete
41
- if (softDelete) {
42
- columns.push(` \`deleted_at\` DATETIME DEFAULT NULL`);
43
- }
44
-
45
- return `CREATE TABLE IF NOT EXISTS \`${table}\` (\n${columns.join(',\n')}\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;\n`;
46
- }
47
-
48
- /**
49
- * 디렉토리의 모든 모델에서 SQL 생성
50
- * @param {string} modelsDir
51
- * @returns {Promise<string>}
52
- */
53
- export async function generateSchema(modelsDir) {
54
- const sqls = [];
55
-
56
- try {
57
- const entries = await fs.readdir(modelsDir, { withFileTypes: true });
58
- const files = entries
59
- .filter(e => e.isFile() && e.name.endsWith('.js') && !e.name.startsWith('.'))
60
- .map(e => path.join(modelsDir, e.name));
61
-
62
- for (const file of files) {
63
- const mod = await import(pathToFileURL(file).href);
64
- const ModelClass = mod.default;
65
- if (ModelClass?.table) {
66
- sqls.push(generateCreateTable(ModelClass));
67
- }
68
- }
69
- } catch {
70
- // 디렉토리 없음
71
- }
72
-
73
- return sqls.join('\n');
74
- }
75
-
76
- /**
77
- * CLI 엔트리
78
- */
79
- export async function run(args) {
80
- const dryRun = args.includes('--dry-run');
81
- const modelsDir = path.resolve('app/models');
82
-
83
- console.log(`[db:sync] Scanning ${modelsDir}...`);
84
-
85
- const sql = await generateSchema(modelsDir);
86
-
87
- if (!sql) {
88
- console.log('[db:sync] No models found.');
89
- return;
90
- }
91
-
92
- if (dryRun) {
93
- console.log('\n-- DRY RUN (preview only) --\n');
94
- console.log(sql);
95
- } else {
96
- console.log('\n-- Generated SQL --\n');
97
- console.log(sql);
98
- console.log('-- Execute this SQL against your database to sync schema --');
99
- }
100
- }
1
+ /**
2
+ * db:sync — 모델 기반 스키마 SQL 생성
3
+ *
4
+ * 사용: fx db:sync [--dry-run]
5
+ *
6
+ * 모델의 static 멤버(table, primaryKey, timestamps, softDelete)에서
7
+ * CREATE TABLE SQL을 생성합니다. 실제 마이그레이션 시스템이 아닌
8
+ * 빠른 프로토타이핑용 도구입니다.
9
+ *
10
+ * @see docs/framework/02-database-orm.md
11
+ */
12
+ import { promises as fs } from 'node:fs';
13
+ import path from 'node:path';
14
+ import { pathToFileURL } from 'node:url';
15
+
16
+ /**
17
+ * 모델 클래스에서 CREATE TABLE SQL 생성
18
+ * @param {typeof import('../lib/Model.js').default} ModelClass
19
+ * @returns {string}
20
+ */
21
+ export function generateCreateTable(ModelClass) {
22
+ const table = ModelClass.table;
23
+ const pk = ModelClass.primaryKey || 'id';
24
+ const timestamps = ModelClass.timestamps !== false;
25
+ const softDelete = ModelClass.softDelete || false;
26
+
27
+ if (!table) return '';
28
+
29
+ const columns = [];
30
+
31
+ // 기본키
32
+ columns.push(` \`${pk}\` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY`);
33
+
34
+ // timestamps
35
+ if (timestamps) {
36
+ columns.push(` \`created_at\` DATETIME DEFAULT CURRENT_TIMESTAMP`);
37
+ columns.push(` \`updated_at\` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP`);
38
+ }
39
+
40
+ // softDelete
41
+ if (softDelete) {
42
+ columns.push(` \`deleted_at\` DATETIME DEFAULT NULL`);
43
+ }
44
+
45
+ return `CREATE TABLE IF NOT EXISTS \`${table}\` (\n${columns.join(',\n')}\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;\n`;
46
+ }
47
+
48
+ /**
49
+ * 디렉토리의 모든 모델에서 SQL 생성
50
+ * @param {string} modelsDir
51
+ * @returns {Promise<string>}
52
+ */
53
+ export async function generateSchema(modelsDir) {
54
+ const sqls = [];
55
+
56
+ try {
57
+ const entries = await fs.readdir(modelsDir, { withFileTypes: true });
58
+ const files = entries
59
+ .filter(e => e.isFile() && e.name.endsWith('.js') && !e.name.startsWith('.'))
60
+ .map(e => path.join(modelsDir, e.name));
61
+
62
+ for (const file of files) {
63
+ const mod = await import(pathToFileURL(file).href);
64
+ const ModelClass = mod.default;
65
+ if (ModelClass?.table) {
66
+ sqls.push(generateCreateTable(ModelClass));
67
+ }
68
+ }
69
+ } catch {
70
+ // 디렉토리 없음
71
+ }
72
+
73
+ return sqls.join('\n');
74
+ }
75
+
76
+ /**
77
+ * CLI 엔트리
78
+ */
79
+ export async function run(args) {
80
+ const dryRun = args.includes('--dry-run');
81
+ const modelsDir = path.resolve('app/models');
82
+
83
+ console.log(`[db:sync] Scanning ${modelsDir}...`);
84
+
85
+ const sql = await generateSchema(modelsDir);
86
+
87
+ if (!sql) {
88
+ console.log('[db:sync] No models found.');
89
+ return;
90
+ }
91
+
92
+ if (dryRun) {
93
+ console.log('\n-- DRY RUN (preview only) --\n');
94
+ console.log(sql);
95
+ } else {
96
+ console.log('\n-- Generated SQL --\n');
97
+ console.log(sql);
98
+ console.log('-- Execute this SQL against your database to sync schema --');
99
+ }
100
+ }