Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ jobs:
run: dart analyze --fatal-infos --fatal-warnings
- name: Publish dry-run
run: melos publish --dry-run --yes
- name: Build DevTools extension
run: ./tool/build.sh
working-directory: packages/powersync_devtools_extension

# TODO: Uncomment after releasing powersync_flutter_libs version 0.5.0+eol.
# pana:
Expand Down
23 changes: 20 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,29 @@ jobs:
gh release upload "${{ github.ref_name }}" packages/powersync/assets/powersync_db.worker.js

publish_powersync:
needs: [setup]
permissions:
id-token: write
if: "${{ startsWith(github.ref_name, 'powersync-') }}"
uses: dart-lang/setup-dart/.github/workflows/publish.yml@v1
with:
working-directory: packages/powersync
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v6
# Install Dart to install an OIDC token for publishing
- uses: dart-lang/setup-dart@v1
- name: Install Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: "3.x"
channel: "stable"
- run: dart pub get
- run: tool/build-sh
name: Build and copy devtools extension
working-directory: packages/powersync_devtools_extension

- name: Publish to pub.dev
run: dart pub lish -f
working-directory: packages/powersync

publish_powersync_flutter_libs:
permissions:
Expand Down
58 changes: 3 additions & 55 deletions demos/supabase-todolist/macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,85 +2,33 @@ PODS:
- app_links (6.4.1):
- FlutterMacOS
- FlutterMacOS (1.0.0)
- path_provider_foundation (0.0.1):
- Flutter
- FlutterMacOS
- powersync-sqlite-core (0.4.10)
- powersync_flutter_libs (0.0.1):
- Flutter
- FlutterMacOS
- powersync-sqlite-core (~> 0.4.10)
- shared_preferences_foundation (0.0.1):
- Flutter
- FlutterMacOS
- sqlite3 (3.50.4):
- sqlite3/common (= 3.50.4)
- sqlite3/common (3.50.4)
- sqlite3/dbstatvtab (3.50.4):
- sqlite3/common
- sqlite3/fts5 (3.50.4):
- sqlite3/common
- sqlite3/math (3.50.4):
- sqlite3/common
- sqlite3/perf-threadsafe (3.50.4):
- sqlite3/common
- sqlite3/rtree (3.50.4):
- sqlite3/common
- sqlite3/session (3.50.4):
- sqlite3/common
- sqlite3_flutter_libs (0.0.1):
- Flutter
- FlutterMacOS
- sqlite3 (~> 3.50.4)
- sqlite3/dbstatvtab
- sqlite3/fts5
- sqlite3/math
- sqlite3/perf-threadsafe
- sqlite3/rtree
- sqlite3/session
- url_launcher_macos (0.0.1):
- FlutterMacOS

DEPENDENCIES:
- app_links (from `Flutter/ephemeral/.symlinks/plugins/app_links/macos`)
- FlutterMacOS (from `Flutter/ephemeral`)
- path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin`)
- powersync_flutter_libs (from `Flutter/ephemeral/.symlinks/plugins/powersync_flutter_libs/darwin`)
- shared_preferences_foundation (from `Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/darwin`)
- sqlite3_flutter_libs (from `Flutter/ephemeral/.symlinks/plugins/sqlite3_flutter_libs/darwin`)
- url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`)

SPEC REPOS:
trunk:
- powersync-sqlite-core
- sqlite3

EXTERNAL SOURCES:
app_links:
:path: Flutter/ephemeral/.symlinks/plugins/app_links/macos
FlutterMacOS:
:path: Flutter/ephemeral
path_provider_foundation:
:path: Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin
powersync_flutter_libs:
:path: Flutter/ephemeral/.symlinks/plugins/powersync_flutter_libs/darwin
shared_preferences_foundation:
:path: Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/darwin
sqlite3_flutter_libs:
:path: Flutter/ephemeral/.symlinks/plugins/sqlite3_flutter_libs/darwin
url_launcher_macos:
:path: Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos

SPEC CHECKSUMS:
app_links: c3185399a5cabc2e610ee5ad52fb7269b84ff869
app_links: 05a6ec2341985eb05e9f97dc63f5837c39895c3f
FlutterMacOS: d0db08ddef1a9af05a5ec4b724367152bb0500b1
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
powersync-sqlite-core: b30017e077c91915d53faebc5f7245384df78275
powersync_flutter_libs: 06a54b2eb2afc6f6fc675859bf1020d9cd6c0e4d
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78
sqlite3: 73513155ec6979715d3904ef53a8d68892d4032b
sqlite3_flutter_libs: 86f82662868ee26ff3451f73cac9c5fc2a1f57fa
url_launcher_macos: c82c93949963e55b228a30115bd219499a6fe404
shared_preferences_foundation: 7036424c3d8ec98dfe75ff1667cb0cd531ec82bb
url_launcher_macos: f87a979182d112f911de6820aefddaf56ee9fbfd

PODFILE CHECKSUM: 9ebaf0ce3d369aaa26a9ea0e159195ed94724cf3

Expand Down
4 changes: 4 additions & 0 deletions devtools_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
description: This file stores settings for Dart & Flutter DevTools.
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
extensions:
- powersync: true
4 changes: 4 additions & 0 deletions packages/powersync/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.1.0 (unreleased)

- Add a DevTools extension to inspect running PowerSync databases in your app.

## 2.0.1

- Fix documentation not generating.
Expand Down
6 changes: 6 additions & 0 deletions packages/powersync/extension/devtools/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: powersync
issueTracker: https://github.com/powersync-ja/powersync.dart/issues
version: 0.0.1
# We can only use Material Icons here, and they're all mediocre. This is the Material Icon "Sync".
materialIconCodePoint: '0xe627'
requiresConnection: true
11 changes: 10 additions & 1 deletion packages/powersync/lib/src/database/powersync_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import 'package:sqlite_async/sqlite_async.dart';
import '../abort_controller.dart';
import '../connector.dart';
import '../crud.dart';
import '../devtools/devtools.dart' as devtools;
import '../devtools/expose_credentials_connector.dart';
import '../log.dart';
import '../platform_specific/platform_specific.dart';
import '../powersync_update_notification.dart';
Expand Down Expand Up @@ -102,7 +104,9 @@ abstract base class PowerSyncDatabase extends SqliteConnection {
@protected
Future<void> get isInitialized;

PowerSyncDatabase._();
PowerSyncDatabase._() {
devtools.handleCreated(this);
}

/// Open a [PowerSyncDatabase].
///
Expand Down Expand Up @@ -265,6 +269,8 @@ abstract base class PowerSyncDatabase extends SqliteConnection {
await disconnect();

if (!database.closed) {
devtools.handleClosed(this);

// Now we can close the database
await database.close();

Expand Down Expand Up @@ -304,6 +310,9 @@ abstract base class PowerSyncDatabase extends SqliteConnection {
params: params,
);

if (devtools.enable) {
connector = ExposeCredentialsConnector(connector, this);
}
await _connections.connect(connector: connector, options: resolvedOptions);
}

Expand Down
62 changes: 62 additions & 0 deletions packages/powersync/lib/src/devtools/devtools.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
@internal
library;

import 'dart:developer' as dev;
import 'package:meta/meta.dart';

import '../connector.dart';
import '../database/powersync_database.dart';
import 'extension.dart';

// We want to avoid including this code for release-mode builds, since it's only
// relevant for development tooling.
const _releaseMode = bool.fromEnvironment('dart.vm.product');
const enable = !_releaseMode;

void postEvent(String type, Map<String, Object?> data) {
dev.postEvent('powersync:$type', data);
}

/// A PowerSync database made accessible to DevTools over a `dart:developer` IPC
/// protocol.
final class ExposedPowerSyncDatabase {
final PowerSyncDatabase database;
final int id;

PowerSyncCredentials? lastCredentials;

ExposedPowerSyncDatabase(this.database) : id = _nextId++ {
byDatabase[database] = this;
byId[id] = this;
}

static int _nextId = 0;

static Map<int, ExposedPowerSyncDatabase> byId = {};

/// Weak map from PowerSync databases to their [ExposedPowerSyncDatabase]
/// instance.
static final Expando<ExposedPowerSyncDatabase> byDatabase = Expando();

static void postChangeEvent() {
postEvent('databases-changed', {});
}
}

void handleCreated(PowerSyncDatabase database) {
if (enable) {
ExposedPowerSyncDatabase(database);
PowerSyncDevToolsExtension.registerIfNeeded();
ExposedPowerSyncDatabase.postChangeEvent();
}
}

void handleClosed(PowerSyncDatabase database) {
if (enable) {
if (ExposedPowerSyncDatabase.byDatabase[database] case final tracked?) {
ExposedPowerSyncDatabase.byId.remove(tracked.id);
}

ExposedPowerSyncDatabase.postChangeEvent();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'package:powersync/src/database/powersync_database.dart';

import '../connector.dart';
import 'devtools.dart';

/// A PowerSync backend connector that logs credentials over the VM service
/// protocol, allowing our DevTools extension to display the current token.
final class ExposeCredentialsConnector extends PowerSyncBackendConnector {
final PowerSyncDatabase database;
final PowerSyncBackendConnector inner;

ExposeCredentialsConnector(this.inner, this.database);

@override
Future<PowerSyncCredentials?> fetchCredentials() async {
final credentials = await inner.fetchCredentials();
if (ExposedPowerSyncDatabase.byDatabase[database] case final exposed?) {
exposed.lastCredentials = credentials;
ExposedPowerSyncDatabase.postChangeEvent();
}

return credentials;
}

@override
Future<void> uploadData(PowerSyncDatabase database) {
return inner.uploadData(database);
}
}
Loading