lakesync 0.1.5 → 0.1.8
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.
- package/dist/adapter.d.ts +199 -19
- package/dist/adapter.js +19 -3
- package/dist/analyst.js +2 -2
- package/dist/{base-poller-CBvhdvcj.d.ts → base-poller-Bj9kX9dv.d.ts} +76 -19
- package/dist/catalogue.d.ts +1 -1
- package/dist/catalogue.js +3 -3
- package/dist/chunk-DGUM43GV.js +11 -0
- package/dist/{chunk-PWGQ3PXE.js → chunk-JI4C4R5H.js} +280 -140
- package/dist/chunk-JI4C4R5H.js.map +1 -0
- package/dist/{chunk-L4ZL5JA7.js → chunk-KVSWLIJR.js} +2 -2
- package/dist/{chunk-7UBS6MFH.js → chunk-LDFFCG2K.js} +377 -247
- package/dist/chunk-LDFFCG2K.js.map +1 -0
- package/dist/{chunk-Z7FGLEQU.js → chunk-LPWXOYNS.js} +376 -287
- package/dist/chunk-LPWXOYNS.js.map +1 -0
- package/dist/{chunk-SZSGSTVZ.js → chunk-PYRS74YP.js} +15 -4
- package/dist/{chunk-SZSGSTVZ.js.map → chunk-PYRS74YP.js.map} +1 -1
- package/dist/{chunk-TVLTXHW6.js → chunk-QNITY4F6.js} +30 -7
- package/dist/{chunk-TVLTXHW6.js.map → chunk-QNITY4F6.js.map} +1 -1
- package/dist/{chunk-46CKACNC.js → chunk-SSICS5KI.js} +2 -2
- package/dist/{chunk-B3QEUG6E.js → chunk-TMLG32QV.js} +2 -2
- package/dist/client.d.ts +164 -13
- package/dist/client.js +310 -163
- package/dist/client.js.map +1 -1
- package/dist/compactor.d.ts +1 -1
- package/dist/compactor.js +4 -4
- package/dist/connector-jira.d.ts +2 -2
- package/dist/connector-jira.js +3 -3
- package/dist/connector-salesforce.d.ts +2 -2
- package/dist/connector-salesforce.js +3 -3
- package/dist/{coordinator-DN8D8C7W.d.ts → coordinator-NXy6tA0h.d.ts} +23 -16
- package/dist/{db-types-B6_JKQWK.d.ts → db-types-CfLMUBfW.d.ts} +1 -1
- package/dist/gateway-server.d.ts +158 -64
- package/dist/gateway-server.js +482 -4003
- package/dist/gateway-server.js.map +1 -1
- package/dist/gateway.d.ts +61 -104
- package/dist/gateway.js +12 -6
- package/dist/index.d.ts +45 -10
- package/dist/index.js +14 -2
- package/dist/parquet.d.ts +1 -1
- package/dist/parquet.js +3 -3
- package/dist/proto.d.ts +1 -1
- package/dist/proto.js +3 -3
- package/dist/react.d.ts +47 -10
- package/dist/react.js +88 -40
- package/dist/react.js.map +1 -1
- package/dist/{registry-BN_9spxE.d.ts → registry-BcspAtZI.d.ts} +19 -4
- package/dist/{gateway-CvO7Xy3T.d.ts → request-handler-pUvL7ozF.d.ts} +139 -10
- package/dist/{resolver-BZURzdlL.d.ts → resolver-CXxmC0jR.d.ts} +1 -1
- package/dist/{src-RR7I76OL.js → src-B6NLV3FP.js} +4 -4
- package/dist/{src-SLVE5567.js → src-ROW4XLO7.js} +15 -3
- package/dist/{src-V2CTPR7V.js → src-ZRHKG42A.js} +4 -4
- package/dist/{types-GGBfZBKQ.d.ts → types-BdGBv2ba.d.ts} +23 -2
- package/dist/{types-D-E0VrfS.d.ts → types-BrcD1oJg.d.ts} +26 -19
- package/package.json +1 -1
- package/dist/chunk-7D4SUZUM.js +0 -38
- package/dist/chunk-7UBS6MFH.js.map +0 -1
- package/dist/chunk-PWGQ3PXE.js.map +0 -1
- package/dist/chunk-Z7FGLEQU.js.map +0 -1
- /package/dist/{chunk-7D4SUZUM.js.map → chunk-DGUM43GV.js.map} +0 -0
- /package/dist/{chunk-L4ZL5JA7.js.map → chunk-KVSWLIJR.js.map} +0 -0
- /package/dist/{chunk-46CKACNC.js.map → chunk-SSICS5KI.js.map} +0 -0
- /package/dist/{chunk-B3QEUG6E.js.map → chunk-TMLG32QV.js.map} +0 -0
- /package/dist/{src-RR7I76OL.js.map → src-B6NLV3FP.js.map} +0 -0
- /package/dist/{src-SLVE5567.js.map → src-ROW4XLO7.js.map} +0 -0
- /package/dist/{src-V2CTPR7V.js.map → src-ZRHKG42A.js.map} +0 -0
package/dist/compactor.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { H as HLCTimestamp, R as Result, L as LakeSyncError, F as FlushError } from './result-CojzlFE2.js';
|
|
2
|
-
import { T as TableSchema } from './types-
|
|
2
|
+
import { T as TableSchema } from './types-BdGBv2ba.js';
|
|
3
3
|
import { L as LakeAdapter } from './types-DSC_EiwR.js';
|
|
4
4
|
|
|
5
5
|
/** Configuration for checkpoint generation */
|
package/dist/compactor.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
encodeSyncResponse
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-KVSWLIJR.js";
|
|
4
4
|
import {
|
|
5
5
|
readParquetToDeltas,
|
|
6
6
|
writeDeltasToParquet
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-SSICS5KI.js";
|
|
8
8
|
import {
|
|
9
9
|
Err,
|
|
10
10
|
FlushError,
|
|
@@ -12,8 +12,8 @@ import {
|
|
|
12
12
|
LakeSyncError,
|
|
13
13
|
Ok,
|
|
14
14
|
rowKey
|
|
15
|
-
} from "./chunk-
|
|
16
|
-
import "./chunk-
|
|
15
|
+
} from "./chunk-LDFFCG2K.js";
|
|
16
|
+
import "./chunk-DGUM43GV.js";
|
|
17
17
|
|
|
18
18
|
// ../compactor/src/checkpoint-generator.ts
|
|
19
19
|
var DEFAULT_CHECKPOINT_CONFIG = {
|
package/dist/connector-jira.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { L as LakeSyncError, R as Result } from './result-CojzlFE2.js';
|
|
2
|
-
import { B as BaseSourcePoller, P as PushTarget } from './base-poller-
|
|
3
|
-
import { T as TableSchema } from './types-
|
|
2
|
+
import { B as BaseSourcePoller, P as PushTarget } from './base-poller-Bj9kX9dv.js';
|
|
3
|
+
import { T as TableSchema } from './types-BdGBv2ba.js';
|
|
4
4
|
import './hlc-DiD8QNG3.js';
|
|
5
5
|
|
|
6
6
|
/** HTTP error from the Jira REST API. */
|
package/dist/connector-jira.js
CHANGED
|
@@ -8,9 +8,9 @@ import {
|
|
|
8
8
|
mapIssue,
|
|
9
9
|
mapProject,
|
|
10
10
|
testConnection
|
|
11
|
-
} from "./chunk-
|
|
12
|
-
import "./chunk-
|
|
13
|
-
import "./chunk-
|
|
11
|
+
} from "./chunk-PYRS74YP.js";
|
|
12
|
+
import "./chunk-LDFFCG2K.js";
|
|
13
|
+
import "./chunk-DGUM43GV.js";
|
|
14
14
|
export {
|
|
15
15
|
JIRA_TABLE_SCHEMAS,
|
|
16
16
|
JiraApiError,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { L as LakeSyncError, R as Result } from './result-CojzlFE2.js';
|
|
2
|
-
import { B as BaseSourcePoller, P as PushTarget } from './base-poller-
|
|
3
|
-
import { T as TableSchema } from './types-
|
|
2
|
+
import { B as BaseSourcePoller, P as PushTarget } from './base-poller-Bj9kX9dv.js';
|
|
3
|
+
import { T as TableSchema } from './types-BdGBv2ba.js';
|
|
4
4
|
import './hlc-DiD8QNG3.js';
|
|
5
5
|
|
|
6
6
|
/** HTTP error from the Salesforce REST API. */
|
|
@@ -9,9 +9,9 @@ import {
|
|
|
9
9
|
mapLead,
|
|
10
10
|
mapOpportunity,
|
|
11
11
|
testConnection
|
|
12
|
-
} from "./chunk-
|
|
13
|
-
import "./chunk-
|
|
14
|
-
import "./chunk-
|
|
12
|
+
} from "./chunk-QNITY4F6.js";
|
|
13
|
+
import "./chunk-LDFFCG2K.js";
|
|
14
|
+
import "./chunk-DGUM43GV.js";
|
|
15
15
|
export {
|
|
16
16
|
SALESFORCE_TABLE_SCHEMAS,
|
|
17
17
|
SalesforceApiError,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { L as LakeSyncError, R as Result, H as HLCTimestamp } from './result-CojzlFE2.js';
|
|
2
2
|
import { A as Action, i as ActionPush, j as ActionResponse, d as ActionDiscovery, k as ActionResult, e as ActionErrorResult } from './types-Bs-QyOe-.js';
|
|
3
3
|
import { H as HLC } from './hlc-DiD8QNG3.js';
|
|
4
|
-
import { a as ConnectorDescriptor } from './registry-
|
|
5
|
-
import { R as RowDelta, S as SyncPush,
|
|
4
|
+
import { a as ConnectorDescriptor } from './registry-BcspAtZI.js';
|
|
5
|
+
import { R as RowDelta, S as SyncPush, e as SyncPull, f as SyncResponse } from './types-BdGBv2ba.js';
|
|
6
6
|
|
|
7
7
|
/** Configuration for opening a local database */
|
|
8
8
|
interface DbConfig {
|
|
@@ -253,10 +253,21 @@ interface SyncTransport {
|
|
|
253
253
|
|
|
254
254
|
/** Controls which operations syncOnce() / startAutoSync() performs */
|
|
255
255
|
type SyncMode = "full" | "pushOnly" | "pullOnly";
|
|
256
|
+
/** Readable snapshot of the coordinator's current sync state. */
|
|
257
|
+
interface SyncState {
|
|
258
|
+
/** Whether a sync cycle is currently in progress. */
|
|
259
|
+
syncing: boolean;
|
|
260
|
+
/** Last successful sync time, or null if never synced. */
|
|
261
|
+
lastSyncTime: Date | null;
|
|
262
|
+
/** HLC timestamp of the last successfully synced delta. */
|
|
263
|
+
lastSyncedHlc: HLCTimestamp;
|
|
264
|
+
}
|
|
256
265
|
/** Events emitted by SyncCoordinator */
|
|
257
266
|
interface SyncEvents {
|
|
258
267
|
/** Fired after remote deltas are applied locally. Count is the number of deltas applied. */
|
|
259
268
|
onChange: (count: number) => void;
|
|
269
|
+
/** Fired when a sync cycle (push + pull) begins. */
|
|
270
|
+
onSyncStart: () => void;
|
|
260
271
|
/** Fired after a successful sync cycle (push + pull) completes. */
|
|
261
272
|
onSyncComplete: () => void;
|
|
262
273
|
/** Fired when a sync error occurs. */
|
|
@@ -290,6 +301,9 @@ interface SyncCoordinatorConfig {
|
|
|
290
301
|
*
|
|
291
302
|
* Uses a {@link SyncTransport} abstraction to communicate with the gateway,
|
|
292
303
|
* allowing both in-process (LocalTransport) and remote (HttpTransport) usage.
|
|
304
|
+
*
|
|
305
|
+
* Delegates auto-sync scheduling to {@link AutoSyncScheduler} and action
|
|
306
|
+
* processing to {@link ActionProcessor}.
|
|
293
307
|
*/
|
|
294
308
|
declare class SyncCoordinator {
|
|
295
309
|
readonly tracker: SyncTracker;
|
|
@@ -301,15 +315,11 @@ declare class SyncCoordinator {
|
|
|
301
315
|
private readonly _clientId;
|
|
302
316
|
private readonly maxRetries;
|
|
303
317
|
private readonly syncMode;
|
|
304
|
-
private readonly autoSyncIntervalMs;
|
|
305
|
-
private readonly realtimeHeartbeatMs;
|
|
306
318
|
private lastSyncedHlc;
|
|
307
319
|
private _lastSyncTime;
|
|
308
|
-
private syncIntervalId;
|
|
309
|
-
private visibilityHandler;
|
|
310
320
|
private syncing;
|
|
311
|
-
private readonly
|
|
312
|
-
private readonly
|
|
321
|
+
private readonly autoSyncScheduler;
|
|
322
|
+
private readonly actionProcessor;
|
|
313
323
|
private listeners;
|
|
314
324
|
constructor(db: LocalDB, transport: SyncTransport, config?: SyncCoordinatorConfig);
|
|
315
325
|
/** Register an event listener */
|
|
@@ -317,6 +327,8 @@ declare class SyncCoordinator {
|
|
|
317
327
|
/** Remove an event listener */
|
|
318
328
|
off<K extends keyof SyncEvents>(event: K, listener: SyncEvents[K]): void;
|
|
319
329
|
private emit;
|
|
330
|
+
/** Readable snapshot of the current sync state. */
|
|
331
|
+
get state(): SyncState;
|
|
320
332
|
/** Push pending deltas to the gateway via the transport */
|
|
321
333
|
pushToGateway(): Promise<void>;
|
|
322
334
|
/**
|
|
@@ -344,11 +356,9 @@ declare class SyncCoordinator {
|
|
|
344
356
|
get lastSyncTime(): Date | null;
|
|
345
357
|
/**
|
|
346
358
|
* Start auto-sync: periodic interval + visibility change handler.
|
|
347
|
-
* Synchronises (push + pull) on tab focus and every
|
|
359
|
+
* Synchronises (push + pull) on tab focus and every N seconds.
|
|
348
360
|
*/
|
|
349
361
|
startAutoSync(): void;
|
|
350
|
-
/** Register a visibility change listener to sync on tab focus. */
|
|
351
|
-
private setupVisibilitySync;
|
|
352
362
|
/**
|
|
353
363
|
* Perform initial sync via checkpoint download.
|
|
354
364
|
*
|
|
@@ -379,10 +389,7 @@ declare class SyncCoordinator {
|
|
|
379
389
|
/**
|
|
380
390
|
* Process pending actions from the action queue.
|
|
381
391
|
*
|
|
382
|
-
*
|
|
383
|
-
* `transport.executeAction()`, and acks/nacks based on the result.
|
|
384
|
-
* Dead-letters entries after `maxActionRetries` failures.
|
|
385
|
-
* Triggers an immediate `syncOnce()` on success to pull fresh state.
|
|
392
|
+
* Delegates to the ActionProcessor if one is configured.
|
|
386
393
|
*/
|
|
387
394
|
processActionQueue(): Promise<void>;
|
|
388
395
|
/**
|
|
@@ -403,4 +410,4 @@ declare class SyncCoordinator {
|
|
|
403
410
|
stopAutoSync(): void;
|
|
404
411
|
}
|
|
405
412
|
|
|
406
|
-
export { type ActionQueue as A, type CheckpointResponse as C, DbError as D, LocalDB as L, type QueueEntry as Q, type SyncQueue as S, type Transaction as T, type SyncCoordinatorConfig as a, SyncCoordinator as b, type SyncTransport as c, type ActionQueueEntry as d, type ActionQueueEntryStatus as e, type DbConfig as f, type QueueEntryStatus as g, type SyncEvents as h, type SyncMode as i,
|
|
413
|
+
export { type ActionQueue as A, type CheckpointResponse as C, DbError as D, LocalDB as L, type QueueEntry as Q, type SyncQueue as S, type Transaction as T, type SyncCoordinatorConfig as a, SyncCoordinator as b, type SyncTransport as c, type ActionQueueEntry as d, type ActionQueueEntryStatus as e, type DbConfig as f, type QueueEntryStatus as g, type SyncEvents as h, type SyncMode as i, type SyncState as j, SyncTracker as k };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { R as Result, A as AdapterError, H as HLCTimestamp } from './result-CojzlFE2.js';
|
|
2
|
-
import { R as RowDelta, T as TableSchema } from './types-
|
|
2
|
+
import { R as RowDelta, T as TableSchema } from './types-BdGBv2ba.js';
|
|
3
3
|
|
|
4
4
|
/** Configuration for a database adapter connection. */
|
|
5
5
|
interface DatabaseAdapterConfig {
|
package/dist/gateway-server.d.ts
CHANGED
|
@@ -1,14 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { A as AuthClaims } from './auth-CAVutXzx.js';
|
|
2
|
+
export { a as AuthError, v as verifyToken } from './auth-CAVutXzx.js';
|
|
3
|
+
import { IncomingMessage, ServerResponse, Server } from 'node:http';
|
|
4
|
+
import { D as DatabaseAdapter } from './db-types-CfLMUBfW.js';
|
|
5
|
+
import { C as ConfigStore, d as SyncGateway, c as HandlerResult } from './request-handler-pUvL7ozF.js';
|
|
6
|
+
import { R as RowDelta, f as SyncResponse } from './types-BdGBv2ba.js';
|
|
5
7
|
import { L as LakeAdapter } from './types-DSC_EiwR.js';
|
|
6
8
|
import { H as HLCTimestamp } from './result-CojzlFE2.js';
|
|
7
9
|
import './types-Bs-QyOe-.js';
|
|
8
|
-
import './
|
|
10
|
+
import './types-BrcD1oJg.js';
|
|
11
|
+
import './base-poller-Bj9kX9dv.js';
|
|
9
12
|
import './hlc-DiD8QNG3.js';
|
|
10
13
|
import './nessie-client-DrNikVXy.js';
|
|
11
14
|
|
|
15
|
+
/** Result of authentication: either authenticated claims or an error. */
|
|
16
|
+
type AuthResult = {
|
|
17
|
+
authenticated: true;
|
|
18
|
+
claims: AuthClaims;
|
|
19
|
+
} | {
|
|
20
|
+
authenticated: false;
|
|
21
|
+
status: number;
|
|
22
|
+
message: string;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Extract the Bearer token from an Authorization header.
|
|
26
|
+
* Returns the raw token string, or null if missing/malformed.
|
|
27
|
+
*/
|
|
28
|
+
declare function extractBearerToken(req: IncomingMessage): string | null;
|
|
29
|
+
/**
|
|
30
|
+
* Authenticate an HTTP request.
|
|
31
|
+
*
|
|
32
|
+
* When `jwtSecret` is undefined, auth is disabled and all requests pass.
|
|
33
|
+
* Otherwise validates the Bearer token, checks gateway ID, and enforces
|
|
34
|
+
* admin role for admin actions.
|
|
35
|
+
*/
|
|
36
|
+
declare function authenticateRequest(req: IncomingMessage, routeGatewayId: string, routeAction: string, jwtSecret: string | undefined): Promise<AuthResult>;
|
|
37
|
+
|
|
12
38
|
/**
|
|
13
39
|
* Interface for distributed locking across gateway-server instances.
|
|
14
40
|
*
|
|
@@ -22,10 +48,21 @@ interface DistributedLock {
|
|
|
22
48
|
release(key: string): Promise<void>;
|
|
23
49
|
}
|
|
24
50
|
/**
|
|
25
|
-
* Database-backed distributed lock using
|
|
51
|
+
* Database-backed distributed lock using advisory lock semantics.
|
|
52
|
+
*
|
|
53
|
+
* Uses the adapter's `ensureSchema` + `insertDeltas` to maintain a
|
|
54
|
+
* dedicated `__lakesync_locks` table. Lock entries are isolated from
|
|
55
|
+
* regular sync data — they use a reserved table prefix that sync
|
|
56
|
+
* queries should never match.
|
|
26
57
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
58
|
+
* Acquire is atomic: the adapter's upsert semantics (INSERT ON CONFLICT
|
|
59
|
+
* or equivalent) ensure only one instance can hold a lock. Release
|
|
60
|
+
* is best-effort — the TTL provides a safety net against holder crashes.
|
|
61
|
+
*
|
|
62
|
+
* Note: This implementation piggybacks on the DatabaseAdapter interface
|
|
63
|
+
* because the adapter abstraction doesn't expose raw SQL. For adapters
|
|
64
|
+
* that support native advisory locks (e.g. Postgres pg_advisory_lock),
|
|
65
|
+
* prefer a specialised implementation of {@link DistributedLock}.
|
|
29
66
|
*/
|
|
30
67
|
declare class AdapterBasedLock implements DistributedLock {
|
|
31
68
|
private readonly adapter;
|
|
@@ -33,9 +70,63 @@ declare class AdapterBasedLock implements DistributedLock {
|
|
|
33
70
|
constructor(adapter: DatabaseAdapter, instanceId?: string);
|
|
34
71
|
acquire(key: string, ttlMs: number): Promise<boolean>;
|
|
35
72
|
release(key: string): Promise<void>;
|
|
36
|
-
|
|
73
|
+
/**
|
|
74
|
+
* Create an HLC-format timestamp from wall clock time.
|
|
75
|
+
*
|
|
76
|
+
* Uses the standard 48-bit wall + 16-bit counter encoding.
|
|
77
|
+
*/
|
|
78
|
+
private makeHlc;
|
|
37
79
|
}
|
|
38
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Manages connector registration, adapter creation, and poller lifecycle.
|
|
83
|
+
*
|
|
84
|
+
* Encapsulates the if/else chains for different connector types and
|
|
85
|
+
* handles clean-up on unregistration.
|
|
86
|
+
*/
|
|
87
|
+
declare class ConnectorManager {
|
|
88
|
+
private readonly configStore;
|
|
89
|
+
private readonly gateway;
|
|
90
|
+
private readonly adapters;
|
|
91
|
+
private readonly pollers;
|
|
92
|
+
constructor(configStore: ConfigStore, gateway: SyncGateway);
|
|
93
|
+
/**
|
|
94
|
+
* Register a connector from raw JSON body.
|
|
95
|
+
*
|
|
96
|
+
* Validates via shared handler, creates adapter/poller as appropriate,
|
|
97
|
+
* registers with the gateway.
|
|
98
|
+
*/
|
|
99
|
+
register(raw: string): Promise<HandlerResult>;
|
|
100
|
+
/**
|
|
101
|
+
* Unregister a connector by name.
|
|
102
|
+
*
|
|
103
|
+
* Stops poller, closes adapter, and unregisters from gateway.
|
|
104
|
+
*/
|
|
105
|
+
unregister(name: string): Promise<HandlerResult>;
|
|
106
|
+
/**
|
|
107
|
+
* List registered connectors with live polling status.
|
|
108
|
+
*/
|
|
109
|
+
list(): Promise<HandlerResult>;
|
|
110
|
+
/** Stop all pollers and close all adapters. */
|
|
111
|
+
stopAll(): Promise<void>;
|
|
112
|
+
private rollbackRegistration;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Configuration for CORS header generation. */
|
|
116
|
+
interface CorsConfig {
|
|
117
|
+
/** Allowed origins. When empty/omitted, all origins are reflected. */
|
|
118
|
+
allowedOrigins?: string[];
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Build CORS response headers for the given origin.
|
|
122
|
+
*
|
|
123
|
+
* When `allowedOrigins` is set, only listed origins receive CORS headers.
|
|
124
|
+
* When omitted, the request origin is reflected (or `*` if no origin header).
|
|
125
|
+
*/
|
|
126
|
+
declare function corsHeaders(origin: string | null | undefined, config: CorsConfig): Record<string, string>;
|
|
127
|
+
/** Handle CORS preflight (OPTIONS) request. Returns true if handled. */
|
|
128
|
+
declare function handlePreflight(method: string, res: ServerResponse, corsH: Record<string, string>): boolean;
|
|
129
|
+
|
|
39
130
|
/** Generic query function — abstracts any SQL database. */
|
|
40
131
|
type QueryFn = (sql: string, params?: unknown[]) => Promise<Record<string, unknown>[]>;
|
|
41
132
|
/** Configuration for a single polling ingest source. */
|
|
@@ -148,6 +239,20 @@ declare class SqlitePersistence implements DeltaPersistence {
|
|
|
148
239
|
close(): void;
|
|
149
240
|
}
|
|
150
241
|
|
|
242
|
+
/** Matched route information. */
|
|
243
|
+
interface RouteMatch {
|
|
244
|
+
gatewayId: string;
|
|
245
|
+
action: string;
|
|
246
|
+
/** Extra route parameters (e.g. connector name from DELETE path). */
|
|
247
|
+
connectorName?: string;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Match a request pathname and method against the route table.
|
|
251
|
+
*
|
|
252
|
+
* Returns the matched route or null if no route matches.
|
|
253
|
+
*/
|
|
254
|
+
declare function matchRoute(pathname: string, method: string): RouteMatch | null;
|
|
255
|
+
|
|
151
256
|
/** Configuration for the self-hosted gateway server. */
|
|
152
257
|
interface GatewayServerConfig {
|
|
153
258
|
/** Port to listen on (default 3000). */
|
|
@@ -183,9 +288,9 @@ interface GatewayServerConfig {
|
|
|
183
288
|
/**
|
|
184
289
|
* Self-hosted HTTP gateway server wrapping {@link SyncGateway}.
|
|
185
290
|
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
291
|
+
* Composes extracted modules: cors-middleware, auth-middleware, router,
|
|
292
|
+
* ws-manager, and connector-manager. Request handling follows the
|
|
293
|
+
* pipeline: cors -> auth -> route -> handler.
|
|
189
294
|
*
|
|
190
295
|
* @example
|
|
191
296
|
* ```ts
|
|
@@ -199,83 +304,45 @@ interface GatewayServerConfig {
|
|
|
199
304
|
* ```
|
|
200
305
|
*/
|
|
201
306
|
declare class GatewayServer {
|
|
202
|
-
private gateway;
|
|
203
|
-
private config;
|
|
307
|
+
private readonly gateway;
|
|
308
|
+
private readonly config;
|
|
309
|
+
private readonly configStore;
|
|
310
|
+
private readonly persistence;
|
|
311
|
+
private readonly connectors;
|
|
312
|
+
private readonly sharedBuffer;
|
|
204
313
|
private httpServer;
|
|
314
|
+
private wsManager;
|
|
205
315
|
private flushTimer;
|
|
206
|
-
private configStore;
|
|
207
|
-
private persistence;
|
|
208
316
|
private resolvedPort;
|
|
209
|
-
private wss;
|
|
210
|
-
private wsClients;
|
|
211
317
|
private pollers;
|
|
212
|
-
private connectorAdapters;
|
|
213
|
-
private connectorPollers;
|
|
214
|
-
private sharedBuffer;
|
|
215
318
|
constructor(config: GatewayServerConfig);
|
|
216
319
|
/**
|
|
217
320
|
* Start the HTTP server and periodic flush timer.
|
|
218
321
|
*
|
|
219
|
-
* Rehydrates unflushed deltas from the persistence layer
|
|
220
|
-
* accepting
|
|
322
|
+
* Rehydrates unflushed deltas from the persistence layer directly
|
|
323
|
+
* into the buffer (bypassing push validation) before accepting
|
|
324
|
+
* connections.
|
|
221
325
|
*/
|
|
222
326
|
start(): Promise<void>;
|
|
223
|
-
/**
|
|
224
|
-
* Handle HTTP -> WebSocket upgrade.
|
|
225
|
-
*
|
|
226
|
-
* Authenticates via Bearer token in Authorization header or `?token=` query param.
|
|
227
|
-
*/
|
|
228
|
-
private handleUpgrade;
|
|
229
|
-
/**
|
|
230
|
-
* Handle an incoming WebSocket message (binary protobuf).
|
|
231
|
-
*/
|
|
232
|
-
private handleWsMessage;
|
|
233
|
-
/**
|
|
234
|
-
* Build sync rules context from WebSocket client claims.
|
|
235
|
-
*/
|
|
236
|
-
private buildWsSyncRulesContext;
|
|
237
|
-
/**
|
|
238
|
-
* Broadcast ingested deltas to all connected WebSocket clients except the sender.
|
|
239
|
-
*/
|
|
240
|
-
private broadcastDeltas;
|
|
241
|
-
private broadcastDeltasAsync;
|
|
242
|
-
/** Stop the server and clear the flush timer. */
|
|
327
|
+
/** Stop the server, pollers, connectors, and WebSocket connections. */
|
|
243
328
|
stop(): Promise<void>;
|
|
244
329
|
/** The port the server is listening on (available after start). */
|
|
245
330
|
get port(): number;
|
|
246
331
|
/** The underlying SyncGateway instance for direct access. */
|
|
247
332
|
get gatewayInstance(): SyncGateway;
|
|
248
333
|
private handleRequest;
|
|
249
|
-
/**
|
|
250
|
-
* Handle `POST /sync/:gatewayId/push` -- ingest client deltas.
|
|
251
|
-
*/
|
|
252
334
|
private handlePush;
|
|
253
|
-
/**
|
|
254
|
-
* Handle `GET /sync/:gatewayId/pull` -- retrieve deltas since a given HLC.
|
|
255
|
-
*/
|
|
256
335
|
private handlePull;
|
|
257
|
-
/**
|
|
258
|
-
* Handle `POST /sync/:gatewayId/action` -- execute imperative actions.
|
|
259
|
-
*/
|
|
260
336
|
private handleAction;
|
|
261
|
-
/** Handle `GET /sync/:gatewayId/actions` -- describe available action handlers. */
|
|
262
337
|
private handleDescribeActions;
|
|
263
|
-
/** Handle `POST /admin/flush/:gatewayId` -- manual flush. */
|
|
264
338
|
private handleFlush;
|
|
265
|
-
/** Handle `POST /admin/schema/:gatewayId` -- save table schema. */
|
|
266
339
|
private handleSaveSchemaRoute;
|
|
267
|
-
/** Handle `POST /admin/sync-rules/:gatewayId` -- save sync rules. */
|
|
268
340
|
private handleSaveSyncRulesRoute;
|
|
269
|
-
|
|
270
|
-
private
|
|
271
|
-
/** Handle `DELETE /admin/connectors/:gatewayId/:name` -- unregister a connector. */
|
|
272
|
-
private handleUnregisterConnector;
|
|
273
|
-
/** Handle `GET /admin/connectors/:gatewayId` -- list registered connectors. */
|
|
341
|
+
private handleRegisterConnectorRoute;
|
|
342
|
+
private handleUnregisterConnectorRoute;
|
|
274
343
|
private handleListConnectorsRoute;
|
|
275
|
-
/** Handle `GET /admin/metrics/:gatewayId` -- return buffer stats and process memory. */
|
|
276
344
|
private handleMetricsRoute;
|
|
277
345
|
private periodicFlush;
|
|
278
|
-
private corsHeaders;
|
|
279
346
|
}
|
|
280
347
|
|
|
281
348
|
/**
|
|
@@ -303,4 +370,31 @@ declare class SharedBuffer {
|
|
|
303
370
|
mergePull(localResult: SyncResponse, sinceHlc: HLCTimestamp): Promise<SyncResponse>;
|
|
304
371
|
}
|
|
305
372
|
|
|
306
|
-
|
|
373
|
+
/**
|
|
374
|
+
* Manages WebSocket connections, message handling, and broadcasting.
|
|
375
|
+
*
|
|
376
|
+
* Decouples the WebSocket protocol from the HTTP server lifecycle.
|
|
377
|
+
*/
|
|
378
|
+
declare class WebSocketManager {
|
|
379
|
+
private readonly gateway;
|
|
380
|
+
private readonly configStore;
|
|
381
|
+
private readonly gatewayId;
|
|
382
|
+
private readonly jwtSecret;
|
|
383
|
+
private readonly wss;
|
|
384
|
+
private readonly clients;
|
|
385
|
+
constructor(gateway: SyncGateway, configStore: ConfigStore, gatewayId: string, jwtSecret: string | undefined);
|
|
386
|
+
/** Attach upgrade listener to an HTTP server. */
|
|
387
|
+
attach(httpServer: Server): void;
|
|
388
|
+
/**
|
|
389
|
+
* Broadcast ingested deltas to all connected WebSocket clients except the sender.
|
|
390
|
+
*/
|
|
391
|
+
broadcastDeltas(deltas: RowDelta[], serverHlc: HLCTimestamp, excludeClientId: string): void;
|
|
392
|
+
/** Close all connections and shut down the WebSocket server. */
|
|
393
|
+
close(): void;
|
|
394
|
+
private handleUpgrade;
|
|
395
|
+
private handleMessage;
|
|
396
|
+
private buildSyncRulesContext;
|
|
397
|
+
private broadcastDeltasAsync;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
export { AdapterBasedLock, AuthClaims, type AuthResult, ConnectorManager, type CorsConfig, type CursorStrategy, type DeltaPersistence, type DiffStrategy, type DistributedLock, GatewayServer, type GatewayServerConfig, type IngestSourceConfig, type IngestTableConfig, MemoryPersistence, type QueryFn, type RouteMatch, SharedBuffer, SourcePoller, SqlitePersistence, WebSocketManager, authenticateRequest, corsHeaders, extractBearerToken, handlePreflight, matchRoute };
|