@powersync/common 0.0.0-dev-20251001121637 → 0.0.0-dev-20251021113138

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1748,7 +1748,6 @@ declare class Schema<S extends SchemaType = SchemaType> {
1748
1748
  }[];
1749
1749
  raw_tables: RawTable[];
1750
1750
  };
1751
- private convertToClassicTables;
1752
1751
  }
1753
1752
 
1754
1753
  interface PowerSyncBackendConnector {
@@ -1854,6 +1853,8 @@ declare class ConnectionManager extends BaseObserver<ConnectionManagerListener>
1854
1853
  */
1855
1854
  private locallyActiveSubscriptions;
1856
1855
  constructor(options: ConnectionManagerOptions);
1856
+ get connector(): PowerSyncBackendConnector | null;
1857
+ get connectionOptions(): InternalConnectionOptions | null;
1857
1858
  get logger(): ILogger;
1858
1859
  close(): Promise<void>;
1859
1860
  connect(connector: PowerSyncBackendConnector, options: InternalConnectionOptions): Promise<void>;
@@ -1867,7 +1868,13 @@ declare class ConnectionManager extends BaseObserver<ConnectionManagerListener>
1867
1868
  protected disconnectInternal(): Promise<void>;
1868
1869
  protected performDisconnect(): Promise<void>;
1869
1870
  stream(adapter: InternalSubscriptionAdapter, name: string, parameters: Record<string, any> | null): SyncStream;
1870
- private get activeStreams();
1871
+ /**
1872
+ * @internal exposed for testing
1873
+ */
1874
+ get activeStreams(): {
1875
+ name: string;
1876
+ params: Record<string, any> | null;
1877
+ }[];
1871
1878
  private subscriptionsMayHaveChanged;
1872
1879
  }
1873
1880
 
@@ -2893,6 +2900,18 @@ declare abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncD
2893
2900
  protected connectionManager: ConnectionManager;
2894
2901
  private subscriptions;
2895
2902
  get syncStreamImplementation(): StreamingSyncImplementation | null;
2903
+ /**
2904
+ * The connector used to connect to the PowerSync service.
2905
+ *
2906
+ * @returns The connector used to connect to the PowerSync service or null if `connect()` has not been called.
2907
+ */
2908
+ get connector(): PowerSyncBackendConnector | null;
2909
+ /**
2910
+ * The resolved connection options used to connect to the PowerSync service.
2911
+ *
2912
+ * @returns The resolved connection options used to connect to the PowerSync service or null if `connect()` has not been called.
2913
+ */
2914
+ get connectionOptions(): InternalConnectionOptions | null;
2896
2915
  protected _schema: Schema;
2897
2916
  private _database;
2898
2917
  protected runExclusiveMutex: Mutex;
@@ -2946,7 +2965,10 @@ declare abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncD
2946
2965
  signal?: AbortSignal;
2947
2966
  priority?: number;
2948
2967
  }): Promise<void>;
2949
- private waitForStatus;
2968
+ /**
2969
+ * Waits for the first sync status for which the `status` callback returns a truthy value.
2970
+ */
2971
+ waitForStatus(predicate: (status: SyncStatus) => any, signal?: AbortSignal): Promise<void>;
2950
2972
  /**
2951
2973
  * Allows for extended implementations to execute custom initialization
2952
2974
  * logic as part of the total init process
@@ -12,7 +12,7 @@ import { PowerSyncBackendConnector } from './connection/PowerSyncBackendConnecto
12
12
  import { BucketStorageAdapter } from './sync/bucket/BucketStorageAdapter.js';
13
13
  import { CrudBatch } from './sync/bucket/CrudBatch.js';
14
14
  import { CrudTransaction } from './sync/bucket/CrudTransaction.js';
15
- import { StreamingSyncImplementation, StreamingSyncImplementationListener, type AdditionalConnectionOptions, type PowerSyncConnectionOptions, type RequiredAdditionalConnectionOptions } from './sync/stream/AbstractStreamingSyncImplementation.js';
15
+ import { InternalConnectionOptions, StreamingSyncImplementation, StreamingSyncImplementationListener, type AdditionalConnectionOptions, type PowerSyncConnectionOptions, type RequiredAdditionalConnectionOptions } from './sync/stream/AbstractStreamingSyncImplementation.js';
16
16
  import { TriggerManager } from './triggers/TriggerManager.js';
17
17
  import { WatchCompatibleQuery } from './watched/WatchedQuery.js';
18
18
  import { WatchedQueryComparator } from './watched/processors/comparators.js';
@@ -132,6 +132,18 @@ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<Pow
132
132
  protected connectionManager: ConnectionManager;
133
133
  private subscriptions;
134
134
  get syncStreamImplementation(): StreamingSyncImplementation | null;
135
+ /**
136
+ * The connector used to connect to the PowerSync service.
137
+ *
138
+ * @returns The connector used to connect to the PowerSync service or null if `connect()` has not been called.
139
+ */
140
+ get connector(): PowerSyncBackendConnector | null;
141
+ /**
142
+ * The resolved connection options used to connect to the PowerSync service.
143
+ *
144
+ * @returns The resolved connection options used to connect to the PowerSync service or null if `connect()` has not been called.
145
+ */
146
+ get connectionOptions(): InternalConnectionOptions | null;
135
147
  protected _schema: Schema;
136
148
  private _database;
137
149
  protected runExclusiveMutex: Mutex;
@@ -185,7 +197,10 @@ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<Pow
185
197
  signal?: AbortSignal;
186
198
  priority?: number;
187
199
  }): Promise<void>;
188
- private waitForStatus;
200
+ /**
201
+ * Waits for the first sync status for which the `status` callback returns a truthy value.
202
+ */
203
+ waitForStatus(predicate: (status: SyncStatus) => any, signal?: AbortSignal): Promise<void>;
189
204
  /**
190
205
  * Allows for extended implementations to execute custom initialization
191
206
  * logic as part of the total init process
@@ -63,6 +63,22 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
63
63
  get syncStreamImplementation() {
64
64
  return this.connectionManager.syncStreamImplementation;
65
65
  }
66
+ /**
67
+ * The connector used to connect to the PowerSync service.
68
+ *
69
+ * @returns The connector used to connect to the PowerSync service or null if `connect()` has not been called.
70
+ */
71
+ get connector() {
72
+ return this.connectionManager.connector;
73
+ }
74
+ /**
75
+ * The resolved connection options used to connect to the PowerSync service.
76
+ *
77
+ * @returns The resolved connection options used to connect to the PowerSync service or null if `connect()` has not been called.
78
+ */
79
+ get connectionOptions() {
80
+ return this.connectionManager.connectionOptions;
81
+ }
66
82
  _schema;
67
83
  _database;
68
84
  runExclusiveMutex;
@@ -188,6 +204,9 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
188
204
  : (status) => status.statusForPriority(priority).hasSynced;
189
205
  return this.waitForStatus(statusMatches, signal);
190
206
  }
207
+ /**
208
+ * Waits for the first sync status for which the `status` callback returns a truthy value.
209
+ */
191
210
  async waitForStatus(predicate, signal) {
192
211
  if (predicate(this.currentStatus)) {
193
212
  return;
@@ -196,15 +215,20 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
196
215
  const dispose = this.registerListener({
197
216
  statusChanged: (status) => {
198
217
  if (predicate(status)) {
199
- dispose();
200
- resolve();
218
+ abort();
201
219
  }
202
220
  }
203
221
  });
204
- signal?.addEventListener('abort', () => {
222
+ function abort() {
205
223
  dispose();
206
224
  resolve();
207
- });
225
+ }
226
+ if (signal?.aborted) {
227
+ abort();
228
+ }
229
+ else {
230
+ signal?.addEventListener('abort', abort);
231
+ }
208
232
  });
209
233
  }
210
234
  /**
@@ -85,6 +85,8 @@ export declare class ConnectionManager extends BaseObserver<ConnectionManagerLis
85
85
  */
86
86
  private locallyActiveSubscriptions;
87
87
  constructor(options: ConnectionManagerOptions);
88
+ get connector(): PowerSyncBackendConnector | null;
89
+ get connectionOptions(): InternalConnectionOptions | null;
88
90
  get logger(): ILogger;
89
91
  close(): Promise<void>;
90
92
  connect(connector: PowerSyncBackendConnector, options: InternalConnectionOptions): Promise<void>;
@@ -98,7 +100,13 @@ export declare class ConnectionManager extends BaseObserver<ConnectionManagerLis
98
100
  protected disconnectInternal(): Promise<void>;
99
101
  protected performDisconnect(): Promise<void>;
100
102
  stream(adapter: InternalSubscriptionAdapter, name: string, parameters: Record<string, any> | null): SyncStream;
101
- private get activeStreams();
103
+ /**
104
+ * @internal exposed for testing
105
+ */
106
+ get activeStreams(): {
107
+ name: string;
108
+ params: Record<string, any> | null;
109
+ }[];
102
110
  private subscriptionsMayHaveChanged;
103
111
  }
104
112
  export {};
@@ -48,6 +48,12 @@ export class ConnectionManager extends BaseObserver {
48
48
  this.syncStreamImplementation = null;
49
49
  this.syncDisposer = null;
50
50
  }
51
+ get connector() {
52
+ return this.pendingConnectionOptions?.connector ?? null;
53
+ }
54
+ get connectionOptions() {
55
+ return this.pendingConnectionOptions?.options ?? null;
56
+ }
51
57
  get logger() {
52
58
  return this.options.logger;
53
59
  }
@@ -224,13 +230,14 @@ export class ConnectionManager extends BaseObserver {
224
230
  }
225
231
  };
226
232
  }
233
+ /**
234
+ * @internal exposed for testing
235
+ */
227
236
  get activeStreams() {
228
237
  return [...this.locallyActiveSubscriptions.values()].map((a) => ({ name: a.name, params: a.parameters }));
229
238
  }
230
239
  subscriptionsMayHaveChanged() {
231
- if (this.syncStreamImplementation) {
232
- this.syncStreamImplementation.updateSubscriptions(this.activeStreams);
233
- }
240
+ this.syncStreamImplementation?.updateSubscriptions(this.activeStreams);
234
241
  }
235
242
  }
236
243
  class ActiveSubscription {
@@ -50,6 +50,5 @@ export declare class Schema<S extends SchemaType = SchemaType> {
50
50
  }[];
51
51
  raw_tables: RawTable[];
52
52
  };
53
- private convertToClassicTables;
54
53
  }
55
54
  export {};
@@ -25,8 +25,9 @@ export class Schema {
25
25
  this.tables = tables;
26
26
  }
27
27
  else {
28
- this.props = tables;
29
- this.tables = this.convertToClassicTables(this.props);
28
+ // Update the table entries with the provided table name key
29
+ this.props = Object.fromEntries(Object.entries(tables).map(([tableName, table]) => [tableName, table.copyWithName(tableName)]));
30
+ this.tables = Object.values(this.props);
30
31
  }
31
32
  this.rawTables = [];
32
33
  }
@@ -52,14 +53,8 @@ export class Schema {
52
53
  }
53
54
  toJSON() {
54
55
  return {
55
- // This is required because "name" field is not present in TableV2
56
56
  tables: this.tables.map((t) => t.toJSON()),
57
57
  raw_tables: this.rawTables
58
58
  };
59
59
  }
60
- convertToClassicTables(props) {
61
- return Object.entries(props).map(([name, table]) => {
62
- return table.copyWithName(name);
63
- });
64
- }
65
60
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powersync/common",
3
- "version": "0.0.0-dev-20251001121637",
3
+ "version": "0.0.0-dev-20251021113138",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"