// @generated by scripts/build-runtime.mjs; do not edit. // @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader. import { filterSnapshotForConfigPolicy, isSessionPath } from "./chunk-EWX3TPLQ.ts"; import { canonicalSnapshotPathForConfig, customIncludePathsByLower, includeFromSelectionConfig, isConfiguredSnapshotPath, normalizeSyncInclude, toPosix } from "./chunk-YQ6UW7IF.ts"; // src/sync-state.ts function hasLocalChanges(local, state, config) { return !sameHashes(fileHashMap(local), stateHashMapForConfig(state, config)); } function remoteChangedSinceState(head, state, config, sameRevision) { if (!head) return Boolean(state.lastAppliedSnapshot); if (head.snapshotId !== state.lastAppliedSnapshot) return true; if (state.lastRemoteRevision && !sameRevision(head.revision, state.lastRemoteRevision)) return true; if (syncIncludeChanged(state, config)) return true; return includeFromSelectionConfig(config).includes("sessions") && !state.include?.includes("sessions") && head.syncSessions; } function hasRemoteChanges(remote, state, config, ignoredPaths = /* @__PURE__ */ new Set()) { if (remote.id === state.lastAppliedSnapshot && !syncPolicyChanged(state, config)) return false; return !snapshotHashesMatchState( filterSnapshotForConfigPolicy(remote, config), state, config, ignoredPaths ); } function sameHashes(left, right) { const keys = /* @__PURE__ */ new Set([...Object.keys(left), ...Object.keys(right)]); for (const key of keys) if (left[key] !== right[key]) return false; return true; } function fileHashMap(snapshot) { return Object.fromEntries(snapshot.files.map((file) => [file.path, file.sha256])); } function stateHashMapForConfig(state, config) { const includePaths = customIncludePathsByLower(includeFromSelectionConfig(config)); return Object.fromEntries( Object.entries(state.lastFileHashes).filter(([filePath]) => isConfiguredSnapshotPath(filePath, config)).map(([filePath, hash]) => [canonicalSnapshotPathForConfig(filePath, includePaths), hash]) ); } function snapshotHashesMatchState(snapshot, state, config, ignoredPaths = /* @__PURE__ */ new Set()) { return sameHashes( withoutHashPaths(fileHashMap(snapshot), ignoredPaths), withoutHashPaths(stateHashMapForConfig(state, config), ignoredPaths) ); } function snapshotsMatch(left, right) { return left.syncSessions === right.syncSessions && sameHashes(fileHashMap(left), fileHashMap(right)); } function withoutHashPaths(hashes, ignoredPaths) { if (ignoredPaths.size === 0) return hashes; return Object.fromEntries( Object.entries(hashes).filter(([filePath]) => !ignoredPaths.has(toPosix(filePath))) ); } function syncPolicyChanged(state, config) { return syncIncludeChanged(state, config); } function shouldRefreshSyncedState(remote, head, state, config, sameRevision) { return remote.id !== state.lastAppliedSnapshot || Boolean( head && (!state.lastRemoteRevision || !sameRevision(head.revision, state.lastRemoteRevision)) ) || syncPolicyChanged(state, config); } function syncIncludeChanged(state, config) { const stored = state.include ? normalizeSyncInclude(state.include) : includeFromSelectionConfig(state); const current = includeFromSelectionConfig(config); return stored.length !== current.length || stored.some((item, index) => item !== current[index]); } function settingsHashMap(snapshot) { return Object.fromEntries( snapshot.files.filter((file) => !isSessionPath(file.path)).map((file) => [file.path, file.sha256]) ); } function sessionHashMap(snapshot) { return Object.fromEntries( snapshot.files.filter((file) => isSessionPath(file.path)).map((file) => [file.path, file.sha256]) ); } function settingsHashMapFromState(state) { return Object.fromEntries( Object.entries(state.lastFileHashes).filter(([filePath]) => !isSessionPath(filePath)) ); } function settingsHashesMatchState(remote, state) { return sameHashes(settingsHashMap(remote), settingsHashMapFromState(state)); } function canPullRemoteSettingsOnFirstSync(local, remote) { const remoteSettings = settingsHashMap(remote); return Object.entries(settingsHashMap(local)).every( ([filePath, hash]) => remoteSettings[filePath] === hash ); } function canPullRemoteSessionsOnFirstSync(local, remote) { const localSessions = sessionHashMap(local); const remoteSessions = sessionHashMap(remote); return Object.entries(localSessions).every( ([filePath, hash]) => remoteSessions[filePath] === hash ); } export { hasLocalChanges, remoteChangedSinceState, hasRemoteChanges, sameHashes, fileHashMap, snapshotHashesMatchState, snapshotsMatch, syncPolicyChanged, shouldRefreshSyncedState, settingsHashMap, sessionHashMap, settingsHashMapFromState, settingsHashesMatchState, canPullRemoteSettingsOnFirstSync, canPullRemoteSessionsOnFirstSync }; //# sourceMappingURL=chunk-RGJ6SOYR.ts.map