@dabble/patches 0.4.4 → 0.4.6

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 (181) hide show
  1. package/dist/algorithms/client/applyCommittedChanges.d.ts +8 -2
  2. package/dist/algorithms/client/applyCommittedChanges.js +30 -38
  3. package/dist/algorithms/client/batching.d.ts +8 -2
  4. package/dist/algorithms/client/batching.js +38 -37
  5. package/dist/algorithms/client/breakChange.d.ts +8 -2
  6. package/dist/algorithms/client/breakChange.js +191 -240
  7. package/dist/algorithms/client/createStateFromSnapshot.d.ts +8 -2
  8. package/dist/algorithms/client/createStateFromSnapshot.js +7 -8
  9. package/dist/algorithms/client/getJSONByteSize.d.ts +3 -1
  10. package/dist/algorithms/client/getJSONByteSize.js +12 -11
  11. package/dist/algorithms/client/makeChange.d.ts +8 -2
  12. package/dist/algorithms/client/makeChange.js +28 -36
  13. package/dist/algorithms/server/commitChanges.d.ts +9 -3
  14. package/dist/algorithms/server/commitChanges.js +69 -78
  15. package/dist/algorithms/server/createVersion.d.ts +9 -3
  16. package/dist/algorithms/server/createVersion.js +21 -27
  17. package/dist/algorithms/server/getSnapshotAtRevision.d.ts +9 -3
  18. package/dist/algorithms/server/getSnapshotAtRevision.js +27 -28
  19. package/dist/algorithms/server/getStateAtRevision.d.ts +9 -3
  20. package/dist/algorithms/server/getStateAtRevision.js +13 -17
  21. package/dist/algorithms/server/handleOfflineSessionsAndBatches.d.ts +9 -3
  22. package/dist/algorithms/server/handleOfflineSessionsAndBatches.js +60 -77
  23. package/dist/algorithms/server/transformIncomingChanges.d.ts +8 -2
  24. package/dist/algorithms/server/transformIncomingChanges.js +27 -39
  25. package/dist/algorithms/shared/applyChanges.d.ts +8 -2
  26. package/dist/algorithms/shared/applyChanges.js +11 -16
  27. package/dist/algorithms/shared/rebaseChanges.d.ts +8 -2
  28. package/dist/algorithms/shared/rebaseChanges.js +30 -49
  29. package/dist/chunk-IZ2YBCUP.js +56 -0
  30. package/dist/client/InMemoryStore.d.ts +9 -3
  31. package/dist/client/InMemoryStore.js +92 -101
  32. package/dist/client/IndexedDBStore.d.ts +9 -3
  33. package/dist/client/IndexedDBStore.js +378 -491
  34. package/dist/client/Patches.d.ts +18 -13
  35. package/dist/client/Patches.js +152 -207
  36. package/dist/client/PatchesDoc.d.ts +14 -8
  37. package/dist/client/PatchesDoc.js +147 -154
  38. package/dist/client/PatchesHistoryClient.d.ts +12 -5
  39. package/dist/client/PatchesHistoryClient.js +110 -117
  40. package/dist/client/PatchesStore.d.ts +9 -3
  41. package/dist/client/PatchesStore.js +0 -1
  42. package/dist/client/index.d.ts +12 -6
  43. package/dist/client/index.js +5 -5
  44. package/dist/data/change.d.ts +9 -3
  45. package/dist/data/change.js +23 -15
  46. package/dist/data/version.d.ts +9 -3
  47. package/dist/data/version.js +11 -15
  48. package/dist/event-signal.d.ts +7 -6
  49. package/dist/event-signal.js +24 -39
  50. package/dist/index-CvQws3AB.d.ts +36 -0
  51. package/dist/index.d.ts +27 -5
  52. package/dist/index.js +10 -4
  53. package/dist/json-patch/JSONPatch.d.ts +9 -5
  54. package/dist/json-patch/JSONPatch.js +175 -183
  55. package/dist/json-patch/applyPatch.d.ts +5 -2
  56. package/dist/json-patch/applyPatch.js +27 -35
  57. package/dist/json-patch/composePatch.d.ts +5 -2
  58. package/dist/json-patch/composePatch.js +34 -34
  59. package/dist/json-patch/createJSONPatch.d.ts +7 -2
  60. package/dist/json-patch/createJSONPatch.js +11 -38
  61. package/dist/json-patch/index.d.ts +14 -6
  62. package/dist/json-patch/index.js +20 -9
  63. package/dist/json-patch/invertPatch.d.ts +5 -2
  64. package/dist/json-patch/invertPatch.js +31 -30
  65. package/dist/json-patch/ops/add.d.ts +5 -2
  66. package/dist/json-patch/ops/add.js +53 -51
  67. package/dist/json-patch/ops/bitmask.d.ts +8 -5
  68. package/dist/json-patch/ops/bitmask.js +41 -44
  69. package/dist/json-patch/ops/copy.d.ts +5 -2
  70. package/dist/json-patch/ops/copy.js +32 -33
  71. package/dist/json-patch/ops/increment.d.ts +5 -2
  72. package/dist/json-patch/ops/increment.js +21 -20
  73. package/dist/json-patch/ops/index.d.ts +10 -21
  74. package/dist/json-patch/ops/index.js +34 -24
  75. package/dist/json-patch/ops/move.d.ts +5 -2
  76. package/dist/json-patch/ops/move.js +132 -198
  77. package/dist/json-patch/ops/remove.d.ts +5 -2
  78. package/dist/json-patch/ops/remove.js +33 -30
  79. package/dist/json-patch/ops/replace.d.ts +5 -2
  80. package/dist/json-patch/ops/replace.js +45 -43
  81. package/dist/json-patch/ops/test.d.ts +5 -2
  82. package/dist/json-patch/ops/test.js +25 -21
  83. package/dist/json-patch/ops/text.d.ts +5 -2
  84. package/dist/json-patch/ops/text.js +54 -54
  85. package/dist/json-patch/pathProxy.d.ts +9 -3
  86. package/dist/json-patch/pathProxy.js +27 -48
  87. package/dist/json-patch/state.d.ts +5 -2
  88. package/dist/json-patch/state.js +11 -7
  89. package/dist/json-patch/transformPatch.d.ts +6 -2
  90. package/dist/json-patch/transformPatch.js +21 -24
  91. package/dist/json-patch/types.d.ts +9 -7
  92. package/dist/json-patch/types.js +0 -1
  93. package/dist/json-patch/utils/deepEqual.d.ts +3 -1
  94. package/dist/json-patch/utils/deepEqual.js +32 -28
  95. package/dist/json-patch/utils/exit.d.ts +5 -2
  96. package/dist/json-patch/utils/exit.js +7 -3
  97. package/dist/json-patch/utils/get.d.ts +5 -2
  98. package/dist/json-patch/utils/get.js +8 -4
  99. package/dist/json-patch/utils/getOpData.d.ts +5 -2
  100. package/dist/json-patch/utils/getOpData.js +12 -9
  101. package/dist/json-patch/utils/getType.d.ts +6 -3
  102. package/dist/json-patch/utils/getType.js +9 -4
  103. package/dist/json-patch/utils/index.d.ts +15 -14
  104. package/dist/json-patch/utils/index.js +14 -14
  105. package/dist/json-patch/utils/log.d.ts +4 -2
  106. package/dist/json-patch/utils/log.js +8 -3
  107. package/dist/json-patch/utils/ops.d.ts +8 -5
  108. package/dist/json-patch/utils/ops.js +83 -100
  109. package/dist/json-patch/utils/paths.d.ts +12 -9
  110. package/dist/json-patch/utils/paths.js +54 -51
  111. package/dist/json-patch/utils/pluck.d.ts +8 -5
  112. package/dist/json-patch/utils/pluck.js +32 -26
  113. package/dist/json-patch/utils/shallowCopy.d.ts +3 -1
  114. package/dist/json-patch/utils/shallowCopy.js +22 -18
  115. package/dist/json-patch/utils/softWrites.d.ts +6 -3
  116. package/dist/json-patch/utils/softWrites.js +17 -16
  117. package/dist/json-patch/utils/toArrayIndex.d.ts +3 -1
  118. package/dist/json-patch/utils/toArrayIndex.js +14 -10
  119. package/dist/json-patch/utils/toKeys.d.ts +3 -1
  120. package/dist/json-patch/utils/toKeys.js +15 -11
  121. package/dist/json-patch/utils/updateArrayIndexes.d.ts +5 -2
  122. package/dist/json-patch/utils/updateArrayIndexes.js +33 -37
  123. package/dist/json-patch/utils/updateArrayPath.d.ts +5 -2
  124. package/dist/json-patch/utils/updateArrayPath.js +29 -42
  125. package/dist/net/PatchesClient.d.ts +128 -0
  126. package/dist/net/PatchesClient.js +161 -0
  127. package/dist/net/PatchesSync.d.ts +19 -9
  128. package/dist/net/PatchesSync.js +291 -386
  129. package/dist/net/error.d.ts +3 -1
  130. package/dist/net/error.js +9 -6
  131. package/dist/net/http/FetchTransport.d.ts +21 -0
  132. package/dist/net/http/FetchTransport.js +34 -0
  133. package/dist/net/index.d.ts +26 -12
  134. package/dist/net/index.js +12 -10
  135. package/dist/net/protocol/JSONRPCClient.d.ts +11 -4
  136. package/dist/net/protocol/JSONRPCClient.js +95 -103
  137. package/dist/net/protocol/JSONRPCServer.d.ts +15 -8
  138. package/dist/net/protocol/JSONRPCServer.js +101 -123
  139. package/dist/net/protocol/types.d.ts +21 -15
  140. package/dist/net/protocol/types.js +0 -1
  141. package/dist/net/protocol/utils.d.ts +12 -0
  142. package/dist/net/protocol/utils.js +15 -0
  143. package/dist/net/types.d.ts +4 -2
  144. package/dist/net/types.js +0 -1
  145. package/dist/net/webrtc/WebRTCAwareness.d.ts +14 -4
  146. package/dist/net/webrtc/WebRTCAwareness.js +111 -120
  147. package/dist/net/webrtc/WebRTCTransport.d.ts +16 -8
  148. package/dist/net/webrtc/WebRTCTransport.js +149 -157
  149. package/dist/net/webrtc/index.d.ts +10 -2
  150. package/dist/net/webrtc/index.js +2 -2
  151. package/dist/net/websocket/AuthorizationProvider.d.ts +7 -5
  152. package/dist/net/websocket/AuthorizationProvider.js +12 -17
  153. package/dist/net/websocket/PatchesWebSocket.d.ts +14 -109
  154. package/dist/net/websocket/PatchesWebSocket.js +37 -184
  155. package/dist/net/websocket/RPCServer.d.ts +19 -10
  156. package/dist/net/websocket/RPCServer.js +190 -192
  157. package/dist/net/websocket/SignalingService.d.ts +12 -32
  158. package/dist/net/websocket/SignalingService.js +126 -133
  159. package/dist/net/websocket/WebSocketServer.d.ts +17 -4
  160. package/dist/net/websocket/WebSocketServer.js +64 -72
  161. package/dist/net/websocket/WebSocketTransport.d.ts +13 -5
  162. package/dist/net/websocket/WebSocketTransport.js +178 -207
  163. package/dist/net/websocket/onlineState.d.ts +6 -3
  164. package/dist/net/websocket/onlineState.js +25 -21
  165. package/dist/server/PatchesBranchManager.d.ts +12 -5
  166. package/dist/server/PatchesBranchManager.js +132 -142
  167. package/dist/server/PatchesHistoryManager.d.ts +11 -3
  168. package/dist/server/PatchesHistoryManager.js +81 -84
  169. package/dist/server/PatchesServer.d.ts +16 -10
  170. package/dist/server/PatchesServer.js +131 -137
  171. package/dist/server/index.d.ts +7 -2
  172. package/dist/server/index.js +9 -3
  173. package/dist/server/types.d.ts +9 -3
  174. package/dist/server/types.js +0 -1
  175. package/dist/types.d.ts +49 -19
  176. package/dist/types.js +1 -1
  177. package/dist/utils/concurrency.d.ts +7 -5
  178. package/dist/utils/concurrency.js +43 -53
  179. package/dist/utils/deferred.d.ts +4 -2
  180. package/dist/utils/deferred.js +25 -21
  181. package/package.json +5 -7
@@ -1,19 +1,14 @@
1
- /**
2
- * A permissive provider that authorises every action.
3
- * WARNING: This should only be used for development/testing purposes.
4
- * Never use this in production as it allows unrestricted access.
5
- */
6
- export const allowAll = {
7
- canAccess: () => true,
1
+ import "../../chunk-IZ2YBCUP.js";
2
+ const allowAll = {
3
+ canAccess: () => true
8
4
  };
9
- /**
10
- * A secure default provider that denies all access.
11
- * This forces developers to explicitly implement proper authorization.
12
- * Use this as the default to ensure security by default.
13
- */
14
- export const denyAll = {
15
- canAccess: () => {
16
- console.warn('Authorization check failed: No authorization provider configured. Access denied.');
17
- return false;
18
- },
5
+ const denyAll = {
6
+ canAccess: () => {
7
+ console.warn("Authorization check failed: No authorization provider configured. Access denied.");
8
+ return false;
9
+ }
10
+ };
11
+ export {
12
+ allowAll,
13
+ denyAll
19
14
  };
@@ -1,20 +1,23 @@
1
- import { type Signal } from '../../event-signal.js';
2
- import type { Change, EditableVersionMetadata, ListVersionsOptions, PatchesSnapshot, PatchesState, VersionMetadata } from '../../types.js';
3
- import type { ConnectionState, PatchesAPI } from '../protocol/types.js';
4
- import { type WebSocketOptions } from './WebSocketTransport.js';
1
+ import { Signal } from '../../event-signal.js';
2
+ import { PatchesClient } from '../PatchesClient.js';
3
+ import { ConnectionState } from '../protocol/types.js';
4
+ import { WebSocketTransport, WebSocketOptions } from './WebSocketTransport.js';
5
+ import '../../types.js';
6
+ import '../../json-patch/JSONPatch.js';
7
+ import '@dabble/delta';
8
+ import '../../json-patch/types.js';
9
+ import '../protocol/JSONRPCClient.js';
10
+
5
11
  /**
6
12
  * High-level client for the Patches real-time collaboration service.
7
13
  * This class provides document subscription, patch notification handling,
8
14
  * versioning, and other OT-specific functionality
9
15
  * over a WebSocket connection.
10
16
  */
11
- export declare class PatchesWebSocket implements PatchesAPI {
12
- private rpc;
13
- private transport;
17
+ declare class PatchesWebSocket extends PatchesClient {
18
+ transport: WebSocketTransport;
14
19
  /** Signal emitted when the underlying WebSocket connection state changes. */
15
20
  readonly onStateChange: Signal<(state: ConnectionState) => void>;
16
- /** Signal emitted when the server pushes document changes. */
17
- readonly onChangesCommitted: Signal<(docId: string, changes: Change[]) => void>;
18
21
  /**
19
22
  * Creates a new Patches WebSocket client instance.
20
23
  * @param url - The WebSocket server URL to connect to
@@ -30,104 +33,6 @@ export declare class PatchesWebSocket implements PatchesAPI {
30
33
  * Terminates the connection to the Patches server.
31
34
  */
32
35
  disconnect(): void;
33
- /**
34
- * Subscribes the client to one or more documents to receive real-time updates.
35
- * @param ids - Document ID or IDs to subscribe to.
36
- * @returns A promise resolving with the list of successfully subscribed document IDs.
37
- */
38
- subscribe(ids: string | string[]): Promise<string[]>;
39
- /**
40
- * Unsubscribes the client from one or more documents.
41
- * @param ids - Document ID or IDs to unsubscribe from.
42
- * @returns A promise resolving when the unsubscription is confirmed.
43
- */
44
- unsubscribe(ids: string | string[]): Promise<void>;
45
- /**
46
- * Gets the latest state (content and revision) of a document.
47
- * @param docId - The ID of the document.
48
- * @returns A promise resolving with the document snapshot.
49
- */
50
- getDoc(docId: string, atRev?: number): Promise<PatchesState>;
51
- /**
52
- * Gets changes that occurred for a document after a specific revision number.
53
- * @param docId - The ID of the document.
54
- * @param rev - The revision number after which to fetch changes.
55
- * @returns A promise resolving with an array of changes.
56
- */
57
- getChangesSince(docId: string, rev: number): Promise<Change[]>;
58
- /**
59
- * Applies a set of client-generated changes to a document on the server.
60
- * @param docId - The ID of the document.
61
- * @param changes - An array of changes to apply.
62
- * @returns A promise resolving with the changes as committed by the server (potentially transformed).
63
- */
64
- commitChanges(docId: string, changes: Change[]): Promise<Change[]>;
65
- /**
66
- * Deletes a document on the server.
67
- * @param docId - The ID of the document to delete.
68
- * @returns A promise resolving when the deletion is confirmed.
69
- */
70
- deleteDoc(docId: string): Promise<void>;
71
- /**
72
- * Creates a named version snapshot of a document's current state on the server.
73
- * @param docId - The ID of the document.
74
- * @param name - A descriptive name for the version.
75
- * @returns A promise resolving with the unique ID of the newly created version.
76
- */
77
- createVersion(docId: string, metadata: EditableVersionMetadata): Promise<string>;
78
- /**
79
- * Lists metadata for saved versions of a document.
80
- * @param docId - The ID of the document.
81
- * @param options - Options for filtering or pagination (e.g., limit, offset).
82
- * @returns A promise resolving with an array of version metadata objects.
83
- */
84
- listVersions(docId: string, options?: ListVersionsOptions): Promise<VersionMetadata[]>;
85
- /**
86
- * Gets the document state snapshot corresponding to a specific version ID.
87
- * @param docId - The ID of the document.
88
- * @param versionId - The ID of the version to retrieve.
89
- * @returns A promise resolving with the document snapshot for that version.
90
- */
91
- getVersionState(docId: string, versionId: string): Promise<PatchesSnapshot>;
92
- /**
93
- * Gets the original changes associated with a specific version ID.
94
- * @param docId - The ID of the document.
95
- * @param versionId - The ID of the version.
96
- * @returns A promise resolving with an array of changes that constitute that version.
97
- */
98
- getVersionChanges(docId: string, versionId: string): Promise<Change[]>;
99
- /**
100
- * Updates the name of a specific version.
101
- * @param docId - The ID of the document.
102
- * @param versionId - The ID of the version to update.
103
- * @param name - The new name for the version.
104
- * @returns A promise resolving when the update is confirmed.
105
- */
106
- updateVersion(docId: string, versionId: string, metadata: EditableVersionMetadata): Promise<void>;
107
- /**
108
- * Lists all branches for a document.
109
- * @param docId - The ID of the document.
110
- * @returns A promise resolving with an array of branch metadata objects.
111
- */
112
- listBranches(docId: string): Promise<VersionMetadata[]>;
113
- /**
114
- * Creates a new branch for a document.
115
- * @param docId - The ID of the document.
116
- * @param rev - The revision number to base the new branch on.
117
- * @param metadata - Optional metadata for the new branch.
118
- * @returns A promise resolving with the unique ID of the newly created branch.
119
- */
120
- createBranch(docId: string, rev: number, metadata?: EditableVersionMetadata): Promise<string>;
121
- /**
122
- * Closes a branch on the server.
123
- * @param branchId - The ID of the branch to close.
124
- * @returns A promise resolving when the branch is closed.
125
- */
126
- closeBranch(branchId: string): Promise<void>;
127
- /**
128
- * Merges a branch on the server.
129
- * @param branchId - The ID of the branch to merge.
130
- * @returns A promise resolving when the merge is confirmed.
131
- */
132
- mergeBranch(branchId: string): Promise<void>;
133
36
  }
37
+
38
+ export { PatchesWebSocket };
@@ -1,185 +1,38 @@
1
- import { signal } from '../../event-signal.js';
2
- import { JSONRPCClient } from '../protocol/JSONRPCClient.js';
3
- import { WebSocketTransport } from './WebSocketTransport.js';
4
- /**
5
- * High-level client for the Patches real-time collaboration service.
6
- * This class provides document subscription, patch notification handling,
7
- * versioning, and other OT-specific functionality
8
- * over a WebSocket connection.
9
- */
10
- export class PatchesWebSocket {
11
- rpc;
12
- transport;
13
- // --- Public Signals ---
14
- /** Signal emitted when the underlying WebSocket connection state changes. */
15
- onStateChange;
16
- /** Signal emitted when the server pushes document changes. */
17
- onChangesCommitted = signal();
18
- /**
19
- * Creates a new Patches WebSocket client instance.
20
- * @param url - The WebSocket server URL to connect to
21
- * @param wsOptions - Optional configuration for the underlying WebSocket connection
22
- */
23
- constructor(url, wsOptions) {
24
- this.transport = new WebSocketTransport(url, wsOptions);
25
- this.rpc = new JSONRPCClient(this.transport);
26
- this.onStateChange = this.transport.onStateChange;
27
- // Register handlers for server-sent notifications
28
- // Note: Type assertions might be needed if rpc.on doesn't infer strongly enough
29
- this.rpc.on('changesCommitted', (params) => {
30
- const { docId, changes } = params;
31
- this.onChangesCommitted.emit(docId, changes);
32
- });
33
- }
34
- // --- Connection Management ---
35
- /**
36
- * Establishes a connection to the Patches server.
37
- * @returns A promise that resolves when the connection is established
38
- */
39
- async connect() {
40
- await this.transport.connect();
41
- }
42
- /**
43
- * Terminates the connection to the Patches server.
44
- */
45
- disconnect() {
46
- // Unsubscribe rpc listeners? JSONRPCClient should handle this if transport disconnects.
47
- this.transport.disconnect();
48
- // Consider clearing signal listeners here if needed, though they are instance-based.
49
- }
50
- // --- Patches API Methods ---
51
- // === Subscription Operations ===
52
- /**
53
- * Subscribes the client to one or more documents to receive real-time updates.
54
- * @param ids - Document ID or IDs to subscribe to.
55
- * @returns A promise resolving with the list of successfully subscribed document IDs.
56
- */
57
- async subscribe(ids) {
58
- return this.rpc.request('subscribe', { ids });
59
- }
60
- /**
61
- * Unsubscribes the client from one or more documents.
62
- * @param ids - Document ID or IDs to unsubscribe from.
63
- * @returns A promise resolving when the unsubscription is confirmed.
64
- */
65
- async unsubscribe(ids) {
66
- return this.rpc.request('unsubscribe', { ids });
67
- }
68
- // === Document Operations ===
69
- /**
70
- * Gets the latest state (content and revision) of a document.
71
- * @param docId - The ID of the document.
72
- * @returns A promise resolving with the document snapshot.
73
- */
74
- async getDoc(docId, atRev) {
75
- return this.rpc.request('getDoc', { docId, atRev });
76
- }
77
- /**
78
- * Gets changes that occurred for a document after a specific revision number.
79
- * @param docId - The ID of the document.
80
- * @param rev - The revision number after which to fetch changes.
81
- * @returns A promise resolving with an array of changes.
82
- */
83
- async getChangesSince(docId, rev) {
84
- return this.rpc.request('getChangesSince', { docId, rev });
85
- }
86
- /**
87
- * Applies a set of client-generated changes to a document on the server.
88
- * @param docId - The ID of the document.
89
- * @param changes - An array of changes to apply.
90
- * @returns A promise resolving with the changes as committed by the server (potentially transformed).
91
- */
92
- async commitChanges(docId, changes) {
93
- return this.rpc.request('commitChanges', { docId, changes });
94
- }
95
- /**
96
- * Deletes a document on the server.
97
- * @param docId - The ID of the document to delete.
98
- * @returns A promise resolving when the deletion is confirmed.
99
- */
100
- async deleteDoc(docId) {
101
- return this.rpc.request('deleteDoc', { docId });
102
- }
103
- // === Version Operations ===
104
- /**
105
- * Creates a named version snapshot of a document's current state on the server.
106
- * @param docId - The ID of the document.
107
- * @param name - A descriptive name for the version.
108
- * @returns A promise resolving with the unique ID of the newly created version.
109
- */
110
- async createVersion(docId, metadata) {
111
- return this.rpc.request('createVersion', { docId, metadata });
112
- }
113
- /**
114
- * Lists metadata for saved versions of a document.
115
- * @param docId - The ID of the document.
116
- * @param options - Options for filtering or pagination (e.g., limit, offset).
117
- * @returns A promise resolving with an array of version metadata objects.
118
- */
119
- async listVersions(docId, options) {
120
- return this.rpc.request('listVersions', { docId, options });
121
- }
122
- /**
123
- * Gets the document state snapshot corresponding to a specific version ID.
124
- * @param docId - The ID of the document.
125
- * @param versionId - The ID of the version to retrieve.
126
- * @returns A promise resolving with the document snapshot for that version.
127
- */
128
- async getVersionState(docId, versionId) {
129
- return this.rpc.request('getVersionState', { docId, versionId });
130
- }
131
- /**
132
- * Gets the original changes associated with a specific version ID.
133
- * @param docId - The ID of the document.
134
- * @param versionId - The ID of the version.
135
- * @returns A promise resolving with an array of changes that constitute that version.
136
- */
137
- async getVersionChanges(docId, versionId) {
138
- return this.rpc.request('getVersionChanges', { docId, versionId });
139
- }
140
- /**
141
- * Updates the name of a specific version.
142
- * @param docId - The ID of the document.
143
- * @param versionId - The ID of the version to update.
144
- * @param name - The new name for the version.
145
- * @returns A promise resolving when the update is confirmed.
146
- */
147
- async updateVersion(docId, versionId, metadata) {
148
- return this.rpc.request('updateVersion', { docId, versionId, metadata });
149
- }
150
- // === Branch Operations ===
151
- /**
152
- * Lists all branches for a document.
153
- * @param docId - The ID of the document.
154
- * @returns A promise resolving with an array of branch metadata objects.
155
- */
156
- async listBranches(docId) {
157
- return this.rpc.request('listBranches', { docId });
158
- }
159
- /**
160
- * Creates a new branch for a document.
161
- * @param docId - The ID of the document.
162
- * @param rev - The revision number to base the new branch on.
163
- * @param metadata - Optional metadata for the new branch.
164
- * @returns A promise resolving with the unique ID of the newly created branch.
165
- */
166
- async createBranch(docId, rev, metadata) {
167
- return this.rpc.request('createBranch', { docId, rev, metadata });
168
- }
169
- /**
170
- * Closes a branch on the server.
171
- * @param branchId - The ID of the branch to close.
172
- * @returns A promise resolving when the branch is closed.
173
- */
174
- async closeBranch(branchId) {
175
- return this.rpc.request('closeBranch', { branchId });
176
- }
177
- /**
178
- * Merges a branch on the server.
179
- * @param branchId - The ID of the branch to merge.
180
- * @returns A promise resolving when the merge is confirmed.
181
- */
182
- async mergeBranch(branchId) {
183
- return this.rpc.request('mergeBranch', { branchId });
184
- }
1
+ import "../../chunk-IZ2YBCUP.js";
2
+ import {} from "../../event-signal.js";
3
+ import { PatchesClient } from "../PatchesClient.js";
4
+ import { WebSocketTransport } from "./WebSocketTransport.js";
5
+ class PatchesWebSocket extends PatchesClient {
6
+ transport;
7
+ // --- Public Signals ---
8
+ /** Signal emitted when the underlying WebSocket connection state changes. */
9
+ onStateChange;
10
+ /**
11
+ * Creates a new Patches WebSocket client instance.
12
+ * @param url - The WebSocket server URL to connect to
13
+ * @param wsOptions - Optional configuration for the underlying WebSocket connection
14
+ */
15
+ constructor(url, wsOptions) {
16
+ const transport = new WebSocketTransport(url, wsOptions);
17
+ super(transport);
18
+ this.transport = transport;
19
+ this.onStateChange = this.transport.onStateChange;
20
+ }
21
+ // --- Connection Management ---
22
+ /**
23
+ * Establishes a connection to the Patches server.
24
+ * @returns A promise that resolves when the connection is established
25
+ */
26
+ async connect() {
27
+ await this.transport.connect();
28
+ }
29
+ /**
30
+ * Terminates the connection to the Patches server.
31
+ */
32
+ disconnect() {
33
+ this.transport.disconnect();
34
+ }
185
35
  }
36
+ export {
37
+ PatchesWebSocket
38
+ };
@@ -1,21 +1,28 @@
1
- import type { PatchesBranchManager } from '../../server/PatchesBranchManager.js';
2
- import type { PatchesHistoryManager } from '../../server/PatchesHistoryManager.js';
3
- import type { PatchesServer } from '../../server/PatchesServer.js';
4
- import type { Change, EditableVersionMetadata, ListChangesOptions, ListVersionsOptions } from '../../types.js';
1
+ import { PatchesState, Change, ListVersionsOptions, VersionMetadata, EditableVersionMetadata, ListChangesOptions, Branch } from '../../types.js';
2
+ import { PatchesBranchManager } from '../../server/PatchesBranchManager.js';
3
+ import { PatchesHistoryManager } from '../../server/PatchesHistoryManager.js';
4
+ import { PatchesServer } from '../../server/PatchesServer.js';
5
5
  import { JSONRPCServer } from '../protocol/JSONRPCServer.js';
6
- import { type AuthContext, type AuthorizationProvider } from './AuthorizationProvider.js';
6
+ import { AuthorizationProvider, AuthContext } from './AuthorizationProvider.js';
7
+ import '../../json-patch/JSONPatch.js';
8
+ import '@dabble/delta';
9
+ import '../../json-patch/types.js';
10
+ import '../../server/types.js';
11
+ import '../../event-signal.js';
12
+ import '../protocol/types.js';
13
+
7
14
  /**
8
15
  * High-level client for the Patches real-time collaboration service.
9
16
  * This class provides document subscription, patch notification handling,
10
17
  * versioning, and other OT-specific functionality over a JSON RPC interface.
11
18
  */
12
- export interface RPCServerOptions {
19
+ interface RPCServerOptions {
13
20
  patches: PatchesServer;
14
21
  history?: PatchesHistoryManager;
15
22
  branches?: PatchesBranchManager;
16
23
  auth?: AuthorizationProvider;
17
24
  }
18
- export declare class RPCServer {
25
+ declare class RPCServer {
19
26
  rpc: JSONRPCServer;
20
27
  auth: AuthorizationProvider;
21
28
  protected patches: PatchesServer;
@@ -39,7 +46,7 @@ export declare class RPCServer {
39
46
  getDoc(params: {
40
47
  docId: string;
41
48
  atRev?: number;
42
- }, ctx?: AuthContext): Promise<import("../../types.js").PatchesState<any>>;
49
+ }, ctx?: AuthContext): Promise<PatchesState<any>>;
43
50
  /**
44
51
  * Gets changes that occurred for a document after a specific revision number.
45
52
  * @param connectionId - The ID of the connection making the request
@@ -74,7 +81,7 @@ export declare class RPCServer {
74
81
  listVersions(params: {
75
82
  docId: string;
76
83
  options?: ListVersionsOptions;
77
- }, ctx?: AuthContext): Promise<import("../../types.js").VersionMetadata[]>;
84
+ }, ctx?: AuthContext): Promise<VersionMetadata[]>;
78
85
  createVersion(params: {
79
86
  docId: string;
80
87
  metadata: EditableVersionMetadata;
@@ -98,7 +105,7 @@ export declare class RPCServer {
98
105
  }, ctx?: AuthContext): Promise<Change[]>;
99
106
  listBranches(params: {
100
107
  docId: string;
101
- }, ctx?: AuthContext): Promise<import("../../types.js").Branch[]>;
108
+ }, ctx?: AuthContext): Promise<Branch[]>;
102
109
  createBranch(params: {
103
110
  docId: string;
104
111
  rev: number;
@@ -116,3 +123,5 @@ export declare class RPCServer {
116
123
  protected assertHistoryEnabled(): void;
117
124
  protected assertBranchingEnabled(): void;
118
125
  }
126
+
127
+ export { RPCServer, type RPCServerOptions };