PowerSync JS SDK

website·Indexed 29 days ago

https://powersync-ja.github.io/powersync-js/

Technical reference and API documentation for PowerSync JavaScript SDKs, including specialized implementations for Web, React Native, Node.js, Vue, Tauri, and TanStack React Query. Covers database schema definitions, sync stream management, and platform-specific hooks and classes.

Tokens
130.7K
Snippets
948
Records
1.2K
Agent score
74%

What's inside PowerSync

  1. Overview of StreamingLocalStorageAdapter

    The StreamingLocalStorageAdapter is an experimental (Alpha) interface that extends LocalStorageAdapter. It is specifically designed to relocate files into managed storage without loading them into memory. This capability is required for AttachmentQueue.saveFileFromUri; only queues configured with a streaming-capable local adapter will expose that method.
  2. Overview of AttachmentQueue

    The AttachmentQueue class manages the lifecycle and synchronization of attachments between local and remote storage. It provides automatic synchronization, upload/download queuing, attachment monitoring, verification and repair of local files, and cleanup of archived attachments. Note: This class is currently in Alpha/Experimental status and may change without a major version bump.
  3. Overview of AttachmentQueue

    The AttachmentQueue class manages the synchronization of attachments between local and remote storage. It provides automatic synchronization, upload/download queuing, attachment monitoring, verification and repair of local files, and cleanup of archived attachments. Note that this class is currently in Alpha/Experimental status and may change without a major version bump.
  4. Understand the WatchOnChangeEvent properties

    The WatchOnChangeEvent provides information about which tables have changed during a watch event. It contains a single property, changedTables, which is an array of strings listing the names of the tables that were modified.
    interface WatchOnChangeEvent {
      changedTables: string[];
    }
  5. Understand the AttachmentRecord structure

    The AttachmentRecord (Alpha) represents an attachment stored in the local database. It contains metadata about the file, its sync state, and its local location.
    interface AttachmentRecord {
      id: string;
      filename: string;
      state: AttachmentState;
      hasSynced?: boolean;
      localUri?: string;
      mediaType?: string;
      metaData?: string;
      size?: number;
      timestamp?: number;
    }
  6. Use BaseObserver to manage event listeners

    The BaseObserver<T> class provides a base implementation for observing updates in the PowerSync client. It allows for registering listeners and iterating over them synchronously or asynchronously. It implements the BaseObserverInterface<T> and is extended by the DBAdapter class. The type parameter T must extend BaseListener.
  7. Understand the CrudEntry structure

    A CrudEntry represents a single client-side change. It contains details about the operation type, the affected table, and the data changed.
    interface CrudEntry {
      clientId: number;        // Auto-incrementing client-side id
      id: string;              // ID of the changed row
      metadata?: string;       // Client-side metadata (available if trackMetadata is true)
      op: UpdateType;          // Type of change
      opData?: Record<string, any>; // Data associated with the change
      previousValues?: Record<string, any>; // Previous values (available if trackPreviousValues is true)
      table: string;           // Table that contained the change
      transactionId?: number;  // Auto-incrementing transaction id
    }
  8. Implement custom attachment error handling with SyncErrorHandler

    The SyncErrorHandler interface (currently Experimental/Alpha) allows you to define custom logic for handling failures during attachment sync operations. By implementing this interface, you can determine whether a failed operation should be retried or if the attachment should be archived. This is useful for implementing retry strategies or logging specific sync failures.
  9. Use GetAllQuery to fetch all records for a watched query

    The GetAllQuery<RowType> class is used to perform a DBGetUtils.getAll operation for a watched query. It implements the WatchCompatibleQuery<RowType[]> interface, allowing it to be used in contexts where watched queries are required. The RowType type parameter defines the structure of the rows returned by the query, defaulting to unknown.
    // Example instantiation
    const query = new GetAllQuery<MyRowType>(options);