@syncular/client 0.1.2 → 0.2.0
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/README.md +227 -709
- package/dist/apply.d.ts +80 -0
- package/dist/apply.js +301 -0
- package/dist/blob.d.ts +127 -0
- package/dist/blob.js +201 -0
- package/dist/bun-database.d.ts +22 -0
- package/dist/bun-database.js +61 -0
- package/dist/client.d.ts +320 -69
- package/dist/client.js +1627 -163
- package/dist/content-type.d.ts +2 -0
- package/dist/content-type.js +2 -0
- package/dist/database.d.ts +35 -80
- package/dist/database.js +32 -947
- package/dist/encryption.d.ts +47 -0
- package/dist/encryption.js +75 -0
- package/dist/errors.d.ts +8 -22
- package/dist/errors.js +10 -207
- package/dist/http.d.ts +32 -0
- package/dist/http.js +196 -0
- package/dist/index.d.ts +28 -16
- package/dist/index.js +25 -12
- package/dist/invalidation.d.ts +69 -0
- package/dist/invalidation.js +84 -0
- package/dist/leader-lock.d.ts +28 -0
- package/dist/leader-lock.js +38 -0
- package/dist/multi-tab.d.ts +134 -0
- package/dist/multi-tab.js +399 -0
- package/dist/node-database.d.ts +41 -0
- package/dist/node-database.js +133 -0
- package/dist/outbox.d.ts +56 -0
- package/dist/outbox.js +140 -0
- package/dist/schema.d.ts +107 -0
- package/dist/schema.js +267 -0
- package/dist/state.d.ts +40 -0
- package/dist/state.js +77 -0
- package/dist/transport.d.ts +44 -0
- package/dist/transport.js +7 -0
- package/dist/wasm-database.d.ts +30 -0
- package/dist/wasm-database.js +170 -0
- package/dist/window.d.ts +64 -0
- package/dist/window.js +0 -0
- package/dist/worker-entry.d.ts +16 -2
- package/dist/worker-entry.js +300 -456
- package/dist/worker-host.d.ts +174 -0
- package/dist/worker-host.js +536 -0
- package/dist/worker-protocol.d.ts +173 -61
- package/dist/worker-protocol.js +7 -16
- package/package.json +45 -112
- package/src/apply.ts +435 -0
- package/src/blob.ts +333 -0
- package/src/bun-database.ts +75 -0
- package/src/client.ts +2247 -277
- package/src/content-type.ts +2 -0
- package/src/database.ts +63 -1389
- package/src/encryption.ts +123 -0
- package/src/errors.ts +11 -265
- package/src/http.ts +254 -0
- package/src/index.ts +25 -20
- package/src/invalidation.ts +128 -0
- package/src/leader-lock.ts +68 -0
- package/src/multi-tab.ts +550 -0
- package/src/node-database.ts +180 -0
- package/src/outbox.ts +206 -0
- package/src/schema.ts +397 -0
- package/src/state.ts +126 -0
- package/src/transport.ts +52 -0
- package/src/wasm-database.ts +279 -0
- package/src/window.ts +0 -0
- package/src/worker-entry.ts +391 -545
- package/src/worker-host.ts +800 -0
- package/src/worker-protocol.ts +204 -99
- package/dist/auth-leases.d.ts +0 -11
- package/dist/auth-leases.d.ts.map +0 -1
- package/dist/auth-leases.js +0 -140
- package/dist/auth-leases.js.map +0 -1
- package/dist/blob-limits.d.ts +0 -15
- package/dist/blob-limits.d.ts.map +0 -1
- package/dist/blob-limits.js +0 -66
- package/dist/blob-limits.js.map +0 -1
- package/dist/bridge-client.d.ts +0 -69
- package/dist/bridge-client.d.ts.map +0 -1
- package/dist/bridge-client.js +0 -282
- package/dist/bridge-client.js.map +0 -1
- package/dist/client-config.d.ts +0 -6
- package/dist/client-config.d.ts.map +0 -1
- package/dist/client-config.js +0 -18
- package/dist/client-config.js.map +0 -1
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js.map +0 -1
- package/dist/command-history.d.ts +0 -35
- package/dist/command-history.d.ts.map +0 -1
- package/dist/command-history.js +0 -378
- package/dist/command-history.js.map +0 -1
- package/dist/console-diagnostics.d.ts +0 -33
- package/dist/console-diagnostics.d.ts.map +0 -1
- package/dist/console-diagnostics.js +0 -496
- package/dist/console-diagnostics.js.map +0 -1
- package/dist/crdt-yjs/index.d.ts +0 -4
- package/dist/crdt-yjs/index.d.ts.map +0 -1
- package/dist/crdt-yjs/index.js +0 -4
- package/dist/crdt-yjs/index.js.map +0 -1
- package/dist/crdt-yjs/webview-host-facade.d.ts +0 -126
- package/dist/crdt-yjs/webview-host-facade.d.ts.map +0 -1
- package/dist/crdt-yjs/webview-host-facade.js +0 -284
- package/dist/crdt-yjs/webview-host-facade.js.map +0 -1
- package/dist/crdt-yjs/yjs-document-field-adapter.d.ts +0 -153
- package/dist/crdt-yjs/yjs-document-field-adapter.d.ts.map +0 -1
- package/dist/crdt-yjs/yjs-document-field-adapter.js +0 -406
- package/dist/crdt-yjs/yjs-document-field-adapter.js.map +0 -1
- package/dist/crdt-yjs/yjs-prosemirror-bridge.d.ts +0 -73
- package/dist/crdt-yjs/yjs-prosemirror-bridge.d.ts.map +0 -1
- package/dist/crdt-yjs/yjs-prosemirror-bridge.js +0 -169
- package/dist/crdt-yjs/yjs-prosemirror-bridge.js.map +0 -1
- package/dist/database.d.ts.map +0 -1
- package/dist/database.js.map +0 -1
- package/dist/diagnostics.d.ts +0 -10
- package/dist/diagnostics.d.ts.map +0 -1
- package/dist/diagnostics.js +0 -83
- package/dist/diagnostics.js.map +0 -1
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js.map +0 -1
- package/dist/generated-bridge.d.ts +0 -365
- package/dist/generated-bridge.d.ts.map +0 -1
- package/dist/generated-bridge.js +0 -250
- package/dist/generated-bridge.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/mutations.d.ts +0 -72
- package/dist/mutations.d.ts.map +0 -1
- package/dist/mutations.js +0 -63
- package/dist/mutations.js.map +0 -1
- package/dist/network.d.ts +0 -3
- package/dist/network.d.ts.map +0 -1
- package/dist/network.js +0 -17
- package/dist/network.js.map +0 -1
- package/dist/react/index.d.ts +0 -169
- package/dist/react/index.d.ts.map +0 -1
- package/dist/react/index.js +0 -628
- package/dist/react/index.js.map +0 -1
- package/dist/react-native/index.d.ts +0 -35
- package/dist/react-native/index.d.ts.map +0 -1
- package/dist/react-native/index.js +0 -49
- package/dist/react-native/index.js.map +0 -1
- package/dist/runtime-contract.d.ts +0 -13
- package/dist/runtime-contract.d.ts.map +0 -1
- package/dist/runtime-contract.js +0 -24
- package/dist/runtime-contract.js.map +0 -1
- package/dist/rust-client.d.ts +0 -106
- package/dist/rust-client.d.ts.map +0 -1
- package/dist/rust-client.js +0 -938
- package/dist/rust-client.js.map +0 -1
- package/dist/sentry.d.ts +0 -35
- package/dist/sentry.d.ts.map +0 -1
- package/dist/sentry.js +0 -155
- package/dist/sentry.js.map +0 -1
- package/dist/sql-safety.d.ts +0 -3
- package/dist/sql-safety.d.ts.map +0 -1
- package/dist/sql-safety.js +0 -62
- package/dist/sql-safety.js.map +0 -1
- package/dist/syncular-runtime-artifacts.json +0 -61
- package/dist/tauri/index.d.ts +0 -35
- package/dist/tauri/index.d.ts.map +0 -1
- package/dist/tauri/index.js +0 -114
- package/dist/tauri/index.js.map +0 -1
- package/dist/types.d.ts +0 -1096
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/dist/wasm/.syncular-wasm-profile +0 -1
- package/dist/wasm/syncular-runtime-artifact.json +0 -21
- package/dist/wasm/syncular.d.ts +0 -207
- package/dist/wasm/syncular.js +0 -2341
- package/dist/wasm/syncular_bg.wasm +0 -0
- package/dist/wasm/syncular_bg.wasm.d.ts +0 -97
- package/dist/wasm-bindings/runtime-contract.d.ts +0 -22
- package/dist/wasm-bindings/runtime-contract.d.ts.map +0 -1
- package/dist/wasm-bindings/runtime-contract.js +0 -112
- package/dist/wasm-bindings/runtime-contract.js.map +0 -1
- package/dist/wasm-core/.syncular-wasm-profile +0 -1
- package/dist/wasm-core/syncular-runtime-artifact.json +0 -17
- package/dist/wasm-core/syncular.d.ts +0 -162
- package/dist/wasm-core/syncular.js +0 -1847
- package/dist/wasm-core/syncular_bg.wasm +0 -0
- package/dist/wasm-core/syncular_bg.wasm.d.ts +0 -77
- package/dist/wasm-perf/.syncular-wasm-profile +0 -1
- package/dist/wasm-perf/syncular-runtime-artifact.json +0 -21
- package/dist/wasm-perf/syncular.d.ts +0 -207
- package/dist/wasm-perf/syncular.js +0 -2341
- package/dist/wasm-perf/syncular_bg.wasm +0 -0
- package/dist/wasm-perf/syncular_bg.wasm.d.ts +0 -97
- package/dist/wasm-runtime.d.ts +0 -23
- package/dist/wasm-runtime.d.ts.map +0 -1
- package/dist/wasm-runtime.js +0 -69
- package/dist/wasm-runtime.js.map +0 -1
- package/dist/worker-client.d.ts +0 -123
- package/dist/worker-client.d.ts.map +0 -1
- package/dist/worker-client.js +0 -1735
- package/dist/worker-client.js.map +0 -1
- package/dist/worker-entry.d.ts.map +0 -1
- package/dist/worker-entry.js.map +0 -1
- package/dist/worker-protocol.d.ts.map +0 -1
- package/dist/worker-protocol.js.map +0 -1
- package/dist/worker-realtime.d.ts +0 -39
- package/dist/worker-realtime.d.ts.map +0 -1
- package/dist/worker-realtime.js +0 -677
- package/dist/worker-realtime.js.map +0 -1
- package/src/auth-leases.ts +0 -251
- package/src/blob-limits.ts +0 -98
- package/src/bridge-client.ts +0 -512
- package/src/client-config.ts +0 -29
- package/src/command-history.ts +0 -623
- package/src/console-diagnostics.ts +0 -617
- package/src/crdt-yjs/index.ts +0 -3
- package/src/crdt-yjs/webview-host-facade.ts +0 -477
- package/src/crdt-yjs/yjs-document-field-adapter.ts +0 -733
- package/src/crdt-yjs/yjs-prosemirror-bridge.ts +0 -272
- package/src/diagnostics.ts +0 -116
- package/src/generated-bridge.ts +0 -741
- package/src/mutations.ts +0 -168
- package/src/network.ts +0 -32
- package/src/react/index.ts +0 -1036
- package/src/react-native/index.ts +0 -152
- package/src/runtime-contract.ts +0 -48
- package/src/rust-client.ts +0 -1491
- package/src/sentry.ts +0 -215
- package/src/sql-safety.ts +0 -61
- package/src/tauri/index.ts +0 -211
- package/src/types.ts +0 -1397
- package/src/wasm-bindings/generated-wasm-bindings.d.ts +0 -70
- package/src/wasm-bindings/runtime-contract.ts +0 -158
- package/src/wasm-runtime.ts +0 -145
- package/src/worker-client.ts +0 -2289
- package/src/worker-realtime.ts +0 -843
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
import * as Y from 'yjs';
|
|
2
|
-
import type {
|
|
3
|
-
SyncularCrdtProjectionDefinition,
|
|
4
|
-
SyncularCrdtProjectionEvent,
|
|
5
|
-
YjsDocumentBinding,
|
|
6
|
-
YjsDocumentRestoreReceipt,
|
|
7
|
-
} from './yjs-document-field-adapter';
|
|
8
|
-
|
|
9
|
-
export interface YjsProseMirrorBridgeOptions {
|
|
10
|
-
containerKey: string;
|
|
11
|
-
doc?: Y.Doc;
|
|
12
|
-
localOrigin?: unknown;
|
|
13
|
-
remoteOrigin?: unknown;
|
|
14
|
-
ignoredOrigins?: readonly unknown[];
|
|
15
|
-
onDocumentReplaced?: (event: YjsProseMirrorDocumentReplacedEvent) => void;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface YjsProseMirrorDocumentReplacedEvent {
|
|
19
|
-
doc: Y.Doc;
|
|
20
|
-
fragment: Y.XmlFragment;
|
|
21
|
-
receipt?: YjsDocumentRestoreReceipt;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface YjsProseMirrorBridge extends YjsDocumentBinding {
|
|
25
|
-
doc(): Y.Doc;
|
|
26
|
-
fragment(): Y.XmlFragment;
|
|
27
|
-
replaceDocumentFromState(
|
|
28
|
-
state: Uint8Array,
|
|
29
|
-
receipt?: YjsDocumentRestoreReceipt
|
|
30
|
-
): void;
|
|
31
|
-
encodeStateAsUpdate(): Uint8Array;
|
|
32
|
-
destroy(): void;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface ProseMirrorReadModel {
|
|
36
|
-
table: string;
|
|
37
|
-
rowId: string;
|
|
38
|
-
field: string;
|
|
39
|
-
prosemirrorJson: unknown;
|
|
40
|
-
title: string;
|
|
41
|
-
preview: string;
|
|
42
|
-
outline: string[];
|
|
43
|
-
searchText: string;
|
|
44
|
-
stateVectorBase64: string;
|
|
45
|
-
source: SyncularCrdtProjectionEvent['source'];
|
|
46
|
-
reason: SyncularCrdtProjectionEvent['reason'];
|
|
47
|
-
operation?: string;
|
|
48
|
-
commitId?: string | null;
|
|
49
|
-
commitSeq?: number | null;
|
|
50
|
-
serverVersion?: number | null;
|
|
51
|
-
documentKey?: string;
|
|
52
|
-
pendingUpdates?: number;
|
|
53
|
-
flushedUpdates?: number;
|
|
54
|
-
ackedUpdates?: number;
|
|
55
|
-
logUpdates?: number;
|
|
56
|
-
updatedAt?: number;
|
|
57
|
-
compactedAt?: number | null;
|
|
58
|
-
latestUpdateId?: string;
|
|
59
|
-
latestUpdateStatus?: string;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export interface ProseMirrorReadModelStore {
|
|
63
|
-
upsert(
|
|
64
|
-
model: ProseMirrorReadModel,
|
|
65
|
-
event: SyncularCrdtProjectionEvent
|
|
66
|
-
): void | Promise<void>;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export interface ProseMirrorReadModelProjectionOptions {
|
|
70
|
-
store: ProseMirrorReadModelStore;
|
|
71
|
-
derive?: (
|
|
72
|
-
value: unknown,
|
|
73
|
-
event: SyncularCrdtProjectionEvent
|
|
74
|
-
) => {
|
|
75
|
-
prosemirrorJson: unknown;
|
|
76
|
-
title: string;
|
|
77
|
-
preview: string;
|
|
78
|
-
outline: string[];
|
|
79
|
-
searchText: string;
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const DEFAULT_REMOTE_ORIGIN = Symbol.for('syncular.crdt.remote');
|
|
84
|
-
|
|
85
|
-
export function createYjsProseMirrorBridge(
|
|
86
|
-
options: YjsProseMirrorBridgeOptions
|
|
87
|
-
): YjsProseMirrorBridge {
|
|
88
|
-
let doc = options.doc ?? new Y.Doc();
|
|
89
|
-
let fragment = doc.getXmlFragment(options.containerKey);
|
|
90
|
-
const remoteOrigin = options.remoteOrigin ?? DEFAULT_REMOTE_ORIGIN;
|
|
91
|
-
const ignoredOrigins = new Set<unknown>([
|
|
92
|
-
remoteOrigin,
|
|
93
|
-
...(options.ignoredOrigins ?? []),
|
|
94
|
-
]);
|
|
95
|
-
const localListeners = new Set<(update: Uint8Array) => void>();
|
|
96
|
-
const docUnsubscribers = new Map<(update: Uint8Array) => void, () => void>();
|
|
97
|
-
|
|
98
|
-
const attachListener = (listener: (update: Uint8Array) => void) => {
|
|
99
|
-
const handler = (update: Uint8Array, origin: unknown) => {
|
|
100
|
-
if (ignoredOrigins.has(origin)) return;
|
|
101
|
-
listener(update);
|
|
102
|
-
};
|
|
103
|
-
doc.on('update', handler);
|
|
104
|
-
docUnsubscribers.set(listener, () => {
|
|
105
|
-
doc.off('update', handler);
|
|
106
|
-
});
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
const attachAllListeners = () => {
|
|
110
|
-
for (const listener of localListeners) attachListener(listener);
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
const detachAllListeners = () => {
|
|
114
|
-
for (const unsubscribe of docUnsubscribers.values()) unsubscribe();
|
|
115
|
-
docUnsubscribers.clear();
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
const replaceDoc = (nextDoc: Y.Doc, receipt?: YjsDocumentRestoreReceipt) => {
|
|
119
|
-
detachAllListeners();
|
|
120
|
-
doc.destroy();
|
|
121
|
-
doc = nextDoc;
|
|
122
|
-
fragment = doc.getXmlFragment(options.containerKey);
|
|
123
|
-
attachAllListeners();
|
|
124
|
-
options.onDocumentReplaced?.({ doc, fragment, receipt });
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
return {
|
|
128
|
-
subscribeLocalUpdates(listener) {
|
|
129
|
-
localListeners.add(listener);
|
|
130
|
-
attachListener(listener);
|
|
131
|
-
return () => {
|
|
132
|
-
localListeners.delete(listener);
|
|
133
|
-
docUnsubscribers.get(listener)?.();
|
|
134
|
-
docUnsubscribers.delete(listener);
|
|
135
|
-
};
|
|
136
|
-
},
|
|
137
|
-
|
|
138
|
-
applyRemoteUpdate(update) {
|
|
139
|
-
Y.applyUpdate(doc, update, remoteOrigin);
|
|
140
|
-
},
|
|
141
|
-
|
|
142
|
-
replaceDocumentState(state, receipt) {
|
|
143
|
-
this.replaceDocumentFromState(state, receipt);
|
|
144
|
-
},
|
|
145
|
-
|
|
146
|
-
replaceMaterializedValue() {},
|
|
147
|
-
|
|
148
|
-
doc() {
|
|
149
|
-
return doc;
|
|
150
|
-
},
|
|
151
|
-
|
|
152
|
-
fragment() {
|
|
153
|
-
return fragment;
|
|
154
|
-
},
|
|
155
|
-
|
|
156
|
-
replaceDocumentFromState(state, receipt) {
|
|
157
|
-
const nextDoc = new Y.Doc();
|
|
158
|
-
if (state.length > 0) {
|
|
159
|
-
Y.applyUpdate(nextDoc, state, remoteOrigin);
|
|
160
|
-
}
|
|
161
|
-
replaceDoc(nextDoc, receipt);
|
|
162
|
-
},
|
|
163
|
-
|
|
164
|
-
encodeStateAsUpdate() {
|
|
165
|
-
return Y.encodeStateAsUpdate(doc);
|
|
166
|
-
},
|
|
167
|
-
|
|
168
|
-
destroy() {
|
|
169
|
-
detachAllListeners();
|
|
170
|
-
localListeners.clear();
|
|
171
|
-
doc.destroy();
|
|
172
|
-
},
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export function prosemirrorJsonProjection(value: unknown): {
|
|
177
|
-
prosemirrorJson: unknown;
|
|
178
|
-
title: string;
|
|
179
|
-
preview: string;
|
|
180
|
-
outline: string[];
|
|
181
|
-
searchText: string;
|
|
182
|
-
} {
|
|
183
|
-
const text = extractProseMirrorText(value);
|
|
184
|
-
const headings = extractProseMirrorHeadings(value);
|
|
185
|
-
return {
|
|
186
|
-
prosemirrorJson: value,
|
|
187
|
-
title: headings[0] ?? firstLine(text) ?? '',
|
|
188
|
-
preview: text.slice(0, 240),
|
|
189
|
-
outline: headings,
|
|
190
|
-
searchText: text,
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
export function createProseMirrorReadModelProjection(
|
|
195
|
-
options: ProseMirrorReadModelProjectionOptions
|
|
196
|
-
): SyncularCrdtProjectionDefinition<ProseMirrorReadModel> {
|
|
197
|
-
return {
|
|
198
|
-
derive(materialization, event) {
|
|
199
|
-
const derived =
|
|
200
|
-
options.derive?.(materialization.value, event) ??
|
|
201
|
-
prosemirrorJsonProjection(materialization.value);
|
|
202
|
-
return {
|
|
203
|
-
table: event.field.table,
|
|
204
|
-
rowId: event.field.rowId,
|
|
205
|
-
field: event.field.field,
|
|
206
|
-
...derived,
|
|
207
|
-
stateVectorBase64: event.stateVectorBase64,
|
|
208
|
-
source: event.source,
|
|
209
|
-
reason: event.reason,
|
|
210
|
-
operation: event.operation,
|
|
211
|
-
commitId: event.commitId,
|
|
212
|
-
commitSeq: event.commitSeq,
|
|
213
|
-
serverVersion: event.serverVersion,
|
|
214
|
-
documentKey: event.documentSnapshot?.documentKey,
|
|
215
|
-
pendingUpdates: event.documentSnapshot?.pendingUpdates,
|
|
216
|
-
flushedUpdates: event.documentSnapshot?.flushedUpdates,
|
|
217
|
-
ackedUpdates: event.documentSnapshot?.ackedUpdates,
|
|
218
|
-
logUpdates: event.documentSnapshot?.logUpdates,
|
|
219
|
-
updatedAt: event.documentSnapshot?.updatedAt,
|
|
220
|
-
compactedAt: event.documentSnapshot?.compactedAt,
|
|
221
|
-
latestUpdateId: event.latestUpdate?.updateId,
|
|
222
|
-
latestUpdateStatus: event.latestUpdate?.status,
|
|
223
|
-
};
|
|
224
|
-
},
|
|
225
|
-
|
|
226
|
-
apply(model, event) {
|
|
227
|
-
return options.store.upsert(model, event);
|
|
228
|
-
},
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
export function extractProseMirrorText(value: unknown): string {
|
|
233
|
-
const parts: string[] = [];
|
|
234
|
-
const visit = (node: unknown) => {
|
|
235
|
-
if (node == null || typeof node !== 'object') return;
|
|
236
|
-
const record = node as Record<string, unknown>;
|
|
237
|
-
if (typeof record.text === 'string') {
|
|
238
|
-
parts.push(record.text);
|
|
239
|
-
}
|
|
240
|
-
const content = record.content;
|
|
241
|
-
if (Array.isArray(content)) {
|
|
242
|
-
for (const child of content) visit(child);
|
|
243
|
-
}
|
|
244
|
-
};
|
|
245
|
-
visit(value);
|
|
246
|
-
return parts.join(' ').replace(/\s+/g, ' ').trim();
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
export function extractProseMirrorHeadings(value: unknown): string[] {
|
|
250
|
-
const headings: string[] = [];
|
|
251
|
-
const visit = (node: unknown) => {
|
|
252
|
-
if (node == null || typeof node !== 'object') return;
|
|
253
|
-
const record = node as Record<string, unknown>;
|
|
254
|
-
if (record.type === 'heading') {
|
|
255
|
-
const text = extractProseMirrorText(record);
|
|
256
|
-
if (text !== '') headings.push(text);
|
|
257
|
-
}
|
|
258
|
-
const content = record.content;
|
|
259
|
-
if (Array.isArray(content)) {
|
|
260
|
-
for (const child of content) visit(child);
|
|
261
|
-
}
|
|
262
|
-
};
|
|
263
|
-
visit(value);
|
|
264
|
-
return headings;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
function firstLine(value: string): string | undefined {
|
|
268
|
-
return value
|
|
269
|
-
.split(/\r?\n/)
|
|
270
|
-
.map((line) => line.trim())
|
|
271
|
-
.find((line) => line !== '');
|
|
272
|
-
}
|
package/src/diagnostics.ts
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
SyncularBootstrapStatus,
|
|
3
|
-
SyncularDiagnosticEvent,
|
|
4
|
-
SyncularDiagnosticSubscriptionSnapshot,
|
|
5
|
-
SyncularSubscriptionSpec,
|
|
6
|
-
SyncularSyncAttempt,
|
|
7
|
-
SyncularSyncTimings,
|
|
8
|
-
} from './types';
|
|
9
|
-
|
|
10
|
-
export const SYNCULAR_DIAGNOSTIC_RING_LIMIT = 100;
|
|
11
|
-
export const SYNCULAR_SYNC_TIMINGS_RING_LIMIT = 20;
|
|
12
|
-
|
|
13
|
-
export function appendSyncularDiagnosticEvent(
|
|
14
|
-
events: SyncularDiagnosticEvent[],
|
|
15
|
-
event: SyncularDiagnosticEvent
|
|
16
|
-
): void {
|
|
17
|
-
events.push(event);
|
|
18
|
-
trimRing(events, SYNCULAR_DIAGNOSTIC_RING_LIMIT);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function appendSyncularSyncTimings(
|
|
22
|
-
timings: SyncularSyncTimings[],
|
|
23
|
-
timing: SyncularSyncTimings
|
|
24
|
-
): void {
|
|
25
|
-
timings.push(timing);
|
|
26
|
-
trimRing(timings, SYNCULAR_SYNC_TIMINGS_RING_LIMIT);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function summarizeSyncularDiagnosticSubscriptions(
|
|
30
|
-
subscriptions: readonly SyncularSubscriptionSpec[],
|
|
31
|
-
bootstrap: SyncularBootstrapStatus | undefined
|
|
32
|
-
): SyncularDiagnosticSubscriptionSnapshot[] {
|
|
33
|
-
const bootstrapById = new Map(
|
|
34
|
-
(bootstrap?.subscriptions ?? []).map((entry) => [entry.id, entry])
|
|
35
|
-
);
|
|
36
|
-
return subscriptions.map((subscription) => {
|
|
37
|
-
const bootstrapped = bootstrapById.get(subscription.id);
|
|
38
|
-
return {
|
|
39
|
-
id: subscription.id,
|
|
40
|
-
table: subscription.table,
|
|
41
|
-
scopeKeys: Object.keys(subscription.scopes).sort(),
|
|
42
|
-
scopeValueCount: countRedactedValues(subscription.scopes),
|
|
43
|
-
paramsKeys: Object.keys(subscription.params ?? {}).sort(),
|
|
44
|
-
paramsValueCount: countRedactedValues(subscription.params ?? {}),
|
|
45
|
-
status: bootstrapped?.status ?? null,
|
|
46
|
-
ready: bootstrapped?.ready ?? false,
|
|
47
|
-
phase: bootstrapped?.phase ?? 'pending',
|
|
48
|
-
progressPercent: bootstrapped?.progressPercent ?? 0,
|
|
49
|
-
cursor: bootstrapped?.cursor ?? null,
|
|
50
|
-
bootstrapPhase:
|
|
51
|
-
bootstrapped?.bootstrapPhase ?? subscription.bootstrapPhase ?? 0,
|
|
52
|
-
bootstrapState: bootstrapped?.bootstrapState ?? null,
|
|
53
|
-
};
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function createSyncularSyncAttempt(): SyncularSyncAttempt {
|
|
58
|
-
const traceId = randomHex(16);
|
|
59
|
-
const spanId = randomHex(8);
|
|
60
|
-
return {
|
|
61
|
-
syncAttemptId: traceId,
|
|
62
|
-
traceId,
|
|
63
|
-
spanId,
|
|
64
|
-
traceparent: `00-${traceId}-${spanId}-01`,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function syncularSyncAttemptHeaders(
|
|
69
|
-
attempt: SyncularSyncAttempt
|
|
70
|
-
): Record<string, string> {
|
|
71
|
-
return {
|
|
72
|
-
traceparent: attempt.traceparent,
|
|
73
|
-
'sentry-trace': `${attempt.traceId}-${attempt.spanId}-1`,
|
|
74
|
-
'x-syncular-sync-attempt-id': attempt.syncAttemptId,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function syncularDiagnosticAttemptFields(
|
|
79
|
-
attempt: SyncularSyncAttempt | undefined
|
|
80
|
-
): Pick<SyncularDiagnosticEvent, 'syncAttemptId' | 'traceId' | 'spanId'> {
|
|
81
|
-
return attempt
|
|
82
|
-
? {
|
|
83
|
-
syncAttemptId: attempt.syncAttemptId,
|
|
84
|
-
traceId: attempt.traceId,
|
|
85
|
-
spanId: attempt.spanId,
|
|
86
|
-
}
|
|
87
|
-
: {};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function countRedactedValues(values: Record<string, unknown>): number {
|
|
91
|
-
let count = 0;
|
|
92
|
-
for (const value of Object.values(values)) {
|
|
93
|
-
count += Array.isArray(value) ? value.length : 1;
|
|
94
|
-
}
|
|
95
|
-
return count;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function trimRing<T>(items: T[], limit: number): void {
|
|
99
|
-
if (items.length <= limit) return;
|
|
100
|
-
items.splice(0, items.length - limit);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function randomHex(byteLength: number): string {
|
|
104
|
-
const bytes = new Uint8Array(byteLength);
|
|
105
|
-
const cryptoSource = globalThis.crypto;
|
|
106
|
-
if (cryptoSource?.getRandomValues) {
|
|
107
|
-
cryptoSource.getRandomValues(bytes);
|
|
108
|
-
} else {
|
|
109
|
-
for (let index = 0; index < bytes.length; index += 1) {
|
|
110
|
-
bytes[index] = Math.floor(Math.random() * 256);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0')).join(
|
|
114
|
-
''
|
|
115
|
-
);
|
|
116
|
-
}
|