Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
40 changes: 40 additions & 0 deletions .github/workflows/dev-packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# The version is pulled from the CHANGELOG.md file of the package.
# Add a `-dev.xxx` suffix to the version.
name: Create Dev Release

on: workflow_dispatch

jobs:
dev-release:
name: Publish Dev Packages
runs-on: windows-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0'

- name: Download PowerSync extension
run: dotnet run --project Tools/Setup

- name: Restore dependencies
run: dotnet restore

- name: Extract Version from CHANGELOG.md
id: extract_version
shell: bash
run: |
VERSION=$(awk '/^## [0-9]+\.[0-9]+\.[0-9]+/ {print $2; exit}' PowerSync/PowerSync.Common/CHANGELOG.md)
echo "Detected Version: $VERSION"
echo "VERSION=$VERSION" >> $GITHUB_ENV

- name: Run Pack
run: dotnet pack -c Release -o ${{ github.workspace }}/output

- name: Run Push
run: dotnet nuget push ${{ github.workspace }}\output\*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}

39 changes: 39 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# The version is pulled from the CHANGELOG.md file of the package.
name: Release

on: workflow_dispatch

jobs:
release:
name: Release
runs-on: windows-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0'

- name: Download PowerSync extension
run: dotnet run --project Tools/Setup

- name: Restore dependencies
run: dotnet restore

- name: Extract Version from CHANGELOG.md
id: extract_version
shell: bash
run: |
VERSION=$(awk '/^## [0-9]+\.[0-9]+\.[0-9]+/ {print $2; exit}' PowerSync/PowerSync.Common/CHANGELOG.md)
echo "Detected Version: $VERSION"
echo "VERSION=$VERSION" >> $GITHUB_ENV

- name: Run Pack
run: dotnet pack -c Release -o ${{ github.workspace }}/output

- name: Run Push
run: dotnet nuget push ${{ github.workspace }}\output\*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}

27 changes: 27 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Test Packages

on:
push:

jobs:
build:
name: Test Packages
runs-on: windows-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0'

- name: Download PowerSync extension
run: dotnet run --project Tools/Setup

- name: Restore dependencies
run: dotnet restore

- name: Run tests
run: dotnet test -v n --framework net8.0
10 changes: 10 additions & 0 deletions PowerSync/PowerSync.Common/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## 0.0.2-alpha.1

- Introduce package. Support for Desktop .NET use cases.

### Platform Runtime Support Added
* linux-arm64
* linux-x64
* osx-arm64
* osx-x64
* wind-x64
4 changes: 2 additions & 2 deletions PowerSync/PowerSync.Common/Client/PowerSyncDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ public async Task<T> WriteTransaction<T>(Func<ITransaction, Task<T>> fn, DBLockO
/// </summary>
public Task Watch<T>(string query, object[]? parameters, WatchHandler<T> handler, SQLWatchOptions? options = null)
{
var tcs = new TaskCompletionSource();
var tcs = new TaskCompletionSource<bool>();
Task.Run(async () =>
{
try
Expand Down Expand Up @@ -611,7 +611,7 @@ public Task Watch<T>(string query, object[]? parameters, WatchHandler<T> handler
Signal = options?.Signal,
ThrottleMs = options?.ThrottleMs
});
tcs.SetResult();
tcs.SetResult(true);
}
catch (Exception ex)
{
Expand Down
27 changes: 25 additions & 2 deletions PowerSync/PowerSync.Common/PowerSync.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,20 @@
<LangVersion>12</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<VersionPrefix>0.0.1</VersionPrefix>
<VersionSuffix>alpha</VersionSuffix>
<PackageId>PowerSync.Common</PackageId>
<Title>PowerSync.Common</Title>
<Description>PowerSync.Common is a package that enables local-first and real-time reactive apps with embedded SQLite for .NET clients</Description>
<Authors>PowerSync</Authors>
<owners>powersync</owners>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<RepositoryUrl>https://github.com/powersync-ja/powersync-dotnet</RepositoryUrl>
<PackageProjectUrl>https://powersync.com</PackageProjectUrl>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<PackageReleaseNotes>https://github.com/powersync-ja/powersync-dotnet/PowerSync/PowerSync.Common/CHANGELOG.md</PackageReleaseNotes>
<PackageTags>powersync local-first local-storage state-management offline sql db persistence sqlite sync </PackageTags>
<PackageIcon>icon.png</PackageIcon>
<NoWarn>NU5100</NoWarn>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
Expand All @@ -18,10 +30,21 @@
<PackageReference Include="System.Threading.Channels" Version="8.0.0" />
</ItemGroup>

<!-- For monorepo, test if we can remove this in monorepo -->
<ItemGroup>
<Content Include="runtimes\**\*.*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<!-- For releasing runtimes -->
<ItemGroup>
<None Include="runtimes\**\*.*" Pack="true" PackagePath="runtimes\" />
</ItemGroup>


<ItemGroup>
<None Include="..\..\icon.png" Pack="true" PackagePath=""/>
<None Include="README.md" Pack="true" PackagePath=""/>
</ItemGroup>
</Project>
14 changes: 14 additions & 0 deletions PowerSync/PowerSync.Common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

This package contains a .NET implementation of a PowerSync database connector and streaming sync bucket implementation.

## ⚠️ Project Status & Release Note

This package is currently in an alpha state, intended strictly for testing. Expect breaking changes and instability as development continues.

Do not rely on this package for production use.

## Installation

This package is published on [NuGet](https://www.nuget.org/packages/PowerSync.Common).

```bash
dotnet add package PowerSync.Common --prerelease
```

## Usage

### Simple Query
Expand Down
7 changes: 7 additions & 0 deletions PowerSync/PowerSync.Common/Utils/PowerSyncPathResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ public static class PowerSyncPathResolver
{
public static string GetNativeLibraryPath(string packagePath)
{

// .NET Framework 4.8 on Windows requires a different path (not supporting versions prior to this)
if (RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework 4.8") && RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return Path.Combine(AppContext.BaseDirectory, "powersync.dll");
}

string rid = GetRuntimeIdentifier();
string nativeDir = Path.Combine(packagePath, "runtimes", rid, "native");

Expand Down
48 changes: 17 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@ _[PowerSync](https://www.powersync.com) is a sync engine for building local-firs

`powersync-dotnet` is the monorepo for PowerSync .NET SDKs.

## ⚠️ Project Status & Release Note

This package is part of a monorepo that is not yet officially released or published. It is currently in a pre-alpha state, intended strictly for closed testing. Expect breaking changes and instability as development continues.

Do not rely on this package for production use.

## Monorepo Structure: Packages

Packages are published to [NuGet](https://www.nuget.org/profiles/PowerSync).

- [PowerSync/Common](./PowerSync/Common/README.md)

- Core package: .NET implementation of a PowerSync database connector and streaming sync bucket implementation. Packages meant for specific platforms will extend functionality of `Common`.
Expand Down Expand Up @@ -54,6 +50,18 @@ This PowerSync SDK currently targets the following .NET versions:
<PackageReference Include="System.Net.Http" Version="4.3.4" />
</ItemGroup>
```

and create a `IsExternalInit.cs` file in your project with the following contents:

```cs
using System.ComponentModel;

namespace System.Runtime.CompilerServices
{
[EditorBrowsable(EditorBrowsableState.Never)]
internal class IsExternalInit { }
}
```

-------

Expand Down Expand Up @@ -87,29 +95,7 @@ Run a specific test
dotnet test -v n --framework net8.0 --filter "test-file-pattern"
```

## Using the PowerSync.Common package in your project (temporary)
A NuGet package will be available soon, until then you clone this repo and follow these steps:

Add the dependency to your project's .csproj:
```.xml
<ItemGroup>
<ProjectReference Include="..\..\powersync-dotnet\PowerSync\Powersync.Common\PowerSync.Common.csproj" />
</ItemGroup>
```

Which assumes the following directory structure:
```
code/
powersync-dotnet (X)
├── PowerSync/PowerSync.Common
│ ├── PowerSync.Common.csproj
│ ├── Class1.cs
│ └── Utils.cs
└── root.sln

your-project
├── demo
│ ├── Program.csproj
│ └── Program.cs
├── root.sln
## Using the PowerSync.Common package in your project
```bash
dotnet add package PowerSync.Common --prerelease
```
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ await db.Execute(
[Fact(Timeout = 2000)]
public async Task ReadWhileWriteIsRunningTest()
{
var tcs = new TaskCompletionSource();
var tcs = new TaskCompletionSource<bool>();

// This wont resolve or free until another connection free's it
var writeTask = db.WriteLock(async context =>
Expand All @@ -200,7 +200,7 @@ public async Task ReadWhileWriteIsRunningTest()
var readTask = db.ReadLock(async context =>
{
// Read logic could execute here while writeLock is still open
tcs.SetResult();
tcs.SetResult(true);
await Task.CompletedTask;
return 42;
});
Expand Down Expand Up @@ -238,13 +238,13 @@ await db.WriteLock(async context =>
public async Task CallUpdateHookOnChangesTest()
{
var cts = new CancellationTokenSource();
var result = new TaskCompletionSource();
var result = new TaskCompletionSource<bool>();

db.OnChange(new WatchOnChangeHandler
{
OnChange = (x) =>
{
result.SetResult();
result.SetResult(true);
cts.Cancel();
return Task.CompletedTask;
}
Expand All @@ -261,7 +261,7 @@ public async Task CallUpdateHookOnChangesTest()
[Fact(Timeout = 2000)]
public async Task ReflectWriteTransactionUpdatesOnReadConnectionsTest()
{
var watched = new TaskCompletionSource();
var watched = new TaskCompletionSource<bool>();

var cts = new CancellationTokenSource();
await db.Watch("SELECT COUNT(*) as count FROM assets", null, new WatchHandler<CountResult>
Expand All @@ -270,7 +270,7 @@ public async Task ReflectWriteTransactionUpdatesOnReadConnectionsTest()
{
if (x.First().count == 1)
{
watched.SetResult();
watched.SetResult(true);
cts.Cancel();
}
}
Expand All @@ -292,7 +292,7 @@ public async Task ReflectWriteLockUpdatesOnReadConnectionsTest()
{
var numberOfAssets = 10_000;

var watched = new TaskCompletionSource();
var watched = new TaskCompletionSource<bool>();

var cts = new CancellationTokenSource();
await db.Watch("SELECT COUNT(*) as count FROM assets", null, new WatchHandler<CountResult>
Expand All @@ -301,7 +301,7 @@ public async Task ReflectWriteLockUpdatesOnReadConnectionsTest()
{
if (x.First().count == numberOfAssets)
{
watched.SetResult();
watched.SetResult(true);
cts.Cancel();
}
}
Expand All @@ -324,12 +324,12 @@ await db.WriteLock(async tx =>
}

[Fact(Timeout = 5000)]
public async Task Insert10000Records_CompleteWithinTimeLimitTest()
public async Task Insert1000Records_CompleteWithinTimeLimitTest()
{
var random = new Random();
var stopwatch = Stopwatch.StartNew();

for (int i = 0; i < 10000; ++i)
for (int i = 0; i < 1000; ++i)
{
int n = random.Next(0, 100000);
await db.Execute(
Expand Down
Loading