@narumitw/pi-sync-daemon 0.9.1 → 0.10.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/CHANGELOG.md +11 -0
- package/README.md +11 -1
- package/dist/cli.js +2 -0
- package/dist/client-transport.d.ts +14 -0
- package/dist/client-transport.js +66 -0
- package/dist/client.d.ts +15 -8
- package/dist/client.js +116 -86
- package/dist/consent.js +33 -11
- package/dist/daemon-debug.d.ts +3 -0
- package/dist/daemon-debug.js +33 -0
- package/dist/daemon-recovery.d.ts +4 -0
- package/dist/daemon-recovery.js +75 -0
- package/dist/engine/backends/git/git-backend.d.ts +8 -0
- package/dist/engine/backends/git/git-backend.js +39 -12
- package/dist/engine/backends/git/git-runner.js +6 -1
- package/dist/engine/backends/git/git-storage.js +5 -9
- package/dist/engine/backends/publication-encoding.d.ts +3 -0
- package/dist/engine/backends/publication-encoding.js +19 -0
- package/dist/engine/backends/s3/s3-backend.js +10 -12
- package/dist/engine/backends/sync-backend.d.ts +4 -0
- package/dist/engine/backends/webdav/webdav-backend.d.ts +0 -2
- package/dist/engine/backends/webdav/webdav-backend.js +15 -26
- package/dist/engine/backends/webdav/webdav-client.js +10 -0
- package/dist/engine/commands/command-types.d.ts +1 -0
- package/dist/engine/debug-log.d.ts +27 -0
- package/dist/engine/debug-log.js +134 -0
- package/dist/engine/paths.d.ts +2 -0
- package/dist/engine/paths.js +7 -1
- package/dist/engine/settings/config-file.d.ts +10 -1
- package/dist/engine/settings/config-file.js +62 -17
- package/dist/engine/settings/config.d.ts +7 -0
- package/dist/engine/settings/config.js +49 -14
- package/dist/engine/snapshot/snapshot-apply.d.ts +2 -1
- package/dist/engine/snapshot/snapshot-apply.js +30 -8
- package/dist/engine/snapshot/snapshot-codec.js +3 -1
- package/dist/engine/snapshot/snapshot-payload.d.ts +4 -0
- package/dist/engine/snapshot/snapshot-payload.js +32 -0
- package/dist/engine/snapshot/snapshot-transaction-images.d.ts +2 -0
- package/dist/engine/snapshot/snapshot-transaction-images.js +34 -0
- package/dist/engine/snapshot/snapshot-transaction.d.ts +4 -1
- package/dist/engine/snapshot/snapshot-transaction.js +50 -7
- package/dist/engine/snapshot/snapshot-types.d.ts +10 -2
- package/dist/engine/snapshot/snapshot.d.ts +3 -1
- package/dist/engine/snapshot/snapshot.js +64 -25
- package/dist/engine/state/lock.d.ts +2 -1
- package/dist/engine/state/lock.js +157 -17
- package/dist/engine/sync/continuous-sync.d.ts +10 -1
- package/dist/engine/sync/continuous-sync.js +35 -11
- package/dist/engine/sync/initialization.d.ts +1 -1
- package/dist/engine/sync/initialization.js +2 -2
- package/dist/engine/sync/local-fields.d.ts +6 -1
- package/dist/engine/sync/local-fields.js +42 -19
- package/dist/engine/sync/merged-sync.js +13 -10
- package/dist/engine/sync/remote-snapshot.js +18 -3
- package/dist/engine/sync/session-push.js +13 -4
- package/dist/engine/sync/startup-bootstrap.d.ts +1 -0
- package/dist/engine/sync/startup-bootstrap.js +105 -0
- package/dist/engine/sync/startup-recovery-evidence.d.ts +1 -0
- package/dist/engine/sync/startup-recovery-evidence.js +37 -0
- package/dist/engine/sync/startup-timings.d.ts +9 -2
- package/dist/engine/sync/startup-timings.js +80 -8
- package/dist/engine/sync/sync-error-guidance.js +6 -1
- package/dist/engine/sync/sync-inspection.js +4 -7
- package/dist/engine/sync/sync-local.d.ts +2 -1
- package/dist/engine/sync/sync-local.js +3 -1
- package/dist/engine/sync/sync-mutations.js +9 -3
- package/dist/engine/sync/sync-policy.d.ts +2 -0
- package/dist/engine/sync/sync-policy.js +9 -1
- package/dist/engine/sync/sync-state.d.ts +8 -3
- package/dist/engine/sync/sync-state.js +12 -4
- package/dist/engine-service.d.ts +6 -0
- package/dist/engine-service.js +54 -10
- package/dist/identity.d.ts +5 -2
- package/dist/identity.js +36 -6
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/monitor.js +20 -1
- package/dist/paged-review.d.ts +35 -0
- package/dist/paged-review.js +177 -0
- package/dist/participant-ledger.d.ts +16 -0
- package/dist/participant-ledger.js +149 -0
- package/dist/protocol.d.ts +15 -0
- package/dist/protocol.js +4 -0
- package/dist/server.d.ts +7 -0
- package/dist/server.js +268 -120
- package/dist/service-host.d.ts +2 -1
- package/dist/service-host.js +29 -9
- package/dist/state-wait-jobs.d.ts +8 -0
- package/dist/state-wait-jobs.js +23 -0
- package/dist/state-wait.d.ts +7 -0
- package/dist/state-wait.js +34 -0
- package/docs/architecture.md +22 -0
- package/package.json +1 -1
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { closeSync, constants, fstatSync, lstatSync, openSync, realpathSync, writeSync, } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { DEBUG_LOG_FILENAME } from "./paths.js";
|
|
4
|
+
import { isStartupTimingReport } from "./sync/startup-timings.js";
|
|
5
|
+
const OPERATIONS = [
|
|
6
|
+
"initialize",
|
|
7
|
+
"inspect",
|
|
8
|
+
"status",
|
|
9
|
+
"diff",
|
|
10
|
+
"doctor",
|
|
11
|
+
"history",
|
|
12
|
+
"push",
|
|
13
|
+
"pull",
|
|
14
|
+
"sync",
|
|
15
|
+
"startup-transfer",
|
|
16
|
+
"shutdown",
|
|
17
|
+
"conflicts",
|
|
18
|
+
"rollback",
|
|
19
|
+
"unlock",
|
|
20
|
+
"migrate-state",
|
|
21
|
+
"daemon.authorize",
|
|
22
|
+
"daemon.authorize-connected",
|
|
23
|
+
"daemon.handover",
|
|
24
|
+
];
|
|
25
|
+
const OUTCOMES = ["started", "completed", "failed", "cancelled", "blocked", "skipped"];
|
|
26
|
+
const JOB_ID = /^[a-f0-9]{16}-[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/u;
|
|
27
|
+
const MAX_RECORD_BYTES = 4_096;
|
|
28
|
+
const CYCLE_REASONS = [
|
|
29
|
+
"transient",
|
|
30
|
+
"contention",
|
|
31
|
+
"stale",
|
|
32
|
+
"authentication",
|
|
33
|
+
"storage",
|
|
34
|
+
"unsafe",
|
|
35
|
+
"model",
|
|
36
|
+
"budget",
|
|
37
|
+
"unknown",
|
|
38
|
+
];
|
|
39
|
+
export function debugOperation(operation) {
|
|
40
|
+
return OPERATIONS.find((known) => known === operation);
|
|
41
|
+
}
|
|
42
|
+
function safeFields(event) {
|
|
43
|
+
switch (event.event) {
|
|
44
|
+
case "startup-timings":
|
|
45
|
+
if (typeof event.report === "string" &&
|
|
46
|
+
event.report.length <= MAX_RECORD_BYTES &&
|
|
47
|
+
isStartupTimingReport(event.report))
|
|
48
|
+
return { event: event.event, report: event.report };
|
|
49
|
+
break;
|
|
50
|
+
case "connection":
|
|
51
|
+
if (["completed", "failed", "cancelled", "skipped"].includes(event.outcome))
|
|
52
|
+
return { event: event.event, outcome: event.outcome };
|
|
53
|
+
break;
|
|
54
|
+
case "lifecycle":
|
|
55
|
+
if (["starting", "ready", "drained", "failed"].includes(event.outcome))
|
|
56
|
+
return { event: event.event, outcome: event.outcome };
|
|
57
|
+
break;
|
|
58
|
+
case "job":
|
|
59
|
+
if (debugOperation(event.operation) && OUTCOMES.includes(event.outcome))
|
|
60
|
+
return {
|
|
61
|
+
event: event.event,
|
|
62
|
+
operation: event.operation,
|
|
63
|
+
outcome: event.outcome,
|
|
64
|
+
...(typeof event.operationId === "string" && JOB_ID.test(event.operationId)
|
|
65
|
+
? { operationId: event.operationId }
|
|
66
|
+
: {}),
|
|
67
|
+
};
|
|
68
|
+
break;
|
|
69
|
+
case "continuous-cycle":
|
|
70
|
+
if (["completed", "failed", "cancelled", "blocked", "skipped"].includes(event.outcome))
|
|
71
|
+
return {
|
|
72
|
+
event: event.event,
|
|
73
|
+
outcome: event.outcome,
|
|
74
|
+
...(event.reason && CYCLE_REASONS.includes(event.reason) ? { reason: event.reason } : {}),
|
|
75
|
+
};
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function owned(stat) {
|
|
80
|
+
return process.getuid === undefined || stat.uid === BigInt(process.getuid());
|
|
81
|
+
}
|
|
82
|
+
function privateFile(stat) {
|
|
83
|
+
return (stat.isFile() && stat.nlink === 1n && owned(stat) && (process.platform === "win32" || (stat.mode & 63n) === 0n));
|
|
84
|
+
}
|
|
85
|
+
function safeRoot(stat) {
|
|
86
|
+
return stat.isDirectory() && owned(stat) && (process.platform === "win32" || (stat.mode & 18n) === 0n);
|
|
87
|
+
}
|
|
88
|
+
function sameIdentity(left, right) {
|
|
89
|
+
return left.dev === right.dev && left.ino === right.ino;
|
|
90
|
+
}
|
|
91
|
+
export function appendDebugEvent(root, source, event) {
|
|
92
|
+
try {
|
|
93
|
+
if (source !== "pi-sync" && source !== "pi-sync-daemon")
|
|
94
|
+
return false;
|
|
95
|
+
const fields = safeFields(event);
|
|
96
|
+
if (!fields)
|
|
97
|
+
return false;
|
|
98
|
+
const bytes = Buffer.from(`${JSON.stringify({ time: new Date().toISOString(), source, pid: process.pid, ...fields })}\n`);
|
|
99
|
+
if (bytes.length > MAX_RECORD_BYTES)
|
|
100
|
+
return false;
|
|
101
|
+
const directory = lstatSync(root, { bigint: true });
|
|
102
|
+
if (!safeRoot(directory) || realpathSync(root) !== root)
|
|
103
|
+
return false;
|
|
104
|
+
const target = path.join(root, DEBUG_LOG_FILENAME);
|
|
105
|
+
const previous = lstatSync(target, { bigint: true, throwIfNoEntry: false });
|
|
106
|
+
if (previous && !privateFile(previous))
|
|
107
|
+
return false;
|
|
108
|
+
const fd = openSync(target, constants.O_CREAT |
|
|
109
|
+
constants.O_WRONLY |
|
|
110
|
+
constants.O_APPEND |
|
|
111
|
+
(constants.O_NOFOLLOW ?? 0) |
|
|
112
|
+
(constants.O_NONBLOCK ?? 0), 0o600);
|
|
113
|
+
try {
|
|
114
|
+
const opened = fstatSync(fd, { bigint: true });
|
|
115
|
+
const current = lstatSync(target, { bigint: true });
|
|
116
|
+
const currentRoot = lstatSync(root, { bigint: true });
|
|
117
|
+
if (!privateFile(opened) ||
|
|
118
|
+
!privateFile(current) ||
|
|
119
|
+
!sameIdentity(opened, current) ||
|
|
120
|
+
(previous && !sameIdentity(previous, opened)) ||
|
|
121
|
+
!safeRoot(currentRoot) ||
|
|
122
|
+
!sameIdentity(directory, currentRoot) ||
|
|
123
|
+
realpathSync(root) !== root)
|
|
124
|
+
return false;
|
|
125
|
+
return writeSync(fd, bytes) === bytes.length;
|
|
126
|
+
}
|
|
127
|
+
finally {
|
|
128
|
+
closeSync(fd);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
}
|
package/dist/engine/paths.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export declare const DEBUG_LOG_FILENAME = "pi-sync.log";
|
|
2
|
+
export declare function isDebugLogPath(relativePath: string): boolean;
|
|
1
3
|
export declare function isDeniedPath(relativePath: string): boolean;
|
|
2
4
|
export declare function isPathInside(parent: string, child: string): boolean;
|
|
3
5
|
export declare function safeJoin(root: string, relativePath: string): string;
|
package/dist/engine/paths.js
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
export const DEBUG_LOG_FILENAME = "pi-sync.log";
|
|
3
|
+
export function isDebugLogPath(relativePath) {
|
|
4
|
+
const root = relativePath.split(/[/\\:]/u, 1)[0].toLowerCase();
|
|
5
|
+
return root.startsWith(DEBUG_LOG_FILENAME) && /^[ .]*$/u.test(root.slice(DEBUG_LOG_FILENAME.length));
|
|
6
|
+
}
|
|
2
7
|
export function isDeniedPath(relativePath) {
|
|
3
8
|
const normalized = toPosix(relativePath);
|
|
4
9
|
const lower = normalized.toLowerCase();
|
|
5
10
|
const segments = lower.split("/");
|
|
6
11
|
const base = path.posix.basename(lower);
|
|
7
|
-
return (
|
|
12
|
+
return (isDebugLogPath(normalized) ||
|
|
13
|
+
segments.includes("node_modules") ||
|
|
8
14
|
segments.includes(".git") ||
|
|
9
15
|
segments.includes(".pisync") ||
|
|
10
16
|
segments.includes("pi-sync") ||
|
|
@@ -28,6 +28,15 @@ export declare function consumeLocalConfigMigrationNotice(): string | undefined;
|
|
|
28
28
|
export declare function readActiveLocalConfigDocumentForRepair(): Promise<LocalConfigDocument | undefined>;
|
|
29
29
|
/** Read-only bootstrap: no authority recursion, migration, or document creation. */
|
|
30
30
|
export declare function peekLocalConfigDocument(): Promise<LocalConfigDocument | undefined>;
|
|
31
|
+
export declare function readLocalConfigForDiagnostics(root: string): Promise<{
|
|
32
|
+
document: {
|
|
33
|
+
bytes: Buffer;
|
|
34
|
+
identity: FileIdentity;
|
|
35
|
+
parsed: Record<string, unknown>;
|
|
36
|
+
path: string;
|
|
37
|
+
};
|
|
38
|
+
stillCurrent(): boolean;
|
|
39
|
+
} | undefined>;
|
|
31
40
|
export declare function withLockedLocalConfigDocument<T>(run: (document: LocalConfigDocument | undefined, recheck: () => void) => Promise<T>, signal?: AbortSignal, forWrite?: boolean, { securePermissions }?: {
|
|
32
41
|
securePermissions?: boolean;
|
|
33
42
|
}): Promise<T>;
|
|
@@ -36,5 +45,5 @@ export declare function updateLocalConfigDocument<T extends Record<string, unkno
|
|
|
36
45
|
export declare function createLocalConfigDocument(value: Record<string, unknown>, signal?: AbortSignal): Promise<void>;
|
|
37
46
|
export declare function replaceLocalConfigDocument(document: LocalConfigDocument, value: Record<string, unknown>): Promise<void>;
|
|
38
47
|
export declare function quarantineAndRemoveConfigIfMatches(filePath: string, identity: FileIdentity, expectedBytes: Buffer): Promise<boolean>;
|
|
39
|
-
export declare function withLocalConfigFileLock<T>(run: () => Promise<T
|
|
48
|
+
export declare function withLocalConfigFileLock<T>(run: () => Promise<T>, readOnly?: boolean): Promise<T>;
|
|
40
49
|
export {};
|
|
@@ -24,6 +24,9 @@ const LOCKFILE_FS_ADAPTER = {
|
|
|
24
24
|
utimesSync,
|
|
25
25
|
};
|
|
26
26
|
let configUpdateQueue = Promise.resolve();
|
|
27
|
+
let pendingMutations = 0;
|
|
28
|
+
let mutationGeneration = 0;
|
|
29
|
+
let localReadLock;
|
|
27
30
|
let publishConfigFile = publishFileWithGuard;
|
|
28
31
|
let beforeConfigPublicationHook = async () => undefined;
|
|
29
32
|
let afterMissingConfigReadProbeHook = async () => undefined;
|
|
@@ -118,6 +121,31 @@ async function peekUnlocked(maxBytes, securePermissions = true) {
|
|
|
118
121
|
const filePath = (await pathExists(canonicalPath)) ? canonicalPath : legacyLocalConfigPath();
|
|
119
122
|
return readConfigDocumentIfExists(filePath, maxBytes, securePermissions);
|
|
120
123
|
}
|
|
124
|
+
export async function readLocalConfigForDiagnostics(root) {
|
|
125
|
+
if (pendingMutations)
|
|
126
|
+
return undefined;
|
|
127
|
+
const generation = mutationGeneration;
|
|
128
|
+
const canonical = path.join(root, CONFIG_FILE_NAME);
|
|
129
|
+
const legacy = path.join(root, LEGACY_CONFIG_FILE_NAME);
|
|
130
|
+
const filePath = (await pathExists(canonical)) ? canonical : legacy;
|
|
131
|
+
if (filePath === legacy)
|
|
132
|
+
await assertNoInterruptedConfigReplacement(canonical);
|
|
133
|
+
const document = await readConfigDocumentIfExists(filePath, MAX_SETTINGS_BYTES, false);
|
|
134
|
+
if (!document)
|
|
135
|
+
return undefined;
|
|
136
|
+
const locked = () => pendingMutations ||
|
|
137
|
+
mutationGeneration !== generation ||
|
|
138
|
+
(localReadLock !== canonical && lstatSync(configMutationLockPath(canonical), { throwIfNoEntry: false }));
|
|
139
|
+
return {
|
|
140
|
+
document,
|
|
141
|
+
stillCurrent() {
|
|
142
|
+
if (locked())
|
|
143
|
+
return false;
|
|
144
|
+
assertCurrentDocument(document, canonical, legacy);
|
|
145
|
+
return !locked();
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
}
|
|
121
149
|
async function readConfigDocumentIfExists(filePath, maxBytes, securePermissions = true) {
|
|
122
150
|
const snapshot = await readConfigSnapshotIfExists(filePath, maxBytes, securePermissions);
|
|
123
151
|
return snapshot ? { path: filePath, ...snapshot } : undefined;
|
|
@@ -136,7 +164,7 @@ export function withLockedLocalConfigDocument(run, signal, forWrite = false, { s
|
|
|
136
164
|
assertCurrentDocument(document);
|
|
137
165
|
});
|
|
138
166
|
});
|
|
139
|
-
});
|
|
167
|
+
}, forWrite);
|
|
140
168
|
}
|
|
141
169
|
export async function readMigratingLocalConfigDocument(validateForMigration) {
|
|
142
170
|
const authority = engineHost().config;
|
|
@@ -158,17 +186,24 @@ export async function readMigratingLocalConfigDocument(validateForMigration) {
|
|
|
158
186
|
}
|
|
159
187
|
async function withLocalConfigReadLockIfNeeded(read) {
|
|
160
188
|
if ((await pathExists(localConfigPath())) || (await pathExists(legacyLocalConfigPath()))) {
|
|
161
|
-
return withLocalConfigFileLock(read);
|
|
189
|
+
return withLocalConfigFileLock(read, true);
|
|
162
190
|
}
|
|
163
191
|
await afterMissingConfigReadProbeHook();
|
|
164
192
|
if (await pathExists(configMutationLockPath()))
|
|
165
|
-
return withLocalConfigFileLock(read);
|
|
193
|
+
return withLocalConfigFileLock(read, true);
|
|
166
194
|
await assertNoInterruptedConfigReplacement();
|
|
167
195
|
return read();
|
|
168
196
|
}
|
|
169
|
-
function
|
|
197
|
+
function beginConfigMutation() {
|
|
198
|
+
pendingMutations++;
|
|
199
|
+
mutationGeneration++;
|
|
200
|
+
return () => pendingMutations--;
|
|
201
|
+
}
|
|
202
|
+
function queueConfigOperation(run, mayMutate = false) {
|
|
170
203
|
// Mutation callbacks use the unlocked helpers below, never a queued public read.
|
|
171
|
-
const
|
|
204
|
+
const finished = mayMutate ? beginConfigMutation() : undefined;
|
|
205
|
+
const queued = configUpdateQueue.then(run);
|
|
206
|
+
const operation = finished ? queued.finally(finished) : queued;
|
|
172
207
|
configUpdateQueue = operation.then(() => undefined, () => undefined);
|
|
173
208
|
return operation;
|
|
174
209
|
}
|
|
@@ -218,7 +253,7 @@ export function updateLocalConfigDocument(defaultValue, update, validate, signal
|
|
|
218
253
|
await installPrivateConfigExclusively(localConfigPath(), serializedConfig(next), signal, review);
|
|
219
254
|
return next;
|
|
220
255
|
});
|
|
221
|
-
});
|
|
256
|
+
}, true);
|
|
222
257
|
}
|
|
223
258
|
export function createLocalConfigDocument(value, signal) {
|
|
224
259
|
const authority = engineHost().config;
|
|
@@ -239,13 +274,13 @@ export function createLocalConfigDocument(value, signal) {
|
|
|
239
274
|
throw error;
|
|
240
275
|
}
|
|
241
276
|
});
|
|
242
|
-
});
|
|
277
|
+
}, true);
|
|
243
278
|
}
|
|
244
279
|
export function replaceLocalConfigDocument(document, value) {
|
|
245
280
|
const authority = engineHost().config;
|
|
246
281
|
if (authority)
|
|
247
282
|
return authority.replace(document, value);
|
|
248
|
-
return queueConfigOperation(() => withLocalConfigFileLock(() => replaceLocalConfigDocumentUnlocked(document, value)));
|
|
283
|
+
return queueConfigOperation(() => withLocalConfigFileLock(() => replaceLocalConfigDocumentUnlocked(document, value)), true);
|
|
249
284
|
}
|
|
250
285
|
async function replaceLocalConfigDocumentUnlocked(document, value, signal, review) {
|
|
251
286
|
const nextBytes = serializedConfig(value);
|
|
@@ -353,6 +388,15 @@ async function prepareLocalConfigPath(validateForMigration) {
|
|
|
353
388
|
if (!legacy)
|
|
354
389
|
return canonicalPath;
|
|
355
390
|
validateForMigration(legacy.parsed);
|
|
391
|
+
const finished = beginConfigMutation();
|
|
392
|
+
try {
|
|
393
|
+
return await migrateLegacyConfig(canonicalPath, legacyPath, legacy);
|
|
394
|
+
}
|
|
395
|
+
finally {
|
|
396
|
+
finished();
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
async function migrateLegacyConfig(canonicalPath, legacyPath, legacy) {
|
|
356
400
|
let installedIdentity;
|
|
357
401
|
try {
|
|
358
402
|
installedIdentity = await installPrivateConfigExclusively(canonicalPath, legacy.bytes);
|
|
@@ -407,9 +451,7 @@ async function secureIgnoredLegacyIfPresent(filePath) {
|
|
|
407
451
|
await handle?.close().catch(() => undefined);
|
|
408
452
|
}
|
|
409
453
|
}
|
|
410
|
-
function assertCurrentDocument(document) {
|
|
411
|
-
const canonical = localConfigPath();
|
|
412
|
-
const legacy = legacyLocalConfigPath();
|
|
454
|
+
function assertCurrentDocument(document, canonical = localConfigPath(), legacy = legacyLocalConfigPath()) {
|
|
413
455
|
const filePath = lstatSync(canonical, { throwIfNoEntry: false }) ? canonical : legacy;
|
|
414
456
|
const before = lstatSync(filePath, { throwIfNoEntry: false });
|
|
415
457
|
if (!document) {
|
|
@@ -568,7 +610,7 @@ async function configSnapshotStillMatches(filePath, snapshot) {
|
|
|
568
610
|
return fileIdentityAndContentsMatch(filePath, snapshot.identity, snapshot.bytes);
|
|
569
611
|
}
|
|
570
612
|
export function quarantineAndRemoveConfigIfMatches(filePath, identity, expectedBytes) {
|
|
571
|
-
return queueConfigOperation(() => withLocalConfigFileLock(() => quarantineAndRemoveConfigIfMatchesUnlocked(filePath, identity, expectedBytes)));
|
|
613
|
+
return queueConfigOperation(() => withLocalConfigFileLock(() => quarantineAndRemoveConfigIfMatchesUnlocked(filePath, identity, expectedBytes)), true);
|
|
572
614
|
}
|
|
573
615
|
async function quarantineAndRemoveConfigIfMatchesUnlocked(filePath, identity, expectedBytes) {
|
|
574
616
|
const quarantinePath = path.join(path.dirname(filePath), `.${path.basename(filePath)}.${randomUUID()}.migration-retired`);
|
|
@@ -634,10 +676,10 @@ async function restoreQuarantinedConfig(filePath, quarantinePath) {
|
|
|
634
676
|
// Preserve the quarantine rather than risk deleting settings that changed concurrently.
|
|
635
677
|
}
|
|
636
678
|
}
|
|
637
|
-
function configMutationLockPath() {
|
|
638
|
-
return `${
|
|
679
|
+
function configMutationLockPath(configPath = localConfigPath()) {
|
|
680
|
+
return `${configPath}.mutation-lock`;
|
|
639
681
|
}
|
|
640
|
-
export async function withLocalConfigFileLock(run) {
|
|
682
|
+
export async function withLocalConfigFileLock(run, readOnly = false) {
|
|
641
683
|
const configPath = localConfigPath();
|
|
642
684
|
await fs.mkdir(path.dirname(configPath), { recursive: true });
|
|
643
685
|
let compromisedError;
|
|
@@ -652,6 +694,8 @@ export async function withLocalConfigFileLock(run) {
|
|
|
652
694
|
compromisedError = error;
|
|
653
695
|
},
|
|
654
696
|
});
|
|
697
|
+
if (readOnly)
|
|
698
|
+
localReadLock = configPath;
|
|
655
699
|
try {
|
|
656
700
|
await assertNoInterruptedConfigReplacement();
|
|
657
701
|
const result = await run();
|
|
@@ -660,6 +704,8 @@ export async function withLocalConfigFileLock(run) {
|
|
|
660
704
|
return result;
|
|
661
705
|
}
|
|
662
706
|
finally {
|
|
707
|
+
if (readOnly)
|
|
708
|
+
localReadLock = undefined;
|
|
663
709
|
await release();
|
|
664
710
|
}
|
|
665
711
|
}
|
|
@@ -701,8 +747,7 @@ async function renameFileWithoutReplacement(source, destination, signal) {
|
|
|
701
747
|
signal?.throwIfAborted();
|
|
702
748
|
await fs.rename(source, destination);
|
|
703
749
|
}
|
|
704
|
-
async function assertNoInterruptedConfigReplacement() {
|
|
705
|
-
const configPath = localConfigPath();
|
|
750
|
+
async function assertNoInterruptedConfigReplacement(configPath = localConfigPath()) {
|
|
706
751
|
if (await pathExists(configPath))
|
|
707
752
|
return;
|
|
708
753
|
let names;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type SyncSelectionConfig } from "../sync/sync-policy.js";
|
|
2
|
+
import { type LocalConfigDocument } from "./config-file.js";
|
|
2
3
|
import type { AnySyncConfig, PartialConfig, PiSyncSettingsV3, StorageConnectionSettings, SyncSetupSettings } from "./settings-types.js";
|
|
3
4
|
export declare function loadConfig(setupName?: string, signal?: AbortSignal): Promise<AnySyncConfig>;
|
|
4
5
|
/** A background freshness read must never trigger legacy-file publication. */
|
|
@@ -6,6 +7,12 @@ export declare function loadConfigForCheck(setupName?: string, signal?: AbortSig
|
|
|
6
7
|
export declare function loadSettingsConfig(setupName?: string): Promise<AnySyncConfig>;
|
|
7
8
|
export declare function requireLegacyOperationConfig(config: AnySyncConfig): AnySyncConfig;
|
|
8
9
|
export declare function resolveIgnoreConfig(settings: PiSyncSettingsV3, setupName?: string, signal?: AbortSignal): Promise<AnySyncConfig>;
|
|
10
|
+
export declare function createSettingsConfigView(document: LocalConfigDocument): {
|
|
11
|
+
activeSetupName: string | undefined;
|
|
12
|
+
setupNames: string[];
|
|
13
|
+
metadata: (setupName?: string) => AnySyncConfig;
|
|
14
|
+
observe(setupName?: string, signal?: AbortSignal): Promise<AnySyncConfig>;
|
|
15
|
+
};
|
|
9
16
|
export declare function configFromSettings(settings: PiSyncSettingsV3, setupName?: string): AnySyncConfig;
|
|
10
17
|
export type SyncSetupStorageReview = Pick<PartialConfig, "connectionName" | "storageKind" | "storagePath" | "bucket" | "branch">;
|
|
11
18
|
/** A validated setup-facing projection used by manager and settings UI. */
|
|
@@ -33,7 +33,7 @@ async function operationalConfig(document, setupName, signal) {
|
|
|
33
33
|
return config;
|
|
34
34
|
if (engineHost().ignoreFileOperationsAvailable === false)
|
|
35
35
|
return requireLegacyOperationConfig(config);
|
|
36
|
-
return resolveOperationPolicy(config, setupName, signal, document);
|
|
36
|
+
return resolveOperationPolicy(config, setupName, signal, document && { kind: "checked", document });
|
|
37
37
|
}
|
|
38
38
|
export async function loadSettingsConfig(setupName) {
|
|
39
39
|
return configFromSettings(await readSettingsForCheck(), setupName);
|
|
@@ -56,10 +56,31 @@ export async function resolveIgnoreConfig(settings, setupName, signal) {
|
|
|
56
56
|
signal?.throwIfAborted();
|
|
57
57
|
return resolveOperationPolicy(configFromSettings(validateSettingsDocument(settings), setupName), setupName, signal);
|
|
58
58
|
}
|
|
59
|
+
export function createSettingsConfigView(document) {
|
|
60
|
+
const settings = validateSettingsDocument(document.parsed);
|
|
61
|
+
const ignoreNames = reservedIgnoreFilenames(settings);
|
|
62
|
+
const metadata = (setupName) => projectSettingsConfig(settings, setupName, () => ignoreNames);
|
|
63
|
+
let fingerprint;
|
|
64
|
+
return {
|
|
65
|
+
activeSetupName: settings.activeSyncSetup,
|
|
66
|
+
setupNames: Object.keys(settings.syncSetups),
|
|
67
|
+
metadata,
|
|
68
|
+
async observe(setupName, signal) {
|
|
69
|
+
signal?.throwIfAborted();
|
|
70
|
+
const config = metadata(setupName);
|
|
71
|
+
if (!config.reservedIgnoreNames)
|
|
72
|
+
return config;
|
|
73
|
+
if (engineHost().ignoreFileOperationsAvailable === false)
|
|
74
|
+
return requireLegacyOperationConfig(config);
|
|
75
|
+
fingerprint ??= settingsDocumentFingerprint(document);
|
|
76
|
+
return resolveOperationPolicy(config, setupName, signal, { kind: "view", fingerprint });
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
59
80
|
function settingsDocumentFingerprint(document) {
|
|
60
81
|
return documentFingerprint(document && { bytes: document.bytes.toString("base64"), identity: document.identity });
|
|
61
82
|
}
|
|
62
|
-
async function resolveOperationPolicy(config, setupName, signal,
|
|
83
|
+
async function resolveOperationPolicy(config, setupName, signal, settingsSource) {
|
|
63
84
|
if (!config.reservedIgnoreNames)
|
|
64
85
|
return config;
|
|
65
86
|
const root = getEngineRoot();
|
|
@@ -68,8 +89,9 @@ async function resolveOperationPolicy(config, setupName, signal, original) {
|
|
|
68
89
|
if (root !== getEngineRoot())
|
|
69
90
|
throw new Error("The Pi agent directory changed; reopen the review before continuing.");
|
|
70
91
|
};
|
|
71
|
-
const
|
|
72
|
-
const
|
|
92
|
+
const original = settingsSource?.kind === "checked" ? settingsSource.document : undefined;
|
|
93
|
+
const configDocumentFingerprint = settingsSource?.kind === "view" ? settingsSource.fingerprint : original && settingsDocumentFingerprint(original);
|
|
94
|
+
const settingsFingerprint = settingsSource?.kind === "view" ? undefined : syncCheckConfigFingerprint(config);
|
|
73
95
|
const validateSettings = (document) => {
|
|
74
96
|
validateRoot();
|
|
75
97
|
if ((original &&
|
|
@@ -81,16 +103,21 @@ async function resolveOperationPolicy(config, setupName, signal, original) {
|
|
|
81
103
|
};
|
|
82
104
|
const source = config.pathPolicy === "ignore-file" ? await readIgnoreSource(root, config.ignoreFile, signal) : undefined;
|
|
83
105
|
validateRoot();
|
|
84
|
-
if (
|
|
106
|
+
if (settingsSource && source && !source.present) {
|
|
85
107
|
throw new Error(`Ignore file is missing: ${safeTerminalText(path.join(root, source.filename))}. Create it and reopen Pi Sync; starter rules are only a preview.`);
|
|
86
108
|
}
|
|
87
109
|
if (original && source)
|
|
88
110
|
validateSettings(await readActiveLocalConfigDocumentForRepair());
|
|
89
|
-
|
|
111
|
+
const observed = {
|
|
90
112
|
...config,
|
|
91
113
|
...(configDocumentFingerprint ? { configDocumentFingerprint } : {}),
|
|
92
114
|
...(source ? { ignorePolicy: compileEffectiveIgnorePolicy(source, ignorePolicyInput(config)) } : {}),
|
|
93
115
|
...(source?.identity ? { ignoreSourceIdentity: source.identity } : {}),
|
|
116
|
+
};
|
|
117
|
+
if (settingsSource?.kind === "view")
|
|
118
|
+
return observed;
|
|
119
|
+
return {
|
|
120
|
+
...observed,
|
|
94
121
|
validateIgnorePolicy: async () => {
|
|
95
122
|
validateRoot();
|
|
96
123
|
await withLockedLocalConfigDocument(async (document, recheck) => {
|
|
@@ -121,7 +148,21 @@ function ignorePolicyInput(config) {
|
|
|
121
148
|
configuredFilenames: config.reservedIgnoreNames ?? [],
|
|
122
149
|
};
|
|
123
150
|
}
|
|
151
|
+
function reservedIgnoreFilenames(settings) {
|
|
152
|
+
const names = new Set();
|
|
153
|
+
for (const { sync } of Object.values(settings.syncSetups)) {
|
|
154
|
+
if (sync.pathPolicy === "ignore-file")
|
|
155
|
+
names.add(validateIgnoreFilename(sync.ignoreFile ?? DEFAULT_IGNORE_FILENAME).toLowerCase());
|
|
156
|
+
}
|
|
157
|
+
if (names.size === 0)
|
|
158
|
+
return undefined;
|
|
159
|
+
names.add(DEFAULT_IGNORE_FILENAME);
|
|
160
|
+
return [...names].sort();
|
|
161
|
+
}
|
|
124
162
|
export function configFromSettings(settings, setupName) {
|
|
163
|
+
return projectSettingsConfig(settings, setupName, () => reservedIgnoreFilenames(settings));
|
|
164
|
+
}
|
|
165
|
+
function projectSettingsConfig(settings, setupName, getReservedIgnoreNames) {
|
|
125
166
|
const selectedName = setupName ?? settings.activeSyncSetup;
|
|
126
167
|
if (!selectedName)
|
|
127
168
|
throw new Error("No sync setups are configured.");
|
|
@@ -134,17 +175,11 @@ export function configFromSettings(settings, setupName) {
|
|
|
134
175
|
if (!connection) {
|
|
135
176
|
throw new Error(`Invalid pi-sync settings: sync setup “${selectedName}” references missing storage connection “${connectionName}”.`);
|
|
136
177
|
}
|
|
137
|
-
const
|
|
138
|
-
for (const { sync } of Object.values(settings.syncSetups)) {
|
|
139
|
-
if (sync.pathPolicy === "ignore-file")
|
|
140
|
-
ignoreNames.add(validateIgnoreFilename(sync.ignoreFile ?? DEFAULT_IGNORE_FILENAME).toLowerCase());
|
|
141
|
-
}
|
|
142
|
-
if (ignoreNames.size > 0)
|
|
143
|
-
ignoreNames.add(DEFAULT_IGNORE_FILENAME);
|
|
178
|
+
const reservedIgnoreNames = getReservedIgnoreNames();
|
|
144
179
|
return {
|
|
145
180
|
...resolveSyncConfig(selectedName, setup, connectionName, connection, settings.onSwitch, settings.skipSecretScan ?? false, settings.showStatus ?? true),
|
|
146
181
|
debug: settings.debug ?? false,
|
|
147
|
-
...(
|
|
182
|
+
...(reservedIgnoreNames ? { reservedIgnoreNames } : {}),
|
|
148
183
|
};
|
|
149
184
|
}
|
|
150
185
|
/** A validated setup-facing projection used by manager and settings UI. */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type SkippedSnapshotWrite } from "./snapshot-transaction.js";
|
|
1
2
|
import { type Snapshot, type SnapshotApplyPlan, type SnapshotOptions } from "./snapshot-types.js";
|
|
2
3
|
export declare function applySnapshot(snapshot: Snapshot, protectedRelativePaths?: Set<string>, options?: Pick<SnapshotOptions, "include" | "exclude" | "scope" | "reinclude" | "ignorePolicy" | "reservedIgnoreNames" | "setupName" | "recoverySetupKey" | "ignoreSourceIdentity" | "sessionDir" | "syncFiles" | "syncSessions" | "extraFiles" | "signal" | "validateMutation" | "validateIgnorePolicy" | "validateApplyReview" | "expectedFileHashes"> & {
|
|
3
4
|
reviewedLocal?: Pick<Snapshot, "files">;
|
|
@@ -17,5 +18,5 @@ export declare function preflightSnapshotMutations(root: string, plan: {
|
|
|
17
18
|
target: string;
|
|
18
19
|
content: Buffer;
|
|
19
20
|
}>;
|
|
20
|
-
}, sessionDir?: string, options?: MutationGuards): Promise<
|
|
21
|
+
}, sessionDir?: string, options?: MutationGuards, unchangedHashes?: ReadonlyMap<string, string>): Promise<SkippedSnapshotWrite[]>;
|
|
21
22
|
export {};
|
|
@@ -4,7 +4,8 @@ import path from "node:path";
|
|
|
4
4
|
import { assertWithinRoot, isDeniedPath, isPathInside, parentPaths, safeJoin, toPosix } from "../paths.js";
|
|
5
5
|
import { syncDirectory } from "../state/json-file.js";
|
|
6
6
|
import { stateDir } from "../state/state-directory.js";
|
|
7
|
-
import {
|
|
7
|
+
import { collidingPaths } from "../sync/file-merge-planner.js";
|
|
8
|
+
import { assertSnapshotExcludesDebugLog, compileSyncPolicyExclude, requireLegacyTransferPolicy, sameSnapshotSelection, selectionForSnapshot, } from "../sync/sync-policy.js";
|
|
8
9
|
import { agentDir } from "./session-paths.js";
|
|
9
10
|
import { agentDirectoryConfiguredSessionDir, agentDirectoryInventory, createSnapshot, isSessionFilePath, isSessionPath, sessionStorageRoot, snapshotIncludesSessions, snapshotTarget, } from "./snapshot.js";
|
|
10
11
|
import { assertAgentDirectorySnapshotBound } from "./snapshot-bounds.js";
|
|
@@ -12,7 +13,7 @@ import { assertProjectedAgentDirectoryBudget } from "./snapshot-entry-projection
|
|
|
12
13
|
import { agentDirectoryPhysicalSessionPath, assertUnexcludedTargets } from "./snapshot-exclude-safety.js";
|
|
13
14
|
import { decodeBase64Strict } from "./snapshot-payload.js";
|
|
14
15
|
import { reviewedSnapshotPreimages } from "./snapshot-reviewed-preimages.js";
|
|
15
|
-
import { applySnapshotTransaction, recoverPendingSnapshotTransactions } from "./snapshot-transaction.js";
|
|
16
|
+
import { applySnapshotTransaction, recoverPendingSnapshotTransactions, } from "./snapshot-transaction.js";
|
|
16
17
|
import { ignorePolicyValidator } from "./snapshot-transaction-policy.js";
|
|
17
18
|
import { IGNORE_SNAPSHOT_VERSION, } from "./snapshot-types.js";
|
|
18
19
|
function sha256(value) {
|
|
@@ -22,6 +23,7 @@ function fileHashMap(snapshot) {
|
|
|
22
23
|
return Object.fromEntries(snapshot.files.map((file) => [file.path, file.sha256]));
|
|
23
24
|
}
|
|
24
25
|
function assertSnapshotApplyPolicy(snapshot, options) {
|
|
26
|
+
assertSnapshotExcludesDebugLog(snapshot);
|
|
25
27
|
if (snapshot.version !== IGNORE_SNAPSHOT_VERSION) {
|
|
26
28
|
requireLegacyTransferPolicy(snapshot);
|
|
27
29
|
if (options.ignorePolicy)
|
|
@@ -77,6 +79,16 @@ export async function applySnapshot(snapshot, protectedRelativePaths = new Set()
|
|
|
77
79
|
]);
|
|
78
80
|
}
|
|
79
81
|
const plan = await addTopLevelCaseVariantDeletes(root, protectSnapshotApplyPlan(root, preflightSnapshotApply(root, snapshot, current, options), protectedRelativePaths, sessionDir), snapshot, options);
|
|
82
|
+
const currentHashes = new Map(current.files.map(({ path, sha256 }) => [path, sha256]));
|
|
83
|
+
const dependencies = collidingPaths([...plan.deletes, ...plan.writes.map(({ target }) => target)].map(toPosix));
|
|
84
|
+
const unchangedHashes = new Map();
|
|
85
|
+
for (const file of snapshot.files) {
|
|
86
|
+
if (currentHashes.get(file.path) !== file.sha256)
|
|
87
|
+
continue;
|
|
88
|
+
const target = snapshotTarget(root, file.path, sessionDir);
|
|
89
|
+
if (!dependencies.has(toPosix(target)))
|
|
90
|
+
unchangedHashes.set(target, file.sha256);
|
|
91
|
+
}
|
|
80
92
|
if (inventory) {
|
|
81
93
|
assertProjectedAgentDirectoryBudget(inventory, {
|
|
82
94
|
deletes: plan.deletes,
|
|
@@ -85,8 +97,10 @@ export async function applySnapshot(snapshot, protectedRelativePaths = new Set()
|
|
|
85
97
|
{ target: stateDir(root) },
|
|
86
98
|
],
|
|
87
99
|
}, options);
|
|
88
|
-
await preflightSnapshotMutations(root, plan, sessionDir, options);
|
|
89
100
|
}
|
|
101
|
+
const skipped = inventory
|
|
102
|
+
? await preflightSnapshotMutations(root, plan, sessionDir, options, unchangedHashes)
|
|
103
|
+
: undefined;
|
|
90
104
|
if (options.reviewedLocal || inventory) {
|
|
91
105
|
const images = reviewedSnapshotPreimages(root, sessionDir, current.files, plan, inventory);
|
|
92
106
|
const reviewed = options.reviewedLocal;
|
|
@@ -102,9 +116,7 @@ export async function applySnapshot(snapshot, protectedRelativePaths = new Set()
|
|
|
102
116
|
transactionOptions.expectedPreimages.set(target, image);
|
|
103
117
|
}
|
|
104
118
|
}
|
|
105
|
-
|
|
106
|
-
await preflightSnapshotMutations(root, plan, sessionDir, options);
|
|
107
|
-
await applySnapshotTransaction(plan, transactionOptions);
|
|
119
|
+
await applySnapshotTransaction(plan, transactionOptions, skipped ?? (await preflightSnapshotMutations(root, plan, sessionDir, options, unchangedHashes)));
|
|
108
120
|
return appliedFileHashMap(snapshot, current, protectedRelativePaths);
|
|
109
121
|
}
|
|
110
122
|
function sameReviewedFiles(scanned, reviewed) {
|
|
@@ -242,7 +254,8 @@ function excludedApplyPath(root, options) {
|
|
|
242
254
|
return (relative) => excluded(relative) ||
|
|
243
255
|
(/^sessions(?:\/|$)/iu.test(relative) ? !isSessionFilePath(relative) : physicalSessionPath(relative));
|
|
244
256
|
}
|
|
245
|
-
export async function preflightSnapshotMutations(root, plan, sessionDir, options = {}) {
|
|
257
|
+
export async function preflightSnapshotMutations(root, plan, sessionDir, options = {}, unchangedHashes) {
|
|
258
|
+
const skipped = [];
|
|
246
259
|
assertMutationCurrent(options);
|
|
247
260
|
await assertUnexcludedTargets(root, [...plan.deletes, ...plan.writes.map((item) => item.target)], {
|
|
248
261
|
...options,
|
|
@@ -255,9 +268,17 @@ export async function preflightSnapshotMutations(root, plan, sessionDir, options
|
|
|
255
268
|
assertMutationCurrent(options);
|
|
256
269
|
}
|
|
257
270
|
for (const item of plan.writes) {
|
|
258
|
-
await prepareSnapshotWrite(rootForTarget(root, item.target, sessionDir), item.target, deletePaths, options);
|
|
271
|
+
const stat = await prepareSnapshotWrite(rootForTarget(root, item.target, sessionDir), item.target, deletePaths, options);
|
|
259
272
|
assertMutationCurrent(options);
|
|
273
|
+
const hash = unchangedHashes?.get(item.target);
|
|
274
|
+
if (hash !== undefined && stat?.isFile() && stat.nlink === 1) {
|
|
275
|
+
const canonical = await fs.realpath(item.target);
|
|
276
|
+
assertMutationCurrent(options);
|
|
277
|
+
if (canonical === item.target)
|
|
278
|
+
skipped.push({ ...item, preimage: `file:${hash}` });
|
|
279
|
+
}
|
|
260
280
|
}
|
|
281
|
+
return skipped;
|
|
261
282
|
}
|
|
262
283
|
function assertMutationCurrent(options) {
|
|
263
284
|
options.validateMutation?.();
|
|
@@ -296,6 +317,7 @@ async function prepareSnapshotWrite(root, target, deletePaths, options) {
|
|
|
296
317
|
if (stat?.isDirectory() && !deletePaths.has(target)) {
|
|
297
318
|
throw new Error(`Refusing to overwrite directory during snapshot apply: ${target}`);
|
|
298
319
|
}
|
|
320
|
+
return stat;
|
|
299
321
|
}
|
|
300
322
|
async function ensureSafeDirectory(root, directory, deletePaths, options) {
|
|
301
323
|
assertMutationCurrent(options);
|
|
@@ -4,7 +4,7 @@ import { pipeline } from "node:stream/promises";
|
|
|
4
4
|
import { promisify } from "node:util";
|
|
5
5
|
import { createGunzip, gzip } from "node:zlib";
|
|
6
6
|
import { throwIfAborted } from "../sync/signals.js";
|
|
7
|
-
import { snapshotSelectionInclude, validateSnapshotSelection } from "../sync/sync-policy.js";
|
|
7
|
+
import { assertSnapshotExcludesDebugLog, snapshotSelectionInclude, validateSnapshotSelection, } from "../sync/sync-policy.js";
|
|
8
8
|
import { IGNORE_SNAPSHOT_VERSION, isSupportedSnapshotVersion } from "./snapshot-types.js";
|
|
9
9
|
const VERSION = 1;
|
|
10
10
|
const MAX_DECOMPRESSED_SNAPSHOT_BYTES = 512 * 1024 * 1024;
|
|
@@ -12,6 +12,7 @@ const gzipAsync = promisify(gzip);
|
|
|
12
12
|
export async function encodeSnapshot(snapshot) {
|
|
13
13
|
if (!isSupportedSnapshotVersion(snapshot?.version))
|
|
14
14
|
throw new Error("Unsupported snapshot format.");
|
|
15
|
+
assertSnapshotExcludesDebugLog(snapshot);
|
|
15
16
|
if (snapshot.version !== IGNORE_SNAPSHOT_VERSION)
|
|
16
17
|
snapshotSelectionInclude(snapshot);
|
|
17
18
|
validateSnapshotSelection(snapshot);
|
|
@@ -46,6 +47,7 @@ export async function decodeSnapshot(buffer, options = {}) {
|
|
|
46
47
|
}
|
|
47
48
|
if (parsed.version === IGNORE_SNAPSHOT_VERSION && !isUtf8(payload))
|
|
48
49
|
throw new Error("Invalid snapshot UTF-8.");
|
|
50
|
+
assertSnapshotExcludesDebugLog(parsed);
|
|
49
51
|
validateSnapshotSelection(parsed);
|
|
50
52
|
if (parsed.version !== VERSION) {
|
|
51
53
|
const { normalizeLocalFields, validatePortableSnapshot } = await import("../sync/local-fields.js");
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
+
import type { SnapshotFile } from "./snapshot-types.js";
|
|
2
|
+
export declare function assertSnapshotFilePayload(file: SnapshotFile, message: string): void;
|
|
3
|
+
export declare function materializeSnapshotFilePayload(file: SnapshotFile, message: string): Buffer;
|
|
4
|
+
export declare function snapshotFileFromBlob(path: string, content: Buffer, sha256: string, message: string): SnapshotFile;
|
|
1
5
|
export declare function snapshotBase64Size(value: string, filePath: string): number;
|
|
2
6
|
export declare function decodeBase64Strict(value: string, filePath: string): Buffer<ArrayBuffer>;
|