@qlever-llc/trellis 0.10.22 → 0.11.0-rc.1
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/esm/auth/mod.d.ts +1 -1
- package/esm/auth/mod.d.ts.map +1 -1
- package/esm/auth/mod.js +1 -1
- package/esm/auth/protocol.d.ts +55 -0
- package/esm/auth/protocol.d.ts.map +1 -1
- package/esm/browser.d.ts +3 -3
- package/esm/browser.d.ts.map +1 -1
- package/esm/browser.js +1 -1
- package/esm/client_connect.d.ts +12 -3
- package/esm/client_connect.d.ts.map +1 -1
- package/esm/client_connect.js +112 -7
- package/esm/codec.d.ts +7 -6
- package/esm/codec.d.ts.map +1 -1
- package/esm/codec.js +125 -6
- package/esm/contract_support/canonical.d.ts +3 -0
- package/esm/contract_support/canonical.d.ts.map +1 -1
- package/esm/contract_support/canonical.js +3 -0
- package/esm/contract_support/mod.d.ts +125 -10
- package/esm/contract_support/mod.d.ts.map +1 -1
- package/esm/contract_support/mod.js +159 -5
- package/esm/contract_support/protocol.d.ts +92 -7
- package/esm/contract_support/protocol.d.ts.map +1 -1
- package/esm/contract_support/protocol.js +41 -7
- package/esm/contract_support/runtime.d.ts +4 -1
- package/esm/contract_support/runtime.d.ts.map +1 -1
- package/esm/errors/SchemaValidationError.d.ts +49 -0
- package/esm/errors/SchemaValidationError.d.ts.map +1 -0
- package/esm/errors/SchemaValidationError.js +67 -0
- package/esm/errors/index.d.ts +38 -9
- package/esm/errors/index.d.ts.map +1 -1
- package/esm/errors/index.js +16 -0
- package/esm/generated-sdk/auth/api.d.ts +33 -605
- package/esm/generated-sdk/auth/api.d.ts.map +1 -1
- package/esm/generated-sdk/auth/api.js +6 -1
- package/esm/generated-sdk/auth/client.d.ts +129 -134
- package/esm/generated-sdk/auth/client.d.ts.map +1 -1
- package/esm/generated-sdk/auth/contract.d.ts +2 -601
- package/esm/generated-sdk/auth/contract.d.ts.map +1 -1
- package/esm/generated-sdk/auth/contract.js +310 -93
- package/esm/generated-sdk/auth/mod.d.ts +1 -1
- package/esm/generated-sdk/auth/mod.d.ts.map +1 -1
- package/esm/generated-sdk/auth/owned_api.d.ts +88 -86
- package/esm/generated-sdk/auth/owned_api.d.ts.map +1 -1
- package/esm/generated-sdk/auth/owned_api.js +6 -0
- package/esm/generated-sdk/auth/schemas.d.ts +284 -136
- package/esm/generated-sdk/auth/schemas.d.ts.map +1 -1
- package/esm/generated-sdk/auth/schemas.js +231 -92
- package/esm/generated-sdk/auth/types.d.ts +565 -89
- package/esm/generated-sdk/auth/types.d.ts.map +1 -1
- package/esm/generated-sdk/auth/types.js +1 -1
- package/esm/generated-sdk/health/api.d.ts +29 -18
- package/esm/generated-sdk/health/api.d.ts.map +1 -1
- package/esm/generated-sdk/health/client.d.ts +7 -21
- package/esm/generated-sdk/health/client.d.ts.map +1 -1
- package/esm/generated-sdk/health/contract.d.ts +2 -15
- package/esm/generated-sdk/health/contract.d.ts.map +1 -1
- package/esm/generated-sdk/health/contract.js +2 -10
- package/esm/generated-sdk/health/mod.d.ts +1 -1
- package/esm/generated-sdk/health/mod.d.ts.map +1 -1
- package/esm/generated-sdk/health/owned_api.d.ts +2 -2
- package/esm/generated-sdk/health/schemas.d.ts +1 -14
- package/esm/generated-sdk/health/schemas.d.ts.map +1 -1
- package/esm/generated-sdk/health/schemas.js +1 -9
- package/esm/generated-sdk/health/types.d.ts +10 -5
- package/esm/generated-sdk/health/types.d.ts.map +1 -1
- package/esm/generated-sdk/health/types.js +1 -2
- package/esm/generated-sdk/jobs/api.d.ts +29 -109
- package/esm/generated-sdk/jobs/api.d.ts.map +1 -1
- package/esm/generated-sdk/jobs/client.d.ts +21 -33
- package/esm/generated-sdk/jobs/client.d.ts.map +1 -1
- package/esm/generated-sdk/jobs/contract.d.ts +2 -106
- package/esm/generated-sdk/jobs/contract.d.ts.map +1 -1
- package/esm/generated-sdk/jobs/contract.js +268 -1
- package/esm/generated-sdk/jobs/mod.d.ts +1 -1
- package/esm/generated-sdk/jobs/mod.d.ts.map +1 -1
- package/esm/generated-sdk/jobs/owned_api.d.ts +22 -9
- package/esm/generated-sdk/jobs/owned_api.d.ts.map +1 -1
- package/esm/generated-sdk/jobs/owned_api.js +20 -1
- package/esm/generated-sdk/jobs/schemas.d.ts +437 -0
- package/esm/generated-sdk/jobs/schemas.d.ts.map +1 -1
- package/esm/generated-sdk/jobs/schemas.js +211 -0
- package/esm/generated-sdk/jobs/types.d.ts +195 -12
- package/esm/generated-sdk/jobs/types.d.ts.map +1 -1
- package/esm/generated-sdk/jobs/types.js +1 -1
- package/esm/generated-sdk/state/api.d.ts +29 -68
- package/esm/generated-sdk/state/api.d.ts.map +1 -1
- package/esm/generated-sdk/state/client.d.ts +17 -31
- package/esm/generated-sdk/state/client.d.ts.map +1 -1
- package/esm/generated-sdk/state/contract.d.ts +1 -64
- package/esm/generated-sdk/state/contract.d.ts.map +1 -1
- package/esm/generated-sdk/state/mod.d.ts +1 -1
- package/esm/generated-sdk/state/mod.d.ts.map +1 -1
- package/esm/generated-sdk/state/owned_api.d.ts +7 -7
- package/esm/generated-sdk/state/types.d.ts +52 -9
- package/esm/generated-sdk/state/types.d.ts.map +1 -1
- package/esm/generated-sdk/trellis-core/api.d.ts +33 -45
- package/esm/generated-sdk/trellis-core/api.d.ts.map +1 -1
- package/esm/generated-sdk/trellis-core/api.js +6 -1
- package/esm/generated-sdk/trellis-core/client.d.ts +31 -20
- package/esm/generated-sdk/trellis-core/client.d.ts.map +1 -1
- package/esm/generated-sdk/trellis-core/contract.d.ts +2 -41
- package/esm/generated-sdk/trellis-core/contract.d.ts.map +1 -1
- package/esm/generated-sdk/trellis-core/contract.js +91 -1
- package/esm/generated-sdk/trellis-core/mod.d.ts +1 -1
- package/esm/generated-sdk/trellis-core/mod.d.ts.map +1 -1
- package/esm/generated-sdk/trellis-core/owned_api.d.ts +4 -4
- package/esm/generated-sdk/trellis-core/schemas.d.ts +113 -0
- package/esm/generated-sdk/trellis-core/schemas.d.ts.map +1 -1
- package/esm/generated-sdk/trellis-core/schemas.js +81 -0
- package/esm/generated-sdk/trellis-core/types.d.ts +54 -7
- package/esm/generated-sdk/trellis-core/types.d.ts.map +1 -1
- package/esm/generated-sdk/trellis-core/types.js +1 -1
- package/esm/health.d.ts +1 -1
- package/esm/health.d.ts.map +1 -1
- package/esm/health.js +1 -1
- package/esm/index.d.ts +4 -4
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +2 -2
- package/esm/jobs.d.ts +69 -3
- package/esm/jobs.d.ts.map +1 -1
- package/esm/jobs.js +92 -3
- package/esm/server/health.d.ts +2 -6
- package/esm/server/health.d.ts.map +1 -1
- package/esm/server/health_schemas.d.ts +0 -8
- package/esm/server/health_schemas.d.ts.map +1 -1
- package/esm/server/health_schemas.js +0 -5
- package/esm/server/internal_jobs/bindings.d.ts +11 -0
- package/esm/server/internal_jobs/bindings.d.ts.map +1 -1
- package/esm/server/internal_jobs/job-manager.d.ts +58 -2
- package/esm/server/internal_jobs/job-manager.d.ts.map +1 -1
- package/esm/server/internal_jobs/job-manager.js +429 -55
- package/esm/server/internal_jobs/key-coordinator.d.ts +269 -0
- package/esm/server/internal_jobs/key-coordinator.d.ts.map +1 -0
- package/esm/server/internal_jobs/key-coordinator.js +677 -0
- package/esm/server/internal_jobs/projection.d.ts.map +1 -1
- package/esm/server/internal_jobs/projection.js +2 -0
- package/esm/server/internal_jobs/runtime-worker.d.ts +5 -1
- package/esm/server/internal_jobs/runtime-worker.d.ts.map +1 -1
- package/esm/server/internal_jobs/runtime-worker.js +14 -2
- package/esm/server/internal_jobs/types.d.ts +5 -5
- package/esm/server/internal_jobs/types.d.ts.map +1 -1
- package/esm/server/internal_jobs/types.js +6 -0
- package/esm/server/runtime.d.ts.map +1 -1
- package/esm/server/service.d.ts +81 -112
- package/esm/server/service.d.ts.map +1 -1
- package/esm/server/service.js +372 -130
- package/esm/server.d.ts +3 -3
- package/esm/server.d.ts.map +1 -1
- package/esm/service/deno.d.ts +1 -1
- package/esm/service/deno.d.ts.map +1 -1
- package/esm/service/drizzle.d.ts +52 -0
- package/esm/service/drizzle.d.ts.map +1 -0
- package/esm/service/drizzle.js +108 -0
- package/esm/service/mod.d.ts +3 -3
- package/esm/service/mod.d.ts.map +1 -1
- package/esm/service/mod.js +2 -2
- package/esm/service/node.d.ts +1 -1
- package/esm/service/node.d.ts.map +1 -1
- package/esm/service/outbox_inbox.d.ts +76 -22
- package/esm/service/outbox_inbox.d.ts.map +1 -1
- package/esm/service/outbox_inbox.js +231 -70
- package/esm/telemetry/metrics.d.ts +55 -0
- package/esm/telemetry/metrics.d.ts.map +1 -1
- package/esm/telemetry/metrics.js +86 -0
- package/esm/telemetry/mod.d.ts +2 -1
- package/esm/telemetry/mod.d.ts.map +1 -1
- package/esm/telemetry/mod.js +1 -1
- package/esm/trellis.d.ts +62 -30
- package/esm/trellis.d.ts.map +1 -1
- package/esm/trellis.js +125 -42
- package/package.json +14 -2
- package/script/auth/mod.d.ts +1 -1
- package/script/auth/mod.d.ts.map +1 -1
- package/script/auth/mod.js +11 -4
- package/script/auth/protocol.d.ts +55 -0
- package/script/auth/protocol.d.ts.map +1 -1
- package/script/browser.d.ts +3 -3
- package/script/browser.d.ts.map +1 -1
- package/script/browser.js +3 -2
- package/script/client_connect.d.ts +12 -3
- package/script/client_connect.d.ts.map +1 -1
- package/script/client_connect.js +111 -6
- package/script/codec.d.ts +7 -6
- package/script/codec.d.ts.map +1 -1
- package/script/codec.js +124 -5
- package/script/contract_support/canonical.d.ts +3 -0
- package/script/contract_support/canonical.d.ts.map +1 -1
- package/script/contract_support/canonical.js +3 -0
- package/script/contract_support/mod.d.ts +125 -10
- package/script/contract_support/mod.d.ts.map +1 -1
- package/script/contract_support/mod.js +165 -5
- package/script/contract_support/protocol.d.ts +92 -7
- package/script/contract_support/protocol.d.ts.map +1 -1
- package/script/contract_support/protocol.js +42 -8
- package/script/contract_support/runtime.d.ts +4 -1
- package/script/contract_support/runtime.d.ts.map +1 -1
- package/script/errors/SchemaValidationError.d.ts +49 -0
- package/script/errors/SchemaValidationError.d.ts.map +1 -0
- package/script/errors/SchemaValidationError.js +74 -0
- package/script/errors/index.d.ts +38 -9
- package/script/errors/index.d.ts.map +1 -1
- package/script/errors/index.js +20 -1
- package/script/generated-sdk/auth/api.d.ts +33 -605
- package/script/generated-sdk/auth/api.d.ts.map +1 -1
- package/script/generated-sdk/auth/api.js +6 -1
- package/script/generated-sdk/auth/client.d.ts +129 -134
- package/script/generated-sdk/auth/client.d.ts.map +1 -1
- package/script/generated-sdk/auth/contract.d.ts +2 -601
- package/script/generated-sdk/auth/contract.d.ts.map +1 -1
- package/script/generated-sdk/auth/contract.js +310 -93
- package/script/generated-sdk/auth/mod.d.ts +1 -1
- package/script/generated-sdk/auth/mod.d.ts.map +1 -1
- package/script/generated-sdk/auth/owned_api.d.ts +88 -86
- package/script/generated-sdk/auth/owned_api.d.ts.map +1 -1
- package/script/generated-sdk/auth/owned_api.js +6 -0
- package/script/generated-sdk/auth/schemas.d.ts +284 -136
- package/script/generated-sdk/auth/schemas.d.ts.map +1 -1
- package/script/generated-sdk/auth/schemas.js +231 -92
- package/script/generated-sdk/auth/types.d.ts +565 -89
- package/script/generated-sdk/auth/types.d.ts.map +1 -1
- package/script/generated-sdk/auth/types.js +1 -1
- package/script/generated-sdk/health/api.d.ts +29 -18
- package/script/generated-sdk/health/api.d.ts.map +1 -1
- package/script/generated-sdk/health/client.d.ts +7 -21
- package/script/generated-sdk/health/client.d.ts.map +1 -1
- package/script/generated-sdk/health/contract.d.ts +2 -15
- package/script/generated-sdk/health/contract.d.ts.map +1 -1
- package/script/generated-sdk/health/contract.js +2 -10
- package/script/generated-sdk/health/mod.d.ts +1 -1
- package/script/generated-sdk/health/mod.d.ts.map +1 -1
- package/script/generated-sdk/health/owned_api.d.ts +2 -2
- package/script/generated-sdk/health/schemas.d.ts +1 -14
- package/script/generated-sdk/health/schemas.d.ts.map +1 -1
- package/script/generated-sdk/health/schemas.js +1 -9
- package/script/generated-sdk/health/types.d.ts +10 -5
- package/script/generated-sdk/health/types.d.ts.map +1 -1
- package/script/generated-sdk/health/types.js +1 -2
- package/script/generated-sdk/jobs/api.d.ts +29 -109
- package/script/generated-sdk/jobs/api.d.ts.map +1 -1
- package/script/generated-sdk/jobs/client.d.ts +21 -33
- package/script/generated-sdk/jobs/client.d.ts.map +1 -1
- package/script/generated-sdk/jobs/contract.d.ts +2 -106
- package/script/generated-sdk/jobs/contract.d.ts.map +1 -1
- package/script/generated-sdk/jobs/contract.js +268 -1
- package/script/generated-sdk/jobs/mod.d.ts +1 -1
- package/script/generated-sdk/jobs/mod.d.ts.map +1 -1
- package/script/generated-sdk/jobs/owned_api.d.ts +22 -9
- package/script/generated-sdk/jobs/owned_api.d.ts.map +1 -1
- package/script/generated-sdk/jobs/owned_api.js +19 -0
- package/script/generated-sdk/jobs/schemas.d.ts +437 -0
- package/script/generated-sdk/jobs/schemas.d.ts.map +1 -1
- package/script/generated-sdk/jobs/schemas.js +212 -1
- package/script/generated-sdk/jobs/types.d.ts +195 -12
- package/script/generated-sdk/jobs/types.d.ts.map +1 -1
- package/script/generated-sdk/jobs/types.js +1 -1
- package/script/generated-sdk/state/api.d.ts +29 -68
- package/script/generated-sdk/state/api.d.ts.map +1 -1
- package/script/generated-sdk/state/client.d.ts +17 -31
- package/script/generated-sdk/state/client.d.ts.map +1 -1
- package/script/generated-sdk/state/contract.d.ts +1 -64
- package/script/generated-sdk/state/contract.d.ts.map +1 -1
- package/script/generated-sdk/state/mod.d.ts +1 -1
- package/script/generated-sdk/state/mod.d.ts.map +1 -1
- package/script/generated-sdk/state/owned_api.d.ts +7 -7
- package/script/generated-sdk/state/types.d.ts +52 -9
- package/script/generated-sdk/state/types.d.ts.map +1 -1
- package/script/generated-sdk/trellis-core/api.d.ts +33 -45
- package/script/generated-sdk/trellis-core/api.d.ts.map +1 -1
- package/script/generated-sdk/trellis-core/api.js +6 -1
- package/script/generated-sdk/trellis-core/client.d.ts +31 -20
- package/script/generated-sdk/trellis-core/client.d.ts.map +1 -1
- package/script/generated-sdk/trellis-core/contract.d.ts +2 -41
- package/script/generated-sdk/trellis-core/contract.d.ts.map +1 -1
- package/script/generated-sdk/trellis-core/contract.js +91 -1
- package/script/generated-sdk/trellis-core/mod.d.ts +1 -1
- package/script/generated-sdk/trellis-core/mod.d.ts.map +1 -1
- package/script/generated-sdk/trellis-core/owned_api.d.ts +4 -4
- package/script/generated-sdk/trellis-core/schemas.d.ts +113 -0
- package/script/generated-sdk/trellis-core/schemas.d.ts.map +1 -1
- package/script/generated-sdk/trellis-core/schemas.js +81 -0
- package/script/generated-sdk/trellis-core/types.d.ts +54 -7
- package/script/generated-sdk/trellis-core/types.d.ts.map +1 -1
- package/script/generated-sdk/trellis-core/types.js +1 -1
- package/script/health.d.ts +1 -1
- package/script/health.d.ts.map +1 -1
- package/script/health.js +1 -2
- package/script/index.d.ts +4 -4
- package/script/index.d.ts.map +1 -1
- package/script/index.js +2 -2
- package/script/jobs.d.ts +69 -3
- package/script/jobs.d.ts.map +1 -1
- package/script/jobs.js +93 -3
- package/script/server/health.d.ts +2 -6
- package/script/server/health.d.ts.map +1 -1
- package/script/server/health_schemas.d.ts +0 -8
- package/script/server/health_schemas.d.ts.map +1 -1
- package/script/server/health_schemas.js +1 -6
- package/script/server/internal_jobs/bindings.d.ts +11 -0
- package/script/server/internal_jobs/bindings.d.ts.map +1 -1
- package/script/server/internal_jobs/job-manager.d.ts +58 -2
- package/script/server/internal_jobs/job-manager.d.ts.map +1 -1
- package/script/server/internal_jobs/job-manager.js +429 -54
- package/script/server/internal_jobs/key-coordinator.d.ts +269 -0
- package/script/server/internal_jobs/key-coordinator.d.ts.map +1 -0
- package/script/server/internal_jobs/key-coordinator.js +690 -0
- package/script/server/internal_jobs/projection.d.ts.map +1 -1
- package/script/server/internal_jobs/projection.js +2 -0
- package/script/server/internal_jobs/runtime-worker.d.ts +5 -1
- package/script/server/internal_jobs/runtime-worker.d.ts.map +1 -1
- package/script/server/internal_jobs/runtime-worker.js +14 -2
- package/script/server/internal_jobs/types.d.ts +5 -5
- package/script/server/internal_jobs/types.d.ts.map +1 -1
- package/script/server/internal_jobs/types.js +6 -0
- package/script/server/runtime.d.ts.map +1 -1
- package/script/server/service.d.ts +81 -112
- package/script/server/service.d.ts.map +1 -1
- package/script/server/service.js +369 -127
- package/script/server.d.ts +3 -3
- package/script/server.d.ts.map +1 -1
- package/script/service/deno.d.ts +1 -1
- package/script/service/deno.d.ts.map +1 -1
- package/script/service/drizzle.d.ts +52 -0
- package/script/service/drizzle.d.ts.map +1 -0
- package/script/service/drizzle.js +113 -0
- package/script/service/mod.d.ts +3 -3
- package/script/service/mod.d.ts.map +1 -1
- package/script/service/mod.js +4 -3
- package/script/service/node.d.ts +1 -1
- package/script/service/node.d.ts.map +1 -1
- package/script/service/outbox_inbox.d.ts +76 -22
- package/script/service/outbox_inbox.d.ts.map +1 -1
- package/script/service/outbox_inbox.js +233 -70
- package/script/telemetry/metrics.d.ts +55 -0
- package/script/telemetry/metrics.d.ts.map +1 -1
- package/script/telemetry/metrics.js +88 -0
- package/script/telemetry/mod.d.ts +2 -1
- package/script/telemetry/mod.d.ts.map +1 -1
- package/script/telemetry/mod.js +3 -1
- package/script/trellis.d.ts +62 -30
- package/script/trellis.d.ts.map +1 -1
- package/script/trellis.js +124 -41
- package/src/auth/mod.ts +7 -0
- package/src/browser.ts +5 -7
- package/src/client_connect.ts +200 -12
- package/src/codec.ts +186 -11
- package/src/contract_support/canonical.ts +3 -0
- package/src/contract_support/mod.ts +380 -9
- package/src/contract_support/protocol.ts +57 -10
- package/src/contract_support/runtime.ts +7 -0
- package/src/errors/SchemaValidationError.ts +67 -0
- package/src/errors/index.ts +28 -0
- package/src/health.ts +0 -1
- package/src/index.ts +7 -8
- package/src/jobs.ts +138 -1
- package/src/sdk/_generated/auth/api.ts +38 -7
- package/src/sdk/_generated/auth/client.ts +168 -530
- package/src/sdk/_generated/auth/contract.ts +310 -93
- package/src/sdk/_generated/auth/mod.ts +0 -1
- package/src/sdk/_generated/auth/owned_api.ts +92 -86
- package/src/sdk/_generated/auth/schemas.ts +231 -92
- package/src/sdk/_generated/auth/types.ts +1069 -273
- package/src/sdk/_generated/core/api.ts +38 -7
- package/src/sdk/_generated/core/client.ts +47 -73
- package/src/sdk/_generated/core/contract.ts +91 -1
- package/src/sdk/_generated/core/mod.ts +0 -1
- package/src/sdk/_generated/core/owned_api.ts +4 -4
- package/src/sdk/_generated/core/schemas.ts +81 -0
- package/src/sdk/_generated/core/types.ts +79 -15
- package/src/sdk/_generated/health/api.ts +29 -5
- package/src/sdk/_generated/health/client.ts +11 -58
- package/src/sdk/_generated/health/contract.ts +2 -10
- package/src/sdk/_generated/health/mod.ts +0 -1
- package/src/sdk/_generated/health/owned_api.ts +2 -2
- package/src/sdk/_generated/health/schemas.ts +1 -9
- package/src/sdk/_generated/health/types.ts +23 -2
- package/src/sdk/_generated/jobs/api.ts +29 -5
- package/src/sdk/_generated/jobs/client.ts +25 -109
- package/src/sdk/_generated/jobs/contract.ts +269 -1
- package/src/sdk/_generated/jobs/mod.ts +0 -1
- package/src/sdk/_generated/jobs/owned_api.ts +30 -9
- package/src/sdk/_generated/jobs/schemas.ts +213 -0
- package/src/sdk/_generated/jobs/types.ts +252 -18
- package/src/sdk/_generated/state/api.ts +29 -5
- package/src/sdk/_generated/state/client.ts +18 -95
- package/src/sdk/_generated/state/mod.ts +0 -1
- package/src/sdk/_generated/state/owned_api.ts +7 -7
- package/src/sdk/_generated/state/types.ts +91 -15
- package/src/server/health.ts +2 -6
- package/src/server/health_schemas.ts +0 -6
- package/src/server/internal_jobs/bindings.ts +11 -0
- package/src/server/internal_jobs/job-manager.ts +553 -24
- package/src/server/internal_jobs/key-coordinator.ts +1080 -0
- package/src/server/internal_jobs/projection.ts +2 -0
- package/src/server/internal_jobs/runtime-worker.ts +17 -1
- package/src/server/internal_jobs/types.ts +6 -0
- package/src/server/runtime.ts +4 -0
- package/src/server/service.ts +645 -625
- package/src/server.ts +14 -7
- package/src/service/deno.ts +0 -5
- package/src/service/drizzle.ts +184 -0
- package/src/service/mod.ts +17 -7
- package/src/service/node.ts +0 -5
- package/src/service/outbox_inbox.ts +354 -88
- package/src/telemetry/metrics.ts +198 -1
- package/src/telemetry/mod.ts +6 -0
- package/src/trellis.ts +286 -105
package/src/trellis.ts
CHANGED
|
@@ -68,6 +68,7 @@ import {
|
|
|
68
68
|
AuthError,
|
|
69
69
|
BUILTIN_RPC_ERRORS,
|
|
70
70
|
getBuiltinRpcError,
|
|
71
|
+
SchemaValidationError,
|
|
71
72
|
type StoreError,
|
|
72
73
|
TransferError,
|
|
73
74
|
TransportError,
|
|
@@ -248,14 +249,14 @@ function classifyRequestTransportFailure(args: {
|
|
|
248
249
|
function encodeRuntimeSchema(
|
|
249
250
|
schema: unknown,
|
|
250
251
|
data: unknown,
|
|
251
|
-
): Result<string, ValidationError | UnexpectedError> {
|
|
252
|
+
): Result<string, SchemaValidationError | ValidationError | UnexpectedError> {
|
|
252
253
|
return encodeSchema(schema as never, data);
|
|
253
254
|
}
|
|
254
255
|
|
|
255
256
|
function parseRuntimeSchema(
|
|
256
257
|
schema: unknown,
|
|
257
258
|
data: JsonValue,
|
|
258
|
-
): Result<unknown, ValidationError | UnexpectedError> {
|
|
259
|
+
): Result<unknown, SchemaValidationError | ValidationError | UnexpectedError> {
|
|
259
260
|
return parseUnknownSchema(
|
|
260
261
|
schema as Parameters<typeof parseUnknownSchema>[0],
|
|
261
262
|
data,
|
|
@@ -479,24 +480,79 @@ type RequestErrorOf<TA extends AnyTrellisAPI, M extends MethodsOf<TA>> =
|
|
|
479
480
|
type HandlerErrorOf<TA extends AnyTrellisAPI, M extends MethodsOf<TA>> =
|
|
480
481
|
| MethodDeclaredErrorOf<TA, M>
|
|
481
482
|
| TrellisErrorInstance;
|
|
482
|
-
|
|
483
|
+
|
|
484
|
+
type OperationDescriptorOf<
|
|
485
|
+
TA extends AnyTrellisAPI,
|
|
486
|
+
O extends OperationsOf<TA>,
|
|
487
|
+
> = TA["operations"][O] extends {
|
|
488
|
+
input: infer TInput;
|
|
489
|
+
progress?: infer TProgress;
|
|
490
|
+
output?: infer TOutput;
|
|
491
|
+
errors?: infer TErrors;
|
|
492
|
+
runtimeErrors?: infer TRuntimeErrors;
|
|
493
|
+
declaredErrorTypes?: infer TDeclaredErrorTypes;
|
|
494
|
+
} ? {
|
|
495
|
+
input: TInput;
|
|
496
|
+
progress?: TProgress;
|
|
497
|
+
output?: TOutput;
|
|
498
|
+
errors?: TErrors;
|
|
499
|
+
runtimeErrors?: TRuntimeErrors;
|
|
500
|
+
declaredErrorTypes?: TDeclaredErrorTypes;
|
|
501
|
+
} & TA["operations"][O]
|
|
502
|
+
: never;
|
|
503
|
+
|
|
504
|
+
type OperationDeclaredErrorOf<
|
|
505
|
+
TA extends AnyTrellisAPI,
|
|
506
|
+
O extends OperationsOf<TA>,
|
|
507
|
+
> = OperationDescriptorOf<TA, O> extends {
|
|
508
|
+
errors?: infer TErrors;
|
|
509
|
+
runtimeErrors?: infer TRuntimeErrors;
|
|
510
|
+
} ? DeclaredBuiltinErrorOf<TErrors> | DeclaredRuntimeErrorOf<TRuntimeErrors>
|
|
511
|
+
: never;
|
|
512
|
+
|
|
513
|
+
export type OperationHandlerErrorOf<
|
|
514
|
+
TA extends AnyTrellisAPI,
|
|
515
|
+
O extends OperationsOf<TA>,
|
|
516
|
+
> = OperationDeclaredErrorOf<TA, O> | TrellisErrorInstance;
|
|
517
|
+
type EventMessageOf<TA extends AnyTrellisAPI, E extends EventsOf<TA>> =
|
|
483
518
|
TA["events"][E] extends EventDesc<infer TEvent> ? InferSchemaType<TEvent>
|
|
484
519
|
: never;
|
|
520
|
+
type EventOf<TA extends AnyTrellisAPI, E extends EventsOf<TA>> = EventMessageOf<
|
|
521
|
+
TA,
|
|
522
|
+
E
|
|
523
|
+
>;
|
|
485
524
|
type EventDescriptorOf<TA extends AnyTrellisAPI, E extends EventsOf<TA>> =
|
|
486
525
|
TA["events"][E] extends EventDesc<infer TEvent>
|
|
487
526
|
? EventDesc<TEvent> & TA["events"][E]
|
|
488
527
|
: never;
|
|
489
|
-
type EventPayloadOf<TA extends AnyTrellisAPI, E extends EventsOf<TA>> =
|
|
490
|
-
EventOf<TA, E
|
|
491
|
-
|
|
492
|
-
|
|
528
|
+
type EventPayloadOf<TA extends AnyTrellisAPI, E extends EventsOf<TA>> =
|
|
529
|
+
& EventOf<TA, E>
|
|
530
|
+
& Record<string, unknown>;
|
|
531
|
+
/** Runtime metadata assigned to every Trellis event message. */
|
|
532
|
+
export type TrellisEventHeader = Readonly<{
|
|
533
|
+
/** Stable event id used for event identity and JetStream de-duplication. */
|
|
534
|
+
id: string;
|
|
535
|
+
/** Event creation time in ISO-8601 format. */
|
|
536
|
+
time: string;
|
|
537
|
+
}>;
|
|
538
|
+
/** Event body plus Trellis runtime event metadata. */
|
|
539
|
+
export type TrellisEventMessage<
|
|
540
|
+
TBody extends Record<string, unknown> = Record<string, unknown>,
|
|
541
|
+
> = Readonly<{
|
|
542
|
+
/** User-authored contract event body. */
|
|
543
|
+
body: Readonly<TBody>;
|
|
544
|
+
/** Runtime metadata assigned by Trellis. */
|
|
545
|
+
header: TrellisEventHeader;
|
|
546
|
+
}>;
|
|
493
547
|
/** A fully encoded event whose subject, payload, and headers are stable. */
|
|
494
548
|
export type PreparedTrellisEvent<
|
|
495
549
|
TPayload extends Record<string, unknown> = Record<string, unknown>,
|
|
496
550
|
> = Readonly<{
|
|
497
551
|
event: string;
|
|
498
552
|
subject: string;
|
|
499
|
-
|
|
553
|
+
/** Runtime event metadata assigned when the event was prepared. */
|
|
554
|
+
header: TrellisEventHeader;
|
|
555
|
+
payload: Readonly<TPayload>;
|
|
500
556
|
encodedPayload: string;
|
|
501
557
|
headers: Readonly<Record<string, string>>;
|
|
502
558
|
}>;
|
|
@@ -521,17 +577,21 @@ export type OperationInputOf<
|
|
|
521
577
|
export type OperationProgressOf<
|
|
522
578
|
TA extends AnyTrellisAPI,
|
|
523
579
|
O extends OperationsOf<TA>,
|
|
524
|
-
> = TA["operations"][O] extends { progress
|
|
580
|
+
> = TA["operations"][O] extends { progress?: infer TProgress }
|
|
525
581
|
? TProgress extends undefined ? unknown
|
|
526
582
|
: InferSchemaType<NonNullable<TProgress>>
|
|
527
583
|
: unknown;
|
|
528
584
|
export type OperationOutputOf<
|
|
529
585
|
TA extends AnyTrellisAPI,
|
|
530
586
|
O extends OperationsOf<TA>,
|
|
531
|
-
> = TA["operations"][O] extends { output
|
|
587
|
+
> = TA["operations"][O] extends { output?: infer TOutput }
|
|
532
588
|
? TOutput extends undefined ? unknown : InferSchemaType<NonNullable<TOutput>>
|
|
533
589
|
: unknown;
|
|
534
|
-
export type OperationRuntimeHandle<
|
|
590
|
+
export type OperationRuntimeHandle<
|
|
591
|
+
TProgress,
|
|
592
|
+
TOutput,
|
|
593
|
+
TError extends BaseError,
|
|
594
|
+
> = {
|
|
535
595
|
id: string;
|
|
536
596
|
started(): AsyncResult<RuntimeOperationSnapshot, BaseError>;
|
|
537
597
|
progress(
|
|
@@ -541,7 +601,7 @@ export type OperationRuntimeHandle<TProgress = unknown, TOutput = unknown> = {
|
|
|
541
601
|
value: TOutput,
|
|
542
602
|
): AsyncResult<RuntimeOperationSnapshot, BaseError>;
|
|
543
603
|
fail(
|
|
544
|
-
error:
|
|
604
|
+
error: TError,
|
|
545
605
|
): AsyncResult<RuntimeOperationSnapshot, BaseError>;
|
|
546
606
|
cancel(): AsyncResult<RuntimeOperationSnapshot, BaseError>;
|
|
547
607
|
attach(
|
|
@@ -567,8 +627,12 @@ export function isOperationDeferred(
|
|
|
567
627
|
return !!value && typeof value === "object" &&
|
|
568
628
|
"kind" in value && value.kind === "deferred";
|
|
569
629
|
}
|
|
570
|
-
export type AcceptedOperation<
|
|
571
|
-
|
|
630
|
+
export type AcceptedOperation<
|
|
631
|
+
TProgress,
|
|
632
|
+
TOutput,
|
|
633
|
+
TError extends BaseError,
|
|
634
|
+
> =
|
|
635
|
+
& OperationRuntimeHandle<TProgress, TOutput, TError>
|
|
572
636
|
& {
|
|
573
637
|
ref: OperationRefData;
|
|
574
638
|
snapshot: RuntimeOperationSnapshot & {
|
|
@@ -679,33 +743,44 @@ export type StateFacade<TState extends RuntimeStateStores> = {
|
|
|
679
743
|
};
|
|
680
744
|
export type OperationHandlerContext<
|
|
681
745
|
TInput,
|
|
682
|
-
TProgress
|
|
683
|
-
TOutput
|
|
684
|
-
TTransfer
|
|
746
|
+
TProgress,
|
|
747
|
+
TOutput,
|
|
748
|
+
TTransfer,
|
|
749
|
+
TError extends BaseError,
|
|
685
750
|
> = {
|
|
686
751
|
input: TInput;
|
|
687
|
-
op: OperationRuntimeHandle<TProgress, TOutput>;
|
|
752
|
+
op: OperationRuntimeHandle<TProgress, TOutput, TError>;
|
|
688
753
|
caller: SessionCaller;
|
|
689
754
|
} & (TTransfer extends undefined ? {} : { transfer: TTransfer });
|
|
690
755
|
export type OperationRegistration<
|
|
691
756
|
TInput,
|
|
692
|
-
TProgress
|
|
693
|
-
TOutput
|
|
694
|
-
TTransfer
|
|
757
|
+
TProgress,
|
|
758
|
+
TOutput,
|
|
759
|
+
TTransfer,
|
|
760
|
+
TError extends BaseError,
|
|
695
761
|
> = {
|
|
696
762
|
accept(args: {
|
|
697
763
|
sessionKey: string;
|
|
698
|
-
}): AsyncResult<
|
|
764
|
+
}): AsyncResult<
|
|
765
|
+
AcceptedOperation<TProgress, TOutput, TError>,
|
|
766
|
+
UnexpectedError
|
|
767
|
+
>;
|
|
699
768
|
/**
|
|
700
769
|
* Loads an existing operation by id and returns a service-side control handle.
|
|
701
770
|
* The operation must belong to this service and registration name.
|
|
702
771
|
*/
|
|
703
772
|
control(
|
|
704
773
|
operationId: string,
|
|
705
|
-
): AsyncResult<OperationRuntimeHandle<TProgress, TOutput>, BaseError>;
|
|
774
|
+
): AsyncResult<OperationRuntimeHandle<TProgress, TOutput, TError>, BaseError>;
|
|
706
775
|
handle(
|
|
707
776
|
handler: (
|
|
708
|
-
context: OperationHandlerContext<
|
|
777
|
+
context: OperationHandlerContext<
|
|
778
|
+
TInput,
|
|
779
|
+
TProgress,
|
|
780
|
+
TOutput,
|
|
781
|
+
TTransfer,
|
|
782
|
+
TError
|
|
783
|
+
>,
|
|
709
784
|
) => unknown | Promise<unknown>,
|
|
710
785
|
): Promise<void>;
|
|
711
786
|
};
|
|
@@ -724,7 +799,8 @@ export type OperationSurface<
|
|
|
724
799
|
OperationInputOf<TA, O>,
|
|
725
800
|
OperationProgressOf<TA, O>,
|
|
726
801
|
OperationOutputOf<TA, O>,
|
|
727
|
-
OperationTransferContextOf<TA, O
|
|
802
|
+
OperationTransferContextOf<TA, O>,
|
|
803
|
+
OperationHandlerErrorOf<TA, O>
|
|
728
804
|
>
|
|
729
805
|
: OperationInvoker<TA["operations"][O] & RuntimeOperationDesc>;
|
|
730
806
|
|
|
@@ -1088,26 +1164,18 @@ export type EventListenerContext = {
|
|
|
1088
1164
|
};
|
|
1089
1165
|
|
|
1090
1166
|
function createEventListenerContext(args: {
|
|
1091
|
-
payload: unknown;
|
|
1092
1167
|
subject: string;
|
|
1093
1168
|
mode: "durable" | "ephemeral";
|
|
1094
1169
|
group?: string;
|
|
1095
1170
|
message: object;
|
|
1096
1171
|
}): EventListenerContext {
|
|
1097
|
-
const
|
|
1098
|
-
|
|
1099
|
-
: undefined;
|
|
1100
|
-
const id = typeof header === "object" && header !== null
|
|
1101
|
-
? Reflect.get(header, "id")
|
|
1102
|
-
: undefined;
|
|
1103
|
-
const time = typeof header === "object" && header !== null
|
|
1104
|
-
? Reflect.get(header, "time")
|
|
1105
|
-
: undefined;
|
|
1172
|
+
const messageId = readMessageHeader(args.message, "Nats-Msg-Id");
|
|
1173
|
+
const messageTime = readMessageHeader(args.message, "Trellis-Event-Time");
|
|
1106
1174
|
const sequence = Reflect.get(args.message, "seq");
|
|
1107
1175
|
|
|
1108
1176
|
return {
|
|
1109
|
-
id:
|
|
1110
|
-
time: new Date(
|
|
1177
|
+
id: messageId ?? "",
|
|
1178
|
+
time: new Date(messageTime ?? 0),
|
|
1111
1179
|
subject: args.subject,
|
|
1112
1180
|
mode: args.mode,
|
|
1113
1181
|
...(args.group ? { group: args.group } : {}),
|
|
@@ -1115,6 +1183,15 @@ function createEventListenerContext(args: {
|
|
|
1115
1183
|
};
|
|
1116
1184
|
}
|
|
1117
1185
|
|
|
1186
|
+
function readMessageHeader(message: object, key: string): string | undefined {
|
|
1187
|
+
const headers = Reflect.get(message, "headers");
|
|
1188
|
+
if (typeof headers !== "object" || headers === null) return undefined;
|
|
1189
|
+
const get = Reflect.get(headers, "get");
|
|
1190
|
+
if (typeof get !== "function") return undefined;
|
|
1191
|
+
const value = get.call(headers, key);
|
|
1192
|
+
return typeof value === "string" ? value : undefined;
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1118
1195
|
type RuntimeEventConsumers = {
|
|
1119
1196
|
metadata?: RuntimeEventConsumerGroups;
|
|
1120
1197
|
bindings?: Record<string, EventConsumerResourceBinding>;
|
|
@@ -1129,6 +1206,12 @@ type RuntimeEventConsumerGroups = Readonly<
|
|
|
1129
1206
|
Record<string, RuntimeEventConsumerGroup>
|
|
1130
1207
|
>;
|
|
1131
1208
|
|
|
1209
|
+
/** @internal Hook used by Trellis-owned integration tests for durable event interleavings. */
|
|
1210
|
+
export type TrellisDurableEventConsumerBeforeReadinessCheckHook = (args: {
|
|
1211
|
+
group: string;
|
|
1212
|
+
subject: string;
|
|
1213
|
+
}) => void | Promise<void>;
|
|
1214
|
+
|
|
1132
1215
|
function eventConsumerGroupEvents(group: RuntimeEventConsumerGroup): string[] {
|
|
1133
1216
|
const events = new Set<string>();
|
|
1134
1217
|
for (const groupEvents of Object.values(group.uses ?? {})) {
|
|
@@ -1138,11 +1221,29 @@ function eventConsumerGroupEvents(group: RuntimeEventConsumerGroup): string[] {
|
|
|
1138
1221
|
return [...events].sort();
|
|
1139
1222
|
}
|
|
1140
1223
|
|
|
1224
|
+
function isConsumerNotFoundError(error: unknown): boolean {
|
|
1225
|
+
return error instanceof Error && (
|
|
1226
|
+
error.name === "ConsumerNotFoundError" ||
|
|
1227
|
+
error.message.includes("consumer not found")
|
|
1228
|
+
);
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1141
1231
|
type TrellisInternalOpts<TA extends AnyTrellisAPI> = TrellisOpts<TA> & {
|
|
1142
1232
|
eventConsumers?: RuntimeEventConsumers;
|
|
1233
|
+
durableEventConsumerBeforeReadinessCheck?:
|
|
1234
|
+
TrellisDurableEventConsumerBeforeReadinessCheckHook;
|
|
1143
1235
|
};
|
|
1144
1236
|
|
|
1145
|
-
|
|
1237
|
+
const internalEventConsumers = Symbol("trellis.internal.eventConsumers");
|
|
1238
|
+
const internalDurableEventConsumerBeforeReadinessCheck = Symbol(
|
|
1239
|
+
"trellis.internal.durableEventConsumerBeforeReadinessCheck",
|
|
1240
|
+
);
|
|
1241
|
+
|
|
1242
|
+
type InternalizedTrellisOpts<TA extends AnyTrellisAPI> = TrellisOpts<TA> & {
|
|
1243
|
+
[internalEventConsumers]?: RuntimeEventConsumers;
|
|
1244
|
+
[internalDurableEventConsumerBeforeReadinessCheck]?:
|
|
1245
|
+
TrellisDurableEventConsumerBeforeReadinessCheckHook;
|
|
1246
|
+
};
|
|
1146
1247
|
|
|
1147
1248
|
/**
|
|
1148
1249
|
* Creates a Trellis runtime with bootstrap-resolved bindings.
|
|
@@ -1159,13 +1260,18 @@ export function createTrellisInternal<
|
|
|
1159
1260
|
auth: TrellisAuth,
|
|
1160
1261
|
opts?: TrellisInternalOpts<TA>,
|
|
1161
1262
|
): Trellis<TA, TMode, TState> {
|
|
1162
|
-
const {
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1168
|
-
|
|
1263
|
+
const {
|
|
1264
|
+
durableEventConsumerBeforeReadinessCheck,
|
|
1265
|
+
eventConsumers,
|
|
1266
|
+
...publicOpts
|
|
1267
|
+
} = opts ?? {};
|
|
1268
|
+
const internalOpts: InternalizedTrellisOpts<TA> = {
|
|
1269
|
+
...publicOpts,
|
|
1270
|
+
[internalEventConsumers]: eventConsumers,
|
|
1271
|
+
[internalDurableEventConsumerBeforeReadinessCheck]:
|
|
1272
|
+
durableEventConsumerBeforeReadinessCheck,
|
|
1273
|
+
};
|
|
1274
|
+
return new Trellis<TA, TMode, TState>(name, nats, auth, internalOpts);
|
|
1169
1275
|
}
|
|
1170
1276
|
|
|
1171
1277
|
type DurableEventRegistration<TA extends AnyTrellisAPI> = {
|
|
@@ -1199,7 +1305,12 @@ export type FeedHandlerContext<TInput, TEvent> = {
|
|
|
1199
1305
|
input: TInput;
|
|
1200
1306
|
caller: SessionCaller;
|
|
1201
1307
|
signal: AbortSignal;
|
|
1202
|
-
emit(
|
|
1308
|
+
emit(
|
|
1309
|
+
event: TEvent,
|
|
1310
|
+
): AsyncResult<
|
|
1311
|
+
void,
|
|
1312
|
+
SchemaValidationError | ValidationError | UnexpectedError
|
|
1313
|
+
>;
|
|
1203
1314
|
};
|
|
1204
1315
|
|
|
1205
1316
|
export type FeedRegistration<TInput, TEvent> = {
|
|
@@ -1357,6 +1468,8 @@ type EventCallback<TMessage> = {
|
|
|
1357
1468
|
export type RpcHandlerContext = {
|
|
1358
1469
|
caller: SessionCaller;
|
|
1359
1470
|
sessionKey: string;
|
|
1471
|
+
requestId?: string;
|
|
1472
|
+
traceId?: string;
|
|
1360
1473
|
};
|
|
1361
1474
|
|
|
1362
1475
|
export type HandlerTrellis<
|
|
@@ -1383,6 +1496,8 @@ export type HandlerTrellis<
|
|
|
1383
1496
|
publishPrepared(
|
|
1384
1497
|
event: PreparedTrellisEvent,
|
|
1385
1498
|
): AsyncResult<void, UnexpectedError>;
|
|
1499
|
+
/** Stops durable event listener loops owned by this handler runtime. */
|
|
1500
|
+
stopEventListeners(): void;
|
|
1386
1501
|
};
|
|
1387
1502
|
|
|
1388
1503
|
function surfaceGroupName(key: string): string {
|
|
@@ -1528,30 +1643,18 @@ export type ConnectedTrellisClient<TContract> = Simplify<
|
|
|
1528
1643
|
>
|
|
1529
1644
|
>;
|
|
1530
1645
|
|
|
1531
|
-
export type
|
|
1646
|
+
export type HandlerFn<
|
|
1532
1647
|
TMountApi extends AnyTrellisAPI,
|
|
1533
1648
|
M extends MethodsOf<TMountApi>,
|
|
1534
1649
|
TOutboundApi extends AnyTrellisAPI = TMountApi,
|
|
1535
1650
|
TTrellis = HandlerTrellis<TOutboundApi>,
|
|
1536
|
-
> = {
|
|
1651
|
+
> = (args: {
|
|
1537
1652
|
input: MethodInputOf<TMountApi, M>;
|
|
1538
1653
|
context: RpcHandlerContext;
|
|
1539
1654
|
client: TTrellis;
|
|
1540
|
-
}
|
|
1541
|
-
|
|
1542
|
-
export type HandlerFn<
|
|
1543
|
-
TMountApi extends AnyTrellisAPI,
|
|
1544
|
-
M extends MethodsOf<TMountApi>,
|
|
1545
|
-
TOutboundApi extends AnyTrellisAPI = TMountApi,
|
|
1546
|
-
TTrellis = HandlerTrellis<TOutboundApi>,
|
|
1547
|
-
> = (args: HandlerArgs<TMountApi, M, TOutboundApi, TTrellis>) => MaybePromise<
|
|
1655
|
+
}) => MaybePromise<
|
|
1548
1656
|
Result<MethodOutputOf<TMountApi, M>, HandlerErrorOf<TMountApi, M>>
|
|
1549
1657
|
>;
|
|
1550
|
-
export type RpcHandlerFn<
|
|
1551
|
-
TA extends AnyTrellisAPI,
|
|
1552
|
-
M extends RpcMethodNameOf<TA>,
|
|
1553
|
-
> = HandlerFn<TA, M, TA>;
|
|
1554
|
-
export type TrellisFor<TContract> = HandlerTrellisForContract<TContract>;
|
|
1555
1658
|
|
|
1556
1659
|
const DEFAULT_STATE_LIST_LIMIT = 100;
|
|
1557
1660
|
|
|
@@ -1624,7 +1727,25 @@ function validateStateValue(
|
|
|
1624
1727
|
schema: unknown,
|
|
1625
1728
|
value: JsonValue,
|
|
1626
1729
|
): Result<unknown, ValidationError | UnexpectedError> {
|
|
1627
|
-
|
|
1730
|
+
const result = parseRuntimeSchema(schema, value);
|
|
1731
|
+
// State validation is an internal path; collapse SchemaValidationError
|
|
1732
|
+
// into ValidationError to keep internal error types narrow.
|
|
1733
|
+
if (result.isOk()) {
|
|
1734
|
+
return result as Result<unknown, ValidationError | UnexpectedError>;
|
|
1735
|
+
}
|
|
1736
|
+
const resultError = result.error;
|
|
1737
|
+
if (resultError instanceof SchemaValidationError) {
|
|
1738
|
+
return Result.err(
|
|
1739
|
+
new ValidationError({
|
|
1740
|
+
errors: resultError.issues.map((i) => ({
|
|
1741
|
+
path: i.path,
|
|
1742
|
+
message: i.message,
|
|
1743
|
+
})),
|
|
1744
|
+
cause: resultError.cause,
|
|
1745
|
+
}),
|
|
1746
|
+
) as Result<unknown, ValidationError | UnexpectedError>;
|
|
1747
|
+
}
|
|
1748
|
+
return result as Result<unknown, ValidationError | UnexpectedError>;
|
|
1628
1749
|
}
|
|
1629
1750
|
|
|
1630
1751
|
function validateStateGetResult<TStore extends RuntimeStateStoreShape>(
|
|
@@ -1821,22 +1942,6 @@ function validateStateListResult(
|
|
|
1821
1942
|
return Result.ok({ ...result, entries });
|
|
1822
1943
|
}
|
|
1823
1944
|
|
|
1824
|
-
export type RpcArgs<
|
|
1825
|
-
TContract,
|
|
1826
|
-
M extends RpcMethodNameOf<OwnedApiFor<TContract>>,
|
|
1827
|
-
> = HandlerArgs<
|
|
1828
|
-
OwnedApiFor<TContract>,
|
|
1829
|
-
M,
|
|
1830
|
-
TrellisApiFor<TContract>,
|
|
1831
|
-
HandlerTrellisForContract<TContract>
|
|
1832
|
-
>;
|
|
1833
|
-
export type RpcResult<
|
|
1834
|
-
TContract,
|
|
1835
|
-
M extends RpcMethodNameOf<OwnedApiFor<TContract>>,
|
|
1836
|
-
> = Result<
|
|
1837
|
-
RpcOutputOf<OwnedApiFor<TContract>, M>,
|
|
1838
|
-
RpcHandlerErrorOf<OwnedApiFor<TContract>, M>
|
|
1839
|
-
>;
|
|
1840
1945
|
export type RpcRequestErrorOf<
|
|
1841
1946
|
TA extends AnyTrellisAPI,
|
|
1842
1947
|
M extends RpcMethodNameOf<TA>,
|
|
@@ -1854,13 +1959,6 @@ export type EventPayload<
|
|
|
1854
1959
|
TContract,
|
|
1855
1960
|
E extends EventName<TContract>,
|
|
1856
1961
|
> = EventPayloadOf<OwnedApiFor<TContract>, E>;
|
|
1857
|
-
export type EventHandler<
|
|
1858
|
-
TContract,
|
|
1859
|
-
E extends EventName<TContract>,
|
|
1860
|
-
> = (
|
|
1861
|
-
event: EventType<TContract, E>,
|
|
1862
|
-
context: EventListenerContext,
|
|
1863
|
-
) => MaybeAsync<void, BaseError>;
|
|
1864
1962
|
|
|
1865
1963
|
type DeepRecord<T> = {
|
|
1866
1964
|
[k: string]: T | DeepRecord<T>;
|
|
@@ -2054,7 +2152,10 @@ export class Trellis<
|
|
|
2054
2152
|
#onSessionNotFound?: () => MaybePromise<void>;
|
|
2055
2153
|
#operationStore?: Promise<TypedKV<typeof DurableOperationRecordSchema>>;
|
|
2056
2154
|
#eventConsumers: RuntimeEventConsumers;
|
|
2155
|
+
#durableEventConsumerBeforeReadinessCheck?:
|
|
2156
|
+
TrellisDurableEventConsumerBeforeReadinessCheckHook;
|
|
2057
2157
|
#durableEventLoops = new Map<string, DurableEventConsumerLoop<TA>>();
|
|
2158
|
+
#durableEventListenersStopped = false;
|
|
2058
2159
|
|
|
2059
2160
|
constructor(
|
|
2060
2161
|
name: string, // Must be unique for a service
|
|
@@ -2062,6 +2163,7 @@ export class Trellis<
|
|
|
2062
2163
|
auth: TrellisAuth,
|
|
2063
2164
|
opts?: TrellisOpts<TA>,
|
|
2064
2165
|
) {
|
|
2166
|
+
const internalOpts = opts as InternalizedTrellisOpts<TA> | undefined;
|
|
2065
2167
|
const api = opts?.api;
|
|
2066
2168
|
|
|
2067
2169
|
this.name = name;
|
|
@@ -2080,7 +2182,9 @@ export class Trellis<
|
|
|
2080
2182
|
this.#noResponderRetryMs = opts?.noResponderRetry?.baseDelayMs ??
|
|
2081
2183
|
DEFAULT_NO_RESPONDER_RETRY_MS;
|
|
2082
2184
|
this.#onSessionNotFound = opts?.onSessionNotFound;
|
|
2083
|
-
this.#eventConsumers =
|
|
2185
|
+
this.#eventConsumers = internalOpts?.[internalEventConsumers] ?? {};
|
|
2186
|
+
this.#durableEventConsumerBeforeReadinessCheck = internalOpts
|
|
2187
|
+
?.[internalDurableEventConsumerBeforeReadinessCheck];
|
|
2084
2188
|
this.connection = opts?.connection ??
|
|
2085
2189
|
new TrellisConnection({ kind: "client" });
|
|
2086
2190
|
|
|
@@ -2323,6 +2427,7 @@ export class Trellis<
|
|
|
2323
2427
|
prepare: (event, data) => this.prepare(event, data),
|
|
2324
2428
|
publish: (event, data) => this.publish(event, data),
|
|
2325
2429
|
publishPrepared: (event) => this.publishPrepared(event),
|
|
2430
|
+
stopEventListeners: () => this.stopEventListeners(),
|
|
2326
2431
|
};
|
|
2327
2432
|
}
|
|
2328
2433
|
|
|
@@ -3439,6 +3544,10 @@ export class Trellis<
|
|
|
3439
3544
|
|
|
3440
3545
|
let caller: SessionCaller;
|
|
3441
3546
|
const callerSessionKey = msg.headers?.get("session-key") ?? "";
|
|
3547
|
+
const handlerRequestIdFromHeader = msg.headers?.get("request-id") ?? "";
|
|
3548
|
+
const handlerTraceIdFromHeader = traceIdFromTraceparent(
|
|
3549
|
+
msg.headers?.get("traceparent"),
|
|
3550
|
+
);
|
|
3442
3551
|
|
|
3443
3552
|
const authRequired = ctx.authRequired ?? true;
|
|
3444
3553
|
if (!authRequired) {
|
|
@@ -3709,6 +3818,8 @@ export class Trellis<
|
|
|
3709
3818
|
context: {
|
|
3710
3819
|
caller,
|
|
3711
3820
|
sessionKey: callerSessionKey,
|
|
3821
|
+
requestId: handlerRequestIdFromHeader || undefined,
|
|
3822
|
+
traceId: handlerTraceIdFromHeader || undefined,
|
|
3712
3823
|
},
|
|
3713
3824
|
client: handlerTrellis,
|
|
3714
3825
|
}),
|
|
@@ -3954,10 +4065,7 @@ export class Trellis<
|
|
|
3954
4065
|
id: ulid(),
|
|
3955
4066
|
time: new Date().toISOString(),
|
|
3956
4067
|
};
|
|
3957
|
-
const payload = Object.freeze({
|
|
3958
|
-
...data,
|
|
3959
|
-
header: Object.freeze(header),
|
|
3960
|
-
});
|
|
4068
|
+
const payload = Object.freeze({ ...data });
|
|
3961
4069
|
const msg = encodeSchema(ctx.event, payload).take();
|
|
3962
4070
|
if (isErr(msg)) {
|
|
3963
4071
|
logger.error({ err: msg.error }, "Failed to encode event.");
|
|
@@ -3973,6 +4081,7 @@ export class Trellis<
|
|
|
3973
4081
|
|
|
3974
4082
|
const headers = natsHeaders();
|
|
3975
4083
|
headers.set("Nats-Msg-Id", header.id);
|
|
4084
|
+
headers.set("Trellis-Event-Time", header.time);
|
|
3976
4085
|
injectTraceContext(createNatsHeaderCarrier(headers));
|
|
3977
4086
|
|
|
3978
4087
|
const headerRecord: Record<string, string> = {};
|
|
@@ -3983,6 +4092,7 @@ export class Trellis<
|
|
|
3983
4092
|
return ok(Object.freeze({
|
|
3984
4093
|
event: event.toString(),
|
|
3985
4094
|
subject,
|
|
4095
|
+
header: Object.freeze(header),
|
|
3986
4096
|
payload,
|
|
3987
4097
|
encodedPayload: msg,
|
|
3988
4098
|
headers: Object.freeze(headerRecord),
|
|
@@ -4074,7 +4184,7 @@ export class Trellis<
|
|
|
4074
4184
|
if (isErr(subject)) return subject;
|
|
4075
4185
|
|
|
4076
4186
|
if (opts?.mode === "ephemeral") {
|
|
4077
|
-
return this.#startEphemeralEvent(
|
|
4187
|
+
return await this.#startEphemeralEvent(
|
|
4078
4188
|
eventName,
|
|
4079
4189
|
ctx,
|
|
4080
4190
|
subject,
|
|
@@ -4118,20 +4228,36 @@ export class Trellis<
|
|
|
4118
4228
|
})());
|
|
4119
4229
|
}
|
|
4120
4230
|
|
|
4121
|
-
#startEphemeralEvent(
|
|
4231
|
+
async #startEphemeralEvent(
|
|
4122
4232
|
event: EventsOf<TA>,
|
|
4123
4233
|
ctx: EventDescriptorOf<TA, EventsOf<TA>>,
|
|
4124
4234
|
subject: string,
|
|
4125
4235
|
fn: EventCallback<EventOf<TA, EventsOf<TA>>>,
|
|
4126
4236
|
signal?: AbortSignal,
|
|
4127
|
-
): Result<void, ValidationError | UnexpectedError
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4237
|
+
): Promise<Result<void, ValidationError | UnexpectedError>> {
|
|
4238
|
+
let sub: ReturnType<NatsConnection["subscribe"]> | undefined;
|
|
4239
|
+
try {
|
|
4240
|
+
sub = this.nats.subscribe(subject);
|
|
4241
|
+
if (signal) {
|
|
4242
|
+
if (signal.aborted) {
|
|
4243
|
+
sub.unsubscribe();
|
|
4244
|
+
return ok(undefined);
|
|
4245
|
+
}
|
|
4246
|
+
signal.addEventListener("abort", () => sub?.unsubscribe(), {
|
|
4247
|
+
once: true,
|
|
4248
|
+
});
|
|
4249
|
+
}
|
|
4250
|
+
await this.nats.flush();
|
|
4251
|
+
} catch (cause) {
|
|
4252
|
+
if (sub) {
|
|
4131
4253
|
sub.unsubscribe();
|
|
4132
|
-
return ok(undefined);
|
|
4133
4254
|
}
|
|
4134
|
-
|
|
4255
|
+
return err(
|
|
4256
|
+
new UnexpectedError({
|
|
4257
|
+
cause,
|
|
4258
|
+
context: { event: String(event), subject },
|
|
4259
|
+
}),
|
|
4260
|
+
);
|
|
4135
4261
|
}
|
|
4136
4262
|
|
|
4137
4263
|
const task = AsyncResult.try(async () => {
|
|
@@ -4199,7 +4325,6 @@ export class Trellis<
|
|
|
4199
4325
|
const result = await Promise.resolve(args.fn(
|
|
4200
4326
|
args.payload as EventOf<TA, EventsOf<TA>>,
|
|
4201
4327
|
createEventListenerContext({
|
|
4202
|
-
payload: args.payload,
|
|
4203
4328
|
subject: args.message.subject,
|
|
4204
4329
|
mode: args.mode,
|
|
4205
4330
|
...(args.group ? { group: args.group } : {}),
|
|
@@ -4301,7 +4426,7 @@ export class Trellis<
|
|
|
4301
4426
|
fn: EventCallback<EventOf<TA, EventsOf<TA>>>;
|
|
4302
4427
|
signal?: AbortSignal;
|
|
4303
4428
|
}): void {
|
|
4304
|
-
if (args.signal?.aborted) return;
|
|
4429
|
+
if (args.signal?.aborted || this.#durableEventListenersStopped) return;
|
|
4305
4430
|
|
|
4306
4431
|
const loop = this.#durableEventLoops.get(args.group) ?? {
|
|
4307
4432
|
registrations: [],
|
|
@@ -4331,7 +4456,10 @@ export class Trellis<
|
|
|
4331
4456
|
group: string,
|
|
4332
4457
|
loop: DurableEventConsumerLoop<TA>,
|
|
4333
4458
|
): void {
|
|
4334
|
-
if (
|
|
4459
|
+
if (
|
|
4460
|
+
this.#durableEventListenersStopped || loop.started ||
|
|
4461
|
+
!this.#durableEventConsumerGroupReady(group, loop)
|
|
4462
|
+
) {
|
|
4335
4463
|
return;
|
|
4336
4464
|
}
|
|
4337
4465
|
loop.started = true;
|
|
@@ -4378,10 +4506,29 @@ export class Trellis<
|
|
|
4378
4506
|
return await jsm.consumers.info(binding.stream, binding.consumerName);
|
|
4379
4507
|
});
|
|
4380
4508
|
const info = infoResult.take();
|
|
4381
|
-
if (isErr(info))
|
|
4509
|
+
if (isErr(info)) {
|
|
4510
|
+
if (
|
|
4511
|
+
this.#durableEventListenersStopped ||
|
|
4512
|
+
!this.#durableEventConsumerGroupReady(group, loop)
|
|
4513
|
+
) {
|
|
4514
|
+
return ok(undefined);
|
|
4515
|
+
}
|
|
4516
|
+
if (isConsumerNotFoundError(info.error.cause)) {
|
|
4517
|
+
this.#log.debug(
|
|
4518
|
+
{ group, stream: binding.stream, consumer: binding.consumerName },
|
|
4519
|
+
"Durable event consumer is not available yet; retrying",
|
|
4520
|
+
);
|
|
4521
|
+
await sleep(25);
|
|
4522
|
+
return ok(undefined);
|
|
4523
|
+
}
|
|
4524
|
+
return info;
|
|
4525
|
+
}
|
|
4382
4526
|
|
|
4383
4527
|
const consumer = this.js.consumers.getConsumerFromInfo(info);
|
|
4384
|
-
while (
|
|
4528
|
+
while (
|
|
4529
|
+
!this.#durableEventListenersStopped &&
|
|
4530
|
+
this.#durableEventConsumerGroupReady(group, loop)
|
|
4531
|
+
) {
|
|
4385
4532
|
const messages = await consumer.fetch({
|
|
4386
4533
|
max_messages: 1,
|
|
4387
4534
|
expires: 30_000,
|
|
@@ -4394,10 +4541,28 @@ export class Trellis<
|
|
|
4394
4541
|
await this.#handleDurableEventConsumer(group, loop, messages)
|
|
4395
4542
|
.orThrow();
|
|
4396
4543
|
}
|
|
4544
|
+
} catch (cause) {
|
|
4545
|
+
if (
|
|
4546
|
+
this.#durableEventListenersStopped ||
|
|
4547
|
+
!this.#durableEventConsumerGroupReady(group, loop)
|
|
4548
|
+
) {
|
|
4549
|
+
return ok(undefined);
|
|
4550
|
+
}
|
|
4551
|
+
if (isConsumerNotFoundError(cause)) {
|
|
4552
|
+
this.#log.debug(
|
|
4553
|
+
{ group, stream: binding.stream, consumer: binding.consumerName },
|
|
4554
|
+
"Durable event consumer is not available yet; retrying",
|
|
4555
|
+
);
|
|
4556
|
+
await sleep(25);
|
|
4557
|
+
return ok(undefined);
|
|
4558
|
+
}
|
|
4559
|
+
return err(new UnexpectedError({ cause, context: { group } }));
|
|
4397
4560
|
} finally {
|
|
4398
4561
|
loop.started = false;
|
|
4399
4562
|
loop.messages = undefined;
|
|
4400
|
-
this.#
|
|
4563
|
+
if (!this.#durableEventListenersStopped) {
|
|
4564
|
+
this.#startDurableEventConsumer(group, loop);
|
|
4565
|
+
}
|
|
4401
4566
|
}
|
|
4402
4567
|
return ok(undefined);
|
|
4403
4568
|
})());
|
|
@@ -4452,6 +4617,10 @@ export class Trellis<
|
|
|
4452
4617
|
): AsyncResult<void, ValidationError | UnexpectedError> {
|
|
4453
4618
|
return AsyncResult.try(async () => {
|
|
4454
4619
|
for await (const msg of messages) {
|
|
4620
|
+
await this.#durableEventConsumerBeforeReadinessCheck?.({
|
|
4621
|
+
group,
|
|
4622
|
+
subject: msg.subject,
|
|
4623
|
+
});
|
|
4455
4624
|
if (!this.#durableEventConsumerGroupReady(group, loop)) {
|
|
4456
4625
|
messages.stop();
|
|
4457
4626
|
break;
|
|
@@ -4531,7 +4700,10 @@ export class Trellis<
|
|
|
4531
4700
|
event: EventsOf<TA>,
|
|
4532
4701
|
ctx: EventDescriptorOf<TA, EventsOf<TA>>,
|
|
4533
4702
|
msg: Pick<Msg, "json" | "subject">,
|
|
4534
|
-
): Result<
|
|
4703
|
+
): Result<
|
|
4704
|
+
unknown,
|
|
4705
|
+
SchemaValidationError | ValidationError | UnexpectedError
|
|
4706
|
+
> {
|
|
4535
4707
|
const jsonData = Result.try<JsonValue>(() => msg.json());
|
|
4536
4708
|
const json = jsonData.take();
|
|
4537
4709
|
if (isErr(json)) {
|
|
@@ -4549,6 +4721,15 @@ export class Trellis<
|
|
|
4549
4721
|
return this.#tasks.wait();
|
|
4550
4722
|
}
|
|
4551
4723
|
|
|
4724
|
+
/** Stops durable event listener loops without closing the underlying transport. */
|
|
4725
|
+
stopEventListeners(): void {
|
|
4726
|
+
this.#durableEventListenersStopped = true;
|
|
4727
|
+
for (const loop of this.#durableEventLoops.values()) {
|
|
4728
|
+
loop.registrations.splice(0, loop.registrations.length);
|
|
4729
|
+
loop.messages?.stop();
|
|
4730
|
+
}
|
|
4731
|
+
}
|
|
4732
|
+
|
|
4552
4733
|
// FIXME: If are validating things twice in most cases...
|
|
4553
4734
|
template(
|
|
4554
4735
|
subject: string,
|