mega-framework 0.1.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.
- package/.env +127 -0
- package/.env.example +186 -0
- package/.prettierrc.json +8 -0
- package/CHANGELOG.md +259 -0
- package/LICENSE +21 -0
- package/README.md +153 -0
- package/bin/mega-ws-hub.js +15 -0
- package/bin/mega.js +38 -0
- package/docker-compose.yml +201 -0
- package/eslint.config.js +57 -0
- package/infra/otel-collector-config.yaml +43 -0
- package/jsconfig.json +18 -0
- package/package.json +121 -0
- package/sample/crud/.env +18 -0
- package/sample/crud/.env.example +50 -0
- package/sample/crud/README.md +85 -0
- package/sample/crud/apps/main/app.config.js +114 -0
- package/sample/crud/apps/main/channels/chat-bus.js +115 -0
- package/sample/crud/apps/main/channels/chat-channel.js +145 -0
- package/sample/crud/apps/main/controllers/auth-controller.js +144 -0
- package/sample/crud/apps/main/controllers/cron-controller.js +34 -0
- package/sample/crud/apps/main/controllers/guide-controller.js +37 -0
- package/sample/crud/apps/main/controllers/jobs-controller.js +43 -0
- package/sample/crud/apps/main/controllers/logs-controller.js +35 -0
- package/sample/crud/apps/main/controllers/metrics-controller.js +22 -0
- package/sample/crud/apps/main/controllers/note-controller.js +116 -0
- package/sample/crud/apps/main/controllers/perf-controller.js +38 -0
- package/sample/crud/apps/main/controllers/redis-controller.js +36 -0
- package/sample/crud/apps/main/controllers/tracing-controller.js +43 -0
- package/sample/crud/apps/main/controllers/upload-controller.js +98 -0
- package/sample/crud/apps/main/controllers/user-controller.js +34 -0
- package/sample/crud/apps/main/controllers/web-controller.js +137 -0
- package/sample/crud/apps/main/controllers/worker-controller.js +57 -0
- package/sample/crud/apps/main/controllers/ws-controller.js +29 -0
- package/sample/crud/apps/main/jobs/email-job.js +72 -0
- package/sample/crud/apps/main/locales/client/en.json +3 -0
- package/sample/crud/apps/main/locales/client/ko.json +3 -0
- package/sample/crud/apps/main/locales/server/en.json +316 -0
- package/sample/crud/apps/main/locales/server/ko.json +316 -0
- package/sample/crud/apps/main/middleware/web-auth.js +40 -0
- package/sample/crud/apps/main/middleware/ws-auth.js +48 -0
- package/sample/crud/apps/main/migrations/20260606000001-create-users.js +27 -0
- package/sample/crud/apps/main/migrations/20260606000002-add-auth-to-users.js +30 -0
- package/sample/crud/apps/main/models/note.js +71 -0
- package/sample/crud/apps/main/models/user.js +86 -0
- package/sample/crud/apps/main/public/css/app.css +101 -0
- package/sample/crud/apps/main/public/css/guide.css +137 -0
- package/sample/crud/apps/main/public/js/app.js +54 -0
- package/sample/crud/apps/main/public/js/perf.js +129 -0
- package/sample/crud/apps/main/public/js/theme-init.js +12 -0
- package/sample/crud/apps/main/public/js/upload-demo.js +63 -0
- package/sample/crud/apps/main/public/js/worker-demo.js +92 -0
- package/sample/crud/apps/main/public/js/ws-chat.js +161 -0
- package/sample/crud/apps/main/public/vendor/bootstrap/bootstrap.bundle.min.js +7 -0
- package/sample/crud/apps/main/public/vendor/bootstrap/bootstrap.min.css +6 -0
- package/sample/crud/apps/main/public/vendor/highlight/github-dark.css +109 -0
- package/sample/crud/apps/main/public/vendor/highlight/github.css +118 -0
- package/sample/crud/apps/main/public/vendor/mega-client-wasm/README.md +19 -0
- package/sample/crud/apps/main/public/vendor/mega-client-wasm/mega_client_wasm.d.ts +196 -0
- package/sample/crud/apps/main/public/vendor/mega-client-wasm/mega_client_wasm.js +1187 -0
- package/sample/crud/apps/main/public/vendor/mega-client-wasm/mega_client_wasm_bg.wasm +0 -0
- package/sample/crud/apps/main/routes/auth.js +15 -0
- package/sample/crud/apps/main/routes/cron.js +14 -0
- package/sample/crud/apps/main/routes/guide.js +25 -0
- package/sample/crud/apps/main/routes/jobs.js +14 -0
- package/sample/crud/apps/main/routes/logs.js +28 -0
- package/sample/crud/apps/main/routes/metrics.js +13 -0
- package/sample/crud/apps/main/routes/notes.js +19 -0
- package/sample/crud/apps/main/routes/perf.js +47 -0
- package/sample/crud/apps/main/routes/redis.js +14 -0
- package/sample/crud/apps/main/routes/tracing.js +14 -0
- package/sample/crud/apps/main/routes/upload.js +16 -0
- package/sample/crud/apps/main/routes/users.js +54 -0
- package/sample/crud/apps/main/routes/web.js +23 -0
- package/sample/crud/apps/main/routes/worker.js +15 -0
- package/sample/crud/apps/main/routes/ws.js +30 -0
- package/sample/crud/apps/main/schedules/cron-counter-schedule.js +30 -0
- package/sample/crud/apps/main/services/auth-service.js +74 -0
- package/sample/crud/apps/main/services/cron-demo-service.js +66 -0
- package/sample/crud/apps/main/services/guide-service.js +145 -0
- package/sample/crud/apps/main/services/jobs-demo-service.js +83 -0
- package/sample/crud/apps/main/services/logs-demo-service.js +59 -0
- package/sample/crud/apps/main/services/metrics-demo-service.js +144 -0
- package/sample/crud/apps/main/services/note-service.js +75 -0
- package/sample/crud/apps/main/services/perf-service.js +302 -0
- package/sample/crud/apps/main/services/redis-demo-service.js +75 -0
- package/sample/crud/apps/main/services/tracing-demo-service.js +69 -0
- package/sample/crud/apps/main/services/upload-demo-service.js +48 -0
- package/sample/crud/apps/main/services/user-service.js +65 -0
- package/sample/crud/apps/main/views/auth/login.ejs +57 -0
- package/sample/crud/apps/main/views/auth/register.ejs +71 -0
- package/sample/crud/apps/main/views/cron/index.ejs +92 -0
- package/sample/crud/apps/main/views/guide/index.ejs +24 -0
- package/sample/crud/apps/main/views/guide/page.ejs +64 -0
- package/sample/crud/apps/main/views/home.ejs +82 -0
- package/sample/crud/apps/main/views/jobs/index.ejs +113 -0
- package/sample/crud/apps/main/views/layouts/main.ejs +112 -0
- package/sample/crud/apps/main/views/logs/index.ejs +80 -0
- package/sample/crud/apps/main/views/metrics/index.ejs +123 -0
- package/sample/crud/apps/main/views/notes/edit.ejs +45 -0
- package/sample/crud/apps/main/views/notes/list.ejs +74 -0
- package/sample/crud/apps/main/views/notes/new.ejs +45 -0
- package/sample/crud/apps/main/views/perf/index.ejs +90 -0
- package/sample/crud/apps/main/views/redis/index.ejs +65 -0
- package/sample/crud/apps/main/views/tracing/index.ejs +106 -0
- package/sample/crud/apps/main/views/upload/index.ejs +79 -0
- package/sample/crud/apps/main/views/users/edit.ejs +48 -0
- package/sample/crud/apps/main/views/users/list.ejs +81 -0
- package/sample/crud/apps/main/views/users/new.ejs +48 -0
- package/sample/crud/apps/main/views/worker/index.ejs +70 -0
- package/sample/crud/apps/main/views/ws/index.ejs +62 -0
- package/sample/crud/apps/main/workers/hash-worker.js +17 -0
- package/sample/crud/apps/main/workers/hash.task.js +22 -0
- package/sample/crud/ecosystem.config.cjs +9 -0
- package/sample/crud/mega.config.js +105 -0
- package/sample/crud/package-lock.json +5665 -0
- package/sample/crud/package.json +28 -0
- package/sample/crud/test/apps/main/auth-flow.integration.test.js +177 -0
- package/sample/crud/test/apps/main/auth-service.test.js +93 -0
- package/sample/crud/test/apps/main/chat-bus.test.js +101 -0
- package/sample/crud/test/apps/main/chat-channel.test.js +144 -0
- package/sample/crud/test/apps/main/cron-demo-service.test.js +93 -0
- package/sample/crud/test/apps/main/demo-flow.integration.test.js +386 -0
- package/sample/crud/test/apps/main/email-job.test.js +76 -0
- package/sample/crud/test/apps/main/guide-service.test.js +68 -0
- package/sample/crud/test/apps/main/hash-task.test.js +30 -0
- package/sample/crud/test/apps/main/jobs-demo-service.test.js +88 -0
- package/sample/crud/test/apps/main/logs-demo-service.test.js +85 -0
- package/sample/crud/test/apps/main/metrics-demo-service.test.js +90 -0
- package/sample/crud/test/apps/main/note-service.test.js +68 -0
- package/sample/crud/test/apps/main/perf-service.test.js +121 -0
- package/sample/crud/test/apps/main/perf.integration.test.js +202 -0
- package/sample/crud/test/apps/main/redis-demo-service.test.js +98 -0
- package/sample/crud/test/apps/main/tracing-demo-service.test.js +90 -0
- package/sample/crud/test/apps/main/upload-demo-service.test.js +61 -0
- package/sample/crud/test/apps/main/user-service.test.js +65 -0
- package/sample/crud/test/apps/main/ws-chat.integration.test.js +232 -0
- package/sample/crud/vitest.config.js +8 -0
- package/sample/crud/yarn.lock +2142 -0
- package/sample/simple/.env.example +15 -0
- package/sample/simple/README.md +52 -0
- package/sample/simple/apps/main/app.config.js +35 -0
- package/sample/simple/apps/main/controllers/pages-controller.js +22 -0
- package/sample/simple/apps/main/locales/client/en.json +3 -0
- package/sample/simple/apps/main/locales/client/ko.json +3 -0
- package/sample/simple/apps/main/locales/server/en.json +23 -0
- package/sample/simple/apps/main/locales/server/ko.json +23 -0
- package/sample/simple/apps/main/public/css/app.css +101 -0
- package/sample/simple/apps/main/public/hello.txt +1 -0
- package/sample/simple/apps/main/public/js/app.js +54 -0
- package/sample/simple/apps/main/public/js/theme-init.js +12 -0
- package/sample/simple/apps/main/public/vendor/bootstrap/bootstrap.bundle.min.js +7 -0
- package/sample/simple/apps/main/public/vendor/bootstrap/bootstrap.min.css +6 -0
- package/sample/simple/apps/main/routes/index.js +9 -0
- package/sample/simple/apps/main/routes/pages.js +12 -0
- package/sample/simple/apps/main/views/index.ejs +56 -0
- package/sample/simple/apps/main/views/layouts/main.ejs +74 -0
- package/sample/simple/ecosystem.config.cjs +10 -0
- package/sample/simple/mega.config.js +27 -0
- package/sample/simple/package-lock.json +1851 -0
- package/sample/simple/package.json +25 -0
- package/sample/simple/test/apps/main/index.test.js +13 -0
- package/sample/simple/vitest.config.js +8 -0
- package/src/adapters/adapter-manager.js +305 -0
- package/src/adapters/adapter-options.js +208 -0
- package/src/adapters/file-adapter.js +350 -0
- package/src/adapters/file-session-adapter.js +363 -0
- package/src/adapters/index.js +38 -0
- package/src/adapters/maria-adapter.js +425 -0
- package/src/adapters/mega-adapter.js +511 -0
- package/src/adapters/mega-bus-adapter.js +81 -0
- package/src/adapters/mega-cache-adapter.js +94 -0
- package/src/adapters/mega-db-adapter.js +72 -0
- package/src/adapters/mega-lock-adapter.js +118 -0
- package/src/adapters/mega-log-sink-adapter.js +46 -0
- package/src/adapters/mega-session-adapter.js +72 -0
- package/src/adapters/mongo-adapter.js +396 -0
- package/src/adapters/nats-adapter.js +370 -0
- package/src/adapters/postgres-adapter.js +341 -0
- package/src/adapters/redis-adapter.js +331 -0
- package/src/adapters/redis-session-adapter.js +261 -0
- package/src/adapters/redlock-adapter.js +385 -0
- package/src/adapters/registry.js +157 -0
- package/src/adapters/sqlite-adapter.js +309 -0
- package/src/auth/index.js +103 -0
- package/src/cli/commands/console-cmd.js +56 -0
- package/src/cli/commands/new.js +101 -0
- package/src/cli/commands/routes.js +107 -0
- package/src/cli/commands/scaffold.js +120 -0
- package/src/cli/commands/test-cmd.js +45 -0
- package/src/cli/generators/index.js +368 -0
- package/src/cli/index.js +472 -0
- package/src/cli/template-engine.js +72 -0
- package/src/cli/ws-hub.js +582 -0
- package/src/core/ajv-mapper.js +80 -0
- package/src/core/boot.js +323 -0
- package/src/core/cluster-metrics.js +278 -0
- package/src/core/config-loader.js +115 -0
- package/src/core/config-validator.js +322 -0
- package/src/core/ctx-builder.js +253 -0
- package/src/core/envelope.js +88 -0
- package/src/core/error-mapper.js +116 -0
- package/src/core/formbody.js +69 -0
- package/src/core/hub-link.js +552 -0
- package/src/core/i18n.js +525 -0
- package/src/core/index.js +63 -0
- package/src/core/mega-app.js +1138 -0
- package/src/core/mega-cluster.js +232 -0
- package/src/core/mega-server.js +176 -0
- package/src/core/mega-service.js +41 -0
- package/src/core/migration-runner.js +196 -0
- package/src/core/multipart.js +282 -0
- package/src/core/openapi.js +114 -0
- package/src/core/router.js +388 -0
- package/src/core/routes-loader.js +57 -0
- package/src/core/scope-registry.js +53 -0
- package/src/core/security.js +275 -0
- package/src/core/services-loader.js +98 -0
- package/src/core/session-cleanup-schedule.js +57 -0
- package/src/core/session-store.js +55 -0
- package/src/core/session.js +414 -0
- package/src/core/static-assets.js +126 -0
- package/src/core/template.js +294 -0
- package/src/core/workers-manager.js +193 -0
- package/src/core/ws-compression.js +112 -0
- package/src/core/ws-controller.js +109 -0
- package/src/core/ws-message.js +176 -0
- package/src/core/ws-upgrade.js +445 -0
- package/src/errors/config-error.js +16 -0
- package/src/errors/http-errors.js +130 -0
- package/src/errors/index.js +19 -0
- package/src/errors/mega-error.js +34 -0
- package/src/eslint-plugin/index.js +15 -0
- package/src/eslint-plugin/no-direct-model-import.js +113 -0
- package/src/index.js +131 -0
- package/src/lib/asp/config.js +83 -0
- package/src/lib/asp/crypto.js +145 -0
- package/src/lib/asp/errors.js +49 -0
- package/src/lib/asp/nonce-cache.js +94 -0
- package/src/lib/asp/plugin.js +263 -0
- package/src/lib/asp/ws-terminator.js +101 -0
- package/src/lib/env-mapper.js +222 -0
- package/src/lib/hub-protocol.js +322 -0
- package/src/lib/index.js +42 -0
- package/src/lib/logger/telegram-core.js +150 -0
- package/src/lib/logger/telegram-transport.js +126 -0
- package/src/lib/mega-brute-force.js +225 -0
- package/src/lib/mega-circuit-breaker.js +412 -0
- package/src/lib/mega-cron.js +169 -0
- package/src/lib/mega-hash.js +179 -0
- package/src/lib/mega-health.js +91 -0
- package/src/lib/mega-job-queue.js +600 -0
- package/src/lib/mega-job-worker.js +295 -0
- package/src/lib/mega-job.js +140 -0
- package/src/lib/mega-logger.js +128 -0
- package/src/lib/mega-metrics.js +661 -0
- package/src/lib/mega-plugin.js +650 -0
- package/src/lib/mega-retry.js +95 -0
- package/src/lib/mega-schedule.js +507 -0
- package/src/lib/mega-shutdown.js +176 -0
- package/src/lib/mega-tracing.js +715 -0
- package/src/lib/mega-worker.js +653 -0
- package/src/lib/worker-runner/process-entry.js +30 -0
- package/src/lib/worker-runner/task-dispatch.js +72 -0
- package/src/lib/worker-runner/thread-entry.js +26 -0
- package/src/models/index.js +7 -0
- package/src/models/mega-model.js +151 -0
- package/src/test/index.js +288 -0
- package/templates/adapter/code.tpl +40 -0
- package/templates/adapter/test.tpl +13 -0
- package/templates/app/app.config.tpl +10 -0
- package/templates/app/route.tpl +10 -0
- package/templates/app/test.tpl +13 -0
- package/templates/channel/code.tpl +38 -0
- package/templates/channel/test.tpl +19 -0
- package/templates/controller/code.tpl +16 -0
- package/templates/controller/route.tpl +9 -0
- package/templates/controller/test.tpl +14 -0
- package/templates/job/code.tpl +23 -0
- package/templates/job/test.tpl +17 -0
- package/templates/locale/code.tpl +3 -0
- package/templates/locale/test.tpl +13 -0
- package/templates/middleware/code.tpl +13 -0
- package/templates/middleware/test.tpl +11 -0
- package/templates/migration/code.tpl +20 -0
- package/templates/migration/test.tpl +14 -0
- package/templates/model/code.tpl +21 -0
- package/templates/model/test.tpl +29 -0
- package/templates/project/app.config.tpl +8 -0
- package/templates/project/app.config.views.tpl +37 -0
- package/templates/project/ecosystem.config.tpl +10 -0
- package/templates/project/env.tpl +12 -0
- package/templates/project/gitignore.tpl +8 -0
- package/templates/project/locales/client/en.json.tpl +3 -0
- package/templates/project/locales/client/ko.json.tpl +3 -0
- package/templates/project/locales/server/en.json.tpl +17 -0
- package/templates/project/locales/server/ko.json.tpl +17 -0
- package/templates/project/mega.config.tpl +11 -0
- package/templates/project/package.tpl +25 -0
- package/templates/project/public/css/app.css +101 -0
- package/templates/project/public/js/app.js +54 -0
- package/templates/project/public/js/theme-init.js +12 -0
- package/templates/project/public/vendor/bootstrap/bootstrap.bundle.min.js +7 -0
- package/templates/project/public/vendor/bootstrap/bootstrap.min.css +6 -0
- package/templates/project/readme.tpl +48 -0
- package/templates/project/route.test.tpl +13 -0
- package/templates/project/route.test.views.tpl +15 -0
- package/templates/project/route.tpl +10 -0
- package/templates/project/route.views.tpl +10 -0
- package/templates/project/views/index.ejs.tpl +58 -0
- package/templates/project/views/layout.ejs.tpl +73 -0
- package/templates/project/vitest.config.tpl +8 -0
- package/templates/route/code.tpl +11 -0
- package/templates/route/test.tpl +26 -0
- package/templates/schedule/code.tpl +19 -0
- package/templates/schedule/test.tpl +17 -0
- package/templates/service/code.tpl +18 -0
- package/templates/service/test.tpl +17 -0
- package/templates/worker/code.tpl +14 -0
- package/templates/worker/task.tpl +13 -0
- package/templates/worker/test.tpl +18 -0
- package/vitest.config.js +33 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { describe, test, expect } from 'vitest'
|
|
3
|
+
import routes from '../../../apps/main/routes/index.js'
|
|
4
|
+
|
|
5
|
+
describe('main app index route', () => {
|
|
6
|
+
test('GET / 등록 + hello world 반환', async () => {
|
|
7
|
+
/** @type {Function|undefined} */
|
|
8
|
+
let handler
|
|
9
|
+
routes({ http: { get: (/** @type {string} */ _p, /** @type {Function} */ h) => void (handler = h) } })
|
|
10
|
+
expect(typeof handler).toBe('function')
|
|
11
|
+
expect(await /** @type {any} */ (handler)({}, {}, {})).toEqual({ message: 'Hello from {{name}}!' })
|
|
12
|
+
})
|
|
13
|
+
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { describe, test, expect, vi } from 'vitest'
|
|
3
|
+
import routes from '../../../apps/main/routes/index.js'
|
|
4
|
+
|
|
5
|
+
describe('main app index route (views)', () => {
|
|
6
|
+
test('GET / 가 index 뷰를 렌더', async () => {
|
|
7
|
+
/** @type {Function|undefined} */
|
|
8
|
+
let handler
|
|
9
|
+
routes({ http: { get: (/** @type {string} */ _p, /** @type {Function} */ h) => void (handler = h) } })
|
|
10
|
+
expect(typeof handler).toBe('function')
|
|
11
|
+
const ctx = { t: (/** @type {string} */ k) => k, render: vi.fn(() => 'html') }
|
|
12
|
+
await /** @type {any} */ (handler)({}, {}, ctx)
|
|
13
|
+
expect(ctx.render).toHaveBeenCalledWith('index', { title: 'welcome' })
|
|
14
|
+
})
|
|
15
|
+
})
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/**
|
|
3
|
+
* apps/main 기본 라우트 — 자동 로딩(loadRoutes). `mega start` 후 GET / 로 hello world.
|
|
4
|
+
*/
|
|
5
|
+
export default (/** @type {any} */ router) => {
|
|
6
|
+
router.http.get('/', async (/** @type {any} */ _req, /** @type {any} */ _res, /** @type {any} */ _ctx) => {
|
|
7
|
+
// 핸들러는 raw data 만 반환한다 — 프레임워크가 `{ ok, data, meta }` envelope 로 자동 wrap(ADR-018).
|
|
8
|
+
return { message: 'Hello from {{name}}!' }
|
|
9
|
+
})
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/**
|
|
3
|
+
* apps/main 기본 라우트 — 자동 로딩(loadRoutes). `mega start` 후 GET / 로 Bootstrap 5 뷰를 렌더한다.
|
|
4
|
+
*/
|
|
5
|
+
export default (/** @type {any} */ router) => {
|
|
6
|
+
router.http.get('/', async (/** @type {any} */ _req, /** @type {any} */ _reply, /** @type {any} */ ctx) => {
|
|
7
|
+
// ctx.render 가 EJS + ejs-mate 로 index.ejs 를 렌더한다(req.t/req.lang 자동 병합 → 다국어 뷰).
|
|
8
|
+
return ctx.render('index', { title: ctx.t('welcome') })
|
|
9
|
+
})
|
|
10
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
<% layout('layouts/main') %>
|
|
2
|
+
|
|
3
|
+
<section class="hero p-4 p-md-5 mb-5">
|
|
4
|
+
<div class="row align-items-center g-4">
|
|
5
|
+
<div class="col-lg-7">
|
|
6
|
+
<span class="badge text-bg-light border mb-3">{{name}}</span>
|
|
7
|
+
<h1 class="display-5 fw-bold mb-3"><%= t('hero_title') %></h1>
|
|
8
|
+
<p class="fs-5 text-body-secondary mb-4"><%= t('hero_subtitle') %></p>
|
|
9
|
+
<div class="d-flex flex-wrap gap-2">
|
|
10
|
+
<a href="https://www.npmjs.com/package/mega-framework" class="btn btn-primary btn-lg" target="_blank" rel="noopener"
|
|
11
|
+
><%= t('hero_cta_primary') %></a
|
|
12
|
+
>
|
|
13
|
+
<a href="https://getbootstrap.com/" class="btn btn-outline-secondary btn-lg" target="_blank" rel="noopener"
|
|
14
|
+
><%= t('hero_cta_secondary') %></a
|
|
15
|
+
>
|
|
16
|
+
</div>
|
|
17
|
+
</div>
|
|
18
|
+
<div class="col-lg-5 text-center d-none d-lg-block">
|
|
19
|
+
<div class="display-1">🚀</div>
|
|
20
|
+
</div>
|
|
21
|
+
</div>
|
|
22
|
+
</section>
|
|
23
|
+
|
|
24
|
+
<section>
|
|
25
|
+
<h2 class="h4 mb-4"><%= t('features_heading') %></h2>
|
|
26
|
+
<div class="row g-4">
|
|
27
|
+
<div class="col-md-4">
|
|
28
|
+
<div class="card h-100 feature-card border-0 shadow-sm">
|
|
29
|
+
<div class="card-body">
|
|
30
|
+
<div class="feature-icon mb-3">🎨</div>
|
|
31
|
+
<h3 class="h5 card-title"><%= t('feature1_title') %></h3>
|
|
32
|
+
<p class="card-text text-body-secondary mb-0"><%= t('feature1_desc') %></p>
|
|
33
|
+
</div>
|
|
34
|
+
</div>
|
|
35
|
+
</div>
|
|
36
|
+
<div class="col-md-4">
|
|
37
|
+
<div class="card h-100 feature-card border-0 shadow-sm">
|
|
38
|
+
<div class="card-body">
|
|
39
|
+
<div class="feature-icon mb-3">🌐</div>
|
|
40
|
+
<h3 class="h5 card-title"><%= t('feature2_title') %></h3>
|
|
41
|
+
<p class="card-text text-body-secondary mb-0"><%= t('feature2_desc') %></p>
|
|
42
|
+
</div>
|
|
43
|
+
</div>
|
|
44
|
+
</div>
|
|
45
|
+
<div class="col-md-4">
|
|
46
|
+
<div class="card h-100 feature-card border-0 shadow-sm">
|
|
47
|
+
<div class="card-body">
|
|
48
|
+
<div class="feature-icon mb-3">🌓</div>
|
|
49
|
+
<h3 class="h5 card-title"><%= t('feature3_title') %></h3>
|
|
50
|
+
<p class="card-text text-body-secondary mb-0"><%= t('feature3_desc') %></p>
|
|
51
|
+
</div>
|
|
52
|
+
</div>
|
|
53
|
+
</div>
|
|
54
|
+
</div>
|
|
55
|
+
<p class="text-body-secondary small mt-4 mb-0">
|
|
56
|
+
<code>apps/main/views/index.ejs</code> · <code>lang=<%= lang %></code>
|
|
57
|
+
</p>
|
|
58
|
+
</section>
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="<%= lang %>" data-bs-theme="light">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<title><%= typeof title !== 'undefined' ? title : '{{name}}' %></title>
|
|
7
|
+
<%# FOUC 방지 — 저장된 테마를 페인트 전에 적용. CSP(script-src 'self')라 인라인 불가 → 외부 파일. %>
|
|
8
|
+
<script src="/static/js/theme-init.js"></script>
|
|
9
|
+
<link rel="stylesheet" href="/static/vendor/bootstrap/bootstrap.min.css" />
|
|
10
|
+
<link rel="stylesheet" href="/static/css/app.css" />
|
|
11
|
+
</head>
|
|
12
|
+
<body class="d-flex flex-column min-vh-100">
|
|
13
|
+
<nav class="navbar navbar-expand-md border-bottom">
|
|
14
|
+
<div class="container">
|
|
15
|
+
<a class="navbar-brand" href="/">{{name}}</a>
|
|
16
|
+
<button
|
|
17
|
+
class="navbar-toggler"
|
|
18
|
+
type="button"
|
|
19
|
+
data-bs-toggle="collapse"
|
|
20
|
+
data-bs-target="#navmenu"
|
|
21
|
+
aria-controls="navmenu"
|
|
22
|
+
aria-expanded="false"
|
|
23
|
+
aria-label="menu"
|
|
24
|
+
>
|
|
25
|
+
<span class="navbar-toggler-icon"></span>
|
|
26
|
+
</button>
|
|
27
|
+
<div class="collapse navbar-collapse" id="navmenu">
|
|
28
|
+
<ul class="navbar-nav me-auto">
|
|
29
|
+
<li class="nav-item"><a class="nav-link" href="/"><%= t('nav_home') %></a></li>
|
|
30
|
+
</ul>
|
|
31
|
+
<div class="d-flex align-items-center gap-2">
|
|
32
|
+
<button
|
|
33
|
+
type="button"
|
|
34
|
+
class="btn btn-outline-secondary btn-sm"
|
|
35
|
+
data-theme-toggle
|
|
36
|
+
aria-label="<%= t('theme_toggle') %>"
|
|
37
|
+
title="<%= t('theme_toggle') %>"
|
|
38
|
+
>
|
|
39
|
+
<span class="theme-icon-light">☀️</span><span class="theme-icon-dark">🌙</span>
|
|
40
|
+
</button>
|
|
41
|
+
<div class="dropdown">
|
|
42
|
+
<button
|
|
43
|
+
class="btn btn-outline-secondary btn-sm dropdown-toggle"
|
|
44
|
+
type="button"
|
|
45
|
+
data-bs-toggle="dropdown"
|
|
46
|
+
aria-expanded="false"
|
|
47
|
+
>
|
|
48
|
+
<%= lang === 'ko' ? '한국어' : 'English' %>
|
|
49
|
+
</button>
|
|
50
|
+
<ul class="dropdown-menu dropdown-menu-end">
|
|
51
|
+
<li><a class="dropdown-item" href="#" data-lang="ko">한국어</a></li>
|
|
52
|
+
<li><a class="dropdown-item" href="#" data-lang="en">English</a></li>
|
|
53
|
+
</ul>
|
|
54
|
+
</div>
|
|
55
|
+
</div>
|
|
56
|
+
</div>
|
|
57
|
+
</div>
|
|
58
|
+
</nav>
|
|
59
|
+
|
|
60
|
+
<main class="container py-4 py-md-5 flex-grow-1">
|
|
61
|
+
<%- body %>
|
|
62
|
+
</main>
|
|
63
|
+
|
|
64
|
+
<footer class="site-footer py-4 mt-auto">
|
|
65
|
+
<div class="container text-center text-body-secondary small">
|
|
66
|
+
<%= t('footer_built') %>
|
|
67
|
+
</div>
|
|
68
|
+
</footer>
|
|
69
|
+
|
|
70
|
+
<script src="/static/vendor/bootstrap/bootstrap.bundle.min.js"></script>
|
|
71
|
+
<script src="/static/js/app.js"></script>
|
|
72
|
+
</body>
|
|
73
|
+
</html>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/**
|
|
3
|
+
* {{name}} 라우트 — 자동 로딩(loadRoutes) 대상. `export default (router) => { ... }` 단일 시그니처
|
|
4
|
+
* (ADR-074/089). 핸들러는 인라인 함수 또는 정적 메서드 참조(둘 다 그냥 함수).
|
|
5
|
+
*/
|
|
6
|
+
export default (/** @type {any} */ router) => {
|
|
7
|
+
router.http.get('/{{name}}', async (/** @type {any} */ _req, /** @type {any} */ _res, /** @type {any} */ _ctx) => {
|
|
8
|
+
// 핸들러는 raw data 만 반환한다 — 프레임워크가 `{ ok, data, meta }` envelope 로 자동 wrap(ADR-018).
|
|
9
|
+
return { resource: '{{name}}' }
|
|
10
|
+
})
|
|
11
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { describe, test, expect } from 'vitest'
|
|
3
|
+
import routes from '{{importPath}}'
|
|
4
|
+
|
|
5
|
+
describe('{{name}} routes', () => {
|
|
6
|
+
/** @returns {{ http: Record<string, any>, calls: any[] }} */
|
|
7
|
+
function makeRouter() {
|
|
8
|
+
/** @type {any[]} */
|
|
9
|
+
const calls = []
|
|
10
|
+
const rec = (/** @type {string} */ method) => (/** @type {string} */ path, /** @type {Function} */ handler) => calls.push({ method, path, handler })
|
|
11
|
+
return { http: { get: rec('get'), post: rec('post'), put: rec('put'), patch: rec('patch'), delete: rec('delete') }, calls }
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
test('GET /{{name}} 등록', () => {
|
|
15
|
+
const router = makeRouter()
|
|
16
|
+
routes(router)
|
|
17
|
+
expect(router.calls).toContainEqual(expect.objectContaining({ method: 'get', path: '/{{name}}' }))
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
test('핸들러가 data 반환', async () => {
|
|
21
|
+
const router = makeRouter()
|
|
22
|
+
routes(router)
|
|
23
|
+
const handler = router.calls.find((/** @type {any} */ c) => c.path === '/{{name}}').handler
|
|
24
|
+
expect(await handler({}, {}, {})).toEqual({ resource: '{{name}}' })
|
|
25
|
+
})
|
|
26
|
+
})
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { MegaSchedule } from 'mega-framework'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* {{Name}}Schedule — cron 정기 작업(ADR-028). `mega scheduler` 프로세스가 실행한다. 다중 인스턴스
|
|
6
|
+
* 중복 방지가 필요하면 `static lock = { lock: '<alias>', ttl: 60000 }`(ms) 을 추가한다(ADR-029).
|
|
7
|
+
*/
|
|
8
|
+
export class {{Name}}Schedule extends MegaSchedule {
|
|
9
|
+
static cron = '{{cron}}'
|
|
10
|
+
static timezone = 'Asia/Seoul'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {Record<string, any>} ctx
|
|
14
|
+
* @returns {Promise<void>}
|
|
15
|
+
*/
|
|
16
|
+
async run(ctx) {
|
|
17
|
+
ctx.log?.info?.('{{camelName}}: run')
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { describe, test, expect, vi } from 'vitest'
|
|
3
|
+
import { MegaSchedule } from 'mega-framework'
|
|
4
|
+
import { {{Name}}Schedule } from '{{importPath}}'
|
|
5
|
+
|
|
6
|
+
describe('{{Name}}Schedule', () => {
|
|
7
|
+
test('MegaSchedule 상속 + static cron 설정', () => {
|
|
8
|
+
expect(Object.getPrototypeOf({{Name}}Schedule)).toBe(MegaSchedule)
|
|
9
|
+
expect(typeof {{Name}}Schedule.cron).toBe('string')
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
test('run — ctx.log 호출', async () => {
|
|
13
|
+
const info = vi.fn()
|
|
14
|
+
await new {{Name}}Schedule().run({ log: { info } })
|
|
15
|
+
expect(info).toHaveBeenCalled()
|
|
16
|
+
})
|
|
17
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { MegaService } from 'mega-framework'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* {{Name}}Service — {{name}} 도메인 비즈니스 로직. 컨트롤러는 모델을 직접 import 하지 않고 서비스를
|
|
6
|
+
* 경유한다(ADR-022). 서비스 안에서는 모델 import 가 허용된다(모델의 유일한 접근 경로).
|
|
7
|
+
*/
|
|
8
|
+
export class {{Name}}Service extends MegaService {
|
|
9
|
+
/**
|
|
10
|
+
* 목록 조회 예시. 실제 구현은 모델을 호출한다(예: `return {{Name}}.list(query)`).
|
|
11
|
+
* @param {object} [query]
|
|
12
|
+
* @returns {Promise<object[]>}
|
|
13
|
+
*/
|
|
14
|
+
async list(query = {}) {
|
|
15
|
+
this.log.debug({ query }, '{{camelName}}.list')
|
|
16
|
+
return []
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { describe, test, expect } from 'vitest'
|
|
3
|
+
import { MegaService } from 'mega-framework'
|
|
4
|
+
import { {{Name}}Service } from '{{importPath}}'
|
|
5
|
+
|
|
6
|
+
describe('{{Name}}Service', () => {
|
|
7
|
+
const ctx = { log: { debug() {} } }
|
|
8
|
+
|
|
9
|
+
test('MegaService 를 상속', () => {
|
|
10
|
+
expect(new {{Name}}Service(ctx)).toBeInstanceOf(MegaService)
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
test('list — 기본 빈 배열', async () => {
|
|
14
|
+
const svc = new {{Name}}Service(ctx)
|
|
15
|
+
expect(await svc.list({ page: 1 })).toEqual([])
|
|
16
|
+
})
|
|
17
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { MegaWorker } from 'mega-framework'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* {{Name}}Worker — CPU 격리 워커 풀(ADR-124). 작업 로직은 `static taskFile` 모듈에 named export 한
|
|
6
|
+
* async 함수다(worker_threads/process 경계는 함수·클로저를 못 넘기므로 파일 경로 필수). 호출:
|
|
7
|
+
* `ctx.workers['{{name}}'].run('{{camelName}}', args)`.
|
|
8
|
+
*/
|
|
9
|
+
export class {{Name}}Worker extends MegaWorker {
|
|
10
|
+
static name = '{{name}}'
|
|
11
|
+
static taskFile = '{{taskFile}}'
|
|
12
|
+
static mode = 'thread'
|
|
13
|
+
static poolSize = 2
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/**
|
|
3
|
+
* {{Name}}Worker 의 작업 함수 모듈(= `static taskFile`). named export 한 async 함수를 워커가 로드해
|
|
4
|
+
* `run(taskName, args)` 의 taskName 으로 디스패치한다(ADR-124). 보일러플레이트 없이 함수만 export.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param {{ value?: number }} task - 워커 경계를 넘는 직렬화 가능한 데이터만.
|
|
9
|
+
* @returns {Promise<object>}
|
|
10
|
+
*/
|
|
11
|
+
export async function {{camelName}}(task) {
|
|
12
|
+
return { value: task.value, done: true }
|
|
13
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { describe, test, expect } from 'vitest'
|
|
3
|
+
import { MegaWorker } from 'mega-framework'
|
|
4
|
+
import { {{Name}}Worker } from '{{importPath}}'
|
|
5
|
+
import { {{camelName}} } from '{{taskImportPath}}'
|
|
6
|
+
|
|
7
|
+
describe('{{Name}}Worker', () => {
|
|
8
|
+
test('MegaWorker 상속 + static taskFile/mode/name', () => {
|
|
9
|
+
expect(Object.getPrototypeOf({{Name}}Worker)).toBe(MegaWorker)
|
|
10
|
+
expect({{Name}}Worker.name).toBe('{{name}}')
|
|
11
|
+
expect({{Name}}Worker.taskFile).toContain('{{name}}.task')
|
|
12
|
+
expect(['thread', 'process']).toContain({{Name}}Worker.mode)
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
test('task 함수 {{camelName}} — 순수 실행', async () => {
|
|
16
|
+
expect(await {{camelName}}({ value: 2 })).toEqual({ value: 2, done: true })
|
|
17
|
+
})
|
|
18
|
+
})
|
package/vitest.config.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { defineConfig } from 'vitest/config'
|
|
2
|
+
import { loadEnv } from 'vite'
|
|
3
|
+
|
|
4
|
+
// ── .env 자동 로드 (ADR-128) ───────────────────────────────────────────
|
|
5
|
+
// 통합 테스트(redis/pg/mongo/nats 등)는 process.env 의 연결 URL 로 docker 실
|
|
6
|
+
// 인프라 가동 여부를 판단해 skip/run 을 결정한다(예: REDIS_CACHE_URL 없으면
|
|
7
|
+
// describe.skip). 하지만 vitest 는 기본적으로 .env 를 process.env 로 주입하지
|
|
8
|
+
// 않아, .env 가 있어도 통합 테스트 63건이 전부 skip 되던 문제가 있었다.
|
|
9
|
+
// → Vite 내장 loadEnv(mode, cwd, '') 로 .env(+.env.<mode>) 를 읽어 test.env 에
|
|
10
|
+
// 주입한다. 세 번째 인자 '' 는 prefix 필터('VITE_') 를 해제해 모든 키를 노출.
|
|
11
|
+
// → 새 npm 의존성 0 (loadEnv 는 vite 내장). dotenv 미도입. (P8 불필요)
|
|
12
|
+
// mode 기본값은 'test' (vitest). CI 에서 컨테이너 미기동이면 URL 도 없어 자연히 skip.
|
|
13
|
+
export default defineConfig(({ mode }) => ({
|
|
14
|
+
test: {
|
|
15
|
+
env: loadEnv(mode, process.cwd(), ''),
|
|
16
|
+
include: ['test/**/*.test.js', 'test/**/*.integration.test.js'],
|
|
17
|
+
exclude: ['test/**/*.e2e.test.js', 'node_modules/**'],
|
|
18
|
+
coverage: {
|
|
19
|
+
provider: 'v8',
|
|
20
|
+
include: ['src/**/*.js'],
|
|
21
|
+
exclude: [
|
|
22
|
+
'src/**/*.test.js',
|
|
23
|
+
// 워커 런타임 진입 스크립트(ADR-124) — worker_threads/child_process **안에서만** 실행돼 부모
|
|
24
|
+
// 프로세스 v8 커버리지가 측정할 수 없다(별도 isolate/process). 실 동작은 mega-worker E2E 가
|
|
25
|
+
// 디스패치·결과·crash 로 증명하고, 핵심 로직(task-dispatch.js)은 in-process 단위로 별도 커버.
|
|
26
|
+
// 두 파일은 import + 리스너 부착 + ready 송신뿐인 얇은 wiring 이라 제외해도 사각 위험 낮음.
|
|
27
|
+
'src/lib/worker-runner/thread-entry.js',
|
|
28
|
+
'src/lib/worker-runner/process-entry.js',
|
|
29
|
+
],
|
|
30
|
+
thresholds: { lines: 90, functions: 90, branches: 85, statements: 90 },
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
}))
|