@enbox/dwn-sdk-js 0.3.9 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/browser.mjs +11 -11
- package/dist/browser.mjs.map +4 -4
- package/dist/esm/generated/precompiled-validators.js +783 -1206
- package/dist/esm/generated/precompiled-validators.js.map +1 -1
- package/dist/esm/src/core/dwn-constant.js +5 -0
- package/dist/esm/src/core/dwn-constant.js.map +1 -1
- package/dist/esm/src/core/dwn-error.js +13 -7
- package/dist/esm/src/core/dwn-error.js.map +1 -1
- package/dist/esm/src/core/grant-authorization.js +9 -18
- package/dist/esm/src/core/grant-authorization.js.map +1 -1
- package/dist/esm/src/core/message-reply.js.map +1 -1
- package/dist/esm/src/core/messages-grant-authorization.js +28 -61
- package/dist/esm/src/core/messages-grant-authorization.js.map +1 -1
- package/dist/esm/src/core/protocol-authorization-action.js +25 -27
- package/dist/esm/src/core/protocol-authorization-action.js.map +1 -1
- package/dist/esm/src/core/protocol-authorization-validation.js +31 -69
- package/dist/esm/src/core/protocol-authorization-validation.js.map +1 -1
- package/dist/esm/src/core/protocol-authorization.js +44 -118
- package/dist/esm/src/core/protocol-authorization.js.map +1 -1
- package/dist/esm/src/core/protocols-grant-authorization.js +5 -5
- package/dist/esm/src/core/protocols-grant-authorization.js.map +1 -1
- package/dist/esm/src/core/recording-validation-state-reader.js +84 -0
- package/dist/esm/src/core/recording-validation-state-reader.js.map +1 -0
- package/dist/esm/src/core/records-grant-authorization.js +11 -11
- package/dist/esm/src/core/records-grant-authorization.js.map +1 -1
- package/dist/esm/src/core/replication-apply.js +295 -0
- package/dist/esm/src/core/replication-apply.js.map +1 -0
- package/dist/esm/src/core/resumable-task-manager.js +5 -4
- package/dist/esm/src/core/resumable-task-manager.js.map +1 -1
- package/dist/esm/src/core/validation-state-reader.js +237 -0
- package/dist/esm/src/core/validation-state-reader.js.map +1 -0
- package/dist/esm/src/dwn.js +261 -16
- package/dist/esm/src/dwn.js.map +1 -1
- package/dist/esm/src/enums/dwn-interface-method.js +0 -1
- package/dist/esm/src/enums/dwn-interface-method.js.map +1 -1
- package/dist/esm/src/event-stream/durable-event-log.js +365 -0
- package/dist/esm/src/event-stream/durable-event-log.js.map +1 -0
- package/dist/esm/src/event-stream/event-emitter-wake-publisher.js +25 -0
- package/dist/esm/src/event-stream/event-emitter-wake-publisher.js.map +1 -0
- package/dist/esm/src/handlers/messages-query.js +159 -0
- package/dist/esm/src/handlers/messages-query.js.map +1 -0
- package/dist/esm/src/handlers/messages-read.js +5 -5
- package/dist/esm/src/handlers/messages-read.js.map +1 -1
- package/dist/esm/src/handlers/messages-subscribe.js +8 -8
- package/dist/esm/src/handlers/messages-subscribe.js.map +1 -1
- package/dist/esm/src/handlers/protocols-configure.js +30 -49
- package/dist/esm/src/handlers/protocols-configure.js.map +1 -1
- package/dist/esm/src/handlers/protocols-query.js +1 -1
- package/dist/esm/src/handlers/protocols-query.js.map +1 -1
- package/dist/esm/src/handlers/records-count.js +20 -11
- package/dist/esm/src/handlers/records-count.js.map +1 -1
- package/dist/esm/src/handlers/records-delete.js +20 -16
- package/dist/esm/src/handlers/records-delete.js.map +1 -1
- package/dist/esm/src/handlers/records-query.js +35 -11
- package/dist/esm/src/handlers/records-query.js.map +1 -1
- package/dist/esm/src/handlers/records-read.js +52 -42
- package/dist/esm/src/handlers/records-read.js.map +1 -1
- package/dist/esm/src/handlers/records-subscribe.js +107 -11
- package/dist/esm/src/handlers/records-subscribe.js.map +1 -1
- package/dist/esm/src/handlers/records-write.js +62 -116
- package/dist/esm/src/handlers/records-write.js.map +1 -1
- package/dist/esm/src/index.js +7 -8
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/interfaces/messages-query.js +49 -0
- package/dist/esm/src/interfaces/messages-query.js.map +1 -0
- package/dist/esm/src/interfaces/protocols-configure.js +7 -3
- package/dist/esm/src/interfaces/protocols-configure.js.map +1 -1
- package/dist/esm/src/interfaces/protocols-query.js +3 -4
- package/dist/esm/src/interfaces/protocols-query.js.map +1 -1
- package/dist/esm/src/interfaces/records-count.js +4 -3
- package/dist/esm/src/interfaces/records-count.js.map +1 -1
- package/dist/esm/src/interfaces/records-delete.js +21 -4
- package/dist/esm/src/interfaces/records-delete.js.map +1 -1
- package/dist/esm/src/interfaces/records-query.js +4 -3
- package/dist/esm/src/interfaces/records-query.js.map +1 -1
- package/dist/esm/src/interfaces/records-read.js +3 -3
- package/dist/esm/src/interfaces/records-read.js.map +1 -1
- package/dist/esm/src/interfaces/records-subscribe.js +4 -3
- package/dist/esm/src/interfaces/records-subscribe.js.map +1 -1
- package/dist/esm/src/interfaces/records-write.js +27 -13
- package/dist/esm/src/interfaces/records-write.js.map +1 -1
- package/dist/esm/src/protocols/permissions.js +27 -34
- package/dist/esm/src/protocols/permissions.js.map +1 -1
- package/dist/esm/src/store/index-level.js +24 -9
- package/dist/esm/src/store/index-level.js.map +1 -1
- package/dist/esm/src/store/level-wrapper.js +7 -0
- package/dist/esm/src/store/level-wrapper.js.map +1 -1
- package/dist/esm/src/store/message-store-level.js +536 -42
- package/dist/esm/src/store/message-store-level.js.map +1 -1
- package/dist/esm/src/store/storage-controller.js +58 -49
- package/dist/esm/src/store/storage-controller.js.map +1 -1
- package/dist/esm/src/types/message-types.js.map +1 -1
- package/dist/esm/src/types/validation-state-reader.js +2 -0
- package/dist/esm/src/types/validation-state-reader.js.map +1 -0
- package/dist/esm/src/utils/messages.js +17 -0
- package/dist/esm/src/utils/messages.js.map +1 -1
- package/dist/esm/src/utils/record-limit-occupancy.js +244 -0
- package/dist/esm/src/utils/record-limit-occupancy.js.map +1 -0
- package/dist/esm/src/utils/records.js +50 -14
- package/dist/esm/src/utils/records.js.map +1 -1
- package/dist/esm/src/utils/replication.js +85 -0
- package/dist/esm/src/utils/replication.js.map +1 -0
- package/dist/esm/tests/core/grant-authorization.spec.js +4 -4
- package/dist/esm/tests/core/grant-authorization.spec.js.map +1 -1
- package/dist/esm/tests/core/process-message-parity.spec.js +222 -0
- package/dist/esm/tests/core/process-message-parity.spec.js.map +1 -0
- package/dist/esm/tests/core/protocol-authorization.spec.js +5 -2
- package/dist/esm/tests/core/protocol-authorization.spec.js.map +1 -1
- package/dist/esm/tests/core/records-grant-authorization.spec.js +5 -5
- package/dist/esm/tests/core/records-grant-authorization.spec.js.map +1 -1
- package/dist/esm/tests/core/replication-apply.spec.js +274 -0
- package/dist/esm/tests/core/replication-apply.spec.js.map +1 -0
- package/dist/esm/tests/core/replication-replay-property.spec.js +350 -0
- package/dist/esm/tests/core/replication-replay-property.spec.js.map +1 -0
- package/dist/esm/tests/core/validation-read-closure.spec.js +469 -0
- package/dist/esm/tests/core/validation-read-closure.spec.js.map +1 -0
- package/dist/esm/tests/core/validation-state-reader.spec.js +716 -0
- package/dist/esm/tests/core/validation-state-reader.spec.js.map +1 -0
- package/dist/esm/tests/durable-event-log.spec.js +373 -0
- package/dist/esm/tests/durable-event-log.spec.js.map +1 -0
- package/dist/esm/tests/dwn.spec.js +620 -14
- package/dist/esm/tests/dwn.spec.js.map +1 -1
- package/dist/esm/tests/features/author-delegated-grant.spec.js +9 -6
- package/dist/esm/tests/features/author-delegated-grant.spec.js.map +1 -1
- package/dist/esm/tests/features/owner-delegated-grant.spec.js +1 -4
- package/dist/esm/tests/features/owner-delegated-grant.spec.js.map +1 -1
- package/dist/esm/tests/features/owner-signature.spec.js +1 -4
- package/dist/esm/tests/features/owner-signature.spec.js.map +1 -1
- package/dist/esm/tests/features/permissions.spec.js +165 -4
- package/dist/esm/tests/features/permissions.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-composition.spec.js +8 -11
- package/dist/esm/tests/features/protocol-composition.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-create-action.spec.js +1 -4
- package/dist/esm/tests/features/protocol-create-action.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-delete-action.spec.js +3 -5
- package/dist/esm/tests/features/protocol-delete-action.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-update-action.spec.js +3 -6
- package/dist/esm/tests/features/protocol-update-action.spec.js.map +1 -1
- package/dist/esm/tests/features/records-delivery.spec.js +1 -4
- package/dist/esm/tests/features/records-delivery.spec.js.map +1 -1
- package/dist/esm/tests/features/records-immutable.spec.js +1 -4
- package/dist/esm/tests/features/records-immutable.spec.js.map +1 -1
- package/dist/esm/tests/features/records-nested-query-scope.spec.js +281 -0
- package/dist/esm/tests/features/records-nested-query-scope.spec.js.map +1 -0
- package/dist/esm/tests/features/records-prune-cross-protocol.spec.js +3 -7
- package/dist/esm/tests/features/records-prune-cross-protocol.spec.js.map +1 -1
- package/dist/esm/tests/features/records-prune.spec.js +11 -22
- package/dist/esm/tests/features/records-prune.spec.js.map +1 -1
- package/dist/esm/tests/features/records-record-limit.spec.js +441 -231
- package/dist/esm/tests/features/records-record-limit.spec.js.map +1 -1
- package/dist/esm/tests/features/records-squash.spec.js +6 -4
- package/dist/esm/tests/features/records-squash.spec.js.map +1 -1
- package/dist/esm/tests/features/records-tags.spec.js +1 -4
- package/dist/esm/tests/features/records-tags.spec.js.map +1 -1
- package/dist/esm/tests/features/resumable-tasks.spec.js +3 -5
- package/dist/esm/tests/features/resumable-tasks.spec.js.map +1 -1
- package/dist/esm/tests/fuzz/message-store.fuzz.spec.js +1 -2
- package/dist/esm/tests/fuzz/message-store.fuzz.spec.js.map +1 -1
- package/dist/esm/tests/fuzz/process-message.fuzz.spec.js +2 -4
- package/dist/esm/tests/fuzz/process-message.fuzz.spec.js.map +1 -1
- package/dist/esm/tests/fuzz/schema-validation.fuzz.spec.js +1 -1
- package/dist/esm/tests/fuzz/schema-validation.fuzz.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-query.spec.js +246 -0
- package/dist/esm/tests/handlers/messages-query.spec.js.map +1 -0
- package/dist/esm/tests/handlers/messages-read.spec.js +2 -5
- package/dist/esm/tests/handlers/messages-read.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-subscribe.spec.js +3 -14
- package/dist/esm/tests/handlers/messages-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/handlers/protocols-configure.spec.js +27 -26
- package/dist/esm/tests/handlers/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/handlers/protocols-query.spec.js +1 -4
- package/dist/esm/tests/handlers/protocols-query.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-count.spec.js +1 -4
- package/dist/esm/tests/handlers/records-count.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-delete.spec.js +312 -30
- package/dist/esm/tests/handlers/records-delete.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-query.spec.js +32 -9
- package/dist/esm/tests/handlers/records-query.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-read.spec.js +4 -4
- package/dist/esm/tests/handlers/records-read.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-subscribe.spec.js +33 -14
- package/dist/esm/tests/handlers/records-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-write.spec.js +84 -38
- package/dist/esm/tests/handlers/records-write.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-delete.spec.js +69 -2
- package/dist/esm/tests/interfaces/records-delete.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-write.spec.js +4 -3
- package/dist/esm/tests/interfaces/records-write.spec.js.map +1 -1
- package/dist/esm/tests/protocols/permissions.spec.js +55 -6
- package/dist/esm/tests/protocols/permissions.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/aggregator.spec.js +1 -4
- package/dist/esm/tests/scenarios/aggregator.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/deleted-record.spec.js +1 -4
- package/dist/esm/tests/scenarios/deleted-record.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js +1 -4
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/nested-roles.spec.js +1 -4
- package/dist/esm/tests/scenarios/nested-roles.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/subscriptions.spec.js +1 -4
- package/dist/esm/tests/scenarios/subscriptions.spec.js.map +1 -1
- package/dist/esm/tests/store/message-store-level.spec.js +361 -5
- package/dist/esm/tests/store/message-store-level.spec.js.map +1 -1
- package/dist/esm/tests/store/message-store.spec.js +60 -0
- package/dist/esm/tests/store/message-store.spec.js.map +1 -1
- package/dist/esm/tests/test-event-stream.js +7 -3
- package/dist/esm/tests/test-event-stream.js.map +1 -1
- package/dist/esm/tests/test-stores.js +19 -9
- package/dist/esm/tests/test-stores.js.map +1 -1
- package/dist/esm/tests/test-suite.js +4 -4
- package/dist/esm/tests/test-suite.js.map +1 -1
- package/dist/esm/tests/utils/test-data-generator.js +25 -0
- package/dist/esm/tests/utils/test-data-generator.js.map +1 -1
- package/dist/esm/tests/utils/test-stub-generator.js.map +1 -1
- package/dist/esm/tests/utils/test-validation-state-reader.js +16 -0
- package/dist/esm/tests/utils/test-validation-state-reader.js.map +1 -0
- package/dist/types/generated/precompiled-validators.d.ts +6 -6
- package/dist/types/generated/precompiled-validators.d.ts.map +1 -1
- package/dist/types/src/core/core-protocol.d.ts +3 -3
- package/dist/types/src/core/core-protocol.d.ts.map +1 -1
- package/dist/types/src/core/dwn-constant.d.ts +5 -0
- package/dist/types/src/core/dwn-constant.d.ts.map +1 -1
- package/dist/types/src/core/dwn-error.d.ts +13 -7
- package/dist/types/src/core/dwn-error.d.ts.map +1 -1
- package/dist/types/src/core/grant-authorization.d.ts +5 -5
- package/dist/types/src/core/grant-authorization.d.ts.map +1 -1
- package/dist/types/src/core/message-reply.d.ts +5 -4
- package/dist/types/src/core/message-reply.d.ts.map +1 -1
- package/dist/types/src/core/messages-grant-authorization.d.ts +12 -15
- package/dist/types/src/core/messages-grant-authorization.d.ts.map +1 -1
- package/dist/types/src/core/protocol-authorization-action.d.ts +4 -5
- package/dist/types/src/core/protocol-authorization-action.d.ts.map +1 -1
- package/dist/types/src/core/protocol-authorization-validation.d.ts +13 -16
- package/dist/types/src/core/protocol-authorization-validation.d.ts.map +1 -1
- package/dist/types/src/core/protocol-authorization.d.ts +8 -33
- package/dist/types/src/core/protocol-authorization.d.ts.map +1 -1
- package/dist/types/src/core/protocols-grant-authorization.d.ts +4 -4
- package/dist/types/src/core/protocols-grant-authorization.d.ts.map +1 -1
- package/dist/types/src/core/recording-validation-state-reader.d.ts +75 -0
- package/dist/types/src/core/recording-validation-state-reader.d.ts.map +1 -0
- package/dist/types/src/core/records-grant-authorization.d.ts +8 -8
- package/dist/types/src/core/records-grant-authorization.d.ts.map +1 -1
- package/dist/types/src/core/replication-apply.d.ts +129 -0
- package/dist/types/src/core/replication-apply.d.ts.map +1 -0
- package/dist/types/src/core/resumable-task-manager.d.ts +1 -1
- package/dist/types/src/core/resumable-task-manager.d.ts.map +1 -1
- package/dist/types/src/core/validation-state-reader.d.ts +79 -0
- package/dist/types/src/core/validation-state-reader.d.ts.map +1 -0
- package/dist/types/src/dwn.d.ts +47 -13
- package/dist/types/src/dwn.d.ts.map +1 -1
- package/dist/types/src/enums/dwn-interface-method.d.ts +0 -1
- package/dist/types/src/enums/dwn-interface-method.d.ts.map +1 -1
- package/dist/types/src/event-stream/durable-event-log.d.ts +69 -0
- package/dist/types/src/event-stream/durable-event-log.d.ts.map +1 -0
- package/dist/types/src/event-stream/event-emitter-wake-publisher.d.ts +13 -0
- package/dist/types/src/event-stream/event-emitter-wake-publisher.d.ts.map +1 -0
- package/dist/types/src/handlers/messages-query.d.ts +20 -0
- package/dist/types/src/handlers/messages-query.d.ts.map +1 -0
- package/dist/types/src/handlers/messages-read.d.ts +1 -1
- package/dist/types/src/handlers/messages-read.d.ts.map +1 -1
- package/dist/types/src/handlers/messages-subscribe.d.ts.map +1 -1
- package/dist/types/src/handlers/protocols-configure.d.ts +0 -5
- package/dist/types/src/handlers/protocols-configure.d.ts.map +1 -1
- package/dist/types/src/handlers/records-count.d.ts +2 -1
- package/dist/types/src/handlers/records-count.d.ts.map +1 -1
- package/dist/types/src/handlers/records-delete.d.ts +2 -2
- package/dist/types/src/handlers/records-delete.d.ts.map +1 -1
- package/dist/types/src/handlers/records-query.d.ts +1 -1
- package/dist/types/src/handlers/records-query.d.ts.map +1 -1
- package/dist/types/src/handlers/records-read.d.ts +2 -1
- package/dist/types/src/handlers/records-read.d.ts.map +1 -1
- package/dist/types/src/handlers/records-subscribe.d.ts +4 -5
- package/dist/types/src/handlers/records-subscribe.d.ts.map +1 -1
- package/dist/types/src/handlers/records-write.d.ts +3 -11
- package/dist/types/src/handlers/records-write.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +16 -18
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/interfaces/messages-query.d.ts +23 -0
- package/dist/types/src/interfaces/messages-query.d.ts.map +1 -0
- package/dist/types/src/interfaces/protocols-configure.d.ts +3 -3
- package/dist/types/src/interfaces/protocols-configure.d.ts.map +1 -1
- package/dist/types/src/interfaces/protocols-query.d.ts +2 -2
- package/dist/types/src/interfaces/protocols-query.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-count.d.ts +3 -3
- package/dist/types/src/interfaces/records-count.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-delete.d.ts +11 -3
- package/dist/types/src/interfaces/records-delete.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-query.d.ts +3 -3
- package/dist/types/src/interfaces/records-query.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-read.d.ts +3 -3
- package/dist/types/src/interfaces/records-read.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-subscribe.d.ts +3 -3
- package/dist/types/src/interfaces/records-subscribe.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-write.d.ts +15 -7
- package/dist/types/src/interfaces/records-write.d.ts.map +1 -1
- package/dist/types/src/protocols/permissions.d.ts +9 -12
- package/dist/types/src/protocols/permissions.d.ts.map +1 -1
- package/dist/types/src/store/index-level.d.ts +10 -1
- package/dist/types/src/store/index-level.d.ts.map +1 -1
- package/dist/types/src/store/level-wrapper.d.ts +5 -0
- package/dist/types/src/store/level-wrapper.d.ts.map +1 -1
- package/dist/types/src/store/message-store-level.d.ts +94 -14
- package/dist/types/src/store/message-store-level.d.ts.map +1 -1
- package/dist/types/src/store/storage-controller.d.ts +17 -14
- package/dist/types/src/store/storage-controller.d.ts.map +1 -1
- package/dist/types/src/types/message-store.d.ts +29 -1
- package/dist/types/src/types/message-store.d.ts.map +1 -1
- package/dist/types/src/types/message-types.d.ts +2 -0
- package/dist/types/src/types/message-types.d.ts.map +1 -1
- package/dist/types/src/types/messages-types.d.ts +21 -55
- package/dist/types/src/types/messages-types.d.ts.map +1 -1
- package/dist/types/src/types/method-handler.d.ts +2 -2
- package/dist/types/src/types/method-handler.d.ts.map +1 -1
- package/dist/types/src/types/permission-types.d.ts +1 -1
- package/dist/types/src/types/subscriptions.d.ts +50 -39
- package/dist/types/src/types/subscriptions.d.ts.map +1 -1
- package/dist/types/src/types/validation-state-reader.d.ts +116 -0
- package/dist/types/src/types/validation-state-reader.d.ts.map +1 -0
- package/dist/types/src/utils/messages.d.ts +10 -0
- package/dist/types/src/utils/messages.d.ts.map +1 -1
- package/dist/types/src/utils/record-limit-occupancy.d.ts +40 -0
- package/dist/types/src/utils/record-limit-occupancy.d.ts.map +1 -0
- package/dist/types/src/utils/records.d.ts +25 -3
- package/dist/types/src/utils/records.d.ts.map +1 -1
- package/dist/types/src/utils/replication.d.ts +22 -0
- package/dist/types/src/utils/replication.d.ts.map +1 -0
- package/dist/types/tests/core/process-message-parity.spec.d.ts +2 -0
- package/dist/types/tests/core/process-message-parity.spec.d.ts.map +1 -0
- package/dist/types/tests/core/replication-apply.spec.d.ts +2 -0
- package/dist/types/tests/core/replication-apply.spec.d.ts.map +1 -0
- package/dist/types/tests/core/replication-replay-property.spec.d.ts +2 -0
- package/dist/types/tests/core/replication-replay-property.spec.d.ts.map +1 -0
- package/dist/types/tests/core/validation-read-closure.spec.d.ts +2 -0
- package/dist/types/tests/core/validation-read-closure.spec.d.ts.map +1 -0
- package/dist/types/tests/core/validation-state-reader.spec.d.ts +2 -0
- package/dist/types/tests/core/validation-state-reader.spec.d.ts.map +1 -0
- package/dist/types/tests/durable-event-log.spec.d.ts +2 -0
- package/dist/types/tests/durable-event-log.spec.d.ts.map +1 -0
- package/dist/types/tests/dwn.spec.d.ts.map +1 -1
- package/dist/types/tests/features/author-delegated-grant.spec.d.ts.map +1 -1
- package/dist/types/tests/features/owner-delegated-grant.spec.d.ts.map +1 -1
- package/dist/types/tests/features/owner-signature.spec.d.ts.map +1 -1
- package/dist/types/tests/features/permissions.spec.d.ts.map +1 -1
- package/dist/types/tests/features/protocol-composition.spec.d.ts.map +1 -1
- package/dist/types/tests/features/protocol-create-action.spec.d.ts.map +1 -1
- package/dist/types/tests/features/protocol-delete-action.spec.d.ts.map +1 -1
- package/dist/types/tests/features/protocol-update-action.spec.d.ts.map +1 -1
- package/dist/types/tests/features/records-delivery.spec.d.ts.map +1 -1
- package/dist/types/tests/features/records-immutable.spec.d.ts.map +1 -1
- package/dist/types/tests/features/records-nested-query-scope.spec.d.ts +2 -0
- package/dist/types/tests/features/records-nested-query-scope.spec.d.ts.map +1 -0
- package/dist/types/tests/features/records-prune-cross-protocol.spec.d.ts.map +1 -1
- package/dist/types/tests/features/records-prune.spec.d.ts.map +1 -1
- package/dist/types/tests/features/records-record-limit.spec.d.ts.map +1 -1
- package/dist/types/tests/features/records-squash.spec.d.ts.map +1 -1
- package/dist/types/tests/features/records-tags.spec.d.ts.map +1 -1
- package/dist/types/tests/features/resumable-tasks.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/messages-query.spec.d.ts +2 -0
- package/dist/types/tests/handlers/messages-query.spec.d.ts.map +1 -0
- package/dist/types/tests/handlers/messages-read.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/messages-subscribe.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/protocols-configure.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/protocols-query.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-count.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-delete.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-query.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-read.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-subscribe.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-write.spec.d.ts.map +1 -1
- package/dist/types/tests/scenarios/deleted-record.spec.d.ts.map +1 -1
- package/dist/types/tests/scenarios/end-to-end-tests.spec.d.ts.map +1 -1
- package/dist/types/tests/scenarios/nested-roles.spec.d.ts.map +1 -1
- package/dist/types/tests/scenarios/subscriptions.spec.d.ts.map +1 -1
- package/dist/types/tests/store/message-store.spec.d.ts.map +1 -1
- package/dist/types/tests/test-event-stream.d.ts +1 -1
- package/dist/types/tests/test-event-stream.d.ts.map +1 -1
- package/dist/types/tests/test-stores.d.ts +5 -4
- package/dist/types/tests/test-stores.d.ts.map +1 -1
- package/dist/types/tests/test-suite.d.ts +1 -2
- package/dist/types/tests/test-suite.d.ts.map +1 -1
- package/dist/types/tests/utils/test-data-generator.d.ts +20 -1
- package/dist/types/tests/utils/test-data-generator.d.ts.map +1 -1
- package/dist/types/tests/utils/test-validation-state-reader.d.ts +15 -0
- package/dist/types/tests/utils/test-validation-state-reader.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/core/core-protocol.ts +3 -3
- package/src/core/dwn-constant.ts +7 -1
- package/src/core/dwn-error.ts +13 -7
- package/src/core/grant-authorization.ts +11 -20
- package/src/core/message-reply.ts +6 -5
- package/src/core/messages-grant-authorization.ts +37 -100
- package/src/core/protocol-authorization-action.ts +29 -38
- package/src/core/protocol-authorization-validation.ts +41 -98
- package/src/core/protocol-authorization.ts +56 -202
- package/src/core/protocols-grant-authorization.ts +9 -9
- package/src/core/recording-validation-state-reader.ts +130 -0
- package/src/core/records-grant-authorization.ts +16 -16
- package/src/core/replication-apply.ts +412 -0
- package/src/core/resumable-task-manager.ts +10 -8
- package/src/core/validation-state-reader.ts +350 -0
- package/src/dwn.ts +417 -30
- package/src/enums/dwn-interface-method.ts +0 -1
- package/src/event-stream/durable-event-log.ts +509 -0
- package/src/event-stream/event-emitter-wake-publisher.ts +34 -0
- package/src/handlers/messages-query.ts +203 -0
- package/src/handlers/messages-read.ts +9 -10
- package/src/handlers/messages-subscribe.ts +12 -13
- package/src/handlers/protocols-configure.ts +37 -58
- package/src/handlers/protocols-query.ts +1 -1
- package/src/handlers/records-count.ts +24 -17
- package/src/handlers/records-delete.ts +29 -27
- package/src/handlers/records-query.ts +38 -17
- package/src/handlers/records-read.ts +63 -50
- package/src/handlers/records-subscribe.ts +132 -19
- package/src/handlers/records-write.ts +77 -168
- package/src/index.ts +16 -20
- package/src/interfaces/messages-query.ts +70 -0
- package/src/interfaces/protocols-configure.ts +12 -4
- package/src/interfaces/protocols-query.ts +4 -5
- package/src/interfaces/records-count.ts +9 -4
- package/src/interfaces/records-delete.ts +25 -5
- package/src/interfaces/records-query.ts +9 -4
- package/src/interfaces/records-read.ts +4 -4
- package/src/interfaces/records-subscribe.ts +9 -4
- package/src/interfaces/records-write.ts +41 -13
- package/src/protocols/permissions.ts +32 -52
- package/src/store/index-level.ts +30 -9
- package/src/store/level-wrapper.ts +9 -1
- package/src/store/message-store-level.ts +757 -47
- package/src/store/storage-controller.ts +74 -63
- package/src/types/message-store.ts +45 -2
- package/src/types/message-types.ts +3 -1
- package/src/types/messages-types.ts +26 -65
- package/src/types/method-handler.ts +3 -3
- package/src/types/permission-types.ts +1 -1
- package/src/types/subscriptions.ts +53 -42
- package/src/types/validation-state-reader.ts +127 -0
- package/src/utils/messages.ts +25 -1
- package/src/utils/record-limit-occupancy.ts +377 -0
- package/src/utils/records.ts +69 -13
- package/src/utils/replication.ts +122 -0
- package/dist/esm/src/core/record-chain.js +0 -64
- package/dist/esm/src/core/record-chain.js.map +0 -1
- package/dist/esm/src/event-stream/event-emitter-event-log.js +0 -334
- package/dist/esm/src/event-stream/event-emitter-event-log.js.map +0 -1
- package/dist/esm/src/handlers/messages-sync.js +0 -581
- package/dist/esm/src/handlers/messages-sync.js.map +0 -1
- package/dist/esm/src/interfaces/messages-sync.js +0 -54
- package/dist/esm/src/interfaces/messages-sync.js.map +0 -1
- package/dist/esm/src/smt/smt-store-level.js +0 -103
- package/dist/esm/src/smt/smt-store-level.js.map +0 -1
- package/dist/esm/src/smt/smt-store-memory.js +0 -41
- package/dist/esm/src/smt/smt-store-memory.js.map +0 -1
- package/dist/esm/src/smt/smt-utils.js +0 -129
- package/dist/esm/src/smt/smt-utils.js.map +0 -1
- package/dist/esm/src/smt/sparse-merkle-tree.js +0 -577
- package/dist/esm/src/smt/sparse-merkle-tree.js.map +0 -1
- package/dist/esm/src/state-index/state-index-level.js +0 -191
- package/dist/esm/src/state-index/state-index-level.js.map +0 -1
- package/dist/esm/src/sync/records-projection.js +0 -228
- package/dist/esm/src/sync/records-projection.js.map +0 -1
- package/dist/esm/src/types/smt-types.js +0 -5
- package/dist/esm/src/types/smt-types.js.map +0 -1
- package/dist/esm/src/types/state-index.js +0 -2
- package/dist/esm/src/types/state-index.js.map +0 -1
- package/dist/esm/tests/event-emitter-event-log.spec.js +0 -499
- package/dist/esm/tests/event-emitter-event-log.spec.js.map +0 -1
- package/dist/esm/tests/handlers/messages-sync.spec.js +0 -1771
- package/dist/esm/tests/handlers/messages-sync.spec.js.map +0 -1
- package/dist/esm/tests/smt/smt-store-level.spec.js +0 -132
- package/dist/esm/tests/smt/smt-store-level.spec.js.map +0 -1
- package/dist/esm/tests/smt/sparse-merkle-tree.spec.js +0 -732
- package/dist/esm/tests/smt/sparse-merkle-tree.spec.js.map +0 -1
- package/dist/esm/tests/state-index/state-index-level.spec.js +0 -245
- package/dist/esm/tests/state-index/state-index-level.spec.js.map +0 -1
- package/dist/esm/tests/sync/records-projection.spec.js +0 -245
- package/dist/esm/tests/sync/records-projection.spec.js.map +0 -1
- package/dist/types/src/core/record-chain.d.ts +0 -24
- package/dist/types/src/core/record-chain.d.ts.map +0 -1
- package/dist/types/src/event-stream/event-emitter-event-log.d.ts +0 -80
- package/dist/types/src/event-stream/event-emitter-event-log.d.ts.map +0 -1
- package/dist/types/src/handlers/messages-sync.d.ts +0 -83
- package/dist/types/src/handlers/messages-sync.d.ts.map +0 -1
- package/dist/types/src/interfaces/messages-sync.d.ts +0 -23
- package/dist/types/src/interfaces/messages-sync.d.ts.map +0 -1
- package/dist/types/src/smt/smt-store-level.d.ts +0 -32
- package/dist/types/src/smt/smt-store-level.d.ts.map +0 -1
- package/dist/types/src/smt/smt-store-memory.d.ts +0 -22
- package/dist/types/src/smt/smt-store-memory.d.ts.map +0 -1
- package/dist/types/src/smt/smt-utils.d.ts +0 -58
- package/dist/types/src/smt/smt-utils.d.ts.map +0 -1
- package/dist/types/src/smt/sparse-merkle-tree.d.ts +0 -124
- package/dist/types/src/smt/sparse-merkle-tree.d.ts.map +0 -1
- package/dist/types/src/state-index/state-index-level.d.ts +0 -83
- package/dist/types/src/state-index/state-index-level.d.ts.map +0 -1
- package/dist/types/src/sync/records-projection.d.ts +0 -98
- package/dist/types/src/sync/records-projection.d.ts.map +0 -1
- package/dist/types/src/types/smt-types.d.ts +0 -81
- package/dist/types/src/types/smt-types.d.ts.map +0 -1
- package/dist/types/src/types/state-index.d.ts +0 -90
- package/dist/types/src/types/state-index.d.ts.map +0 -1
- package/dist/types/tests/event-emitter-event-log.spec.d.ts +0 -2
- package/dist/types/tests/event-emitter-event-log.spec.d.ts.map +0 -1
- package/dist/types/tests/handlers/messages-sync.spec.d.ts +0 -2
- package/dist/types/tests/handlers/messages-sync.spec.d.ts.map +0 -1
- package/dist/types/tests/smt/smt-store-level.spec.d.ts +0 -2
- package/dist/types/tests/smt/smt-store-level.spec.d.ts.map +0 -1
- package/dist/types/tests/smt/sparse-merkle-tree.spec.d.ts +0 -2
- package/dist/types/tests/smt/sparse-merkle-tree.spec.d.ts.map +0 -1
- package/dist/types/tests/state-index/state-index-level.spec.d.ts +0 -2
- package/dist/types/tests/state-index/state-index-level.spec.d.ts.map +0 -1
- package/dist/types/tests/sync/records-projection.spec.d.ts +0 -2
- package/dist/types/tests/sync/records-projection.spec.d.ts.map +0 -1
- package/src/core/record-chain.ts +0 -99
- package/src/event-stream/event-emitter-event-log.ts +0 -430
- package/src/handlers/messages-sync.ts +0 -896
- package/src/interfaces/messages-sync.ts +0 -86
- package/src/smt/smt-store-level.ts +0 -143
- package/src/smt/smt-store-memory.ts +0 -53
- package/src/smt/smt-utils.ts +0 -149
- package/src/smt/sparse-merkle-tree.ts +0 -698
- package/src/state-index/state-index-level.ts +0 -239
- package/src/sync/records-projection.ts +0 -328
- package/src/types/smt-types.ts +0 -95
- package/src/types/state-index.ts +0 -100
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { MessageStore } from '../types/message-store.js';
|
|
2
1
|
import type { PermissionGrant } from '../protocols/permission-grant.js';
|
|
3
2
|
import type { ProtocolScope } from '../utils/permission-scope.js';
|
|
3
|
+
import type { ValidationStateReader } from '../types/validation-state-reader.js';
|
|
4
4
|
import type { PermissionConditions, RecordsPermissionScope } from '../types/permission-types.js';
|
|
5
5
|
import type { RecordsCountMessage, RecordsDeleteMessage, RecordsQueryMessage, RecordsReadMessage, RecordsSubscribeMessage, RecordsWriteMessage } from '../types/records-types.js';
|
|
6
6
|
|
|
@@ -18,10 +18,10 @@ export class RecordsGrantAuthorization {
|
|
|
18
18
|
expectedGrantor: string,
|
|
19
19
|
expectedGrantee: string,
|
|
20
20
|
permissionGrant: PermissionGrant,
|
|
21
|
-
|
|
21
|
+
validationStateReader: ValidationStateReader,
|
|
22
22
|
}): Promise<void> {
|
|
23
23
|
const {
|
|
24
|
-
recordsWriteMessage, expectedGrantor, expectedGrantee, permissionGrant,
|
|
24
|
+
recordsWriteMessage, expectedGrantor, expectedGrantee, permissionGrant, validationStateReader
|
|
25
25
|
} = input;
|
|
26
26
|
|
|
27
27
|
await GrantAuthorization.performBaseValidation({
|
|
@@ -29,7 +29,7 @@ export class RecordsGrantAuthorization {
|
|
|
29
29
|
expectedGrantor,
|
|
30
30
|
expectedGrantee,
|
|
31
31
|
permissionGrant,
|
|
32
|
-
|
|
32
|
+
validationStateReader
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
// NOTE: validated the invoked permission is for Records in GrantAuthorization.performBaseValidation()
|
|
@@ -40,7 +40,7 @@ export class RecordsGrantAuthorization {
|
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
42
|
* Authorizes a RecordsReadMessage using the given permission grant.
|
|
43
|
-
* @param
|
|
43
|
+
* @param validationStateReader Used to check if the given grant has been revoked.
|
|
44
44
|
*/
|
|
45
45
|
public static async authorizeRead(input: {
|
|
46
46
|
recordsReadMessage: RecordsReadMessage,
|
|
@@ -48,10 +48,10 @@ export class RecordsGrantAuthorization {
|
|
|
48
48
|
expectedGrantor: string,
|
|
49
49
|
expectedGrantee: string,
|
|
50
50
|
permissionGrant: PermissionGrant,
|
|
51
|
-
|
|
51
|
+
validationStateReader: ValidationStateReader,
|
|
52
52
|
}): Promise<void> {
|
|
53
53
|
const {
|
|
54
|
-
recordsReadMessage, recordsWriteMessageToBeRead, expectedGrantor, expectedGrantee, permissionGrant,
|
|
54
|
+
recordsReadMessage, recordsWriteMessageToBeRead, expectedGrantor, expectedGrantee, permissionGrant, validationStateReader
|
|
55
55
|
} = input;
|
|
56
56
|
|
|
57
57
|
await GrantAuthorization.performBaseValidation({
|
|
@@ -59,7 +59,7 @@ export class RecordsGrantAuthorization {
|
|
|
59
59
|
expectedGrantor,
|
|
60
60
|
expectedGrantee,
|
|
61
61
|
permissionGrant,
|
|
62
|
-
|
|
62
|
+
validationStateReader
|
|
63
63
|
});
|
|
64
64
|
|
|
65
65
|
// NOTE: validated the invoked permission is for Records in GrantAuthorization.performBaseValidation()
|
|
@@ -68,17 +68,17 @@ export class RecordsGrantAuthorization {
|
|
|
68
68
|
|
|
69
69
|
/**
|
|
70
70
|
* Authorizes the scope of a permission grant for RecordsQuery or RecordsSubscribe.
|
|
71
|
-
* @param
|
|
71
|
+
* @param validationStateReader Used to check if the grant has been revoked.
|
|
72
72
|
*/
|
|
73
73
|
public static async authorizeQueryOrSubscribe(input: {
|
|
74
74
|
incomingMessage: RecordsCountMessage | RecordsQueryMessage | RecordsSubscribeMessage,
|
|
75
75
|
expectedGrantor: string,
|
|
76
76
|
expectedGrantee: string,
|
|
77
77
|
permissionGrant: PermissionGrant,
|
|
78
|
-
|
|
78
|
+
validationStateReader: ValidationStateReader,
|
|
79
79
|
}): Promise<void> {
|
|
80
80
|
const {
|
|
81
|
-
incomingMessage, expectedGrantor, expectedGrantee, permissionGrant,
|
|
81
|
+
incomingMessage, expectedGrantor, expectedGrantee, permissionGrant, validationStateReader
|
|
82
82
|
} = input;
|
|
83
83
|
|
|
84
84
|
await GrantAuthorization.performBaseValidation({
|
|
@@ -86,7 +86,7 @@ export class RecordsGrantAuthorization {
|
|
|
86
86
|
expectedGrantor,
|
|
87
87
|
expectedGrantee,
|
|
88
88
|
permissionGrant,
|
|
89
|
-
|
|
89
|
+
validationStateReader
|
|
90
90
|
});
|
|
91
91
|
|
|
92
92
|
// The grant's protocol must match the query/subscribe filter's protocol.
|
|
@@ -107,7 +107,7 @@ export class RecordsGrantAuthorization {
|
|
|
107
107
|
|
|
108
108
|
/**
|
|
109
109
|
* Authorizes the scope of a permission grant for RecordsDelete.
|
|
110
|
-
* @param
|
|
110
|
+
* @param validationStateReader Used to check if the grant has been revoked.
|
|
111
111
|
*/
|
|
112
112
|
public static async authorizeDelete(input: {
|
|
113
113
|
recordsDeleteMessage: RecordsDeleteMessage,
|
|
@@ -115,10 +115,10 @@ export class RecordsGrantAuthorization {
|
|
|
115
115
|
expectedGrantor: string,
|
|
116
116
|
expectedGrantee: string,
|
|
117
117
|
permissionGrant: PermissionGrant,
|
|
118
|
-
|
|
118
|
+
validationStateReader: ValidationStateReader,
|
|
119
119
|
}): Promise<void> {
|
|
120
120
|
const {
|
|
121
|
-
recordsDeleteMessage, recordsWriteToDelete, expectedGrantor, expectedGrantee, permissionGrant,
|
|
121
|
+
recordsDeleteMessage, recordsWriteToDelete, expectedGrantor, expectedGrantee, permissionGrant, validationStateReader
|
|
122
122
|
} = input;
|
|
123
123
|
|
|
124
124
|
await GrantAuthorization.performBaseValidation({
|
|
@@ -126,7 +126,7 @@ export class RecordsGrantAuthorization {
|
|
|
126
126
|
expectedGrantor,
|
|
127
127
|
expectedGrantee,
|
|
128
128
|
permissionGrant,
|
|
129
|
-
|
|
129
|
+
validationStateReader
|
|
130
130
|
});
|
|
131
131
|
|
|
132
132
|
// NOTE: validated the invoked permission is for Records in GrantAuthorization.performBaseValidation()
|
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
import type { GenericMessage } from '../types/message-types.js';
|
|
2
|
+
import type { ProgressToken } from '../types/subscriptions.js';
|
|
3
|
+
import type { ProtocolDefinition } from '../types/protocols-types.js';
|
|
4
|
+
import type { ValidationStateReader } from '../types/validation-state-reader.js';
|
|
5
|
+
|
|
6
|
+
import { DwnErrorCode } from './dwn-error.js';
|
|
7
|
+
import { Encoder } from '../utils/encoder.js';
|
|
8
|
+
import { Message } from './message.js';
|
|
9
|
+
import { DwnInterfaceName, DwnMethodName } from '../enums/dwn-interface-method.js';
|
|
10
|
+
import { isCrossProtocolRef, parseCrossProtocolRef } from '../utils/protocols.js';
|
|
11
|
+
|
|
12
|
+
export type ReplicationApplyOptions = {
|
|
13
|
+
dataStream?: ReadableStream<Uint8Array>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type ReplicationApplyResult =
|
|
17
|
+
| {
|
|
18
|
+
kind: 'Applied';
|
|
19
|
+
/** True when the local store retained dependency ancestry but did not advance latest state. */
|
|
20
|
+
ancestryOnly?: true;
|
|
21
|
+
/** Local admission position, when the receiving store has a durable replication log. */
|
|
22
|
+
position?: ProgressToken;
|
|
23
|
+
}
|
|
24
|
+
| { kind: 'Duplicate' }
|
|
25
|
+
| { kind: 'Superseded' }
|
|
26
|
+
| { kind: 'Incomplete'; missing: DependencyRef[] }
|
|
27
|
+
| { kind: 'Invalid'; reason: string }
|
|
28
|
+
| { kind: 'Deferred'; reason: 'tenant-inactive' | 'resolver-unavailable' | 'storage' };
|
|
29
|
+
|
|
30
|
+
export type ReplicationApplyResultContext = {
|
|
31
|
+
protocolDefinition?: ProtocolDefinition;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Complete set of locally-missing ancestor recordIds for a missing-ancestor failure
|
|
35
|
+
* (immediate parent or record-chain construction), ordered root-first with the failure-named
|
|
36
|
+
* ancestor last, as computed by `missingAncestorRecordIdsFromReply()`. When present, the
|
|
37
|
+
* resulting `Incomplete` carries one ref per entry so the entire ancestry resolves in a
|
|
38
|
+
* single fetch pass instead of one ancestry level per retry.
|
|
39
|
+
*/
|
|
40
|
+
missingAncestorRecordIds?: string[];
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type DependencyRef =
|
|
44
|
+
| { type: 'Protocol'; protocol: string; messageCid?: string; terminal?: boolean }
|
|
45
|
+
| { type: 'InitialWrite'; recordId: string; protocol?: string; messageCid?: string; terminal?: boolean }
|
|
46
|
+
| { type: 'Parent'; recordId: string; protocol: string; messageCid?: string; terminal?: boolean }
|
|
47
|
+
| { type: 'Ancestor'; recordId: string; protocol?: string; messageCid?: string; terminal?: boolean }
|
|
48
|
+
| { type: 'Role'; protocol: string; protocolPath: string; recipient: string; contextPrefix?: string; messageCid?: string; terminal?: boolean }
|
|
49
|
+
| { type: 'Grant'; permissionGrantId: string; messageCid?: string; terminal?: boolean }
|
|
50
|
+
| { type: 'KeyDelivery'; protocol: string; contextId: string; messageCid?: string; terminal?: boolean }
|
|
51
|
+
| { type: 'CrossProtocolRef'; protocol: string; recordId: string; messageCid?: string; terminal?: boolean }
|
|
52
|
+
| { type: 'RecordData'; recordId: string; dataCid: string; protocol?: string; messageCid?: string; terminal?: boolean };
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Converts a regular handler reply into the structured result consumed by
|
|
56
|
+
* replication sync. The DWN handler remains the dependency authority; this
|
|
57
|
+
* adapter only gives the sync transport a typed way to distinguish missing
|
|
58
|
+
* dependencies from terminal invalid messages.
|
|
59
|
+
*/
|
|
60
|
+
export function replicationApplyResultFromReply(
|
|
61
|
+
message: GenericMessage,
|
|
62
|
+
reply: { status: { code: number; detail?: string }; position?: ProgressToken },
|
|
63
|
+
context: ReplicationApplyResultContext = {},
|
|
64
|
+
): ReplicationApplyResult {
|
|
65
|
+
const { code, detail = '' } = reply.status;
|
|
66
|
+
|
|
67
|
+
if (code === 202 || code === 204) {
|
|
68
|
+
return {
|
|
69
|
+
kind: 'Applied',
|
|
70
|
+
...(code === 204 ? { ancestryOnly: true as const } : {}),
|
|
71
|
+
...(reply.position === undefined ? {} : { position: reply.position }),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (code === 409) {
|
|
76
|
+
return { kind: 'Superseded' };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (getDwnErrorCode(detail) === DwnErrorCode.RecordsWriteNotAllowedAfterDelete) {
|
|
80
|
+
return { kind: 'Superseded' };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (isResolverFailure(detail)) {
|
|
84
|
+
return { kind: 'Deferred', reason: 'resolver-unavailable' };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const missing = dependencyRefsFromStatus(message, code, detail, context);
|
|
88
|
+
if (missing.length > 0) {
|
|
89
|
+
return { kind: 'Incomplete', missing };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (code >= 500) {
|
|
93
|
+
return { kind: 'Deferred', reason: 'storage' };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return { kind: 'Invalid', reason: detail || `replicated message rejected with status ${code}` };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Computes the complete set of locally-missing ancestor recordIds for a replicated message that
|
|
101
|
+
* failed on a missing ancestor — either the immediate parent referential check
|
|
102
|
+
* (`ProtocolAuthorizationParentRecordNotFound`) or record-chain construction
|
|
103
|
+
* (`ProtocolAuthorizationParentNotFoundConstructingRecordChain`).
|
|
104
|
+
*
|
|
105
|
+
* Both failures name a single ancestor, but the message's `contextId` names the full ancestor
|
|
106
|
+
* recordId chain, so every segment the failed check could not reach is presence-checked here and
|
|
107
|
+
* all absent segments are returned in one batch (ordered root-first, named ancestor last).
|
|
108
|
+
* Feeding the result to `replicationApplyResultFromReply()` via `ReplicationApplyResultContext`
|
|
109
|
+
* lets sync fetch the entire ancestry in a single pass instead of one level per retry.
|
|
110
|
+
*
|
|
111
|
+
* @returns the missing ancestor recordIds, or `undefined` when the reply is not a
|
|
112
|
+
* missing-ancestor failure or the chain cannot be determined from the message (callers
|
|
113
|
+
* then fall back to emitting the single ancestor named by the failure).
|
|
114
|
+
*/
|
|
115
|
+
export async function missingAncestorRecordIdsFromReply(
|
|
116
|
+
tenant: string,
|
|
117
|
+
message: GenericMessage,
|
|
118
|
+
reply: { status: { detail?: string } },
|
|
119
|
+
validationStateReader: ValidationStateReader,
|
|
120
|
+
): Promise<string[] | undefined> {
|
|
121
|
+
const detail = reply.status.detail ?? '';
|
|
122
|
+
const errorCode = getDwnErrorCode(detail);
|
|
123
|
+
|
|
124
|
+
let namedRecordId: string | undefined;
|
|
125
|
+
if (errorCode === DwnErrorCode.ProtocolAuthorizationParentRecordNotFound) {
|
|
126
|
+
namedRecordId = parentRecordIdFromMessage(message, detail);
|
|
127
|
+
} else if (errorCode === DwnErrorCode.ProtocolAuthorizationParentNotFoundConstructingRecordChain) {
|
|
128
|
+
namedRecordId = ancestorRecordIdFromDetail(detail);
|
|
129
|
+
} else {
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const contextId = (message as { contextId?: unknown }).contextId;
|
|
134
|
+
if (namedRecordId === undefined || typeof contextId !== 'string') {
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// `contextId` is the ancestor recordId chain ending with the record's own recordId. The failed
|
|
139
|
+
// check stopped at `namedRecordId`, so every segment below it is locally present; only the
|
|
140
|
+
// segments above it (closer to the root) still need a presence check. Presence means an initial
|
|
141
|
+
// write exists — exactly what record-chain construction reads for the segments above the
|
|
142
|
+
// immediate parent.
|
|
143
|
+
const ancestorRecordIds = contextId.split('/').slice(0, -1);
|
|
144
|
+
const namedIndex = ancestorRecordIds.indexOf(namedRecordId);
|
|
145
|
+
if (namedIndex === -1) {
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const missingRecordIds: string[] = [];
|
|
150
|
+
for (const ancestorRecordId of ancestorRecordIds.slice(0, namedIndex)) {
|
|
151
|
+
const initialWrite = await validationStateReader.fetchInitialWrite(tenant, ancestorRecordId);
|
|
152
|
+
if (initialWrite === undefined) {
|
|
153
|
+
missingRecordIds.push(ancestorRecordId);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
missingRecordIds.push(namedRecordId);
|
|
157
|
+
|
|
158
|
+
return missingRecordIds;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function dependencyRefsFromStatus(
|
|
162
|
+
message: GenericMessage,
|
|
163
|
+
code: number,
|
|
164
|
+
detail: string,
|
|
165
|
+
context: ReplicationApplyResultContext,
|
|
166
|
+
): DependencyRef[] {
|
|
167
|
+
const errorCode = getDwnErrorCode(detail);
|
|
168
|
+
switch (errorCode) {
|
|
169
|
+
case DwnErrorCode.ProtocolAuthorizationProtocolNotFound:
|
|
170
|
+
case DwnErrorCode.ProtocolsConfigureComposedProtocolNotInstalled:
|
|
171
|
+
return toRefList(protocolDependencyFromMessage(message, detail));
|
|
172
|
+
case DwnErrorCode.ProtocolAuthorizationParentRecordNotFound:
|
|
173
|
+
return parentDependenciesFromMessage(message, detail, context);
|
|
174
|
+
case DwnErrorCode.ProtocolAuthorizationCrossProtocolParentNotFound:
|
|
175
|
+
return toRefList(parentDependencyFromMessage(message, detail));
|
|
176
|
+
case DwnErrorCode.ProtocolAuthorizationParentNotFoundConstructingRecordChain:
|
|
177
|
+
return ancestorDependenciesFromMessage(message, detail, context);
|
|
178
|
+
case DwnErrorCode.RecordsWriteGetInitialWriteNotFound:
|
|
179
|
+
return toRefList(initialWriteDependencyFromMessage(message));
|
|
180
|
+
case DwnErrorCode.GrantAuthorizationGrantMissing:
|
|
181
|
+
return toRefList(grantDependencyFromMessage(message));
|
|
182
|
+
case DwnErrorCode.ProtocolAuthorizationMatchingRoleRecordNotFound:
|
|
183
|
+
return toRefList(roleDependencyFromMessage(message, context));
|
|
184
|
+
case DwnErrorCode.RecordsWriteMissingDataInPrevious:
|
|
185
|
+
case DwnErrorCode.RecordsWriteMissingEncodedDataInPrevious:
|
|
186
|
+
return toRefList(recordDataDependencyFromMessage(message));
|
|
187
|
+
default:
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (code === 404 && isRecordsDelete(message)) {
|
|
192
|
+
return [{ type: 'InitialWrite', recordId: getRecordsDeleteRecordId(message) }];
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return [];
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function toRefList(ref: DependencyRef | undefined): DependencyRef[] {
|
|
199
|
+
return ref === undefined ? [] : [ref];
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function getDwnErrorCode(detail: string): string | undefined {
|
|
203
|
+
const delimiter = detail.indexOf(':');
|
|
204
|
+
return delimiter === -1 ? undefined : detail.slice(0, delimiter);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function isResolverFailure(detail: string): boolean {
|
|
208
|
+
return getDwnErrorCode(detail) === DwnErrorCode.GeneralJwsVerifierGetPublicKeyNotFound;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function protocolDependencyFromMessage(message: GenericMessage, detail: string): DependencyRef | undefined {
|
|
212
|
+
const composedProtocol = /composed protocol '([^']+)'/.exec(detail)?.[1];
|
|
213
|
+
if (composedProtocol !== undefined) {
|
|
214
|
+
return { type: 'Protocol', protocol: composedProtocol };
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const protocol = (message.descriptor as Record<string, unknown>).protocol;
|
|
218
|
+
return typeof protocol === 'string' ? { type: 'Protocol', protocol } : undefined;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Emits the refs for an immediate-parent referential failure. The missing parent keeps its
|
|
223
|
+
* existing `Parent` ref; when the apply context carries the layer-batched missing-ancestor set
|
|
224
|
+
* (see `missingAncestorRecordIdsFromReply()`), an `Ancestor` ref is additionally emitted for
|
|
225
|
+
* every locally-absent segment above the parent, so the entire ancestry resolves in a single
|
|
226
|
+
* fetch pass instead of one level per retry.
|
|
227
|
+
*/
|
|
228
|
+
function parentDependenciesFromMessage(
|
|
229
|
+
message: GenericMessage,
|
|
230
|
+
detail: string,
|
|
231
|
+
context: ReplicationApplyResultContext,
|
|
232
|
+
): DependencyRef[] {
|
|
233
|
+
const parentRef = parentDependencyFromMessage(message, detail);
|
|
234
|
+
if (parentRef === undefined) {
|
|
235
|
+
return [];
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const protocol = (message.descriptor as Record<string, unknown>).protocol;
|
|
239
|
+
const protocolProperty = typeof protocol === 'string' ? { protocol } : {};
|
|
240
|
+
const ancestorRefs = (context.missingAncestorRecordIds ?? [])
|
|
241
|
+
.filter((recordId): boolean => recordId !== parentRef.recordId)
|
|
242
|
+
.map((recordId): DependencyRef => ({ type: 'Ancestor', recordId, ...protocolProperty }));
|
|
243
|
+
|
|
244
|
+
return [...ancestorRefs, parentRef];
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function parentDependencyFromMessage(
|
|
248
|
+
message: GenericMessage,
|
|
249
|
+
detail: string,
|
|
250
|
+
): Extract<DependencyRef, { type: 'Parent' }> | undefined {
|
|
251
|
+
const descriptor = message.descriptor as Record<string, unknown>;
|
|
252
|
+
const parentId = parentRecordIdFromMessage(message, detail);
|
|
253
|
+
const protocol = /in protocol '([^']+)'/.exec(detail)?.[1] ?? descriptor.protocol;
|
|
254
|
+
|
|
255
|
+
if (parentId === undefined || typeof protocol !== 'string') {
|
|
256
|
+
return undefined;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return { type: 'Parent', recordId: parentId, protocol };
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function parentRecordIdFromMessage(message: GenericMessage, detail: string): string | undefined {
|
|
263
|
+
const descriptor = message.descriptor as Record<string, unknown>;
|
|
264
|
+
return typeof descriptor.parentId === 'string'
|
|
265
|
+
? descriptor.parentId
|
|
266
|
+
: /parent record '([^']+)'/.exec(detail)?.[1];
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Emits `Ancestor` refs for a record-chain construction failure. When the apply context carries
|
|
271
|
+
* the layer-batched missing-ancestor set (see `missingAncestorRecordIdsFromReply()`), one ref is
|
|
272
|
+
* emitted per missing segment so the entire ancestry resolves in a single fetch pass; otherwise
|
|
273
|
+
* falls back to the single ancestor named by the failure detail (e.g. for messages that carry no
|
|
274
|
+
* `contextId` chain).
|
|
275
|
+
*/
|
|
276
|
+
function ancestorDependenciesFromMessage(
|
|
277
|
+
message: GenericMessage,
|
|
278
|
+
detail: string,
|
|
279
|
+
context: ReplicationApplyResultContext,
|
|
280
|
+
): DependencyRef[] {
|
|
281
|
+
const protocol = (message.descriptor as Record<string, unknown>).protocol;
|
|
282
|
+
const protocolProperty = typeof protocol === 'string' ? { protocol } : {};
|
|
283
|
+
|
|
284
|
+
const batchedRecordIds = context.missingAncestorRecordIds;
|
|
285
|
+
if (batchedRecordIds !== undefined && batchedRecordIds.length > 0) {
|
|
286
|
+
return batchedRecordIds.map((recordId): DependencyRef => ({ type: 'Ancestor', recordId, ...protocolProperty }));
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const namedRecordId = ancestorRecordIdFromDetail(detail);
|
|
290
|
+
if (namedRecordId === undefined) {
|
|
291
|
+
return [];
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
return [{ type: 'Ancestor', recordId: namedRecordId, ...protocolProperty }];
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function ancestorRecordIdFromDetail(detail: string): string | undefined {
|
|
298
|
+
return /ID ([^ ]+)/.exec(detail)?.[1];
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function initialWriteDependencyFromMessage(message: GenericMessage): DependencyRef | undefined {
|
|
302
|
+
if (!isRecordsWrite(message)) {
|
|
303
|
+
return undefined;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const protocol = (message.descriptor as Record<string, unknown>).protocol;
|
|
307
|
+
return {
|
|
308
|
+
type : 'InitialWrite',
|
|
309
|
+
recordId : message.recordId,
|
|
310
|
+
...(typeof protocol === 'string' ? { protocol } : {}),
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function grantDependencyFromMessage(message: GenericMessage): DependencyRef | undefined {
|
|
315
|
+
const descriptorGrantId = (message.descriptor as Record<string, unknown>).permissionGrantId;
|
|
316
|
+
if (typeof descriptorGrantId === 'string') {
|
|
317
|
+
return { type: 'Grant', permissionGrantId: descriptorGrantId };
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const payloadGrantId = getSignaturePayload(message)?.permissionGrantId;
|
|
321
|
+
return typeof payloadGrantId === 'string'
|
|
322
|
+
? { type: 'Grant', permissionGrantId: payloadGrantId }
|
|
323
|
+
: undefined;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function recordDataDependencyFromMessage(message: GenericMessage): DependencyRef | undefined {
|
|
327
|
+
if (!isRecordsWrite(message)) {
|
|
328
|
+
return undefined;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const descriptor = message.descriptor as Record<string, unknown>;
|
|
332
|
+
const dataCid = descriptor.dataCid;
|
|
333
|
+
const protocol = descriptor.protocol;
|
|
334
|
+
return typeof dataCid === 'string'
|
|
335
|
+
? {
|
|
336
|
+
type : 'RecordData',
|
|
337
|
+
recordId : message.recordId,
|
|
338
|
+
dataCid,
|
|
339
|
+
...(typeof protocol === 'string' ? { protocol } : {}),
|
|
340
|
+
}
|
|
341
|
+
: undefined;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function roleDependencyFromMessage(message: GenericMessage, context: ReplicationApplyResultContext): DependencyRef | undefined {
|
|
345
|
+
const descriptor = message.descriptor as Record<string, unknown>;
|
|
346
|
+
const filter = descriptor.filter as Record<string, unknown> | undefined;
|
|
347
|
+
const protocol = descriptor.protocol ?? filter?.protocol;
|
|
348
|
+
const protocolRole = getSignaturePayload(message)?.protocolRole;
|
|
349
|
+
const recipient = Message.getAuthor(message);
|
|
350
|
+
|
|
351
|
+
if (typeof protocol !== 'string' || typeof protocolRole !== 'string' || recipient === undefined) {
|
|
352
|
+
return undefined;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
let roleProtocol = protocol;
|
|
356
|
+
let roleProtocolPath = protocolRole;
|
|
357
|
+
if (isCrossProtocolRef(protocolRole)) {
|
|
358
|
+
const parsed = parseCrossProtocolRef(protocolRole);
|
|
359
|
+
const referencedProtocol = parsed === undefined ? undefined : context.protocolDefinition?.uses?.[parsed.alias];
|
|
360
|
+
if (parsed !== undefined && referencedProtocol !== undefined) {
|
|
361
|
+
roleProtocol = referencedProtocol;
|
|
362
|
+
roleProtocolPath = parsed.protocolPath;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
let contextId: string | undefined;
|
|
367
|
+
if (typeof descriptor.contextId === 'string') {
|
|
368
|
+
contextId = descriptor.contextId;
|
|
369
|
+
} else if (typeof filter?.contextId === 'string') {
|
|
370
|
+
contextId = filter.contextId;
|
|
371
|
+
}
|
|
372
|
+
const roleSegments = roleProtocolPath.split('/').length - 1;
|
|
373
|
+
const contextPrefix = roleSegments > 0 && contextId !== undefined
|
|
374
|
+
? contextId.split('/').slice(0, roleSegments).join('/')
|
|
375
|
+
: undefined;
|
|
376
|
+
|
|
377
|
+
return {
|
|
378
|
+
type : 'Role',
|
|
379
|
+
protocol : roleProtocol,
|
|
380
|
+
protocolPath : roleProtocolPath,
|
|
381
|
+
recipient,
|
|
382
|
+
...(contextPrefix === undefined ? {} : { contextPrefix }),
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function isRecordsWrite(message: GenericMessage): message is GenericMessage & { recordId: string } {
|
|
387
|
+
return message.descriptor.interface === DwnInterfaceName.Records &&
|
|
388
|
+
message.descriptor.method === DwnMethodName.Write &&
|
|
389
|
+
typeof (message as { recordId?: unknown }).recordId === 'string';
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function isRecordsDelete(message: GenericMessage): boolean {
|
|
393
|
+
return message.descriptor.interface === DwnInterfaceName.Records &&
|
|
394
|
+
message.descriptor.method === DwnMethodName.Delete;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function getRecordsDeleteRecordId(message: GenericMessage): string {
|
|
398
|
+
return (message.descriptor as unknown as { recordId: string }).recordId;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function getSignaturePayload(message: GenericMessage): Record<string, unknown> | undefined {
|
|
402
|
+
const payload = message.authorization?.signature.payload;
|
|
403
|
+
if (payload === undefined) {
|
|
404
|
+
return undefined;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
try {
|
|
408
|
+
return Encoder.base64UrlToObject(payload) as Record<string, unknown>;
|
|
409
|
+
} catch {
|
|
410
|
+
return undefined;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
@@ -11,6 +11,7 @@ export type ResumableTask = {
|
|
|
11
11
|
data: any;
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
+
type ResumableTaskHandler = (taskData: any) => Promise<unknown>;
|
|
14
15
|
|
|
15
16
|
export class ResumableTaskManager {
|
|
16
17
|
|
|
@@ -20,34 +21,34 @@ export class ResumableTaskManager {
|
|
|
20
21
|
public static readonly timeoutExtensionFrequencyInSeconds = 30;
|
|
21
22
|
|
|
22
23
|
private resumableTaskBatchSize = 100;
|
|
23
|
-
private readonly resumableTaskHandlers: { [key:string]:
|
|
24
|
+
private readonly resumableTaskHandlers: { [key:string]: ResumableTaskHandler };
|
|
24
25
|
|
|
25
26
|
public constructor(private readonly resumableTaskStore: ResumableTaskStore, storageController: StorageController) {
|
|
26
27
|
// assign resumable task handlers
|
|
27
28
|
this.resumableTaskHandlers = {
|
|
28
29
|
// NOTE: The arrow function is IMPORTANT here, else the `this` context will be lost within the invoked method.
|
|
29
30
|
// e.g. code within performRecordsDelete() won't know `this` refers to the `storageController` instance.
|
|
30
|
-
[ResumableTaskName.RecordsDelete] : async (task): Promise<
|
|
31
|
-
[ResumableTaskName.RecordsSquash] : async (task): Promise<
|
|
31
|
+
[ResumableTaskName.RecordsDelete] : async (task): Promise<unknown> => storageController.performRecordsDelete(task),
|
|
32
|
+
[ResumableTaskName.RecordsSquash] : async (task): Promise<unknown> => storageController.performRecordsSquash(task),
|
|
32
33
|
};
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
/**
|
|
36
37
|
* Runs a new resumable task.
|
|
37
38
|
*/
|
|
38
|
-
public async run(task: ResumableTask): Promise<
|
|
39
|
+
public async run<T = unknown>(task: ResumableTask): Promise<T> {
|
|
39
40
|
const timeoutInSeconds = ResumableTaskManager.timeoutExtensionFrequencyInSeconds * 2; // give ample time for extension to take place
|
|
40
41
|
|
|
41
42
|
// register the new resumable task before running it so that it can be resumed if it times out for any reason
|
|
42
43
|
const managedResumableTask = await this.resumableTaskStore.register(task, timeoutInSeconds);
|
|
43
|
-
|
|
44
|
+
return this.runWithAutomaticTimeoutExtension<T>(managedResumableTask);
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
/**
|
|
47
48
|
* Runs a resumable task with automatic timeout extension.
|
|
48
49
|
* Deletes the task from the resumable task store once it is completed.
|
|
49
50
|
*/
|
|
50
|
-
private async runWithAutomaticTimeoutExtension(managedTask: ManagedResumableTask): Promise<
|
|
51
|
+
private async runWithAutomaticTimeoutExtension<T = unknown>(managedTask: ManagedResumableTask): Promise<T> {
|
|
51
52
|
const timeoutInSeconds = ResumableTaskManager.timeoutExtensionFrequencyInSeconds * 2; // give ample time for extension to take place
|
|
52
53
|
|
|
53
54
|
let timer!: ReturnType<typeof setInterval>;
|
|
@@ -58,8 +59,9 @@ export class ResumableTaskManager {
|
|
|
58
59
|
}, ResumableTaskManager.timeoutExtensionFrequencyInSeconds * 1000);
|
|
59
60
|
|
|
60
61
|
const handler = this.resumableTaskHandlers[managedTask.task.name];
|
|
61
|
-
await handler(managedTask.task.data);
|
|
62
|
+
const result = await handler(managedTask.task.data) as T;
|
|
62
63
|
await this.resumableTaskStore.delete(managedTask.id);
|
|
64
|
+
return result;
|
|
63
65
|
} finally {
|
|
64
66
|
ResumableTaskManager.clearTimeoutExtensionTimer(timer);
|
|
65
67
|
}
|
|
@@ -112,4 +114,4 @@ export class ResumableTaskManager {
|
|
|
112
114
|
}
|
|
113
115
|
}
|
|
114
116
|
}
|
|
115
|
-
}
|
|
117
|
+
}
|