@powersync/common 1.57.1 → 2.0.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 (219) hide show
  1. package/lib/attachments/AttachmentContext.d.ts +5 -5
  2. package/lib/attachments/AttachmentContext.js +6 -2
  3. package/lib/attachments/AttachmentContext.js.map +1 -1
  4. package/lib/attachments/AttachmentQueue.d.ts +6 -6
  5. package/lib/attachments/AttachmentQueue.js +9 -8
  6. package/lib/attachments/AttachmentQueue.js.map +1 -1
  7. package/lib/attachments/AttachmentService.d.ts +3 -3
  8. package/lib/attachments/AttachmentService.js +4 -3
  9. package/lib/attachments/AttachmentService.js.map +1 -1
  10. package/lib/attachments/Schema.d.ts +2 -2
  11. package/lib/attachments/SyncingService.d.ts +2 -2
  12. package/lib/attachments/SyncingService.js +21 -6
  13. package/lib/attachments/SyncingService.js.map +1 -1
  14. package/lib/client/{AbstractPowerSyncDatabase.d.ts → CommonPowerSyncDatabase.d.ts} +56 -232
  15. package/lib/client/CommonPowerSyncDatabase.js +2 -0
  16. package/lib/client/CommonPowerSyncDatabase.js.map +1 -0
  17. package/lib/client/SQLOpenFactory.d.ts +35 -13
  18. package/lib/client/SQLOpenFactory.js +1 -25
  19. package/lib/client/SQLOpenFactory.js.map +1 -1
  20. package/lib/client/compilableQueryWatch.d.ts +2 -2
  21. package/lib/client/compilableQueryWatch.js +1 -2
  22. package/lib/client/compilableQueryWatch.js.map +1 -1
  23. package/lib/client/connection/PowerSyncBackendConnector.d.ts +3 -3
  24. package/lib/client/runOnSchemaChange.d.ts +2 -2
  25. package/lib/client/runOnSchemaChange.js.map +1 -1
  26. package/lib/client/sync/bucket/CrudEntry.d.ts +3 -34
  27. package/lib/client/sync/bucket/CrudEntry.js +0 -99
  28. package/lib/client/sync/bucket/CrudEntry.js.map +1 -1
  29. package/lib/client/sync/options.d.ts +65 -0
  30. package/lib/client/sync/options.js +25 -0
  31. package/lib/client/sync/options.js.map +1 -0
  32. package/lib/client/sync/sync-streams.d.ts +1 -1
  33. package/lib/client/triggers/TriggerManager.d.ts +9 -38
  34. package/lib/client/watched/GetAllQuery.d.ts +3 -3
  35. package/lib/client/watched/GetAllQuery.js +1 -1
  36. package/lib/client/watched/GetAllQuery.js.map +1 -1
  37. package/lib/client/watched/WatchedQuery.d.ts +2 -10
  38. package/lib/client/watched/WatchedQuery.js +0 -11
  39. package/lib/client/watched/WatchedQuery.js.map +1 -1
  40. package/lib/client/watched/processors/DifferentialQueryProcessor.d.ts +0 -50
  41. package/lib/client/watched/processors/DifferentialQueryProcessor.js +1 -176
  42. package/lib/client/watched/processors/DifferentialQueryProcessor.js.map +1 -1
  43. package/lib/client/watched/processors/OnChangeQueryProcessor.d.ts +0 -22
  44. package/lib/client/watched/processors/OnChangeQueryProcessor.js +1 -82
  45. package/lib/client/watched/processors/OnChangeQueryProcessor.js.map +1 -1
  46. package/lib/db/DBAdapter.d.ts +72 -154
  47. package/lib/db/DBAdapter.js +70 -108
  48. package/lib/db/DBAdapter.js.map +1 -1
  49. package/lib/db/QueryResult.d.ts +104 -0
  50. package/lib/db/QueryResult.js +96 -0
  51. package/lib/db/QueryResult.js.map +1 -0
  52. package/lib/db/crud/SyncProgress.d.ts +1 -13
  53. package/lib/db/crud/SyncProgress.js +1 -62
  54. package/lib/db/crud/SyncProgress.js.map +1 -1
  55. package/lib/db/crud/SyncStatus.d.ts +32 -66
  56. package/lib/db/crud/SyncStatus.js +1 -253
  57. package/lib/db/crud/SyncStatus.js.map +1 -1
  58. package/lib/db/schema/Column.d.ts +0 -7
  59. package/lib/db/schema/Column.js +0 -7
  60. package/lib/db/schema/Column.js.map +1 -1
  61. package/lib/db/schema/Index.d.ts +2 -6
  62. package/lib/db/schema/Index.js +1 -4
  63. package/lib/db/schema/Index.js.map +1 -1
  64. package/lib/db/schema/IndexedColumn.d.ts +2 -6
  65. package/lib/db/schema/IndexedColumn.js +1 -4
  66. package/lib/db/schema/IndexedColumn.js.map +1 -1
  67. package/lib/db/schema/Schema.d.ts +4 -28
  68. package/lib/db/schema/Schema.js.map +1 -1
  69. package/lib/db/schema/Table.d.ts +50 -96
  70. package/lib/db/schema/Table.js +83 -91
  71. package/lib/db/schema/Table.js.map +1 -1
  72. package/lib/index.d.ts +5 -21
  73. package/lib/index.js +5 -22
  74. package/lib/index.js.map +1 -1
  75. package/lib/utils/BaseObserver.d.ts +1 -1
  76. package/lib/utils/BaseObserver.js +1 -1
  77. package/lib/utils/Logger.d.ts +52 -23
  78. package/lib/utils/Logger.js +35 -33
  79. package/lib/utils/Logger.js.map +1 -1
  80. package/lib/utils/MetaBaseObserver.d.ts +11 -11
  81. package/lib/utils/MetaBaseObserver.js +1 -50
  82. package/lib/utils/MetaBaseObserver.js.map +1 -1
  83. package/lib/utils/mutex.d.ts +3 -53
  84. package/lib/utils/mutex.js +1 -156
  85. package/lib/utils/mutex.js.map +1 -1
  86. package/package.json +8 -45
  87. package/src/attachments/AttachmentContext.ts +11 -10
  88. package/src/attachments/AttachmentQueue.ts +15 -14
  89. package/src/attachments/AttachmentService.ts +7 -6
  90. package/src/attachments/Schema.ts +2 -2
  91. package/src/attachments/SyncingService.ts +23 -9
  92. package/src/client/CommonPowerSyncDatabase.ts +540 -0
  93. package/src/client/SQLOpenFactory.ts +38 -22
  94. package/src/client/compilableQueryWatch.ts +3 -4
  95. package/src/client/connection/PowerSyncBackendConnector.ts +3 -3
  96. package/src/client/runOnSchemaChange.ts +2 -2
  97. package/src/client/sync/bucket/CrudEntry.ts +4 -104
  98. package/src/client/sync/options.ts +77 -0
  99. package/src/client/sync/sync-streams.ts +1 -1
  100. package/src/client/triggers/TriggerManager.ts +10 -41
  101. package/src/client/watched/GetAllQuery.ts +3 -3
  102. package/src/client/watched/WatchedQuery.ts +2 -15
  103. package/src/client/watched/processors/DifferentialQueryProcessor.ts +0 -223
  104. package/src/client/watched/processors/OnChangeQueryProcessor.ts +0 -111
  105. package/src/db/DBAdapter.ts +141 -226
  106. package/src/db/QueryResult.ts +195 -0
  107. package/src/db/crud/SyncProgress.ts +2 -42
  108. package/src/db/crud/SyncStatus.ts +45 -220
  109. package/src/db/schema/Column.ts +0 -8
  110. package/src/db/schema/Index.ts +3 -6
  111. package/src/db/schema/IndexedColumn.ts +3 -6
  112. package/src/db/schema/Schema.ts +4 -4
  113. package/src/db/schema/Table.ts +111 -186
  114. package/src/index.ts +5 -21
  115. package/src/utils/BaseObserver.ts +1 -1
  116. package/src/utils/Logger.ts +80 -34
  117. package/src/utils/MetaBaseObserver.ts +14 -60
  118. package/src/utils/mutex.ts +4 -201
  119. package/dist/bundle.cjs +0 -14390
  120. package/dist/bundle.cjs.map +0 -1
  121. package/dist/bundle.mjs +0 -14309
  122. package/dist/bundle.mjs.map +0 -1
  123. package/dist/bundle.node.cjs +0 -12021
  124. package/dist/bundle.node.cjs.map +0 -1
  125. package/dist/bundle.node.mjs +0 -11940
  126. package/dist/bundle.node.mjs.map +0 -1
  127. package/dist/index.d.cts +0 -4651
  128. package/legacy/sync_protocol.d.ts +0 -103
  129. package/lib/client/AbstractPowerSyncDatabase.js +0 -990
  130. package/lib/client/AbstractPowerSyncDatabase.js.map +0 -1
  131. package/lib/client/AbstractPowerSyncOpenFactory.d.ts +0 -28
  132. package/lib/client/AbstractPowerSyncOpenFactory.js +0 -28
  133. package/lib/client/AbstractPowerSyncOpenFactory.js.map +0 -1
  134. package/lib/client/ConnectionManager.d.ts +0 -115
  135. package/lib/client/ConnectionManager.js +0 -294
  136. package/lib/client/ConnectionManager.js.map +0 -1
  137. package/lib/client/CustomQuery.d.ts +0 -22
  138. package/lib/client/CustomQuery.js +0 -43
  139. package/lib/client/CustomQuery.js.map +0 -1
  140. package/lib/client/constants.d.ts +0 -4
  141. package/lib/client/constants.js +0 -5
  142. package/lib/client/constants.js.map +0 -1
  143. package/lib/client/sync/bucket/BucketStorageAdapter.d.ts +0 -56
  144. package/lib/client/sync/bucket/BucketStorageAdapter.js +0 -29
  145. package/lib/client/sync/bucket/BucketStorageAdapter.js.map +0 -1
  146. package/lib/client/sync/bucket/SqliteBucketStorage.d.ts +0 -37
  147. package/lib/client/sync/bucket/SqliteBucketStorage.js +0 -165
  148. package/lib/client/sync/bucket/SqliteBucketStorage.js.map +0 -1
  149. package/lib/client/sync/stream/AbstractRemote.d.ts +0 -180
  150. package/lib/client/sync/stream/AbstractRemote.js +0 -505
  151. package/lib/client/sync/stream/AbstractRemote.js.map +0 -1
  152. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +0 -265
  153. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +0 -705
  154. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js.map +0 -1
  155. package/lib/client/sync/stream/WebsocketClientTransport.d.ts +0 -15
  156. package/lib/client/sync/stream/WebsocketClientTransport.js +0 -62
  157. package/lib/client/sync/stream/WebsocketClientTransport.js.map +0 -1
  158. package/lib/client/sync/stream/core-instruction.d.ts +0 -77
  159. package/lib/client/sync/stream/core-instruction.js +0 -30
  160. package/lib/client/sync/stream/core-instruction.js.map +0 -1
  161. package/lib/client/triggers/MemoryTriggerClaimManager.d.ts +0 -6
  162. package/lib/client/triggers/MemoryTriggerClaimManager.js +0 -21
  163. package/lib/client/triggers/MemoryTriggerClaimManager.js.map +0 -1
  164. package/lib/client/triggers/TriggerManagerImpl.d.ts +0 -39
  165. package/lib/client/triggers/TriggerManagerImpl.js +0 -410
  166. package/lib/client/triggers/TriggerManagerImpl.js.map +0 -1
  167. package/lib/client/watched/processors/AbstractQueryProcessor.d.ts +0 -68
  168. package/lib/client/watched/processors/AbstractQueryProcessor.js +0 -151
  169. package/lib/client/watched/processors/AbstractQueryProcessor.js.map +0 -1
  170. package/lib/db/ConnectionClosedError.d.ts +0 -12
  171. package/lib/db/ConnectionClosedError.js +0 -23
  172. package/lib/db/ConnectionClosedError.js.map +0 -1
  173. package/lib/db/schema/TableV2.d.ts +0 -11
  174. package/lib/db/schema/TableV2.js +0 -11
  175. package/lib/db/schema/TableV2.js.map +0 -1
  176. package/lib/utils/AbortOperation.d.ts +0 -11
  177. package/lib/utils/AbortOperation.js +0 -21
  178. package/lib/utils/AbortOperation.js.map +0 -1
  179. package/lib/utils/ControlledExecutor.d.ts +0 -31
  180. package/lib/utils/ControlledExecutor.js +0 -54
  181. package/lib/utils/ControlledExecutor.js.map +0 -1
  182. package/lib/utils/async.d.ts +0 -46
  183. package/lib/utils/async.js +0 -147
  184. package/lib/utils/async.js.map +0 -1
  185. package/lib/utils/compatibility.d.ts +0 -8
  186. package/lib/utils/compatibility.js +0 -9
  187. package/lib/utils/compatibility.js.map +0 -1
  188. package/lib/utils/parseQuery.d.ts +0 -12
  189. package/lib/utils/parseQuery.js +0 -20
  190. package/lib/utils/parseQuery.js.map +0 -1
  191. package/lib/utils/queue.d.ts +0 -16
  192. package/lib/utils/queue.js +0 -42
  193. package/lib/utils/queue.js.map +0 -1
  194. package/lib/utils/stream_transform.d.ts +0 -41
  195. package/lib/utils/stream_transform.js +0 -211
  196. package/lib/utils/stream_transform.js.map +0 -1
  197. package/src/client/AbstractPowerSyncDatabase.ts +0 -1408
  198. package/src/client/AbstractPowerSyncOpenFactory.ts +0 -45
  199. package/src/client/ConnectionManager.ts +0 -405
  200. package/src/client/CustomQuery.ts +0 -56
  201. package/src/client/constants.ts +0 -4
  202. package/src/client/sync/bucket/BucketStorageAdapter.ts +0 -65
  203. package/src/client/sync/bucket/SqliteBucketStorage.ts +0 -202
  204. package/src/client/sync/stream/AbstractRemote.ts +0 -644
  205. package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +0 -970
  206. package/src/client/sync/stream/WebsocketClientTransport.ts +0 -82
  207. package/src/client/sync/stream/core-instruction.ts +0 -109
  208. package/src/client/triggers/MemoryTriggerClaimManager.ts +0 -25
  209. package/src/client/triggers/TriggerManagerImpl.ts +0 -501
  210. package/src/client/watched/processors/AbstractQueryProcessor.ts +0 -226
  211. package/src/db/ConnectionClosedError.ts +0 -25
  212. package/src/db/schema/TableV2.ts +0 -11
  213. package/src/utils/AbortOperation.ts +0 -19
  214. package/src/utils/ControlledExecutor.ts +0 -78
  215. package/src/utils/async.ts +0 -185
  216. package/src/utils/compatibility.ts +0 -9
  217. package/src/utils/parseQuery.ts +0 -31
  218. package/src/utils/queue.ts +0 -48
  219. package/src/utils/stream_transform.ts +0 -260
@@ -1,505 +0,0 @@
1
- import Logger from 'js-logger';
2
- import { RSocketConnector } from 'rsocket-core';
3
- import PACKAGE from '../../../../package.json' with { type: 'json' };
4
- import { AbortOperation } from '../../../utils/AbortOperation.js';
5
- import { WebsocketClientTransport } from './WebsocketClientTransport.js';
6
- import { doneResult, extractBsonObjects, extractJsonLines, valueResult } from '../../../utils/stream_transform.js';
7
- import { EventQueue } from '../../../utils/async.js';
8
- const POWERSYNC_TRAILING_SLASH_MATCH = /\/+$/;
9
- const POWERSYNC_JS_VERSION = PACKAGE.version;
10
- const SYNC_QUEUE_REQUEST_HIGH_WATER = 10;
11
- const SYNC_QUEUE_REQUEST_LOW_WATER = 5;
12
- // Keep alive message is sent every period
13
- const KEEP_ALIVE_MS = 20_000;
14
- // One message of any type must be received in this period.
15
- const SOCKET_TIMEOUT_MS = 30_000;
16
- // One keepalive message must be received in this period.
17
- // If there is a backlog of messages (for example on slow connections), keepalive messages could be delayed
18
- // significantly. Therefore this is longer than the socket timeout.
19
- const KEEP_ALIVE_LIFETIME_MS = 90_000;
20
- /**
21
- * @internal
22
- */
23
- export const DEFAULT_REMOTE_LOGGER = Logger.get('PowerSyncRemote');
24
- /**
25
- * @public
26
- */
27
- export var FetchStrategy;
28
- (function (FetchStrategy) {
29
- /**
30
- * Queues multiple sync events before processing, reducing round-trips.
31
- * This comes at the cost of more processing overhead, which may cause ACK timeouts on older/weaker devices for big enough datasets.
32
- */
33
- FetchStrategy["Buffered"] = "buffered";
34
- /**
35
- * Processes each sync event immediately before requesting the next.
36
- * This reduces processing overhead and improves real-time responsiveness.
37
- */
38
- FetchStrategy["Sequential"] = "sequential";
39
- })(FetchStrategy || (FetchStrategy = {}));
40
- /**
41
- * Class wrapper for providing a fetch implementation.
42
- * The class wrapper is used to distinguish the fetchImplementation
43
- * option in [AbstractRemoteOptions] from the general fetch method
44
- * which is typeof "function"
45
- *
46
- * @internal
47
- */
48
- export class FetchImplementationProvider {
49
- getFetch() {
50
- throw new Error('Unspecified fetch implementation');
51
- }
52
- }
53
- /**
54
- * @internal
55
- */
56
- export const DEFAULT_REMOTE_OPTIONS = {
57
- socketUrlTransformer: (url) => url.replace(/^https?:\/\//, function (match) {
58
- return match === 'https://' ? 'wss://' : 'ws://';
59
- }),
60
- fetchImplementation: new FetchImplementationProvider(),
61
- fetchOptions: {}
62
- };
63
- /**
64
- * @internal
65
- */
66
- export class AbstractRemote {
67
- connector;
68
- logger;
69
- credentials = null;
70
- options;
71
- constructor(connector, logger = DEFAULT_REMOTE_LOGGER, options) {
72
- this.connector = connector;
73
- this.logger = logger;
74
- this.options = {
75
- ...DEFAULT_REMOTE_OPTIONS,
76
- ...(options ?? {})
77
- };
78
- }
79
- /**
80
- * @returns a fetch implementation (function)
81
- * which can be called to perform fetch requests
82
- */
83
- get fetch() {
84
- const { fetchImplementation } = this.options;
85
- return fetchImplementation instanceof FetchImplementationProvider
86
- ? fetchImplementation.getFetch()
87
- : fetchImplementation;
88
- }
89
- /**
90
- * Get credentials currently cached, or fetch new credentials if none are
91
- * available.
92
- *
93
- * These credentials may have expired already.
94
- */
95
- async getCredentials() {
96
- if (this.credentials) {
97
- return this.credentials;
98
- }
99
- return this.prefetchCredentials();
100
- }
101
- /**
102
- * Fetch a new set of credentials and cache it.
103
- *
104
- * Until this call succeeds, `getCredentials` will still return the
105
- * old credentials.
106
- *
107
- * This may be called before the current credentials have expired.
108
- */
109
- async prefetchCredentials() {
110
- this.credentials = await this.fetchCredentials();
111
- return this.credentials;
112
- }
113
- /**
114
- * Get credentials for PowerSync.
115
- *
116
- * This should always fetch a fresh set of credentials - don't use cached
117
- * values.
118
- */
119
- async fetchCredentials() {
120
- const credentials = await this.connector.fetchCredentials();
121
- if (credentials?.endpoint.match(POWERSYNC_TRAILING_SLASH_MATCH)) {
122
- throw new Error(`A trailing forward slash "/" was found in the fetchCredentials endpoint: "${credentials.endpoint}". Remove the trailing forward slash "/" to fix this error.`);
123
- }
124
- return credentials;
125
- }
126
- /***
127
- * Immediately invalidate credentials.
128
- *
129
- * This may be called when the current credentials have expired.
130
- */
131
- invalidateCredentials() {
132
- this.credentials = null;
133
- this.connector.invalidateCredentials?.();
134
- }
135
- getUserAgent() {
136
- return `powersync-js/${POWERSYNC_JS_VERSION}`;
137
- }
138
- async buildRequest(path) {
139
- const credentials = await this.getCredentials();
140
- if (credentials != null && (credentials.endpoint == null || credentials.endpoint == '')) {
141
- throw new Error('PowerSync endpoint not configured');
142
- }
143
- else if (credentials?.token == null || credentials?.token == '') {
144
- const error = new Error(`Not signed in`);
145
- error.status = 401;
146
- throw error;
147
- }
148
- const userAgent = this.getUserAgent();
149
- return {
150
- url: credentials.endpoint + path,
151
- headers: {
152
- 'content-type': 'application/json',
153
- Authorization: `Token ${credentials.token}`,
154
- 'x-user-agent': userAgent
155
- }
156
- };
157
- }
158
- async post(path, data, headers = {}) {
159
- const request = await this.buildRequest(path);
160
- const res = await this.fetch(request.url, {
161
- method: 'POST',
162
- headers: {
163
- ...headers,
164
- ...request.headers
165
- },
166
- body: JSON.stringify(data)
167
- });
168
- if (res.status === 401) {
169
- this.invalidateCredentials();
170
- }
171
- if (!res.ok) {
172
- throw new Error(`Received ${res.status} - ${res.statusText} when posting to ${path}: ${await res.text()}}`);
173
- }
174
- return res.json();
175
- }
176
- async get(path, headers) {
177
- const request = await this.buildRequest(path);
178
- const res = await this.fetch(request.url, {
179
- method: 'GET',
180
- headers: {
181
- ...headers,
182
- ...request.headers
183
- }
184
- });
185
- if (res.status === 401) {
186
- this.invalidateCredentials();
187
- }
188
- if (!res.ok) {
189
- throw new Error(`Received ${res.status} - ${res.statusText} when getting from ${path}: ${await res.text()}}`);
190
- }
191
- return res.json();
192
- }
193
- /**
194
- * @returns A text decoder decoding UTF-8. This is a method to allow patching it for Hermes which doesn't support the
195
- * builtin, without forcing us to bundle a polyfill with `@powersync/common`.
196
- */
197
- createTextDecoder() {
198
- return new TextDecoder();
199
- }
200
- createSocket(url) {
201
- return new WebSocket(url);
202
- }
203
- /**
204
- * Returns a data stream of sync line data, fetched via RSocket-over-WebSocket.
205
- *
206
- * The only mechanism to abort the returned stream is to use the abort signal in {@link SocketSyncStreamOptions}.
207
- */
208
- async socketStreamRaw(options) {
209
- const { path, fetchStrategy = FetchStrategy.Buffered } = options;
210
- const mimeType = 'application/json';
211
- function toBuffer(js) {
212
- return Buffer.from(JSON.stringify(js));
213
- }
214
- const syncQueueRequestSize = fetchStrategy == FetchStrategy.Buffered ? 10 : 1;
215
- const request = await this.buildRequest(path);
216
- const url = this.options.socketUrlTransformer(request.url);
217
- // Add the user agent in the setup payload - we can't set custom
218
- // headers with websockets on web. The browser userAgent is however added
219
- // automatically as a header.
220
- const userAgent = this.getUserAgent();
221
- // While we're connecting (a process that can't be aborted in RSocket), the WebSocket instance to close if we wanted
222
- // to abort the connection.
223
- let pendingSocket = null;
224
- let keepAliveTimeout;
225
- let rsocket = null;
226
- let paused = false;
227
- const queue = new EventQueue({
228
- eventDelivered: () => {
229
- if (queue.countOutstandingEvents <= SYNC_QUEUE_REQUEST_LOW_WATER) {
230
- paused = false;
231
- requestMore();
232
- }
233
- }
234
- });
235
- let didClose = false;
236
- let connectionEstablished = false;
237
- let pendingEventsCount = syncQueueRequestSize;
238
- let res = null;
239
- const abortRequest = () => {
240
- if (didClose) {
241
- return;
242
- }
243
- didClose = true;
244
- clearTimeout(keepAliveTimeout);
245
- if (pendingSocket) {
246
- pendingSocket.close();
247
- }
248
- if (rsocket) {
249
- rsocket.close();
250
- }
251
- // Send a bogus event to the queue to ensure a pending listener gets woken up. We check for didClose and would
252
- // return a doneEvent.
253
- queue.notify(null);
254
- };
255
- function push(event) {
256
- queue.notify(event);
257
- if (queue.countOutstandingEvents >= SYNC_QUEUE_REQUEST_HIGH_WATER) {
258
- paused = true;
259
- }
260
- }
261
- function requestMore() {
262
- const delta = syncQueueRequestSize - pendingEventsCount;
263
- if (!paused && delta > 0) {
264
- res?.request(delta);
265
- pendingEventsCount = syncQueueRequestSize;
266
- }
267
- }
268
- // Handle upstream abort
269
- if (options.abortSignal.aborted) {
270
- throw new AbortOperation('Connection request aborted');
271
- }
272
- else {
273
- options.abortSignal.addEventListener('abort', abortRequest);
274
- }
275
- const resetTimeout = () => {
276
- clearTimeout(keepAliveTimeout);
277
- keepAliveTimeout = setTimeout(() => {
278
- this.logger.error(`No data received on WebSocket in ${SOCKET_TIMEOUT_MS}ms, closing connection.`);
279
- abortRequest();
280
- }, SOCKET_TIMEOUT_MS);
281
- };
282
- resetTimeout();
283
- const connector = new RSocketConnector({
284
- transport: new WebsocketClientTransport({
285
- url,
286
- wsCreator: (url) => {
287
- const socket = (pendingSocket = this.createSocket(url));
288
- socket.addEventListener('message', () => {
289
- resetTimeout();
290
- });
291
- return socket;
292
- }
293
- }),
294
- setup: {
295
- keepAlive: KEEP_ALIVE_MS,
296
- lifetime: KEEP_ALIVE_LIFETIME_MS,
297
- dataMimeType: mimeType,
298
- metadataMimeType: mimeType,
299
- payload: {
300
- data: null,
301
- metadata: toBuffer({
302
- token: request.headers.Authorization,
303
- user_agent: userAgent
304
- })
305
- }
306
- }
307
- });
308
- try {
309
- rsocket = await connector.connect();
310
- // The connection is established, we no longer need to monitor the initial timeout
311
- pendingSocket = null;
312
- }
313
- catch (ex) {
314
- this.logger.error(`Failed to connect WebSocket`, ex);
315
- abortRequest();
316
- throw ex;
317
- }
318
- resetTimeout();
319
- // Helps to prevent double close scenarios
320
- rsocket.onClose(() => (rsocket = null));
321
- return await new Promise((resolve, reject) => {
322
- const queueAsIterator = {
323
- next: async () => {
324
- if (didClose)
325
- return doneResult;
326
- const notification = await queue.waitForEvent(options.abortSignal);
327
- if (didClose) {
328
- return doneResult;
329
- }
330
- else {
331
- return valueResult(notification);
332
- }
333
- }
334
- };
335
- res = rsocket.requestStream({
336
- data: toBuffer(options.data),
337
- metadata: toBuffer({
338
- path
339
- })
340
- }, syncQueueRequestSize, // The initial N amount
341
- {
342
- onError: (e) => {
343
- if (e.message.includes('PSYNC_')) {
344
- if (e.message.includes('PSYNC_S21')) {
345
- this.invalidateCredentials();
346
- }
347
- }
348
- else {
349
- // Possible that connection is with an older service, always invalidate to be safe
350
- if (e.message !== 'Closed. ') {
351
- this.invalidateCredentials();
352
- }
353
- }
354
- // Don't log closed as an error
355
- if (e.message !== 'Closed. ') {
356
- this.logger.error(e);
357
- }
358
- // RSocket will close the RSocket stream automatically
359
- // Close the downstream stream as well - this will close the RSocket connection and WebSocket
360
- abortRequest();
361
- // Handles cases where the connection failed e.g. auth error or connection error
362
- if (!connectionEstablished) {
363
- reject(e);
364
- }
365
- },
366
- onNext: (payload) => {
367
- // The connection is active
368
- if (!connectionEstablished) {
369
- connectionEstablished = true;
370
- resolve(queueAsIterator);
371
- }
372
- const { data } = payload;
373
- if (data) {
374
- push(data);
375
- }
376
- // Less events are now pending
377
- pendingEventsCount--;
378
- // Request another event (unless the downstream consumer is paused).
379
- requestMore();
380
- },
381
- onComplete: () => {
382
- abortRequest(); // this will also emit a done event
383
- },
384
- onExtension: () => { }
385
- });
386
- });
387
- }
388
- /**
389
- * @returns Whether the HTTP implementation on this platform can receive streamed binary responses. This is true on
390
- * all platforms except React Native (who would have guessed...), where we must not request BSON responses.
391
- *
392
- * @see https://github.com/react-native-community/fetch?tab=readme-ov-file#motivation
393
- */
394
- get supportsStreamingBinaryResponses() {
395
- return true;
396
- }
397
- /**
398
- * Posts a `/sync/stream` request, asserts that it completes successfully and returns the streaming response as an
399
- * async iterator of byte blobs.
400
- *
401
- * To cancel the async iterator, use the abort signal from {@link SyncStreamOptions} passed to this method.
402
- */
403
- async fetchStreamRaw(options) {
404
- const { data, path, headers, abortSignal } = options;
405
- const request = await this.buildRequest(path);
406
- /**
407
- * This abort controller will abort pending fetch requests.
408
- * If the request has resolved, it will be used to close the readable stream.
409
- * Which will cancel the network request.
410
- *
411
- * This nested controller is required since:
412
- * Aborting the active fetch request while it is being consumed seems to throw
413
- * an unhandled exception on the window level.
414
- */
415
- if (abortSignal.aborted) {
416
- throw new AbortOperation('Abort request received before making fetchStreamRaw request');
417
- }
418
- const controller = new AbortController();
419
- let reader = null;
420
- abortSignal.addEventListener('abort', () => {
421
- const reason = abortSignal.reason ??
422
- new AbortOperation('Cancelling network request before it resolves. Abort signal has been received.');
423
- if (reader == null) {
424
- // Only abort via the abort controller if the request has not resolved yet
425
- controller.abort(reason);
426
- }
427
- else {
428
- reader.cancel(reason).catch(() => {
429
- // Cancelling the reader might rethrow an exception we would have handled by throwing in next(). So we can
430
- // ignore it here.
431
- });
432
- }
433
- });
434
- let res;
435
- let responseIsBson = false;
436
- try {
437
- const ndJson = 'application/x-ndjson';
438
- const bson = 'application/vnd.powersync.bson-stream';
439
- res = await this.fetch(request.url, {
440
- method: 'POST',
441
- headers: {
442
- ...headers,
443
- ...request.headers,
444
- accept: this.supportsStreamingBinaryResponses ? `${bson};q=0.9,${ndJson};q=0.8` : ndJson
445
- },
446
- body: JSON.stringify(data),
447
- signal: controller.signal,
448
- cache: 'no-store',
449
- ...(this.options.fetchOptions ?? {}),
450
- ...options.fetchOptions
451
- });
452
- if (!res.ok || !res.body) {
453
- const text = await res.text();
454
- this.logger.error(`Could not POST streaming to ${path} - ${res.status} - ${res.statusText}: ${text}`);
455
- const error = new Error(`HTTP ${res.statusText}: ${text}`);
456
- error.status = res.status;
457
- throw error;
458
- }
459
- const contentType = res.headers.get('content-type');
460
- responseIsBson = contentType == bson;
461
- }
462
- catch (ex) {
463
- if (ex.name == 'AbortError') {
464
- throw new AbortOperation(`Pending fetch request to ${request.url} has been aborted.`);
465
- }
466
- throw ex;
467
- }
468
- reader = res.body.getReader();
469
- const stream = {
470
- next: async () => {
471
- if (controller.signal.aborted) {
472
- return doneResult;
473
- }
474
- try {
475
- return await reader.read();
476
- }
477
- catch (ex) {
478
- if (controller.signal.aborted) {
479
- // .read() completes with an error if we cancel the reader, which we do to disconnect. So this is just
480
- // things working as intended, we can return a done event and consider the exception handled.
481
- return doneResult;
482
- }
483
- throw ex;
484
- }
485
- }
486
- };
487
- return { isBson: responseIsBson, stream };
488
- }
489
- /**
490
- * Posts a `/sync/stream` request.
491
- *
492
- * Depending on the `Content-Type` of the response, this returns strings for sync lines or encoded BSON documents as
493
- * `Uint8Array`s.
494
- */
495
- async fetchStream(options) {
496
- const { isBson, stream } = await this.fetchStreamRaw(options);
497
- if (isBson) {
498
- return extractBsonObjects(stream);
499
- }
500
- else {
501
- return extractJsonLines(stream, this.createTextDecoder());
502
- }
503
- }
504
- }
505
- //# sourceMappingURL=AbstractRemote.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AbstractRemote.js","sourceRoot":"","sources":["../../../../src/client/sync/stream/AbstractRemote.ts"],"names":[],"mappings":"AACA,OAAO,MAAmB,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAwB,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,OAAO,MAAM,0BAA0B,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAElE,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EACL,UAAU,EACV,kBAAkB,EAClB,gBAAgB,EAEhB,WAAW,EACZ,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAUrD,MAAM,8BAA8B,GAAG,MAAM,CAAC;AAC9C,MAAM,oBAAoB,GAAG,OAAO,CAAC,OAAO,CAAC;AAE7C,MAAM,6BAA6B,GAAG,EAAE,CAAC;AACzC,MAAM,4BAA4B,GAAG,CAAC,CAAC;AAEvC,0CAA0C;AAC1C,MAAM,aAAa,GA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