diff --git a/.changeset/dry-bugs-invite.md b/.changeset/dry-bugs-invite.md new file mode 100644 index 000000000..3e57b4df1 --- /dev/null +++ b/.changeset/dry-bugs-invite.md @@ -0,0 +1,5 @@ +--- +'@powersync/common': minor +--- + +[Attachments] Added `AttachmentTableRecord` type, which describes the attachment table's row type. diff --git a/packages/common/etc/common.api.md b/packages/common/etc/common.api.md index 9012adc3e..fa41eaed3 100644 --- a/packages/common/etc/common.api.md +++ b/packages/common/etc/common.api.md @@ -373,6 +373,18 @@ export interface ArrayQueryDefinition { // @alpha export const ATTACHMENT_TABLE = "attachments"; +// @alpha (undocumented) +export const ATTACHMENT_TABLE_COLUMNS: { + filename: BaseColumnType; + local_uri: BaseColumnType; + timestamp: BaseColumnType; + size: BaseColumnType; + media_type: BaseColumnType; + state: BaseColumnType; + has_synced: BaseColumnType; + meta_data: BaseColumnType; +}; + // @alpha export class AttachmentContext { constructor(db: AbstractPowerSyncDatabase, tableName: string | undefined, logger: ILogger, archivedCacheLimit: number); @@ -506,7 +518,7 @@ export enum AttachmentState { } // @alpha -export class AttachmentTable extends Table { +export class AttachmentTable extends Table { constructor(options?: AttachmentTableOptions); } @@ -514,6 +526,9 @@ export class AttachmentTable extends Table { export interface AttachmentTableOptions extends Omit { } +// @alpha +export type AttachmentTableRecord = RowType; + // @public (undocumented) export type BaseColumnType = { type: ColumnType; diff --git a/packages/common/src/attachments/Schema.ts b/packages/common/src/attachments/Schema.ts index 1714e1d75..f7ac5bfe9 100644 --- a/packages/common/src/attachments/Schema.ts +++ b/packages/common/src/attachments/Schema.ts @@ -1,5 +1,5 @@ import { column } from '../db/schema/Column.js'; -import { Table } from '../db/schema/Table.js'; +import { RowType, Table } from '../db/schema/Table.js'; import { TableV2Options } from '../db/schema/Table.js'; /** @@ -66,30 +66,39 @@ export enum AttachmentState { */ export interface AttachmentTableOptions extends Omit {} +/** + * @alpha + */ +export const ATTACHMENT_TABLE_COLUMNS = { + filename: column.text, + local_uri: column.text, + timestamp: column.integer, + size: column.integer, + media_type: column.text, + state: column.integer, // Corresponds to AttachmentState + has_synced: column.integer, + meta_data: column.text +}; + /** * AttachmentTable defines the schema for the attachment queue table. * * @alpha */ -export class AttachmentTable extends Table { +export class AttachmentTable extends Table { constructor(options?: AttachmentTableOptions) { - super( - { - filename: column.text, - local_uri: column.text, - timestamp: column.integer, - size: column.integer, - media_type: column.text, - state: column.integer, // Corresponds to AttachmentState - has_synced: column.integer, - meta_data: column.text - }, - { - ...options, - viewName: options?.viewName ?? ATTACHMENT_TABLE, - localOnly: true, - insertOnly: false - } - ); + super(ATTACHMENT_TABLE_COLUMNS, { + ...options, + viewName: options?.viewName ?? ATTACHMENT_TABLE, + localOnly: true, + insertOnly: false + }); } } + +/** + * AttachmentTableRecord represents the row type of the attachment table. + * + * @alpha + */ +export type AttachmentTableRecord = RowType;