@qlever-llc/trellis 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -2
- package/esm/_dnt.polyfills.d.ts +11 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -1
- package/esm/_dnt.polyfills.js +14 -0
- package/esm/_dnt.shims.d.ts +6 -0
- package/esm/_dnt.shims.d.ts.map +1 -0
- package/esm/_dnt.shims.js +61 -0
- package/esm/auth/browser/login.d.ts +27 -0
- package/esm/auth/browser/login.d.ts.map +1 -0
- package/esm/auth/browser/login.js +94 -0
- package/esm/auth/browser/portal.d.ts +11 -0
- package/esm/auth/browser/portal.d.ts.map +1 -0
- package/esm/auth/browser/portal.js +33 -0
- package/esm/auth/browser/session.d.ts +19 -0
- package/esm/auth/browser/session.d.ts.map +1 -0
- package/esm/auth/browser/session.js +65 -0
- package/esm/auth/browser/storage.d.ts +12 -0
- package/esm/auth/browser/storage.d.ts.map +1 -0
- package/esm/auth/browser/storage.js +61 -0
- package/esm/auth/browser.d.ts +13 -0
- package/esm/auth/browser.d.ts.map +1 -0
- package/esm/auth/browser.js +11 -0
- package/esm/auth/keys.d.ts +5 -0
- package/esm/auth/keys.d.ts.map +1 -0
- package/esm/auth/keys.js +50 -0
- package/esm/auth/mod.d.ts +18 -0
- package/esm/auth/mod.d.ts.map +1 -0
- package/esm/auth/mod.js +17 -0
- package/esm/auth/proof.d.ts +9 -0
- package/esm/auth/proof.d.ts.map +1 -0
- package/esm/auth/proof.js +43 -0
- package/esm/auth/protocol.d.ts +1212 -0
- package/esm/auth/protocol.d.ts.map +1 -0
- package/esm/auth/protocol.js +682 -0
- package/esm/auth/schemas.d.ts +93 -0
- package/esm/auth/schemas.d.ts.map +1 -0
- package/esm/auth/schemas.js +64 -0
- package/esm/auth/session_auth.d.ts +20 -0
- package/esm/auth/session_auth.d.ts.map +1 -0
- package/esm/auth/session_auth.js +42 -0
- package/esm/auth/trellis_id.d.ts +2 -0
- package/esm/auth/trellis_id.d.ts.map +1 -0
- package/esm/auth/trellis_id.js +5 -0
- package/esm/auth/types.d.ts +8 -0
- package/esm/auth/types.d.ts.map +1 -0
- package/esm/auth/types.js +1 -0
- package/esm/auth/utils.d.ts +11 -0
- package/esm/auth/utils.d.ts.map +1 -0
- package/esm/auth/utils.js +68 -0
- package/esm/auth/workload_activation.d.ts +192 -0
- package/esm/auth/workload_activation.d.ts.map +1 -0
- package/esm/auth/workload_activation.js +290 -0
- package/esm/contracts/canonical.d.ts +14 -0
- package/esm/contracts/canonical.d.ts.map +1 -0
- package/esm/contracts/canonical.js +135 -0
- package/esm/contracts/mod.d.ts +462 -0
- package/esm/contracts/mod.d.ts.map +1 -0
- package/esm/contracts/mod.js +532 -0
- package/esm/contracts/protocol.d.ts +301 -0
- package/esm/contracts/protocol.d.ts.map +1 -0
- package/esm/contracts/protocol.js +130 -0
- package/esm/contracts/runtime.d.ts +48 -0
- package/esm/contracts/runtime.d.ts.map +1 -0
- package/esm/contracts/runtime.js +9 -0
- package/esm/contracts/schema_pointers.d.ts +18 -0
- package/esm/contracts/schema_pointers.d.ts.map +1 -0
- package/esm/contracts/schema_pointers.js +59 -0
- package/esm/server/deno.d.ts +7 -0
- package/esm/server/deno.d.ts.map +1 -0
- package/esm/server/deno.js +16 -0
- package/esm/server/health.d.ts +92 -0
- package/esm/server/health.d.ts.map +1 -0
- package/esm/server/health.js +74 -0
- package/esm/server/health_rpc.d.ts +16 -0
- package/esm/server/health_rpc.d.ts.map +1 -0
- package/esm/server/health_rpc.js +23 -0
- package/esm/server/health_schemas.d.ts +20 -0
- package/esm/server/health_schemas.d.ts.map +1 -0
- package/esm/server/health_schemas.js +18 -0
- package/esm/server/mod.d.ts +17 -0
- package/esm/server/mod.d.ts.map +1 -0
- package/esm/server/mod.js +17 -0
- package/esm/server/node.d.ts +7 -0
- package/esm/server/node.d.ts.map +1 -0
- package/esm/server/node.js +16 -0
- package/esm/server/runtime.d.ts +16 -0
- package/esm/server/runtime.d.ts.map +1 -0
- package/esm/server/runtime.js +1 -0
- package/esm/server/service.d.ts +121 -0
- package/esm/server/service.d.ts.map +1 -0
- package/esm/server/service.js +256 -0
- package/esm/server/subscription.d.ts +99 -0
- package/esm/server/subscription.d.ts.map +1 -0
- package/esm/server/subscription.js +25 -0
- package/esm/telemetry/carrier.d.ts +9 -0
- package/esm/telemetry/carrier.d.ts.map +1 -0
- package/esm/telemetry/carrier.js +20 -0
- package/esm/telemetry/core.d.ts +8 -0
- package/esm/telemetry/core.d.ts.map +1 -0
- package/esm/telemetry/core.js +14 -0
- package/esm/telemetry/env.d.ts +2 -0
- package/esm/telemetry/env.d.ts.map +1 -0
- package/esm/telemetry/env.js +10 -0
- package/esm/telemetry/mod.d.ts +11 -0
- package/esm/telemetry/mod.d.ts.map +1 -0
- package/esm/telemetry/mod.js +7 -0
- package/esm/telemetry/nats.d.ts +7 -0
- package/esm/telemetry/nats.d.ts.map +1 -0
- package/esm/telemetry/nats.js +6 -0
- package/esm/telemetry/result.d.ts +2 -0
- package/esm/telemetry/result.d.ts.map +1 -0
- package/esm/telemetry/result.js +18 -0
- package/esm/telemetry/runtime.d.ts +2 -0
- package/esm/telemetry/runtime.d.ts.map +1 -0
- package/esm/telemetry/runtime.js +53 -0
- package/esm/telemetry/trace.d.ts +5 -0
- package/esm/telemetry/trace.d.ts.map +1 -0
- package/esm/telemetry/trace.js +26 -0
- package/esm/telemetry/trellis.d.ts +3 -0
- package/esm/telemetry/trellis.d.ts.map +1 -0
- package/esm/telemetry/trellis.js +7 -0
- package/esm/trellis/_sdk/activity/_dnt.polyfills.d.ts +12 -0
- package/esm/trellis/_sdk/activity/_dnt.polyfills.d.ts.map +1 -0
- package/esm/trellis/_sdk/activity/_dnt.polyfills.js +15 -0
- package/esm/trellis/_sdk/activity/api.d.ts +10 -0
- package/esm/trellis/_sdk/activity/api.d.ts.map +1 -0
- package/esm/trellis/_sdk/activity/api.js +43 -0
- package/esm/trellis/_sdk/activity/contract.d.ts +8 -0
- package/esm/trellis/_sdk/activity/contract.d.ts.map +1 -0
- package/esm/trellis/_sdk/activity/contract.js +59 -0
- package/esm/trellis/_sdk/activity/mod.d.ts +7 -0
- package/esm/trellis/_sdk/activity/mod.d.ts.map +1 -0
- package/esm/trellis/_sdk/activity/mod.js +5 -0
- package/esm/trellis/_sdk/activity/package.json +3 -0
- package/esm/trellis/_sdk/activity/schemas.d.ts +607 -0
- package/esm/trellis/_sdk/activity/schemas.d.ts.map +1 -0
- package/esm/trellis/_sdk/activity/schemas.js +33 -0
- package/esm/trellis/_sdk/activity/types.d.ts +96 -0
- package/esm/trellis/_sdk/activity/types.d.ts.map +1 -0
- package/esm/trellis/_sdk/activity/types.js +3 -0
- package/esm/trellis/_sdk/auth/_dnt.polyfills.d.ts +12 -0
- package/esm/trellis/_sdk/auth/_dnt.polyfills.d.ts.map +1 -0
- package/esm/trellis/_sdk/auth/_dnt.polyfills.js +15 -0
- package/esm/trellis/_sdk/auth/api.d.ts +10 -0
- package/esm/trellis/_sdk/auth/api.d.ts.map +1 -0
- package/esm/trellis/_sdk/auth/api.js +354 -0
- package/esm/trellis/_sdk/auth/contract.d.ts +28 -0
- package/esm/trellis/_sdk/auth/contract.d.ts.map +1 -0
- package/esm/trellis/_sdk/auth/contract.js +83 -0
- package/esm/trellis/_sdk/auth/mod.d.ts +7 -0
- package/esm/trellis/_sdk/auth/mod.d.ts.map +1 -0
- package/esm/trellis/_sdk/auth/mod.js +5 -0
- package/esm/trellis/_sdk/auth/package.json +3 -0
- package/esm/trellis/_sdk/auth/schemas.d.ts +8967 -0
- package/esm/trellis/_sdk/auth/schemas.d.ts.map +1 -0
- package/esm/trellis/_sdk/auth/schemas.js +306 -0
- package/esm/trellis/_sdk/auth/types.d.ts +1232 -0
- package/esm/trellis/_sdk/auth/types.d.ts.map +1 -0
- package/esm/trellis/_sdk/auth/types.js +3 -0
- package/esm/trellis/_sdk/core/_dnt.polyfills.d.ts +12 -0
- package/esm/trellis/_sdk/core/_dnt.polyfills.d.ts.map +1 -0
- package/esm/trellis/_sdk/core/_dnt.polyfills.js +15 -0
- package/esm/trellis/_sdk/core/api.d.ts +10 -0
- package/esm/trellis/_sdk/core/api.d.ts.map +1 -0
- package/esm/trellis/_sdk/core/api.js +36 -0
- package/esm/trellis/_sdk/core/contract.d.ts +8 -0
- package/esm/trellis/_sdk/core/contract.d.ts.map +1 -0
- package/esm/trellis/_sdk/core/contract.js +59 -0
- package/esm/trellis/_sdk/core/mod.d.ts +7 -0
- package/esm/trellis/_sdk/core/mod.d.ts.map +1 -0
- package/esm/trellis/_sdk/core/mod.js +5 -0
- package/esm/trellis/_sdk/core/package.json +3 -0
- package/esm/trellis/_sdk/core/schemas.d.ts +1144 -0
- package/esm/trellis/_sdk/core/schemas.d.ts.map +1 -0
- package/esm/trellis/_sdk/core/schemas.js +28 -0
- package/esm/trellis/_sdk/core/types.d.ts +176 -0
- package/esm/trellis/_sdk/core/types.d.ts.map +1 -0
- package/esm/trellis/_sdk/core/types.js +3 -0
- package/esm/trellis/auth/browser.d.ts +3 -0
- package/esm/trellis/auth/browser.d.ts.map +1 -0
- package/esm/trellis/auth/browser.js +2 -0
- package/esm/trellis/auth.d.ts +3 -0
- package/esm/trellis/auth.d.ts.map +1 -0
- package/esm/trellis/auth.js +2 -0
- package/esm/trellis/browser.d.ts +2 -7
- package/esm/trellis/browser.d.ts.map +1 -1
- package/esm/trellis/browser.js +2 -7
- package/esm/trellis/client.d.ts +6 -4
- package/esm/trellis/client.d.ts.map +1 -1
- package/esm/trellis/client.js +28 -1
- package/esm/trellis/codec.d.ts +4 -3
- package/esm/trellis/codec.d.ts.map +1 -1
- package/esm/trellis/codec.js +15 -2
- package/esm/trellis/contract.d.ts +11 -0
- package/esm/trellis/contract.d.ts.map +1 -0
- package/esm/trellis/contract.js +15 -0
- package/esm/trellis/contracts.d.ts +5 -0
- package/esm/trellis/contracts.d.ts.map +1 -0
- package/esm/trellis/contracts.js +3 -0
- package/esm/trellis/env.d.ts +1 -1
- package/esm/trellis/env.d.ts.map +1 -1
- package/esm/trellis/env.js +1 -1
- package/esm/trellis/errors/AuthError.d.ts +1 -1
- package/esm/trellis/errors/AuthError.d.ts.map +1 -1
- package/esm/trellis/errors/AuthError.js +11 -0
- package/esm/trellis/errors/RemoteError.d.ts +3 -3
- package/esm/trellis/errors/RemoteError.d.ts.map +1 -1
- package/esm/trellis/errors/RemoteError.js +3 -3
- package/esm/trellis/errors/TrellisError.d.ts +1 -1
- package/esm/trellis/errors/TrellisError.js +1 -1
- package/esm/trellis/errors/index.d.ts +2 -1
- package/esm/trellis/errors/index.d.ts.map +1 -1
- package/esm/trellis/errors/index.js +3 -2
- package/esm/trellis/globals.d.ts +9 -1
- package/esm/trellis/globals.d.ts.map +1 -1
- package/esm/trellis/globals.js +16 -8
- package/esm/trellis/helpers.d.ts +2 -1
- package/esm/trellis/helpers.d.ts.map +1 -1
- package/esm/trellis/helpers.js +1 -0
- package/esm/trellis/index.d.ts +13 -5
- package/esm/trellis/index.d.ts.map +1 -1
- package/esm/trellis/index.js +8 -3
- package/esm/trellis/kv.d.ts +10 -7
- package/esm/trellis/kv.d.ts.map +1 -1
- package/esm/trellis/kv.js +57 -34
- package/esm/trellis/models/trellis/TrellisError.d.ts +1 -1
- package/esm/trellis/models/trellis/TrellisError.js +1 -1
- package/esm/trellis/operations.d.ts +81 -0
- package/esm/trellis/operations.d.ts.map +1 -0
- package/esm/trellis/operations.js +206 -0
- package/esm/trellis/sdk/activity.d.ts +3 -0
- package/esm/trellis/sdk/activity.d.ts.map +1 -0
- package/esm/trellis/sdk/activity.js +2 -0
- package/esm/trellis/sdk/auth.d.ts +4 -0
- package/esm/trellis/sdk/auth.d.ts.map +1 -0
- package/esm/trellis/sdk/auth.js +3 -0
- package/esm/trellis/sdk/core.d.ts +4 -0
- package/esm/trellis/sdk/core.d.ts.map +1 -0
- package/esm/trellis/sdk/core.js +3 -0
- package/esm/trellis/server/deno.d.ts +3 -0
- package/esm/trellis/server/deno.d.ts.map +1 -0
- package/esm/trellis/server/deno.js +2 -0
- package/esm/trellis/server/health.d.ts +5 -0
- package/esm/trellis/server/health.d.ts.map +1 -0
- package/esm/trellis/server/health.js +3 -0
- package/esm/trellis/server/mod.d.ts +3 -0
- package/esm/trellis/server/mod.d.ts.map +1 -0
- package/esm/trellis/server/mod.js +2 -0
- package/esm/trellis/server/node.d.ts +3 -0
- package/esm/trellis/server/node.d.ts.map +1 -0
- package/esm/trellis/server/node.js +2 -0
- package/esm/trellis/server/runtime.d.ts +4 -0
- package/esm/trellis/server/runtime.d.ts.map +1 -0
- package/esm/trellis/server/runtime.js +2 -0
- package/esm/trellis/server.d.ts +21 -0
- package/esm/trellis/server.d.ts.map +1 -0
- package/esm/trellis/server.js +536 -0
- package/esm/trellis/server_logger.d.ts +3 -0
- package/esm/trellis/server_logger.d.ts.map +1 -0
- package/esm/trellis/server_logger.js +7 -0
- package/esm/trellis/tasks.d.ts +3 -3
- package/esm/trellis/tasks.d.ts.map +1 -1
- package/esm/trellis/tasks.js +1 -1
- package/esm/trellis/tracing.d.ts +2 -2
- package/esm/trellis/tracing.d.ts.map +1 -1
- package/esm/trellis/tracing.js +2 -2
- package/esm/trellis/trellis.d.ts +167 -78
- package/esm/trellis/trellis.d.ts.map +1 -1
- package/esm/trellis/trellis.js +281 -87
- package/esm/trellis/workload.d.ts +45 -0
- package/esm/trellis/workload.d.ts.map +1 -0
- package/esm/trellis/workload.js +144 -0
- package/package.json +63 -4
- package/script/auth/browser/login.d.ts +27 -0
- package/script/auth/browser/login.d.ts.map +1 -0
- package/script/auth/browser/login.js +100 -0
- package/script/auth/browser/portal.d.ts +11 -0
- package/script/auth/browser/portal.d.ts.map +1 -0
- package/script/auth/browser/portal.js +40 -0
- package/script/auth/browser/session.d.ts +19 -0
- package/script/auth/browser/session.d.ts.map +1 -0
- package/script/auth/browser/session.js +79 -0
- package/script/auth/browser/storage.d.ts +12 -0
- package/script/auth/browser/storage.d.ts.map +1 -0
- package/script/auth/browser/storage.js +67 -0
- package/script/auth/browser.d.ts +13 -0
- package/script/auth/browser.d.ts.map +1 -0
- package/script/auth/browser.js +46 -0
- package/script/auth/keys.d.ts +5 -0
- package/script/auth/keys.d.ts.map +1 -0
- package/script/auth/keys.js +56 -0
- package/script/auth/mod.d.ts +18 -0
- package/script/auth/mod.d.ts.map +1 -0
- package/script/auth/mod.js +172 -0
- package/script/auth/proof.d.ts +9 -0
- package/script/auth/proof.d.ts.map +1 -0
- package/script/auth/proof.js +48 -0
- package/script/auth/protocol.d.ts +1212 -0
- package/script/auth/protocol.d.ts.map +1 -0
- package/script/auth/protocol.js +687 -0
- package/script/auth/schemas.d.ts +93 -0
- package/script/auth/schemas.d.ts.map +1 -0
- package/script/auth/schemas.js +67 -0
- package/script/auth/session_auth.d.ts +20 -0
- package/script/auth/session_auth.d.ts.map +1 -0
- package/script/auth/session_auth.js +45 -0
- package/script/auth/trellis_id.d.ts +2 -0
- package/script/auth/trellis_id.d.ts.map +1 -0
- package/script/auth/trellis_id.js +8 -0
- package/script/auth/types.d.ts +8 -0
- package/script/auth/types.d.ts.map +1 -0
- package/script/auth/utils.d.ts +11 -0
- package/script/auth/utils.d.ts.map +1 -0
- package/script/auth/utils.js +77 -0
- package/script/auth/workload_activation.d.ts +192 -0
- package/script/auth/workload_activation.d.ts.map +1 -0
- package/script/auth/workload_activation.js +308 -0
- package/script/contracts/canonical.d.ts +14 -0
- package/script/contracts/canonical.d.ts.map +1 -0
- package/script/contracts/canonical.js +144 -0
- package/script/contracts/mod.d.ts +462 -0
- package/script/contracts/mod.d.ts.map +1 -0
- package/script/contracts/mod.js +555 -0
- package/script/contracts/protocol.d.ts +301 -0
- package/script/contracts/protocol.d.ts.map +1 -0
- package/script/contracts/protocol.js +136 -0
- package/script/contracts/runtime.d.ts +48 -0
- package/script/contracts/runtime.d.ts.map +1 -0
- package/script/contracts/runtime.js +13 -0
- package/script/contracts/schema_pointers.d.ts +18 -0
- package/script/contracts/schema_pointers.d.ts.map +1 -0
- package/script/contracts/schema_pointers.js +63 -0
- package/script/telemetry/carrier.d.ts +9 -0
- package/script/telemetry/carrier.d.ts.map +1 -0
- package/script/telemetry/carrier.js +25 -0
- package/script/telemetry/core.d.ts +8 -0
- package/script/telemetry/core.d.ts.map +1 -0
- package/script/telemetry/core.js +24 -0
- package/script/telemetry/env.d.ts +2 -0
- package/script/telemetry/env.d.ts.map +1 -0
- package/script/telemetry/env.js +12 -0
- package/script/telemetry/mod.d.ts +11 -0
- package/script/telemetry/mod.d.ts.map +1 -0
- package/script/telemetry/mod.js +29 -0
- package/script/telemetry/nats.d.ts +7 -0
- package/script/telemetry/nats.d.ts.map +1 -0
- package/script/telemetry/nats.js +9 -0
- package/script/telemetry/result.d.ts +2 -0
- package/script/telemetry/result.d.ts.map +1 -0
- package/script/telemetry/result.js +21 -0
- package/script/telemetry/runtime.d.ts +2 -0
- package/script/telemetry/runtime.d.ts.map +1 -0
- package/script/telemetry/runtime.js +79 -0
- package/script/telemetry/trace.d.ts +5 -0
- package/script/telemetry/trace.d.ts.map +1 -0
- package/script/telemetry/trace.js +31 -0
- package/script/telemetry/trellis.d.ts +3 -0
- package/script/telemetry/trellis.d.ts.map +1 -0
- package/script/telemetry/trellis.js +14 -0
- package/script/trellis/_sdk/activity/_dnt.polyfills.d.ts +12 -0
- package/script/trellis/_sdk/activity/_dnt.polyfills.d.ts.map +1 -0
- package/script/trellis/_sdk/activity/_dnt.polyfills.js +16 -0
- package/script/trellis/_sdk/activity/api.d.ts +10 -0
- package/script/trellis/_sdk/activity/api.d.ts.map +1 -0
- package/script/trellis/_sdk/activity/api.js +46 -0
- package/script/trellis/_sdk/activity/contract.d.ts +8 -0
- package/script/trellis/_sdk/activity/contract.d.ts.map +1 -0
- package/script/trellis/_sdk/activity/contract.js +62 -0
- package/script/trellis/_sdk/activity/mod.d.ts +7 -0
- package/script/trellis/_sdk/activity/mod.d.ts.map +1 -0
- package/script/trellis/_sdk/activity/mod.js +30 -0
- package/script/trellis/_sdk/activity/package.json +3 -0
- package/script/trellis/_sdk/activity/schemas.d.ts +607 -0
- package/script/trellis/_sdk/activity/schemas.d.ts.map +1 -0
- package/script/trellis/_sdk/activity/schemas.js +36 -0
- package/script/trellis/_sdk/activity/types.d.ts +96 -0
- package/script/trellis/_sdk/activity/types.d.ts.map +1 -0
- package/script/trellis/_sdk/activity/types.js +6 -0
- package/script/trellis/_sdk/auth/_dnt.polyfills.d.ts +12 -0
- package/script/trellis/_sdk/auth/_dnt.polyfills.d.ts.map +1 -0
- package/script/trellis/_sdk/auth/_dnt.polyfills.js +16 -0
- package/script/trellis/_sdk/auth/api.d.ts +10 -0
- package/script/trellis/_sdk/auth/api.d.ts.map +1 -0
- package/script/trellis/_sdk/auth/api.js +357 -0
- package/script/trellis/_sdk/auth/contract.d.ts +28 -0
- package/script/trellis/_sdk/auth/contract.d.ts.map +1 -0
- package/script/trellis/_sdk/auth/contract.js +86 -0
- package/script/trellis/_sdk/auth/mod.d.ts +7 -0
- package/script/trellis/_sdk/auth/mod.d.ts.map +1 -0
- package/script/trellis/_sdk/auth/mod.js +31 -0
- package/script/trellis/_sdk/auth/package.json +3 -0
- package/script/trellis/_sdk/auth/schemas.d.ts +8967 -0
- package/script/trellis/_sdk/auth/schemas.d.ts.map +1 -0
- package/script/trellis/_sdk/auth/schemas.js +309 -0
- package/script/trellis/_sdk/auth/types.d.ts +1232 -0
- package/script/trellis/_sdk/auth/types.d.ts.map +1 -0
- package/script/trellis/_sdk/auth/types.js +6 -0
- package/script/trellis/_sdk/core/_dnt.polyfills.d.ts +12 -0
- package/script/trellis/_sdk/core/_dnt.polyfills.d.ts.map +1 -0
- package/script/trellis/_sdk/core/_dnt.polyfills.js +16 -0
- package/script/trellis/_sdk/core/api.d.ts +10 -0
- package/script/trellis/_sdk/core/api.d.ts.map +1 -0
- package/script/trellis/_sdk/core/api.js +39 -0
- package/script/trellis/_sdk/core/contract.d.ts +8 -0
- package/script/trellis/_sdk/core/contract.d.ts.map +1 -0
- package/script/trellis/_sdk/core/contract.js +62 -0
- package/script/trellis/_sdk/core/mod.d.ts +7 -0
- package/script/trellis/_sdk/core/mod.d.ts.map +1 -0
- package/script/trellis/_sdk/core/mod.js +30 -0
- package/script/trellis/_sdk/core/package.json +3 -0
- package/script/trellis/_sdk/core/schemas.d.ts +1144 -0
- package/script/trellis/_sdk/core/schemas.d.ts.map +1 -0
- package/script/trellis/_sdk/core/schemas.js +31 -0
- package/script/trellis/_sdk/core/types.d.ts +176 -0
- package/script/trellis/_sdk/core/types.d.ts.map +1 -0
- package/script/trellis/_sdk/core/types.js +6 -0
- package/script/trellis/auth.d.ts +2 -0
- package/script/trellis/auth.d.ts.map +1 -0
- package/script/trellis/auth.js +17 -0
- package/script/trellis/client.d.ts +8 -6
- package/script/trellis/client.d.ts.map +1 -1
- package/script/trellis/client.js +54 -3
- package/script/trellis/codec.d.ts +5 -4
- package/script/trellis/codec.d.ts.map +1 -1
- package/script/trellis/codec.js +31 -17
- package/script/trellis/contract.d.ts +11 -0
- package/script/trellis/contract.d.ts.map +1 -0
- package/script/trellis/contract.js +18 -0
- package/script/trellis/contracts.d.ts +4 -0
- package/script/trellis/contracts.d.ts.map +1 -0
- package/script/trellis/contracts.js +20 -0
- package/script/trellis/errors/AuthError.d.ts +2 -2
- package/script/trellis/errors/AuthError.d.ts.map +1 -1
- package/script/trellis/errors/AuthError.js +13 -2
- package/script/trellis/errors/KVError.d.ts +1 -1
- package/script/trellis/errors/KVError.d.ts.map +1 -1
- package/script/trellis/errors/KVError.js +2 -2
- package/script/trellis/errors/RemoteError.d.ts +4 -4
- package/script/trellis/errors/RemoteError.d.ts.map +1 -1
- package/script/trellis/errors/RemoteError.js +11 -11
- package/script/trellis/errors/TrellisError.d.ts +1 -1
- package/script/trellis/errors/TrellisError.d.ts.map +1 -1
- package/script/trellis/errors/TrellisError.js +2 -2
- package/script/trellis/errors/ValidationError.d.ts +1 -1
- package/script/trellis/errors/ValidationError.d.ts.map +1 -1
- package/script/trellis/errors/ValidationError.js +2 -2
- package/script/trellis/errors/index.d.ts +14 -14
- package/script/trellis/errors/index.d.ts.map +1 -1
- package/script/trellis/errors/index.js +31 -31
- package/script/trellis/globals.d.ts +9 -1
- package/script/trellis/globals.d.ts.map +1 -1
- package/script/trellis/globals.js +16 -8
- package/script/trellis/helpers.d.ts +1 -1
- package/script/trellis/helpers.d.ts.map +1 -1
- package/script/trellis/index.d.ts +17 -10
- package/script/trellis/index.d.ts.map +1 -1
- package/script/trellis/index.js +57 -22
- package/script/trellis/kv.d.ts +11 -8
- package/script/trellis/kv.d.ts.map +1 -1
- package/script/trellis/kv.js +91 -68
- package/script/trellis/models/trellis/TrellisError.d.ts +1 -1
- package/script/trellis/models/trellis/TrellisError.d.ts.map +1 -1
- package/script/trellis/models/trellis/TrellisError.js +8 -8
- package/script/trellis/operations.d.ts +81 -0
- package/script/trellis/operations.d.ts.map +1 -0
- package/script/trellis/operations.js +212 -0
- package/script/trellis/sdk/core.d.ts +3 -0
- package/script/trellis/sdk/core.d.ts.map +1 -0
- package/script/trellis/sdk/core.js +20 -0
- package/script/trellis/tasks.d.ts +3 -3
- package/script/trellis/tasks.d.ts.map +1 -1
- package/script/trellis/tasks.js +5 -5
- package/script/trellis/tracing.d.ts +2 -3
- package/script/trellis/tracing.d.ts.map +1 -1
- package/script/trellis/tracing.js +17 -20
- package/script/trellis/trellis.d.ts +169 -80
- package/script/trellis/trellis.d.ts.map +1 -1
- package/script/trellis/trellis.js +379 -177
- package/script/trellis/workload.d.ts +45 -0
- package/script/trellis/workload.d.ts.map +1 -0
- package/script/trellis/workload.js +172 -0
- package/script/_dnt.polyfills.d.ts +0 -7
- package/script/_dnt.polyfills.d.ts.map +0 -1
- package/script/trellis/browser.d.ts +0 -11
- package/script/trellis/browser.d.ts.map +0 -1
- package/script/trellis/browser.js +0 -21
- package/script/trellis/env.d.ts +0 -2
- package/script/trellis/env.d.ts.map +0 -1
- package/script/trellis/env.js +0 -5
- /package/script/{_dnt.polyfills.js → auth/types.js} +0 -0
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// @ts-nocheck
|
|
3
2
|
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
4
3
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
5
4
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
@@ -11,28 +10,45 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
11
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
12
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
13
12
|
};
|
|
14
|
-
var _Trellis_instances, _Trellis_log, _Trellis_tasks, _Trellis_noResponderMaxRetries, _Trellis_noResponderRetryMs, _Trellis_authBypassMethods, _Trellis_handleRPC, _Trellis_processRPCMessage, _Trellis_respondWithError, _Trellis_handleEvent, _Trellis_escapeSubjectToken, _Trellis_createProof,
|
|
13
|
+
var _Trellis_instances, _Trellis_log, _Trellis_tasks, _Trellis_hasExplicitApi, _Trellis_noResponderMaxRetries, _Trellis_noResponderRetryMs, _Trellis_authBypassMethods, _Trellis_operationStore, _Trellis_unknownApiError, _Trellis_handleRPC, _Trellis_processRPCMessage, _Trellis_respondWithError, _Trellis_handleEvent, _Trellis_escapeSubjectToken, _Trellis_createProof, _Trellis_requestJson, _Trellis_watchJson;
|
|
15
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.
|
|
15
|
+
exports.Trellis = exports.DurableOperationRecordSchema = void 0;
|
|
16
|
+
exports.safeJson = safeJson;
|
|
17
|
+
exports.base64urlEncode = base64urlEncode;
|
|
18
|
+
exports.base64urlDecode = base64urlDecode;
|
|
19
|
+
exports.toArrayBuffer = toArrayBuffer;
|
|
20
|
+
exports.sha256 = sha256;
|
|
21
|
+
exports.buildProofInput = buildProofInput;
|
|
22
|
+
exports.isResultLike = isResultLike;
|
|
23
|
+
exports.buildRuntimeOperationSnapshot = buildRuntimeOperationSnapshot;
|
|
24
|
+
exports.isTerminalRuntimeOperationSnapshot = isTerminalRuntimeOperationSnapshot;
|
|
17
25
|
const jetstream_1 = require("@nats-io/jetstream");
|
|
18
26
|
const nats_core_1 = require("@nats-io/nats-core");
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
27
|
+
const result_1 = require("@qlever-llc/result");
|
|
28
|
+
const tracing_ts_1 = require("./tracing.ts");
|
|
29
|
+
const typebox_1 = require("typebox");
|
|
22
30
|
const value_1 = require("typebox/value");
|
|
23
31
|
const ulid_1 = require("ulid");
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const
|
|
32
|
+
const codec_ts_1 = require("./codec.ts");
|
|
33
|
+
const index_ts_1 = require("./errors/index.ts");
|
|
34
|
+
const RemoteError_ts_1 = require("./errors/RemoteError.ts");
|
|
35
|
+
const globals_ts_1 = require("./globals.ts");
|
|
36
|
+
const kv_ts_1 = require("./kv.ts");
|
|
37
|
+
const TrellisError_ts_1 = require("./models/trellis/TrellisError.ts");
|
|
38
|
+
const operations_ts_1 = require("./operations.ts");
|
|
39
|
+
const tasks_ts_1 = require("./tasks.ts");
|
|
30
40
|
/**
|
|
31
41
|
* Safely extract JSON from a NATS message.
|
|
32
42
|
* The .json() method can throw if the message data is not valid JSON.
|
|
33
43
|
*/
|
|
34
44
|
function safeJson(msg) {
|
|
35
|
-
return
|
|
45
|
+
return result_1.Result.try(() => msg.json());
|
|
46
|
+
}
|
|
47
|
+
function encodeRuntimeSchema(schema, data) {
|
|
48
|
+
return (0, codec_ts_1.encodeSchema)(schema, data);
|
|
49
|
+
}
|
|
50
|
+
function parseRuntimeSchema(schema, data) {
|
|
51
|
+
return (0, codec_ts_1.parseUnknownSchema)(schema, data);
|
|
36
52
|
}
|
|
37
53
|
function base64urlEncode(data) {
|
|
38
54
|
const b64 = btoa(String.fromCharCode(...data));
|
|
@@ -86,9 +102,90 @@ function buildProofInput(sessionKey, subject, payloadHash) {
|
|
|
86
102
|
buf.set(payloadHash, offset);
|
|
87
103
|
return buf;
|
|
88
104
|
}
|
|
105
|
+
function isResultLike(value) {
|
|
106
|
+
return value instanceof result_1.Result;
|
|
107
|
+
}
|
|
108
|
+
const DurableOperationSnapshotSchema = typebox_1.Type.Object({
|
|
109
|
+
id: typebox_1.Type.String(),
|
|
110
|
+
service: typebox_1.Type.String(),
|
|
111
|
+
operation: typebox_1.Type.String(),
|
|
112
|
+
revision: typebox_1.Type.Number(),
|
|
113
|
+
state: typebox_1.Type.Union([
|
|
114
|
+
typebox_1.Type.Literal("pending"),
|
|
115
|
+
typebox_1.Type.Literal("running"),
|
|
116
|
+
typebox_1.Type.Literal("completed"),
|
|
117
|
+
typebox_1.Type.Literal("failed"),
|
|
118
|
+
typebox_1.Type.Literal("cancelled"),
|
|
119
|
+
]),
|
|
120
|
+
createdAt: typebox_1.Type.String(),
|
|
121
|
+
updatedAt: typebox_1.Type.String(),
|
|
122
|
+
completedAt: typebox_1.Type.Optional(typebox_1.Type.String()),
|
|
123
|
+
progress: typebox_1.Type.Optional(typebox_1.Type.Any()),
|
|
124
|
+
output: typebox_1.Type.Optional(typebox_1.Type.Any()),
|
|
125
|
+
error: typebox_1.Type.Optional(typebox_1.Type.Object({
|
|
126
|
+
type: typebox_1.Type.String(),
|
|
127
|
+
message: typebox_1.Type.String(),
|
|
128
|
+
})),
|
|
129
|
+
});
|
|
130
|
+
exports.DurableOperationRecordSchema = typebox_1.Type.Object({
|
|
131
|
+
ownerSessionKey: typebox_1.Type.String(),
|
|
132
|
+
sequence: typebox_1.Type.Number(),
|
|
133
|
+
snapshot: DurableOperationSnapshotSchema,
|
|
134
|
+
});
|
|
135
|
+
function buildRuntimeOperationSnapshot(runtime, state, patch) {
|
|
136
|
+
const updatedAt = new Date().toISOString();
|
|
137
|
+
const completedAt = state === "completed" || state === "failed" || state === "cancelled"
|
|
138
|
+
? (patch?.completedAt ?? updatedAt)
|
|
139
|
+
: patch?.completedAt;
|
|
140
|
+
return {
|
|
141
|
+
id: runtime.id,
|
|
142
|
+
service: runtime.service,
|
|
143
|
+
operation: runtime.operation,
|
|
144
|
+
revision: patch?.revision ?? runtime.snapshot.revision + 1,
|
|
145
|
+
state,
|
|
146
|
+
createdAt: patch?.createdAt ?? runtime.snapshot.createdAt,
|
|
147
|
+
updatedAt,
|
|
148
|
+
...(completedAt ? { completedAt } : {}),
|
|
149
|
+
...(patch?.progress !== undefined
|
|
150
|
+
? { progress: patch.progress }
|
|
151
|
+
: runtime.snapshot.progress !== undefined
|
|
152
|
+
? { progress: runtime.snapshot.progress }
|
|
153
|
+
: {}),
|
|
154
|
+
...(patch?.output !== undefined
|
|
155
|
+
? { output: patch.output }
|
|
156
|
+
: runtime.snapshot.output !== undefined
|
|
157
|
+
? { output: runtime.snapshot.output }
|
|
158
|
+
: {}),
|
|
159
|
+
...(patch?.error
|
|
160
|
+
? { error: patch.error }
|
|
161
|
+
: runtime.snapshot.error
|
|
162
|
+
? { error: runtime.snapshot.error }
|
|
163
|
+
: {}),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function isRuntimeOperationSnapshot(value) {
|
|
167
|
+
return !!value && typeof value === "object" &&
|
|
168
|
+
typeof value.id === "string" &&
|
|
169
|
+
typeof value.service === "string" &&
|
|
170
|
+
typeof value.operation === "string" &&
|
|
171
|
+
typeof value.revision === "number" &&
|
|
172
|
+
typeof value.state === "string" &&
|
|
173
|
+
typeof value.createdAt === "string" &&
|
|
174
|
+
typeof value.updatedAt === "string";
|
|
175
|
+
}
|
|
176
|
+
function isTerminalRuntimeOperationSnapshot(value) {
|
|
177
|
+
return isRuntimeOperationSnapshot(value) && (value.state === "completed" || value.state === "failed" ||
|
|
178
|
+
value.state === "cancelled");
|
|
179
|
+
}
|
|
89
180
|
const NATS_SUBJECT_TOKEN_FORBIDDEN = /[\u0000\s.*>~]/gu;
|
|
90
181
|
const DEFAULT_NO_RESPONDER_MAX_RETRIES = 2;
|
|
91
182
|
const DEFAULT_NO_RESPONDER_RETRY_MS = 200;
|
|
183
|
+
const EMPTY_TRELLIS_API = {
|
|
184
|
+
rpc: {},
|
|
185
|
+
operations: {},
|
|
186
|
+
events: {},
|
|
187
|
+
subjects: {},
|
|
188
|
+
};
|
|
92
189
|
class Trellis {
|
|
93
190
|
constructor(name, // Must be unique for a service
|
|
94
191
|
nats, auth, opts) {
|
|
@@ -137,23 +234,27 @@ class Trellis {
|
|
|
137
234
|
});
|
|
138
235
|
_Trellis_log.set(this, void 0);
|
|
139
236
|
_Trellis_tasks.set(this, void 0);
|
|
237
|
+
_Trellis_hasExplicitApi.set(this, void 0);
|
|
140
238
|
_Trellis_noResponderMaxRetries.set(this, void 0);
|
|
141
239
|
_Trellis_noResponderRetryMs.set(this, void 0);
|
|
142
240
|
_Trellis_authBypassMethods.set(this, void 0);
|
|
241
|
+
_Trellis_operationStore.set(this, void 0);
|
|
242
|
+
const api = opts?.api;
|
|
143
243
|
this.name = name;
|
|
144
244
|
this.nats = nats;
|
|
145
245
|
this.js = (0, jetstream_1.jetstream)(this.nats);
|
|
146
246
|
this.auth = auth;
|
|
147
|
-
this.api = (
|
|
148
|
-
__classPrivateFieldSet(this, _Trellis_log, (opts?.log ??
|
|
247
|
+
this.api = (api ?? EMPTY_TRELLIS_API);
|
|
248
|
+
__classPrivateFieldSet(this, _Trellis_log, (opts?.log ?? globals_ts_1.logger).child({ lib: "trellis" }), "f");
|
|
149
249
|
this.timeout = opts?.timeout ?? 3000;
|
|
150
250
|
this.stream = opts?.stream ?? "trellis";
|
|
251
|
+
__classPrivateFieldSet(this, _Trellis_hasExplicitApi, api !== undefined, "f");
|
|
151
252
|
__classPrivateFieldSet(this, _Trellis_noResponderMaxRetries, opts?.noResponderRetry?.maxAttempts ??
|
|
152
253
|
DEFAULT_NO_RESPONDER_MAX_RETRIES, "f");
|
|
153
254
|
__classPrivateFieldSet(this, _Trellis_noResponderRetryMs, opts?.noResponderRetry?.baseDelayMs ??
|
|
154
255
|
DEFAULT_NO_RESPONDER_RETRY_MS, "f");
|
|
155
256
|
__classPrivateFieldSet(this, _Trellis_authBypassMethods, new Set(opts?.authBypassMethods ?? []), "f");
|
|
156
|
-
__classPrivateFieldSet(this, _Trellis_tasks, new
|
|
257
|
+
__classPrivateFieldSet(this, _Trellis_tasks, new tasks_ts_1.TrellisTasks({ log: __classPrivateFieldGet(this, _Trellis_log, "f") }), "f");
|
|
157
258
|
}
|
|
158
259
|
/**
|
|
159
260
|
* Returns the underlying NATS connection.
|
|
@@ -161,6 +262,41 @@ class Trellis {
|
|
|
161
262
|
get natsConnection() {
|
|
162
263
|
return this.nats;
|
|
163
264
|
}
|
|
265
|
+
async operationStoreHandle() {
|
|
266
|
+
if (!__classPrivateFieldGet(this, _Trellis_operationStore, "f")) {
|
|
267
|
+
const bucket = `trellis_operations_${this.name.replace(/[^A-Za-z0-9_-]/g, "_")}`;
|
|
268
|
+
__classPrivateFieldSet(this, _Trellis_operationStore, (async () => {
|
|
269
|
+
const result = await kv_ts_1.TypedKV.open(this.nats, bucket, exports.DurableOperationRecordSchema, {
|
|
270
|
+
history: 5,
|
|
271
|
+
ttl: 0,
|
|
272
|
+
});
|
|
273
|
+
const value = result.take();
|
|
274
|
+
if ((0, result_1.isErr)(value)) {
|
|
275
|
+
throw value.error;
|
|
276
|
+
}
|
|
277
|
+
return value;
|
|
278
|
+
})(), "f");
|
|
279
|
+
}
|
|
280
|
+
return __classPrivateFieldGet(this, _Trellis_operationStore, "f");
|
|
281
|
+
}
|
|
282
|
+
async loadOperationRecord(operationId) {
|
|
283
|
+
const store = await this.operationStoreHandle();
|
|
284
|
+
const entry = await store.get(operationId);
|
|
285
|
+
const value = entry.take();
|
|
286
|
+
if ((0, result_1.isErr)(value)) {
|
|
287
|
+
return null;
|
|
288
|
+
}
|
|
289
|
+
return value.value;
|
|
290
|
+
}
|
|
291
|
+
async saveOperationRecord(runtime) {
|
|
292
|
+
const store = await this.operationStoreHandle();
|
|
293
|
+
const record = {
|
|
294
|
+
ownerSessionKey: runtime.ownerSessionKey,
|
|
295
|
+
sequence: runtime.sequence,
|
|
296
|
+
snapshot: runtime.snapshot,
|
|
297
|
+
};
|
|
298
|
+
await store.put(runtime.id, record);
|
|
299
|
+
}
|
|
164
300
|
/**
|
|
165
301
|
* Makes an authenticated request to a Trellis RPC method.
|
|
166
302
|
*
|
|
@@ -174,44 +310,42 @@ class Trellis {
|
|
|
174
310
|
* ok: A validated reponse of method M
|
|
175
311
|
* err: RemoteError | ValidationError | UnexpectedError
|
|
176
312
|
*/
|
|
177
|
-
// TypeScript hits recursion limits on this generic surface under the app's Svelte check.
|
|
178
|
-
// The implementation still builds and is exercised by runtime validation below.
|
|
179
|
-
// @ts-expect-error
|
|
180
313
|
async request(method, input, opts) {
|
|
181
|
-
__classPrivateFieldGet(this, _Trellis_log, "f").trace({ method: String(method)
|
|
182
|
-
const
|
|
314
|
+
__classPrivateFieldGet(this, _Trellis_log, "f").trace({ method: String(method) }, `Calling ${method.toString()}.`);
|
|
315
|
+
const methodName = method;
|
|
316
|
+
const ctx = this.api["rpc"][methodName];
|
|
183
317
|
if (!ctx) {
|
|
184
|
-
return (0,
|
|
185
|
-
cause:
|
|
318
|
+
return (0, result_1.err)(new index_ts_1.UnexpectedError({
|
|
319
|
+
cause: __classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_unknownApiError).call(this, "RPC method", method.toString()),
|
|
186
320
|
context: { method: method.toString() },
|
|
187
321
|
}));
|
|
188
322
|
}
|
|
189
|
-
const msg = (
|
|
190
|
-
if ((0,
|
|
323
|
+
const msg = encodeRuntimeSchema(ctx.input, input).take();
|
|
324
|
+
if ((0, result_1.isErr)(msg)) {
|
|
191
325
|
return msg;
|
|
192
326
|
}
|
|
193
327
|
const subject = this.template(ctx.subject, input).take();
|
|
194
|
-
if ((0,
|
|
328
|
+
if ((0, result_1.isErr)(subject)) {
|
|
195
329
|
return subject;
|
|
196
330
|
}
|
|
197
331
|
// Start a client span for this RPC request
|
|
198
|
-
const span = (0,
|
|
332
|
+
const span = (0, tracing_ts_1.startClientSpan)(method, subject);
|
|
199
333
|
const attempt = async () => {
|
|
200
334
|
const proof = await __classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_createProof).call(this, subject, msg);
|
|
201
335
|
const headers = (0, nats_core_1.headers)();
|
|
202
336
|
headers.set("session-key", this.auth.sessionKey);
|
|
203
337
|
headers.set("proof", proof);
|
|
204
338
|
// Inject trace context into NATS headers for propagation
|
|
205
|
-
(0,
|
|
339
|
+
(0, tracing_ts_1.injectTraceContext)((0, tracing_ts_1.createNatsHeaderCarrier)(headers), span);
|
|
206
340
|
// Attempt request with retry for transient "no responders" errors
|
|
207
341
|
const requestWithRetry = async () => {
|
|
208
342
|
for (let retry = 0; retry <= __classPrivateFieldGet(this, _Trellis_noResponderMaxRetries, "f"); retry++) {
|
|
209
|
-
const result = await
|
|
343
|
+
const result = await result_1.AsyncResult.try(() => this.nats.request(subject, msg, {
|
|
210
344
|
headers,
|
|
211
345
|
timeout: opts?.timeout ?? this.timeout,
|
|
212
346
|
}));
|
|
213
347
|
if (result.isOk()) {
|
|
214
|
-
return (0,
|
|
348
|
+
return (0, result_1.ok)((await result).take());
|
|
215
349
|
}
|
|
216
350
|
const cause = result.error.cause;
|
|
217
351
|
const message = cause instanceof Error
|
|
@@ -230,7 +364,7 @@ class Trellis {
|
|
|
230
364
|
const reason = isNatsPermission
|
|
231
365
|
? `Permission denied. You need one of these capabilities: ${ctx.callerCapabilities.join(", ")}`
|
|
232
366
|
: message;
|
|
233
|
-
return (0,
|
|
367
|
+
return (0, result_1.err)(new index_ts_1.UnexpectedError({
|
|
234
368
|
cause,
|
|
235
369
|
context: {
|
|
236
370
|
method,
|
|
@@ -242,114 +376,144 @@ class Trellis {
|
|
|
242
376
|
}));
|
|
243
377
|
}
|
|
244
378
|
// Should be unreachable, but TypeScript needs explicit return
|
|
245
|
-
return (0,
|
|
379
|
+
return (0, result_1.err)(new index_ts_1.UnexpectedError({
|
|
246
380
|
context: { method, subject, reason: "retry loop exhausted" },
|
|
247
381
|
}));
|
|
248
382
|
};
|
|
249
383
|
const msgResult = await requestWithRetry();
|
|
250
384
|
const m = msgResult.take();
|
|
251
|
-
if ((0,
|
|
385
|
+
if ((0, result_1.isErr)(m)) {
|
|
252
386
|
return m;
|
|
253
387
|
}
|
|
254
388
|
if (m.headers?.get("status") === "error") {
|
|
255
389
|
const json = safeJson(m).take();
|
|
256
|
-
if ((0,
|
|
390
|
+
if ((0, result_1.isErr)(json)) {
|
|
257
391
|
return json;
|
|
258
392
|
}
|
|
259
|
-
const error = (0,
|
|
260
|
-
if ((0,
|
|
393
|
+
const error = (0, codec_ts_1.parse)(TrellisError_ts_1.TrellisErrorDataSchema, json).take();
|
|
394
|
+
if ((0, result_1.isErr)(error)) {
|
|
261
395
|
return error;
|
|
262
396
|
}
|
|
263
|
-
return (0,
|
|
397
|
+
return (0, result_1.err)(new RemoteError_ts_1.RemoteError({ error }));
|
|
264
398
|
}
|
|
265
399
|
const json = safeJson(m).take();
|
|
266
|
-
if ((0,
|
|
400
|
+
if ((0, result_1.isErr)(json)) {
|
|
267
401
|
return json;
|
|
268
402
|
}
|
|
269
|
-
const outputResult = (
|
|
270
|
-
if (
|
|
271
|
-
return outputResult;
|
|
403
|
+
const outputResult = parseRuntimeSchema(ctx.output, json).take();
|
|
404
|
+
if ((0, result_1.isErr)(outputResult)) {
|
|
405
|
+
return (0, result_1.err)(outputResult.error);
|
|
272
406
|
}
|
|
273
|
-
|
|
274
|
-
return (0, trellis_result_1.ok)(output);
|
|
407
|
+
return (0, result_1.ok)(outputResult);
|
|
275
408
|
};
|
|
276
|
-
return (0,
|
|
409
|
+
return (0, tracing_ts_1.withSpanAsync)(span, async () => {
|
|
277
410
|
try {
|
|
278
411
|
const result = await attempt();
|
|
279
412
|
const value = result.take();
|
|
280
|
-
if ((0,
|
|
413
|
+
if ((0, result_1.isErr)(value)) {
|
|
281
414
|
span.setStatus({
|
|
282
|
-
code:
|
|
415
|
+
code: tracing_ts_1.SpanStatusCode.ERROR,
|
|
283
416
|
message: value.error.message,
|
|
284
417
|
});
|
|
285
418
|
}
|
|
286
419
|
else {
|
|
287
|
-
span.setStatus({ code:
|
|
420
|
+
span.setStatus({ code: tracing_ts_1.SpanStatusCode.OK });
|
|
288
421
|
}
|
|
289
422
|
return result;
|
|
290
423
|
}
|
|
291
424
|
catch (cause) {
|
|
292
|
-
const unexpected = new
|
|
425
|
+
const unexpected = new index_ts_1.UnexpectedError({ cause });
|
|
293
426
|
span.setStatus({
|
|
294
|
-
code:
|
|
427
|
+
code: tracing_ts_1.SpanStatusCode.ERROR,
|
|
295
428
|
message: unexpected.message,
|
|
296
429
|
});
|
|
297
430
|
span.recordException(unexpected);
|
|
298
|
-
return (0,
|
|
431
|
+
return (0, result_1.err)(unexpected);
|
|
299
432
|
}
|
|
300
433
|
finally {
|
|
301
434
|
span.end();
|
|
302
435
|
}
|
|
303
436
|
});
|
|
304
437
|
}
|
|
438
|
+
async requestOrThrow(method, input, opts) {
|
|
439
|
+
const result = await this.request(method, input, opts);
|
|
440
|
+
const value = result.take();
|
|
441
|
+
if ((0, result_1.isErr)(value)) {
|
|
442
|
+
throw value.error;
|
|
443
|
+
}
|
|
444
|
+
return value;
|
|
445
|
+
}
|
|
446
|
+
operation(operation) {
|
|
447
|
+
const descriptor = this.api["operations"]?.[operation];
|
|
448
|
+
if (!descriptor) {
|
|
449
|
+
throw __classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_unknownApiError).call(this, "operation", operation.toString());
|
|
450
|
+
}
|
|
451
|
+
const transport = {
|
|
452
|
+
requestJson: (subject, body) => __classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_requestJson).call(this, subject, body),
|
|
453
|
+
watchJson: (subject, body) => __classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_watchJson).call(this, subject, body),
|
|
454
|
+
};
|
|
455
|
+
return new operations_ts_1.OperationInvoker(transport, descriptor);
|
|
456
|
+
}
|
|
305
457
|
/*
|
|
306
458
|
* Mount a handler to process requests made to a specific Trellis API
|
|
307
459
|
*/
|
|
308
460
|
async mount(method, fn) {
|
|
309
|
-
|
|
461
|
+
const methodName = method;
|
|
462
|
+
const ctx = this.api["rpc"][methodName];
|
|
463
|
+
if (!ctx) {
|
|
464
|
+
throw __classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_unknownApiError).call(this, "RPC method", method.toString());
|
|
465
|
+
}
|
|
466
|
+
const task = __classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_handleRPC).call(this, methodName, fn);
|
|
467
|
+
__classPrivateFieldGet(this, _Trellis_tasks, "f").add(methodName, task);
|
|
468
|
+
}
|
|
469
|
+
respondWithError(msg, error) {
|
|
470
|
+
__classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_respondWithError).call(this, msg, error);
|
|
310
471
|
}
|
|
311
472
|
async publish(event, data) {
|
|
312
|
-
const
|
|
473
|
+
const eventName = event;
|
|
474
|
+
const ctx = this.api["events"][eventName];
|
|
313
475
|
if (!ctx) {
|
|
314
|
-
return (0,
|
|
315
|
-
cause:
|
|
476
|
+
return (0, result_1.err)(new index_ts_1.UnexpectedError({
|
|
477
|
+
cause: __classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_unknownApiError).call(this, "event", event.toString()),
|
|
316
478
|
context: { event: event.toString() },
|
|
317
479
|
}));
|
|
318
480
|
}
|
|
319
481
|
const subject = this.template(ctx.subject, data).take();
|
|
320
|
-
if ((0,
|
|
321
|
-
|
|
482
|
+
if ((0, result_1.isErr)(subject)) {
|
|
483
|
+
globals_ts_1.logger.error({ err: subject.error }, "Failed to template event.");
|
|
322
484
|
return subject;
|
|
323
485
|
}
|
|
324
|
-
const
|
|
486
|
+
const payload = {
|
|
325
487
|
...data,
|
|
326
488
|
header: {
|
|
327
489
|
id: (0, ulid_1.ulid)(),
|
|
328
490
|
time: new Date().toISOString(),
|
|
329
491
|
},
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
492
|
+
};
|
|
493
|
+
const msg = (0, codec_ts_1.encodeSchema)(ctx.event, payload).take();
|
|
494
|
+
if ((0, result_1.isErr)(msg)) {
|
|
495
|
+
globals_ts_1.logger.error({ err: msg.error }, "Failed to encode event.");
|
|
496
|
+
return (0, result_1.err)(new index_ts_1.UnexpectedError({ cause: msg.error }));
|
|
334
497
|
}
|
|
335
|
-
|
|
498
|
+
globals_ts_1.logger.trace({ subject }, `Publishing ${event.toString()} event.`);
|
|
336
499
|
await this.js.publish(subject, msg);
|
|
337
|
-
return (0,
|
|
500
|
+
return (0, result_1.ok)(undefined);
|
|
338
501
|
}
|
|
339
502
|
async event(event, subjectData, fn) {
|
|
340
|
-
const
|
|
503
|
+
const eventName = event;
|
|
504
|
+
const ctx = this.api["events"][eventName];
|
|
341
505
|
if (!ctx) {
|
|
342
|
-
return (0,
|
|
343
|
-
cause:
|
|
506
|
+
return (0, result_1.err)(new index_ts_1.UnexpectedError({
|
|
507
|
+
cause: __classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_unknownApiError).call(this, "event", event.toString()),
|
|
344
508
|
context: { event: event.toString() },
|
|
345
509
|
}));
|
|
346
510
|
}
|
|
347
511
|
const jsm = await (0, jetstream_1.jetstreamManager)(this.nats);
|
|
348
512
|
const subject = this.template(ctx.subject, subjectData, true).take();
|
|
349
|
-
if ((0,
|
|
513
|
+
if ((0, result_1.isErr)(subject))
|
|
350
514
|
return subject;
|
|
351
515
|
const consumerName = `${this.name}-${event.replaceAll(".", "_")}`;
|
|
352
|
-
const addResult = await
|
|
516
|
+
const addResult = await result_1.AsyncResult.try(() => jsm.consumers.add(this.stream, {
|
|
353
517
|
durable_name: consumerName,
|
|
354
518
|
ack_policy: "explicit",
|
|
355
519
|
deliver_policy: "all",
|
|
@@ -358,13 +522,13 @@ class Trellis {
|
|
|
358
522
|
// If add failed (consumer already exists), try to get existing consumer info
|
|
359
523
|
const consumerInfoResult = addResult.isOk()
|
|
360
524
|
? addResult
|
|
361
|
-
: await
|
|
525
|
+
: await result_1.AsyncResult.try(() => jsm.consumers.info(this.stream, consumerName));
|
|
362
526
|
const info = consumerInfoResult.take();
|
|
363
|
-
if ((0,
|
|
527
|
+
if ((0, result_1.isErr)(info))
|
|
364
528
|
return info;
|
|
365
529
|
const consumer = this.js.consumers.getConsumerFromInfo(info);
|
|
366
|
-
__classPrivateFieldGet(this, _Trellis_tasks, "f").add(
|
|
367
|
-
return (0,
|
|
530
|
+
__classPrivateFieldGet(this, _Trellis_tasks, "f").add(eventName, __classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_handleEvent).call(this, eventName, consumer, fn));
|
|
531
|
+
return (0, result_1.ok)(undefined);
|
|
368
532
|
}
|
|
369
533
|
wait() {
|
|
370
534
|
return __classPrivateFieldGet(this, _Trellis_tasks, "f").wait();
|
|
@@ -377,7 +541,7 @@ class Trellis {
|
|
|
377
541
|
const key = placeholder.slice(1, -1); // Remove { and }
|
|
378
542
|
const value = value_1.Pointer.Get(data, key);
|
|
379
543
|
if ((value === undefined || value === null) && !allowWildcards) {
|
|
380
|
-
return (0,
|
|
544
|
+
return (0, result_1.err)(new index_ts_1.ValidationError({
|
|
381
545
|
errors: [
|
|
382
546
|
{
|
|
383
547
|
path: key,
|
|
@@ -398,24 +562,35 @@ class Trellis {
|
|
|
398
562
|
}
|
|
399
563
|
return __classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_escapeSubjectToken).call(this, `${value}`);
|
|
400
564
|
});
|
|
401
|
-
return (0,
|
|
565
|
+
return (0, result_1.ok)(result);
|
|
566
|
+
}
|
|
567
|
+
async requestAuthValidate(input) {
|
|
568
|
+
const request = this.request.bind(this);
|
|
569
|
+
const result = await request("Auth.ValidateRequest", input);
|
|
570
|
+
return result;
|
|
402
571
|
}
|
|
403
572
|
}
|
|
404
573
|
exports.Trellis = Trellis;
|
|
405
|
-
_Trellis_log = new WeakMap(), _Trellis_tasks = new WeakMap(), _Trellis_noResponderMaxRetries = new WeakMap(), _Trellis_noResponderRetryMs = new WeakMap(), _Trellis_authBypassMethods = new WeakMap(), _Trellis_instances = new WeakSet(),
|
|
574
|
+
_Trellis_log = new WeakMap(), _Trellis_tasks = new WeakMap(), _Trellis_hasExplicitApi = new WeakMap(), _Trellis_noResponderMaxRetries = new WeakMap(), _Trellis_noResponderRetryMs = new WeakMap(), _Trellis_authBypassMethods = new WeakMap(), _Trellis_operationStore = new WeakMap(), _Trellis_instances = new WeakSet(), _Trellis_unknownApiError = function _Trellis_unknownApiError(kind, name) {
|
|
575
|
+
const base = `Unknown ${kind} '${name}'.`;
|
|
576
|
+
if (__classPrivateFieldGet(this, _Trellis_hasExplicitApi, "f")) {
|
|
577
|
+
return new Error(`${base} Did you forget to include its API module?`);
|
|
578
|
+
}
|
|
579
|
+
return new Error(`${base} No API surface was provided. Pass opts.api, use createClient(contract, ...), or await createCoreClient(...) instead.`);
|
|
580
|
+
}, _Trellis_handleRPC = function _Trellis_handleRPC(method, fn, subjectData = {}) {
|
|
406
581
|
// Get API details
|
|
407
582
|
const ctx = this.api["rpc"][method];
|
|
408
583
|
const subject = this.template(ctx.subject, subjectData, true).take();
|
|
409
|
-
if ((0,
|
|
410
|
-
return
|
|
584
|
+
if ((0, result_1.isErr)(subject)) {
|
|
585
|
+
return result_1.AsyncResult.lift(subject);
|
|
411
586
|
}
|
|
412
587
|
__classPrivateFieldGet(this, _Trellis_log, "f").info({ method: String(method) }, `Mounting ${method.toString()} RPC handler`);
|
|
413
588
|
const sub = this.nats.subscribe(subject);
|
|
414
|
-
return
|
|
589
|
+
return result_1.AsyncResult.try(async () => {
|
|
415
590
|
for await (const msg of sub) {
|
|
416
591
|
const resultPromise = await __classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_processRPCMessage).call(this, method, ctx, msg, fn);
|
|
417
592
|
const result = resultPromise.take();
|
|
418
|
-
if ((0,
|
|
593
|
+
if ((0, result_1.isErr)(result)) {
|
|
419
594
|
__classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_respondWithError).call(this, msg, result.error);
|
|
420
595
|
continue;
|
|
421
596
|
}
|
|
@@ -425,42 +600,41 @@ _Trellis_log = new WeakMap(), _Trellis_tasks = new WeakMap(), _Trellis_noRespond
|
|
|
425
600
|
}, _Trellis_processRPCMessage = async function _Trellis_processRPCMessage(method, ctx, msg, fn) {
|
|
426
601
|
__classPrivateFieldGet(this, _Trellis_log, "f").debug({ method: String(method), subject: msg.subject }, "Processing RPC message");
|
|
427
602
|
// Extract trace context from incoming NATS headers
|
|
428
|
-
const parentContext = (0,
|
|
603
|
+
const parentContext = (0, tracing_ts_1.extractTraceContext)((0, tracing_ts_1.createNatsHeaderCarrier)({
|
|
429
604
|
get: (k) => msg.headers?.get(k) ?? undefined,
|
|
430
605
|
set: () => { }, // Server doesn't need to set headers on incoming messages
|
|
431
606
|
}));
|
|
432
607
|
// Start a server span for this RPC handler
|
|
433
|
-
const span = (0,
|
|
608
|
+
const span = (0, tracing_ts_1.startServerSpan)(method, msg.subject, parentContext);
|
|
434
609
|
// Execute the handler within the span's context
|
|
435
|
-
return (0,
|
|
610
|
+
return (0, tracing_ts_1.withSpanAsync)(span, async () => {
|
|
436
611
|
const execute = async () => {
|
|
437
612
|
const jsonData = safeJson(msg).take();
|
|
438
|
-
if ((0,
|
|
613
|
+
if ((0, result_1.isErr)(jsonData)) {
|
|
439
614
|
__classPrivateFieldGet(this, _Trellis_log, "f").warn({ method, error: jsonData.error.message }, "Failed to parse JSON");
|
|
440
615
|
span.setStatus({
|
|
441
|
-
code:
|
|
616
|
+
code: tracing_ts_1.SpanStatusCode.ERROR,
|
|
442
617
|
message: "Failed to parse JSON",
|
|
443
618
|
});
|
|
444
619
|
return jsonData;
|
|
445
620
|
}
|
|
446
|
-
const parsedInput = (
|
|
447
|
-
if ((0,
|
|
621
|
+
const parsedInput = parseRuntimeSchema(ctx.input, jsonData).take();
|
|
622
|
+
if ((0, result_1.isErr)(parsedInput)) {
|
|
448
623
|
span.setStatus({
|
|
449
|
-
code:
|
|
624
|
+
code: tracing_ts_1.SpanStatusCode.ERROR,
|
|
450
625
|
message: "Input validation failed",
|
|
451
626
|
});
|
|
452
627
|
return parsedInput;
|
|
453
628
|
}
|
|
454
|
-
let
|
|
629
|
+
let caller;
|
|
455
630
|
const callerSessionKey = msg.headers?.get("session-key") ?? "";
|
|
456
631
|
const authRequired = ctx.authRequired ?? true;
|
|
457
632
|
if (!authRequired || __classPrivateFieldGet(this, _Trellis_authBypassMethods, "f").has(method)) {
|
|
458
|
-
|
|
633
|
+
caller = {
|
|
634
|
+
type: "service",
|
|
459
635
|
id: "system",
|
|
460
|
-
origin: "trellis",
|
|
461
636
|
active: true,
|
|
462
637
|
name: "System",
|
|
463
|
-
email: "system@trellis.internal",
|
|
464
638
|
capabilities: ["service"],
|
|
465
639
|
};
|
|
466
640
|
}
|
|
@@ -470,25 +644,25 @@ _Trellis_log = new WeakMap(), _Trellis_tasks = new WeakMap(), _Trellis_noRespond
|
|
|
470
644
|
if (!sessionKey) {
|
|
471
645
|
__classPrivateFieldGet(this, _Trellis_log, "f").warn({ method }, "Missing session-key header");
|
|
472
646
|
span.setStatus({
|
|
473
|
-
code:
|
|
647
|
+
code: tracing_ts_1.SpanStatusCode.ERROR,
|
|
474
648
|
message: "Missing session-key",
|
|
475
649
|
});
|
|
476
|
-
return (0,
|
|
650
|
+
return (0, result_1.err)(new index_ts_1.AuthError({ reason: "missing_session_key" }));
|
|
477
651
|
}
|
|
478
652
|
if (!proof) {
|
|
479
653
|
__classPrivateFieldGet(this, _Trellis_log, "f").warn({ method }, "Missing proof in request");
|
|
480
654
|
span.setStatus({
|
|
481
|
-
code:
|
|
655
|
+
code: tracing_ts_1.SpanStatusCode.ERROR,
|
|
482
656
|
message: "Missing proof",
|
|
483
657
|
});
|
|
484
|
-
return (0,
|
|
658
|
+
return (0, result_1.err)(new index_ts_1.AuthError({ reason: "missing_proof" }));
|
|
485
659
|
}
|
|
486
660
|
// Verify proof signature locally using the raw request bytes we received.
|
|
487
661
|
const payloadBytes = msg.data ?? new Uint8Array();
|
|
488
662
|
const payloadHash = await sha256(payloadBytes);
|
|
489
663
|
const proofInput = buildProofInput(sessionKey, msg.subject, payloadHash);
|
|
490
664
|
const digest = await sha256(proofInput);
|
|
491
|
-
const verifyResult = await
|
|
665
|
+
const verifyResult = await result_1.AsyncResult.try(async () => {
|
|
492
666
|
const publicKeyRaw = base64urlDecode(sessionKey);
|
|
493
667
|
const pub = await crypto.subtle.importKey("raw", toArrayBuffer(publicKeyRaw), { name: "Ed25519" }, true, ["verify"]);
|
|
494
668
|
return crypto.subtle.verify({ name: "Ed25519" }, pub, toArrayBuffer(base64urlDecode(proof)), toArrayBuffer(digest));
|
|
@@ -497,15 +671,15 @@ _Trellis_log = new WeakMap(), _Trellis_tasks = new WeakMap(), _Trellis_noRespond
|
|
|
497
671
|
(await verifyResult).take() === true;
|
|
498
672
|
if (!signatureOk) {
|
|
499
673
|
span.setStatus({
|
|
500
|
-
code:
|
|
674
|
+
code: tracing_ts_1.SpanStatusCode.ERROR,
|
|
501
675
|
message: "Invalid signature",
|
|
502
676
|
});
|
|
503
|
-
return (0,
|
|
677
|
+
return (0, result_1.err)(new index_ts_1.AuthError({
|
|
504
678
|
reason: "invalid_signature",
|
|
505
679
|
context: { sessionKey },
|
|
506
680
|
}));
|
|
507
681
|
}
|
|
508
|
-
const authResult = await this.
|
|
682
|
+
const authResult = await this.requestAuthValidate({
|
|
509
683
|
sessionKey,
|
|
510
684
|
proof,
|
|
511
685
|
subject: msg.subject,
|
|
@@ -513,52 +687,61 @@ _Trellis_log = new WeakMap(), _Trellis_tasks = new WeakMap(), _Trellis_noRespond
|
|
|
513
687
|
capabilities: ctx.callerCapabilities,
|
|
514
688
|
});
|
|
515
689
|
const auth = authResult.take();
|
|
516
|
-
if ((0,
|
|
690
|
+
if ((0, result_1.isErr)(auth)) {
|
|
517
691
|
__classPrivateFieldGet(this, _Trellis_log, "f").warn({
|
|
518
692
|
method,
|
|
519
693
|
error: auth.error.message,
|
|
520
694
|
errorType: auth.error.name,
|
|
521
|
-
remoteError: auth.error instanceof
|
|
695
|
+
remoteError: auth.error instanceof RemoteError_ts_1.RemoteError
|
|
522
696
|
? auth.error.toSerializable()
|
|
523
697
|
: undefined,
|
|
524
698
|
}, "Auth.ValidateRequest failed");
|
|
525
699
|
span.setStatus({
|
|
526
|
-
code:
|
|
700
|
+
code: tracing_ts_1.SpanStatusCode.ERROR,
|
|
527
701
|
message: "Auth.ValidateRequest failed",
|
|
528
702
|
});
|
|
529
|
-
return auth;
|
|
703
|
+
return (0, result_1.err)(auth.error);
|
|
530
704
|
}
|
|
531
705
|
if (!auth.allowed) {
|
|
532
706
|
span.setStatus({
|
|
533
|
-
code:
|
|
707
|
+
code: tracing_ts_1.SpanStatusCode.ERROR,
|
|
534
708
|
message: "Insufficient permissions",
|
|
535
709
|
});
|
|
536
|
-
return (0,
|
|
710
|
+
return (0, result_1.err)(new index_ts_1.AuthError({
|
|
537
711
|
reason: "insufficient_permissions",
|
|
538
712
|
context: {
|
|
539
713
|
requiredCapabilities: ctx.callerCapabilities,
|
|
540
|
-
userCapabilities: auth.
|
|
714
|
+
userCapabilities: auth.caller.capabilities,
|
|
541
715
|
},
|
|
542
716
|
}));
|
|
543
717
|
}
|
|
544
718
|
if (typeof msg.reply !== "string" ||
|
|
545
719
|
!msg.reply.startsWith(`${auth.inboxPrefix}.`)) {
|
|
546
720
|
span.setStatus({
|
|
547
|
-
code:
|
|
721
|
+
code: tracing_ts_1.SpanStatusCode.ERROR,
|
|
548
722
|
message: "Reply subject mismatch",
|
|
549
723
|
});
|
|
550
|
-
return (0,
|
|
724
|
+
return (0, result_1.err)(new index_ts_1.AuthError({
|
|
551
725
|
reason: "reply_subject_mismatch",
|
|
552
726
|
context: { expected: auth.inboxPrefix, actual: msg.reply },
|
|
553
727
|
}));
|
|
554
728
|
}
|
|
555
|
-
|
|
729
|
+
caller = auth.caller;
|
|
730
|
+
}
|
|
731
|
+
span.setAttribute("auth.caller.type", caller.type);
|
|
732
|
+
if (caller.type === "user") {
|
|
733
|
+
span.setAttribute("user.id", caller.id);
|
|
734
|
+
span.setAttribute("user.origin", caller.origin);
|
|
556
735
|
}
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
736
|
+
if (caller.type === "service") {
|
|
737
|
+
span.setAttribute("service.id", caller.id);
|
|
738
|
+
}
|
|
739
|
+
if (caller.type === "workload") {
|
|
740
|
+
span.setAttribute("workload.instance_id", caller.instanceId);
|
|
741
|
+
span.setAttribute("workload.profile_id", caller.profileId);
|
|
742
|
+
}
|
|
743
|
+
const handlerResultWrapped = await result_1.AsyncResult.try(() => fn(parsedInput, {
|
|
744
|
+
caller,
|
|
562
745
|
sessionKey: callerSessionKey,
|
|
563
746
|
}));
|
|
564
747
|
if (handlerResultWrapped.isErr()) {
|
|
@@ -571,21 +754,21 @@ _Trellis_log = new WeakMap(), _Trellis_tasks = new WeakMap(), _Trellis_noRespond
|
|
|
571
754
|
: error.cause,
|
|
572
755
|
}, "Handler threw unexpectedly.");
|
|
573
756
|
span.setStatus({
|
|
574
|
-
code:
|
|
757
|
+
code: tracing_ts_1.SpanStatusCode.ERROR,
|
|
575
758
|
message: error.message,
|
|
576
759
|
});
|
|
577
760
|
span.recordException(error);
|
|
578
|
-
return (0,
|
|
761
|
+
return (0, result_1.err)(error);
|
|
579
762
|
}
|
|
580
763
|
const handlerResult = (await handlerResultWrapped).take();
|
|
581
764
|
const handlerOutcome = handlerResult.take();
|
|
582
|
-
if ((0,
|
|
765
|
+
if ((0, result_1.isErr)(handlerOutcome)) {
|
|
583
766
|
const handlerError = handlerOutcome.error;
|
|
584
|
-
const error = handlerError instanceof
|
|
585
|
-
handlerError instanceof
|
|
586
|
-
handlerError instanceof
|
|
767
|
+
const error = handlerError instanceof index_ts_1.UnexpectedError ||
|
|
768
|
+
handlerError instanceof index_ts_1.AuthError ||
|
|
769
|
+
handlerError instanceof index_ts_1.ValidationError
|
|
587
770
|
? handlerError
|
|
588
|
-
: new
|
|
771
|
+
: new index_ts_1.UnexpectedError({ cause: handlerError });
|
|
589
772
|
__classPrivateFieldGet(this, _Trellis_log, "f").error({
|
|
590
773
|
method,
|
|
591
774
|
error: error.message,
|
|
@@ -595,38 +778,38 @@ _Trellis_log = new WeakMap(), _Trellis_tasks = new WeakMap(), _Trellis_noRespond
|
|
|
595
778
|
: error.cause,
|
|
596
779
|
}, "Handler returned error.");
|
|
597
780
|
span.setStatus({
|
|
598
|
-
code:
|
|
781
|
+
code: tracing_ts_1.SpanStatusCode.ERROR,
|
|
599
782
|
message: error.message,
|
|
600
783
|
});
|
|
601
|
-
return (0,
|
|
784
|
+
return (0, result_1.err)(error);
|
|
602
785
|
}
|
|
603
|
-
const encoded = (0,
|
|
604
|
-
if ((0,
|
|
786
|
+
const encoded = (0, codec_ts_1.encodeSchema)(ctx.output, handlerOutcome).take();
|
|
787
|
+
if ((0, result_1.isErr)(encoded)) {
|
|
605
788
|
span.setStatus({
|
|
606
|
-
code:
|
|
789
|
+
code: tracing_ts_1.SpanStatusCode.ERROR,
|
|
607
790
|
message: "Output encoding failed",
|
|
608
791
|
});
|
|
609
792
|
return encoded;
|
|
610
793
|
}
|
|
611
|
-
span.setStatus({ code:
|
|
612
|
-
return (0,
|
|
794
|
+
span.setStatus({ code: tracing_ts_1.SpanStatusCode.OK });
|
|
795
|
+
return (0, result_1.ok)(encoded);
|
|
613
796
|
};
|
|
614
797
|
const result = await execute();
|
|
615
798
|
span.end();
|
|
616
799
|
return result;
|
|
617
800
|
});
|
|
618
801
|
}, _Trellis_respondWithError = function _Trellis_respondWithError(msg, error) {
|
|
619
|
-
const trellisError = error instanceof
|
|
620
|
-
error instanceof
|
|
621
|
-
error instanceof
|
|
622
|
-
error instanceof
|
|
802
|
+
const trellisError = error instanceof index_ts_1.UnexpectedError ||
|
|
803
|
+
error instanceof index_ts_1.AuthError ||
|
|
804
|
+
error instanceof index_ts_1.ValidationError ||
|
|
805
|
+
error instanceof RemoteError_ts_1.RemoteError
|
|
623
806
|
? error
|
|
624
|
-
: new
|
|
807
|
+
: new index_ts_1.UnexpectedError({ cause: error });
|
|
625
808
|
__classPrivateFieldGet(this, _Trellis_log, "f").error({ error: trellisError.toSerializable() }, "RPC error");
|
|
626
809
|
const errorData = trellisError.toSerializable();
|
|
627
810
|
const hdrs = (0, nats_core_1.headers)();
|
|
628
811
|
hdrs.set("status", "error");
|
|
629
|
-
const serialized =
|
|
812
|
+
const serialized = result_1.Result.try(() => JSON.stringify(errorData));
|
|
630
813
|
if (serialized.isErr()) {
|
|
631
814
|
__classPrivateFieldGet(this, _Trellis_log, "f").error({ error: serialized.error }, "Failed to serialize error response");
|
|
632
815
|
msg.respond('{"type":"UnexpectedError","message":"Failed to serialize error"}', { headers: hdrs });
|
|
@@ -635,24 +818,35 @@ _Trellis_log = new WeakMap(), _Trellis_tasks = new WeakMap(), _Trellis_noRespond
|
|
|
635
818
|
msg.respond(serialized.take(), { headers: hdrs });
|
|
636
819
|
}, _Trellis_handleEvent = function _Trellis_handleEvent(event, consumer, fn) {
|
|
637
820
|
const ctx = this.api["events"][event];
|
|
638
|
-
return
|
|
821
|
+
return result_1.AsyncResult.try(async () => {
|
|
639
822
|
const msgs = await consumer.consume();
|
|
640
823
|
for await (const msg of msgs) {
|
|
641
|
-
const jsonData =
|
|
824
|
+
const jsonData = result_1.Result.try(() => msg.json());
|
|
642
825
|
if (jsonData.isErr()) {
|
|
643
826
|
__classPrivateFieldGet(this, _Trellis_log, "f").error({ error: jsonData.error }, "Event parse failed");
|
|
644
827
|
msg.term();
|
|
645
828
|
continue;
|
|
646
829
|
}
|
|
647
|
-
const
|
|
648
|
-
if ((0,
|
|
830
|
+
const json = jsonData.take();
|
|
831
|
+
if ((0, result_1.isErr)(json)) {
|
|
832
|
+
__classPrivateFieldGet(this, _Trellis_log, "f").error({ error: json.error }, "Event parse failed");
|
|
833
|
+
msg.term();
|
|
834
|
+
continue;
|
|
835
|
+
}
|
|
836
|
+
const parsedEvent = parseRuntimeSchema(ctx.event, json);
|
|
837
|
+
const m = parsedEvent.take();
|
|
838
|
+
if ((0, result_1.isErr)(m)) {
|
|
649
839
|
__classPrivateFieldGet(this, _Trellis_log, "f").error({ error: m.error }, "Event validation failed");
|
|
650
840
|
msg.term();
|
|
651
841
|
continue;
|
|
652
842
|
}
|
|
653
|
-
const handlerResult = await
|
|
843
|
+
const handlerResult = await result_1.AsyncResult.lift(fn(m));
|
|
654
844
|
if (handlerResult.isErr()) {
|
|
655
|
-
__classPrivateFieldGet(this, _Trellis_log, "f").error({
|
|
845
|
+
__classPrivateFieldGet(this, _Trellis_log, "f").error({
|
|
846
|
+
error: handlerResult.error.toSerializable(),
|
|
847
|
+
event,
|
|
848
|
+
subject: msg.subject,
|
|
849
|
+
}, "Event handler failed");
|
|
656
850
|
msg.nak();
|
|
657
851
|
continue;
|
|
658
852
|
}
|
|
@@ -673,43 +867,51 @@ _Trellis_log = new WeakMap(), _Trellis_tasks = new WeakMap(), _Trellis_noRespond
|
|
|
673
867
|
const digest = await sha256(input);
|
|
674
868
|
const sigBytes = await this.auth.sign(digest);
|
|
675
869
|
return base64urlEncode(sigBytes);
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
870
|
+
}, _Trellis_requestJson = async function _Trellis_requestJson(subject, body) {
|
|
871
|
+
const payload = JSON.stringify(body);
|
|
872
|
+
const proof = await __classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_createProof).call(this, subject, payload);
|
|
873
|
+
const headers = (0, nats_core_1.headers)();
|
|
874
|
+
headers.set("session-key", this.auth.sessionKey);
|
|
875
|
+
headers.set("proof", proof);
|
|
876
|
+
const response = await result_1.AsyncResult.try(() => this.nats.request(subject, payload, {
|
|
877
|
+
timeout: this.timeout,
|
|
878
|
+
headers,
|
|
879
|
+
})).take();
|
|
880
|
+
if ((0, result_1.isErr)(response)) {
|
|
881
|
+
return response;
|
|
684
882
|
}
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
return new TrellisServer(name, nats, auth, opts);
|
|
883
|
+
return safeJson(response);
|
|
884
|
+
}, _Trellis_watchJson = async function _Trellis_watchJson(subject, body) {
|
|
885
|
+
const payload = JSON.stringify(body);
|
|
886
|
+
const proof = await __classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_createProof).call(this, subject, payload);
|
|
887
|
+
const headers = (0, nats_core_1.headers)();
|
|
888
|
+
headers.set("session-key", this.auth.sessionKey);
|
|
889
|
+
headers.set("proof", proof);
|
|
890
|
+
const inbox = (0, nats_core_1.createInbox)(`_INBOX.${this.auth.sessionKey.slice(0, 16)}`);
|
|
891
|
+
const sub = this.nats.subscribe(inbox);
|
|
892
|
+
try {
|
|
893
|
+
this.nats.publish(subject, payload, {
|
|
894
|
+
headers,
|
|
895
|
+
reply: inbox,
|
|
896
|
+
});
|
|
897
|
+
await this.nats.flush();
|
|
701
898
|
}
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
* This method is idempotent and can be called multiple times safely.
|
|
706
|
-
*/
|
|
707
|
-
async stop() {
|
|
708
|
-
// Only drain if the connection is not already closed
|
|
709
|
-
if (!this.natsConnection.isClosed()) {
|
|
710
|
-
await this.natsConnection.drain();
|
|
711
|
-
}
|
|
899
|
+
catch (cause) {
|
|
900
|
+
sub.unsubscribe();
|
|
901
|
+
return (0, result_1.err)(new index_ts_1.UnexpectedError({ cause }));
|
|
712
902
|
}
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
903
|
+
return (0, result_1.ok)((async function* () {
|
|
904
|
+
try {
|
|
905
|
+
for await (const msg of sub) {
|
|
906
|
+
if (msg.headers?.get("status") === "error") {
|
|
907
|
+
yield (0, result_1.err)(new index_ts_1.UnexpectedError({ cause: new Error(msg.string()) }));
|
|
908
|
+
continue;
|
|
909
|
+
}
|
|
910
|
+
yield safeJson(msg);
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
finally {
|
|
914
|
+
sub.unsubscribe();
|
|
915
|
+
}
|
|
916
|
+
})());
|
|
917
|
+
};
|