Skip to content

Commit 16fc278

Browse files
committed
Merge remote-tracking branch 'origin' into document-vfs
2 parents 5974e52 + 994afb5 commit 16fc278

File tree

70 files changed

+1194
-646
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1194
-646
lines changed

client-sdk-references/javascript-web/usage-examples.mdx

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,3 +268,129 @@ The [WASQLiteDBAdapter](https://powersync-ja.github.io/powersync-js/web-sdk/clas
268268
```
269269
chrome://inspect/#workers
270270
```
271+
272+
## Using PowerSyncDatabase Flags
273+
274+
This guide provides an overview of the customizable flags available for the `PowerSyncDatabase` in the JavaScript Web SDK. These flags allow you to enable or disable specific features to suit your application's requirements.
275+
276+
### Configuring Flags
277+
278+
You can configure flags during the initialization of the `PowerSyncDatabase`. Flags can be set using the `flags` property, which allows you to enable or disable specific functionalities.
279+
280+
```javascript
281+
import { PowerSyncDatabase, resolveWebPowerSyncFlags, WebPowerSyncFlags } from '@powersync/web';
282+
import { AppSchema } from '@/library/powersync/AppSchema';
283+
284+
// Define custom flags
285+
const customFlags: WebPowerSyncFlags = resolveWebPowerSyncFlags({
286+
enableMultiTabs: true,
287+
broadcastLogs: true,
288+
disableSSRWarning: false,
289+
ssrMode: false,
290+
useWebWorker: true,
291+
});
292+
293+
// Create the PowerSync database instance
294+
export const db = new PowerSyncDatabase({
295+
schema: AppSchema,
296+
database: {
297+
dbFilename: 'example.db',
298+
},
299+
flags: customFlags,
300+
});
301+
```
302+
303+
#### Available Flags
304+
<ParamField path="enableMultiTabs">
305+
default: `true`
306+
307+
Enables support for multiple tabs using shared web workers. When enabled, multiple tabs can interact with the same database and sync data seamlessly.
308+
</ParamField>
309+
310+
<ParamField path="broadcastLogs">
311+
default: `false`
312+
313+
Enables the broadcasting of logs for debugging purposes. This flag helps monitor shared worker logs in a multi-tab environment.
314+
</ParamField>
315+
316+
<ParamField path="disableSSRWarning">
317+
default: `false`
318+
319+
Disables warnings when running in SSR (Server-Side Rendering) mode.
320+
</ParamField>
321+
322+
<ParamField path="ssrMode">
323+
default: `false`
324+
325+
Enables SSR mode. In this mode, only empty query results will be returned, and syncing with the backend is disabled.
326+
</ParamField>
327+
328+
<ParamField path="useWebWorker">
329+
default: `true`
330+
331+
Enables the use of web workers for database operations. Disabling this flag also disables multi-tab support.
332+
</ParamField>
333+
334+
335+
### Flag Behavior
336+
337+
#### Example 1: Multi-Tab Support
338+
339+
By default, multi-tab support is enabled if supported by the browser. To explicitly disable this feature:
340+
341+
```javascript
342+
export const db = new PowerSyncDatabase({
343+
schema: AppSchema,
344+
database: {
345+
dbFilename: 'my_app_db.sqlite',
346+
},
347+
flags: {
348+
enableMultiTabs: false,
349+
},
350+
});
351+
```
352+
353+
When disabled, each tab will use independent workers, and changes in one tab will not automatically propagate to others.
354+
355+
#### Example 2: SSR Mode
356+
357+
To enable SSR mode and suppress warnings:
358+
359+
```javascript
360+
export const db = new PowerSyncDatabase({
361+
schema: AppSchema,
362+
database: {
363+
dbFilename: 'my_app_db.sqlite',
364+
},
365+
flags: {
366+
ssrMode: true,
367+
disableSSRWarning: true,
368+
},
369+
});
370+
```
371+
372+
#### Example 3: Verbose Debugging with Broadcast Logs
373+
374+
To enable detailed logging for debugging:
375+
376+
```javascript
377+
export const db = new PowerSyncDatabase({
378+
schema: AppSchema,
379+
database: {
380+
dbFilename: 'my_app_db.sqlite',
381+
},
382+
flags: {
383+
broadcastLogs: true,
384+
},
385+
});
386+
```
387+
388+
Logs will include detailed insights into database operations and synchronization.
389+
390+
### Recommendations
391+
392+
1. **Set `enableMultiTabs`** to `true` if your application requires seamless data sharing across multiple tabs.
393+
2. **Set `useWebWorker`** to `true` for efficient database operations using web workers.
394+
3. **Set `broadcastLogs`** to `true` during development to troubleshoot and monitor database and sync operations.
395+
4. **Set `disableSSRWarning`** to `true` when running in SSR mode to avoid unnecessary console warnings.
396+
5. **Test combinations** of flags to validate their behavior in your application's specific use case.

client-sdk-references/kotlin-multiplatform.mdx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ sidebarTitle: Overview
99
</Card>
1010
<Card title="Source Code" icon="github" href="https://github.com/powersync-ja/powersync-kotlin/">
1111
Refer to the powersync-kotlin repo on GitHub.
12-
</Card>
12+
</Card>
1313
<Card title="API Reference (Coming soon)" icon="book" href="">
1414
A full API Reference for this SDK is not yet available. This is planned for the stable release.
1515
</Card>
@@ -19,7 +19,7 @@ sidebarTitle: Overview
1919
</CardGroup>
2020

2121
<Note>
22-
The PowerSync Swift SDK is currently in a beta release. It is suitable for production use at this stage given you've tested your use cases extensively. Breaking changes are unlikely to occur.
22+
This SDK is currently in a [**beta** release](/resources/feature-status). It is suitable for production use provided you've tested your specific use cases.
2323
</Note>
2424

2525
### SDK Features
@@ -31,12 +31,18 @@ sidebarTitle: Overview
3131
* Enables subscription to queries for receiving live updates.
3232
* Eliminates the need for client-side database migrations as these are managed automatically.
3333

34-
Supported targets: Android and iOS.
34+
Supported targets: Android, iOS and Desktop.
3535

3636
## Installation
3737

3838
See the [SDK's README](https://github.com/powersync-ja/powersync-kotlin?tab=readme-ov-file#installation) for installation instructions.
3939

40+
<Info>
41+
**JVM compatibility for Desktop**
42+
* The following platforms are supported: Linux AArch64, Linux X64, MacOS AArch64, MacOS X64, Windows X64.
43+
* See this [example build.gradle file](https://github.com/powersync-ja/powersync-kotlin/blob/main/demos/hello-powersync/composeApp/build.gradle.kts) for the relevant JVM config.
44+
</Info>
45+
4046
## Getting Started
4147

4248
Before implementing the PowerSync SDK in your project, make sure you have completed these steps:
@@ -112,7 +118,7 @@ import com.powersync.PowerSyncDatabase
112118

113119
// Android
114120
val driverFactory = DatabaseDriverFactory(this)
115-
// iOS
121+
// iOS & Desktop
116122
val driverFactory = DatabaseDriverFactory()
117123
```
118124

client-sdk-references/react-native-and-expo/react-native-web-support.mdx

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,34 @@ title: "React Native Web Support"
77
Support for React Native Web is available since versions 1.12.1 of the [PowerSync React Native SDK](/client-sdk-references/react-native-and-expo) and 1.8.0 if the [JavaScript/Web SDK](/client-sdk-references/javascript-web), and is currently in a **beta** release.
88

99
A demo app showcasing this functionality is available here:
10-
<Card
11-
title="powersync-js/demos/react-native-web-supabase-todolist"
12-
icon="github"
13-
href="https://github.com/powersync-ja/powersync-js/tree/main/demos/react-native-web-supabase-todolist"
14-
horizontal
15-
/>
10+
11+
<Card title="powersync-js/demos/react-native-web-supabase-todolist" icon="github" href="https://github.com/powersync-ja/powersync-js/tree/main/demos/react-native-web-supabase-todolist" horizontal />
1612

1713
## Configuring PowerSync in your React Native for Web project
1814

1915
To ensure that PowerSync features are fully supported in your React Native Web project, follow the below steps. This documentation covers necessary web worker configurations, database instantiation, and multi-platform implementations.
2016

21-
### 1\. Install Web SDK
17+
### 1. Install Web SDK
2218

2319
The [PowerSync Web SDK](/client-sdk-references/javascript-web), alongside the [PowerSync React Native SDK](/client-sdk-references/react-native-and-expo), is required for Web support.
2420

2521
See installation instructions [here](https://www.npmjs.com/package/@powersync/web).
2622

27-
### 2\. Configure Web Workers
23+
### 2. Configure Web Workers
2824

2925
For React Native for Web, workers need to be configured when instantiating `PowerSyncDatabase`. An example of this is available [here](https://github.com/powersync-ja/powersync-js/blob/main/demos/react-native-web-supabase-todolist/library/powersync/system.ts).
3026

3127
To do this, copy the contents of `node_modules/@powersync/web/dist` to the root of your project (typically in the `public `directory). To make it easier to manage these files in the `public` directory, it is recommended to place the contents in a nested directory like `@powersync`.
3228

33-
You can run the following bash command to automate the copying process. It will create copy the contents to `/public/@powersync`.
29+
The [`@powersync/web`](https://github.com/powersync-ja/powersync-js/tree/main/packages/web) package includes a CLI utility which can copy the required assets to the `public` directory (configurable with the `--output` option).
3430

3531
```bash
36-
mkdir -p public/@powersync && cp -r node_modules/@powersync/web/dist/* public/@powersync/
32+
# Places assets into public/@powersync by default. Override with `--output path/from_current_working_dir`.
33+
npx powersync-web copy-assets
34+
# or pnpm powersync-web copy-assets
3735
```
3836

39-
### 3\. Instantiate Web Workers
37+
### 3. Instantiate Web Workers
4038

4139
The example below demonstrates how to instantiate the workers (PowerSync requires a database and a sync worker) when instantiating `PowerSyncDatabase`. You can either specify a path to the worker (they are available in the `worker` directory of the `dist` contents), or provide a factory function to create the worker.
4240

@@ -82,7 +80,7 @@ this.powersync = new PowerSyncDatabaseWeb({
8280

8381
This `PowerSyncDatabaseWeb` database will be used alongside the native `PowerSyncDatabase` to support platform-specific implementations. See the [Instantiating PowerSync](/client-sdk-references/react-native-and-expo/react-native-web-support#implementations) section below for more details.
8482

85-
### 4\. Enable multiple platforms
83+
### 4. Enable multiple platforms
8684

8785
To target both mobile and web platforms, you need to adjust the Metro configuration and handle platform-specific libraries accordingly.
8886

@@ -192,6 +190,7 @@ export async function prompt(
192190
```
193191

194192
Which can then be used agnostically in a component.
193+
195194
```js
196195
import { Button } from 'react-native';
197196
import { prompt } from 'util/prompt';
@@ -214,15 +213,17 @@ import { prompt } from 'util/prompt';
214213
}}
215214
/>;
216215
```
217-
### 5\. Configure UMD target
216+
217+
### 5. Configure UMD target
218218

219219
React Native Web requires the UMD target of `@powersync/web` (available at `@powersync/web/umd`). To fully support this target version, configure the following in your project:
220220

221221
1. Add `config.resolver.unstable_enablePackageExports = true;` to your `metro.config.js` file.
222+
222223
2. TypeScript projects: In the `tsconfig.json` file specify the `moduleResolution` to be `Bundler`.
223224

224225
```json
225226
"compilerOptions": {
226227
"moduleResolution": "Bundler"
227228
}
228-
```
229+
```

client-sdk-references/swift.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ sidebarTitle: "Overview"
1616
</CardGroup>
1717

1818
<Note>
19-
The PowerSync Swift SDK is currently in a beta release. It is suitable for production use at this stage given you've tested your use cases extensively. Breaking changes are unlikely to occur.
19+
This SDK is currently in a [**beta** release](/resources/feature-status). It is suitable for production use provided you've tested your specific use cases.
2020
</Note>
2121

2222
## Kotlin Multiplatform -> Native Swift SDK
@@ -26,7 +26,7 @@ The PowerSync Swift SDK currently makes use of the [PowerSync Kotlin Multiplatfo
2626
<Tip>
2727
**Demo App**
2828

29-
We recommend the [Supabase Todo List Demo](https://github.com/powersync-ja/powersync-swift/tree/main/Demo) app as a starting point for using the Swift SDK. See the README for details to run it.
29+
We recommend the [Supabase To-Do List Demo](https://github.com/powersync-ja/powersync-swift/tree/main/Demo) app as a starting point for using the Swift SDK. See the README for details to run it.
3030
</Tip>
3131

3232
### SDK Features
@@ -90,7 +90,7 @@ The beta version of this SDK introduces a Swift-native wrapper around the packag
9090
* `@MainThread` usage is no longer required and should be removed.
9191
* Implementing `SuspendTaskWrapper` for database transactions is no longer required and should be removed.
9292

93-
See the [Todo List Demo app](https://github.com/powersync-ja/powersync-swift/tree/main/Demo) as a reference.
93+
See the [To-Do List Demo app](https://github.com/powersync-ja/powersync-swift/tree/main/Demo) as a reference.
9494

9595
## Getting Started
9696

48.8 KB
Loading
79.4 KB
Loading

images/integration-3.png

-69.4 KB
Binary file not shown.
180 KB
Loading
402 KB
Loading

images/self-hosting-3.avif

-8.93 KB
Binary file not shown.

0 commit comments

Comments
 (0)