|
| 1 | +import { BucketParameterQuerier, ParameterLookup } from './BucketParameterQuerier.js'; |
| 2 | +import { ColumnDefinition } from './ExpressionType.js'; |
| 3 | +import { SourceTableInterface } from './SourceTableInterface.js'; |
| 4 | +import { GetQuerierOptions } from './SqlSyncRules.js'; |
| 5 | +import { TablePattern } from './TablePattern.js'; |
| 6 | +import { EvaluatedParametersResult, EvaluateRowOptions, EvaluationResult, SourceSchema, SqliteRow } from './types.js'; |
| 7 | + |
| 8 | +/** |
| 9 | + * An interface declaring |
| 10 | + * |
| 11 | + * - which buckets the sync service should create when processing change streams from the database. |
| 12 | + * - how data in source tables maps to data in buckets (e.g. when we're not selecting all columns). |
| 13 | + * - which buckets a given connection has access to. |
| 14 | + * |
| 15 | + * There are two ways to define bucket sources: Via sync rules made up of parameter and data queries, and via stream |
| 16 | + * definitions that only consist of a single query. |
| 17 | + */ |
| 18 | +export interface BucketSource { |
| 19 | + name: string; |
| 20 | + |
| 21 | + /** |
| 22 | + * Given a row in a source table that affects sync parameters, returns a structure to index which buckets rows should |
| 23 | + * be associated with. |
| 24 | + * |
| 25 | + * The returned {@link ParameterLookup} can be referenced by {@link pushBucketParameterQueriers} to allow the storage |
| 26 | + * system to find buckets. |
| 27 | + */ |
| 28 | + evaluateParameterRow(sourceTable: SourceTableInterface, row: SqliteRow): EvaluatedParametersResult[]; |
| 29 | + |
| 30 | + /** |
| 31 | + * Given a row as it appears in a table that affects sync data, return buckets, logical table names and transformed |
| 32 | + * data for rows to add to buckets. |
| 33 | + */ |
| 34 | + evaluateRow(options: EvaluateRowOptions): EvaluationResult[]; |
| 35 | + |
| 36 | + /** |
| 37 | + * Reports {@link BucketParameterQuerier}s resolving buckets that a specific stream request should have access to. |
| 38 | + * |
| 39 | + * @param result The target array to insert queriers into. |
| 40 | + * @param options Options, including parameters that may affect the buckets loaded by this source. |
| 41 | + */ |
| 42 | + pushBucketParameterQueriers(result: BucketParameterQuerier[], options: GetQuerierOptions): void; |
| 43 | + |
| 44 | + /** |
| 45 | + * Whether {@link pushBucketParameterQueriers} may include a querier where |
| 46 | + * {@link BucketParameterQuerier.hasDynamicBuckets} is true. |
| 47 | + * |
| 48 | + * This is mostly used for testing. |
| 49 | + */ |
| 50 | + hasDynamicBucketQueries(): boolean; |
| 51 | + |
| 52 | + getSourceTables(): Set<TablePattern>; |
| 53 | + |
| 54 | + /** Whether the table possibly affects the buckets resolved by this source. */ |
| 55 | + tableSyncsParameters(table: SourceTableInterface): boolean; |
| 56 | + |
| 57 | + /** Whether the table possibly affects the contents of buckets resolved by this source. */ |
| 58 | + tableSyncsData(table: SourceTableInterface): boolean; |
| 59 | + |
| 60 | + /** |
| 61 | + * Given a static schema, infer all logical tables and associated columns that appear in buckets defined by this |
| 62 | + * source. |
| 63 | + * |
| 64 | + * This is use to generate the client-side schema. |
| 65 | + */ |
| 66 | + resolveResultSets(schema: SourceSchema): ResultSetDescription[]; |
| 67 | +} |
| 68 | + |
| 69 | +export type ResultSetDescription = { name: string; columns: ColumnDefinition[] }; |
0 commit comments