@powersync/web 0.0.0-dev-20240723112746 → 0.0.0-dev-20240726145924

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.
@@ -16,14 +16,11 @@ export const DEFAULT_WEB_SQL_FLAGS = {
16
16
  useWebWorker: true
17
17
  };
18
18
  export function resolveWebSQLFlags(flags) {
19
- const resolvedFlags = {
20
- ...DEFAULT_WEB_SQL_FLAGS,
21
- ...(flags ?? {})
22
- };
23
- if (typeof flags?.enableMultiTabs != 'undefined') {
19
+ const resolvedFlags = Object.assign(Object.assign({}, DEFAULT_WEB_SQL_FLAGS), (flags !== null && flags !== void 0 ? flags : {}));
20
+ if (typeof (flags === null || flags === void 0 ? void 0 : flags.enableMultiTabs) != 'undefined') {
24
21
  resolvedFlags.enableMultiTabs = flags.enableMultiTabs;
25
22
  }
26
- if (flags?.useWebWorker === false) {
23
+ if ((flags === null || flags === void 0 ? void 0 : flags.useWebWorker) === false) {
27
24
  resolvedFlags.enableMultiTabs = false;
28
25
  }
29
26
  return resolvedFlags;
@@ -1,8 +1,6 @@
1
1
  import { AbstractStreamingSyncImplementation, LockType } from '@powersync/common';
2
2
  import { Mutex } from 'async-mutex';
3
3
  export class SSRStreamingSyncImplementation extends AbstractStreamingSyncImplementation {
4
- syncMutex;
5
- crudMutex;
6
4
  constructor(options) {
7
5
  super(options);
8
6
  this.syncMutex = new Mutex();
@@ -1,3 +1,12 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  import * as Comlink from 'comlink';
2
11
  import { WebStreamingSyncImplementation } from './WebStreamingSyncImplementation';
3
12
  import { SharedSyncClientEvent } from '../../worker/sync/SharedSyncImplementation';
@@ -8,70 +17,76 @@ import { openWorkerDatabasePort } from '../../worker/db/open-worker-database';
8
17
  * via this client provider.
9
18
  */
10
19
  class SharedSyncClientProvider extends AbstractSharedSyncClientProvider {
11
- options;
12
- statusChanged;
13
20
  constructor(options, statusChanged) {
14
21
  super();
15
22
  this.options = options;
16
23
  this.statusChanged = statusChanged;
17
24
  }
18
- async fetchCredentials() {
19
- const credentials = await this.options.remote.getCredentials();
20
- if (credentials == null) {
21
- return null;
22
- }
23
- /**
24
- * The credentials need to be serializable.
25
- * Users might extend [PowerSyncCredentials] to contain
26
- * items which are not serializable.
27
- * This returns only the essential fields.
28
- */
29
- return {
30
- endpoint: credentials.endpoint,
31
- token: credentials.token,
32
- expiresAt: credentials.expiresAt
33
- };
25
+ fetchCredentials() {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const credentials = yield this.options.remote.getCredentials();
28
+ if (credentials == null) {
29
+ return null;
30
+ }
31
+ /**
32
+ * The credentials need to be serializable.
33
+ * Users might extend [PowerSyncCredentials] to contain
34
+ * items which are not serializable.
35
+ * This returns only the essential fields.
36
+ */
37
+ return {
38
+ endpoint: credentials.endpoint,
39
+ token: credentials.token,
40
+ expiresAt: credentials.expiresAt
41
+ };
42
+ });
34
43
  }
35
- async uploadCrud() {
36
- /**
37
- * Don't return anything here, just incase something which is not
38
- * serializable is returned from the `uploadCrud` function.
39
- */
40
- await this.options.uploadCrud();
44
+ uploadCrud() {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ /**
47
+ * Don't return anything here, just incase something which is not
48
+ * serializable is returned from the `uploadCrud` function.
49
+ */
50
+ yield this.options.uploadCrud();
51
+ });
41
52
  }
42
53
  get logger() {
43
54
  return this.options.logger;
44
55
  }
45
56
  trace(...x) {
46
- this.logger?.trace(...x);
57
+ var _a;
58
+ (_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace(...x);
47
59
  }
48
60
  debug(...x) {
49
- this.logger?.debug(...x);
61
+ var _a;
62
+ (_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug(...x);
50
63
  }
51
64
  info(...x) {
52
- this.logger?.info(...x);
65
+ var _a;
66
+ (_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(...x);
53
67
  }
54
68
  log(...x) {
55
- this.logger?.log(...x);
69
+ var _a;
70
+ (_a = this.logger) === null || _a === void 0 ? void 0 : _a.log(...x);
56
71
  }
57
72
  warn(...x) {
58
- this.logger?.warn(...x);
73
+ var _a;
74
+ (_a = this.logger) === null || _a === void 0 ? void 0 : _a.warn(...x);
59
75
  }
60
76
  error(...x) {
61
- this.logger?.error(...x);
77
+ var _a;
78
+ (_a = this.logger) === null || _a === void 0 ? void 0 : _a.error(...x);
62
79
  }
63
80
  time(label) {
64
- this.logger?.time(label);
81
+ var _a;
82
+ (_a = this.logger) === null || _a === void 0 ? void 0 : _a.time(label);
65
83
  }
66
84
  timeEnd(label) {
67
- this.logger?.timeEnd(label);
85
+ var _a;
86
+ (_a = this.logger) === null || _a === void 0 ? void 0 : _a.timeEnd(label);
68
87
  }
69
88
  }
70
89
  export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplementation {
71
- syncManager;
72
- clientProvider;
73
- messagePort;
74
- isInitialized;
75
90
  constructor(options) {
76
91
  super(options);
77
92
  /**
@@ -120,39 +135,53 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
120
135
  * Starts the sync process, this effectively acts as a call to
121
136
  * `connect` if not yet connected.
122
137
  */
123
- async connect(options) {
124
- await this.waitForReady();
125
- return this.syncManager.connect(options);
126
- }
127
- async disconnect() {
128
- await this.waitForReady();
129
- return this.syncManager.disconnect();
130
- }
131
- async getWriteCheckpoint() {
132
- await this.waitForReady();
133
- return this.syncManager.getWriteCheckpoint();
134
- }
135
- async hasCompletedSync() {
136
- return this.syncManager.hasCompletedSync();
137
- }
138
- async dispose() {
139
- await this.waitForReady();
140
- // Signal the shared worker that this client is closing its connection to the worker
141
- const closeMessagePayload = {
142
- event: SharedSyncClientEvent.CLOSE_CLIENT,
143
- data: {}
144
- };
145
- this.messagePort.postMessage(closeMessagePayload);
146
- // Release the proxy
147
- this.syncManager[Comlink.releaseProxy]();
148
- }
149
- async waitForReady() {
150
- return this.isInitialized;
138
+ connect(options) {
139
+ return __awaiter(this, void 0, void 0, function* () {
140
+ yield this.waitForReady();
141
+ return this.syncManager.connect(options);
142
+ });
143
+ }
144
+ disconnect() {
145
+ return __awaiter(this, void 0, void 0, function* () {
146
+ yield this.waitForReady();
147
+ return this.syncManager.disconnect();
148
+ });
149
+ }
150
+ getWriteCheckpoint() {
151
+ return __awaiter(this, void 0, void 0, function* () {
152
+ yield this.waitForReady();
153
+ return this.syncManager.getWriteCheckpoint();
154
+ });
155
+ }
156
+ hasCompletedSync() {
157
+ return __awaiter(this, void 0, void 0, function* () {
158
+ return this.syncManager.hasCompletedSync();
159
+ });
160
+ }
161
+ dispose() {
162
+ return __awaiter(this, void 0, void 0, function* () {
163
+ yield this.waitForReady();
164
+ // Signal the shared worker that this client is closing its connection to the worker
165
+ const closeMessagePayload = {
166
+ event: SharedSyncClientEvent.CLOSE_CLIENT,
167
+ data: {}
168
+ };
169
+ this.messagePort.postMessage(closeMessagePayload);
170
+ // Release the proxy
171
+ this.syncManager[Comlink.releaseProxy]();
172
+ });
173
+ }
174
+ waitForReady() {
175
+ return __awaiter(this, void 0, void 0, function* () {
176
+ return this.isInitialized;
177
+ });
151
178
  }
152
179
  /**
153
180
  * Used in tests to force a connection states
154
181
  */
155
- async _testUpdateStatus(status) {
156
- return this.syncManager['_testUpdateAllStatuses'](status.toJSON());
182
+ _testUpdateStatus(status) {
183
+ return __awaiter(this, void 0, void 0, function* () {
184
+ return this.syncManager['_testUpdateAllStatuses'](status.toJSON());
185
+ });
157
186
  }
158
187
  }
@@ -1,9 +1,5 @@
1
- import { type ILogger } from 'js-logger';
2
- import { AbstractRemote, AbstractRemoteOptions, BSONImplementation, RemoteConnector } from '@powersync/common';
1
+ import { AbstractRemote, BSONImplementation } from '@powersync/common';
3
2
  export declare class WebRemote extends AbstractRemote {
4
- protected connector: RemoteConnector;
5
- protected logger: ILogger;
6
3
  private _bson;
7
- constructor(connector: RemoteConnector, logger?: ILogger, options?: Partial<AbstractRemoteOptions>);
8
4
  getBSON(): Promise<BSONImplementation>;
9
5
  }
@@ -1,33 +1,25 @@
1
- import { AbstractRemote, DEFAULT_REMOTE_LOGGER, FetchImplementationProvider } from '@powersync/common';
2
- /*
3
- * Depends on browser's implementation of global fetch.
4
- */
5
- class WebFetchProvider extends FetchImplementationProvider {
6
- getFetch() {
7
- return fetch.bind(globalThis);
8
- }
9
- }
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { AbstractRemote } from '@powersync/common';
10
11
  export class WebRemote extends AbstractRemote {
11
- connector;
12
- logger;
13
- _bson;
14
- constructor(connector, logger = DEFAULT_REMOTE_LOGGER, options) {
15
- super(connector, logger, {
16
- ...(options ?? {}),
17
- fetchImplementation: options?.fetchImplementation ?? new WebFetchProvider()
18
- });
19
- this.connector = connector;
20
- this.logger = logger;
21
- }
22
- async getBSON() {
23
- if (this._bson) {
12
+ getBSON() {
13
+ return __awaiter(this, void 0, void 0, function* () {
14
+ if (this._bson) {
15
+ return this._bson;
16
+ }
17
+ /**
18
+ * Dynamic import to be used only when needed.
19
+ */
20
+ const { BSON } = yield import('bson');
21
+ this._bson = BSON;
24
22
  return this._bson;
25
- }
26
- /**
27
- * Dynamic import to be used only when needed.
28
- */
29
- const { BSON } = await import('bson');
30
- this._bson = BSON;
31
- return this._bson;
23
+ });
32
24
  }
33
25
  }