@pattern-stack/codegen 0.10.0 → 0.11.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/CHANGELOG.md +135 -0
- package/README.md +5 -5
- package/consumer-skills/codegen/SKILL.md +2 -2
- package/consumer-skills/events/typed-bus-and-outbox.md +1 -1
- package/consumer-skills/{sync → integration}/SKILL.md +29 -29
- package/consumer-skills/{sync → integration}/audit-and-detection.md +22 -22
- package/consumer-skills/{sync → integration}/change-sources-and-sinks.md +60 -60
- package/consumer-skills/subsystems/SKILL.md +64 -8
- package/consumer-skills/subsystems/wiring-and-order.md +7 -7
- package/dist/runtime/base-classes/index.d.ts +4 -4
- package/dist/runtime/base-classes/index.js +35 -35
- package/dist/runtime/base-classes/index.js.map +1 -1
- package/dist/runtime/base-classes/{synced-entity-repository.d.ts → integrated-entity-repository.d.ts} +15 -15
- package/dist/runtime/base-classes/{synced-entity-repository.js → integrated-entity-repository.js} +21 -21
- package/dist/runtime/base-classes/integrated-entity-repository.js.map +1 -0
- package/dist/runtime/base-classes/{synced-entity-service.d.ts → integrated-entity-service.d.ts} +6 -6
- package/dist/runtime/base-classes/{synced-entity-service.js → integrated-entity-service.js} +4 -4
- package/dist/runtime/base-classes/integrated-entity-service.js.map +1 -0
- package/dist/runtime/base-classes/{sync-upsert-config.d.ts → integration-upsert-config.d.ts} +13 -13
- package/dist/runtime/base-classes/integration-upsert-config.js +1 -0
- package/dist/runtime/base-classes/{junction-sync-repository.d.ts → junction-integration-repository.d.ts} +11 -11
- package/dist/runtime/base-classes/{junction-sync-repository.js → junction-integration-repository.js} +15 -15
- package/dist/runtime/base-classes/junction-integration-repository.js.map +1 -0
- package/dist/runtime/subsystems/auth/auth-oauth-state.schema.js.map +1 -1
- package/dist/runtime/subsystems/auth/auth.module.d.ts +4 -4
- package/dist/runtime/subsystems/auth/auth.module.js +3 -3
- package/dist/runtime/subsystems/auth/auth.module.js.map +1 -1
- package/dist/runtime/subsystems/auth/auth.tokens.d.ts +8 -8
- package/dist/runtime/subsystems/auth/auth.tokens.js +6 -6
- package/dist/runtime/subsystems/auth/auth.tokens.js.map +1 -1
- package/dist/runtime/subsystems/auth/backends/state-store.drizzle-backend.js.map +1 -1
- package/dist/runtime/subsystems/auth/controllers/auth.controller.d.ts +2 -2
- package/dist/runtime/subsystems/auth/controllers/auth.controller.js +3 -3
- package/dist/runtime/subsystems/auth/controllers/auth.controller.js.map +1 -1
- package/dist/runtime/subsystems/auth/index.d.ts +3 -3
- package/dist/runtime/subsystems/auth/index.js +40 -40
- package/dist/runtime/subsystems/auth/index.js.map +1 -1
- package/dist/runtime/subsystems/auth/middleware/requester-context.js.map +1 -1
- package/dist/runtime/subsystems/auth/protocols/auth-strategy.d.ts +3 -3
- package/dist/runtime/subsystems/auth/protocols/{integration-store.d.ts → connection-store.d.ts} +20 -20
- package/dist/runtime/subsystems/auth/protocols/connection-store.js +1 -0
- package/dist/runtime/subsystems/auth/protocols/provider-strategy.d.ts +3 -3
- package/dist/runtime/subsystems/auth/runtime/{integration-broken.error.d.ts → connection-broken.error.d.ts} +5 -5
- package/dist/runtime/subsystems/auth/runtime/connection-broken.error.js +19 -0
- package/dist/runtime/subsystems/auth/runtime/connection-broken.error.js.map +1 -0
- package/dist/runtime/subsystems/auth/runtime/oauth2-refresh.strategy.d.ts +10 -10
- package/dist/runtime/subsystems/auth/runtime/oauth2-refresh.strategy.js +28 -28
- package/dist/runtime/subsystems/auth/runtime/oauth2-refresh.strategy.js.map +1 -1
- package/dist/runtime/subsystems/auth/runtime/with-auth-retry.d.ts +1 -1
- package/dist/runtime/subsystems/auth/runtime/with-auth-retry.js +3 -3
- package/dist/runtime/subsystems/auth/runtime/with-auth-retry.js.map +1 -1
- package/dist/runtime/subsystems/bridge/bridge.module.d.ts +0 -1
- package/dist/runtime/subsystems/bridge/bridge.module.js +294 -710
- package/dist/runtime/subsystems/bridge/bridge.module.js.map +1 -1
- package/dist/runtime/subsystems/bridge/index.d.ts +0 -1
- package/dist/runtime/subsystems/bridge/index.js +248 -664
- package/dist/runtime/subsystems/bridge/index.js.map +1 -1
- package/dist/runtime/subsystems/events/event-bus.drizzle-backend.js +18 -10
- package/dist/runtime/subsystems/events/event-bus.drizzle-backend.js.map +1 -1
- package/dist/runtime/subsystems/events/events.module.js +43 -244
- package/dist/runtime/subsystems/events/events.module.js.map +1 -1
- package/dist/runtime/subsystems/events/index.d.ts +0 -1
- package/dist/runtime/subsystems/events/index.js +39 -241
- package/dist/runtime/subsystems/events/index.js.map +1 -1
- package/dist/runtime/subsystems/index.d.ts +7 -7
- package/dist/runtime/subsystems/index.js +222 -839
- package/dist/runtime/subsystems/index.js.map +1 -1
- package/dist/runtime/subsystems/{sync → integration}/build-change-source.d.ts +3 -3
- package/dist/runtime/subsystems/{sync → integration}/build-change-source.js +3 -3
- package/dist/runtime/subsystems/integration/build-change-source.js.map +1 -0
- package/dist/runtime/subsystems/{sync → integration}/deep-equal.differ.d.ts +2 -2
- package/dist/runtime/subsystems/{sync → integration}/deep-equal.differ.js +1 -1
- package/dist/runtime/subsystems/integration/deep-equal.differ.js.map +1 -0
- package/dist/runtime/subsystems/{sync → integration}/detection-config.schema.d.ts +3 -3
- package/dist/runtime/subsystems/{sync → integration}/detection-config.schema.js +1 -1
- package/dist/runtime/subsystems/integration/detection-config.schema.js.map +1 -0
- package/dist/runtime/subsystems/{sync/execute-sync.use-case.d.ts → integration/execute-integration.use-case.d.ts} +13 -13
- package/dist/runtime/subsystems/{sync/execute-sync.use-case.js → integration/execute-integration.use-case.js} +30 -30
- package/dist/runtime/subsystems/integration/execute-integration.use-case.js.map +1 -0
- package/dist/runtime/subsystems/integration/index.d.ts +28 -0
- package/dist/runtime/subsystems/{sync → integration}/index.js +171 -171
- package/dist/runtime/subsystems/integration/index.js.map +1 -0
- package/dist/runtime/subsystems/{sync/sync-audit.schema.d.ts → integration/integration-audit.schema.d.ts} +64 -64
- package/dist/runtime/subsystems/{sync/sync-audit.schema.js → integration/integration-audit.schema.js} +47 -47
- package/dist/runtime/subsystems/integration/integration-audit.schema.js.map +1 -0
- package/dist/runtime/subsystems/{sync/sync-change-source.protocol.d.ts → integration/integration-change-source.protocol.d.ts} +10 -10
- package/dist/runtime/subsystems/integration/integration-change-source.protocol.js +1 -0
- package/dist/runtime/subsystems/{sync/sync-cursor-store.drizzle-backend.d.ts → integration/integration-cursor-store.drizzle-backend.d.ts} +1 -1
- package/dist/runtime/subsystems/{sync/sync-cursor-store.drizzle-backend.js → integration/integration-cursor-store.drizzle-backend.js} +65 -65
- package/dist/runtime/subsystems/integration/integration-cursor-store.drizzle-backend.js.map +1 -0
- package/dist/runtime/subsystems/{sync/sync-cursor-store.memory-backend.d.ts → integration/integration-cursor-store.memory-backend.d.ts} +6 -6
- package/dist/runtime/subsystems/{sync/sync-cursor-store.memory-backend.js → integration/integration-cursor-store.memory-backend.js} +5 -5
- package/dist/runtime/subsystems/integration/integration-cursor-store.memory-backend.js.map +1 -0
- package/dist/runtime/subsystems/{sync/sync-cursor-store.protocol.d.ts → integration/integration-cursor-store.protocol.d.ts} +13 -13
- package/dist/runtime/subsystems/integration/integration-cursor-store.protocol.js +1 -0
- package/dist/runtime/subsystems/{sync/sync-errors.d.ts → integration/integration-errors.d.ts} +2 -2
- package/dist/runtime/subsystems/{sync/sync-errors.js → integration/integration-errors.js} +3 -3
- package/dist/runtime/subsystems/integration/integration-errors.js.map +1 -0
- package/dist/runtime/subsystems/{sync/sync-field-diff.protocol.d.ts → integration/integration-field-diff.protocol.d.ts} +2 -2
- package/dist/runtime/subsystems/{sync/sync-field-diff.protocol.js → integration/integration-field-diff.protocol.js} +2 -2
- package/dist/runtime/subsystems/integration/integration-field-diff.protocol.js.map +1 -0
- package/dist/runtime/subsystems/{sync/sync-loopback.protocol.d.ts → integration/integration-loopback.protocol.d.ts} +2 -2
- package/dist/runtime/subsystems/integration/integration-loopback.protocol.js +1 -0
- package/dist/runtime/subsystems/{sync/sync-middleware.protocol.d.ts → integration/integration-middleware.protocol.d.ts} +5 -5
- package/dist/runtime/subsystems/integration/integration-middleware.protocol.js +1 -0
- package/dist/runtime/subsystems/{sync/sync-run-recorder.drizzle-backend.d.ts → integration/integration-run-recorder.drizzle-backend.d.ts} +5 -5
- package/dist/runtime/subsystems/{sync/sync-run-recorder.drizzle-backend.js → integration/integration-run-recorder.drizzle-backend.js} +73 -73
- package/dist/runtime/subsystems/integration/integration-run-recorder.drizzle-backend.js.map +1 -0
- package/dist/runtime/subsystems/{sync/sync-run-recorder.memory-backend.d.ts → integration/integration-run-recorder.memory-backend.d.ts} +15 -15
- package/dist/runtime/subsystems/{sync/sync-run-recorder.memory-backend.js → integration/integration-run-recorder.memory-backend.js} +11 -11
- package/dist/runtime/subsystems/integration/integration-run-recorder.memory-backend.js.map +1 -0
- package/dist/runtime/subsystems/{sync/sync-run-recorder.protocol.d.ts → integration/integration-run-recorder.protocol.d.ts} +25 -25
- package/dist/runtime/subsystems/integration/integration-run-recorder.protocol.js +1 -0
- package/dist/runtime/subsystems/{sync/sync-sink.protocol.d.ts → integration/integration-sink.protocol.d.ts} +5 -5
- package/dist/runtime/subsystems/integration/integration-sink.protocol.js +1 -0
- package/dist/runtime/subsystems/{sync/sync.module.d.ts → integration/integration.module.d.ts} +24 -24
- package/dist/runtime/subsystems/{sync/sync.module.js → integration/integration.module.js} +132 -132
- package/dist/runtime/subsystems/integration/integration.module.js.map +1 -0
- package/dist/runtime/subsystems/integration/integration.tokens.d.ts +47 -0
- package/dist/runtime/subsystems/integration/integration.tokens.js +18 -0
- package/dist/runtime/subsystems/integration/integration.tokens.js.map +1 -0
- package/dist/runtime/subsystems/{sync → integration}/loopback.middleware.d.ts +5 -5
- package/dist/runtime/subsystems/{sync → integration}/loopback.middleware.js +1 -1
- package/dist/runtime/subsystems/integration/loopback.middleware.js.map +1 -0
- package/dist/runtime/subsystems/{sync → integration}/poll-change-source.d.ts +5 -5
- package/dist/runtime/subsystems/{sync → integration}/poll-change-source.js +1 -1
- package/dist/runtime/subsystems/integration/poll-change-source.js.map +1 -0
- package/dist/runtime/subsystems/{sync → integration}/webhook-change-source.d.ts +5 -5
- package/dist/runtime/subsystems/{sync → integration}/webhook-change-source.js +1 -1
- package/dist/runtime/subsystems/integration/webhook-change-source.js.map +1 -0
- package/dist/runtime/subsystems/jobs/bullmq.config.d.ts +22 -3
- package/dist/runtime/subsystems/jobs/bullmq.config.js.map +1 -1
- package/dist/runtime/subsystems/jobs/index.d.ts +1 -4
- package/dist/runtime/subsystems/jobs/index.js +87 -506
- package/dist/runtime/subsystems/jobs/index.js.map +1 -1
- package/dist/runtime/subsystems/jobs/job-orchestrator.bullmq-backend.js.map +1 -1
- package/dist/runtime/subsystems/jobs/job-worker.bullmq-backend.js +3 -0
- package/dist/runtime/subsystems/jobs/job-worker.bullmq-backend.js.map +1 -1
- package/dist/runtime/subsystems/jobs/job-worker.module.d.ts +10 -3
- package/dist/runtime/subsystems/jobs/job-worker.module.js +248 -664
- package/dist/runtime/subsystems/jobs/job-worker.module.js.map +1 -1
- package/dist/runtime/subsystems/jobs/jobs-domain.module.d.ts +0 -1
- package/dist/runtime/subsystems/jobs/jobs-domain.module.js +89 -391
- package/dist/runtime/subsystems/jobs/jobs-domain.module.js.map +1 -1
- package/dist/runtime/subsystems/observability/index.d.ts +4 -4
- package/dist/runtime/subsystems/observability/index.js +11 -11
- package/dist/runtime/subsystems/observability/index.js.map +1 -1
- package/dist/runtime/subsystems/observability/observability.module.d.ts +2 -2
- package/dist/runtime/subsystems/observability/observability.module.js +11 -11
- package/dist/runtime/subsystems/observability/observability.module.js.map +1 -1
- package/dist/runtime/subsystems/observability/observability.protocol.d.ts +11 -11
- package/dist/runtime/subsystems/observability/observability.service.d.ts +6 -6
- package/dist/runtime/subsystems/observability/observability.service.js +11 -11
- package/dist/runtime/subsystems/observability/observability.service.js.map +1 -1
- package/dist/runtime/subsystems/observability/observability.tokens.d.ts +1 -1
- package/dist/runtime/subsystems/observability/observability.tokens.js.map +1 -1
- package/dist/runtime/subsystems/observability/reporters/bridge-metrics.reporter.d.ts +3 -3
- package/dist/runtime/subsystems/observability/reporters/bridge-metrics.reporter.js.map +1 -1
- package/dist/runtime/subsystems/observability/reporters/index.d.ts +3 -3
- package/dist/runtime/subsystems/observability/reporters/index.js.map +1 -1
- package/dist/src/cli/index.js +412 -302
- package/dist/src/cli/index.js.map +1 -1
- package/dist/src/index.d.ts +22 -22
- package/dist/src/index.js +191 -191
- package/dist/src/index.js.map +1 -1
- package/examples/auth-integrations/README.md +32 -32
- package/examples/auth-integrations/definitions/entities/{integration.yaml → connection.yaml} +10 -10
- package/examples/auth-integrations/runtime/{integrations/adapters/integration-grant-sink.adapter.ts → connections/adapters/connection-grant-sink.adapter.ts} +7 -7
- package/examples/auth-integrations/runtime/{integrations/adapters/integration-reader.adapter.ts → connections/adapters/connection-reader.adapter.ts} +10 -10
- package/examples/auth-integrations/runtime/{integrations/adapters/integration-token-writer.adapter.ts → connections/adapters/connection-token-writer.adapter.ts} +11 -11
- package/examples/auth-integrations/runtime/connections/connections-auth.module.ts +81 -0
- package/examples/auth-integrations/runtime/{integrations/facade/integrations.service.ts → connections/facade/connections.service.ts} +35 -35
- package/examples/auth-integrations/runtime/{integrations → connections}/oauth/use-cases/create-or-update-from-oauth-grant.use-case.ts +11 -11
- package/examples/auth-integrations/runtime/{integrations/oauth/use-cases/disconnect-integration.use-case.ts → connections/oauth/use-cases/disconnect-connection.use-case.ts} +6 -6
- package/examples/auth-integrations/runtime/connections/oauth/use-cases/list-user-connections.use-case.ts +21 -0
- package/examples/auth-integrations/runtime/connections/oauth/use-cases/mark-connection-requires-reauth.use-case.ts +21 -0
- package/package.json +1 -1
- package/runtime/base-classes/index.ts +8 -8
- package/runtime/base-classes/{synced-entity-repository.ts → integrated-entity-repository.ts} +36 -36
- package/runtime/base-classes/{synced-entity-service.ts → integrated-entity-service.ts} +6 -6
- package/runtime/base-classes/{sync-upsert-config.ts → integration-upsert-config.ts} +12 -12
- package/runtime/base-classes/{junction-sync-repository.ts → junction-integration-repository.ts} +28 -28
- package/runtime/subsystems/auth/auth-oauth-state.schema.ts +1 -1
- package/runtime/subsystems/auth/auth.module.ts +4 -4
- package/runtime/subsystems/auth/auth.tokens.ts +7 -7
- package/runtime/subsystems/auth/controllers/auth.controller.ts +7 -7
- package/runtime/subsystems/auth/index.ts +19 -19
- package/runtime/subsystems/auth/protocols/auth-strategy.ts +3 -3
- package/runtime/subsystems/auth/protocols/{integration-store.ts → connection-store.ts} +19 -19
- package/runtime/subsystems/auth/protocols/provider-strategy.ts +2 -2
- package/runtime/subsystems/auth/runtime/{integration-broken.error.ts → connection-broken.error.ts} +5 -5
- package/runtime/subsystems/auth/runtime/oauth2-refresh.strategy.ts +35 -35
- package/runtime/subsystems/auth/runtime/with-auth-retry.ts +3 -3
- package/runtime/subsystems/events/event-bus.drizzle-backend.ts +32 -10
- package/runtime/subsystems/events/events.module.ts +38 -6
- package/runtime/subsystems/events/index.ts +7 -1
- package/runtime/subsystems/index.ts +11 -11
- package/runtime/subsystems/{sync → integration}/build-change-source.ts +3 -3
- package/runtime/subsystems/{sync → integration}/deep-equal.differ.ts +7 -7
- package/runtime/subsystems/{sync → integration}/detection-config.schema.ts +3 -3
- package/runtime/subsystems/{sync/execute-sync.use-case.ts → integration/execute-integration.use-case.ts} +40 -40
- package/runtime/subsystems/{sync → integration}/index.ts +47 -47
- package/runtime/subsystems/{sync/sync-audit.schema.ts → integration/integration-audit.schema.ts} +61 -61
- package/runtime/subsystems/{sync/sync-change-source.protocol.ts → integration/integration-change-source.protocol.ts} +9 -9
- package/runtime/subsystems/{sync/sync-cursor-store.drizzle-backend.ts → integration/integration-cursor-store.drizzle-backend.ts} +30 -30
- package/runtime/subsystems/{sync/sync-cursor-store.memory-backend.ts → integration/integration-cursor-store.memory-backend.ts} +9 -9
- package/runtime/subsystems/{sync/sync-cursor-store.protocol.ts → integration/integration-cursor-store.protocol.ts} +13 -13
- package/runtime/subsystems/{sync/sync-errors.ts → integration/integration-errors.ts} +3 -3
- package/runtime/subsystems/{sync/sync-field-diff.protocol.ts → integration/integration-field-diff.protocol.ts} +2 -2
- package/runtime/subsystems/{sync/sync-loopback.protocol.ts → integration/integration-loopback.protocol.ts} +2 -2
- package/runtime/subsystems/{sync/sync-middleware.protocol.ts → integration/integration-middleware.protocol.ts} +6 -6
- package/runtime/subsystems/{sync/sync-run-recorder.drizzle-backend.ts → integration/integration-run-recorder.drizzle-backend.ts} +39 -39
- package/runtime/subsystems/{sync/sync-run-recorder.memory-backend.ts → integration/integration-run-recorder.memory-backend.ts} +23 -23
- package/runtime/subsystems/{sync/sync-run-recorder.protocol.ts → integration/integration-run-recorder.protocol.ts} +25 -25
- package/runtime/subsystems/{sync/sync-sink.protocol.ts → integration/integration-sink.protocol.ts} +4 -4
- package/runtime/subsystems/{sync/sync.module.ts → integration/integration.module.ts} +48 -48
- package/runtime/subsystems/integration/integration.tokens.ts +49 -0
- package/runtime/subsystems/{sync → integration}/loopback.middleware.ts +5 -5
- package/runtime/subsystems/{sync → integration}/poll-change-source.ts +7 -7
- package/runtime/subsystems/{sync → integration}/webhook-change-source.ts +7 -7
- package/runtime/subsystems/jobs/bullmq.config.ts +23 -3
- package/runtime/subsystems/jobs/index.ts +13 -8
- package/runtime/subsystems/jobs/job-worker.bullmq-backend.ts +5 -2
- package/runtime/subsystems/jobs/job-worker.module.ts +27 -7
- package/runtime/subsystems/jobs/jobs-domain.module.ts +27 -2
- package/runtime/subsystems/observability/index.ts +1 -1
- package/runtime/subsystems/observability/observability.module.ts +2 -2
- package/runtime/subsystems/observability/observability.protocol.ts +11 -11
- package/runtime/subsystems/observability/observability.service.ts +13 -13
- package/runtime/subsystems/observability/observability.tokens.ts +1 -1
- package/src/patterns/library/index.ts +4 -4
- package/src/patterns/library/{synced.pattern.ts → integrated.pattern.ts} +12 -12
- package/src/patterns/library/junction.pattern.ts +1 -1
- package/src/patterns/pattern-definition.ts +3 -3
- package/templates/entity/new/backend/modules/core/{sync-source.ejs.t → integration-source.ejs.t} +6 -6
- package/templates/entity/new/backend/modules/core/{sync-source.providers.ejs.t → integration-source.providers.ejs.t} +2 -2
- package/templates/entity/new/clean-lite-ps/entity.ejs.t +1 -1
- package/templates/entity/new/clean-lite-ps/module.ejs.t +1 -1
- package/templates/entity/new/clean-lite-ps/prompt-extension.js +33 -33
- package/templates/entity/new/clean-lite-ps/repository.ejs.t +27 -27
- package/templates/entity/new/frontend/collections/collection.ejs.t +26 -1
- package/templates/entity/new/frontend/collections/collections-base.ejs.t +11 -0
- package/templates/entity/new/frontend/entity/combined.ejs.t +31 -1
- package/templates/entity/new/prompt.js +27 -15
- package/templates/junction/new/entity.ejs.t +1 -1
- package/templates/junction/new/prompt.js +24 -24
- package/templates/junction/new/repository.ejs.t +19 -19
- package/templates/subsystem/auth/auth-oauth-state.schema.ejs.t +2 -2
- package/templates/subsystem/auth-config/prompt.js +1 -1
- package/templates/subsystem/auth-integrations/app-module-hook.ejs.t +5 -5
- package/templates/subsystem/bridge/prompt.js +1 -1
- package/templates/subsystem/events/domain-events.schema.ejs.t +43 -2
- package/templates/subsystem/integration/integration-audit.schema.ejs.t +192 -0
- package/templates/subsystem/{sync → integration}/prompt.js +12 -12
- package/templates/subsystem/{sync-config/codegen-config-sync-block.ejs.t → integration-config/codegen-config-integration-block.ejs.t} +7 -7
- package/templates/subsystem/integration-config/prompt.js +22 -0
- package/templates/subsystem/jobs/worker.ejs.t +2 -2
- package/templates/subsystem/observability/main-hook.ejs.t +1 -1
- package/templates/subsystem/observability/prompt.js +1 -1
- package/templates/subsystem/openapi-config/prompt.js +1 -1
- package/dist/runtime/base-classes/junction-sync-repository.js.map +0 -1
- package/dist/runtime/base-classes/sync-upsert-config.js +0 -1
- package/dist/runtime/base-classes/synced-entity-repository.js.map +0 -1
- package/dist/runtime/base-classes/synced-entity-service.js.map +0 -1
- package/dist/runtime/subsystems/auth/protocols/integration-store.js +0 -1
- package/dist/runtime/subsystems/auth/runtime/integration-broken.error.js +0 -19
- package/dist/runtime/subsystems/auth/runtime/integration-broken.error.js.map +0 -1
- package/dist/runtime/subsystems/sync/build-change-source.js.map +0 -1
- package/dist/runtime/subsystems/sync/deep-equal.differ.js.map +0 -1
- package/dist/runtime/subsystems/sync/detection-config.schema.js.map +0 -1
- package/dist/runtime/subsystems/sync/execute-sync.use-case.js.map +0 -1
- package/dist/runtime/subsystems/sync/index.d.ts +0 -28
- package/dist/runtime/subsystems/sync/index.js.map +0 -1
- package/dist/runtime/subsystems/sync/loopback.middleware.js.map +0 -1
- package/dist/runtime/subsystems/sync/poll-change-source.js.map +0 -1
- package/dist/runtime/subsystems/sync/sync-audit.schema.js.map +0 -1
- package/dist/runtime/subsystems/sync/sync-change-source.protocol.js +0 -1
- package/dist/runtime/subsystems/sync/sync-cursor-store.drizzle-backend.js.map +0 -1
- package/dist/runtime/subsystems/sync/sync-cursor-store.memory-backend.js.map +0 -1
- package/dist/runtime/subsystems/sync/sync-cursor-store.protocol.js +0 -1
- package/dist/runtime/subsystems/sync/sync-errors.js.map +0 -1
- package/dist/runtime/subsystems/sync/sync-field-diff.protocol.js.map +0 -1
- package/dist/runtime/subsystems/sync/sync-loopback.protocol.js +0 -1
- package/dist/runtime/subsystems/sync/sync-middleware.protocol.js +0 -1
- package/dist/runtime/subsystems/sync/sync-run-recorder.drizzle-backend.js.map +0 -1
- package/dist/runtime/subsystems/sync/sync-run-recorder.memory-backend.js.map +0 -1
- package/dist/runtime/subsystems/sync/sync-run-recorder.protocol.js +0 -1
- package/dist/runtime/subsystems/sync/sync-sink.protocol.js +0 -1
- package/dist/runtime/subsystems/sync/sync.module.js.map +0 -1
- package/dist/runtime/subsystems/sync/sync.tokens.d.ts +0 -47
- package/dist/runtime/subsystems/sync/sync.tokens.js +0 -18
- package/dist/runtime/subsystems/sync/sync.tokens.js.map +0 -1
- package/dist/runtime/subsystems/sync/webhook-change-source.js.map +0 -1
- package/examples/auth-integrations/runtime/integrations/integrations-auth.module.ts +0 -81
- package/examples/auth-integrations/runtime/integrations/oauth/use-cases/list-user-integrations.use-case.ts +0 -21
- package/examples/auth-integrations/runtime/integrations/oauth/use-cases/mark-integration-requires-reauth.use-case.ts +0 -21
- package/runtime/subsystems/sync/sync.tokens.ts +0 -49
- package/templates/subsystem/sync/sync-audit.schema.ejs.t +0 -192
- package/templates/subsystem/sync-config/prompt.js +0 -22
- /package/dist/runtime/base-classes/{sync-upsert-config.js.map → integration-upsert-config.js.map} +0 -0
- /package/dist/runtime/subsystems/auth/protocols/{integration-store.js.map → connection-store.js.map} +0 -0
- /package/dist/runtime/subsystems/{sync/sync-change-source.protocol.js.map → integration/integration-change-source.protocol.js.map} +0 -0
- /package/dist/runtime/subsystems/{sync/sync-cursor-store.protocol.js.map → integration/integration-cursor-store.protocol.js.map} +0 -0
- /package/dist/runtime/subsystems/{sync/sync-loopback.protocol.js.map → integration/integration-loopback.protocol.js.map} +0 -0
- /package/dist/runtime/subsystems/{sync/sync-middleware.protocol.js.map → integration/integration-middleware.protocol.js.map} +0 -0
- /package/dist/runtime/subsystems/{sync/sync-run-recorder.protocol.js.map → integration/integration-run-recorder.protocol.js.map} +0 -0
- /package/dist/runtime/subsystems/{sync/sync-sink.protocol.js.map → integration/integration-sink.protocol.js.map} +0 -0
|
@@ -362,13 +362,12 @@ var BRIDGE_OUTBOX_DRAIN_HOOK = "BRIDGE_OUTBOX_DRAIN_HOOK";
|
|
|
362
362
|
// runtime/subsystems/events/event-bus.drizzle-backend.ts
|
|
363
363
|
var POLL_INTERVAL_MS = 1e3;
|
|
364
364
|
var POLL_BATCH_SIZE = 50;
|
|
365
|
-
function toInsertValues(event) {
|
|
365
|
+
function toInsertValues(event, multiTenant) {
|
|
366
366
|
const metadata = event.metadata ?? void 0;
|
|
367
367
|
const pool = metadata?.["pool"] ?? null;
|
|
368
368
|
const direction = metadata?.["direction"] ?? null;
|
|
369
|
-
const tenantId = metadata?.["tenantId"] ?? null;
|
|
370
369
|
const tier = metadata?.["tier"] ?? "domain";
|
|
371
|
-
|
|
370
|
+
const base = {
|
|
372
371
|
id: event.id,
|
|
373
372
|
type: event.type,
|
|
374
373
|
aggregateId: event.aggregateId,
|
|
@@ -380,9 +379,11 @@ function toInsertValues(event) {
|
|
|
380
379
|
metadata: event.metadata,
|
|
381
380
|
pool,
|
|
382
381
|
direction,
|
|
383
|
-
tier
|
|
384
|
-
tenantId
|
|
382
|
+
tier
|
|
385
383
|
};
|
|
384
|
+
if (!multiTenant) return base;
|
|
385
|
+
const tenantId = metadata?.["tenantId"] ?? null;
|
|
386
|
+
return { ...base, tenantId };
|
|
386
387
|
}
|
|
387
388
|
function toEventSummary(r) {
|
|
388
389
|
const metadata = r.metadata ?? void 0;
|
|
@@ -397,7 +398,11 @@ function toEventSummary(r) {
|
|
|
397
398
|
direction: r.direction,
|
|
398
399
|
tier: r.tier,
|
|
399
400
|
rootRunId: typeof rootRunId === "string" ? rootRunId : null,
|
|
400
|
-
|
|
401
|
+
// EVT-8: `tenant_id` is a scaffold-time conditional column. Read it
|
|
402
|
+
// structurally so this projection typechecks against both the
|
|
403
|
+
// multi-tenant schema (column present) and the single-tenant schema
|
|
404
|
+
// (column absent → undefined → null).
|
|
405
|
+
tenantId: r.tenantId ?? null,
|
|
401
406
|
occurredAt: r.occurredAt instanceof Date ? r.occurredAt : new Date(r.occurredAt),
|
|
402
407
|
processedAt: r.processedAt == null ? null : r.processedAt instanceof Date ? r.processedAt : new Date(r.processedAt)
|
|
403
408
|
};
|
|
@@ -434,12 +439,14 @@ var DrizzleEventBus = class {
|
|
|
434
439
|
// ============================================================================
|
|
435
440
|
async publish(event, tx) {
|
|
436
441
|
const client = tx ?? this.db;
|
|
437
|
-
|
|
442
|
+
const multiTenant = this.opts.multiTenant ?? false;
|
|
443
|
+
await client.insert(domainEvents).values(toInsertValues(event, multiTenant));
|
|
438
444
|
}
|
|
439
445
|
async publishMany(events, tx) {
|
|
440
446
|
if (events.length === 0) return;
|
|
441
447
|
const client = tx ?? this.db;
|
|
442
|
-
|
|
448
|
+
const multiTenant = this.opts.multiTenant ?? false;
|
|
449
|
+
await client.insert(domainEvents).values(events.map((e) => toInsertValues(e, multiTenant)));
|
|
443
450
|
}
|
|
444
451
|
async findById(eventId) {
|
|
445
452
|
const rows = await this.db.select().from(domainEvents).where(eq(domainEvents.id, eventId)).limit(1);
|
|
@@ -481,9 +488,10 @@ var DrizzleEventBus = class {
|
|
|
481
488
|
sql2`${domainEvents.metadata}->>'rootRunId' = ${query.rootRunId}`
|
|
482
489
|
);
|
|
483
490
|
}
|
|
484
|
-
if (query.tenantId !== void 0) {
|
|
491
|
+
if (this.opts.multiTenant && query.tenantId !== void 0) {
|
|
492
|
+
const tenantIdColumn = domainEvents.tenantId;
|
|
485
493
|
conditions.push(
|
|
486
|
-
query.tenantId === null ? sql2`${
|
|
494
|
+
query.tenantId === null ? sql2`${tenantIdColumn} is null` : eq(tenantIdColumn, query.tenantId)
|
|
487
495
|
);
|
|
488
496
|
}
|
|
489
497
|
if (query.cursor) {
|
|
@@ -814,233 +822,12 @@ MemoryEventBus = __decorateClass([
|
|
|
814
822
|
__decorateParam(0, Inject3(EVENTS_MODULE_OPTIONS))
|
|
815
823
|
], MemoryEventBus);
|
|
816
824
|
|
|
817
|
-
// runtime/subsystems/events/event-bus.redis-backend.ts
|
|
818
|
-
import { Injectable as Injectable4, Inject as Inject4, Logger as Logger3 } from "@nestjs/common";
|
|
819
|
-
var CHANNEL_PREFIX = "events:";
|
|
820
|
-
async function createRedisClient(url) {
|
|
821
|
-
let Redis;
|
|
822
|
-
try {
|
|
823
|
-
const mod = await import("ioredis");
|
|
824
|
-
Redis = mod.default ?? mod;
|
|
825
|
-
} catch {
|
|
826
|
-
throw new Error(
|
|
827
|
-
'RedisEventBus requires the "ioredis" package. Install it with: npm install ioredis'
|
|
828
|
-
);
|
|
829
|
-
}
|
|
830
|
-
return new Redis(url);
|
|
831
|
-
}
|
|
832
|
-
var RedisEventBus = class {
|
|
833
|
-
constructor(redisUrl) {
|
|
834
|
-
this.redisUrl = redisUrl;
|
|
835
|
-
}
|
|
836
|
-
redisUrl;
|
|
837
|
-
logger = new Logger3(RedisEventBus.name);
|
|
838
|
-
publisher = null;
|
|
839
|
-
subscriber = null;
|
|
840
|
-
connected = false;
|
|
841
|
-
/**
|
|
842
|
-
* In-process subscriber registry. Handlers registered here are called when
|
|
843
|
-
* a message arrives on the subscriber client — keeping fan-out within the
|
|
844
|
-
* same process without an extra round-trip through Redis.
|
|
845
|
-
*/
|
|
846
|
-
handlers = /* @__PURE__ */ new Map();
|
|
847
|
-
/**
|
|
848
|
-
* Track which event types have active Redis subscriptions.
|
|
849
|
-
* Used to avoid subscribing multiple times to the same type channel.
|
|
850
|
-
*/
|
|
851
|
-
subscribedTypes = /* @__PURE__ */ new Set();
|
|
852
|
-
// ============================================================================
|
|
853
|
-
// Lifecycle
|
|
854
|
-
// ============================================================================
|
|
855
|
-
async onModuleInit() {
|
|
856
|
-
this.publisher = await createRedisClient(this.redisUrl);
|
|
857
|
-
this.subscriber = await createRedisClient(this.redisUrl);
|
|
858
|
-
this.publisher.on(
|
|
859
|
-
"error",
|
|
860
|
-
(err) => this.logger.error(`Redis publisher error: ${err.message}`, err.stack)
|
|
861
|
-
);
|
|
862
|
-
this.subscriber.on(
|
|
863
|
-
"error",
|
|
864
|
-
(err) => this.logger.error(`Redis subscriber error: ${err.message}`, err.stack)
|
|
865
|
-
);
|
|
866
|
-
this.subscriber.on("message", (channel, message) => {
|
|
867
|
-
void this.handleMessage(channel, message);
|
|
868
|
-
});
|
|
869
|
-
this.connected = true;
|
|
870
|
-
this.logger.log(`RedisEventBus connected to ${this.redisUrl}`);
|
|
871
|
-
}
|
|
872
|
-
async onModuleDestroy() {
|
|
873
|
-
this.connected = false;
|
|
874
|
-
if (this.subscriber) {
|
|
875
|
-
await this.subscriber.unsubscribe();
|
|
876
|
-
this.subscriber.disconnect();
|
|
877
|
-
this.subscriber = null;
|
|
878
|
-
}
|
|
879
|
-
if (this.publisher) {
|
|
880
|
-
this.publisher.disconnect();
|
|
881
|
-
this.publisher = null;
|
|
882
|
-
}
|
|
883
|
-
this.subscribedTypes.clear();
|
|
884
|
-
this.logger.log("RedisEventBus disconnected");
|
|
885
|
-
}
|
|
886
|
-
// ============================================================================
|
|
887
|
-
// IEventBus
|
|
888
|
-
// ============================================================================
|
|
889
|
-
/**
|
|
890
|
-
* Publish a single event.
|
|
891
|
-
*
|
|
892
|
-
* `tx` is accepted but ignored — see module-level JSDoc for details.
|
|
893
|
-
*/
|
|
894
|
-
async publish(event, tx) {
|
|
895
|
-
void tx;
|
|
896
|
-
this.assertConnected();
|
|
897
|
-
const payload = this.serialize(event);
|
|
898
|
-
const channel = `${CHANNEL_PREFIX}${event.type}`;
|
|
899
|
-
await this.publisher.publish(channel, payload);
|
|
900
|
-
}
|
|
901
|
-
/**
|
|
902
|
-
* Publish multiple events using a pipeline so all PUBLISH commands are sent
|
|
903
|
-
* in a single round-trip.
|
|
904
|
-
*
|
|
905
|
-
* `tx` is accepted but ignored — see module-level JSDoc for details.
|
|
906
|
-
*/
|
|
907
|
-
async publishMany(events, tx) {
|
|
908
|
-
void tx;
|
|
909
|
-
if (events.length === 0) return;
|
|
910
|
-
this.assertConnected();
|
|
911
|
-
const pipeline = this.publisher.pipeline();
|
|
912
|
-
for (const event of events) {
|
|
913
|
-
const payload = this.serialize(event);
|
|
914
|
-
const channel = `${CHANNEL_PREFIX}${event.type}`;
|
|
915
|
-
pipeline.publish(channel, payload);
|
|
916
|
-
}
|
|
917
|
-
await pipeline.exec();
|
|
918
|
-
}
|
|
919
|
-
/**
|
|
920
|
-
* Register a handler for a specific event type.
|
|
921
|
-
* Returns an unsubscribe function — call it to remove the handler.
|
|
922
|
-
*
|
|
923
|
-
* On first handler for a type, subscribes to the per-type Redis channel.
|
|
924
|
-
* On removal of the last handler for a type, unsubscribes from the channel.
|
|
925
|
-
*/
|
|
926
|
-
/**
|
|
927
|
-
* Lookup by id is unsupported on the Redis Pub/Sub backend — Pub/Sub
|
|
928
|
-
* does not retain history. Always returns `null`. Logs a warning the
|
|
929
|
-
* first time it's called so a misconfiguration surfaces visibly. Using
|
|
930
|
-
* the bridge with the Redis backend is unsupported (the bridge requires
|
|
931
|
-
* a durable event store).
|
|
932
|
-
*/
|
|
933
|
-
warnedFindById = false;
|
|
934
|
-
async findById(_eventId) {
|
|
935
|
-
if (!this.warnedFindById) {
|
|
936
|
-
this.warnedFindById = true;
|
|
937
|
-
this.logger.warn(
|
|
938
|
-
"RedisEventBus.findById is unsupported (Pub/Sub has no history). The bridge subsystem requires a durable event store; switch to DrizzleEventBus if you need bridge fanout."
|
|
939
|
-
);
|
|
940
|
-
}
|
|
941
|
-
return null;
|
|
942
|
-
}
|
|
943
|
-
subscribe(eventType, handler) {
|
|
944
|
-
if (!this.handlers.has(eventType)) {
|
|
945
|
-
this.handlers.set(eventType, /* @__PURE__ */ new Set());
|
|
946
|
-
void this.subscribeToType(eventType);
|
|
947
|
-
}
|
|
948
|
-
const set = this.handlers.get(eventType);
|
|
949
|
-
const h = handler;
|
|
950
|
-
set.add(h);
|
|
951
|
-
return () => {
|
|
952
|
-
set.delete(h);
|
|
953
|
-
if (set.size === 0) {
|
|
954
|
-
this.handlers.delete(eventType);
|
|
955
|
-
void this.unsubscribeFromType(eventType);
|
|
956
|
-
}
|
|
957
|
-
};
|
|
958
|
-
}
|
|
959
|
-
// ============================================================================
|
|
960
|
-
// Internal helpers
|
|
961
|
-
// ============================================================================
|
|
962
|
-
assertConnected() {
|
|
963
|
-
if (!this.connected || !this.publisher) {
|
|
964
|
-
throw new Error(
|
|
965
|
-
"RedisEventBus is not connected. Ensure the module has been initialised before publishing."
|
|
966
|
-
);
|
|
967
|
-
}
|
|
968
|
-
}
|
|
969
|
-
serialize(event) {
|
|
970
|
-
return JSON.stringify({
|
|
971
|
-
...event,
|
|
972
|
-
occurredAt: event.occurredAt.toISOString()
|
|
973
|
-
});
|
|
974
|
-
}
|
|
975
|
-
deserialize(raw) {
|
|
976
|
-
const parsed = JSON.parse(raw);
|
|
977
|
-
return {
|
|
978
|
-
...parsed,
|
|
979
|
-
occurredAt: new Date(parsed.occurredAt)
|
|
980
|
-
};
|
|
981
|
-
}
|
|
982
|
-
async handleMessage(channel, message) {
|
|
983
|
-
let event;
|
|
984
|
-
try {
|
|
985
|
-
event = this.deserialize(message);
|
|
986
|
-
} catch (err) {
|
|
987
|
-
this.logger.warn(`Failed to deserialize event on channel "${channel}": ${err}`);
|
|
988
|
-
return;
|
|
989
|
-
}
|
|
990
|
-
await this.dispatch(event);
|
|
991
|
-
}
|
|
992
|
-
async dispatch(event) {
|
|
993
|
-
const set = this.handlers.get(event.type);
|
|
994
|
-
if (!set) return;
|
|
995
|
-
for (const handler of set) {
|
|
996
|
-
try {
|
|
997
|
-
await handler(event);
|
|
998
|
-
} catch (err) {
|
|
999
|
-
this.logger.error(
|
|
1000
|
-
`Handler error for event type "${event.type}" (id: ${event.id}): ${err}`
|
|
1001
|
-
);
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
|
-
/**
|
|
1006
|
-
* Subscribe to a per-type Redis channel.
|
|
1007
|
-
* Called lazily when the first handler is registered for a type.
|
|
1008
|
-
*/
|
|
1009
|
-
async subscribeToType(eventType) {
|
|
1010
|
-
if (this.subscribedTypes.has(eventType)) {
|
|
1011
|
-
return;
|
|
1012
|
-
}
|
|
1013
|
-
const channel = `${CHANNEL_PREFIX}${eventType}`;
|
|
1014
|
-
try {
|
|
1015
|
-
await this.subscriber.subscribe(channel);
|
|
1016
|
-
this.subscribedTypes.add(eventType);
|
|
1017
|
-
} catch (err) {
|
|
1018
|
-
this.logger.error(`Failed to subscribe to channel "${channel}": ${err}`);
|
|
1019
|
-
}
|
|
1020
|
-
}
|
|
1021
|
-
/**
|
|
1022
|
-
* Unsubscribe from a per-type Redis channel.
|
|
1023
|
-
* Called when the last handler for a type is removed.
|
|
1024
|
-
*/
|
|
1025
|
-
async unsubscribeFromType(eventType) {
|
|
1026
|
-
if (!this.subscribedTypes.has(eventType)) {
|
|
1027
|
-
return;
|
|
1028
|
-
}
|
|
1029
|
-
const channel = `${CHANNEL_PREFIX}${eventType}`;
|
|
1030
|
-
try {
|
|
1031
|
-
await this.subscriber.unsubscribe(channel);
|
|
1032
|
-
this.subscribedTypes.delete(eventType);
|
|
1033
|
-
} catch (err) {
|
|
1034
|
-
this.logger.error(`Failed to unsubscribe from channel "${channel}": ${err}`);
|
|
1035
|
-
}
|
|
1036
|
-
}
|
|
1037
|
-
};
|
|
1038
|
-
RedisEventBus = __decorateClass([
|
|
1039
|
-
Injectable4(),
|
|
1040
|
-
__decorateParam(0, Inject4(REDIS_URL))
|
|
1041
|
-
], RedisEventBus);
|
|
1042
|
-
|
|
1043
825
|
// runtime/subsystems/events/events.module.ts
|
|
826
|
+
async function loadRedisEventBus() {
|
|
827
|
+
const specifier = "./event-bus.redis-backend";
|
|
828
|
+
const mod = await import(specifier);
|
|
829
|
+
return mod.RedisEventBus;
|
|
830
|
+
}
|
|
1044
831
|
function buildTypedBusProviders(multiTenant) {
|
|
1045
832
|
return [
|
|
1046
833
|
TypedEventBus,
|
|
@@ -1048,7 +835,7 @@ function buildTypedBusProviders(multiTenant) {
|
|
|
1048
835
|
{ provide: EVENTS_MULTI_TENANT, useValue: multiTenant }
|
|
1049
836
|
];
|
|
1050
837
|
}
|
|
1051
|
-
function buildEventBusAsync(options, db, redisUrl) {
|
|
838
|
+
async function buildEventBusAsync(options, db, redisUrl) {
|
|
1052
839
|
if (options.backend === "drizzle") {
|
|
1053
840
|
if (!db) {
|
|
1054
841
|
throw new Error(
|
|
@@ -1058,6 +845,7 @@ function buildEventBusAsync(options, db, redisUrl) {
|
|
|
1058
845
|
return new DrizzleEventBus(db, options);
|
|
1059
846
|
}
|
|
1060
847
|
if (options.backend === "redis") {
|
|
848
|
+
const RedisEventBus = await loadRedisEventBus();
|
|
1061
849
|
return new RedisEventBus(redisUrl);
|
|
1062
850
|
}
|
|
1063
851
|
return new MemoryEventBus(options);
|
|
@@ -1119,9 +907,20 @@ var EventsModule = class {
|
|
|
1119
907
|
providers: [
|
|
1120
908
|
{ provide: EVENTS_MODULE_OPTIONS, useValue: options },
|
|
1121
909
|
{ provide: REDIS_URL, useValue: resolvedUrl },
|
|
1122
|
-
{
|
|
1123
|
-
|
|
1124
|
-
|
|
910
|
+
{
|
|
911
|
+
// #6: useFactory + dynamic import so the consumer's tsc never
|
|
912
|
+
// needs to resolve `event-bus.redis-backend.ts` for drizzle/
|
|
913
|
+
// memory installs (the file is filtered out by
|
|
914
|
+
// `backendFileFilter`). Nest awaits async factories + manages
|
|
915
|
+
// lifecycle on the returned instance, so we drop the old bare
|
|
916
|
+
// `RedisEventBus` provider entry.
|
|
917
|
+
provide: EVENT_BUS,
|
|
918
|
+
useFactory: async (url) => {
|
|
919
|
+
const RedisEventBus = await loadRedisEventBus();
|
|
920
|
+
return new RedisEventBus(url);
|
|
921
|
+
},
|
|
922
|
+
inject: [REDIS_URL]
|
|
923
|
+
},
|
|
1125
924
|
...buildTypedBusProviders(multiTenant)
|
|
1126
925
|
],
|
|
1127
926
|
exports: [EVENT_BUS, TYPED_EVENT_BUS, EVENTS_MULTI_TENANT]
|
|
@@ -1324,7 +1123,7 @@ var HandlerRegistry;
|
|
|
1324
1123
|
|
|
1325
1124
|
// runtime/subsystems/jobs/job-orchestrator.drizzle-backend.ts
|
|
1326
1125
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
1327
|
-
import { Inject as
|
|
1126
|
+
import { Inject as Inject4, Injectable as Injectable4, Logger as Logger3 } from "@nestjs/common";
|
|
1328
1127
|
import { and as and2, desc as desc2, eq as eq2, gt, inArray as inArray2, isNotNull, ne, notInArray, sql as sql4 } from "drizzle-orm";
|
|
1329
1128
|
|
|
1330
1129
|
// runtime/subsystems/jobs/jobs-errors.ts
|
|
@@ -1432,7 +1231,7 @@ var DrizzleJobOrchestrator = class {
|
|
|
1432
1231
|
db;
|
|
1433
1232
|
multiTenant;
|
|
1434
1233
|
// TODO(logging-subsystem): swap to ILogger once ADR-028 lands
|
|
1435
|
-
logger = new
|
|
1234
|
+
logger = new Logger3(DrizzleJobOrchestrator.name);
|
|
1436
1235
|
/**
|
|
1437
1236
|
* JOB-8 — resolve `tenantId` for a mutating / targeted-read call.
|
|
1438
1237
|
* Returns the tenant value that should be written to the row (or compared
|
|
@@ -1721,9 +1520,9 @@ var DrizzleJobOrchestrator = class {
|
|
|
1721
1520
|
}
|
|
1722
1521
|
};
|
|
1723
1522
|
DrizzleJobOrchestrator = __decorateClass([
|
|
1724
|
-
|
|
1725
|
-
__decorateParam(0,
|
|
1726
|
-
__decorateParam(1,
|
|
1523
|
+
Injectable4(),
|
|
1524
|
+
__decorateParam(0, Inject4(DRIZZLE)),
|
|
1525
|
+
__decorateParam(1, Inject4(JOBS_MULTI_TENANT))
|
|
1727
1526
|
], DrizzleJobOrchestrator);
|
|
1728
1527
|
function notInStatus(statuses) {
|
|
1729
1528
|
const negated = statuses.map((s) => ne(jobRuns.status, s));
|
|
@@ -1731,7 +1530,7 @@ function notInStatus(statuses) {
|
|
|
1731
1530
|
}
|
|
1732
1531
|
|
|
1733
1532
|
// runtime/subsystems/jobs/job-run-service.drizzle-backend.ts
|
|
1734
|
-
import { Inject as
|
|
1533
|
+
import { Inject as Inject5, Injectable as Injectable5 } from "@nestjs/common";
|
|
1735
1534
|
import { and as and3, asc as asc2, desc as desc3, eq as eq3, gte as gte2, inArray as inArray3, isNull, lt as lt2, or as or2, sql as sql5 } from "drizzle-orm";
|
|
1736
1535
|
|
|
1737
1536
|
// runtime/subsystems/jobs/job-run-keyset-cursor.ts
|
|
@@ -1951,14 +1750,14 @@ var DrizzleJobRunService = class {
|
|
|
1951
1750
|
}
|
|
1952
1751
|
};
|
|
1953
1752
|
DrizzleJobRunService = __decorateClass([
|
|
1954
|
-
|
|
1955
|
-
__decorateParam(0,
|
|
1956
|
-
__decorateParam(1,
|
|
1957
|
-
__decorateParam(2,
|
|
1753
|
+
Injectable5(),
|
|
1754
|
+
__decorateParam(0, Inject5(DRIZZLE)),
|
|
1755
|
+
__decorateParam(1, Inject5(JOB_ORCHESTRATOR)),
|
|
1756
|
+
__decorateParam(2, Inject5(JOBS_MULTI_TENANT))
|
|
1958
1757
|
], DrizzleJobRunService);
|
|
1959
1758
|
|
|
1960
1759
|
// runtime/subsystems/jobs/job-step-service.drizzle-backend.ts
|
|
1961
|
-
import { Inject as
|
|
1760
|
+
import { Inject as Inject6, Injectable as Injectable6 } from "@nestjs/common";
|
|
1962
1761
|
import { and as and4, eq as eq4 } from "drizzle-orm";
|
|
1963
1762
|
var DrizzleJobStepService = class {
|
|
1964
1763
|
constructor(db) {
|
|
@@ -1997,15 +1796,10 @@ var DrizzleJobStepService = class {
|
|
|
1997
1796
|
}
|
|
1998
1797
|
};
|
|
1999
1798
|
DrizzleJobStepService = __decorateClass([
|
|
2000
|
-
|
|
2001
|
-
__decorateParam(0,
|
|
1799
|
+
Injectable6(),
|
|
1800
|
+
__decorateParam(0, Inject6(DRIZZLE))
|
|
2002
1801
|
], DrizzleJobStepService);
|
|
2003
1802
|
|
|
2004
|
-
// runtime/subsystems/jobs/job-orchestrator.bullmq-backend.ts
|
|
2005
|
-
import { createHash } from "crypto";
|
|
2006
|
-
import { Inject as Inject8, Injectable as Injectable8, Logger as Logger5, Optional as Optional3 } from "@nestjs/common";
|
|
2007
|
-
import { eq as eq5 } from "drizzle-orm";
|
|
2008
|
-
|
|
2009
1803
|
// runtime/subsystems/jobs/pool-config.loader.ts
|
|
2010
1804
|
import { existsSync, readFileSync } from "fs";
|
|
2011
1805
|
import { resolve } from "path";
|
|
@@ -2153,443 +1947,9 @@ function resolvePoolQueueName(pool, config, poolConfig = loadPoolConfig()) {
|
|
|
2153
1947
|
return prefix ? `${prefix}:${alias}` : alias;
|
|
2154
1948
|
}
|
|
2155
1949
|
|
|
2156
|
-
// runtime/subsystems/jobs/job-orchestrator.bullmq-backend.ts
|
|
2157
|
-
function sha1JobId(idempotencyKey) {
|
|
2158
|
-
return createHash("sha1").update(idempotencyKey).digest("hex");
|
|
2159
|
-
}
|
|
2160
|
-
var BullMQJobOrchestrator = class extends DrizzleJobOrchestrator {
|
|
2161
|
-
constructor(db, multiTenant, connection, bullConfig = null) {
|
|
2162
|
-
super(db, multiTenant);
|
|
2163
|
-
this.connection = connection;
|
|
2164
|
-
this.bullConfig = bullConfig;
|
|
2165
|
-
this.bullDb = db;
|
|
2166
|
-
}
|
|
2167
|
-
connection;
|
|
2168
|
-
bullConfig;
|
|
2169
|
-
// TODO(logging-subsystem): swap to ILogger once ADR-028 lands
|
|
2170
|
-
bullLogger = new Logger5(BullMQJobOrchestrator.name);
|
|
2171
|
-
/** Lazily-opened `Queue` handles, one per pool. */
|
|
2172
|
-
queues = /* @__PURE__ */ new Map();
|
|
2173
|
-
/** Single FlowProducer for parent/child hierarchies. Lazily opened. */
|
|
2174
|
-
_flow = null;
|
|
2175
|
-
/**
|
|
2176
|
-
* Cached `bullmq` value constructors, populated by `loadBullMq()` on first
|
|
2177
|
-
* use (the `start`/`cancel`/`replay` entrypoints `await` it before touching
|
|
2178
|
-
* a queue). Kept off the import graph so a `drizzle`-only consumer never
|
|
2179
|
-
* resolves the optional `'bullmq'` package.
|
|
2180
|
-
*/
|
|
2181
|
-
QueueCtor = null;
|
|
2182
|
-
FlowProducerCtor = null;
|
|
2183
|
-
bullMqLoad = null;
|
|
2184
|
-
/**
|
|
2185
|
-
* Own reference to the Drizzle client. `DrizzleJobOrchestrator.db` is
|
|
2186
|
-
* `private` (can't be redeclared even privately in a subclass), and the
|
|
2187
|
-
* spec forbids touching that file — so the subclass keeps its own handle
|
|
2188
|
-
* under a distinct name (same instance, passed through to `super`) for the
|
|
2189
|
-
* cancel-cascade snapshot + definition/run loads below.
|
|
2190
|
-
*/
|
|
2191
|
-
bullDb;
|
|
2192
|
-
/**
|
|
2193
|
-
* Lazily load the optional `bullmq` package and cache its value
|
|
2194
|
-
* constructors. Idempotent (single in-flight promise). Throws a friendly,
|
|
2195
|
-
* actionable error when the consumer selected `backend: 'bullmq'` but did
|
|
2196
|
-
* not install the package — mirrors `createRedisClient` in the redis event
|
|
2197
|
-
* backend. Must be `await`ed before any `queueFor`/`flow` access.
|
|
2198
|
-
*/
|
|
2199
|
-
async loadBullMq() {
|
|
2200
|
-
if (this.QueueCtor && this.FlowProducerCtor) return;
|
|
2201
|
-
if (!this.bullMqLoad) {
|
|
2202
|
-
this.bullMqLoad = (async () => {
|
|
2203
|
-
try {
|
|
2204
|
-
const mod = await import("bullmq");
|
|
2205
|
-
this.QueueCtor = mod.Queue;
|
|
2206
|
-
this.FlowProducerCtor = mod.FlowProducer;
|
|
2207
|
-
} catch {
|
|
2208
|
-
throw new Error(
|
|
2209
|
-
'BullMQ backend requires the "bullmq" package. Install it with: npm install bullmq'
|
|
2210
|
-
);
|
|
2211
|
-
}
|
|
2212
|
-
})();
|
|
2213
|
-
}
|
|
2214
|
-
await this.bullMqLoad;
|
|
2215
|
-
}
|
|
2216
|
-
/**
|
|
2217
|
-
* Open (or reuse) the `Queue` for a pool. Synchronous — callers `await
|
|
2218
|
-
* loadBullMq()` first so `QueueCtor` is populated.
|
|
2219
|
-
*/
|
|
2220
|
-
queueFor(pool) {
|
|
2221
|
-
if (!this.QueueCtor) {
|
|
2222
|
-
throw new Error("BullMQJobOrchestrator: queueFor called before loadBullMq()");
|
|
2223
|
-
}
|
|
2224
|
-
const name = resolvePoolQueueName(pool, this.bullConfig);
|
|
2225
|
-
let q = this.queues.get(name);
|
|
2226
|
-
if (!q) {
|
|
2227
|
-
q = new this.QueueCtor(name, { connection: this.connection });
|
|
2228
|
-
this.queues.set(name, q);
|
|
2229
|
-
}
|
|
2230
|
-
return q;
|
|
2231
|
-
}
|
|
2232
|
-
flow() {
|
|
2233
|
-
if (!this.FlowProducerCtor) {
|
|
2234
|
-
throw new Error("BullMQJobOrchestrator: flow called before loadBullMq()");
|
|
2235
|
-
}
|
|
2236
|
-
if (!this._flow) {
|
|
2237
|
-
this._flow = new this.FlowProducerCtor({ connection: this.connection });
|
|
2238
|
-
}
|
|
2239
|
-
return this._flow;
|
|
2240
|
-
}
|
|
2241
|
-
// ==========================================================================
|
|
2242
|
-
// start — Postgres insert (super) + BullMQ dispatch
|
|
2243
|
-
// ==========================================================================
|
|
2244
|
-
async start(type, input, opts = {}, tx) {
|
|
2245
|
-
const run = await super.start(type, input, opts, tx);
|
|
2246
|
-
await this.dispatch(run, type);
|
|
2247
|
-
return run;
|
|
2248
|
-
}
|
|
2249
|
-
/**
|
|
2250
|
-
* Map a `job_run` row onto a BullMQ job via `queue.add`. When the run has a
|
|
2251
|
-
* `parentRunId` we attach it to the parent's existing BullMQ job through the
|
|
2252
|
-
* `parent: { id, queue }` opt — BullMQ then tracks the parent/child link in
|
|
2253
|
-
* its own graph. (The FlowProducer is reserved for whole-tree atomic
|
|
2254
|
-
* submits, exposed as an opt-in extension via `flowProducer()`; runtime
|
|
2255
|
-
* `ctx.spawnChild` is incremental, so `queue.add` with a parent ref is the
|
|
2256
|
-
* correct primitive here.)
|
|
2257
|
-
*
|
|
2258
|
-
* The `jobId` is colon-safe + stable: `sha1(dedupeKey)` when a dedupe key is
|
|
2259
|
-
* present (so the same logical key dedups), else the `job_run.id` UUID
|
|
2260
|
-
* (already colon-free).
|
|
2261
|
-
*
|
|
2262
|
-
* The domain `parentClosePolicy` cascade is still enforced in Postgres by
|
|
2263
|
-
* the shared `cancel` path — BullMQ's parent link is dispatch bookkeeping,
|
|
2264
|
-
* not the authority.
|
|
2265
|
-
*/
|
|
2266
|
-
async dispatch(run, type) {
|
|
2267
|
-
await this.loadBullMq();
|
|
2268
|
-
const def = await this.loadDefinition(type);
|
|
2269
|
-
const jobId = run.dedupeKey ? sha1JobId(run.dedupeKey) : run.id;
|
|
2270
|
-
const jobOpts = {
|
|
2271
|
-
jobId,
|
|
2272
|
-
...this.retryOpts(def),
|
|
2273
|
-
...this.dedupeOpts(run, def)
|
|
2274
|
-
};
|
|
2275
|
-
if (run.parentRunId) {
|
|
2276
|
-
const parentRow = await this.loadRun(run.parentRunId);
|
|
2277
|
-
if (parentRow) {
|
|
2278
|
-
const parentJobId = parentRow.dedupeKey ? sha1JobId(parentRow.dedupeKey) : parentRow.id;
|
|
2279
|
-
jobOpts.parent = {
|
|
2280
|
-
id: parentJobId,
|
|
2281
|
-
queue: resolvePoolQueueName(parentRow.pool, this.bullConfig)
|
|
2282
|
-
};
|
|
2283
|
-
}
|
|
2284
|
-
}
|
|
2285
|
-
const payload = { runId: run.id, type, input: run.input };
|
|
2286
|
-
await this.queueFor(run.pool).add(type, payload, jobOpts);
|
|
2287
|
-
}
|
|
2288
|
-
/**
|
|
2289
|
-
* Opt-in extension (spec §Extensions): expose the FlowProducer for
|
|
2290
|
-
* consumers that want to submit a whole parent/child DAG atomically up
|
|
2291
|
-
* front, rather than incrementally via `ctx.spawnChild`. Backend-specific —
|
|
2292
|
-
* code using it is not portable to the Drizzle backend. Async because it
|
|
2293
|
-
* lazily loads the optional `bullmq` package on first use.
|
|
2294
|
-
*/
|
|
2295
|
-
async flowProducer() {
|
|
2296
|
-
await this.loadBullMq();
|
|
2297
|
-
return this.flow();
|
|
2298
|
-
}
|
|
2299
|
-
retryOpts(def) {
|
|
2300
|
-
const policy = def.retryPolicy;
|
|
2301
|
-
if (!policy) return {};
|
|
2302
|
-
return {
|
|
2303
|
-
attempts: policy.attempts,
|
|
2304
|
-
backoff: {
|
|
2305
|
-
type: policy.backoff === "exponential" ? "exponential" : "fixed",
|
|
2306
|
-
delay: policy.baseMs
|
|
2307
|
-
}
|
|
2308
|
-
};
|
|
2309
|
-
}
|
|
2310
|
-
dedupeOpts(run, def) {
|
|
2311
|
-
if (!run.dedupeKey || !def.dedupeWindowMs) return {};
|
|
2312
|
-
return {
|
|
2313
|
-
deduplication: {
|
|
2314
|
-
id: sha1JobId(run.dedupeKey),
|
|
2315
|
-
ttl: def.dedupeWindowMs
|
|
2316
|
-
}
|
|
2317
|
-
};
|
|
2318
|
-
}
|
|
2319
|
-
// ==========================================================================
|
|
2320
|
-
// cancel — Postgres cascade (super) + remove from queue
|
|
2321
|
-
// ==========================================================================
|
|
2322
|
-
async cancel(runId, opts = {}) {
|
|
2323
|
-
const target = await this.loadRun(runId);
|
|
2324
|
-
await super.cancel(runId, opts);
|
|
2325
|
-
if (!target) return;
|
|
2326
|
-
await this.loadBullMq();
|
|
2327
|
-
await this.removeFromQueue(target);
|
|
2328
|
-
if (opts.cascade === false) return;
|
|
2329
|
-
const descendants = await this.bullDb.select().from(jobRuns).where(eq5(jobRuns.rootRunId, target.rootRunId));
|
|
2330
|
-
for (const child of descendants) {
|
|
2331
|
-
if (child.id === runId) continue;
|
|
2332
|
-
await this.removeFromQueue(child);
|
|
2333
|
-
}
|
|
2334
|
-
}
|
|
2335
|
-
async removeFromQueue(run) {
|
|
2336
|
-
const jobId = run.dedupeKey ? sha1JobId(run.dedupeKey) : run.id;
|
|
2337
|
-
try {
|
|
2338
|
-
const job = await this.queueFor(run.pool).getJob(jobId);
|
|
2339
|
-
if (job) await job.remove();
|
|
2340
|
-
} catch (err) {
|
|
2341
|
-
this.bullLogger.warn(
|
|
2342
|
-
`cancel: could not remove BullMQ job ${jobId} (pool=${run.pool}): ${err.message}`
|
|
2343
|
-
);
|
|
2344
|
-
}
|
|
2345
|
-
}
|
|
2346
|
-
// ==========================================================================
|
|
2347
|
-
// replay — Postgres reset (super) + re-enqueue
|
|
2348
|
-
// ==========================================================================
|
|
2349
|
-
async replay(runId) {
|
|
2350
|
-
const run = await super.replay(runId);
|
|
2351
|
-
await this.dispatch(run, run.jobType);
|
|
2352
|
-
return run;
|
|
2353
|
-
}
|
|
2354
|
-
// ==========================================================================
|
|
2355
|
-
// Internals
|
|
2356
|
-
// ==========================================================================
|
|
2357
|
-
async loadDefinition(type) {
|
|
2358
|
-
const [def] = await this.bullDb.select().from(jobs).where(eq5(jobs.type, type)).limit(1);
|
|
2359
|
-
if (!def) {
|
|
2360
|
-
throw new Error(`BullMQJobOrchestrator: no job definition for '${type}'`);
|
|
2361
|
-
}
|
|
2362
|
-
return def;
|
|
2363
|
-
}
|
|
2364
|
-
async loadRun(id) {
|
|
2365
|
-
const [row] = await this.bullDb.select().from(jobRuns).where(eq5(jobRuns.id, id)).limit(1);
|
|
2366
|
-
return row ?? null;
|
|
2367
|
-
}
|
|
2368
|
-
/** Close all open queue + flow connections. Called on module destroy. */
|
|
2369
|
-
async closeConnections() {
|
|
2370
|
-
for (const q of this.queues.values()) {
|
|
2371
|
-
await q.close().catch(() => void 0);
|
|
2372
|
-
}
|
|
2373
|
-
this.queues.clear();
|
|
2374
|
-
if (this._flow) {
|
|
2375
|
-
await this._flow.close().catch(() => void 0);
|
|
2376
|
-
this._flow = null;
|
|
2377
|
-
}
|
|
2378
|
-
}
|
|
2379
|
-
};
|
|
2380
|
-
BullMQJobOrchestrator = __decorateClass([
|
|
2381
|
-
Injectable8(),
|
|
2382
|
-
__decorateParam(0, Inject8(DRIZZLE)),
|
|
2383
|
-
__decorateParam(1, Inject8(JOBS_MULTI_TENANT)),
|
|
2384
|
-
__decorateParam(2, Inject8(BULLMQ_CONNECTION)),
|
|
2385
|
-
__decorateParam(3, Optional3()),
|
|
2386
|
-
__decorateParam(3, Inject8(BULLMQ_RESOLVED_CONFIG))
|
|
2387
|
-
], BullMQJobOrchestrator);
|
|
2388
|
-
|
|
2389
|
-
// runtime/subsystems/jobs/job-worker.bullmq-backend.ts
|
|
2390
|
-
import { Logger as Logger6 } from "@nestjs/common";
|
|
2391
|
-
import { eq as eq6 } from "drizzle-orm";
|
|
2392
|
-
function serialiseError(err, attempt, retryable) {
|
|
2393
|
-
const e = err;
|
|
2394
|
-
return {
|
|
2395
|
-
message: e?.message ?? String(err),
|
|
2396
|
-
stack: e?.stack,
|
|
2397
|
-
retryable,
|
|
2398
|
-
attempt
|
|
2399
|
-
};
|
|
2400
|
-
}
|
|
2401
|
-
var BullMQJobWorker = class _BullMQJobWorker {
|
|
2402
|
-
constructor(db, orchestrator, stepService, options, moduleRef) {
|
|
2403
|
-
this.db = db;
|
|
2404
|
-
this.orchestrator = orchestrator;
|
|
2405
|
-
this.stepService = stepService;
|
|
2406
|
-
this.options = options;
|
|
2407
|
-
this.moduleRef = moduleRef;
|
|
2408
|
-
}
|
|
2409
|
-
db;
|
|
2410
|
-
orchestrator;
|
|
2411
|
-
stepService;
|
|
2412
|
-
options;
|
|
2413
|
-
moduleRef;
|
|
2414
|
-
logger = new Logger6(_BullMQJobWorker.name);
|
|
2415
|
-
worker = null;
|
|
2416
|
-
async onModuleInit() {
|
|
2417
|
-
let WorkerCtor;
|
|
2418
|
-
try {
|
|
2419
|
-
const mod = await import("bullmq");
|
|
2420
|
-
WorkerCtor = mod.Worker;
|
|
2421
|
-
} catch {
|
|
2422
|
-
throw new Error(
|
|
2423
|
-
'BullMQ backend requires the "bullmq" package. Install it with: npm install bullmq'
|
|
2424
|
-
);
|
|
2425
|
-
}
|
|
2426
|
-
this.worker = new WorkerCtor(
|
|
2427
|
-
this.options.queueName,
|
|
2428
|
-
(job) => this.process(job),
|
|
2429
|
-
{
|
|
2430
|
-
connection: this.options.connection,
|
|
2431
|
-
concurrency: this.options.concurrency
|
|
2432
|
-
}
|
|
2433
|
-
);
|
|
2434
|
-
this.worker.on("failed", (job, err) => {
|
|
2435
|
-
if (!job) return;
|
|
2436
|
-
const attemptsMade = job.attemptsMade;
|
|
2437
|
-
const maxAttempts = job.opts.attempts ?? 1;
|
|
2438
|
-
if (attemptsMade >= maxAttempts) {
|
|
2439
|
-
void this.markFailed(job.data.runId, err, attemptsMade);
|
|
2440
|
-
}
|
|
2441
|
-
});
|
|
2442
|
-
this.logger.log(
|
|
2443
|
-
`BullMQ worker started: pool='${this.options.pool}' queue='${this.options.queueName}' concurrency=${this.options.concurrency}`
|
|
2444
|
-
);
|
|
2445
|
-
}
|
|
2446
|
-
async onModuleDestroy() {
|
|
2447
|
-
if (this.worker) {
|
|
2448
|
-
await this.worker.close();
|
|
2449
|
-
this.worker = null;
|
|
2450
|
-
}
|
|
2451
|
-
}
|
|
2452
|
-
/**
|
|
2453
|
-
* Process one BullMQ job. Returns the handler output (stored by BullMQ as
|
|
2454
|
-
* the job return value AND written to `job_run.output`). Throws on handler
|
|
2455
|
-
* failure so BullMQ applies the retry policy.
|
|
2456
|
-
*/
|
|
2457
|
-
async process(job) {
|
|
2458
|
-
const { runId } = job.data;
|
|
2459
|
-
const [row] = await this.db.select().from(jobRuns).where(eq6(jobRuns.id, runId)).limit(1);
|
|
2460
|
-
if (!row) {
|
|
2461
|
-
this.logger.warn(`process: job_run ${runId} not found; skipping`);
|
|
2462
|
-
return {};
|
|
2463
|
-
}
|
|
2464
|
-
const run = row;
|
|
2465
|
-
if (run.status === "canceled") {
|
|
2466
|
-
return {};
|
|
2467
|
-
}
|
|
2468
|
-
const registryEntry = JOB_HANDLER_REGISTRY.get(run.jobType);
|
|
2469
|
-
if (!registryEntry) {
|
|
2470
|
-
throw new Error(
|
|
2471
|
-
`No handler registered for jobType='${run.jobType}' (run ${run.id})`
|
|
2472
|
-
);
|
|
2473
|
-
}
|
|
2474
|
-
await this.db.update(jobRuns).set({
|
|
2475
|
-
status: "running",
|
|
2476
|
-
claimedAt: /* @__PURE__ */ new Date(),
|
|
2477
|
-
startedAt: /* @__PURE__ */ new Date(),
|
|
2478
|
-
attempts: job.attemptsMade + 1,
|
|
2479
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
2480
|
-
}).where(eq6(jobRuns.id, run.id));
|
|
2481
|
-
const HandlerClass = registryEntry.handlerClass;
|
|
2482
|
-
const handler = this.moduleRef.get(
|
|
2483
|
-
HandlerClass,
|
|
2484
|
-
{ strict: false }
|
|
2485
|
-
);
|
|
2486
|
-
const ctx = {
|
|
2487
|
-
input: run.input,
|
|
2488
|
-
run,
|
|
2489
|
-
step: this.makeStepFn(run),
|
|
2490
|
-
spawnChild: this.makeSpawnFn(run),
|
|
2491
|
-
logger: new Logger6(`JobRun:${run.id}`)
|
|
2492
|
-
};
|
|
2493
|
-
const output = await handler.run(ctx);
|
|
2494
|
-
await this.db.update(jobRuns).set({
|
|
2495
|
-
status: "completed",
|
|
2496
|
-
output: output ?? {},
|
|
2497
|
-
finishedAt: /* @__PURE__ */ new Date(),
|
|
2498
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
2499
|
-
}).where(eq6(jobRuns.id, run.id));
|
|
2500
|
-
return output ?? {};
|
|
2501
|
-
}
|
|
2502
|
-
async markFailed(runId, err, finalAttempts) {
|
|
2503
|
-
const [row] = await this.db.select().from(jobRuns).where(eq6(jobRuns.id, runId)).limit(1);
|
|
2504
|
-
if (!row) return;
|
|
2505
|
-
const run = row;
|
|
2506
|
-
await this.db.update(jobRuns).set({
|
|
2507
|
-
status: "failed",
|
|
2508
|
-
attempts: finalAttempts,
|
|
2509
|
-
finishedAt: /* @__PURE__ */ new Date(),
|
|
2510
|
-
error: serialiseError(err, finalAttempts, false),
|
|
2511
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
2512
|
-
}).where(eq6(jobRuns.id, runId));
|
|
2513
|
-
if (run.parentClosePolicy === "terminate") {
|
|
2514
|
-
try {
|
|
2515
|
-
await this.orchestrator.cancel(run.id, {
|
|
2516
|
-
cascade: true,
|
|
2517
|
-
reason: "parent-failed",
|
|
2518
|
-
tenantId: run.tenantId
|
|
2519
|
-
});
|
|
2520
|
-
} catch (cascadeErr) {
|
|
2521
|
-
this.logger.warn(
|
|
2522
|
-
`cascade on failed run ${run.id}: ${cascadeErr.message}`
|
|
2523
|
-
);
|
|
2524
|
-
}
|
|
2525
|
-
}
|
|
2526
|
-
}
|
|
2527
|
-
// ── ctx.step / ctx.spawnChild (mirror JobWorker) ──────────────────────────
|
|
2528
|
-
makeStepFn(run) {
|
|
2529
|
-
return async (stepId, fn, _opts) => {
|
|
2530
|
-
void _opts;
|
|
2531
|
-
const existing = await this.stepService.findStep(run.id, stepId);
|
|
2532
|
-
if (existing?.status === "completed") {
|
|
2533
|
-
return existing.output;
|
|
2534
|
-
}
|
|
2535
|
-
const nextAttempts = (existing?.attempts ?? 0) + 1;
|
|
2536
|
-
const seq = nextAttempts;
|
|
2537
|
-
await this.stepService.recordStep({
|
|
2538
|
-
jobRunId: run.id,
|
|
2539
|
-
stepId,
|
|
2540
|
-
kind: "task",
|
|
2541
|
-
seq,
|
|
2542
|
-
status: "running",
|
|
2543
|
-
startedAt: /* @__PURE__ */ new Date(),
|
|
2544
|
-
attempts: nextAttempts
|
|
2545
|
-
});
|
|
2546
|
-
try {
|
|
2547
|
-
const output = await fn();
|
|
2548
|
-
await this.stepService.recordStep({
|
|
2549
|
-
jobRunId: run.id,
|
|
2550
|
-
stepId,
|
|
2551
|
-
kind: "task",
|
|
2552
|
-
seq,
|
|
2553
|
-
status: "completed",
|
|
2554
|
-
output,
|
|
2555
|
-
finishedAt: /* @__PURE__ */ new Date(),
|
|
2556
|
-
attempts: nextAttempts
|
|
2557
|
-
});
|
|
2558
|
-
return output;
|
|
2559
|
-
} catch (err) {
|
|
2560
|
-
await this.stepService.recordStep({
|
|
2561
|
-
jobRunId: run.id,
|
|
2562
|
-
stepId,
|
|
2563
|
-
kind: "task",
|
|
2564
|
-
seq,
|
|
2565
|
-
status: "failed",
|
|
2566
|
-
error: serialiseError(err, nextAttempts, false),
|
|
2567
|
-
finishedAt: /* @__PURE__ */ new Date(),
|
|
2568
|
-
attempts: nextAttempts
|
|
2569
|
-
});
|
|
2570
|
-
throw err;
|
|
2571
|
-
}
|
|
2572
|
-
};
|
|
2573
|
-
}
|
|
2574
|
-
makeSpawnFn(run) {
|
|
2575
|
-
return async (type, input, opts) => {
|
|
2576
|
-
return this.orchestrator.start(type, input, {
|
|
2577
|
-
parentRunId: run.id,
|
|
2578
|
-
parentClosePolicy: opts?.closePolicy,
|
|
2579
|
-
runAt: opts?.runAt,
|
|
2580
|
-
priority: opts?.priority,
|
|
2581
|
-
tags: opts?.tags,
|
|
2582
|
-
triggerSource: "parent",
|
|
2583
|
-
triggerRef: run.id,
|
|
2584
|
-
tenantId: run.tenantId
|
|
2585
|
-
});
|
|
2586
|
-
};
|
|
2587
|
-
}
|
|
2588
|
-
};
|
|
2589
|
-
|
|
2590
1950
|
// runtime/subsystems/jobs/job-worker.ts
|
|
2591
|
-
import { Inject as
|
|
2592
|
-
import { and as and5, asc as asc3, desc as desc4, eq as
|
|
1951
|
+
import { Inject as Inject7, Injectable as Injectable7, Logger as Logger4 } from "@nestjs/common";
|
|
1952
|
+
import { and as and5, asc as asc3, desc as desc4, eq as eq5, inArray as inArray4, lt as lt3, lte, sql as sql6 } from "drizzle-orm";
|
|
2593
1953
|
var JOB_WORKER_OPTIONS = /* @__PURE__ */ Symbol("JOB_WORKER_OPTIONS");
|
|
2594
1954
|
var DEFAULT_POLL_INTERVAL_MS = 1e3;
|
|
2595
1955
|
var DEFAULT_STALE_SWEEPER_INTERVAL_MS = 6e4;
|
|
@@ -2618,7 +1978,7 @@ function classifyError(err, policy, currentAttempts) {
|
|
|
2618
1978
|
if (currentAttempts + 1 >= policy.attempts) return "fail";
|
|
2619
1979
|
return "retry";
|
|
2620
1980
|
}
|
|
2621
|
-
function
|
|
1981
|
+
function serialiseError(err, attempt, retryable) {
|
|
2622
1982
|
const e = err;
|
|
2623
1983
|
return {
|
|
2624
1984
|
message: e?.message ?? String(err),
|
|
@@ -2652,7 +2012,7 @@ var JobWorker = class {
|
|
|
2652
2012
|
stepService;
|
|
2653
2013
|
options;
|
|
2654
2014
|
moduleRef;
|
|
2655
|
-
logger = new
|
|
2015
|
+
logger = new Logger4(JobWorker.name);
|
|
2656
2016
|
shuttingDown = false;
|
|
2657
2017
|
inFlight = /* @__PURE__ */ new Set();
|
|
2658
2018
|
pollTimer = null;
|
|
@@ -2693,7 +2053,7 @@ var JobWorker = class {
|
|
|
2693
2053
|
await this.drainInFlight();
|
|
2694
2054
|
try {
|
|
2695
2055
|
await this.db.update(jobRuns).set({ status: "pending", claimedAt: null, startedAt: null }).where(
|
|
2696
|
-
and5(
|
|
2056
|
+
and5(eq5(jobRuns.status, "running"), eq5(jobRuns.pool, this.options.pool))
|
|
2697
2057
|
);
|
|
2698
2058
|
} catch (err) {
|
|
2699
2059
|
this.logger.error(`shutdown reset failed: ${err.message}`);
|
|
@@ -2743,8 +2103,8 @@ var JobWorker = class {
|
|
|
2743
2103
|
return this.db.transaction(async (tx) => {
|
|
2744
2104
|
const candidates = await tx.select({ id: jobRuns.id }).from(jobRuns).where(
|
|
2745
2105
|
and5(
|
|
2746
|
-
|
|
2747
|
-
|
|
2106
|
+
eq5(jobRuns.status, "pending"),
|
|
2107
|
+
eq5(jobRuns.pool, pool),
|
|
2748
2108
|
lte(jobRuns.runAt, /* @__PURE__ */ new Date())
|
|
2749
2109
|
)
|
|
2750
2110
|
).orderBy(desc4(jobRuns.priority), asc3(jobRuns.runAt)).limit(1).for("update", { skipLocked: true });
|
|
@@ -2755,7 +2115,7 @@ var JobWorker = class {
|
|
|
2755
2115
|
claimedAt: /* @__PURE__ */ new Date(),
|
|
2756
2116
|
startedAt: /* @__PURE__ */ new Date(),
|
|
2757
2117
|
updatedAt: /* @__PURE__ */ new Date()
|
|
2758
|
-
}).where(
|
|
2118
|
+
}).where(eq5(jobRuns.id, candidate.id)).returning();
|
|
2759
2119
|
return claimed ?? null;
|
|
2760
2120
|
});
|
|
2761
2121
|
}
|
|
@@ -2773,7 +2133,7 @@ var JobWorker = class {
|
|
|
2773
2133
|
await this.db.transaction(async (tx) => {
|
|
2774
2134
|
const threshold = new Date(Date.now() - this.staleThresholdMs);
|
|
2775
2135
|
const stale = await tx.select({ id: jobRuns.id }).from(jobRuns).where(
|
|
2776
|
-
and5(
|
|
2136
|
+
and5(eq5(jobRuns.status, "running"), lt3(jobRuns.claimedAt, threshold))
|
|
2777
2137
|
).for("update", { skipLocked: true });
|
|
2778
2138
|
if (stale.length === 0) return;
|
|
2779
2139
|
const ids = stale.map((r) => r.id);
|
|
@@ -2806,8 +2166,8 @@ var JobWorker = class {
|
|
|
2806
2166
|
if (claimed.concurrencyKey) {
|
|
2807
2167
|
const inflight = await this.db.select({ id: jobRuns.id }).from(jobRuns).where(
|
|
2808
2168
|
and5(
|
|
2809
|
-
|
|
2810
|
-
|
|
2169
|
+
eq5(jobRuns.concurrencyKey, claimed.concurrencyKey),
|
|
2170
|
+
eq5(jobRuns.status, "running")
|
|
2811
2171
|
)
|
|
2812
2172
|
);
|
|
2813
2173
|
const other = inflight.find((r) => r.id !== claimed.id);
|
|
@@ -2817,7 +2177,7 @@ var JobWorker = class {
|
|
|
2817
2177
|
claimedAt: null,
|
|
2818
2178
|
startedAt: null,
|
|
2819
2179
|
updatedAt: /* @__PURE__ */ new Date()
|
|
2820
|
-
}).where(
|
|
2180
|
+
}).where(eq5(jobRuns.id, claimed.id));
|
|
2821
2181
|
return;
|
|
2822
2182
|
}
|
|
2823
2183
|
}
|
|
@@ -2832,7 +2192,7 @@ var JobWorker = class {
|
|
|
2832
2192
|
run: claimed,
|
|
2833
2193
|
step: this.makeStepFn(claimed),
|
|
2834
2194
|
spawnChild: this.makeSpawnFn(claimed),
|
|
2835
|
-
logger: new
|
|
2195
|
+
logger: new Logger4(`JobRun:${claimed.id}`)
|
|
2836
2196
|
};
|
|
2837
2197
|
const attemptsBefore = claimed.attempts ?? 0;
|
|
2838
2198
|
try {
|
|
@@ -2843,7 +2203,7 @@ var JobWorker = class {
|
|
|
2843
2203
|
finishedAt: /* @__PURE__ */ new Date(),
|
|
2844
2204
|
updatedAt: /* @__PURE__ */ new Date(),
|
|
2845
2205
|
attempts: attemptsBefore + 1
|
|
2846
|
-
}).where(
|
|
2206
|
+
}).where(eq5(jobRuns.id, claimed.id));
|
|
2847
2207
|
} catch (err) {
|
|
2848
2208
|
const policy = meta.retry;
|
|
2849
2209
|
const decision = classifyError(err, policy, attemptsBefore);
|
|
@@ -2856,9 +2216,9 @@ var JobWorker = class {
|
|
|
2856
2216
|
runAt: new Date(Date.now() + delay),
|
|
2857
2217
|
startedAt: null,
|
|
2858
2218
|
claimedAt: null,
|
|
2859
|
-
error:
|
|
2219
|
+
error: serialiseError(err, nextAttempts, true),
|
|
2860
2220
|
updatedAt: /* @__PURE__ */ new Date()
|
|
2861
|
-
}).where(
|
|
2221
|
+
}).where(eq5(jobRuns.id, claimed.id));
|
|
2862
2222
|
} else {
|
|
2863
2223
|
await this.markFailed(claimed, err, nextAttempts);
|
|
2864
2224
|
}
|
|
@@ -2869,9 +2229,9 @@ var JobWorker = class {
|
|
|
2869
2229
|
status: "failed",
|
|
2870
2230
|
attempts: finalAttempts,
|
|
2871
2231
|
finishedAt: /* @__PURE__ */ new Date(),
|
|
2872
|
-
error:
|
|
2232
|
+
error: serialiseError(err, finalAttempts, false),
|
|
2873
2233
|
updatedAt: /* @__PURE__ */ new Date()
|
|
2874
|
-
}).where(
|
|
2234
|
+
}).where(eq5(jobRuns.id, claimed.id));
|
|
2875
2235
|
if (claimed.parentClosePolicy === "terminate") {
|
|
2876
2236
|
try {
|
|
2877
2237
|
await this.orchestrator.cancel(claimed.id, {
|
|
@@ -2928,7 +2288,7 @@ var JobWorker = class {
|
|
|
2928
2288
|
kind: "task",
|
|
2929
2289
|
seq,
|
|
2930
2290
|
status: "failed",
|
|
2931
|
-
error:
|
|
2291
|
+
error: serialiseError(err, nextAttempts, false),
|
|
2932
2292
|
finishedAt: /* @__PURE__ */ new Date(),
|
|
2933
2293
|
attempts: nextAttempts
|
|
2934
2294
|
});
|
|
@@ -2974,12 +2334,12 @@ var JobWorker = class {
|
|
|
2974
2334
|
// ============================================================================
|
|
2975
2335
|
};
|
|
2976
2336
|
JobWorker = __decorateClass([
|
|
2977
|
-
|
|
2978
|
-
__decorateParam(0,
|
|
2979
|
-
__decorateParam(1,
|
|
2980
|
-
__decorateParam(2,
|
|
2981
|
-
__decorateParam(3,
|
|
2982
|
-
__decorateParam(4,
|
|
2337
|
+
Injectable7(),
|
|
2338
|
+
__decorateParam(0, Inject7(DRIZZLE)),
|
|
2339
|
+
__decorateParam(1, Inject7(JOB_ORCHESTRATOR)),
|
|
2340
|
+
__decorateParam(2, Inject7(JOB_RUN_SERVICE)),
|
|
2341
|
+
__decorateParam(3, Inject7(JOB_STEP_SERVICE)),
|
|
2342
|
+
__decorateParam(4, Inject7(JOB_WORKER_OPTIONS))
|
|
2983
2343
|
], JobWorker);
|
|
2984
2344
|
|
|
2985
2345
|
// runtime/subsystems/jobs/memory-job-store.ts
|
|
@@ -3000,7 +2360,7 @@ var MemoryJobStore = class {
|
|
|
3000
2360
|
|
|
3001
2361
|
// runtime/subsystems/jobs/job-orchestrator.memory-backend.ts
|
|
3002
2362
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
3003
|
-
import { Inject as
|
|
2363
|
+
import { Inject as Inject8, Injectable as Injectable8, Logger as Logger5, Optional as Optional3 } from "@nestjs/common";
|
|
3004
2364
|
var QUEUED_RUN_AT = /* @__PURE__ */ new Date(864e13);
|
|
3005
2365
|
var TERMINAL_STATUSES2 = [
|
|
3006
2366
|
"completed",
|
|
@@ -3047,7 +2407,7 @@ var MemoryJobOrchestrator = class {
|
|
|
3047
2407
|
stepService;
|
|
3048
2408
|
multiTenant;
|
|
3049
2409
|
moduleRef;
|
|
3050
|
-
logger = new
|
|
2410
|
+
logger = new Logger5(MemoryJobOrchestrator.name);
|
|
3051
2411
|
mutex = new PromiseMutex();
|
|
3052
2412
|
handlerRegistry = /* @__PURE__ */ new Map();
|
|
3053
2413
|
/**
|
|
@@ -3396,7 +2756,7 @@ var MemoryJobOrchestrator = class {
|
|
|
3396
2756
|
run,
|
|
3397
2757
|
step: this.makeStepFn(run),
|
|
3398
2758
|
spawnChild: this.makeSpawnFn(run),
|
|
3399
|
-
logger: new
|
|
2759
|
+
logger: new Logger5(`JobRun:${run.id}`)
|
|
3400
2760
|
};
|
|
3401
2761
|
const attemptsBefore = run.attempts ?? 0;
|
|
3402
2762
|
try {
|
|
@@ -3453,7 +2813,7 @@ var MemoryJobOrchestrator = class {
|
|
|
3453
2813
|
kind: "task",
|
|
3454
2814
|
seq,
|
|
3455
2815
|
status: "failed",
|
|
3456
|
-
error:
|
|
2816
|
+
error: serialiseError2(err, nextAttempts, false),
|
|
3457
2817
|
finishedAt: /* @__PURE__ */ new Date(),
|
|
3458
2818
|
attempts: nextAttempts
|
|
3459
2819
|
});
|
|
@@ -3508,7 +2868,7 @@ var MemoryJobOrchestrator = class {
|
|
|
3508
2868
|
finishedAt: now,
|
|
3509
2869
|
updatedAt: now,
|
|
3510
2870
|
attempts,
|
|
3511
|
-
error:
|
|
2871
|
+
error: serialiseError2(err, attempts, false)
|
|
3512
2872
|
});
|
|
3513
2873
|
this.unblockQueuedDependents(run.id);
|
|
3514
2874
|
});
|
|
@@ -3539,7 +2899,7 @@ var MemoryJobOrchestrator = class {
|
|
|
3539
2899
|
startedAt: null,
|
|
3540
2900
|
claimedAt: null,
|
|
3541
2901
|
updatedAt: now,
|
|
3542
|
-
error:
|
|
2902
|
+
error: serialiseError2(err, attempts, true)
|
|
3543
2903
|
});
|
|
3544
2904
|
});
|
|
3545
2905
|
}
|
|
@@ -3569,9 +2929,9 @@ var MemoryJobOrchestrator = class {
|
|
|
3569
2929
|
}
|
|
3570
2930
|
};
|
|
3571
2931
|
MemoryJobOrchestrator = __decorateClass([
|
|
3572
|
-
|
|
3573
|
-
__decorateParam(2,
|
|
3574
|
-
__decorateParam(3,
|
|
2932
|
+
Injectable8(),
|
|
2933
|
+
__decorateParam(2, Inject8(JOBS_MULTI_TENANT)),
|
|
2934
|
+
__decorateParam(3, Optional3())
|
|
3575
2935
|
], MemoryJobOrchestrator);
|
|
3576
2936
|
function classifyError2(err, policy, currentAttempts) {
|
|
3577
2937
|
if (!policy) return "fail";
|
|
@@ -3594,7 +2954,7 @@ function computeBackoff2(policy, attempts) {
|
|
|
3594
2954
|
}
|
|
3595
2955
|
return raw;
|
|
3596
2956
|
}
|
|
3597
|
-
function
|
|
2957
|
+
function serialiseError2(err, attempt, retryable) {
|
|
3598
2958
|
const e = err;
|
|
3599
2959
|
return {
|
|
3600
2960
|
message: e?.message ?? String(err),
|
|
@@ -3605,7 +2965,7 @@ function serialiseError3(err, attempt, retryable) {
|
|
|
3605
2965
|
}
|
|
3606
2966
|
|
|
3607
2967
|
// runtime/subsystems/jobs/job-run-service.memory-backend.ts
|
|
3608
|
-
import { Inject as
|
|
2968
|
+
import { Inject as Inject9, Injectable as Injectable9 } from "@nestjs/common";
|
|
3609
2969
|
var NON_TERMINAL_STATUSES2 = [
|
|
3610
2970
|
"pending",
|
|
3611
2971
|
"running",
|
|
@@ -3772,9 +3132,9 @@ var MemoryJobRunService = class {
|
|
|
3772
3132
|
}
|
|
3773
3133
|
};
|
|
3774
3134
|
MemoryJobRunService = __decorateClass([
|
|
3775
|
-
|
|
3776
|
-
__decorateParam(1,
|
|
3777
|
-
__decorateParam(2,
|
|
3135
|
+
Injectable9(),
|
|
3136
|
+
__decorateParam(1, Inject9(JOB_ORCHESTRATOR)),
|
|
3137
|
+
__decorateParam(2, Inject9(JOBS_MULTI_TENANT))
|
|
3778
3138
|
], MemoryJobRunService);
|
|
3779
3139
|
function compareBy(a, b, order) {
|
|
3780
3140
|
switch (order) {
|
|
@@ -3792,7 +3152,7 @@ function compareBy(a, b, order) {
|
|
|
3792
3152
|
|
|
3793
3153
|
// runtime/subsystems/jobs/job-step-service.memory-backend.ts
|
|
3794
3154
|
import { randomUUID as randomUUID4 } from "crypto";
|
|
3795
|
-
import { Injectable as
|
|
3155
|
+
import { Injectable as Injectable10 } from "@nestjs/common";
|
|
3796
3156
|
var MemoryJobStepService = class {
|
|
3797
3157
|
constructor(store) {
|
|
3798
3158
|
this.store = store;
|
|
@@ -3885,7 +3245,7 @@ var MemoryJobStepService = class {
|
|
|
3885
3245
|
}
|
|
3886
3246
|
};
|
|
3887
3247
|
MemoryJobStepService = __decorateClass([
|
|
3888
|
-
|
|
3248
|
+
Injectable10()
|
|
3889
3249
|
], MemoryJobStepService);
|
|
3890
3250
|
|
|
3891
3251
|
// runtime/subsystems/jobs/jobs-domain.module.ts
|
|
@@ -3914,7 +3274,20 @@ var JobsDomainModule = class {
|
|
|
3914
3274
|
const resolved = resolveBullMqConfig(opts.extensions?.bullmq);
|
|
3915
3275
|
providers.push({ provide: BULLMQ_CONNECTION, useValue: resolved.connection });
|
|
3916
3276
|
providers.push({ provide: BULLMQ_RESOLVED_CONFIG, useValue: resolved });
|
|
3917
|
-
providers.push({
|
|
3277
|
+
providers.push({
|
|
3278
|
+
provide: JOB_ORCHESTRATOR,
|
|
3279
|
+
useFactory: async (...args) => {
|
|
3280
|
+
const specifier = "./job-orchestrator.bullmq-backend";
|
|
3281
|
+
const mod = await import(specifier);
|
|
3282
|
+
return new mod.BullMQJobOrchestrator(...args);
|
|
3283
|
+
},
|
|
3284
|
+
// The bullmq orchestrator constructor mirrors DrizzleJobOrchestrator's
|
|
3285
|
+
// injection list: DRIZZLE + JOBS_MULTI_TENANT + the resolved BullMQ
|
|
3286
|
+
// tokens. Importing token references would force a static dep on the
|
|
3287
|
+
// tokens file in this module's import graph; using the existing
|
|
3288
|
+
// symbols already in scope is sufficient.
|
|
3289
|
+
inject: [DRIZZLE, JOBS_MULTI_TENANT, BULLMQ_CONNECTION, BULLMQ_RESOLVED_CONFIG]
|
|
3290
|
+
});
|
|
3918
3291
|
providers.push({ provide: JOB_RUN_SERVICE, useClass: DrizzleJobRunService });
|
|
3919
3292
|
providers.push({ provide: JOB_STEP_SERVICE, useClass: DrizzleJobStepService });
|
|
3920
3293
|
} else {
|
|
@@ -3945,11 +3318,11 @@ JobsDomainModule = __decorateClass([
|
|
|
3945
3318
|
|
|
3946
3319
|
// runtime/subsystems/jobs/job-worker.module.ts
|
|
3947
3320
|
import {
|
|
3948
|
-
Inject as
|
|
3949
|
-
Injectable as
|
|
3950
|
-
Logger as
|
|
3321
|
+
Inject as Inject10,
|
|
3322
|
+
Injectable as Injectable11,
|
|
3323
|
+
Logger as Logger6,
|
|
3951
3324
|
Module as Module3,
|
|
3952
|
-
Optional as
|
|
3325
|
+
Optional as Optional4
|
|
3953
3326
|
} from "@nestjs/common";
|
|
3954
3327
|
var DEFAULT_SHUTDOWN_TIMEOUT_MS2 = 3e4;
|
|
3955
3328
|
var JOB_WORKER_MODULE_OPTIONS = /* @__PURE__ */ Symbol("JOB_WORKER_MODULE_OPTIONS");
|
|
@@ -3972,7 +3345,7 @@ var JobWorkerOrchestrator = class {
|
|
|
3972
3345
|
moduleRef;
|
|
3973
3346
|
bullConnection;
|
|
3974
3347
|
bullConfig;
|
|
3975
|
-
logger = new
|
|
3348
|
+
logger = new Logger6(JobWorkerOrchestrator.name);
|
|
3976
3349
|
workers = [];
|
|
3977
3350
|
// ============================================================================
|
|
3978
3351
|
// Lifecycle
|
|
@@ -4002,7 +3375,7 @@ var JobWorkerOrchestrator = class {
|
|
|
4002
3375
|
concurrency: def.concurrency,
|
|
4003
3376
|
shutdownTimeoutMs: this.options.shutdownTimeoutMs ?? DEFAULT_SHUTDOWN_TIMEOUT_MS2
|
|
4004
3377
|
};
|
|
4005
|
-
const worker = this.options.workerFactory ? this.options.workerFactory(workerOptions) : backend === "bullmq" ? this.spawnBullMQWorker(poolName, def.queue, def.concurrency, poolConfig) : this.spawnWorker(workerOptions);
|
|
3378
|
+
const worker = this.options.workerFactory ? this.options.workerFactory(workerOptions) : backend === "bullmq" ? await this.spawnBullMQWorker(poolName, def.queue, def.concurrency, poolConfig) : this.spawnWorker(workerOptions);
|
|
4006
3379
|
await worker.onModuleInit();
|
|
4007
3380
|
this.workers.push(worker);
|
|
4008
3381
|
this.logger.log(
|
|
@@ -4102,7 +3475,15 @@ var JobWorkerOrchestrator = class {
|
|
|
4102
3475
|
* orchestrator's `dispatch` via `resolvePoolQueueName(pool, …)` so producer
|
|
4103
3476
|
* and consumer agree.
|
|
4104
3477
|
*/
|
|
4105
|
-
|
|
3478
|
+
/**
|
|
3479
|
+
* #6 — async + dynamic-import. The `job-worker.bullmq-backend.ts` file is
|
|
3480
|
+
* filtered out of the vendor set for drizzle/memory installs (no `bullmq`
|
|
3481
|
+
* peer dep needed). The non-literal import specifier makes TS treat the
|
|
3482
|
+
* module as `any` so the consumer's tsc never tries to resolve an absent
|
|
3483
|
+
* file. This method is only entered when `backend === 'bullmq'` — at which
|
|
3484
|
+
* point the file IS vendored.
|
|
3485
|
+
*/
|
|
3486
|
+
async spawnBullMQWorker(pool, _queueAlias, concurrency, poolConfig) {
|
|
4106
3487
|
if (!this.db) {
|
|
4107
3488
|
throw new Error(
|
|
4108
3489
|
`JobWorkerModule: BullMQ worker spawning requires the Drizzle client (no DRIZZLE provider available) \u2014 job_run remains the source of truth.`
|
|
@@ -4119,7 +3500,9 @@ var JobWorkerOrchestrator = class {
|
|
|
4119
3500
|
);
|
|
4120
3501
|
}
|
|
4121
3502
|
const queueName = resolvePoolQueueName(pool, this.bullConfig, poolConfig);
|
|
4122
|
-
|
|
3503
|
+
const specifier = "./job-worker.bullmq-backend";
|
|
3504
|
+
const mod = await import(specifier);
|
|
3505
|
+
return new mod.BullMQJobWorker(
|
|
4123
3506
|
this.db,
|
|
4124
3507
|
this.orchestrator,
|
|
4125
3508
|
this.stepService,
|
|
@@ -4134,17 +3517,17 @@ var JobWorkerOrchestrator = class {
|
|
|
4134
3517
|
}
|
|
4135
3518
|
};
|
|
4136
3519
|
JobWorkerOrchestrator = __decorateClass([
|
|
4137
|
-
|
|
4138
|
-
__decorateParam(0,
|
|
4139
|
-
__decorateParam(1,
|
|
4140
|
-
__decorateParam(2,
|
|
4141
|
-
__decorateParam(3,
|
|
4142
|
-
__decorateParam(4,
|
|
4143
|
-
__decorateParam(4,
|
|
4144
|
-
__decorateParam(6,
|
|
4145
|
-
__decorateParam(6,
|
|
4146
|
-
__decorateParam(7,
|
|
4147
|
-
__decorateParam(7,
|
|
3520
|
+
Injectable11(),
|
|
3521
|
+
__decorateParam(0, Inject10(JOB_ORCHESTRATOR)),
|
|
3522
|
+
__decorateParam(1, Inject10(JOB_RUN_SERVICE)),
|
|
3523
|
+
__decorateParam(2, Inject10(JOB_STEP_SERVICE)),
|
|
3524
|
+
__decorateParam(3, Inject10(JOB_WORKER_MODULE_OPTIONS)),
|
|
3525
|
+
__decorateParam(4, Optional4()),
|
|
3526
|
+
__decorateParam(4, Inject10(DRIZZLE)),
|
|
3527
|
+
__decorateParam(6, Optional4()),
|
|
3528
|
+
__decorateParam(6, Inject10(BULLMQ_CONNECTION)),
|
|
3529
|
+
__decorateParam(7, Optional4()),
|
|
3530
|
+
__decorateParam(7, Inject10(BULLMQ_RESOLVED_CONFIG))
|
|
4148
3531
|
], JobWorkerOrchestrator);
|
|
4149
3532
|
var JobWorkerModule = class {
|
|
4150
3533
|
static forRoot(opts) {
|
|
@@ -4184,8 +3567,8 @@ var CACHE_DEFAULT_TTL = /* @__PURE__ */ Symbol("CACHE_DEFAULT_TTL");
|
|
|
4184
3567
|
import { Module as Module4 } from "@nestjs/common";
|
|
4185
3568
|
|
|
4186
3569
|
// runtime/subsystems/cache/cache.drizzle-backend.ts
|
|
4187
|
-
import { Injectable as
|
|
4188
|
-
import { gt as gt2, or as or3, like, sql as sql7, eq as
|
|
3570
|
+
import { Injectable as Injectable12, Inject as Inject11, Optional as Optional5 } from "@nestjs/common";
|
|
3571
|
+
import { gt as gt2, or as or3, like, sql as sql7, eq as eq6 } from "drizzle-orm";
|
|
4189
3572
|
|
|
4190
3573
|
// runtime/subsystems/cache/cache.schema.ts
|
|
4191
3574
|
import { pgTable as pgTable3, text as text3, jsonb as jsonb3, timestamp as timestamp3 } from "drizzle-orm/pg-core";
|
|
@@ -4246,7 +3629,7 @@ var DrizzleCacheService = class {
|
|
|
4246
3629
|
});
|
|
4247
3630
|
}
|
|
4248
3631
|
async delete(key) {
|
|
4249
|
-
await this.db.delete(cacheEntries).where(
|
|
3632
|
+
await this.db.delete(cacheEntries).where(eq6(cacheEntries.key, key));
|
|
4250
3633
|
}
|
|
4251
3634
|
async invalidateByPrefix(prefix) {
|
|
4252
3635
|
const escaped = prefix.replace(/%/g, "\\%").replace(/_/g, "\\_");
|
|
@@ -4288,14 +3671,14 @@ var DrizzleCacheService = class {
|
|
|
4288
3671
|
}
|
|
4289
3672
|
};
|
|
4290
3673
|
DrizzleCacheService = __decorateClass([
|
|
4291
|
-
|
|
4292
|
-
__decorateParam(0,
|
|
4293
|
-
__decorateParam(1,
|
|
4294
|
-
__decorateParam(1,
|
|
3674
|
+
Injectable12(),
|
|
3675
|
+
__decorateParam(0, Inject11(DRIZZLE)),
|
|
3676
|
+
__decorateParam(1, Optional5()),
|
|
3677
|
+
__decorateParam(1, Inject11(CACHE_DEFAULT_TTL))
|
|
4295
3678
|
], DrizzleCacheService);
|
|
4296
3679
|
|
|
4297
3680
|
// runtime/subsystems/cache/cache.memory-backend.ts
|
|
4298
|
-
import { Injectable as
|
|
3681
|
+
import { Injectable as Injectable13, Inject as Inject12, Optional as Optional6 } from "@nestjs/common";
|
|
4299
3682
|
var MemoryCacheService = class {
|
|
4300
3683
|
constructor(defaultTtl = null) {
|
|
4301
3684
|
this.defaultTtl = defaultTtl;
|
|
@@ -4369,9 +3752,9 @@ var MemoryCacheService = class {
|
|
|
4369
3752
|
}
|
|
4370
3753
|
};
|
|
4371
3754
|
MemoryCacheService = __decorateClass([
|
|
4372
|
-
|
|
4373
|
-
__decorateParam(0,
|
|
4374
|
-
__decorateParam(0,
|
|
3755
|
+
Injectable13(),
|
|
3756
|
+
__decorateParam(0, Optional6()),
|
|
3757
|
+
__decorateParam(0, Inject12(CACHE_DEFAULT_TTL))
|
|
4375
3758
|
], MemoryCacheService);
|
|
4376
3759
|
|
|
4377
3760
|
// runtime/subsystems/cache/cache.module.ts
|
|
@@ -4631,25 +4014,25 @@ var OBSERVABILITY_MODULE_OPTIONS = "OBSERVABILITY_MODULE_OPTIONS";
|
|
|
4631
4014
|
import { Module as Module6 } from "@nestjs/common";
|
|
4632
4015
|
|
|
4633
4016
|
// runtime/subsystems/observability/observability.service.ts
|
|
4634
|
-
import { Inject as
|
|
4017
|
+
import { Inject as Inject13, Injectable as Injectable14, Optional as Optional7 } from "@nestjs/common";
|
|
4635
4018
|
|
|
4636
|
-
// runtime/subsystems/
|
|
4637
|
-
var
|
|
4638
|
-
var
|
|
4019
|
+
// runtime/subsystems/integration/integration.tokens.ts
|
|
4020
|
+
var INTEGRATION_CURSOR_STORE = "INTEGRATION_CURSOR_STORE";
|
|
4021
|
+
var INTEGRATION_RUN_RECORDER = "INTEGRATION_RUN_RECORDER";
|
|
4639
4022
|
|
|
4640
4023
|
// runtime/subsystems/observability/observability.service.ts
|
|
4641
4024
|
var MAX_TIMELINE_PAGES = 50;
|
|
4642
4025
|
var ObservabilityService = class {
|
|
4643
|
-
constructor(jobRuns2, bridge,
|
|
4026
|
+
constructor(jobRuns2, bridge, integrationRuns, cursors, events) {
|
|
4644
4027
|
this.jobRuns = jobRuns2;
|
|
4645
4028
|
this.bridge = bridge;
|
|
4646
|
-
this.
|
|
4029
|
+
this.integrationRuns = integrationRuns;
|
|
4647
4030
|
this.cursors = cursors;
|
|
4648
4031
|
this.events = events;
|
|
4649
4032
|
}
|
|
4650
4033
|
jobRuns;
|
|
4651
4034
|
bridge;
|
|
4652
|
-
|
|
4035
|
+
integrationRuns;
|
|
4653
4036
|
cursors;
|
|
4654
4037
|
events;
|
|
4655
4038
|
async getPoolDepths(tenantId) {
|
|
@@ -4664,9 +4047,9 @@ var ObservabilityService = class {
|
|
|
4664
4047
|
if (!this.bridge) return { ...ObservabilityService.EMPTY_HISTOGRAM };
|
|
4665
4048
|
return this.bridge.getStatusHistogram(windowHours, tenantId);
|
|
4666
4049
|
}
|
|
4667
|
-
async
|
|
4668
|
-
if (!this.
|
|
4669
|
-
return this.
|
|
4050
|
+
async getRecentIntegrationRuns(limit, subscriptionId, tenantId) {
|
|
4051
|
+
if (!this.integrationRuns) return [];
|
|
4052
|
+
return this.integrationRuns.listRecent(limit, subscriptionId, tenantId);
|
|
4670
4053
|
}
|
|
4671
4054
|
async getCursors(tenantId) {
|
|
4672
4055
|
if (!this.cursors) return [];
|
|
@@ -4784,24 +4167,24 @@ __publicField(ObservabilityService, "EMPTY_EVENT_PAGE", {
|
|
|
4784
4167
|
nextCursor: null
|
|
4785
4168
|
});
|
|
4786
4169
|
ObservabilityService = __decorateClass([
|
|
4787
|
-
|
|
4788
|
-
__decorateParam(0,
|
|
4789
|
-
__decorateParam(0,
|
|
4790
|
-
__decorateParam(1,
|
|
4791
|
-
__decorateParam(1,
|
|
4792
|
-
__decorateParam(2,
|
|
4793
|
-
__decorateParam(2,
|
|
4794
|
-
__decorateParam(3,
|
|
4795
|
-
__decorateParam(3,
|
|
4796
|
-
__decorateParam(4,
|
|
4797
|
-
__decorateParam(4,
|
|
4170
|
+
Injectable14(),
|
|
4171
|
+
__decorateParam(0, Optional7()),
|
|
4172
|
+
__decorateParam(0, Inject13(JOB_RUN_SERVICE)),
|
|
4173
|
+
__decorateParam(1, Optional7()),
|
|
4174
|
+
__decorateParam(1, Inject13(BRIDGE_DELIVERY_REPO)),
|
|
4175
|
+
__decorateParam(2, Optional7()),
|
|
4176
|
+
__decorateParam(2, Inject13(INTEGRATION_RUN_RECORDER)),
|
|
4177
|
+
__decorateParam(3, Optional7()),
|
|
4178
|
+
__decorateParam(3, Inject13(INTEGRATION_CURSOR_STORE)),
|
|
4179
|
+
__decorateParam(4, Optional7()),
|
|
4180
|
+
__decorateParam(4, Inject13(EVENT_READ_PORT))
|
|
4798
4181
|
], ObservabilityService);
|
|
4799
4182
|
|
|
4800
4183
|
// runtime/subsystems/observability/reporters/bridge-metrics.reporter.ts
|
|
4801
4184
|
import {
|
|
4802
|
-
Inject as
|
|
4803
|
-
Injectable as
|
|
4804
|
-
Logger as
|
|
4185
|
+
Inject as Inject14,
|
|
4186
|
+
Injectable as Injectable15,
|
|
4187
|
+
Logger as Logger7
|
|
4805
4188
|
} from "@nestjs/common";
|
|
4806
4189
|
var BridgeMetricsReporter = class {
|
|
4807
4190
|
constructor(observability, options) {
|
|
@@ -4809,7 +4192,7 @@ var BridgeMetricsReporter = class {
|
|
|
4809
4192
|
this.config = options.reporters?.bridgeMetrics;
|
|
4810
4193
|
}
|
|
4811
4194
|
observability;
|
|
4812
|
-
logger = new
|
|
4195
|
+
logger = new Logger7(BridgeMetricsReporter.name);
|
|
4813
4196
|
handle = null;
|
|
4814
4197
|
config;
|
|
4815
4198
|
onModuleInit() {
|
|
@@ -4860,9 +4243,9 @@ var BridgeMetricsReporter = class {
|
|
|
4860
4243
|
}
|
|
4861
4244
|
};
|
|
4862
4245
|
BridgeMetricsReporter = __decorateClass([
|
|
4863
|
-
|
|
4864
|
-
__decorateParam(0,
|
|
4865
|
-
__decorateParam(1,
|
|
4246
|
+
Injectable15(),
|
|
4247
|
+
__decorateParam(0, Inject14(OBSERVABILITY)),
|
|
4248
|
+
__decorateParam(1, Inject14(OBSERVABILITY_MODULE_OPTIONS))
|
|
4866
4249
|
], BridgeMetricsReporter);
|
|
4867
4250
|
|
|
4868
4251
|
// runtime/subsystems/observability/observability.module.ts
|
|
@@ -4917,25 +4300,25 @@ var OAuthStateError = class extends Error {
|
|
|
4917
4300
|
// runtime/subsystems/auth/auth.tokens.ts
|
|
4918
4301
|
var ENCRYPTION_KEY = /* @__PURE__ */ Symbol("ENCRYPTION_KEY");
|
|
4919
4302
|
var OAUTH_STATE_STORE = /* @__PURE__ */ Symbol("OAUTH_STATE_STORE");
|
|
4920
|
-
var
|
|
4921
|
-
var
|
|
4922
|
-
var
|
|
4303
|
+
var AUTH_CONNECTION_READER = /* @__PURE__ */ Symbol("AUTH_CONNECTION_READER");
|
|
4304
|
+
var AUTH_CONNECTION_TOKEN_WRITER = /* @__PURE__ */ Symbol("AUTH_CONNECTION_TOKEN_WRITER");
|
|
4305
|
+
var AUTH_CONNECTION_GRANT_SINK = /* @__PURE__ */ Symbol("AUTH_CONNECTION_GRANT_SINK");
|
|
4923
4306
|
var AUTH_USER_CONTEXT = /* @__PURE__ */ Symbol("AUTH_USER_CONTEXT");
|
|
4924
4307
|
var STRATEGY_REGISTRY = /* @__PURE__ */ Symbol("STRATEGY_REGISTRY");
|
|
4925
4308
|
var AUTH_OPTIONS = /* @__PURE__ */ Symbol("AUTH_OPTIONS");
|
|
4926
4309
|
|
|
4927
|
-
// runtime/subsystems/auth/runtime/
|
|
4928
|
-
var
|
|
4929
|
-
constructor(
|
|
4310
|
+
// runtime/subsystems/auth/runtime/connection-broken.error.ts
|
|
4311
|
+
var ConnectionBrokenError = class extends Error {
|
|
4312
|
+
constructor(connectionId, errorCode, errorDescription) {
|
|
4930
4313
|
super(
|
|
4931
|
-
`
|
|
4314
|
+
`Connection ${connectionId} broken: ${errorCode} - ${errorDescription}`
|
|
4932
4315
|
);
|
|
4933
|
-
this.
|
|
4316
|
+
this.connectionId = connectionId;
|
|
4934
4317
|
this.errorCode = errorCode;
|
|
4935
4318
|
this.errorDescription = errorDescription;
|
|
4936
|
-
this.name = "
|
|
4319
|
+
this.name = "ConnectionBrokenError";
|
|
4937
4320
|
}
|
|
4938
|
-
|
|
4321
|
+
connectionId;
|
|
4939
4322
|
errorCode;
|
|
4940
4323
|
errorDescription;
|
|
4941
4324
|
};
|
|
@@ -4943,53 +4326,53 @@ var IntegrationBrokenError = class extends Error {
|
|
|
4943
4326
|
// runtime/subsystems/auth/runtime/oauth2-refresh.strategy.ts
|
|
4944
4327
|
var REFRESH_SAFETY_MS = 5 * 60 * 1e3;
|
|
4945
4328
|
var OAuth2RefreshStrategy = class {
|
|
4946
|
-
|
|
4329
|
+
connectionReader;
|
|
4947
4330
|
tokenWriter;
|
|
4948
4331
|
fetchImpl;
|
|
4949
4332
|
now;
|
|
4950
4333
|
constructor(opts) {
|
|
4951
|
-
this.
|
|
4334
|
+
this.connectionReader = opts.connectionReader;
|
|
4952
4335
|
this.tokenWriter = opts.tokenWriter;
|
|
4953
4336
|
this.fetchImpl = opts.fetch ?? fetch;
|
|
4954
4337
|
this.now = opts.now ?? Date.now;
|
|
4955
4338
|
}
|
|
4956
|
-
async resolve(
|
|
4957
|
-
const
|
|
4958
|
-
if (!
|
|
4959
|
-
throw new Error(`
|
|
4339
|
+
async resolve(connectionId, opts = {}) {
|
|
4340
|
+
const connection = await this.connectionReader.findByIdDecrypted(connectionId);
|
|
4341
|
+
if (!connection) {
|
|
4342
|
+
throw new Error(`Connection ${connectionId} not found`);
|
|
4960
4343
|
}
|
|
4961
|
-
if (
|
|
4344
|
+
if (connection.provider !== this.provider) {
|
|
4962
4345
|
throw new Error(
|
|
4963
|
-
`${this.constructor.name} called for non-${this.provider}
|
|
4346
|
+
`${this.constructor.name} called for non-${this.provider} connection ${connectionId} (provider=${connection.provider})`
|
|
4964
4347
|
);
|
|
4965
4348
|
}
|
|
4966
|
-
const needsRefresh = opts.forceRefresh || this.isExpiring(
|
|
4349
|
+
const needsRefresh = opts.forceRefresh || this.isExpiring(connection.expiresAt) || !connection.accessToken;
|
|
4967
4350
|
if (!needsRefresh) {
|
|
4968
|
-
return this.buildCredentials(
|
|
4351
|
+
return this.buildCredentials(connection.accessToken, connection);
|
|
4969
4352
|
}
|
|
4970
|
-
if (!
|
|
4971
|
-
throw new
|
|
4972
|
-
|
|
4353
|
+
if (!connection.refreshToken) {
|
|
4354
|
+
throw new ConnectionBrokenError(
|
|
4355
|
+
connectionId,
|
|
4973
4356
|
"no_refresh_token",
|
|
4974
|
-
"
|
|
4357
|
+
"Connection has no refresh token; user must reconnect"
|
|
4975
4358
|
);
|
|
4976
4359
|
}
|
|
4977
4360
|
const { parsed, raw } = await this.executeRefresh(
|
|
4978
|
-
|
|
4979
|
-
|
|
4361
|
+
connectionId,
|
|
4362
|
+
connection.refreshToken
|
|
4980
4363
|
);
|
|
4981
4364
|
const newExpiresAt = new Date(
|
|
4982
4365
|
this.now() + (parsed.expiresInSec ?? this.defaultExpiresInSec) * 1e3
|
|
4983
4366
|
);
|
|
4984
4367
|
await this.tokenWriter.persistRefresh({
|
|
4985
|
-
|
|
4368
|
+
connectionId,
|
|
4986
4369
|
accessToken: parsed.accessToken,
|
|
4987
4370
|
refreshToken: parsed.refreshToken ?? void 0,
|
|
4988
4371
|
expiresAt: newExpiresAt
|
|
4989
4372
|
});
|
|
4990
|
-
return this.buildCredentials(parsed.accessToken,
|
|
4373
|
+
return this.buildCredentials(parsed.accessToken, connection, raw);
|
|
4991
4374
|
}
|
|
4992
|
-
async executeRefresh(
|
|
4375
|
+
async executeRefresh(connectionId, refreshToken) {
|
|
4993
4376
|
const body = new URLSearchParams({
|
|
4994
4377
|
grant_type: "refresh_token",
|
|
4995
4378
|
refresh_token: refreshToken,
|
|
@@ -5003,8 +4386,8 @@ var OAuth2RefreshStrategy = class {
|
|
|
5003
4386
|
if (!response.ok) {
|
|
5004
4387
|
const err = await safeJson(response);
|
|
5005
4388
|
if (response.status === 400 && (err.error === "invalid_grant" || err.error === "invalid_token")) {
|
|
5006
|
-
throw new
|
|
5007
|
-
|
|
4389
|
+
throw new ConnectionBrokenError(
|
|
4390
|
+
connectionId,
|
|
5008
4391
|
err.error ?? "invalid_grant",
|
|
5009
4392
|
err.error_description ?? err.message ?? "refresh token rejected"
|
|
5010
4393
|
);
|
|
@@ -5047,14 +4430,14 @@ function isSessionExpiredError(err) {
|
|
|
5047
4430
|
}
|
|
5048
4431
|
|
|
5049
4432
|
// runtime/subsystems/auth/runtime/with-auth-retry.ts
|
|
5050
|
-
async function withAuthRetry(authStrategy,
|
|
4433
|
+
async function withAuthRetry(authStrategy, connectionId, op, options = {}) {
|
|
5051
4434
|
const classify = options.isSessionExpired ?? isSessionExpiredError;
|
|
5052
|
-
let creds = await authStrategy.resolve(
|
|
4435
|
+
let creds = await authStrategy.resolve(connectionId);
|
|
5053
4436
|
try {
|
|
5054
4437
|
return await op(creds);
|
|
5055
4438
|
} catch (e) {
|
|
5056
4439
|
if (!classify(e)) throw e;
|
|
5057
|
-
creds = await authStrategy.resolve(
|
|
4440
|
+
creds = await authStrategy.resolve(connectionId, { forceRefresh: true });
|
|
5058
4441
|
return op(creds);
|
|
5059
4442
|
}
|
|
5060
4443
|
}
|
|
@@ -5156,7 +4539,7 @@ var MemoryOAuthStateStore = class {
|
|
|
5156
4539
|
|
|
5157
4540
|
// runtime/subsystems/auth/backends/state-store.drizzle-backend.ts
|
|
5158
4541
|
import { randomBytes as randomBytes3 } from "crypto";
|
|
5159
|
-
import { eq as
|
|
4542
|
+
import { eq as eq7 } from "drizzle-orm";
|
|
5160
4543
|
var DrizzleOAuthStateStore = class {
|
|
5161
4544
|
constructor(db, opts = {}) {
|
|
5162
4545
|
this.db = db;
|
|
@@ -5180,7 +4563,7 @@ var DrizzleOAuthStateStore = class {
|
|
|
5180
4563
|
return state;
|
|
5181
4564
|
}
|
|
5182
4565
|
async consume(state) {
|
|
5183
|
-
const rows = await this.db.delete(authOAuthState).where(
|
|
4566
|
+
const rows = await this.db.delete(authOAuthState).where(eq7(authOAuthState.state, state)).returning();
|
|
5184
4567
|
const row = rows[0];
|
|
5185
4568
|
if (!row) {
|
|
5186
4569
|
throw new OAuthStateError(
|
|
@@ -5202,7 +4585,7 @@ var DrizzleOAuthStateStore = class {
|
|
|
5202
4585
|
import {
|
|
5203
4586
|
Controller,
|
|
5204
4587
|
Get,
|
|
5205
|
-
Inject as
|
|
4588
|
+
Inject as Inject15,
|
|
5206
4589
|
Param,
|
|
5207
4590
|
Query,
|
|
5208
4591
|
Req,
|
|
@@ -5264,7 +4647,7 @@ var AuthController = class {
|
|
|
5264
4647
|
});
|
|
5265
4648
|
return res.redirect(
|
|
5266
4649
|
HttpStatus.FOUND,
|
|
5267
|
-
redirect ?? `/settings/
|
|
4650
|
+
redirect ?? `/settings/connections?connected=${encodeURIComponent(slug)}`
|
|
5268
4651
|
);
|
|
5269
4652
|
}
|
|
5270
4653
|
requireStrategy(slug) {
|
|
@@ -5304,11 +4687,11 @@ __decorateClass([
|
|
|
5304
4687
|
], AuthController.prototype, "callback", 1);
|
|
5305
4688
|
AuthController = __decorateClass([
|
|
5306
4689
|
Controller("auth"),
|
|
5307
|
-
__decorateParam(0,
|
|
5308
|
-
__decorateParam(1,
|
|
5309
|
-
__decorateParam(2,
|
|
5310
|
-
__decorateParam(3,
|
|
5311
|
-
__decorateParam(4,
|
|
4690
|
+
__decorateParam(0, Inject15(STRATEGY_REGISTRY)),
|
|
4691
|
+
__decorateParam(1, Inject15(AUTH_USER_CONTEXT)),
|
|
4692
|
+
__decorateParam(2, Inject15(OAUTH_STATE_STORE)),
|
|
4693
|
+
__decorateParam(3, Inject15(AUTH_CONNECTION_GRANT_SINK)),
|
|
4694
|
+
__decorateParam(4, Inject15(AUTH_OPTIONS))
|
|
5312
4695
|
], AuthController);
|
|
5313
4696
|
|
|
5314
4697
|
// runtime/base-classes/tenant-context.ts
|
|
@@ -5379,15 +4762,16 @@ AuthModule = __decorateClass([
|
|
|
5379
4762
|
Module7({})
|
|
5380
4763
|
], AuthModule);
|
|
5381
4764
|
export {
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
4765
|
+
AUTH_CONNECTION_GRANT_SINK,
|
|
4766
|
+
AUTH_CONNECTION_READER,
|
|
4767
|
+
AUTH_CONNECTION_TOKEN_WRITER,
|
|
5385
4768
|
AUTH_OPTIONS,
|
|
5386
4769
|
AUTH_USER_CONTEXT,
|
|
5387
4770
|
AuthController,
|
|
5388
4771
|
AuthModule,
|
|
5389
4772
|
CACHE,
|
|
5390
4773
|
CacheModule,
|
|
4774
|
+
ConnectionBrokenError,
|
|
5391
4775
|
DrizzleCacheService,
|
|
5392
4776
|
DrizzleEventBus,
|
|
5393
4777
|
DrizzleOAuthStateStore,
|
|
@@ -5395,7 +4779,6 @@ export {
|
|
|
5395
4779
|
EVENT_BUS,
|
|
5396
4780
|
EnvEncryptionKey,
|
|
5397
4781
|
EventsModule,
|
|
5398
|
-
IntegrationBrokenError,
|
|
5399
4782
|
LocalStorageBackend,
|
|
5400
4783
|
MemoryCacheService,
|
|
5401
4784
|
MemoryEventBus,
|