create-nexwire 4.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.
- package/README.md +233 -0
- package/express/.dockerignore +14 -0
- package/express/.env +44 -0
- package/express/.env.example +42 -0
- package/express/.vscode/settings.json +26 -0
- package/express/LICENSE +21 -0
- package/express/README.md +211 -0
- package/express/biome.json +66 -0
- package/express/drizzle.config.ts +25 -0
- package/express/gitignore-stub +24 -0
- package/express/package.json +108 -0
- package/express/public/.gitkeep +0 -0
- package/express/src/config/app.ts +41 -0
- package/express/src/config/auth.ts +12 -0
- package/express/src/config/cache.ts +16 -0
- package/express/src/config/cookie.ts +15 -0
- package/express/src/config/cors.ts +12 -0
- package/express/src/config/database.ts +29 -0
- package/express/src/config/index.ts +83 -0
- package/express/src/config/jwt.ts +19 -0
- package/express/src/config/logging.ts +13 -0
- package/express/src/config/mail.ts +24 -0
- package/express/src/config/openapi.ts +54 -0
- package/express/src/config/queue.ts +30 -0
- package/express/src/config/rateLimit.ts +17 -0
- package/express/src/config/realtime.ts +15 -0
- package/express/src/config/redis.ts +18 -0
- package/express/src/config/security.ts +44 -0
- package/express/src/config/session.ts +17 -0
- package/express/src/config/storage.ts +22 -0
- package/express/src/config/validate.ts +40 -0
- package/express/src/database/migrations/sqlite/0000_init.sql +61 -0
- package/express/src/database/migrations/sqlite/meta/0000_snapshot.json +412 -0
- package/express/src/database/migrations/sqlite/meta/_journal.json +13 -0
- package/express/src/database/schema.ts +3 -0
- package/express/src/env.ts +76 -0
- package/express/src/framework/cache/cache.ts +81 -0
- package/express/src/framework/circuit-breaker/cb.ts +60 -0
- package/express/src/framework/database/connection.ts +196 -0
- package/express/src/framework/database/migrate-hooks.ts +87 -0
- package/express/src/framework/database/paginate.ts +227 -0
- package/express/src/framework/database/schema.ts +20 -0
- package/express/src/framework/database/seed.ts +139 -0
- package/express/src/framework/events/dispatcher.ts +49 -0
- package/express/src/framework/facade.ts +48 -0
- package/express/src/framework/http/app.ts +107 -0
- package/express/src/framework/http/cors.ts +7 -0
- package/express/src/framework/http/logger.ts +69 -0
- package/express/src/framework/http/metrics.ts +22 -0
- package/express/src/framework/http/openapi.ts +54 -0
- package/express/src/framework/http/ratelimiter.ts +16 -0
- package/express/src/framework/http/router.ts +178 -0
- package/express/src/framework/http/security.ts +23 -0
- package/express/src/framework/http/static.ts +23 -0
- package/express/src/framework/http/validation.ts +18 -0
- package/express/src/framework/kernel.ts +52 -0
- package/express/src/framework/maker-cli/db/core.mjs +288 -0
- package/express/src/framework/maker-cli/db/index.mjs +204 -0
- package/express/src/framework/maker-cli/deploy/core.mjs +1047 -0
- package/express/src/framework/maker-cli/deploy/index.mjs +91 -0
- package/express/src/framework/maker-cli/index.mjs +53 -0
- package/express/src/framework/maker-cli/middleware/core.mjs +47 -0
- package/express/src/framework/maker-cli/middleware/index.mjs +17 -0
- package/express/src/framework/maker-cli/module/core.mjs +684 -0
- package/express/src/framework/maker-cli/module/index.mjs +140 -0
- package/express/src/framework/maker-cli/runtime/build-ui.mjs +16 -0
- package/express/src/framework/maker-cli/runtime/core.mjs +543 -0
- package/express/src/framework/maker-cli/runtime/index.mjs +104 -0
- package/express/src/framework/maker-cli/runtime/redis-commander-patch.cjs +20 -0
- package/express/src/framework/maker-cli/stubs/controller/openapi.ts.stub +47 -0
- package/express/src/framework/maker-cli/stubs/controller/openapi.with-model.ts.stub +48 -0
- package/express/src/framework/maker-cli/stubs/controller/plain.ts.stub +54 -0
- package/express/src/framework/maker-cli/stubs/controller/schema.plain.ts.stub +14 -0
- package/express/src/framework/maker-cli/stubs/controller/schema.ts.stub +33 -0
- package/express/src/framework/maker-cli/stubs/deploy/Dockerfile.bun.stub +52 -0
- package/express/src/framework/maker-cli/stubs/deploy/Dockerfile.pnpm.stub +55 -0
- package/express/src/framework/maker-cli/stubs/deploy/Dockerfile.stub +51 -0
- package/express/src/framework/maker-cli/stubs/deploy/Dockerfile.yarn.stub +55 -0
- package/express/src/framework/maker-cli/stubs/deploy/README.stub +59 -0
- package/express/src/framework/maker-cli/stubs/deploy/compose/mysql.server.stub +45 -0
- package/express/src/framework/maker-cli/stubs/deploy/compose/postgres.server.stub +45 -0
- package/express/src/framework/maker-cli/stubs/deploy/compose/sqlite.stub +45 -0
- package/express/src/framework/maker-cli/stubs/deploy/env/mysql.server.stub +68 -0
- package/express/src/framework/maker-cli/stubs/deploy/env/postgres.server.stub +68 -0
- package/express/src/framework/maker-cli/stubs/deploy/env/sqlite.stub +67 -0
- package/express/src/framework/maker-cli/stubs/deploy/scripts/auto-migrate.sh.stub +41 -0
- package/express/src/framework/maker-cli/stubs/deploy/server/README.stub +78 -0
- package/express/src/framework/maker-cli/stubs/deploy/server/compose/noredis.stub +120 -0
- package/express/src/framework/maker-cli/stubs/deploy/server/compose/redis.dev.stub +133 -0
- package/express/src/framework/maker-cli/stubs/deploy/server/compose/redis.stub +131 -0
- package/express/src/framework/maker-cli/stubs/deploy/server/env/local.example.stub +11 -0
- package/express/src/framework/maker-cli/stubs/deploy/server/env/noredis.stub +25 -0
- package/express/src/framework/maker-cli/stubs/deploy/server/env/redis.stub +25 -0
- package/express/src/framework/maker-cli/stubs/deploy/server/nginx-vhost/README.stub +16 -0
- package/express/src/framework/maker-cli/stubs/deploy/server/nginx-vhost/app.example.com.stub +13 -0
- package/express/src/framework/maker-cli/stubs/deploy/server/pgadmin/servers.stub +14 -0
- package/express/src/framework/maker-cli/stubs/deploy/server/redis/redis.conf.stub +7 -0
- package/express/src/framework/maker-cli/stubs/deploy/supervisor/noredis.stub +54 -0
- package/express/src/framework/maker-cli/stubs/deploy/supervisor/redis.stub +70 -0
- package/express/src/framework/maker-cli/stubs/deploy/workflow/local.json.stub +25 -0
- package/express/src/framework/maker-cli/stubs/deploy/workflow/remote.json.stub +24 -0
- package/express/src/framework/maker-cli/stubs/example/console.ts.stub +34 -0
- package/express/src/framework/maker-cli/stubs/example/controller.ts.stub +418 -0
- package/express/src/framework/maker-cli/stubs/example/job.ts.stub +75 -0
- package/express/src/framework/maker-cli/stubs/example/route.api.ts.stub +207 -0
- package/express/src/framework/maker-cli/stubs/example/route.plain.ts.stub +18 -0
- package/express/src/framework/maker-cli/stubs/example/schema.plain.ts.stub +42 -0
- package/express/src/framework/maker-cli/stubs/example/schema.ts.stub +42 -0
- package/express/src/framework/maker-cli/stubs/job/name.ts.stub +25 -0
- package/express/src/framework/maker-cli/stubs/middleware/name.ts.stub +14 -0
- package/express/src/framework/maker-cli/stubs/model/name.mysql.ts.stub +9 -0
- package/express/src/framework/maker-cli/stubs/model/name.postgresql.ts.stub +9 -0
- package/express/src/framework/maker-cli/stubs/model/name.sqlite.ts.stub +9 -0
- package/express/src/framework/maker-cli/stubs/notification/controller.ts.stub +77 -0
- package/express/src/framework/maker-cli/stubs/notification/job.ts.stub +13 -0
- package/express/src/framework/maker-cli/stubs/notification/route.api.ts.stub +50 -0
- package/express/src/framework/maker-cli/stubs/notification/route.plain.ts.stub +12 -0
- package/express/src/framework/maker-cli/stubs/notification/schema.plain.ts.stub +26 -0
- package/express/src/framework/maker-cli/stubs/notification/schema.ts.stub +26 -0
- package/express/src/framework/maker-cli/stubs/route/api.ts.stub +80 -0
- package/express/src/framework/maker-cli/stubs/route/plain.ts.stub +11 -0
- package/express/src/framework/maker-cli/stubs/schedule/name.ts.stub +36 -0
- package/express/src/framework/maker-cli/stubs/seeder/name.ts.stub +20 -0
- package/express/src/framework/maker-cli/stubs/test/unit.ts.stub +22 -0
- package/express/src/framework/maker-cli/utils/env-config.mjs +44 -0
- package/express/src/framework/maker-cli/utils/env-db.mjs +61 -0
- package/express/src/framework/maker-cli/utils/file-ops.mjs +30 -0
- package/express/src/framework/maker-cli/utils/flags.mjs +14 -0
- package/express/src/framework/maker-cli/utils/help.mjs +50 -0
- package/express/src/framework/maker-cli/utils/naming.mjs +13 -0
- package/express/src/framework/maker-cli/utils/process.mjs +52 -0
- package/express/src/framework/modules/discover.ts +54 -0
- package/express/src/framework/modules/routes.ts +21 -0
- package/express/src/framework/notification/index.ts +116 -0
- package/express/src/framework/queue/clear.ts +22 -0
- package/express/src/framework/queue/queue.ts +342 -0
- package/express/src/framework/queue/ui.ts +187 -0
- package/express/src/framework/queue/worker.ts +61 -0
- package/express/src/framework/realtime/broadcast.ts +46 -0
- package/express/src/framework/realtime/index.ts +2 -0
- package/express/src/framework/realtime/socket-cookie.ts +71 -0
- package/express/src/framework/realtime/socket.ts +119 -0
- package/express/src/framework/realtime/types.ts +6 -0
- package/express/src/framework/realtime/ui.ts +16 -0
- package/express/src/framework/redis/client.ts +151 -0
- package/express/src/framework/runtime/runtime.ts +23 -0
- package/express/src/framework/runtime/server-adapter.ts +34 -0
- package/express/src/framework/scheduler/lock.ts +116 -0
- package/express/src/framework/scheduler/run.ts +48 -0
- package/express/src/framework/scheduler/scheduler.ts +155 -0
- package/express/src/framework/server.ts +177 -0
- package/express/src/framework/session/session.ts +98 -0
- package/express/src/framework/storage/storage.ts +785 -0
- package/express/src/framework/support/cookie.ts +62 -0
- package/express/src/framework/support/jwt.ts +33 -0
- package/express/src/framework/support/lifecycle.ts +35 -0
- package/express/src/framework/support/logger.ts +148 -0
- package/express/src/framework/support/mail.ts +48 -0
- package/express/src/framework/support/password.ts +23 -0
- package/express/src/framework/support/upload.ts +160 -0
- package/express/src/framework/support/url.ts +41 -0
- package/express/src/middlewares/auth-middleware.ts +98 -0
- package/express/src/middlewares/role-middleware.ts +25 -0
- package/express/src/modules/auth/controllers/auth.controller.ts +358 -0
- package/express/src/modules/auth/controllers/auth.helpers.ts +104 -0
- package/express/src/modules/auth/controllers/auth.schema.ts +102 -0
- package/express/src/modules/auth/controllers/role.controller.ts +15 -0
- package/express/src/modules/auth/database/models/notifications.ts +24 -0
- package/express/src/modules/auth/database/models/role.ts +14 -0
- package/express/src/modules/auth/database/models/user.ts +46 -0
- package/express/src/modules/auth/database/seeders/role.ts +18 -0
- package/express/src/modules/auth/database/seeders/user.ts +35 -0
- package/express/src/modules/auth/jobs/forgetpass.ts +20 -0
- package/express/src/modules/auth/jobs/registeruser.ts +23 -0
- package/express/src/modules/auth/jobs/verifyemail.ts +18 -0
- package/express/src/modules/auth/routes/api.ts +150 -0
- package/express/src/modules/auth/routes/role.ts +33 -0
- package/express/src/resources/index.html +17 -0
- package/express/src/resources/src/App.vue +5 -0
- package/express/src/resources/src/assets/css/styles.css +14761 -0
- package/express/src/resources/src/assets/css/styles.css.map +1 -0
- package/express/src/resources/src/assets/fonts/public-sans/public-sans-latin-ext.woff2 +0 -0
- package/express/src/resources/src/assets/fonts/public-sans/public-sans-latin.woff2 +0 -0
- package/express/src/resources/src/assets/images/favicon/favicon.ico +0 -0
- package/express/src/resources/src/assets/images/logo.png +0 -0
- package/express/src/resources/src/assets/scss/custom.css +217 -0
- package/express/src/resources/src/assets/scss/custom.css.map +1 -0
- package/express/src/resources/src/assets/scss/custom.scss +1346 -0
- package/express/src/resources/src/components/Button.vue +32 -0
- package/express/src/resources/src/components/Checkbox.vue +29 -0
- package/express/src/resources/src/components/Datepicker.vue +106 -0
- package/express/src/resources/src/components/FeatureButton.vue +53 -0
- package/express/src/resources/src/components/FloatButton.vue +33 -0
- package/express/src/resources/src/components/Href.vue +32 -0
- package/express/src/resources/src/components/Input.vue +223 -0
- package/express/src/resources/src/components/InputGroup.vue +145 -0
- package/express/src/resources/src/components/InputPasswordToggle.vue +213 -0
- package/express/src/resources/src/components/Modal.vue +55 -0
- package/express/src/resources/src/components/Pagebar.vue +26 -0
- package/express/src/resources/src/components/Select.vue +384 -0
- package/express/src/resources/src/components/Spinner.vue +42 -0
- package/express/src/resources/src/components/Switch.vue +65 -0
- package/express/src/resources/src/components/TextArea.vue +117 -0
- package/express/src/resources/src/components/Toast.vue +56 -0
- package/express/src/resources/src/components/datatable/DataTableSkeleton.vue +98 -0
- package/express/src/resources/src/components/datatable/Pagination.vue +147 -0
- package/express/src/resources/src/components/datatable/SelectOpption.vue +64 -0
- package/express/src/resources/src/components/datatable/index.vue +199 -0
- package/express/src/resources/src/composables/useAuth.ts +52 -0
- package/express/src/resources/src/helpers/nformatter.ts +10 -0
- package/express/src/resources/src/helpers/utils.ts +75 -0
- package/express/src/resources/src/layouts/AuthLayout.vue +20 -0
- package/express/src/resources/src/layouts/Layout/Footer.vue +23 -0
- package/express/src/resources/src/layouts/Layout/Header.vue +105 -0
- package/express/src/resources/src/layouts/Layout/Sidebar.vue +137 -0
- package/express/src/resources/src/layouts/Layout/index.vue +87 -0
- package/express/src/resources/src/main.ts +26 -0
- package/express/src/resources/src/pages/auth/forgetPassword.vue +82 -0
- package/express/src/resources/src/pages/auth/login.vue +99 -0
- package/express/src/resources/src/pages/auth/register.vue +133 -0
- package/express/src/resources/src/pages/auth/resetPassword.vue +118 -0
- package/express/src/resources/src/pages/auth/verifyEmail.vue +68 -0
- package/express/src/resources/src/pages/dashboard/index.vue +66 -0
- package/express/src/resources/src/plugins/axios.ts +31 -0
- package/express/src/resources/src/plugins/browserDetect.ts +55 -0
- package/express/src/resources/src/plugins/dialog.ts +216 -0
- package/express/src/resources/src/plugins/gum.ts +367 -0
- package/express/src/resources/src/plugins/pulse.ts +147 -0
- package/express/src/resources/src/plugins/routeProgress.ts +87 -0
- package/express/src/resources/src/router/index.ts +85 -0
- package/express/src/resources/src/stores/admin-ui.ts +148 -0
- package/express/src/resources/src/stores/auth.ts +164 -0
- package/express/src/resources/tsconfig.json +19 -0
- package/express/src/resources/vite.config.ts +46 -0
- package/express/src/storage/app/private/.gitkeep +0 -0
- package/express/src/storage/app/public/.gitkeep +0 -0
- package/express/src/storage/app/tmp/generated/.gitkeep +0 -0
- package/express/src/storage/database/nexwire.sqlite +0 -0
- package/express/src/storage/logs/.gitkeep +0 -0
- package/express/src/storage/tmp/.gitkeep +0 -0
- package/express/src/storage/trash/modules/.gitkeep +0 -0
- package/express/src/types/global.d.ts +26 -0
- package/express/tsconfig.json +19 -0
- package/express/vitest.config.ts +23 -0
- package/hono/.dockerignore +14 -0
- package/hono/.env +44 -0
- package/hono/.env.example +42 -0
- package/hono/.vscode/settings.json +26 -0
- package/hono/LICENSE +21 -0
- package/hono/README.md +211 -0
- package/hono/biome.json +76 -0
- package/hono/drizzle.config.ts +25 -0
- package/hono/gitignore-stub +24 -0
- package/hono/package.json +99 -0
- package/hono/public/.gitkeep +0 -0
- package/hono/src/config/app.ts +41 -0
- package/hono/src/config/auth.ts +12 -0
- package/hono/src/config/cache.ts +16 -0
- package/hono/src/config/cookie.ts +15 -0
- package/hono/src/config/cors.ts +12 -0
- package/hono/src/config/database.ts +29 -0
- package/hono/src/config/index.ts +83 -0
- package/hono/src/config/jwt.ts +19 -0
- package/hono/src/config/logging.ts +13 -0
- package/hono/src/config/mail.ts +24 -0
- package/hono/src/config/openapi.ts +54 -0
- package/hono/src/config/queue.ts +30 -0
- package/hono/src/config/rateLimit.ts +17 -0
- package/hono/src/config/realtime.ts +15 -0
- package/hono/src/config/redis.ts +18 -0
- package/hono/src/config/security.ts +44 -0
- package/hono/src/config/session.ts +17 -0
- package/hono/src/config/storage.ts +22 -0
- package/hono/src/config/validate.ts +40 -0
- package/hono/src/database/migrations/sqlite/0000_init.sql +61 -0
- package/hono/src/database/migrations/sqlite/meta/0000_snapshot.json +412 -0
- package/hono/src/database/migrations/sqlite/meta/_journal.json +13 -0
- package/hono/src/database/schema.ts +3 -0
- package/hono/src/env.ts +76 -0
- package/hono/src/framework/cache/cache.ts +81 -0
- package/hono/src/framework/circuit-breaker/cb.ts +60 -0
- package/hono/src/framework/database/connection.ts +196 -0
- package/hono/src/framework/database/migrate-hooks.ts +87 -0
- package/hono/src/framework/database/paginate.ts +253 -0
- package/hono/src/framework/database/schema.ts +20 -0
- package/hono/src/framework/database/seed.ts +139 -0
- package/hono/src/framework/events/dispatcher.ts +49 -0
- package/hono/src/framework/facade.ts +29 -0
- package/hono/src/framework/http/app.ts +109 -0
- package/hono/src/framework/http/cors.ts +19 -0
- package/hono/src/framework/http/logger.ts +81 -0
- package/hono/src/framework/http/metrics.ts +22 -0
- package/hono/src/framework/http/openapi.ts +42 -0
- package/hono/src/framework/http/ratelimiter.ts +172 -0
- package/hono/src/framework/http/router.ts +76 -0
- package/hono/src/framework/http/security.ts +23 -0
- package/hono/src/framework/http/static.ts +70 -0
- package/hono/src/framework/http/validation.ts +21 -0
- package/hono/src/framework/kernel.ts +48 -0
- package/hono/src/framework/maker-cli/db/core.mjs +288 -0
- package/hono/src/framework/maker-cli/db/index.mjs +204 -0
- package/hono/src/framework/maker-cli/deploy/core.mjs +1038 -0
- package/hono/src/framework/maker-cli/deploy/index.mjs +91 -0
- package/hono/src/framework/maker-cli/index.mjs +53 -0
- package/hono/src/framework/maker-cli/middleware/core.mjs +47 -0
- package/hono/src/framework/maker-cli/middleware/index.mjs +12 -0
- package/hono/src/framework/maker-cli/module/core.mjs +684 -0
- package/hono/src/framework/maker-cli/module/index.mjs +140 -0
- package/hono/src/framework/maker-cli/runtime/build-ui.mjs +17 -0
- package/hono/src/framework/maker-cli/runtime/core.mjs +543 -0
- package/hono/src/framework/maker-cli/runtime/index.mjs +104 -0
- package/hono/src/framework/maker-cli/runtime/redis-commander-patch.cjs +20 -0
- package/hono/src/framework/maker-cli/stubs/controller/openapi.ts.stub +57 -0
- package/hono/src/framework/maker-cli/stubs/controller/openapi.with-model.ts.stub +58 -0
- package/hono/src/framework/maker-cli/stubs/controller/plain.ts.stub +59 -0
- package/hono/src/framework/maker-cli/stubs/controller/schema.plain.ts.stub +14 -0
- package/hono/src/framework/maker-cli/stubs/controller/schema.ts.stub +33 -0
- package/hono/src/framework/maker-cli/stubs/deploy/Dockerfile.bun.stub +52 -0
- package/hono/src/framework/maker-cli/stubs/deploy/Dockerfile.pnpm.stub +55 -0
- package/hono/src/framework/maker-cli/stubs/deploy/Dockerfile.stub +51 -0
- package/hono/src/framework/maker-cli/stubs/deploy/Dockerfile.yarn.stub +55 -0
- package/hono/src/framework/maker-cli/stubs/deploy/README.stub +59 -0
- package/hono/src/framework/maker-cli/stubs/deploy/compose/mysql.server.stub +45 -0
- package/hono/src/framework/maker-cli/stubs/deploy/compose/postgres.server.stub +45 -0
- package/hono/src/framework/maker-cli/stubs/deploy/compose/sqlite.stub +45 -0
- package/hono/src/framework/maker-cli/stubs/deploy/env/mysql.server.stub +68 -0
- package/hono/src/framework/maker-cli/stubs/deploy/env/postgres.server.stub +68 -0
- package/hono/src/framework/maker-cli/stubs/deploy/env/sqlite.stub +67 -0
- package/hono/src/framework/maker-cli/stubs/deploy/scripts/auto-migrate.sh.stub +41 -0
- package/hono/src/framework/maker-cli/stubs/deploy/server/README.stub +78 -0
- package/hono/src/framework/maker-cli/stubs/deploy/server/compose/noredis.stub +120 -0
- package/hono/src/framework/maker-cli/stubs/deploy/server/compose/redis.dev.stub +133 -0
- package/hono/src/framework/maker-cli/stubs/deploy/server/compose/redis.stub +131 -0
- package/hono/src/framework/maker-cli/stubs/deploy/server/env/local.example.stub +11 -0
- package/hono/src/framework/maker-cli/stubs/deploy/server/env/noredis.stub +25 -0
- package/hono/src/framework/maker-cli/stubs/deploy/server/env/redis.stub +25 -0
- package/hono/src/framework/maker-cli/stubs/deploy/server/nginx-vhost/README.stub +16 -0
- package/hono/src/framework/maker-cli/stubs/deploy/server/nginx-vhost/app.example.com.stub +13 -0
- package/hono/src/framework/maker-cli/stubs/deploy/server/pgadmin/servers.stub +14 -0
- package/hono/src/framework/maker-cli/stubs/deploy/server/redis/redis.conf.stub +7 -0
- package/hono/src/framework/maker-cli/stubs/deploy/supervisor/noredis.stub +54 -0
- package/hono/src/framework/maker-cli/stubs/deploy/supervisor/redis.stub +70 -0
- package/hono/src/framework/maker-cli/stubs/deploy/workflow/local.json.stub +25 -0
- package/hono/src/framework/maker-cli/stubs/deploy/workflow/remote.json.stub +24 -0
- package/hono/src/framework/maker-cli/stubs/example/console.ts.stub +34 -0
- package/hono/src/framework/maker-cli/stubs/example/controller.ts.stub +505 -0
- package/hono/src/framework/maker-cli/stubs/example/job.ts.stub +75 -0
- package/hono/src/framework/maker-cli/stubs/example/route.api.ts.stub +207 -0
- package/hono/src/framework/maker-cli/stubs/example/route.plain.ts.stub +18 -0
- package/hono/src/framework/maker-cli/stubs/example/schema.plain.ts.stub +42 -0
- package/hono/src/framework/maker-cli/stubs/example/schema.ts.stub +42 -0
- package/hono/src/framework/maker-cli/stubs/job/name.ts.stub +25 -0
- package/hono/src/framework/maker-cli/stubs/middleware/name.ts.stub +14 -0
- package/hono/src/framework/maker-cli/stubs/model/name.mysql.ts.stub +9 -0
- package/hono/src/framework/maker-cli/stubs/model/name.postgresql.ts.stub +9 -0
- package/hono/src/framework/maker-cli/stubs/model/name.sqlite.ts.stub +9 -0
- package/hono/src/framework/maker-cli/stubs/notification/controller.ts.stub +86 -0
- package/hono/src/framework/maker-cli/stubs/notification/job.ts.stub +13 -0
- package/hono/src/framework/maker-cli/stubs/notification/route.api.ts.stub +50 -0
- package/hono/src/framework/maker-cli/stubs/notification/route.plain.ts.stub +12 -0
- package/hono/src/framework/maker-cli/stubs/notification/schema.plain.ts.stub +26 -0
- package/hono/src/framework/maker-cli/stubs/notification/schema.ts.stub +26 -0
- package/hono/src/framework/maker-cli/stubs/route/api.ts.stub +80 -0
- package/hono/src/framework/maker-cli/stubs/route/plain.ts.stub +11 -0
- package/hono/src/framework/maker-cli/stubs/schedule/name.ts.stub +36 -0
- package/hono/src/framework/maker-cli/stubs/seeder/name.ts.stub +20 -0
- package/hono/src/framework/maker-cli/stubs/test/unit.ts.stub +22 -0
- package/hono/src/framework/maker-cli/utils/env-config.mjs +44 -0
- package/hono/src/framework/maker-cli/utils/env-db.mjs +61 -0
- package/hono/src/framework/maker-cli/utils/file-ops.mjs +30 -0
- package/hono/src/framework/maker-cli/utils/flags.mjs +14 -0
- package/hono/src/framework/maker-cli/utils/help.mjs +50 -0
- package/hono/src/framework/maker-cli/utils/naming.mjs +13 -0
- package/hono/src/framework/maker-cli/utils/process.mjs +52 -0
- package/hono/src/framework/modules/discover.ts +54 -0
- package/hono/src/framework/modules/routes.ts +24 -0
- package/hono/src/framework/notification/index.ts +116 -0
- package/hono/src/framework/queue/clear.ts +22 -0
- package/hono/src/framework/queue/queue.ts +342 -0
- package/hono/src/framework/queue/ui.ts +214 -0
- package/hono/src/framework/queue/worker.ts +61 -0
- package/hono/src/framework/realtime/broadcast.ts +46 -0
- package/hono/src/framework/realtime/index.ts +2 -0
- package/hono/src/framework/realtime/socket-cookie.ts +68 -0
- package/hono/src/framework/realtime/socket.ts +196 -0
- package/hono/src/framework/realtime/types.ts +6 -0
- package/hono/src/framework/realtime/ui.ts +16 -0
- package/hono/src/framework/redis/client.ts +151 -0
- package/hono/src/framework/runtime/runtime.ts +23 -0
- package/hono/src/framework/runtime/server-adapter.ts +94 -0
- package/hono/src/framework/scheduler/lock.ts +116 -0
- package/hono/src/framework/scheduler/run.ts +48 -0
- package/hono/src/framework/scheduler/scheduler.ts +155 -0
- package/hono/src/framework/server.ts +183 -0
- package/hono/src/framework/session/session.ts +116 -0
- package/hono/src/framework/storage/storage.ts +785 -0
- package/hono/src/framework/support/cookie.ts +99 -0
- package/hono/src/framework/support/jwt.ts +45 -0
- package/hono/src/framework/support/lifecycle.ts +35 -0
- package/hono/src/framework/support/logger.ts +148 -0
- package/hono/src/framework/support/mail.ts +48 -0
- package/hono/src/framework/support/password.ts +23 -0
- package/hono/src/framework/support/url.ts +41 -0
- package/hono/src/middlewares/auth-middleware.ts +98 -0
- package/hono/src/middlewares/role-middleware.ts +25 -0
- package/hono/src/modules/auth/controllers/auth.controller.ts +413 -0
- package/hono/src/modules/auth/controllers/auth.helpers.ts +128 -0
- package/hono/src/modules/auth/controllers/auth.schema.ts +102 -0
- package/hono/src/modules/auth/controllers/role.controller.ts +25 -0
- package/hono/src/modules/auth/database/models/notifications.ts +24 -0
- package/hono/src/modules/auth/database/models/role.ts +14 -0
- package/hono/src/modules/auth/database/models/user.ts +46 -0
- package/hono/src/modules/auth/database/seeders/role.ts +18 -0
- package/hono/src/modules/auth/database/seeders/user.ts +35 -0
- package/hono/src/modules/auth/jobs/forgetpass.ts +20 -0
- package/hono/src/modules/auth/jobs/registeruser.ts +23 -0
- package/hono/src/modules/auth/jobs/verifyemail.ts +18 -0
- package/hono/src/modules/auth/routes/api.ts +150 -0
- package/hono/src/modules/auth/routes/role.ts +33 -0
- package/hono/src/resources/index.html +17 -0
- package/hono/src/resources/src/App.vue +5 -0
- package/hono/src/resources/src/assets/css/styles.css +14913 -0
- package/hono/src/resources/src/assets/css/styles.css.map +1 -0
- package/hono/src/resources/src/assets/fonts/public-sans/public-sans-latin-ext.woff2 +0 -0
- package/hono/src/resources/src/assets/fonts/public-sans/public-sans-latin.woff2 +0 -0
- package/hono/src/resources/src/assets/images/favicon/favicon.ico +0 -0
- package/hono/src/resources/src/assets/images/logo.png +0 -0
- package/hono/src/resources/src/assets/scss/custom.css +217 -0
- package/hono/src/resources/src/assets/scss/custom.css.map +1 -0
- package/hono/src/resources/src/assets/scss/custom.scss +1346 -0
- package/hono/src/resources/src/components/Button.vue +32 -0
- package/hono/src/resources/src/components/Checkbox.vue +29 -0
- package/hono/src/resources/src/components/Datepicker.vue +106 -0
- package/hono/src/resources/src/components/FeatureButton.vue +53 -0
- package/hono/src/resources/src/components/FloatButton.vue +33 -0
- package/hono/src/resources/src/components/Href.vue +32 -0
- package/hono/src/resources/src/components/Input.vue +234 -0
- package/hono/src/resources/src/components/InputGroup.vue +149 -0
- package/hono/src/resources/src/components/InputPasswordToggle.vue +222 -0
- package/hono/src/resources/src/components/Modal.vue +55 -0
- package/hono/src/resources/src/components/Pagebar.vue +26 -0
- package/hono/src/resources/src/components/Select.vue +415 -0
- package/hono/src/resources/src/components/Spinner.vue +42 -0
- package/hono/src/resources/src/components/Switch.vue +65 -0
- package/hono/src/resources/src/components/TextArea.vue +121 -0
- package/hono/src/resources/src/components/Toast.vue +56 -0
- package/hono/src/resources/src/components/datatable/DataTableSkeleton.vue +98 -0
- package/hono/src/resources/src/components/datatable/Pagination.vue +147 -0
- package/hono/src/resources/src/components/datatable/SelectOpption.vue +64 -0
- package/hono/src/resources/src/components/datatable/index.vue +199 -0
- package/hono/src/resources/src/composables/useAuth.ts +52 -0
- package/hono/src/resources/src/helpers/nformatter.ts +10 -0
- package/hono/src/resources/src/helpers/utils.ts +75 -0
- package/hono/src/resources/src/layouts/AuthLayout.vue +20 -0
- package/hono/src/resources/src/layouts/Layout/Footer.vue +23 -0
- package/hono/src/resources/src/layouts/Layout/Header.vue +105 -0
- package/hono/src/resources/src/layouts/Layout/Sidebar.vue +137 -0
- package/hono/src/resources/src/layouts/Layout/index.vue +87 -0
- package/hono/src/resources/src/main.ts +26 -0
- package/hono/src/resources/src/pages/auth/forgetPassword.vue +82 -0
- package/hono/src/resources/src/pages/auth/login.vue +99 -0
- package/hono/src/resources/src/pages/auth/register.vue +133 -0
- package/hono/src/resources/src/pages/auth/resetPassword.vue +118 -0
- package/hono/src/resources/src/pages/auth/verifyEmail.vue +68 -0
- package/hono/src/resources/src/pages/dashboard/index.vue +66 -0
- package/hono/src/resources/src/plugins/axios.ts +31 -0
- package/hono/src/resources/src/plugins/browserDetect.ts +55 -0
- package/hono/src/resources/src/plugins/dialog.ts +216 -0
- package/hono/src/resources/src/plugins/gum.ts +367 -0
- package/hono/src/resources/src/plugins/pulse.ts +147 -0
- package/hono/src/resources/src/plugins/routeProgress.ts +87 -0
- package/hono/src/resources/src/router/index.ts +85 -0
- package/hono/src/resources/src/stores/admin-ui.ts +148 -0
- package/hono/src/resources/src/stores/auth.ts +164 -0
- package/hono/src/resources/tsconfig.json +19 -0
- package/hono/src/resources/vite.config.ts +46 -0
- package/hono/src/storage/app/private/.gitkeep +0 -0
- package/hono/src/storage/app/public/.gitkeep +0 -0
- package/hono/src/storage/app/tmp/generated/.gitkeep +0 -0
- package/hono/src/storage/database/nexwire.sqlite +0 -0
- package/hono/src/storage/logs/.gitkeep +0 -0
- package/hono/src/storage/tmp/.gitkeep +0 -0
- package/hono/src/storage/trash/modules/.gitkeep +0 -0
- package/hono/src/types/global.d.ts +26 -0
- package/hono/tsconfig.json +20 -0
- package/hono/vitest.config.ts +23 -0
- package/package.json +238 -0
- package/src/index.js +204 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { signedCookie } from "cookie-parser";
|
|
2
|
+
import type { Socket } from "socket.io";
|
|
3
|
+
import { cookieConfig } from "@/config/index.js";
|
|
4
|
+
import type { RealtimeAuthContext } from "@/framework/realtime/types.js";
|
|
5
|
+
import { jwt } from "@/framework/support/jwt.js";
|
|
6
|
+
|
|
7
|
+
export function unauthenticatedRealtimeAuth(): RealtimeAuthContext {
|
|
8
|
+
return { isAuthenticated: false, userId: null, roles: [], payload: null };
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function parseCookieHeader(header: string | undefined) {
|
|
12
|
+
if (!header) return {} as Record<string, string>;
|
|
13
|
+
|
|
14
|
+
const cookies: Record<string, string> = {};
|
|
15
|
+
for (const part of header.split(";")) {
|
|
16
|
+
const [rawName, ...rawValue] = part.trim().split("=");
|
|
17
|
+
if (!rawName || rawValue.length === 0) continue;
|
|
18
|
+
cookies[rawName] = decodeURIComponent(rawValue.join("="));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return cookies;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function userIdFromPayload(payload: Record<string, unknown>) {
|
|
25
|
+
const candidate = payload.userId ?? payload.id ?? payload.sub;
|
|
26
|
+
if (candidate === null || candidate === undefined) return null;
|
|
27
|
+
return String(candidate);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function rolesFromPayload(payload: Record<string, unknown>) {
|
|
31
|
+
const direct = payload.roles;
|
|
32
|
+
if (Array.isArray(direct)) return direct.map((role) => String(role));
|
|
33
|
+
|
|
34
|
+
const single = payload.role;
|
|
35
|
+
if (single === null || single === undefined) return [];
|
|
36
|
+
return [String(single)];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Why: Resolves auth context for websocket connections from cookies.
|
|
41
|
+
* When: Socket.IO handshake middleware executes.
|
|
42
|
+
* Where: Realtime server auth pipeline.
|
|
43
|
+
* How: Parses access cookie, verifies JWT, then normalizes user/role claims.
|
|
44
|
+
*/
|
|
45
|
+
export async function authFromSocketHandshake(socket: Socket): Promise<RealtimeAuthContext> {
|
|
46
|
+
const cookies = parseCookieHeader(socket.handshake.headers.cookie);
|
|
47
|
+
const rawToken = cookies[`${cookieConfig.name}_access`];
|
|
48
|
+
|
|
49
|
+
if (!rawToken) {
|
|
50
|
+
return unauthenticatedRealtimeAuth();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const token = signedCookie(rawToken, cookieConfig.secret);
|
|
54
|
+
if (!token) {
|
|
55
|
+
return unauthenticatedRealtimeAuth();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const payload = await jwt.verifyToken(token, "access");
|
|
59
|
+
if (!payload) {
|
|
60
|
+
return unauthenticatedRealtimeAuth();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const normalizedPayload = payload as Record<string, unknown>;
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
isAuthenticated: true,
|
|
67
|
+
userId: userIdFromPayload(normalizedPayload),
|
|
68
|
+
roles: rolesFromPayload(normalizedPayload),
|
|
69
|
+
payload: normalizedPayload
|
|
70
|
+
};
|
|
71
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { createAdapter } from "@socket.io/redis-adapter";
|
|
2
|
+
import { Server as SocketIOServer } from "socket.io";
|
|
3
|
+
import { appConfig, realtimeConfig, redisConfig } from "@/config/index.js";
|
|
4
|
+
import { authFromSocketHandshake, unauthenticatedRealtimeAuth } from "@/framework/realtime/socket-cookie.js";
|
|
5
|
+
import type { RealtimeAuthContext } from "@/framework/realtime/types.js";
|
|
6
|
+
import { redisClientIfReady } from "@/framework/redis/client.js";
|
|
7
|
+
import { logger } from "@/framework/support/logger.js";
|
|
8
|
+
|
|
9
|
+
export type RealtimeServeWebSocket = Record<string, never>;
|
|
10
|
+
|
|
11
|
+
export type RealtimeInit = {
|
|
12
|
+
io: SocketIOServer;
|
|
13
|
+
websocketServe: RealtimeServeWebSocket;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const WS_PATH = "/socket.io";
|
|
17
|
+
|
|
18
|
+
let io: SocketIOServer | null = null;
|
|
19
|
+
let adapterSubClient: ReturnType<typeof redisClientIfReady> | null = null;
|
|
20
|
+
|
|
21
|
+
function socketAllowedOrigins() {
|
|
22
|
+
const origins = [appConfig.url, appConfig.frontendUrl].filter(Boolean) as string[];
|
|
23
|
+
if (realtimeConfig.enabled) origins.push("https://admin.socket.io");
|
|
24
|
+
return [...new Set(origins)];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function attachRedisAdapter() {
|
|
28
|
+
if (!redisConfig.enabled) return;
|
|
29
|
+
|
|
30
|
+
const pubClient = redisClientIfReady();
|
|
31
|
+
if (!pubClient) return;
|
|
32
|
+
|
|
33
|
+
adapterSubClient = pubClient.duplicate();
|
|
34
|
+
await adapterSubClient.connect();
|
|
35
|
+
io?.adapter(createAdapter(pubClient, adapterSubClient));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function registerAuthAndRooms() {
|
|
39
|
+
io?.use(async (socket, next) => {
|
|
40
|
+
const auth = await authFromSocketHandshake(socket);
|
|
41
|
+
socket.data.auth = auth as RealtimeAuthContext;
|
|
42
|
+
|
|
43
|
+
if (auth.isAuthenticated) {
|
|
44
|
+
socket.join("auth");
|
|
45
|
+
if (auth.userId) socket.join(`user:${auth.userId}`);
|
|
46
|
+
for (const role of auth.roles) socket.join(`role:${role}`);
|
|
47
|
+
} else {
|
|
48
|
+
socket.join("guest");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
next();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
io?.on("connection", (socket) => {
|
|
55
|
+
const auth = (socket.data.auth || unauthenticatedRealtimeAuth()) as RealtimeAuthContext;
|
|
56
|
+
|
|
57
|
+
logger.debug("Socket connected", {
|
|
58
|
+
socketId: socket.id,
|
|
59
|
+
authenticated: auth.isAuthenticated,
|
|
60
|
+
userId: auth.userId
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
socket.on("join", (room) => socket.join(String(room)));
|
|
64
|
+
socket.on("disconnect", (reason) => {
|
|
65
|
+
logger.info("Socket disconnected", {
|
|
66
|
+
socketId: socket.id,
|
|
67
|
+
reason,
|
|
68
|
+
authenticated: auth.isAuthenticated,
|
|
69
|
+
userId: auth.userId
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export async function initRealtime(target: { httpServer: any }): Promise<RealtimeInit | null> {
|
|
76
|
+
if (!realtimeConfig.enabled) {
|
|
77
|
+
logger.info("Socket.IO disabled (disabled in config)");
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (io) return { io, websocketServe: {} };
|
|
82
|
+
|
|
83
|
+
io = new SocketIOServer(target.httpServer, {
|
|
84
|
+
cors: { origin: socketAllowedOrigins(), credentials: true }
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
await attachRedisAdapter();
|
|
88
|
+
registerAuthAndRooms();
|
|
89
|
+
|
|
90
|
+
logger.info(`Socket.IO enabled at ${WS_PATH}`);
|
|
91
|
+
return { io, websocketServe: {} };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function socketServer() {
|
|
95
|
+
return io;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function ioServer() {
|
|
99
|
+
return io;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export async function closeRealtime() {
|
|
103
|
+
if (!io) return;
|
|
104
|
+
|
|
105
|
+
await new Promise<void>((resolve) => {
|
|
106
|
+
io?.close(() => resolve());
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
if (adapterSubClient) {
|
|
110
|
+
try {
|
|
111
|
+
await adapterSubClient.quit();
|
|
112
|
+
} catch {
|
|
113
|
+
adapterSubClient.disconnect();
|
|
114
|
+
}
|
|
115
|
+
adapterSubClient = null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
io = null;
|
|
119
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { instrument } from "@socket.io/admin-ui";
|
|
2
|
+
import type { Server as SocketIOServer } from "socket.io";
|
|
3
|
+
import { appConfig, realtimeConfig } from "@/config/index.js";
|
|
4
|
+
|
|
5
|
+
export function setupSocketAdminUI(io: SocketIOServer | null) {
|
|
6
|
+
if (!io || !realtimeConfig.enabled || appConfig.environment === "production") {
|
|
7
|
+
return { enabled: false };
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
instrument(io, {
|
|
11
|
+
auth: false,
|
|
12
|
+
mode: "development"
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
return { enabled: true };
|
|
16
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { Redis } from "ioredis";
|
|
2
|
+
import { redisConfig } from "@/config/index.js";
|
|
3
|
+
import { CircuitBreaker } from "@/framework/circuit-breaker/cb.js";
|
|
4
|
+
import { logger } from "@/framework/support/logger.js";
|
|
5
|
+
|
|
6
|
+
export type redis = Redis;
|
|
7
|
+
|
|
8
|
+
let client: redis | null = null;
|
|
9
|
+
let ready = false;
|
|
10
|
+
let lastError: string | null = null;
|
|
11
|
+
let redisBreaker: CircuitBreaker | null = null;
|
|
12
|
+
|
|
13
|
+
if (redisConfig.enabled) {
|
|
14
|
+
redisBreaker = new CircuitBreaker();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function safeRedisUrl() {
|
|
18
|
+
try {
|
|
19
|
+
const url = new URL(redisConfig.url);
|
|
20
|
+
if (url.password) url.password = "***";
|
|
21
|
+
return url.toString();
|
|
22
|
+
} catch {
|
|
23
|
+
return redisConfig.url;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Why: Initializes shared Redis connection for cache/queue/events/session.
|
|
29
|
+
* When: Runtime bootstrap before Redis-backed features are used.
|
|
30
|
+
* Where: Server, worker, scheduler startup paths.
|
|
31
|
+
* How: Connects once, tracks readiness, and degrades gracefully if unavailable.
|
|
32
|
+
*/
|
|
33
|
+
export async function initRedis() {
|
|
34
|
+
if (client) return client;
|
|
35
|
+
|
|
36
|
+
if (!redisConfig.enabled) {
|
|
37
|
+
ready = false;
|
|
38
|
+
lastError = "redis disabled in config";
|
|
39
|
+
logger.info("Redis disabled; cache, session storage, queue, events, and cockpit unavailable");
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (redisBreaker?.getState() === "open") {
|
|
44
|
+
lastError = "redis circuit breaker is open";
|
|
45
|
+
logger.warn("Redis circuit breaker is open; skipping connection");
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
client = new Redis(redisConfig.url, {
|
|
51
|
+
lazyConnect: true,
|
|
52
|
+
enableReadyCheck: true,
|
|
53
|
+
maxRetriesPerRequest: 0,
|
|
54
|
+
retryStrategy: () => null
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
client.on("error", (error) => {
|
|
58
|
+
lastError = error.message;
|
|
59
|
+
if (ready) {
|
|
60
|
+
logger.warn("Redis connection error", {
|
|
61
|
+
redisUrl: safeRedisUrl(),
|
|
62
|
+
error: error.message
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
await client.connect();
|
|
68
|
+
await client.ping();
|
|
69
|
+
ready = true;
|
|
70
|
+
redisBreaker?.onSuccess();
|
|
71
|
+
return client;
|
|
72
|
+
} catch (error) {
|
|
73
|
+
lastError ||= error instanceof Error ? error.message : String(error);
|
|
74
|
+
client?.disconnect();
|
|
75
|
+
client = null;
|
|
76
|
+
ready = false;
|
|
77
|
+
redisBreaker?.onFailure();
|
|
78
|
+
logger.warn(`Redis unavailable; continuing without Redis features (${lastError})`);
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Why: Returns the current Redis client instance.
|
|
85
|
+
* When: Internal helpers need direct Redis operations.
|
|
86
|
+
* Where: Cache/session/queue/events modules.
|
|
87
|
+
* How: Returns nullable singleton without creating a new connection.
|
|
88
|
+
*/
|
|
89
|
+
export function redis() {
|
|
90
|
+
return client;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Why: Indicates whether Redis is connected and usable.
|
|
95
|
+
* When: Features need to branch on Redis availability.
|
|
96
|
+
* Where: Cache/session/queue/event internals.
|
|
97
|
+
* How: Combines readiness flag with client presence.
|
|
98
|
+
*/
|
|
99
|
+
export function redisReady() {
|
|
100
|
+
return ready && client !== null;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Why: Provides a single ready-checked Redis client accessor.
|
|
105
|
+
* When: Redis-backed modules need quick availability guard.
|
|
106
|
+
* Where: Cache/session/queue/events/BullBoard internals.
|
|
107
|
+
* How: Returns connected client or null when Redis is unavailable.
|
|
108
|
+
*/
|
|
109
|
+
export function redisClientIfReady() {
|
|
110
|
+
if (redisBreaker?.getState() === "open") return null;
|
|
111
|
+
return redisReady() ? client : null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Why: Exposes last Redis error for diagnostics.
|
|
116
|
+
* When: Startup or health logs need failure detail.
|
|
117
|
+
* Where: Runtime status output.
|
|
118
|
+
* How: Returns cached error message string.
|
|
119
|
+
*/
|
|
120
|
+
export function redisError() {
|
|
121
|
+
return lastError;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Why: Returns the Redis circuit breaker instance or null when disabled.
|
|
126
|
+
* When: Health checks and diagnostics need breaker state.
|
|
127
|
+
* Where: Runtime status and monitoring paths.
|
|
128
|
+
* How: Returns the breaker if Redis is enabled, null otherwise.
|
|
129
|
+
*/
|
|
130
|
+
export function getRedisBreaker() {
|
|
131
|
+
return redisBreaker;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Why: Closes Redis connection during graceful shutdown.
|
|
136
|
+
* When: Process stop hooks for server/worker/scheduler.
|
|
137
|
+
* Where: Runtime lifecycle files.
|
|
138
|
+
* How: Attempts quit, falls back to disconnect, then resets state.
|
|
139
|
+
*/
|
|
140
|
+
export async function closeRedis() {
|
|
141
|
+
if (!client) return;
|
|
142
|
+
|
|
143
|
+
try {
|
|
144
|
+
await client.quit();
|
|
145
|
+
} catch {
|
|
146
|
+
client.disconnect();
|
|
147
|
+
} finally {
|
|
148
|
+
client = null;
|
|
149
|
+
ready = false;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type Runtime = "node" | "bun" | "unknown";
|
|
2
|
+
|
|
3
|
+
const runtimeGlobals = globalThis as Record<string, unknown>;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Why: Select the correct driver/flavor when a runtime has specialized packages.
|
|
7
|
+
* When: Loading DB clients, web servers, and queues that vary per runtime.
|
|
8
|
+
* Where: Framework bootstrap and driver resolution layers.
|
|
9
|
+
* How: Inspects global runtime markers (Bun) and falls back to Node/unknown.
|
|
10
|
+
*/
|
|
11
|
+
export function runtime(): Runtime {
|
|
12
|
+
if (runtimeGlobals.Bun !== undefined) return "bun";
|
|
13
|
+
if (typeof process !== "undefined" && process.versions?.node) return "node";
|
|
14
|
+
return "unknown";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function isBun(): boolean {
|
|
18
|
+
return runtime() === "bun";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function isNode(): boolean {
|
|
22
|
+
return runtime() === "node";
|
|
23
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { AddressInfo } from "node:net";
|
|
2
|
+
import type { Express } from "express";
|
|
3
|
+
import type { RealtimeServeWebSocket } from "@/framework/realtime/socket.js";
|
|
4
|
+
import { runtime } from "@/framework/runtime/runtime.js";
|
|
5
|
+
|
|
6
|
+
export type HttpServerHandle = {
|
|
7
|
+
address(): string | AddressInfo | null;
|
|
8
|
+
close(): Promise<void>;
|
|
9
|
+
native: unknown;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
async function startNode(app: Express, port: number, _websocket?: RealtimeServeWebSocket): Promise<HttpServerHandle> {
|
|
13
|
+
const { createServer } = await import("node:http");
|
|
14
|
+
|
|
15
|
+
const server = createServer(app);
|
|
16
|
+
await new Promise<void>((resolve) => server.listen(port, resolve));
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
native: server,
|
|
20
|
+
address: () => server.address(),
|
|
21
|
+
close: () => new Promise<void>((resolve) => server.close(() => resolve()))
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function startBun(app: Express, port: number, _websocket?: RealtimeServeWebSocket): Promise<HttpServerHandle> {
|
|
26
|
+
const server = await startNode(app, port);
|
|
27
|
+
return server;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function startHttpServer(app: Express, port: number, websocket?: RealtimeServeWebSocket): Promise<HttpServerHandle> {
|
|
31
|
+
const activeRuntime = runtime();
|
|
32
|
+
if (activeRuntime === "bun") return startBun(app, port, websocket);
|
|
33
|
+
return startNode(app, port, websocket);
|
|
34
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { redisConfig } from "@/config/index.js";
|
|
3
|
+
import { databaseDialect, databasePool } from "@/framework/database/connection.js";
|
|
4
|
+
import { redis, redisReady } from "@/framework/redis/client.js";
|
|
5
|
+
|
|
6
|
+
type LockOptions = { ttlMs?: number; tableName?: string };
|
|
7
|
+
|
|
8
|
+
function table(name?: string) {
|
|
9
|
+
return name || "scheduler_locks";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async function ensureTable(tableName?: string) {
|
|
13
|
+
const pool = databasePool();
|
|
14
|
+
const dialect = databaseDialect();
|
|
15
|
+
const lockTable = table(tableName);
|
|
16
|
+
|
|
17
|
+
if (dialect === "mysql") {
|
|
18
|
+
await pool.query(
|
|
19
|
+
`CREATE TABLE IF NOT EXISTS \`${lockTable}\` (name VARCHAR(191) PRIMARY KEY, owner VARCHAR(191) NOT NULL, expires_at BIGINT NOT NULL)`
|
|
20
|
+
);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (dialect === "postgresql") {
|
|
25
|
+
await pool.unsafe(
|
|
26
|
+
`CREATE TABLE IF NOT EXISTS "${lockTable}" (name VARCHAR(191) PRIMARY KEY, owner VARCHAR(191) NOT NULL, expires_at BIGINT NOT NULL)`
|
|
27
|
+
);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
await pool.execute(`CREATE TABLE IF NOT EXISTS "${lockTable}" (name TEXT PRIMARY KEY, owner TEXT NOT NULL, expires_at INTEGER NOT NULL)`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function acquireDbLock(name: string, owner: string, ttlMs: number, tableName?: string) {
|
|
35
|
+
await ensureTable(tableName);
|
|
36
|
+
const pool = databasePool();
|
|
37
|
+
const dialect = databaseDialect();
|
|
38
|
+
const lockTable = table(tableName);
|
|
39
|
+
const now = Date.now();
|
|
40
|
+
const expiresAt = now + ttlMs;
|
|
41
|
+
|
|
42
|
+
if (dialect === "postgresql") {
|
|
43
|
+
const rows = await pool.unsafe(
|
|
44
|
+
`INSERT INTO "${lockTable}" (name, owner, expires_at) VALUES ($1, $2, $3) ON CONFLICT (name) DO UPDATE SET owner = EXCLUDED.owner, expires_at = EXCLUDED.expires_at WHERE "${lockTable}".expires_at < $4 RETURNING owner`,
|
|
45
|
+
[name, owner, expiresAt, now]
|
|
46
|
+
);
|
|
47
|
+
return rows?.[0]?.owner === owner;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (dialect === "mysql") {
|
|
51
|
+
await pool.query(
|
|
52
|
+
`INSERT INTO \`${lockTable}\` (name, owner, expires_at) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE owner = IF(expires_at < ?, VALUES(owner), owner), expires_at = IF(expires_at < ?, VALUES(expires_at), expires_at)`,
|
|
53
|
+
[name, owner, expiresAt, now, now]
|
|
54
|
+
);
|
|
55
|
+
const [rows] = await pool.query(`SELECT owner FROM \`${lockTable}\` WHERE name = ?`, [name]);
|
|
56
|
+
return rows?.[0]?.owner === owner;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
await pool.execute({
|
|
60
|
+
sql: `INSERT INTO "${lockTable}" (name, owner, expires_at) VALUES (?, ?, ?) ON CONFLICT(name) DO UPDATE SET owner = excluded.owner, expires_at = excluded.expires_at WHERE "${lockTable}".expires_at < ?`,
|
|
61
|
+
args: [name, owner, expiresAt, now]
|
|
62
|
+
});
|
|
63
|
+
const result = await pool.execute({
|
|
64
|
+
sql: `SELECT owner FROM "${lockTable}" WHERE name = ?`,
|
|
65
|
+
args: [name]
|
|
66
|
+
});
|
|
67
|
+
return result.rows?.[0]?.owner === owner;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function releaseDbLock(name: string, owner: string, tableName?: string) {
|
|
71
|
+
const pool = databasePool();
|
|
72
|
+
const dialect = databaseDialect();
|
|
73
|
+
const lockTable = table(tableName);
|
|
74
|
+
|
|
75
|
+
if (dialect === "postgresql") return await pool.unsafe(`DELETE FROM "${lockTable}" WHERE name = $1 AND owner = $2`, [name, owner]);
|
|
76
|
+
if (dialect === "mysql") return await pool.query(`DELETE FROM \`${lockTable}\` WHERE name = ? AND owner = ?`, [name, owner]);
|
|
77
|
+
await pool.execute({
|
|
78
|
+
sql: `DELETE FROM "${lockTable}" WHERE name = ? AND owner = ?`,
|
|
79
|
+
args: [name, owner]
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Why: Runs a handler with distributed lock to prevent duplicate execution.
|
|
85
|
+
* When: Scheduled tasks may run across multiple processes/instances.
|
|
86
|
+
* Where: Scheduler runtime around each cron job.
|
|
87
|
+
* How: Uses Redis NX lock when available, otherwise falls back to DB lock table.
|
|
88
|
+
*/
|
|
89
|
+
export async function runWithLock<T>(name: string, handler: () => Promise<T>, options: LockOptions = {}) {
|
|
90
|
+
const owner = randomUUID();
|
|
91
|
+
const ttlMs = options.ttlMs || 60_000;
|
|
92
|
+
const client = redis();
|
|
93
|
+
|
|
94
|
+
if (redisReady() && client) {
|
|
95
|
+
const key = `${redisConfig.prefix}:lock:${name}`;
|
|
96
|
+
const ok = await client.set(key, owner, "PX", ttlMs, "NX");
|
|
97
|
+
if (!ok) return { ran: false, backend: "redis" as const };
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
const result = await handler();
|
|
101
|
+
return { ran: true, backend: "redis" as const, result };
|
|
102
|
+
} finally {
|
|
103
|
+
await client.del(key);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const ok = await acquireDbLock(name, owner, ttlMs, options.tableName);
|
|
108
|
+
if (!ok) return { ran: false, backend: "db" as const };
|
|
109
|
+
|
|
110
|
+
try {
|
|
111
|
+
const result = await handler();
|
|
112
|
+
return { ran: true, backend: "db" as const, result };
|
|
113
|
+
} finally {
|
|
114
|
+
await releaseDbLock(name, owner, options.tableName);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { initDatabase } from "@/framework/database/connection.js";
|
|
2
|
+
import { bootQueueJobs, stopQueueRuntime } from "@/framework/queue/queue.js";
|
|
3
|
+
import { closeRedis, initRedis } from "@/framework/redis/client.js";
|
|
4
|
+
import { startScheduler, stopScheduler } from "@/framework/scheduler/scheduler.js";
|
|
5
|
+
import { registerShutdownSignals, type ShutdownSignal } from "@/framework/support/lifecycle.js";
|
|
6
|
+
import { logger } from "@/framework/support/logger.js";
|
|
7
|
+
|
|
8
|
+
export interface SchedulerHandle {
|
|
9
|
+
count: number;
|
|
10
|
+
shutdown: (signal: ShutdownSignal) => Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Why: Starts the scheduler and wires DB/Redis/queue shutdown.
|
|
15
|
+
* When: CLI `schedule:work` command or E2E test bootstrap.
|
|
16
|
+
* Where: Scheduler entrypoint.
|
|
17
|
+
* How: Inits DB/Redis, boots queue jobs, starts scheduler, registers signals.
|
|
18
|
+
* When called as the main module, also prints the startup banner.
|
|
19
|
+
*/
|
|
20
|
+
export async function startSchedulerRuntime(): Promise<SchedulerHandle> {
|
|
21
|
+
await initDatabase();
|
|
22
|
+
await initRedis();
|
|
23
|
+
await bootQueueJobs();
|
|
24
|
+
const count = await startScheduler();
|
|
25
|
+
console.log(`Scheduler started [${count} schedule(s)]`);
|
|
26
|
+
|
|
27
|
+
let shuttingDown = false;
|
|
28
|
+
|
|
29
|
+
async function shutdown(signal: ShutdownSignal) {
|
|
30
|
+
if (shuttingDown) return;
|
|
31
|
+
shuttingDown = true;
|
|
32
|
+
|
|
33
|
+
logger.info("Scheduler shutdown signal received", { signal });
|
|
34
|
+
await Promise.allSettled([Promise.resolve(stopScheduler()), stopQueueRuntime()]);
|
|
35
|
+
await closeRedis();
|
|
36
|
+
|
|
37
|
+
process.exit(0);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
registerShutdownSignals(shutdown);
|
|
41
|
+
|
|
42
|
+
return { count, shutdown };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const isMain = process.argv[1]?.endsWith("run.ts") || process.argv[1]?.endsWith("run.js");
|
|
46
|
+
if (isMain) {
|
|
47
|
+
await startSchedulerRuntime();
|
|
48
|
+
}
|