Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
87 changes: 87 additions & 0 deletions .changeset/afraid-carpets-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
'@powersync/common': major
'@powersync/web': major
'@powersync/capacitor': minor
'@powersync/node': minor
'@powersync/nuxt': minor
'@powersync/tauri-plugin': patch
---

Refactor open and sync options:

- Sync options are now represented through the `SyncOptions` interface alone, which
replaces `PowerSyncConnectionOptions` and several other existing types.
Sync options are only set on the call to `connect()`, and can no longer be set when
constructing a database.
`SyncOptions` is the same type across all SDKs, SDK-specific options need to be specified
when opening a database.
- Refactor open options: Each SDK has its own option type (but most use `PowerSyncDatabaseOptions`).
Using a custom open factory or an existing `DBAdapter` instance now requires the `factory` and
`opened` key, respectively (previously these options shadowed the `database` field).
On the web, all options that previously required a `WASQLiteOpenFactory` are now available on
`database` too.
Also on the web, all database open options are represented via `WebSQLOpenOptions`. Additional
options related to the sync process have moved to the `WebSpecificOptions` type to separate those
concerns better.
- Aligning the implementation with the public documentation, the default connection method has changed
from WebSockets to HTTP.

As a small guide on how to upgrade, consider these examples:

```TypeScript
// Before: Sync options set on database constructor
new PowerSyncDatabase({database: { dbFilename: 'test.db' }, retryDelayMs: 1000});

// After: Sync options can only be set when connecting
const db = new PowerSyncDatabase({database: { dbFilename: 'test.db' }});
await db.connect(yourConnector, { retryDelayMs: 1000 });
```

```TypeScript
// Before: Using a custom factory
new PowerSyncDatabase({database: new OPSqliteOpenFactory({ dbFilename: 'test.db' })});

// After: Option renamed to factory
new PowerSyncDatabase({factory: new OPSqliteOpenFactory({ dbFilename: 'test.db' })});
```

```TypeScript
// Before (web specific): Using WASQLiteOpenFactory to specify a custom VFS
new PowerSyncDatabase({
schema: AppSchema,
database: new WASQLiteOpenFactory({
dbFilename: 'exampleVFS.db',
vfs: WASQLiteVFS.OPFSWriteAheadVFS,
additionalReaders: 2
})
});

// After: Options are available on database variant, factory no longer necessary
new PowerSyncDatabase({
schema: AppSchema,
database: {
dbFilename: 'exampleVFS.db',
vfs: WASQLiteVFS.OPFSWriteAheadVFS,
additionalReaders: 2
}
});
```

```TypeScript
// Before (web specific): Misc options in flags field
new PowerSyncDatabase({
schema: AppSchema,
database: { dbFilename: 'test.db' },
flags: { broadcastLogs: true, disableSSRWarning: true }
});

// After: Flags moved to more specific keys.
new PowerSyncDatabase({
schema: AppSchema,
database: {
dbFilename: 'test.db',
disableSSRWarning: true,
},
broadcastLogs: true,
});
```
5 changes: 5 additions & 0 deletions .changeset/chatty-suits-complain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@powersync/web': minor
---

This adds the `preparedStatementsCache` option when opening databases. When set to a value greater than zero, that amount of SQL statements are cached by workers to avoid having to parse them every time a statement is executed.
11 changes: 11 additions & 0 deletions .changeset/clean-poems-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@powersync/attachments': major
'@powersync/react-native': major
'@powersync/common': major
'@powersync/web': major
'@powersync/capacitor': minor
'@powersync/node': minor
'@powersync/nuxt': minor
---

Remove the deprecated table v1 syntax. To create tables based on column arrays, use the new ResolvedTable class.
15 changes: 15 additions & 0 deletions .changeset/dirty-planets-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'@powersync/react-native': major
---

This release removes polyfills previously embedded into the React Native SDK to support
older React Native versions.

In particular, the following polyfills have been removed:

- `TextEncoder` and `TextDecoder`: Support for `TextDecoder` has recently been added to React Native,
and the SDK only uses it with very old PowerSync service versions as binary streams are preferred.
- `react-native-fetch-api`: The package was effectively unmaintained. We now use `expo/fetch` as a default
HTTP client. When unavailable, we fall back to the builtin `fetch` polyfill in React Native.
Note that this doesn't support streams, so we recommend enabling `{ connectionMethod: SyncStreamConnectionMethod.WEB_SOCKET }` for non-Expo apps with PowerSync.
- `ReadableStream`: We expect that `fetch` implementations correctly implement `Response.getReader()`.
6 changes: 6 additions & 0 deletions .changeset/famous-apes-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@powersync/vue': minor
'@powersync/react': major
---

Breaking: Remove `usePowerSyncQuery` and `usePowerSyncWatchedQuery` (use `useQuery` instead) and `usePowerSyncStatus` (use `useStatus` instead).
9 changes: 9 additions & 0 deletions .changeset/five-roses-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@powersync/react-native': major
'@powersync/common': major
'@powersync/web': major
'@powersync/capacitor': minor
'@powersync/tauri-plugin': patch
---

Remove `SQLOnChangeOptions.rawTableNames` and `WatchOnChangeHandler.onError` - both were already ignored before.
18 changes: 18 additions & 0 deletions .changeset/funny-deers-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
'@powersync/react-native': major
'@powersync/web': major
'@powersync/capacitor': minor
'@powersync/common': minor
'@powersync/tauri-plugin': minor
'@powersync/node': minor
'@powersync/nuxt': minor
'@powersync/vue': minor
---

Rename `AbstractPowerSyncDatabase` to `CommonPowerSyncDatabase`, make it a TypeScript interface.

`CrudEntry` is now a TypeScript interface, remove it's constructor and `CrudEntry.fromRow`.

`SyncStatus` is no longer constructable in user code.

Deprecate `DataFlowStatus`. Use fields on `SyncStatus` directly instead.
11 changes: 11 additions & 0 deletions .changeset/many-boxes-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@powersync/web': major
---

To reduce setup complexity, the database and sync workers have moved to a single file.

The UMD build for the main library has been removed, import `@powersync/web` directly and
remove import mappings pointing to `@powersync/web/umd`.

If you were using the pre-bundled sync or web workers, run `powersync-web copy-assets` again
and update URLs from `/@powersync/worker/WASQLiteDB.umd.js` and `/@powersync/worker/SharedSyncImplementation.umd.js` to `/@powersync/worker.js`.
7 changes: 7 additions & 0 deletions .changeset/real-mugs-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@powersync/react-native': minor
'@powersync/node': minor
'@powersync/web': minor
---

Internal: Refactor remote to load WebSocket support lazily, reducing the size of the main PowerSync SDK.
12 changes: 12 additions & 0 deletions .changeset/sixty-peas-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@powersync/react-native': major
'@powersync/web': major
'@powersync/common': major
'@powersync/node': minor
'tauri-plugin-powersync': patch
'@powersync/tauri-plugin': patch
'@powersync/nuxt': patch
'@powersync/capacitor': minor
---

Make `DBAdapter` and `LockContext` abstract classes, refactor `QueryResult` to provide column names and raw data.
5 changes: 5 additions & 0 deletions .changeset/strong-flies-watch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@powersync/common': major
---

Remove js-logger dependency in favor of a custom logger interface that needs to be passed to PowerSync databases explicitly.
8 changes: 8 additions & 0 deletions .changeset/tough-elephants-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@powersync/kysely-driver': major
'@powersync/attachments': major
'@powersync/drizzle-driver': minor
'@powersync/attachments-storage-react-native': patch
---

Remove CommonJS distribution.
24 changes: 24 additions & 0 deletions .changeset/wicked-waves-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
'@powersync/react-native': major
---

Remove support for React Native Quick SQLite (RNQS). Additionally, `OPSqliteOpenFactory` is now the default and part
of the `@powersync/react-native` package.

To upgrade, drop dependencies on `@powersync/op-sqlite`. If you've previously used RNQS, also add a dependency on
`@op-engineering/op-sqlite`.

If you've previously used a `OPSqliteOpenFactory`, all options are now available on the `PowerSyncDatabase`
constructor directly:

```TypeScript
// Before
const db = new PowerSyncDatabase({
database: new OPSqliteOpenFactory({dbFilename: 'test.db'})
});

// After
const db = new PowerSyncDatabase({
database: { dbFilename: 'test.db' }
});
```
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
run: |
pnpm build:packages:prod
pnpm changeset version --no-git-tag --snapshot dev
pnpm install --no-frozen-lockfile
pnpm changeset publish --tag dev
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68 changes: 33 additions & 35 deletions demos/angular-supabase-todolist/src/app/powersync.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Injectable } from '@angular/core';
import {
AbstractPowerSyncDatabase,
Column,
ColumnType,
Index,
IndexedColumn,
column,
CommonPowerSyncDatabase,
createConsoleLogger,
LogLevels,
PowerSyncBackendConnector,
PowerSyncDatabase,
Schema,
Expand Down Expand Up @@ -34,51 +33,50 @@ export interface TodoRecord {
export const LISTS_TABLE = 'lists';
export const TODOS_TABLE = 'todos';

export const AppSchema = new Schema([
new Table({
name: TODOS_TABLE,
columns: [
new Column({ name: 'list_id', type: ColumnType.TEXT }),
new Column({ name: 'created_at', type: ColumnType.TEXT }),
new Column({ name: 'completed_at', type: ColumnType.TEXT }),
new Column({ name: 'description', type: ColumnType.TEXT }),
new Column({ name: 'completed', type: ColumnType.INTEGER }),
new Column({ name: 'created_by', type: ColumnType.TEXT }),
new Column({ name: 'completed_by', type: ColumnType.TEXT })
],
indexes: [new Index({ name: 'list', columns: [new IndexedColumn({ name: 'list_id' })] })]
}),
new Table({
name: LISTS_TABLE,
columns: [
new Column({ name: 'created_at', type: ColumnType.TEXT }),
new Column({ name: 'name', type: ColumnType.TEXT }),
new Column({ name: 'owner_id', type: ColumnType.TEXT })
]
export const AppSchema = new Schema({
[TODOS_TABLE]: new Table(
{
list_id: column.text,
created_at: column.text,
completed_at: column.text,
description: column.text,
completed: column.integer,
created_by: column.text,
completed_by: column.text
},
{ indexes: { list: ['list_id'] } }
),
[LISTS_TABLE]: new Table({
created_at: column.text,
name: column.text,
owner_id: column.text
})
]);
});

@Injectable({
providedIn: 'root'
})
export class PowerSyncService {
db: AbstractPowerSyncDatabase;
db: CommonPowerSyncDatabase;

constructor() {
const factory = new WASQLiteOpenFactory({
dbFilename: 'test.db',
vfs: WASQLiteVFS.OPFSCoopSyncVFS,
// Specify the path to the worker script
worker: 'assets/@powersync/worker/WASQLiteDB.umd.js'
logger: createConsoleLogger({ prefix: 'powersync' }),
open: {
dbFilename: 'test.db',
vfs: WASQLiteVFS.OPFSCoopSyncVFS,
// Specify the path to the worker script
worker: 'assets/@powersync/worker.js',
databaseWorkerLogLevel: LogLevels.debug
}
});

this.db = new PowerSyncDatabase({
schema: AppSchema,
database: factory,

factory,
sync: {
// Specify the path to the worker script
worker: 'assets/@powersync/worker/SharedSyncImplementation.umd.js'
worker: 'assets/@powersync/worker.js'
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { CircularProgress } from '@mui/material';
import { PowerSyncDatabase } from '@powersync/capacitor';
import { PowerSyncContext } from '@powersync/react';
import { createBaseLogger, LogLevel } from '@powersync/web';
import { createConsoleLogger, LogLevels } from '@powersync/web';
import React, { Suspense } from 'react';
import { AppSchema } from '../../library/powersync/AppSchema.js';
import { BackendConnector } from '../../library/powersync/BackendConnector.js';

const logger = createBaseLogger();
logger.useDefaults();
logger.setLevel(LogLevel.DEBUG);

// Uses the Web SDK for web, and Capacitor adapters for iOS/Android.
const powerSync = new PowerSyncDatabase({
database: {
Expand All @@ -18,7 +14,8 @@ const powerSync = new PowerSyncDatabase({
schema: AppSchema,
flags: {
enableMultiTabs: typeof SharedWorker !== 'undefined'
}
},
logger: createConsoleLogger({ minLevel: LogLevels.debug })
});
const connector = new BackendConnector();

Expand Down
15 changes: 2 additions & 13 deletions demos/example-electron-node/src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
import fs from 'node:fs';
import { Worker } from 'node:worker_threads';

import {
createBaseLogger,
createLogger,
LogLevel,
PowerSyncDatabase,
SyncStreamConnectionMethod
} from '@powersync/node';
import { createConsoleLogger, LogLevels, PowerSyncDatabase, SyncStreamConnectionMethod } from '@powersync/node';
import { app, BrowserWindow, ipcMain, MessagePortMain } from 'electron';
import { AppSchema, BackendConnector } from './powersync';

const baseLogger = createBaseLogger();
baseLogger.useDefaults({ defaultLevel: LogLevel.WARN });

const logger = createLogger('PowerSyncDemo');

// This allows TypeScript to pick up the magic constants that's auto-generated by Forge's Webpack
// plugin that tells the Electron app where to look for the Webpack-bundled app code (depending on
// whether you're running in development or production).
Expand Down Expand Up @@ -47,7 +36,7 @@ const database = new PowerSyncDatabase({
return new Worker(new URL('./worker.ts', import.meta.url), options);
}
},
logger
logger: createConsoleLogger({ minLevel: LogLevels.debug })
});

const createWindow = (): void => {
Expand Down
Loading
Loading