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