Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

108 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

@pitzzahh/signaldb-adapter-tauri

npm version Test License: MIT

A simple and reliable persistence adapter for SignalDB in Tauri applications. Persist your reactive data collections to the local filesystem with built-in AES-256-GCM encryption β€” recommended for all production apps.

✨ Features

  • πŸš€ Zero Configuration - Works out of the box with sensible defaults
  • πŸ’Ύ Native Tauri Integration - Uses Tauri's secure filesystem API
  • πŸ” Built-in Encryption β€” AES-256-GCM via createEncryption(). Also supports custom encrypt/decrypt functions.
  • πŸ“± Cross-Platform - Works on Windows, macOS, and Linux
  • 🎯 Type Safe - Full TypeScript support with comprehensive type definitions
  • ⚑ Zero Dependencies - No runtime dependencies, maximum performance
  • πŸ”„ Auto-Recovery - Graceful handling of corrupted or missing files

πŸ“¦ Installation

Install the package using your preferred package manager:

npm install @pitzzahh/signaldb-adapter-tauri
yarn add @pitzzahh/signaldb-adapter-tauri
pnpm add @pitzzahh/signaldb-adapter-tauri
bun add @pitzzahh/signaldb-adapter-tauri

πŸš€ Quick Start

Basic Usage

import { Collection } from '@signaldb/core';
import { createTauriFileSystemAdapter } from '@pitzzahh/signaldb-adapter-tauri';

// Create a collection with filesystem persistence
const users = new Collection({
  name: 'users',
  persistence: createTauriFileSystemAdapter('users.json')
});

// Your data is now automatically persisted to the filesystem!
users.insert({ name: 'John Doe', email: 'john@example.com' });

⚠️ Production apps should use encryption. The example above stores data in plaintext. See With Encryption below to enable built-in AES-256-GCM encryption in one line.

πŸ“– Need more examples? Check out our Usage Examples in the wiki.

With Encryption

Use the built-in AES-256-GCM encryption (recommended):

import { createEncryption } from '@pitzzahh/signaldb-adapter-tauri';

// AES-256-GCM authenticated encryption with PBKDF2 key derivation
const { encrypt, decrypt } = createEncryption('your-strong-passphrase');

const adapter = createTauriFileSystemAdapter('secure-data.json', {
  encrypt,
  decrypt,
  security: { enforceEncryption: true, allowPlaintextFallback: false }
});

Or bring your own encryption functions with full control over the algorithm:

const adapter = createTauriFileSystemAdapter('secure-data.json', {
  encrypt: async (data) => yourCustomEncrypt(data),
  decrypt: async (data) => yourCustomDecrypt(data)
});

πŸ” Need key rotation? createEncryption supports versioned passphrases. See our Security Guide for production-ready examples.

With Custom Base Directory

import { BaseDirectory } from '@tauri-apps/plugin-fs';

const adapter = createTauriFileSystemAdapter('app-data.json', {
  base_dir: BaseDirectory.AppConfig
});

πŸ“ Learn about all storage options: Storage Configuration

API Reference

createTauriFileSystemAdapter(filename, options?)

Creates a new persistence adapter instance.

Parameters

Parameter Type Required Description
filename string βœ… Name of the file to store data in
options AdapterOptions ❌ Configuration options

Options

Option Type Default Description
base_dir BaseDirectory AppLocalData Tauri base directory for file storage
encrypt EncryptFunction<T> undefined Custom encryption function
decrypt DecryptFunction<T> undefined Custom decryption function
security Partial<SecurityOptions> {} Security configuration options

Type Definitions

export type EncryptFunction<T> = (data: T[]) => Promise<string>;
export type DecryptFunction<T> = (encrypted: string) => Promise<T[]>;

export interface SecurityOptions {
  /** Whether to enforce encryption (throw error if encrypt/decrypt not provided) */
  enforceEncryption: boolean;
  /** Whether to allow fallback to plaintext on decryption failure */
  allowPlaintextFallback: boolean;
  /** Whether to validate decrypted data structure */
  validateDecryptedData: boolean;
  /** Whether callback errors should propagate */
  propagateCallbackErrors: boolean;
  /** Custom data validator function */
  dataValidator: <T>(data: unknown) => data is T[];
  /** Whether to create backup files on save (default: false for sync scenarios) */
  createBackups: boolean;
  /** Maximum number of backup files to keep (default: 5) */
  maxBackups: number;
}

export interface AdapterOptions<T> {
  base_dir?: import('@tauri-apps/plugin-fs').BaseDirectory;
  encrypt?: EncryptFunction<T>;
  decrypt?: DecryptFunction<T>;
  security?: Partial<SecurityOptions>;
}

πŸ“š For complete API documentation and advanced configuration options, visit our Wiki.

πŸ› οΈ Requirements

  • Tauri: v2.0+ with @tauri-apps/plugin-fs
  • SignalDB: v1.0+
  • Node.js: v18.0+
  • TypeScript: v5.0+ (recommended)

Note: This adapter has zero runtime dependencies. All required packages are peer dependencies that should already be installed in your Tauri + SignalDB project.

πŸ“‚ Storage Locations

Files are stored in platform-specific directories:

Platform Default Location
Linux ~/.local/share/[app-name]/
Windows %APPDATA%/[app-name]/
macOS ~/Library/Application Support/[app-name]/

πŸ—‚οΈ Need help with custom storage locations? Check our Storage Configuration Guide.

πŸ“– Documentation

For detailed guides and examples, visit our Wiki:

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • SignalDB - The reactive database this adapter is built for
  • Tauri - The framework that makes secure desktop apps possible
  • Bun - The fast JavaScript runtime used for development

Built with ❀️ by Peter John Arao

About

A SignalDB persistence adapter for Tauri apps with encryption support

Topics

Resources

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages