(file: DeepnoteFile)
| 146 | * @returns Object containing source and snapshot files |
| 147 | */ |
| 148 | export 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. |
no test coverage detected