@powersync/web
Enumerations
| Enumeration | Description |
|---|---|
| ColumnType | - |
| DiffTriggerOperation | SQLite operations to track changes for with TriggerManager |
| FetchStrategy | - |
| LockType | - |
| OpTypeEnum | - |
| PowerSyncControlCommand | - |
| PSInternalTable | - |
| RowUpdateType | Update table operation numbers from SQLite |
| SyncClientImplementation | - |
| SyncStreamConnectionMethod | - |
| TemporaryStorageOption | - |
| UpdateType | Type of local change. |
| WASQLiteVFS | List of currently tested virtual filesystems |
| 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 | - |
| AbstractWebPowerSyncDatabaseOpenFactory | Intermediate PowerSync Database Open factory for Web which uses a mock SSR DB Adapter if running on server side. Most SQLite DB implementations only run on client side, this will safely return empty query results in SSR which will allow for generating server partial views. |
| AbstractWebSQLOpenFactory | - |
| 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. |
| BaseObserver | - |
| Column | - |
| 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 | - |
| 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. |
| Schema | A schema is a collection of tables. It is used to define the structure of a database. |
| SharedWebStreamingSyncImplementation | The local part of the sync implementation on the web, which talks to a sync implementation hosted in a shared worker. |
| SqliteBucketStorage | - |
| SyncDataBatch | - |
| SyncDataBucket | - |
| SyncProgress | Provides realtime progress on how PowerSync is downloading rows. |
| SyncStatus | - |
| Table | - |
| Generate a new table from the columns and indexes | |
| UploadQueueStats | - |
| WASqliteConnection | WA-SQLite connection which directly interfaces with WA-SQLite. This is usually instantiated inside a worker. |
| WASQLiteDBAdapter | Adapter for WA-SQLite SQLite connections. |
| WASQLiteOpenFactory | Opens a SQLite connection using WA-SQLite. |
| - | |
| WebRemote | - |
| WebStreamingSyncImplementation | - |
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
Extended by
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 | - |
AsyncDatabaseConnection<Config>
Internal
An async Database connection which provides basic async SQL methods. This is usually a proxied through a web worker.
Type Parameters
| Type Parameter | Default type |
|---|---|
Config extends ResolvedWebSQLOpenOptions | ResolvedWebSQLOpenOptions |
Methods
close()
close(): Promise<void>
Returns
Promise<void>
execute()
execute(sql, params?): Promise<ProxiedQueryResult>
Parameters
| Parameter | Type |
|---|---|
sql | string |
params? | any[] |
Returns
Promise<ProxiedQueryResult>
executeBatch()
executeBatch(sql, params?): Promise<ProxiedQueryResult>
Parameters
| Parameter | Type |
|---|---|
sql | string |
params? | any[] |
Returns
Promise<ProxiedQueryResult>
executeRaw()
executeRaw(sql, params?): Promise<any[][]>
Parameters
| Parameter | Type |
|---|---|
sql | string |
params? | any[] |
Returns
Promise<any[][]>
getConfig()
getConfig(): Promise<Config>
Returns
Promise<Config>
init()
init(): Promise<void>
Returns
Promise<void>
isAutoCommit()
isAutoCommit(): Promise<boolean>
Checks if the database connection is in autocommit mode.
Returns
Promise<boolean>
true if in autocommit mode, false if in a transaction
markHold()
markHold(): Promise<string>
Marks the connection as in-use by a certain actor.
Returns
Promise<string>
A hold ID which can be used to release the hold.
registerOnTableChange()
registerOnTableChange(callback): Promise<() => void>
Parameters
| Parameter | Type |
|---|---|
callback | OnTableChangeCallback |
Returns
Promise<() => void>
releaseHold()
releaseHold(holdId): Promise<void>
Releases a hold on the connection.
Parameters
| Parameter | Type | Description |
|---|---|---|
holdId | string | The hold ID to release. |
Returns
Promise<void>
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>
Returns
Promise<boolean>
hasCrud()
hasCrud(): Promise<boolean>
Returns
Promise<boolean>
hasMigratedSubkeys()
hasMigratedSubkeys(): Promise<boolean>
Returns
Promise<boolean>
init()
init(): Promise<void>
Returns
Promise<void>
migrateToFixedSubkeys()
migrateToFixedSubkeys(): Promise<void>
Returns
Promise<void>
nextCrudItem()
nextCrudItem(): Promise<undefined | CrudEntry>
Returns
Promise<undefined | CrudEntry>
registerListener()
registerListener(listener): () => void
Parameters
| Parameter | Type |
|---|---|
listener | Partial<BucketStorageListener> |
Returns
Function
Returns
void
Inherited from
BaseObserverInterface.registerListener
removeBuckets()
removeBuckets(buckets): Promise<void>
Parameters
| Parameter | Type |
|---|---|
buckets | string[] |
Returns
Promise<void>
saveSyncData()
saveSyncData(batch, fixedKeyFormat?): Promise<void>
Parameters
| Parameter | Type |
|---|---|
batch | SyncDataBatch |
fixedKeyFormat? | boolean |
Returns
Promise<void>
setTargetCheckpoint()
setTargetCheckpoint(checkpoint): Promise<void>
Parameters
| Parameter | Type |
|---|---|
checkpoint | Checkpoint |