@powersync/shared-internals 0.0.0-tmp.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 (153) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +5 -0
  3. package/dist/bundle.cjs +11787 -0
  4. package/dist/bundle.cjs.map +1 -0
  5. package/dist/bundle.mjs +11757 -0
  6. package/dist/bundle.mjs.map +1 -0
  7. package/dist/bundle.node.cjs +9418 -0
  8. package/dist/bundle.node.cjs.map +1 -0
  9. package/dist/bundle.node.mjs +9388 -0
  10. package/dist/bundle.node.mjs.map +1 -0
  11. package/dist/index.d.cts +1159 -0
  12. package/dist/websockets.mjs +7558 -0
  13. package/dist/websockets.mjs.map +1 -0
  14. package/dist/websockets.node.mjs +5189 -0
  15. package/dist/websockets.node.mjs.map +1 -0
  16. package/legacy/sync_protocol.d.ts +103 -0
  17. package/lib/client/BasePowerSyncDatabase.d.ts +147 -0
  18. package/lib/client/BasePowerSyncDatabase.js +622 -0
  19. package/lib/client/BasePowerSyncDatabase.js.map +1 -0
  20. package/lib/client/ConnectionManager.d.ts +116 -0
  21. package/lib/client/ConnectionManager.js +306 -0
  22. package/lib/client/ConnectionManager.js.map +1 -0
  23. package/lib/client/CustomQuery.d.ts +21 -0
  24. package/lib/client/CustomQuery.js +43 -0
  25. package/lib/client/CustomQuery.js.map +1 -0
  26. package/lib/client/sync/bucket/BucketStorageAdapter.d.ts +42 -0
  27. package/lib/client/sync/bucket/BucketStorageAdapter.js +23 -0
  28. package/lib/client/sync/bucket/BucketStorageAdapter.js.map +1 -0
  29. package/lib/client/sync/bucket/CrudEntry.d.ts +46 -0
  30. package/lib/client/sync/bucket/CrudEntry.js +60 -0
  31. package/lib/client/sync/bucket/CrudEntry.js.map +1 -0
  32. package/lib/client/sync/bucket/SqliteBucketStorage.d.ts +33 -0
  33. package/lib/client/sync/bucket/SqliteBucketStorage.js +166 -0
  34. package/lib/client/sync/bucket/SqliteBucketStorage.js.map +1 -0
  35. package/lib/client/sync/options.d.ts +9 -0
  36. package/lib/client/sync/options.js +16 -0
  37. package/lib/client/sync/options.js.map +1 -0
  38. package/lib/client/sync/stream/AbstractRemote.d.ts +125 -0
  39. package/lib/client/sync/stream/AbstractRemote.js +265 -0
  40. package/lib/client/sync/stream/AbstractRemote.js.map +1 -0
  41. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +138 -0
  42. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +611 -0
  43. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js.map +1 -0
  44. package/lib/client/sync/stream/WebSocketSupport.d.ts +26 -0
  45. package/lib/client/sync/stream/WebSocketSupport.js +198 -0
  46. package/lib/client/sync/stream/WebSocketSupport.js.map +1 -0
  47. package/lib/client/sync/stream/WebsocketClientTransport.d.ts +15 -0
  48. package/lib/client/sync/stream/WebsocketClientTransport.js +62 -0
  49. package/lib/client/sync/stream/WebsocketClientTransport.js.map +1 -0
  50. package/lib/client/sync/stream/core-instruction.d.ts +75 -0
  51. package/lib/client/sync/stream/core-instruction.js +4 -0
  52. package/lib/client/sync/stream/core-instruction.js.map +1 -0
  53. package/lib/client/triggers/MemoryTriggerClaimManager.d.ts +6 -0
  54. package/lib/client/triggers/MemoryTriggerClaimManager.js +21 -0
  55. package/lib/client/triggers/MemoryTriggerClaimManager.js.map +1 -0
  56. package/lib/client/triggers/TriggerManagerImpl.d.ts +68 -0
  57. package/lib/client/triggers/TriggerManagerImpl.js +415 -0
  58. package/lib/client/triggers/TriggerManagerImpl.js.map +1 -0
  59. package/lib/client/watched/AbstractQueryProcessor.d.ts +68 -0
  60. package/lib/client/watched/AbstractQueryProcessor.js +155 -0
  61. package/lib/client/watched/AbstractQueryProcessor.js.map +1 -0
  62. package/lib/client/watched/DifferentialQueryProcessor.d.ts +50 -0
  63. package/lib/client/watched/DifferentialQueryProcessor.js +174 -0
  64. package/lib/client/watched/DifferentialQueryProcessor.js.map +1 -0
  65. package/lib/client/watched/OnChangeQueryProcessor.d.ts +22 -0
  66. package/lib/client/watched/OnChangeQueryProcessor.js +80 -0
  67. package/lib/client/watched/OnChangeQueryProcessor.js.map +1 -0
  68. package/lib/client/watched/WatchedQuery.d.ts +9 -0
  69. package/lib/client/watched/WatchedQuery.js +12 -0
  70. package/lib/client/watched/WatchedQuery.js.map +1 -0
  71. package/lib/constants.d.ts +5 -0
  72. package/lib/constants.js +6 -0
  73. package/lib/constants.js.map +1 -0
  74. package/lib/db/ConnectionClosedError.d.ts +12 -0
  75. package/lib/db/ConnectionClosedError.js +23 -0
  76. package/lib/db/ConnectionClosedError.js.map +1 -0
  77. package/lib/db/crud/SyncProgress.d.ts +10 -0
  78. package/lib/db/crud/SyncProgress.js +33 -0
  79. package/lib/db/crud/SyncProgress.js.map +1 -0
  80. package/lib/db/crud/SyncStatus.d.ts +48 -0
  81. package/lib/db/crud/SyncStatus.js +178 -0
  82. package/lib/db/crud/SyncStatus.js.map +1 -0
  83. package/lib/db/openDatabase.d.ts +7 -0
  84. package/lib/db/openDatabase.js +22 -0
  85. package/lib/db/openDatabase.js.map +1 -0
  86. package/lib/index.d.ts +22 -0
  87. package/lib/index.js +22 -0
  88. package/lib/index.js.map +1 -0
  89. package/lib/utils/AbortOperation.d.ts +11 -0
  90. package/lib/utils/AbortOperation.js +21 -0
  91. package/lib/utils/AbortOperation.js.map +1 -0
  92. package/lib/utils/ControlledExecutor.d.ts +31 -0
  93. package/lib/utils/ControlledExecutor.js +54 -0
  94. package/lib/utils/ControlledExecutor.js.map +1 -0
  95. package/lib/utils/MetaBaseObserver.d.ts +11 -0
  96. package/lib/utils/MetaBaseObserver.js +51 -0
  97. package/lib/utils/MetaBaseObserver.js.map +1 -0
  98. package/lib/utils/async.d.ts +46 -0
  99. package/lib/utils/async.js +147 -0
  100. package/lib/utils/async.js.map +1 -0
  101. package/lib/utils/compatibility.d.ts +8 -0
  102. package/lib/utils/compatibility.js +9 -0
  103. package/lib/utils/compatibility.js.map +1 -0
  104. package/lib/utils/mutex.d.ts +42 -0
  105. package/lib/utils/mutex.js +150 -0
  106. package/lib/utils/mutex.js.map +1 -0
  107. package/lib/utils/parseQuery.d.ts +12 -0
  108. package/lib/utils/parseQuery.js +20 -0
  109. package/lib/utils/parseQuery.js.map +1 -0
  110. package/lib/utils/queue.d.ts +16 -0
  111. package/lib/utils/queue.js +42 -0
  112. package/lib/utils/queue.js.map +1 -0
  113. package/lib/utils/stream_transform.d.ts +41 -0
  114. package/lib/utils/stream_transform.js +211 -0
  115. package/lib/utils/stream_transform.js.map +1 -0
  116. package/lib/version.d.ts +1 -0
  117. package/lib/version.js +4 -0
  118. package/lib/version.js.map +1 -0
  119. package/package.json +65 -0
  120. package/src/client/BasePowerSyncDatabase.ts +853 -0
  121. package/src/client/ConnectionManager.ts +419 -0
  122. package/src/client/CustomQuery.ts +60 -0
  123. package/src/client/sync/bucket/BucketStorageAdapter.ts +51 -0
  124. package/src/client/sync/bucket/CrudEntry.ts +116 -0
  125. package/src/client/sync/bucket/SqliteBucketStorage.ts +213 -0
  126. package/src/client/sync/options.ts +24 -0
  127. package/src/client/sync/stream/AbstractRemote.ts +369 -0
  128. package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +795 -0
  129. package/src/client/sync/stream/WebSocketSupport.ts +259 -0
  130. package/src/client/sync/stream/WebsocketClientTransport.ts +82 -0
  131. package/src/client/sync/stream/core-instruction.ts +78 -0
  132. package/src/client/triggers/MemoryTriggerClaimManager.ts +25 -0
  133. package/src/client/triggers/TriggerManagerImpl.ts +538 -0
  134. package/src/client/watched/AbstractQueryProcessor.ts +231 -0
  135. package/src/client/watched/DifferentialQueryProcessor.ts +226 -0
  136. package/src/client/watched/OnChangeQueryProcessor.ts +108 -0
  137. package/src/client/watched/WatchedQuery.ts +14 -0
  138. package/src/constants.ts +6 -0
  139. package/src/db/ConnectionClosedError.ts +25 -0
  140. package/src/db/crud/SyncProgress.ts +39 -0
  141. package/src/db/crud/SyncStatus.ts +234 -0
  142. package/src/db/openDatabase.ts +23 -0
  143. package/src/index.ts +24 -0
  144. package/src/utils/AbortOperation.ts +19 -0
  145. package/src/utils/ControlledExecutor.ts +78 -0
  146. package/src/utils/MetaBaseObserver.ts +65 -0
  147. package/src/utils/async.ts +185 -0
  148. package/src/utils/compatibility.ts +9 -0
  149. package/src/utils/mutex.ts +186 -0
  150. package/src/utils/parseQuery.ts +31 -0
  151. package/src/utils/queue.ts +48 -0
  152. package/src/utils/stream_transform.ts +260 -0
  153. package/src/version.ts +3 -0
@@ -0,0 +1,116 @@
1
+ import { BaseObserver, PowerSyncLogger, SyncStatus, BaseListener, PowerSyncBackendConnector, SyncStream, SyncOptions, SyncStreamConnectionMethod } from '@powersync/common';
2
+ import { StreamingSyncImplementation, SubscribedStream } from './sync/stream/AbstractStreamingSyncImplementation.js';
3
+ import { ResolvedSyncOptions } from './sync/options.js';
4
+ /**
5
+ * @internal
6
+ */
7
+ export interface ConnectionManagerSyncImplementationResult {
8
+ sync: StreamingSyncImplementation;
9
+ /**
10
+ * Additional cleanup function which is called after the sync stream implementation
11
+ * is disposed.
12
+ */
13
+ onDispose: () => Promise<void> | void;
14
+ }
15
+ /**
16
+ * The subset of {@link AbstractStreamingSyncImplementationOptions} managed by the connection manager.
17
+ *
18
+ * @internal
19
+ */
20
+ export interface CreateSyncImplementationOptions {
21
+ subscriptions: SubscribedStream[];
22
+ serializedSchema: any;
23
+ }
24
+ /**
25
+ * @internal
26
+ */
27
+ export interface InternalSubscriptionAdapter {
28
+ firstStatusMatching(predicate: (status: SyncStatus) => any, abort?: AbortSignal): Promise<void>;
29
+ resolveOfflineSyncStatus(): Promise<void>;
30
+ rustSubscriptionsCommand(payload: any): Promise<void>;
31
+ }
32
+ /**
33
+ * @internal
34
+ */
35
+ export interface ConnectionManagerOptions {
36
+ createSyncImplementation(connector: PowerSyncBackendConnector, options: CreateSyncImplementationOptions): Promise<ConnectionManagerSyncImplementationResult>;
37
+ readonly defaultConnectionMethod: SyncStreamConnectionMethod;
38
+ logger: PowerSyncLogger;
39
+ }
40
+ type StoredConnectionOptions = {
41
+ connector: PowerSyncBackendConnector;
42
+ options: ResolvedSyncOptions;
43
+ schema: any;
44
+ };
45
+ /**
46
+ * @internal
47
+ */
48
+ export interface ConnectionManagerListener extends BaseListener {
49
+ syncStreamCreated: (sync: StreamingSyncImplementation) => void;
50
+ }
51
+ /**
52
+ * @internal
53
+ */
54
+ export declare class ConnectionManager extends BaseObserver<ConnectionManagerListener> {
55
+ protected options: ConnectionManagerOptions;
56
+ /**
57
+ * Tracks active connection attempts
58
+ */
59
+ protected connectingPromise: Promise<void> | null;
60
+ /**
61
+ * Tracks actively instantiating a streaming sync implementation.
62
+ */
63
+ protected syncStreamInitPromise: Promise<void> | null;
64
+ /**
65
+ * Active disconnect operation. Calling disconnect multiple times
66
+ * will resolve to the same operation.
67
+ */
68
+ protected disconnectingPromise: Promise<void> | null;
69
+ /**
70
+ * Tracks the last parameters supplied to `connect` calls.
71
+ * Calling `connect` multiple times in succession will result in:
72
+ * - 1 pending connection operation which will be aborted.
73
+ * - updating the last set of parameters while waiting for the pending
74
+ * attempt to be aborted
75
+ * - internally connecting with the last set of parameters
76
+ */
77
+ protected pendingConnectionOptions: StoredConnectionOptions | null;
78
+ private currentOptions;
79
+ syncStreamImplementation: StreamingSyncImplementation | null;
80
+ /**
81
+ * Additional cleanup function which is called after the sync stream implementation
82
+ * is disposed.
83
+ */
84
+ protected syncDisposer: (() => Promise<void> | void) | null;
85
+ /**
86
+ * Subscriptions managed in this connection manager.
87
+ *
88
+ * On the web, these local subscriptions are merged across tabs by a shared worker.
89
+ */
90
+ private locallyActiveSubscriptions;
91
+ constructor(options: ConnectionManagerOptions);
92
+ get connector(): PowerSyncBackendConnector | null;
93
+ get connectionOptions(): Required<SyncOptions> | null;
94
+ get logger(): PowerSyncLogger;
95
+ close(): Promise<void>;
96
+ connect(connector: PowerSyncBackendConnector, options: SyncOptions, serializedSchema: any): Promise<void>;
97
+ protected connectInternal(): Promise<void>;
98
+ /**
99
+ * Close the sync connection.
100
+ *
101
+ * Use {@link ConnectionManager.connect} to connect again.
102
+ */
103
+ disconnect(): Promise<void>;
104
+ protected disconnectInternal(): Promise<void>;
105
+ protected performDisconnect(): Promise<void>;
106
+ stream(adapter: InternalSubscriptionAdapter, name: string, parameters: Record<string, any> | null): SyncStream;
107
+ /**
108
+ * @internal exposed for testing
109
+ */
110
+ get activeStreams(): {
111
+ name: string;
112
+ params: Record<string, any> | null;
113
+ }[];
114
+ private subscriptionsMayHaveChanged;
115
+ }
116
+ export {};
@@ -0,0 +1,306 @@
1
+ import { BaseObserver, LogLevels } from '@powersync/common';
2
+ import { resolveSyncOptions } from './sync/options.js';
3
+ /**
4
+ * @internal
5
+ */
6
+ export class ConnectionManager extends BaseObserver {
7
+ options;
8
+ /**
9
+ * Tracks active connection attempts
10
+ */
11
+ connectingPromise;
12
+ /**
13
+ * Tracks actively instantiating a streaming sync implementation.
14
+ */
15
+ syncStreamInitPromise;
16
+ /**
17
+ * Active disconnect operation. Calling disconnect multiple times
18
+ * will resolve to the same operation.
19
+ */
20
+ disconnectingPromise;
21
+ /**
22
+ * Tracks the last parameters supplied to `connect` calls.
23
+ * Calling `connect` multiple times in succession will result in:
24
+ * - 1 pending connection operation which will be aborted.
25
+ * - updating the last set of parameters while waiting for the pending
26
+ * attempt to be aborted
27
+ * - internally connecting with the last set of parameters
28
+ */
29
+ pendingConnectionOptions;
30
+ currentOptions;
31
+ syncStreamImplementation;
32
+ /**
33
+ * Additional cleanup function which is called after the sync stream implementation
34
+ * is disposed.
35
+ */
36
+ syncDisposer;
37
+ /**
38
+ * Subscriptions managed in this connection manager.
39
+ *
40
+ * On the web, these local subscriptions are merged across tabs by a shared worker.
41
+ */
42
+ locallyActiveSubscriptions = new Map();
43
+ constructor(options) {
44
+ super();
45
+ this.options = options;
46
+ this.connectingPromise = null;
47
+ this.syncStreamInitPromise = null;
48
+ this.disconnectingPromise = null;
49
+ this.pendingConnectionOptions = null;
50
+ this.syncStreamImplementation = null;
51
+ this.currentOptions = null;
52
+ this.syncDisposer = null;
53
+ }
54
+ get connector() {
55
+ return this.pendingConnectionOptions?.connector ?? null;
56
+ }
57
+ get connectionOptions() {
58
+ return this.currentOptions ?? this.pendingConnectionOptions?.options ?? null;
59
+ }
60
+ get logger() {
61
+ return this.options.logger;
62
+ }
63
+ async close() {
64
+ await this.syncStreamImplementation?.dispose();
65
+ await this.syncDisposer?.();
66
+ }
67
+ async connect(connector, options, serializedSchema) {
68
+ // Keep track if there were pending operations before this call
69
+ const hadPendingOptions = !!this.pendingConnectionOptions;
70
+ // Update pending options to the latest values
71
+ this.pendingConnectionOptions = {
72
+ connector,
73
+ options: resolveSyncOptions(options, this.options.defaultConnectionMethod),
74
+ schema: serializedSchema
75
+ };
76
+ // Disconnecting here provides aborting in progress connection attempts.
77
+ // The connectInternal method will clear pending options once it starts connecting (with the options).
78
+ // We only need to trigger a disconnect here if we have already reached the point of connecting.
79
+ // If we do already have pending options, a disconnect has already been performed.
80
+ // The connectInternal method also does a sanity disconnect to prevent straggler connections.
81
+ // We should also disconnect if we have already completed a connection attempt.
82
+ if (!hadPendingOptions || this.syncStreamImplementation) {
83
+ await this.disconnectInternal();
84
+ }
85
+ // Triggers a connect which checks if pending options are available after the connect completes.
86
+ // The completion can be for a successful, unsuccessful or aborted connection attempt.
87
+ // If pending options are available another connection will be triggered.
88
+ const checkConnection = async () => {
89
+ if (this.pendingConnectionOptions) {
90
+ // Pending options have been placed while connecting.
91
+ // Need to reconnect.
92
+ this.connectingPromise = this.connectInternal()
93
+ .catch(() => { })
94
+ .finally(checkConnection);
95
+ return this.connectingPromise;
96
+ }
97
+ else {
98
+ // Clear the connecting promise, done.
99
+ this.connectingPromise = null;
100
+ return;
101
+ }
102
+ };
103
+ this.connectingPromise ??= this.connectInternal()
104
+ .catch(() => { })
105
+ .finally(checkConnection);
106
+ return this.connectingPromise;
107
+ }
108
+ async connectInternal() {
109
+ let appliedOptions = null;
110
+ // This method ensures a disconnect before any connection attempt
111
+ await this.disconnectInternal();
112
+ /**
113
+ * This portion creates a sync implementation which can be racy when disconnecting or
114
+ * if multiple tabs on web are in use.
115
+ * This is protected in an exclusive lock.
116
+ * The promise tracks the creation which is used to synchronize disconnect attempts.
117
+ */
118
+ this.syncStreamInitPromise = new Promise(async (resolve, reject) => {
119
+ try {
120
+ if (!this.pendingConnectionOptions) {
121
+ this.logger.log({
122
+ level: LogLevels.debug,
123
+ message: 'No pending connection options found, not creating sync stream implementation'
124
+ });
125
+ // A disconnect could have cleared this.
126
+ resolve();
127
+ return;
128
+ }
129
+ if (this.disconnectingPromise) {
130
+ resolve();
131
+ return;
132
+ }
133
+ const { connector, options, schema } = this.pendingConnectionOptions;
134
+ appliedOptions = options;
135
+ this.currentOptions = options;
136
+ this.pendingConnectionOptions = null;
137
+ const { sync, onDispose } = await this.options.createSyncImplementation(connector, {
138
+ subscriptions: this.activeStreams,
139
+ serializedSchema: schema
140
+ });
141
+ this.iterateListeners((l) => l.syncStreamCreated?.(sync));
142
+ this.syncStreamImplementation = sync;
143
+ this.syncDisposer = onDispose;
144
+ await this.syncStreamImplementation.waitForReady();
145
+ resolve();
146
+ }
147
+ catch (error) {
148
+ reject(error);
149
+ }
150
+ });
151
+ await this.syncStreamInitPromise;
152
+ this.syncStreamInitPromise = null;
153
+ if (!appliedOptions) {
154
+ // A disconnect could have cleared the options which did not create a syncStreamImplementation
155
+ return;
156
+ }
157
+ // It might be possible that a disconnect triggered between the last check
158
+ // and this point. Awaiting here allows the sync stream to be cleared if disconnected.
159
+ await this.disconnectingPromise;
160
+ this.logger.log({ level: LogLevels.debug, message: 'Attempting to connect to PowerSync instance' });
161
+ await this.syncStreamImplementation?.connect(appliedOptions);
162
+ }
163
+ /**
164
+ * Close the sync connection.
165
+ *
166
+ * Use {@link ConnectionManager.connect} to connect again.
167
+ */
168
+ async disconnect() {
169
+ // This will help abort pending connects
170
+ this.pendingConnectionOptions = null;
171
+ this.currentOptions = null;
172
+ await this.disconnectInternal();
173
+ }
174
+ async disconnectInternal() {
175
+ if (this.disconnectingPromise) {
176
+ // A disconnect is already in progress
177
+ return this.disconnectingPromise;
178
+ }
179
+ this.disconnectingPromise = this.performDisconnect();
180
+ await this.disconnectingPromise;
181
+ this.disconnectingPromise = null;
182
+ }
183
+ async performDisconnect() {
184
+ // Wait if a sync stream implementation is being created before closing it
185
+ // (syncStreamImplementation must be assigned before we can properly dispose it)
186
+ await this.syncStreamInitPromise;
187
+ // Keep reference to the sync stream implementation and disposer
188
+ // The class members will be cleared before we trigger the disconnect
189
+ // to prevent any further calls to the sync stream implementation.
190
+ const sync = this.syncStreamImplementation;
191
+ this.syncStreamImplementation = null;
192
+ const disposer = this.syncDisposer;
193
+ this.syncDisposer = null;
194
+ await sync?.disconnect();
195
+ await sync?.dispose();
196
+ await disposer?.();
197
+ }
198
+ stream(adapter, name, parameters) {
199
+ const desc = { name, parameters };
200
+ const waitForFirstSync = (abort) => {
201
+ return adapter.firstStatusMatching((s) => s.forStream(desc)?.subscription.hasSynced, abort);
202
+ };
203
+ return {
204
+ ...desc,
205
+ subscribe: async (options) => {
206
+ // NOTE: We also run this command if a subscription already exists, because this increases the expiry date
207
+ // (relevant if the app is closed before connecting again, where the last subscribe call determines the ttl).
208
+ await adapter.rustSubscriptionsCommand({
209
+ subscribe: {
210
+ stream: {
211
+ name,
212
+ params: parameters
213
+ },
214
+ ttl: options?.ttl,
215
+ priority: options?.priority
216
+ }
217
+ });
218
+ if (!this.syncStreamImplementation) {
219
+ // We're not connected. So, update the offline sync status to reflect the new subscription.
220
+ // (With an active iteration, the sync client would include it in its state).
221
+ await adapter.resolveOfflineSyncStatus();
222
+ }
223
+ const key = `${name}|${JSON.stringify(parameters)}`;
224
+ let subscription = this.locallyActiveSubscriptions.get(key);
225
+ if (subscription == null) {
226
+ const clearSubscription = () => {
227
+ this.locallyActiveSubscriptions.delete(key);
228
+ this.subscriptionsMayHaveChanged();
229
+ };
230
+ subscription = new ActiveSubscription(name, parameters, this.logger, waitForFirstSync, clearSubscription);
231
+ this.locallyActiveSubscriptions.set(key, subscription);
232
+ this.subscriptionsMayHaveChanged();
233
+ }
234
+ return new SyncStreamSubscriptionHandle(subscription);
235
+ },
236
+ unsubscribeAll: async () => {
237
+ await adapter.rustSubscriptionsCommand({ unsubscribe: { name, params: parameters } });
238
+ this.subscriptionsMayHaveChanged();
239
+ }
240
+ };
241
+ }
242
+ /**
243
+ * @internal exposed for testing
244
+ */
245
+ get activeStreams() {
246
+ return [...this.locallyActiveSubscriptions.values()].map((a) => ({ name: a.name, params: a.parameters }));
247
+ }
248
+ subscriptionsMayHaveChanged() {
249
+ this.syncStreamImplementation?.updateSubscriptions(this.activeStreams);
250
+ }
251
+ }
252
+ class ActiveSubscription {
253
+ name;
254
+ parameters;
255
+ logger;
256
+ waitForFirstSync;
257
+ clearSubscription;
258
+ refcount = 0;
259
+ constructor(name, parameters, logger, waitForFirstSync, clearSubscription) {
260
+ this.name = name;
261
+ this.parameters = parameters;
262
+ this.logger = logger;
263
+ this.waitForFirstSync = waitForFirstSync;
264
+ this.clearSubscription = clearSubscription;
265
+ }
266
+ decrementRefCount() {
267
+ this.refcount--;
268
+ if (this.refcount == 0) {
269
+ this.clearSubscription();
270
+ }
271
+ }
272
+ }
273
+ class SyncStreamSubscriptionHandle {
274
+ subscription;
275
+ active = true;
276
+ constructor(subscription) {
277
+ this.subscription = subscription;
278
+ subscription.refcount++;
279
+ _finalizer?.register(this, subscription, this);
280
+ }
281
+ get name() {
282
+ return this.subscription.name;
283
+ }
284
+ get parameters() {
285
+ return this.subscription.parameters;
286
+ }
287
+ waitForFirstSync(abort) {
288
+ return this.subscription.waitForFirstSync(abort);
289
+ }
290
+ unsubscribe() {
291
+ if (this.active) {
292
+ this.active = false;
293
+ _finalizer?.unregister(this);
294
+ this.subscription.decrementRefCount();
295
+ }
296
+ }
297
+ }
298
+ const _finalizer = 'FinalizationRegistry' in globalThis
299
+ ? new FinalizationRegistry((sub) => {
300
+ sub.logger.log({
301
+ level: LogLevels.warn,
302
+ message: `A subscription to ${sub.name} with params ${JSON.stringify(sub.parameters)} leaked! Please ensure calling unsubscribe() when you don't need a subscription anymore. For global subscriptions, consider storing them in global fields to avoid this warning.`
303
+ });
304
+ })
305
+ : null;
306
+ //# sourceMappingURL=ConnectionManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConnectionManager.js","sourceRoot":"","sources":["../../src/client/ConnectionManager.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,SAAS,EAWV,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAuB,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AA2D5E;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,YAAuC;IAyCtD;IAxCtB;;OAEG;IACO,iBAAiB,CAAuB;IAClD;;OAEG;IACO,qBAAqB,CAAuB;IACtD;;;OAGG;IACO,oBAAoB,CAAuB;IACrD;;;;;;;OAOG;IACO,wBAAwB,CAAiC;IAE3D,cAAc,CAA6B;IAEnD,wBAAwB,CAAqC;IAE7D;;;OAGG;IACO,YAAY,CAAsC;IAE5D;;;;OAIG;IACK,0BAA0B,GAAG,IAAI,GAAG,EAA8B,CAAC;IAE3E,YAAsB,OAAiC;QACrD,KAAK,EAAE,CAAC;QADY,YAAO,GAAP,OAAO,CAA0B;QAErD,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;QAC9B,IAAI,CAAC,qBAAqB,GAAG,IAAI,CAAC;QAClC,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC;QACjC,IAAI,CAAC,wBAAwB,GAAG,IAAI,CAAC;QACrC,IAAI,CAAC,wBAAwB,GAAG,IAAI,CAAC;QACrC,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;QAC3B,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;IAC3B,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,wBAAwB,EAAE,SAAS,I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AAC,YAAY,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACnD,CAAC;IAED,WAAW;QACT,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;YACpB,UAAU,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;YAC7B,IAAI,CAAC,YAAY,CAAC,iBAAiB,EAAE,CAAC;QACxC,CAAC;IACH,CAAC;CACF;AAED,MAAM,UAAU,GACd,sBAAsB,IAAI,UAAU;IAClC,CAAC,CAAC,IAAI,oBAAoB,CAAqB,CAAC,GAAG,EAAE,EAAE;QACnD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC;YACb,KAAK,EAAE,SAAS,CAAC,IAAI;YACrB,OAAO,EAAE,qBAAqB,GAAG,CAAC,IAAI,gBAAgB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,kLAAkL;SACvQ,CAAC,CAAC;IACL,CAAC,CAAC;IACJ,CAAC,CAAC,IAAI,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { Query, StandardWatchedQueryOptions, WatchCompatibleQuery, WatchedQueryOptions, DifferentialWatchedQueryOptions } from '@powersync/common';
2
+ import { BasePowerSyncDatabase } from './BasePowerSyncDatabase.js';
3
+ import { DifferentialQueryProcessor } from './watched/DifferentialQueryProcessor.js';
4
+ import { OnChangeQueryProcessor } from './watched/OnChangeQueryProcessor.js';
5
+ /**
6
+ * @internal
7
+ */
8
+ export interface CustomQueryOptions<RowType> {
9
+ db: BasePowerSyncDatabase;
10
+ query: WatchCompatibleQuery<RowType[]>;
11
+ }
12
+ /**
13
+ * @internal
14
+ */
15
+ export declare class CustomQuery<RowType> implements Query<RowType> {
16
+ protected options: CustomQueryOptions<RowType>;
17
+ constructor(options: CustomQueryOptions<RowType>);
18
+ protected resolveOptions(options: WatchedQueryOptions): WatchedQueryOptions;
19
+ watch(watchOptions: StandardWatchedQueryOptions<RowType>): OnChangeQueryProcessor<RowType[]>;
20
+ differentialWatch(differentialWatchOptions: DifferentialWatchedQueryOptions<RowType>): DifferentialQueryProcessor<RowType>;
21
+ }
@@ -0,0 +1,43 @@
1
+ import { FalsyComparator } from '@powersync/common';
2
+ import { DifferentialQueryProcessor } from './watched/DifferentialQueryProcessor.js';
3
+ import { OnChangeQueryProcessor } from './watched/OnChangeQueryProcessor.js';
4
+ import { DEFAULT_WATCH_QUERY_OPTIONS } from './watched/WatchedQuery.js';
5
+ /**
6
+ * @internal
7
+ */
8
+ export class CustomQuery {
9
+ options;
10
+ constructor(options) {
11
+ this.options = options;
12
+ }
13
+ resolveOptions(options) {
14
+ return {
15
+ reportFetching: options?.reportFetching ?? DEFAULT_WATCH_QUERY_OPTIONS.reportFetching,
16
+ throttleMs: options?.throttleMs ?? DEFAULT_WATCH_QUERY_OPTIONS.throttleMs,
17
+ triggerOnTables: options?.triggerOnTables
18
+ };
19
+ }
20
+ watch(watchOptions) {
21
+ return new OnChangeQueryProcessor({
22
+ db: this.options.db,
23
+ comparator: watchOptions?.comparator ?? FalsyComparator,
24
+ placeholderData: watchOptions?.placeholderData ?? [],
25
+ watchOptions: {
26
+ ...this.resolveOptions(watchOptions),
27
+ query: this.options.query
28
+ }
29
+ });
30
+ }
31
+ differentialWatch(differentialWatchOptions) {
32
+ return new DifferentialQueryProcessor({
33
+ db: this.options.db,
34
+ rowComparator: differentialWatchOptions?.rowComparator,
35
+ placeholderData: differentialWatchOptions?.placeholderData ?? [],
36
+ watchOptions: {
37
+ ...this.resolveOptions(differentialWatchOptions),
38
+ query: this.options.query
39
+ }
40
+ });
41
+ }
42
+ }
43
+ //# sourceMappingURL=CustomQuery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CustomQuery.js","sourceRoot":"","sources":["../../src/client/CustomQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,eAAe,EAIhB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAC;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2
+ export declare enum PSInternalTable {
3
+ DATA = "ps_data",
4
+ CRUD = "ps_crud",
5
+ BUCKETS = "ps_buckets",
6
+ OPLOG = "ps_oplog",
7
+ UNTYPED = "ps_untyped"
8
+ }
9
+ export declare enum PowerSyncControlCommand {
10
+ PROCESS_TEXT_LINE = "line_text",
11
+ PROCESS_BSON_LINE = "line_binary",
12
+ STOP = "stop",
13
+ START = "start",
14
+ NOTIFY_TOKEN_REFRESHED = "refreshed_token",
15
+ NOTIFY_CRUD_UPLOAD_COMPLETED = "completed_upload",
16
+ UPDATE_SUBSCRIPTIONS = "update_subscriptions",
17
+ /**
18
+ * An `established` or `end` event for response streams.
19
+ */
20
+ CONNECTION_STATE = "connection"
21
+ }
22
+ export interface BucketStorageListener extends BaseListener {
23
+ crudUpdate: () => void;
24
+ }
25
+ export interface BucketStorageAdapter extends BaseObserverInterface<BucketStorageListener>, Disposable {
26
+ init(): Promise<void>;
27
+ hasMigratedSubkeys(): Promise<boolean>;
28
+ migrateToFixedSubkeys(): Promise<void>;
29
+ nextCrudItem(): Promise<CrudEntry | undefined>;
30
+ hasCrud(): Promise<boolean>;
31
+ getCrudBatch(limit?: number): Promise<CrudBatch | null>;
32
+ updateLocalTarget(cb: () => Promise<string>): Promise<boolean>;
33
+ getMaxOpId(): string;
34
+ /**
35
+ * Get an unique client id.
36
+ */
37
+ getClientId(): Promise<string>;
38
+ /**
39
+ * Invokes the `powersync_control` function for the sync client.
40
+ */
41
+ control(op: PowerSyncControlCommand, payload: string | Uint8Array | null): Promise<string>;
42
+ }
@@ -0,0 +1,23 @@
1
+ export var PSInternalTable;
2
+ (function (PSInternalTable) {
3
+ PSInternalTable["DATA"] = "ps_data";
4
+ PSInternalTable["CRUD"] = "ps_crud";
5
+ PSInternalTable["BUCKETS"] = "ps_buckets";
6
+ PSInternalTable["OPLOG"] = "ps_oplog";
7
+ PSInternalTable["UNTYPED"] = "ps_untyped";
8
+ })(PSInternalTable || (PSInternalTable = {}));
9
+ export var PowerSyncControlCommand;
10
+ (function (PowerSyncControlCommand) {
11
+ PowerSyncControlCommand["PROCESS_TEXT_LINE"] = "line_text";
12
+ PowerSyncControlCommand["PROCESS_BSON_LINE"] = "line_binary";
13
+ PowerSyncControlCommand["STOP"] = "stop";
14
+ PowerSyncControlCommand["START"] = "start";
15
+ PowerSyncControlCommand["NOTIFY_TOKEN_REFRESHED"] = "refreshed_token";
16
+ PowerSyncControlCommand["NOTIFY_CRUD_UPLOAD_COMPLETED"] = "completed_upload";
17
+ PowerSyncControlCommand["UPDATE_SUBSCRIPTIONS"] = "update_subscriptions";
18
+ /**
19
+ * An `established` or `end` event for response streams.
20
+ */
21
+ PowerSyncControlCommand["CONNECTION_STATE"] = "connection";
22
+ })(PowerSyncControlCommand || (PowerSyncControlCommand = {}));
23
+ //# sourceMappingURL=BucketStorageAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BucketStorageAdapter.js","sourceRoot":"","sources":["../../../../src/client/sync/bucket/BucketStorageAdapter.ts"],"names":[],"mappings":"AAEA,MAAM,CAAN,IAAY,eAMX;AAND,WAAY,eAAe;IACzB,mCAAgB,CAAA;IAChB,mCAAgB,CAAA;IAChB,yCAAsB,CAAA;IACtB,qCAAkB,CAAA;IAClB,yCAAsB,CAAA;AACxB,CAAC,EANW,eAAe,KAAf,eAAe,QAM1B;AAED,MAAM,CAAN,IAAY,uBAYX;AAZD,WAAY,uBAAuB;IACjC,0DAA+B,CAAA;IAC/B,4DAAiC,CAAA;IACjC,wCAAa,CAAA;IACb,0CAAe,CAAA;IACf,qEAA0C,CAAA;IAC1C,4EAAiD,CAAA;IACjD,wEAA6C,CAAA;IAC7C;;OAEG;IACH,0DAA+B,CAAA;AACjC,CAAC,EAZW,uBAAuB,KAAvB,uBAAuB,QAYlC"}
@@ -0,0 +1,46 @@
1
+ import { CrudEntry, UpdateType } from '@powersync/common';
2
+ /**
3
+ * @internal
4
+ */
5
+ export type CrudEntryJSON = {
6
+ id: string;
7
+ data: string;
8
+ tx_id?: number;
9
+ };
10
+ /**
11
+ * The output JSON seems to be a third type of JSON, not the same as the input JSON.
12
+ */
13
+ type CrudEntryOutputJSON = {
14
+ op_id: number;
15
+ op: UpdateType;
16
+ type: string;
17
+ id: string;
18
+ tx_id?: number;
19
+ data?: Record<string, any>;
20
+ old?: Record<string, any>;
21
+ metadata?: string;
22
+ };
23
+ /**
24
+ * A single client-side change.
25
+ *
26
+ * @public
27
+ */
28
+ export declare class CrudEntryImpl implements CrudEntry {
29
+ clientId: number;
30
+ id: string;
31
+ op: UpdateType;
32
+ opData?: Record<string, any>;
33
+ previousValues?: Record<string, any>;
34
+ table: string;
35
+ transactionId?: number;
36
+ metadata?: string;
37
+ static fromRow(dbRow: CrudEntryJSON): CrudEntry;
38
+ constructor(clientId: number, op: UpdateType, table: string, id: string, transactionId?: number, opData?: Record<string, any>, previousValues?: Record<string, any>, metadata?: string);
39
+ toJSON(): CrudEntryOutputJSON;
40
+ equals(entry: CrudEntry): boolean;
41
+ /**
42
+ * Generates an array for use in deep comparison operations
43
+ */
44
+ toComparisonArray(): unknown[];
45
+ }
46
+ export {};