@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,193 +1,191 @@
1
- import { StatusError } from '../error.js';
2
- import { JSONRPCServer } from '../protocol/JSONRPCServer.js';
3
- import { denyAll } from './AuthorizationProvider.js';
4
- export class RPCServer {
5
- rpc;
6
- auth;
7
- patches;
8
- history;
9
- branches;
10
- /**
11
- * Creates a new Patches WebSocket client instance.
12
- * @param patches - The patches server instance to handle document operations
13
- * @param history - (Optional) History manager instance to handle versioning operations
14
- * @param branches - (Optional) Branch manager instance to handle branching operations
15
- * @param auth - (Optional) Authorization provider implementation. Defaults to deny-all for security.
16
- */
17
- constructor({ patches, history, branches, auth = denyAll }) {
18
- this.rpc = new JSONRPCServer();
19
- this.patches = patches;
20
- this.history = history;
21
- this.branches = branches;
22
- this.auth = auth;
23
- // Document operations
24
- this.rpc.registerMethod('getDoc', this.getDoc.bind(this));
25
- this.rpc.registerMethod('getChangesSince', this.getChangesSince.bind(this));
26
- this.rpc.registerMethod('commitChanges', this.commitChanges.bind(this));
27
- this.rpc.registerMethod('deleteDoc', this.deleteDoc.bind(this));
28
- // History manager operations (if provided)
29
- if (this.history) {
30
- this.rpc.registerMethod('listVersions', this.listVersions.bind(this));
31
- this.rpc.registerMethod('createVersion', this.createVersion.bind(this));
32
- this.rpc.registerMethod('updateVersion', this.updateVersion.bind(this));
33
- this.rpc.registerMethod('getVersionState', this.getVersionState.bind(this));
34
- this.rpc.registerMethod('getVersionChanges', this.getVersionChanges.bind(this));
35
- this.rpc.registerMethod('listServerChanges', this.listServerChanges.bind(this));
36
- }
37
- // Branch manager operations (if provided)
38
- if (this.branches) {
39
- this.rpc.registerMethod('listBranches', this.listBranches.bind(this));
40
- this.rpc.registerMethod('createBranch', this.createBranch.bind(this));
41
- this.rpc.registerMethod('closeBranch', this.closeBranch.bind(this));
42
- this.rpc.registerMethod('mergeBranch', this.mergeBranch.bind(this));
43
- }
44
- // -------------------------------------------------------------------------
45
- // Listen to core server events and forward as JSON-RPC notifications
46
- // -------------------------------------------------------------------------
47
- this.patches.onChangesCommitted((docId, changes, originClientId) => {
48
- this.rpc.notify('changesCommitted', { docId, changes }, originClientId);
49
- });
50
- this.patches.onDocDeleted((docId, originClientId) => {
51
- this.rpc.notify('docDeleted', { docId }, originClientId);
52
- });
53
- }
54
- /**
55
- * Gets the latest state (content and revision) of a document.
56
- * @param connectionId - The ID of the connection making the request
57
- * @param params - The document parameters
58
- * @param params.docId - The ID of the document
59
- * @param params.atRev - Optional revision number to get document state at
60
- */
61
- async getDoc(params, ctx) {
62
- const { docId, atRev } = params;
63
- await this.assertRead(ctx, docId, 'getDoc', params);
64
- return this.patches.getDoc(docId, atRev);
65
- }
66
- /**
67
- * Gets changes that occurred for a document after a specific revision number.
68
- * @param connectionId - The ID of the connection making the request
69
- * @param params - The change request parameters
70
- * @param params.docId - The ID of the document
71
- * @param params.rev - The revision number after which to fetch changes
72
- */
73
- async getChangesSince(params, ctx) {
74
- const { docId, rev } = params;
75
- await this.assertRead(ctx, docId, 'getChangesSince', params);
76
- return this.patches.getChangesSince(docId, rev);
77
- }
78
- /**
79
- * Applies a set of client-generated changes to a document on the server.
80
- * @param connectionId - The ID of the connection making the request
81
- * @param params - The change parameters
82
- * @param params.docId - The ID of the document
83
- * @param params.changes - An array of changes to apply
84
- */
85
- async commitChanges(params, ctx) {
86
- const { docId, changes } = params;
87
- await this.assertWrite(ctx, docId, 'commitChanges', params);
88
- const [priorChanges, newChanges] = await this.patches.commitChanges(docId, changes, ctx?.clientId);
89
- return [...priorChanges, ...newChanges];
90
- }
91
- /**
92
- * Deletes a document on the server.
93
- * @param connectionId - The ID of the connection making the request
94
- * @param params - The deletion parameters
95
- * @param params.docId - The ID of the document to delete
96
- */
97
- async deleteDoc(params, ctx) {
98
- const { docId } = params;
99
- await this.assertWrite(ctx, docId, 'deleteDoc', params);
100
- await this.patches.deleteDoc(docId, ctx?.clientId);
101
- }
102
- // ---------------------------------------------------------------------------
103
- // History Manager wrappers
104
- // ---------------------------------------------------------------------------
105
- async listVersions(params, ctx) {
106
- this.assertHistoryEnabled();
107
- const { docId, options } = params;
108
- await this.assertRead(ctx, docId, 'listVersions', params);
109
- return this.history.listVersions(docId, options ?? {});
110
- }
111
- async createVersion(params, ctx) {
112
- this.assertHistoryEnabled();
113
- const { docId, metadata } = params;
114
- await this.assertWrite(ctx, docId, 'createVersion', params);
115
- return this.history.createVersion(docId, metadata);
116
- }
117
- async updateVersion(params, ctx) {
118
- this.assertHistoryEnabled();
119
- const { docId, versionId, metadata } = params;
120
- await this.assertWrite(ctx, docId, 'updateVersion', params);
121
- return this.history.updateVersion(docId, versionId, metadata);
122
- }
123
- async getVersionState(params, ctx) {
124
- this.assertHistoryEnabled();
125
- const { docId, versionId } = params;
126
- await this.assertRead(ctx, docId, 'getStateAtVersion', params);
127
- return this.history.getStateAtVersion(docId, versionId);
128
- }
129
- async getVersionChanges(params, ctx) {
130
- this.assertHistoryEnabled();
131
- const { docId, versionId } = params;
132
- await this.assertRead(ctx, docId, 'getChangesForVersion', params);
133
- return this.history.getChangesForVersion(docId, versionId);
134
- }
135
- async listServerChanges(params, ctx) {
136
- this.assertHistoryEnabled();
137
- const { docId, options } = params;
138
- await this.assertRead(ctx, docId, 'listServerChanges', params);
139
- return this.history.listServerChanges(docId, options ?? {});
140
- }
141
- // ---------------------------------------------------------------------------
142
- // Branch Manager wrappers
143
- // ---------------------------------------------------------------------------
144
- async listBranches(params, ctx) {
145
- this.assertBranchingEnabled();
146
- const { docId } = params;
147
- await this.assertRead(ctx, docId, 'listBranches', params);
148
- return this.branches.listBranches(docId);
149
- }
150
- async createBranch(params, ctx) {
151
- this.assertBranchingEnabled();
152
- const { docId, rev, metadata } = params;
153
- await this.assertWrite(ctx, docId, 'createBranch', params);
154
- return this.branches.createBranch(docId, rev, metadata);
155
- }
156
- async closeBranch(params, ctx) {
157
- this.assertBranchingEnabled();
158
- const { branchId } = params;
159
- await this.assertWrite(ctx, branchId, 'closeBranch', params);
160
- return this.branches.closeBranch(branchId, 'closed');
161
- }
162
- async mergeBranch(params, ctx) {
163
- this.assertBranchingEnabled();
164
- const { branchId } = params;
165
- await this.assertWrite(ctx, branchId, 'mergeBranch', params);
166
- return this.branches.mergeBranch(branchId);
167
- }
168
- // ---------------------------------------------------------------------------
169
- // Authorization helpers
170
- // ---------------------------------------------------------------------------
171
- async assertAccess(ctx, docId, kind, method, params) {
172
- const ok = await this.auth.canAccess(ctx, docId, kind, method, params);
173
- if (!ok) {
174
- throw new StatusError(401, `${kind.toUpperCase()}_FORBIDDEN:${docId}`);
175
- }
176
- }
177
- assertRead(ctx, docId, method, params) {
178
- return this.assertAccess(ctx, docId, 'read', method, params);
179
- }
180
- assertWrite(ctx, docId, method, params) {
181
- return this.assertAccess(ctx, docId, 'write', method, params);
182
- }
183
- assertHistoryEnabled() {
184
- if (!this.history) {
185
- throw new StatusError(404, 'History is not enabled');
186
- }
187
- }
188
- assertBranchingEnabled() {
189
- if (!this.branches) {
190
- throw new StatusError(404, 'Branching is not enabled');
191
- }
192
- }
1
+ import "../../chunk-IZ2YBCUP.js";
2
+ import { StatusError } from "../error.js";
3
+ import { JSONRPCServer } from "../protocol/JSONRPCServer.js";
4
+ import { denyAll } from "./AuthorizationProvider.js";
5
+ class RPCServer {
6
+ rpc;
7
+ auth;
8
+ patches;
9
+ history;
10
+ branches;
11
+ /**
12
+ * Creates a new Patches WebSocket client instance.
13
+ * @param patches - The patches server instance to handle document operations
14
+ * @param history - (Optional) History manager instance to handle versioning operations
15
+ * @param branches - (Optional) Branch manager instance to handle branching operations
16
+ * @param auth - (Optional) Authorization provider implementation. Defaults to deny-all for security.
17
+ */
18
+ constructor({ patches, history, branches, auth = denyAll }) {
19
+ this.rpc = new JSONRPCServer();
20
+ this.patches = patches;
21
+ this.history = history;
22
+ this.branches = branches;
23
+ this.auth = auth;
24
+ this.rpc.registerMethod("getDoc", this.getDoc.bind(this));
25
+ this.rpc.registerMethod("getChangesSince", this.getChangesSince.bind(this));
26
+ this.rpc.registerMethod("commitChanges", this.commitChanges.bind(this));
27
+ this.rpc.registerMethod("deleteDoc", this.deleteDoc.bind(this));
28
+ if (this.history) {
29
+ this.rpc.registerMethod("listVersions", this.listVersions.bind(this));
30
+ this.rpc.registerMethod("createVersion", this.createVersion.bind(this));
31
+ this.rpc.registerMethod("updateVersion", this.updateVersion.bind(this));
32
+ this.rpc.registerMethod("getVersionState", this.getVersionState.bind(this));
33
+ this.rpc.registerMethod("getVersionChanges", this.getVersionChanges.bind(this));
34
+ this.rpc.registerMethod("listServerChanges", this.listServerChanges.bind(this));
35
+ }
36
+ if (this.branches) {
37
+ this.rpc.registerMethod("listBranches", this.listBranches.bind(this));
38
+ this.rpc.registerMethod("createBranch", this.createBranch.bind(this));
39
+ this.rpc.registerMethod("closeBranch", this.closeBranch.bind(this));
40
+ this.rpc.registerMethod("mergeBranch", this.mergeBranch.bind(this));
41
+ }
42
+ this.patches.onChangesCommitted((docId, changes, originClientId) => {
43
+ this.rpc.notify("changesCommitted", { docId, changes }, originClientId);
44
+ });
45
+ this.patches.onDocDeleted((docId, originClientId) => {
46
+ this.rpc.notify("docDeleted", { docId }, originClientId);
47
+ });
48
+ }
49
+ /**
50
+ * Gets the latest state (content and revision) of a document.
51
+ * @param connectionId - The ID of the connection making the request
52
+ * @param params - The document parameters
53
+ * @param params.docId - The ID of the document
54
+ * @param params.atRev - Optional revision number to get document state at
55
+ */
56
+ async getDoc(params, ctx) {
57
+ const { docId, atRev } = params;
58
+ await this.assertRead(ctx, docId, "getDoc", params);
59
+ return this.patches.getDoc(docId, atRev);
60
+ }
61
+ /**
62
+ * Gets changes that occurred for a document after a specific revision number.
63
+ * @param connectionId - The ID of the connection making the request
64
+ * @param params - The change request parameters
65
+ * @param params.docId - The ID of the document
66
+ * @param params.rev - The revision number after which to fetch changes
67
+ */
68
+ async getChangesSince(params, ctx) {
69
+ const { docId, rev } = params;
70
+ await this.assertRead(ctx, docId, "getChangesSince", params);
71
+ return this.patches.getChangesSince(docId, rev);
72
+ }
73
+ /**
74
+ * Applies a set of client-generated changes to a document on the server.
75
+ * @param connectionId - The ID of the connection making the request
76
+ * @param params - The change parameters
77
+ * @param params.docId - The ID of the document
78
+ * @param params.changes - An array of changes to apply
79
+ */
80
+ async commitChanges(params, ctx) {
81
+ const { docId, changes } = params;
82
+ await this.assertWrite(ctx, docId, "commitChanges", params);
83
+ const [priorChanges, newChanges] = await this.patches.commitChanges(docId, changes, ctx?.clientId);
84
+ return [...priorChanges, ...newChanges];
85
+ }
86
+ /**
87
+ * Deletes a document on the server.
88
+ * @param connectionId - The ID of the connection making the request
89
+ * @param params - The deletion parameters
90
+ * @param params.docId - The ID of the document to delete
91
+ */
92
+ async deleteDoc(params, ctx) {
93
+ const { docId } = params;
94
+ await this.assertWrite(ctx, docId, "deleteDoc", params);
95
+ await this.patches.deleteDoc(docId, ctx?.clientId);
96
+ }
97
+ // ---------------------------------------------------------------------------
98
+ // History Manager wrappers
99
+ // ---------------------------------------------------------------------------
100
+ async listVersions(params, ctx) {
101
+ this.assertHistoryEnabled();
102
+ const { docId, options } = params;
103
+ await this.assertRead(ctx, docId, "listVersions", params);
104
+ return this.history.listVersions(docId, options ?? {});
105
+ }
106
+ async createVersion(params, ctx) {
107
+ this.assertHistoryEnabled();
108
+ const { docId, metadata } = params;
109
+ await this.assertWrite(ctx, docId, "createVersion", params);
110
+ return this.history.createVersion(docId, metadata);
111
+ }
112
+ async updateVersion(params, ctx) {
113
+ this.assertHistoryEnabled();
114
+ const { docId, versionId, metadata } = params;
115
+ await this.assertWrite(ctx, docId, "updateVersion", params);
116
+ return this.history.updateVersion(docId, versionId, metadata);
117
+ }
118
+ async getVersionState(params, ctx) {
119
+ this.assertHistoryEnabled();
120
+ const { docId, versionId } = params;
121
+ await this.assertRead(ctx, docId, "getStateAtVersion", params);
122
+ return this.history.getStateAtVersion(docId, versionId);
123
+ }
124
+ async getVersionChanges(params, ctx) {
125
+ this.assertHistoryEnabled();
126
+ const { docId, versionId } = params;
127
+ await this.assertRead(ctx, docId, "getChangesForVersion", params);
128
+ return this.history.getChangesForVersion(docId, versionId);
129
+ }
130
+ async listServerChanges(params, ctx) {
131
+ this.assertHistoryEnabled();
132
+ const { docId, options } = params;
133
+ await this.assertRead(ctx, docId, "listServerChanges", params);
134
+ return this.history.listServerChanges(docId, options ?? {});
135
+ }
136
+ // ---------------------------------------------------------------------------
137
+ // Branch Manager wrappers
138
+ // ---------------------------------------------------------------------------
139
+ async listBranches(params, ctx) {
140
+ this.assertBranchingEnabled();
141
+ const { docId } = params;
142
+ await this.assertRead(ctx, docId, "listBranches", params);
143
+ return this.branches.listBranches(docId);
144
+ }
145
+ async createBranch(params, ctx) {
146
+ this.assertBranchingEnabled();
147
+ const { docId, rev, metadata } = params;
148
+ await this.assertWrite(ctx, docId, "createBranch", params);
149
+ return this.branches.createBranch(docId, rev, metadata);
150
+ }
151
+ async closeBranch(params, ctx) {
152
+ this.assertBranchingEnabled();
153
+ const { branchId } = params;
154
+ await this.assertWrite(ctx, branchId, "closeBranch", params);
155
+ return this.branches.closeBranch(branchId, "closed");
156
+ }
157
+ async mergeBranch(params, ctx) {
158
+ this.assertBranchingEnabled();
159
+ const { branchId } = params;
160
+ await this.assertWrite(ctx, branchId, "mergeBranch", params);
161
+ return this.branches.mergeBranch(branchId);
162
+ }
163
+ // ---------------------------------------------------------------------------
164
+ // Authorization helpers
165
+ // ---------------------------------------------------------------------------
166
+ async assertAccess(ctx, docId, kind, method, params) {
167
+ const ok = await this.auth.canAccess(ctx, docId, kind, method, params);
168
+ if (!ok) {
169
+ throw new StatusError(401, `${kind.toUpperCase()}_FORBIDDEN:${docId}`);
170
+ }
171
+ }
172
+ assertRead(ctx, docId, method, params) {
173
+ return this.assertAccess(ctx, docId, "read", method, params);
174
+ }
175
+ assertWrite(ctx, docId, method, params) {
176
+ return this.assertAccess(ctx, docId, "write", method, params);
177
+ }
178
+ assertHistoryEnabled() {
179
+ if (!this.history) {
180
+ throw new StatusError(404, "History is not enabled");
181
+ }
182
+ }
183
+ assertBranchingEnabled() {
184
+ if (!this.branches) {
185
+ throw new StatusError(404, "Branching is not enabled");
186
+ }
187
+ }
193
188
  }
189
+ export {
190
+ RPCServer
191
+ };
@@ -1,41 +1,19 @@
1
- /**
2
- * Represents a JSON-RPC 2.0 request object.
3
- */
4
- export interface JsonRpcRequest {
5
- /** JSON-RPC protocol version, always "2.0" */
6
- jsonrpc: '2.0';
7
- /** Name of the remote procedure to call */
8
- method: string;
9
- /** Parameters to pass to the remote procedure */
10
- params?: any;
11
- /** Request identifier, used to match responses to requests */
12
- id?: number | string;
13
- }
14
- /**
15
- * Represents a JSON-RPC 2.0 response object.
16
- */
17
- export interface JsonRpcResponse {
18
- /** JSON-RPC protocol version, always "2.0" */
19
- jsonrpc: '2.0';
20
- /** Result of the successful procedure call */
21
- result?: any;
22
- /** Error information if the procedure call failed */
23
- error?: {
24
- code: number;
25
- message: string;
26
- };
27
- /** Response identifier, matches the id of the corresponding request */
28
- id: number | string;
29
- }
1
+ import { JsonRpcRequest, JsonRpcResponse } from '../protocol/types.js';
2
+ import '../../event-signal.js';
3
+ import '../../types.js';
4
+ import '../../json-patch/JSONPatch.js';
5
+ import '@dabble/delta';
6
+ import '../../json-patch/types.js';
7
+
30
8
  /** Union type for all possible JSON-RPC message types */
31
- export type JsonRpcMessage = JsonRpcRequest | JsonRpcResponse;
9
+ type JsonRpcMessage = JsonRpcRequest | JsonRpcResponse;
32
10
  /** Function type for sending JSON-RPC messages */
33
- export type SendFn = (message: JsonRpcMessage) => void;
11
+ type SendFn = (message: JsonRpcMessage) => void;
34
12
  /**
35
13
  * Service that facilitates WebRTC connection establishment by relaying signaling messages.
36
14
  * Acts as a central hub for WebRTC peers to exchange connection information.
37
15
  */
38
- export declare class SignalingService {
16
+ declare class SignalingService {
39
17
  private clients;
40
18
  /**
41
19
  * Registers a new client connection with the signaling service.
@@ -89,3 +67,5 @@ export declare class SignalingService {
89
67
  */
90
68
  private broadcast;
91
69
  }
70
+
71
+ export { type JsonRpcMessage, type SendFn, SignalingService };