lakesync 0.1.6 → 0.2.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.
Files changed (70) hide show
  1. package/dist/adapter-types-DwsQGQS4.d.ts +94 -0
  2. package/dist/adapter.d.ts +202 -63
  3. package/dist/adapter.js +20 -5
  4. package/dist/analyst.js +2 -2
  5. package/dist/{base-poller-BpUyuG2R.d.ts → base-poller-Y7ORYgUv.d.ts} +78 -19
  6. package/dist/catalogue.d.ts +1 -1
  7. package/dist/catalogue.js +3 -3
  8. package/dist/{chunk-P3FT7QCW.js → chunk-4SG66H5K.js} +395 -252
  9. package/dist/chunk-4SG66H5K.js.map +1 -0
  10. package/dist/{chunk-GUJWMK5P.js → chunk-C4KD6YKP.js} +419 -380
  11. package/dist/chunk-C4KD6YKP.js.map +1 -0
  12. package/dist/chunk-DGUM43GV.js +11 -0
  13. package/dist/{chunk-IRJ4QRWV.js → chunk-FIIHPQMQ.js} +396 -209
  14. package/dist/chunk-FIIHPQMQ.js.map +1 -0
  15. package/dist/{chunk-UAUQGP3B.js → chunk-U2NV4DUX.js} +2 -2
  16. package/dist/{chunk-NCZYFZ3B.js → chunk-XVP5DJJ7.js} +44 -18
  17. package/dist/{chunk-NCZYFZ3B.js.map → chunk-XVP5DJJ7.js.map} +1 -1
  18. package/dist/{chunk-FHVTUKXL.js → chunk-YHYBLU6W.js} +2 -2
  19. package/dist/{chunk-QMS7TGFL.js → chunk-ZNY4DSFU.js} +29 -15
  20. package/dist/{chunk-QMS7TGFL.js.map → chunk-ZNY4DSFU.js.map} +1 -1
  21. package/dist/{chunk-SF7Y6ZUA.js → chunk-ZU7RC7CT.js} +2 -2
  22. package/dist/client.d.ts +186 -17
  23. package/dist/client.js +456 -188
  24. package/dist/client.js.map +1 -1
  25. package/dist/compactor.d.ts +2 -2
  26. package/dist/compactor.js +4 -4
  27. package/dist/connector-jira.d.ts +13 -3
  28. package/dist/connector-jira.js +7 -3
  29. package/dist/connector-salesforce.d.ts +13 -3
  30. package/dist/connector-salesforce.js +7 -3
  31. package/dist/{coordinator-D32a5rNk.d.ts → coordinator-eGmZMnJ_.d.ts} +120 -30
  32. package/dist/create-poller-Cc2MGfhh.d.ts +55 -0
  33. package/dist/factory-DFfR-030.d.ts +33 -0
  34. package/dist/gateway-server.d.ts +516 -119
  35. package/dist/gateway-server.js +1201 -4035
  36. package/dist/gateway-server.js.map +1 -1
  37. package/dist/gateway.d.ts +69 -106
  38. package/dist/gateway.js +13 -6
  39. package/dist/index.d.ts +65 -58
  40. package/dist/index.js +18 -4
  41. package/dist/parquet.d.ts +1 -1
  42. package/dist/parquet.js +3 -3
  43. package/dist/proto.d.ts +1 -1
  44. package/dist/proto.js +3 -3
  45. package/dist/react.d.ts +47 -10
  46. package/dist/react.js +88 -40
  47. package/dist/react.js.map +1 -1
  48. package/dist/{registry-CPTgO9jv.d.ts → registry-Dd8JuW8T.d.ts} +19 -4
  49. package/dist/{gateway-Bpvatd9n.d.ts → request-handler-B1I5xDOx.d.ts} +193 -20
  50. package/dist/{resolver-CbuXm3nB.d.ts → resolver-CXxmC0jR.d.ts} +1 -1
  51. package/dist/{src-RHKJFQKR.js → src-WU7IBVC4.js} +19 -5
  52. package/dist/{types-CLlD4XOy.d.ts → types-BdGBv2ba.d.ts} +17 -2
  53. package/dist/{types-D-E0VrfS.d.ts → types-D2C9jTbL.d.ts} +39 -22
  54. package/package.json +1 -1
  55. package/dist/auth-CAVutXzx.d.ts +0 -30
  56. package/dist/chunk-7D4SUZUM.js +0 -38
  57. package/dist/chunk-GUJWMK5P.js.map +0 -1
  58. package/dist/chunk-IRJ4QRWV.js.map +0 -1
  59. package/dist/chunk-P3FT7QCW.js.map +0 -1
  60. package/dist/db-types-BlN-4KbQ.d.ts +0 -29
  61. package/dist/src-CLCALYDT.js +0 -25
  62. package/dist/src-FPJQYQNA.js +0 -27
  63. package/dist/src-FPJQYQNA.js.map +0 -1
  64. package/dist/src-RHKJFQKR.js.map +0 -1
  65. package/dist/types-DSC_EiwR.d.ts +0 -45
  66. /package/dist/{chunk-7D4SUZUM.js.map → chunk-DGUM43GV.js.map} +0 -0
  67. /package/dist/{chunk-UAUQGP3B.js.map → chunk-U2NV4DUX.js.map} +0 -0
  68. /package/dist/{chunk-FHVTUKXL.js.map → chunk-YHYBLU6W.js.map} +0 -0
  69. /package/dist/{chunk-SF7Y6ZUA.js.map → chunk-ZU7RC7CT.js.map} +0 -0
  70. /package/dist/{src-CLCALYDT.js.map → src-WU7IBVC4.js.map} +0 -0
@@ -0,0 +1,94 @@
1
+ import { R as RowDelta, T as TableSchema } from './types-BdGBv2ba.js';
2
+ import { R as Result, A as AdapterError, H as HLCTimestamp } from './result-CojzlFE2.js';
3
+
4
+ /** Information about an object in the lake store. */
5
+ interface ObjectInfo {
6
+ /** S3 object key */
7
+ key: string;
8
+ /** Object size in bytes */
9
+ size: number;
10
+ /** Last modification date */
11
+ lastModified: Date;
12
+ }
13
+ /** Abstract interface for lake storage operations. */
14
+ interface LakeAdapter {
15
+ /** Store an object in the lake. */
16
+ putObject(path: string, data: Uint8Array, contentType?: string): Promise<Result<void, AdapterError>>;
17
+ /** Retrieve an object from the lake. */
18
+ getObject(path: string): Promise<Result<Uint8Array, AdapterError>>;
19
+ /** Get object metadata without retrieving the body. */
20
+ headObject(path: string): Promise<Result<{
21
+ size: number;
22
+ lastModified: Date;
23
+ }, AdapterError>>;
24
+ /** List objects matching a given prefix. */
25
+ listObjects(prefix: string): Promise<Result<ObjectInfo[], AdapterError>>;
26
+ /** Delete a single object from the lake. */
27
+ deleteObject(path: string): Promise<Result<void, AdapterError>>;
28
+ /** Delete multiple objects from the lake in a single batch operation. */
29
+ deleteObjects(paths: string[]): Promise<Result<void, AdapterError>>;
30
+ }
31
+ /** Configuration for a database adapter connection. */
32
+ interface DatabaseAdapterConfig {
33
+ /** Connection string (e.g. postgres://user:pass@host/db) */
34
+ connectionString: string;
35
+ /** Maximum number of connections in the pool (default: 10). */
36
+ poolMax?: number;
37
+ /** Connection idle timeout in milliseconds (default: 10000). */
38
+ idleTimeoutMs?: number;
39
+ /** Connection acquisition timeout in milliseconds (default: 30000). */
40
+ connectionTimeoutMs?: number;
41
+ /** Statement timeout in milliseconds (default: 30000). */
42
+ statementTimeoutMs?: number;
43
+ }
44
+ /**
45
+ * Abstract interface for SQL database storage operations.
46
+ * Alternative to LakeAdapter for small-data backends (Postgres, MySQL, etc).
47
+ */
48
+ interface DatabaseAdapter {
49
+ /** Insert deltas into the database in a single batch. Idempotent via deltaId uniqueness. */
50
+ insertDeltas(deltas: RowDelta[]): Promise<Result<void, AdapterError>>;
51
+ /** Query deltas with HLC greater than the given timestamp, optionally filtered by table. */
52
+ queryDeltasSince(hlc: HLCTimestamp, tables?: string[]): Promise<Result<RowDelta[], AdapterError>>;
53
+ /** Get the latest merged state for a specific row. Returns null if the row doesn't exist. */
54
+ getLatestState(table: string, rowId: string): Promise<Result<Record<string, unknown> | null, AdapterError>>;
55
+ /** Ensure the database schema matches the given TableSchema. Creates/alters tables as needed. */
56
+ ensureSchema(schema: TableSchema): Promise<Result<void, AdapterError>>;
57
+ /** Close the database connection and release resources. */
58
+ close(): Promise<void>;
59
+ }
60
+ /** Type guard to distinguish DatabaseAdapter from LakeAdapter at runtime. */
61
+ declare function isDatabaseAdapter(adapter: unknown): adapter is DatabaseAdapter;
62
+ /**
63
+ * Opt-in capability for adapters that can materialise deltas into destination tables.
64
+ *
65
+ * Materialisation is a separate concern from delta storage — adapters that store
66
+ * deltas (via `DatabaseAdapter.insertDeltas`) may also materialise them into
67
+ * queryable destination tables by implementing this interface.
68
+ *
69
+ * Destination tables follow the hybrid column model:
70
+ * - Synced columns (written by materialiser, derived from `TableSchema.columns`)
71
+ * - `props JSONB DEFAULT '{}'` — consumer-extensible, never touched by materialiser
72
+ * - `synced_at` — updated on every materialise cycle
73
+ */
74
+ interface Materialisable {
75
+ /**
76
+ * Materialise deltas into destination tables.
77
+ *
78
+ * For each table with a matching schema, merges delta history into the
79
+ * latest row state and upserts into the destination table. Tombstoned
80
+ * rows are deleted. The `props` column is never touched.
81
+ *
82
+ * @param deltas - The deltas that were just flushed.
83
+ * @param schemas - Table schemas defining destination tables and column mappings.
84
+ */
85
+ materialise(deltas: RowDelta[], schemas: ReadonlyArray<TableSchema>): Promise<Result<void, AdapterError>>;
86
+ }
87
+ /**
88
+ * Type guard to check if an adapter supports materialisation.
89
+ *
90
+ * Uses duck-typing (same pattern as `isDatabaseAdapter`).
91
+ */
92
+ declare function isMaterialisable(adapter: unknown): adapter is Materialisable;
93
+
94
+ export { type DatabaseAdapter as D, type LakeAdapter as L, type Materialisable as M, type ObjectInfo as O, type DatabaseAdapterConfig as a, isMaterialisable as b, isDatabaseAdapter as i };
package/dist/adapter.d.ts CHANGED
@@ -1,44 +1,15 @@
1
1
  import { BigQuery } from '@google-cloud/bigquery';
2
2
  import { R as Result, A as AdapterError, H as HLCTimestamp } from './result-CojzlFE2.js';
3
- import { R as RowDelta, T as TableSchema, C as ColumnDelta } from './types-CLlD4XOy.js';
4
- import { D as DatabaseAdapter, a as DatabaseAdapterConfig } from './db-types-BlN-4KbQ.js';
5
- export { i as isDatabaseAdapter, l as lakeSyncTypeToBigQuery } from './db-types-BlN-4KbQ.js';
6
- import { C as ConnectorConfig } from './types-D-E0VrfS.js';
7
- import { L as LakeAdapter, A as AdapterConfig, O as ObjectInfo } from './types-DSC_EiwR.js';
3
+ import { D as DatabaseAdapter, M as Materialisable, L as LakeAdapter, O as ObjectInfo, a as DatabaseAdapterConfig } from './adapter-types-DwsQGQS4.js';
4
+ export { i as isDatabaseAdapter, b as isMaterialisable } from './adapter-types-DwsQGQS4.js';
5
+ import { T as TableSchema, a as ColumnDelta, R as RowDelta } from './types-BdGBv2ba.js';
6
+ export { A as AdapterFactory, a as AdapterFactoryRegistry, c as createAdapterFactoryRegistry, b as createDatabaseAdapter, d as defaultAdapterFactoryRegistry } from './factory-DFfR-030.js';
8
7
  import mysql from 'mysql2/promise';
9
8
  import { Pool } from 'pg';
9
+ import { C as ConnectorConfig } from './types-D2C9jTbL.js';
10
+
11
+ declare function lakeSyncTypeToBigQuery(type: TableSchema["columns"][number]["type"]): string;
10
12
 
11
- /**
12
- * Opt-in capability for adapters that can materialise deltas into destination tables.
13
- *
14
- * Materialisation is a separate concern from delta storage — adapters that store
15
- * deltas (via `DatabaseAdapter.insertDeltas`) may also materialise them into
16
- * queryable destination tables by implementing this interface.
17
- *
18
- * Destination tables follow the hybrid column model:
19
- * - Synced columns (written by materialiser, derived from `TableSchema.columns`)
20
- * - `props JSONB DEFAULT '{}'` — consumer-extensible, never touched by materialiser
21
- * - `synced_at` — updated on every materialise cycle
22
- */
23
- interface Materialisable {
24
- /**
25
- * Materialise deltas into destination tables.
26
- *
27
- * For each table with a matching schema, merges delta history into the
28
- * latest row state and upserts into the destination table. Tombstoned
29
- * rows are deleted. The `props` column is never touched.
30
- *
31
- * @param deltas - The deltas that were just flushed.
32
- * @param schemas - Table schemas defining destination tables and column mappings.
33
- */
34
- materialise(deltas: RowDelta[], schemas: ReadonlyArray<TableSchema>): Promise<Result<void, AdapterError>>;
35
- }
36
- /**
37
- * Type guard to check if an adapter supports materialisation.
38
- *
39
- * Uses duck-typing (same pattern as `isDatabaseAdapter`).
40
- */
41
- declare function isMaterialisable(adapter: unknown): adapter is Materialisable;
42
13
  /**
43
14
  * Resolve the primary key columns for a table schema.
44
15
  * Defaults to `["row_id"]` when not explicitly set.
@@ -70,6 +41,56 @@ declare function groupDeltasByTable(deltas: ReadonlyArray<RowDelta>): Map<string
70
41
  * @returns A map from source table name to schema.
71
42
  */
72
43
  declare function buildSchemaIndex(schemas: ReadonlyArray<TableSchema>): Map<string, TableSchema>;
44
+ /** Minimal query interface for executing SQL against a database. */
45
+ interface QueryExecutor {
46
+ query(sql: string, params: unknown[]): Promise<void>;
47
+ queryRows(sql: string, params: unknown[]): Promise<Array<{
48
+ row_id: string;
49
+ columns: string | ColumnDelta[];
50
+ op: string;
51
+ }>>;
52
+ }
53
+ /**
54
+ * SQL dialect interface — encapsulates the syntactic differences between
55
+ * Postgres, MySQL, and BigQuery for the materialise algorithm.
56
+ */
57
+ interface SqlDialect {
58
+ /** Generate CREATE TABLE IF NOT EXISTS for the destination table. */
59
+ createDestinationTable(dest: string, schema: TableSchema, pk: string[], softDelete: boolean): {
60
+ sql: string;
61
+ params: unknown[];
62
+ };
63
+ /** Generate a query to fetch delta history for a set of affected row IDs. */
64
+ queryDeltaHistory(sourceTable: string, rowIds: string[]): {
65
+ sql: string;
66
+ params: unknown[];
67
+ };
68
+ /** Generate an upsert statement for the merged row states. */
69
+ buildUpsert(dest: string, schema: TableSchema, conflictCols: string[], softDelete: boolean, upserts: Array<{
70
+ rowId: string;
71
+ state: Record<string, unknown>;
72
+ }>): {
73
+ sql: string;
74
+ params: unknown[];
75
+ };
76
+ /** Generate a delete (hard or soft) statement for tombstoned row IDs. */
77
+ buildDelete(dest: string, deleteIds: string[], softDelete: boolean): {
78
+ sql: string;
79
+ params: unknown[];
80
+ };
81
+ }
82
+ /**
83
+ * Execute the shared materialise algorithm using the provided dialect and executor.
84
+ *
85
+ * Algorithm: group by table -> build schema index -> for each table:
86
+ * create dest table -> query history -> merge -> upsert -> delete.
87
+ *
88
+ * @param executor - Executes SQL statements against the database.
89
+ * @param dialect - Generates dialect-specific SQL.
90
+ * @param deltas - The deltas that were just flushed.
91
+ * @param schemas - Table schemas defining destination tables and column mappings.
92
+ */
93
+ declare function executeMaterialise(executor: QueryExecutor, dialect: SqlDialect, deltas: RowDelta[], schemas: ReadonlyArray<TableSchema>): Promise<Result<void, AdapterError>>;
73
94
 
74
95
  /**
75
96
  * Configuration for the BigQuery adapter.
@@ -85,6 +106,40 @@ interface BigQueryAdapterConfig {
85
106
  /** Dataset location (default: "US"). */
86
107
  location?: string;
87
108
  }
109
+ /**
110
+ * BigQuery SQL dialect for the shared materialise algorithm.
111
+ *
112
+ * Uses `@name` named parameters, `MERGE` for upserts, `JSON` type,
113
+ * `TIMESTAMP` types, and `CLUSTER BY` for table creation.
114
+ *
115
+ * BigQuery's parameterised query API uses named params in a flat object,
116
+ * so this dialect encodes params as named keys and returns them as an
117
+ * array of `[key, value]` pairs that the executor unpacks into a
118
+ * `Record<string, unknown>`.
119
+ */
120
+ declare class BigQuerySqlDialect implements SqlDialect {
121
+ private readonly dataset;
122
+ constructor(dataset: string);
123
+ createDestinationTable(dest: string, schema: TableSchema, pk: string[], softDelete: boolean): {
124
+ sql: string;
125
+ params: unknown[];
126
+ };
127
+ queryDeltaHistory(sourceTable: string, rowIds: string[]): {
128
+ sql: string;
129
+ params: unknown[];
130
+ };
131
+ buildUpsert(dest: string, schema: TableSchema, conflictCols: string[], softDelete: boolean, upserts: Array<{
132
+ rowId: string;
133
+ state: Record<string, unknown>;
134
+ }>): {
135
+ sql: string;
136
+ params: unknown[];
137
+ };
138
+ buildDelete(dest: string, deleteIds: string[], softDelete: boolean): {
139
+ sql: string;
140
+ params: unknown[];
141
+ };
142
+ }
88
143
  /**
89
144
  * BigQuery database adapter for LakeSync.
90
145
  *
@@ -103,6 +158,8 @@ declare class BigQueryAdapter implements DatabaseAdapter, Materialisable {
103
158
  readonly dataset: string;
104
159
  /** @internal */
105
160
  readonly location: string;
161
+ private readonly dialect;
162
+ private readonly executor;
106
163
  constructor(config: BigQueryAdapterConfig);
107
164
  /**
108
165
  * Insert deltas into the database in a single batch.
@@ -127,10 +184,8 @@ declare class BigQueryAdapter implements DatabaseAdapter, Materialisable {
127
184
  /**
128
185
  * Materialise deltas into destination tables.
129
186
  *
130
- * For each affected table, queries the full delta history for touched rows,
131
- * merges to latest state via column-level LWW, then upserts live rows and
132
- * deletes tombstoned rows. The consumer-owned `props` column is never
133
- * touched on UPDATE.
187
+ * Delegates to the shared `executeMaterialise` algorithm with the
188
+ * BigQuery SQL dialect.
134
189
  */
135
190
  materialise(deltas: RowDelta[], schemas: ReadonlyArray<TableSchema>): Promise<Result<void, AdapterError>>;
136
191
  /**
@@ -174,18 +229,6 @@ declare class CompositeAdapter implements DatabaseAdapter {
174
229
  close(): Promise<void>;
175
230
  }
176
231
 
177
- /**
178
- * Instantiate a {@link DatabaseAdapter} from a {@link ConnectorConfig}.
179
- *
180
- * Switches on `config.type` and creates the matching adapter using
181
- * the type-specific connection configuration. Returns an {@link AdapterError}
182
- * if the type-specific config is missing or the adapter constructor throws.
183
- *
184
- * @param config - Validated connector configuration.
185
- * @returns The instantiated adapter or an error.
186
- */
187
- declare function createDatabaseAdapter(config: ConnectorConfig): Result<DatabaseAdapter, AdapterError>;
188
-
189
232
  /** Configuration for the FanOutAdapter. */
190
233
  interface FanOutAdapterConfig {
191
234
  /** The primary adapter that handles all reads and authoritative writes. */
@@ -199,8 +242,14 @@ interface FanOutAdapterConfig {
199
242
  *
200
243
  * Secondary failures are silently caught and never affect the return value.
201
244
  * Use case: write to Postgres (fast, operational), replicate to BigQuery (analytics).
245
+ *
246
+ * **Materialisation:** This adapter exposes a `materialise()` method for
247
+ * duck-type compatibility with `isMaterialisable()`. When the primary adapter
248
+ * is itself materialisable, materialisation is delegated to it; otherwise
249
+ * the method is a graceful no-op returning `Ok`. Materialisable secondaries
250
+ * receive fire-and-forget replication.
202
251
  */
203
- declare class FanOutAdapter implements DatabaseAdapter, Materialisable {
252
+ declare class FanOutAdapter implements DatabaseAdapter {
204
253
  private readonly primary;
205
254
  private readonly secondaries;
206
255
  constructor(config: FanOutAdapterConfig);
@@ -241,8 +290,14 @@ interface LifecycleAdapterConfig {
241
290
  *
242
291
  * Use {@link migrateToTier} as a background job to copy aged-out deltas
243
292
  * from hot to cold.
293
+ *
294
+ * **Materialisation:** This adapter exposes a `materialise()` method for
295
+ * duck-type compatibility with `isMaterialisable()`. Materialisation is
296
+ * delegated to the hot tier only — cold tier stores archived deltas, not
297
+ * destination tables. When the hot adapter is not materialisable, the
298
+ * method is a graceful no-op returning `Ok`.
244
299
  */
245
- declare class LifecycleAdapter implements DatabaseAdapter, Materialisable {
300
+ declare class LifecycleAdapter implements DatabaseAdapter {
246
301
  private readonly hot;
247
302
  private readonly cold;
248
303
  private readonly maxAgeMs;
@@ -317,6 +372,21 @@ interface MigrateResult {
317
372
  */
318
373
  declare function migrateAdapter(opts: MigrateOptions): Promise<Result<MigrateResult, AdapterError>>;
319
374
 
375
+ /** Configuration for connecting to the lake store */
376
+ interface AdapterConfig {
377
+ /** Endpoint URL (e.g. http://localhost:9000) */
378
+ endpoint: string;
379
+ /** Bucket name */
380
+ bucket: string;
381
+ /** AWS region (defaults to us-east-1) */
382
+ region?: string;
383
+ /** Access credentials */
384
+ credentials: {
385
+ accessKeyId: string;
386
+ secretAccessKey: string;
387
+ };
388
+ }
389
+
320
390
  /**
321
391
  * MinIO/S3-compatible lake adapter.
322
392
  *
@@ -345,6 +415,33 @@ declare class MinIOAdapter implements LakeAdapter {
345
415
  deleteObjects(paths: string[]): Promise<Result<void, AdapterError>>;
346
416
  }
347
417
 
418
+ /**
419
+ * MySQL SQL dialect for the shared materialise algorithm.
420
+ *
421
+ * Uses `?` positional parameters, `ON DUPLICATE KEY UPDATE`,
422
+ * `JSON` type, and `TIMESTAMP` types.
423
+ */
424
+ declare class MySqlDialect implements SqlDialect {
425
+ createDestinationTable(dest: string, schema: TableSchema, pk: string[], softDelete: boolean): {
426
+ sql: string;
427
+ params: unknown[];
428
+ };
429
+ queryDeltaHistory(sourceTable: string, rowIds: string[]): {
430
+ sql: string;
431
+ params: unknown[];
432
+ };
433
+ buildUpsert(dest: string, schema: TableSchema, _conflictCols: string[], softDelete: boolean, upserts: Array<{
434
+ rowId: string;
435
+ state: Record<string, unknown>;
436
+ }>): {
437
+ sql: string;
438
+ params: unknown[];
439
+ };
440
+ buildDelete(dest: string, deleteIds: string[], softDelete: boolean): {
441
+ sql: string;
442
+ params: unknown[];
443
+ };
444
+ }
348
445
  /**
349
446
  * MySQL database adapter for LakeSync.
350
447
  *
@@ -355,7 +452,9 @@ declare class MinIOAdapter implements LakeAdapter {
355
452
  declare class MySQLAdapter implements DatabaseAdapter, Materialisable {
356
453
  /** @internal */
357
454
  readonly pool: mysql.Pool;
455
+ private readonly dialect;
358
456
  constructor(config: DatabaseAdapterConfig);
457
+ private get executor();
359
458
  /**
360
459
  * Insert deltas into the database in a single batch.
361
460
  * Uses INSERT IGNORE for idempotent writes — duplicate deltaIds are silently skipped.
@@ -379,16 +478,41 @@ declare class MySQLAdapter implements DatabaseAdapter, Materialisable {
379
478
  /**
380
479
  * Materialise deltas into destination tables.
381
480
  *
382
- * For each table with a matching schema, merges delta history into the
383
- * latest row state and upserts into the destination table. Tombstoned
384
- * rows are soft-deleted (default) or hard-deleted. The `props` column
385
- * is never touched.
481
+ * Delegates to the shared `executeMaterialise` algorithm with the
482
+ * MySQL SQL dialect.
386
483
  */
387
484
  materialise(deltas: RowDelta[], schemas: ReadonlyArray<TableSchema>): Promise<Result<void, AdapterError>>;
388
485
  /** Close the database connection pool and release resources. */
389
486
  close(): Promise<void>;
390
487
  }
391
488
 
489
+ /**
490
+ * Postgres SQL dialect for the shared materialise algorithm.
491
+ *
492
+ * Uses `$N` positional parameters, `ON CONFLICT DO UPDATE`, `JSONB`,
493
+ * and `TIMESTAMPTZ` types.
494
+ */
495
+ declare class PostgresSqlDialect implements SqlDialect {
496
+ createDestinationTable(dest: string, schema: TableSchema, pk: string[], softDelete: boolean): {
497
+ sql: string;
498
+ params: unknown[];
499
+ };
500
+ queryDeltaHistory(sourceTable: string, rowIds: string[]): {
501
+ sql: string;
502
+ params: unknown[];
503
+ };
504
+ buildUpsert(dest: string, schema: TableSchema, conflictCols: string[], softDelete: boolean, upserts: Array<{
505
+ rowId: string;
506
+ state: Record<string, unknown>;
507
+ }>): {
508
+ sql: string;
509
+ params: unknown[];
510
+ };
511
+ buildDelete(dest: string, deleteIds: string[], softDelete: boolean): {
512
+ sql: string;
513
+ params: unknown[];
514
+ };
515
+ }
392
516
  /**
393
517
  * PostgreSQL database adapter for LakeSync.
394
518
  *
@@ -398,7 +522,9 @@ declare class MySQLAdapter implements DatabaseAdapter, Materialisable {
398
522
  declare class PostgresAdapter implements DatabaseAdapter, Materialisable {
399
523
  /** @internal */
400
524
  readonly pool: Pool;
525
+ private readonly dialect;
401
526
  constructor(config: DatabaseAdapterConfig);
527
+ private get executor();
402
528
  /**
403
529
  * Insert deltas into the database in a single batch.
404
530
  * Idempotent via `ON CONFLICT (delta_id) DO NOTHING`.
@@ -422,9 +548,8 @@ declare class PostgresAdapter implements DatabaseAdapter, Materialisable {
422
548
  /**
423
549
  * Materialise deltas into destination tables.
424
550
  *
425
- * For each table with a matching schema, merges delta history into the
426
- * latest row state and upserts into the destination table. Tombstoned
427
- * rows are deleted. The `props` column is never touched.
551
+ * Delegates to the shared `executeMaterialise` algorithm with the
552
+ * Postgres SQL dialect.
428
553
  */
429
554
  materialise(deltas: RowDelta[], schemas: ReadonlyArray<TableSchema>): Promise<Result<void, AdapterError>>;
430
555
  /** Close the database connection pool and release resources. */
@@ -438,13 +563,27 @@ type QueryFn = (sql: string, params?: unknown[]) => Promise<Record<string, unkno
438
563
  *
439
564
  * Uses dynamic imports so the database drivers (pg, mysql2) are only
440
565
  * loaded when actually needed. Returns `null` for connector types that
441
- * do not support the standard SQL polling model (e.g. BigQuery).
566
+ * do not support the standard SQL polling model (e.g. BigQuery, Jira, Salesforce).
442
567
  *
443
568
  * @param config - Validated connector configuration.
444
569
  * @returns A query function or `null` if the connector type is unsupported.
445
570
  */
446
571
  declare function createQueryFn(config: ConnectorConfig): Promise<QueryFn | null>;
447
572
 
573
+ /**
574
+ * Group raw delta rows by row_id, merge to latest state, and partition into upserts and deletes.
575
+ */
576
+ declare function groupAndMerge(rows: Array<{
577
+ row_id: string;
578
+ columns: string | ColumnDelta[];
579
+ op: string;
580
+ }>): {
581
+ upserts: Array<{
582
+ rowId: string;
583
+ state: Record<string, unknown>;
584
+ }>;
585
+ deleteIds: string[];
586
+ };
448
587
  /** Normalise a caught value into an Error or undefined. */
449
588
  declare function toCause(error: unknown): Error | undefined;
450
589
  /** Execute an async operation and wrap errors into an AdapterError Result. */
@@ -459,4 +598,4 @@ declare function mergeLatestState(rows: Array<{
459
598
  op: string;
460
599
  }>): Record<string, unknown> | null;
461
600
 
462
- export { AdapterConfig, BigQueryAdapter, type BigQueryAdapterConfig, CompositeAdapter, type CompositeAdapterConfig, type CompositeRoute, DatabaseAdapter, DatabaseAdapterConfig, FanOutAdapter, type FanOutAdapterConfig, LakeAdapter, LifecycleAdapter, type LifecycleAdapterConfig, type Materialisable, type MigrateOptions, type MigrateProgress, type MigrateResult, MinIOAdapter, MySQLAdapter, ObjectInfo, PostgresAdapter, type QueryFn, buildSchemaIndex, createDatabaseAdapter, createQueryFn, groupDeltasByTable, isMaterialisable, isSoftDelete, mergeLatestState, migrateAdapter, migrateToTier, resolveConflictColumns, resolvePrimaryKey, toCause, wrapAsync };
601
+ export { type AdapterConfig, BigQueryAdapter, type BigQueryAdapterConfig, BigQuerySqlDialect, CompositeAdapter, type CompositeAdapterConfig, type CompositeRoute, DatabaseAdapter, DatabaseAdapterConfig, FanOutAdapter, type FanOutAdapterConfig, LakeAdapter, LifecycleAdapter, type LifecycleAdapterConfig, Materialisable, type MigrateOptions, type MigrateProgress, type MigrateResult, MinIOAdapter, MySQLAdapter, MySqlDialect, ObjectInfo, PostgresAdapter, PostgresSqlDialect, type QueryExecutor, type QueryFn, type SqlDialect, buildSchemaIndex, createQueryFn, executeMaterialise, groupAndMerge, groupDeltasByTable, isSoftDelete, lakeSyncTypeToBigQuery, mergeLatestState, migrateAdapter, migrateToTier, resolveConflictColumns, resolvePrimaryKey, toCause, wrapAsync };
package/dist/adapter.js CHANGED
@@ -1,17 +1,22 @@
1
1
  import {
2
2
  BigQueryAdapter,
3
+ BigQuerySqlDialect,
3
4
  CompositeAdapter,
4
5
  FanOutAdapter,
5
6
  LifecycleAdapter,
6
7
  MinIOAdapter,
7
8
  MySQLAdapter,
9
+ MySqlDialect,
8
10
  PostgresAdapter,
11
+ PostgresSqlDialect,
9
12
  buildSchemaIndex,
13
+ createAdapterFactoryRegistry,
10
14
  createDatabaseAdapter,
11
15
  createQueryFn,
16
+ defaultAdapterFactoryRegistry,
17
+ executeMaterialise,
18
+ groupAndMerge,
12
19
  groupDeltasByTable,
13
- isDatabaseAdapter,
14
- isMaterialisable,
15
20
  isSoftDelete,
16
21
  lakeSyncTypeToBigQuery,
17
22
  mergeLatestState,
@@ -21,20 +26,30 @@ import {
21
26
  resolvePrimaryKey,
22
27
  toCause,
23
28
  wrapAsync
24
- } from "./chunk-GUJWMK5P.js";
25
- import "./chunk-P3FT7QCW.js";
26
- import "./chunk-7D4SUZUM.js";
29
+ } from "./chunk-C4KD6YKP.js";
30
+ import {
31
+ isDatabaseAdapter,
32
+ isMaterialisable
33
+ } from "./chunk-4SG66H5K.js";
34
+ import "./chunk-DGUM43GV.js";
27
35
  export {
28
36
  BigQueryAdapter,
37
+ BigQuerySqlDialect,
29
38
  CompositeAdapter,
30
39
  FanOutAdapter,
31
40
  LifecycleAdapter,
32
41
  MinIOAdapter,
33
42
  MySQLAdapter,
43
+ MySqlDialect,
34
44
  PostgresAdapter,
45
+ PostgresSqlDialect,
35
46
  buildSchemaIndex,
47
+ createAdapterFactoryRegistry,
36
48
  createDatabaseAdapter,
37
49
  createQueryFn,
50
+ defaultAdapterFactoryRegistry,
51
+ executeMaterialise,
52
+ groupAndMerge,
38
53
  groupDeltasByTable,
39
54
  isDatabaseAdapter,
40
55
  isMaterialisable,
package/dist/analyst.js CHANGED
@@ -2,8 +2,8 @@ import {
2
2
  Err,
3
3
  LakeSyncError,
4
4
  Ok
5
- } from "./chunk-P3FT7QCW.js";
6
- import "./chunk-7D4SUZUM.js";
5
+ } from "./chunk-4SG66H5K.js";
6
+ import "./chunk-DGUM43GV.js";
7
7
 
8
8
  // ../analyst/src/duckdb.ts
9
9
  var DuckDBClient = class {
@@ -1,11 +1,78 @@
1
- import { S as SyncPush, R as RowDelta } from './types-CLlD4XOy.js';
1
+ import { S as SyncPush, R as RowDelta } from './types-BdGBv2ba.js';
2
2
  import { H as HLC } from './hlc-DiD8QNG3.js';
3
3
  import { R as Result, F as FlushError } from './result-CojzlFE2.js';
4
4
 
5
+ /**
6
+ * Target that supports flush and buffer inspection.
7
+ * Implemented by SyncGateway so pollers can trigger flushes to relieve memory pressure.
8
+ */
9
+ interface FlushableTarget {
10
+ flush(): Promise<Result<void, FlushError>>;
11
+ shouldFlush(): boolean;
12
+ readonly bufferStats: {
13
+ logSize: number;
14
+ indexSize: number;
15
+ byteSize: number;
16
+ };
17
+ }
18
+ /**
19
+ * Monitors buffer pressure on a {@link FlushableTarget} and triggers
20
+ * flushes when thresholds are exceeded. Created at construction time
21
+ * only when the target supports flushing — no runtime type checks needed.
22
+ */
23
+ declare class PressureManager {
24
+ private readonly target;
25
+ private readonly memoryBudgetBytes;
26
+ private readonly flushThreshold;
27
+ constructor(config: {
28
+ target: FlushableTarget;
29
+ memoryBudgetBytes?: number;
30
+ flushThreshold?: number;
31
+ });
32
+ /** Check buffer pressure and flush if thresholds are exceeded. */
33
+ checkAndFlush(): Promise<void>;
34
+ /** Force a flush regardless of current pressure. */
35
+ forceFlush(): Promise<void>;
36
+ private shouldFlush;
37
+ }
38
+
5
39
  /** Minimal interface for a push target (avoids depending on @lakesync/gateway). */
6
40
  interface PushTarget {
7
41
  handlePush(push: SyncPush): unknown;
8
42
  }
43
+ /**
44
+ * Manages chunked pushing of deltas to a {@link PushTarget}.
45
+ * Handles backpressure retry (flush + retry once) when a
46
+ * {@link PressureManager} is present.
47
+ *
48
+ * No runtime type checks — the PressureManager is either provided
49
+ * at construction (target supports flush) or null.
50
+ */
51
+ declare class ChunkedPusher {
52
+ private readonly target;
53
+ private readonly clientId;
54
+ private readonly chunkSize;
55
+ private readonly pressure;
56
+ private pendingDeltas;
57
+ constructor(config: {
58
+ target: PushTarget;
59
+ clientId: string;
60
+ chunkSize: number;
61
+ pressure: PressureManager | null;
62
+ });
63
+ /**
64
+ * Accumulate a single delta. When `chunkSize` is reached, the pending
65
+ * deltas are automatically pushed (and flushed if needed).
66
+ */
67
+ accumulate(delta: RowDelta): Promise<void>;
68
+ /** Flush any remaining accumulated deltas. */
69
+ flush(): Promise<void>;
70
+ /** Push deltas directly (single-shot, backward compat). */
71
+ pushImmediate(deltas: RowDelta[]): void;
72
+ private pushPendingChunk;
73
+ private pushChunkWithFlush;
74
+ }
75
+
9
76
  /**
10
77
  * Extended push target that supports flush and buffer inspection.
11
78
  * Implemented by SyncGateway so pollers can trigger flushes to relieve memory pressure.
@@ -32,19 +99,20 @@ interface PollerMemoryConfig {
32
99
  }
33
100
  /**
34
101
  * Base class for source pollers that poll an external API and push deltas
35
- * to a SyncGateway. Handles lifecycle (start/stop/schedule), and push.
102
+ * to a SyncGateway.
103
+ *
104
+ * Composes {@link PollingScheduler} (lifecycle), {@link ChunkedPusher}
105
+ * (chunked push with backpressure), and {@link PressureManager}
106
+ * (memory-budget flush decisions).
36
107
  */
37
108
  declare abstract class BaseSourcePoller {
38
109
  protected readonly gateway: PushTarget;
39
110
  protected readonly hlc: HLC;
40
111
  protected readonly clientId: string;
41
- private readonly intervalMs;
42
- private timer;
43
- private running;
44
- private readonly chunkSize;
45
- private readonly memoryBudgetBytes;
46
- private readonly flushThreshold;
47
- private pendingDeltas;
112
+ private readonly scheduler;
113
+ private readonly pusher;
114
+ /** Optional callback invoked after each poll with the current cursor state. */
115
+ onCursorUpdate?: (state: Record<string, unknown>) => void;
48
116
  constructor(config: {
49
117
  name: string;
50
118
  intervalMs: number;
@@ -77,15 +145,6 @@ declare abstract class BaseSourcePoller {
77
145
  protected accumulateDelta(delta: RowDelta): Promise<void>;
78
146
  /** Flush any remaining accumulated deltas. Call at the end of `poll()`. */
79
147
  protected flushAccumulator(): Promise<void>;
80
- /**
81
- * Push a chunk of pending deltas. If the gateway is an IngestTarget,
82
- * checks memory pressure and flushes before/after push when needed.
83
- * On backpressure, flushes once and retries.
84
- */
85
- private pushPendingChunk;
86
- private pushChunkWithFlush;
87
- private shouldFlushTarget;
88
- private schedulePoll;
89
148
  }
90
149
 
91
- export { BaseSourcePoller as B, type IngestTarget as I, type PushTarget as P, type PollerMemoryConfig as a, isIngestTarget as i };
150
+ export { BaseSourcePoller as B, ChunkedPusher as C, type FlushableTarget as F, type IngestTarget as I, type PushTarget as P, type PollerMemoryConfig as a, PressureManager as b, isIngestTarget as i };