opencode-github-sync 3.1.1 → 3.3.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.
- package/README.md +535 -220
- package/README.zh-CN.md +387 -197
- package/dist/cli/app.d.ts +39 -0
- package/dist/cli/app.d.ts.map +1 -0
- package/dist/cli/app.js +179 -0
- package/dist/cli/app.js.map +1 -0
- package/dist/cli/args.d.ts +10 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +39 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/i18n.d.ts +378 -0
- package/dist/cli/i18n.d.ts.map +1 -0
- package/dist/cli/i18n.js +793 -0
- package/dist/cli/i18n.js.map +1 -0
- package/dist/cli/index.js +362 -115
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/menu.d.ts +52 -0
- package/dist/cli/menu.d.ts.map +1 -0
- package/dist/cli/menu.js +1126 -0
- package/dist/cli/menu.js.map +1 -0
- package/dist/cli/render.d.ts +3 -0
- package/dist/cli/render.d.ts.map +1 -1
- package/dist/cli/render.js +6 -1
- package/dist/cli/render.js.map +1 -1
- package/dist/cli/ui.d.ts +62 -0
- package/dist/cli/ui.d.ts.map +1 -0
- package/dist/cli/ui.js +383 -0
- package/dist/cli/ui.js.map +1 -0
- package/dist/core/autosync.d.ts +136 -0
- package/dist/core/autosync.d.ts.map +1 -0
- package/dist/core/autosync.js +516 -0
- package/dist/core/autosync.js.map +1 -0
- package/dist/core/bundle.d.ts +11 -0
- package/dist/core/bundle.d.ts.map +1 -0
- package/dist/core/bundle.js +87 -0
- package/dist/core/bundle.js.map +1 -0
- package/dist/core/categories.d.ts +37 -0
- package/dist/core/categories.d.ts.map +1 -0
- package/dist/core/categories.js +115 -0
- package/dist/core/categories.js.map +1 -0
- package/dist/core/compare.d.ts +21 -0
- package/dist/core/compare.d.ts.map +1 -0
- package/dist/core/compare.js +124 -0
- package/dist/core/compare.js.map +1 -0
- package/dist/core/credentials.d.ts +40 -0
- package/dist/core/credentials.d.ts.map +1 -0
- package/dist/core/credentials.js +364 -0
- package/dist/core/credentials.js.map +1 -0
- package/dist/core/env.d.ts +16 -0
- package/dist/core/env.d.ts.map +1 -0
- package/dist/core/env.js +47 -0
- package/dist/core/env.js.map +1 -0
- package/dist/core/fsx.d.ts +2 -0
- package/dist/core/fsx.d.ts.map +1 -1
- package/dist/core/fsx.js +6 -0
- package/dist/core/fsx.js.map +1 -1
- package/dist/core/git.d.ts +6 -0
- package/dist/core/git.d.ts.map +1 -1
- package/dist/core/git.js +44 -4
- package/dist/core/git.js.map +1 -1
- package/dist/core/guard.d.ts +36 -0
- package/dist/core/guard.d.ts.map +1 -0
- package/dist/core/guard.js +65 -0
- package/dist/core/guard.js.map +1 -0
- package/dist/core/history.d.ts +38 -0
- package/dist/core/history.d.ts.map +1 -0
- package/dist/core/history.js +98 -0
- package/dist/core/history.js.map +1 -0
- package/dist/core/index.d.ts +11 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +11 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/lease.d.ts +52 -0
- package/dist/core/lease.d.ts.map +1 -0
- package/dist/core/lease.js +235 -0
- package/dist/core/lease.js.map +1 -0
- package/dist/core/notify.d.ts +9 -0
- package/dist/core/notify.d.ts.map +1 -0
- package/dist/core/notify.js +69 -0
- package/dist/core/notify.js.map +1 -0
- package/dist/core/projects.d.ts +79 -0
- package/dist/core/projects.d.ts.map +1 -0
- package/dist/core/projects.js +192 -0
- package/dist/core/projects.js.map +1 -0
- package/dist/core/recovery.d.ts +26 -0
- package/dist/core/recovery.d.ts.map +1 -0
- package/dist/core/recovery.js +56 -0
- package/dist/core/recovery.js.map +1 -0
- package/dist/core/repair.d.ts +44 -0
- package/dist/core/repair.d.ts.map +1 -0
- package/dist/core/repair.js +81 -0
- package/dist/core/repair.js.map +1 -0
- package/dist/core/repo.d.ts +34 -2
- package/dist/core/repo.d.ts.map +1 -1
- package/dist/core/repo.js +87 -5
- package/dist/core/repo.js.map +1 -1
- package/dist/core/rows.d.ts +36 -0
- package/dist/core/rows.d.ts.map +1 -0
- package/dist/core/rows.js +75 -0
- package/dist/core/rows.js.map +1 -0
- package/dist/core/scheduler.d.ts +138 -0
- package/dist/core/scheduler.d.ts.map +1 -0
- package/dist/core/scheduler.js +531 -0
- package/dist/core/scheduler.js.map +1 -0
- package/dist/core/sessions.d.ts +32 -4
- package/dist/core/sessions.d.ts.map +1 -1
- package/dist/core/sessions.js +316 -104
- package/dist/core/sessions.js.map +1 -1
- package/dist/core/settings.d.ts +67 -0
- package/dist/core/settings.d.ts.map +1 -1
- package/dist/core/settings.js +45 -2
- package/dist/core/settings.js.map +1 -1
- package/dist/core/setup.d.ts +20 -0
- package/dist/core/setup.d.ts.map +1 -1
- package/dist/core/setup.js +87 -4
- package/dist/core/setup.js.map +1 -1
- package/dist/core/sqlite.d.ts +2 -0
- package/dist/core/sqlite.d.ts.map +1 -1
- package/dist/core/sqlite.js +14 -0
- package/dist/core/sqlite.js.map +1 -1
- package/dist/core/stage.d.ts +18 -0
- package/dist/core/stage.d.ts.map +1 -1
- package/dist/core/stage.js +133 -4
- package/dist/core/stage.js.map +1 -1
- package/dist/core/sync.d.ts +25 -0
- package/dist/core/sync.d.ts.map +1 -1
- package/dist/core/sync.js +283 -43
- package/dist/core/sync.js.map +1 -1
- package/dist/core/update.d.ts +21 -0
- package/dist/core/update.d.ts.map +1 -0
- package/dist/core/update.js +75 -0
- package/dist/core/update.js.map +1 -0
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +6 -5
- package/dist/plugin/index.js.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recovery.d.ts","sourceRoot":"","sources":["../../src/core/recovery.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC;;;;;;;;GAQG;AAEH,eAAO,MAAM,YAAY,2BAA2B,CAAC;AAErD,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAEjD;AAED,MAAM,WAAW,aAAa;IAC5B,gDAAgD;IAChD,MAAM,EAAE,MAAM,CAAC;IACf,qDAAqD;IACrD,GAAG,EAAE,MAAM,CAAC;CACb;AAMD;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,aAAa,EAAE,EACxB,GAAG,OAAa,GACf,MAAM,GAAG,SAAS,CAkBpB;AAED,sCAAsC;AACtC,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,EAAE,CASnD"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
/**
|
|
4
|
+
* Recovery copies.
|
|
5
|
+
*
|
|
6
|
+
* Whenever this tool is about to replace bytes the user may still want — a
|
|
7
|
+
* forced pull, a "repository wins" first link, a file restored from history —
|
|
8
|
+
* the current version is copied here first. The directory lives under the data
|
|
9
|
+
* root, which is never mirrored into the repository as a whole, so recovery
|
|
10
|
+
* copies stay on this machine.
|
|
11
|
+
*/
|
|
12
|
+
export const RECOVERY_DIR = "opencode-sync-recovery";
|
|
13
|
+
export function recoveryRoot(roots) {
|
|
14
|
+
return path.join(roots.data, RECOVERY_DIR);
|
|
15
|
+
}
|
|
16
|
+
function stamp(now) {
|
|
17
|
+
return now.toISOString().replace(/[:.]/g, "-").replace("Z", "");
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Copy files into a fresh recovery folder. Missing sources are skipped.
|
|
21
|
+
* Returns the folder, or `undefined` when nothing needed saving.
|
|
22
|
+
*/
|
|
23
|
+
export function saveToRecovery(roots, label, entries, now = new Date()) {
|
|
24
|
+
const existing = entries.filter((e) => {
|
|
25
|
+
try {
|
|
26
|
+
return fs.statSync(e.source).isFile();
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
if (existing.length === 0)
|
|
33
|
+
return undefined;
|
|
34
|
+
const safeLabel = label.replace(/[^A-Za-z0-9._-]+/g, "-");
|
|
35
|
+
const dir = path.join(recoveryRoot(roots), `${stamp(now)}-${safeLabel}`);
|
|
36
|
+
for (const entry of existing) {
|
|
37
|
+
const rel = entry.rel.replace(/^[A-Za-z]:/, "").replace(/^[\\/]+/, "");
|
|
38
|
+
const target = path.join(dir, rel);
|
|
39
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
40
|
+
fs.copyFileSync(entry.source, target);
|
|
41
|
+
}
|
|
42
|
+
return dir;
|
|
43
|
+
}
|
|
44
|
+
/** Recovery folders, newest first. */
|
|
45
|
+
export function listRecovery(roots) {
|
|
46
|
+
const root = recoveryRoot(roots);
|
|
47
|
+
if (!fs.existsSync(root))
|
|
48
|
+
return [];
|
|
49
|
+
return fs
|
|
50
|
+
.readdirSync(root, { withFileTypes: true })
|
|
51
|
+
.filter((d) => d.isDirectory())
|
|
52
|
+
.map((d) => path.join(root, d.name))
|
|
53
|
+
.sort()
|
|
54
|
+
.reverse();
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=recovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recovery.js","sourceRoot":"","sources":["../../src/core/recovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B;;;;;;;;GAQG;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG,wBAAwB,CAAC;AAErD,MAAM,UAAU,YAAY,CAAC,KAAY;IACvC,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;AAC7C,CAAC;AASD,SAAS,KAAK,CAAC,GAAS;IACtB,OAAO,GAAG,CAAC,WAAW,EAAE,CA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AAG,CAAC;AACb,CAAC;AAED,sCAAsC;AACtC,MAAM,UAAU,YAAY,CAAC,KAAY;IACvC,MAAM,IAAI,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,CAAC;IACpC,OAAO,EAAE;SACN,WAAW,CAAC,IAAI,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;SAC1C,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;SAC9B,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;SACnC,IAAI,EAAE;SACN,OAAO,EAAE,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Move OpenCode 2 sessions into the project OpenCode 2 resolves for them.
|
|
3
|
+
*
|
|
4
|
+
* OpenCode 2 lists only the current project's sessions. Two kinds of session
|
|
5
|
+
* end up listed nowhere after an upgrade from 1.x, although their content is
|
|
6
|
+
* intact:
|
|
7
|
+
*
|
|
8
|
+
* - OpenCode 1 put every session outside a repository in the synthetic
|
|
9
|
+
* `global` project. OpenCode 2 gives such a directory its own project, so
|
|
10
|
+
* migrated `global` sessions are invisible.
|
|
11
|
+
* - A repository can have several project rows for one worktree (a new id
|
|
12
|
+
* after its history changed). OpenCode 2 uses the newest; sessions under
|
|
13
|
+
* the older rows are invisible.
|
|
14
|
+
*
|
|
15
|
+
* Only the project, directory spelling and relative path of a session change.
|
|
16
|
+
* Sessions already in the right project are not touched. A `global` session
|
|
17
|
+
* whose directory has no project yet is parked in the home project; any other
|
|
18
|
+
* unresolved session is left alone and reported. No project rows are created:
|
|
19
|
+
* OpenCode creates them itself the first time it opens a directory.
|
|
20
|
+
*/
|
|
21
|
+
export interface RepairMove {
|
|
22
|
+
id: string;
|
|
23
|
+
from: string;
|
|
24
|
+
to: string;
|
|
25
|
+
parked: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface RepairResult {
|
|
28
|
+
/** False when the database is not an OpenCode 2 database. */
|
|
29
|
+
supported: boolean;
|
|
30
|
+
sessions: number;
|
|
31
|
+
moves: RepairMove[];
|
|
32
|
+
/** `global` sessions with no project to move to, by directory. */
|
|
33
|
+
unresolved: {
|
|
34
|
+
directory: string;
|
|
35
|
+
count: number;
|
|
36
|
+
}[];
|
|
37
|
+
applied: number;
|
|
38
|
+
}
|
|
39
|
+
export interface RepairOptions {
|
|
40
|
+
apply: boolean;
|
|
41
|
+
home?: string;
|
|
42
|
+
}
|
|
43
|
+
export declare function repairSessions(databaseFile: string, options: RepairOptions): Promise<RepairResult>;
|
|
44
|
+
//# sourceMappingURL=repair.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repair.d.ts","sourceRoot":"","sources":["../../src/core/repair.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IAC3B,6DAA6D;IAC7D,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,kEAAkE;IAClE,UAAU,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACnD,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,wBAAsB,cAAc,CAClC,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,YAAY,CAAC,CA2EvB"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { GLOBAL_PROJECT_ID, ProjectResolver, homeDir } from "./projects.js";
|
|
3
|
+
import { readRows } from "./rows.js";
|
|
4
|
+
import { hasTable, openDatabase } from "./sqlite.js";
|
|
5
|
+
export async function repairSessions(databaseFile, options) {
|
|
6
|
+
const result = {
|
|
7
|
+
supported: false,
|
|
8
|
+
sessions: 0,
|
|
9
|
+
moves: [],
|
|
10
|
+
unresolved: [],
|
|
11
|
+
applied: 0,
|
|
12
|
+
};
|
|
13
|
+
if (!fs.existsSync(databaseFile))
|
|
14
|
+
return result;
|
|
15
|
+
const db = await openDatabase(databaseFile, { readOnly: !options.apply });
|
|
16
|
+
try {
|
|
17
|
+
if (!hasTable(db, "session_v2"))
|
|
18
|
+
return result;
|
|
19
|
+
result.supported = true;
|
|
20
|
+
const resolver = new ProjectResolver(db, {
|
|
21
|
+
home: options.home ?? homeDir(),
|
|
22
|
+
createProjects: false,
|
|
23
|
+
now: Date.now(),
|
|
24
|
+
});
|
|
25
|
+
const sessions = readRows(db, "SELECT id, project_id, directory, path FROM session_v2");
|
|
26
|
+
result.sessions = sessions.length;
|
|
27
|
+
const updates = [];
|
|
28
|
+
const unresolved = new Map();
|
|
29
|
+
for (const row of sessions) {
|
|
30
|
+
const current = String(row.project_id ?? "");
|
|
31
|
+
const directory = String(row.directory ?? "");
|
|
32
|
+
const resolved = resolver.resolve(directory);
|
|
33
|
+
// Neither placed by a project here nor invisible: leave it as it is.
|
|
34
|
+
if (!resolved && current !== GLOBAL_PROJECT_ID)
|
|
35
|
+
continue;
|
|
36
|
+
if (resolved && resolved.id === current)
|
|
37
|
+
continue;
|
|
38
|
+
const placement = resolver.place({
|
|
39
|
+
directory,
|
|
40
|
+
projectId: current,
|
|
41
|
+
path: row.path == null ? null : String(row.path),
|
|
42
|
+
});
|
|
43
|
+
if (placement.projectId === current) {
|
|
44
|
+
unresolved.set(directory, (unresolved.get(directory) ?? 0) + 1);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
result.moves.push({
|
|
48
|
+
id: String(row.id),
|
|
49
|
+
from: current,
|
|
50
|
+
to: placement.projectId,
|
|
51
|
+
parked: placement.parked,
|
|
52
|
+
});
|
|
53
|
+
updates.push({
|
|
54
|
+
id: String(row.id),
|
|
55
|
+
project: placement.projectId,
|
|
56
|
+
directory: placement.directory,
|
|
57
|
+
path: placement.path,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
result.unresolved = [...unresolved].map(([directory, count]) => ({ directory, count }));
|
|
61
|
+
if (options.apply && updates.length > 0) {
|
|
62
|
+
const statement = db.prepare("UPDATE session_v2 SET project_id = ?, directory = ?, path = ? WHERE id = ?");
|
|
63
|
+
db.exec("BEGIN IMMEDIATE");
|
|
64
|
+
try {
|
|
65
|
+
for (const u of updates)
|
|
66
|
+
statement.run(u.project, u.directory, u.path, u.id);
|
|
67
|
+
db.exec("COMMIT");
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
db.exec("ROLLBACK");
|
|
71
|
+
throw err;
|
|
72
|
+
}
|
|
73
|
+
result.applied = updates.length;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
db.close();
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=repair.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repair.js","sourceRoot":"","sources":["../../src/core/repair.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,QAA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K,EAAE,CAAC,CAAC,CAAC;QAExF,IAAI,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACxC,MAAM,SAAS,GAAG,EAAE,CAAC,OAAO,CAC1B,4EAA4E,CAC7E,CAAC;YACF,EAAE,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;YAC3B,IAAI,CAAC;gBACH,KAAK,MAAM,CAAC,IAAI,OAAO;oBAAE,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;gBAC7E,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACpB,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;gBACpB,MAAM,GAAG,CAAC;YACZ,CAAC;YACD,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;QAClC,CAAC;IACH,CAAC;YAAS,CAAC;QACT,EAAE,CAAC,KAAK,EAAE,CAAC;IACb,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/core/repo.d.ts
CHANGED
|
@@ -7,8 +7,26 @@
|
|
|
7
7
|
* represented instead by the shards in `_sessions/`
|
|
8
8
|
* - caches, logs and OS junk
|
|
9
9
|
*/
|
|
10
|
-
export declare const DEFAULT_GITIGNORE = "# opencode-github-sync \u2014 machine-local, never committed\nopencode-sync.jsonc\nopencode-sync.overrides.jsonc\n.opencode-sync.lock\n\n# Runtime / generated\nnode_modules/\nbun.lock\nlogs/\n**/__pycache__/\n*.pyc\n\n# Session storage lives in _sessions/ as portable shards.\n# The raw database is far too large for git and cannot be merged.\n_data/opencode.db\n_data/opencode.db-shm\n_data/opencode.db-wal\n_data/bin/\n_data/log/\n_data/tool-output/\n_data/snapshot/\n_data/storage/session\n_data/storage/session_diff\n\n# Machine-local UI state\n_state/session.json\n\n# Empty directories recreated by OpenCode at runtime\nplugin/\n\n# OS files\n.DS_Store\nThumbs.db\ndesktop.ini\n";
|
|
11
|
-
export declare const DEFAULT_GITATTRIBUTES = "# Store and check out everything with LF.\n# \"text=auto\" alone would rewrite files to CRLF on Windows, which silently\n# breaks shell scripts shipped inside skills and makes every cross-platform\n# pull look like a whole-file change.\n* text=auto eol=lf\n\n#
|
|
10
|
+
export declare const DEFAULT_GITIGNORE = "# opencode-github-sync \u2014 machine-local, never committed\nopencode-sync.jsonc\nopencode-sync.overrides.jsonc\n.opencode-sync.lock\n\n# Runtime / generated\nnode_modules/\nbun.lock\nlogs/\n**/__pycache__/\n*.pyc\n\n# Session storage lives in _sessions/ as portable shards.\n# The raw database is far too large for git and cannot be merged.\n_data/opencode.db\n_data/opencode.db-shm\n_data/opencode.db-wal\n_data/bin/\n_data/log/\n_data/tool-output/\n_data/snapshot/\n_data/storage/session\n_data/storage/session_diff\n\n# Machine-local UI state and the autosync runtime state\n_state/session.json\n_state/opencode-sync-autosync.json\n_state/opencode-sync-autosync.json.tmp\n\n# OpenCode 2 machine files: the background-service record (URL, pid and a\n# plaintext password, in both the config and the state directory), lock files\n# and per-machine histories\n/service.json\n_state/service.json\n_state/locks/\n_state/prompt-history.jsonl\n_state/frecency.jsonl\n\n# Empty directories recreated by OpenCode at runtime\nplugin/\n\n# OS files\n.DS_Store\nThumbs.db\ndesktop.ini\n";
|
|
11
|
+
export declare const DEFAULT_GITATTRIBUTES = "# Store and check out everything with LF.\n# \"text=auto\" alone would rewrite files to CRLF on Windows, which silently\n# breaks shell scripts shipped inside skills and makes every cross-platform\n# pull look like a whole-file change.\n* text=auto eol=lf\n\n# Session shards are gzipped JSON \u2014 binary, and never line-merged\n_sessions/*.json.gz binary\n";
|
|
12
|
+
/**
|
|
13
|
+
* Files an older version could have committed that must never be tracked:
|
|
14
|
+
* machine secrets and per-machine histories. They are dropped from the index
|
|
15
|
+
* (never from disk) on every push, so upgrading cleans existing repositories.
|
|
16
|
+
*/
|
|
17
|
+
export declare const UNTRACKED_MACHINE_FILES: string[];
|
|
18
|
+
/** Remove machine files from the index if a previous version committed them. */
|
|
19
|
+
export declare function untrackMachineFiles(root: string): void;
|
|
20
|
+
/**
|
|
21
|
+
* Keep this machine's config-dir `service.json` exactly as it is across a sync.
|
|
22
|
+
*
|
|
23
|
+
* Git treats ignored files as expendable: a reset, fast-forward or rebase onto
|
|
24
|
+
* a commit that still tracks `service.json` (pushed by an older version)
|
|
25
|
+
* overwrites the local file, and replaying the commit that untracks it then
|
|
26
|
+
* deletes it. Returns the function that puts the original back, or removes
|
|
27
|
+
* another machine's copy when this machine had none.
|
|
28
|
+
*/
|
|
29
|
+
export declare function holdMachineFiles(root: string): () => void;
|
|
12
30
|
/**
|
|
13
31
|
* Paths that exist inside the worktree but must stay out of every commit.
|
|
14
32
|
*
|
|
@@ -25,6 +43,15 @@ export interface EnsureRepoOptions {
|
|
|
25
43
|
root: string;
|
|
26
44
|
remote: string;
|
|
27
45
|
branch: string;
|
|
46
|
+
/**
|
|
47
|
+
* How an existing remote history is adopted by a directory that is not yet
|
|
48
|
+
* a repository. `remote` (default) checks the remote files out over the
|
|
49
|
+
* local ones; `local` keeps every local file and only moves the branch, so
|
|
50
|
+
* the next commit records this machine's state on top of the remote.
|
|
51
|
+
*/
|
|
52
|
+
adopt?: "remote" | "local";
|
|
53
|
+
/** Called before `remote` adoption overwrites the worktree. */
|
|
54
|
+
beforeAdopt?: (root: string, ref: string) => void;
|
|
28
55
|
}
|
|
29
56
|
export type RepoState = "ready" | "adopted" | "fresh";
|
|
30
57
|
/** Configure identity and metadata files. Safe to call repeatedly. */
|
|
@@ -56,6 +83,11 @@ export declare const REPO_DIRS: {
|
|
|
56
83
|
};
|
|
57
84
|
export declare function headCommit(root: string): string | undefined;
|
|
58
85
|
export declare function readStageOutMark(root: string): string | undefined;
|
|
86
|
+
/**
|
|
87
|
+
* When the real directories last matched the repository, in epoch ms; 0 when
|
|
88
|
+
* unknown. Any untracked file newer than this is a local edit.
|
|
89
|
+
*/
|
|
90
|
+
export declare function readStageOutMarkTime(root: string): number;
|
|
59
91
|
/** Record that the real directories now match HEAD. */
|
|
60
92
|
export declare function writeStageOutMark(root: string): void;
|
|
61
93
|
//# sourceMappingURL=repo.d.ts.map
|
package/dist/core/repo.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repo.d.ts","sourceRoot":"","sources":["../../src/core/repo.ts"],"names":[],"mappings":"AAOA;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"repo.d.ts","sourceRoot":"","sources":["../../src/core/repo.ts"],"names":[],"mappings":"AAOA;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,4jCA6C7B,CAAC;AAEF,eAAO,MAAM,qBAAqB,4WAQjC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,UAMnC,CAAC;AAEF,gFAAgF;AAChF,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAatD;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,IAAI,CAmBzD;AAED;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,UAQ/B,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAM7D;AAED,wBAAgB,gBAAgB,IAAI,MAAM,EAAE,CAE3C;AAED,qFAAqF;AACrF,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAE3D;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,KAAK,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC;IAC3B,+DAA+D;IAC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|
40
|
-
# Machine-local UI state
|
|
40
|
+
# Machine-local UI state and the autosync runtime state
|
|
41
41
|
${STATE_DIR}/session.json
|
|
42
|
+
${STATE_DIR}/opencode-sync-autosync.json
|
|
43
|
+
${STATE_DIR}/opencode-sync-autosync.json.tmp
|
|
44
|
+
|
|
45
|
+
# OpenCode 2 machine files: the background-service record (URL, pid and a
|
|
46
|
+
# plaintext password, in both the config and the state directory), lock files
|
|
47
|
+
# and per-machine histories
|
|
48
|
+
/service.json
|
|
49
|
+
${STATE_DIR}/service.json
|
|
50
|
+
${STATE_DIR}/locks/
|
|
51
|
+
${STATE_DIR}/prompt-history.jsonl
|
|
52
|
+
${STATE_DIR}/frecency.jsonl
|
|
42
53
|
|
|
43
54
|
# Empty directories recreated by OpenCode at runtime
|
|
44
55
|
plugin/
|
|
@@ -54,12 +65,65 @@ export const DEFAULT_GITATTRIBUTES = `# Store and check out everything with LF.
|
|
|
54
65
|
# pull look like a whole-file change.
|
|
55
66
|
* text=auto eol=lf
|
|
56
67
|
|
|
57
|
-
# Append-only history files merge cleanly by taking both sides
|
|
58
|
-
${STATE_DIR}/prompt-history.jsonl text eol=lf merge=union
|
|
59
|
-
|
|
60
68
|
# Session shards are gzipped JSON — binary, and never line-merged
|
|
61
69
|
${SESSIONS_DIR}/*.json.gz binary
|
|
62
70
|
`;
|
|
71
|
+
/**
|
|
72
|
+
* Files an older version could have committed that must never be tracked:
|
|
73
|
+
* machine secrets and per-machine histories. They are dropped from the index
|
|
74
|
+
* (never from disk) on every push, so upgrading cleans existing repositories.
|
|
75
|
+
*/
|
|
76
|
+
export const UNTRACKED_MACHINE_FILES = [
|
|
77
|
+
"service.json",
|
|
78
|
+
`${STATE_DIR}/service.json`,
|
|
79
|
+
`${STATE_DIR}/locks`,
|
|
80
|
+
`${STATE_DIR}/prompt-history.jsonl`,
|
|
81
|
+
`${STATE_DIR}/frecency.jsonl`,
|
|
82
|
+
];
|
|
83
|
+
/** Remove machine files from the index if a previous version committed them. */
|
|
84
|
+
export function untrackMachineFiles(root) {
|
|
85
|
+
git([
|
|
86
|
+
"rm",
|
|
87
|
+
"-r",
|
|
88
|
+
"-q",
|
|
89
|
+
"--cached",
|
|
90
|
+
"--ignore-unmatch",
|
|
91
|
+
"--",
|
|
92
|
+
...UNTRACKED_MACHINE_FILES.map((p) => `:(top,literal)${p}`),
|
|
93
|
+
], { cwd: root });
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Keep this machine's config-dir `service.json` exactly as it is across a sync.
|
|
97
|
+
*
|
|
98
|
+
* Git treats ignored files as expendable: a reset, fast-forward or rebase onto
|
|
99
|
+
* a commit that still tracks `service.json` (pushed by an older version)
|
|
100
|
+
* overwrites the local file, and replaying the commit that untracks it then
|
|
101
|
+
* deletes it. Returns the function that puts the original back, or removes
|
|
102
|
+
* another machine's copy when this machine had none.
|
|
103
|
+
*/
|
|
104
|
+
export function holdMachineFiles(root) {
|
|
105
|
+
const file = path.join(root, "service.json");
|
|
106
|
+
let original;
|
|
107
|
+
try {
|
|
108
|
+
original = fs.readFileSync(file);
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
original = undefined;
|
|
112
|
+
}
|
|
113
|
+
return () => {
|
|
114
|
+
try {
|
|
115
|
+
if (original === undefined) {
|
|
116
|
+
fs.rmSync(file, { force: true });
|
|
117
|
+
}
|
|
118
|
+
else if (!fs.existsSync(file) || !fs.readFileSync(file).equals(original)) {
|
|
119
|
+
fs.writeFileSync(file, original, { mode: 0o600 });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
// Best effort: OpenCode recreates its service record on start.
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
63
127
|
/**
|
|
64
128
|
* Paths that exist inside the worktree but must stay out of every commit.
|
|
65
129
|
*
|
|
@@ -128,7 +192,13 @@ export function initRepo(options) {
|
|
|
128
192
|
ensureGitIdentity(root);
|
|
129
193
|
const fetched = git(["fetch", "origin", branch], { cwd: root });
|
|
130
194
|
if (fetched.ok && git(["rev-parse", `origin/${branch}`], { cwd: root }).ok) {
|
|
131
|
-
|
|
195
|
+
if (options.adopt === "local") {
|
|
196
|
+
git(["reset", "-q", `origin/${branch}`], { cwd: root });
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
options.beforeAdopt?.(root, `origin/${branch}`);
|
|
200
|
+
git(["reset", "--hard", `origin/${branch}`], { cwd: root });
|
|
201
|
+
}
|
|
132
202
|
git(["branch", `--set-upstream-to=origin/${branch}`, branch], { cwd: root });
|
|
133
203
|
return "adopted";
|
|
134
204
|
}
|
|
@@ -207,6 +277,18 @@ export function readStageOutMark(root) {
|
|
|
207
277
|
return undefined;
|
|
208
278
|
}
|
|
209
279
|
}
|
|
280
|
+
/**
|
|
281
|
+
* When the real directories last matched the repository, in epoch ms; 0 when
|
|
282
|
+
* unknown. Any untracked file newer than this is a local edit.
|
|
283
|
+
*/
|
|
284
|
+
export function readStageOutMarkTime(root) {
|
|
285
|
+
try {
|
|
286
|
+
return fs.statSync(stageOutMarkPath(root)).mtimeMs;
|
|
287
|
+
}
|
|
288
|
+
catch {
|
|
289
|
+
return 0;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
210
292
|
/** Record that the real directories now match HEAD. */
|
|
211
293
|
export function writeStageOutMark(root) {
|
|
212
294
|
const head = headCommit(root);
|
package/dist/core/repo.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repo.js","sourceRoot":"","sources":["../../src/core/repo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,EAAkB,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,SAA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AAG,UAAU,CAAC,IAAI,CAAC,CAAC;IAC9B,IAAI,CAAC,IAAI;QAAE,OAAO;IAClB,IAAI,CAAC;QACH,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACxE,EAAE,CAAC,aAAa,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,IAAI,CAAC,CAAC;IACxD,CAAC;IAAC,MAAM,CAAC;QACP,oEAAoE;IACtE,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { SqliteDatabase } from "./sqlite.js";
|
|
2
|
+
/**
|
|
3
|
+
* Row-level helpers shared by the session exporters and importers.
|
|
4
|
+
*
|
|
5
|
+
* Shards are JSON, so binary columns (OpenCode 2 stores attachments in
|
|
6
|
+
* `blob.data`) are written as `{ "$base64": "..." }` and turned back into
|
|
7
|
+
* bytes on import.
|
|
8
|
+
*/
|
|
9
|
+
export type Row = Record<string, unknown>;
|
|
10
|
+
export interface TableInfo {
|
|
11
|
+
columns: Set<string>;
|
|
12
|
+
primaryKey: string[];
|
|
13
|
+
}
|
|
14
|
+
export declare function readRows(db: SqliteDatabase, sql: string, params?: unknown[]): Row[];
|
|
15
|
+
/** Cached column and key information per table for one connection. */
|
|
16
|
+
export declare function tableInfoCache(db: SqliteDatabase): (table: string) => TableInfo;
|
|
17
|
+
/** Make a row JSON-safe: binary values become `{ $base64 }`. */
|
|
18
|
+
export declare function encodeRow(row: Row): Row;
|
|
19
|
+
/** SQLite drivers accept null/number/string/bigint/Buffer only. */
|
|
20
|
+
export declare function normalize(value: unknown): unknown;
|
|
21
|
+
/**
|
|
22
|
+
* Insert a row, or update the existing one in place.
|
|
23
|
+
*
|
|
24
|
+
* This must be a true UPSERT, never `INSERT OR REPLACE`: REPLACE deletes the
|
|
25
|
+
* conflicting row before inserting, and with foreign keys enforced (node:sqlite
|
|
26
|
+
* enables them) deleting the shared `project` row cascades through
|
|
27
|
+
* `session.project_id ON DELETE CASCADE` and silently removes every session
|
|
28
|
+
* imported before it (#2).
|
|
29
|
+
*
|
|
30
|
+
* Primary-key columns are never rewritten, so composite keys such as
|
|
31
|
+
* `todo (session_id, position)` stay intact. A row that is newer locally, by
|
|
32
|
+
* `time_updated`, is left alone. `keepExisting` turns the update into a no-op
|
|
33
|
+
* for rows that must stay machine-local once they exist.
|
|
34
|
+
*/
|
|
35
|
+
export declare function upsert(db: SqliteDatabase, table: string, row: Row, info: TableInfo, keepExisting?: boolean): void;
|
|
36
|
+
//# sourceMappingURL=rows.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rows.d.ts","sourceRoot":"","sources":["../../src/core/rows.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGlD;;;;;;GAMG;AAEH,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE1C,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACrB,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,wBAAgB,QAAQ,CAAC,EAAE,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,OAAO,EAAO,GAAG,GAAG,EAAE,CAEvF;AAED,sEAAsE;AACtE,wBAAgB,cAAc,CAAC,EAAE,EAAE,cAAc,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,SAAS,CAU/E;AAED,gEAAgE;AAChE,wBAAgB,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,CAOvC;AAED,mEAAmE;AACnE,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAWjD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,MAAM,CACpB,EAAE,EAAE,cAAc,EAClB,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,SAAS,EACf,YAAY,UAAQ,GACnB,IAAI,CAsBN"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { tableColumns, tablePrimaryKey } from "./sqlite.js";
|
|
2
|
+
export function readRows(db, sql, params = []) {
|
|
3
|
+
return db.prepare(sql).all(...params);
|
|
4
|
+
}
|
|
5
|
+
/** Cached column and key information per table for one connection. */
|
|
6
|
+
export function tableInfoCache(db) {
|
|
7
|
+
const cache = new Map();
|
|
8
|
+
return (table) => {
|
|
9
|
+
let info = cache.get(table);
|
|
10
|
+
if (!info) {
|
|
11
|
+
info = { columns: new Set(tableColumns(db, table)), primaryKey: tablePrimaryKey(db, table) };
|
|
12
|
+
cache.set(table, info);
|
|
13
|
+
}
|
|
14
|
+
return info;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/** Make a row JSON-safe: binary values become `{ $base64 }`. */
|
|
18
|
+
export function encodeRow(row) {
|
|
19
|
+
const out = {};
|
|
20
|
+
for (const [key, value] of Object.entries(row)) {
|
|
21
|
+
out[key] =
|
|
22
|
+
value instanceof Uint8Array ? { $base64: Buffer.from(value).toString("base64") } : value;
|
|
23
|
+
}
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
/** SQLite drivers accept null/number/string/bigint/Buffer only. */
|
|
27
|
+
export function normalize(value) {
|
|
28
|
+
if (value === undefined)
|
|
29
|
+
return null;
|
|
30
|
+
if (typeof value === "boolean")
|
|
31
|
+
return value ? 1 : 0;
|
|
32
|
+
if (value !== null && typeof value === "object" && !Buffer.isBuffer(value)) {
|
|
33
|
+
const encoded = value.$base64;
|
|
34
|
+
if (typeof encoded === "string" && Object.keys(value).length === 1) {
|
|
35
|
+
return Buffer.from(encoded, "base64");
|
|
36
|
+
}
|
|
37
|
+
return JSON.stringify(value);
|
|
38
|
+
}
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Insert a row, or update the existing one in place.
|
|
43
|
+
*
|
|
44
|
+
* This must be a true UPSERT, never `INSERT OR REPLACE`: REPLACE deletes the
|
|
45
|
+
* conflicting row before inserting, and with foreign keys enforced (node:sqlite
|
|
46
|
+
* enables them) deleting the shared `project` row cascades through
|
|
47
|
+
* `session.project_id ON DELETE CASCADE` and silently removes every session
|
|
48
|
+
* imported before it (#2).
|
|
49
|
+
*
|
|
50
|
+
* Primary-key columns are never rewritten, so composite keys such as
|
|
51
|
+
* `todo (session_id, position)` stay intact. A row that is newer locally, by
|
|
52
|
+
* `time_updated`, is left alone. `keepExisting` turns the update into a no-op
|
|
53
|
+
* for rows that must stay machine-local once they exist.
|
|
54
|
+
*/
|
|
55
|
+
export function upsert(db, table, row, info, keepExisting = false) {
|
|
56
|
+
const columns = Object.keys(row).filter((column) => info.columns.has(column));
|
|
57
|
+
if (columns.length === 0)
|
|
58
|
+
return;
|
|
59
|
+
const placeholders = columns.map(() => "?").join(", ");
|
|
60
|
+
const quoted = columns.map((column) => `"${column}"`).join(", ");
|
|
61
|
+
// No conflict target: the update applies to whichever uniqueness constraint
|
|
62
|
+
// fired (primary key, composite key or a secondary UNIQUE index), matching
|
|
63
|
+
// what REPLACE used to cover. Needs SQLite 3.35+, which both drivers bundle.
|
|
64
|
+
const updates = columns.filter((column) => !info.primaryKey.includes(column));
|
|
65
|
+
let action = "DO NOTHING";
|
|
66
|
+
if (!keepExisting && updates.length > 0) {
|
|
67
|
+
const assignments = updates.map((column) => `"${column}" = excluded."${column}"`).join(", ");
|
|
68
|
+
const newerWins = columns.includes("time_updated")
|
|
69
|
+
? ` WHERE "${table}"."time_updated" IS NULL OR excluded."time_updated" >= "${table}"."time_updated"`
|
|
70
|
+
: "";
|
|
71
|
+
action = `DO UPDATE SET ${assignments}${newerWins}`;
|
|
72
|
+
}
|
|
73
|
+
db.prepare(`INSERT INTO "${table}" (${quoted}) VALUES (${placeholders}) ON CONFLICT ${action}`).run(...columns.map((column) => normalize(row[column])));
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=rows.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rows.js","sourceRoot":"","sources":["../../src/core/rows.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAiB5D,MAAM,UAAU,QAAQ,CAAC,EAAkB,EAAE,GAAW,EAAE,SAAoB,EAAE;IAC9E,OAAO,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,MAAM,CAAU,CAAC;AACjD,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,cAAc,CAAC,EAAkB;IAC/C,MAAM,KAAK,GAAG,IAAI,GAAG,EAAqB,CAAC;IAC3C,OAAO,CAAC,KAAK,EAAE,EAAE;QACf,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC5B,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,IAAI,GAAG,EAAE,OAAO,EAAE,IAAI,GAAG,CAAC,YAAY,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,EAAE,UAAU,EAAE,eAAe,CAAC,EAAE,EAAE,KAAK,CAAC,EAAE,CAAC;YAC7F,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QACzB,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;AACJ,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,SAAS,CAAC,GAAQ;IAChC,MAAM,GAAG,GAAQ,EAAE,CAAC;IACpB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/C,GAAG,CAAC,GAAG,CAAC;YACN,KAAK,YAAY,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,IA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