@powersync/common 1.47.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/dist/bundle.cjs +42 -45
- package/dist/bundle.cjs.map +1 -1
- package/dist/bundle.mjs +43 -45
- package/dist/bundle.mjs.map +1 -1
- package/dist/bundle.node.cjs +42 -45
- package/dist/bundle.node.cjs.map +1 -1
- package/dist/bundle.node.mjs +43 -45
- package/dist/bundle.node.mjs.map +1 -1
- package/dist/index.d.cts +124 -79
- 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 +1 -1
- package/lib/index.js +0 -1
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- 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 +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 {
|
|
@@ -4268,5 +4313,5 @@ interface ParsedQuery {
|
|
|
4268
4313
|
}
|
|
4269
4314
|
declare const parseQuery: <T>(query: string | CompilableQuery<T>, parameters: any[]) => ParsedQuery;
|
|
4270
4315
|
|
|
4271
|
-
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,
|
|
4272
|
-
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, 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 };
|
|
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 };
|
|
@@ -1,8 +1,21 @@
|
|
|
1
|
+
import { TableOrRawTableOptions } from './Table.js';
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
3
|
+
* Instructs PowerSync to sync data into a "raw" table.
|
|
4
|
+
*
|
|
5
|
+
* Since raw tables are not backed by JSON, running complex queries on them may be more efficient. Further, they allow
|
|
6
|
+
* using client-side table and column constraints.
|
|
7
|
+
*
|
|
8
|
+
* To collect local writes to raw tables with PowerSync, custom triggers are required. See
|
|
9
|
+
* {@link https://docs.powersync.com/usage/use-case-examples/raw-tables the documentation} for details and an example on
|
|
10
|
+
* using raw tables.
|
|
11
|
+
*
|
|
12
|
+
* Note that raw tables are only supported when using the new `SyncClientImplementation.rust` sync client.
|
|
13
|
+
*
|
|
14
|
+
* @experimental Please note that this feature is experimental at the moment, and not covered by PowerSync semver or
|
|
15
|
+
* stability guarantees.
|
|
4
16
|
*/
|
|
5
|
-
export type RawTableType =
|
|
17
|
+
export type RawTableType = RawTableTypeWithStatements | InferredRawTableType;
|
|
18
|
+
interface RawTableTypeWithStatements {
|
|
6
19
|
/**
|
|
7
20
|
* The statement to run when PowerSync detects that a row needs to be inserted or updated.
|
|
8
21
|
*/
|
|
@@ -11,7 +24,40 @@ export type RawTableType = {
|
|
|
11
24
|
* The statement to run when PowerSync detects that a row needs to be deleted.
|
|
12
25
|
*/
|
|
13
26
|
delete: PendingStatement;
|
|
14
|
-
|
|
27
|
+
/**
|
|
28
|
+
* An optional statement to run when `disconnectAndClear()` is called on a PowerSync database.
|
|
29
|
+
*/
|
|
30
|
+
clear?: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The schema of a {@link RawTableType} in the local database.
|
|
34
|
+
*
|
|
35
|
+
* This information is optional when declaring raw tables. However, providing it allows the sync client to infer `put`
|
|
36
|
+
* and `delete` statements automatically.
|
|
37
|
+
*/
|
|
38
|
+
interface RawTableSchema extends TableOrRawTableOptions {
|
|
39
|
+
/**
|
|
40
|
+
* The actual name of the raw table in the local schema.
|
|
41
|
+
*
|
|
42
|
+
* Unlike {@link RawTable.name}, which describes the name of synced tables to match, this reflects the SQLite table
|
|
43
|
+
* name. This is used to infer {@link RawTableType.put} and {@link RawTableType.delete} statements for the sync
|
|
44
|
+
* client. It can also be used to auto-generate triggers forwarding writes on raw tables into the CRUD upload queue
|
|
45
|
+
* (using the `powersync_create_raw_table_crud_trigger` SQL function).
|
|
46
|
+
*
|
|
47
|
+
* When absent, defaults to {@link RawTable.name}.
|
|
48
|
+
*/
|
|
49
|
+
tableName?: string;
|
|
50
|
+
/**
|
|
51
|
+
* An optional filter of columns that should be synced.
|
|
52
|
+
*
|
|
53
|
+
* By default, all columns in a raw table are considered for sync. If a filter is specified, PowerSync treats
|
|
54
|
+
* unmatched columns as local-only and will not attempt to sync them.
|
|
55
|
+
*/
|
|
56
|
+
syncedColumns?: string[];
|
|
57
|
+
}
|
|
58
|
+
interface InferredRawTableType extends Partial<RawTableTypeWithStatements> {
|
|
59
|
+
schema: RawTableSchema;
|
|
60
|
+
}
|
|
15
61
|
/**
|
|
16
62
|
* A parameter to use as part of {@link PendingStatement}.
|
|
17
63
|
*
|
|
@@ -20,10 +66,12 @@ export type RawTableType = {
|
|
|
20
66
|
*
|
|
21
67
|
* For insert and replace operations, the values of columns in the table are available as parameters through
|
|
22
68
|
* `{Column: 'name'}`.
|
|
69
|
+
* The `"Rest"` parameter gets resolved to a JSON object covering all values from the synced row that haven't been
|
|
70
|
+
* covered by a `Column` parameter.
|
|
23
71
|
*/
|
|
24
72
|
export type PendingStatementParameter = 'Id' | {
|
|
25
73
|
Column: string;
|
|
26
|
-
};
|
|
74
|
+
} | 'Rest';
|
|
27
75
|
/**
|
|
28
76
|
* A statement that the PowerSync client should use to insert or delete data into a table managed by the user.
|
|
29
77
|
*/
|
|
@@ -32,30 +80,17 @@ export type PendingStatement = {
|
|
|
32
80
|
params: PendingStatementParameter[];
|
|
33
81
|
};
|
|
34
82
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* Since raw tables are not backed by JSON, running complex queries on them may be more efficient. Further, they allow
|
|
38
|
-
* using client-side table and column constraints.
|
|
39
|
-
*
|
|
40
|
-
* To collect local writes to raw tables with PowerSync, custom triggers are required. See
|
|
41
|
-
* {@link https://docs.powersync.com/usage/use-case-examples/raw-tables the documentation} for details and an example on
|
|
42
|
-
* using raw tables.
|
|
43
|
-
*
|
|
44
|
-
* Note that raw tables are only supported when using the new `SyncClientImplementation.rust` sync client.
|
|
45
|
-
*
|
|
46
|
-
* @experimental Please note that this feature is experimental at the moment, and not covered by PowerSync semver or
|
|
47
|
-
* stability guarantees.
|
|
83
|
+
* @internal
|
|
48
84
|
*/
|
|
49
|
-
export
|
|
85
|
+
export type RawTable<T extends RawTableType = RawTableType> = T & {
|
|
50
86
|
/**
|
|
51
87
|
* The name of the table.
|
|
52
88
|
*
|
|
53
|
-
* This does not have to match the actual table name in the schema - {@link put} and
|
|
54
|
-
* another table. Instead, this name is used by the sync client to
|
|
55
|
-
* appears in the source / backend database) are to be handled
|
|
89
|
+
* This does not have to match the actual table name in the schema - {@link RawTableType.put} and
|
|
90
|
+
* {@link RawTableType.delete} are free to use another table. Instead, this name is used by the sync client to
|
|
91
|
+
* recognize that operations on this table (as it appears in the source / backend database) are to be handled
|
|
92
|
+
* specially.
|
|
56
93
|
*/
|
|
57
94
|
name: string;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
constructor(name: string, type: RawTableType);
|
|
61
|
-
}
|
|
95
|
+
};
|
|
96
|
+
export {};
|
|
@@ -1,33 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
* Instructs PowerSync to sync data into a "raw" table.
|
|
3
|
-
*
|
|
4
|
-
* Since raw tables are not backed by JSON, running complex queries on them may be more efficient. Further, they allow
|
|
5
|
-
* using client-side table and column constraints.
|
|
6
|
-
*
|
|
7
|
-
* To collect local writes to raw tables with PowerSync, custom triggers are required. See
|
|
8
|
-
* {@link https://docs.powersync.com/usage/use-case-examples/raw-tables the documentation} for details and an example on
|
|
9
|
-
* using raw tables.
|
|
10
|
-
*
|
|
11
|
-
* Note that raw tables are only supported when using the new `SyncClientImplementation.rust` sync client.
|
|
12
|
-
*
|
|
13
|
-
* @experimental Please note that this feature is experimental at the moment, and not covered by PowerSync semver or
|
|
14
|
-
* stability guarantees.
|
|
15
|
-
*/
|
|
16
|
-
export class RawTable {
|
|
17
|
-
/**
|
|
18
|
-
* The name of the table.
|
|
19
|
-
*
|
|
20
|
-
* This does not have to match the actual table name in the schema - {@link put} and {@link delete} are free to use
|
|
21
|
-
* another table. Instead, this name is used by the sync client to recognize that operations on this table (as it
|
|
22
|
-
* appears in the source / backend database) are to be handled specially.
|
|
23
|
-
*/
|
|
24
|
-
name;
|
|
25
|
-
put;
|
|
26
|
-
delete;
|
|
27
|
-
constructor(name, type) {
|
|
28
|
-
this.name = name;
|
|
29
|
-
this.put = type.put;
|
|
30
|
-
this.delete = type.delete;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
1
|
+
export {};
|
|
33
2
|
//# sourceMappingURL=RawTable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RawTable.js","sourceRoot":"","sources":["../../../src/db/schema/RawTable.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"RawTable.js","sourceRoot":"","sources":["../../../src/db/schema/RawTable.ts"],"names":[],"mappings":""}
|
|
@@ -27,14 +27,14 @@ export declare class Schema<S extends SchemaType = SchemaType> {
|
|
|
27
27
|
validate(): void;
|
|
28
28
|
toJSON(): {
|
|
29
29
|
tables: {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
local_only: boolean;
|
|
33
|
-
insert_only: boolean;
|
|
30
|
+
local_only: boolean | undefined;
|
|
31
|
+
insert_only: boolean | undefined;
|
|
34
32
|
include_old: any;
|
|
35
33
|
include_old_only_when_changed: boolean;
|
|
36
|
-
include_metadata: boolean;
|
|
37
|
-
ignore_empty_update: boolean;
|
|
34
|
+
include_metadata: boolean | undefined;
|
|
35
|
+
ignore_empty_update: boolean | undefined;
|
|
36
|
+
name: string;
|
|
37
|
+
view_name: string;
|
|
38
38
|
columns: {
|
|
39
39
|
name: string;
|
|
40
40
|
type: import("./Column.js").ColumnType | undefined;
|
|
@@ -48,7 +48,14 @@ export declare class Schema<S extends SchemaType = SchemaType> {
|
|
|
48
48
|
}[];
|
|
49
49
|
}[];
|
|
50
50
|
}[];
|
|
51
|
-
raw_tables:
|
|
51
|
+
raw_tables: unknown[];
|
|
52
52
|
};
|
|
53
|
+
/**
|
|
54
|
+
* Returns a representation of the raw table that is understood by the PowerSync SQLite core extension.
|
|
55
|
+
*
|
|
56
|
+
* The output of this can be passed through `JSON.serialize` and then used in `powersync_create_raw_table_crud_trigger`
|
|
57
|
+
* to define triggers for this table.
|
|
58
|
+
*/
|
|
59
|
+
static rawTableToJson(table: RawTable): unknown;
|
|
53
60
|
}
|
|
54
61
|
export {};
|
package/lib/db/schema/Schema.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { encodeTableOptions } from './internal.js';
|
|
2
2
|
/**
|
|
3
3
|
* A schema is a collection of tables. It is used to define the structure of a database.
|
|
4
4
|
*/
|
|
@@ -43,7 +43,7 @@ export class Schema {
|
|
|
43
43
|
*/
|
|
44
44
|
withRawTables(tables) {
|
|
45
45
|
for (const [name, rawTableDefinition] of Object.entries(tables)) {
|
|
46
|
-
this.rawTables.push(
|
|
46
|
+
this.rawTables.push({ name, ...rawTableDefinition });
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
validate() {
|
|
@@ -54,8 +54,30 @@ export class Schema {
|
|
|
54
54
|
toJSON() {
|
|
55
55
|
return {
|
|
56
56
|
tables: this.tables.map((t) => t.toJSON()),
|
|
57
|
-
raw_tables: this.rawTables
|
|
57
|
+
raw_tables: this.rawTables.map(Schema.rawTableToJson)
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Returns a representation of the raw table that is understood by the PowerSync SQLite core extension.
|
|
62
|
+
*
|
|
63
|
+
* The output of this can be passed through `JSON.serialize` and then used in `powersync_create_raw_table_crud_trigger`
|
|
64
|
+
* to define triggers for this table.
|
|
65
|
+
*/
|
|
66
|
+
static rawTableToJson(table) {
|
|
67
|
+
const serialized = {
|
|
68
|
+
name: table.name,
|
|
69
|
+
put: table.put,
|
|
70
|
+
delete: table.delete,
|
|
71
|
+
clear: table.clear
|
|
72
|
+
};
|
|
73
|
+
if ('schema' in table) {
|
|
74
|
+
// We have schema options, those are flattened into the outer JSON object for the core extension.
|
|
75
|
+
const schema = table.schema;
|
|
76
|
+
serialized.table_name = schema.tableName ?? table.name;
|
|
77
|
+
serialized.synced_columns = schema.syncedColumns;
|
|
78
|
+
Object.assign(serialized, encodeTableOptions(table.schema));
|
|
79
|
+
}
|
|
80
|
+
return serialized;
|
|
81
|
+
}
|
|
60
82
|
}
|
|
61
83
|
//# sourceMappingURL=Schema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Schema.js","sourceRoot":"","sources":["../../../src/db/schema/Schema.ts"],"names":[],"mappings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E,GAAG,kBAAkB,EAAE,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;IAED,QAAQ;QACN,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChC,KAAK,CAAC,QAAQ,EAAE,CAAC;QACnB,CAAC;IACH,CAAC;IAED,MAAM;QACJ,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;YAC1C,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,cAAc,CAAC;SACtD,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,cAAc,CAAC,KAAe;QACnC,MAAM,UAAU,GAAQ;YACtB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,GAAG,EAAE,KAAK,CAAC,GAAG;YACd,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,KAAK,EAAE,KAAK,CAAC,KAAK;SACnB,CAAC;QACF,IAAI,QAAQ,IAAI,KAAK,EAAE,CAAC;YACtB,iGAAiG;YACjG,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;YAC5B,UAAU,CAAC,UAAU,GAAG,MAAM,CAAC,SAAS,IAAI,KAAK,CAAC,IAAI,CAAC;YACvD,UAAU,CAAC,cAAc,GAAG,MAAM,CAAC,aAAa,CAAC;YACjD,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,kBAAkB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;QAC9D,CAAC;QAED,OAAO,UAAU,CAAC;IACpB,CAAC;CACF"}
|
package/lib/db/schema/Table.d.ts
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import { Column, ColumnsType, ColumnType, ExtractColumnValueType } from './Column.js';
|
|
2
2
|
import { Index } from './Index.js';
|
|
3
3
|
import { TableV2 } from './TableV2.js';
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Options that apply both to JSON-based tables and raw tables.
|
|
6
|
+
*/
|
|
7
|
+
export interface TableOrRawTableOptions {
|
|
5
8
|
localOnly?: boolean;
|
|
6
9
|
insertOnly?: boolean;
|
|
7
|
-
viewName?: string;
|
|
8
10
|
trackPrevious?: boolean | TrackPreviousOptions;
|
|
9
11
|
trackMetadata?: boolean;
|
|
10
12
|
ignoreEmptyUpdates?: boolean;
|
|
11
13
|
}
|
|
14
|
+
interface SharedTableOptions extends TableOrRawTableOptions {
|
|
15
|
+
viewName?: string;
|
|
16
|
+
}
|
|
12
17
|
/** Whether to include previous column values when PowerSync tracks local changes.
|
|
13
18
|
*
|
|
14
19
|
* Including old values may be helpful for some backend connector implementations, which is
|
|
@@ -132,14 +137,14 @@ export declare class Table<Columns extends ColumnsType = ColumnsType> {
|
|
|
132
137
|
get validName(): boolean;
|
|
133
138
|
validate(): void;
|
|
134
139
|
toJSON(): {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
local_only: boolean;
|
|
138
|
-
insert_only: boolean;
|
|
140
|
+
local_only: boolean | undefined;
|
|
141
|
+
insert_only: boolean | undefined;
|
|
139
142
|
include_old: any;
|
|
140
143
|
include_old_only_when_changed: boolean;
|
|
141
|
-
include_metadata: boolean;
|
|
142
|
-
ignore_empty_update: boolean;
|
|
144
|
+
include_metadata: boolean | undefined;
|
|
145
|
+
ignore_empty_update: boolean | undefined;
|
|
146
|
+
name: string;
|
|
147
|
+
view_name: string;
|
|
143
148
|
columns: {
|
|
144
149
|
name: string;
|
|
145
150
|
type: ColumnType | undefined;
|
package/lib/db/schema/Table.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Column, ColumnType, MAX_AMOUNT_OF_COLUMNS } from './Column.js';
|
|
2
2
|
import { Index } from './Index.js';
|
|
3
3
|
import { IndexedColumn } from './IndexedColumn.js';
|
|
4
|
+
import { encodeTableOptions } from './internal.js';
|
|
4
5
|
export const DEFAULT_TABLE_OPTIONS = {
|
|
5
6
|
indexes: [],
|
|
6
7
|
insertOnly: false,
|
|
@@ -190,18 +191,12 @@ export class Table {
|
|
|
190
191
|
}
|
|
191
192
|
}
|
|
192
193
|
toJSON() {
|
|
193
|
-
const trackPrevious = this.trackPrevious;
|
|
194
194
|
return {
|
|
195
195
|
name: this.name,
|
|
196
196
|
view_name: this.viewName,
|
|
197
|
-
local_only: this.localOnly,
|
|
198
|
-
insert_only: this.insertOnly,
|
|
199
|
-
include_old: trackPrevious && (trackPrevious.columns ?? true),
|
|
200
|
-
include_old_only_when_changed: typeof trackPrevious == 'object' && trackPrevious.onlyWhenChanged == true,
|
|
201
|
-
include_metadata: this.trackMetadata,
|
|
202
|
-
ignore_empty_update: this.ignoreEmptyUpdates,
|
|
203
197
|
columns: this.columns.map((c) => c.toJSON()),
|
|
204
|
-
indexes: this.indexes.map((e) => e.toJSON(this))
|
|
198
|
+
indexes: this.indexes.map((e) => e.toJSON(this)),
|
|
199
|
+
...encodeTableOptions(this)
|
|
205
200
|
};
|
|
206
201
|
}
|
|
207
202
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Table.js","sourceRoot":"","sources":["../../../src/db/schema/Table.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,MAAM,EAEN,UAAU,EAEV,qBAAqB,EACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"Table.js","sourceRoot":"","sources":["../../../src/db/schema/Table.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,MAAM,EAEN,UAAU,EAEV,qBAAqB,EACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,M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AAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAChD,GAAG,kBAAkB,CAAC,IAAI,CAAC;SAC5B,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TableOrRawTableOptions } from './Table.js';
|
|
2
|
+
/**
|
|
3
|
+
* @internal Not exported from `index.ts`.
|
|
4
|
+
*/
|
|
5
|
+
export declare function encodeTableOptions(options: TableOrRawTableOptions): {
|
|
6
|
+
local_only: boolean | undefined;
|
|
7
|
+
insert_only: boolean | undefined;
|
|
8
|
+
include_old: any;
|
|
9
|
+
include_old_only_when_changed: boolean;
|
|
10
|
+
include_metadata: boolean | undefined;
|
|
11
|
+
ignore_empty_update: boolean | undefined;
|
|
12
|
+
};
|