@powersync/node 0.0.0-dev-20260128170935 → 0.0.0-dev-20260202162549

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 (67) hide show
  1. package/package.json +4 -4
  2. package/dist/DefaultWorker.cjs +0 -232
  3. package/dist/DefaultWorker.cjs.map +0 -1
  4. package/dist/bundle.cjs +0 -647
  5. package/dist/bundle.cjs.map +0 -1
  6. package/dist/bundle.d.cts +0 -127
  7. package/dist/worker.cjs +0 -233
  8. package/dist/worker.cjs.map +0 -1
  9. package/dist/worker.d.cts +0 -20
  10. package/lib/attachments/NodeFileSystemAdapter.d.ts +0 -30
  11. package/lib/attachments/NodeFileSystemAdapter.js +0 -77
  12. package/lib/attachments/NodeFileSystemAdapter.js.map +0 -1
  13. package/lib/db/AsyncDatabase.d.ts +0 -22
  14. package/lib/db/AsyncDatabase.js +0 -2
  15. package/lib/db/AsyncDatabase.js.map +0 -1
  16. package/lib/db/BetterSqliteWorker.d.ts +0 -26
  17. package/lib/db/BetterSqliteWorker.js +0 -59
  18. package/lib/db/BetterSqliteWorker.js.map +0 -1
  19. package/lib/db/DefaultWorker.d.ts +0 -1
  20. package/lib/db/DefaultWorker.js +0 -3
  21. package/lib/db/DefaultWorker.js.map +0 -1
  22. package/lib/db/NodeSqliteWorker.d.ts +0 -21
  23. package/lib/db/NodeSqliteWorker.js +0 -47
  24. package/lib/db/NodeSqliteWorker.js.map +0 -1
  25. package/lib/db/PowerSyncDatabase.d.ts +0 -39
  26. package/lib/db/PowerSyncDatabase.js +0 -57
  27. package/lib/db/PowerSyncDatabase.js.map +0 -1
  28. package/lib/db/RemoteConnection.d.ts +0 -29
  29. package/lib/db/RemoteConnection.js +0 -106
  30. package/lib/db/RemoteConnection.js.map +0 -1
  31. package/lib/db/SqliteWorker.d.ts +0 -17
  32. package/lib/db/SqliteWorker.js +0 -105
  33. package/lib/db/SqliteWorker.js.map +0 -1
  34. package/lib/db/WorkerConnectionPool.d.ts +0 -32
  35. package/lib/db/WorkerConnectionPool.js +0 -266
  36. package/lib/db/WorkerConnectionPool.js.map +0 -1
  37. package/lib/db/options.d.ts +0 -44
  38. package/lib/db/options.js +0 -2
  39. package/lib/db/options.js.map +0 -1
  40. package/lib/index.d.ts +0 -3
  41. package/lib/index.js +0 -5
  42. package/lib/index.js.map +0 -1
  43. package/lib/libpowersync_aarch64.linux.so +0 -0
  44. package/lib/libpowersync_aarch64.macos.dylib +0 -0
  45. package/lib/libpowersync_armv7.linux.so +0 -0
  46. package/lib/libpowersync_riscv64gc.linux.so +0 -0
  47. package/lib/libpowersync_x64.linux.so +0 -0
  48. package/lib/libpowersync_x64.macos.dylib +0 -0
  49. package/lib/libpowersync_x86.linux.so +0 -0
  50. package/lib/powersync_aarch64.dll +0 -0
  51. package/lib/powersync_x64.dll +0 -0
  52. package/lib/powersync_x86.dll +0 -0
  53. package/lib/sync/stream/NodeRemote.d.ts +0 -23
  54. package/lib/sync/stream/NodeRemote.js +0 -79
  55. package/lib/sync/stream/NodeRemote.js.map +0 -1
  56. package/lib/sync/stream/NodeStreamingSyncImplementation.d.ts +0 -11
  57. package/lib/sync/stream/NodeStreamingSyncImplementation.js +0 -44
  58. package/lib/sync/stream/NodeStreamingSyncImplementation.js.map +0 -1
  59. package/lib/utils/modules.d.ts +0 -2
  60. package/lib/utils/modules.js +0 -6
  61. package/lib/utils/modules.js.map +0 -1
  62. package/lib/utils/modules_commonjs.d.ts +0 -2
  63. package/lib/utils/modules_commonjs.js +0 -7
  64. package/lib/utils/modules_commonjs.js.map +0 -1
  65. package/lib/worker.d.ts +0 -1
  66. package/lib/worker.js +0 -2
  67. package/lib/worker.js.map +0 -1
@@ -1,266 +0,0 @@
1
- import * as Comlink from 'comlink';
2
- import fs from 'node:fs/promises';
3
- import * as path from 'node:path';
4
- import { Worker } from 'node:worker_threads';
5
- import { BaseObserver } from '@powersync/common';
6
- import { AsyncResource } from 'node:async_hooks';
7
- import { isBundledToCommonJs } from '../utils/modules.js';
8
- import { RemoteConnection } from './RemoteConnection.js';
9
- const READ_CONNECTIONS = 5;
10
- const defaultDatabaseImplementation = {
11
- type: 'better-sqlite3'
12
- };
13
- /**
14
- * Adapter for better-sqlite3
15
- */
16
- export class WorkerConnectionPool extends BaseObserver {
17
- options;
18
- name;
19
- readConnections;
20
- writeConnection;
21
- readQueue = [];
22
- writeQueue = [];
23
- constructor(options) {
24
- super();
25
- if (options.readWorkerCount != null && options.readWorkerCount < 1) {
26
- throw `Needs at least one worker for reads, got ${options.readWorkerCount}`;
27
- }
28
- this.options = options;
29
- this.name = options.dbFilename;
30
- }
31
- async initialize() {
32
- let dbFilePath = this.options.dbFilename;
33
- if (this.options.dbLocation !== undefined) {
34
- // Make sure the dbLocation exists, we get a TypeError from better-sqlite3 otherwise.
35
- let directoryExists = false;
36
- try {
37
- const stat = await fs.stat(this.options.dbLocation);
38
- directoryExists = stat.isDirectory();
39
- }
40
- catch (_) {
41
- // If we can't even stat, the directory won't be accessible to SQLite either.
42
- }
43
- if (!directoryExists) {
44
- throw new Error(`The dbLocation directory at "${this.options.dbLocation}" does not exist. Please create it before opening the PowerSync database!`);
45
- }
46
- dbFilePath = path.join(this.options.dbLocation, dbFilePath);
47
- }
48
- const openWorker = async (isWriter) => {
49
- const isCommonJsModule = isBundledToCommonJs;
50
- let worker;
51
- const workerName = isWriter ? `write ${dbFilePath}` : `read ${dbFilePath}`;
52
- const workerFactory = this.options.openWorker ?? ((...args) => new Worker(...args));
53
- if (isCommonJsModule) {
54
- worker = workerFactory(path.resolve(__dirname, 'DefaultWorker.cjs'), { name: workerName });
55
- }
56
- else {
57
- worker = workerFactory(new URL('./DefaultWorker.js', import.meta.url), { name: workerName });
58
- }
59
- const listeners = new WeakMap();
60
- const comlink = Comlink.wrap({
61
- postMessage: worker.postMessage.bind(worker),
62
- addEventListener: (type, listener) => {
63
- let resolved = 'handleEvent' in listener ? listener.handleEvent.bind(listener) : listener;
64
- // Comlink wants message events, but the message event on workers in Node returns the data only.
65
- if (type === 'message') {
66
- const original = resolved;
67
- resolved = (data) => {
68
- original({ data });
69
- };
70
- }
71
- listeners.set(listener, resolved);
72
- worker.addListener(type, resolved);
73
- },
74
- removeEventListener: (type, listener) => {
75
- const resolved = listeners.get(listener);
76
- if (!resolved) {
77
- return;
78
- }
79
- worker.removeListener(type, resolved);
80
- }
81
- });
82
- worker.once('error', (e) => {
83
- console.error('Unexpected PowerSync database worker error', e);
84
- });
85
- const database = (await comlink.open({
86
- path: dbFilePath,
87
- isWriter,
88
- implementation: this.options.implementation ?? defaultDatabaseImplementation
89
- }));
90
- if (isWriter) {
91
- await database.execute("SELECT powersync_update_hooks('install');", []);
92
- }
93
- const connection = new RemoteConnection(worker, comlink, database);
94
- if (this.options.initializeConnection) {
95
- await this.options.initializeConnection(connection, isWriter);
96
- }
97
- if (!isWriter) {
98
- await connection.execute('pragma query_only = true');
99
- }
100
- else {
101
- // We only need to enable this on the writer connection.
102
- // We can get `database is locked` errors if we enable this on concurrently opening read connections.
103
- await connection.execute('pragma journal_mode = WAL');
104
- }
105
- return connection;
106
- };
107
- // Open the writer first to avoid multiple threads enabling WAL concurrently (causing "database is locked" errors).
108
- this.writeConnection = await openWorker(true);
109
- const createWorkers = [];
110
- const amountOfReaders = this.options.readWorkerCount ?? READ_CONNECTIONS;
111
- for (let i = 0; i < amountOfReaders; i++) {
112
- createWorkers.push(openWorker(false));
113
- }
114
- this.readConnections = await Promise.all(createWorkers);
115
- }
116
- async close() {
117
- await this.writeConnection.close();
118
- for (const connection of this.readConnections) {
119
- await connection.close();
120
- }
121
- }
122
- readLock(fn, _options) {
123
- let resolveConnectionPromise;
124
- const connectionPromise = new Promise((resolve, _reject) => {
125
- resolveConnectionPromise = AsyncResource.bind(resolve);
126
- });
127
- const connection = this.readConnections.find((connection) => !connection.isBusy);
128
- if (connection) {
129
- connection.isBusy = true;
130
- resolveConnectionPromise(connection);
131
- }
132
- else {
133
- this.readQueue.push(resolveConnectionPromise);
134
- }
135
- return (async () => {
136
- const connection = await connectionPromise;
137
- try {
138
- return await fn(connection);
139
- }
140
- finally {
141
- const next = this.readQueue.shift();
142
- if (next) {
143
- next(connection);
144
- }
145
- else {
146
- connection.isBusy = false;
147
- }
148
- }
149
- })();
150
- }
151
- writeLock(fn, _options) {
152
- let resolveLockPromise;
153
- const lockPromise = new Promise((resolve, _reject) => {
154
- resolveLockPromise = AsyncResource.bind(resolve);
155
- });
156
- if (!this.writeConnection.isBusy) {
157
- this.writeConnection.isBusy = true;
158
- resolveLockPromise();
159
- }
160
- else {
161
- this.writeQueue.push(resolveLockPromise);
162
- }
163
- return (async () => {
164
- await lockPromise;
165
- try {
166
- try {
167
- return await fn(this.writeConnection);
168
- }
169
- finally {
170
- const serializedUpdates = await this.writeConnection.executeRaw("SELECT powersync_update_hooks('get');", []);
171
- const updates = JSON.parse(serializedUpdates[0][0]);
172
- if (updates.length > 0) {
173
- const event = {
174
- tables: updates,
175
- groupedUpdates: {},
176
- rawUpdates: []
177
- };
178
- this.iterateListeners((cb) => cb.tablesUpdated?.(event));
179
- }
180
- }
181
- }
182
- finally {
183
- const next = this.writeQueue.shift();
184
- if (next) {
185
- next();
186
- }
187
- else {
188
- this.writeConnection.isBusy = false;
189
- }
190
- }
191
- })();
192
- }
193
- readTransaction(fn, _options) {
194
- return this.readLock((ctx) => this.internalTransaction(ctx, fn));
195
- }
196
- writeTransaction(fn, _options) {
197
- return this.writeLock((ctx) => this.internalTransaction(ctx, fn));
198
- }
199
- async internalTransaction(connection, fn) {
200
- let finalized = false;
201
- const commit = async () => {
202
- if (!finalized) {
203
- finalized = true;
204
- await connection.execute('COMMIT');
205
- }
206
- return { rowsAffected: 0 };
207
- };
208
- const rollback = async () => {
209
- if (!finalized) {
210
- finalized = true;
211
- await connection.execute('ROLLBACK');
212
- }
213
- return { rowsAffected: 0 };
214
- };
215
- try {
216
- await connection.execute('BEGIN');
217
- const result = await fn({
218
- execute: (query, params) => connection.execute(query, params),
219
- executeRaw: (query, params) => connection.executeRaw(query, params),
220
- executeBatch: (query, params) => connection.executeBatch(query, params),
221
- get: (query, params) => connection.get(query, params),
222
- getAll: (query, params) => connection.getAll(query, params),
223
- getOptional: (query, params) => connection.getOptional(query, params),
224
- commit,
225
- rollback
226
- });
227
- await commit();
228
- return result;
229
- }
230
- catch (ex) {
231
- try {
232
- await rollback();
233
- }
234
- catch (ex2) {
235
- // In rare cases, a rollback may fail.
236
- // Safe to ignore.
237
- }
238
- throw ex;
239
- }
240
- }
241
- getAll(sql, parameters) {
242
- return this.readLock((ctx) => ctx.getAll(sql, parameters));
243
- }
244
- getOptional(sql, parameters) {
245
- return this.readLock((ctx) => ctx.getOptional(sql, parameters));
246
- }
247
- get(sql, parameters) {
248
- return this.readLock((ctx) => ctx.get(sql, parameters));
249
- }
250
- execute(query, params) {
251
- return this.writeLock((ctx) => ctx.execute(query, params));
252
- }
253
- executeRaw(query, params) {
254
- return this.writeLock((ctx) => ctx.executeRaw(query, params));
255
- }
256
- executeBatch(query, params) {
257
- return this.writeTransaction((ctx) => ctx.executeBatch(query, params));
258
- }
259
- async refreshSchema() {
260
- await this.writeConnection.refreshSchema();
261
- for (const readConnection of this.readConnections) {
262
- await readConnection.refreshSchema();
263
- }
264
- }
265
- }
266
- //# sourceMappingURL=WorkerConnectionPool.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WorkerConnectionPool.js","sourceRoot":"","sources":["../../src/db/WorkerConnectionPool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,OAAO,EACL,YAAY,EAQb,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qB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,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;IAC7D,CAAC;IAED,UAAU,CAAC,KAAa,EAAE,MAA0B;QAClD,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;IAChE,CAAC;IAED,YAAY,CAAC,KAAa,EAAE,MAAgB;QAC1C,OAAO,IAAI,CAAC,gBAAgB,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;IACzE,CAAC;IAED,KAAK,CAAC,aAAa;QACjB,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,EAAE,CAAC;QAE3C,KAAK,MAAM,cAAc,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YAClD,MAAM,cAAc,CAAC,aAAa,EAAE,CAAC;QACvC,CAAC;IACH,CAAC;CACF"}
@@ -1,44 +0,0 @@
1
- import { type Worker } from 'node:worker_threads';
2
- import { LockContext, SQLOpenOptions } from '@powersync/common';
3
- export type WorkerOpener = (...args: ConstructorParameters<typeof Worker>) => InstanceType<typeof Worker>;
4
- /**
5
- * Use the [better-sqlite3](https://github.com/WiseLibs/better-sqlite3) package as a SQLite driver for PowerSync.
6
- */
7
- export interface BetterSqlite3Options {
8
- type: 'better-sqlite3';
9
- }
10
- /**
11
- * Use the experimental `node:sqlite` interface as a SQLite driver for PowerSync.
12
- *
13
- * Note that this option is not currently tested and highly unstable.
14
- */
15
- export interface NodeSqliteOptions {
16
- type: 'node:sqlite';
17
- }
18
- export type NodeDatabaseImplementation = BetterSqlite3Options | NodeSqliteOptions;
19
- /**
20
- * The {@link SQLOpenOptions} available across all PowerSync SDKs for JavaScript extended with
21
- * Node.JS-specific options.
22
- */
23
- export interface NodeSQLOpenOptions extends SQLOpenOptions {
24
- implementation?: NodeDatabaseImplementation;
25
- /**
26
- * The Node.JS SDK will use one worker to run writing queries and additional workers to run reads.
27
- * This option controls how many workers to use for reads.
28
- */
29
- readWorkerCount?: number;
30
- /**
31
- * A callback to allow customizing how the Node.JS SDK loads workers. This can be customized to
32
- * use workers at different paths.
33
- *
34
- * @param args The arguments that would otherwise be passed to the {@link Worker} constructor.
35
- * @returns the resolved worker.
36
- */
37
- openWorker?: WorkerOpener;
38
- /**
39
- * Initializes a created database connection.
40
- *
41
- * This can be used to e.g. set encryption keys, if an encrypted database should be used.
42
- */
43
- initializeConnection?: (db: LockContext, isWriter: boolean) => Promise<void>;
44
- }
package/lib/db/options.js DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=options.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/db/options.ts"],"names":[],"mappings":""}
package/lib/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from '@powersync/common';
2
- export * from './db/PowerSyncDatabase.js';
3
- export * from './attachments/NodeFileSystemAdapter.js';
package/lib/index.js DELETED
@@ -1,5 +0,0 @@
1
- // Re export to only require one import in client side code
2
- export * from '@powersync/common';
3
- export * from './db/PowerSyncDatabase.js';
4
- export * from './attachments/NodeFileSystemAdapter.js';
5
- //# sourceMappingURL=index.js.map
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,cAAc,mBAAmB,CAAC;AAElC,cAAc,2BAA2B,CAAC;AAE1C,cAAc,wCAAwC,CAAC"}
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,23 +0,0 @@
1
- import { type ILogger, AbstractRemote, AbstractRemoteOptions, BSONImplementation, RemoteConnector } from '@powersync/common';
2
- import { Dispatcher } from 'undici';
3
- export declare const STREAMING_POST_TIMEOUT_MS = 30000;
4
- export type NodeCustomConnectionOptions = {
5
- /**
6
- * Optional custom dispatcher for HTTP or WEB_SOCKET connections.
7
- *
8
- * This can be used to customize proxy usage (using undici ProxyAgent),
9
- * or other connection options.
10
- */
11
- dispatcher?: Dispatcher;
12
- };
13
- export type NodeRemoteOptions = AbstractRemoteOptions & NodeCustomConnectionOptions;
14
- export declare class NodeRemote extends AbstractRemote {
15
- protected connector: RemoteConnector;
16
- protected logger: ILogger;
17
- private wsDispatcher;
18
- constructor(connector: RemoteConnector, logger?: ILogger, options?: Partial<NodeRemoteOptions>);
19
- protected createSocket(url: string): globalThis.WebSocket;
20
- protected getWebsocketDispatcher(url: string): Dispatcher;
21
- getUserAgent(): string;
22
- getBSON(): Promise<BSONImplementation>;
23
- }
@@ -1,79 +0,0 @@
1
- import * as os from 'node:os';
2
- import { AbstractRemote, DEFAULT_REMOTE_LOGGER, FetchImplementationProvider } from '@powersync/common';
3
- import { BSON } from 'bson';
4
- import { EnvHttpProxyAgent, getGlobalDispatcher, ProxyAgent, WebSocket as UndiciWebSocket } from 'undici';
5
- export const STREAMING_POST_TIMEOUT_MS = 30_000;
6
- class NodeFetchProvider extends FetchImplementationProvider {
7
- getFetch() {
8
- return fetch.bind(globalThis);
9
- }
10
- }
11
- export class NodeRemote extends AbstractRemote {
12
- connector;
13
- logger;
14
- wsDispatcher;
15
- constructor(connector, logger = DEFAULT_REMOTE_LOGGER, options) {
16
- const fetchDispatcher = options?.dispatcher ?? defaultFetchDispatcher();
17
- super(connector, logger, {
18
- fetchImplementation: options?.fetchImplementation ?? new NodeFetchProvider(),
19
- fetchOptions: {
20
- dispatcher: fetchDispatcher
21
- },
22
- ...(options ?? {})
23
- });
24
- this.connector = connector;
25
- this.logger = logger;
26
- this.wsDispatcher = options?.dispatcher;
27
- }
28
- createSocket(url) {
29
- // Create dedicated dispatcher for this WebSocket
30
- const baseDispatcher = this.getWebsocketDispatcher(url);
31
- // Create WebSocket with dedicated dispatcher
32
- const ws = new UndiciWebSocket(url, {
33
- dispatcher: baseDispatcher,
34
- headers: {
35
- 'User-Agent': this.getUserAgent()
36
- }
37
- });
38
- return ws;
39
- }
40
- getWebsocketDispatcher(url) {
41
- if (this.wsDispatcher != null) {
42
- return this.wsDispatcher;
43
- }
44
- const protocol = new URL(url).protocol.replace(':', '');
45
- const proxy = getProxyForProtocol(protocol);
46
- if (proxy != null) {
47
- return new ProxyAgent(proxy);
48
- }
49
- else {
50
- return getGlobalDispatcher();
51
- }
52
- }
53
- getUserAgent() {
54
- return [
55
- super.getUserAgent(),
56
- `powersync-node`,
57
- `node/${process.versions.node}`,
58
- `${os.platform()}/${os.release()}`
59
- ].join(' ');
60
- }
61
- async getBSON() {
62
- return BSON;
63
- }
64
- }
65
- function defaultFetchDispatcher() {
66
- // EnvHttpProxyAgent automatically uses HTTP_PROXY, HTTPS_PROXY and NO_PROXY env vars by default.
67
- // We add ALL_PROXY support.
68
- return new EnvHttpProxyAgent({
69
- httpProxy: getProxyForProtocol('http'),
70
- httpsProxy: getProxyForProtocol('https')
71
- });
72
- }
73
- function getProxyForProtocol(protocol) {
74
- return (process.env[`${protocol.toLowerCase()}_proxy`] ??
75
- process.env[`${protocol.toUpperCase()}_PROXY`] ??
76
- process.env[`all_proxy`] ??
77
- process.env[`ALL_PROXY`]);
78
- }
79
- //# sourceMappingURL=NodeRemote.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"NodeRemote.js","sourceRoot":"","sources":["../../../src/sync/stream/NodeRemote.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAE9B,OAAO,EAEL,cAAc,EAGd,qBAAqB,EAErB,2BAA2B,EAE5B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAEL,iBAAiB,EAEjB,mBAAmB,EACnB,UAAU,EACV,SAAS,IAAI,eAAe,EAC7B,MAAM,QAAQ,CAAC;AAEhB,MAAM,CAAC,MAAM,yBAAyB,GAAG,MAAM,CAAC;AAEhD,MA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AAM,KAAK,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAC;QAC5C,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC;aAAM,CAAC;YACN,OAAO,mBAAmB,EAAE,CAAC;QAC/B,CAAC;IACH,CAAC;IAED,YAAY;QACV,OAAO;YACL,KAAK,CAAC,YAAY,EAAE;YACpB,gBAAgB;YAChB,QAAQ,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE;YAC/B,GAAG,EAAE,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE;SACnC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACd,CAAC;IAED,KAAK,CAAC,OAAO;QACX,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,SAAS,sBAAsB;IAC7B,iGAAiG;IACjG,4BAA4B;IAC5B,OAAO,IAAI,iBAAiB,CAAC;QAC3B,SAAS,EAAE,mBAAmB,CAAC,MAAM,CAAC;QACtC,UAAU,EAAE,mBAAmB,CAAC,OAAO,CAAC;KACzC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,mBAAmB,CAAC,QAAgB;IAC3C,OAAO,CACL,OAAO,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC;QAC9C,OAAO,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC;QAC9C,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;QACxB,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CACzB,CAAC;AACJ,CAAC"}
@@ -1,11 +0,0 @@
1
- import { AbstractStreamingSyncImplementation, AbstractStreamingSyncImplementationOptions, LockOptions, LockType } from '@powersync/common';
2
- import { Mutex } from 'async-mutex';
3
- export declare class NodeStreamingSyncImplementation extends AbstractStreamingSyncImplementation {
4
- locks: Map<LockType, Mutex>;
5
- constructor(options: AbstractStreamingSyncImplementationOptions);
6
- /**
7
- * Configures global locks on sync process
8
- */
9
- initLocks(): void;
10
- obtainLock<T>(lockOptions: LockOptions<T>): Promise<T>;
11
- }
@@ -1,44 +0,0 @@
1
- import { AbstractStreamingSyncImplementation, LockType } from '@powersync/common';
2
- import { Mutex } from 'async-mutex';
3
- /**
4
- * Global locks which prevent multiple instances from syncing
5
- * concurrently.
6
- */
7
- const LOCKS = new Map();
8
- const lockTypes = new Set(Object.values(LockType));
9
- export class NodeStreamingSyncImplementation extends AbstractStreamingSyncImplementation {
10
- locks;
11
- constructor(options) {
12
- super(options);
13
- this.initLocks();
14
- }
15
- /**
16
- * Configures global locks on sync process
17
- */
18
- initLocks() {
19
- const { identifier } = this.options;
20
- if (identifier && LOCKS.has(identifier)) {
21
- this.locks = LOCKS.get(identifier);
22
- return;
23
- }
24
- this.locks = new Map();
25
- this.locks.set(LockType.CRUD, new Mutex());
26
- this.locks.set(LockType.SYNC, new Mutex());
27
- if (identifier) {
28
- LOCKS.set(identifier, this.locks);
29
- }
30
- }
31
- obtainLock(lockOptions) {
32
- const lock = this.locks.get(lockOptions.type);
33
- if (!lock) {
34
- throw new Error(`Lock type ${lockOptions.type} not found`);
35
- }
36
- return lock.runExclusive(async () => {
37
- if (lockOptions.signal?.aborted) {
38
- throw new Error('Aborted');
39
- }
40
- return lockOptions.callback();
41
- });
42
- }
43
- }
44
- //# sourceMappingURL=NodeStreamingSyncImplementation.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"NodeStreamingSyncImplementation.js","sourceRoot":"","sources":["../../../src/sync/stream/NodeStreamingSyncImplementation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mCAAmC,EAGnC,QAAQ,EACT,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC;;;GAGG;AACH,MAAM,KAAK,GAAG,IAAI,GAAG,EAAgC,CAAC;AAEtD,MAAM,SAAS,GAAG,IAAI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S,CAAC,CAAC;YAC7B,CAAC;YAED,OAAO,WAAW,CAAC,QAAQ,EAAE,CAAC;QAChC,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -1,2 +0,0 @@
1
- export declare const isBundledToCommonJs: boolean;
2
- export declare function dynamicImport(path: string): Promise<any>;
@@ -1,6 +0,0 @@
1
- // Note: When updating this file, always update module_commonjs.ts as well.
2
- export const isBundledToCommonJs = false;
3
- export async function dynamicImport(path) {
4
- return await import(path);
5
- }
6
- //# sourceMappingURL=modules.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"modules.js","sourceRoot":"","sources":["../../src/utils/modules.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,MAAM,CAAC,MAAM,mBAAmB,GAAY,KAAK,CAAC;AAElD,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,IAAY;IAC9C,OAAO,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC"}
@@ -1,2 +0,0 @@
1
- export declare const isBundledToCommonJs: boolean;
2
- export declare function dynamicImport(path: string): Promise<any>;
@@ -1,7 +0,0 @@
1
- // NOTE! Do not import this file directly! We have a rollup plugin that rewrites imports to modules.js to this file when
2
- // bundling to CommonJS.
3
- export const isBundledToCommonJs = true;
4
- export async function dynamicImport(path) {
5
- return require(path);
6
- }
7
- //# sourceMappingURL=modules_commonjs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"modules_commonjs.js","sourceRoot":"","sources":["../../src/utils/modules_commonjs.ts"],"names":[],"mappings":"AAAA,wHAAwH;AACxH,wBAAwB;AACxB,MAAM,CAAC,MAAM,mBAAmB,GAAY,IAAI,CAAC;AAEjD,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,IAAY;IAC9C,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;AACvB,CAAC"}
package/lib/worker.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './db/SqliteWorker.js';
package/lib/worker.js DELETED
@@ -1,2 +0,0 @@
1
- export * from './db/SqliteWorker.js';
2
- //# sourceMappingURL=worker.js.map
package/lib/worker.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"worker.js","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC"}