@qlever-llc/trellis 0.8.3 → 0.9.0-rc.10
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 +1 -1
- package/bin/trellis-generate.js +132 -0
- package/esm/auth/browser/login.d.ts.map +1 -1
- package/esm/auth/browser/login.js +46 -3
- package/esm/auth/browser/portal.d.ts.map +1 -1
- package/esm/auth/browser/portal.js +5 -1
- package/esm/auth/browser/session.d.ts +18 -7
- package/esm/auth/browser/session.d.ts.map +1 -1
- package/esm/auth/browser/session.js +47 -11
- package/esm/auth/browser/storage.d.ts +6 -1
- package/esm/auth/browser/storage.d.ts.map +1 -1
- package/esm/auth/browser/storage.js +15 -3
- package/esm/auth/browser.d.ts +2 -2
- package/esm/auth/browser.d.ts.map +1 -1
- package/esm/auth/browser.js +1 -1
- package/esm/auth/device_activation.d.ts +36 -33
- package/esm/auth/device_activation.d.ts.map +1 -1
- package/esm/auth/device_activation.js +26 -22
- package/esm/auth/mod.d.ts +4 -4
- package/esm/auth/mod.d.ts.map +1 -1
- package/esm/auth/mod.js +2 -2
- package/esm/auth/proof.d.ts +3 -1
- package/esm/auth/proof.d.ts.map +1 -1
- package/esm/auth/proof.js +21 -15
- package/esm/auth/protocol.d.ts +2457 -941
- package/esm/auth/protocol.d.ts.map +1 -1
- package/esm/auth/protocol.js +747 -375
- package/esm/auth/schemas.d.ts +25 -4
- package/esm/auth/schemas.d.ts.map +1 -1
- package/esm/auth/schemas.js +14 -4
- package/esm/auth/session_auth.d.ts +1 -1
- package/esm/auth/session_auth.d.ts.map +1 -1
- package/esm/auth/session_auth.js +7 -1
- package/esm/client_connect.d.ts +2 -0
- package/esm/client_connect.d.ts.map +1 -1
- package/esm/client_connect.js +76 -15
- package/esm/contract.d.ts +3 -0
- package/esm/contract.d.ts.map +1 -1
- package/esm/contract_support/mod.d.ts +422 -43
- package/esm/contract_support/mod.d.ts.map +1 -1
- package/esm/contract_support/mod.js +734 -33
- package/esm/contract_support/protocol.d.ts +20 -5
- package/esm/contract_support/protocol.d.ts.map +1 -1
- package/esm/contract_support/protocol.js +18 -10
- package/esm/contract_support/runtime.d.ts +11 -0
- package/esm/contract_support/runtime.d.ts.map +1 -1
- package/esm/contract_support/schema_pointers.d.ts.map +1 -1
- package/esm/contract_support/schema_pointers.js +32 -14
- package/esm/device.d.ts +2 -0
- package/esm/device.d.ts.map +1 -1
- package/esm/device.js +3 -0
- package/esm/errors/AuthError.d.ts +2 -1
- package/esm/errors/AuthError.d.ts.map +1 -1
- package/esm/errors/AuthError.js +8 -3
- package/esm/errors/index.d.ts +4 -4
- package/esm/errors/index.d.ts.map +1 -1
- package/esm/errors/index.js +1 -0
- package/esm/generated-sdk/auth/api.d.ts +27 -9
- package/esm/generated-sdk/auth/api.d.ts.map +1 -1
- package/esm/generated-sdk/auth/api.js +16 -590
- package/esm/generated-sdk/auth/client.d.ts +91 -85
- package/esm/generated-sdk/auth/client.d.ts.map +1 -1
- package/esm/generated-sdk/auth/contract.d.ts +1 -1
- package/esm/generated-sdk/auth/contract.d.ts.map +1 -1
- package/esm/generated-sdk/auth/contract.js +4 -2
- package/esm/generated-sdk/auth/mod.d.ts +1 -0
- package/esm/generated-sdk/auth/mod.d.ts.map +1 -1
- package/esm/generated-sdk/auth/owned_api.d.ts +3 -0
- package/esm/generated-sdk/auth/owned_api.d.ts.map +1 -0
- package/esm/generated-sdk/auth/owned_api.js +594 -0
- package/esm/generated-sdk/auth/schemas.d.ts +9959 -5160
- package/esm/generated-sdk/auth/schemas.d.ts.map +1 -1
- package/esm/generated-sdk/auth/schemas.js +136 -137
- package/esm/generated-sdk/auth/types.d.ts +2418 -1557
- 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 +24 -9
- package/esm/generated-sdk/health/api.d.ts.map +1 -1
- package/esm/generated-sdk/health/api.js +12 -20
- package/esm/generated-sdk/health/client.d.ts +2 -1
- package/esm/generated-sdk/health/client.d.ts.map +1 -1
- package/esm/generated-sdk/health/contract.d.ts.map +1 -1
- package/esm/generated-sdk/health/contract.js +2 -0
- package/esm/generated-sdk/health/owned_api.d.ts +3 -0
- package/esm/generated-sdk/health/owned_api.d.ts.map +1 -0
- package/esm/generated-sdk/health/owned_api.js +16 -0
- package/esm/generated-sdk/health/types.d.ts +2 -0
- package/esm/generated-sdk/health/types.d.ts.map +1 -1
- package/esm/generated-sdk/jobs/api.d.ts +33 -9
- package/esm/generated-sdk/jobs/api.d.ts.map +1 -1
- package/esm/generated-sdk/jobs/api.js +22 -87
- package/esm/generated-sdk/jobs/client.d.ts +9 -2
- package/esm/generated-sdk/jobs/client.d.ts.map +1 -1
- package/esm/generated-sdk/jobs/contract.d.ts +1 -1
- package/esm/generated-sdk/jobs/contract.d.ts.map +1 -1
- package/esm/generated-sdk/jobs/contract.js +4 -2
- package/esm/generated-sdk/jobs/owned_api.d.ts +3 -0
- package/esm/generated-sdk/jobs/owned_api.d.ts.map +1 -0
- package/esm/generated-sdk/jobs/owned_api.js +118 -0
- package/esm/generated-sdk/jobs/schemas.d.ts +336 -123
- package/esm/generated-sdk/jobs/schemas.d.ts.map +1 -1
- package/esm/generated-sdk/jobs/schemas.js +17 -15
- package/esm/generated-sdk/jobs/types.d.ts +144 -34
- package/esm/generated-sdk/jobs/types.d.ts.map +1 -1
- package/esm/generated-sdk/jobs/types.js +36 -1
- package/esm/generated-sdk/state/api.d.ts +27 -9
- package/esm/generated-sdk/state/api.d.ts.map +1 -1
- package/esm/generated-sdk/state/api.js +16 -71
- package/esm/generated-sdk/state/client.d.ts +4 -2
- package/esm/generated-sdk/state/client.d.ts.map +1 -1
- package/esm/generated-sdk/state/contract.d.ts +1 -1
- package/esm/generated-sdk/state/contract.d.ts.map +1 -1
- package/esm/generated-sdk/state/contract.js +4 -2
- package/esm/generated-sdk/state/owned_api.d.ts +3 -0
- package/esm/generated-sdk/state/owned_api.d.ts.map +1 -0
- package/esm/generated-sdk/state/owned_api.js +66 -0
- package/esm/generated-sdk/state/schemas.d.ts +264 -284
- package/esm/generated-sdk/state/schemas.d.ts.map +1 -1
- package/esm/generated-sdk/state/schemas.js +6 -6
- package/esm/generated-sdk/state/types.d.ts +24 -23
- package/esm/generated-sdk/state/types.d.ts.map +1 -1
- package/esm/generated-sdk/state/types.js +1 -1
- package/esm/generated-sdk/trellis-core/api.d.ts +27 -9
- package/esm/generated-sdk/trellis-core/api.d.ts.map +1 -1
- package/esm/generated-sdk/trellis-core/api.js +16 -39
- package/esm/generated-sdk/trellis-core/client.d.ts +5 -2
- package/esm/generated-sdk/trellis-core/client.d.ts.map +1 -1
- package/esm/generated-sdk/trellis-core/contract.d.ts +1 -1
- package/esm/generated-sdk/trellis-core/contract.d.ts.map +1 -1
- package/esm/generated-sdk/trellis-core/contract.js +4 -2
- package/esm/generated-sdk/trellis-core/owned_api.d.ts +3 -0
- package/esm/generated-sdk/trellis-core/owned_api.d.ts.map +1 -0
- package/esm/generated-sdk/trellis-core/owned_api.js +42 -0
- package/esm/generated-sdk/trellis-core/schemas.d.ts +259 -11
- package/esm/generated-sdk/trellis-core/schemas.d.ts.map +1 -1
- package/esm/generated-sdk/trellis-core/schemas.js +5 -3
- package/esm/generated-sdk/trellis-core/types.d.ts +56 -1
- package/esm/generated-sdk/trellis-core/types.d.ts.map +1 -1
- package/esm/generated-sdk/trellis-core/types.js +1 -1
- package/esm/helpers.d.ts.map +1 -1
- package/esm/index.d.ts +4 -3
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +1 -0
- package/esm/jobs.d.ts +10 -1
- package/esm/jobs.d.ts.map +1 -1
- package/esm/jobs.js +16 -1
- package/esm/kv.d.ts.map +1 -1
- package/esm/kv.js +10 -4
- package/esm/models/auth/rpc/Logout.d.ts +4 -4
- package/esm/models/auth/rpc/Logout.d.ts.map +1 -1
- package/esm/models/auth/rpc/Logout.js +2 -2
- package/esm/models/trellis/Page.d.ts +2 -0
- package/esm/models/trellis/Page.d.ts.map +1 -0
- package/esm/models/trellis/Page.js +1 -0
- package/esm/models/trellis/State.d.ts +1 -0
- package/esm/models/trellis/State.d.ts.map +1 -1
- package/esm/models/trellis/State.js +1 -0
- package/esm/models/trellis/rpc/StateList.d.ts +9 -12
- package/esm/models/trellis/rpc/StateList.d.ts.map +1 -1
- package/esm/models/trellis/rpc/StateList.js +16 -18
- package/esm/npm/src/auth/browser/login.d.ts.map +1 -1
- package/esm/npm/src/auth/browser/login.js +46 -3
- package/esm/npm/src/auth/browser/portal.d.ts.map +1 -1
- package/esm/npm/src/auth/browser/portal.js +5 -1
- package/esm/npm/src/auth/browser/session.d.ts +18 -7
- package/esm/npm/src/auth/browser/session.d.ts.map +1 -1
- package/esm/npm/src/auth/browser/session.js +47 -11
- package/esm/npm/src/auth/browser/storage.d.ts +6 -1
- package/esm/npm/src/auth/browser/storage.d.ts.map +1 -1
- package/esm/npm/src/auth/browser/storage.js +15 -3
- package/esm/npm/src/auth/browser.d.ts +2 -2
- package/esm/npm/src/auth/browser.d.ts.map +1 -1
- package/esm/npm/src/auth/browser.js +1 -1
- package/esm/npm/src/auth/device_activation.d.ts +36 -33
- package/esm/npm/src/auth/device_activation.d.ts.map +1 -1
- package/esm/npm/src/auth/device_activation.js +26 -22
- package/esm/npm/src/auth/mod.d.ts +4 -4
- package/esm/npm/src/auth/mod.d.ts.map +1 -1
- package/esm/npm/src/auth/mod.js +2 -2
- package/esm/npm/src/auth/proof.d.ts +3 -1
- package/esm/npm/src/auth/proof.d.ts.map +1 -1
- package/esm/npm/src/auth/proof.js +21 -15
- package/esm/npm/src/auth/protocol.d.ts +2457 -941
- package/esm/npm/src/auth/protocol.d.ts.map +1 -1
- package/esm/npm/src/auth/protocol.js +747 -375
- package/esm/npm/src/auth/schemas.d.ts +25 -4
- package/esm/npm/src/auth/schemas.d.ts.map +1 -1
- package/esm/npm/src/auth/schemas.js +14 -4
- package/esm/npm/src/auth/session_auth.d.ts +1 -1
- package/esm/npm/src/auth/session_auth.d.ts.map +1 -1
- package/esm/npm/src/auth/session_auth.js +7 -1
- package/esm/npm/src/client_connect.d.ts +2 -0
- package/esm/npm/src/client_connect.d.ts.map +1 -1
- package/esm/npm/src/client_connect.js +76 -15
- package/esm/npm/src/contract.d.ts +3 -0
- package/esm/npm/src/contract.d.ts.map +1 -1
- package/esm/npm/src/contract_support/mod.d.ts +422 -43
- package/esm/npm/src/contract_support/mod.d.ts.map +1 -1
- package/esm/npm/src/contract_support/mod.js +734 -33
- package/esm/npm/src/contract_support/protocol.d.ts +20 -5
- package/esm/npm/src/contract_support/protocol.d.ts.map +1 -1
- package/esm/npm/src/contract_support/protocol.js +18 -10
- package/esm/npm/src/contract_support/runtime.d.ts +11 -0
- package/esm/npm/src/contract_support/runtime.d.ts.map +1 -1
- package/esm/npm/src/contract_support/schema_pointers.d.ts.map +1 -1
- package/esm/npm/src/contract_support/schema_pointers.js +32 -14
- package/esm/npm/src/device/deno.d.ts.map +1 -1
- package/esm/npm/src/device/deno.js +6 -0
- package/esm/npm/src/device.d.ts +2 -0
- package/esm/npm/src/device.d.ts.map +1 -1
- package/esm/npm/src/device.js +3 -0
- package/esm/npm/src/errors/AuthError.d.ts +2 -1
- package/esm/npm/src/errors/AuthError.d.ts.map +1 -1
- package/esm/npm/src/errors/AuthError.js +8 -3
- package/esm/npm/src/errors/index.d.ts +4 -4
- package/esm/npm/src/errors/index.d.ts.map +1 -1
- package/esm/npm/src/errors/index.js +1 -0
- package/esm/npm/src/generate.js +54 -24
- package/esm/npm/src/helpers.d.ts.map +1 -1
- package/esm/npm/src/index.d.ts +4 -3
- package/esm/npm/src/index.d.ts.map +1 -1
- package/esm/npm/src/index.js +1 -0
- package/esm/npm/src/jobs.d.ts +10 -1
- package/esm/npm/src/jobs.d.ts.map +1 -1
- package/esm/npm/src/jobs.js +16 -1
- package/esm/npm/src/kv.d.ts.map +1 -1
- package/esm/npm/src/kv.js +10 -4
- package/esm/npm/src/models/auth/rpc/Logout.d.ts +4 -4
- package/esm/npm/src/models/auth/rpc/Logout.d.ts.map +1 -1
- package/esm/npm/src/models/auth/rpc/Logout.js +2 -2
- package/esm/npm/src/models/trellis/Page.d.ts +2 -0
- package/esm/npm/src/models/trellis/Page.d.ts.map +1 -0
- package/esm/npm/src/models/trellis/Page.js +1 -0
- package/esm/npm/src/models/trellis/State.d.ts +1 -0
- package/esm/npm/src/models/trellis/State.d.ts.map +1 -1
- package/esm/npm/src/models/trellis/State.js +1 -0
- package/esm/npm/src/models/trellis/rpc/StateList.d.ts +9 -12
- package/esm/npm/src/models/trellis/rpc/StateList.d.ts.map +1 -1
- package/esm/npm/src/models/trellis/rpc/StateList.js +16 -18
- package/esm/npm/src/operations.d.ts +16 -7
- package/esm/npm/src/operations.d.ts.map +1 -1
- package/esm/npm/src/operations.js +84 -19
- package/esm/npm/src/runtime_transport.d.ts +2 -0
- package/esm/npm/src/runtime_transport.d.ts.map +1 -1
- package/esm/npm/src/runtime_transport.js +1 -0
- package/esm/npm/src/server/internal_jobs/active-job.d.ts +2 -1
- package/esm/npm/src/server/internal_jobs/active-job.d.ts.map +1 -1
- package/esm/npm/src/server/internal_jobs/active-job.js +3 -0
- package/esm/npm/src/server/internal_jobs/job-manager.d.ts +4 -1
- package/esm/npm/src/server/internal_jobs/job-manager.d.ts.map +1 -1
- package/esm/npm/src/server/internal_jobs/job-manager.js +61 -1
- package/esm/npm/src/server/internal_jobs/projection.js +1 -0
- package/esm/npm/src/server/internal_jobs/runtime-worker.d.ts +13 -1
- package/esm/npm/src/server/internal_jobs/runtime-worker.d.ts.map +1 -1
- package/esm/npm/src/server/internal_jobs/runtime-worker.js +73 -13
- package/esm/npm/src/server/internal_jobs/types.d.ts +19 -0
- package/esm/npm/src/server/internal_jobs/types.d.ts.map +1 -1
- package/esm/npm/src/server/internal_jobs/types.js +10 -0
- package/esm/npm/src/server/runtime.d.ts +1 -0
- package/esm/npm/src/server/runtime.d.ts.map +1 -1
- package/esm/npm/src/server/service.d.ts +10 -1
- package/esm/npm/src/server/service.d.ts.map +1 -1
- package/esm/npm/src/server/service.js +210 -64
- package/esm/npm/src/server/transfer.d.ts.map +1 -1
- package/esm/npm/src/server/transfer.js +4 -0
- package/esm/npm/src/server.d.ts.map +1 -1
- package/esm/npm/src/server.js +337 -34
- package/esm/npm/src/store.d.ts +8 -1
- package/esm/npm/src/store.d.ts.map +1 -1
- package/esm/npm/src/store.js +46 -8
- package/esm/npm/src/transfer.d.ts +3 -0
- package/esm/npm/src/transfer.d.ts.map +1 -1
- package/esm/npm/src/transfer.js +20 -30
- package/esm/npm/src/trellis.d.ts +85 -22
- package/esm/npm/src/trellis.d.ts.map +1 -1
- package/esm/npm/src/trellis.js +525 -61
- package/esm/operations.d.ts +16 -7
- package/esm/operations.d.ts.map +1 -1
- package/esm/operations.js +84 -19
- package/esm/runtime_transport.d.ts +2 -0
- package/esm/runtime_transport.d.ts.map +1 -1
- package/esm/runtime_transport.js +1 -0
- package/esm/store.d.ts +8 -1
- package/esm/store.d.ts.map +1 -1
- package/esm/store.js +46 -8
- package/esm/transfer.d.ts +3 -0
- package/esm/transfer.d.ts.map +1 -1
- package/esm/transfer.js +20 -30
- package/esm/trellis.d.ts +85 -22
- package/esm/trellis.d.ts.map +1 -1
- package/esm/trellis.js +525 -61
- package/package.json +6 -4
- package/script/auth/browser/login.d.ts.map +1 -1
- package/script/auth/browser/login.js +46 -3
- package/script/auth/browser/portal.d.ts.map +1 -1
- package/script/auth/browser/portal.js +5 -1
- package/script/auth/browser/session.d.ts +18 -7
- package/script/auth/browser/session.d.ts.map +1 -1
- package/script/auth/browser/session.js +47 -11
- package/script/auth/browser/storage.d.ts +6 -1
- package/script/auth/browser/storage.d.ts.map +1 -1
- package/script/auth/browser/storage.js +15 -3
- package/script/auth/browser.d.ts +2 -2
- package/script/auth/browser.d.ts.map +1 -1
- package/script/auth/browser.js +2 -1
- package/script/auth/device_activation.d.ts +36 -33
- package/script/auth/device_activation.d.ts.map +1 -1
- package/script/auth/device_activation.js +25 -21
- package/script/auth/mod.d.ts +4 -4
- package/script/auth/mod.d.ts.map +1 -1
- package/script/auth/mod.js +132 -137
- package/script/auth/proof.d.ts +3 -1
- package/script/auth/proof.d.ts.map +1 -1
- package/script/auth/proof.js +21 -15
- package/script/auth/protocol.d.ts +2457 -941
- package/script/auth/protocol.d.ts.map +1 -1
- package/script/auth/protocol.js +749 -377
- package/script/auth/schemas.d.ts +25 -4
- package/script/auth/schemas.d.ts.map +1 -1
- package/script/auth/schemas.js +16 -5
- package/script/auth/session_auth.d.ts +1 -1
- package/script/auth/session_auth.d.ts.map +1 -1
- package/script/auth/session_auth.js +7 -1
- package/script/client_connect.d.ts +2 -0
- package/script/client_connect.d.ts.map +1 -1
- package/script/client_connect.js +76 -15
- package/script/contract.d.ts +3 -0
- package/script/contract.d.ts.map +1 -1
- package/script/contract_support/mod.d.ts +422 -43
- package/script/contract_support/mod.d.ts.map +1 -1
- package/script/contract_support/mod.js +757 -51
- package/script/contract_support/protocol.d.ts +20 -5
- package/script/contract_support/protocol.d.ts.map +1 -1
- package/script/contract_support/protocol.js +20 -11
- package/script/contract_support/runtime.d.ts +11 -0
- package/script/contract_support/runtime.d.ts.map +1 -1
- package/script/contract_support/schema_pointers.d.ts.map +1 -1
- package/script/contract_support/schema_pointers.js +32 -14
- package/script/device.d.ts +2 -0
- package/script/device.d.ts.map +1 -1
- package/script/device.js +3 -0
- package/script/errors/AuthError.d.ts +2 -1
- package/script/errors/AuthError.d.ts.map +1 -1
- package/script/errors/AuthError.js +8 -3
- package/script/errors/index.d.ts +4 -4
- package/script/errors/index.d.ts.map +1 -1
- package/script/errors/index.js +1 -0
- package/script/generated-sdk/auth/api.d.ts +27 -9
- package/script/generated-sdk/auth/api.d.ts.map +1 -1
- package/script/generated-sdk/auth/api.js +17 -591
- package/script/generated-sdk/auth/client.d.ts +91 -85
- package/script/generated-sdk/auth/client.d.ts.map +1 -1
- package/script/generated-sdk/auth/contract.d.ts +1 -1
- package/script/generated-sdk/auth/contract.d.ts.map +1 -1
- package/script/generated-sdk/auth/contract.js +4 -2
- package/script/generated-sdk/auth/mod.d.ts +1 -0
- package/script/generated-sdk/auth/mod.d.ts.map +1 -1
- package/script/generated-sdk/auth/owned_api.d.ts +3 -0
- package/script/generated-sdk/auth/owned_api.d.ts.map +1 -0
- package/script/generated-sdk/auth/owned_api.js +597 -0
- package/script/generated-sdk/auth/schemas.d.ts +9959 -5160
- package/script/generated-sdk/auth/schemas.d.ts.map +1 -1
- package/script/generated-sdk/auth/schemas.js +139 -140
- package/script/generated-sdk/auth/types.d.ts +2418 -1557
- 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 +24 -9
- package/script/generated-sdk/health/api.d.ts.map +1 -1
- package/script/generated-sdk/health/api.js +13 -21
- package/script/generated-sdk/health/client.d.ts +2 -1
- package/script/generated-sdk/health/client.d.ts.map +1 -1
- package/script/generated-sdk/health/contract.d.ts.map +1 -1
- package/script/generated-sdk/health/contract.js +2 -0
- package/script/generated-sdk/health/owned_api.d.ts +3 -0
- package/script/generated-sdk/health/owned_api.d.ts.map +1 -0
- package/script/generated-sdk/health/owned_api.js +19 -0
- package/script/generated-sdk/health/types.d.ts +2 -0
- package/script/generated-sdk/health/types.d.ts.map +1 -1
- package/script/generated-sdk/jobs/api.d.ts +33 -9
- package/script/generated-sdk/jobs/api.d.ts.map +1 -1
- package/script/generated-sdk/jobs/api.js +23 -88
- package/script/generated-sdk/jobs/client.d.ts +9 -2
- package/script/generated-sdk/jobs/client.d.ts.map +1 -1
- package/script/generated-sdk/jobs/contract.d.ts +1 -1
- package/script/generated-sdk/jobs/contract.d.ts.map +1 -1
- package/script/generated-sdk/jobs/contract.js +4 -2
- package/script/generated-sdk/jobs/owned_api.d.ts +3 -0
- package/script/generated-sdk/jobs/owned_api.d.ts.map +1 -0
- package/script/generated-sdk/jobs/owned_api.js +154 -0
- package/script/generated-sdk/jobs/schemas.d.ts +336 -123
- package/script/generated-sdk/jobs/schemas.d.ts.map +1 -1
- package/script/generated-sdk/jobs/schemas.js +18 -16
- package/script/generated-sdk/jobs/types.d.ts +144 -34
- package/script/generated-sdk/jobs/types.d.ts.map +1 -1
- package/script/generated-sdk/jobs/types.js +38 -2
- package/script/generated-sdk/state/api.d.ts +27 -9
- package/script/generated-sdk/state/api.d.ts.map +1 -1
- package/script/generated-sdk/state/api.js +17 -72
- package/script/generated-sdk/state/client.d.ts +4 -2
- package/script/generated-sdk/state/client.d.ts.map +1 -1
- package/script/generated-sdk/state/contract.d.ts +1 -1
- package/script/generated-sdk/state/contract.d.ts.map +1 -1
- package/script/generated-sdk/state/contract.js +4 -2
- package/script/generated-sdk/state/owned_api.d.ts +3 -0
- package/script/generated-sdk/state/owned_api.d.ts.map +1 -0
- package/script/generated-sdk/state/owned_api.js +69 -0
- package/script/generated-sdk/state/schemas.d.ts +264 -284
- package/script/generated-sdk/state/schemas.d.ts.map +1 -1
- package/script/generated-sdk/state/schemas.js +6 -6
- package/script/generated-sdk/state/types.d.ts +24 -23
- package/script/generated-sdk/state/types.d.ts.map +1 -1
- package/script/generated-sdk/state/types.js +1 -1
- package/script/generated-sdk/trellis-core/api.d.ts +27 -9
- package/script/generated-sdk/trellis-core/api.d.ts.map +1 -1
- package/script/generated-sdk/trellis-core/api.js +17 -40
- package/script/generated-sdk/trellis-core/client.d.ts +5 -2
- package/script/generated-sdk/trellis-core/client.d.ts.map +1 -1
- package/script/generated-sdk/trellis-core/contract.d.ts +1 -1
- package/script/generated-sdk/trellis-core/contract.d.ts.map +1 -1
- package/script/generated-sdk/trellis-core/contract.js +4 -2
- package/script/generated-sdk/trellis-core/owned_api.d.ts +3 -0
- package/script/generated-sdk/trellis-core/owned_api.d.ts.map +1 -0
- package/script/generated-sdk/trellis-core/owned_api.js +45 -0
- package/script/generated-sdk/trellis-core/schemas.d.ts +259 -11
- package/script/generated-sdk/trellis-core/schemas.d.ts.map +1 -1
- package/script/generated-sdk/trellis-core/schemas.js +6 -4
- package/script/generated-sdk/trellis-core/types.d.ts +56 -1
- package/script/generated-sdk/trellis-core/types.d.ts.map +1 -1
- package/script/generated-sdk/trellis-core/types.js +1 -1
- package/script/helpers.d.ts.map +1 -1
- package/script/index.d.ts +4 -3
- package/script/index.d.ts.map +1 -1
- package/script/index.js +5 -2
- package/script/jobs.d.ts +10 -1
- package/script/jobs.d.ts.map +1 -1
- package/script/jobs.js +17 -2
- package/script/kv.d.ts.map +1 -1
- package/script/kv.js +10 -4
- package/script/models/auth/rpc/Logout.d.ts +4 -4
- package/script/models/auth/rpc/Logout.d.ts.map +1 -1
- package/script/models/auth/rpc/Logout.js +3 -3
- package/script/models/trellis/Page.d.ts +2 -0
- package/script/models/trellis/Page.d.ts.map +1 -0
- package/script/models/trellis/Page.js +6 -0
- package/script/models/trellis/State.d.ts +1 -0
- package/script/models/trellis/State.d.ts.map +1 -1
- package/script/models/trellis/State.js +1 -0
- package/script/models/trellis/rpc/StateList.d.ts +9 -12
- package/script/models/trellis/rpc/StateList.d.ts.map +1 -1
- package/script/models/trellis/rpc/StateList.js +16 -18
- package/script/npm/src/auth/browser/login.d.ts.map +1 -1
- package/script/npm/src/auth/browser/login.js +46 -3
- package/script/npm/src/auth/browser/portal.d.ts.map +1 -1
- package/script/npm/src/auth/browser/portal.js +5 -1
- package/script/npm/src/auth/browser/session.d.ts +18 -7
- package/script/npm/src/auth/browser/session.d.ts.map +1 -1
- package/script/npm/src/auth/browser/session.js +47 -11
- package/script/npm/src/auth/browser/storage.d.ts +6 -1
- package/script/npm/src/auth/browser/storage.d.ts.map +1 -1
- package/script/npm/src/auth/browser/storage.js +15 -3
- package/script/npm/src/auth/browser.d.ts +2 -2
- package/script/npm/src/auth/browser.d.ts.map +1 -1
- package/script/npm/src/auth/browser.js +2 -1
- package/script/npm/src/auth/device_activation.d.ts +36 -33
- package/script/npm/src/auth/device_activation.d.ts.map +1 -1
- package/script/npm/src/auth/device_activation.js +25 -21
- package/script/npm/src/auth/mod.d.ts +4 -4
- package/script/npm/src/auth/mod.d.ts.map +1 -1
- package/script/npm/src/auth/mod.js +132 -137
- package/script/npm/src/auth/proof.d.ts +3 -1
- package/script/npm/src/auth/proof.d.ts.map +1 -1
- package/script/npm/src/auth/proof.js +21 -15
- package/script/npm/src/auth/protocol.d.ts +2457 -941
- package/script/npm/src/auth/protocol.d.ts.map +1 -1
- package/script/npm/src/auth/protocol.js +749 -377
- package/script/npm/src/auth/schemas.d.ts +25 -4
- package/script/npm/src/auth/schemas.d.ts.map +1 -1
- package/script/npm/src/auth/schemas.js +16 -5
- package/script/npm/src/auth/session_auth.d.ts +1 -1
- package/script/npm/src/auth/session_auth.d.ts.map +1 -1
- package/script/npm/src/auth/session_auth.js +7 -1
- package/script/npm/src/client_connect.d.ts +2 -0
- package/script/npm/src/client_connect.d.ts.map +1 -1
- package/script/npm/src/client_connect.js +76 -15
- package/script/npm/src/contract.d.ts +3 -0
- package/script/npm/src/contract.d.ts.map +1 -1
- package/script/npm/src/contract_support/mod.d.ts +422 -43
- package/script/npm/src/contract_support/mod.d.ts.map +1 -1
- package/script/npm/src/contract_support/mod.js +757 -51
- package/script/npm/src/contract_support/protocol.d.ts +20 -5
- package/script/npm/src/contract_support/protocol.d.ts.map +1 -1
- package/script/npm/src/contract_support/protocol.js +20 -11
- package/script/npm/src/contract_support/runtime.d.ts +11 -0
- package/script/npm/src/contract_support/runtime.d.ts.map +1 -1
- package/script/npm/src/contract_support/schema_pointers.d.ts.map +1 -1
- package/script/npm/src/contract_support/schema_pointers.js +32 -14
- package/script/npm/src/device/deno.d.ts.map +1 -1
- package/script/npm/src/device/deno.js +6 -0
- package/script/npm/src/device.d.ts +2 -0
- package/script/npm/src/device.d.ts.map +1 -1
- package/script/npm/src/device.js +3 -0
- package/script/npm/src/errors/AuthError.d.ts +2 -1
- package/script/npm/src/errors/AuthError.d.ts.map +1 -1
- package/script/npm/src/errors/AuthError.js +8 -3
- package/script/npm/src/errors/index.d.ts +4 -4
- package/script/npm/src/errors/index.d.ts.map +1 -1
- package/script/npm/src/errors/index.js +1 -0
- package/script/npm/src/generate.js +54 -57
- package/script/npm/src/helpers.d.ts.map +1 -1
- package/script/npm/src/index.d.ts +4 -3
- package/script/npm/src/index.d.ts.map +1 -1
- package/script/npm/src/index.js +5 -2
- package/script/npm/src/jobs.d.ts +10 -1
- package/script/npm/src/jobs.d.ts.map +1 -1
- package/script/npm/src/jobs.js +17 -2
- package/script/npm/src/kv.d.ts.map +1 -1
- package/script/npm/src/kv.js +10 -4
- package/script/npm/src/models/auth/rpc/Logout.d.ts +4 -4
- package/script/npm/src/models/auth/rpc/Logout.d.ts.map +1 -1
- package/script/npm/src/models/auth/rpc/Logout.js +3 -3
- package/script/npm/src/models/trellis/Page.d.ts +2 -0
- package/script/npm/src/models/trellis/Page.d.ts.map +1 -0
- package/script/npm/src/models/trellis/Page.js +6 -0
- package/script/npm/src/models/trellis/State.d.ts +1 -0
- package/script/npm/src/models/trellis/State.d.ts.map +1 -1
- package/script/npm/src/models/trellis/State.js +1 -0
- package/script/npm/src/models/trellis/rpc/StateList.d.ts +9 -12
- package/script/npm/src/models/trellis/rpc/StateList.d.ts.map +1 -1
- package/script/npm/src/models/trellis/rpc/StateList.js +16 -18
- package/script/npm/src/operations.d.ts +16 -7
- package/script/npm/src/operations.d.ts.map +1 -1
- package/script/npm/src/operations.js +84 -19
- package/script/npm/src/runtime_transport.d.ts +2 -0
- package/script/npm/src/runtime_transport.d.ts.map +1 -1
- package/script/npm/src/runtime_transport.js +2 -1
- package/script/npm/src/server/internal_jobs/active-job.d.ts +2 -1
- package/script/npm/src/server/internal_jobs/active-job.d.ts.map +1 -1
- package/script/npm/src/server/internal_jobs/active-job.js +3 -0
- package/script/npm/src/server/internal_jobs/job-manager.d.ts +4 -1
- package/script/npm/src/server/internal_jobs/job-manager.d.ts.map +1 -1
- package/script/npm/src/server/internal_jobs/job-manager.js +61 -1
- package/script/npm/src/server/internal_jobs/projection.js +1 -0
- package/script/npm/src/server/internal_jobs/runtime-worker.d.ts +13 -1
- package/script/npm/src/server/internal_jobs/runtime-worker.d.ts.map +1 -1
- package/script/npm/src/server/internal_jobs/runtime-worker.js +74 -13
- package/script/npm/src/server/internal_jobs/types.d.ts +19 -0
- package/script/npm/src/server/internal_jobs/types.d.ts.map +1 -1
- package/script/npm/src/server/internal_jobs/types.js +11 -1
- package/script/npm/src/server/runtime.d.ts +1 -0
- package/script/npm/src/server/runtime.d.ts.map +1 -1
- package/script/npm/src/server/service.d.ts +10 -1
- package/script/npm/src/server/service.d.ts.map +1 -1
- package/script/npm/src/server/service.js +208 -62
- package/script/npm/src/server/transfer.d.ts.map +1 -1
- package/script/npm/src/server/transfer.js +4 -0
- package/script/npm/src/server.d.ts.map +1 -1
- package/script/npm/src/server.js +336 -33
- package/script/npm/src/store.d.ts +8 -1
- package/script/npm/src/store.d.ts.map +1 -1
- package/script/npm/src/store.js +46 -8
- package/script/npm/src/transfer.d.ts +3 -0
- package/script/npm/src/transfer.d.ts.map +1 -1
- package/script/npm/src/transfer.js +19 -29
- package/script/npm/src/trellis.d.ts +85 -22
- package/script/npm/src/trellis.d.ts.map +1 -1
- package/script/npm/src/trellis.js +525 -61
- package/script/operations.d.ts +16 -7
- package/script/operations.d.ts.map +1 -1
- package/script/operations.js +84 -19
- package/script/runtime_transport.d.ts +2 -0
- package/script/runtime_transport.d.ts.map +1 -1
- package/script/runtime_transport.js +2 -1
- package/script/store.d.ts +8 -1
- package/script/store.d.ts.map +1 -1
- package/script/store.js +46 -8
- package/script/transfer.d.ts +3 -0
- package/script/transfer.d.ts.map +1 -1
- package/script/transfer.js +19 -29
- package/script/trellis.d.ts +85 -22
- package/script/trellis.d.ts.map +1 -1
- package/script/trellis.js +525 -61
- package/src/_dnt.polyfills.ts +274 -0
- package/src/_dnt.shims.ts +64 -0
- package/src/auth/browser/login.ts +295 -0
- package/src/auth/browser/portal.ts +75 -0
- package/src/auth/browser/session.ts +197 -0
- package/src/auth/browser/storage.ts +105 -0
- package/src/auth/browser.ts +82 -0
- package/src/auth/device_activation.ts +715 -0
- package/src/auth/keys.ts +116 -0
- package/src/auth/mod.ts +298 -0
- package/src/auth/proof.ts +111 -0
- package/src/auth/protocol.ts +1629 -0
- package/src/auth/schemas.ts +145 -0
- package/src/auth/session_auth.ts +167 -0
- package/src/auth/time.ts +15 -0
- package/src/auth/trellis_id.ts +9 -0
- package/src/auth/types.ts +4 -0
- package/src/auth/utils.ts +87 -0
- package/src/auth.ts +2 -0
- package/src/browser.ts +8 -0
- package/src/client.ts +164 -0
- package/src/client_connect.ts +1328 -0
- package/src/codec.ts +107 -0
- package/src/connection.ts +466 -0
- package/src/contract.ts +84 -0
- package/src/contract_support/canonical.ts +217 -0
- package/src/contract_support/mod.ts +5079 -0
- package/src/contract_support/protocol.ts +213 -0
- package/src/contract_support/runtime.ts +129 -0
- package/src/contract_support/schema_pointers.ts +161 -0
- package/src/contracts.ts +9 -0
- package/src/device/deno.ts +941 -0
- package/src/device.ts +989 -0
- package/src/env.ts +1 -0
- package/src/errors/AuthError.ts +82 -0
- package/src/errors/KVError.ts +47 -0
- package/src/errors/RemoteError.ts +111 -0
- package/src/errors/StoreError.ts +43 -0
- package/src/errors/TransferError.ts +43 -0
- package/src/errors/TransportError.ts +48 -0
- package/src/errors/TrellisError.ts +20 -0
- package/src/errors/ValidationError.ts +80 -0
- package/src/errors/index.ts +195 -0
- package/src/generate.ts +329 -0
- package/src/globals.ts +26 -0
- package/src/health.ts +28 -0
- package/src/helpers.ts +63 -0
- package/src/host/mod.ts +9 -0
- package/src/host/node.ts +9 -0
- package/src/index.ts +233 -0
- package/src/jobs.ts +344 -0
- package/src/kv.ts +564 -0
- package/src/models/auth/rpc/Logout.ts +15 -0
- package/src/models/trellis/Page.ts +6 -0
- package/src/models/trellis/State.ts +55 -0
- package/src/models/trellis/TrellisError.ts +21 -0
- package/src/models/trellis/rpc/StateDelete.ts +13 -0
- package/src/models/trellis/rpc/StateGet.ts +25 -0
- package/src/models/trellis/rpc/StateList.ts +26 -0
- package/src/models/trellis/rpc/StatePut.ts +42 -0
- package/src/operations.ts +1508 -0
- package/src/runtime_transport.ts +132 -0
- package/src/sdk/auth.ts +2 -0
- package/src/sdk/core.ts +2 -0
- package/src/sdk/health.ts +2 -0
- package/src/sdk/jobs.ts +2 -0
- package/src/sdk/state.ts +2 -0
- package/src/server/health.ts +379 -0
- package/src/server/health_rpc.ts +51 -0
- package/src/server/health_schemas.ts +61 -0
- package/src/server/internal_jobs/active-job.ts +115 -0
- package/src/server/internal_jobs/bindings.ts +26 -0
- package/src/server/internal_jobs/cancellation-registry.ts +71 -0
- package/src/server/internal_jobs/heartbeat.ts +120 -0
- package/src/server/internal_jobs/job-manager.ts +456 -0
- package/src/server/internal_jobs/projection.ts +48 -0
- package/src/server/internal_jobs/runtime-worker.ts +741 -0
- package/src/server/internal_jobs/types.ts +124 -0
- package/src/server/runtime.ts +27 -0
- package/src/server/service.ts +2377 -0
- package/src/server/subscription.ts +143 -0
- package/src/server/transfer.ts +962 -0
- package/src/server.ts +1725 -0
- package/src/server_logger.ts +10 -0
- package/src/service/deno.ts +18 -0
- package/src/service/mod.ts +68 -0
- package/src/service/node.ts +18 -0
- package/src/store.ts +658 -0
- package/src/tasks.ts +34 -0
- package/src/telemetry/carrier.ts +35 -0
- package/src/telemetry/core.ts +31 -0
- package/src/telemetry/env.ts +23 -0
- package/src/telemetry/mod.ts +26 -0
- package/src/telemetry/nats.ts +15 -0
- package/src/telemetry/result.ts +20 -0
- package/src/telemetry/trace.ts +39 -0
- package/src/telemetry/trellis.ts +1 -0
- package/src/tracing.ts +28 -0
- package/src/transfer.ts +602 -0
- package/src/trellis.ts +3650 -0
- package/esm/models/trellis/Paginate.d.ts +0 -7
- package/esm/models/trellis/Paginate.d.ts.map +0 -1
- package/esm/models/trellis/Paginate.js +0 -5
- package/esm/npm/src/models/trellis/Paginate.d.ts +0 -7
- package/esm/npm/src/models/trellis/Paginate.d.ts.map +0 -1
- package/esm/npm/src/models/trellis/Paginate.js +0 -5
- package/script/models/trellis/Paginate.d.ts +0 -7
- package/script/models/trellis/Paginate.d.ts.map +0 -1
- package/script/models/trellis/Paginate.js +0 -11
- package/script/npm/src/models/trellis/Paginate.d.ts +0 -7
- package/script/npm/src/models/trellis/Paginate.d.ts.map +0 -1
- package/script/npm/src/models/trellis/Paginate.js +0 -11
|
@@ -0,0 +1,1508 @@
|
|
|
1
|
+
import type { InferSchemaType } from "./contracts.js";
|
|
2
|
+
import { AsyncResult, err, isErr, ok, type Result } from "@qlever-llc/result";
|
|
3
|
+
|
|
4
|
+
import type { JsonValue } from "./codec.js";
|
|
5
|
+
import {
|
|
6
|
+
TransferError,
|
|
7
|
+
TransportError,
|
|
8
|
+
UnexpectedError,
|
|
9
|
+
} from "./errors/index.js";
|
|
10
|
+
import type { FileInfo, SendTransferGrant, TransferBody } from "./transfer.js";
|
|
11
|
+
|
|
12
|
+
export type OperationState =
|
|
13
|
+
| "pending"
|
|
14
|
+
| "running"
|
|
15
|
+
| "completed"
|
|
16
|
+
| "failed"
|
|
17
|
+
| "cancelled";
|
|
18
|
+
|
|
19
|
+
export type OperationRefData = {
|
|
20
|
+
id: string;
|
|
21
|
+
service: string;
|
|
22
|
+
operation: string;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type OperationSnapshot<TProgress = unknown, TOutput = unknown> = {
|
|
26
|
+
id: string;
|
|
27
|
+
service: string;
|
|
28
|
+
operation: string;
|
|
29
|
+
revision: number;
|
|
30
|
+
state: OperationState;
|
|
31
|
+
createdAt: string;
|
|
32
|
+
updatedAt: string;
|
|
33
|
+
completedAt?: string;
|
|
34
|
+
progress?: TProgress;
|
|
35
|
+
transfer?: OperationTransferProgress;
|
|
36
|
+
output?: TOutput;
|
|
37
|
+
error?: {
|
|
38
|
+
type: string;
|
|
39
|
+
message: string;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type OperationTransferProgress = {
|
|
44
|
+
chunkIndex: number;
|
|
45
|
+
chunkBytes: number;
|
|
46
|
+
transferredBytes: number;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export type TerminalOperation<TProgress = unknown, TOutput = unknown> =
|
|
50
|
+
| (OperationSnapshot<TProgress, TOutput> & { state: "completed" })
|
|
51
|
+
| (OperationSnapshot<TProgress, TOutput> & { state: "failed" })
|
|
52
|
+
| (OperationSnapshot<TProgress, TOutput> & { state: "cancelled" });
|
|
53
|
+
|
|
54
|
+
export type OperationSignalAck<TProgress = unknown, TOutput = unknown> = {
|
|
55
|
+
kind: "signal-accepted";
|
|
56
|
+
operationId: string;
|
|
57
|
+
signal: string;
|
|
58
|
+
signalSequence: number;
|
|
59
|
+
acceptedAt: string;
|
|
60
|
+
snapshot: OperationSnapshot<TProgress, TOutput>;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export type CompletedTransfer<
|
|
64
|
+
TDesc extends OperationShape,
|
|
65
|
+
TProgress = OperationProgressOf<TDesc>,
|
|
66
|
+
TOutput = OperationOutputOf<TDesc>,
|
|
67
|
+
> = {
|
|
68
|
+
transferred: FileInfo;
|
|
69
|
+
terminal: TerminalOperation<TProgress, TOutput>;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export type StartedTransfer<
|
|
73
|
+
TDesc extends OperationShape,
|
|
74
|
+
TProgress = OperationProgressOf<TDesc>,
|
|
75
|
+
TOutput = OperationOutputOf<TDesc>,
|
|
76
|
+
> = {
|
|
77
|
+
operation: OperationRef<
|
|
78
|
+
TDesc,
|
|
79
|
+
TProgress,
|
|
80
|
+
TOutput
|
|
81
|
+
>;
|
|
82
|
+
wait(): AsyncResult<
|
|
83
|
+
CompletedTransfer<TDesc, TProgress, TOutput>,
|
|
84
|
+
TransportError | UnexpectedError | TransferError
|
|
85
|
+
>;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export type OperationRef<
|
|
89
|
+
TDesc extends OperationShape,
|
|
90
|
+
TProgress = OperationProgressOf<TDesc>,
|
|
91
|
+
TOutput = OperationOutputOf<TDesc>,
|
|
92
|
+
> = {
|
|
93
|
+
id: string;
|
|
94
|
+
service: string;
|
|
95
|
+
operation: string;
|
|
96
|
+
get(): AsyncResult<
|
|
97
|
+
OperationSnapshot<TProgress, TOutput>,
|
|
98
|
+
TransportError | UnexpectedError
|
|
99
|
+
>;
|
|
100
|
+
wait(): AsyncResult<
|
|
101
|
+
TerminalOperation<TProgress, TOutput>,
|
|
102
|
+
TransportError | UnexpectedError
|
|
103
|
+
>;
|
|
104
|
+
watch(): AsyncResult<
|
|
105
|
+
AsyncIterable<OperationEvent<TProgress, TOutput>>,
|
|
106
|
+
TransportError | UnexpectedError
|
|
107
|
+
>;
|
|
108
|
+
cancel(): AsyncResult<
|
|
109
|
+
OperationSnapshot<TProgress, TOutput>,
|
|
110
|
+
TransportError | UnexpectedError
|
|
111
|
+
>;
|
|
112
|
+
signal(
|
|
113
|
+
signal: string,
|
|
114
|
+
input?: unknown,
|
|
115
|
+
): AsyncResult<
|
|
116
|
+
OperationSignalAck<TProgress, TOutput>,
|
|
117
|
+
TransportError | UnexpectedError
|
|
118
|
+
>;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export type AcceptedOperationEvent<TProgress = unknown, TOutput = unknown> = {
|
|
122
|
+
type: "accepted";
|
|
123
|
+
snapshot: OperationSnapshot<TProgress, TOutput>;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export type StartedOperationEvent<TProgress = unknown, TOutput = unknown> = {
|
|
127
|
+
type: "started";
|
|
128
|
+
snapshot: OperationSnapshot<TProgress, TOutput>;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export type TransferOperationSnapshot<TProgress = unknown, TOutput = unknown> =
|
|
132
|
+
& OperationSnapshot<TProgress, TOutput>
|
|
133
|
+
& { transfer: OperationTransferProgress };
|
|
134
|
+
|
|
135
|
+
export type TransferOperationEvent<TProgress = unknown, TOutput = unknown> = {
|
|
136
|
+
type: "transfer";
|
|
137
|
+
snapshot: TransferOperationSnapshot<TProgress, TOutput>;
|
|
138
|
+
transfer: OperationTransferProgress;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export type ProgressOperationSnapshot<TProgress = unknown, TOutput = unknown> =
|
|
142
|
+
& OperationSnapshot<TProgress, TOutput>
|
|
143
|
+
& { progress: TProgress };
|
|
144
|
+
|
|
145
|
+
export type ProgressOperationEvent<TProgress = unknown, TOutput = unknown> = {
|
|
146
|
+
type: "progress";
|
|
147
|
+
snapshot: ProgressOperationSnapshot<TProgress, TOutput>;
|
|
148
|
+
progress: TProgress;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
export type CompletedOperationEvent<TProgress = unknown, TOutput = unknown> = {
|
|
152
|
+
type: "completed";
|
|
153
|
+
snapshot: TerminalOperation<TProgress, TOutput>;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
export type FailedOperationEvent<TProgress = unknown, TOutput = unknown> = {
|
|
157
|
+
type: "failed";
|
|
158
|
+
snapshot: TerminalOperation<TProgress, TOutput>;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
export type CancelledOperationEvent<TProgress = unknown, TOutput = unknown> = {
|
|
162
|
+
type: "cancelled";
|
|
163
|
+
snapshot: TerminalOperation<TProgress, TOutput>;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
export type OperationEvent<TProgress = unknown, TOutput = unknown> =
|
|
167
|
+
| AcceptedOperationEvent<TProgress, TOutput>
|
|
168
|
+
| StartedOperationEvent<TProgress, TOutput>
|
|
169
|
+
| TransferOperationEvent<TProgress, TOutput>
|
|
170
|
+
| ProgressOperationEvent<TProgress, TOutput>
|
|
171
|
+
| CompletedOperationEvent<TProgress, TOutput>
|
|
172
|
+
| FailedOperationEvent<TProgress, TOutput>
|
|
173
|
+
| CancelledOperationEvent<TProgress, TOutput>;
|
|
174
|
+
|
|
175
|
+
export type OperationObserverCallbacks<TProgress = unknown, TOutput = unknown> =
|
|
176
|
+
{
|
|
177
|
+
onAccepted?: (
|
|
178
|
+
event: AcceptedOperationEvent<TProgress, TOutput>,
|
|
179
|
+
) => void | Promise<void>;
|
|
180
|
+
onStarted?: (
|
|
181
|
+
event: StartedOperationEvent<TProgress, TOutput>,
|
|
182
|
+
) => void | Promise<void>;
|
|
183
|
+
onTransfer?: (
|
|
184
|
+
event: TransferOperationEvent<TProgress, TOutput>,
|
|
185
|
+
) => void | Promise<void>;
|
|
186
|
+
onProgress?: (
|
|
187
|
+
event: ProgressOperationEvent<TProgress, TOutput>,
|
|
188
|
+
) => void | Promise<void>;
|
|
189
|
+
onCompleted?: (
|
|
190
|
+
event: CompletedOperationEvent<TProgress, TOutput>,
|
|
191
|
+
) => void | Promise<void>;
|
|
192
|
+
onFailed?: (
|
|
193
|
+
event: FailedOperationEvent<TProgress, TOutput>,
|
|
194
|
+
) => void | Promise<void>;
|
|
195
|
+
onCancelled?: (
|
|
196
|
+
event: CancelledOperationEvent<TProgress, TOutput>,
|
|
197
|
+
) => void | Promise<void>;
|
|
198
|
+
onEvent?: (
|
|
199
|
+
event: OperationEvent<TProgress, TOutput>,
|
|
200
|
+
) => void | Promise<void>;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
interface OperationObserverBuilderBase<
|
|
204
|
+
TBuilder,
|
|
205
|
+
TProgress = unknown,
|
|
206
|
+
TOutput = unknown,
|
|
207
|
+
> {
|
|
208
|
+
onAccepted(
|
|
209
|
+
handler: NonNullable<
|
|
210
|
+
OperationObserverCallbacks<TProgress, TOutput>["onAccepted"]
|
|
211
|
+
>,
|
|
212
|
+
): TBuilder;
|
|
213
|
+
onStarted(
|
|
214
|
+
handler: NonNullable<
|
|
215
|
+
OperationObserverCallbacks<TProgress, TOutput>["onStarted"]
|
|
216
|
+
>,
|
|
217
|
+
): TBuilder;
|
|
218
|
+
onProgress(
|
|
219
|
+
handler: NonNullable<
|
|
220
|
+
OperationObserverCallbacks<TProgress, TOutput>["onProgress"]
|
|
221
|
+
>,
|
|
222
|
+
): TBuilder;
|
|
223
|
+
onCompleted(
|
|
224
|
+
handler: NonNullable<
|
|
225
|
+
OperationObserverCallbacks<TProgress, TOutput>["onCompleted"]
|
|
226
|
+
>,
|
|
227
|
+
): TBuilder;
|
|
228
|
+
onFailed(
|
|
229
|
+
handler: NonNullable<
|
|
230
|
+
OperationObserverCallbacks<TProgress, TOutput>["onFailed"]
|
|
231
|
+
>,
|
|
232
|
+
): TBuilder;
|
|
233
|
+
onCancelled(
|
|
234
|
+
handler: NonNullable<
|
|
235
|
+
OperationObserverCallbacks<TProgress, TOutput>["onCancelled"]
|
|
236
|
+
>,
|
|
237
|
+
): TBuilder;
|
|
238
|
+
onEvent(
|
|
239
|
+
handler: NonNullable<
|
|
240
|
+
OperationObserverCallbacks<TProgress, TOutput>["onEvent"]
|
|
241
|
+
>,
|
|
242
|
+
): TBuilder;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
interface OperationInputBuilderBase<
|
|
246
|
+
TDesc extends OperationShape,
|
|
247
|
+
TProgress,
|
|
248
|
+
TOutput,
|
|
249
|
+
TBuilder,
|
|
250
|
+
> extends OperationObserverBuilderBase<TBuilder, TProgress, TOutput> {
|
|
251
|
+
start(): AsyncResult<
|
|
252
|
+
OperationRef<TDesc, TProgress, TOutput>,
|
|
253
|
+
TransportError | UnexpectedError
|
|
254
|
+
>;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export interface TransferOperationBuilder<
|
|
258
|
+
TDesc extends OperationShape,
|
|
259
|
+
TProgress = OperationProgressOf<TDesc>,
|
|
260
|
+
TOutput = OperationOutputOf<TDesc>,
|
|
261
|
+
> extends
|
|
262
|
+
OperationObserverBuilderBase<
|
|
263
|
+
TransferOperationBuilder<TDesc, TProgress, TOutput>,
|
|
264
|
+
TProgress,
|
|
265
|
+
TOutput
|
|
266
|
+
> {
|
|
267
|
+
onTransfer(
|
|
268
|
+
handler: NonNullable<
|
|
269
|
+
OperationObserverCallbacks<TProgress, TOutput>["onTransfer"]
|
|
270
|
+
>,
|
|
271
|
+
): TransferOperationBuilder<TDesc, TProgress, TOutput>;
|
|
272
|
+
start(): AsyncResult<
|
|
273
|
+
StartedTransfer<TDesc, TProgress, TOutput>,
|
|
274
|
+
TransportError | UnexpectedError | TransferError
|
|
275
|
+
>;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export interface OperationInputBuilder<
|
|
279
|
+
TDesc extends OperationShape,
|
|
280
|
+
TProgress = OperationProgressOf<TDesc>,
|
|
281
|
+
TOutput = OperationOutputOf<TDesc>,
|
|
282
|
+
> extends
|
|
283
|
+
OperationInputBuilderBase<
|
|
284
|
+
TDesc,
|
|
285
|
+
TProgress,
|
|
286
|
+
TOutput,
|
|
287
|
+
OperationInputBuilder<TDesc, TProgress, TOutput>
|
|
288
|
+
> {
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export interface TransferCapableOperationInputBuilder<
|
|
292
|
+
TDesc extends OperationShape,
|
|
293
|
+
TProgress = OperationProgressOf<TDesc>,
|
|
294
|
+
TOutput = OperationOutputOf<TDesc>,
|
|
295
|
+
> extends
|
|
296
|
+
OperationInputBuilderBase<
|
|
297
|
+
TDesc,
|
|
298
|
+
TProgress,
|
|
299
|
+
TOutput,
|
|
300
|
+
TransferCapableOperationInputBuilder<TDesc, TProgress, TOutput>
|
|
301
|
+
> {
|
|
302
|
+
transfer(
|
|
303
|
+
body: TransferBody,
|
|
304
|
+
): TransferOperationBuilder<TDesc, TProgress, TOutput>;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
type OperationAcceptedEnvelope<TProgress = unknown, TOutput = unknown> = {
|
|
308
|
+
kind: "accepted";
|
|
309
|
+
ref: OperationRefData;
|
|
310
|
+
snapshot: OperationSnapshot<TProgress, TOutput>;
|
|
311
|
+
transfer?: SendTransferGrant;
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
type OperationSnapshotFrame<TProgress = unknown, TOutput = unknown> = {
|
|
315
|
+
kind: "snapshot";
|
|
316
|
+
snapshot: OperationSnapshot<TProgress, TOutput>;
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
type OperationSignalAckFrame<TProgress = unknown, TOutput = unknown> =
|
|
320
|
+
OperationSignalAck<TProgress, TOutput>;
|
|
321
|
+
|
|
322
|
+
type OperationControlErrorFrame = {
|
|
323
|
+
kind: "error";
|
|
324
|
+
error: {
|
|
325
|
+
type: string;
|
|
326
|
+
message: string;
|
|
327
|
+
};
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
type OperationShape = {
|
|
331
|
+
subject: string;
|
|
332
|
+
input: unknown;
|
|
333
|
+
progress?: unknown;
|
|
334
|
+
output?: unknown;
|
|
335
|
+
transfer?: {
|
|
336
|
+
store: string;
|
|
337
|
+
key: `/${string}`;
|
|
338
|
+
contentType?: `/${string}`;
|
|
339
|
+
metadata?: `/${string}`;
|
|
340
|
+
expiresInMs?: number;
|
|
341
|
+
maxBytes?: number;
|
|
342
|
+
};
|
|
343
|
+
cancel?: boolean;
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
type OperationInputOf<TDesc extends OperationShape> = InferSchemaType<
|
|
347
|
+
TDesc["input"]
|
|
348
|
+
>;
|
|
349
|
+
type OperationProgressOf<TDesc extends OperationShape> =
|
|
350
|
+
TDesc["progress"] extends undefined ? unknown
|
|
351
|
+
: InferSchemaType<NonNullable<TDesc["progress"]>>;
|
|
352
|
+
type OperationOutputOf<TDesc extends OperationShape> = TDesc["output"] extends
|
|
353
|
+
undefined ? unknown
|
|
354
|
+
: InferSchemaType<NonNullable<TDesc["output"]>>;
|
|
355
|
+
|
|
356
|
+
export interface OperationTransport {
|
|
357
|
+
requestJson(
|
|
358
|
+
subject: string,
|
|
359
|
+
body: JsonValue,
|
|
360
|
+
): AsyncResult<JsonValue, TransportError | UnexpectedError>;
|
|
361
|
+
watchJson(
|
|
362
|
+
subject: string,
|
|
363
|
+
body: JsonValue,
|
|
364
|
+
): AsyncResult<
|
|
365
|
+
AsyncIterable<Result<JsonValue, TransportError | UnexpectedError>>,
|
|
366
|
+
TransportError | UnexpectedError
|
|
367
|
+
>;
|
|
368
|
+
putTransfer(
|
|
369
|
+
grant: SendTransferGrant,
|
|
370
|
+
body: TransferBody,
|
|
371
|
+
): AsyncResult<FileInfo, TransferError>;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
function operationRequestBody(input: unknown): JsonValue {
|
|
375
|
+
return input as JsonValue;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
export function controlSubject(subject: string): string {
|
|
379
|
+
return `${subject}.control`;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function isTerminalState(state: OperationState): boolean {
|
|
383
|
+
return state === "completed" || state === "failed" || state === "cancelled";
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function createTransportError(args: {
|
|
387
|
+
code: string;
|
|
388
|
+
message: string;
|
|
389
|
+
hint: string;
|
|
390
|
+
context?: Record<string, unknown>;
|
|
391
|
+
cause?: unknown;
|
|
392
|
+
}): TransportError {
|
|
393
|
+
return new TransportError({
|
|
394
|
+
code: args.code,
|
|
395
|
+
message: args.message,
|
|
396
|
+
hint: args.hint,
|
|
397
|
+
cause: args.cause,
|
|
398
|
+
context: {
|
|
399
|
+
...(args.context ?? {}),
|
|
400
|
+
...(args.cause instanceof Error
|
|
401
|
+
? { causeName: args.cause.name, causeMessage: args.cause.message }
|
|
402
|
+
: args.cause === undefined
|
|
403
|
+
? {}
|
|
404
|
+
: { cause: String(args.cause) }),
|
|
405
|
+
},
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
function snapshotToEvent<TProgress, TOutput>(
|
|
410
|
+
snapshot: OperationSnapshot<TProgress, TOutput>,
|
|
411
|
+
): OperationEvent<TProgress, TOutput> {
|
|
412
|
+
switch (snapshot.state) {
|
|
413
|
+
case "pending":
|
|
414
|
+
return { type: "accepted", snapshot };
|
|
415
|
+
case "running":
|
|
416
|
+
return { type: "started", snapshot };
|
|
417
|
+
case "completed":
|
|
418
|
+
return {
|
|
419
|
+
type: "completed",
|
|
420
|
+
snapshot: snapshot as TerminalOperation<TProgress, TOutput>,
|
|
421
|
+
};
|
|
422
|
+
case "failed":
|
|
423
|
+
return {
|
|
424
|
+
type: "failed",
|
|
425
|
+
snapshot: snapshot as TerminalOperation<TProgress, TOutput>,
|
|
426
|
+
};
|
|
427
|
+
case "cancelled":
|
|
428
|
+
return {
|
|
429
|
+
type: "cancelled",
|
|
430
|
+
snapshot: snapshot as TerminalOperation<TProgress, TOutput>,
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
function isTerminalEvent<TProgress, TOutput>(
|
|
436
|
+
event: OperationEvent<TProgress, TOutput>,
|
|
437
|
+
): event is Extract<
|
|
438
|
+
OperationEvent<TProgress, TOutput>,
|
|
439
|
+
{ type: "completed" | "failed" | "cancelled" }
|
|
440
|
+
> {
|
|
441
|
+
return event.type === "completed" || event.type === "failed" ||
|
|
442
|
+
event.type === "cancelled";
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
function normalizeOperationEvent<TProgress, TOutput>(
|
|
446
|
+
event: OperationEvent<TProgress, TOutput>,
|
|
447
|
+
): Result<OperationEvent<TProgress, TOutput>, TransportError> {
|
|
448
|
+
try {
|
|
449
|
+
switch (event.type) {
|
|
450
|
+
case "transfer": {
|
|
451
|
+
const transfer = event.transfer ?? event.snapshot.transfer;
|
|
452
|
+
if (!transfer) {
|
|
453
|
+
throw new Error("transfer event is missing transfer progress");
|
|
454
|
+
}
|
|
455
|
+
return ok({
|
|
456
|
+
type: "transfer",
|
|
457
|
+
transfer,
|
|
458
|
+
snapshot: {
|
|
459
|
+
...event.snapshot,
|
|
460
|
+
transfer,
|
|
461
|
+
},
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
case "progress": {
|
|
466
|
+
const progress = event.progress ?? event.snapshot.progress;
|
|
467
|
+
if (progress === undefined) {
|
|
468
|
+
throw new Error("progress event is missing progress payload");
|
|
469
|
+
}
|
|
470
|
+
return ok({
|
|
471
|
+
type: "progress",
|
|
472
|
+
progress,
|
|
473
|
+
snapshot: {
|
|
474
|
+
...event.snapshot,
|
|
475
|
+
progress,
|
|
476
|
+
},
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
default:
|
|
481
|
+
return ok(event);
|
|
482
|
+
}
|
|
483
|
+
} catch (cause) {
|
|
484
|
+
return err(createTransportError({
|
|
485
|
+
code: "trellis.operation.invalid_event",
|
|
486
|
+
message: "Trellis returned an invalid operation event.",
|
|
487
|
+
hint:
|
|
488
|
+
"Retry the operation watch. If it keeps failing, reconnect to Trellis and try again.",
|
|
489
|
+
cause,
|
|
490
|
+
}));
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
async function dispatchObservedOperationEvent<TProgress, TOutput>(
|
|
495
|
+
options: OperationObserverCallbacks<TProgress, TOutput>,
|
|
496
|
+
event: OperationEvent<TProgress, TOutput>,
|
|
497
|
+
): Promise<void> {
|
|
498
|
+
switch (event.type) {
|
|
499
|
+
case "accepted":
|
|
500
|
+
await options.onAccepted?.(event);
|
|
501
|
+
break;
|
|
502
|
+
case "started":
|
|
503
|
+
await options.onStarted?.(event);
|
|
504
|
+
break;
|
|
505
|
+
case "transfer":
|
|
506
|
+
await options.onTransfer?.(event);
|
|
507
|
+
break;
|
|
508
|
+
case "progress":
|
|
509
|
+
await options.onProgress?.(event);
|
|
510
|
+
break;
|
|
511
|
+
case "completed":
|
|
512
|
+
await options.onCompleted?.(event);
|
|
513
|
+
break;
|
|
514
|
+
case "failed":
|
|
515
|
+
await options.onFailed?.(event);
|
|
516
|
+
break;
|
|
517
|
+
case "cancelled":
|
|
518
|
+
await options.onCancelled?.(event);
|
|
519
|
+
break;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
await options.onEvent?.(event);
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
function hasObserverCallbacks<TProgress, TOutput>(
|
|
526
|
+
options: OperationObserverCallbacks<TProgress, TOutput>,
|
|
527
|
+
): boolean {
|
|
528
|
+
return Boolean(
|
|
529
|
+
options.onAccepted ||
|
|
530
|
+
options.onStarted ||
|
|
531
|
+
options.onTransfer ||
|
|
532
|
+
options.onProgress ||
|
|
533
|
+
options.onCompleted ||
|
|
534
|
+
options.onFailed ||
|
|
535
|
+
options.onCancelled ||
|
|
536
|
+
options.onEvent,
|
|
537
|
+
);
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
function decodeAcceptedEnvelope<TProgress, TOutput>(
|
|
541
|
+
value: JsonValue,
|
|
542
|
+
): Result<OperationAcceptedEnvelope<TProgress, TOutput>, TransportError> {
|
|
543
|
+
try {
|
|
544
|
+
const envelope = value as OperationAcceptedEnvelope<TProgress, TOutput>;
|
|
545
|
+
if (envelope?.kind !== "accepted" || !envelope.ref || !envelope.snapshot) {
|
|
546
|
+
throw new Error(
|
|
547
|
+
`Expected accepted operation envelope, got ${JSON.stringify(value)}`,
|
|
548
|
+
);
|
|
549
|
+
}
|
|
550
|
+
return ok(envelope);
|
|
551
|
+
} catch (cause) {
|
|
552
|
+
return err(createTransportError({
|
|
553
|
+
code: "trellis.operation.invalid_accept",
|
|
554
|
+
message: "Trellis returned an invalid operation start response.",
|
|
555
|
+
hint:
|
|
556
|
+
"Retry starting the operation. If it keeps failing, reconnect to Trellis and try again.",
|
|
557
|
+
cause,
|
|
558
|
+
}));
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
function decodeSnapshotFrame<TProgress, TOutput>(
|
|
563
|
+
value: JsonValue,
|
|
564
|
+
): Result<OperationSnapshotFrame<TProgress, TOutput>, TransportError> {
|
|
565
|
+
try {
|
|
566
|
+
if (isOperationControlErrorFrame(value)) {
|
|
567
|
+
return err(controlFrameToTransportError(value));
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
const frame = value as OperationSnapshotFrame<TProgress, TOutput>;
|
|
571
|
+
if (frame?.kind !== "snapshot" || !frame.snapshot) {
|
|
572
|
+
throw new Error("Expected snapshot operation frame");
|
|
573
|
+
}
|
|
574
|
+
return ok(frame);
|
|
575
|
+
} catch (cause) {
|
|
576
|
+
return err(createTransportError({
|
|
577
|
+
code: "trellis.operation.invalid_snapshot",
|
|
578
|
+
message: "Trellis returned an invalid operation snapshot.",
|
|
579
|
+
hint:
|
|
580
|
+
"Retry the operation request. If it keeps failing, reconnect to Trellis and try again.",
|
|
581
|
+
cause,
|
|
582
|
+
}));
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
function decodeSignalAckFrame<TProgress, TOutput>(
|
|
587
|
+
value: JsonValue,
|
|
588
|
+
): Result<OperationSignalAckFrame<TProgress, TOutput>, TransportError> {
|
|
589
|
+
try {
|
|
590
|
+
if (isOperationControlErrorFrame(value)) {
|
|
591
|
+
return err(controlFrameToTransportError(value));
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
const frame = value as OperationSignalAckFrame<TProgress, TOutput>;
|
|
595
|
+
if (
|
|
596
|
+
frame?.kind !== "signal-accepted" ||
|
|
597
|
+
typeof frame.operationId !== "string" ||
|
|
598
|
+
typeof frame.signal !== "string" ||
|
|
599
|
+
typeof frame.signalSequence !== "number" ||
|
|
600
|
+
typeof frame.acceptedAt !== "string" ||
|
|
601
|
+
!frame.snapshot
|
|
602
|
+
) {
|
|
603
|
+
throw new Error("Expected signal-accepted operation frame");
|
|
604
|
+
}
|
|
605
|
+
return ok(frame);
|
|
606
|
+
} catch (cause) {
|
|
607
|
+
return err(createTransportError({
|
|
608
|
+
code: "trellis.operation.invalid_signal_ack",
|
|
609
|
+
message: "Trellis returned an invalid operation signal response.",
|
|
610
|
+
hint:
|
|
611
|
+
"Retry the operation signal. If it keeps failing, reconnect to Trellis and try again.",
|
|
612
|
+
cause,
|
|
613
|
+
}));
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
class RuntimeOperationRef<
|
|
618
|
+
TDesc extends OperationShape,
|
|
619
|
+
TProgress = OperationProgressOf<TDesc>,
|
|
620
|
+
TOutput = OperationOutputOf<TDesc>,
|
|
621
|
+
> {
|
|
622
|
+
readonly id: string;
|
|
623
|
+
readonly service: string;
|
|
624
|
+
readonly operation: string;
|
|
625
|
+
|
|
626
|
+
readonly #transport: OperationTransport;
|
|
627
|
+
readonly #descriptor: TDesc;
|
|
628
|
+
readonly #acceptedTransfer?: SendTransferGrant;
|
|
629
|
+
|
|
630
|
+
constructor(
|
|
631
|
+
transport: OperationTransport,
|
|
632
|
+
descriptor: TDesc,
|
|
633
|
+
ref: OperationRefData,
|
|
634
|
+
acceptedTransfer?: SendTransferGrant,
|
|
635
|
+
) {
|
|
636
|
+
this.#transport = transport;
|
|
637
|
+
this.#descriptor = descriptor;
|
|
638
|
+
this.id = ref.id;
|
|
639
|
+
this.service = ref.service;
|
|
640
|
+
this.operation = ref.operation;
|
|
641
|
+
this.#acceptedTransfer = acceptedTransfer;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
get(): AsyncResult<
|
|
645
|
+
OperationSnapshot<TProgress, TOutput>,
|
|
646
|
+
TransportError | UnexpectedError
|
|
647
|
+
> {
|
|
648
|
+
return this.#controlSnapshot("get");
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
wait(): AsyncResult<
|
|
652
|
+
TerminalOperation<TProgress, TOutput>,
|
|
653
|
+
TransportError | UnexpectedError
|
|
654
|
+
> {
|
|
655
|
+
return AsyncResult.from((async () => {
|
|
656
|
+
const initialTerminal = await this.#terminalSnapshotFromGet().take();
|
|
657
|
+
if (isErr(initialTerminal)) {
|
|
658
|
+
return initialTerminal;
|
|
659
|
+
}
|
|
660
|
+
if (initialTerminal !== null) {
|
|
661
|
+
return ok(initialTerminal);
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
const eventsValue = await this.watch().take();
|
|
665
|
+
if (isErr(eventsValue)) {
|
|
666
|
+
const terminal = await this.#terminalSnapshotFromGet().take();
|
|
667
|
+
if (!isErr(terminal) && terminal !== null) {
|
|
668
|
+
return ok(terminal);
|
|
669
|
+
}
|
|
670
|
+
return eventsValue;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
try {
|
|
674
|
+
for await (const event of eventsValue) {
|
|
675
|
+
if (isTerminalEvent(event)) {
|
|
676
|
+
return ok(event.snapshot);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
} catch (cause) {
|
|
680
|
+
const terminal = await this.#terminalSnapshotFromGet().take();
|
|
681
|
+
if (!isErr(terminal) && terminal !== null) {
|
|
682
|
+
return ok(terminal);
|
|
683
|
+
}
|
|
684
|
+
return err(
|
|
685
|
+
cause instanceof TransportError || cause instanceof UnexpectedError
|
|
686
|
+
? cause
|
|
687
|
+
: new UnexpectedError({ cause }),
|
|
688
|
+
);
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
const terminal = await this.#terminalSnapshotFromGet().take();
|
|
692
|
+
if (!isErr(terminal) && terminal !== null) {
|
|
693
|
+
return ok(terminal);
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
return err(createTransportError({
|
|
697
|
+
code: "trellis.operation.watch_closed",
|
|
698
|
+
message: "Trellis operation watch ended before a terminal snapshot.",
|
|
699
|
+
hint:
|
|
700
|
+
"Retry the operation wait. If it keeps happening, reconnect to Trellis and try again.",
|
|
701
|
+
context: { operationId: this.id, operation: this.operation },
|
|
702
|
+
}));
|
|
703
|
+
})());
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
#terminalSnapshotFromGet(): AsyncResult<
|
|
707
|
+
TerminalOperation<TProgress, TOutput> | null,
|
|
708
|
+
TransportError | UnexpectedError
|
|
709
|
+
> {
|
|
710
|
+
return AsyncResult.from((async () => {
|
|
711
|
+
const snapshotValue = await this.#controlSnapshot("get").take();
|
|
712
|
+
if (isErr(snapshotValue)) {
|
|
713
|
+
return snapshotValue;
|
|
714
|
+
}
|
|
715
|
+
if (isTerminalState(snapshotValue.state)) {
|
|
716
|
+
return ok(snapshotValue as TerminalOperation<TProgress, TOutput>);
|
|
717
|
+
}
|
|
718
|
+
return ok(null);
|
|
719
|
+
})());
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
cancel(): AsyncResult<
|
|
723
|
+
OperationSnapshot<TProgress, TOutput>,
|
|
724
|
+
TransportError | UnexpectedError
|
|
725
|
+
> {
|
|
726
|
+
return this.#controlSnapshot("cancel");
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
signal(
|
|
730
|
+
signal: string,
|
|
731
|
+
input?: unknown,
|
|
732
|
+
): AsyncResult<
|
|
733
|
+
OperationSignalAck<TProgress, TOutput>,
|
|
734
|
+
TransportError | UnexpectedError
|
|
735
|
+
> {
|
|
736
|
+
return AsyncResult.from((async () => {
|
|
737
|
+
const body: {
|
|
738
|
+
action: "signal";
|
|
739
|
+
operationId: string;
|
|
740
|
+
signal: string;
|
|
741
|
+
input?: JsonValue;
|
|
742
|
+
} = {
|
|
743
|
+
action: "signal",
|
|
744
|
+
operationId: this.id,
|
|
745
|
+
signal,
|
|
746
|
+
};
|
|
747
|
+
if (input !== undefined) {
|
|
748
|
+
body.input = input as JsonValue;
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
const responseValue = await this.#transport.requestJson(
|
|
752
|
+
controlSubject(this.#descriptor.subject),
|
|
753
|
+
body,
|
|
754
|
+
).take();
|
|
755
|
+
if (isErr(responseValue)) {
|
|
756
|
+
return responseValue;
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
return decodeSignalAckFrame<TProgress, TOutput>(responseValue);
|
|
760
|
+
})());
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
startTransfer(body: TransferBody): AsyncResult<FileInfo, TransferError> {
|
|
764
|
+
const grant = this.#acceptedTransfer;
|
|
765
|
+
if (!grant) {
|
|
766
|
+
return AsyncResult.err(
|
|
767
|
+
new TransferError({
|
|
768
|
+
operation: "transfer",
|
|
769
|
+
context: { reason: "missing_transfer" },
|
|
770
|
+
}),
|
|
771
|
+
);
|
|
772
|
+
}
|
|
773
|
+
return this.#transport.putTransfer(grant, body);
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
watch(): AsyncResult<
|
|
777
|
+
AsyncIterable<OperationEvent<TProgress, TOutput>>,
|
|
778
|
+
TransportError | UnexpectedError
|
|
779
|
+
> {
|
|
780
|
+
return AsyncResult.from((async () => {
|
|
781
|
+
const rawIterable = await this.#transport.watchJson(
|
|
782
|
+
controlSubject(this.#descriptor.subject),
|
|
783
|
+
{
|
|
784
|
+
action: "watch",
|
|
785
|
+
operationId: this.id,
|
|
786
|
+
},
|
|
787
|
+
).take();
|
|
788
|
+
if (isErr(rawIterable)) {
|
|
789
|
+
return err(rawIterable.error);
|
|
790
|
+
}
|
|
791
|
+
const iterable = rawIterable as AsyncIterable<
|
|
792
|
+
Result<JsonValue, TransportError | UnexpectedError>
|
|
793
|
+
>;
|
|
794
|
+
|
|
795
|
+
async function* events() {
|
|
796
|
+
for await (const frame of iterable) {
|
|
797
|
+
const frameValue = frame.take();
|
|
798
|
+
if (isErr(frameValue)) {
|
|
799
|
+
throw frameValue.error;
|
|
800
|
+
}
|
|
801
|
+
const decoded = decodeWatchFrame<TProgress, TOutput>(frameValue);
|
|
802
|
+
const decodedValue = decoded.take();
|
|
803
|
+
if (isErr(decodedValue)) {
|
|
804
|
+
throw decodedValue.error;
|
|
805
|
+
}
|
|
806
|
+
if (decodedValue === null) {
|
|
807
|
+
continue;
|
|
808
|
+
}
|
|
809
|
+
const normalized = normalizeOperationEvent(decodedValue).take();
|
|
810
|
+
if (isErr(normalized)) {
|
|
811
|
+
throw normalized.error;
|
|
812
|
+
}
|
|
813
|
+
yield normalized;
|
|
814
|
+
if (isTerminalEvent(normalized)) {
|
|
815
|
+
break;
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
return ok(events());
|
|
821
|
+
})());
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
#controlSnapshot(
|
|
825
|
+
action: "get" | "wait" | "cancel" | "watch",
|
|
826
|
+
): AsyncResult<
|
|
827
|
+
OperationSnapshot<TProgress, TOutput>,
|
|
828
|
+
TransportError | UnexpectedError
|
|
829
|
+
> {
|
|
830
|
+
return AsyncResult.from((async () => {
|
|
831
|
+
const responseValue = await this.#transport.requestJson(
|
|
832
|
+
controlSubject(this.#descriptor.subject),
|
|
833
|
+
{
|
|
834
|
+
action,
|
|
835
|
+
operationId: this.id,
|
|
836
|
+
},
|
|
837
|
+
).take();
|
|
838
|
+
if (isErr(responseValue)) {
|
|
839
|
+
return responseValue;
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
const frame = decodeSnapshotFrame<TProgress, TOutput>(
|
|
843
|
+
responseValue,
|
|
844
|
+
).take();
|
|
845
|
+
if (isErr(frame)) {
|
|
846
|
+
return frame;
|
|
847
|
+
}
|
|
848
|
+
return ok(frame.snapshot);
|
|
849
|
+
})());
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
function decodeWatchFrame<TProgress, TOutput>(
|
|
854
|
+
value: JsonValue,
|
|
855
|
+
): Result<OperationEvent<TProgress, TOutput> | null, TransportError> {
|
|
856
|
+
try {
|
|
857
|
+
if (
|
|
858
|
+
value && typeof value === "object" &&
|
|
859
|
+
(value as { kind?: string }).kind === "keepalive"
|
|
860
|
+
) {
|
|
861
|
+
return ok(null);
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
if (isOperationControlErrorFrame(value)) {
|
|
865
|
+
return err(controlFrameToTransportError(value));
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
const frame = value as
|
|
869
|
+
| { kind: "snapshot"; snapshot: OperationSnapshot<TProgress, TOutput> }
|
|
870
|
+
| { kind: "event"; event: OperationEvent<TProgress, TOutput> };
|
|
871
|
+
|
|
872
|
+
if (
|
|
873
|
+
(frame as { kind?: string }).kind === "snapshot" && "snapshot" in frame
|
|
874
|
+
) {
|
|
875
|
+
return ok(snapshotToEvent(frame.snapshot));
|
|
876
|
+
}
|
|
877
|
+
if ((frame as { kind?: string }).kind === "event" && "event" in frame) {
|
|
878
|
+
return ok(frame.event);
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
throw new Error("Expected snapshot, event, or keepalive frame");
|
|
882
|
+
} catch (cause) {
|
|
883
|
+
return err(createTransportError({
|
|
884
|
+
code: "trellis.operation.invalid_frame",
|
|
885
|
+
message: "Trellis returned an invalid operation watch frame.",
|
|
886
|
+
hint:
|
|
887
|
+
"Retry the operation watch. If it keeps failing, reconnect to Trellis and try again.",
|
|
888
|
+
cause,
|
|
889
|
+
}));
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
type OperationWatchObservation<TProgress, TOutput> = {
|
|
894
|
+
task?: Promise<
|
|
895
|
+
Result<
|
|
896
|
+
TerminalOperation<TProgress, TOutput>,
|
|
897
|
+
TransportError | UnexpectedError
|
|
898
|
+
>
|
|
899
|
+
>;
|
|
900
|
+
close?: () => Promise<void>;
|
|
901
|
+
};
|
|
902
|
+
|
|
903
|
+
type ObservedWatchOptions<TProgress, TOutput> = {
|
|
904
|
+
ready?: Promise<void>;
|
|
905
|
+
skipEvent?: (event: OperationEvent<TProgress, TOutput>) => boolean;
|
|
906
|
+
};
|
|
907
|
+
|
|
908
|
+
type InvokedOperation<TDesc extends OperationShape, TProgress, TOutput> = {
|
|
909
|
+
accepted: AcceptedOperationEvent<TProgress, TOutput>;
|
|
910
|
+
operation: RuntimeOperationRef<TDesc, TProgress, TOutput>;
|
|
911
|
+
};
|
|
912
|
+
|
|
913
|
+
function invokeOperation<TDesc extends OperationShape, TProgress, TOutput>(
|
|
914
|
+
transport: OperationTransport,
|
|
915
|
+
descriptor: TDesc,
|
|
916
|
+
input: unknown,
|
|
917
|
+
): AsyncResult<
|
|
918
|
+
InvokedOperation<TDesc, TProgress, TOutput>,
|
|
919
|
+
TransportError | UnexpectedError
|
|
920
|
+
> {
|
|
921
|
+
return AsyncResult.from((async () => {
|
|
922
|
+
const responseValue = await transport.requestJson(
|
|
923
|
+
descriptor.subject,
|
|
924
|
+
operationRequestBody(input),
|
|
925
|
+
).take();
|
|
926
|
+
if (isErr(responseValue)) {
|
|
927
|
+
return responseValue;
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
const envelope = decodeAcceptedEnvelope<TProgress, TOutput>(responseValue)
|
|
931
|
+
.take();
|
|
932
|
+
if (isErr(envelope)) {
|
|
933
|
+
return envelope;
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
return ok({
|
|
937
|
+
accepted: {
|
|
938
|
+
type: "accepted",
|
|
939
|
+
snapshot: envelope.snapshot,
|
|
940
|
+
},
|
|
941
|
+
operation: new RuntimeOperationRef<TDesc, TProgress, TOutput>(
|
|
942
|
+
transport,
|
|
943
|
+
descriptor,
|
|
944
|
+
envelope.ref,
|
|
945
|
+
envelope.transfer,
|
|
946
|
+
),
|
|
947
|
+
});
|
|
948
|
+
})());
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
function beginObservedWatch<
|
|
952
|
+
TDesc extends OperationShape,
|
|
953
|
+
TProgress,
|
|
954
|
+
TOutput,
|
|
955
|
+
>(
|
|
956
|
+
operation: RuntimeOperationRef<TDesc, TProgress, TOutput>,
|
|
957
|
+
callbacks: OperationObserverCallbacks<TProgress, TOutput>,
|
|
958
|
+
options: ObservedWatchOptions<TProgress, TOutput> = {},
|
|
959
|
+
): AsyncResult<
|
|
960
|
+
OperationWatchObservation<TProgress, TOutput>,
|
|
961
|
+
TransportError | UnexpectedError
|
|
962
|
+
> {
|
|
963
|
+
if (!hasObserverCallbacks(callbacks)) {
|
|
964
|
+
return AsyncResult.ok({});
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
return AsyncResult.from((async () => {
|
|
968
|
+
const watchValue = await operation.watch().take();
|
|
969
|
+
if (isErr(watchValue)) {
|
|
970
|
+
return watchValue;
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
const iterator = watchValue[Symbol.asyncIterator]();
|
|
974
|
+
const close = async () => {
|
|
975
|
+
await iterator.return?.();
|
|
976
|
+
};
|
|
977
|
+
|
|
978
|
+
const task = (async (): Promise<
|
|
979
|
+
Result<
|
|
980
|
+
TerminalOperation<TProgress, TOutput>,
|
|
981
|
+
TransportError | UnexpectedError
|
|
982
|
+
>
|
|
983
|
+
> => {
|
|
984
|
+
try {
|
|
985
|
+
await options.ready;
|
|
986
|
+
|
|
987
|
+
while (true) {
|
|
988
|
+
const next = await iterator.next();
|
|
989
|
+
if (next.done) {
|
|
990
|
+
break;
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
const event = next.value;
|
|
994
|
+
if (options.skipEvent?.(event)) {
|
|
995
|
+
continue;
|
|
996
|
+
}
|
|
997
|
+
try {
|
|
998
|
+
await dispatchObservedOperationEvent(callbacks, event);
|
|
999
|
+
} catch (cause) {
|
|
1000
|
+
return err(toObservedCallbackError(cause));
|
|
1001
|
+
}
|
|
1002
|
+
if (isTerminalEvent(event)) {
|
|
1003
|
+
await close();
|
|
1004
|
+
return ok(
|
|
1005
|
+
event.snapshot as TerminalOperation<TProgress, TOutput>,
|
|
1006
|
+
);
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
return err(createTransportError({
|
|
1011
|
+
code: "trellis.operation.watch_incomplete",
|
|
1012
|
+
message: "Trellis ended the operation watch before completion.",
|
|
1013
|
+
hint:
|
|
1014
|
+
"Retry watching the operation. If it keeps happening, reconnect to Trellis and try again.",
|
|
1015
|
+
cause: new Error("operation watch ended before terminal event"),
|
|
1016
|
+
}));
|
|
1017
|
+
} catch (cause) {
|
|
1018
|
+
return err(
|
|
1019
|
+
cause instanceof TransportError || cause instanceof UnexpectedError
|
|
1020
|
+
? cause
|
|
1021
|
+
: new UnexpectedError({ cause }),
|
|
1022
|
+
);
|
|
1023
|
+
}
|
|
1024
|
+
})();
|
|
1025
|
+
|
|
1026
|
+
return ok({ task, close });
|
|
1027
|
+
})());
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
function startObservedOperation<
|
|
1031
|
+
TDesc extends OperationShape,
|
|
1032
|
+
TProgress,
|
|
1033
|
+
TOutput,
|
|
1034
|
+
>(
|
|
1035
|
+
transport: OperationTransport,
|
|
1036
|
+
descriptor: TDesc,
|
|
1037
|
+
input: unknown,
|
|
1038
|
+
callbacks: OperationObserverCallbacks<TProgress, TOutput>,
|
|
1039
|
+
): AsyncResult<
|
|
1040
|
+
OperationRef<TDesc, TProgress, TOutput>,
|
|
1041
|
+
TransportError | UnexpectedError
|
|
1042
|
+
> {
|
|
1043
|
+
return AsyncResult.from((async () => {
|
|
1044
|
+
const startedValue = await invokeOperation<TDesc, TProgress, TOutput>(
|
|
1045
|
+
transport,
|
|
1046
|
+
descriptor,
|
|
1047
|
+
input,
|
|
1048
|
+
).take();
|
|
1049
|
+
if (isErr(startedValue)) {
|
|
1050
|
+
return startedValue;
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
const ready = deferred<void>();
|
|
1054
|
+
|
|
1055
|
+
const observedValue = await beginObservedWatch(
|
|
1056
|
+
startedValue.operation,
|
|
1057
|
+
callbacks,
|
|
1058
|
+
{
|
|
1059
|
+
ready: ready.promise,
|
|
1060
|
+
skipEvent: createAcceptedReplayFilter(startedValue.accepted),
|
|
1061
|
+
},
|
|
1062
|
+
).take();
|
|
1063
|
+
const observation = isErr(observedValue) ? {} : observedValue;
|
|
1064
|
+
|
|
1065
|
+
const accepted = await dispatchOperationEventResult(
|
|
1066
|
+
callbacks,
|
|
1067
|
+
startedValue.accepted,
|
|
1068
|
+
);
|
|
1069
|
+
if (accepted.isErr()) {
|
|
1070
|
+
if (!isErr(observedValue)) {
|
|
1071
|
+
ready.resolve();
|
|
1072
|
+
await observation.close?.();
|
|
1073
|
+
}
|
|
1074
|
+
return ok(createPublicOperationRef(
|
|
1075
|
+
startedValue.operation,
|
|
1076
|
+
failedObservation(accepted.error),
|
|
1077
|
+
));
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
if (!isErr(observedValue)) {
|
|
1081
|
+
ready.resolve();
|
|
1082
|
+
}
|
|
1083
|
+
return ok(createPublicOperationRef(startedValue.operation, observation));
|
|
1084
|
+
})());
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
function startObservedTransfer<
|
|
1088
|
+
TDesc extends OperationShape,
|
|
1089
|
+
TProgress,
|
|
1090
|
+
TOutput,
|
|
1091
|
+
>(
|
|
1092
|
+
transport: OperationTransport,
|
|
1093
|
+
descriptor: TDesc,
|
|
1094
|
+
input: unknown,
|
|
1095
|
+
body: TransferBody,
|
|
1096
|
+
callbacks: OperationObserverCallbacks<TProgress, TOutput>,
|
|
1097
|
+
): AsyncResult<
|
|
1098
|
+
StartedTransfer<TDesc, TProgress, TOutput>,
|
|
1099
|
+
TransportError | UnexpectedError | TransferError
|
|
1100
|
+
> {
|
|
1101
|
+
return AsyncResult.from((async () => {
|
|
1102
|
+
const startedValue = await invokeOperation<TDesc, TProgress, TOutput>(
|
|
1103
|
+
transport,
|
|
1104
|
+
descriptor,
|
|
1105
|
+
input,
|
|
1106
|
+
).take();
|
|
1107
|
+
if (isErr(startedValue)) {
|
|
1108
|
+
return startedValue;
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
const operation = startedValue.operation;
|
|
1112
|
+
const ready = deferred<void>();
|
|
1113
|
+
const observedValue = await beginObservedWatch(operation, callbacks, {
|
|
1114
|
+
ready: ready.promise,
|
|
1115
|
+
skipEvent: createAcceptedReplayFilter(startedValue.accepted),
|
|
1116
|
+
}).take();
|
|
1117
|
+
const observation = isErr(observedValue) ? {} : observedValue;
|
|
1118
|
+
|
|
1119
|
+
const accepted = await dispatchOperationEventResult(
|
|
1120
|
+
callbacks,
|
|
1121
|
+
startedValue.accepted,
|
|
1122
|
+
);
|
|
1123
|
+
if (accepted.isErr()) {
|
|
1124
|
+
if (!isErr(observedValue)) {
|
|
1125
|
+
ready.resolve();
|
|
1126
|
+
await observation.close?.();
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
if (!isErr(observedValue)) {
|
|
1131
|
+
ready.resolve();
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
const transferTask = (async () => {
|
|
1135
|
+
const transferredValue = await operation.startTransfer(body).take();
|
|
1136
|
+
if (isErr(transferredValue)) {
|
|
1137
|
+
await observation.close?.();
|
|
1138
|
+
return transferredValue;
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
return ok(transferredValue);
|
|
1142
|
+
})();
|
|
1143
|
+
|
|
1144
|
+
const publicOperation = createPublicOperationRef(
|
|
1145
|
+
operation,
|
|
1146
|
+
accepted.isErr() ? failedObservation(accepted.error) : observation,
|
|
1147
|
+
);
|
|
1148
|
+
|
|
1149
|
+
return ok({
|
|
1150
|
+
operation: publicOperation,
|
|
1151
|
+
wait: () =>
|
|
1152
|
+
AsyncResult.from((async () => {
|
|
1153
|
+
const transferred = await transferTask;
|
|
1154
|
+
const transferredValue = transferred.take();
|
|
1155
|
+
if (isErr(transferredValue)) {
|
|
1156
|
+
return transferredValue;
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
const terminalValue = await publicOperation.wait().take();
|
|
1160
|
+
if (isErr(terminalValue)) {
|
|
1161
|
+
return terminalValue;
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
return ok({
|
|
1165
|
+
transferred: transferredValue,
|
|
1166
|
+
terminal: terminalValue,
|
|
1167
|
+
});
|
|
1168
|
+
})()),
|
|
1169
|
+
});
|
|
1170
|
+
})());
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
function createObservedOperationRef<
|
|
1174
|
+
TDesc extends OperationShape,
|
|
1175
|
+
TProgress,
|
|
1176
|
+
TOutput,
|
|
1177
|
+
>(
|
|
1178
|
+
operation: RuntimeOperationRef<TDesc, TProgress, TOutput>,
|
|
1179
|
+
observation: OperationWatchObservation<TProgress, TOutput>,
|
|
1180
|
+
): OperationRef<TDesc, TProgress, TOutput> {
|
|
1181
|
+
return createPublicOperationRef(operation, observation);
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
function createPublicOperationRef<
|
|
1185
|
+
TDesc extends OperationShape,
|
|
1186
|
+
TProgress,
|
|
1187
|
+
TOutput,
|
|
1188
|
+
>(
|
|
1189
|
+
operation: RuntimeOperationRef<TDesc, TProgress, TOutput>,
|
|
1190
|
+
observation: OperationWatchObservation<TProgress, TOutput>,
|
|
1191
|
+
): OperationRef<TDesc, TProgress, TOutput> {
|
|
1192
|
+
const base = {
|
|
1193
|
+
id: operation.id,
|
|
1194
|
+
service: operation.service,
|
|
1195
|
+
operation: operation.operation,
|
|
1196
|
+
get: () => operation.get(),
|
|
1197
|
+
wait: () =>
|
|
1198
|
+
AsyncResult.from((async () => {
|
|
1199
|
+
if (observation.task) {
|
|
1200
|
+
const terminal = await observation.task;
|
|
1201
|
+
const terminalValue = terminal.take();
|
|
1202
|
+
if (!isErr(terminalValue)) {
|
|
1203
|
+
return ok(terminalValue);
|
|
1204
|
+
}
|
|
1205
|
+
if (isObservedCallbackError(terminalValue.error)) {
|
|
1206
|
+
return terminalValue;
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
return await operation.wait();
|
|
1211
|
+
})()),
|
|
1212
|
+
watch: () => operation.watch(),
|
|
1213
|
+
cancel: () => operation.cancel(),
|
|
1214
|
+
signal: (signal: string, input?: unknown) =>
|
|
1215
|
+
operation.signal(signal, input),
|
|
1216
|
+
};
|
|
1217
|
+
|
|
1218
|
+
return base as OperationRef<TDesc, TProgress, TOutput>;
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
function createOperationInputBuilder<
|
|
1222
|
+
TDesc extends OperationShape,
|
|
1223
|
+
TProgress,
|
|
1224
|
+
TOutput,
|
|
1225
|
+
>(
|
|
1226
|
+
transport: OperationTransport,
|
|
1227
|
+
descriptor: TDesc,
|
|
1228
|
+
input: unknown,
|
|
1229
|
+
callbacks: OperationObserverCallbacks<TProgress, TOutput> = {},
|
|
1230
|
+
): TDesc["transfer"] extends undefined
|
|
1231
|
+
? OperationInputBuilder<TDesc, TProgress, TOutput>
|
|
1232
|
+
: TransferCapableOperationInputBuilder<TDesc, TProgress, TOutput> {
|
|
1233
|
+
const rebuild = (
|
|
1234
|
+
nextCallbacks: OperationObserverCallbacks<TProgress, TOutput>,
|
|
1235
|
+
) =>
|
|
1236
|
+
createOperationInputBuilder<TDesc, TProgress, TOutput>(
|
|
1237
|
+
transport,
|
|
1238
|
+
descriptor,
|
|
1239
|
+
input,
|
|
1240
|
+
nextCallbacks,
|
|
1241
|
+
);
|
|
1242
|
+
|
|
1243
|
+
const baseBuilder = {
|
|
1244
|
+
onAccepted(
|
|
1245
|
+
handler: NonNullable<
|
|
1246
|
+
OperationObserverCallbacks<TProgress, TOutput>["onAccepted"]
|
|
1247
|
+
>,
|
|
1248
|
+
) {
|
|
1249
|
+
return rebuild({ ...callbacks, onAccepted: handler });
|
|
1250
|
+
},
|
|
1251
|
+
onStarted(
|
|
1252
|
+
handler: NonNullable<
|
|
1253
|
+
OperationObserverCallbacks<TProgress, TOutput>["onStarted"]
|
|
1254
|
+
>,
|
|
1255
|
+
) {
|
|
1256
|
+
return rebuild({ ...callbacks, onStarted: handler });
|
|
1257
|
+
},
|
|
1258
|
+
onProgress(
|
|
1259
|
+
handler: NonNullable<
|
|
1260
|
+
OperationObserverCallbacks<TProgress, TOutput>["onProgress"]
|
|
1261
|
+
>,
|
|
1262
|
+
) {
|
|
1263
|
+
return rebuild({ ...callbacks, onProgress: handler });
|
|
1264
|
+
},
|
|
1265
|
+
onCompleted(
|
|
1266
|
+
handler: NonNullable<
|
|
1267
|
+
OperationObserverCallbacks<TProgress, TOutput>["onCompleted"]
|
|
1268
|
+
>,
|
|
1269
|
+
) {
|
|
1270
|
+
return rebuild({ ...callbacks, onCompleted: handler });
|
|
1271
|
+
},
|
|
1272
|
+
onFailed(
|
|
1273
|
+
handler: NonNullable<
|
|
1274
|
+
OperationObserverCallbacks<TProgress, TOutput>["onFailed"]
|
|
1275
|
+
>,
|
|
1276
|
+
) {
|
|
1277
|
+
return rebuild({ ...callbacks, onFailed: handler });
|
|
1278
|
+
},
|
|
1279
|
+
onCancelled(
|
|
1280
|
+
handler: NonNullable<
|
|
1281
|
+
OperationObserverCallbacks<TProgress, TOutput>["onCancelled"]
|
|
1282
|
+
>,
|
|
1283
|
+
) {
|
|
1284
|
+
return rebuild({ ...callbacks, onCancelled: handler });
|
|
1285
|
+
},
|
|
1286
|
+
onEvent(
|
|
1287
|
+
handler: NonNullable<
|
|
1288
|
+
OperationObserverCallbacks<TProgress, TOutput>["onEvent"]
|
|
1289
|
+
>,
|
|
1290
|
+
) {
|
|
1291
|
+
return rebuild({ ...callbacks, onEvent: handler });
|
|
1292
|
+
},
|
|
1293
|
+
start() {
|
|
1294
|
+
return startObservedOperation<TDesc, TProgress, TOutput>(
|
|
1295
|
+
transport,
|
|
1296
|
+
descriptor,
|
|
1297
|
+
input,
|
|
1298
|
+
callbacks,
|
|
1299
|
+
);
|
|
1300
|
+
},
|
|
1301
|
+
} satisfies OperationInputBuilderBase<
|
|
1302
|
+
TDesc,
|
|
1303
|
+
TProgress,
|
|
1304
|
+
TOutput,
|
|
1305
|
+
OperationInputBuilder<TDesc, TProgress, TOutput>
|
|
1306
|
+
>;
|
|
1307
|
+
|
|
1308
|
+
if (descriptor.transfer) {
|
|
1309
|
+
return {
|
|
1310
|
+
...baseBuilder,
|
|
1311
|
+
transfer(body: TransferBody) {
|
|
1312
|
+
return createTransferOperationBuilder<TDesc, TProgress, TOutput>(
|
|
1313
|
+
transport,
|
|
1314
|
+
descriptor,
|
|
1315
|
+
input,
|
|
1316
|
+
body,
|
|
1317
|
+
callbacks,
|
|
1318
|
+
);
|
|
1319
|
+
},
|
|
1320
|
+
} as TDesc["transfer"] extends undefined
|
|
1321
|
+
? OperationInputBuilder<TDesc, TProgress, TOutput>
|
|
1322
|
+
: TransferCapableOperationInputBuilder<TDesc, TProgress, TOutput>;
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
return baseBuilder as TDesc["transfer"] extends undefined
|
|
1326
|
+
? OperationInputBuilder<TDesc, TProgress, TOutput>
|
|
1327
|
+
: TransferCapableOperationInputBuilder<TDesc, TProgress, TOutput>;
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
function createTransferOperationBuilder<
|
|
1331
|
+
TDesc extends OperationShape,
|
|
1332
|
+
TProgress,
|
|
1333
|
+
TOutput,
|
|
1334
|
+
>(
|
|
1335
|
+
transport: OperationTransport,
|
|
1336
|
+
descriptor: TDesc,
|
|
1337
|
+
input: unknown,
|
|
1338
|
+
body: TransferBody,
|
|
1339
|
+
callbacks: OperationObserverCallbacks<TProgress, TOutput> = {},
|
|
1340
|
+
): TransferOperationBuilder<TDesc, TProgress, TOutput> {
|
|
1341
|
+
const rebuild = (
|
|
1342
|
+
nextCallbacks: OperationObserverCallbacks<TProgress, TOutput>,
|
|
1343
|
+
) =>
|
|
1344
|
+
createTransferOperationBuilder<TDesc, TProgress, TOutput>(
|
|
1345
|
+
transport,
|
|
1346
|
+
descriptor,
|
|
1347
|
+
input,
|
|
1348
|
+
body,
|
|
1349
|
+
nextCallbacks,
|
|
1350
|
+
);
|
|
1351
|
+
|
|
1352
|
+
return {
|
|
1353
|
+
onAccepted(handler) {
|
|
1354
|
+
return rebuild({ ...callbacks, onAccepted: handler });
|
|
1355
|
+
},
|
|
1356
|
+
onStarted(handler) {
|
|
1357
|
+
return rebuild({ ...callbacks, onStarted: handler });
|
|
1358
|
+
},
|
|
1359
|
+
onTransfer(handler) {
|
|
1360
|
+
return rebuild({ ...callbacks, onTransfer: handler });
|
|
1361
|
+
},
|
|
1362
|
+
onProgress(handler) {
|
|
1363
|
+
return rebuild({ ...callbacks, onProgress: handler });
|
|
1364
|
+
},
|
|
1365
|
+
onCompleted(handler) {
|
|
1366
|
+
return rebuild({ ...callbacks, onCompleted: handler });
|
|
1367
|
+
},
|
|
1368
|
+
onFailed(handler) {
|
|
1369
|
+
return rebuild({ ...callbacks, onFailed: handler });
|
|
1370
|
+
},
|
|
1371
|
+
onCancelled(handler) {
|
|
1372
|
+
return rebuild({ ...callbacks, onCancelled: handler });
|
|
1373
|
+
},
|
|
1374
|
+
onEvent(handler) {
|
|
1375
|
+
return rebuild({ ...callbacks, onEvent: handler });
|
|
1376
|
+
},
|
|
1377
|
+
start() {
|
|
1378
|
+
return startObservedTransfer<TDesc, TProgress, TOutput>(
|
|
1379
|
+
transport,
|
|
1380
|
+
descriptor,
|
|
1381
|
+
input,
|
|
1382
|
+
body,
|
|
1383
|
+
callbacks,
|
|
1384
|
+
);
|
|
1385
|
+
},
|
|
1386
|
+
};
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
export class OperationInvoker<
|
|
1390
|
+
TDesc extends OperationShape,
|
|
1391
|
+
TInput = OperationInputOf<TDesc>,
|
|
1392
|
+
TProgress = OperationProgressOf<TDesc>,
|
|
1393
|
+
TOutput = OperationOutputOf<TDesc>,
|
|
1394
|
+
> {
|
|
1395
|
+
readonly #transport: OperationTransport;
|
|
1396
|
+
readonly #descriptor: TDesc;
|
|
1397
|
+
|
|
1398
|
+
constructor(transport: OperationTransport, descriptor: TDesc) {
|
|
1399
|
+
this.#transport = transport;
|
|
1400
|
+
this.#descriptor = descriptor;
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
resume(ref: OperationRefData): OperationRef<TDesc, TProgress, TOutput> {
|
|
1404
|
+
return createPublicOperationRef(
|
|
1405
|
+
new RuntimeOperationRef<TDesc, TProgress, TOutput>(
|
|
1406
|
+
this.#transport,
|
|
1407
|
+
this.#descriptor,
|
|
1408
|
+
ref,
|
|
1409
|
+
),
|
|
1410
|
+
{},
|
|
1411
|
+
);
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1414
|
+
input(
|
|
1415
|
+
input: TInput,
|
|
1416
|
+
): TDesc["transfer"] extends undefined
|
|
1417
|
+
? OperationInputBuilder<TDesc, TProgress, TOutput>
|
|
1418
|
+
: TransferCapableOperationInputBuilder<TDesc, TProgress, TOutput> {
|
|
1419
|
+
return createOperationInputBuilder<TDesc, TProgress, TOutput>(
|
|
1420
|
+
this.#transport,
|
|
1421
|
+
this.#descriptor,
|
|
1422
|
+
input as OperationInputOf<TDesc>,
|
|
1423
|
+
) as TDesc["transfer"] extends undefined
|
|
1424
|
+
? OperationInputBuilder<TDesc, TProgress, TOutput>
|
|
1425
|
+
: TransferCapableOperationInputBuilder<TDesc, TProgress, TOutput>;
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
function isOperationControlErrorFrame(
|
|
1430
|
+
value: JsonValue,
|
|
1431
|
+
): value is OperationControlErrorFrame {
|
|
1432
|
+
return !!value && typeof value === "object" &&
|
|
1433
|
+
(value as { kind?: string }).kind === "error" &&
|
|
1434
|
+
typeof Reflect.get(value, "error") === "object";
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
function controlFrameToTransportError(
|
|
1438
|
+
frame: OperationControlErrorFrame,
|
|
1439
|
+
): TransportError {
|
|
1440
|
+
return createTransportError({
|
|
1441
|
+
code: "trellis.operation.control_error",
|
|
1442
|
+
message: "Trellis rejected the operation control request.",
|
|
1443
|
+
hint:
|
|
1444
|
+
"Check the operation state, then retry the action if it still applies.",
|
|
1445
|
+
context: {
|
|
1446
|
+
controlErrorType: frame.error.type,
|
|
1447
|
+
controlErrorMessage: frame.error.message,
|
|
1448
|
+
},
|
|
1449
|
+
});
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1452
|
+
function deferred<T>(): {
|
|
1453
|
+
promise: Promise<T>;
|
|
1454
|
+
resolve: (value: T | PromiseLike<T>) => void;
|
|
1455
|
+
} {
|
|
1456
|
+
let resolve!: (value: T | PromiseLike<T>) => void;
|
|
1457
|
+
const promise = new Promise<T>((r) => {
|
|
1458
|
+
resolve = r;
|
|
1459
|
+
});
|
|
1460
|
+
return { promise, resolve };
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
function createAcceptedReplayFilter<TProgress, TOutput>(
|
|
1464
|
+
accepted: AcceptedOperationEvent<TProgress, TOutput>,
|
|
1465
|
+
): (event: OperationEvent<TProgress, TOutput>) => boolean {
|
|
1466
|
+
return (event) => {
|
|
1467
|
+
return event.type === "accepted" &&
|
|
1468
|
+
event.snapshot.id === accepted.snapshot.id &&
|
|
1469
|
+
event.snapshot.service === accepted.snapshot.service &&
|
|
1470
|
+
event.snapshot.operation === accepted.snapshot.operation &&
|
|
1471
|
+
event.snapshot.revision === accepted.snapshot.revision &&
|
|
1472
|
+
event.snapshot.state === accepted.snapshot.state;
|
|
1473
|
+
};
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
function failedObservation<TProgress, TOutput>(
|
|
1477
|
+
error: TransportError | UnexpectedError,
|
|
1478
|
+
): OperationWatchObservation<TProgress, TOutput> {
|
|
1479
|
+
return {
|
|
1480
|
+
task: Promise.resolve(err(error)),
|
|
1481
|
+
};
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
async function dispatchOperationEventResult<TProgress, TOutput>(
|
|
1485
|
+
callbacks: OperationObserverCallbacks<TProgress, TOutput>,
|
|
1486
|
+
event: OperationEvent<TProgress, TOutput>,
|
|
1487
|
+
): Promise<Result<void, UnexpectedError>> {
|
|
1488
|
+
try {
|
|
1489
|
+
await dispatchObservedOperationEvent(callbacks, event);
|
|
1490
|
+
return ok(undefined);
|
|
1491
|
+
} catch (cause) {
|
|
1492
|
+
return err(toObservedCallbackError(cause));
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1496
|
+
function toObservedCallbackError(cause: unknown): UnexpectedError {
|
|
1497
|
+
return (cause instanceof UnexpectedError
|
|
1498
|
+
? cause
|
|
1499
|
+
: new UnexpectedError({ cause }))
|
|
1500
|
+
.withContext({ operationObserverCallback: true });
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
function isObservedCallbackError(
|
|
1504
|
+
error: TransportError | UnexpectedError,
|
|
1505
|
+
): boolean {
|
|
1506
|
+
return error instanceof UnexpectedError &&
|
|
1507
|
+
error.getContext().operationObserverCallback === true;
|
|
1508
|
+
}
|