lakesync 0.1.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 (69) hide show
  1. package/README.md +74 -0
  2. package/dist/adapter.d.ts +369 -0
  3. package/dist/adapter.js +39 -0
  4. package/dist/adapter.js.map +1 -0
  5. package/dist/analyst.d.ts +268 -0
  6. package/dist/analyst.js +495 -0
  7. package/dist/analyst.js.map +1 -0
  8. package/dist/auth-CAVutXzx.d.ts +30 -0
  9. package/dist/base-poller-Qo_SmCZs.d.ts +82 -0
  10. package/dist/catalogue.d.ts +65 -0
  11. package/dist/catalogue.js +17 -0
  12. package/dist/catalogue.js.map +1 -0
  13. package/dist/chunk-4ARO6KTJ.js +257 -0
  14. package/dist/chunk-4ARO6KTJ.js.map +1 -0
  15. package/dist/chunk-5YOFCJQ7.js +1115 -0
  16. package/dist/chunk-5YOFCJQ7.js.map +1 -0
  17. package/dist/chunk-7D4SUZUM.js +38 -0
  18. package/dist/chunk-7D4SUZUM.js.map +1 -0
  19. package/dist/chunk-BNJOGBYK.js +335 -0
  20. package/dist/chunk-BNJOGBYK.js.map +1 -0
  21. package/dist/chunk-ICNT7I3K.js +1180 -0
  22. package/dist/chunk-ICNT7I3K.js.map +1 -0
  23. package/dist/chunk-P5DRFKIT.js +413 -0
  24. package/dist/chunk-P5DRFKIT.js.map +1 -0
  25. package/dist/chunk-X3RO5SYJ.js +880 -0
  26. package/dist/chunk-X3RO5SYJ.js.map +1 -0
  27. package/dist/client.d.ts +428 -0
  28. package/dist/client.js +2048 -0
  29. package/dist/client.js.map +1 -0
  30. package/dist/compactor.d.ts +342 -0
  31. package/dist/compactor.js +793 -0
  32. package/dist/compactor.js.map +1 -0
  33. package/dist/coordinator-CxckTzYW.d.ts +396 -0
  34. package/dist/db-types-BR6Kt4uf.d.ts +29 -0
  35. package/dist/gateway-D5SaaMvT.d.ts +337 -0
  36. package/dist/gateway-server.d.ts +306 -0
  37. package/dist/gateway-server.js +4663 -0
  38. package/dist/gateway-server.js.map +1 -0
  39. package/dist/gateway.d.ts +196 -0
  40. package/dist/gateway.js +79 -0
  41. package/dist/gateway.js.map +1 -0
  42. package/dist/hlc-DiD8QNG3.d.ts +70 -0
  43. package/dist/index.d.ts +245 -0
  44. package/dist/index.js +102 -0
  45. package/dist/index.js.map +1 -0
  46. package/dist/json-dYtqiL0F.d.ts +18 -0
  47. package/dist/nessie-client-DrNikVXy.d.ts +160 -0
  48. package/dist/parquet.d.ts +78 -0
  49. package/dist/parquet.js +15 -0
  50. package/dist/parquet.js.map +1 -0
  51. package/dist/proto.d.ts +434 -0
  52. package/dist/proto.js +67 -0
  53. package/dist/proto.js.map +1 -0
  54. package/dist/react.d.ts +147 -0
  55. package/dist/react.js +224 -0
  56. package/dist/react.js.map +1 -0
  57. package/dist/resolver-C3Wphi6O.d.ts +10 -0
  58. package/dist/result-CojzlFE2.d.ts +64 -0
  59. package/dist/src-QU2YLPZY.js +383 -0
  60. package/dist/src-QU2YLPZY.js.map +1 -0
  61. package/dist/src-WYBF5LOI.js +102 -0
  62. package/dist/src-WYBF5LOI.js.map +1 -0
  63. package/dist/src-WZNPHANQ.js +426 -0
  64. package/dist/src-WZNPHANQ.js.map +1 -0
  65. package/dist/types-Bs-QyOe-.d.ts +143 -0
  66. package/dist/types-DAQL_vU_.d.ts +118 -0
  67. package/dist/types-DSC_EiwR.d.ts +45 -0
  68. package/dist/types-V_jVu2sA.d.ts +73 -0
  69. package/package.json +119 -0
@@ -0,0 +1,196 @@
1
+ import { S as SyncRulesConfig, R as ResolvedClaims, b as SyncRulesContext, i as ActionPush } from './types-Bs-QyOe-.js';
2
+ export { d as ActionDiscovery, g as ActionHandler, j as ActionResponse, l as AuthContext } from './types-Bs-QyOe-.js';
3
+ export { I as IngestTarget, i as isIngestTarget } from './base-poller-Qo_SmCZs.js';
4
+ import { T as TableSchema, R as RowDelta, S as SyncPull, b as SyncPush } from './types-V_jVu2sA.js';
5
+ export { c as SyncResponse } from './types-V_jVu2sA.js';
6
+ export { b as bigintReplacer, a as bigintReviver } from './json-dYtqiL0F.js';
7
+ import { S as SyncGateway } from './gateway-D5SaaMvT.js';
8
+ export { A as ActionDispatcher, B as BufferConfig, D as DeltaBuffer, F as FlushEnvelope, G as GatewayConfig, a as GatewayState, H as HandlePushResult, b as SchemaManager } from './gateway-D5SaaMvT.js';
9
+ import { C as ConnectorConfig } from './types-DAQL_vU_.js';
10
+ import { R as Result, F as FlushError, H as HLCTimestamp } from './result-CojzlFE2.js';
11
+ import { D as DatabaseAdapter } from './db-types-BR6Kt4uf.js';
12
+ import { L as LakeAdapter } from './types-DSC_EiwR.js';
13
+ import { N as NessieCatalogueClient } from './nessie-client-DrNikVXy.js';
14
+ import './hlc-DiD8QNG3.js';
15
+
16
+ /**
17
+ * Platform-agnostic configuration storage interface.
18
+ *
19
+ * Implemented by MemoryConfigStore (tests, gateway-server) and
20
+ * DurableStorageConfigStore (gateway-worker).
21
+ */
22
+ interface ConfigStore {
23
+ getSchema(gatewayId: string): Promise<TableSchema | undefined>;
24
+ setSchema(gatewayId: string, schema: TableSchema): Promise<void>;
25
+ getSyncRules(gatewayId: string): Promise<SyncRulesConfig | undefined>;
26
+ setSyncRules(gatewayId: string, rules: SyncRulesConfig): Promise<void>;
27
+ getConnectors(): Promise<Record<string, ConnectorConfig>>;
28
+ setConnectors(connectors: Record<string, ConnectorConfig>): Promise<void>;
29
+ }
30
+ /**
31
+ * In-memory implementation of ConfigStore.
32
+ * Used by tests and gateway-server.
33
+ */
34
+ declare class MemoryConfigStore implements ConfigStore {
35
+ private schemas;
36
+ private syncRules;
37
+ private connectors;
38
+ getSchema(gatewayId: string): Promise<TableSchema | undefined>;
39
+ setSchema(gatewayId: string, schema: TableSchema): Promise<void>;
40
+ getSyncRules(gatewayId: string): Promise<SyncRulesConfig | undefined>;
41
+ setSyncRules(gatewayId: string, rules: SyncRulesConfig): Promise<void>;
42
+ getConnectors(): Promise<Record<string, ConnectorConfig>>;
43
+ setConnectors(connectors: Record<string, ConnectorConfig>): Promise<void>;
44
+ }
45
+
46
+ /** Maximum push payload size (1 MiB). */
47
+ declare const MAX_PUSH_PAYLOAD_BYTES = 1048576;
48
+ /** Maximum number of deltas allowed in a single push. */
49
+ declare const MAX_DELTAS_PER_PUSH = 10000;
50
+ /** Maximum number of deltas returned in a single pull. */
51
+ declare const MAX_PULL_LIMIT = 10000;
52
+ /** Default number of deltas returned in a pull when no limit is specified. */
53
+ declare const DEFAULT_PULL_LIMIT = 100;
54
+ /** Allowed column types for schema validation. */
55
+ declare const VALID_COLUMN_TYPES: Set<string>;
56
+ /** Default maximum buffer size before triggering flush (4 MiB). */
57
+ declare const DEFAULT_MAX_BUFFER_BYTES: number;
58
+ /** Default maximum buffer age before triggering flush (30 seconds). */
59
+ declare const DEFAULT_MAX_BUFFER_AGE_MS = 30000;
60
+
61
+ /** Configuration for flush operations. */
62
+ interface FlushConfig {
63
+ gatewayId: string;
64
+ flushFormat?: "json" | "parquet";
65
+ tableSchema?: TableSchema;
66
+ catalogue?: NessieCatalogueClient;
67
+ }
68
+ /** Dependencies injected into flush operations. */
69
+ interface FlushDeps {
70
+ adapter: LakeAdapter | DatabaseAdapter;
71
+ config: FlushConfig;
72
+ restoreEntries: (entries: RowDelta[]) => void;
73
+ }
74
+ /** Find the min and max HLC in a non-empty array of deltas. */
75
+ declare function hlcRange(entries: RowDelta[]): {
76
+ min: HLCTimestamp;
77
+ max: HLCTimestamp;
78
+ };
79
+ /**
80
+ * Flush a set of entries to the configured adapter.
81
+ *
82
+ * Unifies both full-buffer flush and per-table flush. The `keyPrefix`
83
+ * parameter, when provided, is prepended to the HLC range in the object key
84
+ * (e.g. "todos" for per-table flush).
85
+ */
86
+ declare function flushEntries(entries: RowDelta[], byteSize: number, deps: FlushDeps, keyPrefix?: string): Promise<Result<void, FlushError>>;
87
+ /**
88
+ * Best-effort catalogue commit. Registers the flushed Parquet file
89
+ * as an Iceberg snapshot via Nessie. Errors are logged but do not
90
+ * fail the flush — the Parquet file is the source of truth.
91
+ */
92
+ declare function commitToCatalogue(objectKey: string, fileSizeInBytes: number, recordCount: number, catalogue: NessieCatalogueClient, schema: TableSchema): Promise<void>;
93
+
94
+ /** Result from a request handler, ready for platform-specific serialisation. */
95
+ interface HandlerResult {
96
+ status: number;
97
+ body: unknown;
98
+ }
99
+ /**
100
+ * Handle a push request.
101
+ *
102
+ * @param gateway - The SyncGateway instance.
103
+ * @param raw - The raw request body string.
104
+ * @param headerClientId - Client ID from auth header (for mismatch check).
105
+ * @param opts - Optional callbacks for persistence and broadcast.
106
+ */
107
+ declare function handlePushRequest(gateway: SyncGateway, raw: string, headerClientId?: string | null, opts?: {
108
+ /** Persist deltas before processing (WAL-style). */
109
+ persistBatch?: (deltas: RowDelta[]) => void;
110
+ /** Clear persisted deltas after successful push. */
111
+ clearPersistence?: () => void;
112
+ /** Broadcast deltas to connected clients. */
113
+ broadcastFn?: (deltas: RowDelta[], serverHlc: HLCTimestamp, excludeClientId: string) => void | Promise<void>;
114
+ }): HandlerResult;
115
+ /**
116
+ * Handle a pull request.
117
+ */
118
+ declare function handlePullRequest(gateway: SyncGateway, params: {
119
+ since: string | null;
120
+ clientId: string | null;
121
+ limit: string | null;
122
+ source: string | null;
123
+ }, claims?: ResolvedClaims, syncRules?: SyncRulesConfig): Promise<HandlerResult>;
124
+ /**
125
+ * Handle an action request.
126
+ */
127
+ declare function handleActionRequest(gateway: SyncGateway, raw: string, headerClientId?: string | null, claims?: ResolvedClaims): Promise<HandlerResult>;
128
+ /**
129
+ * Handle a flush request.
130
+ */
131
+ declare function handleFlushRequest(gateway: SyncGateway, opts?: {
132
+ clearPersistence?: () => void;
133
+ }): Promise<HandlerResult>;
134
+ /**
135
+ * Handle saving a table schema.
136
+ */
137
+ declare function handleSaveSchema(raw: string, store: ConfigStore, gatewayId: string): Promise<HandlerResult>;
138
+ /**
139
+ * Handle saving sync rules.
140
+ */
141
+ declare function handleSaveSyncRules(raw: string, store: ConfigStore, gatewayId: string): Promise<HandlerResult>;
142
+ /**
143
+ * Handle registering a connector.
144
+ */
145
+ declare function handleRegisterConnector(raw: string, store: ConfigStore): Promise<HandlerResult>;
146
+ /**
147
+ * Handle unregistering a connector.
148
+ */
149
+ declare function handleUnregisterConnector(name: string, store: ConfigStore): Promise<HandlerResult>;
150
+ /**
151
+ * Handle listing connectors.
152
+ */
153
+ declare function handleListConnectors(store: ConfigStore): Promise<HandlerResult>;
154
+ /**
155
+ * Handle metrics request.
156
+ */
157
+ declare function handleMetrics(gateway: SyncGateway, extra?: Record<string, unknown>): HandlerResult;
158
+
159
+ /** Validation error with HTTP status code. */
160
+ interface RequestError {
161
+ status: number;
162
+ message: string;
163
+ }
164
+ /**
165
+ * Validate and parse a push request body.
166
+ * Handles JSON parsing with bigint revival.
167
+ */
168
+ declare function validatePushBody(raw: string, headerClientId?: string | null): Result<SyncPush, RequestError>;
169
+ /**
170
+ * Parse and validate pull query parameters.
171
+ */
172
+ declare function parsePullParams(params: {
173
+ since: string | null;
174
+ clientId: string | null;
175
+ limit: string | null;
176
+ source: string | null;
177
+ }): Result<SyncPull, RequestError>;
178
+ /**
179
+ * Validate and parse an action request body.
180
+ */
181
+ declare function validateActionBody(raw: string, headerClientId?: string | null): Result<ActionPush, RequestError>;
182
+ /**
183
+ * Validate a table schema body.
184
+ */
185
+ declare function validateSchemaBody(raw: string): Result<TableSchema, RequestError>;
186
+ /**
187
+ * Map a gateway push error code to an HTTP status code.
188
+ */
189
+ declare function pushErrorToStatus(code: string): number;
190
+ /**
191
+ * Build a SyncRulesContext from rules and claims.
192
+ * Returns undefined when no rules or empty buckets.
193
+ */
194
+ declare function buildSyncRulesContext(rules: SyncRulesConfig | undefined, claims: ResolvedClaims): SyncRulesContext | undefined;
195
+
196
+ export { ActionPush, type ConfigStore, DEFAULT_MAX_BUFFER_AGE_MS, DEFAULT_MAX_BUFFER_BYTES, DEFAULT_PULL_LIMIT, type FlushConfig, type FlushDeps, type HandlerResult, MAX_DELTAS_PER_PUSH, MAX_PULL_LIMIT, MAX_PUSH_PAYLOAD_BYTES, MemoryConfigStore, type RequestError, SyncGateway, SyncPull, SyncPush, VALID_COLUMN_TYPES, buildSyncRulesContext, commitToCatalogue, flushEntries, handleActionRequest, handleFlushRequest, handleListConnectors, handleMetrics, handlePullRequest, handlePushRequest, handleRegisterConnector, handleSaveSchema, handleSaveSyncRules, handleUnregisterConnector, hlcRange, parsePullParams, pushErrorToStatus, validateActionBody, validatePushBody, validateSchemaBody };
@@ -0,0 +1,79 @@
1
+ import {
2
+ ActionDispatcher,
3
+ DEFAULT_MAX_BUFFER_AGE_MS,
4
+ DEFAULT_MAX_BUFFER_BYTES,
5
+ DEFAULT_PULL_LIMIT,
6
+ DeltaBuffer,
7
+ MAX_DELTAS_PER_PUSH,
8
+ MAX_PULL_LIMIT,
9
+ MAX_PUSH_PAYLOAD_BYTES,
10
+ MemoryConfigStore,
11
+ SchemaManager,
12
+ SyncGateway,
13
+ VALID_COLUMN_TYPES,
14
+ buildSyncRulesContext,
15
+ commitToCatalogue,
16
+ flushEntries,
17
+ handleActionRequest,
18
+ handleFlushRequest,
19
+ handleListConnectors,
20
+ handleMetrics,
21
+ handlePullRequest,
22
+ handlePushRequest,
23
+ handleRegisterConnector,
24
+ handleSaveSchema,
25
+ handleSaveSyncRules,
26
+ handleUnregisterConnector,
27
+ hlcRange,
28
+ parsePullParams,
29
+ pushErrorToStatus,
30
+ validateActionBody,
31
+ validatePushBody,
32
+ validateSchemaBody
33
+ } from "./chunk-5YOFCJQ7.js";
34
+ import "./chunk-X3RO5SYJ.js";
35
+ import "./chunk-P5DRFKIT.js";
36
+ import "./chunk-4ARO6KTJ.js";
37
+ import {
38
+ bigintReplacer,
39
+ bigintReviver,
40
+ isIngestTarget
41
+ } from "./chunk-ICNT7I3K.js";
42
+ import "./chunk-7D4SUZUM.js";
43
+ export {
44
+ ActionDispatcher,
45
+ DEFAULT_MAX_BUFFER_AGE_MS,
46
+ DEFAULT_MAX_BUFFER_BYTES,
47
+ DEFAULT_PULL_LIMIT,
48
+ DeltaBuffer,
49
+ MAX_DELTAS_PER_PUSH,
50
+ MAX_PULL_LIMIT,
51
+ MAX_PUSH_PAYLOAD_BYTES,
52
+ MemoryConfigStore,
53
+ SchemaManager,
54
+ SyncGateway,
55
+ VALID_COLUMN_TYPES,
56
+ bigintReplacer,
57
+ bigintReviver,
58
+ buildSyncRulesContext,
59
+ commitToCatalogue,
60
+ flushEntries,
61
+ handleActionRequest,
62
+ handleFlushRequest,
63
+ handleListConnectors,
64
+ handleMetrics,
65
+ handlePullRequest,
66
+ handlePushRequest,
67
+ handleRegisterConnector,
68
+ handleSaveSchema,
69
+ handleSaveSyncRules,
70
+ handleUnregisterConnector,
71
+ hlcRange,
72
+ isIngestTarget,
73
+ parsePullParams,
74
+ pushErrorToStatus,
75
+ validateActionBody,
76
+ validatePushBody,
77
+ validateSchemaBody
78
+ };
79
+ //# sourceMappingURL=gateway.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,70 @@
1
+ import { H as HLCTimestamp, R as Result, b as ClockDriftError } from './result-CojzlFE2.js';
2
+
3
+ /**
4
+ * Hybrid Logical Clock implementation.
5
+ *
6
+ * 64-bit layout: [48-bit wall clock ms][16-bit logical counter].
7
+ * Maximum allowed clock drift: 5 seconds.
8
+ *
9
+ * The wall clock source is injectable for deterministic testing.
10
+ */
11
+ declare class HLC {
12
+ private readonly wallClock;
13
+ private counter;
14
+ private lastWall;
15
+ /** Maximum tolerated drift between local and remote physical clocks (ms). */
16
+ static readonly MAX_DRIFT_MS = 5000;
17
+ /** Maximum value of the 16-bit logical counter. */
18
+ static readonly MAX_COUNTER = 65535;
19
+ /**
20
+ * Create a new HLC instance.
21
+ *
22
+ * @param wallClock - Optional injectable clock source returning epoch ms.
23
+ * Defaults to `Date.now`.
24
+ */
25
+ constructor(wallClock?: () => number);
26
+ /**
27
+ * Generate a new monotonically increasing HLC timestamp.
28
+ *
29
+ * The returned timestamp is guaranteed to be strictly greater than any
30
+ * previously returned by this instance.
31
+ */
32
+ now(): HLCTimestamp;
33
+ /**
34
+ * Receive a remote HLC timestamp and advance the local clock.
35
+ *
36
+ * Returns `Err(ClockDriftError)` if the remote timestamp indicates
37
+ * clock drift exceeding {@link MAX_DRIFT_MS}.
38
+ *
39
+ * @param remote - The HLC timestamp received from a remote node.
40
+ * @returns A `Result` containing the new local HLC timestamp, or a
41
+ * `ClockDriftError` if the remote clock is too far ahead.
42
+ */
43
+ recv(remote: HLCTimestamp): Result<HLCTimestamp, ClockDriftError>;
44
+ /**
45
+ * Encode a wall clock value (ms) and logical counter into a 64-bit HLC timestamp.
46
+ *
47
+ * @param wall - Wall clock component in epoch milliseconds (48-bit).
48
+ * @param counter - Logical counter component (16-bit, 0..65535).
49
+ * @returns The encoded {@link HLCTimestamp}.
50
+ */
51
+ static encode(wall: number, counter: number): HLCTimestamp;
52
+ /**
53
+ * Decode an HLC timestamp into its wall clock (ms) and logical counter components.
54
+ *
55
+ * @param ts - The {@link HLCTimestamp} to decode.
56
+ * @returns An object with `wall` (epoch ms) and `counter` (logical) fields.
57
+ */
58
+ static decode(ts: HLCTimestamp): {
59
+ wall: number;
60
+ counter: number;
61
+ };
62
+ /**
63
+ * Compare two HLC timestamps.
64
+ *
65
+ * @returns `-1` if `a < b`, `0` if `a === b`, `1` if `a > b`.
66
+ */
67
+ static compare(a: HLCTimestamp, b: HLCTimestamp): -1 | 0 | 1;
68
+ }
69
+
70
+ export { HLC as H };
@@ -0,0 +1,245 @@
1
+ import { A as Action, a as ActionValidationError, S as SyncRulesConfig, B as BucketDefinition, R as ResolvedClaims, b as SyncRulesContext } from './types-Bs-QyOe-.js';
2
+ export { c as ActionDescriptor, d as ActionDiscovery, e as ActionErrorResult, f as ActionExecutionError, g as ActionHandler, h as ActionNotSupportedError, i as ActionPush, j as ActionResponse, k as ActionResult, l as AuthContext, m as SyncRuleFilter, n as SyncRuleOp, o as isActionError, p as isActionHandler } from './types-Bs-QyOe-.js';
3
+ import { H as HLCTimestamp, R as Result, C as ConflictError, L as LakeSyncError, S as SchemaError } from './result-CojzlFE2.js';
4
+ export { A as AdapterError, a as AdapterNotFoundError, B as BackpressureError, b as ClockDriftError, E as Err, F as FlushError, O as Ok, f as flatMapResult, c as fromPromise, m as mapResult, t as toError, u as unwrapOrThrow } from './result-CojzlFE2.js';
5
+ export { A as AuthClaims, a as AuthError, v as verifyToken } from './auth-CAVutXzx.js';
6
+ export { B as BaseSourcePoller, I as IngestTarget, P as PollerMemoryConfig, a as PushTarget, i as isIngestTarget } from './base-poller-Qo_SmCZs.js';
7
+ import { R as RowDelta, T as TableSchema } from './types-V_jVu2sA.js';
8
+ export { C as ColumnDelta, D as DeltaOp, a as RowKey, S as SyncPull, b as SyncPush, c as SyncResponse, r as rowKey } from './types-V_jVu2sA.js';
9
+ import { C as ConflictResolver } from './resolver-C3Wphi6O.js';
10
+ import { C as ConnectorConfig } from './types-DAQL_vU_.js';
11
+ export { B as BigQueryConnectorConfig, a as CONNECTOR_TYPES, b as ConnectorIngestConfig, c as ConnectorIngestTable, d as ConnectorType, J as JiraConnectorConfig, M as MySQLConnectorConfig, P as PostgresConnectorConfig, S as SalesforceConnectorConfig } from './types-DAQL_vU_.js';
12
+ export { H as HLC } from './hlc-DiD8QNG3.js';
13
+ export { b as bigintReplacer, a as bigintReviver } from './json-dYtqiL0F.js';
14
+
15
+ /**
16
+ * Generate a deterministic action ID using SHA-256.
17
+ *
18
+ * Same pattern as `generateDeltaId` in `delta/extract.ts` — uses the
19
+ * Web Crypto API for cross-runtime compatibility (Node, Bun, browsers).
20
+ */
21
+ declare function generateActionId(params: {
22
+ clientId: string;
23
+ hlc: HLCTimestamp;
24
+ connector: string;
25
+ actionType: string;
26
+ params: Record<string, unknown>;
27
+ }): Promise<string>;
28
+
29
+ /**
30
+ * Validate the structural integrity of an Action.
31
+ *
32
+ * Checks that all required fields are present and of the correct type.
33
+ * Returns a `Result` so callers never need to catch.
34
+ */
35
+ declare function validateAction(action: unknown): Result<Action, ActionValidationError>;
36
+
37
+ /**
38
+ * Column-level Last-Write-Wins conflict resolver.
39
+ *
40
+ * For each column present in both deltas, the one with the higher HLC wins.
41
+ * Equal HLC tiebreak: lexicographically higher clientId wins (deterministic).
42
+ * Columns only present in one delta are always included in the result.
43
+ */
44
+ declare class LWWResolver implements ConflictResolver {
45
+ /**
46
+ * Resolve two conflicting deltas for the same row, returning the merged result.
47
+ *
48
+ * Rules:
49
+ * - Both DELETE: the delta with the higher HLC (or clientId tiebreak) wins.
50
+ * - One DELETE, one non-DELETE: the delta with the higher HLC wins.
51
+ * If the DELETE wins, the row is tombstoned (empty columns).
52
+ * If the non-DELETE wins, the row is resurrected.
53
+ * - Both non-DELETE: columns are merged per-column using LWW semantics.
54
+ *
55
+ * @param local - The locally held delta for this row.
56
+ * @param remote - The incoming remote delta for this row.
57
+ * @returns A `Result` containing the resolved `RowDelta`, or a
58
+ * `ConflictError` if the deltas refer to different tables/rows.
59
+ */
60
+ resolve(local: RowDelta, remote: RowDelta): Result<RowDelta, ConflictError>;
61
+ }
62
+ /**
63
+ * Convenience function — resolves two conflicting deltas using the
64
+ * column-level Last-Write-Wins strategy.
65
+ *
66
+ * @param local - The locally held delta for this row.
67
+ * @param remote - The incoming remote delta for this row.
68
+ * @returns A `Result` containing the resolved `RowDelta`, or a
69
+ * `ConflictError` if the deltas refer to different tables/rows.
70
+ */
71
+ declare function resolveLWW(local: RowDelta, remote: RowDelta): Result<RowDelta, ConflictError>;
72
+
73
+ /** Connector configuration validation error. */
74
+ declare class ConnectorValidationError extends LakeSyncError {
75
+ constructor(message: string, cause?: Error);
76
+ }
77
+
78
+ /**
79
+ * Validate a connector configuration for structural correctness.
80
+ *
81
+ * Checks:
82
+ * - `name` is a non-empty string
83
+ * - `type` is one of the supported connector types
84
+ * - Type-specific config object is present and valid
85
+ * - Optional ingest config has valid table definitions
86
+ *
87
+ * @param input - Raw input to validate.
88
+ * @returns The validated {@link ConnectorConfig} or a validation error.
89
+ */
90
+ declare function validateConnectorConfig(input: unknown): Result<ConnectorConfig, ConnectorValidationError>;
91
+
92
+ /**
93
+ * Apply a delta to an existing row, returning the merged result.
94
+ *
95
+ * - DELETE → returns null
96
+ * - INSERT → creates a new row from delta columns
97
+ * - UPDATE → merges delta columns onto existing row (immutable — returns a new object)
98
+ *
99
+ * @param row - The current row state, or null if no row exists
100
+ * @param delta - The delta to apply
101
+ * @returns The merged row, or null for DELETE operations
102
+ */
103
+ declare function applyDelta(row: Record<string, unknown> | null, delta: RowDelta): Record<string, unknown> | null;
104
+
105
+ /**
106
+ * Extract a column-level delta between two row states.
107
+ *
108
+ * - `before` null/undefined + `after` present -> INSERT (all columns)
109
+ * - `before` present + `after` null/undefined -> DELETE (empty columns)
110
+ * - Both present -> compare each column, emit only changed columns as UPDATE
111
+ * - No columns changed -> returns null (no-op)
112
+ *
113
+ * If `schema` is provided, only columns listed in the schema are considered.
114
+ *
115
+ * @param before - The previous row state, or null/undefined for a new row
116
+ * @param after - The current row state, or null/undefined for a deleted row
117
+ * @param opts - Table name, row ID, client ID, HLC timestamp, and optional schema
118
+ * @returns The extracted RowDelta, or null if nothing changed
119
+ */
120
+ declare function extractDelta(before: Record<string, unknown> | null | undefined, after: Record<string, unknown> | null | undefined, opts: {
121
+ table: string;
122
+ rowId: string;
123
+ clientId: string;
124
+ hlc: HLCTimestamp;
125
+ schema?: TableSchema;
126
+ }): Promise<RowDelta | null>;
127
+
128
+ /**
129
+ * Create a pass-all sync rules configuration.
130
+ *
131
+ * Every delta reaches every client — equivalent to having no rules at all.
132
+ * Useful for apps without multi-tenancy or per-user data isolation.
133
+ */
134
+ declare function createPassAllRules(): SyncRulesConfig;
135
+ /**
136
+ * Create user-scoped sync rules configuration.
137
+ *
138
+ * Filters rows by matching a configurable column against the JWT `sub` claim,
139
+ * so each client only receives deltas belonging to the authenticated user.
140
+ *
141
+ * @param tables - Which tables to scope. Empty array means all tables.
142
+ * @param userColumn - Column to match against `jwt:sub`. Defaults to `"user_id"`.
143
+ */
144
+ declare function createUserScopedRules(tables: string[], userColumn?: string): SyncRulesConfig;
145
+
146
+ /** Sync rule configuration or evaluation error */
147
+ declare class SyncRuleError extends LakeSyncError {
148
+ constructor(message: string, cause?: Error);
149
+ }
150
+
151
+ /**
152
+ * Resolve a filter value, substituting JWT claim references.
153
+ *
154
+ * Values prefixed with `jwt:` are looked up in the claims record.
155
+ * Literal values are returned as-is (wrapped in an array for uniform handling).
156
+ *
157
+ * @param value - The filter value string (e.g. "jwt:sub" or "tenant-1")
158
+ * @param claims - Resolved JWT claims
159
+ * @returns An array of resolved values, or an empty array if the claim is missing
160
+ */
161
+ declare function resolveFilterValue(value: string, claims: ResolvedClaims): string[];
162
+ /**
163
+ * Check whether a delta matches a single bucket definition.
164
+ *
165
+ * A delta matches if:
166
+ * 1. The bucket's `tables` list is empty (matches all tables) or includes the delta's table
167
+ * 2. All filters match (conjunctive AND):
168
+ * - `eq`: the delta column value equals one of the resolved filter values
169
+ * - `in`: the delta column value is contained in the resolved filter values
170
+ *
171
+ * @param delta - The row delta to evaluate
172
+ * @param bucket - The bucket definition
173
+ * @param claims - Resolved JWT claims
174
+ * @returns true if the delta matches this bucket
175
+ */
176
+ declare function deltaMatchesBucket(delta: RowDelta, bucket: BucketDefinition, claims: ResolvedClaims): boolean;
177
+ /**
178
+ * Filter an array of deltas by sync rules.
179
+ *
180
+ * A delta is included if it matches **any** bucket (union across buckets).
181
+ * If no sync rules are configured (empty buckets), all deltas pass through.
182
+ *
183
+ * @param deltas - The deltas to filter
184
+ * @param context - Sync rules context (rules + resolved claims)
185
+ * @returns Filtered array of deltas
186
+ */
187
+ declare function filterDeltas(deltas: RowDelta[], context: SyncRulesContext): RowDelta[];
188
+ /**
189
+ * Determine which buckets a client matches based on their claims.
190
+ *
191
+ * A client matches a bucket if the bucket has no table-level restrictions
192
+ * or if the client's claims satisfy all filter conditions for at least
193
+ * one possible row. This is used for bucket-level access decisions, not
194
+ * row-level filtering.
195
+ *
196
+ * @param rules - The sync rules configuration
197
+ * @param claims - Resolved JWT claims
198
+ * @returns Array of bucket names the client matches
199
+ */
200
+ declare function resolveClientBuckets(rules: SyncRulesConfig, claims: ResolvedClaims): string[];
201
+ /**
202
+ * Validate a sync rules configuration for structural correctness.
203
+ *
204
+ * Checks:
205
+ * - Version is a positive integer
206
+ * - Buckets is an array
207
+ * - Each bucket has a non-empty name, valid tables array, valid filters
208
+ * - Filter operators are "eq" or "in"
209
+ * - Filter values and columns are non-empty strings
210
+ * - Bucket names are unique
211
+ *
212
+ * @param config - The sync rules configuration to validate
213
+ * @returns Ok(void) if valid, Err(SyncRuleError) with details if invalid
214
+ */
215
+ declare function validateSyncRules(config: unknown): Result<void, SyncRuleError>;
216
+
217
+ /**
218
+ * Check whether a string is a valid SQL identifier.
219
+ *
220
+ * Valid identifiers start with a letter or underscore, contain only
221
+ * alphanumeric characters and underscores, and are at most 64 characters long.
222
+ *
223
+ * @param name - The identifier to validate
224
+ * @returns `true` if valid, `false` otherwise
225
+ */
226
+ declare function isValidIdentifier(name: string): boolean;
227
+ /**
228
+ * Assert that a string is a valid SQL identifier, returning a Result.
229
+ *
230
+ * @param name - The identifier to validate
231
+ * @returns Ok(undefined) if valid, Err(SchemaError) if invalid
232
+ */
233
+ declare function assertValidIdentifier(name: string): Result<void, SchemaError>;
234
+ /**
235
+ * Quote a SQL identifier using double quotes as defence-in-depth.
236
+ *
237
+ * Any embedded double-quote characters are escaped by doubling them,
238
+ * following the SQL standard for delimited identifiers.
239
+ *
240
+ * @param name - The identifier to quote
241
+ * @returns The double-quoted identifier string
242
+ */
243
+ declare function quoteIdentifier(name: string): string;
244
+
245
+ export { Action, ActionValidationError, BucketDefinition, ConflictError, ConflictResolver, ConnectorConfig, ConnectorValidationError, HLCTimestamp, LWWResolver, LakeSyncError, ResolvedClaims, Result, RowDelta, SchemaError, SyncRuleError, SyncRulesConfig, SyncRulesContext, TableSchema, applyDelta, assertValidIdentifier, createPassAllRules, createUserScopedRules, deltaMatchesBucket, extractDelta, filterDeltas, generateActionId, isValidIdentifier, quoteIdentifier, resolveClientBuckets, resolveFilterValue, resolveLWW, validateAction, validateConnectorConfig, validateSyncRules };
package/dist/index.js ADDED
@@ -0,0 +1,102 @@
1
+ import {
2
+ ActionExecutionError,
3
+ ActionNotSupportedError,
4
+ ActionValidationError,
5
+ AdapterError,
6
+ AdapterNotFoundError,
7
+ AuthError,
8
+ BackpressureError,
9
+ BaseSourcePoller,
10
+ CONNECTOR_TYPES,
11
+ ClockDriftError,
12
+ ConflictError,
13
+ ConnectorValidationError,
14
+ Err,
15
+ FlushError,
16
+ HLC,
17
+ LWWResolver,
18
+ LakeSyncError,
19
+ Ok,
20
+ SchemaError,
21
+ SyncRuleError,
22
+ applyDelta,
23
+ assertValidIdentifier,
24
+ bigintReplacer,
25
+ bigintReviver,
26
+ createPassAllRules,
27
+ createUserScopedRules,
28
+ deltaMatchesBucket,
29
+ extractDelta,
30
+ filterDeltas,
31
+ flatMapResult,
32
+ fromPromise,
33
+ generateActionId,
34
+ isActionError,
35
+ isActionHandler,
36
+ isIngestTarget,
37
+ isValidIdentifier,
38
+ mapResult,
39
+ quoteIdentifier,
40
+ resolveClientBuckets,
41
+ resolveFilterValue,
42
+ resolveLWW,
43
+ rowKey,
44
+ toError,
45
+ unwrapOrThrow,
46
+ validateAction,
47
+ validateConnectorConfig,
48
+ validateSyncRules,
49
+ verifyToken
50
+ } from "./chunk-ICNT7I3K.js";
51
+ import "./chunk-7D4SUZUM.js";
52
+ export {
53
+ ActionExecutionError,
54
+ ActionNotSupportedError,
55
+ ActionValidationError,
56
+ AdapterError,
57
+ AdapterNotFoundError,
58
+ AuthError,
59
+ BackpressureError,
60
+ BaseSourcePoller,
61
+ CONNECTOR_TYPES,
62
+ ClockDriftError,
63
+ ConflictError,
64
+ ConnectorValidationError,
65
+ Err,
66
+ FlushError,
67
+ HLC,
68
+ LWWResolver,
69
+ LakeSyncError,
70
+ Ok,
71
+ SchemaError,
72
+ SyncRuleError,
73
+ applyDelta,
74
+ assertValidIdentifier,
75
+ bigintReplacer,
76
+ bigintReviver,
77
+ createPassAllRules,
78
+ createUserScopedRules,
79
+ deltaMatchesBucket,
80
+ extractDelta,
81
+ filterDeltas,
82
+ flatMapResult,
83
+ fromPromise,
84
+ generateActionId,
85
+ isActionError,
86
+ isActionHandler,
87
+ isIngestTarget,
88
+ isValidIdentifier,
89
+ mapResult,
90
+ quoteIdentifier,
91
+ resolveClientBuckets,
92
+ resolveFilterValue,
93
+ resolveLWW,
94
+ rowKey,
95
+ toError,
96
+ unwrapOrThrow,
97
+ validateAction,
98
+ validateConnectorConfig,
99
+ validateSyncRules,
100
+ verifyToken
101
+ };
102
+ //# sourceMappingURL=index.js.map