cursor-history 0.6.0 → 0.9.1
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/LICENSE +7 -0
- package/README.md +371 -9
- package/dist/cli/commands/backup.d.ts +9 -0
- package/dist/cli/commands/backup.d.ts.map +1 -0
- package/dist/cli/commands/backup.js +168 -0
- package/dist/cli/commands/backup.js.map +1 -0
- package/dist/cli/commands/export.d.ts.map +1 -1
- package/dist/cli/commands/export.js +38 -6
- package/dist/cli/commands/export.js.map +1 -1
- package/dist/cli/commands/list-backups.d.ts +9 -0
- package/dist/cli/commands/list-backups.d.ts.map +1 -0
- package/dist/cli/commands/list-backups.js +166 -0
- package/dist/cli/commands/list-backups.js.map +1 -0
- package/dist/cli/commands/list.d.ts.map +1 -1
- package/dist/cli/commands/list.js +44 -9
- package/dist/cli/commands/list.js.map +1 -1
- package/dist/cli/commands/migrate-session.d.ts +12 -0
- package/dist/cli/commands/migrate-session.d.ts.map +1 -0
- package/dist/cli/commands/migrate-session.js +125 -0
- package/dist/cli/commands/migrate-session.js.map +1 -0
- package/dist/cli/commands/migrate.d.ts +13 -0
- package/dist/cli/commands/migrate.d.ts.map +1 -0
- package/dist/cli/commands/migrate.js +122 -0
- package/dist/cli/commands/migrate.js.map +1 -0
- package/dist/cli/commands/restore.d.ts +9 -0
- package/dist/cli/commands/restore.d.ts.map +1 -0
- package/dist/cli/commands/restore.js +192 -0
- package/dist/cli/commands/restore.js.map +1 -0
- package/dist/cli/commands/search.d.ts.map +1 -1
- package/dist/cli/commands/search.js +30 -2
- package/dist/cli/commands/search.js.map +1 -1
- package/dist/cli/commands/show.d.ts.map +1 -1
- package/dist/cli/commands/show.js +31 -3
- package/dist/cli/commands/show.js.map +1 -1
- package/dist/cli/index.js +10 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/core/backup.d.ts +86 -0
- package/dist/core/backup.d.ts.map +1 -0
- package/dist/core/backup.js +727 -0
- package/dist/core/backup.js.map +1 -0
- package/dist/core/database/debug.d.ts +12 -0
- package/dist/core/database/debug.d.ts.map +1 -0
- package/dist/core/database/debug.js +16 -0
- package/dist/core/database/debug.js.map +1 -0
- package/dist/core/database/drivers/better-sqlite3.d.ts +11 -0
- package/dist/core/database/drivers/better-sqlite3.d.ts.map +1 -0
- package/dist/core/database/drivers/better-sqlite3.js +93 -0
- package/dist/core/database/drivers/better-sqlite3.js.map +1 -0
- package/dist/core/database/drivers/node-sqlite.d.ts +15 -0
- package/dist/core/database/drivers/node-sqlite.d.ts.map +1 -0
- package/dist/core/database/drivers/node-sqlite.js +135 -0
- package/dist/core/database/drivers/node-sqlite.js.map +1 -0
- package/dist/core/database/errors.d.ts +24 -0
- package/dist/core/database/errors.d.ts.map +1 -0
- package/dist/core/database/errors.js +38 -0
- package/dist/core/database/errors.js.map +1 -0
- package/dist/core/database/index.d.ts +98 -0
- package/dist/core/database/index.d.ts.map +1 -0
- package/dist/core/database/index.js +125 -0
- package/dist/core/database/index.js.map +1 -0
- package/dist/core/database/registry.d.ts +81 -0
- package/dist/core/database/registry.d.ts.map +1 -0
- package/dist/core/database/registry.js +171 -0
- package/dist/core/database/registry.js.map +1 -0
- package/dist/core/database/types.d.ts +115 -0
- package/dist/core/database/types.d.ts.map +1 -0
- package/dist/core/database/types.js +8 -0
- package/dist/core/database/types.js.map +1 -0
- package/dist/core/migrate.d.ts +40 -0
- package/dist/core/migrate.d.ts.map +1 -0
- package/dist/core/migrate.js +586 -0
- package/dist/core/migrate.js.map +1 -0
- package/dist/core/storage.d.ts +84 -10
- package/dist/core/storage.d.ts.map +1 -1
- package/dist/core/storage.js +319 -33
- package/dist/core/storage.js.map +1 -1
- package/dist/core/types.d.ts +252 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/lib/backup.d.ts +98 -0
- package/dist/lib/backup.d.ts.map +1 -0
- package/dist/lib/backup.js +108 -0
- package/dist/lib/backup.js.map +1 -0
- package/dist/lib/config.d.ts +3 -1
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +10 -0
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/errors.d.ts +229 -0
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/errors.js +361 -0
- package/dist/lib/errors.js.map +1 -1
- package/dist/lib/index.d.ts +133 -24
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +212 -49
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/platform.d.ts +11 -0
- package/dist/lib/platform.d.ts.map +1 -1
- package/dist/lib/platform.js +32 -0
- package/dist/lib/platform.js.map +1 -1
- package/dist/lib/types.d.ts +267 -0
- package/dist/lib/types.d.ts.map +1 -1
- package/package.json +23 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/database/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAYH,mBAAmB;AACnB,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AAErB,8BAA8B;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,iCAAiC;AACjC,QAAQ,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC;AACpC,QAAQ,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC;AAEvC;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,IAAY;IAC7C,OAAO,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;AACrC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,IAAY;IACtD,OAAO,QAAQ,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC;AAC9C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO,QAAQ,CAAC,eAAe,EAAE,CAAC;AACpC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO,QAAQ,CAAC,eAAe,EAAE,CAAC;AACpC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,IAAsC;IACpE,OAAO,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AAClC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,oBAAoB;IAClC,OAAO,QAAQ,CAAC,oBAAoB,EAAE,CAAC;AACzC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB;IACvC,OAAO,QAAQ,CAAC,mBAAmB,EAAE,CAAC;AACxC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa;IAC3B,QAAQ,CAAC,KAAK,EAAE,CAAC;AACnB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY;IAChC,MAAM,QAAQ,CAAC,YAAY,EAAE,CAAC;AAChC,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,UAAkB,EAAE,QAAgB;IACvE,OAAO,QAAQ,CAAC,cAAc,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Driver Registry - Singleton for managing SQLite driver selection
|
|
3
|
+
*
|
|
4
|
+
* Handles auto-detection, manual selection, and runtime switching of drivers.
|
|
5
|
+
*/
|
|
6
|
+
import type { Database, DatabaseDriver, DriverName } from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Singleton registry for managing SQLite drivers
|
|
9
|
+
*/
|
|
10
|
+
declare class DriverRegistry {
|
|
11
|
+
private drivers;
|
|
12
|
+
private currentDriver;
|
|
13
|
+
private initialized;
|
|
14
|
+
/**
|
|
15
|
+
* Register a driver with the registry
|
|
16
|
+
*/
|
|
17
|
+
register(driver: DatabaseDriver): void;
|
|
18
|
+
/**
|
|
19
|
+
* Get all registered driver names
|
|
20
|
+
*/
|
|
21
|
+
getRegisteredDrivers(): string[];
|
|
22
|
+
/**
|
|
23
|
+
* Check which drivers are currently available
|
|
24
|
+
*/
|
|
25
|
+
getAvailableDrivers(): Promise<string[]>;
|
|
26
|
+
/**
|
|
27
|
+
* Auto-detect and select the best available driver
|
|
28
|
+
*
|
|
29
|
+
* Priority:
|
|
30
|
+
* 1. User-specified via CURSOR_HISTORY_SQLITE_DRIVER env var
|
|
31
|
+
* 2. node:sqlite (no native bindings, ESM compatible)
|
|
32
|
+
* 3. better-sqlite3 (fallback)
|
|
33
|
+
*/
|
|
34
|
+
autoSelect(): Promise<DatabaseDriver>;
|
|
35
|
+
/**
|
|
36
|
+
* Manually set the active driver by name
|
|
37
|
+
*/
|
|
38
|
+
setDriver(name: DriverName): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Get the name of the currently active driver
|
|
41
|
+
*/
|
|
42
|
+
getActiveDriver(): string;
|
|
43
|
+
/**
|
|
44
|
+
* Check if a driver has been selected
|
|
45
|
+
*/
|
|
46
|
+
hasActiveDriver(): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Get the current driver, auto-selecting if needed
|
|
49
|
+
*/
|
|
50
|
+
ensureDriver(): Promise<DatabaseDriver>;
|
|
51
|
+
/**
|
|
52
|
+
* Open a database in read-only mode
|
|
53
|
+
*/
|
|
54
|
+
openDatabase(path: string): Promise<Database>;
|
|
55
|
+
/**
|
|
56
|
+
* Open a database in read-write mode
|
|
57
|
+
*/
|
|
58
|
+
openDatabaseReadWrite(path: string): Promise<Database>;
|
|
59
|
+
/**
|
|
60
|
+
* Synchronous database open (requires driver to already be selected)
|
|
61
|
+
*
|
|
62
|
+
* This is used by backup module which needs synchronous access.
|
|
63
|
+
* Auto-selection must have happened before calling this.
|
|
64
|
+
*/
|
|
65
|
+
openSync(path: string, options: {
|
|
66
|
+
readonly: boolean;
|
|
67
|
+
}): Database;
|
|
68
|
+
/**
|
|
69
|
+
* Backup a database file to another location
|
|
70
|
+
*
|
|
71
|
+
* Uses the native SQLite backup API for consistent snapshots.
|
|
72
|
+
*/
|
|
73
|
+
backupDatabase(sourcePath: string, destPath: string): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Reset the registry (mainly for testing)
|
|
76
|
+
*/
|
|
77
|
+
reset(): void;
|
|
78
|
+
}
|
|
79
|
+
export declare const registry: DriverRegistry;
|
|
80
|
+
export {};
|
|
81
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/core/database/registry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAIvE;;GAEG;AACH,cAAM,cAAc;IAClB,OAAO,CAAC,OAAO,CAA0C;IACzD,OAAO,CAAC,aAAa,CAA+B;IACpD,OAAO,CAAC,WAAW,CAAS;IAE5B;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI;IAKtC;;OAEG;IACH,oBAAoB,IAAI,MAAM,EAAE;IAIhC;;OAEG;IACG,mBAAmB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAU9C;;;;;;;OAOG;IACG,UAAU,IAAI,OAAO,CAAC,cAAc,CAAC;IAuC3C;;OAEG;IACG,SAAS,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBhD;;OAEG;IACH,eAAe,IAAI,MAAM;IAOzB;;OAEG;IACH,eAAe,IAAI,OAAO;IAI1B;;OAEG;IACG,YAAY,IAAI,OAAO,CAAC,cAAc,CAAC;IAO7C;;OAEG;IACG,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAKnD;;OAEG;IACG,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAK5D;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,QAAQ,EAAE,OAAO,CAAA;KAAE,GAAG,QAAQ;IAUhE;;;;OAIG;IACG,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKzE;;OAEG;IACH,KAAK,IAAI,IAAI;CAKd;AAGD,eAAO,MAAM,QAAQ,gBAAuB,CAAC"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Driver Registry - Singleton for managing SQLite driver selection
|
|
3
|
+
*
|
|
4
|
+
* Handles auto-detection, manual selection, and runtime switching of drivers.
|
|
5
|
+
*/
|
|
6
|
+
import { NoDriverAvailableError, DriverNotAvailableError } from './errors.js';
|
|
7
|
+
import { debugLog } from './debug.js';
|
|
8
|
+
/**
|
|
9
|
+
* Singleton registry for managing SQLite drivers
|
|
10
|
+
*/
|
|
11
|
+
class DriverRegistry {
|
|
12
|
+
drivers = new Map();
|
|
13
|
+
currentDriver = null;
|
|
14
|
+
initialized = false;
|
|
15
|
+
/**
|
|
16
|
+
* Register a driver with the registry
|
|
17
|
+
*/
|
|
18
|
+
register(driver) {
|
|
19
|
+
this.drivers.set(driver.name, driver);
|
|
20
|
+
debugLog(`Registered driver: ${driver.name}`);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get all registered driver names
|
|
24
|
+
*/
|
|
25
|
+
getRegisteredDrivers() {
|
|
26
|
+
return Array.from(this.drivers.keys());
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Check which drivers are currently available
|
|
30
|
+
*/
|
|
31
|
+
async getAvailableDrivers() {
|
|
32
|
+
const available = [];
|
|
33
|
+
for (const [name, driver] of this.drivers) {
|
|
34
|
+
if (await driver.isAvailable()) {
|
|
35
|
+
available.push(name);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return available;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Auto-detect and select the best available driver
|
|
42
|
+
*
|
|
43
|
+
* Priority:
|
|
44
|
+
* 1. User-specified via CURSOR_HISTORY_SQLITE_DRIVER env var
|
|
45
|
+
* 2. node:sqlite (no native bindings, ESM compatible)
|
|
46
|
+
* 3. better-sqlite3 (fallback)
|
|
47
|
+
*/
|
|
48
|
+
async autoSelect() {
|
|
49
|
+
// Check for user override via environment variable
|
|
50
|
+
const envDriver = process.env['CURSOR_HISTORY_SQLITE_DRIVER'];
|
|
51
|
+
if (envDriver) {
|
|
52
|
+
debugLog(`Environment override: CURSOR_HISTORY_SQLITE_DRIVER=${envDriver}`);
|
|
53
|
+
const driver = this.drivers.get(envDriver);
|
|
54
|
+
if (driver && (await driver.isAvailable())) {
|
|
55
|
+
this.currentDriver = driver;
|
|
56
|
+
this.initialized = true;
|
|
57
|
+
debugLog(`Using driver from env var: ${driver.name}`);
|
|
58
|
+
return driver;
|
|
59
|
+
}
|
|
60
|
+
// Driver specified but not available
|
|
61
|
+
const available = await this.getAvailableDrivers();
|
|
62
|
+
throw new DriverNotAvailableError(envDriver, available);
|
|
63
|
+
}
|
|
64
|
+
// Auto-detect: try node:sqlite first (no native bindings)
|
|
65
|
+
const nodeSqlite = this.drivers.get('node:sqlite');
|
|
66
|
+
if (nodeSqlite && (await nodeSqlite.isAvailable())) {
|
|
67
|
+
this.currentDriver = nodeSqlite;
|
|
68
|
+
this.initialized = true;
|
|
69
|
+
debugLog(`Auto-selected driver: node:sqlite`);
|
|
70
|
+
return nodeSqlite;
|
|
71
|
+
}
|
|
72
|
+
// Fallback to better-sqlite3
|
|
73
|
+
const betterSqlite = this.drivers.get('better-sqlite3');
|
|
74
|
+
if (betterSqlite && (await betterSqlite.isAvailable())) {
|
|
75
|
+
this.currentDriver = betterSqlite;
|
|
76
|
+
this.initialized = true;
|
|
77
|
+
debugLog(`Auto-selected driver: better-sqlite3`);
|
|
78
|
+
return betterSqlite;
|
|
79
|
+
}
|
|
80
|
+
// No driver available
|
|
81
|
+
throw new NoDriverAvailableError();
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Manually set the active driver by name
|
|
85
|
+
*/
|
|
86
|
+
async setDriver(name) {
|
|
87
|
+
const driver = this.drivers.get(name);
|
|
88
|
+
if (!driver) {
|
|
89
|
+
const available = await this.getAvailableDrivers();
|
|
90
|
+
throw new DriverNotAvailableError(name, available);
|
|
91
|
+
}
|
|
92
|
+
if (!(await driver.isAvailable())) {
|
|
93
|
+
const available = await this.getAvailableDrivers();
|
|
94
|
+
throw new DriverNotAvailableError(name, available);
|
|
95
|
+
}
|
|
96
|
+
this.currentDriver = driver;
|
|
97
|
+
this.initialized = true;
|
|
98
|
+
debugLog(`Manually set driver: ${name}`);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Get the name of the currently active driver
|
|
102
|
+
*/
|
|
103
|
+
getActiveDriver() {
|
|
104
|
+
if (!this.currentDriver) {
|
|
105
|
+
throw new Error('No driver is currently active. Call autoSelect() or setDriver() first.');
|
|
106
|
+
}
|
|
107
|
+
return this.currentDriver.name;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Check if a driver has been selected
|
|
111
|
+
*/
|
|
112
|
+
hasActiveDriver() {
|
|
113
|
+
return this.currentDriver !== null;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Get the current driver, auto-selecting if needed
|
|
117
|
+
*/
|
|
118
|
+
async ensureDriver() {
|
|
119
|
+
if (!this.initialized || !this.currentDriver) {
|
|
120
|
+
return this.autoSelect();
|
|
121
|
+
}
|
|
122
|
+
return this.currentDriver;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Open a database in read-only mode
|
|
126
|
+
*/
|
|
127
|
+
async openDatabase(path) {
|
|
128
|
+
const driver = await this.ensureDriver();
|
|
129
|
+
return driver.open(path, { readonly: true });
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Open a database in read-write mode
|
|
133
|
+
*/
|
|
134
|
+
async openDatabaseReadWrite(path) {
|
|
135
|
+
const driver = await this.ensureDriver();
|
|
136
|
+
return driver.open(path, { readonly: false });
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Synchronous database open (requires driver to already be selected)
|
|
140
|
+
*
|
|
141
|
+
* This is used by backup module which needs synchronous access.
|
|
142
|
+
* Auto-selection must have happened before calling this.
|
|
143
|
+
*/
|
|
144
|
+
openSync(path, options) {
|
|
145
|
+
if (!this.currentDriver) {
|
|
146
|
+
throw new Error('No driver is currently active. Auto-selection must complete before using openSync(). ' +
|
|
147
|
+
'Call a database operation first to trigger auto-selection.');
|
|
148
|
+
}
|
|
149
|
+
return this.currentDriver.open(path, options);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Backup a database file to another location
|
|
153
|
+
*
|
|
154
|
+
* Uses the native SQLite backup API for consistent snapshots.
|
|
155
|
+
*/
|
|
156
|
+
async backupDatabase(sourcePath, destPath) {
|
|
157
|
+
const driver = await this.ensureDriver();
|
|
158
|
+
return driver.backup(sourcePath, destPath);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Reset the registry (mainly for testing)
|
|
162
|
+
*/
|
|
163
|
+
reset() {
|
|
164
|
+
this.currentDriver = null;
|
|
165
|
+
this.initialized = false;
|
|
166
|
+
debugLog('Registry reset');
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
// Singleton instance
|
|
170
|
+
export const registry = new DriverRegistry();
|
|
171
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/core/database/registry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA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;;OAEG;IACH,KAAK,CAAC,qBAAqB,CAAC,IAAY;QACtC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;QACzC,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;IAChD,CAAC;IAED;;;;;OAKG;IACH,QAAQ,CAAC,IAAY,EAAE,OAA8B;QACnD,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CACb,uFAAuF;gBACvF,4DAA4D,CAC7D,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAChD,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,cAAc,CAAC,UAAkB,EAAE,QAAgB;QACvD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;QACzC,OAAO,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IAC7C,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC1B,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QACzB,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IAC7B,CAAC;CACF;AAED,qBAAqB;AACrB,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,cAAc,EAAE,CAAC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pluggable SQLite Driver - Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* These interfaces define the contract for the driver abstraction layer.
|
|
5
|
+
* Both better-sqlite3 and node:sqlite adapters must conform to these types.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Result of running a statement that modifies data (INSERT/UPDATE/DELETE)
|
|
9
|
+
*/
|
|
10
|
+
export interface RunResult {
|
|
11
|
+
/** Number of rows affected by the operation */
|
|
12
|
+
changes: number;
|
|
13
|
+
/** Row ID of the last inserted row (for INSERT operations) */
|
|
14
|
+
lastInsertRowid: number | bigint;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Prepared SQL statement that can be run multiple times with different parameters
|
|
18
|
+
*/
|
|
19
|
+
export interface Statement {
|
|
20
|
+
/**
|
|
21
|
+
* Run the statement and return the first row
|
|
22
|
+
* @param params - Bind parameters for the query
|
|
23
|
+
* @returns The first row as an object, or undefined if no rows
|
|
24
|
+
*/
|
|
25
|
+
get(...params: unknown[]): unknown;
|
|
26
|
+
/**
|
|
27
|
+
* Run the statement and return all rows
|
|
28
|
+
* @param params - Bind parameters for the query
|
|
29
|
+
* @returns Array of row objects (empty array if no rows)
|
|
30
|
+
*/
|
|
31
|
+
all(...params: unknown[]): unknown[];
|
|
32
|
+
/**
|
|
33
|
+
* Run the statement for side effects (INSERT/UPDATE/DELETE)
|
|
34
|
+
* @param params - Bind parameters for the query
|
|
35
|
+
* @returns Result containing changes count and last insert ID
|
|
36
|
+
*/
|
|
37
|
+
run(...params: unknown[]): RunResult;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Open database connection
|
|
41
|
+
*/
|
|
42
|
+
export interface Database {
|
|
43
|
+
/**
|
|
44
|
+
* Create a prepared statement from SQL
|
|
45
|
+
* @param sql - SQL query string
|
|
46
|
+
* @returns Prepared statement object
|
|
47
|
+
*/
|
|
48
|
+
prepare(sql: string): Statement;
|
|
49
|
+
/**
|
|
50
|
+
* Run raw SQL directly without returning results
|
|
51
|
+
* Useful for DDL statements or multiple statements
|
|
52
|
+
* Note: Named 'runSQL' to avoid confusion with child_process methods
|
|
53
|
+
* @param sql - SQL to run
|
|
54
|
+
*/
|
|
55
|
+
runSQL(sql: string): void;
|
|
56
|
+
/**
|
|
57
|
+
* Close the database connection
|
|
58
|
+
* After calling this, the database object should not be used
|
|
59
|
+
*/
|
|
60
|
+
close(): void;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Options for opening a database connection
|
|
64
|
+
*/
|
|
65
|
+
export interface DatabaseOptions {
|
|
66
|
+
/** If true, open in read-only mode (writes will fail) */
|
|
67
|
+
readonly: boolean;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Pluggable database driver implementation
|
|
71
|
+
*
|
|
72
|
+
* Each driver adapter (better-sqlite3, node:sqlite, etc.) must implement
|
|
73
|
+
* this interface to be usable with the driver registry.
|
|
74
|
+
*/
|
|
75
|
+
export interface DatabaseDriver {
|
|
76
|
+
/** Unique identifier for this driver (e.g., "better-sqlite3", "node:sqlite") */
|
|
77
|
+
readonly name: string;
|
|
78
|
+
/**
|
|
79
|
+
* Check if this driver is available in the current environment
|
|
80
|
+
*
|
|
81
|
+
* This method should:
|
|
82
|
+
* - Attempt to load/import the underlying driver
|
|
83
|
+
* - Return true if successful, false otherwise
|
|
84
|
+
* - Not throw exceptions
|
|
85
|
+
*
|
|
86
|
+
* @returns Promise resolving to availability status
|
|
87
|
+
*/
|
|
88
|
+
isAvailable(): Promise<boolean>;
|
|
89
|
+
/**
|
|
90
|
+
* Open a database connection using this driver
|
|
91
|
+
*
|
|
92
|
+
* @param path - Path to the SQLite database file
|
|
93
|
+
* @param options - Connection options (readonly, etc.)
|
|
94
|
+
* @returns Open database connection
|
|
95
|
+
* @throws Error if database cannot be opened
|
|
96
|
+
*/
|
|
97
|
+
open(path: string, options: DatabaseOptions): Database;
|
|
98
|
+
/**
|
|
99
|
+
* Backup a database to another file
|
|
100
|
+
*
|
|
101
|
+
* Uses the native SQLite backup API for consistent snapshots even
|
|
102
|
+
* while the source database is being written to.
|
|
103
|
+
*
|
|
104
|
+
* @param sourcePath - Path to the source database file
|
|
105
|
+
* @param destPath - Path where backup will be created
|
|
106
|
+
* @returns Promise that resolves when backup is complete
|
|
107
|
+
* @throws Error if backup fails
|
|
108
|
+
*/
|
|
109
|
+
backup(sourcePath: string, destPath: string): Promise<void>;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Driver names that can be used for manual selection
|
|
113
|
+
*/
|
|
114
|
+
export type DriverName = 'better-sqlite3' | 'node:sqlite';
|
|
115
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/database/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,+CAA+C;IAC/C,OAAO,EAAE,MAAM,CAAC;IAChB,8DAA8D;IAC9D,eAAe,EAAE,MAAM,GAAG,MAAM,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB;;;;OAIG;IACH,GAAG,CAAC,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAEnC;;;;OAIG;IACH,GAAG,CAAC,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC;IAErC;;;;OAIG;IACH,GAAG,CAAC,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,SAAS,CAAC;CACtC;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB;;;;OAIG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IAEhC;;;;;OAKG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAE1B;;;OAGG;IACH,KAAK,IAAI,IAAI,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,yDAAyD;IACzD,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,gFAAgF;IAChF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;;;;;;;OASG;IACH,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAEhC;;;;;;;OAOG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,QAAQ,CAAC;IAEvD;;;;;;;;;;OAUG;IACH,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7D;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,gBAAgB,GAAG,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/database/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core migration logic for Cursor chat history
|
|
3
|
+
*
|
|
4
|
+
* This module provides session-level migration as the core primitive.
|
|
5
|
+
* Workspace-level migration is built on top of session migration.
|
|
6
|
+
*/
|
|
7
|
+
import type { MigrateSessionOptions, MigrateWorkspaceOptions, SessionMigrationResult, WorkspaceMigrationResult } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Migrate a single session from its current workspace to a destination workspace.
|
|
10
|
+
*
|
|
11
|
+
* This is the core primitive for all migration operations.
|
|
12
|
+
* Move mode: removes session from source, adds to destination.
|
|
13
|
+
* Copy mode: duplicates session to destination, keeps source intact.
|
|
14
|
+
*
|
|
15
|
+
* @param sessionId - The session ID to migrate
|
|
16
|
+
* @param options - Migration options
|
|
17
|
+
* @returns Migration result for this session
|
|
18
|
+
*/
|
|
19
|
+
export declare function migrateSession(sessionId: string, options: Omit<MigrateSessionOptions, 'sessionIds'>): Promise<SessionMigrationResult>;
|
|
20
|
+
/**
|
|
21
|
+
* Migrate multiple sessions to a destination workspace.
|
|
22
|
+
*
|
|
23
|
+
* Handles batch migration with partial failure support.
|
|
24
|
+
* Each session is migrated independently - failures don't stop the batch.
|
|
25
|
+
*
|
|
26
|
+
* @param options - Migration options including session IDs
|
|
27
|
+
* @returns Array of results for each session
|
|
28
|
+
*/
|
|
29
|
+
export declare function migrateSessions(options: MigrateSessionOptions): Promise<SessionMigrationResult[]>;
|
|
30
|
+
/**
|
|
31
|
+
* Migrate all sessions from one workspace to another.
|
|
32
|
+
*
|
|
33
|
+
* This is a convenience wrapper that finds all sessions in the source workspace
|
|
34
|
+
* and calls migrateSession for each one.
|
|
35
|
+
*
|
|
36
|
+
* @param options - Workspace migration options
|
|
37
|
+
* @returns Aggregate result with per-session details
|
|
38
|
+
*/
|
|
39
|
+
export declare function migrateWorkspace(options: MigrateWorkspaceOptions): Promise<WorkspaceMigrationResult>;
|
|
40
|
+
//# sourceMappingURL=migrate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../src/core/migrate.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAsBH,OAAO,KAAK,EACV,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,wBAAwB,EACzB,MAAM,YAAY,CAAC;AA+apB;;;;;;;;;;GAUG;AACH,wBAAsB,cAAc,CAClC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,IAAI,CAAC,qBAAqB,EAAE,YAAY,CAAC,GACjD,OAAO,CAAC,sBAAsB,CAAC,CA+IjC;AAED;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,sBAAsB,EAAE,CAAC,CAuBvG;AAED;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAoF1G"}
|