@syncular/client 0.1.3 → 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.
Files changed (233) hide show
  1. package/README.md +227 -709
  2. package/dist/apply.d.ts +80 -0
  3. package/dist/apply.js +301 -0
  4. package/dist/blob.d.ts +127 -0
  5. package/dist/blob.js +201 -0
  6. package/dist/bun-database.d.ts +22 -0
  7. package/dist/bun-database.js +61 -0
  8. package/dist/client.d.ts +320 -69
  9. package/dist/client.js +1627 -163
  10. package/dist/content-type.d.ts +2 -0
  11. package/dist/content-type.js +2 -0
  12. package/dist/database.d.ts +35 -80
  13. package/dist/database.js +32 -947
  14. package/dist/encryption.d.ts +47 -0
  15. package/dist/encryption.js +75 -0
  16. package/dist/errors.d.ts +8 -22
  17. package/dist/errors.js +10 -207
  18. package/dist/http.d.ts +32 -0
  19. package/dist/http.js +196 -0
  20. package/dist/index.d.ts +28 -16
  21. package/dist/index.js +25 -12
  22. package/dist/invalidation.d.ts +69 -0
  23. package/dist/invalidation.js +84 -0
  24. package/dist/leader-lock.d.ts +28 -0
  25. package/dist/leader-lock.js +38 -0
  26. package/dist/multi-tab.d.ts +134 -0
  27. package/dist/multi-tab.js +399 -0
  28. package/dist/node-database.d.ts +41 -0
  29. package/dist/node-database.js +133 -0
  30. package/dist/outbox.d.ts +56 -0
  31. package/dist/outbox.js +140 -0
  32. package/dist/schema.d.ts +107 -0
  33. package/dist/schema.js +267 -0
  34. package/dist/state.d.ts +40 -0
  35. package/dist/state.js +77 -0
  36. package/dist/transport.d.ts +44 -0
  37. package/dist/transport.js +7 -0
  38. package/dist/wasm-database.d.ts +30 -0
  39. package/dist/wasm-database.js +170 -0
  40. package/dist/window.d.ts +64 -0
  41. package/dist/window.js +0 -0
  42. package/dist/worker-entry.d.ts +16 -2
  43. package/dist/worker-entry.js +300 -456
  44. package/dist/worker-host.d.ts +174 -0
  45. package/dist/worker-host.js +536 -0
  46. package/dist/worker-protocol.d.ts +173 -61
  47. package/dist/worker-protocol.js +7 -16
  48. package/package.json +45 -112
  49. package/src/apply.ts +435 -0
  50. package/src/blob.ts +333 -0
  51. package/src/bun-database.ts +75 -0
  52. package/src/client.ts +2247 -277
  53. package/src/content-type.ts +2 -0
  54. package/src/database.ts +63 -1389
  55. package/src/encryption.ts +123 -0
  56. package/src/errors.ts +11 -265
  57. package/src/http.ts +254 -0
  58. package/src/index.ts +25 -20
  59. package/src/invalidation.ts +128 -0
  60. package/src/leader-lock.ts +68 -0
  61. package/src/multi-tab.ts +550 -0
  62. package/src/node-database.ts +180 -0
  63. package/src/outbox.ts +206 -0
  64. package/src/schema.ts +397 -0
  65. package/src/state.ts +126 -0
  66. package/src/transport.ts +52 -0
  67. package/src/wasm-database.ts +279 -0
  68. package/src/window.ts +0 -0
  69. package/src/worker-entry.ts +391 -545
  70. package/src/worker-host.ts +800 -0
  71. package/src/worker-protocol.ts +204 -99
  72. package/dist/auth-leases.d.ts +0 -11
  73. package/dist/auth-leases.d.ts.map +0 -1
  74. package/dist/auth-leases.js +0 -140
  75. package/dist/auth-leases.js.map +0 -1
  76. package/dist/blob-limits.d.ts +0 -15
  77. package/dist/blob-limits.d.ts.map +0 -1
  78. package/dist/blob-limits.js +0 -66
  79. package/dist/blob-limits.js.map +0 -1
  80. package/dist/bridge-client.d.ts +0 -69
  81. package/dist/bridge-client.d.ts.map +0 -1
  82. package/dist/bridge-client.js +0 -282
  83. package/dist/bridge-client.js.map +0 -1
  84. package/dist/client-config.d.ts +0 -6
  85. package/dist/client-config.d.ts.map +0 -1
  86. package/dist/client-config.js +0 -18
  87. package/dist/client-config.js.map +0 -1
  88. package/dist/client.d.ts.map +0 -1
  89. package/dist/client.js.map +0 -1
  90. package/dist/command-history.d.ts +0 -35
  91. package/dist/command-history.d.ts.map +0 -1
  92. package/dist/command-history.js +0 -378
  93. package/dist/command-history.js.map +0 -1
  94. package/dist/console-diagnostics.d.ts +0 -33
  95. package/dist/console-diagnostics.d.ts.map +0 -1
  96. package/dist/console-diagnostics.js +0 -496
  97. package/dist/console-diagnostics.js.map +0 -1
  98. package/dist/crdt-yjs/index.d.ts +0 -4
  99. package/dist/crdt-yjs/index.d.ts.map +0 -1
  100. package/dist/crdt-yjs/index.js +0 -4
  101. package/dist/crdt-yjs/index.js.map +0 -1
  102. package/dist/crdt-yjs/webview-host-facade.d.ts +0 -126
  103. package/dist/crdt-yjs/webview-host-facade.d.ts.map +0 -1
  104. package/dist/crdt-yjs/webview-host-facade.js +0 -284
  105. package/dist/crdt-yjs/webview-host-facade.js.map +0 -1
  106. package/dist/crdt-yjs/yjs-document-field-adapter.d.ts +0 -153
  107. package/dist/crdt-yjs/yjs-document-field-adapter.d.ts.map +0 -1
  108. package/dist/crdt-yjs/yjs-document-field-adapter.js +0 -406
  109. package/dist/crdt-yjs/yjs-document-field-adapter.js.map +0 -1
  110. package/dist/crdt-yjs/yjs-prosemirror-bridge.d.ts +0 -73
  111. package/dist/crdt-yjs/yjs-prosemirror-bridge.d.ts.map +0 -1
  112. package/dist/crdt-yjs/yjs-prosemirror-bridge.js +0 -169
  113. package/dist/crdt-yjs/yjs-prosemirror-bridge.js.map +0 -1
  114. package/dist/database.d.ts.map +0 -1
  115. package/dist/database.js.map +0 -1
  116. package/dist/diagnostics.d.ts +0 -10
  117. package/dist/diagnostics.d.ts.map +0 -1
  118. package/dist/diagnostics.js +0 -83
  119. package/dist/diagnostics.js.map +0 -1
  120. package/dist/errors.d.ts.map +0 -1
  121. package/dist/errors.js.map +0 -1
  122. package/dist/generated-bridge.d.ts +0 -365
  123. package/dist/generated-bridge.d.ts.map +0 -1
  124. package/dist/generated-bridge.js +0 -250
  125. package/dist/generated-bridge.js.map +0 -1
  126. package/dist/index.d.ts.map +0 -1
  127. package/dist/index.js.map +0 -1
  128. package/dist/mutations.d.ts +0 -72
  129. package/dist/mutations.d.ts.map +0 -1
  130. package/dist/mutations.js +0 -63
  131. package/dist/mutations.js.map +0 -1
  132. package/dist/network.d.ts +0 -3
  133. package/dist/network.d.ts.map +0 -1
  134. package/dist/network.js +0 -17
  135. package/dist/network.js.map +0 -1
  136. package/dist/react/index.d.ts +0 -169
  137. package/dist/react/index.d.ts.map +0 -1
  138. package/dist/react/index.js +0 -628
  139. package/dist/react/index.js.map +0 -1
  140. package/dist/react-native/index.d.ts +0 -35
  141. package/dist/react-native/index.d.ts.map +0 -1
  142. package/dist/react-native/index.js +0 -49
  143. package/dist/react-native/index.js.map +0 -1
  144. package/dist/runtime-contract.d.ts +0 -13
  145. package/dist/runtime-contract.d.ts.map +0 -1
  146. package/dist/runtime-contract.js +0 -24
  147. package/dist/runtime-contract.js.map +0 -1
  148. package/dist/rust-client.d.ts +0 -106
  149. package/dist/rust-client.d.ts.map +0 -1
  150. package/dist/rust-client.js +0 -938
  151. package/dist/rust-client.js.map +0 -1
  152. package/dist/sentry.d.ts +0 -35
  153. package/dist/sentry.d.ts.map +0 -1
  154. package/dist/sentry.js +0 -155
  155. package/dist/sentry.js.map +0 -1
  156. package/dist/sql-safety.d.ts +0 -3
  157. package/dist/sql-safety.d.ts.map +0 -1
  158. package/dist/sql-safety.js +0 -62
  159. package/dist/sql-safety.js.map +0 -1
  160. package/dist/syncular-runtime-artifacts.json +0 -61
  161. package/dist/tauri/index.d.ts +0 -35
  162. package/dist/tauri/index.d.ts.map +0 -1
  163. package/dist/tauri/index.js +0 -114
  164. package/dist/tauri/index.js.map +0 -1
  165. package/dist/types.d.ts +0 -1096
  166. package/dist/types.d.ts.map +0 -1
  167. package/dist/types.js +0 -2
  168. package/dist/types.js.map +0 -1
  169. package/dist/wasm/.syncular-wasm-profile +0 -1
  170. package/dist/wasm/syncular-runtime-artifact.json +0 -21
  171. package/dist/wasm/syncular.d.ts +0 -207
  172. package/dist/wasm/syncular.js +0 -2341
  173. package/dist/wasm/syncular_bg.wasm +0 -0
  174. package/dist/wasm/syncular_bg.wasm.d.ts +0 -97
  175. package/dist/wasm-bindings/runtime-contract.d.ts +0 -22
  176. package/dist/wasm-bindings/runtime-contract.d.ts.map +0 -1
  177. package/dist/wasm-bindings/runtime-contract.js +0 -112
  178. package/dist/wasm-bindings/runtime-contract.js.map +0 -1
  179. package/dist/wasm-core/.syncular-wasm-profile +0 -1
  180. package/dist/wasm-core/syncular-runtime-artifact.json +0 -17
  181. package/dist/wasm-core/syncular.d.ts +0 -162
  182. package/dist/wasm-core/syncular.js +0 -1847
  183. package/dist/wasm-core/syncular_bg.wasm +0 -0
  184. package/dist/wasm-core/syncular_bg.wasm.d.ts +0 -77
  185. package/dist/wasm-perf/.syncular-wasm-profile +0 -1
  186. package/dist/wasm-perf/syncular-runtime-artifact.json +0 -21
  187. package/dist/wasm-perf/syncular.d.ts +0 -207
  188. package/dist/wasm-perf/syncular.js +0 -2341
  189. package/dist/wasm-perf/syncular_bg.wasm +0 -0
  190. package/dist/wasm-perf/syncular_bg.wasm.d.ts +0 -97
  191. package/dist/wasm-runtime.d.ts +0 -23
  192. package/dist/wasm-runtime.d.ts.map +0 -1
  193. package/dist/wasm-runtime.js +0 -69
  194. package/dist/wasm-runtime.js.map +0 -1
  195. package/dist/worker-client.d.ts +0 -123
  196. package/dist/worker-client.d.ts.map +0 -1
  197. package/dist/worker-client.js +0 -1735
  198. package/dist/worker-client.js.map +0 -1
  199. package/dist/worker-entry.d.ts.map +0 -1
  200. package/dist/worker-entry.js.map +0 -1
  201. package/dist/worker-protocol.d.ts.map +0 -1
  202. package/dist/worker-protocol.js.map +0 -1
  203. package/dist/worker-realtime.d.ts +0 -39
  204. package/dist/worker-realtime.d.ts.map +0 -1
  205. package/dist/worker-realtime.js +0 -677
  206. package/dist/worker-realtime.js.map +0 -1
  207. package/src/auth-leases.ts +0 -251
  208. package/src/blob-limits.ts +0 -98
  209. package/src/bridge-client.ts +0 -512
  210. package/src/client-config.ts +0 -29
  211. package/src/command-history.ts +0 -623
  212. package/src/console-diagnostics.ts +0 -617
  213. package/src/crdt-yjs/index.ts +0 -3
  214. package/src/crdt-yjs/webview-host-facade.ts +0 -477
  215. package/src/crdt-yjs/yjs-document-field-adapter.ts +0 -733
  216. package/src/crdt-yjs/yjs-prosemirror-bridge.ts +0 -272
  217. package/src/diagnostics.ts +0 -116
  218. package/src/generated-bridge.ts +0 -741
  219. package/src/mutations.ts +0 -168
  220. package/src/network.ts +0 -32
  221. package/src/react/index.ts +0 -1036
  222. package/src/react-native/index.ts +0 -152
  223. package/src/runtime-contract.ts +0 -48
  224. package/src/rust-client.ts +0 -1491
  225. package/src/sentry.ts +0 -215
  226. package/src/sql-safety.ts +0 -61
  227. package/src/tauri/index.ts +0 -211
  228. package/src/types.ts +0 -1397
  229. package/src/wasm-bindings/generated-wasm-bindings.d.ts +0 -70
  230. package/src/wasm-bindings/runtime-contract.ts +0 -158
  231. package/src/wasm-runtime.ts +0 -145
  232. package/src/worker-client.ts +0 -2289
  233. package/src/worker-realtime.ts +0 -843
@@ -1,741 +0,0 @@
1
- // @generated by packages/client/scripts/generate-bridge.ts
2
- import type { BlobRef, SyncOperation } from '@syncular/core';
3
- import type {
4
- SyncularApplyYjsEnvelopeToPayloadArgs,
5
- SyncularApplyYjsTextUpdatesArgs,
6
- SyncularAuthHeaders,
7
- SyncularAuthLeaseRecord,
8
- SyncularBlobEncryptionConfig,
9
- SyncularBlobStoreOptions,
10
- SyncularBlobUploadQueueProcessOptions,
11
- SyncularBuildYjsTextUpdateArgs,
12
- SyncularClientConfig,
13
- SyncularConflictResolution,
14
- SyncularCrdtFieldCompactionRequest,
15
- SyncularCrdtFieldRequest,
16
- SyncularCrdtFieldTextRequest,
17
- SyncularCrdtFieldYjsUpdateRequest,
18
- SyncularEncryptedCrdtConfig,
19
- SyncularEncryptionHelperMethod,
20
- SyncularFieldEncryptionConfig,
21
- SyncularLiveQueryDependencyHint,
22
- SyncularLocalHealthRepairRequest,
23
- SyncularLocalSyncResetRequest,
24
- SyncularStorageCompactionOptions,
25
- SyncularSubscriptionSpec,
26
- SyncularSyncAttempt,
27
- } from './types';
28
- import type { SYNCULAR_WORKER_PROTOCOL_VERSION } from './worker-protocol';
29
-
30
- export interface SyncularWorkerRuntimeArtifact {
31
- name?: string;
32
- wasmGlueUrl?: string;
33
- wasmUrl?: string;
34
- features?: string[];
35
- }
36
-
37
- export type SyncularWorkerRealtimeOptions = {
38
- wsUrl?: string;
39
- params?: Record<string, string>;
40
- initialReconnectDelayMs?: number;
41
- maxReconnectDelayMs?: number;
42
- reconnectBackoffFactor?: number;
43
- reconnectJitterRatio?: number;
44
- pullRecoveryJitterMs?: number;
45
- heartbeatTimeoutMs?: number;
46
- };
47
-
48
- export type SyncularGeneratedWorkerRequest =
49
- | {
50
- id: number;
51
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
52
- type: 'open';
53
- config: SyncularClientConfig;
54
- runtime?: SyncularWorkerRuntimeArtifact;
55
- }
56
- | {
57
- id: number;
58
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
59
- type: 'setAuthHeaders';
60
- headers: SyncularAuthHeaders;
61
- }
62
- | {
63
- id: number;
64
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
65
- type: 'setFieldEncryption';
66
- config: SyncularFieldEncryptionConfig | null;
67
- }
68
- | {
69
- id: number;
70
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
71
- type: 'setEncryptedCrdt';
72
- config: SyncularEncryptedCrdtConfig | null;
73
- }
74
- | {
75
- id: number;
76
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
77
- type: 'setBlobEncryption';
78
- config: SyncularBlobEncryptionConfig | null;
79
- }
80
- | {
81
- id: number;
82
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
83
- type: 'setSubscriptions';
84
- subscriptions: SyncularSubscriptionSpec[];
85
- }
86
- | {
87
- id: number;
88
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
89
- type: 'forceSubscriptionsBootstrap';
90
- subscriptionIds?: string[];
91
- }
92
- | {
93
- id: number;
94
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
95
- type: 'upsertAuthLease';
96
- lease: SyncularAuthLeaseRecord;
97
- }
98
- | {
99
- id: number;
100
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
101
- type: 'authLease';
102
- leaseId: string;
103
- }
104
- | {
105
- id: number;
106
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
107
- type: 'activeAuthLeases';
108
- actorId?: string | null;
109
- nowMs: number;
110
- }
111
- | {
112
- id: number;
113
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
114
- type: 'startRealtime';
115
- options: SyncularWorkerRealtimeOptions;
116
- }
117
- | {
118
- id: number;
119
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
120
- type: 'stopRealtime';
121
- }
122
- | {
123
- id: number;
124
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
125
- type: 'sendPresence';
126
- action: 'join' | 'leave' | 'update';
127
- scopeKey: string;
128
- metadata?: Record<string, unknown>;
129
- }
130
- | {
131
- id: number;
132
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
133
- type: 'executeSql';
134
- sql: string;
135
- params: unknown[];
136
- }
137
- | {
138
- id: number;
139
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
140
- type: 'executeUnsafeSql';
141
- sql: string;
142
- params: unknown[];
143
- }
144
- | {
145
- id: number;
146
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
147
- type: 'subscribeQuery';
148
- sql: string;
149
- params: unknown[];
150
- tables: string[];
151
- hints?: SyncularLiveQueryDependencyHint[];
152
- }
153
- | {
154
- id: number;
155
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
156
- type: 'unsubscribeQuery';
157
- queryId: string;
158
- }
159
- | {
160
- id: number;
161
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
162
- type: 'drainLiveQueryEvents';
163
- }
164
- | {
165
- id: number;
166
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
167
- type: 'liveQueryDiagnostics';
168
- }
169
- | {
170
- id: number;
171
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
172
- type: 'applyMutation';
173
- operation: SyncOperation;
174
- localRow?: unknown | null;
175
- }
176
- | {
177
- id: number;
178
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
179
- type: 'applyLeasedMutation';
180
- operation: SyncOperation;
181
- localRow?: unknown | null;
182
- }
183
- | {
184
- id: number;
185
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
186
- type: 'applyMutationsBatch';
187
- operations: Array<{
188
- operation: SyncOperation;
189
- localRow?: unknown | null;
190
- }>;
191
- }
192
- | {
193
- id: number;
194
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
195
- type: 'applyMutationsCommit';
196
- operations: Array<{
197
- operation: SyncOperation;
198
- localRow?: unknown | null;
199
- }>;
200
- }
201
- | {
202
- id: number;
203
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
204
- type: 'applyLeasedMutationsCommit';
205
- operations: Array<{
206
- operation: SyncOperation;
207
- localRow?: unknown | null;
208
- }>;
209
- }
210
- | {
211
- id: number;
212
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
213
- type: 'syncPull';
214
- syncAttempt?: SyncularSyncAttempt;
215
- }
216
- | {
217
- id: number;
218
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
219
- type: 'syncPush';
220
- syncAttempt?: SyncularSyncAttempt;
221
- }
222
- | {
223
- id: number;
224
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
225
- type: 'syncOnce';
226
- syncAttempt?: SyncularSyncAttempt;
227
- }
228
- | {
229
- id: number;
230
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
231
- type: 'transportStats';
232
- }
233
- | {
234
- id: number;
235
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
236
- type: 'resetTransportStats';
237
- }
238
- | {
239
- id: number;
240
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
241
- type: 'conflictSummaries';
242
- }
243
- | {
244
- id: number;
245
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
246
- type: 'retryConflictKeepLocal';
247
- conflictId: string;
248
- }
249
- | {
250
- id: number;
251
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
252
- type: 'resolveConflict';
253
- conflictId: string;
254
- resolution: SyncularConflictResolution;
255
- }
256
- | {
257
- id: number;
258
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
259
- type: 'listTable';
260
- table: string;
261
- }
262
- | {
263
- id: number;
264
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
265
- type: 'storeBlob';
266
- data: Uint8Array;
267
- options?: SyncularBlobStoreOptions;
268
- }
269
- | {
270
- id: number;
271
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
272
- type: 'retrieveBlob';
273
- ref: BlobRef;
274
- }
275
- | {
276
- id: number;
277
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
278
- type: 'isBlobLocal';
279
- hash: string;
280
- }
281
- | {
282
- id: number;
283
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
284
- type: 'processBlobUploadQueue';
285
- options?: SyncularBlobUploadQueueProcessOptions;
286
- }
287
- | {
288
- id: number;
289
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
290
- type: 'blobUploadQueueStats';
291
- }
292
- | {
293
- id: number;
294
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
295
- type: 'blobCacheStats';
296
- }
297
- | {
298
- id: number;
299
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
300
- type: 'pruneBlobCache';
301
- maxBytes?: number;
302
- }
303
- | {
304
- id: number;
305
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
306
- type: 'clearBlobCache';
307
- }
308
- | {
309
- id: number;
310
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
311
- type: 'compactStorage';
312
- options?: SyncularStorageCompactionOptions;
313
- }
314
- | {
315
- id: number;
316
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
317
- type: 'generatedSchemaState';
318
- }
319
- | {
320
- id: number;
321
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
322
- type: 'localHealthCheck';
323
- }
324
- | {
325
- id: number;
326
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
327
- type: 'exportLocalSupportBundle';
328
- }
329
- | {
330
- id: number;
331
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
332
- type: 'importLocalSupportBundle';
333
- bundleJson: string;
334
- }
335
- | {
336
- id: number;
337
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
338
- type: 'repairLocalHealth';
339
- request: SyncularLocalHealthRepairRequest;
340
- }
341
- | {
342
- id: number;
343
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
344
- type: 'resetLocalSyncState';
345
- request?: SyncularLocalSyncResetRequest;
346
- }
347
- | {
348
- id: number;
349
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
350
- type: 'buildYjsTextUpdate';
351
- args: SyncularBuildYjsTextUpdateArgs;
352
- }
353
- | {
354
- id: number;
355
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
356
- type: 'applyYjsTextUpdates';
357
- args: SyncularApplyYjsTextUpdatesArgs;
358
- }
359
- | {
360
- id: number;
361
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
362
- type: 'applyYjsEnvelopeToPayload';
363
- args: SyncularApplyYjsEnvelopeToPayloadArgs;
364
- }
365
- | {
366
- id: number;
367
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
368
- type: 'openCrdtField';
369
- request: SyncularCrdtFieldRequest;
370
- }
371
- | {
372
- id: number;
373
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
374
- type: 'applyCrdtFieldText';
375
- request: SyncularCrdtFieldTextRequest;
376
- }
377
- | {
378
- id: number;
379
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
380
- type: 'applyCrdtFieldYjsUpdate';
381
- request: SyncularCrdtFieldYjsUpdateRequest;
382
- }
383
- | {
384
- id: number;
385
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
386
- type: 'materializeCrdtField';
387
- request: SyncularCrdtFieldRequest;
388
- }
389
- | {
390
- id: number;
391
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
392
- type: 'crdtDocumentSnapshot';
393
- request: SyncularCrdtFieldRequest;
394
- }
395
- | {
396
- id: number;
397
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
398
- type: 'crdtUpdateLog';
399
- request: SyncularCrdtFieldRequest & { limit?: number };
400
- }
401
- | {
402
- id: number;
403
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
404
- type: 'snapshotCrdtFieldStateVector';
405
- request: SyncularCrdtFieldRequest;
406
- }
407
- | {
408
- id: number;
409
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
410
- type: 'compactCrdtField';
411
- request: SyncularCrdtFieldCompactionRequest;
412
- }
413
- | {
414
- id: number;
415
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
416
- type: 'encryptionHelper';
417
- method: SyncularEncryptionHelperMethod;
418
- args?: unknown;
419
- }
420
- | {
421
- id: number;
422
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
423
- type: 'runtimeInfo';
424
- }
425
- | {
426
- id: number;
427
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
428
- type: 'close';
429
- }
430
- | {
431
- id: number;
432
- protocolVersion: typeof SYNCULAR_WORKER_PROTOCOL_VERSION;
433
- type: 'cancel';
434
- requestId: number;
435
- };
436
-
437
- export type SyncularGeneratedWorkerRequestInput =
438
- SyncularGeneratedWorkerRequest extends infer Request
439
- ? Request extends SyncularGeneratedWorkerRequest
440
- ? Omit<Request, 'id' | 'protocolVersion'>
441
- : never
442
- : never;
443
-
444
- export type SyncularGeneratedWorkerRequestType =
445
- SyncularGeneratedWorkerRequest['type'];
446
-
447
- const ABORTABLE_WORKER_REQUEST_TYPES = new Set<string>([
448
- 'syncPull',
449
- 'syncPush',
450
- 'syncOnce',
451
- 'storeBlob',
452
- 'retrieveBlob',
453
- 'processBlobUploadQueue',
454
- ]);
455
- const DIAGNOSED_SUCCESS_WORKER_REQUEST_TYPES = new Set<string>([
456
- 'open',
457
- 'setAuthHeaders',
458
- 'setFieldEncryption',
459
- 'setEncryptedCrdt',
460
- 'setBlobEncryption',
461
- 'forceSubscriptionsBootstrap',
462
- 'startRealtime',
463
- 'stopRealtime',
464
- 'syncPull',
465
- 'syncPush',
466
- 'syncOnce',
467
- 'storeBlob',
468
- 'retrieveBlob',
469
- 'processBlobUploadQueue',
470
- 'pruneBlobCache',
471
- 'clearBlobCache',
472
- 'compactStorage',
473
- 'exportLocalSupportBundle',
474
- 'importLocalSupportBundle',
475
- 'repairLocalHealth',
476
- 'resetLocalSyncState',
477
- 'close',
478
- ]);
479
- const OPERATIONAL_STATE_WORKER_REQUEST_TYPES = new Set<string>([
480
- 'upsertAuthLease',
481
- 'applyMutation',
482
- 'applyLeasedMutation',
483
- 'applyMutationsBatch',
484
- 'applyMutationsCommit',
485
- 'applyLeasedMutationsCommit',
486
- 'syncPull',
487
- 'syncPush',
488
- 'syncOnce',
489
- 'retryConflictKeepLocal',
490
- 'resolveConflict',
491
- 'compactStorage',
492
- 'repairLocalHealth',
493
- 'resetLocalSyncState',
494
- ]);
495
- const WORKER_REQUEST_DIAGNOSTIC_SOURCES: Record<
496
- string,
497
- 'auth' | 'blob' | 'client' | 'realtime' | 'storage' | 'sync' | 'worker'
498
- > = {
499
- open: 'storage',
500
- setAuthHeaders: 'auth',
501
- setFieldEncryption: 'client',
502
- setEncryptedCrdt: 'client',
503
- setBlobEncryption: 'client',
504
- setSubscriptions: 'sync',
505
- forceSubscriptionsBootstrap: 'sync',
506
- startRealtime: 'realtime',
507
- stopRealtime: 'realtime',
508
- syncPull: 'sync',
509
- syncPush: 'sync',
510
- syncOnce: 'sync',
511
- storeBlob: 'blob',
512
- retrieveBlob: 'blob',
513
- isBlobLocal: 'blob',
514
- processBlobUploadQueue: 'blob',
515
- blobUploadQueueStats: 'blob',
516
- blobCacheStats: 'blob',
517
- pruneBlobCache: 'blob',
518
- clearBlobCache: 'blob',
519
- compactStorage: 'storage',
520
- generatedSchemaState: 'storage',
521
- localHealthCheck: 'storage',
522
- exportLocalSupportBundle: 'storage',
523
- importLocalSupportBundle: 'storage',
524
- repairLocalHealth: 'storage',
525
- resetLocalSyncState: 'storage',
526
- encryptionHelper: 'client',
527
- close: 'storage',
528
- };
529
-
530
- export function isGeneratedSyncularAbortableWorkerRequestType(
531
- type: SyncularGeneratedWorkerRequestType
532
- ): boolean {
533
- return ABORTABLE_WORKER_REQUEST_TYPES.has(type);
534
- }
535
-
536
- export function isGeneratedSyncularDiagnosedSuccessWorkerRequestType(
537
- type: SyncularGeneratedWorkerRequestType
538
- ): boolean {
539
- return DIAGNOSED_SUCCESS_WORKER_REQUEST_TYPES.has(type);
540
- }
541
-
542
- export function isGeneratedSyncularOperationalStateWorkerRequestType(
543
- type: SyncularGeneratedWorkerRequestType
544
- ): boolean {
545
- return OPERATIONAL_STATE_WORKER_REQUEST_TYPES.has(type);
546
- }
547
-
548
- export function generatedSyncularWorkerRequestDiagnosticSource(
549
- type: SyncularGeneratedWorkerRequestType
550
- ): 'auth' | 'blob' | 'client' | 'realtime' | 'storage' | 'sync' | 'worker' {
551
- return WORKER_REQUEST_DIAGNOSTIC_SOURCES[type] ?? 'worker';
552
- }
553
-
554
- export interface SyncularGeneratedWorkerDispatchContext {
555
- requireClient(): any;
556
- openClient(
557
- request: Extract<SyncularGeneratedWorkerRequest, { type: 'open' }>
558
- ): Promise<unknown>;
559
- startRealtime(options: SyncularWorkerRealtimeOptions): unknown;
560
- stopRealtime(): unknown;
561
- sendPresence(
562
- action: 'join' | 'leave' | 'update',
563
- scopeKey: string,
564
- metadata?: Record<string, unknown>
565
- ): unknown;
566
- runtimeInfo(): Promise<unknown>;
567
- closeClient(): unknown;
568
- }
569
-
570
- export async function dispatchGeneratedSyncularWorkerRequest(
571
- context: SyncularGeneratedWorkerDispatchContext,
572
- request: SyncularGeneratedWorkerRequest
573
- ): Promise<unknown> {
574
- switch (request.type) {
575
- case 'open':
576
- return context.openClient(request);
577
- case 'setAuthHeaders':
578
- return context.requireClient().setAuthHeaders(request.headers);
579
- case 'setFieldEncryption':
580
- return context.requireClient().setFieldEncryption(request.config);
581
- case 'setEncryptedCrdt':
582
- return context.requireClient().setEncryptedCrdt(request.config);
583
- case 'setBlobEncryption':
584
- return context.requireClient().setBlobEncryption(request.config);
585
- case 'setSubscriptions':
586
- return context.requireClient().setSubscriptions(request.subscriptions);
587
- case 'forceSubscriptionsBootstrap':
588
- return context
589
- .requireClient()
590
- .forceSubscriptionsBootstrap(request.subscriptionIds ?? []);
591
- case 'upsertAuthLease':
592
- return context.requireClient().upsertAuthLease(request.lease);
593
- case 'authLease':
594
- return context.requireClient().authLease(request.leaseId);
595
- case 'activeAuthLeases':
596
- return context
597
- .requireClient()
598
- .activeAuthLeases(request.actorId, request.nowMs);
599
- case 'startRealtime':
600
- return context.startRealtime(request.options);
601
- case 'stopRealtime':
602
- return context.stopRealtime();
603
- case 'sendPresence':
604
- return context.sendPresence(
605
- request.action,
606
- request.scopeKey,
607
- request.metadata
608
- );
609
- case 'executeSql':
610
- return context.requireClient().executeSql(request.sql, request.params);
611
- case 'executeUnsafeSql':
612
- return context
613
- .requireClient()
614
- .executeUnsafeSql(request.sql, request.params);
615
- case 'subscribeQuery':
616
- return context
617
- .requireClient()
618
- .subscribeQuery(
619
- request.sql,
620
- request.params,
621
- request.tables,
622
- request.hints ?? []
623
- );
624
- case 'unsubscribeQuery':
625
- return context.requireClient().unsubscribeQuery(request.queryId) ?? true;
626
- case 'drainLiveQueryEvents':
627
- return context.requireClient().drainLiveQueryEvents();
628
- case 'liveQueryDiagnostics':
629
- return context.requireClient().liveQueryDiagnostics();
630
- case 'applyMutation':
631
- return context
632
- .requireClient()
633
- .applyMutation(request.operation, request.localRow);
634
- case 'applyLeasedMutation':
635
- return context
636
- .requireClient()
637
- .applyLeasedMutation(request.operation, request.localRow);
638
- case 'applyMutationsBatch':
639
- return context.requireClient().applyMutationsBatch(request.operations);
640
- case 'applyMutationsCommit':
641
- return context.requireClient().applyMutationsCommit(request.operations);
642
- case 'applyLeasedMutationsCommit':
643
- return context
644
- .requireClient()
645
- .applyLeasedMutationsCommit(request.operations);
646
- case 'syncPull':
647
- return context
648
- .requireClient()
649
- .syncPull({ syncAttempt: request.syncAttempt });
650
- case 'syncPush':
651
- return context
652
- .requireClient()
653
- .syncPush({ syncAttempt: request.syncAttempt });
654
- case 'syncOnce':
655
- return context
656
- .requireClient()
657
- .syncOnce({ syncAttempt: request.syncAttempt });
658
- case 'transportStats':
659
- return context.requireClient().transportStats();
660
- case 'resetTransportStats':
661
- return context.requireClient().resetTransportStats() ?? true;
662
- case 'conflictSummaries':
663
- return context.requireClient().conflictSummaries();
664
- case 'retryConflictKeepLocal':
665
- return context.requireClient().retryConflictKeepLocal(request.conflictId);
666
- case 'resolveConflict':
667
- return context
668
- .requireClient()
669
- .resolveConflict(request.conflictId, request.resolution);
670
- case 'listTable':
671
- return context.requireClient().listTable(request.table);
672
- case 'storeBlob':
673
- return context.requireClient().storeBlob(request.data, request.options);
674
- case 'retrieveBlob':
675
- return context.requireClient().retrieveBlob(request.ref);
676
- case 'isBlobLocal':
677
- return context.requireClient().isBlobLocal(request.hash);
678
- case 'processBlobUploadQueue':
679
- return context.requireClient().processBlobUploadQueue(request.options);
680
- case 'blobUploadQueueStats':
681
- return context.requireClient().blobUploadQueueStats();
682
- case 'blobCacheStats':
683
- return context.requireClient().blobCacheStats();
684
- case 'pruneBlobCache':
685
- return context.requireClient().pruneBlobCache(request.maxBytes);
686
- case 'clearBlobCache':
687
- return context.requireClient().clearBlobCache() ?? true;
688
- case 'compactStorage':
689
- return context.requireClient().compactStorage(request.options);
690
- case 'generatedSchemaState':
691
- return context.requireClient().generatedSchemaState();
692
- case 'localHealthCheck':
693
- return context.requireClient().localHealthCheck();
694
- case 'exportLocalSupportBundle':
695
- return context.requireClient().exportLocalSupportBundle();
696
- case 'importLocalSupportBundle':
697
- return context
698
- .requireClient()
699
- .importLocalSupportBundle(request.bundleJson);
700
- case 'repairLocalHealth':
701
- return context.requireClient().repairLocalHealth(request.request);
702
- case 'resetLocalSyncState':
703
- return context.requireClient().resetLocalSyncState(request.request);
704
- case 'buildYjsTextUpdate':
705
- return context.requireClient().buildYjsTextUpdate(request.args);
706
- case 'applyYjsTextUpdates':
707
- return context.requireClient().applyYjsTextUpdates(request.args);
708
- case 'applyYjsEnvelopeToPayload':
709
- return context.requireClient().applyYjsEnvelopeToPayload(request.args);
710
- case 'openCrdtField':
711
- return context.requireClient().openCrdtField(request.request);
712
- case 'applyCrdtFieldText':
713
- return context.requireClient().applyCrdtFieldText(request.request);
714
- case 'applyCrdtFieldYjsUpdate':
715
- return context.requireClient().applyCrdtFieldYjsUpdate(request.request);
716
- case 'materializeCrdtField':
717
- return context.requireClient().materializeCrdtField(request.request);
718
- case 'crdtDocumentSnapshot':
719
- return context.requireClient().crdtDocumentSnapshot(request.request);
720
- case 'crdtUpdateLog':
721
- return context.requireClient().crdtUpdateLog(request.request);
722
- case 'snapshotCrdtFieldStateVector':
723
- return context
724
- .requireClient()
725
- .snapshotCrdtFieldStateVector(request.request);
726
- case 'compactCrdtField':
727
- return context.requireClient().compactCrdtField(request.request);
728
- case 'encryptionHelper':
729
- return context
730
- .requireClient()
731
- .encryptionHelper(request.method, request.args);
732
- case 'runtimeInfo':
733
- return context.runtimeInfo();
734
- case 'close':
735
- return context.closeClient();
736
- case 'cancel':
737
- throw new Error(
738
- 'Generated Syncular bridge dispatch does not handle cancel requests.'
739
- );
740
- }
741
- }