import { Column, ColumnsType, ColumnType, ExtractColumnValueType } from './Column.js'; import { Index } from './Index.js'; import { TableV2 } from './TableV2.js'; interface SharedTableOptions { localOnly?: boolean; insertOnly?: boolean; viewName?: string; trackPrevious?: boolean | TrackPreviousOptions; trackMetadata?: boolean; ignoreEmptyUpdates?: boolean; } /** Whether to include previous column values when PowerSync tracks local changes. * * Including old values may be helpful for some backend connector implementations, which is * why it can be enabled on per-table or per-columm basis. */ export interface TrackPreviousOptions { /** When defined, a list of column names for which old values should be tracked. */ columns?: string[]; /** When enabled, only include values that have actually been changed by an update. */ onlyWhenChanged?: boolean; } export interface TableOptions extends SharedTableOptions { /** * The synced table name, matching sync rules */ name: string; columns: Column[]; indexes?: Index[]; } export type RowType> = { [K in keyof T['columnMap']]: ExtractColumnValueType; } & { id: string; }; export type IndexShorthand = Record; export interface TableV2Options extends SharedTableOptions { indexes?: IndexShorthand; } export declare const DEFAULT_TABLE_OPTIONS: { indexes: never[]; insertOnly: boolean; localOnly: boolean; trackPrevious: boolean; trackMetadata: boolean; ignoreEmptyUpdates: boolean; }; export declare const InvalidSQLCharacters: RegExp; export declare class Table { protected options: TableOptions; protected _mappedColumns: Columns; static createLocalOnly(options: TableOptions): Table; static createInsertOnly(options: TableOptions): Table; /** * Create a table. * @deprecated This was only only included for TableV2 and is no longer necessary. * Prefer to use new Table() directly. * * TODO remove in the next major release. */ static createTable(name: string, table: Table): Table; /** * Creates a new Table instance. * * This constructor supports two different versions: * 1. New constructor: Using a Columns object and an optional TableV2Options object * 2. Deprecated constructor: Using a TableOptions object (will be removed in the next major release) * * @constructor * @param {Columns | TableOptions} optionsOrColumns - Either a Columns object (for V2 syntax) or a TableOptions object (for V1 syntax) * @param {TableV2Options} [v2Options] - Optional configuration options for V2 syntax * * @example * ```javascript * // New Constructor * const table = new Table( * { * name: column.text, * age: column.integer * }, * { indexes: { nameIndex: ['name'] } } * ); *``` * * * @example * ```javascript * // Deprecated Constructor * const table = new Table({ * name: 'users', * columns: [ * new Column({ name: 'name', type: ColumnType.TEXT }), * new Column({ name: 'age', type: ColumnType.INTEGER }) * ] * }); *``` */ constructor(columns: Columns, options?: TableV2Options); /** * @deprecated This constructor will be removed in the next major release. * Use the new constructor shown below instead as this does not show types. * @example * Use this instead * ```javascript * const table = new Table( * { * name: column.text, * age: column.integer * }, * { indexes: { nameIndex: ['name'] } } * ); *``` */ constructor(options: TableOptions); copyWithName(name: string): Table; private isTableV1; private initTableV1; private initTableV2; private applyDefaultOptions; get name(): string; get viewNameOverride(): string | undefined; get viewName(): string; get columns(): Column[]; get columnMap(): Columns; get indexes(): Index[]; get localOnly(): boolean; get insertOnly(): boolean; get trackPrevious(): boolean | TrackPreviousOptions; get trackMetadata(): boolean; get ignoreEmptyUpdates(): boolean; get internalName(): string; get validName(): boolean; validate(): void; toJSON(): { name: string; view_name: string; local_only: boolean; insert_only: boolean; include_old: any; include_old_only_when_changed: boolean; include_metadata: boolean; ignore_empty_update: boolean; columns: { name: string; type: ColumnType | undefined; }[]; indexes: { name: string; columns: { name: string; ascending: boolean | undefined; type: ColumnType; }[]; }[]; }; } export {};