MCPcopy Index your code
hub / github.com/deepnote/deepnote / splitDeepnoteFile

Function splitDeepnoteFile

packages/convert/src/snapshot/split.ts:148–185  ·  view source on GitHub ↗
(file: DeepnoteFile)

Source from the content-addressed store, hash-verified

146 * @returns Object containing source and snapshot files
147 */
148export function splitDeepnoteFile(file: DeepnoteFile): SplitResult {
149 // First ensure all blocks have content hashes (returns new file, doesn't mutate)
150 const fileWithHashes = addContentHashes(file)
151
152 // Compute snapshot hash before stripping outputs
153 const snapshotHash = computeSnapshotHash(fileWithHashes)
154
155 // Create source file with outputs stripped (exclude snapshotHash from source)
156 const { snapshotHash: _snapshotHash, ...sourceMetadata } = (fileWithHashes.metadata ?? {}) as NonNullable<
157 typeof fileWithHashes.metadata
158 > & {
159 snapshotHash?: string
160 }
161 const source: DeepnoteFile = {
162 ...fileWithHashes,
163 metadata: sourceMetadata,
164 project: {
165 ...fileWithHashes.project,
166 notebooks: fileWithHashes.project.notebooks.map(notebook => ({
167 ...notebook,
168 blocks: notebook.blocks.map(stripOutputsFromBlock),
169 })),
170 },
171 }
172
173 // Create snapshot file with all data plus snapshot metadata
174 const snapshot: DeepnoteSnapshot = {
175 ...fileWithHashes,
176 environment: fileWithHashes.environment ?? {},
177 execution: fileWithHashes.execution ?? {},
178 metadata: {
179 ...fileWithHashes.metadata,
180 snapshotHash,
181 },
182 }
183
184 return { source, snapshot }
185}
186
187/**
188 * Checks if a DeepnoteFile has any outputs.

Callers 5

writeDeepnoteFileFunction · 0.90
split.test.tsFile · 0.90
saveExecutionSnapshotFunction · 0.90
handleSnapshotSplitFunction · 0.90

Calls 2

addContentHashesFunction · 0.90
computeSnapshotHashFunction · 0.90

Tested by

no test coverage detected