@powerhousedao/reactor 6.0.0-dev.7 → 6.0.0-dev.77
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/dist/src/cache/collection-membership-cache.d.ts +13 -0
- package/dist/src/cache/collection-membership-cache.d.ts.map +1 -0
- package/dist/src/cache/document-meta-cache.d.ts.map +1 -1
- package/dist/src/cache/kysely-operation-index.d.ts +6 -1
- package/dist/src/cache/kysely-operation-index.d.ts.map +1 -1
- package/dist/src/cache/kysely-write-cache.d.ts +9 -2
- package/dist/src/cache/kysely-write-cache.d.ts.map +1 -1
- package/dist/src/cache/operation-index-types.d.ts +16 -2
- package/dist/src/cache/operation-index-types.d.ts.map +1 -1
- package/dist/src/cache/write/interfaces.d.ts +7 -2
- package/dist/src/cache/write/interfaces.d.ts.map +1 -1
- package/dist/src/client/reactor-client.d.ts +13 -10
- package/dist/src/client/reactor-client.d.ts.map +1 -1
- package/dist/src/client/types.d.ts +25 -6
- package/dist/src/client/types.d.ts.map +1 -1
- package/dist/src/core/reactor-builder.d.ts +23 -7
- package/dist/src/core/reactor-builder.d.ts.map +1 -1
- package/dist/src/core/reactor-client-builder.d.ts +5 -4
- package/dist/src/core/reactor-client-builder.d.ts.map +1 -1
- package/dist/src/core/reactor.d.ts +20 -80
- package/dist/src/core/reactor.d.ts.map +1 -1
- package/dist/src/core/types.d.ts +64 -28
- package/dist/src/core/types.d.ts.map +1 -1
- package/dist/src/core/utils.d.ts +39 -3
- package/dist/src/core/utils.d.ts.map +1 -1
- package/dist/src/events/types.d.ts +35 -10
- package/dist/src/events/types.d.ts.map +1 -1
- package/dist/src/executor/document-action-handler.d.ts +37 -0
- package/dist/src/executor/document-action-handler.d.ts.map +1 -0
- package/dist/src/executor/signature-verifier.d.ts +9 -0
- package/dist/src/executor/signature-verifier.d.ts.map +1 -0
- package/dist/src/executor/simple-job-executor-manager.d.ts +6 -1
- package/dist/src/executor/simple-job-executor-manager.d.ts.map +1 -1
- package/dist/src/executor/simple-job-executor.d.ts +6 -46
- package/dist/src/executor/simple-job-executor.d.ts.map +1 -1
- package/dist/src/executor/types.d.ts +1 -3
- package/dist/src/executor/types.d.ts.map +1 -1
- package/dist/src/executor/util.d.ts +12 -2
- package/dist/src/executor/util.d.ts.map +1 -1
- package/dist/src/index.d.ts +11 -9
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +19998 -61
- package/dist/src/job-tracker/in-memory-job-tracker.d.ts +4 -3
- package/dist/src/job-tracker/in-memory-job-tracker.d.ts.map +1 -1
- package/dist/src/job-tracker/interfaces.d.ts +3 -1
- package/dist/src/job-tracker/interfaces.d.ts.map +1 -1
- package/dist/src/logging/console.d.ts +1 -22
- package/dist/src/logging/console.d.ts.map +1 -1
- package/dist/src/logging/types.d.ts +1 -11
- package/dist/src/logging/types.d.ts.map +1 -1
- package/dist/src/processors/index.d.ts +1 -1
- package/dist/src/processors/index.d.ts.map +1 -1
- package/dist/src/processors/processor-manager.d.ts +2 -2
- package/dist/src/processors/processor-manager.d.ts.map +1 -1
- package/dist/src/processors/relational/types.d.ts +2 -0
- package/dist/src/processors/relational/types.d.ts.map +1 -0
- package/dist/src/processors/relational/utils.d.ts +2 -0
- package/dist/src/processors/relational/utils.d.ts.map +1 -0
- package/dist/src/processors/utils.d.ts +2 -2
- package/dist/src/processors/utils.d.ts.map +1 -1
- package/dist/src/queue/job-execution-handle.d.ts +3 -0
- package/dist/src/queue/job-execution-handle.d.ts.map +1 -1
- package/dist/src/queue/queue.d.ts +30 -1
- package/dist/src/queue/queue.d.ts.map +1 -1
- package/dist/src/queue/types.d.ts +4 -3
- package/dist/src/queue/types.d.ts.map +1 -1
- package/dist/src/read-models/base-read-model.d.ts +1 -1
- package/dist/src/read-models/base-read-model.d.ts.map +1 -1
- package/dist/src/read-models/coordinator.d.ts +2 -2
- package/dist/src/read-models/coordinator.d.ts.map +1 -1
- package/dist/src/read-models/document-view.d.ts +6 -3
- package/dist/src/read-models/document-view.d.ts.map +1 -1
- package/dist/src/read-models/interfaces.d.ts +1 -1
- package/dist/src/read-models/interfaces.d.ts.map +1 -1
- package/dist/src/registry/document-model-resolver.d.ts +29 -0
- package/dist/src/registry/document-model-resolver.d.ts.map +1 -0
- package/dist/src/registry/implementation.d.ts +4 -0
- package/dist/src/registry/implementation.d.ts.map +1 -1
- package/dist/src/registry/index.d.ts +3 -1
- package/dist/src/registry/index.d.ts.map +1 -1
- package/dist/src/registry/interfaces.d.ts +8 -0
- package/dist/src/registry/interfaces.d.ts.map +1 -1
- package/dist/src/shared/awaiter.d.ts +2 -2
- package/dist/src/shared/awaiter.d.ts.map +1 -1
- package/dist/src/shared/collect-all-pages.d.ts +7 -0
- package/dist/src/shared/collect-all-pages.d.ts.map +1 -0
- package/dist/src/shared/drive-url.d.ts +15 -0
- package/dist/src/shared/drive-url.d.ts.map +1 -0
- package/dist/src/shared/errors.d.ts +9 -0
- package/dist/src/shared/errors.d.ts.map +1 -1
- package/dist/src/shared/factories.d.ts +6 -2
- package/dist/src/shared/factories.d.ts.map +1 -1
- package/dist/src/shared/types.d.ts +32 -6
- package/dist/src/shared/types.d.ts.map +1 -1
- package/dist/src/signer/passthrough-signer.d.ts +1 -1
- package/dist/src/signer/passthrough-signer.d.ts.map +1 -1
- package/dist/src/storage/interfaces.d.ts +238 -124
- package/dist/src/storage/interfaces.d.ts.map +1 -1
- package/dist/src/storage/kysely/document-indexer.d.ts +8 -7
- package/dist/src/storage/kysely/document-indexer.d.ts.map +1 -1
- package/dist/src/storage/kysely/store.d.ts +5 -4
- package/dist/src/storage/kysely/store.d.ts.map +1 -1
- package/dist/src/storage/kysely/sync-cursor-storage.d.ts +1 -1
- package/dist/src/storage/kysely/sync-cursor-storage.d.ts.map +1 -1
- package/dist/src/storage/kysely/sync-dead-letter-storage.d.ts +17 -0
- package/dist/src/storage/kysely/sync-dead-letter-storage.d.ts.map +1 -0
- package/dist/src/storage/kysely/types.d.ts +22 -0
- package/dist/src/storage/kysely/types.d.ts.map +1 -1
- package/dist/src/storage/migrations/011_add_cursor_type_column.d.ts +3 -0
- package/dist/src/storage/migrations/011_add_cursor_type_column.d.ts.map +1 -0
- package/dist/src/storage/migrations/012_add_source_remote_column.d.ts +3 -0
- package/dist/src/storage/migrations/012_add_source_remote_column.d.ts.map +1 -0
- package/dist/src/storage/migrations/013_create_sync_dead_letters_table.d.ts +3 -0
- package/dist/src/storage/migrations/013_create_sync_dead_letters_table.d.ts.map +1 -0
- package/dist/src/storage/migrations/migrator.d.ts.map +1 -1
- package/dist/src/subs/default-error-handler.d.ts.map +1 -1
- package/dist/src/subs/subscription-notification-read-model.d.ts +3 -2
- package/dist/src/subs/subscription-notification-read-model.d.ts.map +1 -1
- package/dist/src/sync/batch-aggregator.d.ts +25 -0
- package/dist/src/sync/batch-aggregator.d.ts.map +1 -0
- package/dist/src/sync/buffered-mailbox.d.ts +36 -0
- package/dist/src/sync/buffered-mailbox.d.ts.map +1 -0
- package/dist/src/sync/channels/{gql-channel.d.ts → gql-req-channel.d.ts} +49 -42
- package/dist/src/sync/channels/gql-req-channel.d.ts.map +1 -0
- package/dist/src/sync/channels/gql-request-channel-factory.d.ts +32 -0
- package/dist/src/sync/channels/gql-request-channel-factory.d.ts.map +1 -0
- package/dist/src/sync/channels/gql-res-channel.d.ts +25 -0
- package/dist/src/sync/channels/gql-res-channel.d.ts.map +1 -0
- package/dist/src/sync/channels/gql-response-channel-factory.d.ts +13 -0
- package/dist/src/sync/channels/gql-response-channel-factory.d.ts.map +1 -0
- package/dist/src/sync/channels/index.d.ts +6 -4
- package/dist/src/sync/channels/index.d.ts.map +1 -1
- package/dist/src/sync/channels/interval-poll-timer.d.ts +40 -0
- package/dist/src/sync/channels/interval-poll-timer.d.ts.map +1 -0
- package/dist/src/sync/channels/poll-timer.d.ts +14 -0
- package/dist/src/sync/channels/poll-timer.d.ts.map +1 -0
- package/dist/src/sync/channels/utils.d.ts +15 -1
- package/dist/src/sync/channels/utils.d.ts.map +1 -1
- package/dist/src/sync/index.d.ts +10 -6
- package/dist/src/sync/index.d.ts.map +1 -1
- package/dist/src/sync/interfaces.d.ts +34 -21
- package/dist/src/sync/interfaces.d.ts.map +1 -1
- package/dist/src/sync/mailbox.d.ts +51 -12
- package/dist/src/sync/mailbox.d.ts.map +1 -1
- package/dist/src/sync/sync-awaiter.d.ts +34 -0
- package/dist/src/sync/sync-awaiter.d.ts.map +1 -0
- package/dist/src/sync/sync-builder.d.ts +5 -1
- package/dist/src/sync/sync-builder.d.ts.map +1 -1
- package/dist/src/sync/sync-manager.d.ts +21 -8
- package/dist/src/sync/sync-manager.d.ts.map +1 -1
- package/dist/src/sync/sync-operation.d.ts +4 -2
- package/dist/src/sync/sync-operation.d.ts.map +1 -1
- package/dist/src/sync/sync-status-tracker.d.ts +31 -0
- package/dist/src/sync/sync-status-tracker.d.ts.map +1 -0
- package/dist/src/sync/types.d.ts +90 -2
- package/dist/src/sync/types.d.ts.map +1 -1
- package/dist/src/sync/utils.d.ts +37 -2
- package/dist/src/sync/utils.d.ts.map +1 -1
- package/dist/src/utils/reshuffle.d.ts +22 -5
- package/dist/src/utils/reshuffle.d.ts.map +1 -1
- package/package.json +24 -20
- package/dist/src/actions/index.js +0 -76
- package/dist/src/actions/index.js.map +0 -1
- package/dist/src/cache/buffer/ring-buffer.js +0 -69
- package/dist/src/cache/buffer/ring-buffer.js.map +0 -1
- package/dist/src/cache/document-meta-cache-types.js +0 -2
- package/dist/src/cache/document-meta-cache-types.js.map +0 -1
- package/dist/src/cache/document-meta-cache.js +0 -128
- package/dist/src/cache/document-meta-cache.js.map +0 -1
- package/dist/src/cache/index.js +0 -2
- package/dist/src/cache/index.js.map +0 -1
- package/dist/src/cache/kysely-operation-index.js +0 -250
- package/dist/src/cache/kysely-operation-index.js.map +0 -1
- package/dist/src/cache/kysely-write-cache.js +0 -388
- package/dist/src/cache/kysely-write-cache.js.map +0 -1
- package/dist/src/cache/lru/lru-tracker.js +0 -96
- package/dist/src/cache/lru/lru-tracker.js.map +0 -1
- package/dist/src/cache/operation-index-types.js +0 -4
- package/dist/src/cache/operation-index-types.js.map +0 -1
- package/dist/src/cache/write/interfaces.js +0 -2
- package/dist/src/cache/write/interfaces.js.map +0 -1
- package/dist/src/cache/write-cache-types.js +0 -2
- package/dist/src/cache/write-cache-types.js.map +0 -1
- package/dist/src/client/reactor-client.js +0 -406
- package/dist/src/client/reactor-client.js.map +0 -1
- package/dist/src/client/types.js +0 -14
- package/dist/src/client/types.js.map +0 -1
- package/dist/src/core/reactor-builder.js +0 -231
- package/dist/src/core/reactor-builder.js.map +0 -1
- package/dist/src/core/reactor-client-builder.js +0 -123
- package/dist/src/core/reactor-client-builder.js.map +0 -1
- package/dist/src/core/reactor.js +0 -981
- package/dist/src/core/reactor.js.map +0 -1
- package/dist/src/core/types.js +0 -2
- package/dist/src/core/types.js.map +0 -1
- package/dist/src/core/utils.js +0 -171
- package/dist/src/core/utils.js.map +0 -1
- package/dist/src/events/event-bus.js +0 -53
- package/dist/src/events/event-bus.js.map +0 -1
- package/dist/src/events/interfaces.js +0 -2
- package/dist/src/events/interfaces.js.map +0 -1
- package/dist/src/events/types.js +0 -28
- package/dist/src/events/types.js.map +0 -1
- package/dist/src/executor/interfaces.js +0 -2
- package/dist/src/executor/interfaces.js.map +0 -1
- package/dist/src/executor/simple-job-executor-manager.js +0 -233
- package/dist/src/executor/simple-job-executor-manager.js.map +0 -1
- package/dist/src/executor/simple-job-executor.js +0 -898
- package/dist/src/executor/simple-job-executor.js.map +0 -1
- package/dist/src/executor/types.js +0 -11
- package/dist/src/executor/types.js.map +0 -1
- package/dist/src/executor/util.js +0 -184
- package/dist/src/executor/util.js.map +0 -1
- package/dist/src/index.js.map +0 -1
- package/dist/src/job-tracker/in-memory-job-tracker.js +0 -112
- package/dist/src/job-tracker/in-memory-job-tracker.js.map +0 -1
- package/dist/src/job-tracker/index.js +0 -2
- package/dist/src/job-tracker/index.js.map +0 -1
- package/dist/src/job-tracker/interfaces.js +0 -2
- package/dist/src/job-tracker/interfaces.js.map +0 -1
- package/dist/src/logging/console.js +0 -108
- package/dist/src/logging/console.js.map +0 -1
- package/dist/src/logging/types.js +0 -2
- package/dist/src/logging/types.js.map +0 -1
- package/dist/src/processors/index.js +0 -2
- package/dist/src/processors/index.js.map +0 -1
- package/dist/src/processors/processor-manager.js +0 -165
- package/dist/src/processors/processor-manager.js.map +0 -1
- package/dist/src/processors/types.d.ts +0 -63
- package/dist/src/processors/types.d.ts.map +0 -1
- package/dist/src/processors/types.js +0 -2
- package/dist/src/processors/types.js.map +0 -1
- package/dist/src/processors/utils.js +0 -58
- package/dist/src/processors/utils.js.map +0 -1
- package/dist/src/queue/interfaces.js +0 -2
- package/dist/src/queue/interfaces.js.map +0 -1
- package/dist/src/queue/job-execution-handle.js +0 -62
- package/dist/src/queue/job-execution-handle.js.map +0 -1
- package/dist/src/queue/queue.js +0 -384
- package/dist/src/queue/queue.js.map +0 -1
- package/dist/src/queue/types.js +0 -19
- package/dist/src/queue/types.js.map +0 -1
- package/dist/src/read-models/base-read-model.js +0 -143
- package/dist/src/read-models/base-read-model.js.map +0 -1
- package/dist/src/read-models/coordinator.js +0 -72
- package/dist/src/read-models/coordinator.js.map +0 -1
- package/dist/src/read-models/document-view.js +0 -375
- package/dist/src/read-models/document-view.js.map +0 -1
- package/dist/src/read-models/interfaces.js +0 -2
- package/dist/src/read-models/interfaces.js.map +0 -1
- package/dist/src/read-models/types.js +0 -2
- package/dist/src/read-models/types.js.map +0 -1
- package/dist/src/registry/implementation.js +0 -216
- package/dist/src/registry/implementation.js.map +0 -1
- package/dist/src/registry/index.js +0 -2
- package/dist/src/registry/index.js.map +0 -1
- package/dist/src/registry/interfaces.js +0 -2
- package/dist/src/registry/interfaces.js.map +0 -1
- package/dist/src/shared/awaiter.js +0 -123
- package/dist/src/shared/awaiter.js.map +0 -1
- package/dist/src/shared/consistency-tracker.js +0 -123
- package/dist/src/shared/consistency-tracker.js.map +0 -1
- package/dist/src/shared/errors.js +0 -75
- package/dist/src/shared/errors.js.map +0 -1
- package/dist/src/shared/factories.js +0 -33
- package/dist/src/shared/factories.js.map +0 -1
- package/dist/src/shared/types.js +0 -38
- package/dist/src/shared/types.js.map +0 -1
- package/dist/src/shared/utils.js +0 -8
- package/dist/src/shared/utils.js.map +0 -1
- package/dist/src/signer/passthrough-signer.js +0 -19
- package/dist/src/signer/passthrough-signer.js.map +0 -1
- package/dist/src/signer/types.js +0 -2
- package/dist/src/signer/types.js.map +0 -1
- package/dist/src/storage/consistency-aware-legacy-storage.d.ts +0 -33
- package/dist/src/storage/consistency-aware-legacy-storage.d.ts.map +0 -1
- package/dist/src/storage/consistency-aware-legacy-storage.js +0 -65
- package/dist/src/storage/consistency-aware-legacy-storage.js.map +0 -1
- package/dist/src/storage/index.js +0 -3
- package/dist/src/storage/index.js.map +0 -1
- package/dist/src/storage/interfaces.js +0 -19
- package/dist/src/storage/interfaces.js.map +0 -1
- package/dist/src/storage/kysely/document-indexer.js +0 -350
- package/dist/src/storage/kysely/document-indexer.js.map +0 -1
- package/dist/src/storage/kysely/keyframe-store.js +0 -64
- package/dist/src/storage/kysely/keyframe-store.js.map +0 -1
- package/dist/src/storage/kysely/store.js +0 -233
- package/dist/src/storage/kysely/store.js.map +0 -1
- package/dist/src/storage/kysely/sync-cursor-storage.js +0 -93
- package/dist/src/storage/kysely/sync-cursor-storage.js.map +0 -1
- package/dist/src/storage/kysely/sync-remote-storage.js +0 -133
- package/dist/src/storage/kysely/sync-remote-storage.js.map +0 -1
- package/dist/src/storage/kysely/types.js +0 -2
- package/dist/src/storage/kysely/types.js.map +0 -1
- package/dist/src/storage/migrations/001_create_operation_table.js +0 -41
- package/dist/src/storage/migrations/001_create_operation_table.js.map +0 -1
- package/dist/src/storage/migrations/002_create_keyframe_table.js +0 -27
- package/dist/src/storage/migrations/002_create_keyframe_table.js.map +0 -1
- package/dist/src/storage/migrations/003_create_document_table.js +0 -10
- package/dist/src/storage/migrations/003_create_document_table.js.map +0 -1
- package/dist/src/storage/migrations/004_create_document_relationship_table.js +0 -35
- package/dist/src/storage/migrations/004_create_document_relationship_table.js.map +0 -1
- package/dist/src/storage/migrations/005_create_indexer_state_table.js +0 -10
- package/dist/src/storage/migrations/005_create_indexer_state_table.js.map +0 -1
- package/dist/src/storage/migrations/006_create_document_snapshot_table.js +0 -49
- package/dist/src/storage/migrations/006_create_document_snapshot_table.js.map +0 -1
- package/dist/src/storage/migrations/007_create_slug_mapping_table.js +0 -24
- package/dist/src/storage/migrations/007_create_slug_mapping_table.js.map +0 -1
- package/dist/src/storage/migrations/008_create_view_state_table.js +0 -10
- package/dist/src/storage/migrations/008_create_view_state_table.js.map +0 -1
- package/dist/src/storage/migrations/009_create_operation_index_tables.js +0 -50
- package/dist/src/storage/migrations/009_create_operation_index_tables.js.map +0 -1
- package/dist/src/storage/migrations/010_create_sync_tables.js +0 -43
- package/dist/src/storage/migrations/010_create_sync_tables.js.map +0 -1
- package/dist/src/storage/migrations/index.js +0 -3
- package/dist/src/storage/migrations/index.js.map +0 -1
- package/dist/src/storage/migrations/migrator.js +0 -78
- package/dist/src/storage/migrations/migrator.js.map +0 -1
- package/dist/src/storage/migrations/run-migrations.js +0 -58
- package/dist/src/storage/migrations/run-migrations.js.map +0 -1
- package/dist/src/storage/migrations/types.js +0 -2
- package/dist/src/storage/migrations/types.js.map +0 -1
- package/dist/src/storage/txn.js +0 -42
- package/dist/src/storage/txn.js.map +0 -1
- package/dist/src/subs/default-error-handler.js +0 -27
- package/dist/src/subs/default-error-handler.js.map +0 -1
- package/dist/src/subs/react-subscription-manager.js +0 -185
- package/dist/src/subs/react-subscription-manager.js.map +0 -1
- package/dist/src/subs/subscription-notification-read-model.js +0 -62
- package/dist/src/subs/subscription-notification-read-model.js.map +0 -1
- package/dist/src/subs/types.js +0 -2
- package/dist/src/subs/types.js.map +0 -1
- package/dist/src/sync/channels/composite-channel-factory.d.ts +0 -30
- package/dist/src/sync/channels/composite-channel-factory.d.ts.map +0 -1
- package/dist/src/sync/channels/composite-channel-factory.js +0 -87
- package/dist/src/sync/channels/composite-channel-factory.js.map +0 -1
- package/dist/src/sync/channels/gql-channel-factory.d.ts +0 -25
- package/dist/src/sync/channels/gql-channel-factory.d.ts.map +0 -1
- package/dist/src/sync/channels/gql-channel-factory.js +0 -76
- package/dist/src/sync/channels/gql-channel-factory.js.map +0 -1
- package/dist/src/sync/channels/gql-channel.d.ts.map +0 -1
- package/dist/src/sync/channels/gql-channel.js +0 -423
- package/dist/src/sync/channels/gql-channel.js.map +0 -1
- package/dist/src/sync/channels/index.js +0 -6
- package/dist/src/sync/channels/index.js.map +0 -1
- package/dist/src/sync/channels/polling-channel.d.ts +0 -39
- package/dist/src/sync/channels/polling-channel.d.ts.map +0 -1
- package/dist/src/sync/channels/polling-channel.js +0 -72
- package/dist/src/sync/channels/polling-channel.js.map +0 -1
- package/dist/src/sync/channels/utils.js +0 -96
- package/dist/src/sync/channels/utils.js.map +0 -1
- package/dist/src/sync/errors.js +0 -17
- package/dist/src/sync/errors.js.map +0 -1
- package/dist/src/sync/index.js +0 -9
- package/dist/src/sync/index.js.map +0 -1
- package/dist/src/sync/interfaces.js +0 -2
- package/dist/src/sync/interfaces.js.map +0 -1
- package/dist/src/sync/mailbox.js +0 -59
- package/dist/src/sync/mailbox.js.map +0 -1
- package/dist/src/sync/sync-builder.js +0 -39
- package/dist/src/sync/sync-builder.js.map +0 -1
- package/dist/src/sync/sync-manager.js +0 -266
- package/dist/src/sync/sync-manager.js.map +0 -1
- package/dist/src/sync/sync-operation.js +0 -63
- package/dist/src/sync/sync-operation.js.map +0 -1
- package/dist/src/sync/types.js +0 -16
- package/dist/src/sync/types.js.map +0 -1
- package/dist/src/sync/utils.js +0 -78
- package/dist/src/sync/utils.js.map +0 -1
- package/dist/src/utils/reshuffle.js +0 -47
- package/dist/src/utils/reshuffle.js.map +0 -1
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { ISyncCursorStorage } from "../../storage/interfaces.js";
|
|
2
|
-
import type { IChannel } from "../interfaces.js";
|
|
3
|
-
import type { SyncOperation } from "../sync-operation.js";
|
|
4
|
-
import { Mailbox } from "../mailbox.js";
|
|
5
|
-
import type { SyncEnvelope } from "../types.js";
|
|
6
|
-
/**
|
|
7
|
-
* Channel for cursor-based polling by external clients.
|
|
8
|
-
*
|
|
9
|
-
* PollingChannel does NOT auto-remove operations from the outbox.
|
|
10
|
-
* Operations remain until explicitly acknowledged via cursor
|
|
11
|
-
* advancement through updateCursor().
|
|
12
|
-
*/
|
|
13
|
-
export declare class PollingChannel implements IChannel {
|
|
14
|
-
readonly inbox: Mailbox<SyncOperation>;
|
|
15
|
-
readonly outbox: Mailbox<SyncOperation>;
|
|
16
|
-
readonly deadLetter: Mailbox<SyncOperation>;
|
|
17
|
-
private readonly channelId;
|
|
18
|
-
private readonly remoteName;
|
|
19
|
-
private readonly cursorStorage;
|
|
20
|
-
private isShutdown;
|
|
21
|
-
constructor(channelId: string, remoteName: string, cursorStorage: ISyncCursorStorage);
|
|
22
|
-
shutdown(): void;
|
|
23
|
-
init(): Promise<void>;
|
|
24
|
-
/**
|
|
25
|
-
* Receives a sync envelope from a peer channel.
|
|
26
|
-
*
|
|
27
|
-
* @param envelope - The sync envelope to receive
|
|
28
|
-
* @throws {PollingChannelError} If channel is shutdown
|
|
29
|
-
*/
|
|
30
|
-
receive(envelope: SyncEnvelope): void;
|
|
31
|
-
/**
|
|
32
|
-
* Advances the cursor and removes acknowledged operations from outbox.
|
|
33
|
-
* Operations with ordinal <= cursorOrdinal are considered acknowledged.
|
|
34
|
-
*
|
|
35
|
-
* @param cursorOrdinal - The last processed ordinal (exclusive)
|
|
36
|
-
*/
|
|
37
|
-
updateCursor(cursorOrdinal: number): Promise<void>;
|
|
38
|
-
}
|
|
39
|
-
//# sourceMappingURL=polling-channel.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"polling-channel.d.ts","sourceRoot":"","sources":["../../../../src/sync/channels/polling-channel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAEtE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,EAAgB,YAAY,EAAE,MAAM,aAAa,CAAC;AAG9D;;;;;;GAMG;AACH,qBAAa,cAAe,YAAW,QAAQ;IAC7C,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IACvC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IACxC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IAE5C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAqB;IACnD,OAAO,CAAC,UAAU,CAAU;gBAG1B,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,kBAAkB;IAYnC,QAAQ,IAAI,IAAI;IAIV,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAE3B;;;;;OAKG;IACH,OAAO,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI;IAgBrC;;;;;OAKG;IACG,YAAY,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAmBzD"}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { PollingChannelError } from "../errors.js";
|
|
2
|
-
import { Mailbox } from "../mailbox.js";
|
|
3
|
-
import { envelopesToSyncOperations } from "./utils.js";
|
|
4
|
-
/**
|
|
5
|
-
* Channel for cursor-based polling by external clients.
|
|
6
|
-
*
|
|
7
|
-
* PollingChannel does NOT auto-remove operations from the outbox.
|
|
8
|
-
* Operations remain until explicitly acknowledged via cursor
|
|
9
|
-
* advancement through updateCursor().
|
|
10
|
-
*/
|
|
11
|
-
export class PollingChannel {
|
|
12
|
-
inbox;
|
|
13
|
-
outbox;
|
|
14
|
-
deadLetter;
|
|
15
|
-
channelId;
|
|
16
|
-
remoteName;
|
|
17
|
-
cursorStorage;
|
|
18
|
-
isShutdown;
|
|
19
|
-
constructor(channelId, remoteName, cursorStorage) {
|
|
20
|
-
this.channelId = channelId;
|
|
21
|
-
this.remoteName = remoteName;
|
|
22
|
-
this.cursorStorage = cursorStorage;
|
|
23
|
-
this.isShutdown = false;
|
|
24
|
-
this.inbox = new Mailbox();
|
|
25
|
-
this.outbox = new Mailbox();
|
|
26
|
-
this.deadLetter = new Mailbox();
|
|
27
|
-
}
|
|
28
|
-
shutdown() {
|
|
29
|
-
this.isShutdown = true;
|
|
30
|
-
}
|
|
31
|
-
async init() { }
|
|
32
|
-
/**
|
|
33
|
-
* Receives a sync envelope from a peer channel.
|
|
34
|
-
*
|
|
35
|
-
* @param envelope - The sync envelope to receive
|
|
36
|
-
* @throws {PollingChannelError} If channel is shutdown
|
|
37
|
-
*/
|
|
38
|
-
receive(envelope) {
|
|
39
|
-
if (this.isShutdown) {
|
|
40
|
-
throw new PollingChannelError(`Channel ${this.channelId} is shutdown and cannot receive envelopes`);
|
|
41
|
-
}
|
|
42
|
-
if (envelope.type === "operations" && envelope.operations) {
|
|
43
|
-
const syncOps = envelopesToSyncOperations(envelope, this.remoteName);
|
|
44
|
-
for (const syncOp of syncOps) {
|
|
45
|
-
syncOp.transported();
|
|
46
|
-
this.inbox.add(syncOp);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Advances the cursor and removes acknowledged operations from outbox.
|
|
52
|
-
* Operations with ordinal <= cursorOrdinal are considered acknowledged.
|
|
53
|
-
*
|
|
54
|
-
* @param cursorOrdinal - The last processed ordinal (exclusive)
|
|
55
|
-
*/
|
|
56
|
-
async updateCursor(cursorOrdinal) {
|
|
57
|
-
const cursor = {
|
|
58
|
-
remoteName: this.remoteName,
|
|
59
|
-
cursorOrdinal,
|
|
60
|
-
lastSyncedAtUtcMs: Date.now(),
|
|
61
|
-
};
|
|
62
|
-
await this.cursorStorage.upsert(cursor);
|
|
63
|
-
for (const op of this.outbox.items) {
|
|
64
|
-
const maxOrdinal = Math.max(...op.operations.map((o) => o.context.ordinal));
|
|
65
|
-
if (maxOrdinal <= cursorOrdinal) {
|
|
66
|
-
op.executed();
|
|
67
|
-
this.outbox.remove(op);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
//# sourceMappingURL=polling-channel.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"polling-channel.js","sourceRoot":"","sources":["../../../../src/sync/channels/polling-channel.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAGnD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,OAAO,cAAc;IAChB,KAAK,CAAyB;IAC9B,MAAM,CAAyB;IAC/B,UAAU,CAAyB;IAE3B,SAAS,CAAS;IAClB,UAAU,CAAS;IACnB,aAAa,CAAqB;IAC3C,UAAU,CAAU;IAE5B,YACE,SAAiB,EACjB,UAAkB,EAClB,aAAiC;QAEjC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;QAExB,IAAI,CAAC,KAAK,GAAG,IAAI,OAAO,EAAiB,CAAC;QAC1C,IAAI,CAAC,MAAM,GAAG,IAAI,OAAO,EAAiB,CAAC;QAC3C,IAAI,CAAC,UAAU,GAAG,IAAI,OAAO,EAAiB,CAAC;IACjD,CAAC;IAED,QAAQ;QACN,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,IAAI,KAAmB,CAAC;IAE9B;;;;;OAKG;IACH,OAAO,CAAC,QAAsB;QAC5B,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,MAAM,IAAI,mBAAmB,CAC3B,WAAW,IAAI,CAAC,SAAS,2CAA2C,CACrE,CAAC;QACJ,CAAC;QAED,IAAI,QAAQ,CAAC,IAAI,KAAK,YAAY,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC;YAC1D,MAAM,OAAO,GAAG,yBAAyB,CAAC,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;YACrE,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;gBAC7B,MAAM,CAAC,WAAW,EAAE,CAAC;gBACrB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACzB,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,YAAY,CAAC,aAAqB;QACtC,MAAM,MAAM,GAAiB;YAC3B,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,aAAa;YACb,iBAAiB,EAAE,IAAI,CAAC,GAAG,EAAE;SAC9B,CAAC;QAEF,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAExC,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YACnC,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CACzB,GAAG,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAC/C,CAAC;YACF,IAAI,UAAU,IAAI,aAAa,EAAE,CAAC;gBAChC,EAAE,CAAC,QAAQ,EAAE,CAAC;gBACd,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YACzB,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { SyncOperation } from "../sync-operation.js";
|
|
2
|
-
import { batchOperationsByDocument } from "../utils.js";
|
|
3
|
-
let syncOpCounter = 0;
|
|
4
|
-
/**
|
|
5
|
-
* Deserializes a signature from a comma-separated string back to a tuple.
|
|
6
|
-
*
|
|
7
|
-
* GraphQL serializes Signature tuples as comma-separated strings for transport.
|
|
8
|
-
* This function converts them back to the expected [string, string, string, string, string] format.
|
|
9
|
-
*/
|
|
10
|
-
function deserializeSignature(sig) {
|
|
11
|
-
if (Array.isArray(sig)) {
|
|
12
|
-
return sig;
|
|
13
|
-
}
|
|
14
|
-
return sig.split(", ");
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Deserializes signatures in an operation's signer context from strings back to tuples.
|
|
18
|
-
*
|
|
19
|
-
* When operations are transported via GraphQL, signatures are serialized as comma-separated
|
|
20
|
-
* strings. This function restores them to the Signature tuple format required for verification.
|
|
21
|
-
*/
|
|
22
|
-
function deserializeOperationSignatures(opWithContext) {
|
|
23
|
-
const signer = opWithContext.operation.action.context?.signer;
|
|
24
|
-
if (!signer?.signatures || signer.signatures.length === 0) {
|
|
25
|
-
return opWithContext;
|
|
26
|
-
}
|
|
27
|
-
const deserializedSignatures = signer.signatures.map(deserializeSignature);
|
|
28
|
-
const deserializedOperation = {
|
|
29
|
-
...opWithContext.operation,
|
|
30
|
-
action: {
|
|
31
|
-
...opWithContext.operation.action,
|
|
32
|
-
context: {
|
|
33
|
-
...opWithContext.operation.action.context,
|
|
34
|
-
signer: {
|
|
35
|
-
...signer,
|
|
36
|
-
signatures: deserializedSignatures,
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
return {
|
|
42
|
-
...opWithContext,
|
|
43
|
-
operation: deserializedOperation,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Converts a SyncEnvelope containing operations into a SyncOperation.
|
|
48
|
-
*
|
|
49
|
-
* Extracts the necessary metadata from the envelope's operations to create
|
|
50
|
-
* a sync operation that can be processed by the receiving channel. Also
|
|
51
|
-
* deserializes any signatures from comma-separated strings back to tuples,
|
|
52
|
-
* as GraphQL transport serializes Signature tuples for compatibility.
|
|
53
|
-
*
|
|
54
|
-
* @param envelope - The sync envelope containing operations
|
|
55
|
-
* @param remoteName - The name of the remote this sync operation is associated with
|
|
56
|
-
* @returns A new SyncOperation containing the envelope's operations with deserialized signatures
|
|
57
|
-
* @throws Error if envelope has no operations or operations array is empty
|
|
58
|
-
*/
|
|
59
|
-
export function envelopeToSyncOperation(envelope, remoteName) {
|
|
60
|
-
if (!envelope.operations || envelope.operations.length === 0) {
|
|
61
|
-
throw new Error("Cannot create SyncOperation from envelope without operations");
|
|
62
|
-
}
|
|
63
|
-
const deserializedOperations = envelope.operations.map(deserializeOperationSignatures);
|
|
64
|
-
const firstOp = deserializedOperations[0];
|
|
65
|
-
const documentId = firstOp.context.documentId;
|
|
66
|
-
const branch = firstOp.context.branch;
|
|
67
|
-
const scopes = [
|
|
68
|
-
...new Set(deserializedOperations.map((op) => op.context.scope)),
|
|
69
|
-
];
|
|
70
|
-
const syncOpId = `syncop-${envelope.channelMeta.id}-${Date.now()}-${syncOpCounter++}`;
|
|
71
|
-
return new SyncOperation(syncOpId, remoteName, documentId, scopes, branch, deserializedOperations);
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Converts a SyncEnvelope containing operations into multiple SyncOperations.
|
|
75
|
-
*
|
|
76
|
-
* This function batches operations by documentId, preserving cross-document ordering.
|
|
77
|
-
* For operations [a1, a2, a3, b1, b2, a4], it returns:
|
|
78
|
-
* - SyncOperation 1: [a1, a2, a3] for doc-a
|
|
79
|
-
* - SyncOperation 2: [b1, b2] for doc-b
|
|
80
|
-
* - SyncOperation 3: [a4] for doc-a
|
|
81
|
-
*
|
|
82
|
-
* This ensures operations are grouped for efficient processing while maintaining
|
|
83
|
-
* causality across documents.
|
|
84
|
-
*/
|
|
85
|
-
export function envelopesToSyncOperations(envelope, remoteName) {
|
|
86
|
-
if (!envelope.operations || envelope.operations.length === 0) {
|
|
87
|
-
return [];
|
|
88
|
-
}
|
|
89
|
-
const deserializedOps = envelope.operations.map(deserializeOperationSignatures);
|
|
90
|
-
const batches = batchOperationsByDocument(deserializedOps);
|
|
91
|
-
return batches.map((batch) => {
|
|
92
|
-
const syncOpId = `syncop-${envelope.channelMeta.id}-${Date.now()}-${syncOpCounter++}`;
|
|
93
|
-
return new SyncOperation(syncOpId, remoteName, batch.documentId, [batch.scope], batch.branch, batch.operations);
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/sync/channels/utils.ts"],"names":[],"mappings":"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"}
|
package/dist/src/sync/errors.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export class PollingChannelError extends Error {
|
|
2
|
-
constructor(message) {
|
|
3
|
-
super(message);
|
|
4
|
-
this.name = "PollingChannelError";
|
|
5
|
-
}
|
|
6
|
-
}
|
|
7
|
-
export class ChannelError extends Error {
|
|
8
|
-
source;
|
|
9
|
-
error;
|
|
10
|
-
constructor(source, error) {
|
|
11
|
-
super(`ChannelError[${source}]: ${error.message}`);
|
|
12
|
-
this.name = "ChannelError";
|
|
13
|
-
this.source = source;
|
|
14
|
-
this.error = error;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=errors.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/sync/errors.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AAED,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,MAAM,CAAqB;IAC3B,KAAK,CAAQ;IAEb,YAAY,MAA0B,EAAE,KAAY;QAClD,KAAK,CAAC,gBAAgB,MAAM,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACnD,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF"}
|
package/dist/src/sync/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export { ChannelErrorSource, SyncOperationStatus } from "./types.js";
|
|
2
|
-
export { SyncOperation, SyncOperationAggregateError, } from "./sync-operation.js";
|
|
3
|
-
export { Mailbox } from "./mailbox.js";
|
|
4
|
-
export { ChannelError, PollingChannelError } from "./errors.js";
|
|
5
|
-
export { PollingChannel, GqlChannelFactory, CompositeChannelFactory, } from "./channels/index.js";
|
|
6
|
-
export { SyncManager } from "./sync-manager.js";
|
|
7
|
-
export { SyncBuilder } from "./sync-builder.js";
|
|
8
|
-
export { createIdleHealth, filterOperations } from "./utils.js";
|
|
9
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/sync/index.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAErE,OAAO,EACL,aAAa,EACb,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAoB,MAAM,cAAc,CAAC;AAEzD,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEhE,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/sync/interfaces.ts"],"names":[],"mappings":""}
|
package/dist/src/sync/mailbox.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
export class MailboxAggregateError extends Error {
|
|
2
|
-
errors;
|
|
3
|
-
constructor(errors) {
|
|
4
|
-
const messages = errors.map((e) => e.message).join("; ");
|
|
5
|
-
super(`Mailbox callback failed with ${errors.length} error(s): ${messages}`);
|
|
6
|
-
this.name = "MailboxAggregateError";
|
|
7
|
-
this.errors = errors;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
export class Mailbox {
|
|
11
|
-
itemsMap = new Map();
|
|
12
|
-
addedCallbacks = [];
|
|
13
|
-
removedCallbacks = [];
|
|
14
|
-
get items() {
|
|
15
|
-
return Array.from(this.itemsMap.values());
|
|
16
|
-
}
|
|
17
|
-
get(id) {
|
|
18
|
-
return this.itemsMap.get(id);
|
|
19
|
-
}
|
|
20
|
-
add(item) {
|
|
21
|
-
this.itemsMap.set(item.id, item);
|
|
22
|
-
const callbacks = [...this.addedCallbacks];
|
|
23
|
-
const errors = [];
|
|
24
|
-
for (const callback of callbacks) {
|
|
25
|
-
try {
|
|
26
|
-
callback(item);
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
errors.push(error instanceof Error ? error : new Error(String(error)));
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
if (errors.length > 0) {
|
|
33
|
-
throw new MailboxAggregateError(errors);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
remove(item) {
|
|
37
|
-
this.itemsMap.delete(item.id);
|
|
38
|
-
const callbacks = [...this.removedCallbacks];
|
|
39
|
-
const errors = [];
|
|
40
|
-
for (const callback of callbacks) {
|
|
41
|
-
try {
|
|
42
|
-
callback(item);
|
|
43
|
-
}
|
|
44
|
-
catch (error) {
|
|
45
|
-
errors.push(error instanceof Error ? error : new Error(String(error)));
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (errors.length > 0) {
|
|
49
|
-
throw new MailboxAggregateError(errors);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
onAdded(callback) {
|
|
53
|
-
this.addedCallbacks.push(callback);
|
|
54
|
-
}
|
|
55
|
-
onRemoved(callback) {
|
|
56
|
-
this.removedCallbacks.push(callback);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
//# sourceMappingURL=mailbox.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mailbox.js","sourceRoot":"","sources":["../../../src/sync/mailbox.ts"],"names":[],"mappings":"AAMA,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAC9C,MAAM,CAAU;IAEhB,YAAY,MAAe;QACzB,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzD,KAAK,CACH,gCAAgC,MAAM,CAAC,MAAM,cAAc,QAAQ,EAAE,CACtE,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;QACpC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED,MAAM,OAAO,OAAO;IACV,QAAQ,GAAmB,IAAI,GAAG,EAAE,CAAC;IACrC,cAAc,GAAyB,EAAE,CAAC;IAC1C,gBAAgB,GAAyB,EAAE,CAAC;IAEpD,IAAI,KAAK;QACP,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED,GAAG,CAAC,EAAU;QACZ,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC/B,CAAC;IAED,GAAG,CAAC,IAAO;QACT,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QACjC,MAAM,SAAS,GAAG,CAAC,GAAG,IAAI,CAAC,cAAc,CAAC,CAAC;QAC3C,MAAM,MAAM,GAAY,EAAE,CAAC;QAC3B,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;YACjC,IAAI,CAAC;gBACH,QAAQ,CAAC,IAAI,CAAC,CAAC;YACjB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,CAAC,IAAI,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACzE,CAAC;QACH,CAAC;QACD,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC;IAED,MAAM,CAAC,IAAO;QACZ,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC9B,MAAM,SAAS,GAAG,CAAC,GAAG,IAAI,CAAC,gBAAgB,CAAC,CAAC;QAC7C,MAAM,MAAM,GAAY,EAAE,CAAC;QAC3B,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;YACjC,IAAI,CAAC;gBACH,QAAQ,CAAC,IAAI,CAAC,CAAC;YACjB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,CAAC,IAAI,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACzE,CAAC;QACH,CAAC;QACD,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC;IAED,OAAO,CAAC,QAA4B;QAClC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACrC,CAAC;IAED,SAAS,CAAC,QAA4B;QACpC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACvC,CAAC;CACF"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { KyselySyncCursorStorage } from "../storage/kysely/sync-cursor-storage.js";
|
|
2
|
-
import { KyselySyncRemoteStorage } from "../storage/kysely/sync-remote-storage.js";
|
|
3
|
-
import { SyncManager } from "./sync-manager.js";
|
|
4
|
-
export class SyncBuilder {
|
|
5
|
-
channelFactory;
|
|
6
|
-
remoteStorage;
|
|
7
|
-
cursorStorage;
|
|
8
|
-
withChannelFactory(factory) {
|
|
9
|
-
this.channelFactory = factory;
|
|
10
|
-
return this;
|
|
11
|
-
}
|
|
12
|
-
withRemoteStorage(storage) {
|
|
13
|
-
this.remoteStorage = storage;
|
|
14
|
-
return this;
|
|
15
|
-
}
|
|
16
|
-
withCursorStorage(storage) {
|
|
17
|
-
this.cursorStorage = storage;
|
|
18
|
-
return this;
|
|
19
|
-
}
|
|
20
|
-
build(reactor, logger, operationIndex, eventBus, db) {
|
|
21
|
-
const module = this.buildModule(reactor, logger, operationIndex, eventBus, db);
|
|
22
|
-
return module.syncManager;
|
|
23
|
-
}
|
|
24
|
-
buildModule(reactor, logger, operationIndex, eventBus, db) {
|
|
25
|
-
if (!this.channelFactory) {
|
|
26
|
-
throw new Error("Channel factory is required");
|
|
27
|
-
}
|
|
28
|
-
const remoteStorage = this.remoteStorage ?? new KyselySyncRemoteStorage(db);
|
|
29
|
-
const cursorStorage = this.cursorStorage ?? new KyselySyncCursorStorage(db);
|
|
30
|
-
const syncManager = new SyncManager(logger, remoteStorage, cursorStorage, this.channelFactory, operationIndex, reactor, eventBus);
|
|
31
|
-
return {
|
|
32
|
-
remoteStorage,
|
|
33
|
-
cursorStorage,
|
|
34
|
-
channelFactory: this.channelFactory,
|
|
35
|
-
syncManager,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
//# sourceMappingURL=sync-builder.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sync-builder.js","sourceRoot":"","sources":["../../../src/sync/sync-builder.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AACnF,OAAO,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AAGnF,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,OAAO,WAAW;IACd,cAAc,CAAmB;IACjC,aAAa,CAAsB;IACnC,aAAa,CAAsB;IAE3C,kBAAkB,CAAC,OAAwB;QACzC,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC;QAC9B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,iBAAiB,CAAC,OAA2B;QAC3C,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,iBAAiB,CAAC,OAA2B;QAC3C,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CACH,OAAiB,EACjB,MAAe,EACf,cAA+B,EAC/B,QAAmB,EACnB,EAAoB;QAEpB,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAC7B,OAAO,EACP,MAAM,EACN,cAAc,EACd,QAAQ,EACR,EAAE,CACH,CAAC;QACF,OAAO,MAAM,CAAC,WAAW,CAAC;IAC5B,CAAC;IAED,WAAW,CACT,OAAiB,EACjB,MAAe,EACf,cAA+B,EAC/B,QAAmB,EACnB,EAAoB;QAEpB,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACjD,CAAC;QAED,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,IAAI,IAAI,uBAAuB,CAAC,EAAE,CAAC,CAAC;QAC5E,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,IAAI,IAAI,uBAAuB,CAAC,EAAE,CAAC,CAAC;QAE5E,MAAM,WAAW,GAAG,IAAI,WAAW,CACjC,MAAM,EACN,aAAa,EACb,aAAa,EACb,IAAI,CAAC,cAAc,EACnB,cAAc,EACd,OAAO,EACP,QAAQ,CACT,CAAC;QAEF,OAAO;YACL,aAAa;YACb,aAAa;YACb,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,WAAW;SACZ,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
import { OperationEventTypes, } from "../events/types.js";
|
|
2
|
-
import { JobAwaiter } from "../shared/awaiter.js";
|
|
3
|
-
import { JobStatus, } from "../shared/types.js";
|
|
4
|
-
import { ChannelError } from "./errors.js";
|
|
5
|
-
import { SyncOperation } from "./sync-operation.js";
|
|
6
|
-
import { ChannelErrorSource, SyncOperationStatus } from "./types.js";
|
|
7
|
-
import { batchOperationsByDocument, createIdleHealth, filterOperations, } from "./utils.js";
|
|
8
|
-
export class SyncManager {
|
|
9
|
-
logger;
|
|
10
|
-
remoteStorage;
|
|
11
|
-
cursorStorage;
|
|
12
|
-
channelFactory;
|
|
13
|
-
_operationIndex;
|
|
14
|
-
reactor;
|
|
15
|
-
eventBus;
|
|
16
|
-
remotes;
|
|
17
|
-
awaiter;
|
|
18
|
-
isShutdown;
|
|
19
|
-
eventUnsubscribe;
|
|
20
|
-
loadJobs = new Map();
|
|
21
|
-
constructor(logger, remoteStorage, cursorStorage, channelFactory, operationIndex, reactor, eventBus) {
|
|
22
|
-
this.logger = logger;
|
|
23
|
-
this.remoteStorage = remoteStorage;
|
|
24
|
-
this.cursorStorage = cursorStorage;
|
|
25
|
-
this.channelFactory = channelFactory;
|
|
26
|
-
this._operationIndex = operationIndex;
|
|
27
|
-
this.reactor = reactor;
|
|
28
|
-
this.eventBus = eventBus;
|
|
29
|
-
this.remotes = new Map();
|
|
30
|
-
this.awaiter = new JobAwaiter(eventBus, (jobId, signal) => reactor.getJobStatus(jobId, signal));
|
|
31
|
-
this.isShutdown = false;
|
|
32
|
-
}
|
|
33
|
-
async startup() {
|
|
34
|
-
if (this.isShutdown) {
|
|
35
|
-
throw new Error("SyncManager is already shutdown and cannot be started");
|
|
36
|
-
}
|
|
37
|
-
const remoteRecords = await this.remoteStorage.list();
|
|
38
|
-
for (const record of remoteRecords) {
|
|
39
|
-
const channel = this.channelFactory.instance(record.id, record.name, record.channelConfig, this.cursorStorage, record.collectionId, record.filter);
|
|
40
|
-
try {
|
|
41
|
-
await channel.init();
|
|
42
|
-
}
|
|
43
|
-
catch (error) {
|
|
44
|
-
console.error(`Error initializing channel for remote ${record.name}: ${error instanceof Error ? error.message : String(error)}`);
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
const remote = {
|
|
48
|
-
id: record.id,
|
|
49
|
-
name: record.name,
|
|
50
|
-
collectionId: record.collectionId,
|
|
51
|
-
filter: record.filter,
|
|
52
|
-
options: record.options,
|
|
53
|
-
channel,
|
|
54
|
-
};
|
|
55
|
-
this.remotes.set(record.name, remote);
|
|
56
|
-
this.wireChannelCallbacks(remote);
|
|
57
|
-
}
|
|
58
|
-
this.eventUnsubscribe = this.eventBus.subscribe(OperationEventTypes.OPERATION_WRITTEN, (_type, event) => this.handleOperationWritten(event));
|
|
59
|
-
}
|
|
60
|
-
shutdown() {
|
|
61
|
-
this.isShutdown = true;
|
|
62
|
-
if (this.eventUnsubscribe) {
|
|
63
|
-
this.eventUnsubscribe();
|
|
64
|
-
this.eventUnsubscribe = undefined;
|
|
65
|
-
}
|
|
66
|
-
this.awaiter.shutdown();
|
|
67
|
-
for (const remote of this.remotes.values()) {
|
|
68
|
-
try {
|
|
69
|
-
remote.channel.shutdown();
|
|
70
|
-
}
|
|
71
|
-
catch (error) {
|
|
72
|
-
console.error(`Error shutting down channel for remote ${remote.name}: ${error instanceof Error ? error.message : String(error)}`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
this.remotes.clear();
|
|
76
|
-
return {
|
|
77
|
-
isShutdown: true,
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
getByName(name) {
|
|
81
|
-
const remote = this.remotes.get(name);
|
|
82
|
-
if (!remote) {
|
|
83
|
-
throw new Error(`Remote with name '${name}' does not exist`);
|
|
84
|
-
}
|
|
85
|
-
return remote;
|
|
86
|
-
}
|
|
87
|
-
getById(id) {
|
|
88
|
-
for (const remote of this.remotes.values()) {
|
|
89
|
-
if (remote.id === id) {
|
|
90
|
-
return remote;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
throw new Error(`Remote with id '${id}' does not exist`);
|
|
94
|
-
}
|
|
95
|
-
async add(name, collectionId, channelConfig, filter = { documentId: [], scope: [], branch: "" }, options = {}, id) {
|
|
96
|
-
if (this.isShutdown) {
|
|
97
|
-
throw new Error("SyncManager is shutdown and cannot add remotes");
|
|
98
|
-
}
|
|
99
|
-
if (this.remotes.has(name)) {
|
|
100
|
-
throw new Error(`Remote with name '${name}' already exists`);
|
|
101
|
-
}
|
|
102
|
-
this.logger.debug("Adding remote (@name, @collectionId, @channelConfig, @filter, @options, @id)", name, collectionId, channelConfig, filter, options, id);
|
|
103
|
-
const remoteId = id ?? crypto.randomUUID();
|
|
104
|
-
const status = {
|
|
105
|
-
push: createIdleHealth(),
|
|
106
|
-
pull: createIdleHealth(),
|
|
107
|
-
};
|
|
108
|
-
const remoteRecord = {
|
|
109
|
-
id: remoteId,
|
|
110
|
-
name,
|
|
111
|
-
collectionId,
|
|
112
|
-
channelConfig,
|
|
113
|
-
filter,
|
|
114
|
-
options,
|
|
115
|
-
status,
|
|
116
|
-
};
|
|
117
|
-
await this.remoteStorage.upsert(remoteRecord);
|
|
118
|
-
const channel = this.channelFactory.instance(remoteId, name, channelConfig, this.cursorStorage, collectionId, filter);
|
|
119
|
-
await channel.init();
|
|
120
|
-
const remote = {
|
|
121
|
-
id: remoteId,
|
|
122
|
-
name,
|
|
123
|
-
collectionId,
|
|
124
|
-
filter,
|
|
125
|
-
options,
|
|
126
|
-
channel,
|
|
127
|
-
};
|
|
128
|
-
this.remotes.set(name, remote);
|
|
129
|
-
this.wireChannelCallbacks(remote);
|
|
130
|
-
await this.backfillOutbox(remote, collectionId, filter);
|
|
131
|
-
return remote;
|
|
132
|
-
}
|
|
133
|
-
async backfillOutbox(remote, collectionId, filter) {
|
|
134
|
-
let historicalOps;
|
|
135
|
-
try {
|
|
136
|
-
historicalOps = await this._operationIndex.find(collectionId);
|
|
137
|
-
}
|
|
138
|
-
catch {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
if (historicalOps.items.length === 0) {
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
const opsWithContext = historicalOps.items.map((entry) => ({
|
|
145
|
-
operation: {
|
|
146
|
-
id: entry.id,
|
|
147
|
-
index: entry.index,
|
|
148
|
-
skip: entry.skip,
|
|
149
|
-
hash: entry.hash,
|
|
150
|
-
timestampUtcMs: entry.timestampUtcMs,
|
|
151
|
-
action: entry.action,
|
|
152
|
-
},
|
|
153
|
-
context: {
|
|
154
|
-
documentId: entry.documentId,
|
|
155
|
-
documentType: entry.documentType,
|
|
156
|
-
scope: entry.scope,
|
|
157
|
-
branch: entry.branch,
|
|
158
|
-
ordinal: entry.ordinal ?? 0,
|
|
159
|
-
},
|
|
160
|
-
}));
|
|
161
|
-
const filteredOps = filterOperations(opsWithContext, filter);
|
|
162
|
-
if (filteredOps.length === 0) {
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
const batches = batchOperationsByDocument(filteredOps);
|
|
166
|
-
for (const batch of batches) {
|
|
167
|
-
const syncOp = new SyncOperation(crypto.randomUUID(), remote.name, batch.documentId, [batch.scope], batch.branch, batch.operations);
|
|
168
|
-
remote.channel.outbox.add(syncOp);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
async remove(name) {
|
|
172
|
-
const remote = this.remotes.get(name);
|
|
173
|
-
if (!remote) {
|
|
174
|
-
throw new Error(`Remote with name '${name}' does not exist`);
|
|
175
|
-
}
|
|
176
|
-
await this.remoteStorage.remove(name);
|
|
177
|
-
remote.channel.shutdown();
|
|
178
|
-
this.remotes.delete(name);
|
|
179
|
-
}
|
|
180
|
-
list() {
|
|
181
|
-
return Array.from(this.remotes.values());
|
|
182
|
-
}
|
|
183
|
-
wireChannelCallbacks(remote) {
|
|
184
|
-
remote.channel.inbox.onAdded((syncOp) => {
|
|
185
|
-
this.handleInboxJob(remote, syncOp);
|
|
186
|
-
});
|
|
187
|
-
remote.channel.outbox.onAdded((syncOp) => {
|
|
188
|
-
this.handleOutboxJob(remote, syncOp);
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
handleOperationWritten(event) {
|
|
192
|
-
if (this.isShutdown) {
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
const sourceRemote = event.jobMeta?.sourceRemote;
|
|
196
|
-
for (const remote of this.remotes.values()) {
|
|
197
|
-
if (sourceRemote && remote.name === sourceRemote) {
|
|
198
|
-
continue;
|
|
199
|
-
}
|
|
200
|
-
const filteredOps = filterOperations(event.operations, remote.filter);
|
|
201
|
-
if (filteredOps.length === 0) {
|
|
202
|
-
continue;
|
|
203
|
-
}
|
|
204
|
-
const batches = batchOperationsByDocument(filteredOps);
|
|
205
|
-
for (const batch of batches) {
|
|
206
|
-
const syncOp = new SyncOperation(crypto.randomUUID(), remote.name, batch.documentId, [batch.scope], batch.branch, batch.operations);
|
|
207
|
-
remote.channel.outbox.add(syncOp);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
handleInboxJob(remote, syncOp) {
|
|
212
|
-
if (this.isShutdown) {
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
void this.applyInboxJob(remote, syncOp);
|
|
216
|
-
}
|
|
217
|
-
handleOutboxJob(remote, syncOp) {
|
|
218
|
-
syncOp.on((syncOp, _prev, next) => {
|
|
219
|
-
if (next === SyncOperationStatus.Applied) {
|
|
220
|
-
remote.channel.outbox.remove(syncOp);
|
|
221
|
-
}
|
|
222
|
-
else if (next === SyncOperationStatus.Error) {
|
|
223
|
-
remote.channel.outbox.remove(syncOp);
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
async applyInboxJob(remote, syncOp) {
|
|
228
|
-
const operations = syncOp.operations.map((op) => op.operation);
|
|
229
|
-
let jobInfo;
|
|
230
|
-
try {
|
|
231
|
-
jobInfo = await this.reactor.load(syncOp.documentId, syncOp.branch, operations, undefined, { sourceRemote: remote.name });
|
|
232
|
-
}
|
|
233
|
-
catch (error) {
|
|
234
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
235
|
-
const channelError = new ChannelError(ChannelErrorSource.Inbox, err);
|
|
236
|
-
syncOp.failed(channelError);
|
|
237
|
-
remote.channel.deadLetter.add(syncOp);
|
|
238
|
-
remote.channel.inbox.remove(syncOp);
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
let completedJobInfo;
|
|
242
|
-
try {
|
|
243
|
-
completedJobInfo = await this.awaiter.waitForJob(jobInfo.id);
|
|
244
|
-
}
|
|
245
|
-
catch (error) {
|
|
246
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
247
|
-
const channelError = new ChannelError(ChannelErrorSource.Inbox, err);
|
|
248
|
-
syncOp.failed(channelError);
|
|
249
|
-
remote.channel.deadLetter.add(syncOp);
|
|
250
|
-
remote.channel.inbox.remove(syncOp);
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
const jobKey = `${syncOp.documentId}:${syncOp.branch}`;
|
|
254
|
-
this.loadJobs.set(jobKey, completedJobInfo);
|
|
255
|
-
if (completedJobInfo.status === JobStatus.FAILED) {
|
|
256
|
-
const error = new ChannelError(ChannelErrorSource.Inbox, new Error(`Failed to apply operations: ${completedJobInfo.error?.message || "Unknown error"}`));
|
|
257
|
-
syncOp.failed(error);
|
|
258
|
-
remote.channel.deadLetter.add(syncOp);
|
|
259
|
-
}
|
|
260
|
-
else {
|
|
261
|
-
syncOp.executed();
|
|
262
|
-
}
|
|
263
|
-
remote.channel.inbox.remove(syncOp);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
//# sourceMappingURL=sync-manager.js.map
|