@hasna/cloud 0.1.3 → 0.1.5
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 +2 -0
- package/dist/adapter.d.ts.map +1 -1
- package/dist/auto-sync.d.ts +57 -0
- package/dist/auto-sync.d.ts.map +1 -0
- package/dist/cli/index.js +176 -154
- package/dist/cli-helpers.d.ts.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +726 -63
- package/dist/mcp/index.js +173 -151
- package/dist/mcp-helpers.d.ts.map +1 -1
- package/dist/sync-conflicts.d.ts +76 -0
- package/dist/sync-conflicts.d.ts.map +1 -0
- package/dist/sync-incremental.d.ts +62 -0
- package/dist/sync-incremental.d.ts.map +1 -0
- package/dist/sync-progress.d.ts +68 -0
- package/dist/sync-progress.d.ts.map +1 -0
- package/dist/sync.d.ts +10 -9
- package/dist/sync.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { DbAdapter } from "./adapter.js";
|
|
2
|
+
export interface SyncProgressInfo {
|
|
3
|
+
table: string;
|
|
4
|
+
total: number;
|
|
5
|
+
done: number;
|
|
6
|
+
percent: number;
|
|
7
|
+
elapsed_ms: number;
|
|
8
|
+
eta_ms: number;
|
|
9
|
+
status: "pending" | "in_progress" | "completed" | "failed" | "resumed";
|
|
10
|
+
}
|
|
11
|
+
export type ProgressCallback = (progress: SyncProgressInfo) => void;
|
|
12
|
+
export interface ResumePoint {
|
|
13
|
+
table_name: string;
|
|
14
|
+
last_row_id: string;
|
|
15
|
+
direction: string;
|
|
16
|
+
started_at: string;
|
|
17
|
+
status: string;
|
|
18
|
+
}
|
|
19
|
+
export declare class SyncProgressTracker {
|
|
20
|
+
private db;
|
|
21
|
+
private progress;
|
|
22
|
+
private startTimes;
|
|
23
|
+
private callback?;
|
|
24
|
+
constructor(db: DbAdapter, callback?: ProgressCallback);
|
|
25
|
+
private ensureResumeTable;
|
|
26
|
+
/**
|
|
27
|
+
* Start tracking a table sync. Sets status to in_progress or resumed.
|
|
28
|
+
*/
|
|
29
|
+
start(table: string, total: number, direction: string): void;
|
|
30
|
+
/**
|
|
31
|
+
* Update progress for a table after processing rows.
|
|
32
|
+
*/
|
|
33
|
+
update(table: string, done: number, lastRowId: string): void;
|
|
34
|
+
/**
|
|
35
|
+
* Mark a table sync as completed.
|
|
36
|
+
*/
|
|
37
|
+
markComplete(table: string): void;
|
|
38
|
+
/**
|
|
39
|
+
* Mark a table sync as failed.
|
|
40
|
+
*/
|
|
41
|
+
markFailed(table: string, _error: string): void;
|
|
42
|
+
/**
|
|
43
|
+
* Check if a previous sync was interrupted (status is 'in_progress' or 'resumed').
|
|
44
|
+
*/
|
|
45
|
+
canResume(table: string): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Returns the last successfully synced row ID for a table, or null.
|
|
48
|
+
*/
|
|
49
|
+
getResumePoint(table: string): ResumePoint | null;
|
|
50
|
+
/**
|
|
51
|
+
* Clear resume state for a table (e.g., after a fresh sync starts).
|
|
52
|
+
*/
|
|
53
|
+
clearResume(table: string): void;
|
|
54
|
+
/**
|
|
55
|
+
* Get current progress info for a table.
|
|
56
|
+
*/
|
|
57
|
+
getProgress(table: string): SyncProgressInfo | null;
|
|
58
|
+
/**
|
|
59
|
+
* Get progress info for all tracked tables.
|
|
60
|
+
*/
|
|
61
|
+
getAllProgress(): SyncProgressInfo[];
|
|
62
|
+
/**
|
|
63
|
+
* List all resume records from the database (including historical).
|
|
64
|
+
*/
|
|
65
|
+
listResumeRecords(): ResumePoint[];
|
|
66
|
+
private notify;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=sync-progress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync-progress.d.ts","sourceRoot":"","sources":["../src/sync-progress.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAA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G,OAAO;IASjC;;OAEG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI;IAUjD;;OAEG;IACH,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAahC;;OAEG;IACH,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI;IAInD;;OAEG;IACH,cAAc,IAAI,gBAAgB,EAAE;IAIpC;;OAEG;IACH,iBAAiB,IAAI,WAAW,EAAE;IAUlC,OAAO,CAAC,MAAM;CAMf"}
|
package/dist/sync.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { DbAdapter } from "./adapter.js";
|
|
2
|
+
import type { PgAdapterAsync } from "./adapter.js";
|
|
2
3
|
export interface SyncProgress {
|
|
3
4
|
table: string;
|
|
4
5
|
phase: "reading" | "writing" | "done";
|
|
@@ -13,7 +14,7 @@ export interface SyncOptions {
|
|
|
13
14
|
tables: string[];
|
|
14
15
|
/** Optional progress callback. */
|
|
15
16
|
onProgress?: SyncProgressCallback;
|
|
16
|
-
/** Batch size for UPSERT operations. Default:
|
|
17
|
+
/** Batch size for UPSERT operations. Default: 100 */
|
|
17
18
|
batchSize?: number;
|
|
18
19
|
/** Conflict resolution column (default: "updated_at"). Newest wins. */
|
|
19
20
|
conflictColumn?: string;
|
|
@@ -28,21 +29,21 @@ export interface SyncResult {
|
|
|
28
29
|
errors: string[];
|
|
29
30
|
}
|
|
30
31
|
/**
|
|
31
|
-
* Push data from a local database to the cloud database.
|
|
32
|
-
*
|
|
33
|
-
* Conflict resolution: compare `updated_at`, newest wins.
|
|
32
|
+
* Push data from a local SQLite database to the cloud PostgreSQL database.
|
|
33
|
+
* Uses batch UPSERT for performance and FK-aware table ordering.
|
|
34
34
|
*/
|
|
35
|
-
export declare function syncPush(local: DbAdapter,
|
|
35
|
+
export declare function syncPush(local: DbAdapter, remote: PgAdapterAsync, options: SyncOptions): Promise<SyncResult[]>;
|
|
36
36
|
/**
|
|
37
|
-
* Pull data from the cloud database into
|
|
37
|
+
* Pull data from the cloud PostgreSQL database into a local SQLite database.
|
|
38
|
+
* Uses FK-aware table ordering.
|
|
38
39
|
*/
|
|
39
|
-
export declare function syncPull(
|
|
40
|
+
export declare function syncPull(remote: PgAdapterAsync, local: DbAdapter, options: SyncOptions): Promise<SyncResult[]>;
|
|
40
41
|
/**
|
|
41
42
|
* List all user tables in a SQLite database.
|
|
42
43
|
*/
|
|
43
44
|
export declare function listSqliteTables(db: DbAdapter): string[];
|
|
44
45
|
/**
|
|
45
|
-
* List all user tables in a PostgreSQL database.
|
|
46
|
+
* List all user tables in a PostgreSQL database (async).
|
|
46
47
|
*/
|
|
47
|
-
export declare function listPgTables(db:
|
|
48
|
+
export declare function listPgTables(db: PgAdapterAsync): Promise<string[]>;
|
|
48
49
|
//# sourceMappingURL=sync.d.ts.map
|
package/dist/sync.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAMnD,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,SAAS,GAAG,SAAS,GAAG,MAAM,CAAC;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,MAAM,oBAAoB,GAAG,CAAC,QAAQ,EAAE,YAAY,KAAK,IAAI,CAAC;AAEpE,MAAM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