@starci/hfs 4.0.8 → 4.0.9
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/CHANGELOG.md +9 -0
- package/README.md +81 -39
- package/emit/contracts.mjs +56 -9
- package/emit/db-types.mjs +169 -0
- package/emit/events.mjs +41 -0
- package/emit/operations-worker.mjs +1 -1
- package/emit/operations.mjs +2 -2
- package/emit/schema-worker.mjs +1 -1
- package/lint/bound-sys.cjs +50 -0
- package/lint/run.mjs +53 -19
- package/package.json +14 -9
- package/report/sonar.mjs +8 -8
- package/runtime/engine/config.mjs +494 -0
- package/runtime/engine/invalid-config.mjs +15 -0
- package/runtime/engine/orca-config.mjs +27 -0
- package/runtime/knowledge/hfs/canon-pins.yaml +160 -29
- package/runtime/knowledge/hfs/peer-integrations.yaml +2 -2
- package/runtime/knowledge/hfs/rules.yaml +2059 -0
- package/runtime/knowledge/hfs/slots.yaml +912 -120
- package/runtime/knowledge/patterns/be/api.yaml +369 -0
- package/runtime/knowledge/patterns/be/cli.yaml +297 -0
- package/runtime/knowledge/patterns/be/domain.yaml +113 -0
- package/runtime/knowledge/patterns/be/event-bus.yaml +285 -0
- package/runtime/knowledge/patterns/be/jobs.yaml +261 -0
- package/runtime/knowledge/patterns/be/projections.yaml +178 -0
- package/runtime/knowledge/patterns/be/queues.yaml +236 -0
- package/runtime/knowledge/patterns/be/reactors.yaml +140 -0
- package/runtime/knowledge/patterns/be/realtime.yaml +222 -0
- package/runtime/knowledge/patterns/be/saga.yaml +248 -0
- package/runtime/knowledge/patterns/be/webhooks.yaml +221 -0
- package/runtime/knowledge/patterns/fe/folder.yaml +131 -25
- package/runtime/knowledge/sonar-gate.yaml +52 -18
- package/runtime/modules/kernel/failure-codes.yaml +571 -51
- package/runtime/modules/models/registry.yaml +591 -0
- package/runtime/modules/models/runtimes.yaml +701 -0
- package/runtime/scripts/api/fs/forbidden-root.mjs +51 -0
- package/runtime/scripts/api/fs/is-link-like.mjs +25 -0
- package/runtime/scripts/api/fs/lib.mjs +10 -2
- package/runtime/scripts/api/fs/safe-remove.mjs +12 -132
- package/runtime/scripts/api/git/config-get.mjs +10 -0
- package/runtime/scripts/api/git/diff.mjs +5 -0
- package/runtime/scripts/api/git/lib.mjs +16 -26
- package/runtime/scripts/api/git/log.mjs +5 -0
- package/runtime/scripts/api/git/ls-files.mjs +6 -0
- package/runtime/scripts/api/git/ls-tree.mjs +5 -0
- package/runtime/scripts/api/git/merge-base.mjs +9 -0
- package/runtime/scripts/api/git/remote.mjs +5 -0
- package/runtime/scripts/api/git/rev-parse-query.mjs +5 -0
- package/runtime/scripts/api/git/show.mjs +6 -0
- package/runtime/scripts/api/sops/decrypt.mjs +9 -5
- package/runtime/scripts/api/sops/lib.mjs +35 -0
- package/runtime/scripts/api/sops/seal.mjs +18 -0
- package/runtime/scripts/hfs/architecture/ast-walks.mjs +220 -0
- package/runtime/scripts/hfs/architecture/backend.mjs +16 -23
- package/runtime/scripts/hfs/architecture/background-unowned.mjs +16 -34
- package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +3 -1
- package/runtime/scripts/hfs/architecture/clones.mjs +4 -4
- package/runtime/scripts/hfs/architecture/config.mjs +9 -6
- package/runtime/scripts/hfs/architecture/connection-map.mjs +20 -8
- package/runtime/scripts/hfs/architecture/context-coupling.mjs +88 -0
- package/runtime/scripts/hfs/architecture/context-map.mjs +237 -0
- package/runtime/scripts/hfs/architecture/context-owner.mjs +82 -0
- package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +47 -0
- package/runtime/scripts/hfs/architecture/context-transaction.mjs +60 -0
- package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +4 -10
- package/runtime/scripts/hfs/architecture/contracts.mjs +33 -162
- package/runtime/scripts/hfs/architecture/dead-exports.mjs +58 -29
- package/runtime/scripts/hfs/architecture/doc-language.mjs +1 -1
- package/runtime/scripts/hfs/architecture/entrypoint.mjs +2 -1
- package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +1 -1
- package/runtime/scripts/hfs/architecture/feature-shape.mjs +5 -2
- package/runtime/scripts/hfs/architecture/framework-pinned.mjs +1 -1
- package/runtime/scripts/hfs/architecture/frontend.mjs +17 -43
- package/runtime/scripts/hfs/architecture/hfs.mjs +24 -39
- package/runtime/scripts/hfs/architecture/i18n-keys.mjs +1 -1
- package/runtime/scripts/hfs/architecture/index.mjs +17 -4
- package/runtime/scripts/hfs/architecture/machine-ast.mjs +44 -11
- package/runtime/scripts/hfs/architecture/managed-scripts.mjs +27 -0
- package/runtime/scripts/hfs/architecture/module-per-transport.mjs +30 -6
- package/runtime/scripts/hfs/architecture/next-data.mjs +22 -63
- package/runtime/scripts/hfs/architecture/owners.mjs +35 -15
- package/runtime/scripts/hfs/architecture/register-once.mjs +2 -1
- package/runtime/scripts/hfs/architecture/registration.mjs +23 -81
- package/runtime/scripts/hfs/architecture/required-files.mjs +20 -12
- package/runtime/scripts/hfs/architecture/schema-owner.mjs +17 -114
- package/runtime/scripts/hfs/architecture/server-action.mjs +24 -0
- package/runtime/scripts/hfs/architecture/side-boundary.mjs +16 -0
- package/runtime/scripts/hfs/architecture/source-names.mjs +27 -147
- package/runtime/scripts/hfs/architecture/sql-owner.mjs +59 -18
- package/runtime/scripts/hfs/architecture/sql-returning.mjs +64 -0
- package/runtime/scripts/hfs/architecture/supabase-ast.mjs +111 -0
- package/runtime/scripts/hfs/architecture/supabase-be.mjs +131 -0
- package/runtime/scripts/hfs/architecture/supabase-tables.mjs +42 -0
- package/runtime/scripts/hfs/architecture/supabase.mjs +434 -0
- package/runtime/scripts/hfs/architecture/surface.mjs +9 -3
- package/runtime/scripts/hfs/architecture/test-world-files.mjs +9 -19
- package/runtime/scripts/hfs/architecture/tiers.mjs +47 -5
- package/runtime/scripts/hfs/architecture/transport-owner.mjs +3 -3
- package/runtime/scripts/hfs/architecture/typescript.mjs +12 -26
- package/runtime/scripts/hfs/architecture.mjs +4 -4
- package/runtime/scripts/hfs/check.mjs +75 -72
- package/runtime/scripts/hfs/coverage-scope.mjs +162 -0
- package/runtime/scripts/hfs/declaration-shape.mjs +62 -0
- package/runtime/scripts/hfs/declaration-slots.mjs +75 -0
- package/runtime/scripts/hfs/edition-slots.mjs +66 -0
- package/runtime/scripts/hfs/manifest-shape.mjs +109 -32
- package/runtime/scripts/hfs/param-names.mjs +18 -0
- package/runtime/scripts/hfs/path-findings.mjs +1 -1
- package/runtime/scripts/hfs/repo-identity.mjs +9 -6
- package/runtime/scripts/hfs/rule-params-shape.mjs +50 -0
- package/runtime/scripts/hfs/rules/app-root.mjs +51 -0
- package/runtime/scripts/hfs/rules/cli.mjs +37 -0
- package/runtime/scripts/hfs/rules/contract-compat.mjs +71 -0
- package/runtime/scripts/hfs/rules/contract.mjs +10 -9
- package/runtime/scripts/hfs/rules/database-config.mjs +102 -0
- package/runtime/scripts/hfs/rules/database-constants.mjs +13 -0
- package/runtime/scripts/hfs/rules/database-migrations.mjs +111 -0
- package/runtime/scripts/hfs/rules/database-plpgsql.mjs +233 -0
- package/runtime/scripts/hfs/rules/database-sql.mjs +336 -0
- package/runtime/scripts/hfs/rules/database.mjs +68 -0
- package/runtime/scripts/hfs/rules/deps.mjs +1 -1
- package/runtime/scripts/hfs/rules/docker.mjs +259 -0
- package/runtime/scripts/hfs/rules/edition.mjs +111 -0
- package/runtime/scripts/hfs/rules/event-bus.mjs +153 -0
- package/runtime/scripts/hfs/rules/fe-contract-documents.mjs +1 -1
- package/runtime/scripts/hfs/rules/fe-no-tests.mjs +6 -5
- package/runtime/scripts/hfs/rules/frontend-tree.mjs +9 -9
- package/runtime/scripts/hfs/rules/integration-specs.mjs +3 -6
- package/runtime/scripts/hfs/rules/kinds.mjs +84 -0
- package/runtime/scripts/hfs/rules/lint-suppression.mjs +1 -1
- package/runtime/scripts/hfs/rules/monorepo.mjs +179 -0
- package/runtime/scripts/hfs/rules/peer-integrations.mjs +3 -3
- package/runtime/scripts/hfs/rules/pipeline.mjs +11 -21
- package/runtime/scripts/hfs/rules/proof-commands.mjs +2 -2
- package/runtime/scripts/hfs/rules/read.mjs +1 -1
- package/runtime/scripts/hfs/rules/repo-local-checks.mjs +2 -2
- package/runtime/scripts/hfs/rules/saga.mjs +170 -0
- package/runtime/scripts/hfs/rules/secrets.mjs +3 -3
- package/runtime/scripts/hfs/rules/services.mjs +220 -0
- package/runtime/scripts/hfs/rules/spec-placement.mjs +1 -1
- package/runtime/scripts/hfs/rules/stacks.mjs +3 -3
- package/runtime/scripts/hfs/rules/supabase-secrets.mjs +89 -0
- package/runtime/scripts/hfs/rules/test-topology.mjs +2 -2
- package/runtime/scripts/hfs/secret.mjs +175 -0
- package/runtime/scripts/hfs/slots.mjs +78 -108
- package/runtime/scripts/hfs/sql/pg-parse.mjs +46 -0
- package/runtime/scripts/hfs/test-world-slot.mjs +6 -0
- package/runtime/scripts/hfs/tree.mjs +5 -4
- package/runtime/scripts/hfs/typescript-programs.mjs +0 -5
- package/runtime/scripts/hfs/view.mjs +3 -2
- package/runtime/scripts/lib/dockerfile.mjs +124 -0
- package/runtime/scripts/lib/env.mjs +10 -0
- package/runtime/scripts/lib/event-contract.mjs +103 -0
- package/runtime/scripts/lib/git.mjs +36 -0
- package/runtime/scripts/lib/graphql-contract.mjs +1 -1
- package/runtime/scripts/lib/i18n.mjs +86 -0
- package/runtime/scripts/lib/json.mjs +13 -3
- package/runtime/scripts/lib/language.mjs +24 -5
- package/runtime/scripts/lib/list.mjs +20 -0
- package/runtime/scripts/lib/package-at.mjs +37 -0
- package/runtime/scripts/lib/path-key.mjs +57 -2
- package/runtime/scripts/lib/read-text.mjs +34 -0
- package/runtime/scripts/lib/regex.mjs +4 -0
- package/runtime/scripts/lib/same-text.mjs +5 -0
- package/runtime/scripts/lib/secret-patterns.mjs +4 -3
- package/runtime/scripts/lib/sleep-sync.mjs +2 -1
- package/runtime/scripts/lib/sops-envelope.mjs +58 -0
- package/runtime/scripts/lib/stack-services.mjs +7 -31
- package/runtime/scripts/lib/ts-ast.mjs +35 -0
- package/runtime/scripts/lib/walk.mjs +4 -3
- package/scaffold/add-app.mjs +174 -0
- package/scaffold/add-cli-lite.mjs +257 -0
- package/scaffold/add-inbox-lite.mjs +314 -0
- package/scaffold/add-table.mjs +344 -0
- package/scaffold/add.mjs +299 -0
- package/scaffold/app.mjs +358 -69
- package/scaffold/edition-gate.mjs +25 -0
- package/scaffold/image.mjs +19 -0
- package/scaffold/lite-exports.mjs +186 -0
- package/scaffold/service.mjs +32 -26
- package/scaffold/supabase-ports.mjs +26 -0
- package/src/main.mjs +327 -0
- package/sync/cli.mjs +6 -9
- package/sync/format.mjs +1 -1
- package/sync/hygiene.mjs +10 -10
- package/sync/index.mjs +167 -104
- package/sync/managed.mjs +19 -11
- package/sync/sonar-key.mjs +5 -0
- package/templates/app/ci-workflows/github/workflows/ci.yml +14 -14
- package/templates/app/ci-workflows/github/workflows/images.yml +37 -0
- package/templates/app/ci-workflows/sonar-steps.yml +9 -0
- package/templates/app/ci-workflows-lite/github/workflows/ci.yml +66 -0
- package/templates/app/ci-workflows-lite/github/workflows/db-deploy.yml +31 -0
- package/templates/app/ci-workflows-lite/github/workflows/images.yml +37 -0
- package/templates/app/codegen-lite/scripts/codegen.mjs +32 -0
- package/templates/app/docker-ignore/dockerignore +50 -0
- package/templates/app/gitignore-lite +35 -0
- package/templates/app/hooks/husky/pre-commit +3 -8
- package/templates/app/hooks/husky/pre-push +45 -6
- package/templates/app/package-scripts/core.json +8 -0
- package/templates/app/package-scripts/package.json +3 -10
- package/templates/app/package-scripts-lite/package.json +15 -0
- package/templates/app/quality-config/codecov.yml +15 -3
- package/templates/app/quality-config/sonar-base.properties +4 -0
- package/templates/app/quality-config/sonar-project.properties +1 -4
- package/templates/app/quality-config-lite/sonar-project.properties +5 -0
- package/templates/app/skeleton/.starcistacks/dev/seeds/primary-notes.sql +5 -0
- package/templates/app/skeleton/.starciwork/features/system-health/index.yaml +4 -0
- package/templates/app/skeleton/.starciwork/{features/index.yaml → index.yaml} +2 -2
- package/templates/app/skeleton/README.md +7 -5
- package/templates/app/skeleton-lite/.sops.yaml +3 -0
- package/templates/app/skeleton-lite/.starcistacks/dev/environment.json +5 -0
- package/templates/app/skeleton-lite/.starcistacks/dev/secrets/.gitkeep +1 -0
- package/templates/app/skeleton-lite/.starciwork/shell/index.yaml +55 -0
- package/templates/app/skeleton-lite/README.md +40 -0
- package/templates/app/skeleton-lite/supabase/config.toml +41 -0
- package/templates/app/skeleton-lite/supabase/migrations/__timestamp___baseline.sql +56 -0
- package/templates/app/skeleton-lite/supabase/seed.sql +0 -0
- package/templates/app/task-graph/turbo.json +23 -0
- package/templates/app/tool-config-lite/prettierignore +2 -0
- package/templates/app/tool-config-lite/prettierrc +1 -0
- package/templates/app/upgrade-full/.starcistacks/application-stacks.yaml +38 -0
- package/templates/app/upgrade-full/.starcistacks/dev/README.md +10 -0
- package/templates/app/upgrade-full/.starcistacks/dev/infra/compose/api.yaml +13 -0
- package/templates/app/upgrade-full/.starcistacks/dev/infra/compose/compose.yaml +3 -0
- package/templates/app/upgrade-full/.starcistacks/dev/infra/compose/postgres.yaml +12 -0
- package/templates/app/upgrade-full/.starcistacks/dev/infra/metadata.json +7 -0
- package/templates/be/common/main-listen.ts.partial +14 -0
- package/templates/be/common/sql-ident.ts.partial +7 -0
- package/templates/be/common/sql-tag.ts.partial +5 -0
- package/templates/be/image/api/Dockerfile +38 -0
- package/templates/be/image/cli/Dockerfile +38 -0
- package/templates/be/image/worker/Dockerfile +36 -0
- package/templates/be/inbox/database-client.ts.tpl +50 -0
- package/templates/be/inbox/index.ts.tpl +2 -0
- package/templates/be/inbox/migration.sql.tpl +29 -0
- package/templates/be/inbox/module-definition.ts.tpl +6 -0
- package/templates/be/inbox/module.ts.tpl +14 -0
- package/templates/be/inbox/options.ts.tpl +2 -0
- package/templates/be/inbox/service.ts.tpl +33 -0
- package/templates/be/inbox/sql.ts.tpl +16 -0
- package/templates/be/inbox/webhook-door.ts.tpl +36 -0
- package/templates/be/patterns/api/application.command.http.ts.tpl +10 -0
- package/templates/be/patterns/api/application.command.ts.tpl +10 -0
- package/templates/be/patterns/api/application.contracts.ts.tpl +11 -0
- package/templates/be/patterns/api/application.handler.http.ts.tpl +22 -0
- package/templates/be/patterns/api/application.handler.ts.tpl +22 -0
- package/templates/be/patterns/api/feature.index.http.ts.tpl +1 -0
- package/templates/be/patterns/api/feature.index.ts.tpl +1 -0
- package/templates/be/patterns/api/feature.module.ts.tpl +6 -0
- package/templates/be/patterns/api/graphql.input.ts.tpl +13 -0
- package/templates/be/patterns/api/graphql.mapper.ts.tpl +9 -0
- package/templates/be/patterns/api/graphql.module.ts.tpl +7 -0
- package/templates/be/patterns/api/graphql.resolver.ts.tpl +27 -0
- package/templates/be/patterns/api/graphql.type.ts.tpl +9 -0
- package/templates/be/patterns/api/http.controller.ts.tpl +27 -0
- package/templates/be/patterns/api/http.mapper.ts.tpl +9 -0
- package/templates/be/patterns/api/http.module.ts.tpl +7 -0
- package/templates/be/patterns/api/http.request.ts.tpl +10 -0
- package/templates/be/patterns/api/http.response.ts.tpl +5 -0
- package/templates/be/patterns/cli/group.cli.spec.ts.tpl +15 -0
- package/templates/be/patterns/cli/group.cli.ts.tpl +11 -0
- package/templates/be/patterns/cli/group.module.ts.tpl +7 -0
- package/templates/be/patterns/cli/sub.run.cli.spec.ts.tpl +17 -0
- package/templates/be/patterns/cli/sub.run.cli.ts.tpl +15 -0
- package/templates/be/patterns/event-bus/platform/errors/event-bus.error.ts.tpl +22 -0
- package/templates/be/patterns/event-bus/platform/event-bus.config.ts.tpl +19 -0
- package/templates/be/patterns/event-bus/platform/event-bus.contracts.ts.tpl +58 -0
- package/templates/be/patterns/event-bus/platform/event-bus.decorators.ts.tpl +46 -0
- package/templates/be/patterns/event-bus/platform/event-bus.log-events.ts.tpl +12 -0
- package/templates/be/patterns/event-bus/platform/event-bus.module-definition.ts.tpl +10 -0
- package/templates/be/patterns/event-bus/platform/event-bus.module.ts.tpl +52 -0
- package/templates/be/patterns/event-bus/platform/event-bus.options.ts.tpl +19 -0
- package/templates/be/patterns/event-bus/platform/event-bus.port.ts.tpl +28 -0
- package/templates/be/patterns/event-bus/platform/event-bus.service.spec.ts.tpl +165 -0
- package/templates/be/patterns/event-bus/platform/event-bus.service.ts.tpl +93 -0
- package/templates/be/patterns/event-bus/platform/event-envelope.policy.spec.ts.tpl +90 -0
- package/templates/be/patterns/event-bus/platform/event-envelope.policy.ts.tpl +58 -0
- package/templates/be/patterns/event-bus/platform/event-relay.service.spec.ts.tpl +136 -0
- package/templates/be/patterns/event-bus/platform/event-relay.service.ts.tpl +56 -0
- package/templates/be/patterns/event-bus/platform/event-runner.service.spec.ts.tpl +272 -0
- package/templates/be/patterns/event-bus/platform/event-runner.service.ts.tpl +128 -0
- package/templates/be/patterns/event-bus/platform/event-transport.port.ts.tpl +180 -0
- package/templates/be/patterns/event-bus/platform/event.policy.spec.ts.tpl +67 -0
- package/templates/be/patterns/event-bus/platform/event.policy.ts.tpl +38 -0
- package/templates/be/patterns/event-bus/platform/index.ts.tpl +11 -0
- package/templates/be/patterns/event-bus/platform/kafka-event-transport.client.spec.ts.tpl +348 -0
- package/templates/be/patterns/event-bus/platform/kafka-event-transport.client.ts.tpl +241 -0
- package/templates/be/patterns/event-bus/platform/messages/event-bus.messages.ts.tpl +15 -0
- package/templates/be/patterns/event-bus/platform/persistence/connection.ts.tpl +8 -0
- package/templates/be/patterns/event-bus/platform/persistence/entities/event-outbox.entity.ts.tpl +37 -0
- package/templates/be/patterns/event-bus/platform/persistence/event-bus.rows.ts.tpl +11 -0
- package/templates/be/patterns/event-bus/platform/persistence/event-bus.sql.ts.tpl +12 -0
- package/templates/be/patterns/event-bus/platform/persistence/migrations/1789800009000-create-event-outbox.ts.tpl +26 -0
- package/templates/be/patterns/jobs/job.index.ts.tpl +1 -0
- package/templates/be/patterns/jobs/job.module.ts.tpl +6 -0
- package/templates/be/patterns/jobs/job.processor.ts.tpl +20 -0
- package/templates/be/patterns/jobs/job.queue.module.ts.tpl +20 -0
- package/templates/be/patterns/jobs/job.step.ts.tpl +19 -0
- package/templates/be/patterns/jobs/platform/fenced.processor.spec.ts.tpl +31 -0
- package/templates/be/patterns/jobs/platform/fenced.processor.ts.tpl +13 -0
- package/templates/be/patterns/jobs/platform/job-claim.service.spec.ts.tpl +150 -0
- package/templates/be/patterns/jobs/platform/job-claim.service.ts.tpl +100 -0
- package/templates/be/patterns/jobs/platform/job-runner.service.spec.ts.tpl +138 -0
- package/templates/be/patterns/jobs/platform/job-runner.service.ts.tpl +69 -0
- package/templates/be/patterns/jobs/platform/jobs.config.ts.tpl +11 -0
- package/templates/be/patterns/jobs/platform/jobs.contracts.ts.tpl +62 -0
- package/templates/be/patterns/jobs/platform/jobs.decorators.ts.tpl +31 -0
- package/templates/be/patterns/jobs/platform/jobs.error.ts.tpl +22 -0
- package/templates/be/patterns/jobs/platform/jobs.index.ts.tpl +11 -0
- package/templates/be/patterns/jobs/platform/jobs.log-events.ts.tpl +9 -0
- package/templates/be/patterns/jobs/platform/jobs.messages.ts.tpl +15 -0
- package/templates/be/patterns/jobs/platform/jobs.module-definition.ts.tpl +10 -0
- package/templates/be/patterns/jobs/platform/jobs.module.ts.tpl +32 -0
- package/templates/be/patterns/jobs/platform/jobs.options.ts.tpl +11 -0
- package/templates/be/patterns/jobs/platform/jobs.port.ts.tpl +36 -0
- package/templates/be/patterns/jobs/platform/persistence.connection.ts.tpl +8 -0
- package/templates/be/patterns/jobs/platform/persistence.job.entity.ts.tpl +53 -0
- package/templates/be/patterns/jobs/platform/persistence.jobs.rows.ts.tpl +13 -0
- package/templates/be/patterns/jobs/platform/persistence.jobs.sql.ts.tpl +33 -0
- package/templates/be/patterns/jobs/platform/persistence.migration.ts.tpl +29 -0
- package/templates/be/patterns/outbox/platform/index.ts.tpl +2 -0
- package/templates/be/patterns/outbox/platform/outbox-relay.policy.spec.ts.tpl +96 -0
- package/templates/be/patterns/outbox/platform/outbox-relay.policy.ts.tpl +78 -0
- package/templates/be/patterns/outbox/platform/outbox.log-events.ts.tpl +5 -0
- package/templates/be/patterns/projections/migration.ts.tpl +18 -0
- package/templates/be/patterns/projections/persistence.connection.ts.tpl +8 -0
- package/templates/be/patterns/projections/projection.entity.ts.tpl +9 -0
- package/templates/be/patterns/projections/projection.index.ts.tpl +3 -0
- package/templates/be/patterns/projections/projection.module-definition.ts.tpl +7 -0
- package/templates/be/patterns/projections/projection.module.ts.tpl +18 -0
- package/templates/be/patterns/projections/projection.options.ts.tpl +2 -0
- package/templates/be/patterns/projections/projection.projection.spec.ts.tpl +55 -0
- package/templates/be/patterns/projections/projection.projection.ts.tpl +21 -0
- package/templates/be/patterns/queues/platform/bullmq-queue-transport.client.spec.ts.tpl +142 -0
- package/templates/be/patterns/queues/platform/bullmq-queue-transport.client.ts.tpl +81 -0
- package/templates/be/patterns/queues/platform/persistence.connection.ts.tpl +8 -0
- package/templates/be/patterns/queues/platform/persistence.migration.ts.tpl +25 -0
- package/templates/be/patterns/queues/platform/persistence.queue-outbox.entity.ts.tpl +25 -0
- package/templates/be/patterns/queues/platform/persistence.queue.rows.ts.tpl +9 -0
- package/templates/be/patterns/queues/platform/persistence.queue.sql.ts.tpl +12 -0
- package/templates/be/patterns/queues/platform/queue-outbox.service.spec.ts.tpl +48 -0
- package/templates/be/patterns/queues/platform/queue-outbox.service.ts.tpl +17 -0
- package/templates/be/patterns/queues/platform/queue-relay.service.spec.ts.tpl +128 -0
- package/templates/be/patterns/queues/platform/queue-relay.service.ts.tpl +48 -0
- package/templates/be/patterns/queues/platform/queue-transport.port.ts.tpl +115 -0
- package/templates/be/patterns/queues/platform/queue-worker.service.spec.ts.tpl +91 -0
- package/templates/be/patterns/queues/platform/queue-worker.service.ts.tpl +45 -0
- package/templates/be/patterns/queues/platform/queue.config.ts.tpl +15 -0
- package/templates/be/patterns/queues/platform/queue.contracts.ts.tpl +31 -0
- package/templates/be/patterns/queues/platform/queue.decorators.ts.tpl +45 -0
- package/templates/be/patterns/queues/platform/queue.index.ts.tpl +7 -0
- package/templates/be/patterns/queues/platform/queue.log-events.ts.tpl +5 -0
- package/templates/be/patterns/queues/platform/queue.module-definition.ts.tpl +10 -0
- package/templates/be/patterns/queues/platform/queue.module.ts.tpl +62 -0
- package/templates/be/patterns/queues/platform/queue.options.ts.tpl +22 -0
- package/templates/be/patterns/queues/platform/queue.policy.spec.ts.tpl +19 -0
- package/templates/be/patterns/queues/platform/queue.policy.ts.tpl +11 -0
- package/templates/be/patterns/queues/platform/queue.port.ts.tpl +14 -0
- package/templates/be/patterns/queues/queue.index.ts.tpl +3 -0
- package/templates/be/patterns/queues/queue.module.ts.tpl +6 -0
- package/templates/be/patterns/queues/queue.queue.ts.tpl +23 -0
- package/templates/be/patterns/reactors/application.command.ts.tpl +10 -0
- package/templates/be/patterns/reactors/application.contracts.ts.tpl +12 -0
- package/templates/be/patterns/reactors/application.handler.ts.tpl +22 -0
- package/templates/be/patterns/reactors/consumer.ts.tpl +19 -0
- package/templates/be/patterns/reactors/message.module.ts.tpl +20 -0
- package/templates/be/patterns/reactors/reactor.index.ts.tpl +1 -0
- package/templates/be/patterns/reactors/reactor.module.ts.tpl +6 -0
- package/templates/be/patterns/realtime/channel.graphql.module.ts.tpl +6 -0
- package/templates/be/patterns/realtime/channel.index.ts.tpl +1 -0
- package/templates/be/patterns/realtime/channel.input.ts.tpl +12 -0
- package/templates/be/patterns/realtime/channel.subscription.spec.ts.tpl +51 -0
- package/templates/be/patterns/realtime/channel.subscription.ts.tpl +32 -0
- package/templates/be/patterns/realtime/channel.type.ts.tpl +9 -0
- package/templates/be/patterns/saga/saga.compensate.command.ts.tpl +11 -0
- package/templates/be/patterns/saga/saga.compensate.contracts.ts.tpl +7 -0
- package/templates/be/patterns/saga/saga.compensate.handler.ts.tpl +22 -0
- package/templates/be/patterns/saga/saga.compensation.ts.tpl +21 -0
- package/templates/be/patterns/saga/saga.complete.command.ts.tpl +11 -0
- package/templates/be/patterns/saga/saga.complete.contracts.ts.tpl +7 -0
- package/templates/be/patterns/saga/saga.complete.handler.ts.tpl +22 -0
- package/templates/be/patterns/saga/saga.done.consumer.ts.tpl +21 -0
- package/templates/be/patterns/saga/saga.failed.consumer.ts.tpl +21 -0
- package/templates/be/patterns/saga/saga.index.ts.tpl +1 -0
- package/templates/be/patterns/saga/saga.message.module.ts.tpl +23 -0
- package/templates/be/patterns/saga/saga.module.ts.tpl +20 -0
- package/templates/be/patterns/saga/saga.service.spec.ts.tpl +70 -0
- package/templates/be/patterns/saga/saga.service.ts.tpl +44 -0
- package/templates/be/patterns/saga/saga.state.ts.tpl +14 -0
- package/templates/be/patterns/saga/saga.step.ts.tpl +11 -0
- package/templates/be/patterns/saga/saga.undo.command.ts.tpl +10 -0
- package/templates/be/patterns/saga/saga.undo.contracts.ts.tpl +5 -0
- package/templates/be/patterns/saga/saga.undo.handler.ts.tpl +21 -0
- package/templates/be/patterns/webhooks/webhook.door.spec.ts.tpl +72 -0
- package/templates/be/patterns/webhooks/webhook.door.ts.tpl +36 -0
- package/templates/be/patterns/webhooks/webhook.http.module.ts.tpl +6 -0
- package/templates/be/patterns/webhooks/webhook.index.ts.tpl +1 -0
- package/templates/be/patterns/webhooks/webhook.request.ts.tpl +9 -0
- package/templates/be/skeleton/apps/__app__/src/__app__.options.ts +3 -0
- package/templates/be/skeleton/apps/__app__/src/app.module.ts +15 -2
- package/templates/be/skeleton/apps/__app__/src/main.ts +7 -15
- package/templates/be/skeleton/apps/cli/src/app.module.ts +30 -0
- package/templates/be/skeleton/apps/cli/src/cli.options.ts +22 -0
- package/templates/be/skeleton/apps/cli/src/main.ts +24 -0
- package/templates/be/skeleton/src/features/cli/cli.module.ts +7 -0
- package/templates/be/skeleton/src/features/cli/index.ts +1 -0
- package/templates/be/skeleton/src/features/cli/migrate/migrate.cli.spec.ts +17 -0
- package/templates/be/skeleton/src/features/cli/migrate/migrate.cli.ts +15 -0
- package/templates/be/skeleton/src/features/cli/migrate/migrate.module.ts +7 -0
- package/templates/be/skeleton/src/features/cli/migrate/subs/run.cli.spec.ts +17 -0
- package/templates/be/skeleton/src/features/cli/migrate/subs/run.cli.ts +18 -0
- package/templates/be/skeleton/src/features/cli/seed/seed.cli.spec.ts +17 -0
- package/templates/be/skeleton/src/features/cli/seed/seed.cli.ts +15 -0
- package/templates/be/skeleton/src/features/cli/seed/seed.module.ts +7 -0
- package/templates/be/skeleton/src/features/cli/seed/subs/run.cli.spec.ts +33 -0
- package/templates/be/skeleton/src/features/cli/seed/subs/run.cli.ts +34 -0
- package/templates/be/skeleton/src/modules/domain/identity/admission.policy.spec.ts +13 -0
- package/templates/be/skeleton/src/modules/domain/identity/auth.guard.spec.ts +40 -0
- package/templates/be/skeleton/src/modules/domain/identity/messages/identity.messages.ts +1 -1
- package/templates/be/skeleton/src/modules/domain/note/errors/note.error.ts +16 -0
- package/templates/be/skeleton/src/modules/domain/note/index.ts +3 -0
- package/templates/be/skeleton/src/modules/domain/note/note.contracts.ts +19 -0
- package/templates/be/skeleton/src/modules/domain/note/note.decorators.ts +9 -0
- package/templates/be/skeleton/src/modules/domain/note/note.module-definition.ts +7 -0
- package/templates/be/skeleton/src/modules/domain/note/note.module.ts +19 -0
- package/templates/be/skeleton/src/modules/domain/note/note.options.ts +2 -0
- package/templates/be/skeleton/src/modules/domain/note/note.service.spec.ts +76 -0
- package/templates/be/skeleton/src/modules/domain/note/note.service.ts +37 -0
- package/templates/be/skeleton/src/modules/domain/note/persistence/connection.ts +8 -0
- package/templates/be/skeleton/src/modules/domain/note/persistence/entities/note.entity.ts +17 -0
- package/templates/be/skeleton/src/modules/domain/note/persistence/migrations/1790000000000-init-note.ts +22 -0
- package/templates/be/skeleton/src/modules/domain/note/persistence/note.rows.ts +17 -0
- package/templates/be/skeleton/src/modules/domain/note/persistence/note.sql.ts +4 -0
- package/templates/be/skeleton/src/modules/platform/config/env-source.config.ts +20 -0
- package/templates/be/skeleton/src/modules/platform/config/index.ts +1 -1
- package/templates/be/skeleton/src/modules/platform/cqrs/cqrs.contracts.ts +18 -0
- package/templates/be/skeleton/src/modules/platform/database/connection-source.client.spec.ts +41 -0
- package/templates/be/skeleton/src/modules/platform/database/connection-source.client.ts +17 -0
- package/templates/be/skeleton/src/modules/platform/database/database.module-definition.ts +13 -0
- package/templates/be/skeleton/src/modules/platform/database/database.module.ts +77 -0
- package/templates/be/skeleton/src/modules/platform/database/database.options.ts +30 -0
- package/templates/be/skeleton/src/modules/platform/database/database.port.ts +65 -0
- package/templates/be/skeleton/src/modules/platform/database/database.sql.ts +47 -0
- package/templates/be/skeleton/src/modules/platform/database/errors/database.error.ts +16 -0
- package/templates/be/skeleton/src/modules/platform/database/index.ts +9 -0
- package/templates/be/skeleton/src/modules/platform/database/migrate-connections.client.ts +30 -0
- package/templates/be/skeleton/src/modules/platform/database/migration-runner.service.spec.ts +84 -0
- package/templates/be/skeleton/src/modules/platform/database/migration-runner.service.ts +23 -0
- package/templates/be/skeleton/src/modules/platform/database/primary.config.ts +9 -0
- package/templates/be/skeleton/src/modules/platform/database/primary.connection.ts +2 -0
- package/templates/be/skeleton/src/modules/platform/database/primary.decorators.ts +10 -0
- package/templates/be/skeleton/src/modules/platform/database/seed-connections.client.spec.ts +108 -0
- package/templates/be/skeleton/src/modules/platform/database/seed-connections.client.ts +75 -0
- package/templates/be/skeleton/src/modules/platform/database/seed-runner.service.spec.ts +88 -0
- package/templates/be/skeleton/src/modules/platform/database/seed-runner.service.ts +29 -0
- package/templates/be/skeleton/src/modules/platform/errors/errors.filter.spec.ts +48 -0
- package/templates/be/skeleton/src/modules/platform/errors/messages/errors.messages.ts +1 -1
- package/templates/be/skeleton/src/modules/platform/http-security/errors/http-security.error.ts +12 -0
- package/templates/be/skeleton/src/modules/platform/http-security/execution-request.mapper.spec.ts +16 -0
- package/templates/be/skeleton/src/modules/platform/http-security/http-security.config.ts +8 -1
- package/templates/be/skeleton/src/modules/platform/http-security/http-security.decorators.ts +8 -0
- package/templates/be/skeleton/src/modules/platform/http-security/http-security.module.ts +14 -1
- package/templates/be/skeleton/src/modules/platform/http-security/http-security.options.ts +12 -0
- package/templates/be/skeleton/src/modules/platform/http-security/messages/http-security.messages.ts +10 -2
- package/templates/be/skeleton/src/modules/platform/http-security/origin.guard.spec.ts +63 -0
- package/templates/be/skeleton/src/modules/platform/http-security/rate-limit.guard.spec.ts +108 -0
- package/templates/be/skeleton/src/modules/platform/http-security/request-validation.service.spec.ts +39 -0
- package/templates/be/skeleton/src/modules/platform/http-security/request-validation.service.ts +25 -0
- package/templates/be/skeleton/src/modules/platform/http-security/webhook-signature.service.spec.ts +172 -0
- package/templates/be/skeleton/src/modules/platform/http-security/webhook-signature.service.ts +66 -0
- package/templates/be/skeleton/src/modules/platform/logging/logging.log-events.ts +3 -1
- package/templates/be/skeleton/src/modules/platform/primitives/outcome.mapper.spec.ts +52 -0
- package/templates/be/skeleton-lite/apps/api/Dockerfile +37 -0
- package/templates/be/skeleton-lite/apps/api/src/api.options.ts +16 -0
- package/templates/be/skeleton-lite/apps/api/src/app.module.ts +81 -0
- package/templates/be/skeleton-lite/apps/api/src/main.ts +34 -0
- package/templates/be/skeleton-lite/src/modules/domain/identity/admission.policy.ts +14 -0
- package/templates/be/skeleton-lite/src/modules/domain/identity/auth.guard.ts +50 -0
- package/templates/be/skeleton-lite/src/modules/domain/identity/identity.contracts.ts +26 -0
- package/templates/be/skeleton-lite/src/modules/domain/identity/identity.decorators.ts +19 -0
- package/templates/be/skeleton-lite/src/modules/domain/identity/identity.module.ts +26 -0
- package/templates/be/skeleton-lite/src/modules/domain/identity/identity.options.ts +7 -0
- package/templates/be/skeleton-lite/src/modules/domain/identity/index.ts +6 -0
- package/templates/be/skeleton-lite/src/modules/integrations/supabase/errors/supabase.error.ts +19 -0
- package/templates/be/skeleton-lite/src/modules/integrations/supabase/index.ts +10 -0
- package/templates/be/skeleton-lite/src/modules/integrations/supabase/supabase.client.ts +24 -0
- package/templates/be/skeleton-lite/src/modules/integrations/supabase/supabase.config.ts +8 -0
- package/templates/be/skeleton-lite/src/modules/integrations/supabase/supabase.decorators.ts +17 -0
- package/templates/be/skeleton-lite/src/modules/integrations/supabase/supabase.jwks.ts +32 -0
- package/templates/be/skeleton-lite/src/modules/integrations/supabase/supabase.options.ts +24 -0
- package/templates/be/skeleton-lite/src/modules/platform/cqrs/index.ts +4 -0
- package/templates/be/skeleton-lite/src/modules/platform/database/database.module.ts +54 -0
- package/templates/be/skeleton-lite/src/modules/platform/database/database.options.ts +23 -0
- package/templates/be/skeleton-lite/src/modules/platform/database/database.port.ts +10 -0
- package/templates/be/skeleton-lite/src/modules/platform/database/database.sql.ts +49 -0
- package/templates/be/skeleton-lite/src/modules/platform/database/index.ts +4 -0
- package/templates/be/skeleton-lite/src/modules/platform/database/migration-runner.service.ts +21 -0
- package/templates/be/skeleton-lite/src/modules/platform/database/primary.config.ts +11 -0
- package/templates/be/skeleton-lite/src/modules/platform/database/seed-runner.service.ts +28 -0
- package/templates/be/skeleton-lite/src/modules/platform/http-security/http-security.module.ts +25 -0
- package/templates/be/skeleton-lite/src/modules/platform/http-security/index.ts +9 -0
- package/templates/be/skeleton-lite/src/modules/platform/i18n/index.ts +4 -0
- package/templates/be/skeleton-lite/src/modules/platform/logging/index.ts +5 -0
- package/templates/be/table/error.ts.tpl +16 -0
- package/templates/be/table/index.ts.tpl +2 -0
- package/templates/be/table/migration.sql.tpl +51 -0
- package/templates/be/table/module-definition.ts.tpl +7 -0
- package/templates/be/table/module.ts.tpl +14 -0
- package/templates/be/table/options.ts.tpl +2 -0
- package/templates/be/table/rows.ts.tpl +4 -0
- package/templates/be/table/service.ts.tpl +23 -0
- package/templates/be/table/sql.ts.tpl +4 -0
- package/templates/be/tool-config/jest.config.js +3 -1
- package/templates/be/upgrade-full/apps/cli/src/app.module.ts +14 -0
- package/templates/be/upgrade-full/apps/cli/src/main.ts +26 -0
- package/templates/be/upgrade-full/src/features/cli/cli.module.ts +6 -0
- package/templates/be/upgrade-full/src/features/cli/migrate/subs/run.cli.ts +23 -0
- package/templates/common/gitignore.base +1 -2
- package/templates/fe/app/package.json.tpl +1 -0
- package/templates/fe/app/tsconfig.json +12 -0
- package/templates/fe/common/app-layout.tsx.partial +8 -0
- package/templates/fe/common/site-shell.tsx.partial +9 -0
- package/templates/fe/image/next/Dockerfile +42 -0
- package/templates/fe/skeleton/apps/app/next.config.ts +23 -0
- package/templates/fe/skeleton/apps/app/postcss.config.mjs +7 -0
- package/templates/fe/skeleton/apps/{__app__ → app}/src/app/[locale]/error.tsx +2 -2
- package/templates/fe/skeleton/apps/app/src/app/[locale]/layout.tsx +22 -0
- package/templates/fe/skeleton/apps/{__app__ → app}/src/app/[locale]/loading.tsx +2 -2
- package/templates/fe/skeleton/apps/{__app__ → app}/src/app/[locale]/not-found.tsx +2 -2
- package/templates/fe/skeleton/apps/app/src/app/[locale]/page.tsx +9 -0
- package/templates/fe/skeleton/apps/{__app__ → app}/src/app/global-error.tsx +2 -2
- package/templates/fe/skeleton/apps/app/src/app/globals.css +10 -0
- package/templates/fe/skeleton/apps/app/src/features/layouts/AppLayout/index.tsx +18 -0
- package/templates/fe/skeleton/apps/app/src/features/pages/AppErrorPage/component.tsx +19 -0
- package/templates/fe/skeleton/apps/app/src/features/pages/AppErrorPage/index.tsx +11 -0
- package/templates/fe/skeleton/apps/app/src/features/pages/AppGlobalErrorPage/index.tsx +16 -0
- package/templates/fe/skeleton/apps/app/src/features/pages/AppHomePage/component.tsx +10 -0
- package/templates/fe/skeleton/apps/app/src/features/pages/AppHomePage/index.tsx +15 -0
- package/templates/fe/skeleton/apps/app/src/features/pages/AppLoadingPage/index.tsx +8 -0
- package/templates/fe/skeleton/apps/app/src/features/pages/AppNotFoundPage/index.tsx +9 -0
- package/templates/fe/skeleton/apps/app/src/modules/i18n/index.ts +4 -0
- package/templates/fe/skeleton/apps/app/src/modules/i18n/messages/vi.json +28 -0
- package/templates/fe/skeleton/apps/app/src/modules/i18n/request.ts +4 -0
- package/templates/fe/skeleton/apps/app/src/modules/routes/index.ts +4 -0
- package/templates/fe/skeleton/apps/app/src/proxy.ts +1 -0
- package/templates/fe/skeleton/apps/{__app__ → landing}/next.config.ts +4 -2
- package/templates/fe/skeleton/apps/landing/postcss.config.mjs +7 -0
- package/templates/fe/skeleton/apps/landing/src/app/[locale]/error.tsx +10 -0
- package/templates/fe/skeleton/apps/landing/src/app/[locale]/layout.tsx +22 -0
- package/templates/fe/skeleton/apps/landing/src/app/[locale]/loading.tsx +6 -0
- package/templates/fe/skeleton/apps/landing/src/app/[locale]/not-found.tsx +6 -0
- package/templates/fe/skeleton/apps/landing/src/app/[locale]/page.tsx +9 -0
- package/templates/fe/skeleton/apps/landing/src/app/global-error.tsx +10 -0
- package/templates/fe/skeleton/apps/landing/src/app/globals.css +10 -0
- package/templates/fe/skeleton/apps/landing/src/features/layouts/LandingLayout/index.tsx +24 -0
- package/templates/fe/skeleton/apps/landing/src/features/pages/LandingErrorPage/component.tsx +18 -0
- package/templates/fe/skeleton/apps/landing/src/features/pages/LandingErrorPage/index.tsx +11 -0
- package/templates/fe/skeleton/apps/landing/src/features/pages/LandingGlobalErrorPage/index.tsx +16 -0
- package/templates/fe/skeleton/apps/landing/src/features/pages/LandingLoadingPage/index.tsx +8 -0
- package/templates/fe/skeleton/apps/landing/src/features/pages/LandingNotFoundPage/index.tsx +9 -0
- package/templates/fe/skeleton/apps/landing/src/features/pages/LandingPage/component.tsx +24 -0
- package/templates/fe/skeleton/apps/landing/src/features/pages/LandingPage/index.tsx +16 -0
- package/templates/fe/skeleton/apps/landing/src/modules/config/index.ts +12 -0
- package/templates/fe/skeleton/apps/landing/src/modules/i18n/index.ts +7 -0
- package/templates/fe/skeleton/apps/landing/src/modules/i18n/messages/vi.json +31 -0
- package/templates/fe/skeleton/apps/landing/src/modules/i18n/request.ts +4 -0
- package/templates/fe/skeleton/apps/landing/src/modules/routes/index.ts +4 -0
- package/templates/fe/skeleton/apps/landing/src/proxy.ts +1 -0
- package/templates/fe/skeleton/packages/__project__-i18n/src/index.ts +49 -0
- package/templates/fe/skeleton/packages/__project__-i18n/src/proxy.ts +24 -0
- package/templates/fe/skeleton/packages/__project__-i18n/src/routing.ts +20 -0
- package/templates/fe/skeleton/packages/__project__-ui/src/branches/Providers/index.tsx +23 -0
- package/templates/fe/skeleton/packages/__project__-ui/src/composites/ErrorNotice/index.tsx +14 -0
- package/templates/fe/skeleton/packages/__project__-ui/src/composites/GlobalErrorNotice/index.tsx +25 -0
- package/templates/fe/skeleton/packages/__project__-ui/src/composites/LoadingNotice/index.tsx +9 -0
- package/templates/fe/skeleton/packages/__project__-ui/src/composites/LocaleShell/index.tsx +21 -0
- package/templates/fe/skeleton/packages/__project__-ui/src/composites/NotFoundNotice/index.tsx +19 -0
- package/templates/fe/skeleton/packages/__project__-ui/src/composites/SiteShell/classNames.ts +4 -0
- package/templates/fe/skeleton/packages/__project__-ui/src/composites/SiteShell/index.tsx +19 -0
- package/templates/fe/skeleton/packages/__project__-ui/src/index.ts +6 -0
- package/templates/fe/skeleton-lite/apps/web/next.config.ts +22 -0
- package/templates/fe/skeleton-lite/apps/web/src/app/[locale]/error.tsx +10 -0
- package/templates/fe/skeleton-lite/apps/web/src/app/[locale]/layout.tsx +37 -0
- package/templates/fe/skeleton-lite/apps/web/src/app/[locale]/loading.tsx +6 -0
- package/templates/fe/skeleton-lite/apps/web/src/app/[locale]/not-found.tsx +6 -0
- package/templates/fe/skeleton-lite/apps/web/src/app/[locale]/page.tsx +9 -0
- package/templates/fe/skeleton-lite/apps/web/src/app/[locale]/providers.tsx +26 -0
- package/templates/fe/skeleton-lite/apps/web/src/app/auth/callback/route.ts +24 -0
- package/templates/fe/skeleton-lite/apps/web/src/app/global-error.tsx +10 -0
- package/templates/fe/{skeleton/apps/__app__ → skeleton-lite/apps/web}/src/app/globals.css +1 -1
- package/templates/fe/skeleton-lite/apps/web/src/app/health/live/route.ts +5 -0
- package/templates/fe/skeleton-lite/apps/web/src/components/blocks/SignInForm/component.tsx +29 -0
- package/templates/fe/skeleton-lite/apps/web/src/components/blocks/SignInForm/index.tsx +41 -0
- package/templates/fe/skeleton-lite/apps/web/src/components/blocks/SignOutButton/component.tsx +17 -0
- package/templates/fe/skeleton-lite/apps/web/src/components/blocks/SignOutButton/index.tsx +38 -0
- package/templates/fe/skeleton-lite/apps/web/src/components/composites/ErrorNotice/index.tsx +13 -0
- package/templates/fe/skeleton-lite/apps/web/src/components/composites/GlobalErrorNotice/index.tsx +24 -0
- package/templates/fe/skeleton-lite/apps/web/src/components/composites/LoadingNotice/index.tsx +7 -0
- package/templates/fe/skeleton-lite/apps/web/src/components/composites/NotFoundNotice/index.tsx +18 -0
- package/templates/fe/skeleton-lite/apps/web/src/components/composites/SiteShell/classNames.ts +4 -0
- package/templates/fe/skeleton-lite/apps/web/src/components/composites/SiteShell/index.tsx +13 -0
- package/templates/fe/skeleton-lite/apps/web/src/features/layouts/AppLayout/index.tsx +31 -0
- package/templates/fe/skeleton-lite/apps/web/src/features/pages/AppErrorPage/component.tsx +12 -0
- package/templates/fe/skeleton-lite/apps/web/src/features/pages/AppErrorPage/index.tsx +10 -0
- package/templates/fe/skeleton-lite/apps/web/src/features/pages/AppGlobalErrorPage/index.tsx +15 -0
- package/templates/fe/skeleton-lite/apps/web/src/features/pages/AppHomePage/component.tsx +14 -0
- package/templates/fe/skeleton-lite/apps/web/src/features/pages/AppHomePage/index.tsx +30 -0
- package/templates/fe/skeleton-lite/apps/web/src/features/pages/AppLoadingPage/index.tsx +8 -0
- package/templates/fe/skeleton-lite/apps/web/src/features/pages/AppNotFoundPage/index.tsx +9 -0
- package/templates/fe/skeleton-lite/apps/web/src/modules/brand/brand.css +20 -0
- package/templates/fe/skeleton-lite/apps/web/src/modules/brand/index.ts +2 -0
- package/templates/fe/skeleton-lite/apps/web/src/modules/config/index.ts +20 -0
- package/templates/fe/skeleton-lite/apps/web/src/modules/db/auth/read-session.ts +25 -0
- package/templates/fe/skeleton-lite/apps/web/src/modules/db/auth/write-sign-in.ts +25 -0
- package/templates/fe/skeleton-lite/apps/web/src/modules/db/auth/write-sign-out.ts +17 -0
- package/templates/fe/skeleton-lite/apps/web/src/modules/db/browser.ts +14 -0
- package/templates/fe/skeleton-lite/apps/web/src/modules/db/index.ts +3 -0
- package/templates/fe/skeleton-lite/apps/web/src/modules/db/outcome.ts +59 -0
- package/templates/fe/skeleton-lite/apps/web/src/modules/db/principal.ts +29 -0
- package/templates/fe/skeleton-lite/apps/web/src/modules/db/server.ts +70 -0
- package/templates/fe/skeleton-lite/apps/web/src/modules/db/validation/validation.mapper.ts +50 -0
- package/templates/fe/skeleton-lite/apps/web/src/modules/i18n/index.ts +8 -0
- package/templates/fe/skeleton-lite/apps/web/src/modules/i18n/messages/vi.json +48 -0
- package/templates/fe/skeleton-lite/apps/web/src/modules/i18n/request.ts +16 -0
- package/templates/fe/skeleton-lite/apps/web/src/modules/i18n/routing.ts +14 -0
- package/templates/fe/skeleton-lite/apps/web/src/modules/routes/index.ts +7 -0
- package/templates/fe/skeleton-lite/apps/web/src/modules/routes/safe-next-path.ts +26 -0
- package/templates/fe/skeleton-lite/apps/web/src/proxy.ts +43 -0
- package/templates/fe/table/read.ts.tpl +16 -0
- package/templates/fe/table/write.ts.tpl +16 -0
- package/upgrade/check.mjs +137 -0
- package/upgrade/index.mjs +524 -0
- package/bin/hfs.mjs +0 -233
- package/runtime/scripts/api/fs/rmdir-link.mjs +0 -12
- package/runtime/scripts/lib/test-secrets.mjs +0 -116
- package/templates/fe/skeleton/apps/__app__/src/app/[locale]/layout.tsx +0 -20
- package/templates/fe/skeleton/apps/__app__/src/app/[locale]/page.tsx +0 -9
- package/templates/fe/skeleton/apps/__app__/src/components/composites/FailureScreen/index.tsx +0 -28
- package/templates/fe/skeleton/apps/__app__/src/features/layouts/LocaleShell/index.tsx +0 -35
- package/templates/fe/skeleton/apps/__app__/src/features/pages/ErrorPage/component.tsx +0 -19
- package/templates/fe/skeleton/apps/__app__/src/features/pages/ErrorPage/index.tsx +0 -11
- package/templates/fe/skeleton/apps/__app__/src/features/pages/GlobalErrorPage/component.tsx +0 -24
- package/templates/fe/skeleton/apps/__app__/src/features/pages/GlobalErrorPage/index.tsx +0 -14
- package/templates/fe/skeleton/apps/__app__/src/features/pages/HomePage/component.tsx +0 -21
- package/templates/fe/skeleton/apps/__app__/src/features/pages/HomePage/index.tsx +0 -15
- package/templates/fe/skeleton/apps/__app__/src/features/pages/LoadingPage/component.tsx +0 -23
- package/templates/fe/skeleton/apps/__app__/src/features/pages/LoadingPage/index.tsx +0 -8
- package/templates/fe/skeleton/apps/__app__/src/features/pages/NotFoundPage/component.tsx +0 -28
- package/templates/fe/skeleton/apps/__app__/src/features/pages/NotFoundPage/index.tsx +0 -8
- package/templates/fe/skeleton/apps/__app__/src/modules/i18n/config.ts +0 -8
- package/templates/fe/skeleton/apps/__app__/src/modules/i18n/index.ts +0 -2
- package/templates/fe/skeleton/apps/__app__/src/modules/i18n/messages/vi.json +0 -25
- package/templates/fe/skeleton/apps/__app__/src/modules/i18n/request.ts +0 -19
- package/templates/fe/skeleton/apps/__app__/src/modules/i18n/routing.ts +0 -9
- package/templates/fe/skeleton/apps/__app__/src/modules/routes/index.ts +0 -4
- package/templates/fe/skeleton/apps/__app__/src/proxy.ts +0 -10
- /package/templates/be/skeleton/src/features/{system-health → api/system-health}/application/check-liveness.contracts.ts +0 -0
- /package/templates/be/skeleton/src/features/{system-health → api/system-health}/application/check-liveness.handler.ts +0 -0
- /package/templates/be/skeleton/src/features/{system-health → api/system-health}/application/check-liveness.query.ts +0 -0
- /package/templates/be/skeleton/src/features/{system-health → api/system-health}/index.ts +0 -0
- /package/templates/be/skeleton/src/features/{system-health → api/system-health}/system-health.module.ts +0 -0
- /package/templates/be/skeleton/src/features/{system-health → api/system-health}/transport/http/live.controller.ts +0 -0
- /package/templates/be/skeleton/src/features/{system-health → api/system-health}/transport/http/system-health-http.module.ts +0 -0
- /package/templates/fe/skeleton/apps/{__app__ → app}/src/app/health/live/route.ts +0 -0
- /package/templates/fe/skeleton/apps/{__app__ → app}/src/modules/config/index.ts +0 -0
- /package/templates/fe/{skeleton/apps/__app__ → skeleton-lite/apps/web}/postcss.config.mjs +0 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { Test } from "@nestjs/testing"
|
|
2
|
+
import { FakeClock, mock, mockEntityManager } from "@starci/jest-preset"
|
|
3
|
+
import { CLOCK } from "@modules/platform/clock"
|
|
4
|
+
import { EventBusErrorCode } from "./errors/event-bus.error"
|
|
5
|
+
import { BaseEvent } from "./event-bus.contracts"
|
|
6
|
+
import type { ParsedEvent } from "./event-bus.contracts"
|
|
7
|
+
import { EVENT_BUS_OPTIONS, EVENT_TRANSPORT } from "./event-bus.decorators"
|
|
8
|
+
import type { EventBusOptions } from "./event-bus.options"
|
|
9
|
+
import { EventBusService } from "./event-bus.service"
|
|
10
|
+
import type { EventTransport, InboundMessage } from "./event-transport.port"
|
|
11
|
+
import { INSERT_OUTBOX_ROW } from "./persistence/event-bus.sql"
|
|
12
|
+
|
|
13
|
+
const AT = "2026-02-03T04:05:06.000Z"
|
|
14
|
+
|
|
15
|
+
const options: EventBusOptions = {
|
|
16
|
+
brokers: ["localhost:9094"],
|
|
17
|
+
groupId: "app",
|
|
18
|
+
topicPrefix: "run-1.",
|
|
19
|
+
relayIntervalMs: 100,
|
|
20
|
+
relayBatch: 50,
|
|
21
|
+
timeoutMs: 3000,
|
|
22
|
+
connections: [],
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface PingPayload {
|
|
26
|
+
readonly note: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
class PingEvent extends BaseEvent {
|
|
30
|
+
static readonly eventName = "probe.ping"
|
|
31
|
+
static readonly version = 1
|
|
32
|
+
|
|
33
|
+
readonly eventName = PingEvent.eventName
|
|
34
|
+
|
|
35
|
+
constructor(
|
|
36
|
+
readonly eventId: string,
|
|
37
|
+
readonly payload: PingPayload,
|
|
38
|
+
) {
|
|
39
|
+
super()
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static parse(): ParsedEvent<PingEvent> {
|
|
43
|
+
return null
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const DLQ = "run-1.events.probe.dlq"
|
|
48
|
+
|
|
49
|
+
const envelope = (eventName: string, eventId: string) => JSON.stringify({ eventId, eventName, payload: {} })
|
|
50
|
+
|
|
51
|
+
const letter = (offset: string, eventName: string, headers: Record<string, string>): InboundMessage => ({
|
|
52
|
+
topic: DLQ,
|
|
53
|
+
partition: 0,
|
|
54
|
+
offset,
|
|
55
|
+
key: `id-${offset}`,
|
|
56
|
+
value: envelope(eventName, `id-${offset}`),
|
|
57
|
+
headers,
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
const build = async () => {
|
|
61
|
+
const transport = mock<EventTransport>()
|
|
62
|
+
const moduleRef = await Test.createTestingModule({
|
|
63
|
+
providers: [
|
|
64
|
+
EventBusService,
|
|
65
|
+
{ provide: EVENT_BUS_OPTIONS, useValue: options },
|
|
66
|
+
{ provide: EVENT_TRANSPORT, useValue: transport },
|
|
67
|
+
{ provide: CLOCK, useValue: new FakeClock(AT) },
|
|
68
|
+
],
|
|
69
|
+
}).compile()
|
|
70
|
+
return { bus: moduleRef.get(EventBusService), transport }
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
describe("EventBusService", () => {
|
|
74
|
+
describe("publish", () => {
|
|
75
|
+
it("writes the envelope as an outbox row of the caller transaction, keyed by the event id on the topic of the service", async () => {
|
|
76
|
+
const tx = mockEntityManager({ query: [INSERT_OUTBOX_ROW, []] })
|
|
77
|
+
const { bus, transport } = await build()
|
|
78
|
+
|
|
79
|
+
await bus.publish(new PingEvent("e-1", { note: "hi" }), tx)
|
|
80
|
+
|
|
81
|
+
expect(tx.query).toHaveBeenCalledWith(INSERT_OUTBOX_ROW, [
|
|
82
|
+
"e-1",
|
|
83
|
+
"probe.ping",
|
|
84
|
+
"run-1.events.probe",
|
|
85
|
+
"e-1",
|
|
86
|
+
JSON.stringify({ eventId: "e-1", eventName: "probe.ping", payload: { note: "hi" } }),
|
|
87
|
+
new Date(AT),
|
|
88
|
+
])
|
|
89
|
+
expect(transport.send).not.toHaveBeenCalled()
|
|
90
|
+
})
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
describe("pendingRetries", () => {
|
|
94
|
+
it("is the lag of the retry topic of the event", async () => {
|
|
95
|
+
const { bus, transport } = await build()
|
|
96
|
+
transport.lag.mockResolvedValue(2)
|
|
97
|
+
|
|
98
|
+
await expect(bus.pendingRetries(PingEvent)).resolves.toBe(2)
|
|
99
|
+
|
|
100
|
+
expect(transport.lag).toHaveBeenCalledWith("run-1.events.probe.retry")
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
describe("deadLetters", () => {
|
|
105
|
+
it("lists the buried events of the class, not the other events of the topic, the markers, or the letters a marker closed", async () => {
|
|
106
|
+
const { bus, transport } = await build()
|
|
107
|
+
transport.read.mockResolvedValue([
|
|
108
|
+
letter("0", "probe.ping", { attempt: "5", reason: "refused", "origin-topic": "run-1.events.probe" }),
|
|
109
|
+
letter("1", "probe.other", { attempt: "5", reason: "other", "origin-topic": "run-1.events.probe" }),
|
|
110
|
+
letter("2", "probe.ping", { attempt: "5", reason: "closed", "origin-topic": "run-1.events.probe" }),
|
|
111
|
+
{ ...letter("3", "probe.ping", { requeued: `${DLQ}|0|2` }), value: "{}" },
|
|
112
|
+
{ ...letter("4", "probe.ping", {}), value: "not json" },
|
|
113
|
+
letter("5", "probe.ping", { "origin-topic": "run-1.events.probe" }),
|
|
114
|
+
])
|
|
115
|
+
|
|
116
|
+
const letters = await bus.deadLetters(PingEvent)
|
|
117
|
+
|
|
118
|
+
expect(letters).toEqual([
|
|
119
|
+
{ id: `${DLQ}|0|0`, eventName: "probe.ping", eventId: "id-0", reason: "refused", attempts: 5 },
|
|
120
|
+
{ id: `${DLQ}|0|5`, eventName: "probe.ping", eventId: "id-5", reason: "", attempts: 0 },
|
|
121
|
+
])
|
|
122
|
+
expect(transport.read).toHaveBeenCalledWith(DLQ)
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
it("treats a value that is a JSON text without an event name as no letter of the class", async () => {
|
|
126
|
+
const { bus, transport } = await build()
|
|
127
|
+
transport.read.mockResolvedValue([{ ...letter("0", "probe.ping", {}), value: "[1]" }])
|
|
128
|
+
|
|
129
|
+
await expect(bus.deadLetters(PingEvent)).resolves.toEqual([])
|
|
130
|
+
})
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
describe("requeue", () => {
|
|
134
|
+
it("puts the original message back on its main topic and closes the dead letter with a marker", async () => {
|
|
135
|
+
const { bus, transport } = await build()
|
|
136
|
+
const original = letter("7", "probe.ping", { "origin-topic": "run-1.events.probe", reason: "x" })
|
|
137
|
+
transport.read.mockResolvedValue([letter("6", "probe.ping", {}), original])
|
|
138
|
+
|
|
139
|
+
await bus.requeue(`${DLQ}|0|7`)
|
|
140
|
+
|
|
141
|
+
expect(transport.send).toHaveBeenCalledWith([
|
|
142
|
+
{ topic: "run-1.events.probe", key: "id-7", value: original.value, headers: {} },
|
|
143
|
+
{ topic: DLQ, key: "id-7", value: "{}", headers: { requeued: `${DLQ}|0|7` } },
|
|
144
|
+
])
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
it("refuses an id the dead-letter topic does not hold", async () => {
|
|
148
|
+
const { bus, transport } = await build()
|
|
149
|
+
transport.read.mockResolvedValue([])
|
|
150
|
+
|
|
151
|
+
await expect(bus.requeue(`${DLQ}|0|9`)).rejects.toMatchObject({
|
|
152
|
+
code: EventBusErrorCode.DeadLetterUnknown,
|
|
153
|
+
params: { id: `${DLQ}|0|9` },
|
|
154
|
+
})
|
|
155
|
+
expect(transport.send).not.toHaveBeenCalled()
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
it("refuses a letter that does not name the topic it came from", async () => {
|
|
159
|
+
const { bus, transport } = await build()
|
|
160
|
+
transport.read.mockResolvedValue([letter("8", "probe.ping", {})])
|
|
161
|
+
|
|
162
|
+
await expect(bus.requeue(`${DLQ}|0|8`)).rejects.toMatchObject({ code: EventBusErrorCode.DeadLetterUnknown })
|
|
163
|
+
})
|
|
164
|
+
})
|
|
165
|
+
})
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { Injectable } from "@nestjs/common"
|
|
2
|
+
import type { EntityManager } from "typeorm"
|
|
3
|
+
import { InjectClock } from "@modules/platform/clock"
|
|
4
|
+
import type { Clock } from "@modules/platform/clock"
|
|
5
|
+
import { EventBusError, EventBusErrorCode } from "./errors/event-bus.error"
|
|
6
|
+
import type { BaseEvent, EventClass, EventDeadLetter, EventEnvelope } from "./event-bus.contracts"
|
|
7
|
+
import { InjectEventBusOptions, InjectEventTransport } from "./event-bus.decorators"
|
|
8
|
+
import type { EventBusOptions } from "./event-bus.options"
|
|
9
|
+
import type { EventBus } from "./event-bus.port"
|
|
10
|
+
import { readEnvelopeText } from "./event-envelope.policy"
|
|
11
|
+
import type { EventTransport, InboundMessage } from "./event-transport.port"
|
|
12
|
+
import {
|
|
13
|
+
ATTEMPT_HEADER,
|
|
14
|
+
DEAD_LETTER_ID_SEPARATOR,
|
|
15
|
+
ORIGIN_HEADER,
|
|
16
|
+
REASON_HEADER,
|
|
17
|
+
REQUEUED_HEADER,
|
|
18
|
+
deadLetterTopicOf,
|
|
19
|
+
retryTopicOf,
|
|
20
|
+
topicOf,
|
|
21
|
+
} from "./event.policy"
|
|
22
|
+
import { INSERT_OUTBOX_ROW } from "./persistence/event-bus.sql"
|
|
23
|
+
|
|
24
|
+
/** The body of a marker message: it carries nothing, its header says which dead letter it closes. */
|
|
25
|
+
const MARKER_VALUE = "{}"
|
|
26
|
+
|
|
27
|
+
/** The id of a dead letter: where its message sits on the dead-letter topic. */
|
|
28
|
+
const deadLetterIdOf = (message: InboundMessage): string =>
|
|
29
|
+
[message.topic, message.partition, message.offset].join(DEAD_LETTER_ID_SEPARATOR)
|
|
30
|
+
|
|
31
|
+
@Injectable()
|
|
32
|
+
/**
|
|
33
|
+
* The publishing side of the event bus. `publish` writes the event as a row of the outbox of the caller's transaction, so the
|
|
34
|
+
* event exists exactly when the change it reports commits; the relay hands the row to the broker afterwards. The operator
|
|
35
|
+
* reads follow the broker: the retry topic says what waits for its backoff, the dead-letter topic what ran out of attempts,
|
|
36
|
+
* and a requeue puts the original message back on its main topic and closes the dead letter with a marker.
|
|
37
|
+
*/
|
|
38
|
+
export class EventBusService implements EventBus {
|
|
39
|
+
constructor(
|
|
40
|
+
@InjectEventBusOptions() private readonly options: EventBusOptions,
|
|
41
|
+
@InjectEventTransport() private readonly transport: EventTransport,
|
|
42
|
+
@InjectClock() private readonly clock: Clock,
|
|
43
|
+
) {}
|
|
44
|
+
|
|
45
|
+
/** Writes the event in the outbox of the transaction `tx`; the event id is the partition key, so the events of one aggregate keep their order. */
|
|
46
|
+
async publish(event: BaseEvent, tx: EntityManager): Promise<void> {
|
|
47
|
+
const envelope: EventEnvelope = { eventId: event.eventId, eventName: event.eventName, payload: event.payload }
|
|
48
|
+
await tx.query(INSERT_OUTBOX_ROW, [
|
|
49
|
+
event.eventId,
|
|
50
|
+
event.eventName,
|
|
51
|
+
topicOf(this.options.topicPrefix, event.eventName),
|
|
52
|
+
event.eventId,
|
|
53
|
+
JSON.stringify(envelope),
|
|
54
|
+
this.clock.now(),
|
|
55
|
+
])
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** How many deliveries of the class wait on the retry topic for their backoff to pass. */
|
|
59
|
+
pendingRetries(event: EventClass<BaseEvent>): Promise<number> {
|
|
60
|
+
return this.transport.lag(retryTopicOf(this.options.topicPrefix, event.eventName))
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The events of the class that ran out of attempts and were not requeued since. */
|
|
64
|
+
async deadLetters(event: EventClass<BaseEvent>): Promise<ReadonlyArray<EventDeadLetter>> {
|
|
65
|
+
const messages = await this.transport.read(deadLetterTopicOf(this.options.topicPrefix, event.eventName))
|
|
66
|
+
const closed = new Set(messages.map((message) => message.headers[REQUEUED_HEADER]))
|
|
67
|
+
return messages
|
|
68
|
+
.filter((message) => message.headers[REQUEUED_HEADER] === undefined)
|
|
69
|
+
.filter((message) => readEnvelopeText(message.value).eventName === event.eventName)
|
|
70
|
+
.filter((message) => !closed.has(deadLetterIdOf(message)))
|
|
71
|
+
.map((message) => ({
|
|
72
|
+
id: deadLetterIdOf(message),
|
|
73
|
+
eventName: event.eventName,
|
|
74
|
+
eventId: message.key,
|
|
75
|
+
reason: message.headers[REASON_HEADER] ?? "",
|
|
76
|
+
attempts: Number(message.headers[ATTEMPT_HEADER] ?? 0),
|
|
77
|
+
}))
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Puts a dead letter back on its main topic with a fresh attempt count and closes it with a marker; an id the topic does not hold is refused. */
|
|
81
|
+
async requeue(deadLetterId: string): Promise<void> {
|
|
82
|
+
const topic = deadLetterId.slice(0, deadLetterId.indexOf(DEAD_LETTER_ID_SEPARATOR))
|
|
83
|
+
const letter = (await this.transport.read(topic)).find((message) => deadLetterIdOf(message) === deadLetterId)
|
|
84
|
+
const origin = letter?.headers[ORIGIN_HEADER]
|
|
85
|
+
if (letter === undefined || origin === undefined) {
|
|
86
|
+
throw new EventBusError({ code: EventBusErrorCode.DeadLetterUnknown, params: { id: deadLetterId } })
|
|
87
|
+
}
|
|
88
|
+
await this.transport.send([
|
|
89
|
+
{ topic: origin, key: letter.key, value: letter.value, headers: {} },
|
|
90
|
+
{ topic, key: letter.key, value: MARKER_VALUE, headers: { [REQUEUED_HEADER]: deadLetterId } },
|
|
91
|
+
])
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { BaseEvent } from "./event-bus.contracts"
|
|
2
|
+
import { readEnvelope, readEnvelopeText, readEventOf } from "./event-envelope.policy"
|
|
3
|
+
|
|
4
|
+
interface PingPayload {
|
|
5
|
+
readonly note: string
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
class PingEvent extends BaseEvent {
|
|
9
|
+
readonly eventName = "probe.ping"
|
|
10
|
+
|
|
11
|
+
constructor(
|
|
12
|
+
readonly eventId: string,
|
|
13
|
+
readonly payload: PingPayload,
|
|
14
|
+
) {
|
|
15
|
+
super()
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const isPingPayload = (payload: Record<string, unknown>): payload is PingPayload & Record<string, unknown> =>
|
|
20
|
+
typeof payload.note === "string"
|
|
21
|
+
const buildPing = (eventId: string, payload: PingPayload): PingEvent => new PingEvent(eventId, payload)
|
|
22
|
+
|
|
23
|
+
describe("event envelope policies", () => {
|
|
24
|
+
describe("readEnvelope", () => {
|
|
25
|
+
it("reads the event id and payload of an envelope", () => {
|
|
26
|
+
expect(readEnvelope({ eventId: "event-1", payload: { note: "hello" }, ignored: true })).toEqual({
|
|
27
|
+
eventId: "event-1",
|
|
28
|
+
payload: { note: "hello" },
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it.each([
|
|
33
|
+
[null, "a non-record"],
|
|
34
|
+
[{ eventId: 1, payload: {} }, "a non-text event id"],
|
|
35
|
+
[{ eventId: "event-1", payload: 1 }, "a non-record payload"],
|
|
36
|
+
])("refuses %s because it is %s", (envelope: unknown, _why: string) => {
|
|
37
|
+
expect(readEnvelope(envelope)).toBeNull()
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
describe("readEnvelopeText", () => {
|
|
42
|
+
it("parses an envelope and names its event", () => {
|
|
43
|
+
const envelope = { eventId: "event-1", eventName: "probe.ping", payload: { note: "hello" } }
|
|
44
|
+
|
|
45
|
+
expect(readEnvelopeText(JSON.stringify(envelope))).toEqual({
|
|
46
|
+
eventName: "probe.ping",
|
|
47
|
+
envelope,
|
|
48
|
+
cause: null,
|
|
49
|
+
})
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it.each([JSON.stringify([]), JSON.stringify({ eventName: 1 })])(
|
|
53
|
+
"keeps a parsed JSON value without a text event name unnamed",
|
|
54
|
+
(value) => {
|
|
55
|
+
expect(readEnvelopeText(value)).toMatchObject({ eventName: "", cause: null })
|
|
56
|
+
},
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
it("returns the parse failure for text that is not JSON", () => {
|
|
60
|
+
const result = readEnvelopeText("not json")
|
|
61
|
+
|
|
62
|
+
expect(result.eventName).toBe("")
|
|
63
|
+
expect(result.envelope).toBeNull()
|
|
64
|
+
expect(result.cause).toBeInstanceOf(SyntaxError)
|
|
65
|
+
})
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
describe("readEventOf", () => {
|
|
69
|
+
it("builds an event after the envelope and its payload are proven", () => {
|
|
70
|
+
expect(readEventOf({ eventId: "event-1", payload: { note: "hello" } }, isPingPayload, buildPing)).toEqual(
|
|
71
|
+
new PingEvent("event-1", { note: "hello" }),
|
|
72
|
+
)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it("refuses a value that is not an envelope without checking its payload", () => {
|
|
76
|
+
let checked = false
|
|
77
|
+
const guard = (payload: Record<string, unknown>): payload is PingPayload & Record<string, unknown> => {
|
|
78
|
+
checked = true
|
|
79
|
+
return isPingPayload(payload)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
expect(readEventOf(null, guard, buildPing)).toBeNull()
|
|
83
|
+
expect(checked).toBe(false)
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
it("refuses an envelope whose payload does not have the event fields", () => {
|
|
87
|
+
expect(readEventOf({ eventId: "event-1", payload: {} }, isPingPayload, buildPing)).toBeNull()
|
|
88
|
+
})
|
|
89
|
+
})
|
|
90
|
+
})
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { BaseEvent, ParsedEvent } from "./event-bus.contracts"
|
|
2
|
+
import { isRecord } from "@modules/platform/primitives"
|
|
3
|
+
|
|
4
|
+
/** What a received envelope carries once its shape is checked: the event id and the payload record. */
|
|
5
|
+
export interface ReadEnvelope {
|
|
6
|
+
/** The stable event id. */
|
|
7
|
+
readonly eventId: string
|
|
8
|
+
/** The payload record, its fields still unchecked. */
|
|
9
|
+
readonly payload: Record<string, unknown>
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** What reading an envelope answers: the checked envelope, or null when the value does not have the shape. */
|
|
13
|
+
export type ReadEnvelopeResult = ReadEnvelope | null
|
|
14
|
+
|
|
15
|
+
/** What reading the text of a message answers: the event name it carries (empty when none), the parsed value, and the failure when the text is not JSON. */
|
|
16
|
+
export interface ReadEnvelopeText {
|
|
17
|
+
/** The event name of the envelope, or an empty text when the value is not an envelope. */
|
|
18
|
+
readonly eventName: string
|
|
19
|
+
/** The parsed value, or null when the text is not JSON. */
|
|
20
|
+
readonly envelope: unknown
|
|
21
|
+
/** Why the text could not be parsed; null when it could. */
|
|
22
|
+
readonly cause: unknown
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Checks the shape every envelope has, `{ eventId, payload }`: what an event class reads its own fields from. */
|
|
26
|
+
export const readEnvelope = (envelope: unknown): ReadEnvelopeResult =>
|
|
27
|
+
isRecord(envelope) && typeof envelope.eventId === "string" && isRecord(envelope.payload)
|
|
28
|
+
? { eventId: envelope.eventId, payload: envelope.payload }
|
|
29
|
+
: null
|
|
30
|
+
|
|
31
|
+
/** Parses the text of a message and names the event it carries; a text that is not JSON has no name and carries the cause. */
|
|
32
|
+
export const readEnvelopeText = (value: string): ReadEnvelopeText => {
|
|
33
|
+
try {
|
|
34
|
+
const envelope: unknown = JSON.parse(value)
|
|
35
|
+
const eventName = isRecord(envelope) && typeof envelope.eventName === "string" ? envelope.eventName : ""
|
|
36
|
+
return { eventName, envelope, cause: null }
|
|
37
|
+
} catch (cause) {
|
|
38
|
+
return { eventName: "", envelope: null, cause }
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** What proves the payload record of an envelope has the fields of an event's payload. */
|
|
43
|
+
export type PayloadGuard<Payload extends object> = (
|
|
44
|
+
payload: Record<string, unknown>,
|
|
45
|
+
) => payload is Payload & Record<string, unknown>
|
|
46
|
+
|
|
47
|
+
/** What makes an event from a checked envelope: its id and its proven payload. */
|
|
48
|
+
export type EventBuilder<Payload extends object, Event extends BaseEvent> = (eventId: string, payload: Payload) => Event
|
|
49
|
+
|
|
50
|
+
/** Reads an envelope into an event: the shape is checked, `isPayload` proves the payload fields, `build` makes the event; null when either check fails. */
|
|
51
|
+
export const readEventOf = <Payload extends object, Event extends BaseEvent>(
|
|
52
|
+
envelope: unknown,
|
|
53
|
+
isPayload: PayloadGuard<Payload>,
|
|
54
|
+
build: EventBuilder<Payload, Event>,
|
|
55
|
+
): ParsedEvent<Event> => {
|
|
56
|
+
const read = readEnvelope(envelope)
|
|
57
|
+
return read !== null && isPayload(read.payload) ? build(read.eventId, read.payload) : null
|
|
58
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { Test } from "@nestjs/testing"
|
|
2
|
+
import { FakeClock, fakeTransaction, mock, mockEntityManager } from "@starci/jest-preset"
|
|
3
|
+
import type { MockEntityManager } from "@starci/jest-preset"
|
|
4
|
+
import { CLOCK } from "@modules/platform/clock"
|
|
5
|
+
import { LOGGER } from "@modules/platform/logging"
|
|
6
|
+
import type { Logger } from "@modules/platform/logging"
|
|
7
|
+
import { EVENT_BUS_OPTIONS, EVENT_RELAY_MANAGERS, EVENT_TRANSPORT } from "./event-bus.decorators"
|
|
8
|
+
import { OutboxLogEvent } from "@modules/platform/outbox"
|
|
9
|
+
import type { EventBusOptions } from "./event-bus.options"
|
|
10
|
+
import { EventRelayService } from "./event-relay.service"
|
|
11
|
+
import type { EventTransport } from "./event-transport.port"
|
|
12
|
+
import { MARK_ROWS_SENT, SELECT_WAITING_ROWS } from "./persistence/event-bus.sql"
|
|
13
|
+
|
|
14
|
+
const AT = "2026-02-03T04:05:06.000Z"
|
|
15
|
+
|
|
16
|
+
const options: EventBusOptions = {
|
|
17
|
+
brokers: ["localhost:9094"],
|
|
18
|
+
groupId: "app",
|
|
19
|
+
topicPrefix: "",
|
|
20
|
+
relayIntervalMs: 100,
|
|
21
|
+
relayBatch: 2,
|
|
22
|
+
timeoutMs: 3000,
|
|
23
|
+
connections: [],
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const row = (id: string) => ({
|
|
27
|
+
id,
|
|
28
|
+
topic: "events.probe",
|
|
29
|
+
message_key: `o-${id}`,
|
|
30
|
+
envelope: { eventId: `o-${id}`, eventName: "probe.ping", payload: {} },
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
const build = async (manager: MockEntityManager) => {
|
|
34
|
+
const transport = mock<EventTransport>()
|
|
35
|
+
const logger = mock<Logger>()
|
|
36
|
+
const moduleRef = await Test.createTestingModule({
|
|
37
|
+
providers: [
|
|
38
|
+
EventRelayService,
|
|
39
|
+
{ provide: EVENT_BUS_OPTIONS, useValue: options },
|
|
40
|
+
{ provide: EVENT_RELAY_MANAGERS, useValue: [manager] },
|
|
41
|
+
{ provide: EVENT_TRANSPORT, useValue: transport },
|
|
42
|
+
{ provide: CLOCK, useValue: new FakeClock(AT) },
|
|
43
|
+
{ provide: LOGGER, useValue: logger },
|
|
44
|
+
],
|
|
45
|
+
}).compile()
|
|
46
|
+
return { relay: moduleRef.get(EventRelayService), transport, logger }
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
describe("EventRelayService", () => {
|
|
50
|
+
describe("relay", () => {
|
|
51
|
+
it("sends the waiting rows in order and marks them sent in the same transaction", async () => {
|
|
52
|
+
const tx = fakeTransaction(
|
|
53
|
+
mockEntityManager({
|
|
54
|
+
query: [
|
|
55
|
+
[SELECT_WAITING_ROWS, [row("1"), row("2")]],
|
|
56
|
+
[MARK_ROWS_SENT, []],
|
|
57
|
+
],
|
|
58
|
+
}),
|
|
59
|
+
)
|
|
60
|
+
const { relay, transport } = await build(tx.em)
|
|
61
|
+
|
|
62
|
+
await expect(relay.relay()).resolves.toBe(2)
|
|
63
|
+
|
|
64
|
+
expect(tx.em.query).toHaveBeenNthCalledWith(1, SELECT_WAITING_ROWS, [2])
|
|
65
|
+
expect(transport.send).toHaveBeenCalledWith([
|
|
66
|
+
{ topic: "events.probe", key: "o-1", value: JSON.stringify(row("1").envelope), headers: {} },
|
|
67
|
+
{ topic: "events.probe", key: "o-2", value: JSON.stringify(row("2").envelope), headers: {} },
|
|
68
|
+
])
|
|
69
|
+
expect(tx.em.query).toHaveBeenNthCalledWith(2, MARK_ROWS_SENT, [["1", "2"], new Date(AT)])
|
|
70
|
+
expect(tx.commits).toBe(1)
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
it("sends nothing and marks nothing when no row waits", async () => {
|
|
74
|
+
const tx = fakeTransaction(mockEntityManager({ query: [SELECT_WAITING_ROWS, []] }))
|
|
75
|
+
const { relay, transport } = await build(tx.em)
|
|
76
|
+
|
|
77
|
+
await expect(relay.relay()).resolves.toBe(0)
|
|
78
|
+
|
|
79
|
+
expect(transport.send).not.toHaveBeenCalled()
|
|
80
|
+
expect(tx.em.query).toHaveBeenCalledTimes(1)
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it("leaves the rows unmarked when the broker refuses, so the next pass sends them again", async () => {
|
|
84
|
+
const tx = fakeTransaction(mockEntityManager({ query: [SELECT_WAITING_ROWS, [row("1")]] }))
|
|
85
|
+
const { relay, transport } = await build(tx.em)
|
|
86
|
+
const failure = new Error("broker down")
|
|
87
|
+
transport.send.mockRejectedValue(failure)
|
|
88
|
+
|
|
89
|
+
await expect(relay.relay()).rejects.toBe(failure)
|
|
90
|
+
|
|
91
|
+
expect(tx.rollbacks).toBe(1)
|
|
92
|
+
expect(tx.em.query).toHaveBeenCalledTimes(1)
|
|
93
|
+
})
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
describe("the loop", () => {
|
|
97
|
+
it("passes again at once after a pass that sent rows, pauses on an empty outbox, logs a failed pass and stops on shutdown", async () => {
|
|
98
|
+
const tx = fakeTransaction(
|
|
99
|
+
mockEntityManager({
|
|
100
|
+
query: [
|
|
101
|
+
[SELECT_WAITING_ROWS, [row("1")]],
|
|
102
|
+
[MARK_ROWS_SENT, []],
|
|
103
|
+
[SELECT_WAITING_ROWS, []],
|
|
104
|
+
],
|
|
105
|
+
}),
|
|
106
|
+
)
|
|
107
|
+
const { relay, transport, logger } = await build(tx.em)
|
|
108
|
+
const failure = new Error("outbox unreadable")
|
|
109
|
+
let waits = 0
|
|
110
|
+
let shutdown: Promise<void> = Promise.resolve()
|
|
111
|
+
let reachedSecondWait: () => void = () => undefined
|
|
112
|
+
const secondWait = new Promise<void>((resolve) => {
|
|
113
|
+
reachedSecondWait = resolve
|
|
114
|
+
})
|
|
115
|
+
transport.wait.mockImplementation(() => {
|
|
116
|
+
waits += 1
|
|
117
|
+
if (waits === 1) tx.em.query.mockRejectedValueOnce(failure)
|
|
118
|
+
else {
|
|
119
|
+
shutdown = relay.onApplicationShutdown()
|
|
120
|
+
reachedSecondWait()
|
|
121
|
+
}
|
|
122
|
+
return Promise.resolve()
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
relay.onApplicationBootstrap()
|
|
126
|
+
await secondWait
|
|
127
|
+
await shutdown
|
|
128
|
+
|
|
129
|
+
expect(transport.send).toHaveBeenCalledTimes(1)
|
|
130
|
+
expect(transport.wait).toHaveBeenCalledWith(100)
|
|
131
|
+
expect(logger.error).toHaveBeenCalledWith(OutboxLogEvent.RelayFailed, failure, {
|
|
132
|
+
outbox: "event-bus",
|
|
133
|
+
})
|
|
134
|
+
})
|
|
135
|
+
})
|
|
136
|
+
})
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Injectable } from "@nestjs/common"
|
|
2
|
+
import type { EntityManager } from "typeorm"
|
|
3
|
+
import { InjectClock } from "@modules/platform/clock"
|
|
4
|
+
import type { Clock } from "@modules/platform/clock"
|
|
5
|
+
import { InjectLogger } from "@modules/platform/logging"
|
|
6
|
+
import type { Logger } from "@modules/platform/logging"
|
|
7
|
+
import { OutboxRelayPolicy } from "@modules/platform/outbox"
|
|
8
|
+
import { InjectEventBusOptions, InjectEventRelayManagers, InjectEventTransport } from "./event-bus.decorators"
|
|
9
|
+
import type { EventBusOptions } from "./event-bus.options"
|
|
10
|
+
import type { EventTransport, OutboundMessage } from "./event-transport.port"
|
|
11
|
+
import { MARK_ROWS_SENT, SELECT_WAITING_ROWS } from "./persistence/event-bus.sql"
|
|
12
|
+
import type { OutboxRow } from "./persistence/event-bus.rows"
|
|
13
|
+
|
|
14
|
+
/** The message the broker receives for one outbox row. */
|
|
15
|
+
const messageOf = (row: OutboxRow): OutboundMessage => ({
|
|
16
|
+
topic: row.topic,
|
|
17
|
+
key: row.message_key,
|
|
18
|
+
value: JSON.stringify(row.envelope),
|
|
19
|
+
headers: {},
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
@Injectable()
|
|
23
|
+
/**
|
|
24
|
+
* The relay of the event outbox: it hands the waiting rows of each connection to the broker and marks them sent in the same
|
|
25
|
+
* transaction (the loop is `OutboxRelayPolicy`'s). A crash between the send and the mark sends the row again, which the consumers
|
|
26
|
+
* absorb through their inbox.
|
|
27
|
+
*/
|
|
28
|
+
export class EventRelayService extends OutboxRelayPolicy<OutboxRow> {
|
|
29
|
+
protected readonly outbox = "event-bus"
|
|
30
|
+
|
|
31
|
+
constructor(
|
|
32
|
+
@InjectEventBusOptions() private readonly options: EventBusOptions,
|
|
33
|
+
@InjectEventRelayManagers() protected readonly managers: ReadonlyArray<EntityManager>,
|
|
34
|
+
@InjectEventTransport() private readonly transport: EventTransport,
|
|
35
|
+
@InjectClock() private readonly clock: Clock,
|
|
36
|
+
@InjectLogger() protected readonly logger: Logger,
|
|
37
|
+
) {
|
|
38
|
+
super()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
protected select(tx: EntityManager): Promise<Array<OutboxRow>> {
|
|
42
|
+
return tx.query(SELECT_WAITING_ROWS, [this.options.relayBatch])
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
protected deliver(rows: ReadonlyArray<OutboxRow>): Promise<void> {
|
|
46
|
+
return this.transport.send(rows.map(messageOf))
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
protected async mark(tx: EntityManager, rows: ReadonlyArray<OutboxRow>): Promise<void> {
|
|
50
|
+
await tx.query(MARK_ROWS_SENT, [rows.map((row) => row.id), this.clock.now()])
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
protected idle(): Promise<void> {
|
|
54
|
+
return this.transport.wait(this.options.relayIntervalMs)
|
|
55
|
+
}
|
|
56
|
+
}
|