MCPcopy
hub / github.com/deepnote/deepnote / mergeSnapshotIntoSource

Function mergeSnapshotIntoSource

packages/convert/src/snapshot/merge.ts:13–93  ·  view source on GitHub ↗
(
  source: DeepnoteFile,
  snapshot: DeepnoteSnapshot,
  options: MergeOptions = {}
)

Source from the content-addressed store, hash-verified

11 * @returns A new DeepnoteFile with outputs merged in
12 */
13export function mergeSnapshotIntoSource(
14 source: DeepnoteFile,
15 snapshot: DeepnoteSnapshot,
16 options: MergeOptions = {}
17): DeepnoteFile {
18 const { skipMismatched = false } = options
19
20 // Build a map of block outputs from snapshot: blockId -> block with outputs
21 const outputMap = new Map<
22 string,
23 {
24 contentHash?: string
25 executionCount?: number | null
26 executionStartedAt?: string
27 executionFinishedAt?: string
28 outputs?: unknown[]
29 }
30 >()
31
32 for (const notebook of snapshot.project.notebooks) {
33 for (const block of notebook.blocks) {
34 const execBlock = block as DeepnoteBlock & {
35 executionCount?: number | null
36 executionStartedAt?: string
37 executionFinishedAt?: string
38 outputs?: unknown[]
39 }
40
41 // Only store blocks that have outputs
42 if (execBlock.outputs && execBlock.outputs.length > 0) {
43 outputMap.set(block.id, {
44 contentHash: block.contentHash,
45 executionCount: execBlock.executionCount,
46 executionStartedAt: execBlock.executionStartedAt,
47 executionFinishedAt: execBlock.executionFinishedAt,
48 outputs: execBlock.outputs,
49 })
50 }
51 }
52 }
53
54 // Merge snapshot environment and execution into source
55 const merged: DeepnoteFile = {
56 ...source,
57 environment: snapshot.environment ?? source.environment,
58 execution: snapshot.execution ?? source.execution,
59 project: {
60 ...source.project,
61 notebooks: source.project.notebooks.map(notebook => ({
62 ...notebook,
63 blocks: notebook.blocks.map(block => {
64 const snapshotData = outputMap.get(block.id)
65
66 if (!snapshotData) {
67 // No outputs for this block
68 return block
69 }
70

Callers 4

convertDeepnoteToFormatFunction · 0.90
merge.test.tsFile · 0.90
handleSnapshotMergeFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected