@powerhousedao/reactor 5.1.0-staging.0 → 5.2.0-dev.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/dist/src/actions/index.d.ts +24 -0
- package/dist/src/actions/index.d.ts.map +1 -0
- package/dist/src/actions/index.js +76 -0
- package/dist/src/actions/index.js.map +1 -0
- package/dist/src/cache/document-meta-cache-types.d.ts +114 -0
- package/dist/src/cache/document-meta-cache-types.d.ts.map +1 -0
- package/dist/src/cache/document-meta-cache-types.js +2 -0
- package/dist/src/cache/document-meta-cache-types.js.map +1 -0
- package/dist/src/cache/document-meta-cache.d.ts +30 -0
- package/dist/src/cache/document-meta-cache.d.ts.map +1 -0
- package/dist/src/cache/document-meta-cache.js +128 -0
- package/dist/src/cache/document-meta-cache.js.map +1 -0
- package/dist/src/cache/kysely-operation-index.d.ts +4 -2
- package/dist/src/cache/kysely-operation-index.d.ts.map +1 -1
- package/dist/src/cache/kysely-operation-index.js +67 -24
- package/dist/src/cache/kysely-operation-index.js.map +1 -1
- package/dist/src/cache/kysely-write-cache.d.ts.map +1 -1
- package/dist/src/cache/kysely-write-cache.js +3 -2
- package/dist/src/cache/kysely-write-cache.js.map +1 -1
- package/dist/src/cache/operation-index-types.d.ts +4 -3
- package/dist/src/cache/operation-index-types.d.ts.map +1 -1
- package/dist/src/cache/operation-index-types.js.map +1 -1
- package/dist/src/client/reactor-client.d.ts +16 -4
- package/dist/src/client/reactor-client.d.ts.map +1 -1
- package/dist/src/client/reactor-client.js +122 -5
- package/dist/src/client/reactor-client.js.map +1 -1
- package/dist/src/client/types.d.ts +22 -3
- package/dist/src/client/types.d.ts.map +1 -1
- package/dist/src/core/reactor-builder.d.ts +10 -9
- package/dist/src/core/reactor-builder.d.ts.map +1 -1
- package/dist/src/core/reactor-builder.js +73 -17
- package/dist/src/core/reactor-builder.js.map +1 -1
- package/dist/src/core/reactor-client-builder.d.ts +10 -1
- package/dist/src/core/reactor-client-builder.d.ts.map +1 -1
- package/dist/src/core/reactor-client-builder.js +16 -1
- package/dist/src/core/reactor-client-builder.js.map +1 -1
- package/dist/src/core/reactor.d.ts +11 -10
- package/dist/src/core/reactor.d.ts.map +1 -1
- package/dist/src/core/reactor.js +78 -91
- package/dist/src/core/reactor.js.map +1 -1
- package/dist/src/core/types.d.ts +22 -7
- package/dist/src/core/types.d.ts.map +1 -1
- package/dist/src/core/utils.d.ts +1 -2
- package/dist/src/core/utils.d.ts.map +1 -1
- package/dist/src/core/utils.js +2 -2
- package/dist/src/core/utils.js.map +1 -1
- package/dist/src/events/types.d.ts +1 -0
- package/dist/src/events/types.d.ts.map +1 -1
- package/dist/src/executor/simple-job-executor-manager.d.ts +3 -1
- package/dist/src/executor/simple-job-executor-manager.d.ts.map +1 -1
- package/dist/src/executor/simple-job-executor-manager.js +10 -7
- package/dist/src/executor/simple-job-executor-manager.js.map +1 -1
- package/dist/src/executor/simple-job-executor.d.ts +17 -3
- package/dist/src/executor/simple-job-executor.d.ts.map +1 -1
- package/dist/src/executor/simple-job-executor.js +329 -221
- package/dist/src/executor/simple-job-executor.js.map +1 -1
- package/dist/src/executor/types.d.ts +2 -0
- package/dist/src/executor/types.d.ts.map +1 -1
- package/dist/src/executor/types.js.map +1 -1
- package/dist/src/executor/util.d.ts +14 -5
- package/dist/src/executor/util.d.ts.map +1 -1
- package/dist/src/executor/util.js +36 -9
- package/dist/src/executor/util.js.map +1 -1
- package/dist/src/index.d.ts +12 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +10 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/logging/console.d.ts +11 -1
- package/dist/src/logging/console.d.ts.map +1 -1
- package/dist/src/logging/console.js +45 -14
- package/dist/src/logging/console.js.map +1 -1
- package/dist/src/logging/types.d.ts +1 -0
- package/dist/src/logging/types.d.ts.map +1 -1
- package/dist/src/processors/index.d.ts +3 -0
- package/dist/src/processors/index.d.ts.map +1 -0
- package/dist/src/processors/index.js +2 -0
- package/dist/src/processors/index.js.map +1 -0
- package/dist/src/processors/processor-manager.d.ts +38 -0
- package/dist/src/processors/processor-manager.d.ts.map +1 -0
- package/dist/src/processors/processor-manager.js +165 -0
- package/dist/src/processors/processor-manager.js.map +1 -0
- package/dist/src/processors/types.d.ts +63 -0
- package/dist/src/processors/types.d.ts.map +1 -0
- package/dist/src/processors/types.js +2 -0
- package/dist/src/processors/types.js.map +1 -0
- package/dist/src/processors/utils.d.ts +10 -0
- package/dist/src/processors/utils.d.ts.map +1 -0
- package/dist/src/processors/utils.js +58 -0
- package/dist/src/processors/utils.js.map +1 -0
- package/dist/src/queue/types.d.ts +2 -0
- package/dist/src/queue/types.d.ts.map +1 -1
- package/dist/src/queue/types.js.map +1 -1
- package/dist/src/read-models/base-read-model.d.ts +60 -0
- package/dist/src/read-models/base-read-model.d.ts.map +1 -0
- package/dist/src/read-models/base-read-model.js +143 -0
- package/dist/src/read-models/base-read-model.js.map +1 -0
- package/dist/src/read-models/coordinator.d.ts +3 -2
- package/dist/src/read-models/coordinator.d.ts.map +1 -1
- package/dist/src/read-models/coordinator.js +12 -13
- package/dist/src/read-models/coordinator.js.map +1 -1
- package/dist/src/read-models/document-view.d.ts +6 -7
- package/dist/src/read-models/document-view.d.ts.map +1 -1
- package/dist/src/read-models/document-view.js +18 -81
- package/dist/src/read-models/document-view.js.map +1 -1
- package/dist/src/read-models/types.d.ts +2 -1
- package/dist/src/read-models/types.d.ts.map +1 -1
- package/dist/src/registry/implementation.d.ts +42 -34
- package/dist/src/registry/implementation.d.ts.map +1 -1
- package/dist/src/registry/implementation.js +168 -48
- package/dist/src/registry/implementation.js.map +1 -1
- package/dist/src/registry/interfaces.d.ts +69 -8
- package/dist/src/registry/interfaces.d.ts.map +1 -1
- package/dist/src/shared/errors.d.ts +16 -0
- package/dist/src/shared/errors.d.ts.map +1 -1
- package/dist/src/shared/errors.js +28 -0
- package/dist/src/shared/errors.js.map +1 -1
- package/dist/src/shared/types.d.ts +4 -0
- package/dist/src/shared/types.d.ts.map +1 -1
- package/dist/src/shared/types.js.map +1 -1
- package/dist/src/signer/passthrough-signer.d.ts +9 -3
- package/dist/src/signer/passthrough-signer.d.ts.map +1 -1
- package/dist/src/signer/passthrough-signer.js +13 -0
- package/dist/src/signer/passthrough-signer.js.map +1 -1
- package/dist/src/signer/types.d.ts +2 -22
- package/dist/src/signer/types.d.ts.map +1 -1
- package/dist/src/storage/consistency-aware-legacy-storage.d.ts +33 -0
- package/dist/src/storage/consistency-aware-legacy-storage.d.ts.map +1 -0
- package/dist/src/storage/consistency-aware-legacy-storage.js +65 -0
- package/dist/src/storage/consistency-aware-legacy-storage.js.map +1 -0
- package/dist/src/storage/interfaces.d.ts +94 -1
- package/dist/src/storage/interfaces.d.ts.map +1 -1
- package/dist/src/storage/interfaces.js +2 -2
- package/dist/src/storage/interfaces.js.map +1 -1
- package/dist/src/storage/kysely/store.d.ts +1 -0
- package/dist/src/storage/kysely/store.d.ts.map +1 -1
- package/dist/src/storage/kysely/store.js +41 -4
- package/dist/src/storage/kysely/store.js.map +1 -1
- package/dist/src/storage/kysely/sync-cursor-storage.js +2 -2
- package/dist/src/storage/kysely/sync-cursor-storage.js.map +1 -1
- package/dist/src/storage/kysely/sync-remote-storage.js +8 -8
- package/dist/src/storage/kysely/sync-remote-storage.js.map +1 -1
- package/dist/src/storage/kysely/types.d.ts +6 -6
- package/dist/src/storage/migrations/001_create_operation_table.d.ts.map +1 -1
- package/dist/src/storage/migrations/001_create_operation_table.js +2 -1
- package/dist/src/storage/migrations/001_create_operation_table.js.map +1 -1
- package/dist/src/storage/migrations/008_create_view_state_table.d.ts +1 -1
- package/dist/src/storage/migrations/008_create_view_state_table.d.ts.map +1 -1
- package/dist/src/storage/migrations/008_create_view_state_table.js +2 -1
- package/dist/src/storage/migrations/008_create_view_state_table.js.map +1 -1
- package/dist/src/storage/migrations/009_create_operation_index_tables.js +1 -1
- package/dist/src/storage/migrations/009_create_operation_index_tables.js.map +1 -1
- package/dist/src/storage/migrations/010_create_sync_tables.js +5 -5
- package/dist/src/storage/migrations/010_create_sync_tables.js.map +1 -1
- package/dist/src/storage/migrations/migrator.d.ts +3 -2
- package/dist/src/storage/migrations/migrator.d.ts.map +1 -1
- package/dist/src/storage/migrations/migrator.js +29 -6
- package/dist/src/storage/migrations/migrator.js.map +1 -1
- package/dist/src/storage/txn.d.ts.map +1 -1
- package/dist/src/storage/txn.js +2 -3
- package/dist/src/storage/txn.js.map +1 -1
- package/dist/src/subs/subscription-notification-read-model.d.ts +17 -0
- package/dist/src/subs/subscription-notification-read-model.d.ts.map +1 -0
- package/dist/src/subs/subscription-notification-read-model.js +62 -0
- package/dist/src/subs/subscription-notification-read-model.js.map +1 -0
- package/dist/src/sync/channels/composite-channel-factory.d.ts +30 -0
- package/dist/src/sync/channels/composite-channel-factory.d.ts.map +1 -0
- package/dist/src/sync/channels/composite-channel-factory.js +87 -0
- package/dist/src/sync/channels/composite-channel-factory.js.map +1 -0
- package/dist/src/sync/channels/gql-channel-factory.d.ts +5 -2
- package/dist/src/sync/channels/gql-channel-factory.d.ts.map +1 -1
- package/dist/src/sync/channels/gql-channel-factory.js +8 -2
- package/dist/src/sync/channels/gql-channel-factory.js.map +1 -1
- package/dist/src/sync/channels/gql-channel.d.ts +28 -1
- package/dist/src/sync/channels/gql-channel.d.ts.map +1 -1
- package/dist/src/sync/channels/gql-channel.js +150 -22
- package/dist/src/sync/channels/gql-channel.js.map +1 -1
- package/dist/src/sync/channels/index.d.ts +2 -1
- package/dist/src/sync/channels/index.d.ts.map +1 -1
- package/dist/src/sync/channels/index.js +2 -1
- package/dist/src/sync/channels/index.js.map +1 -1
- package/dist/src/sync/channels/polling-channel.d.ts +39 -0
- package/dist/src/sync/channels/polling-channel.d.ts.map +1 -0
- package/dist/src/sync/channels/polling-channel.js +72 -0
- package/dist/src/sync/channels/polling-channel.js.map +1 -0
- package/dist/src/sync/channels/utils.d.ts +17 -2
- package/dist/src/sync/channels/utils.d.ts.map +1 -1
- package/dist/src/sync/channels/utils.js +76 -6
- package/dist/src/sync/channels/utils.js.map +1 -1
- package/dist/src/sync/errors.d.ts +1 -1
- package/dist/src/sync/errors.d.ts.map +1 -1
- package/dist/src/sync/errors.js +2 -2
- package/dist/src/sync/errors.js.map +1 -1
- package/dist/src/sync/index.d.ts +2 -2
- package/dist/src/sync/index.d.ts.map +1 -1
- package/dist/src/sync/index.js +2 -2
- package/dist/src/sync/index.js.map +1 -1
- package/dist/src/sync/interfaces.d.ts +16 -1
- package/dist/src/sync/interfaces.d.ts.map +1 -1
- package/dist/src/sync/sync-builder.d.ts +3 -2
- package/dist/src/sync/sync-builder.d.ts.map +1 -1
- package/dist/src/sync/sync-builder.js +4 -4
- package/dist/src/sync/sync-builder.js.map +1 -1
- package/dist/src/sync/sync-manager.d.ts +4 -1
- package/dist/src/sync/sync-manager.d.ts.map +1 -1
- package/dist/src/sync/sync-manager.js +65 -8
- package/dist/src/sync/sync-manager.js.map +1 -1
- package/dist/src/sync/utils.d.ts +19 -0
- package/dist/src/sync/utils.d.ts.map +1 -1
- package/dist/src/sync/utils.js +44 -0
- package/dist/src/sync/utils.js.map +1 -1
- package/package.json +3 -3
- package/dist/src/sync/channels/internal-channel.d.ts +0 -57
- package/dist/src/sync/channels/internal-channel.d.ts.map +0 -1
- package/dist/src/sync/channels/internal-channel.js +0 -106
- package/dist/src/sync/channels/internal-channel.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/sync/errors.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,
|
|
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.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ export type { ChannelConfig, ChannelHealth, SyncOperationErrorType, RemoteFilter
|
|
|
4
4
|
export { ChannelErrorSource, SyncOperationStatus } from "./types.js";
|
|
5
5
|
export { SyncOperation, SyncOperationAggregateError, } from "./sync-operation.js";
|
|
6
6
|
export { Mailbox, type MailboxItem } from "./mailbox.js";
|
|
7
|
-
export { ChannelError,
|
|
8
|
-
export {
|
|
7
|
+
export { ChannelError, PollingChannelError } from "./errors.js";
|
|
8
|
+
export { PollingChannel, GqlChannelFactory, CompositeChannelFactory, } from "./channels/index.js";
|
|
9
9
|
export { SyncManager } from "./sync-manager.js";
|
|
10
10
|
export { SyncBuilder } from "./sync-builder.js";
|
|
11
11
|
export { createIdleHealth, filterOperations } from "./utils.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/sync/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,QAAQ,EACR,eAAe,EACf,YAAY,EACZ,MAAM,GACP,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,YAAY,EACV,aAAa,EACb,aAAa,EACb,sBAAsB,EACtB,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,WAAW,GACZ,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAErE,OAAO,EACL,aAAa,EACb,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAEzD,OAAO,EAAE,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/sync/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,QAAQ,EACR,eAAe,EACf,YAAY,EACZ,MAAM,GACP,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,YAAY,EACV,aAAa,EACb,aAAa,EACb,sBAAsB,EACtB,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,WAAW,GACZ,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAErE,OAAO,EACL,aAAa,EACb,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAE,KAAK,WAAW,EAAE,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"}
|
package/dist/src/sync/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { ChannelErrorSource, SyncOperationStatus } from "./types.js";
|
|
2
2
|
export { SyncOperation, SyncOperationAggregateError, } from "./sync-operation.js";
|
|
3
3
|
export { Mailbox } from "./mailbox.js";
|
|
4
|
-
export { ChannelError,
|
|
5
|
-
export {
|
|
4
|
+
export { ChannelError, PollingChannelError } from "./errors.js";
|
|
5
|
+
export { PollingChannel, GqlChannelFactory, CompositeChannelFactory, } from "./channels/index.js";
|
|
6
6
|
export { SyncManager } from "./sync-manager.js";
|
|
7
7
|
export { SyncBuilder } from "./sync-builder.js";
|
|
8
8
|
export { createIdleHealth, filterOperations } from "./utils.js";
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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"}
|
|
@@ -33,10 +33,23 @@ export interface IChannel {
|
|
|
33
33
|
* These sync operations require manual intervention or should be logged for debugging.
|
|
34
34
|
*/
|
|
35
35
|
deadLetter: Mailbox<SyncOperation>;
|
|
36
|
+
/**
|
|
37
|
+
* Initializes the channel asynchronously.
|
|
38
|
+
* For remote channels, this typically involves registering the channel on the remote server.
|
|
39
|
+
* Must be called after construction before the channel is used.
|
|
40
|
+
*/
|
|
41
|
+
init(): Promise<void>;
|
|
36
42
|
/**
|
|
37
43
|
* Shuts down the channel and prevents further operations.
|
|
38
44
|
*/
|
|
39
45
|
shutdown(): void;
|
|
46
|
+
/**
|
|
47
|
+
* Updates the synchronization cursor for this channel.
|
|
48
|
+
* For polling channels, this also removes acknowledged operations from the outbox.
|
|
49
|
+
*
|
|
50
|
+
* @param cursorOrdinal - The last processed ordinal
|
|
51
|
+
*/
|
|
52
|
+
updateCursor(cursorOrdinal: number): Promise<void>;
|
|
40
53
|
}
|
|
41
54
|
/**
|
|
42
55
|
* Factory for creating channel instances.
|
|
@@ -52,9 +65,11 @@ export interface IChannelFactory {
|
|
|
52
65
|
* @param remoteName - Name of the remote
|
|
53
66
|
* @param config - Channel configuration including type and parameters
|
|
54
67
|
* @param cursorStorage - Storage for persisting synchronization cursors
|
|
68
|
+
* @param collectionId - Collection ID to synchronize
|
|
69
|
+
* @param filter - Filter to apply to operations
|
|
55
70
|
* @returns A new channel instance
|
|
56
71
|
*/
|
|
57
|
-
instance(remoteId: string, remoteName: string, config: ChannelConfig, cursorStorage: ISyncCursorStorage): IChannel;
|
|
72
|
+
instance(remoteId: string, remoteName: string, config: ChannelConfig, cursorStorage: ISyncCursorStorage, collectionId: string, filter: RemoteFilter): IChannel;
|
|
58
73
|
}
|
|
59
74
|
/**
|
|
60
75
|
* Represents a configured remote with an active channel.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../src/sync/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EA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C,MAAM,CAAC,CAAC;IAEnB;;;;;;;;;OASG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpC;;;;OAIG;IACH,IAAI,IAAI,MAAM,EAAE,CAAC;CAClB"}
|
|
@@ -2,6 +2,7 @@ import type { Kysely } from "kysely";
|
|
|
2
2
|
import type { IOperationIndex } from "../cache/operation-index-types.js";
|
|
3
3
|
import type { IReactor, SyncModule } from "../core/types.js";
|
|
4
4
|
import type { IEventBus } from "../events/interfaces.js";
|
|
5
|
+
import type { ILogger } from "../logging/types.js";
|
|
5
6
|
import type { ISyncCursorStorage, ISyncRemoteStorage } from "../storage/interfaces.js";
|
|
6
7
|
import type { Database } from "../storage/kysely/types.js";
|
|
7
8
|
import type { IChannelFactory, ISyncManager } from "./interfaces.js";
|
|
@@ -12,7 +13,7 @@ export declare class SyncBuilder {
|
|
|
12
13
|
withChannelFactory(factory: IChannelFactory): this;
|
|
13
14
|
withRemoteStorage(storage: ISyncRemoteStorage): this;
|
|
14
15
|
withCursorStorage(storage: ISyncCursorStorage): this;
|
|
15
|
-
build(reactor: IReactor, operationIndex: IOperationIndex, eventBus: IEventBus, db: Kysely<Database>): ISyncManager;
|
|
16
|
-
buildModule(reactor: IReactor, operationIndex: IOperationIndex, eventBus: IEventBus, db: Kysely<Database>): SyncModule;
|
|
16
|
+
build(reactor: IReactor, logger: ILogger, operationIndex: IOperationIndex, eventBus: IEventBus, db: Kysely<Database>): ISyncManager;
|
|
17
|
+
buildModule(reactor: IReactor, logger: ILogger, operationIndex: IOperationIndex, eventBus: IEventBus, db: Kysely<Database>): SyncModule;
|
|
17
18
|
}
|
|
18
19
|
//# sourceMappingURL=sync-builder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-builder.d.ts","sourceRoot":"","sources":["../../../src/sync/sync-builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,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,EAC/B,QAAQ,EAAE,SAAS,EACnB,EAAE,EAAE,MAAM,CAAC,QAAQ,CAAC,GACnB,YAAY;IAWf,WAAW,CACT,OAAO,EAAE,QAAQ,EACjB,MAAM,EAAE,OAAO,EACf,cAAc,EAAE,eAAe,EAC/B,QAAQ,EAAE,SAAS,EACnB,EAAE,EAAE,MAAM,CAAC,QAAQ,CAAC,GACnB,UAAU;CAyBd"}
|
|
@@ -17,17 +17,17 @@ export class SyncBuilder {
|
|
|
17
17
|
this.cursorStorage = storage;
|
|
18
18
|
return this;
|
|
19
19
|
}
|
|
20
|
-
build(reactor, operationIndex, eventBus, db) {
|
|
21
|
-
const module = this.buildModule(reactor, operationIndex, eventBus, db);
|
|
20
|
+
build(reactor, logger, operationIndex, eventBus, db) {
|
|
21
|
+
const module = this.buildModule(reactor, logger, operationIndex, eventBus, db);
|
|
22
22
|
return module.syncManager;
|
|
23
23
|
}
|
|
24
|
-
buildModule(reactor, operationIndex, eventBus, db) {
|
|
24
|
+
buildModule(reactor, logger, operationIndex, eventBus, db) {
|
|
25
25
|
if (!this.channelFactory) {
|
|
26
26
|
throw new Error("Channel factory is required");
|
|
27
27
|
}
|
|
28
28
|
const remoteStorage = this.remoteStorage ?? new KyselySyncRemoteStorage(db);
|
|
29
29
|
const cursorStorage = this.cursorStorage ?? new KyselySyncCursorStorage(db);
|
|
30
|
-
const syncManager = new SyncManager(remoteStorage, cursorStorage, this.channelFactory, operationIndex, reactor, eventBus);
|
|
30
|
+
const syncManager = new SyncManager(logger, remoteStorage, cursorStorage, this.channelFactory, operationIndex, reactor, eventBus);
|
|
31
31
|
return {
|
|
32
32
|
remoteStorage,
|
|
33
33
|
cursorStorage,
|
|
@@ -1 +1 @@
|
|
|
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,EA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AuB,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,11 +1,13 @@
|
|
|
1
1
|
import type { IOperationIndex } from "../cache/operation-index-types.js";
|
|
2
2
|
import type { IReactor } from "../core/types.js";
|
|
3
3
|
import type { IEventBus } from "../events/interfaces.js";
|
|
4
|
+
import type { ILogger } from "../logging/types.js";
|
|
4
5
|
import { type JobInfo, type ShutdownStatus } from "../shared/types.js";
|
|
5
6
|
import type { ISyncCursorStorage, ISyncRemoteStorage } from "../storage/interfaces.js";
|
|
6
7
|
import type { IChannelFactory, ISyncManager, Remote } from "./interfaces.js";
|
|
7
8
|
import type { ChannelConfig, RemoteFilter, RemoteOptions } from "./types.js";
|
|
8
9
|
export declare class SyncManager implements ISyncManager {
|
|
10
|
+
private readonly logger;
|
|
9
11
|
private readonly remoteStorage;
|
|
10
12
|
private readonly cursorStorage;
|
|
11
13
|
private readonly channelFactory;
|
|
@@ -17,12 +19,13 @@ export declare class SyncManager implements ISyncManager {
|
|
|
17
19
|
private isShutdown;
|
|
18
20
|
private eventUnsubscribe?;
|
|
19
21
|
loadJobs: Map<string, JobInfo>;
|
|
20
|
-
constructor(remoteStorage: ISyncRemoteStorage, cursorStorage: ISyncCursorStorage, channelFactory: IChannelFactory, operationIndex: IOperationIndex, reactor: IReactor, eventBus: IEventBus);
|
|
22
|
+
constructor(logger: ILogger, remoteStorage: ISyncRemoteStorage, cursorStorage: ISyncCursorStorage, channelFactory: IChannelFactory, operationIndex: IOperationIndex, reactor: IReactor, eventBus: IEventBus);
|
|
21
23
|
startup(): Promise<void>;
|
|
22
24
|
shutdown(): ShutdownStatus;
|
|
23
25
|
getByName(name: string): Remote;
|
|
24
26
|
getById(id: string): Remote;
|
|
25
27
|
add(name: string, collectionId: string, channelConfig: ChannelConfig, filter?: RemoteFilter, options?: RemoteOptions, id?: string): Promise<Remote>;
|
|
28
|
+
private backfillOutbox;
|
|
26
29
|
remove(name: string): Promise<void>;
|
|
27
30
|
list(): Remote[];
|
|
28
31
|
private wireChannelCallbacks;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-manager.d.ts","sourceRoot":"","sources":["../../../src/sync/sync-manager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAKzD,OAAO,EAEL,KAAK,OAAO,EACZ,KAAK,cAAc,EACpB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"sync-manager.d.ts","sourceRoot":"","sources":["../../../src/sync/sync-manager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAKzD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EAEL,KAAK,OAAO,EACZ,KAAK,cAAc,EACpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EACV,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAE7E,OAAO,KAAK,EACV,aAAa,EACb,YAAY,EACZ,aAAa,EAGd,MAAM,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AAE;IAIhB,OAAO,CAAC,oBAAoB;IAU5B,OAAO,CAAC,sBAAsB;IAiC9B,OAAO,CAAC,cAAc;IAQtB,OAAO,CAAC,eAAe;YAUT,aAAa;CAsD5B"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { OperationEventTypes, } from "../events/types.js";
|
|
2
|
-
import { JobStatus, } from "../shared/types.js";
|
|
3
2
|
import { JobAwaiter } from "../shared/awaiter.js";
|
|
3
|
+
import { JobStatus, } from "../shared/types.js";
|
|
4
4
|
import { ChannelError } from "./errors.js";
|
|
5
5
|
import { SyncOperation } from "./sync-operation.js";
|
|
6
6
|
import { ChannelErrorSource, SyncOperationStatus } from "./types.js";
|
|
7
|
-
import { createIdleHealth, filterOperations } from "./utils.js";
|
|
7
|
+
import { batchOperationsByDocument, createIdleHealth, filterOperations, } from "./utils.js";
|
|
8
8
|
export class SyncManager {
|
|
9
|
+
logger;
|
|
9
10
|
remoteStorage;
|
|
10
11
|
cursorStorage;
|
|
11
12
|
channelFactory;
|
|
@@ -17,7 +18,8 @@ export class SyncManager {
|
|
|
17
18
|
isShutdown;
|
|
18
19
|
eventUnsubscribe;
|
|
19
20
|
loadJobs = new Map();
|
|
20
|
-
constructor(remoteStorage, cursorStorage, channelFactory, operationIndex, reactor, eventBus) {
|
|
21
|
+
constructor(logger, remoteStorage, cursorStorage, channelFactory, operationIndex, reactor, eventBus) {
|
|
22
|
+
this.logger = logger;
|
|
21
23
|
this.remoteStorage = remoteStorage;
|
|
22
24
|
this.cursorStorage = cursorStorage;
|
|
23
25
|
this.channelFactory = channelFactory;
|
|
@@ -34,7 +36,14 @@ export class SyncManager {
|
|
|
34
36
|
}
|
|
35
37
|
const remoteRecords = await this.remoteStorage.list();
|
|
36
38
|
for (const record of remoteRecords) {
|
|
37
|
-
const channel = this.channelFactory.instance(record.id, record.name, record.channelConfig, this.cursorStorage);
|
|
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
|
+
}
|
|
38
47
|
const remote = {
|
|
39
48
|
id: record.id,
|
|
40
49
|
name: record.name,
|
|
@@ -90,6 +99,7 @@ export class SyncManager {
|
|
|
90
99
|
if (this.remotes.has(name)) {
|
|
91
100
|
throw new Error(`Remote with name '${name}' already exists`);
|
|
92
101
|
}
|
|
102
|
+
this.logger.debug("Adding remote (@name, @collectionId, @channelConfig, @filter, @options, @id)", name, collectionId, channelConfig, filter, options, id);
|
|
93
103
|
const remoteId = id ?? crypto.randomUUID();
|
|
94
104
|
const status = {
|
|
95
105
|
push: createIdleHealth(),
|
|
@@ -105,7 +115,8 @@ export class SyncManager {
|
|
|
105
115
|
status,
|
|
106
116
|
};
|
|
107
117
|
await this.remoteStorage.upsert(remoteRecord);
|
|
108
|
-
const channel = this.channelFactory.instance(remoteId, name, channelConfig, this.cursorStorage);
|
|
118
|
+
const channel = this.channelFactory.instance(remoteId, name, channelConfig, this.cursorStorage, collectionId, filter);
|
|
119
|
+
await channel.init();
|
|
109
120
|
const remote = {
|
|
110
121
|
id: remoteId,
|
|
111
122
|
name,
|
|
@@ -116,8 +127,47 @@ export class SyncManager {
|
|
|
116
127
|
};
|
|
117
128
|
this.remotes.set(name, remote);
|
|
118
129
|
this.wireChannelCallbacks(remote);
|
|
130
|
+
await this.backfillOutbox(remote, collectionId, filter);
|
|
119
131
|
return remote;
|
|
120
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
|
+
}
|
|
121
171
|
async remove(name) {
|
|
122
172
|
const remote = this.remotes.get(name);
|
|
123
173
|
if (!remote) {
|
|
@@ -142,13 +192,20 @@ export class SyncManager {
|
|
|
142
192
|
if (this.isShutdown) {
|
|
143
193
|
return;
|
|
144
194
|
}
|
|
195
|
+
const sourceRemote = event.jobMeta?.sourceRemote;
|
|
145
196
|
for (const remote of this.remotes.values()) {
|
|
197
|
+
if (sourceRemote && remote.name === sourceRemote) {
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
146
200
|
const filteredOps = filterOperations(event.operations, remote.filter);
|
|
147
201
|
if (filteredOps.length === 0) {
|
|
148
202
|
continue;
|
|
149
203
|
}
|
|
150
|
-
const
|
|
151
|
-
|
|
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
|
+
}
|
|
152
209
|
}
|
|
153
210
|
}
|
|
154
211
|
handleInboxJob(remote, syncOp) {
|
|
@@ -171,7 +228,7 @@ export class SyncManager {
|
|
|
171
228
|
const operations = syncOp.operations.map((op) => op.operation);
|
|
172
229
|
let jobInfo;
|
|
173
230
|
try {
|
|
174
|
-
jobInfo = await this.reactor.load(syncOp.documentId, syncOp.branch, operations);
|
|
231
|
+
jobInfo = await this.reactor.load(syncOp.documentId, syncOp.branch, operations, undefined, { sourceRemote: remote.name });
|
|
175
232
|
}
|
|
176
233
|
catch (error) {
|
|
177
234
|
const err = error instanceof Error ? error : new Error(String(error));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-manager.js","sourceRoot":"","sources":["../../../src/sync/sync-manager.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,mBAAmB,GAEpB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"sync-manager.js","sourceRoot":"","sources":["../../../src/sync/sync-manager.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,mBAAmB,GAEpB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EACL,SAAS,GAGV,MAAM,oBAAoB,CAAC;AAK5B,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAQpD,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,EACL,yBAAyB,EACzB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,YAAY,CAAC;AAEpB,MAAM,OAAO,WAAW;IACL,MAAM,CAAU;IAChB,aAAa,CAA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 +1,11 @@
|
|
|
1
1
|
import type { OperationWithContext } from "../storage/interfaces.js";
|
|
2
2
|
import type { ChannelHealth, RemoteFilter } from "./types.js";
|
|
3
|
+
export type OperationBatch = {
|
|
4
|
+
documentId: string;
|
|
5
|
+
branch: string;
|
|
6
|
+
scope: string;
|
|
7
|
+
operations: OperationWithContext[];
|
|
8
|
+
};
|
|
3
9
|
/**
|
|
4
10
|
* Filters operations based on a remote's filter criteria.
|
|
5
11
|
*
|
|
@@ -14,4 +20,17 @@ export declare function filterOperations(operations: OperationWithContext[], fil
|
|
|
14
20
|
* @returns A new idle channel health object
|
|
15
21
|
*/
|
|
16
22
|
export declare function createIdleHealth(): ChannelHealth;
|
|
23
|
+
/**
|
|
24
|
+
* Batches consecutive operations by documentId and scope, preserving ordering.
|
|
25
|
+
*
|
|
26
|
+
* For operations [a1_doc, a1_global, a2_doc, b1_global], this returns:
|
|
27
|
+
* - Batch 1: [a1_doc] for doc-a, document scope
|
|
28
|
+
* - Batch 2: [a1_global] for doc-a, global scope
|
|
29
|
+
* - Batch 3: [a2_doc] for doc-a, document scope
|
|
30
|
+
* - Batch 4: [b1_global] for doc-b, global scope
|
|
31
|
+
*
|
|
32
|
+
* This ensures operations are grouped for efficient processing while maintaining
|
|
33
|
+
* causality across documents and scopes.
|
|
34
|
+
*/
|
|
35
|
+
export declare function batchOperationsByDocument(operations: OperationWithContext[]): OperationBatch[];
|
|
17
36
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/sync/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE9D;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,oBAAoB,EAAE,EAClC,MAAM,EAAE,YAAY,GACnB,oBAAoB,EAAE,CAmBxB;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,aAAa,CAKhD"}
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/sync/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE9D,MAAM,MAAM,cAAc,GAAG;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,oBAAoB,EAAE,CAAC;CACpC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,oBAAoB,EAAE,EAClC,MAAM,EAAE,YAAY,GACnB,oBAAoB,EAAE,CAmBxB;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,aAAa,CAKhD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,yBAAyB,CACvC,UAAU,EAAE,oBAAoB,EAAE,GACjC,cAAc,EAAE,CAsClB"}
|
package/dist/src/sync/utils.js
CHANGED
|
@@ -31,4 +31,48 @@ export function createIdleHealth() {
|
|
|
31
31
|
failureCount: 0,
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Batches consecutive operations by documentId and scope, preserving ordering.
|
|
36
|
+
*
|
|
37
|
+
* For operations [a1_doc, a1_global, a2_doc, b1_global], this returns:
|
|
38
|
+
* - Batch 1: [a1_doc] for doc-a, document scope
|
|
39
|
+
* - Batch 2: [a1_global] for doc-a, global scope
|
|
40
|
+
* - Batch 3: [a2_doc] for doc-a, document scope
|
|
41
|
+
* - Batch 4: [b1_global] for doc-b, global scope
|
|
42
|
+
*
|
|
43
|
+
* This ensures operations are grouped for efficient processing while maintaining
|
|
44
|
+
* causality across documents and scopes.
|
|
45
|
+
*/
|
|
46
|
+
export function batchOperationsByDocument(operations) {
|
|
47
|
+
const batches = [];
|
|
48
|
+
let currentDocId = null;
|
|
49
|
+
let currentScope = null;
|
|
50
|
+
let currentBatch = [];
|
|
51
|
+
const flushBatch = () => {
|
|
52
|
+
if (currentBatch.length === 0 ||
|
|
53
|
+
currentDocId === null ||
|
|
54
|
+
currentScope === null) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
batches.push({
|
|
58
|
+
documentId: currentDocId,
|
|
59
|
+
branch: currentBatch[0].context.branch,
|
|
60
|
+
scope: currentScope,
|
|
61
|
+
operations: currentBatch,
|
|
62
|
+
});
|
|
63
|
+
currentBatch = [];
|
|
64
|
+
};
|
|
65
|
+
for (const op of operations) {
|
|
66
|
+
const docId = op.context.documentId;
|
|
67
|
+
const scope = op.context.scope;
|
|
68
|
+
if (docId !== currentDocId || scope !== currentScope) {
|
|
69
|
+
flushBatch();
|
|
70
|
+
currentDocId = docId;
|
|
71
|
+
currentScope = scope;
|
|
72
|
+
}
|
|
73
|
+
currentBatch.push(op);
|
|
74
|
+
}
|
|
75
|
+
flushBatch();
|
|
76
|
+
return batches;
|
|
77
|
+
}
|
|
34
78
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/sync/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/sync/utils.ts"],"names":[],"mappings":"AAUA;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAC9B,UAAkC,EAClC,MAAoB;IAEpB,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE;QAC9B,IAAI,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,EAAE,CAAC;YACzD,OAAO,KAAK,CAAC;QACf,CAAC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AAC,OAAO,CAAC,UAAU,CAAC;QACpC,MAAM,KAAK,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;QAC/B,IAAI,KAAK,KAAK,YAAY,IAAI,KAAK,KAAK,YAAY,EAAE,CAAC;YACrD,UAAU,EAAE,CAAC;YACb,YAAY,GAAG,KAAK,CAAC;YACrB,YAAY,GAAG,KAAK,CAAC;QACvB,CAAC;QACD,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACxB,CAAC;IAED,UAAU,EAAE,CAAC;IACb,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerhousedao/reactor",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0-dev.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": {
|
|
6
6
|
"url": "https://github.com/powerhouse-inc/powerhouse",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"kysely": "^0.28.2",
|
|
29
29
|
"kysely-pglite-dialect": "^1.1.1",
|
|
30
30
|
"uuid": "^11.0.5",
|
|
31
|
-
"document-drive": "5.
|
|
32
|
-
"document-model": "5.
|
|
31
|
+
"document-drive": "5.2.0-dev.1",
|
|
32
|
+
"document-model": "5.2.0-dev.1"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@vitest/coverage-v8": "^3.2.4",
|
|
@@ -1,57 +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
|
-
* In-memory synchronization channel for testing purposes only.
|
|
8
|
-
*
|
|
9
|
-
* InternalChannel enables direct bidirectional communication between two reactor
|
|
10
|
-
* instances without network transport. Channels are wired together by passing
|
|
11
|
-
* a send function that delivers envelopes to the peer's inbox.
|
|
12
|
-
*/
|
|
13
|
-
export declare class InternalChannel 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 readonly send;
|
|
21
|
-
private isShutdown;
|
|
22
|
-
constructor(channelId: string, remoteName: string, cursorStorage: ISyncCursorStorage, send: (envelope: SyncEnvelope) => void);
|
|
23
|
-
/**
|
|
24
|
-
* Shuts down the channel and prevents further operations.
|
|
25
|
-
*/
|
|
26
|
-
shutdown(): void;
|
|
27
|
-
/**
|
|
28
|
-
* Receives a sync envelope from a peer channel.
|
|
29
|
-
*
|
|
30
|
-
* This method is called by the peer's send function to deliver an envelope
|
|
31
|
-
* to this channel's inbox.
|
|
32
|
-
*
|
|
33
|
-
* @param envelope - The sync envelope to receive
|
|
34
|
-
* @throws {InternalChannelError} If channel is shutdown
|
|
35
|
-
*/
|
|
36
|
-
receive(envelope: SyncEnvelope): void;
|
|
37
|
-
/**
|
|
38
|
-
* Updates the synchronization cursor for this channel's remote.
|
|
39
|
-
*
|
|
40
|
-
* Cursors track progress through the operation stream and enable resuming
|
|
41
|
-
* synchronization after restarts. The cursor is exclusive - the next sync
|
|
42
|
-
* will start at cursorOrdinal + 1.
|
|
43
|
-
*
|
|
44
|
-
* @param cursorOrdinal - The last processed ordinal (exclusive)
|
|
45
|
-
*/
|
|
46
|
-
updateCursor(cursorOrdinal: number): Promise<void>;
|
|
47
|
-
/**
|
|
48
|
-
* Handles sync operations added to the outbox by sending them to the peer.
|
|
49
|
-
*
|
|
50
|
-
* This method is called automatically via the outbox.onAdded callback.
|
|
51
|
-
* It converts the sync operation to a SyncEnvelope and sends it via the send function.
|
|
52
|
-
*
|
|
53
|
-
* @param syncOp - The sync operation to transport
|
|
54
|
-
*/
|
|
55
|
-
private handleOutboxAdded;
|
|
56
|
-
}
|
|
57
|
-
//# sourceMappingURL=internal-channel.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"internal-channel.d.ts","sourceRoot":"","sources":["../../../../src/sync/channels/internal-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;AAI9D;;;;;;GAMG;AACH,qBAAa,eAAgB,YAAW,QAAQ;IAC9C,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,QAAQ,CAAC,IAAI,CAAmC;IACxD,OAAO,CAAC,UAAU,CAAU;gBAG1B,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,kBAAkB,EACjC,IAAI,EAAE,CAAC,QAAQ,EAAE,YAAY,KAAK,IAAI;IAiBxC;;OAEG;IACH,QAAQ,IAAI,IAAI;IAIhB;;;;;;;;OAQG;IACH,OAAO,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI;IA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