@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,129 +1,107 @@
1
- import { signal } from '../../event-signal.js';
2
- /**
3
- * Lightweight JSON-RPC 2.0 server adapter for {@link PatchesServer}.
4
- *
5
- * The class is intentionally transport-agnostic: it only needs an object that
6
- * fulfils the {@link Transport} contract (i.e. something that can exchange
7
- * string messages and notify when one arrives). This makes it suitable for
8
- * WebSocket, TCP, or even `postMessage` usage.
9
- *
10
- * A new instance is typically created per connected client. You therefore
11
- * pass in:
12
- * • the {@link Transport} that represents this client connection
13
- * • a shared (singleton) {@link PatchesServer}
14
- * • the unique `clientId` that identifies the connection in subscription
15
- * calls. How you generate that ID (auth token, random GUID, etc.) is left
16
- * to the host application.
17
- */
18
- export class JSONRPCServer {
19
- /** Map of fully-qualified JSON-RPC method → handler function */
20
- handlers = new Map();
21
- /** Allow external callers to emit server-initiated notifications. */
22
- notificationSignals = new Map();
23
- /** Allow external callers to emit server-initiated notifications. */
24
- onNotify = signal();
25
- // -------------------------------------------------------------------------
26
- // Registration API
27
- // -------------------------------------------------------------------------
28
- /**
29
- * Registers a JSON-RPC method.
30
- *
31
- * @param method Fully-qualified method name (e.g. "patches.subscribe").
32
- * @param handler Function that performs the work and returns the result.
33
- */
34
- registerMethod(method, handler) {
35
- if (this.handlers.has(method)) {
36
- throw new Error(`A handler for method '${method}' is already registered.`);
37
- }
38
- this.handlers.set(method, handler);
1
+ import "../../chunk-IZ2YBCUP.js";
2
+ import { signal } from "../../event-signal.js";
3
+ import { rpcError, rpcNotification, rpcResponse } from "./utils.js";
4
+ class JSONRPCServer {
5
+ /** Map of fully-qualified JSON-RPC method handler function */
6
+ handlers = /* @__PURE__ */ new Map();
7
+ /** Allow external callers to emit server-initiated notifications. */
8
+ notificationSignals = /* @__PURE__ */ new Map();
9
+ /** Allow external callers to emit server-initiated notifications. */
10
+ onNotify = signal();
11
+ // -------------------------------------------------------------------------
12
+ // Registration API
13
+ // -------------------------------------------------------------------------
14
+ /**
15
+ * Registers a JSON-RPC method.
16
+ *
17
+ * @param method Fully-qualified method name (e.g. "patches.subscribe").
18
+ * @param handler Function that performs the work and returns the result.
19
+ */
20
+ registerMethod(method, handler) {
21
+ if (this.handlers.has(method)) {
22
+ throw new Error(`A handler for method '${method}' is already registered.`);
39
23
  }
40
- // -------------------------------------------------------------------------
41
- // Public helpers
42
- // -------------------------------------------------------------------------
43
- /**
44
- * Subscribes to server-sent notifications for a specific method.
45
- *
46
- * @param method - The notification method name to subscribe to
47
- * @param handler - The callback function that will be invoked when notifications are received
48
- * @returns A function that can be called to unsubscribe from the notifications
49
- * @template T - The type of the handler function
50
- */
51
- on(method, handler) {
52
- let thisSignal = this.notificationSignals.get(method);
53
- if (!thisSignal) {
54
- thisSignal = signal();
55
- this.notificationSignals.set(method, thisSignal);
56
- }
57
- return thisSignal(handler);
24
+ this.handlers.set(method, handler);
25
+ }
26
+ // -------------------------------------------------------------------------
27
+ // Public helpers
28
+ // -------------------------------------------------------------------------
29
+ /**
30
+ * Subscribes to server-sent notifications for a specific method.
31
+ *
32
+ * @param method - The notification method name to subscribe to
33
+ * @param handler - The callback function that will be invoked when notifications are received
34
+ * @returns A function that can be called to unsubscribe from the notifications
35
+ * @template T - The type of the handler function
36
+ */
37
+ on(method, handler) {
38
+ let thisSignal = this.notificationSignals.get(method);
39
+ if (!thisSignal) {
40
+ thisSignal = signal();
41
+ this.notificationSignals.set(method, thisSignal);
58
42
  }
59
- /**
60
- * Sends a JSON-RPC notification (no `id`, therefore no response expected) to
61
- * the connected client.
62
- */
63
- async notify(method, params, exceptConnectionId) {
64
- const msg = { jsonrpc: '2.0', method, params };
65
- this.onNotify.emit(msg, exceptConnectionId);
43
+ return thisSignal(handler);
44
+ }
45
+ /**
46
+ * Sends a JSON-RPC notification (no `id`, therefore no response expected) to
47
+ * the connected client.
48
+ */
49
+ async notify(method, params, exceptConnectionId) {
50
+ const msg = rpcNotification(method, params);
51
+ this.onNotify.emit(msg, exceptConnectionId);
52
+ }
53
+ async processMessage(raw, ctx) {
54
+ let message;
55
+ const respond = typeof raw === "string" ? JSON.stringify : (r) => r;
56
+ if (typeof raw === "string") {
57
+ try {
58
+ message = JSON.parse(raw);
59
+ } catch (err) {
60
+ return respond(rpcError(-32700, "Parse error", err));
61
+ }
62
+ } else {
63
+ message = raw;
66
64
  }
67
- async processMessage(raw, ctx) {
68
- let message;
69
- const respond = typeof raw === 'string' ? JSON.stringify : (r) => r;
70
- // --- Parse & basic validation ------------------------------------------------
71
- if (typeof raw === 'string') {
72
- try {
73
- message = JSON.parse(raw);
74
- }
75
- catch (err) {
76
- return respond(rpcError(-32700, 'Parse error', err));
77
- }
78
- }
79
- else {
80
- message = raw;
81
- }
82
- // Ensure it looks like a JSON-RPC call (must have a method field)
83
- if (!message || typeof message !== 'object' || !('method' in message)) {
84
- const invalidId = message?.id ?? null;
85
- return respond(rpcError(-32600, 'Invalid Request', invalidId));
86
- }
87
- // --- Distinguish request vs. notification -----------------------------------
88
- if ('id' in message && message.id !== undefined) {
89
- // -> Request ----------------------------------------------------------------
90
- try {
91
- const result = await this._dispatch(message.method, message.params, ctx);
92
- const response = { jsonrpc: '2.0', id: message.id, result };
93
- return respond(response);
94
- }
95
- catch (err) {
96
- return respond(rpcError(err?.code ?? -32000, err?.message ?? 'Server error', err?.code ? undefined : err?.stack));
97
- }
98
- }
99
- else {
100
- // -> Notification -----------------------------------------------------------
101
- // Forward the notification to any listeners and return nothing.
102
- const thisSignal = this.notificationSignals.get(message.method);
103
- if (thisSignal) {
104
- thisSignal.emit(message.params, ctx?.clientId);
105
- }
106
- return undefined;
107
- }
65
+ if (!message || typeof message !== "object" || !("method" in message)) {
66
+ const invalidId = message?.id ?? null;
67
+ return respond(rpcError(-32600, "Invalid Request", invalidId));
108
68
  }
109
- /**
110
- * Maps JSON-RPC method names to {@link PatchesServer} calls.
111
- * @param connectionId - The WebSocket transport object.
112
- * @param method - The JSON-RPC method name.
113
- * @param params - The JSON-RPC parameters.
114
- * @returns The result of the {@link PatchesServer} call.
115
- */
116
- async _dispatch(method, params, ctx) {
117
- const handler = this.handlers.get(method);
118
- if (!handler) {
119
- throw new Error(`Unknown method '${method}'.`);
120
- }
121
- if (!params || typeof params !== 'object' || Array.isArray(params)) {
122
- throw new Error(`Invalid parameters for method '${method}'.`);
123
- }
124
- return handler(params, ctx);
69
+ if ("id" in message && message.id !== void 0) {
70
+ try {
71
+ const result = await this._dispatch(message.method, message.params, ctx);
72
+ const response = rpcResponse(result, message.id);
73
+ return respond(response);
74
+ } catch (err) {
75
+ return respond(
76
+ rpcError(err?.code ?? -32e3, err?.message ?? "Server error", err?.code ? void 0 : err?.stack, message.id)
77
+ );
78
+ }
79
+ } else {
80
+ const thisSignal = this.notificationSignals.get(message.method);
81
+ if (thisSignal) {
82
+ thisSignal.emit(message.params, ctx?.clientId);
83
+ }
84
+ return void 0;
125
85
  }
86
+ }
87
+ /**
88
+ * Maps JSON-RPC method names to {@link PatchesServer} calls.
89
+ * @param connectionId - The WebSocket transport object.
90
+ * @param method - The JSON-RPC method name.
91
+ * @param params - The JSON-RPC parameters.
92
+ * @returns The result of the {@link PatchesServer} call.
93
+ */
94
+ async _dispatch(method, params, ctx) {
95
+ const handler = this.handlers.get(method);
96
+ if (!handler) {
97
+ throw new Error(`Unknown method '${method}'.`);
98
+ }
99
+ if (!params || typeof params !== "object" || Array.isArray(params)) {
100
+ throw new Error(`Invalid parameters for method '${method}'.`);
101
+ }
102
+ return handler(params, ctx);
103
+ }
126
104
  }
127
- function rpcError(code, message, data) {
128
- return { jsonrpc: '2.0', id: null, error: { code, message, data } };
129
- }
105
+ export {
106
+ JSONRPCServer
107
+ };
@@ -1,5 +1,9 @@
1
- import type { Unsubscriber } from '../../event-signal.js';
2
- import type { Change, EditableVersionMetadata, ListVersionsOptions, PatchesState, VersionMetadata } from '../../types.js';
1
+ import { Unsubscriber } from '../../event-signal.js';
2
+ import { PatchesState, Change, ChangeInput, EditableVersionMetadata, ListVersionsOptions, VersionMetadata } from '../../types.js';
3
+ import '../../json-patch/JSONPatch.js';
4
+ import '@dabble/delta';
5
+ import '../../json-patch/types.js';
6
+
3
7
  /**
4
8
  * Represents the possible states of a network transport connection.
5
9
  * - 'connecting': Connection is being established
@@ -7,7 +11,7 @@ import type { Change, EditableVersionMetadata, ListVersionsOptions, PatchesState
7
11
  * - 'disconnected': Connection is not active
8
12
  * - 'error': Connection encountered an error
9
13
  */
10
- export type ConnectionState = 'connecting' | 'connected' | 'disconnected' | 'error';
14
+ type ConnectionState = 'connecting' | 'connected' | 'disconnected' | 'error';
11
15
  /**
12
16
  * Minimal contract that the JSON-RPC layer (and therefore Patches core) relies on.
13
17
  * A transport only needs the ability to **send** raw strings and **deliver** raw
@@ -16,7 +20,7 @@ export type ConnectionState = 'connecting' | 'connected' | 'disconnected' | 'err
16
20
  * Anything beyond that (connect/disconnect lifecycle, connection state, etc.) is
17
21
  * not needed or handled by Patches and so is not defined here.
18
22
  */
19
- export interface ClientTransport {
23
+ interface ClientTransport {
20
24
  /**
21
25
  * Sends a raw, already-encoded message over the wire.
22
26
  */
@@ -32,7 +36,7 @@ export interface ClientTransport {
32
36
  * Each message must indicate the **from / to** connection. Any additional lifecycle
33
37
  * management (upgrade, close, etc.) stays inside the concrete adapter.
34
38
  */
35
- export interface ServerTransport {
39
+ interface ServerTransport {
36
40
  /** Get a list of all active connection IDs */
37
41
  getConnectionIds(): string[];
38
42
  /** Send a raw JSON-RPC string to a specific connection */
@@ -49,7 +53,7 @@ export interface ServerTransport {
49
53
  /**
50
54
  * Represents a JSON-RPC 2.0 request object.
51
55
  */
52
- export interface Request {
56
+ interface JsonRpcRequest {
53
57
  /** JSON-RPC protocol version, always "2.0" */
54
58
  jsonrpc: '2.0';
55
59
  /** Request identifier, used to match responses to requests */
@@ -62,7 +66,7 @@ export interface Request {
62
66
  /**
63
67
  * Represents a JSON-RPC 2.0 response object.
64
68
  */
65
- export interface Response {
69
+ interface JsonRpcResponse {
66
70
  /** JSON-RPC protocol version, always "2.0" */
67
71
  jsonrpc: '2.0';
68
72
  /** Response identifier, matches the id of the corresponding request */
@@ -83,7 +87,7 @@ export interface Response {
83
87
  * Represents a JSON-RPC 2.0 notification object.
84
88
  * Notifications are one-way messages that don't expect a response.
85
89
  */
86
- export interface Notification {
90
+ interface JsonRpcNotification {
87
91
  /** JSON-RPC protocol version, always "2.0" */
88
92
  jsonrpc: '2.0';
89
93
  /** Name of the notification method */
@@ -92,8 +96,8 @@ export interface Notification {
92
96
  params?: any;
93
97
  }
94
98
  /** Union type for all possible JSON-RPC message types */
95
- export type Message = Request | Response | Notification;
96
- export interface ListOptions {
99
+ type Message = JsonRpcRequest | JsonRpcResponse | JsonRpcNotification;
100
+ interface ListOptions {
97
101
  startAt?: string;
98
102
  startAfter?: string;
99
103
  endAt?: string;
@@ -102,7 +106,7 @@ export interface ListOptions {
102
106
  limit?: number;
103
107
  reverse?: boolean;
104
108
  }
105
- export interface PatchesAPI {
109
+ interface PatchesAPI {
106
110
  /**
107
111
  * Subscribes the connected client to one or more documents.
108
112
  * @param ids Document ID(s) to subscribe to.
@@ -119,7 +123,7 @@ export interface PatchesAPI {
119
123
  /** Get changes that occurred after a specific revision. */
120
124
  getChangesSince(docId: string, rev: number): Promise<Change[]>;
121
125
  /** Apply a set of changes from the client to a document. Returns the committed changes. */
122
- commitChanges(docId: string, changes: Change[]): Promise<Change[]>;
126
+ commitChanges(docId: string, changes: ChangeInput[]): Promise<Change[]>;
123
127
  /** Delete a document. */
124
128
  deleteDoc(docId: string): Promise<void>;
125
129
  /** Create a new named version snapshot of a document's current state. */
@@ -133,18 +137,20 @@ export interface PatchesAPI {
133
137
  /** Update the name and other metadata of a specific version. */
134
138
  updateVersion(docId: string, versionId: string, metadata: EditableVersionMetadata): Promise<void>;
135
139
  }
136
- export interface PatchesNotificationParams {
140
+ interface PatchesNotificationParams {
137
141
  docId: string;
138
142
  changes: Change[];
139
143
  }
140
- export interface AwarenessUpdateNotificationParams {
144
+ interface AwarenessUpdateNotificationParams {
141
145
  docId: string;
142
146
  /** The awareness state from a specific client (server should add sender info) */
143
147
  state: any;
144
148
  /** Server should add the client ID of the sender */
145
149
  clientId?: string;
146
150
  }
147
- export interface SignalNotificationParams {
151
+ interface SignalNotificationParams {
148
152
  fromClientId: string;
149
153
  data: any;
150
154
  }
155
+
156
+ export type { AwarenessUpdateNotificationParams, ClientTransport, ConnectionState, JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, ListOptions, Message, PatchesAPI, PatchesNotificationParams, ServerTransport, SignalNotificationParams };
@@ -1 +0,0 @@
1
- export {};
@@ -0,0 +1,12 @@
1
+ import { JsonRpcResponse, JsonRpcNotification } from './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
+
8
+ declare function rpcResponse<T = any>(result: T, id?: number): JsonRpcResponse;
9
+ declare function rpcError(code: number, message: string, data?: any, id?: number): JsonRpcResponse;
10
+ declare function rpcNotification(method: string, params?: any): JsonRpcNotification;
11
+
12
+ export { rpcError, rpcNotification, rpcResponse };
@@ -0,0 +1,15 @@
1
+ import "../../chunk-IZ2YBCUP.js";
2
+ function rpcResponse(result, id) {
3
+ return { jsonrpc: "2.0", id: id ?? null, result };
4
+ }
5
+ function rpcError(code, message, data, id) {
6
+ return { jsonrpc: "2.0", id: id ?? null, error: { code, message, data } };
7
+ }
8
+ function rpcNotification(method, params) {
9
+ return { jsonrpc: "2.0", method, params };
10
+ }
11
+ export {
12
+ rpcError,
13
+ rpcNotification,
14
+ rpcResponse
15
+ };
@@ -1,6 +1,8 @@
1
- export type SyncingState = 'initial' | 'updating' | null | Error;
2
- export interface PatchesState {
1
+ type SyncingState = 'initial' | 'updating' | null | Error;
2
+ interface PatchesState {
3
3
  online: boolean;
4
4
  connected: boolean;
5
5
  syncing: SyncingState;
6
6
  }
7
+
8
+ export type { PatchesState, SyncingState };
package/dist/net/types.js CHANGED
@@ -1 +0,0 @@
1
- export {};
@@ -1,4 +1,13 @@
1
- import type { WebRTCTransport } from './WebRTCTransport.js';
1
+ import { Signal } from '../../event-signal.js';
2
+ import { WebRTCTransport } from './WebRTCTransport.js';
3
+ import '../protocol/types.js';
4
+ import '../../types.js';
5
+ import '../../json-patch/JSONPatch.js';
6
+ import '@dabble/delta';
7
+ import '../../json-patch/types.js';
8
+ import 'simple-peer';
9
+ import '../websocket/WebSocketTransport.js';
10
+
2
11
  /**
3
12
  * Base type for awareness states, representing arbitrary structured data
4
13
  * that will be shared between peers.
@@ -11,7 +20,7 @@ type AwarenessState = Record<string, any>;
11
20
  *
12
21
  * @template T - The type of awareness state to be shared between peers
13
22
  */
14
- export declare class WebRTCAwareness<T extends AwarenessState = AwarenessState> {
23
+ declare class WebRTCAwareness<T extends AwarenessState = AwarenessState> {
15
24
  private transport;
16
25
  private _states;
17
26
  private _localState;
@@ -19,7 +28,7 @@ export declare class WebRTCAwareness<T extends AwarenessState = AwarenessState>
19
28
  * Signal that emits when the awareness state is updated.
20
29
  * Subscribers receive the complete new awareness state array.
21
30
  */
22
- readonly onUpdate: import("../../event-signal.js").Signal<(states: T[]) => void>;
31
+ readonly onUpdate: Signal<(states: T[]) => void>;
23
32
  /**
24
33
  * The peer ID of this client, obtained from the WebRTC transport.
25
34
  */
@@ -78,4 +87,5 @@ export declare class WebRTCAwareness<T extends AwarenessState = AwarenessState>
78
87
  */
79
88
  private _receiveData;
80
89
  }
81
- export {};
90
+
91
+ export { WebRTCAwareness };