Glesity.Wasm.Data.Abstractions
0.3.0-alpha.2
dotnet add package Glesity.Wasm.Data.Abstractions --version 0.3.0-alpha.2
NuGet\Install-Package Glesity.Wasm.Data.Abstractions -Version 0.3.0-alpha.2
<PackageReference Include="Glesity.Wasm.Data.Abstractions" Version="0.3.0-alpha.2" />
<PackageVersion Include="Glesity.Wasm.Data.Abstractions" Version="0.3.0-alpha.2" />
<PackageReference Include="Glesity.Wasm.Data.Abstractions" />
paket add Glesity.Wasm.Data.Abstractions --version 0.3.0-alpha.2
#r "nuget: Glesity.Wasm.Data.Abstractions, 0.3.0-alpha.2"
#:package Glesity.Wasm.Data.Abstractions@0.3.0-alpha.2
#addin nuget:?package=Glesity.Wasm.Data.Abstractions&version=0.3.0-alpha.2&prerelease
#tool nuget:?package=Glesity.Wasm.Data.Abstractions&version=0.3.0-alpha.2&prerelease
Glesity.Wasm.Data.Abstractions
Zero-reflection, NativeAOT-compatible (wasi-wasm) data attributes, repository contracts, schema migration interfaces, value converters, and exception hierarchy for the Glesity.Wasm data ecosystem:
Glesity.Wasm.Sqlite- Embedded SQLite driver with staticlibsqlite3.alinking and Roslyn Source Generator.Glesity.Wasm.Postgresql(Planned) - Async PostgreSQL driver over WASI sockets.Glesity.Wasm.Redis(Planned) - Async Redis RESP client and key-value store over WASI sockets.
Features
- 100% NativeAOT & Trimming Safe: Built with zero runtime reflection (
IsAotCompatible=true,EnableTrimAnalyzer=true,EnableAotAnalyzer=true). - Source Generator Ready: Multi-targeted for
netstandard2.0(for Roslyn Incremental Source Generators) andnet11.0(for WASI / .NET runtimes) with full XML documentation. - Rich Schema & Mapping Attributes: Supports
[DataEntity],[PrimaryKey],[Column],[Index],[OrderBy],[Flatten],[JsonColumn],[ValueConverter],[DefaultValueConverter], and[Ignore], all validated at construction and markedInherited = false. - Driver-Agnostic Repositories & Migrations: Provides synchronous and asynchronous SQL/KV contracts with pagination (
Page/PageAsync), streaming (StreamAllAsync), batch operations (GetMany/SetMany/DeleteMany), and imperative schema migrations (IMigrationStep).
Installation
dotnet add package Glesity.Wasm.Data.Abstractions --prerelease
Quick Start
1. Define Entities, Value Converters & Flattened Structs
Annotate your record, class, or struct models with attributes from Glesity.Wasm.Data.Abstractions:
using System.Text.Json.Serialization;
using Glesity.Wasm.Data.Abstractions;
[DefaultValueConverter]
public readonly struct PlayerIdConverter : IValueConverter<PlayerRef, Guid>
{
public Guid ToProvider(PlayerRef value) => value.Id;
public PlayerRef FromProvider(Guid value) => new(value);
}
public readonly record struct PlayerRef(Guid Id);
public readonly record struct BlockPos(int X, int Y, int Z);
[JsonSerializable(typeof(List<string>))]
public partial class AccountJsonContext : JsonSerializerContext;
[DataEntity("player_accounts", Schema = "public")]
public sealed record PlayerAccount(
[property: PrimaryKey] PlayerRef PlayerId,
[property: Column("player_name", MaxLength = 32), Index(IsUnique = true)] string Username,
[property: Flatten] BlockPos SpawnPos,
[property: JsonColumn(typeof(AccountJsonContext))] List<string> Roles,
[property: OrderBy(Descending = true)] double Balance,
bool IsBanned,
DateTimeOffset LastLogin,
[property: Ignore] string? TransientSessionToken = null
);
2. Write Driver-Agnostic Application Logic
Program against ISqlRepository<TEntity, TKey>, IAsyncSqlRepository<TEntity, TKey>, IKeyValueStore<TKey, TValue>, or IAsyncKeyValueStore<TKey, TValue>:
using Glesity.Wasm.Data.Abstractions;
public sealed class EconomyService(IAsyncSqlRepository<PlayerAccount, PlayerRef> accounts)
{
public async ValueTask CreditAsync(PlayerRef playerId, double amount, CancellationToken ct = default)
{
var account = await accounts.FindAsync(playerId, ct)
?? throw new InvalidOperationException("Player not found.");
await accounts.UpsertAsync(account with { Balance = account.Balance + amount }, ct);
}
public async ValueTask<List<PlayerAccount>> GetPageAsync(int offset, int limit, CancellationToken ct = default)
{
return await accounts.PageAsync(offset, limit, ct);
}
}
Provided Abstractions
Attributes
All attributes enforce runtime argument validation (non-empty strings, positive MaxLength, valid base/interface types) and specify Inherited = false.
| Attribute | Target | Description |
|---|---|---|
[DataEntity(tableName, Schema = ...)] |
class, struct, record |
Maps a model to a SQL table or key prefix. |
[PrimaryKey(AutoIncrement = ...)] |
property, parameter |
Marks the primary key column (AUTOINCREMENT / SERIAL). |
[Column(name, IsUnique = ..., MaxLength = ...)] |
property, parameter |
Customizes the column name and constraints (UNIQUE, MaxLength > 0). |
[Index(name, IsUnique = ...)] |
property, parameter |
Declares an index (AllowMultiple = true) for FindBy*, ListBy*, and DeleteBy* generation. |
[OrderBy(Descending = true)] |
property, parameter |
Generates TopBy<Property>(int limit) leaderboard queries. |
[Flatten(Prefix = ...)] |
property, parameter |
Expands struct or struct? fields/properties into individual columns. |
[JsonColumn(typeof(TContext))] |
property, parameter |
Serializes complex objects using an AOT JsonSerializerContext. |
[ValueConverter(typeof(TConverter))] |
assembly, class, struct, property, parameter |
Maps domain types via IValueConverter<TModel, TProvider>. |
[DefaultValueConverter] |
struct, class |
Marks an IValueConverter<,> for automatic discovery across referenced assemblies. |
[Ignore] |
property, parameter |
Excludes a property from persistence mapping. |
Repository, Migration & Transaction Contracts
ISqlRepository<TEntity, TKey>/IAsyncSqlRepository<TEntity, TKey>- Relational CRUD (EnsureCreated,Insert,InsertIgnore,Upsert,InsertRange,Find,Exists,Delete,DeleteRange,All,Page,StreamAllAsync,Count).IKeyValueStore<TKey, TValue>/IAsyncKeyValueStore<TKey, TValue>- Key-value storage with optionalTimeSpan? ttland batch operations (Get,Set,Delete,Exists,GetMany,SetMany,DeleteMany).IMigrationStep- Imperative schema migration contract (FromVersion,ToVersion,ExecuteSql,AddColumnIfMissing,CreateIndexIfMissing).IDataTransaction/IAsyncDataTransaction- Atomic transaction scopes withIsCompletedtracking, automatic rollback onDispose/DisposeAsyncif uncommitted, andWasmDataTransactionExceptionprotection against double completion.
Exceptions
All exceptions carry a numeric ErrorCode, optional InnerException, and a raw ProviderErrorCode (e.g., "SQLITE_CONSTRAINT_UNIQUE" or PostgreSQL SQLSTATE "23505"):
WasmDataException- Base exception for all data access errors.WasmDataConnectionException- File open, WASI directory access, or network connection failures.WasmDataConstraintException-UNIQUE,PRIMARY KEY,NOT NULL,FOREIGN KEY, orCHECKconstraint violations.WasmDataConflictException(inherits fromWasmDataConstraintException) - Uniqueness conflicts or optimistic concurrency serialization failures.WasmDataTimeoutException- Lock wait (SQLITE_BUSY) or command execution timeouts.WasmDataTransactionException- Invalid transaction state transitions (e.g., committing or rolling back an already completed transaction).
Building & Testing
dotnet test -c Release
dotnet pack src/Glesity.Wasm.Data.Abstractions/Glesity.Wasm.Data.Abstractions.csproj -c Release
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. net11.0 is compatible. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Bcl.AsyncInterfaces (>= 9.0.0)
- System.Threading.Tasks.Extensions (>= 4.5.4)
-
net11.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Glesity.Wasm.Data.Abstractions:
| Package | Downloads |
|---|---|
|
Glesity.Wasm.Sqlite
Zero-reflection, NativeAOT-LLVM static SQLite engine for .NET WASI / WebAssembly. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.3.0-alpha.2 | 83 | 11/30/2026 |
| 0.3.0-alpha.1 | 67 | 11/30/2026 |
| 0.3.0-alpha | 60 | 11/30/2026 |
| 0.2.0-alpha | 76 | 11/29/2026 |
| 0.1.0-alpha | 84 | 11/29/2026 |