@powersync/node
Enumerations
| Enumeration | Description |
|---|---|
| AttachmentState | AttachmentState represents the current synchronization state of an attachment. |
| ColumnType | - |
| DiffTriggerOperation | SQLite operations to track changes for with TriggerManager |
| EncodingType | - |
| FetchStrategy | - |
| LockType | - |
| OpTypeEnum | - |
| PowerSyncControlCommand | - |
| PSInternalTable | - |
| RowUpdateType | Update table operation numbers from SQLite |
| SyncClientImplementation | - |
| SyncStreamConnectionMethod | - |
| UpdateType | Type of local change. |
| WatchedQueryListenerEvent | - |
Classes
| Class | Description |
|---|---|
| AbortOperation | Calls to Abortcontroller.abort(reason: any) will result in the reason being thrown. This is not necessarily an error, but extends error for better logging purposes. |
| AbstractPowerSyncDatabase | - |
| AbstractPowerSyncDatabaseOpenFactory | - |
| AbstractQueryProcessor | Performs underlying watching and yields a stream of results. |
| AbstractRemote | - |
| AbstractStreamingSyncImplementation | - |
| ArrayComparator | An efficient comparator for WatchedQuery created with Query#watch. This has the ability to determine if a query result has changes without necessarily processing all items in the result. |
| AttachmentContext | AttachmentContext provides database operations for managing attachment records. |
| AttachmentQueue | AttachmentQueue manages the lifecycle and synchronization of attachments between local and remote storage. Provides automatic synchronization, upload/download queuing, attachment monitoring, verification and repair of local files, and cleanup of archived attachments. |
| AttachmentService | Service for querying and watching attachment records in the database. |
| AttachmentTable | AttachmentTable defines the schema for the attachment queue table. |
| BaseObserver | - |
| Column | - |
| ConnectionClosedError | Thrown when an underlying database connection is closed. This is particularly relevant when worker connections are marked as closed while operations are still in progress. |
| ConnectionManager | - |
| ControlledExecutor | - |
| CrudBatch | A batch of client-side changes. |
| CrudEntry | A single client-side change. |
| CrudTransaction | A batch of client-side changes. |
| DataStream | A very basic implementation of a data stream with backpressure support which does not use native JS streams or async iterators. This is handy for environments such as React Native which need polyfills for the above. |
| DifferentialQueryProcessor | Uses the PowerSync onChange event to trigger watched queries. Results are emitted on every change of the relevant tables. |
| FetchImplementationProvider | Class wrapper for providing a fetch implementation. The class wrapper is used to distinguish the fetchImplementation option in [AbstractRemoteOptions] from the general fetch method which is typeof "function" |
| GetAllQuery | Performs a AbstractPowerSyncDatabase.getAll operation for a watched query. |
| Index | - |
| IndexedColumn | - |
| NodeFileSystemAdapter | NodeFileSystemAdapter implements LocalStorageAdapter using Node.js filesystem. Suitable for Node.js environments and Electron applications. |
| OnChangeQueryProcessor | Uses the PowerSync onChange event to trigger watched queries. Results are emitted on every change of the relevant tables. |
| OplogEntry | - |
| OpType | Used internally for sync buckets. |
| PowerSyncDatabase | A PowerSync database which provides SQLite functionality which is automatically synced. |
| RawTable | Instructs PowerSync to sync data into a "raw" table. |
| Schema | A schema is a collection of tables. It is used to define the structure of a database. |
| SqliteBucketStorage | - |
| SyncDataBatch | - |
| SyncDataBucket | - |
| SyncingService | Orchestrates attachment synchronization between local and remote storage. Handles uploads, downloads, deletions, and state transitions. |
| SyncProgress | Provides realtime progress on how PowerSync is downloading rows. |
| SyncStatus | - |
| Table | - |
| Generate a new table from the columns and indexes | |
| TriggerManagerImpl | - |
| UploadQueueStats | - |
Interfaces
AbstractQueryProcessorOptions<Data, Settings>
Internal
Extended by
Type Parameters
| Type Parameter | Default type |
|---|---|
Data | - |
Settings extends WatchedQueryOptions | WatchedQueryOptions |
Properties
| Property | Type |
|---|---|
db | AbstractPowerSyncDatabase |
placeholderData | Data |
watchOptions | Settings |
AbstractStreamingSyncImplementationOptions
Internal
Extends
Properties
| Property | Type | Description | Overrides | Inherited from |
|---|---|---|---|---|
adapter | BucketStorageAdapter | - | - | - |
crudUploadThrottleMs | number | Backend Connector CRUD operations are throttled to occur at most every crudUploadThrottleMs milliseconds. | - | RequiredAdditionalConnectionOptions.crudUploadThrottleMs |
identifier? | string | An identifier for which PowerSync DB this sync implementation is linked to. Most commonly DB name, but not restricted to DB name. | - | - |
logger? | ILogger | - | - | - |
remote | AbstractRemote | - | - | - |
retryDelayMs | number | Delay for retrying sync streaming operations from the PowerSync backend after an error occurs. | - | RequiredAdditionalConnectionOptions.retryDelayMs |
subscriptions | SubscribedStream[] | - | RequiredAdditionalConnectionOptions.subscriptions | - |
uploadCrud | () => Promise<void> | - | - | - |
AdditionalConnectionOptions
Internal
Extended by
Properties
ArrayQueryDefinition<RowType>
Options for building a query with AbstractPowerSyncDatabase#query. This query will be executed with AbstractPowerSyncDatabase#getAll.
Type Parameters
| Type Parameter | Default type |
|---|---|
RowType | unknown |
Properties
| Property | Type | Description |
|---|---|---|
mapper? | (row: Record<string, unknown>) => RowType | Maps the raw SQLite row to a custom typed object. Example mapper: (row) => ({ ...row, created_at: new Date(row.created_at as string), }) |
parameters? | readonly Readonly<QueryParam>[] | - |
sql | string | - |
AttachmentErrorHandler
Experimental Alpha
SyncErrorHandler provides custom error handling for attachment sync operations. Implementations determine whether failed operations should be retried or archived.
This is currently experimental and may change without a major version bump.
Methods
onDeleteError()
onDeleteError(attachment, error): Promise<boolean>
Alpha
Parameters
| Parameter | Type | Description |
|---|---|---|
attachment | AttachmentRecord | The attachment that failed to delete |
error | unknown | The error encountered during the delete |
Returns
Promise<boolean>
true to retry the operation, false to archive the attachment
onDownloadError()
onDownloadError(attachment, error): Promise<boolean>
Alpha
Parameters
| Parameter | Type | Description |
|---|---|---|
attachment | AttachmentRecord | The attachment that failed to download |
error | unknown | The error encountered during the download |
Returns
Promise<boolean>
true to retry the operation, false to archive the attachment
onUploadError()
onUploadError(attachment, error): Promise<boolean>
Alpha
Parameters
| Parameter | Type | Description |
|---|---|---|
attachment | AttachmentRecord | The attachment that failed to upload |
error | unknown | The error encountered during the upload |
Returns
Promise<boolean>
true to retry the operation, false to archive the attachment
AttachmentRecord
Experimental
AttachmentRecord represents an attachment in the local database.
Properties
| Property | Type | Description |
|---|---|---|
filename | string | Experimental |
hasSynced? | boolean | Experimental |
id | string | Experimental |
localUri? | string | Experimental |
mediaType? | string | Experimental |
metaData? | string | Experimental |
size? | number | Experimental |
state | AttachmentState | Experimental |
timestamp? | number | Experimental |
AttachmentTableOptions
Extends
Omit<TableV2Options,"name"|"columns">
Properties
| Property | Type | Inherited from |
|---|---|---|
ignoreEmptyUpdates? | boolean | Omit.ignoreEmptyUpdates |
indexes? | IndexShorthand | Omit.indexes |
insertOnly? | boolean | Omit.insertOnly |
localOnly? | boolean | Omit.localOnly |
trackMetadata? | boolean | Omit.trackMetadata |
trackPrevious? | boolean | TrackPreviousOptions | Omit.trackPrevious |
viewName? | string | Omit.viewName |
BaseConnectionOptions
Internal
Extended by
Properties
| Property | Type | Description |
|---|---|---|
appMetadata? | Record<string, string> | A set of metadata to be included in service logs. |
clientImplementation? | SyncClientImplementation | Whether to use a JavaScript implementation to handle received sync lines from the sync service, or whether this work should be offloaded to the PowerSync core extension. This defaults to the JavaScript implementation (SyncClientImplementation.JAVASCRIPT) since the (SyncClientImplementation.RUST) implementation is experimental at the moment. |
connectionMethod? | SyncStreamConnectionMethod | The connection method to use when streaming updates from the PowerSync backend instance. Defaults to a HTTP streaming connection. |
fetchStrategy? | FetchStrategy | The fetch strategy to use when streaming updates from the PowerSync backend instance. |
includeDefaultStreams? | boolean | Whether to include streams that have auto_subscribe: true in their definition. This defaults to true. |
params? | Record<string, JSONValue> | These parameters are passed to the sync rules, and will be available under theuser_parameters object. |
serializedSchema? | any | The serialized schema - mainly used to forward information about raw tables to the sync client. |
BaseObserverInterface<T>
Extended by
Type Parameters
| Type Parameter |
|---|
T extends BaseListener |
Methods
registerListener()
registerListener(listener): () => void
Parameters
| Parameter | Type |
|---|---|
listener | Partial<T> |
Returns
Function
Returns
void
BasePowerSyncDatabaseOptions
Internal
Extends
Extended by
PowerSyncDatabaseOptionsPowerSyncDatabaseOptionsWithDBAdapterPowerSyncDatabaseOptionsWithOpenFactoryPowerSyncDatabaseOptionsWithSettings
Properties
| Property | Type | Description | Inherited from |
|---|---|---|---|
crudUploadThrottleMs? | number | Backend Connector CRUD operations are throttled to occur at most every crudUploadThrottleMs milliseconds. | AdditionalConnectionOptions.crudUploadThrottleMs |
logger? | ILogger | - | - |
retryDelay? | number | Deprecated Use retryDelayMs instead as this will be removed in future releases. | - |
retryDelayMs? | number | Delay for retrying sync streaming operations from the PowerSync backend after an error occurs. | AdditionalConnectionOptions.retryDelayMs |
schema | Schema | Schema used for the local database. | - |
BaseTriggerDiffRecord<TOperationId>
Experimental
Diffs created by TriggerManager#createDiffTrigger are stored in a temporary table. This is the base record structure for all diff records.
Extended by
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
TOperationId extends string | number | number | The type for operation_id. Defaults to number as returned by default SQLite database queries. Use string for full 64-bit precision when using { castOperationIdAsText: true } option. |
Properties
| Property | Type | Description |
|---|---|---|
id | string | Experimental The modified row's id column value. |
operation | DiffTriggerOperation | Experimental The operation performed which created this record. |
operation_id | TOperationId | Experimental Auto-incrementing primary key for the operation. Defaults to number as returned by database queries (wa-sqlite returns lower 32 bits). Can be string for full 64-bit precision when using { castOperationIdAsText: true } option. |
timestamp | string | Experimental Time the change operation was recorded. This is in ISO 8601 format, e.g. 2023-10-01T12:00:00.000Z. |
BatchedUpdateNotification
Properties
| Property | Type |
|---|---|
groupedUpdates | Record<string, TableUpdateOperation[]> |
rawUpdates | UpdateNotification[] |
tables | string[] |
BucketChecksum
Properties
BucketDescription
Properties
| Property | Type |
|---|---|
name | string |
priority | number |
BucketRequest
Properties
| Property | Type | Description |
|---|---|---|
after | string | Base-10 number. Sync all data from this bucket with op_id > after. |
name | string | - |
BucketState
Properties
| Property | Type |
|---|---|
bucket | string |
op_id | string |
BucketStorageAdapter
Extends
Properties
| Property | Type | Inherited from |
|---|---|---|
dispose | () => void | Promise<void> | Disposable.dispose |
Methods
control()
control(op, payload): Promise<string>
Invokes the powersync_control function for the sync client.
Parameters
| Parameter | Type |
|---|---|
op | PowerSyncControlCommand |
payload | null | string | Uint8Array<ArrayBufferLike> |
Returns
Promise<string>
getBucketOperationProgress()
getBucketOperationProgress(): Promise<BucketOperationProgress>
Returns
Promise<BucketOperationProgress>
getBucketStates()
getBucketStates(): Promise<BucketState[]>
Returns
Promise<BucketState[]>
getClientId()
getClientId(): Promise<string>
Get an unique client id.
Returns
Promise<string>
getCrudBatch()
getCrudBatch(limit?): Promise<null | CrudBatch>
Parameters
| Parameter | Type |
|---|---|
limit? | number |
Returns
Promise<null | CrudBatch>
getMaxOpId()
getMaxOpId(): string
Returns
string
hasCompletedSync()
hasCompletedSync(): Promise<boolean>