@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.
- package/dist/algorithms/client/applyCommittedChanges.d.ts +8 -2
- package/dist/algorithms/client/applyCommittedChanges.js +30 -38
- package/dist/algorithms/client/batching.d.ts +8 -2
- package/dist/algorithms/client/batching.js +38 -37
- package/dist/algorithms/client/breakChange.d.ts +8 -2
- package/dist/algorithms/client/breakChange.js +191 -240
- package/dist/algorithms/client/createStateFromSnapshot.d.ts +8 -2
- package/dist/algorithms/client/createStateFromSnapshot.js +7 -8
- package/dist/algorithms/client/getJSONByteSize.d.ts +3 -1
- package/dist/algorithms/client/getJSONByteSize.js +12 -11
- package/dist/algorithms/client/makeChange.d.ts +8 -2
- package/dist/algorithms/client/makeChange.js +28 -36
- package/dist/algorithms/server/commitChanges.d.ts +9 -3
- package/dist/algorithms/server/commitChanges.js +69 -78
- package/dist/algorithms/server/createVersion.d.ts +9 -3
- package/dist/algorithms/server/createVersion.js +21 -27
- package/dist/algorithms/server/getSnapshotAtRevision.d.ts +9 -3
- package/dist/algorithms/server/getSnapshotAtRevision.js +27 -28
- package/dist/algorithms/server/getStateAtRevision.d.ts +9 -3
- package/dist/algorithms/server/getStateAtRevision.js +13 -17
- package/dist/algorithms/server/handleOfflineSessionsAndBatches.d.ts +9 -3
- package/dist/algorithms/server/handleOfflineSessionsAndBatches.js +60 -77
- package/dist/algorithms/server/transformIncomingChanges.d.ts +8 -2
- package/dist/algorithms/server/transformIncomingChanges.js +27 -39
- package/dist/algorithms/shared/applyChanges.d.ts +8 -2
- package/dist/algorithms/shared/applyChanges.js +11 -16
- package/dist/algorithms/shared/rebaseChanges.d.ts +8 -2
- package/dist/algorithms/shared/rebaseChanges.js +30 -49
- package/dist/chunk-IZ2YBCUP.js +56 -0
- package/dist/client/InMemoryStore.d.ts +9 -3
- package/dist/client/InMemoryStore.js +92 -101
- package/dist/client/IndexedDBStore.d.ts +9 -3
- package/dist/client/IndexedDBStore.js +378 -491
- package/dist/client/Patches.d.ts +18 -13
- package/dist/client/Patches.js +152 -207
- package/dist/client/PatchesDoc.d.ts +14 -8
- package/dist/client/PatchesDoc.js +147 -154
- package/dist/client/PatchesHistoryClient.d.ts +12 -5
- package/dist/client/PatchesHistoryClient.js +110 -117
- package/dist/client/PatchesStore.d.ts +9 -3
- package/dist/client/PatchesStore.js +0 -1
- package/dist/client/index.d.ts +12 -6
- package/dist/client/index.js +5 -5
- package/dist/data/change.d.ts +9 -3
- package/dist/data/change.js +23 -15
- package/dist/data/version.d.ts +9 -3
- package/dist/data/version.js +11 -15
- package/dist/event-signal.d.ts +7 -6
- package/dist/event-signal.js +24 -39
- package/dist/index-CvQws3AB.d.ts +36 -0
- package/dist/index.d.ts +27 -5
- package/dist/index.js +10 -4
- package/dist/json-patch/JSONPatch.d.ts +9 -5
- package/dist/json-patch/JSONPatch.js +175 -183
- package/dist/json-patch/applyPatch.d.ts +5 -2
- package/dist/json-patch/applyPatch.js +27 -35
- package/dist/json-patch/composePatch.d.ts +5 -2
- package/dist/json-patch/composePatch.js +34 -34
- package/dist/json-patch/createJSONPatch.d.ts +7 -2
- package/dist/json-patch/createJSONPatch.js +11 -38
- package/dist/json-patch/index.d.ts +14 -6
- package/dist/json-patch/index.js +20 -9
- package/dist/json-patch/invertPatch.d.ts +5 -2
- package/dist/json-patch/invertPatch.js +31 -30
- package/dist/json-patch/ops/add.d.ts +5 -2
- package/dist/json-patch/ops/add.js +53 -51
- package/dist/json-patch/ops/bitmask.d.ts +8 -5
- package/dist/json-patch/ops/bitmask.js +41 -44
- package/dist/json-patch/ops/copy.d.ts +5 -2
- package/dist/json-patch/ops/copy.js +32 -33
- package/dist/json-patch/ops/increment.d.ts +5 -2
- package/dist/json-patch/ops/increment.js +21 -20
- package/dist/json-patch/ops/index.d.ts +10 -21
- package/dist/json-patch/ops/index.js +34 -24
- package/dist/json-patch/ops/move.d.ts +5 -2
- package/dist/json-patch/ops/move.js +132 -198
- package/dist/json-patch/ops/remove.d.ts +5 -2
- package/dist/json-patch/ops/remove.js +33 -30
- package/dist/json-patch/ops/replace.d.ts +5 -2
- package/dist/json-patch/ops/replace.js +45 -43
- package/dist/json-patch/ops/test.d.ts +5 -2
- package/dist/json-patch/ops/test.js +25 -21
- package/dist/json-patch/ops/text.d.ts +5 -2
- package/dist/json-patch/ops/text.js +54 -54
- package/dist/json-patch/pathProxy.d.ts +9 -3
- package/dist/json-patch/pathProxy.js +27 -48
- package/dist/json-patch/state.d.ts +5 -2
- package/dist/json-patch/state.js +11 -7
- package/dist/json-patch/transformPatch.d.ts +6 -2
- package/dist/json-patch/transformPatch.js +21 -24
- package/dist/json-patch/types.d.ts +9 -7
- package/dist/json-patch/types.js +0 -1
- package/dist/json-patch/utils/deepEqual.d.ts +3 -1
- package/dist/json-patch/utils/deepEqual.js +32 -28
- package/dist/json-patch/utils/exit.d.ts +5 -2
- package/dist/json-patch/utils/exit.js +7 -3
- package/dist/json-patch/utils/get.d.ts +5 -2
- package/dist/json-patch/utils/get.js +8 -4
- package/dist/json-patch/utils/getOpData.d.ts +5 -2
- package/dist/json-patch/utils/getOpData.js +12 -9
- package/dist/json-patch/utils/getType.d.ts +6 -3
- package/dist/json-patch/utils/getType.js +9 -4
- package/dist/json-patch/utils/index.d.ts +15 -14
- package/dist/json-patch/utils/index.js +14 -14
- package/dist/json-patch/utils/log.d.ts +4 -2
- package/dist/json-patch/utils/log.js +8 -3
- package/dist/json-patch/utils/ops.d.ts +8 -5
- package/dist/json-patch/utils/ops.js +83 -100
- package/dist/json-patch/utils/paths.d.ts +12 -9
- package/dist/json-patch/utils/paths.js +54 -51
- package/dist/json-patch/utils/pluck.d.ts +8 -5
- package/dist/json-patch/utils/pluck.js +32 -26
- package/dist/json-patch/utils/shallowCopy.d.ts +3 -1
- package/dist/json-patch/utils/shallowCopy.js +22 -18
- package/dist/json-patch/utils/softWrites.d.ts +6 -3
- package/dist/json-patch/utils/softWrites.js +17 -16
- package/dist/json-patch/utils/toArrayIndex.d.ts +3 -1
- package/dist/json-patch/utils/toArrayIndex.js +14 -10
- package/dist/json-patch/utils/toKeys.d.ts +3 -1
- package/dist/json-patch/utils/toKeys.js +15 -11
- package/dist/json-patch/utils/updateArrayIndexes.d.ts +5 -2
- package/dist/json-patch/utils/updateArrayIndexes.js +33 -37
- package/dist/json-patch/utils/updateArrayPath.d.ts +5 -2
- package/dist/json-patch/utils/updateArrayPath.js +29 -42
- package/dist/net/PatchesClient.d.ts +128 -0
- package/dist/net/PatchesClient.js +161 -0
- package/dist/net/PatchesSync.d.ts +19 -9
- package/dist/net/PatchesSync.js +291 -386
- package/dist/net/error.d.ts +3 -1
- package/dist/net/error.js +9 -6
- package/dist/net/http/FetchTransport.d.ts +21 -0
- package/dist/net/http/FetchTransport.js +34 -0
- package/dist/net/index.d.ts +26 -12
- package/dist/net/index.js +12 -10
- package/dist/net/protocol/JSONRPCClient.d.ts +11 -4
- package/dist/net/protocol/JSONRPCClient.js +95 -103
- package/dist/net/protocol/JSONRPCServer.d.ts +15 -8
- package/dist/net/protocol/JSONRPCServer.js +101 -123
- package/dist/net/protocol/types.d.ts +21 -15
- package/dist/net/protocol/types.js +0 -1
- package/dist/net/protocol/utils.d.ts +12 -0
- package/dist/net/protocol/utils.js +15 -0
- package/dist/net/types.d.ts +4 -2
- package/dist/net/types.js +0 -1
- package/dist/net/webrtc/WebRTCAwareness.d.ts +14 -4
- package/dist/net/webrtc/WebRTCAwareness.js +111 -120
- package/dist/net/webrtc/WebRTCTransport.d.ts +16 -8
- package/dist/net/webrtc/WebRTCTransport.js +149 -157
- package/dist/net/webrtc/index.d.ts +10 -2
- package/dist/net/webrtc/index.js +2 -2
- package/dist/net/websocket/AuthorizationProvider.d.ts +7 -5
- package/dist/net/websocket/AuthorizationProvider.js +12 -17
- package/dist/net/websocket/PatchesWebSocket.d.ts +14 -109
- package/dist/net/websocket/PatchesWebSocket.js +37 -184
- package/dist/net/websocket/RPCServer.d.ts +19 -10
- package/dist/net/websocket/RPCServer.js +190 -192
- package/dist/net/websocket/SignalingService.d.ts +12 -32
- package/dist/net/websocket/SignalingService.js +126 -133
- package/dist/net/websocket/WebSocketServer.d.ts +17 -4
- package/dist/net/websocket/WebSocketServer.js +64 -72
- package/dist/net/websocket/WebSocketTransport.d.ts +13 -5
- package/dist/net/websocket/WebSocketTransport.js +178 -207
- package/dist/net/websocket/onlineState.d.ts +6 -3
- package/dist/net/websocket/onlineState.js +25 -21
- package/dist/server/PatchesBranchManager.d.ts +12 -5
- package/dist/server/PatchesBranchManager.js +132 -142
- package/dist/server/PatchesHistoryManager.d.ts +11 -3
- package/dist/server/PatchesHistoryManager.js +81 -84
- package/dist/server/PatchesServer.d.ts +16 -10
- package/dist/server/PatchesServer.js +131 -137
- package/dist/server/index.d.ts +7 -2
- package/dist/server/index.js +9 -3
- package/dist/server/types.d.ts +9 -3
- package/dist/server/types.js +0 -1
- package/dist/types.d.ts +49 -19
- package/dist/types.js +1 -1
- package/dist/utils/concurrency.d.ts +7 -5
- package/dist/utils/concurrency.js +43 -53
- package/dist/utils/deferred.d.ts +4 -2
- package/dist/utils/deferred.js +25 -21
- package/package.json +5 -7
|
@@ -1,129 +1,107 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
105
|
+
export {
|
|
106
|
+
JSONRPCServer
|
|
107
|
+
};
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
96
|
-
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
140
|
+
interface PatchesNotificationParams {
|
|
137
141
|
docId: string;
|
|
138
142
|
changes: Change[];
|
|
139
143
|
}
|
|
140
|
-
|
|
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
|
-
|
|
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
|
+
};
|
package/dist/net/types.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
90
|
+
|
|
91
|
+
export { WebRTCAwareness };
|