@dabble/patches 0.7.15 → 0.7.16

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.
Files changed (83) hide show
  1. package/README.md +4 -4
  2. package/dist/{BaseDoc-vaMreJL5.d.ts → BaseDoc-BRIP2YZp.d.ts} +16 -35
  3. package/dist/algorithms/ot/server/commitChanges.d.ts +1 -1
  4. package/dist/client/BaseDoc.d.ts +2 -2
  5. package/dist/client/BaseDoc.js +13 -38
  6. package/dist/client/ClientAlgorithm.d.ts +2 -2
  7. package/dist/client/IndexedDBStore.d.ts +2 -2
  8. package/dist/client/IndexedDBStore.js +3 -8
  9. package/dist/client/LWWAlgorithm.d.ts +2 -2
  10. package/dist/client/LWWDoc.d.ts +3 -3
  11. package/dist/client/LWWDoc.js +10 -7
  12. package/dist/client/LWWIndexedDBStore.d.ts +1 -1
  13. package/dist/client/LWWIndexedDBStore.js +4 -4
  14. package/dist/client/OTAlgorithm.d.ts +2 -2
  15. package/dist/client/OTDoc.d.ts +2 -2
  16. package/dist/client/OTDoc.js +7 -8
  17. package/dist/client/OTIndexedDBStore.d.ts +1 -1
  18. package/dist/client/OTIndexedDBStore.js +3 -3
  19. package/dist/client/Patches.d.ts +9 -8
  20. package/dist/client/Patches.js +5 -2
  21. package/dist/client/PatchesDoc.d.ts +2 -2
  22. package/dist/client/PatchesHistoryClient.d.ts +5 -11
  23. package/dist/client/PatchesHistoryClient.js +14 -29
  24. package/dist/client/factories.d.ts +2 -2
  25. package/dist/client/index.d.ts +2 -2
  26. package/dist/index.d.ts +3 -3
  27. package/dist/index.js +23 -2
  28. package/dist/net/PatchesClient.d.ts +3 -3
  29. package/dist/net/PatchesClient.js +1 -1
  30. package/dist/net/PatchesSync.d.ts +13 -28
  31. package/dist/net/PatchesSync.js +68 -87
  32. package/dist/net/http/FetchTransport.d.ts +2 -2
  33. package/dist/net/http/FetchTransport.js +1 -1
  34. package/dist/net/index.d.ts +2 -2
  35. package/dist/net/protocol/JSONRPCClient.d.ts +1 -1
  36. package/dist/net/protocol/JSONRPCClient.js +1 -1
  37. package/dist/net/protocol/JSONRPCServer.d.ts +1 -1
  38. package/dist/net/protocol/JSONRPCServer.js +1 -1
  39. package/dist/net/protocol/types.d.ts +1 -1
  40. package/dist/net/protocol/utils.d.ts +1 -1
  41. package/dist/net/webrtc/WebRTCAwareness.d.ts +2 -2
  42. package/dist/net/webrtc/WebRTCAwareness.js +1 -1
  43. package/dist/net/webrtc/WebRTCTransport.d.ts +5 -5
  44. package/dist/net/webrtc/WebRTCTransport.js +1 -1
  45. package/dist/net/webrtc/index.d.ts +1 -1
  46. package/dist/net/websocket/PatchesWebSocket.d.ts +1 -1
  47. package/dist/net/websocket/PatchesWebSocket.js +1 -1
  48. package/dist/net/websocket/SignalingService.d.ts +1 -1
  49. package/dist/net/websocket/WebSocketServer.d.ts +1 -1
  50. package/dist/net/websocket/WebSocketTransport.d.ts +4 -3
  51. package/dist/net/websocket/WebSocketTransport.js +1 -1
  52. package/dist/net/websocket/onlineState.d.ts +2 -2
  53. package/dist/net/websocket/onlineState.js +1 -1
  54. package/dist/server/LWWBranchManager.d.ts +1 -1
  55. package/dist/server/LWWServer.d.ts +3 -3
  56. package/dist/server/LWWServer.js +1 -1
  57. package/dist/server/OTBranchManager.d.ts +1 -1
  58. package/dist/server/OTServer.d.ts +3 -3
  59. package/dist/server/OTServer.js +1 -1
  60. package/dist/server/PatchesHistoryManager.d.ts +1 -1
  61. package/dist/server/PatchesServer.d.ts +1 -1
  62. package/dist/server/branchUtils.d.ts +1 -1
  63. package/dist/server/index.d.ts +1 -1
  64. package/dist/shared/doc-manager.d.ts +2 -2
  65. package/dist/shared/utils.d.ts +2 -2
  66. package/dist/shared/utils.js +2 -2
  67. package/dist/solid/context.d.ts +2 -2
  68. package/dist/solid/doc-manager.d.ts +2 -2
  69. package/dist/solid/index.d.ts +2 -2
  70. package/dist/solid/managed-docs.js +1 -1
  71. package/dist/solid/primitives.d.ts +2 -2
  72. package/dist/solid/primitives.js +7 -7
  73. package/dist/types.d.ts +4 -4
  74. package/dist/vue/composables.d.ts +2 -2
  75. package/dist/vue/composables.js +7 -7
  76. package/dist/vue/doc-manager.d.ts +2 -2
  77. package/dist/vue/index.d.ts +2 -2
  78. package/dist/vue/managed-docs.d.ts +2 -2
  79. package/dist/vue/managed-docs.js +1 -1
  80. package/dist/vue/provider.d.ts +2 -2
  81. package/package.json +2 -1
  82. package/dist/event-signal.d.ts +0 -32
  83. package/dist/event-signal.js +0 -25
@@ -1,4 +1,4 @@
1
- import { Signal } from '../event-signal.js';
1
+ import { Store } from 'easy-signal';
2
2
  import { PatchesAPI } from '../net/protocol/types.js';
3
3
  import { VersionMetadata, ListVersionsOptions, EditableVersionMetadata, Change } from '../types.js';
4
4
  import '../json-patch/JSONPatch.js';
@@ -13,18 +13,12 @@ declare class PatchesHistoryClient<T = any> {
13
13
  private readonly api;
14
14
  /** Document ID */
15
15
  readonly id: string;
16
- /** Event signal for versions changes */
17
- readonly onVersionsChange: Signal<(versions: VersionMetadata[]) => void>;
18
- /** Event signal for state changes */
19
- readonly onStateChange: Signal<(state: T) => void>;
20
- private _versions;
21
- private _state;
16
+ /** Store for versions list */
17
+ readonly versions: Store<VersionMetadata[]>;
18
+ /** Store for history state (scrubbing) */
19
+ readonly historyState: Store<T>;
22
20
  private cache;
23
21
  constructor(id: string, api: PatchesAPI);
24
- /** List of loaded versions */
25
- get versions(): VersionMetadata[];
26
- /** Current state (for scrubbing) */
27
- get state(): any;
28
22
  /** List version metadata for this document (with options) */
29
23
  listVersions(options?: ListVersionsOptions): Promise<VersionMetadata[]>;
30
24
  /** Create a new named version snapshot of the document's current state. */
@@ -1,6 +1,6 @@
1
1
  import "../chunk-IZ2YBCUP.js";
2
2
  import { applyChanges } from "../algorithms/ot/shared/applyChanges.js";
3
- import { signal } from "../event-signal.js";
3
+ import { store } from "easy-signal";
4
4
  class LRUCache {
5
5
  constructor(maxSize) {
6
6
  this.maxSize = maxSize;
@@ -33,29 +33,20 @@ class PatchesHistoryClient {
33
33
  constructor(id, api) {
34
34
  this.api = api;
35
35
  this.id = id;
36
+ this.versions = store([]);
37
+ this.historyState = store(null);
36
38
  }
37
39
  /** Document ID */
38
40
  id;
39
- /** Event signal for versions changes */
40
- onVersionsChange = signal();
41
- /** Event signal for state changes */
42
- onStateChange = signal();
43
- _versions = [];
44
- _state = null;
41
+ /** Store for versions list */
42
+ versions;
43
+ /** Store for history state (scrubbing) */
44
+ historyState;
45
45
  cache = new LRUCache(6);
46
- /** List of loaded versions */
47
- get versions() {
48
- return this._versions;
49
- }
50
- /** Current state (for scrubbing) */
51
- get state() {
52
- return this._state;
53
- }
54
46
  /** List version metadata for this document (with options) */
55
47
  async listVersions(options) {
56
- this._versions = await this.api.listVersions(this.id, options);
57
- this.onVersionsChange.emit(this._versions);
58
- return this._versions;
48
+ this.versions.state = await this.api.listVersions(this.id, options);
49
+ return this.versions.state;
59
50
  }
60
51
  /** Create a new named version snapshot of the document's current state. */
61
52
  async createVersion(metadata) {
@@ -76,8 +67,7 @@ class PatchesHistoryClient {
76
67
  data = { ...data, state };
77
68
  this.cache.set(versionId, data);
78
69
  }
79
- this._state = data.state;
80
- this.onStateChange.emit(this._state);
70
+ this.historyState.state = data.state;
81
71
  return data.state;
82
72
  }
83
73
  /** Load the changes for a specific version */
@@ -92,25 +82,20 @@ class PatchesHistoryClient {
92
82
  }
93
83
  /** Scrub to a specific change within a version where changeIndex is 1-based and 0 is the parent version */
94
84
  async scrubTo(versionId, changeIndex) {
95
- const version = this.versions.find((v) => v.id === versionId);
85
+ const version = this.versions.state.find((v) => v.id === versionId);
96
86
  const [state, changes] = await Promise.all([
97
87
  version?.parentId ? this.getVersionState(version.parentId) : void 0,
98
88
  this.getVersionChanges(versionId)
99
89
  ]);
100
90
  if (changeIndex > 0) {
101
- this._state = applyChanges(state, changes.slice(0, changeIndex));
91
+ this.historyState.state = applyChanges(state, changes.slice(0, changeIndex));
102
92
  }
103
- this.onStateChange.emit(this._state);
104
93
  }
105
94
  /** Clear caches and listeners */
106
95
  clear() {
107
- this._versions = [];
108
- this._state = null;
109
- this.onVersionsChange.emit(this._versions);
110
- this.onStateChange.emit(this._state);
96
+ this.versions.state = [];
97
+ this.historyState.state = null;
111
98
  this.cache.clear();
112
- this.onVersionsChange.clear();
113
- this.onStateChange.clear();
114
99
  }
115
100
  }
116
101
  export {
@@ -1,11 +1,11 @@
1
1
  import { AlgorithmName } from './PatchesStore.js';
2
2
  import { Patches } from './Patches.js';
3
- import { P as PatchesDocOptions } from '../BaseDoc-vaMreJL5.js';
3
+ import { P as PatchesDocOptions } from '../BaseDoc-BRIP2YZp.js';
4
4
  import '../types.js';
5
5
  import '../json-patch/JSONPatch.js';
6
6
  import '@dabble/delta';
7
7
  import '../json-patch/types.js';
8
- import '../event-signal.js';
8
+ import 'easy-signal';
9
9
  import './ClientAlgorithm.js';
10
10
 
11
11
  /**
@@ -1,4 +1,4 @@
1
- export { B as BaseDoc, O as OTDoc, a as PatchesDoc, O as PatchesDocClass, P as PatchesDocOptions } from '../BaseDoc-vaMreJL5.js';
1
+ export { B as BaseDoc, O as OTDoc, a as PatchesDoc, O as PatchesDocClass, P as PatchesDocOptions } from '../BaseDoc-BRIP2YZp.js';
2
2
  export { IndexedDBFactoryOptions, MultiAlgorithmFactoryOptions, MultiAlgorithmIndexedDBFactoryOptions, PatchesFactoryOptions, createLWWIndexedDBPatches, createLWWPatches, createMultiAlgorithmIndexedDBPatches, createMultiAlgorithmPatches, createOTIndexedDBPatches, createOTPatches } from './factories.js';
3
3
  export { IDBStoreWrapper, IDBTransactionWrapper, IndexedDBStore } from './IndexedDBStore.js';
4
4
  export { OTIndexedDBStore } from './OTIndexedDBStore.js';
@@ -15,7 +15,7 @@ export { AlgorithmName, PatchesStore, TrackedDoc } from './PatchesStore.js';
15
15
  export { OTClientStore } from './OTClientStore.js';
16
16
  export { LWWClientStore } from './LWWClientStore.js';
17
17
  export { ClientAlgorithm } from './ClientAlgorithm.js';
18
- import '../event-signal.js';
18
+ import 'easy-signal';
19
19
  import '../json-patch/types.js';
20
20
  import '../types.js';
21
21
  import '../json-patch/JSONPatch.js';
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { Delta } from '@dabble/delta';
2
- export { B as BaseDoc, O as OTDoc, a as PatchesDoc, O as PatchesDocClass, P as PatchesDocOptions } from './BaseDoc-vaMreJL5.js';
2
+ export { B as BaseDoc, O as OTDoc, a as PatchesDoc, O as PatchesDocClass, P as PatchesDocOptions } from './BaseDoc-BRIP2YZp.js';
3
3
  export { IndexedDBFactoryOptions, MultiAlgorithmFactoryOptions, MultiAlgorithmIndexedDBFactoryOptions, PatchesFactoryOptions, createLWWIndexedDBPatches, createLWWPatches, createMultiAlgorithmIndexedDBPatches, createMultiAlgorithmPatches, createOTIndexedDBPatches, createOTPatches } from './client/factories.js';
4
4
  export { IDBStoreWrapper, IDBTransactionWrapper, IndexedDBStore } from './client/IndexedDBStore.js';
5
5
  export { OTIndexedDBStore } from './client/OTIndexedDBStore.js';
@@ -18,7 +18,7 @@ export { LWWClientStore } from './client/LWWClientStore.js';
18
18
  export { ClientAlgorithm } from './client/ClientAlgorithm.js';
19
19
  export { createChange } from './data/change.js';
20
20
  export { createVersionId, createVersionMetadata } from './data/version.js';
21
- export { ErrorSubscriber, Signal, SignalSubscriber, Unsubscriber, signal } from './event-signal.js';
21
+ export { ReadonlyStore, Signal, SignalSubscriber, Store, Subscriber, Unsubscriber, afterChange, batch, clearAllContext, computed, readonly, signal, store, watch, whenMatches, whenReady } from 'easy-signal';
22
22
  export { fractionalIndex, healDuplicateOrders, sortByOrder } from './fractionalIndex.js';
23
23
  export { applyPatch } from './json-patch/applyPatch.js';
24
24
  export { composePatch } from './json-patch/composePatch.js';
@@ -29,7 +29,7 @@ export { createPathProxy, pathProxy } from './json-patch/pathProxy.js';
29
29
  export { transformPatch } from './json-patch/transformPatch.js';
30
30
  export { JSONPatch, PathLike, WriteOptions } from './json-patch/JSONPatch.js';
31
31
  export { ApplyJSONPatchOptions, JSONPatchOpHandlerMap as JSONPatchCustomTypes, JSONPatchOp } from './json-patch/types.js';
32
- export { Branch, BranchStatus, Change, ChangeInput, ChangeMutator, CommitChangesOptions, DeleteDocOptions, DocSyncStatus, DocumentTombstone, EditableBranchMetadata, EditableVersionMetadata, ListChangesOptions, ListVersionsOptions, PatchesSnapshot, PatchesState, PathProxy, SyncedDoc, VersionMetadata } from './types.js';
32
+ export { Branch, BranchStatus, Change, ChangeInput, ChangeMutator, CommitChangesOptions, DeleteDocOptions, DocSyncState, DocSyncStatus, DocumentTombstone, EditableBranchMetadata, EditableVersionMetadata, ListChangesOptions, ListVersionsOptions, PatchesSnapshot, PatchesState, PathProxy, VersionMetadata } from './types.js';
33
33
  export { add } from './json-patch/ops/add.js';
34
34
  export { copy } from './json-patch/ops/copy.js';
35
35
  export { increment } from './json-patch/ops/increment.js';
package/dist/index.js CHANGED
@@ -3,9 +3,30 @@ import { Delta } from "@dabble/delta";
3
3
  export * from "./client/index.js";
4
4
  export * from "./data/change.js";
5
5
  export * from "./data/version.js";
6
- export * from "./event-signal.js";
6
+ import {
7
+ signal,
8
+ store,
9
+ readonly,
10
+ computed,
11
+ batch,
12
+ watch,
13
+ whenReady,
14
+ whenMatches,
15
+ afterChange,
16
+ clearAllContext
17
+ } from "easy-signal";
7
18
  export * from "./fractionalIndex.js";
8
19
  export * from "./json-patch/index.js";
9
20
  export {
10
- Delta
21
+ Delta,
22
+ afterChange,
23
+ batch,
24
+ clearAllContext,
25
+ computed,
26
+ readonly,
27
+ signal,
28
+ store,
29
+ watch,
30
+ whenMatches,
31
+ whenReady
11
32
  };
@@ -1,4 +1,4 @@
1
- import { Signal } from '../event-signal.js';
1
+ import * as easy_signal from 'easy-signal';
2
2
  import { Change, CommitChangesOptions, PatchesState, ChangeInput, DeleteDocOptions, EditableVersionMetadata, ListVersionsOptions, VersionMetadata, PatchesSnapshot } from '../types.js';
3
3
  import { JSONRPCClient } from './protocol/JSONRPCClient.js';
4
4
  import { PatchesAPI, ClientTransport } from './protocol/types.js';
@@ -16,9 +16,9 @@ declare class PatchesClient implements PatchesAPI {
16
16
  rpc: JSONRPCClient;
17
17
  transport: ClientTransport;
18
18
  /** Signal emitted when the server pushes document changes. */
19
- readonly onChangesCommitted: Signal<(docId: string, changes: Change[], options?: CommitChangesOptions) => void>;
19
+ readonly onChangesCommitted: easy_signal.Signal<(docId: string, changes: Change[], options?: CommitChangesOptions) => void>;
20
20
  /** Signal emitted when a document is deleted (either by another client or discovered on subscribe). */
21
- readonly onDocDeleted: Signal<(docId: string) => void>;
21
+ readonly onDocDeleted: easy_signal.Signal<(docId: string) => void>;
22
22
  /**
23
23
  * Creates a new Patches WebSocket client instance.
24
24
  * @param url - The WebSocket server URL to connect to
@@ -1,5 +1,5 @@
1
1
  import "../chunk-IZ2YBCUP.js";
2
- import { signal } from "../event-signal.js";
2
+ import { signal } from "easy-signal";
3
3
  import { JSONRPCClient } from "./protocol/JSONRPCClient.js";
4
4
  class PatchesClient {
5
5
  rpc;
@@ -1,6 +1,7 @@
1
- import { Signal } from '../event-signal.js';
1
+ import * as easy_signal from 'easy-signal';
2
+ import { ReadonlyStoreClass, Store } from 'easy-signal';
2
3
  import { ConnectionState } from './protocol/types.js';
3
- import { DocSyncStatus, SyncedDoc, Change } from '../types.js';
4
+ import { DocSyncStatus, DocSyncState, Change } from '../types.js';
4
5
  import { JSONRPCClient } from './protocol/JSONRPCClient.js';
5
6
  import { PatchesWebSocket } from './websocket/PatchesWebSocket.js';
6
7
  import { WebSocketOptions } from './websocket/WebSocketTransport.js';
@@ -13,7 +14,7 @@ import '@dabble/delta';
13
14
  import '../json-patch/types.js';
14
15
  import './PatchesClient.js';
15
16
  import '../utils/deferred.js';
16
- import '../BaseDoc-vaMreJL5.js';
17
+ import '../BaseDoc-BRIP2YZp.js';
17
18
 
18
19
  interface PatchesSyncState {
19
20
  online: boolean;
@@ -40,7 +41,7 @@ interface PatchesSyncOptions {
40
41
  * - Applying server changes
41
42
  * - Confirming sent changes
42
43
  */
43
- declare class PatchesSync {
44
+ declare class PatchesSync extends ReadonlyStoreClass<PatchesSyncState> {
44
45
  protected options?: PatchesSyncOptions | undefined;
45
46
  protected ws: PatchesWebSocket;
46
47
  protected patches: Patches;
@@ -50,27 +51,21 @@ declare class PatchesSync {
50
51
  protected trackedDocs: Set<string>;
51
52
  /** Maps docId to the algorithm name used for that doc */
52
53
  protected docAlgorithms: Map<string, AlgorithmName>;
53
- protected _state: PatchesSyncState;
54
- protected _syncedDocs: Record<string, SyncedDoc>;
55
54
  /**
56
- * Signal emitted when the sync state changes.
55
+ * Reactive store tracking per-document sync state.
57
56
  */
58
- readonly onStateChange: Signal<(state: PatchesSyncState) => void>;
57
+ readonly docStates: Store<Record<string, DocSyncState>>;
59
58
  /**
60
59
  * Signal emitted when an error occurs.
61
60
  */
62
- readonly onError: Signal<(error: Error, context?: {
61
+ readonly onError: easy_signal.Signal<(error: Error, context?: {
63
62
  docId?: string;
64
63
  }) => void>;
65
64
  /**
66
65
  * Signal emitted when a document is deleted remotely (by another client or discovered via tombstone).
67
66
  * Provides the pending changes that were discarded so the application can handle them.
68
67
  */
69
- readonly onRemoteDocDeleted: Signal<(docId: string, pendingChanges: Change[]) => void>;
70
- /**
71
- * Signal emitted when the synced doc map changes.
72
- */
73
- readonly onSyncedDocsChange: Signal<(synced: Record<string, SyncedDoc>) => void>;
68
+ readonly onRemoteDocDeleted: easy_signal.Signal<(docId: string, pendingChanges: Change[]) => void>;
74
69
  constructor(patches: Patches, url: string, options?: PatchesSyncOptions | undefined);
75
70
  /**
76
71
  * Gets the algorithm for a document. Uses the open doc's algorithm if available,
@@ -85,15 +80,6 @@ declare class PatchesSync {
85
80
  * Sets the URL of the WebSocket connection.
86
81
  */
87
82
  set url(url: string);
88
- /**
89
- * Gets the current sync state.
90
- */
91
- get state(): PatchesSyncState;
92
- /**
93
- * Map of all tracked documents and their current sync status.
94
- * Updated immutably — new object reference on every change.
95
- */
96
- get syncedDocs(): Record<string, SyncedDoc>;
97
83
  /**
98
84
  * Gets the JSON-RPC client for making custom RPC calls.
99
85
  * Useful for application-specific methods not part of the Patches protocol.
@@ -154,14 +140,13 @@ declare class PatchesSync {
154
140
  */
155
141
  protected _handleRemoteDocDeleted(docId: string): Promise<void>;
156
142
  /**
157
- * Adds, updates, or removes a synced doc entry immutably and emits onSyncedChange.
158
- * - Pass a full SyncedDoc to add a new entry or overwrite an existing one.
159
- * - Pass a Partial<SyncedDoc> to merge into an existing entry (no-ops if doc not in map).
143
+ * Adds, updates, or removes a doc state entry immutably and notifies via store.
144
+ * - Pass a full DocSyncState to add a new entry or overwrite an existing one.
145
+ * - Pass a Partial<DocSyncState> to merge into an existing entry (no-ops if doc not in map).
160
146
  * - Pass undefined to remove the entry.
161
147
  * No-ops if nothing actually changed.
162
148
  */
163
- protected _updateSyncedDoc(docId: string, updates: Partial<SyncedDoc> | undefined, emit?: boolean): void;
164
- protected _emitSyncedChange(): void;
149
+ protected _updateDocSyncState(docId: string, updates: Partial<DocSyncState> | undefined): void;
165
150
  /**
166
151
  * Resets any docs with status 'syncing' back to a stable state on disconnect.
167
152
  * Uses hasPending to decide: pending docs become 'synced' (they have local data),