@artenx/dshb 0.1.38 → 0.1.40
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 +21 -0
- package/lib/auth/gate.d.ts +9 -1
- package/lib/auth/gate.js +12 -5
- package/lib/auth/gate.js.map +1 -1
- package/lib/auth/index.js +42 -9
- package/lib/auth/index.js.map +1 -1
- package/lib/auth/reset-cli.js +0 -0
- package/lib/catalog-B3pDDoR4.js +119 -0
- package/lib/catalog-B3pDDoR4.js.map +1 -0
- package/lib/client.js +1014 -45
- package/lib/client.js.map +1 -1
- package/lib/core/index.js +477 -4
- package/lib/core/index.js.map +1 -1
- package/lib/core/routes.d.ts +1 -1
- package/lib/core/sync/coordinator.d.ts +5 -5
- package/lib/core/sync/coordinator.js +47 -6
- package/lib/core/sync/coordinator.js.map +1 -1
- package/lib/core/sync/host-key.d.ts +1 -1
- package/lib/core/sync/internal-routes.d.ts +3 -3
- package/lib/core/sync/internal-routes.js +36 -3
- package/lib/core/sync/internal-routes.js.map +1 -1
- package/lib/core/sync/model.d.ts +2 -2
- package/lib/core/sync/model.js +62 -1
- package/lib/core/sync/model.js.map +1 -1
- package/lib/core/sync/node-sync.d.ts +1 -1
- package/lib/core/sync/offline-archive.d.ts +6 -4
- package/lib/core/sync/offline-archive.js +31 -8
- package/lib/core/sync/offline-archive.js.map +1 -1
- package/lib/core/sync/offline-routes.js +29 -3
- package/lib/core/sync/offline-routes.js.map +1 -1
- package/lib/core/sync/peer-manager.d.ts +2 -2
- package/lib/core/sync/peer-manager.js +2 -0
- package/lib/core/sync/peer-manager.js.map +1 -1
- package/lib/core/sync/protocol.d.ts +2 -2
- package/lib/core/sync/protocol.js +2 -1
- package/lib/core/sync/protocol.js.map +1 -1
- package/lib/core/sync/remote-helper.js +4 -2
- package/lib/core/sync/remote-helper.js.map +1 -1
- package/lib/core/sync/routes.d.ts +3 -2
- package/lib/core/sync/routes.js +43 -2
- package/lib/core/sync/routes.js.map +1 -1
- package/lib/core/sync/session-journal.d.ts +1 -1
- package/lib/core/sync/session-routes.d.ts +1 -1
- package/lib/core/sync/session-routes.js +25 -1
- package/lib/core/sync/session-routes.js.map +1 -1
- package/lib/core/sync/session-sync.d.ts +1 -1
- package/lib/core/sync/session-sync.js +1 -1
- package/lib/core/sync/ssh-transport.d.ts +1 -1
- package/lib/core/sync/ssh-transport.js +73 -3
- package/lib/core/sync/ssh-transport.js.map +1 -1
- package/lib/core/sync/stores.d.ts +1 -1
- package/lib/core/sync/stores.js +27 -5
- package/lib/core/sync/stores.js.map +1 -1
- package/lib/core/workspaces.d.ts +1 -1
- package/lib/{host-key-CSnpIrjq.d.ts → host-key-Dh2YTRX7.d.ts} +2 -2
- package/lib/{model-CKTBf-Pl.d.ts → model-D1T078kt.d.ts} +74 -6
- package/lib/{node-sync-C3Ym-HDu.d.ts → node-sync-WdEv-ek7.d.ts} +3 -3
- package/lib/{protocol-DJ0zyVlB.d.ts → protocol-DyPDIJWa.d.ts} +3 -2
- package/lib/selection-BABQH1Rt.js +48 -0
- package/lib/selection-BABQH1Rt.js.map +1 -0
- package/lib/{session-journal-VE_1tA2-.d.ts → session-journal-CTblFLJg.d.ts} +2 -2
- package/lib/{session-sync-BBCm_ou2.js → session-sync-BZSp_o4n.js} +81 -1
- package/lib/session-sync-BZSp_o4n.js.map +1 -0
- package/lib/{session-sync-Bw0cZ4oa.d.ts → session-sync-flNnd2JQ.d.ts} +14 -5
- package/lib/{ssh-transport-COZe0BDr.d.ts → ssh-transport-DQPMNwh1.d.ts} +25 -6
- package/lib/{stores-puyTC075.d.ts → stores-CUY_YFD-.d.ts} +2 -2
- package/package.json +9 -7
- package/lib/session-sync-BBCm_ou2.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stores.js","names":[],"sources":["../../../src/core/sync/stores.ts"],"sourcesContent":["import { randomBytes } from 'node:crypto'\nimport {\n chmodSync,\n closeSync,\n fsyncSync,\n mkdirSync,\n openSync,\n readFileSync,\n renameSync,\n unlinkSync,\n writeFileSync,\n} from 'node:fs'\nimport { homedir } from 'node:os'\nimport { basename, dirname, join, posix } from 'node:path'\nimport { HybridLogicalClock, type HlcSnapshot, type SyncRevision } from './revision.js'\nimport {\n isNonNegativeSafeInteger,\n isRecord,\n parseSyncPeer,\n syncRecordKey,\n syncWorkspaceKey,\n type SyncPeer,\n type SyncPeerDraft,\n type SyncPeerProgress,\n type SyncRecordMetadata,\n type SyncSessionArchive,\n type SyncState,\n type SyncWorkspaceMapping,\n} from './model.js'\n\nfunction dshHome(home?: string): string {\n return home ?? process.env.DSH_HOME ?? join(homedir(), '.dsh')\n}\n\nfunction readJson<T>(file: string, validate: (value: unknown) => T): T | undefined {\n let content: string\n try {\n content = readFileSync(file, 'utf8')\n } catch (error) {\n if (isNodeError(error) && error.code === 'ENOENT') return undefined\n throw error\n }\n let value: unknown\n try {\n value = JSON.parse(content)\n } catch {\n throw new Error(`Invalid JSON in ${basename(file)}`)\n }\n return validate(value)\n}\n\nfunction isNodeError(error: unknown): error is NodeJS.ErrnoException {\n return error instanceof Error && 'code' in error\n}\n\nfunction atomicWrite(file: string, content: string): void {\n const dir = dirname(file)\n mkdirSync(dir, { recursive: true, mode: 0o700 })\n const temporary = `${file}.${process.pid}.${randomBytes(8).toString('hex')}.tmp`\n let fd: number | undefined\n try {\n fd = openSync(temporary, 'wx', 0o600)\n writeFileSync(fd, content, 'utf8')\n fsyncSync(fd)\n closeSync(fd)\n fd = undefined\n renameSync(temporary, file)\n chmodSync(file, 0o600)\n } catch (error) {\n if (fd !== undefined) closeSync(fd)\n try {\n unlinkSync(temporary)\n } catch {}\n throw error\n }\n}\n\nfunction clone<T>(value: T): T {\n return JSON.parse(JSON.stringify(value)) as T\n}\n\nfunction instanceIdFile(home: string): string {\n return join(home, 'dshb', 'instance-id')\n}\n\nfunction parseInstanceId(value: string): string {\n const id = value.trim()\n if (!/^i-[a-f0-9]{32}$/.test(id)) throw new Error('Invalid DSHB sync instance ID')\n return id\n}\n\nexport function getOrCreateSyncInstanceId(home?: string): string {\n const root = dshHome(home)\n const file = instanceIdFile(root)\n try {\n return parseInstanceId(readFileSync(file, 'utf8'))\n } catch (error) {\n if (!(isNodeError(error) && error.code === 'ENOENT')) throw error\n }\n\n mkdirSync(dirname(file), { recursive: true, mode: 0o700 })\n const candidate = `i-${randomBytes(16).toString('hex')}`\n let fd: number | undefined\n try {\n fd = openSync(file, 'wx', 0o600)\n writeFileSync(fd, `${candidate}\\n`, 'utf8')\n fsyncSync(fd)\n closeSync(fd)\n fd = undefined\n chmodSync(file, 0o600)\n return candidate\n } catch (error) {\n if (fd !== undefined) closeSync(fd)\n if (isNodeError(error) && error.code === 'EEXIST') {\n return parseInstanceId(readFileSync(file, 'utf8'))\n }\n throw error\n }\n}\n\nfunction newPeerId(): string {\n return `p-${randomBytes(12).toString('hex')}`\n}\n\nfunction validatePeers(value: unknown): SyncPeer[] {\n if (!Array.isArray(value)) throw new Error('Invalid sync peer store')\n const peers = value.map(parseSyncPeer)\n if (new Set(peers.map((peer) => peer.id)).size !== peers.length) {\n throw new Error('Sync peer store contains duplicate IDs')\n }\n return peers\n}\n\nexport class SyncPeerStore {\n private peers: SyncPeer[] | undefined\n private readonly filePath: string\n\n constructor(home?: string) {\n this.filePath = join(dshHome(home), 'dshb', 'sync-peers.json')\n }\n\n list(): SyncPeer[] {\n return clone(this.load())\n }\n\n get(id: string): SyncPeer | undefined {\n const peer = this.load().find((item) => item.id === id)\n return peer ? clone(peer) : undefined\n }\n\n create(draft: SyncPeerDraft): SyncPeer {\n const peer = parseSyncPeer({ ...draft, id: newPeerId() })\n const next = [...this.load(), peer]\n this.save(next)\n return clone(peer)\n }\n\n update(id: string, patch: Partial<Omit<SyncPeer, 'id'>>): SyncPeer {\n const current = this.load()\n const index = current.findIndex((peer) => peer.id === id)\n if (index < 0) throw new Error(`sync peer ${id} not found`)\n const updated = parseSyncPeer({ ...current[index], ...patch, id })\n const next = [...current]\n next[index] = updated\n this.save(next)\n return clone(updated)\n }\n\n remove(id: string): boolean {\n const current = this.load()\n const next = current.filter((peer) => peer.id !== id)\n if (next.length === current.length) return false\n this.save(next)\n return true\n }\n\n private load(): SyncPeer[] {\n if (this.peers) return this.peers\n const stored = readJson(this.filePath, validatePeers)\n this.peers = stored ?? []\n return this.peers\n }\n\n private save(peers: SyncPeer[]): void {\n atomicWrite(this.filePath, `${JSON.stringify(peers, null, 2)}\\n`)\n this.peers = peers\n }\n}\n\nfunction validateProgress(value: unknown): SyncPeerProgress {\n if (!isRecord(value)) throw new Error('Invalid peer sync progress')\n const progress: SyncPeerProgress = {}\n for (const field of ['lastRunAt', 'lastSuccessAt', 'lastManifestDigest', 'watermark', 'lastErrorCode', 'lastErrorMessage'] as const) {\n const entry = value[field]\n if (entry !== undefined) {\n if (\n typeof entry !== 'string' || !entry ||\n entry.length > (field === 'lastErrorMessage' ? 256 : 512) ||\n /[\\u0000-\\u001f\\u007f]/.test(entry)\n ) {\n throw new Error(`Invalid peer sync progress field: ${field}`)\n }\n progress[field] = entry\n }\n }\n if (value.lastRunStatus !== undefined) {\n if (value.lastRunStatus !== 'running' && value.lastRunStatus !== 'succeeded' && value.lastRunStatus !== 'failed' && value.lastRunStatus !== 'stopped') {\n throw new Error('Invalid peer sync run status')\n }\n progress.lastRunStatus = value.lastRunStatus\n }\n if (value.lastResult !== undefined) {\n if (!isRecord(value.lastResult)) throw new Error('Invalid peer sync run result')\n const counts = ['imported', 'exported', 'skipped', 'pendingRemoval'] as const\n for (const field of counts) {\n if (!isNonNegativeSafeInteger(value.lastResult[field])) throw new Error(`Invalid peer sync result field: ${field}`)\n }\n const sessionCounts = ['importedSessions', 'exportedSessions', 'skippedSessions'] as const\n for (const field of sessionCounts) {\n if (value.lastResult[field] !== undefined && !isNonNegativeSafeInteger(value.lastResult[field])) {\n throw new Error(`Invalid peer sync result field: ${field}`)\n }\n }\n progress.lastResult = {\n imported: value.lastResult.imported as number,\n exported: value.lastResult.exported as number,\n skipped: value.lastResult.skipped as number,\n pendingRemoval: value.lastResult.pendingRemoval as number,\n importedSessions: (value.lastResult.importedSessions as number | undefined) ?? 0,\n exportedSessions: (value.lastResult.exportedSessions as number | undefined) ?? 0,\n skippedSessions: (value.lastResult.skippedSessions as number | undefined) ?? 0,\n }\n }\n return progress\n}\n\nfunction validateRevision(value: unknown, label: string): SyncRevision {\n if (\n !isRecord(value) ||\n !isNonNegativeSafeInteger(value.physicalTimeMs) ||\n !isNonNegativeSafeInteger(value.logicalCounter) ||\n typeof value.writerInstanceId !== 'string' ||\n !value.writerInstanceId ||\n /[\\u0000-\\u001f\\u007f]/.test(value.writerInstanceId)\n ) {\n throw new Error(`Invalid ${label} revision`)\n }\n return {\n physicalTimeMs: value.physicalTimeMs,\n logicalCounter: value.logicalCounter,\n writerInstanceId: value.writerInstanceId,\n }\n}\n\nfunction validateRecord(value: unknown): SyncRecordMetadata {\n if (!isRecord(value)) throw new Error('Invalid sync record metadata')\n if (value.kind !== 'node' && value.kind !== 'session') throw new Error('Invalid sync entity kind')\n const requiredText = ['originInstanceId', 'originEntityId', 'localEntityId', 'contentDigest'] as const\n for (const key of requiredText) {\n if (\n typeof value[key] !== 'string' ||\n !(value[key] as string).trim() ||\n (value[key] as string).length > 4096 ||\n /[\\u0000-\\u001f\\u007f]/.test(value[key] as string)\n ) {\n throw new Error(`Invalid sync record field: ${key}`)\n }\n }\n if (value.stateDigest !== undefined && (typeof value.stateDigest !== 'string' || !/^sha256:[a-f0-9]{64}$/.test(value.stateDigest))) {\n throw new Error('Invalid sync record state digest')\n }\n validateRevision(value.revision, 'sync record')\n if (value.deleted !== undefined && typeof value.deleted !== 'boolean') throw new Error('Invalid sync tombstone')\n if (value.pendingRemoval !== undefined && typeof value.pendingRemoval !== 'boolean') {\n throw new Error('Invalid pending removal state')\n }\n if (value.credentialsRequired !== undefined && typeof value.credentialsRequired !== 'boolean') {\n throw new Error('Invalid sync credential requirement state')\n }\n if (value.workspaceOrigin !== undefined) {\n if (!isRecord(value.workspaceOrigin)) throw new Error('Invalid sync workspace origin')\n validateOrigin(value.workspaceOrigin)\n }\n if (value.importedVia !== undefined && value.importedVia !== 'peer' && value.importedVia !== 'offline') {\n throw new Error('Invalid sync import method')\n }\n if (\n value.sourceName !== undefined &&\n (typeof value.sourceName !== 'string' || value.sourceName.length > 256 || /[\\u0000-\\u001f\\u007f]/.test(value.sourceName))\n ) {\n throw new Error('Invalid sync source name')\n }\n return clone(value) as unknown as SyncRecordMetadata\n}\n\nfunction validateWorkspaceMapping(value: unknown): SyncWorkspaceMapping {\n if (!isRecord(value)) throw new Error('Invalid sync workspace mapping')\n const originInstanceId = requiredString(value.originInstanceId, 'workspace origin instance ID', 128)\n const originWorkspaceId = requiredString(value.originWorkspaceId, 'workspace origin ID', 256)\n const localWorkspaceId = requiredString(value.localWorkspaceId, 'local workspace ID', 256)\n const localPath = requiredString(value.localPath, 'local workspace path', 4096)\n const localNodeId = requiredString(value.localNodeId, 'local workspace node ID', 128)\n const remotePath = requiredString(value.remotePath, 'workspace remote path', 4096)\n const title = requiredString(value.title, 'workspace title', 256)\n if (!posix.isAbsolute(remotePath) || posix.normalize(remotePath) !== remotePath || remotePath.split('/').includes('..')) {\n throw new Error('Invalid workspace remote path')\n }\n const contentDigest = requiredString(value.contentDigest, 'workspace content digest', 256)\n if (!/^sha256:[a-f0-9]{64}$/.test(contentDigest)) throw new Error('Invalid workspace content digest')\n return {\n originInstanceId,\n originWorkspaceId,\n localWorkspaceId,\n localPath,\n localNodeId,\n remotePath,\n title,\n revision: validateRevision(value.revision, 'workspace'),\n contentDigest,\n }\n}\n\nfunction validateArchive(value: unknown, branchId: string): SyncSessionArchive {\n if (!isRecord(value) || value.branchId !== branchId || !/^b-[a-f0-9]{32}$/.test(branchId)) {\n throw new Error('Invalid sync session archive')\n }\n const contentDigest = requiredString(value.contentDigest, 'archive content digest', 256)\n const stateDigest = value.stateDigest === undefined\n ? contentDigest\n : requiredString(value.stateDigest, 'archive state digest', 256)\n const workspacePosition = value.workspacePosition === undefined ? 0 : value.workspacePosition\n if (!/^sha256:[a-f0-9]{64}$/.test(contentDigest) || !/^sha256:[a-f0-9]{64}$/.test(stateDigest) ||\n !isNonNegativeSafeInteger(workspacePosition)) throw new Error('Invalid sync session archive digest or order')\n return {\n branchId,\n originInstanceId: requiredString(value.originInstanceId, 'archive origin instance ID', 128),\n originSessionId: requiredString(value.originSessionId, 'archive origin session ID', 256),\n localSessionId: requiredString(value.localSessionId, 'archive local session ID', 256),\n revision: validateRevision(value.revision, 'archive'),\n contentDigest,\n stateDigest,\n workspacePosition,\n ...(value.workspaceId === undefined ? {} : { workspaceId: requiredString(value.workspaceId, 'archive workspace ID', 256) }),\n ...(value.workspaceOrigin === undefined ? {} : { workspaceOrigin: validateOrigin(value.workspaceOrigin) }),\n archivedAt: requiredString(value.archivedAt, 'archive timestamp', 64),\n }\n}\n\nfunction validateOrigin(value: unknown): { originInstanceId: string; originEntityId: string } {\n if (\n !isRecord(value) || typeof value.originInstanceId !== 'string' || !value.originInstanceId ||\n typeof value.originEntityId !== 'string' || !value.originEntityId ||\n value.originInstanceId.length > 512 || value.originEntityId.length > 512 ||\n /[\\u0000-\\u001f\\u007f]/.test(value.originInstanceId) || /[\\u0000-\\u001f\\u007f]/.test(value.originEntityId)\n ) throw new Error('Invalid sync origin reference')\n return { originInstanceId: value.originInstanceId, originEntityId: value.originEntityId }\n}\n\nfunction requiredString(value: unknown, label: string, maxLength: number): string {\n if (typeof value !== 'string' || !value.trim() || value.length > maxLength || /[\\u0000-\\u001f\\u007f]/.test(value)) {\n throw new Error(`Invalid ${label}`)\n }\n return value\n}\n\nfunction validateSyncState(value: unknown): SyncState {\n if (!isRecord(value) || value.version !== 1) throw new Error('Unsupported sync state version')\n if (\n !isRecord(value.clock) ||\n !isNonNegativeSafeInteger(value.clock.physicalTimeMs) ||\n !isNonNegativeSafeInteger(value.clock.logicalCounter)\n ) {\n throw new Error('Invalid sync clock state')\n }\n if (!isRecord(value.peers) || !isRecord(value.records)) throw new Error('Invalid sync state maps')\n const workspaceValues = value.workspaces === undefined ? {} : value.workspaces\n const archiveValues = value.archives === undefined ? {} : value.archives\n if (!isRecord(workspaceValues) || !isRecord(archiveValues)) throw new Error('Invalid sync session state maps')\n\n const peers = Object.create(null) as Record<string, SyncPeerProgress>\n for (const [id, progress] of Object.entries(value.peers)) {\n if (!/^p-[a-f0-9]{24}$/.test(id)) throw new Error('Invalid sync peer ID in state')\n peers[id] = validateProgress(progress)\n }\n\n const records = Object.create(null) as Record<string, SyncRecordMetadata>\n for (const [key, metadata] of Object.entries(value.records)) {\n const validated = validateRecord(metadata)\n if (key !== syncRecordKey(validated.kind, validated)) throw new Error('Sync record key does not match its origin')\n records[key] = validated\n }\n\n const workspaces = Object.create(null) as Record<string, SyncWorkspaceMapping>\n for (const [key, mapping] of Object.entries(workspaceValues)) {\n const validated = validateWorkspaceMapping(mapping)\n if (key !== syncWorkspaceKey(validated.originInstanceId, validated.originWorkspaceId, validated.remotePath)) {\n throw new Error('Sync workspace mapping key does not match its origin')\n }\n workspaces[key] = validated\n }\n\n const archives = Object.create(null) as Record<string, SyncSessionArchive>\n for (const [branchId, archive] of Object.entries(archiveValues)) archives[branchId] = validateArchive(archive, branchId)\n\n return {\n version: 1,\n clock: { physicalTimeMs: value.clock.physicalTimeMs, logicalCounter: value.clock.logicalCounter },\n peers,\n records,\n workspaces,\n archives,\n }\n}\n\nfunction emptySyncState(): SyncState {\n return { version: 1, clock: { physicalTimeMs: 0, logicalCounter: 0 }, peers: {}, records: {}, workspaces: {}, archives: {} }\n}\n\nexport class SyncStateStore {\n private state: SyncState | undefined\n private readonly home: string\n private readonly filePath: string\n\n constructor(home?: string) {\n this.home = dshHome(home)\n this.filePath = join(this.home, 'dshb', 'sync-state.json')\n }\n\n instanceId(): string {\n return getOrCreateSyncInstanceId(this.home)\n }\n\n read(): SyncState {\n return clone(this.load())\n }\n\n update(mutate: (draft: SyncState) => void): SyncState {\n const next = clone(this.load())\n mutate(next)\n const validated = validateSyncState(next)\n atomicWrite(this.filePath, `${JSON.stringify(validated, null, 2)}\\n`)\n this.state = validated\n return clone(validated)\n }\n\n nextRevision(now = Date.now()): SyncRevision {\n const clock = new HybridLogicalClock(this.instanceId(), this.load().clock)\n const revision = clock.tick(now)\n this.update((state) => {\n state.clock = clock.snapshot()\n })\n return revision\n }\n\n observeRevision(remote: SyncRevision, now = Date.now()): SyncRevision {\n const clock = new HybridLogicalClock(this.instanceId(), this.load().clock)\n const revision = clock.observe(remote, now)\n this.update((state) => {\n state.clock = clock.snapshot()\n })\n return revision\n }\n\n private load(): SyncState {\n if (this.state) return this.state\n const state = readJson(this.filePath, validateSyncState)\n this.state = state ?? emptySyncState()\n return this.state\n }\n}\n\nexport type { HlcSnapshot }\n"],"mappings":";;;;;;;AA8BA,SAAS,QAAQ,MAAuB;CACtC,OAAO,QAAQ,QAAQ,IAAI,YAAY,KAAK,QAAQ,GAAG,MAAM;AAC/D;AAEA,SAAS,SAAY,MAAc,UAAgD;CACjF,IAAI;CACJ,IAAI;EACF,UAAU,aAAa,MAAM,MAAM;CACrC,SAAS,OAAO;EACd,IAAI,YAAY,KAAK,KAAK,MAAM,SAAS,UAAU,OAAO,KAAA;EAC1D,MAAM;CACR;CACA,IAAI;CACJ,IAAI;EACF,QAAQ,KAAK,MAAM,OAAO;CAC5B,QAAQ;EACN,MAAM,IAAI,MAAM,mBAAmB,SAAS,IAAI,GAAG;CACrD;CACA,OAAO,SAAS,KAAK;AACvB;AAEA,SAAS,YAAY,OAAgD;CACnE,OAAO,iBAAiB,SAAS,UAAU;AAC7C;AAEA,SAAS,YAAY,MAAc,SAAuB;CACxD,MAAM,MAAM,QAAQ,IAAI;CACxB,UAAU,KAAK;EAAE,WAAW;EAAM,MAAM;CAAM,CAAC;CAC/C,MAAM,YAAY,GAAG,KAAK,GAAG,QAAQ,IAAI,GAAG,YAAY,CAAC,CAAC,CAAC,SAAS,KAAK,EAAE;CAC3E,IAAI;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/stores.ts"],"sourcesContent":["import { randomBytes } from 'node:crypto'\nimport {\n chmodSync,\n closeSync,\n fsyncSync,\n mkdirSync,\n openSync,\n readFileSync,\n renameSync,\n unlinkSync,\n writeFileSync,\n} from 'node:fs'\nimport { homedir } from 'node:os'\nimport { basename, dirname, join, posix } from 'node:path'\nimport { HybridLogicalClock, type HlcSnapshot, type SyncRevision } from './revision.js'\nimport {\n isNonNegativeSafeInteger,\n isRecord,\n parseSyncPeer,\n syncRecordKey,\n syncWorkspaceKey,\n type SyncCatalog,\n type SyncPeer,\n type SyncPeerDraft,\n type SyncPeerProgress,\n type SyncRecordMetadata,\n type SyncSessionArchive,\n type SyncState,\n type SyncWorkspaceMapping,\n} from './model.js'\n\nfunction dshHome(home?: string): string {\n return home ?? process.env.DSH_HOME ?? join(homedir(), '.dsh')\n}\n\nfunction readJson<T>(file: string, validate: (value: unknown) => T): T | undefined {\n let content: string\n try {\n content = readFileSync(file, 'utf8')\n } catch (error) {\n if (isNodeError(error) && error.code === 'ENOENT') return undefined\n throw error\n }\n let value: unknown\n try {\n value = JSON.parse(content)\n } catch {\n throw new Error(`Invalid JSON in ${basename(file)}`)\n }\n return validate(value)\n}\n\nfunction isNodeError(error: unknown): error is NodeJS.ErrnoException {\n return error instanceof Error && 'code' in error\n}\n\nfunction atomicWrite(file: string, content: string): void {\n const dir = dirname(file)\n mkdirSync(dir, { recursive: true, mode: 0o700 })\n const temporary = `${file}.${process.pid}.${randomBytes(8).toString('hex')}.tmp`\n let fd: number | undefined\n try {\n fd = openSync(temporary, 'wx', 0o600)\n writeFileSync(fd, content, 'utf8')\n fsyncSync(fd)\n closeSync(fd)\n fd = undefined\n renameSync(temporary, file)\n chmodSync(file, 0o600)\n } catch (error) {\n if (fd !== undefined) closeSync(fd)\n try {\n unlinkSync(temporary)\n } catch {}\n throw error\n }\n}\n\nfunction clone<T>(value: T): T {\n return JSON.parse(JSON.stringify(value)) as T\n}\n\nfunction instanceIdFile(home: string): string {\n return join(home, 'dshb', 'instance-id')\n}\n\nfunction parseInstanceId(value: string): string {\n const id = value.trim()\n if (!/^i-[a-f0-9]{32}$/.test(id)) throw new Error('Invalid DSHB sync instance ID')\n return id\n}\n\nexport function getOrCreateSyncInstanceId(home?: string): string {\n const root = dshHome(home)\n const file = instanceIdFile(root)\n try {\n return parseInstanceId(readFileSync(file, 'utf8'))\n } catch (error) {\n if (!(isNodeError(error) && error.code === 'ENOENT')) throw error\n }\n\n mkdirSync(dirname(file), { recursive: true, mode: 0o700 })\n const candidate = `i-${randomBytes(16).toString('hex')}`\n let fd: number | undefined\n try {\n fd = openSync(file, 'wx', 0o600)\n writeFileSync(fd, `${candidate}\\n`, 'utf8')\n fsyncSync(fd)\n closeSync(fd)\n fd = undefined\n chmodSync(file, 0o600)\n return candidate\n } catch (error) {\n if (fd !== undefined) closeSync(fd)\n if (isNodeError(error) && error.code === 'EEXIST') {\n return parseInstanceId(readFileSync(file, 'utf8'))\n }\n throw error\n }\n}\n\nfunction newPeerId(): string {\n return `p-${randomBytes(12).toString('hex')}`\n}\n\nfunction validatePeers(value: unknown): SyncPeer[] {\n if (!Array.isArray(value)) throw new Error('Invalid sync peer store')\n const peers = value.map(parseSyncPeer)\n if (new Set(peers.map((peer) => peer.id)).size !== peers.length) {\n throw new Error('Sync peer store contains duplicate IDs')\n }\n return peers\n}\n\nexport class SyncPeerStore {\n private peers: SyncPeer[] | undefined\n private readonly filePath: string\n\n constructor(home?: string) {\n this.filePath = join(dshHome(home), 'dshb', 'sync-peers.json')\n }\n\n list(): SyncPeer[] {\n return clone(this.load())\n }\n\n get(id: string): SyncPeer | undefined {\n const peer = this.load().find((item) => item.id === id)\n return peer ? clone(peer) : undefined\n }\n\n create(draft: SyncPeerDraft): SyncPeer {\n const peer = parseSyncPeer({ ...draft, id: newPeerId() })\n const next = [...this.load(), peer]\n this.save(next)\n return clone(peer)\n }\n\n update(id: string, patch: Partial<Omit<SyncPeer, 'id'>>): SyncPeer {\n const current = this.load()\n const index = current.findIndex((peer) => peer.id === id)\n if (index < 0) throw new Error(`sync peer ${id} not found`)\n const updated = parseSyncPeer({ ...current[index], ...patch, id })\n const next = [...current]\n next[index] = updated\n this.save(next)\n return clone(updated)\n }\n\n remove(id: string): boolean {\n const current = this.load()\n const next = current.filter((peer) => peer.id !== id)\n if (next.length === current.length) return false\n this.save(next)\n return true\n }\n\n private load(): SyncPeer[] {\n if (this.peers) return this.peers\n const stored = readJson(this.filePath, validatePeers)\n this.peers = stored ?? []\n return this.peers\n }\n\n private save(peers: SyncPeer[]): void {\n atomicWrite(this.filePath, `${JSON.stringify(peers, null, 2)}\\n`)\n this.peers = peers\n }\n}\n\nfunction validateProgress(value: unknown): SyncPeerProgress {\n if (!isRecord(value)) throw new Error('Invalid peer sync progress')\n const progress: SyncPeerProgress = {}\n for (const field of ['lastRunAt', 'lastSuccessAt', 'lastManifestDigest', 'watermark', 'lastErrorCode', 'lastErrorMessage'] as const) {\n const entry = value[field]\n if (entry !== undefined) {\n if (\n typeof entry !== 'string' || !entry ||\n entry.length > (field === 'lastErrorMessage' ? 256 : 512) ||\n /[\\u0000-\\u001f\\u007f]/.test(entry)\n ) {\n throw new Error(`Invalid peer sync progress field: ${field}`)\n }\n progress[field] = entry\n }\n }\n if (value.lastRunStatus !== undefined) {\n if (value.lastRunStatus !== 'running' && value.lastRunStatus !== 'succeeded' && value.lastRunStatus !== 'failed' && value.lastRunStatus !== 'stopped') {\n throw new Error('Invalid peer sync run status')\n }\n progress.lastRunStatus = value.lastRunStatus\n }\n if (value.lastResult !== undefined) {\n if (!isRecord(value.lastResult)) throw new Error('Invalid peer sync run result')\n const counts = ['imported', 'exported', 'skipped', 'pendingRemoval'] as const\n for (const field of counts) {\n if (!isNonNegativeSafeInteger(value.lastResult[field])) throw new Error(`Invalid peer sync result field: ${field}`)\n }\n const sessionCounts = ['importedSessions', 'exportedSessions', 'skippedSessions', 'catalogNodes', 'catalogWorkspaces', 'catalogSessions'] as const\n for (const field of sessionCounts) {\n if (value.lastResult[field] !== undefined && !isNonNegativeSafeInteger(value.lastResult[field])) {\n throw new Error(`Invalid peer sync result field: ${field}`)\n }\n }\n progress.lastResult = {\n imported: value.lastResult.imported as number,\n exported: value.lastResult.exported as number,\n skipped: value.lastResult.skipped as number,\n pendingRemoval: value.lastResult.pendingRemoval as number,\n importedSessions: (value.lastResult.importedSessions as number | undefined) ?? 0,\n exportedSessions: (value.lastResult.exportedSessions as number | undefined) ?? 0,\n skippedSessions: (value.lastResult.skippedSessions as number | undefined) ?? 0,\n catalogNodes: value.lastResult.catalogNodes as number | undefined,\n catalogWorkspaces: value.lastResult.catalogWorkspaces as number | undefined,\n catalogSessions: value.lastResult.catalogSessions as number | undefined,\n }\n }\n return progress\n}\n\nfunction validateRevision(value: unknown, label: string): SyncRevision {\n if (\n !isRecord(value) ||\n !isNonNegativeSafeInteger(value.physicalTimeMs) ||\n !isNonNegativeSafeInteger(value.logicalCounter) ||\n typeof value.writerInstanceId !== 'string' ||\n !value.writerInstanceId ||\n /[\\u0000-\\u001f\\u007f]/.test(value.writerInstanceId)\n ) {\n throw new Error(`Invalid ${label} revision`)\n }\n return {\n physicalTimeMs: value.physicalTimeMs,\n logicalCounter: value.logicalCounter,\n writerInstanceId: value.writerInstanceId,\n }\n}\n\nfunction validateRecord(value: unknown): SyncRecordMetadata {\n if (!isRecord(value)) throw new Error('Invalid sync record metadata')\n if (value.kind !== 'node' && value.kind !== 'session') throw new Error('Invalid sync entity kind')\n const requiredText = ['originInstanceId', 'originEntityId', 'localEntityId', 'contentDigest'] as const\n for (const key of requiredText) {\n if (\n typeof value[key] !== 'string' ||\n !(value[key] as string).trim() ||\n (value[key] as string).length > 4096 ||\n /[\\u0000-\\u001f\\u007f]/.test(value[key] as string)\n ) {\n throw new Error(`Invalid sync record field: ${key}`)\n }\n }\n if (value.stateDigest !== undefined && (typeof value.stateDigest !== 'string' || !/^sha256:[a-f0-9]{64}$/.test(value.stateDigest))) {\n throw new Error('Invalid sync record state digest')\n }\n validateRevision(value.revision, 'sync record')\n if (value.deleted !== undefined && typeof value.deleted !== 'boolean') throw new Error('Invalid sync tombstone')\n if (value.pendingRemoval !== undefined && typeof value.pendingRemoval !== 'boolean') {\n throw new Error('Invalid pending removal state')\n }\n if (value.credentialsRequired !== undefined && typeof value.credentialsRequired !== 'boolean') {\n throw new Error('Invalid sync credential requirement state')\n }\n if (value.workspaceOrigin !== undefined) {\n if (!isRecord(value.workspaceOrigin)) throw new Error('Invalid sync workspace origin')\n validateOrigin(value.workspaceOrigin)\n }\n if (value.importedVia !== undefined && value.importedVia !== 'peer' && value.importedVia !== 'offline') {\n throw new Error('Invalid sync import method')\n }\n if (\n value.sourceName !== undefined &&\n (typeof value.sourceName !== 'string' || value.sourceName.length > 256 || /[\\u0000-\\u001f\\u007f]/.test(value.sourceName))\n ) {\n throw new Error('Invalid sync source name')\n }\n return clone(value) as unknown as SyncRecordMetadata\n}\n\nfunction validateWorkspaceMapping(value: unknown): SyncWorkspaceMapping {\n if (!isRecord(value)) throw new Error('Invalid sync workspace mapping')\n const originInstanceId = requiredString(value.originInstanceId, 'workspace origin instance ID', 128)\n const originWorkspaceId = requiredString(value.originWorkspaceId, 'workspace origin ID', 256)\n const localWorkspaceId = requiredString(value.localWorkspaceId, 'local workspace ID', 256)\n const localPath = requiredString(value.localPath, 'local workspace path', 4096)\n const localNodeId = requiredString(value.localNodeId, 'local workspace node ID', 128)\n const remotePath = requiredString(value.remotePath, 'workspace remote path', 4096)\n const title = requiredString(value.title, 'workspace title', 256)\n if (!posix.isAbsolute(remotePath) || posix.normalize(remotePath) !== remotePath || remotePath.split('/').includes('..')) {\n throw new Error('Invalid workspace remote path')\n }\n const contentDigest = requiredString(value.contentDigest, 'workspace content digest', 256)\n if (!/^sha256:[a-f0-9]{64}$/.test(contentDigest)) throw new Error('Invalid workspace content digest')\n return {\n originInstanceId,\n originWorkspaceId,\n localWorkspaceId,\n localPath,\n localNodeId,\n remotePath,\n title,\n revision: validateRevision(value.revision, 'workspace'),\n contentDigest,\n }\n}\n\nfunction validateArchive(value: unknown, branchId: string): SyncSessionArchive {\n if (!isRecord(value) || value.branchId !== branchId || !/^b-[a-f0-9]{32}$/.test(branchId)) {\n throw new Error('Invalid sync session archive')\n }\n const contentDigest = requiredString(value.contentDigest, 'archive content digest', 256)\n const stateDigest = value.stateDigest === undefined\n ? contentDigest\n : requiredString(value.stateDigest, 'archive state digest', 256)\n const workspacePosition = value.workspacePosition === undefined ? 0 : value.workspacePosition\n if (!/^sha256:[a-f0-9]{64}$/.test(contentDigest) || !/^sha256:[a-f0-9]{64}$/.test(stateDigest) ||\n !isNonNegativeSafeInteger(workspacePosition)) throw new Error('Invalid sync session archive digest or order')\n return {\n branchId,\n originInstanceId: requiredString(value.originInstanceId, 'archive origin instance ID', 128),\n originSessionId: requiredString(value.originSessionId, 'archive origin session ID', 256),\n localSessionId: requiredString(value.localSessionId, 'archive local session ID', 256),\n revision: validateRevision(value.revision, 'archive'),\n contentDigest,\n stateDigest,\n workspacePosition,\n ...(value.workspaceId === undefined ? {} : { workspaceId: requiredString(value.workspaceId, 'archive workspace ID', 256) }),\n ...(value.workspaceOrigin === undefined ? {} : { workspaceOrigin: validateOrigin(value.workspaceOrigin) }),\n archivedAt: requiredString(value.archivedAt, 'archive timestamp', 64),\n }\n}\n\nfunction validateOrigin(value: unknown): { originInstanceId: string; originEntityId: string } {\n if (\n !isRecord(value) || typeof value.originInstanceId !== 'string' || !value.originInstanceId ||\n typeof value.originEntityId !== 'string' || !value.originEntityId ||\n value.originInstanceId.length > 512 || value.originEntityId.length > 512 ||\n /[\\u0000-\\u001f\\u007f]/.test(value.originInstanceId) || /[\\u0000-\\u001f\\u007f]/.test(value.originEntityId)\n ) throw new Error('Invalid sync origin reference')\n return { originInstanceId: value.originInstanceId, originEntityId: value.originEntityId }\n}\n\nfunction requiredString(value: unknown, label: string, maxLength: number): string {\n if (typeof value !== 'string' || !value.trim() || value.length > maxLength || /[\\u0000-\\u001f\\u007f]/.test(value)) {\n throw new Error(`Invalid ${label}`)\n }\n return value\n}\n\nfunction validateCatalog(value: unknown): SyncCatalog {\n if (!isRecord(value) || value.protocolVersion !== 1 || typeof value.instanceId !== 'string' ||\n !/^i-[a-f0-9]{32}$/.test(value.instanceId) || !Array.isArray(value.nodes) ||\n !Array.isArray(value.workspaces) || !Array.isArray(value.sessions)) {\n throw new Error('Invalid sync catalog payload')\n }\n return value as unknown as SyncCatalog\n}\n\nfunction validateSyncState(value: unknown): SyncState {\n if (!isRecord(value) || value.version !== 1) throw new Error('Unsupported sync state version')\n if (\n !isRecord(value.clock) ||\n !isNonNegativeSafeInteger(value.clock.physicalTimeMs) ||\n !isNonNegativeSafeInteger(value.clock.logicalCounter)\n ) {\n throw new Error('Invalid sync clock state')\n }\n if (!isRecord(value.peers) || !isRecord(value.records)) throw new Error('Invalid sync state maps')\n const workspaceValues = value.workspaces === undefined ? {} : value.workspaces\n const archiveValues = value.archives === undefined ? {} : value.archives\n const catalogValues = value.catalogs === undefined ? {} : value.catalogs\n if (!isRecord(workspaceValues) || !isRecord(archiveValues) || !isRecord(catalogValues)) throw new Error('Invalid sync session state maps')\n\n const peers = Object.create(null) as Record<string, SyncPeerProgress>\n for (const [id, progress] of Object.entries(value.peers)) {\n if (!/^p-[a-f0-9]{24}$/.test(id)) throw new Error('Invalid sync peer ID in state')\n peers[id] = validateProgress(progress)\n }\n\n const records = Object.create(null) as Record<string, SyncRecordMetadata>\n for (const [key, metadata] of Object.entries(value.records)) {\n const validated = validateRecord(metadata)\n if (key !== syncRecordKey(validated.kind, validated)) throw new Error('Sync record key does not match its origin')\n records[key] = validated\n }\n\n const workspaces = Object.create(null) as Record<string, SyncWorkspaceMapping>\n for (const [key, mapping] of Object.entries(workspaceValues)) {\n const validated = validateWorkspaceMapping(mapping)\n if (key !== syncWorkspaceKey(validated.originInstanceId, validated.originWorkspaceId, validated.remotePath)) {\n throw new Error('Sync workspace mapping key does not match its origin')\n }\n workspaces[key] = validated\n }\n\n const archives = Object.create(null) as Record<string, SyncSessionArchive>\n for (const [branchId, archive] of Object.entries(archiveValues)) archives[branchId] = validateArchive(archive, branchId)\n\n const catalogs = Object.create(null) as Record<string, { fetchedAt: string; catalog: SyncCatalog }>\n for (const [peerId, entryValue] of Object.entries(catalogValues)) {\n if (!/^p-[a-f0-9]{24}$/.test(peerId)) throw new Error('Invalid sync peer ID in catalog state')\n if (!isRecord(entryValue) || typeof entryValue.fetchedAt !== 'string') throw new Error('Invalid sync catalog entry')\n catalogs[peerId] = { fetchedAt: entryValue.fetchedAt, catalog: validateCatalog(entryValue.catalog) }\n }\n\n return {\n version: 1,\n clock: { physicalTimeMs: value.clock.physicalTimeMs, logicalCounter: value.clock.logicalCounter },\n peers,\n records,\n workspaces,\n archives,\n catalogs,\n }\n}\n\nfunction emptySyncState(): SyncState {\n return { version: 1, clock: { physicalTimeMs: 0, logicalCounter: 0 }, peers: {}, records: {}, workspaces: {}, archives: {}, catalogs: {} }\n}\n\nexport class SyncStateStore {\n private state: SyncState | undefined\n private readonly home: string\n private readonly filePath: string\n\n constructor(home?: string) {\n this.home = dshHome(home)\n this.filePath = join(this.home, 'dshb', 'sync-state.json')\n }\n\n instanceId(): string {\n return getOrCreateSyncInstanceId(this.home)\n }\n\n read(): SyncState {\n return clone(this.load())\n }\n\n update(mutate: (draft: SyncState) => void): SyncState {\n const next = clone(this.load())\n mutate(next)\n const validated = validateSyncState(next)\n atomicWrite(this.filePath, `${JSON.stringify(validated, null, 2)}\\n`)\n this.state = validated\n return clone(validated)\n }\n\n nextRevision(now = Date.now()): SyncRevision {\n const clock = new HybridLogicalClock(this.instanceId(), this.load().clock)\n const revision = clock.tick(now)\n this.update((state) => {\n state.clock = clock.snapshot()\n })\n return revision\n }\n\n observeRevision(remote: SyncRevision, now = Date.now()): SyncRevision {\n const clock = new HybridLogicalClock(this.instanceId(), this.load().clock)\n const revision = clock.observe(remote, now)\n this.update((state) => {\n state.clock = clock.snapshot()\n })\n return revision\n }\n\n private load(): SyncState {\n if (this.state) return this.state\n const state = readJson(this.filePath, validateSyncState)\n this.state = state ?? emptySyncState()\n return this.state\n }\n}\n\nexport type { HlcSnapshot }\n"],"mappings":";;;;;;;AA+BA,SAAS,QAAQ,MAAuB;CACtC,OAAO,QAAQ,QAAQ,IAAI,YAAY,KAAK,QAAQ,GAAG,MAAM;AAC/D;AAEA,SAAS,SAAY,MAAc,UAAgD;CACjF,IAAI;CACJ,IAAI;EACF,UAAU,aAAa,MAAM,MAAM;CACrC,SAAS,OAAO;EACd,IAAI,YAAY,KAAK,KAAK,MAAM,SAAS,UAAU,OAAO,KAAA;EAC1D,MAAM;CACR;CACA,IAAI;CACJ,IAAI;EACF,QAAQ,KAAK,MAAM,OAAO;CAC5B,QAAQ;EACN,MAAM,IAAI,MAAM,mBAAmB,SAAS,IAAI,GAAG;CACrD;CACA,OAAO,SAAS,KAAK;AACvB;AAEA,SAAS,YAAY,OAAgD;CACnE,OAAO,iBAAiB,SAAS,UAAU;AAC7C;AAEA,SAAS,YAAY,MAAc,SAAuB;CACxD,MAAM,MAAM,QAAQ,IAAI;CACxB,UAAU,KAAK;EAAE,WAAW;EAAM,MAAM;CAAM,CAAC;CAC/C,MAAM,YAAY,GAAG,KAAK,GAAG,QAAQ,IAAI,GAAG,YAAY,CAAC,CAAC,CAAC,SAAS,KAAK,EAAE;CAC3E,IAAI;CACJ,IAAI;EACF,KAAK,SAAS,WAAW,MAAM,GAAK;EACpC,cAAc,IAAI,SAAS,MAAM;EACjC,UAAU,EAAE;EACZ,UAAU,EAAE;EACZ,KAAK,KAAA;EACL,WAAW,WAAW,IAAI;EAC1B,UAAU,MAAM,GAAK;CACvB,SAAS,OAAO;EACd,IAAI,OAAO,KAAA,GAAW,UAAU,EAAE;EAClC,IAAI;GACF,WAAW,SAAS;EACtB,QAAQ,CAAC;EACT,MAAM;CACR;AACF;AAEA,SAAS,MAAS,OAAa;CAC7B,OAAO,KAAK,MAAM,KAAK,UAAU,KAAK,CAAC;AACzC;AAEA,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gB,QAAsB,MAAM,KAAK,IAAI,GAAiB;EACpE,MAAM,QAAQ,IAAI,mBAAmB,KAAK,WAAW,GAAG,KAAK,KAAK,CAAC,CAAC,KAAK;EACzE,MAAM,WAAW,MAAM,QAAQ,QAAQ,GAAG;EAC1C,KAAK,QAAQ,UAAU;GACrB,MAAM,QAAQ,MAAM,SAAS;EAC/B,CAAC;EACD,OAAO;CACT;CAEA,OAA0B;EACxB,IAAI,KAAK,OAAO,OAAO,KAAK;EAC5B,MAAM,QAAQ,SAAS,KAAK,UAAU,iBAAiB;EACvD,KAAK,QAAQ,SAAS,eAAe;EACrC,OAAO,KAAK;CACd;AACF"}
|
package/lib/core/workspaces.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { o as NodeRegistry } from "../node-registry-BTnnM5-k.js";
|
|
2
2
|
import { r as WorkspaceBindingsStore } from "../workspace-bindings-CsB0TIJB.js";
|
|
3
|
-
import { s as SyncNodeService } from "../node-sync-
|
|
3
|
+
import { s as SyncNodeService } from "../node-sync-WdEv-ek7.js";
|
|
4
4
|
import { Context } from "@deepseek-ai/cordis";
|
|
5
5
|
//#region src/core/workspaces.d.ts
|
|
6
6
|
declare function registerWorkspaceRoutes(ctx: Context, registry: NodeRegistry, bindings: WorkspaceBindingsStore, syncNodes?: SyncNodeService): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { u as SyncPeer } from "./model-D1T078kt.js";
|
|
2
2
|
//#region src/core/sync/host-key.d.ts
|
|
3
3
|
type SyncHostKeyDecision = 'trusted' | 'untrusted' | 'changed';
|
|
4
4
|
declare class SyncHostKeyChallengeError extends Error {
|
|
@@ -27,4 +27,4 @@ declare class SyncHostKeyChallenges {
|
|
|
27
27
|
}
|
|
28
28
|
//#endregion
|
|
29
29
|
export { inspectSyncHostKey as a, SyncHostKeyDecision as i, SyncHostKeyChallengeExpiredError as n, isOpenSshFingerprint as o, SyncHostKeyChallenges as r, opensshFingerprintFromSha256Hex as s, SyncHostKeyChallengeError as t };
|
|
30
|
-
//# sourceMappingURL=host-key-
|
|
30
|
+
//# sourceMappingURL=host-key-Dh2YTRX7.d.ts.map
|
|
@@ -4,6 +4,12 @@ type SyncDirection = 'pull' | 'bidirectional';
|
|
|
4
4
|
type SyncSchedule = 'manual' | 'every-5m';
|
|
5
5
|
type SyncEntityKind = 'node' | 'session';
|
|
6
6
|
type SyncImportMethod = 'peer' | 'offline';
|
|
7
|
+
/** 全量同步传输会话内容;元数据同步只同步目录,点击会话时经 wss 实时操作远端。 */
|
|
8
|
+
type SyncMode = 'full' | 'metadata';
|
|
9
|
+
interface SyncOrigin {
|
|
10
|
+
originInstanceId: string;
|
|
11
|
+
originEntityId: string;
|
|
12
|
+
}
|
|
7
13
|
interface SyncPeer {
|
|
8
14
|
id: string;
|
|
9
15
|
name: string;
|
|
@@ -16,15 +22,67 @@ interface SyncPeer {
|
|
|
16
22
|
remoteWebPort?: number;
|
|
17
23
|
direction: SyncDirection;
|
|
18
24
|
schedule: SyncSchedule;
|
|
25
|
+
mode: SyncMode;
|
|
19
26
|
syncSessions: boolean;
|
|
27
|
+
selection?: SyncSelection;
|
|
20
28
|
enabled: boolean;
|
|
21
29
|
hostKeyFingerprint?: string;
|
|
22
30
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
31
|
+
interface SyncWorkspaceOrigin extends SyncOrigin {
|
|
32
|
+
remotePath: string;
|
|
33
|
+
}
|
|
34
|
+
interface SyncSelection {
|
|
35
|
+
mode: 'all' | 'selected';
|
|
36
|
+
nodes: SyncOrigin[];
|
|
37
|
+
workspaces: SyncWorkspaceOrigin[];
|
|
38
|
+
sessions: SyncOrigin[];
|
|
39
|
+
}
|
|
40
|
+
interface SyncCatalogNode {
|
|
41
|
+
origin: SyncOrigin;
|
|
42
|
+
name: string;
|
|
43
|
+
type: 'remote-ssh' | 'remote-docker';
|
|
44
|
+
}
|
|
45
|
+
interface SyncCatalogWorkspace {
|
|
46
|
+
origin: SyncOrigin;
|
|
47
|
+
nodeOrigin: SyncOrigin;
|
|
48
|
+
remotePath: string;
|
|
49
|
+
title: string;
|
|
50
|
+
}
|
|
51
|
+
interface SyncCatalogSession {
|
|
52
|
+
origin: SyncOrigin;
|
|
53
|
+
workspaceOrigin?: SyncOrigin;
|
|
54
|
+
workspaceRemotePath?: string;
|
|
55
|
+
nodeOrigin?: SyncOrigin;
|
|
56
|
+
sessionId: string;
|
|
57
|
+
sizeBytes?: number;
|
|
58
|
+
branchId?: string;
|
|
59
|
+
deleted?: boolean;
|
|
27
60
|
}
|
|
61
|
+
interface SyncCatalog {
|
|
62
|
+
protocolVersion: 1;
|
|
63
|
+
instanceId: string;
|
|
64
|
+
nodes: SyncCatalogNode[];
|
|
65
|
+
workspaces: SyncCatalogWorkspace[];
|
|
66
|
+
sessions: SyncCatalogSession[];
|
|
67
|
+
}
|
|
68
|
+
interface SyncPeer {
|
|
69
|
+
id: string;
|
|
70
|
+
name: string;
|
|
71
|
+
host: string;
|
|
72
|
+
port: number;
|
|
73
|
+
username: string;
|
|
74
|
+
authKind: 'password' | 'key';
|
|
75
|
+
remoteDshHome?: string;
|
|
76
|
+
remoteProfile?: string;
|
|
77
|
+
remoteWebPort?: number;
|
|
78
|
+
direction: SyncDirection;
|
|
79
|
+
schedule: SyncSchedule;
|
|
80
|
+
syncSessions: boolean;
|
|
81
|
+
selection?: SyncSelection;
|
|
82
|
+
enabled: boolean;
|
|
83
|
+
hostKeyFingerprint?: string;
|
|
84
|
+
}
|
|
85
|
+
type SyncPeerDraft = Omit<SyncPeer, 'id' | 'hostKeyFingerprint'>;
|
|
28
86
|
interface SyncProvenance extends SyncOrigin {
|
|
29
87
|
localEntityId: string;
|
|
30
88
|
importedVia?: SyncImportMethod;
|
|
@@ -56,6 +114,10 @@ interface SyncPeerProgress {
|
|
|
56
114
|
importedSessions: number;
|
|
57
115
|
exportedSessions: number;
|
|
58
116
|
skippedSessions: number;
|
|
117
|
+
/** 元数据同步最近一次目录计数(可选,旧状态缺省)。 */
|
|
118
|
+
catalogNodes?: number;
|
|
119
|
+
catalogWorkspaces?: number;
|
|
120
|
+
catalogSessions?: number;
|
|
59
121
|
};
|
|
60
122
|
}
|
|
61
123
|
interface SyncWorkspaceMapping {
|
|
@@ -92,7 +154,13 @@ interface SyncState {
|
|
|
92
154
|
records: Record<string, SyncRecordMetadata>;
|
|
93
155
|
workspaces: Record<string, SyncWorkspaceMapping>;
|
|
94
156
|
archives: Record<string, SyncSessionArchive>;
|
|
157
|
+
/** 元数据同步的远端目录缓存:peer ID → 最近一次拉取的目录快照。 */
|
|
158
|
+
catalogs: Record<string, {
|
|
159
|
+
fetchedAt: string;
|
|
160
|
+
catalog: SyncCatalog;
|
|
161
|
+
}>;
|
|
95
162
|
}
|
|
163
|
+
declare function parseSyncSelection(value: unknown): SyncSelection;
|
|
96
164
|
declare function parseSyncPeer(value: unknown): SyncPeer;
|
|
97
165
|
declare function parseSyncPeerDraft(value: unknown): SyncPeerDraft;
|
|
98
166
|
declare function syncRecordKey(kind: SyncEntityKind, origin: SyncOrigin): string;
|
|
@@ -100,5 +168,5 @@ declare function syncWorkspaceKey(originInstanceId: string, originWorkspaceId: s
|
|
|
100
168
|
declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
101
169
|
declare function isNonNegativeSafeInteger(value: unknown): value is number;
|
|
102
170
|
//#endregion
|
|
103
|
-
export {
|
|
104
|
-
//# sourceMappingURL=model-
|
|
171
|
+
export { parseSyncPeer as C, syncWorkspaceKey as D, syncRecordKey as E, isRecord as S, parseSyncSelection as T, SyncSessionArchive as _, SyncDirection as a, SyncWorkspaceOrigin as b, SyncMode as c, SyncPeerDraft as d, SyncPeerProgress as f, SyncSelection as g, SyncSchedule as h, SyncCatalogWorkspace as i, SyncOrigin as l, SyncRecordMetadata as m, SyncCatalogNode as n, SyncEntityKind as o, SyncProvenance as p, SyncCatalogSession as r, SyncImportMethod as s, SyncCatalog as t, SyncPeer as u, SyncState as v, parseSyncPeerDraft as w, isNonNegativeSafeInteger as x, SyncWorkspaceMapping as y };
|
|
172
|
+
//# sourceMappingURL=model-D1T078kt.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { c as NodeSsh, o as NodeRegistry, r as NodeDocker, s as NodeSecrets } from "./node-registry-BTnnM5-k.js";
|
|
2
2
|
import { r as WorkspaceBindingsStore } from "./workspace-bindings-CsB0TIJB.js";
|
|
3
|
-
import {
|
|
4
|
-
import { n as SyncStateStore } from "./stores-
|
|
3
|
+
import { m as SyncRecordMetadata, s as SyncImportMethod } from "./model-D1T078kt.js";
|
|
4
|
+
import { n as SyncStateStore } from "./stores-CUY_YFD-.js";
|
|
5
5
|
//#region src/core/sync/node-sync.d.ts
|
|
6
6
|
interface SyncNodeProfile {
|
|
7
7
|
name: string;
|
|
@@ -86,4 +86,4 @@ declare class SyncNodeService {
|
|
|
86
86
|
}
|
|
87
87
|
//#endregion
|
|
88
88
|
export { SyncNodeManifestError as a, SyncNodeView as c, SyncNodeManifest as i, SyncNodeEntry as n, SyncNodeProfile as o, SyncNodeInUseError as r, SyncNodeService as s, SyncNodeApplyResult as t };
|
|
89
|
-
//# sourceMappingURL=node-sync-
|
|
89
|
+
//# sourceMappingURL=node-sync-WdEv-ek7.d.ts.map
|
|
@@ -4,6 +4,7 @@ declare const SYNC_SESSION_MANIFEST_CAPABILITY = "session-manifest-v1";
|
|
|
4
4
|
declare const SYNC_SESSION_EVENT_TAIL_CAPABILITY = "session-event-tail-delta-v1";
|
|
5
5
|
declare const SYNC_SESSION_BUNDLE_OBJECTS_CAPABILITY = "session-bundle-objects-v1";
|
|
6
6
|
declare const SYNC_SESSION_OBJECT_STREAM_CAPABILITY = "session-object-stream-v1";
|
|
7
|
+
declare const SYNC_CATALOG_CAPABILITY = "sync-selection-catalog-v1";
|
|
7
8
|
declare const MAX_SYNC_CONTROL_FRAME_BYTES: number;
|
|
8
9
|
declare const MAX_SYNC_DATA_CHUNK_BYTES: number;
|
|
9
10
|
declare const MAX_SYNC_TRANSFER_BYTES: number;
|
|
@@ -37,5 +38,5 @@ declare class SyncFrameDecoder {
|
|
|
37
38
|
private resetFrame;
|
|
38
39
|
}
|
|
39
40
|
//#endregion
|
|
40
|
-
export { MAX_SYNC_TRANSFER_BYTES as a,
|
|
41
|
-
//# sourceMappingURL=protocol-
|
|
41
|
+
export { MAX_SYNC_TRANSFER_BYTES as a, SYNC_SESSION_BUNDLE_OBJECTS_CAPABILITY as c, SYNC_SESSION_OBJECT_STREAM_CAPABILITY as d, SyncFrame as f, encodeSyncDataFrame as g, encodeSyncControlFrame as h, MAX_SYNC_DATA_CHUNK_BYTES as i, SYNC_SESSION_EVENT_TAIL_CAPABILITY as l, SyncProtocolError as m, MAX_SESSION_OBJECT_STREAM_BYTES as n, SYNC_CATALOG_CAPABILITY as o, SyncFrameDecoder as p, MAX_SYNC_CONTROL_FRAME_BYTES as r, SYNC_PROTOCOL_VERSION as s, MAX_SESSION_OBJECT_INLINE_BYTES as t, SYNC_SESSION_MANIFEST_CAPABILITY as u };
|
|
42
|
+
//# sourceMappingURL=protocol-DyPDIJWa.d.ts.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { syncWorkspaceKey } from "./core/sync/model.js";
|
|
2
|
+
//#region src/core/sync/selection.ts
|
|
3
|
+
function syncOriginKey(origin) {
|
|
4
|
+
return JSON.stringify([origin.originInstanceId, origin.originEntityId]);
|
|
5
|
+
}
|
|
6
|
+
function resolveSyncSelection(selection, catalog) {
|
|
7
|
+
if (!selection || selection.mode === "all") return {
|
|
8
|
+
all: true,
|
|
9
|
+
nodes: /* @__PURE__ */ new Set(),
|
|
10
|
+
workspaces: /* @__PURE__ */ new Set(),
|
|
11
|
+
sessions: /* @__PURE__ */ new Set()
|
|
12
|
+
};
|
|
13
|
+
const nodes = new Set(selection.nodes.map((origin) => syncOriginKey(origin)));
|
|
14
|
+
const workspaces = new Set(selection.workspaces.map((workspace) => syncWorkspaceKey(workspace.originInstanceId, workspace.originEntityId, workspace.remotePath)));
|
|
15
|
+
const sessions = new Set(selection.sessions.map((origin) => syncOriginKey(origin)));
|
|
16
|
+
for (const workspace of catalog.workspaces) {
|
|
17
|
+
const workspaceKey = syncWorkspaceKey(workspace.origin.originInstanceId, workspace.origin.originEntityId, workspace.remotePath);
|
|
18
|
+
if (workspaces.has(workspaceKey)) nodes.add(syncOriginKey(workspace.nodeOrigin));
|
|
19
|
+
}
|
|
20
|
+
for (const session of catalog.sessions) {
|
|
21
|
+
const sessionKey = syncOriginKey(session.origin);
|
|
22
|
+
if (session.workspaceOrigin && selection.workspaces.some((workspace) => syncOriginKey(workspace) === syncOriginKey(session.workspaceOrigin) && (session.workspaceRemotePath === void 0 || workspace.remotePath === session.workspaceRemotePath))) sessions.add(sessionKey);
|
|
23
|
+
if (sessions.has(sessionKey)) {
|
|
24
|
+
if (session.workspaceOrigin && session.workspaceRemotePath) workspaces.add(syncWorkspaceKey(session.workspaceOrigin.originInstanceId, session.workspaceOrigin.originEntityId, session.workspaceRemotePath));
|
|
25
|
+
if (session.nodeOrigin) nodes.add(syncOriginKey(session.nodeOrigin));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
for (const workspace of catalog.workspaces) {
|
|
29
|
+
const key = syncWorkspaceKey(workspace.origin.originInstanceId, workspace.origin.originEntityId, workspace.remotePath);
|
|
30
|
+
if (workspaces.has(key)) nodes.add(syncOriginKey(workspace.nodeOrigin));
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
all: false,
|
|
34
|
+
nodes,
|
|
35
|
+
workspaces,
|
|
36
|
+
sessions
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function selectionIncludesNode(metadata, selection) {
|
|
40
|
+
return selection.all || selection.nodes.has(syncOriginKey(metadata));
|
|
41
|
+
}
|
|
42
|
+
function selectionIncludesSession(metadata, selection) {
|
|
43
|
+
return selection.all || selection.sessions.has(syncOriginKey(metadata));
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
export { syncOriginKey as i, selectionIncludesNode as n, selectionIncludesSession as r, resolveSyncSelection as t };
|
|
47
|
+
|
|
48
|
+
//# sourceMappingURL=selection-BABQH1Rt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selection-BABQH1Rt.js","names":[],"sources":["../src/core/sync/selection.ts"],"sourcesContent":["import { syncWorkspaceKey, type SyncCatalog, type SyncOrigin, type SyncRecordMetadata, type SyncSelection } from './model.js'\n\nexport interface ResolvedSyncSelection {\n all: boolean\n nodes: Set<string>\n workspaces: Set<string>\n sessions: Set<string>\n}\n\nexport function syncOriginKey(origin: SyncOrigin): string {\n return JSON.stringify([origin.originInstanceId, origin.originEntityId])\n}\n\nexport function resolveSyncSelection(selection: SyncSelection | undefined, catalog: SyncCatalog): ResolvedSyncSelection {\n if (!selection || selection.mode === 'all') {\n return { all: true, nodes: new Set(), workspaces: new Set(), sessions: new Set() }\n }\n\n const nodes = new Set(selection.nodes.map((origin) => syncOriginKey(origin)))\n const workspaces = new Set(selection.workspaces.map((workspace) =>\n syncWorkspaceKey(workspace.originInstanceId, workspace.originEntityId, workspace.remotePath)))\n const sessions = new Set(selection.sessions.map((origin) => syncOriginKey(origin)))\n\n for (const workspace of catalog.workspaces) {\n const workspaceKey = syncWorkspaceKey(workspace.origin.originInstanceId, workspace.origin.originEntityId, workspace.remotePath)\n if (workspaces.has(workspaceKey)) nodes.add(syncOriginKey(workspace.nodeOrigin))\n }\n for (const session of catalog.sessions) {\n const sessionKey = syncOriginKey(session.origin)\n const matchesWorkspace = session.workspaceOrigin && selection.workspaces.some((workspace) =>\n syncOriginKey(workspace) === syncOriginKey(session.workspaceOrigin!) &&\n (session.workspaceRemotePath === undefined || workspace.remotePath === session.workspaceRemotePath))\n if (matchesWorkspace) sessions.add(sessionKey)\n if (sessions.has(sessionKey)) {\n if (session.workspaceOrigin && session.workspaceRemotePath) {\n workspaces.add(syncWorkspaceKey(\n session.workspaceOrigin.originInstanceId,\n session.workspaceOrigin.originEntityId,\n session.workspaceRemotePath,\n ))\n }\n if (session.nodeOrigin) nodes.add(syncOriginKey(session.nodeOrigin))\n }\n }\n\n for (const workspace of catalog.workspaces) {\n const key = syncWorkspaceKey(workspace.origin.originInstanceId, workspace.origin.originEntityId, workspace.remotePath)\n if (workspaces.has(key)) nodes.add(syncOriginKey(workspace.nodeOrigin))\n }\n\n return { all: false, nodes, workspaces, sessions }\n}\n\nexport function selectionIncludesNode(metadata: SyncRecordMetadata, selection: ResolvedSyncSelection): boolean {\n return selection.all || selection.nodes.has(syncOriginKey(metadata))\n}\n\nexport function selectionIncludesSession(metadata: SyncRecordMetadata, selection: ResolvedSyncSelection): boolean {\n return selection.all || selection.sessions.has(syncOriginKey(metadata))\n}\n"],"mappings":";;AASA,SAAgB,cAAc,QAA4B;CACxD,OAAO,KAAK,UAAU,CAAC,OAAO,kBAAkB,OAAO,cAAc,CAAC;AACxE;AAEA,SAAgB,qBAAqB,WAAsC,SAA6C;CACtH,IAAI,CAAC,aAAa,UAAU,SAAS,OACnC,OAAO;EAAE,KAAK;EAAM,uBAAO,IAAI,IAAI;EAAG,4BAAY,IAAI,IAAI;EAAG,0BAAU,IAAI,IAAI;CAAE;CAGnF,MAAM,QAAQ,IAAI,IAAI,UAAU,MAAM,KAAK,WAAW,cAAc,MAAM,CAAC,CAAC;CAC5E,MAAM,aAAa,IAAI,IAAI,UAAU,WAAW,KAAK,cACnD,iBAAiB,UAAU,kBAAkB,UAAU,gBAAgB,UAAU,UAAU,CAAC,CAAC;CAC/F,MAAM,WAAW,IAAI,IAAI,UAAU,SAAS,KAAK,WAAW,cAAc,MAAM,CAAC,CAAC;CAElF,KAAK,MAAM,aAAa,QAAQ,YAAY;EAC1C,MAAM,eAAe,iBAAiB,UAAU,OAAO,kBAAkB,UAAU,OAAO,gBAAgB,UAAU,UAAU;EAC9H,IAAI,WAAW,IAAI,YAAY,GAAG,MAAM,IAAI,cAAc,UAAU,UAAU,CAAC;CACjF;CACA,KAAK,MAAM,WAAW,QAAQ,UAAU;EACtC,MAAM,aAAa,cAAc,QAAQ,MAAM;EAI/C,IAHyB,QAAQ,mBAAmB,UAAU,WAAW,MAAM,cAC7E,cAAc,SAAS,MAAM,cAAc,QAAQ,eAAgB,MAClE,QAAQ,wBAAwB,KAAA,KAAa,UAAU,eAAe,QAAQ,oBAAoB,GAC/E,SAAS,IAAI,UAAU;EAC7C,IAAI,SAAS,IAAI,UAAU,GAAG;GAC5B,IAAI,QAAQ,mBAAmB,QAAQ,qBACrC,WAAW,IAAI,iBACb,QAAQ,gBAAgB,kBACxB,QAAQ,gBAAgB,gBACxB,QAAQ,mBACV,CAAC;GAEH,IAAI,QAAQ,YAAY,MAAM,IAAI,cAAc,QAAQ,UAAU,CAAC;EACrE;CACF;CAEA,KAAK,MAAM,aAAa,QAAQ,YAAY;EAC1C,MAAM,MAAM,iBAAiB,UAAU,OAAO,kBAAkB,UAAU,OAAO,gBAAgB,UAAU,UAAU;EACrH,IAAI,WAAW,IAAI,GAAG,GAAG,MAAM,IAAI,cAAc,UAAU,UAAU,CAAC;CACxE;CAEA,OAAO;EAAE,KAAK;EAAO;EAAO;EAAY;CAAS;AACnD;AAEA,SAAgB,sBAAsB,UAA8B,WAA2C;CAC7G,OAAO,UAAU,OAAO,UAAU,MAAM,IAAI,cAAc,QAAQ,CAAC;AACrE;AAEA,SAAgB,yBAAyB,UAA8B,WAA2C;CAChH,OAAO,UAAU,OAAO,UAAU,SAAS,IAAI,cAAc,QAAQ,CAAC;AACxE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { s as SyncImportMethod } from "./model-D1T078kt.js";
|
|
2
2
|
//#region src/core/sync/session-journal.d.ts
|
|
3
3
|
declare class SyncSessionJournalStore {
|
|
4
4
|
private readonly home;
|
|
@@ -43,4 +43,4 @@ declare class SyncSessionJournalStore {
|
|
|
43
43
|
}
|
|
44
44
|
//#endregion
|
|
45
45
|
export { SyncSessionJournalStore as t };
|
|
46
|
-
//# sourceMappingURL=session-journal-
|
|
46
|
+
//# sourceMappingURL=session-journal-CTblFLJg.d.ts.map
|
|
@@ -1901,6 +1901,42 @@ var SyncSessionService = class SyncSessionService {
|
|
|
1901
1901
|
listArchives() {
|
|
1902
1902
|
return Object.values(this.state.read().archives).sort((a, b) => a.archivedAt.localeCompare(b.archivedAt));
|
|
1903
1903
|
}
|
|
1904
|
+
exportCatalog() {
|
|
1905
|
+
return this.serializeMutation(async () => {
|
|
1906
|
+
const catalog = {
|
|
1907
|
+
workspaces: /* @__PURE__ */ new Map(),
|
|
1908
|
+
sessions: []
|
|
1909
|
+
};
|
|
1910
|
+
for (const mapping of Object.values(this.state.read().workspaces)) {
|
|
1911
|
+
const nodeOrigin = this.nodes.originForLocalNode(mapping.localNodeId);
|
|
1912
|
+
if (!nodeOrigin) continue;
|
|
1913
|
+
const workspace = {
|
|
1914
|
+
origin: {
|
|
1915
|
+
originInstanceId: mapping.originInstanceId,
|
|
1916
|
+
originEntityId: mapping.originWorkspaceId
|
|
1917
|
+
},
|
|
1918
|
+
nodeOrigin,
|
|
1919
|
+
remotePath: mapping.remotePath,
|
|
1920
|
+
title: mapping.title
|
|
1921
|
+
};
|
|
1922
|
+
catalog.workspaces.set(syncWorkspaceKey(mapping.originInstanceId, mapping.originWorkspaceId, mapping.remotePath), workspace);
|
|
1923
|
+
}
|
|
1924
|
+
await this.exportBundleNow({
|
|
1925
|
+
manifestOnly: true,
|
|
1926
|
+
catalog
|
|
1927
|
+
});
|
|
1928
|
+
return {
|
|
1929
|
+
workspaces: [...catalog.workspaces.values()],
|
|
1930
|
+
sessions: catalog.sessions
|
|
1931
|
+
};
|
|
1932
|
+
});
|
|
1933
|
+
}
|
|
1934
|
+
async listSessionSizes() {
|
|
1935
|
+
return (await this.requirePersistence().list()).map((snapshot) => ({
|
|
1936
|
+
sessionId: String(snapshot.header.id),
|
|
1937
|
+
...isNonNegativeSafeInteger(snapshot.sizeBytes) ? { sizeBytes: snapshot.sizeBytes } : {}
|
|
1938
|
+
}));
|
|
1939
|
+
}
|
|
1904
1940
|
restoreArchive(branchId) {
|
|
1905
1941
|
return this.serializeMutation(() => this.restoreArchiveNow(branchId));
|
|
1906
1942
|
}
|
|
@@ -1981,6 +2017,42 @@ var SyncSessionService = class SyncSessionService {
|
|
|
1981
2017
|
descriptorCache.set(key, descriptor);
|
|
1982
2018
|
return descriptor;
|
|
1983
2019
|
};
|
|
2020
|
+
const catalogWorkspacesByOrigin = /* @__PURE__ */ new Map();
|
|
2021
|
+
for (const workspace of options.catalog?.workspaces.values() ?? []) catalogWorkspacesByOrigin.set(JSON.stringify([workspace.origin.originInstanceId, workspace.origin.originEntityId]), workspace);
|
|
2022
|
+
const collectWorkspace = (descriptor) => {
|
|
2023
|
+
if (!options.catalog) return void 0;
|
|
2024
|
+
const origin = {
|
|
2025
|
+
originInstanceId: descriptor.originInstanceId,
|
|
2026
|
+
originEntityId: descriptor.originWorkspaceId
|
|
2027
|
+
};
|
|
2028
|
+
const workspace = {
|
|
2029
|
+
origin,
|
|
2030
|
+
nodeOrigin: descriptor.nodeOrigin,
|
|
2031
|
+
remotePath: descriptor.remotePath,
|
|
2032
|
+
title: descriptor.title
|
|
2033
|
+
};
|
|
2034
|
+
options.catalog.workspaces.set(syncWorkspaceKey(origin.originInstanceId, origin.originEntityId, descriptor.remotePath), workspace);
|
|
2035
|
+
catalogWorkspacesByOrigin.set(JSON.stringify([origin.originInstanceId, origin.originEntityId]), workspace);
|
|
2036
|
+
return workspace;
|
|
2037
|
+
};
|
|
2038
|
+
const collectSession = (metadata, workspace, sessionId, sizeBytes, extra = {}) => {
|
|
2039
|
+
if (!options.catalog) return;
|
|
2040
|
+
options.catalog.sessions.push({
|
|
2041
|
+
origin: {
|
|
2042
|
+
originInstanceId: metadata.originInstanceId,
|
|
2043
|
+
originEntityId: metadata.originEntityId
|
|
2044
|
+
},
|
|
2045
|
+
...workspace ? {
|
|
2046
|
+
workspaceOrigin: workspace.origin,
|
|
2047
|
+
workspaceRemotePath: workspace.remotePath,
|
|
2048
|
+
nodeOrigin: workspace.nodeOrigin
|
|
2049
|
+
} : metadata.workspaceOrigin ? { workspaceOrigin: metadata.workspaceOrigin } : {},
|
|
2050
|
+
sessionId,
|
|
2051
|
+
...isNonNegativeSafeInteger(sizeBytes) ? { sizeBytes } : {},
|
|
2052
|
+
...extra.branchId ? { branchId: extra.branchId } : {},
|
|
2053
|
+
...extra.deleted ? { deleted: true } : {}
|
|
2054
|
+
});
|
|
2055
|
+
};
|
|
1984
2056
|
for (const workspace of workspaces) {
|
|
1985
2057
|
workspaceById.set(String(workspace.id), workspace);
|
|
1986
2058
|
const binding = bindingByMirrorPath.get(workspaceCandidateKey(workspace));
|
|
@@ -1989,6 +2061,7 @@ var SyncSessionService = class SyncSessionService {
|
|
|
1989
2061
|
if (!node || !isNodeRemoteType(node.type)) continue;
|
|
1990
2062
|
const nodeOrigin = this.nodes.originForLocalNode(node.id);
|
|
1991
2063
|
if (!nodeOrigin) continue;
|
|
2064
|
+
if (workspace.sessionIds.length > 0) collectWorkspace(getWorkspaceDescriptor(workspace, binding, nodeOrigin));
|
|
1992
2065
|
for (let position = 0; position < workspace.sessionIds.length; position += 1) {
|
|
1993
2066
|
const sessionId = String(workspace.sessionIds[position]);
|
|
1994
2067
|
if (archivedBranchSessionIds.has(sessionId)) continue;
|
|
@@ -2000,6 +2073,7 @@ var SyncSessionService = class SyncSessionService {
|
|
|
2000
2073
|
});
|
|
2001
2074
|
if (selectedKeys && !selectedKeys.has(localKey)) continue;
|
|
2002
2075
|
const descriptor = getWorkspaceDescriptor(workspace, binding, nodeOrigin, currentSession?.workspaceOrigin);
|
|
2076
|
+
const catalogWorkspace = collectWorkspace(descriptor);
|
|
2003
2077
|
const snapshot = await persistence.stat(SessionId(sessionId));
|
|
2004
2078
|
if (!snapshot) continue;
|
|
2005
2079
|
if (snapshot.formatStatus === "migration-required") throw new SyncSessionError("session-format", "会话格式需要由当前 DSH 版本迁移");
|
|
@@ -2007,6 +2081,7 @@ var SyncSessionService = class SyncSessionService {
|
|
|
2007
2081
|
const cached = await this.reuseCachedManifestEntry(persistence, workspace, descriptor, position, SessionId(sessionId), snapshot, pinnedIds.has(sessionId), currentSession, stateIndex);
|
|
2008
2082
|
if (cached) {
|
|
2009
2083
|
entries.push(cached);
|
|
2084
|
+
collectSession(cached.metadata, catalogWorkspace, sessionId, snapshot.sizeBytes);
|
|
2010
2085
|
eligibleLocalIds.add(sessionId);
|
|
2011
2086
|
continue;
|
|
2012
2087
|
}
|
|
@@ -2025,6 +2100,7 @@ var SyncSessionService = class SyncSessionService {
|
|
|
2025
2100
|
}
|
|
2026
2101
|
if (exported) {
|
|
2027
2102
|
const { entry } = exported;
|
|
2103
|
+
collectSession(entry.metadata, catalogWorkspace, sessionId, snapshot.sizeBytes);
|
|
2028
2104
|
if (manifestOnly && options.payloadCache) {
|
|
2029
2105
|
const key = syncSessionEntryKey(entry);
|
|
2030
2106
|
const size = estimateJsonBytes(entry, MAX_MANIFEST_PAYLOAD_CACHE_BYTES - options.payloadCache.bytes);
|
|
@@ -2053,6 +2129,8 @@ var SyncSessionService = class SyncSessionService {
|
|
|
2053
2129
|
if (selectedKeys && !selectedKeys.has(syncSessionEntryKey({ metadata }))) continue;
|
|
2054
2130
|
if (metadata.deleted) {
|
|
2055
2131
|
entries.push({ metadata });
|
|
2132
|
+
const workspaceOrigin = metadata.workspaceOrigin;
|
|
2133
|
+
collectSession(metadata, workspaceOrigin ? catalogWorkspacesByOrigin.get(JSON.stringify([workspaceOrigin.originInstanceId, workspaceOrigin.originEntityId])) : void 0, metadata.localEntityId, void 0, { deleted: true });
|
|
2056
2134
|
const tombstoneKey = sessionExportCacheKey(metadata.localEntityId);
|
|
2057
2135
|
this.exportCache.delete(tombstoneKey);
|
|
2058
2136
|
this.exportCacheStore.delete(tombstoneKey);
|
|
@@ -2085,6 +2163,7 @@ var SyncSessionService = class SyncSessionService {
|
|
|
2085
2163
|
const nodeOrigin = this.nodes.originForLocalNode(node.id);
|
|
2086
2164
|
if (!nodeOrigin) continue;
|
|
2087
2165
|
const descriptor = getWorkspaceDescriptor(workspace, binding, nodeOrigin, stateIndex.archivesByLocalSessionId.get(archive.localSessionId)?.workspaceOrigin);
|
|
2166
|
+
const catalogWorkspace = collectWorkspace(descriptor);
|
|
2088
2167
|
const snapshot = await persistence.stat(SessionId(archive.localSessionId));
|
|
2089
2168
|
if (!snapshot) continue;
|
|
2090
2169
|
let exported;
|
|
@@ -2101,6 +2180,7 @@ var SyncSessionService = class SyncSessionService {
|
|
|
2101
2180
|
}
|
|
2102
2181
|
if (exported) {
|
|
2103
2182
|
const { entry } = exported;
|
|
2183
|
+
collectSession(entry.metadata, catalogWorkspace, archive.localSessionId, snapshot.sizeBytes, { branchId: archive.branchId });
|
|
2104
2184
|
if (manifestOnly && options.payloadCache) {
|
|
2105
2185
|
const key = syncSessionEntryKey(entry);
|
|
2106
2186
|
const size = estimateJsonBytes(entry, MAX_MANIFEST_PAYLOAD_CACHE_BYTES - options.payloadCache.bytes);
|
|
@@ -3413,4 +3493,4 @@ var SyncSessionService = class SyncSessionService {
|
|
|
3413
3493
|
//#endregion
|
|
3414
3494
|
export { estimateJsonBytes as a, planSessionTransfers as c, validateObjectPayload as d, validateSyncSessionBundle as f, SyncSessionService as i, sessionEventListDigest as l, SyncSessionError as n, makeSyncSessionBundle as o, validateSyncSessionManifest as p, SyncSessionObjectInbox as r, makeSyncSessionManifest as s, ExportObjectCache as t, syncSessionEntryKey as u };
|
|
3415
3495
|
|
|
3416
|
-
//# sourceMappingURL=session-sync-
|
|
3496
|
+
//# sourceMappingURL=session-sync-BZSp_o4n.js.map
|