@powersync/common 1.46.0 → 1.48.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/dist/bundle.cjs +1298 -395
- package/dist/bundle.cjs.map +1 -1
- package/dist/bundle.mjs +1291 -395
- package/dist/bundle.mjs.map +1 -1
- package/dist/bundle.node.cjs +1298 -395
- package/dist/bundle.node.cjs.map +1 -1
- package/dist/bundle.node.mjs +1291 -395
- package/dist/bundle.node.mjs.map +1 -1
- package/dist/index.d.cts +652 -106
- package/lib/attachments/AttachmentContext.d.ts +86 -0
- package/lib/attachments/AttachmentContext.js +229 -0
- package/lib/attachments/AttachmentContext.js.map +1 -0
- package/lib/attachments/AttachmentErrorHandler.d.ts +31 -0
- package/lib/attachments/AttachmentErrorHandler.js +2 -0
- package/lib/attachments/AttachmentErrorHandler.js.map +1 -0
- package/lib/attachments/AttachmentQueue.d.ts +149 -0
- package/lib/attachments/AttachmentQueue.js +362 -0
- package/lib/attachments/AttachmentQueue.js.map +1 -0
- package/lib/attachments/AttachmentService.d.ts +29 -0
- package/lib/attachments/AttachmentService.js +56 -0
- package/lib/attachments/AttachmentService.js.map +1 -0
- package/lib/attachments/LocalStorageAdapter.d.ts +62 -0
- package/lib/attachments/LocalStorageAdapter.js +6 -0
- package/lib/attachments/LocalStorageAdapter.js.map +1 -0
- package/lib/attachments/RemoteStorageAdapter.d.ts +27 -0
- package/lib/attachments/RemoteStorageAdapter.js +2 -0
- package/lib/attachments/RemoteStorageAdapter.js.map +1 -0
- package/lib/attachments/Schema.d.ts +50 -0
- package/lib/attachments/Schema.js +62 -0
- package/lib/attachments/Schema.js.map +1 -0
- package/lib/attachments/SyncingService.d.ts +62 -0
- package/lib/attachments/SyncingService.js +168 -0
- package/lib/attachments/SyncingService.js.map +1 -0
- package/lib/attachments/WatchedAttachmentItem.d.ts +17 -0
- package/lib/attachments/WatchedAttachmentItem.js +2 -0
- package/lib/attachments/WatchedAttachmentItem.js.map +1 -0
- package/lib/db/schema/RawTable.d.ts +61 -26
- package/lib/db/schema/RawTable.js +1 -32
- package/lib/db/schema/RawTable.js.map +1 -1
- package/lib/db/schema/Schema.d.ts +14 -7
- package/lib/db/schema/Schema.js +25 -3
- package/lib/db/schema/Schema.js.map +1 -1
- package/lib/db/schema/Table.d.ts +13 -8
- package/lib/db/schema/Table.js +3 -8
- package/lib/db/schema/Table.js.map +1 -1
- package/lib/db/schema/internal.d.ts +12 -0
- package/lib/db/schema/internal.js +15 -0
- package/lib/db/schema/internal.js.map +1 -0
- package/lib/index.d.ts +11 -1
- package/lib/index.js +10 -1
- package/lib/index.js.map +1 -1
- package/lib/utils/mutex.d.ts +1 -1
- package/lib/utils/mutex.js.map +1 -1
- package/package.json +1 -1
- package/src/attachments/AttachmentContext.ts +279 -0
- package/src/attachments/AttachmentErrorHandler.ts +34 -0
- package/src/attachments/AttachmentQueue.ts +472 -0
- package/src/attachments/AttachmentService.ts +62 -0
- package/src/attachments/LocalStorageAdapter.ts +72 -0
- package/src/attachments/README.md +718 -0
- package/src/attachments/RemoteStorageAdapter.ts +30 -0
- package/src/attachments/Schema.ts +87 -0
- package/src/attachments/SyncingService.ts +193 -0
- package/src/attachments/WatchedAttachmentItem.ts +19 -0
- package/src/db/schema/RawTable.ts +66 -31
- package/src/db/schema/Schema.ts +27 -2
- package/src/db/schema/Table.ts +11 -11
- package/src/db/schema/internal.ts +17 -0
- package/src/index.ts +12 -1
- package/src/utils/mutex.ts +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1452,68 +1452,6 @@ declare class Column {
|
|
|
1452
1452
|
};
|
|
1453
1453
|
}
|
|
1454
1454
|
|
|
1455
|
-
/**
|
|
1456
|
-
* A pending variant of a {@link RawTable} that doesn't have a name (because it would be inferred when creating the
|
|
1457
|
-
* schema).
|
|
1458
|
-
*/
|
|
1459
|
-
type RawTableType = {
|
|
1460
|
-
/**
|
|
1461
|
-
* The statement to run when PowerSync detects that a row needs to be inserted or updated.
|
|
1462
|
-
*/
|
|
1463
|
-
put: PendingStatement;
|
|
1464
|
-
/**
|
|
1465
|
-
* The statement to run when PowerSync detects that a row needs to be deleted.
|
|
1466
|
-
*/
|
|
1467
|
-
delete: PendingStatement;
|
|
1468
|
-
};
|
|
1469
|
-
/**
|
|
1470
|
-
* A parameter to use as part of {@link PendingStatement}.
|
|
1471
|
-
*
|
|
1472
|
-
* For delete statements, only the `"Id"` value is supported - the sync client will replace it with the id of the row to
|
|
1473
|
-
* be synced.
|
|
1474
|
-
*
|
|
1475
|
-
* For insert and replace operations, the values of columns in the table are available as parameters through
|
|
1476
|
-
* `{Column: 'name'}`.
|
|
1477
|
-
*/
|
|
1478
|
-
type PendingStatementParameter = 'Id' | {
|
|
1479
|
-
Column: string;
|
|
1480
|
-
};
|
|
1481
|
-
/**
|
|
1482
|
-
* A statement that the PowerSync client should use to insert or delete data into a table managed by the user.
|
|
1483
|
-
*/
|
|
1484
|
-
type PendingStatement = {
|
|
1485
|
-
sql: string;
|
|
1486
|
-
params: PendingStatementParameter[];
|
|
1487
|
-
};
|
|
1488
|
-
/**
|
|
1489
|
-
* Instructs PowerSync to sync data into a "raw" table.
|
|
1490
|
-
*
|
|
1491
|
-
* Since raw tables are not backed by JSON, running complex queries on them may be more efficient. Further, they allow
|
|
1492
|
-
* using client-side table and column constraints.
|
|
1493
|
-
*
|
|
1494
|
-
* To collect local writes to raw tables with PowerSync, custom triggers are required. See
|
|
1495
|
-
* {@link https://docs.powersync.com/usage/use-case-examples/raw-tables the documentation} for details and an example on
|
|
1496
|
-
* using raw tables.
|
|
1497
|
-
*
|
|
1498
|
-
* Note that raw tables are only supported when using the new `SyncClientImplementation.rust` sync client.
|
|
1499
|
-
*
|
|
1500
|
-
* @experimental Please note that this feature is experimental at the moment, and not covered by PowerSync semver or
|
|
1501
|
-
* stability guarantees.
|
|
1502
|
-
*/
|
|
1503
|
-
declare class RawTable implements RawTableType {
|
|
1504
|
-
/**
|
|
1505
|
-
* The name of the table.
|
|
1506
|
-
*
|
|
1507
|
-
* This does not have to match the actual table name in the schema - {@link put} and {@link delete} are free to use
|
|
1508
|
-
* another table. Instead, this name is used by the sync client to recognize that operations on this table (as it
|
|
1509
|
-
* appears in the source / backend database) are to be handled specially.
|
|
1510
|
-
*/
|
|
1511
|
-
name: string;
|
|
1512
|
-
put: PendingStatement;
|
|
1513
|
-
delete: PendingStatement;
|
|
1514
|
-
constructor(name: string, type: RawTableType);
|
|
1515
|
-
}
|
|
1516
|
-
|
|
1517
1455
|
interface IndexColumnOptions {
|
|
1518
1456
|
name: string;
|
|
1519
1457
|
ascending?: boolean;
|
|
@@ -1561,14 +1499,19 @@ declare class Index {
|
|
|
1561
1499
|
declare class TableV2<Columns extends ColumnsType = ColumnsType> extends Table<Columns> {
|
|
1562
1500
|
}
|
|
1563
1501
|
|
|
1564
|
-
|
|
1502
|
+
/**
|
|
1503
|
+
* Options that apply both to JSON-based tables and raw tables.
|
|
1504
|
+
*/
|
|
1505
|
+
interface TableOrRawTableOptions {
|
|
1565
1506
|
localOnly?: boolean;
|
|
1566
1507
|
insertOnly?: boolean;
|
|
1567
|
-
viewName?: string;
|
|
1568
1508
|
trackPrevious?: boolean | TrackPreviousOptions;
|
|
1569
1509
|
trackMetadata?: boolean;
|
|
1570
1510
|
ignoreEmptyUpdates?: boolean;
|
|
1571
1511
|
}
|
|
1512
|
+
interface SharedTableOptions extends TableOrRawTableOptions {
|
|
1513
|
+
viewName?: string;
|
|
1514
|
+
}
|
|
1572
1515
|
/** Whether to include previous column values when PowerSync tracks local changes.
|
|
1573
1516
|
*
|
|
1574
1517
|
* Including old values may be helpful for some backend connector implementations, which is
|
|
@@ -1692,14 +1635,14 @@ declare class Table<Columns extends ColumnsType = ColumnsType> {
|
|
|
1692
1635
|
get validName(): boolean;
|
|
1693
1636
|
validate(): void;
|
|
1694
1637
|
toJSON(): {
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
local_only: boolean;
|
|
1698
|
-
insert_only: boolean;
|
|
1638
|
+
local_only: boolean | undefined;
|
|
1639
|
+
insert_only: boolean | undefined;
|
|
1699
1640
|
include_old: any;
|
|
1700
1641
|
include_old_only_when_changed: boolean;
|
|
1701
|
-
include_metadata: boolean;
|
|
1702
|
-
ignore_empty_update: boolean;
|
|
1642
|
+
include_metadata: boolean | undefined;
|
|
1643
|
+
ignore_empty_update: boolean | undefined;
|
|
1644
|
+
name: string;
|
|
1645
|
+
view_name: string;
|
|
1703
1646
|
columns: {
|
|
1704
1647
|
name: string;
|
|
1705
1648
|
type: ColumnType | undefined;
|
|
@@ -1715,6 +1658,101 @@ declare class Table<Columns extends ColumnsType = ColumnsType> {
|
|
|
1715
1658
|
};
|
|
1716
1659
|
}
|
|
1717
1660
|
|
|
1661
|
+
/**
|
|
1662
|
+
* Instructs PowerSync to sync data into a "raw" table.
|
|
1663
|
+
*
|
|
1664
|
+
* Since raw tables are not backed by JSON, running complex queries on them may be more efficient. Further, they allow
|
|
1665
|
+
* using client-side table and column constraints.
|
|
1666
|
+
*
|
|
1667
|
+
* To collect local writes to raw tables with PowerSync, custom triggers are required. See
|
|
1668
|
+
* {@link https://docs.powersync.com/usage/use-case-examples/raw-tables the documentation} for details and an example on
|
|
1669
|
+
* using raw tables.
|
|
1670
|
+
*
|
|
1671
|
+
* Note that raw tables are only supported when using the new `SyncClientImplementation.rust` sync client.
|
|
1672
|
+
*
|
|
1673
|
+
* @experimental Please note that this feature is experimental at the moment, and not covered by PowerSync semver or
|
|
1674
|
+
* stability guarantees.
|
|
1675
|
+
*/
|
|
1676
|
+
type RawTableType = RawTableTypeWithStatements | InferredRawTableType;
|
|
1677
|
+
interface RawTableTypeWithStatements {
|
|
1678
|
+
/**
|
|
1679
|
+
* The statement to run when PowerSync detects that a row needs to be inserted or updated.
|
|
1680
|
+
*/
|
|
1681
|
+
put: PendingStatement;
|
|
1682
|
+
/**
|
|
1683
|
+
* The statement to run when PowerSync detects that a row needs to be deleted.
|
|
1684
|
+
*/
|
|
1685
|
+
delete: PendingStatement;
|
|
1686
|
+
/**
|
|
1687
|
+
* An optional statement to run when `disconnectAndClear()` is called on a PowerSync database.
|
|
1688
|
+
*/
|
|
1689
|
+
clear?: string;
|
|
1690
|
+
}
|
|
1691
|
+
/**
|
|
1692
|
+
* The schema of a {@link RawTableType} in the local database.
|
|
1693
|
+
*
|
|
1694
|
+
* This information is optional when declaring raw tables. However, providing it allows the sync client to infer `put`
|
|
1695
|
+
* and `delete` statements automatically.
|
|
1696
|
+
*/
|
|
1697
|
+
interface RawTableSchema extends TableOrRawTableOptions {
|
|
1698
|
+
/**
|
|
1699
|
+
* The actual name of the raw table in the local schema.
|
|
1700
|
+
*
|
|
1701
|
+
* Unlike {@link RawTable.name}, which describes the name of synced tables to match, this reflects the SQLite table
|
|
1702
|
+
* name. This is used to infer {@link RawTableType.put} and {@link RawTableType.delete} statements for the sync
|
|
1703
|
+
* client. It can also be used to auto-generate triggers forwarding writes on raw tables into the CRUD upload queue
|
|
1704
|
+
* (using the `powersync_create_raw_table_crud_trigger` SQL function).
|
|
1705
|
+
*
|
|
1706
|
+
* When absent, defaults to {@link RawTable.name}.
|
|
1707
|
+
*/
|
|
1708
|
+
tableName?: string;
|
|
1709
|
+
/**
|
|
1710
|
+
* An optional filter of columns that should be synced.
|
|
1711
|
+
*
|
|
1712
|
+
* By default, all columns in a raw table are considered for sync. If a filter is specified, PowerSync treats
|
|
1713
|
+
* unmatched columns as local-only and will not attempt to sync them.
|
|
1714
|
+
*/
|
|
1715
|
+
syncedColumns?: string[];
|
|
1716
|
+
}
|
|
1717
|
+
interface InferredRawTableType extends Partial<RawTableTypeWithStatements> {
|
|
1718
|
+
schema: RawTableSchema;
|
|
1719
|
+
}
|
|
1720
|
+
/**
|
|
1721
|
+
* A parameter to use as part of {@link PendingStatement}.
|
|
1722
|
+
*
|
|
1723
|
+
* For delete statements, only the `"Id"` value is supported - the sync client will replace it with the id of the row to
|
|
1724
|
+
* be synced.
|
|
1725
|
+
*
|
|
1726
|
+
* For insert and replace operations, the values of columns in the table are available as parameters through
|
|
1727
|
+
* `{Column: 'name'}`.
|
|
1728
|
+
* The `"Rest"` parameter gets resolved to a JSON object covering all values from the synced row that haven't been
|
|
1729
|
+
* covered by a `Column` parameter.
|
|
1730
|
+
*/
|
|
1731
|
+
type PendingStatementParameter = 'Id' | {
|
|
1732
|
+
Column: string;
|
|
1733
|
+
} | 'Rest';
|
|
1734
|
+
/**
|
|
1735
|
+
* A statement that the PowerSync client should use to insert or delete data into a table managed by the user.
|
|
1736
|
+
*/
|
|
1737
|
+
type PendingStatement = {
|
|
1738
|
+
sql: string;
|
|
1739
|
+
params: PendingStatementParameter[];
|
|
1740
|
+
};
|
|
1741
|
+
/**
|
|
1742
|
+
* @internal
|
|
1743
|
+
*/
|
|
1744
|
+
type RawTable<T extends RawTableType = RawTableType> = T & {
|
|
1745
|
+
/**
|
|
1746
|
+
* The name of the table.
|
|
1747
|
+
*
|
|
1748
|
+
* This does not have to match the actual table name in the schema - {@link RawTableType.put} and
|
|
1749
|
+
* {@link RawTableType.delete} are free to use another table. Instead, this name is used by the sync client to
|
|
1750
|
+
* recognize that operations on this table (as it appears in the source / backend database) are to be handled
|
|
1751
|
+
* specially.
|
|
1752
|
+
*/
|
|
1753
|
+
name: string;
|
|
1754
|
+
};
|
|
1755
|
+
|
|
1718
1756
|
type SchemaType = Record<string, Table<any>>;
|
|
1719
1757
|
type SchemaTableType<S extends SchemaType> = {
|
|
1720
1758
|
[K in keyof S]: RowType<S[K]>;
|
|
@@ -1742,14 +1780,14 @@ declare class Schema<S extends SchemaType = SchemaType> {
|
|
|
1742
1780
|
validate(): void;
|
|
1743
1781
|
toJSON(): {
|
|
1744
1782
|
tables: {
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
local_only: boolean;
|
|
1748
|
-
insert_only: boolean;
|
|
1783
|
+
local_only: boolean | undefined;
|
|
1784
|
+
insert_only: boolean | undefined;
|
|
1749
1785
|
include_old: any;
|
|
1750
1786
|
include_old_only_when_changed: boolean;
|
|
1751
|
-
include_metadata: boolean;
|
|
1752
|
-
ignore_empty_update: boolean;
|
|
1787
|
+
include_metadata: boolean | undefined;
|
|
1788
|
+
ignore_empty_update: boolean | undefined;
|
|
1789
|
+
name: string;
|
|
1790
|
+
view_name: string;
|
|
1753
1791
|
columns: {
|
|
1754
1792
|
name: string;
|
|
1755
1793
|
type: ColumnType | undefined;
|
|
@@ -1763,8 +1801,15 @@ declare class Schema<S extends SchemaType = SchemaType> {
|
|
|
1763
1801
|
}[];
|
|
1764
1802
|
}[];
|
|
1765
1803
|
}[];
|
|
1766
|
-
raw_tables:
|
|
1804
|
+
raw_tables: unknown[];
|
|
1767
1805
|
};
|
|
1806
|
+
/**
|
|
1807
|
+
* Returns a representation of the raw table that is understood by the PowerSync SQLite core extension.
|
|
1808
|
+
*
|
|
1809
|
+
* The output of this can be passed through `JSON.serialize` and then used in `powersync_create_raw_table_crud_trigger`
|
|
1810
|
+
* to define triggers for this table.
|
|
1811
|
+
*/
|
|
1812
|
+
static rawTableToJson(table: RawTable): unknown;
|
|
1768
1813
|
}
|
|
1769
1814
|
|
|
1770
1815
|
interface PowerSyncBackendConnector {
|
|
@@ -3529,6 +3574,530 @@ declare abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncD
|
|
|
3529
3574
|
private executeReadOnly;
|
|
3530
3575
|
}
|
|
3531
3576
|
|
|
3577
|
+
declare const LogLevel: {
|
|
3578
|
+
TRACE: Logger.ILogLevel;
|
|
3579
|
+
DEBUG: Logger.ILogLevel;
|
|
3580
|
+
INFO: Logger.ILogLevel;
|
|
3581
|
+
TIME: Logger.ILogLevel;
|
|
3582
|
+
WARN: Logger.ILogLevel;
|
|
3583
|
+
ERROR: Logger.ILogLevel;
|
|
3584
|
+
OFF: Logger.ILogLevel;
|
|
3585
|
+
};
|
|
3586
|
+
interface CreateLoggerOptions {
|
|
3587
|
+
logLevel?: ILogLevel;
|
|
3588
|
+
}
|
|
3589
|
+
/**
|
|
3590
|
+
* Retrieves the base (default) logger instance.
|
|
3591
|
+
*
|
|
3592
|
+
* This base logger controls the default logging configuration and is shared
|
|
3593
|
+
* across all loggers created with `createLogger`. Adjusting settings on this
|
|
3594
|
+
* base logger affects all loggers derived from it unless explicitly overridden.
|
|
3595
|
+
*
|
|
3596
|
+
*/
|
|
3597
|
+
declare function createBaseLogger(): typeof Logger;
|
|
3598
|
+
/**
|
|
3599
|
+
* Creates and configures a new named logger based on the base logger.
|
|
3600
|
+
*
|
|
3601
|
+
* Named loggers allow specific modules or areas of your application to have
|
|
3602
|
+
* their own logging levels and behaviors. These loggers inherit configuration
|
|
3603
|
+
* from the base logger by default but can override settings independently.
|
|
3604
|
+
*/
|
|
3605
|
+
declare function createLogger(name: string, options?: CreateLoggerOptions): ILogger;
|
|
3606
|
+
|
|
3607
|
+
declare const ATTACHMENT_TABLE = "attachments";
|
|
3608
|
+
/**
|
|
3609
|
+
* AttachmentRecord represents an attachment in the local database.
|
|
3610
|
+
*
|
|
3611
|
+
* @experimental
|
|
3612
|
+
*/
|
|
3613
|
+
interface AttachmentRecord {
|
|
3614
|
+
id: string;
|
|
3615
|
+
filename: string;
|
|
3616
|
+
localUri?: string;
|
|
3617
|
+
size?: number;
|
|
3618
|
+
mediaType?: string;
|
|
3619
|
+
timestamp?: number;
|
|
3620
|
+
metaData?: string;
|
|
3621
|
+
hasSynced?: boolean;
|
|
3622
|
+
state: AttachmentState;
|
|
3623
|
+
}
|
|
3624
|
+
/**
|
|
3625
|
+
* Maps a database row to an AttachmentRecord.
|
|
3626
|
+
*
|
|
3627
|
+
* @param row - The database row object
|
|
3628
|
+
* @returns The corresponding AttachmentRecord
|
|
3629
|
+
*
|
|
3630
|
+
* @experimental
|
|
3631
|
+
*/
|
|
3632
|
+
declare function attachmentFromSql(row: any): AttachmentRecord;
|
|
3633
|
+
/**
|
|
3634
|
+
* AttachmentState represents the current synchronization state of an attachment.
|
|
3635
|
+
*
|
|
3636
|
+
* @experimental
|
|
3637
|
+
*/
|
|
3638
|
+
declare enum AttachmentState {
|
|
3639
|
+
QUEUED_UPLOAD = 0,// Attachment to be uploaded
|
|
3640
|
+
QUEUED_DOWNLOAD = 1,// Attachment to be downloaded
|
|
3641
|
+
QUEUED_DELETE = 2,// Attachment to be deleted
|
|
3642
|
+
SYNCED = 3,// Attachment has been synced
|
|
3643
|
+
ARCHIVED = 4
|
|
3644
|
+
}
|
|
3645
|
+
interface AttachmentTableOptions extends Omit<TableV2Options, 'name' | 'columns'> {
|
|
3646
|
+
}
|
|
3647
|
+
/**
|
|
3648
|
+
* AttachmentTable defines the schema for the attachment queue table.
|
|
3649
|
+
*
|
|
3650
|
+
* @internal
|
|
3651
|
+
*/
|
|
3652
|
+
declare class AttachmentTable extends Table {
|
|
3653
|
+
constructor(options?: AttachmentTableOptions);
|
|
3654
|
+
}
|
|
3655
|
+
|
|
3656
|
+
/**
|
|
3657
|
+
* AttachmentContext provides database operations for managing attachment records.
|
|
3658
|
+
*
|
|
3659
|
+
* Provides methods to query, insert, update, and delete attachment records with
|
|
3660
|
+
* proper transaction management through PowerSync.
|
|
3661
|
+
*
|
|
3662
|
+
* @internal
|
|
3663
|
+
*/
|
|
3664
|
+
declare class AttachmentContext {
|
|
3665
|
+
/** PowerSync database instance for executing queries */
|
|
3666
|
+
db: AbstractPowerSyncDatabase;
|
|
3667
|
+
/** Name of the database table storing attachment records */
|
|
3668
|
+
tableName: string;
|
|
3669
|
+
/** Logger instance for diagnostic information */
|
|
3670
|
+
logger: ILogger;
|
|
3671
|
+
/** Maximum number of archived attachments to keep before cleanup */
|
|
3672
|
+
archivedCacheLimit: number;
|
|
3673
|
+
/**
|
|
3674
|
+
* Creates a new AttachmentContext instance.
|
|
3675
|
+
*
|
|
3676
|
+
* @param db - PowerSync database instance
|
|
3677
|
+
* @param tableName - Name of the table storing attachment records. Default: 'attachments'
|
|
3678
|
+
* @param logger - Logger instance for diagnostic output
|
|
3679
|
+
*/
|
|
3680
|
+
constructor(db: AbstractPowerSyncDatabase, tableName: string | undefined, logger: ILogger, archivedCacheLimit: number);
|
|
3681
|
+
/**
|
|
3682
|
+
* Retrieves all active attachments that require synchronization.
|
|
3683
|
+
* Active attachments include those queued for upload, download, or delete.
|
|
3684
|
+
* Results are ordered by timestamp in ascending order.
|
|
3685
|
+
*
|
|
3686
|
+
* @returns Promise resolving to an array of active attachment records
|
|
3687
|
+
*/
|
|
3688
|
+
getActiveAttachments(): Promise<AttachmentRecord[]>;
|
|
3689
|
+
/**
|
|
3690
|
+
* Retrieves all archived attachments.
|
|
3691
|
+
*
|
|
3692
|
+
* Archived attachments are no longer referenced but haven't been permanently deleted.
|
|
3693
|
+
* These are candidates for cleanup operations to free up storage space.
|
|
3694
|
+
*
|
|
3695
|
+
* @returns Promise resolving to an array of archived attachment records
|
|
3696
|
+
*/
|
|
3697
|
+
getArchivedAttachments(): Promise<AttachmentRecord[]>;
|
|
3698
|
+
/**
|
|
3699
|
+
* Retrieves all attachment records regardless of state.
|
|
3700
|
+
* Results are ordered by timestamp in ascending order.
|
|
3701
|
+
*
|
|
3702
|
+
* @returns Promise resolving to an array of all attachment records
|
|
3703
|
+
*/
|
|
3704
|
+
getAttachments(): Promise<AttachmentRecord[]>;
|
|
3705
|
+
/**
|
|
3706
|
+
* Inserts or updates an attachment record within an existing transaction.
|
|
3707
|
+
*
|
|
3708
|
+
* Performs an upsert operation (INSERT OR REPLACE). Must be called within
|
|
3709
|
+
* an active database transaction context.
|
|
3710
|
+
*
|
|
3711
|
+
* @param attachment - The attachment record to upsert
|
|
3712
|
+
* @param context - Active database transaction context
|
|
3713
|
+
*/
|
|
3714
|
+
upsertAttachment(attachment: AttachmentRecord, context: Transaction): Promise<void>;
|
|
3715
|
+
getAttachment(id: string): Promise<AttachmentRecord | undefined>;
|
|
3716
|
+
/**
|
|
3717
|
+
* Permanently deletes an attachment record from the database.
|
|
3718
|
+
*
|
|
3719
|
+
* This operation removes the attachment record but does not delete
|
|
3720
|
+
* the associated local or remote files. File deletion should be handled
|
|
3721
|
+
* separately through the appropriate storage adapters.
|
|
3722
|
+
*
|
|
3723
|
+
* @param attachmentId - Unique identifier of the attachment to delete
|
|
3724
|
+
*/
|
|
3725
|
+
deleteAttachment(attachmentId: string): Promise<void>;
|
|
3726
|
+
clearQueue(): Promise<void>;
|
|
3727
|
+
deleteArchivedAttachments(callback?: (attachments: AttachmentRecord[]) => Promise<void>): Promise<boolean>;
|
|
3728
|
+
/**
|
|
3729
|
+
* Saves multiple attachment records in a single transaction.
|
|
3730
|
+
*
|
|
3731
|
+
* All updates are saved in a single batch after processing.
|
|
3732
|
+
* If the attachments array is empty, no database operations are performed.
|
|
3733
|
+
*
|
|
3734
|
+
* @param attachments - Array of attachment records to save
|
|
3735
|
+
*/
|
|
3736
|
+
saveAttachments(attachments: AttachmentRecord[]): Promise<void>;
|
|
3737
|
+
}
|
|
3738
|
+
|
|
3739
|
+
/**
|
|
3740
|
+
* SyncErrorHandler provides custom error handling for attachment sync operations.
|
|
3741
|
+
* Implementations determine whether failed operations should be retried or archived.
|
|
3742
|
+
*
|
|
3743
|
+
* @experimental
|
|
3744
|
+
* @alpha This is currently experimental and may change without a major version bump.
|
|
3745
|
+
*/
|
|
3746
|
+
interface AttachmentErrorHandler {
|
|
3747
|
+
/**
|
|
3748
|
+
* Handles a download error for a specific attachment.
|
|
3749
|
+
* @param attachment The attachment that failed to download
|
|
3750
|
+
* @param error The error encountered during the download
|
|
3751
|
+
* @returns `true` to retry the operation, `false` to archive the attachment
|
|
3752
|
+
*/
|
|
3753
|
+
onDownloadError(attachment: AttachmentRecord, error: unknown): Promise<boolean>;
|
|
3754
|
+
/**
|
|
3755
|
+
* Handles an upload error for a specific attachment.
|
|
3756
|
+
* @param attachment The attachment that failed to upload
|
|
3757
|
+
* @param error The error encountered during the upload
|
|
3758
|
+
* @returns `true` to retry the operation, `false` to archive the attachment
|
|
3759
|
+
*/
|
|
3760
|
+
onUploadError(attachment: AttachmentRecord, error: unknown): Promise<boolean>;
|
|
3761
|
+
/**
|
|
3762
|
+
* Handles a delete error for a specific attachment.
|
|
3763
|
+
* @param attachment The attachment that failed to delete
|
|
3764
|
+
* @param error The error encountered during the delete
|
|
3765
|
+
* @returns `true` to retry the operation, `false` to archive the attachment
|
|
3766
|
+
*/
|
|
3767
|
+
onDeleteError(attachment: AttachmentRecord, error: unknown): Promise<boolean>;
|
|
3768
|
+
}
|
|
3769
|
+
|
|
3770
|
+
type AttachmentData = ArrayBuffer | string;
|
|
3771
|
+
declare enum EncodingType {
|
|
3772
|
+
UTF8 = "utf8",
|
|
3773
|
+
Base64 = "base64"
|
|
3774
|
+
}
|
|
3775
|
+
/**
|
|
3776
|
+
* LocalStorageAdapter defines the interface for local file storage operations.
|
|
3777
|
+
* Implementations handle file I/O, directory management, and storage initialization.
|
|
3778
|
+
*
|
|
3779
|
+
* @experimental
|
|
3780
|
+
* @alpha This is currently experimental and may change without a major version bump.
|
|
3781
|
+
*/
|
|
3782
|
+
interface LocalStorageAdapter {
|
|
3783
|
+
/**
|
|
3784
|
+
* Saves data to a local file.
|
|
3785
|
+
* @param filePath Path where the file will be stored
|
|
3786
|
+
* @param data Data to store (ArrayBuffer, Blob, or string)
|
|
3787
|
+
* @returns Number of bytes written
|
|
3788
|
+
*/
|
|
3789
|
+
saveFile(filePath: string, data: AttachmentData): Promise<number>;
|
|
3790
|
+
/**
|
|
3791
|
+
* Retrieves file data as an ArrayBuffer.
|
|
3792
|
+
* @param filePath Path where the file is stored
|
|
3793
|
+
* @returns ArrayBuffer containing the file data
|
|
3794
|
+
*/
|
|
3795
|
+
readFile(filePath: string): Promise<ArrayBuffer>;
|
|
3796
|
+
/**
|
|
3797
|
+
* Deletes the file at the given path.
|
|
3798
|
+
* @param filePath Path where the file is stored
|
|
3799
|
+
*/
|
|
3800
|
+
deleteFile(filePath: string): Promise<void>;
|
|
3801
|
+
/**
|
|
3802
|
+
* Checks if a file exists at the given path.
|
|
3803
|
+
* @param filePath Path where the file is stored
|
|
3804
|
+
* @returns True if the file exists, false otherwise
|
|
3805
|
+
*/
|
|
3806
|
+
fileExists(filePath: string): Promise<boolean>;
|
|
3807
|
+
/**
|
|
3808
|
+
* Creates a directory at the specified path.
|
|
3809
|
+
* @param path The full path to the directory
|
|
3810
|
+
*/
|
|
3811
|
+
makeDir(path: string): Promise<void>;
|
|
3812
|
+
/**
|
|
3813
|
+
* Removes a directory at the specified path.
|
|
3814
|
+
* @param path The full path to the directory
|
|
3815
|
+
*/
|
|
3816
|
+
rmDir(path: string): Promise<void>;
|
|
3817
|
+
/**
|
|
3818
|
+
* Initializes the storage adapter (e.g., creating necessary directories).
|
|
3819
|
+
*/
|
|
3820
|
+
initialize(): Promise<void>;
|
|
3821
|
+
/**
|
|
3822
|
+
* Clears all files in the storage.
|
|
3823
|
+
*/
|
|
3824
|
+
clear(): Promise<void>;
|
|
3825
|
+
/**
|
|
3826
|
+
* Returns the file path for the provided filename in the storage directory.
|
|
3827
|
+
* @param filename The filename to get the path for
|
|
3828
|
+
* @returns The full file path
|
|
3829
|
+
*/
|
|
3830
|
+
getLocalUri(filename: string): string;
|
|
3831
|
+
}
|
|
3832
|
+
|
|
3833
|
+
/**
|
|
3834
|
+
* RemoteStorageAdapter defines the interface for remote storage operations.
|
|
3835
|
+
* Implementations handle uploading, downloading, and deleting files from remote storage.
|
|
3836
|
+
*
|
|
3837
|
+
* @experimental
|
|
3838
|
+
* @alpha This is currently experimental and may change without a major version bump.
|
|
3839
|
+
*/
|
|
3840
|
+
interface RemoteStorageAdapter {
|
|
3841
|
+
/**
|
|
3842
|
+
* Uploads a file to remote storage.
|
|
3843
|
+
* @param fileData The binary content of the file to upload
|
|
3844
|
+
* @param attachment The associated attachment metadata
|
|
3845
|
+
*/
|
|
3846
|
+
uploadFile(fileData: ArrayBuffer, attachment: AttachmentRecord): Promise<void>;
|
|
3847
|
+
/**
|
|
3848
|
+
* Downloads a file from remote storage.
|
|
3849
|
+
* @param attachment The attachment describing the file to download
|
|
3850
|
+
* @returns The binary data of the downloaded file
|
|
3851
|
+
*/
|
|
3852
|
+
downloadFile(attachment: AttachmentRecord): Promise<ArrayBuffer>;
|
|
3853
|
+
/**
|
|
3854
|
+
* Deletes a file from remote storage.
|
|
3855
|
+
* @param attachment The attachment describing the file to delete
|
|
3856
|
+
*/
|
|
3857
|
+
deleteFile(attachment: AttachmentRecord): Promise<void>;
|
|
3858
|
+
}
|
|
3859
|
+
|
|
3860
|
+
/**
|
|
3861
|
+
* WatchedAttachmentItem represents an attachment reference in your application's data model.
|
|
3862
|
+
* Use either filename OR fileExtension (not both).
|
|
3863
|
+
*
|
|
3864
|
+
* @experimental
|
|
3865
|
+
*/
|
|
3866
|
+
type WatchedAttachmentItem = {
|
|
3867
|
+
id: string;
|
|
3868
|
+
filename: string;
|
|
3869
|
+
fileExtension?: never;
|
|
3870
|
+
metaData?: string;
|
|
3871
|
+
} | {
|
|
3872
|
+
id: string;
|
|
3873
|
+
fileExtension: string;
|
|
3874
|
+
filename?: never;
|
|
3875
|
+
metaData?: string;
|
|
3876
|
+
};
|
|
3877
|
+
|
|
3878
|
+
/**
|
|
3879
|
+
* AttachmentQueue manages the lifecycle and synchronization of attachments
|
|
3880
|
+
* between local and remote storage.
|
|
3881
|
+
* Provides automatic synchronization, upload/download queuing, attachment monitoring,
|
|
3882
|
+
* verification and repair of local files, and cleanup of archived attachments.
|
|
3883
|
+
*
|
|
3884
|
+
* @experimental
|
|
3885
|
+
* @alpha This is currently experimental and may change without a major version bump.
|
|
3886
|
+
*/
|
|
3887
|
+
declare class AttachmentQueue {
|
|
3888
|
+
/** Timer for periodic synchronization operations */
|
|
3889
|
+
private periodicSyncTimer?;
|
|
3890
|
+
/** Service for synchronizing attachments between local and remote storage */
|
|
3891
|
+
private readonly syncingService;
|
|
3892
|
+
/** Adapter for local file storage operations */
|
|
3893
|
+
readonly localStorage: LocalStorageAdapter;
|
|
3894
|
+
/** Adapter for remote file storage operations */
|
|
3895
|
+
readonly remoteStorage: RemoteStorageAdapter;
|
|
3896
|
+
/**
|
|
3897
|
+
* Callback function to watch for changes in attachment references in your data model.
|
|
3898
|
+
*
|
|
3899
|
+
* This should be implemented by the user of AttachmentQueue to monitor changes in your application's
|
|
3900
|
+
* data that reference attachments. When attachments are added, removed, or modified,
|
|
3901
|
+
* this callback should trigger the onUpdate function with the current set of attachments.
|
|
3902
|
+
*/
|
|
3903
|
+
private readonly watchAttachments;
|
|
3904
|
+
/** Name of the database table storing attachment records */
|
|
3905
|
+
readonly tableName: string;
|
|
3906
|
+
/** Logger instance for diagnostic information */
|
|
3907
|
+
readonly logger: ILogger;
|
|
3908
|
+
/** Interval in milliseconds between periodic sync operations. Default: 30000 (30 seconds) */
|
|
3909
|
+
readonly syncIntervalMs: number;
|
|
3910
|
+
/** Duration in milliseconds to throttle sync operations */
|
|
3911
|
+
readonly syncThrottleDuration: number;
|
|
3912
|
+
/** Whether to automatically download remote attachments. Default: true */
|
|
3913
|
+
readonly downloadAttachments: boolean;
|
|
3914
|
+
/** Maximum number of archived attachments to keep before cleanup. Default: 100 */
|
|
3915
|
+
readonly archivedCacheLimit: number;
|
|
3916
|
+
/** Service for managing attachment-related database operations */
|
|
3917
|
+
private readonly attachmentService;
|
|
3918
|
+
/** PowerSync database instance */
|
|
3919
|
+
private readonly db;
|
|
3920
|
+
/** Cleanup function for status change listener */
|
|
3921
|
+
private statusListenerDispose?;
|
|
3922
|
+
private watchActiveAttachments;
|
|
3923
|
+
private watchAttachmentsAbortController;
|
|
3924
|
+
/**
|
|
3925
|
+
* Creates a new AttachmentQueue instance.
|
|
3926
|
+
*
|
|
3927
|
+
* @param options - Configuration options
|
|
3928
|
+
* @param options.db - PowerSync database instance
|
|
3929
|
+
* @param options.remoteStorage - Remote storage adapter for upload/download operations
|
|
3930
|
+
* @param options.localStorage - Local storage adapter for file persistence
|
|
3931
|
+
* @param options.watchAttachments - Callback for monitoring attachment changes in your data model
|
|
3932
|
+
* @param options.tableName - Name of the table to store attachment records. Default: 'ps_attachment_queue'
|
|
3933
|
+
* @param options.logger - Logger instance. Defaults to db.logger
|
|
3934
|
+
* @param options.syncIntervalMs - Interval between automatic syncs in milliseconds. Default: 30000
|
|
3935
|
+
* @param options.syncThrottleDuration - Throttle duration for sync operations in milliseconds. Default: 1000
|
|
3936
|
+
* @param options.downloadAttachments - Whether to automatically download remote attachments. Default: true
|
|
3937
|
+
* @param options.archivedCacheLimit - Maximum archived attachments before cleanup. Default: 100
|
|
3938
|
+
*/
|
|
3939
|
+
constructor({ db, localStorage, remoteStorage, watchAttachments, logger, tableName, syncIntervalMs, syncThrottleDuration, downloadAttachments, archivedCacheLimit, errorHandler }: {
|
|
3940
|
+
db: AbstractPowerSyncDatabase;
|
|
3941
|
+
remoteStorage: RemoteStorageAdapter;
|
|
3942
|
+
localStorage: LocalStorageAdapter;
|
|
3943
|
+
watchAttachments: (onUpdate: (attachment: WatchedAttachmentItem[]) => Promise<void>, signal: AbortSignal) => void;
|
|
3944
|
+
tableName?: string;
|
|
3945
|
+
logger?: ILogger;
|
|
3946
|
+
syncIntervalMs?: number;
|
|
3947
|
+
syncThrottleDuration?: number;
|
|
3948
|
+
downloadAttachments?: boolean;
|
|
3949
|
+
archivedCacheLimit?: number;
|
|
3950
|
+
errorHandler?: AttachmentErrorHandler;
|
|
3951
|
+
});
|
|
3952
|
+
/**
|
|
3953
|
+
* Generates a new attachment ID using a SQLite UUID function.
|
|
3954
|
+
*
|
|
3955
|
+
* @returns Promise resolving to the new attachment ID
|
|
3956
|
+
*/
|
|
3957
|
+
generateAttachmentId(): Promise<string>;
|
|
3958
|
+
/**
|
|
3959
|
+
* Starts the attachment synchronization process.
|
|
3960
|
+
*
|
|
3961
|
+
* This method:
|
|
3962
|
+
* - Stops any existing sync operations
|
|
3963
|
+
* - Sets up periodic synchronization based on syncIntervalMs
|
|
3964
|
+
* - Registers listeners for active attachment changes
|
|
3965
|
+
* - Processes watched attachments to queue uploads/downloads
|
|
3966
|
+
* - Handles state transitions for archived and new attachments
|
|
3967
|
+
*/
|
|
3968
|
+
startSync(): Promise<void>;
|
|
3969
|
+
/**
|
|
3970
|
+
* Synchronizes all active attachments between local and remote storage.
|
|
3971
|
+
*
|
|
3972
|
+
* This is called automatically at regular intervals when sync is started,
|
|
3973
|
+
* but can also be called manually to trigger an immediate sync.
|
|
3974
|
+
*/
|
|
3975
|
+
syncStorage(): Promise<void>;
|
|
3976
|
+
/**
|
|
3977
|
+
* Stops the attachment synchronization process.
|
|
3978
|
+
*
|
|
3979
|
+
* Clears the periodic sync timer and closes all active attachment watchers.
|
|
3980
|
+
*/
|
|
3981
|
+
stopSync(): Promise<void>;
|
|
3982
|
+
/**
|
|
3983
|
+
* Saves a file to local storage and queues it for upload to remote storage.
|
|
3984
|
+
*
|
|
3985
|
+
* @param options - File save options
|
|
3986
|
+
* @param options.data - The file data as ArrayBuffer, Blob, or base64 string
|
|
3987
|
+
* @param options.fileExtension - File extension (e.g., 'jpg', 'pdf')
|
|
3988
|
+
* @param options.mediaType - MIME type of the file (e.g., 'image/jpeg')
|
|
3989
|
+
* @param options.metaData - Optional metadata to associate with the attachment
|
|
3990
|
+
* @param options.id - Optional custom ID. If not provided, a UUID will be generated
|
|
3991
|
+
* @param options.updateHook - Optional callback to execute additional database operations
|
|
3992
|
+
* within the same transaction as the attachment creation
|
|
3993
|
+
* @returns Promise resolving to the created attachment record
|
|
3994
|
+
*/
|
|
3995
|
+
saveFile({ data, fileExtension, mediaType, metaData, id, updateHook }: {
|
|
3996
|
+
data: AttachmentData;
|
|
3997
|
+
fileExtension: string;
|
|
3998
|
+
mediaType?: string;
|
|
3999
|
+
metaData?: string;
|
|
4000
|
+
id?: string;
|
|
4001
|
+
updateHook?: (transaction: Transaction, attachment: AttachmentRecord) => Promise<void>;
|
|
4002
|
+
}): Promise<AttachmentRecord>;
|
|
4003
|
+
deleteFile({ id, updateHook }: {
|
|
4004
|
+
id: string;
|
|
4005
|
+
updateHook?: (transaction: Transaction, attachment: AttachmentRecord) => Promise<void>;
|
|
4006
|
+
}): Promise<void>;
|
|
4007
|
+
expireCache(): Promise<void>;
|
|
4008
|
+
clearQueue(): Promise<void>;
|
|
4009
|
+
/**
|
|
4010
|
+
* Verifies the integrity of all attachment records and repairs inconsistencies.
|
|
4011
|
+
*
|
|
4012
|
+
* This method checks each attachment record against the local filesystem and:
|
|
4013
|
+
* - Updates localUri if the file exists at a different path
|
|
4014
|
+
* - Archives attachments with missing local files that haven't been uploaded
|
|
4015
|
+
* - Requeues synced attachments for download if their local files are missing
|
|
4016
|
+
*/
|
|
4017
|
+
verifyAttachments(): Promise<void>;
|
|
4018
|
+
}
|
|
4019
|
+
|
|
4020
|
+
/**
|
|
4021
|
+
* Service for querying and watching attachment records in the database.
|
|
4022
|
+
*
|
|
4023
|
+
* @internal
|
|
4024
|
+
*/
|
|
4025
|
+
declare class AttachmentService {
|
|
4026
|
+
private db;
|
|
4027
|
+
private logger;
|
|
4028
|
+
private tableName;
|
|
4029
|
+
private mutex;
|
|
4030
|
+
private context;
|
|
4031
|
+
constructor(db: AbstractPowerSyncDatabase, logger: ILogger, tableName?: string, archivedCacheLimit?: number);
|
|
4032
|
+
/**
|
|
4033
|
+
* Creates a differential watch query for active attachments requiring synchronization.
|
|
4034
|
+
* @returns Watch query that emits changes for queued uploads, downloads, and deletes
|
|
4035
|
+
*/
|
|
4036
|
+
watchActiveAttachments({ throttleMs }?: {
|
|
4037
|
+
throttleMs?: number;
|
|
4038
|
+
}): DifferentialWatchedQuery<AttachmentRecord>;
|
|
4039
|
+
/**
|
|
4040
|
+
* Executes a callback with exclusive access to the attachment context.
|
|
4041
|
+
*/
|
|
4042
|
+
withContext<T>(callback: (context: AttachmentContext) => Promise<T>): Promise<T>;
|
|
4043
|
+
}
|
|
4044
|
+
|
|
4045
|
+
/**
|
|
4046
|
+
* Orchestrates attachment synchronization between local and remote storage.
|
|
4047
|
+
* Handles uploads, downloads, deletions, and state transitions.
|
|
4048
|
+
*
|
|
4049
|
+
* @internal
|
|
4050
|
+
*/
|
|
4051
|
+
declare class SyncingService {
|
|
4052
|
+
private attachmentService;
|
|
4053
|
+
private localStorage;
|
|
4054
|
+
private remoteStorage;
|
|
4055
|
+
private logger;
|
|
4056
|
+
private errorHandler?;
|
|
4057
|
+
constructor(attachmentService: AttachmentService, localStorage: LocalStorageAdapter, remoteStorage: RemoteStorageAdapter, logger: ILogger, errorHandler?: AttachmentErrorHandler);
|
|
4058
|
+
/**
|
|
4059
|
+
* Processes attachments based on their state (upload, download, or delete).
|
|
4060
|
+
* All updates are saved in a single batch after processing.
|
|
4061
|
+
*
|
|
4062
|
+
* @param attachments - Array of attachment records to process
|
|
4063
|
+
* @param context - Attachment context for database operations
|
|
4064
|
+
* @returns Promise that resolves when all attachments have been processed and saved
|
|
4065
|
+
*/
|
|
4066
|
+
processAttachments(attachments: AttachmentRecord[], context: AttachmentContext): Promise<void>;
|
|
4067
|
+
/**
|
|
4068
|
+
* Uploads an attachment from local storage to remote storage.
|
|
4069
|
+
* On success, marks as SYNCED. On failure, defers to error handler or archives.
|
|
4070
|
+
*
|
|
4071
|
+
* @param attachment - The attachment record to upload
|
|
4072
|
+
* @returns Updated attachment record with new state
|
|
4073
|
+
* @throws Error if the attachment has no localUri
|
|
4074
|
+
*/
|
|
4075
|
+
uploadAttachment(attachment: AttachmentRecord): Promise<AttachmentRecord>;
|
|
4076
|
+
/**
|
|
4077
|
+
* Downloads an attachment from remote storage to local storage.
|
|
4078
|
+
* Retrieves the file, converts to base64, and saves locally.
|
|
4079
|
+
* On success, marks as SYNCED. On failure, defers to error handler or archives.
|
|
4080
|
+
*
|
|
4081
|
+
* @param attachment - The attachment record to download
|
|
4082
|
+
* @returns Updated attachment record with local URI and new state
|
|
4083
|
+
*/
|
|
4084
|
+
downloadAttachment(attachment: AttachmentRecord): Promise<AttachmentRecord>;
|
|
4085
|
+
/**
|
|
4086
|
+
* Deletes an attachment from both remote and local storage.
|
|
4087
|
+
* Removes the remote file, local file (if exists), and the attachment record.
|
|
4088
|
+
* On failure, defers to error handler or archives.
|
|
4089
|
+
*
|
|
4090
|
+
* @param attachment - The attachment record to delete
|
|
4091
|
+
* @returns Updated attachment record
|
|
4092
|
+
*/
|
|
4093
|
+
deleteAttachment(attachment: AttachmentRecord): Promise<AttachmentRecord>;
|
|
4094
|
+
/**
|
|
4095
|
+
* Performs cleanup of archived attachments by removing their local files and records.
|
|
4096
|
+
* Errors during local file deletion are logged but do not prevent record deletion.
|
|
4097
|
+
*/
|
|
4098
|
+
deleteArchivedAttachments(context: AttachmentContext): Promise<boolean>;
|
|
4099
|
+
}
|
|
4100
|
+
|
|
3532
4101
|
interface PowerSyncOpenFactoryOptions extends Partial<PowerSyncDatabaseOptions>, SQLOpenOptions {
|
|
3533
4102
|
/** Schema used for the local database. */
|
|
3534
4103
|
schema: Schema;
|
|
@@ -3731,35 +4300,12 @@ declare class ControlledExecutor<T> {
|
|
|
3731
4300
|
private execute;
|
|
3732
4301
|
}
|
|
3733
4302
|
|
|
3734
|
-
declare const LogLevel: {
|
|
3735
|
-
TRACE: Logger.ILogLevel;
|
|
3736
|
-
DEBUG: Logger.ILogLevel;
|
|
3737
|
-
INFO: Logger.ILogLevel;
|
|
3738
|
-
TIME: Logger.ILogLevel;
|
|
3739
|
-
WARN: Logger.ILogLevel;
|
|
3740
|
-
ERROR: Logger.ILogLevel;
|
|
3741
|
-
OFF: Logger.ILogLevel;
|
|
3742
|
-
};
|
|
3743
|
-
interface CreateLoggerOptions {
|
|
3744
|
-
logLevel?: ILogLevel;
|
|
3745
|
-
}
|
|
3746
|
-
/**
|
|
3747
|
-
* Retrieves the base (default) logger instance.
|
|
3748
|
-
*
|
|
3749
|
-
* This base logger controls the default logging configuration and is shared
|
|
3750
|
-
* across all loggers created with `createLogger`. Adjusting settings on this
|
|
3751
|
-
* base logger affects all loggers derived from it unless explicitly overridden.
|
|
3752
|
-
*
|
|
3753
|
-
*/
|
|
3754
|
-
declare function createBaseLogger(): typeof Logger;
|
|
3755
4303
|
/**
|
|
3756
|
-
*
|
|
3757
|
-
*
|
|
3758
|
-
* Named loggers allow specific modules or areas of your application to have
|
|
3759
|
-
* their own logging levels and behaviors. These loggers inherit configuration
|
|
3760
|
-
* from the base logger by default but can override settings independently.
|
|
4304
|
+
* Wrapper for async-mutex runExclusive, which allows for a timeout on each exclusive lock.
|
|
3761
4305
|
*/
|
|
3762
|
-
declare function
|
|
4306
|
+
declare function mutexRunExclusive<T>(mutex: Mutex, callback: () => Promise<T>, options?: {
|
|
4307
|
+
timeoutMs?: number;
|
|
4308
|
+
}): Promise<T>;
|
|
3763
4309
|
|
|
3764
4310
|
interface ParsedQuery {
|
|
3765
4311
|
sqlStatement: string;
|
|
@@ -3767,5 +4313,5 @@ interface ParsedQuery {
|
|
|
3767
4313
|
}
|
|
3768
4314
|
declare const parseQuery: <T>(query: string | CompilableQuery<T>, parameters: any[]) => ParsedQuery;
|
|
3769
4315
|
|
|
3770
|
-
export { AbortOperation, AbstractPowerSyncDatabase, AbstractPowerSyncDatabaseOpenFactory, AbstractQueryProcessor, AbstractRemote, AbstractStreamingSyncImplementation, ArrayComparator, BaseObserver, Column, ColumnType, ConnectionClosedError, ConnectionManager, ControlledExecutor, CrudBatch, CrudEntry, CrudTransaction, DEFAULT_CRUD_BATCH_LIMIT, DEFAULT_CRUD_UPLOAD_THROTTLE_MS, DEFAULT_INDEX_COLUMN_OPTIONS, DEFAULT_INDEX_OPTIONS, DEFAULT_LOCK_TIMEOUT_MS, DEFAULT_POWERSYNC_CLOSE_OPTIONS, DEFAULT_POWERSYNC_DB_OPTIONS, DEFAULT_PRESSURE_LIMITS, DEFAULT_REMOTE_LOGGER, DEFAULT_REMOTE_OPTIONS, DEFAULT_RETRY_DELAY_MS, DEFAULT_ROW_COMPARATOR, DEFAULT_STREAMING_SYNC_OPTIONS, DEFAULT_STREAM_CONNECTION_OPTIONS, DEFAULT_SYNC_CLIENT_IMPLEMENTATION, DEFAULT_TABLE_OPTIONS, DEFAULT_WATCH_QUERY_OPTIONS, DEFAULT_WATCH_THROTTLE_MS, DataStream, DiffTriggerOperation, DifferentialQueryProcessor, EMPTY_DIFFERENTIAL, FalsyComparator, FetchImplementationProvider, FetchStrategy, GetAllQuery, Index, IndexedColumn, InvalidSQLCharacters, LockType, LogLevel, MAX_AMOUNT_OF_COLUMNS, MAX_OP_ID, MEMORY_TRIGGER_CLAIM_MANAGER, OnChangeQueryProcessor, OpType, OpTypeEnum, OplogEntry, PSInternalTable, PowerSyncControlCommand,
|
|
3771
|
-
export type { AbstractQueryProcessorOptions, AbstractRemoteOptions, AbstractStreamingSyncImplementationOptions, AdditionalConnectionOptions, ArrayComparatorOptions, ArrayQueryDefinition, BSONImplementation, BaseColumnType, BaseConnectionOptions, BaseListener, BaseObserverInterface, BasePowerSyncDatabaseOptions, BaseTriggerDiffRecord, BatchedUpdateNotification, BucketChecksum, BucketDescription, BucketOperationProgress, BucketRequest, BucketState, BucketStorageAdapter, BucketStorageListener, Checkpoint, ChecksumCache, ColumnOptions, ColumnsType, CompilableQuery, CompilableQueryWatchHandler, CompiledQuery, ConnectionManagerListener, ConnectionManagerOptions, ConnectionManagerSyncImplementationResult, ContinueCheckpointRequest, ControlledExecutorOptions, CreateDiffTriggerOptions, CreateLoggerOptions, CreateSyncImplementationOptions, CrudRequest, CrudResponse, CrudUploadNotification, DBAdapter, DBAdapterListener, DBGetUtils, DBLockOptions, DataStreamCallback, DataStreamListener, DataStreamOptions, DifferentialQueryProcessorOptions, DifferentialWatchedQuery, DifferentialWatchedQueryComparator, DifferentialWatchedQueryListener, DifferentialWatchedQueryOptions, DifferentialWatchedQuerySettings, DisconnectAndClearOptions, Disposable, ExtractColumnValueType, ExtractedTriggerDiffRecord, FetchImplementation, GetAllQueryOptions, IndexColumnOptions, IndexOptions, IndexShorthand, InternalConnectionOptions, InternalSubscriptionAdapter, LinkQueryOptions, LockContext, LockOptions, MutableWatchedQueryState, OnChangeQueryProcessorOptions, OpId, OpTypeJSON, OplogEntryJSON, ParsedQuery, PendingStatement, PendingStatementParameter, PowerSyncBackendConnector, PowerSyncCloseOptions, PowerSyncConnectionOptions, PowerSyncCredentials, PowerSyncDBListener, PowerSyncDatabaseOptions, PowerSyncDatabaseOptionsWithDBAdapter, PowerSyncDatabaseOptionsWithOpenFactory, PowerSyncDatabaseOptionsWithSettings, PowerSyncOpenFactoryOptions, ProgressWithOperations, Query, QueryParam, QueryResult, RawTableType, RemoteConnector, RequiredAdditionalConnectionOptions, RequiredPowerSyncConnectionOptions, RowType, SQLOnChangeOptions, SQLOpenFactory, SQLOpenOptions, SQLWatchOptions, SavedProgress, SchemaTableType, SocketSyncStreamOptions, StandardWatchedQuery, StandardWatchedQueryOptions, StreamingSyncCheckpoint, StreamingSyncCheckpointComplete, StreamingSyncCheckpointDiff, StreamingSyncCheckpointPartiallyComplete, StreamingSyncDataJSON, StreamingSyncImplementation, StreamingSyncImplementationListener, StreamingSyncKeepalive, StreamingSyncLine, StreamingSyncLineOrCrudUploadComplete, StreamingSyncRequest, StreamingSyncRequestParameterType, SubscribedStream, SyncDataBucketJSON, SyncDataFlowStatus, SyncLocalDatabaseResult, SyncNewCheckpointRequest, SyncPriorityStatus, SyncRequest, SyncResponse, SyncStatusOptions, SyncStream, SyncStreamDescription, SyncStreamOptions, SyncStreamStatus, SyncStreamSubscribeOptions, SyncStreamSubscription, SyncSubscriptionDescription, TableOptions, TableUpdateOperation, TableV2Options, TrackDiffOptions, TrackPreviousOptions, Transaction, TriggerClaimManager, TriggerCreationHooks, TriggerDiffDeleteRecord, TriggerDiffHandlerContext, TriggerDiffInsertRecord, TriggerDiffRecord, TriggerDiffUpdateRecord, TriggerManager, TriggerManagerConfig, TriggerRemoveCallback, UpdateNotification, WatchCompatibleQuery, WatchExecuteOptions, WatchHandler, WatchOnChangeEvent, WatchOnChangeHandler, WatchedQuery, WatchedQueryComparator, WatchedQueryDifferential, WatchedQueryListener, WatchedQueryOptions, WatchedQueryRowDifferential, WatchedQuerySettings, WatchedQueryState, WithDiffOptions };
|
|
4316
|
+
export { ATTACHMENT_TABLE, AbortOperation, AbstractPowerSyncDatabase, AbstractPowerSyncDatabaseOpenFactory, AbstractQueryProcessor, AbstractRemote, AbstractStreamingSyncImplementation, ArrayComparator, AttachmentContext, AttachmentQueue, AttachmentService, AttachmentState, AttachmentTable, BaseObserver, Column, ColumnType, ConnectionClosedError, ConnectionManager, ControlledExecutor, CrudBatch, CrudEntry, CrudTransaction, DEFAULT_CRUD_BATCH_LIMIT, DEFAULT_CRUD_UPLOAD_THROTTLE_MS, DEFAULT_INDEX_COLUMN_OPTIONS, DEFAULT_INDEX_OPTIONS, DEFAULT_LOCK_TIMEOUT_MS, DEFAULT_POWERSYNC_CLOSE_OPTIONS, DEFAULT_POWERSYNC_DB_OPTIONS, DEFAULT_PRESSURE_LIMITS, DEFAULT_REMOTE_LOGGER, DEFAULT_REMOTE_OPTIONS, DEFAULT_RETRY_DELAY_MS, DEFAULT_ROW_COMPARATOR, DEFAULT_STREAMING_SYNC_OPTIONS, DEFAULT_STREAM_CONNECTION_OPTIONS, DEFAULT_SYNC_CLIENT_IMPLEMENTATION, DEFAULT_TABLE_OPTIONS, DEFAULT_WATCH_QUERY_OPTIONS, DEFAULT_WATCH_THROTTLE_MS, DataStream, DiffTriggerOperation, DifferentialQueryProcessor, EMPTY_DIFFERENTIAL, EncodingType, FalsyComparator, FetchImplementationProvider, FetchStrategy, GetAllQuery, Index, IndexedColumn, InvalidSQLCharacters, LockType, LogLevel, MAX_AMOUNT_OF_COLUMNS, MAX_OP_ID, MEMORY_TRIGGER_CLAIM_MANAGER, OnChangeQueryProcessor, OpType, OpTypeEnum, OplogEntry, PSInternalTable, PowerSyncControlCommand, RowUpdateType, Schema, SqliteBucketStorage, SyncClientImplementation, SyncDataBatch, SyncDataBucket, SyncProgress, SyncStatus, SyncStreamConnectionMethod, SyncingService, Table, TableV2, TriggerManagerImpl, UpdateType, UploadQueueStats, WatchedQueryListenerEvent, attachmentFromSql, column, compilableQueryWatch, createBaseLogger, createLogger, extractTableUpdates, isBatchedUpdateNotification, isContinueCheckpointRequest, isDBAdapter, isPowerSyncDatabaseOptionsWithSettings, isSQLOpenFactory, isSQLOpenOptions, isStreamingKeepalive, isStreamingSyncCheckpoint, isStreamingSyncCheckpointComplete, isStreamingSyncCheckpointDiff, isStreamingSyncCheckpointPartiallyComplete, isStreamingSyncData, isSyncNewCheckpointRequest, mutexRunExclusive, parseQuery, runOnSchemaChange, sanitizeSQL, sanitizeUUID };
|
|
4317
|
+
export type { AbstractQueryProcessorOptions, AbstractRemoteOptions, AbstractStreamingSyncImplementationOptions, AdditionalConnectionOptions, ArrayComparatorOptions, ArrayQueryDefinition, AttachmentData, AttachmentErrorHandler, AttachmentRecord, AttachmentTableOptions, BSONImplementation, BaseColumnType, BaseConnectionOptions, BaseListener, BaseObserverInterface, BasePowerSyncDatabaseOptions, BaseTriggerDiffRecord, BatchedUpdateNotification, BucketChecksum, BucketDescription, BucketOperationProgress, BucketRequest, BucketState, BucketStorageAdapter, BucketStorageListener, Checkpoint, ChecksumCache, ColumnOptions, ColumnsType, CompilableQuery, CompilableQueryWatchHandler, CompiledQuery, ConnectionManagerListener, ConnectionManagerOptions, ConnectionManagerSyncImplementationResult, ContinueCheckpointRequest, ControlledExecutorOptions, CreateDiffTriggerOptions, CreateLoggerOptions, CreateSyncImplementationOptions, CrudRequest, CrudResponse, CrudUploadNotification, DBAdapter, DBAdapterListener, DBGetUtils, DBLockOptions, DataStreamCallback, DataStreamListener, DataStreamOptions, DifferentialQueryProcessorOptions, DifferentialWatchedQuery, DifferentialWatchedQueryComparator, DifferentialWatchedQueryListener, DifferentialWatchedQueryOptions, DifferentialWatchedQuerySettings, DisconnectAndClearOptions, Disposable, ExtractColumnValueType, ExtractedTriggerDiffRecord, FetchImplementation, GetAllQueryOptions, IndexColumnOptions, IndexOptions, IndexShorthand, InternalConnectionOptions, InternalSubscriptionAdapter, LinkQueryOptions, LocalStorageAdapter, LockContext, LockOptions, MutableWatchedQueryState, OnChangeQueryProcessorOptions, OpId, OpTypeJSON, OplogEntryJSON, ParsedQuery, PendingStatement, PendingStatementParameter, PowerSyncBackendConnector, PowerSyncCloseOptions, PowerSyncConnectionOptions, PowerSyncCredentials, PowerSyncDBListener, PowerSyncDatabaseOptions, PowerSyncDatabaseOptionsWithDBAdapter, PowerSyncDatabaseOptionsWithOpenFactory, PowerSyncDatabaseOptionsWithSettings, PowerSyncOpenFactoryOptions, ProgressWithOperations, Query, QueryParam, QueryResult, RawTableType, RemoteConnector, RemoteStorageAdapter, RequiredAdditionalConnectionOptions, RequiredPowerSyncConnectionOptions, RowType, SQLOnChangeOptions, SQLOpenFactory, SQLOpenOptions, SQLWatchOptions, SavedProgress, SchemaTableType, SocketSyncStreamOptions, StandardWatchedQuery, StandardWatchedQueryOptions, StreamingSyncCheckpoint, StreamingSyncCheckpointComplete, StreamingSyncCheckpointDiff, StreamingSyncCheckpointPartiallyComplete, StreamingSyncDataJSON, StreamingSyncImplementation, StreamingSyncImplementationListener, StreamingSyncKeepalive, StreamingSyncLine, StreamingSyncLineOrCrudUploadComplete, StreamingSyncRequest, StreamingSyncRequestParameterType, SubscribedStream, SyncDataBucketJSON, SyncDataFlowStatus, SyncLocalDatabaseResult, SyncNewCheckpointRequest, SyncPriorityStatus, SyncRequest, SyncResponse, SyncStatusOptions, SyncStream, SyncStreamDescription, SyncStreamOptions, SyncStreamStatus, SyncStreamSubscribeOptions, SyncStreamSubscription, SyncSubscriptionDescription, TableOptions, TableOrRawTableOptions, TableUpdateOperation, TableV2Options, TrackDiffOptions, TrackPreviousOptions, Transaction, TriggerClaimManager, TriggerCreationHooks, TriggerDiffDeleteRecord, TriggerDiffHandlerContext, TriggerDiffInsertRecord, TriggerDiffRecord, TriggerDiffUpdateRecord, TriggerManager, TriggerManagerConfig, TriggerRemoveCallback, UpdateNotification, WatchCompatibleQuery, WatchExecuteOptions, WatchHandler, WatchOnChangeEvent, WatchOnChangeHandler, WatchedAttachmentItem, WatchedQuery, WatchedQueryComparator, WatchedQueryDifferential, WatchedQueryListener, WatchedQueryOptions, WatchedQueryRowDifferential, WatchedQuerySettings, WatchedQueryState, WithDiffOptions };
|