@powersync/capacitor 0.1.1 → 0.1.3
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/README.md +1 -1
- package/dist/esm/adapter/CapacitorSQLiteAdapter.js +25 -31
- package/dist/esm/adapter/CapacitorSQLiteAdapter.js.map +1 -1
- package/dist/plugin.cjs.js +25 -31
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +25 -31
- package/dist/plugin.js.map +1 -1
- package/package.json +3 -2
- package/src/PowerSyncDatabase.ts +90 -0
- package/src/adapter/CapacitorSQLiteAdapter.ts +336 -0
- package/src/adapter/CapacitorSQLiteOpenFactory.ts +48 -0
- package/src/index.ts +3 -0
- package/src/plugin/PowerSyncCore.ts +6 -0
- package/src/plugin/PowerSyncPlugin.ts +22 -0
- package/src/plugin/web.ts +9 -0
- package/src/sync/CapacitorSyncImplementation.ts +16 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type RegistrationResponse = {
|
|
2
|
+
/**
|
|
3
|
+
* Zero for successful registration, non-zero for failure.
|
|
4
|
+
*/
|
|
5
|
+
responseCode: number;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const messageForErrorCode = (code: number): string => {
|
|
9
|
+
switch (code) {
|
|
10
|
+
case 0:
|
|
11
|
+
return 'Success';
|
|
12
|
+
default:
|
|
13
|
+
return `Extension registration failed with SQLite error code: ${code}`;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export interface PowerSyncPlugin {
|
|
18
|
+
/**
|
|
19
|
+
* Registers the PowerSync core extension with the SQLite library.
|
|
20
|
+
*/
|
|
21
|
+
registerCore(): Promise<RegistrationResponse>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
|
|
3
|
+
import type { PowerSyncPlugin, RegistrationResponse } from './PowerSyncPlugin';
|
|
4
|
+
|
|
5
|
+
export class PowerSyncWeb extends WebPlugin implements PowerSyncPlugin {
|
|
6
|
+
async registerCore(): Promise<RegistrationResponse> {
|
|
7
|
+
throw new Error('This code path is not supported on web.');
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AbstractStreamingSyncImplementation, LockOptions } from '@powersync/web';
|
|
2
|
+
import Lock from 'async-lock';
|
|
3
|
+
|
|
4
|
+
export class CapacitorStreamingSyncImplementation extends AbstractStreamingSyncImplementation {
|
|
5
|
+
static GLOBAL_LOCK = new Lock();
|
|
6
|
+
|
|
7
|
+
async obtainLock<T>(lockOptions: LockOptions<T>): Promise<T> {
|
|
8
|
+
const identifier = `streaming-sync-${lockOptions.type}-${this.options.identifier}`;
|
|
9
|
+
return CapacitorStreamingSyncImplementation.GLOBAL_LOCK.acquire(identifier, async () => {
|
|
10
|
+
if (lockOptions.signal?.aborted) {
|
|
11
|
+
throw new Error('Aborted');
|
|
12
|
+
}
|
|
13
|
+
return await lockOptions.callback();
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|