@deepnote/convert 2.1.0 → 2.1.2
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/dist/bin.cjs +219 -0
- package/dist/bin.d.cts +1 -0
- package/dist/index.cjs +33 -0
- package/dist/index.d.cts +633 -0
- package/dist/index.d.ts +2 -12143
- package/dist/src-DI6mrd_2.cjs +1716 -0
- package/package.json +7 -5
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,633 @@
|
|
|
1
|
+
import { DeepnoteBlock, DeepnoteFile, Environment, Execution } from "@deepnote/blocks";
|
|
2
|
+
|
|
3
|
+
//#region src/types/jupyter.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Shared Jupyter Notebook type definitions used by both
|
|
7
|
+
* deepnote-to-jupyter and jupyter-to-deepnote converters.
|
|
8
|
+
*/
|
|
9
|
+
interface JupyterCell {
|
|
10
|
+
/** Top-level block_group field present in cloud-exported notebooks */
|
|
11
|
+
block_group?: string;
|
|
12
|
+
cell_type: 'code' | 'markdown';
|
|
13
|
+
execution_count?: number | null;
|
|
14
|
+
metadata: JupyterCellMetadata;
|
|
15
|
+
outputs?: any[];
|
|
16
|
+
outputs_reference?: string;
|
|
17
|
+
source: string | string[];
|
|
18
|
+
}
|
|
19
|
+
interface JupyterCellMetadata {
|
|
20
|
+
cell_id?: string;
|
|
21
|
+
deepnote_cell_type?: string;
|
|
22
|
+
deepnote_block_group?: string;
|
|
23
|
+
deepnote_sorting_key?: string;
|
|
24
|
+
deepnote_source?: string;
|
|
25
|
+
[key: string]: unknown;
|
|
26
|
+
}
|
|
27
|
+
interface JupyterNotebook {
|
|
28
|
+
cells: JupyterCell[];
|
|
29
|
+
metadata: JupyterNotebookMetadata;
|
|
30
|
+
nbformat?: number;
|
|
31
|
+
nbformat_minor?: number;
|
|
32
|
+
}
|
|
33
|
+
interface JupyterNotebookMetadata {
|
|
34
|
+
deepnote_notebook_id?: string;
|
|
35
|
+
deepnote_notebook_name?: string;
|
|
36
|
+
deepnote_execution_mode?: 'block' | 'downstream';
|
|
37
|
+
deepnote_is_module?: boolean;
|
|
38
|
+
deepnote_working_directory?: string;
|
|
39
|
+
[key: string]: unknown;
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/deepnote-to-jupyter.d.ts
|
|
43
|
+
interface ConvertDeepnoteFileToJupyterOptions {
|
|
44
|
+
outputDir: string;
|
|
45
|
+
}
|
|
46
|
+
interface ConvertBlocksToJupyterOptions {
|
|
47
|
+
/** Unique identifier for the notebook */
|
|
48
|
+
notebookId: string;
|
|
49
|
+
/** Display name of the notebook */
|
|
50
|
+
notebookName: string;
|
|
51
|
+
/** Execution mode: 'block' runs cells individually, 'downstream' runs dependent cells */
|
|
52
|
+
executionMode?: 'block' | 'downstream';
|
|
53
|
+
/** Whether this notebook is a module (importable by other notebooks) */
|
|
54
|
+
isModule?: boolean;
|
|
55
|
+
/** Working directory for the notebook */
|
|
56
|
+
workingDirectory?: string;
|
|
57
|
+
/** Environment snapshot metadata */
|
|
58
|
+
environment?: Environment;
|
|
59
|
+
/** Execution snapshot metadata */
|
|
60
|
+
execution?: Execution;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Converts an array of Deepnote blocks into a single Jupyter Notebook.
|
|
64
|
+
* This is the lowest-level conversion function, suitable for use in Deepnote Cloud.
|
|
65
|
+
*
|
|
66
|
+
* @param blocks - Array of DeepnoteBlock objects to convert
|
|
67
|
+
* @param options - Notebook metadata options
|
|
68
|
+
* @returns A JupyterNotebook object
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* import { convertBlocksToJupyterNotebook } from '@deepnote/convert'
|
|
73
|
+
*
|
|
74
|
+
* const notebook = convertBlocksToJupyterNotebook(blocks, {
|
|
75
|
+
* notebookId: 'abc123',
|
|
76
|
+
* notebookName: 'My Notebook',
|
|
77
|
+
* executionMode: 'block'
|
|
78
|
+
* })
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
declare function convertBlocksToJupyterNotebook(blocks: DeepnoteBlock[], options: ConvertBlocksToJupyterOptions): JupyterNotebook;
|
|
82
|
+
/**
|
|
83
|
+
* Converts a Deepnote project into Jupyter Notebook objects.
|
|
84
|
+
* This is a pure conversion function that doesn't perform any file I/O.
|
|
85
|
+
* Each notebook in the Deepnote project is converted to a separate Jupyter notebook.
|
|
86
|
+
*
|
|
87
|
+
* @param deepnoteFile - The deserialized Deepnote project file
|
|
88
|
+
* @returns Array of objects containing filename and corresponding Jupyter notebook
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* import { deserializeDeepnoteFile } from '@deepnote/blocks'
|
|
93
|
+
* import { convertDeepnoteToJupyterNotebooks } from '@deepnote/convert'
|
|
94
|
+
*
|
|
95
|
+
* const yamlContent = await fs.readFile('project.deepnote', 'utf-8')
|
|
96
|
+
* const deepnoteFile = deserializeDeepnoteFile(yamlContent)
|
|
97
|
+
* const notebooks = convertDeepnoteToJupyterNotebooks(deepnoteFile)
|
|
98
|
+
*
|
|
99
|
+
* for (const { filename, notebook } of notebooks) {
|
|
100
|
+
* console.log(`${filename}: ${notebook.cells.length} cells`)
|
|
101
|
+
* }
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
declare function convertDeepnoteToJupyterNotebooks(deepnoteFile: DeepnoteFile): Array<{
|
|
105
|
+
filename: string;
|
|
106
|
+
notebook: JupyterNotebook;
|
|
107
|
+
}>;
|
|
108
|
+
/**
|
|
109
|
+
* Converts a Deepnote project file into separate Jupyter Notebook (.ipynb) files.
|
|
110
|
+
* Each notebook in the Deepnote project becomes a separate .ipynb file.
|
|
111
|
+
*/
|
|
112
|
+
declare function convertDeepnoteFileToJupyterFiles(deepnoteFilePath: string, options: ConvertDeepnoteFileToJupyterOptions): Promise<void>;
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/types/marimo.d.ts
|
|
115
|
+
/**
|
|
116
|
+
* Marimo (.py) format type definitions.
|
|
117
|
+
*
|
|
118
|
+
* Marimo is a reactive Python notebook that stores notebooks as pure Python files.
|
|
119
|
+
* Key characteristics:
|
|
120
|
+
* - Pure Python with @app.cell decorators
|
|
121
|
+
* - Reactive execution based on variable dependencies
|
|
122
|
+
* - Function signatures declare dependencies (def __(df): means "depends on df")
|
|
123
|
+
* - Return statements declare exports (return df, means "exports df")
|
|
124
|
+
*
|
|
125
|
+
* Example:
|
|
126
|
+
* ```python
|
|
127
|
+
* import marimo
|
|
128
|
+
*
|
|
129
|
+
* __generated_with = "0.8.0"
|
|
130
|
+
* app = marimo.App(width="medium")
|
|
131
|
+
*
|
|
132
|
+
* @app.cell
|
|
133
|
+
* def __():
|
|
134
|
+
* import pandas as pd
|
|
135
|
+
* return pd,
|
|
136
|
+
*
|
|
137
|
+
* @app.cell
|
|
138
|
+
* def __(pd):
|
|
139
|
+
* df = pd.read_csv("data.csv")
|
|
140
|
+
* return df,
|
|
141
|
+
*
|
|
142
|
+
* if __name__ == "__main__":
|
|
143
|
+
* app.run()
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
interface MarimoCell {
|
|
147
|
+
/** Cell type: 'code', 'markdown', or 'sql' */
|
|
148
|
+
cellType: 'code' | 'markdown' | 'sql';
|
|
149
|
+
/** Cell content (Python code, markdown text, or SQL query) */
|
|
150
|
+
content: string;
|
|
151
|
+
/** Function name (usually __ for anonymous cells) */
|
|
152
|
+
functionName?: string;
|
|
153
|
+
/** Variables this cell depends on (from function parameters) */
|
|
154
|
+
dependencies?: string[];
|
|
155
|
+
/** Variables this cell exports (from return statement) */
|
|
156
|
+
exports?: string[];
|
|
157
|
+
/** Whether this cell is hidden in the UI */
|
|
158
|
+
hidden?: boolean;
|
|
159
|
+
/** Whether this cell is disabled */
|
|
160
|
+
disabled?: boolean;
|
|
161
|
+
}
|
|
162
|
+
interface MarimoApp {
|
|
163
|
+
/** Marimo version that generated this file */
|
|
164
|
+
generatedWith?: string;
|
|
165
|
+
/** App width setting ('medium', 'full', etc.) */
|
|
166
|
+
width?: string;
|
|
167
|
+
/** Array of cells */
|
|
168
|
+
cells: MarimoCell[];
|
|
169
|
+
/** App title (from app.title if present) */
|
|
170
|
+
title?: string;
|
|
171
|
+
}
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region src/deepnote-to-marimo.d.ts
|
|
174
|
+
interface ConvertDeepnoteFileToMarimoOptions {
|
|
175
|
+
outputDir: string;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Converts an array of Deepnote blocks into a Marimo app.
|
|
179
|
+
* This is the lowest-level conversion function.
|
|
180
|
+
*
|
|
181
|
+
* @param blocks - Array of DeepnoteBlock objects to convert
|
|
182
|
+
* @param notebookName - Name of the notebook (used for app title)
|
|
183
|
+
* @returns A MarimoApp object
|
|
184
|
+
*/
|
|
185
|
+
declare function convertBlocksToMarimoApp(blocks: DeepnoteBlock[], notebookName: string): MarimoApp;
|
|
186
|
+
/**
|
|
187
|
+
* Converts a Deepnote project into Marimo app objects.
|
|
188
|
+
* This is a pure conversion function that doesn't perform any file I/O.
|
|
189
|
+
* Each notebook in the Deepnote project is converted to a separate Marimo app.
|
|
190
|
+
*
|
|
191
|
+
* @param deepnoteFile - The deserialized Deepnote project file
|
|
192
|
+
* @returns Array of objects containing filename and corresponding Marimo app
|
|
193
|
+
*/
|
|
194
|
+
declare function convertDeepnoteToMarimoApps(deepnoteFile: DeepnoteFile): Array<{
|
|
195
|
+
filename: string;
|
|
196
|
+
app: MarimoApp;
|
|
197
|
+
}>;
|
|
198
|
+
/**
|
|
199
|
+
* Serializes a Marimo app to a Python file string.
|
|
200
|
+
*
|
|
201
|
+
* @param app - The Marimo app to serialize
|
|
202
|
+
* @returns The serialized Python code string
|
|
203
|
+
*/
|
|
204
|
+
declare function serializeMarimoFormat(app: MarimoApp): string;
|
|
205
|
+
/**
|
|
206
|
+
* Converts a Deepnote project file into separate Marimo (.py) files.
|
|
207
|
+
* Each notebook in the Deepnote project becomes a separate .py file.
|
|
208
|
+
*/
|
|
209
|
+
declare function convertDeepnoteFileToMarimoFiles(deepnoteFilePath: string, options: ConvertDeepnoteFileToMarimoOptions): Promise<void>;
|
|
210
|
+
//#endregion
|
|
211
|
+
//#region src/types/percent.d.ts
|
|
212
|
+
/**
|
|
213
|
+
* Percent format (.py with # %%) type definitions.
|
|
214
|
+
*
|
|
215
|
+
* The percent format is a convention for representing notebooks as plain Python files.
|
|
216
|
+
* It's supported by VS Code, Spyder, PyCharm, JupyText, and Hydrogen.
|
|
217
|
+
*
|
|
218
|
+
* Cell markers:
|
|
219
|
+
* - `# %%` - Code cell
|
|
220
|
+
* - `# %% [markdown]` - Markdown cell
|
|
221
|
+
* - `# %% [raw]` - Raw cell
|
|
222
|
+
* - `# %% title` - Code cell with title
|
|
223
|
+
* - `# %% [markdown] title` - Markdown cell with title
|
|
224
|
+
* - `# %% tags=["a", "b"]` - Cell with tags
|
|
225
|
+
*/
|
|
226
|
+
interface PercentCell {
|
|
227
|
+
/** Cell type: 'code', 'markdown', or 'raw' */
|
|
228
|
+
cellType: 'code' | 'markdown' | 'raw';
|
|
229
|
+
/** Cell content (for markdown cells, this is without the '# ' prefix on each line) */
|
|
230
|
+
content: string;
|
|
231
|
+
/** Optional cell title */
|
|
232
|
+
title?: string;
|
|
233
|
+
/** Optional cell tags */
|
|
234
|
+
tags?: string[];
|
|
235
|
+
/** Additional metadata from the cell marker */
|
|
236
|
+
metadata?: Record<string, unknown>;
|
|
237
|
+
}
|
|
238
|
+
interface PercentNotebook {
|
|
239
|
+
/** Array of cells in the notebook */
|
|
240
|
+
cells: PercentCell[];
|
|
241
|
+
/** Optional file-level metadata (from first line comments) */
|
|
242
|
+
metadata?: {
|
|
243
|
+
/** Original filename */
|
|
244
|
+
filename?: string;
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
//#endregion
|
|
248
|
+
//#region src/deepnote-to-percent.d.ts
|
|
249
|
+
interface ConvertDeepnoteFileToPercentOptions {
|
|
250
|
+
outputDir: string;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Converts an array of Deepnote blocks into a percent format notebook.
|
|
254
|
+
* This is the lowest-level conversion function.
|
|
255
|
+
*
|
|
256
|
+
* @param blocks - Array of DeepnoteBlock objects to convert
|
|
257
|
+
* @returns A PercentNotebook object
|
|
258
|
+
*/
|
|
259
|
+
declare function convertBlocksToPercentNotebook(blocks: DeepnoteBlock[]): PercentNotebook;
|
|
260
|
+
/**
|
|
261
|
+
* Converts a Deepnote project into percent format notebook objects.
|
|
262
|
+
* This is a pure conversion function that doesn't perform any file I/O.
|
|
263
|
+
* Each notebook in the Deepnote project is converted to a separate percent notebook.
|
|
264
|
+
*
|
|
265
|
+
* @param deepnoteFile - The deserialized Deepnote project file
|
|
266
|
+
* @returns Array of objects containing filename and corresponding percent notebook
|
|
267
|
+
*/
|
|
268
|
+
declare function convertDeepnoteToPercentNotebooks(deepnoteFile: DeepnoteFile): Array<{
|
|
269
|
+
filename: string;
|
|
270
|
+
notebook: PercentNotebook;
|
|
271
|
+
}>;
|
|
272
|
+
/**
|
|
273
|
+
* Serializes a percent format notebook to a string.
|
|
274
|
+
*
|
|
275
|
+
* @param notebook - The percent notebook to serialize
|
|
276
|
+
* @returns The serialized percent format string
|
|
277
|
+
*/
|
|
278
|
+
declare function serializePercentFormat(notebook: PercentNotebook): string;
|
|
279
|
+
/**
|
|
280
|
+
* Converts a Deepnote project file into separate percent format (.py) files.
|
|
281
|
+
* Each notebook in the Deepnote project becomes a separate .py file.
|
|
282
|
+
*/
|
|
283
|
+
declare function convertDeepnoteFileToPercentFiles(deepnoteFilePath: string, options: ConvertDeepnoteFileToPercentOptions): Promise<void>;
|
|
284
|
+
//#endregion
|
|
285
|
+
//#region src/types/quarto.d.ts
|
|
286
|
+
/**
|
|
287
|
+
* Quarto (.qmd) format type definitions.
|
|
288
|
+
*
|
|
289
|
+
* Quarto is a next-generation publishing system for scientific and technical documents.
|
|
290
|
+
* It uses markdown with code chunks similar to R Markdown but is language-agnostic.
|
|
291
|
+
*
|
|
292
|
+
* Key elements:
|
|
293
|
+
* - YAML frontmatter for document metadata
|
|
294
|
+
* - Code chunks with ```{python} or ```{r} fencing
|
|
295
|
+
* - Cell options using #| syntax (e.g., #| label: my-chunk)
|
|
296
|
+
* - Rich markdown with special directives
|
|
297
|
+
*/
|
|
298
|
+
interface QuartoCell {
|
|
299
|
+
/** Cell type: 'code' or 'markdown' */
|
|
300
|
+
cellType: 'code' | 'markdown';
|
|
301
|
+
/** Cell content (code or markdown text) */
|
|
302
|
+
content: string;
|
|
303
|
+
/** Language for code cells (e.g., 'python', 'r') */
|
|
304
|
+
language?: string;
|
|
305
|
+
/** Cell options from #| lines */
|
|
306
|
+
options?: QuartoCellOptions;
|
|
307
|
+
}
|
|
308
|
+
interface QuartoCellOptions {
|
|
309
|
+
/** Cell label/identifier */
|
|
310
|
+
label?: string;
|
|
311
|
+
/** Whether to show the code in output */
|
|
312
|
+
echo?: boolean;
|
|
313
|
+
/** Whether to evaluate the code */
|
|
314
|
+
eval?: boolean;
|
|
315
|
+
/** Whether to show output */
|
|
316
|
+
output?: boolean;
|
|
317
|
+
/** Figure caption */
|
|
318
|
+
figCap?: string;
|
|
319
|
+
/** Figure width */
|
|
320
|
+
figWidth?: number;
|
|
321
|
+
/** Figure height */
|
|
322
|
+
figHeight?: number;
|
|
323
|
+
/** Table caption */
|
|
324
|
+
tblCap?: string;
|
|
325
|
+
/** Warning display setting */
|
|
326
|
+
warning?: boolean;
|
|
327
|
+
/** Message display setting */
|
|
328
|
+
message?: boolean;
|
|
329
|
+
/** Additional raw options */
|
|
330
|
+
raw?: Record<string, unknown>;
|
|
331
|
+
}
|
|
332
|
+
interface QuartoFrontmatter {
|
|
333
|
+
/** Document title */
|
|
334
|
+
title?: string;
|
|
335
|
+
/** Author(s) */
|
|
336
|
+
author?: string | string[];
|
|
337
|
+
/** Document date */
|
|
338
|
+
date?: string;
|
|
339
|
+
/** Output format(s) */
|
|
340
|
+
format?: string | Record<string, unknown>;
|
|
341
|
+
/** Jupyter kernel specification */
|
|
342
|
+
jupyter?: string;
|
|
343
|
+
/** Execute options */
|
|
344
|
+
execute?: {
|
|
345
|
+
echo?: boolean;
|
|
346
|
+
eval?: boolean;
|
|
347
|
+
warning?: boolean;
|
|
348
|
+
output?: boolean;
|
|
349
|
+
};
|
|
350
|
+
/** Additional metadata */
|
|
351
|
+
[key: string]: unknown;
|
|
352
|
+
}
|
|
353
|
+
interface QuartoDocument {
|
|
354
|
+
/** YAML frontmatter metadata */
|
|
355
|
+
frontmatter?: QuartoFrontmatter;
|
|
356
|
+
/** Array of cells (code chunks and markdown) */
|
|
357
|
+
cells: QuartoCell[];
|
|
358
|
+
}
|
|
359
|
+
//#endregion
|
|
360
|
+
//#region src/deepnote-to-quarto.d.ts
|
|
361
|
+
interface ConvertDeepnoteFileToQuartoOptions {
|
|
362
|
+
outputDir: string;
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Converts an array of Deepnote blocks into a Quarto document.
|
|
366
|
+
* This is the lowest-level conversion function.
|
|
367
|
+
*
|
|
368
|
+
* @param blocks - Array of DeepnoteBlock objects to convert
|
|
369
|
+
* @param notebookName - Name of the notebook (used for document title)
|
|
370
|
+
* @returns A QuartoDocument object
|
|
371
|
+
*/
|
|
372
|
+
declare function convertBlocksToQuartoDocument(blocks: DeepnoteBlock[], notebookName: string): QuartoDocument;
|
|
373
|
+
/**
|
|
374
|
+
* Converts a Deepnote project into Quarto document objects.
|
|
375
|
+
* This is a pure conversion function that doesn't perform any file I/O.
|
|
376
|
+
* Each notebook in the Deepnote project is converted to a separate Quarto document.
|
|
377
|
+
*
|
|
378
|
+
* @param deepnoteFile - The deserialized Deepnote project file
|
|
379
|
+
* @returns Array of objects containing filename and corresponding Quarto document
|
|
380
|
+
*/
|
|
381
|
+
declare function convertDeepnoteToQuartoDocuments(deepnoteFile: DeepnoteFile): Array<{
|
|
382
|
+
filename: string;
|
|
383
|
+
document: QuartoDocument;
|
|
384
|
+
}>;
|
|
385
|
+
/**
|
|
386
|
+
* Serializes a Quarto document to a string.
|
|
387
|
+
*
|
|
388
|
+
* @param document - The Quarto document to serialize
|
|
389
|
+
* @returns The serialized Quarto format string
|
|
390
|
+
*/
|
|
391
|
+
declare function serializeQuartoFormat(document: QuartoDocument): string;
|
|
392
|
+
/**
|
|
393
|
+
* Converts a Deepnote project file into separate Quarto (.qmd) files.
|
|
394
|
+
* Each notebook in the Deepnote project becomes a separate .qmd file.
|
|
395
|
+
*/
|
|
396
|
+
declare function convertDeepnoteFileToQuartoFiles(deepnoteFilePath: string, options: ConvertDeepnoteFileToQuartoOptions): Promise<void>;
|
|
397
|
+
//#endregion
|
|
398
|
+
//#region src/format-detection.d.ts
|
|
399
|
+
type NotebookFormat = 'jupyter' | 'deepnote' | 'marimo' | 'percent' | 'quarto';
|
|
400
|
+
/**
|
|
401
|
+
* Detects the notebook format from filename and optionally content.
|
|
402
|
+
* For .py files, content is required to distinguish between Marimo and Percent formats.
|
|
403
|
+
*/
|
|
404
|
+
declare function detectFormat(filename: string, content?: string): NotebookFormat;
|
|
405
|
+
//#endregion
|
|
406
|
+
//#region src/jupyter-to-deepnote.d.ts
|
|
407
|
+
interface ConvertIpynbFilesToDeepnoteFileOptions {
|
|
408
|
+
outputPath: string;
|
|
409
|
+
projectName: string;
|
|
410
|
+
}
|
|
411
|
+
interface ConvertJupyterNotebookOptions {
|
|
412
|
+
/** Custom ID generator function. Defaults to uuid v4. */
|
|
413
|
+
idGenerator?: () => string;
|
|
414
|
+
}
|
|
415
|
+
interface JupyterNotebookInput {
|
|
416
|
+
filename: string;
|
|
417
|
+
notebook: JupyterNotebook;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Converts a single Jupyter Notebook into an array of Deepnote blocks.
|
|
421
|
+
* This is the lowest-level conversion function, suitable for use in Deepnote Cloud.
|
|
422
|
+
*
|
|
423
|
+
* @param notebook - The Jupyter notebook object to convert
|
|
424
|
+
* @param options - Optional conversion options including custom ID generator
|
|
425
|
+
* @returns Array of DeepnoteBlock objects
|
|
426
|
+
*
|
|
427
|
+
* @example
|
|
428
|
+
* ```typescript
|
|
429
|
+
* import { convertJupyterNotebookToBlocks } from '@deepnote/convert'
|
|
430
|
+
*
|
|
431
|
+
* const notebook = JSON.parse(ipynbContent)
|
|
432
|
+
* const blocks = convertJupyterNotebookToBlocks(notebook, {
|
|
433
|
+
* idGenerator: () => myCustomIdGenerator()
|
|
434
|
+
* })
|
|
435
|
+
* ```
|
|
436
|
+
*/
|
|
437
|
+
declare function convertJupyterNotebookToBlocks(notebook: JupyterNotebook, options?: ConvertJupyterNotebookOptions): DeepnoteBlock[];
|
|
438
|
+
/**
|
|
439
|
+
* Converts Jupyter Notebook objects into a Deepnote project file.
|
|
440
|
+
* This is a pure conversion function that doesn't perform any file I/O.
|
|
441
|
+
*
|
|
442
|
+
* @param notebooks - Array of Jupyter notebooks with filenames
|
|
443
|
+
* @param options - Conversion options including project name
|
|
444
|
+
* @returns A DeepnoteFile object
|
|
445
|
+
*/
|
|
446
|
+
declare function convertJupyterNotebooksToDeepnote(notebooks: JupyterNotebookInput[], options: {
|
|
447
|
+
projectName: string;
|
|
448
|
+
}): DeepnoteFile;
|
|
449
|
+
/**
|
|
450
|
+
* Converts multiple Jupyter Notebook (.ipynb) files into a single Deepnote project file.
|
|
451
|
+
*/
|
|
452
|
+
declare function convertIpynbFilesToDeepnoteFile(inputFilePaths: string[], options: ConvertIpynbFilesToDeepnoteFileOptions): Promise<void>;
|
|
453
|
+
//#endregion
|
|
454
|
+
//#region src/marimo-to-deepnote.d.ts
|
|
455
|
+
interface ConvertMarimoFilesToDeepnoteFileOptions {
|
|
456
|
+
outputPath: string;
|
|
457
|
+
projectName: string;
|
|
458
|
+
}
|
|
459
|
+
interface ConvertMarimoAppOptions {
|
|
460
|
+
/** Custom ID generator function. Defaults to uuid v4. */
|
|
461
|
+
idGenerator?: () => string;
|
|
462
|
+
}
|
|
463
|
+
interface MarimoAppInput {
|
|
464
|
+
filename: string;
|
|
465
|
+
app: MarimoApp;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Parses a Marimo Python file into a MarimoApp structure.
|
|
469
|
+
*
|
|
470
|
+
* @param content - The raw content of the .py file
|
|
471
|
+
* @returns A MarimoApp object
|
|
472
|
+
*
|
|
473
|
+
* @example
|
|
474
|
+
* ```typescript
|
|
475
|
+
* const content = `import marimo
|
|
476
|
+
*
|
|
477
|
+
* app = marimo.App()
|
|
478
|
+
*
|
|
479
|
+
* @app.cell
|
|
480
|
+
* def __():
|
|
481
|
+
* print("hello")
|
|
482
|
+
* return
|
|
483
|
+
* `
|
|
484
|
+
* const app = parseMarimoFormat(content)
|
|
485
|
+
* ```
|
|
486
|
+
*/
|
|
487
|
+
declare function parseMarimoFormat(content: string): MarimoApp;
|
|
488
|
+
/**
|
|
489
|
+
* Converts a single Marimo app into an array of Deepnote blocks.
|
|
490
|
+
* This is the lowest-level conversion function.
|
|
491
|
+
*
|
|
492
|
+
* @param app - The Marimo app object to convert
|
|
493
|
+
* @param options - Optional conversion options including custom ID generator
|
|
494
|
+
* @returns Array of DeepnoteBlock objects
|
|
495
|
+
*/
|
|
496
|
+
declare function convertMarimoAppToBlocks(app: MarimoApp, options?: ConvertMarimoAppOptions): DeepnoteBlock[];
|
|
497
|
+
interface ConvertMarimoAppsToDeepnoteOptions {
|
|
498
|
+
/** Project name for the Deepnote file */
|
|
499
|
+
projectName: string;
|
|
500
|
+
/** Custom ID generator function. Defaults to uuid v4. */
|
|
501
|
+
idGenerator?: () => string;
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Converts Marimo app objects into a Deepnote project file.
|
|
505
|
+
* This is a pure conversion function that doesn't perform any file I/O.
|
|
506
|
+
*
|
|
507
|
+
* @param apps - Array of Marimo apps with filenames
|
|
508
|
+
* @param options - Conversion options including project name and optional ID generator
|
|
509
|
+
* @returns A DeepnoteFile object
|
|
510
|
+
*/
|
|
511
|
+
declare function convertMarimoAppsToDeepnote(apps: MarimoAppInput[], options: ConvertMarimoAppsToDeepnoteOptions): DeepnoteFile;
|
|
512
|
+
/**
|
|
513
|
+
* Converts multiple Marimo (.py) files into a single Deepnote project file.
|
|
514
|
+
*/
|
|
515
|
+
declare function convertMarimoFilesToDeepnoteFile(inputFilePaths: string[], options: ConvertMarimoFilesToDeepnoteFileOptions): Promise<void>;
|
|
516
|
+
//#endregion
|
|
517
|
+
//#region src/percent-to-deepnote.d.ts
|
|
518
|
+
interface ConvertPercentFilesToDeepnoteFileOptions {
|
|
519
|
+
outputPath: string;
|
|
520
|
+
projectName: string;
|
|
521
|
+
}
|
|
522
|
+
interface ConvertPercentNotebookOptions {
|
|
523
|
+
/** Custom ID generator function. Defaults to uuid v4. */
|
|
524
|
+
idGenerator?: () => string;
|
|
525
|
+
}
|
|
526
|
+
interface PercentNotebookInput {
|
|
527
|
+
filename: string;
|
|
528
|
+
notebook: PercentNotebook;
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Parses a percent format Python file into a PercentNotebook structure.
|
|
532
|
+
*
|
|
533
|
+
* @param content - The raw content of the .py file
|
|
534
|
+
* @returns A PercentNotebook object
|
|
535
|
+
*
|
|
536
|
+
* @example
|
|
537
|
+
* ```typescript
|
|
538
|
+
* const content = `# %% [markdown]
|
|
539
|
+
* # # My Title
|
|
540
|
+
*
|
|
541
|
+
* # %%
|
|
542
|
+
* print("hello")
|
|
543
|
+
* `
|
|
544
|
+
* const notebook = parsePercentFormat(content)
|
|
545
|
+
* ```
|
|
546
|
+
*/
|
|
547
|
+
declare function parsePercentFormat(content: string): PercentNotebook;
|
|
548
|
+
/**
|
|
549
|
+
* Converts a single percent format notebook into an array of Deepnote blocks.
|
|
550
|
+
* This is the lowest-level conversion function.
|
|
551
|
+
*
|
|
552
|
+
* @param notebook - The percent notebook object to convert
|
|
553
|
+
* @param options - Optional conversion options including custom ID generator
|
|
554
|
+
* @returns Array of DeepnoteBlock objects
|
|
555
|
+
*/
|
|
556
|
+
declare function convertPercentNotebookToBlocks(notebook: PercentNotebook, options?: ConvertPercentNotebookOptions): DeepnoteBlock[];
|
|
557
|
+
/**
|
|
558
|
+
* Converts percent format notebook objects into a Deepnote project file.
|
|
559
|
+
* This is a pure conversion function that doesn't perform any file I/O.
|
|
560
|
+
*
|
|
561
|
+
* @param notebooks - Array of percent notebooks with filenames
|
|
562
|
+
* @param options - Conversion options including project name
|
|
563
|
+
* @returns A DeepnoteFile object
|
|
564
|
+
*/
|
|
565
|
+
declare function convertPercentNotebooksToDeepnote(notebooks: PercentNotebookInput[], options: {
|
|
566
|
+
projectName: string;
|
|
567
|
+
}): DeepnoteFile;
|
|
568
|
+
/**
|
|
569
|
+
* Converts multiple percent format (.py) files into a single Deepnote project file.
|
|
570
|
+
*/
|
|
571
|
+
declare function convertPercentFilesToDeepnoteFile(inputFilePaths: string[], options: ConvertPercentFilesToDeepnoteFileOptions): Promise<void>;
|
|
572
|
+
//#endregion
|
|
573
|
+
//#region src/quarto-to-deepnote.d.ts
|
|
574
|
+
interface ConvertQuartoFilesToDeepnoteFileOptions {
|
|
575
|
+
outputPath: string;
|
|
576
|
+
projectName: string;
|
|
577
|
+
}
|
|
578
|
+
interface ConvertQuartoDocumentOptions {
|
|
579
|
+
/** Custom ID generator function. Defaults to uuid v4. */
|
|
580
|
+
idGenerator?: () => string;
|
|
581
|
+
}
|
|
582
|
+
interface QuartoDocumentInput {
|
|
583
|
+
filename: string;
|
|
584
|
+
document: QuartoDocument;
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Parses a Quarto (.qmd) file into a QuartoDocument structure.
|
|
588
|
+
*
|
|
589
|
+
* @param content - The raw content of the .qmd file
|
|
590
|
+
* @returns A QuartoDocument object
|
|
591
|
+
*
|
|
592
|
+
* @example
|
|
593
|
+
* ```typescript
|
|
594
|
+
* const content = `---
|
|
595
|
+
* title: "My Document"
|
|
596
|
+
* ---
|
|
597
|
+
*
|
|
598
|
+
* # Introduction
|
|
599
|
+
*
|
|
600
|
+
* \`\`\`{python}
|
|
601
|
+
* print("hello")
|
|
602
|
+
* \`\`\`
|
|
603
|
+
* `
|
|
604
|
+
* const doc = parseQuartoFormat(content)
|
|
605
|
+
* ```
|
|
606
|
+
*/
|
|
607
|
+
declare function parseQuartoFormat(content: string): QuartoDocument;
|
|
608
|
+
/**
|
|
609
|
+
* Converts a single Quarto document into an array of Deepnote blocks.
|
|
610
|
+
* This is the lowest-level conversion function.
|
|
611
|
+
*
|
|
612
|
+
* @param document - The Quarto document object to convert
|
|
613
|
+
* @param options - Optional conversion options including custom ID generator
|
|
614
|
+
* @returns Array of DeepnoteBlock objects
|
|
615
|
+
*/
|
|
616
|
+
declare function convertQuartoDocumentToBlocks(document: QuartoDocument, options?: ConvertQuartoDocumentOptions): DeepnoteBlock[];
|
|
617
|
+
/**
|
|
618
|
+
* Converts Quarto document objects into a Deepnote project file.
|
|
619
|
+
* This is a pure conversion function that doesn't perform any file I/O.
|
|
620
|
+
*
|
|
621
|
+
* @param documents - Array of Quarto documents with filenames
|
|
622
|
+
* @param options - Conversion options including project name
|
|
623
|
+
* @returns A DeepnoteFile object
|
|
624
|
+
*/
|
|
625
|
+
declare function convertQuartoDocumentsToDeepnote(documents: QuartoDocumentInput[], options: {
|
|
626
|
+
projectName: string;
|
|
627
|
+
}): DeepnoteFile;
|
|
628
|
+
/**
|
|
629
|
+
* Converts multiple Quarto (.qmd) files into a single Deepnote project file.
|
|
630
|
+
*/
|
|
631
|
+
declare function convertQuartoFilesToDeepnoteFile(inputFilePaths: string[], options: ConvertQuartoFilesToDeepnoteFileOptions): Promise<void>;
|
|
632
|
+
//#endregion
|
|
633
|
+
export { type ConvertBlocksToJupyterOptions, type ConvertDeepnoteFileToMarimoOptions, type ConvertDeepnoteFileToPercentOptions, type ConvertDeepnoteFileToQuartoOptions, type ConvertIpynbFilesToDeepnoteFileOptions, type ConvertJupyterNotebookOptions, type ConvertMarimoAppOptions, type ConvertMarimoAppsToDeepnoteOptions, type ConvertMarimoFilesToDeepnoteFileOptions, type ConvertPercentFilesToDeepnoteFileOptions, type ConvertPercentNotebookOptions, type ConvertQuartoDocumentOptions, type ConvertQuartoFilesToDeepnoteFileOptions, type JupyterCell, type JupyterNotebook, type JupyterNotebookInput, type MarimoApp, type MarimoAppInput, type MarimoCell, type NotebookFormat, type PercentCell, type PercentNotebook, type PercentNotebookInput, type QuartoCell, type QuartoCellOptions, type QuartoDocument, type QuartoDocumentInput, type QuartoFrontmatter, convertBlocksToJupyterNotebook, convertBlocksToMarimoApp, convertBlocksToPercentNotebook, convertBlocksToQuartoDocument, convertDeepnoteFileToJupyterFiles as convertDeepnoteFileToJupyter, convertDeepnoteFileToMarimoFiles, convertDeepnoteFileToPercentFiles, convertDeepnoteFileToQuartoFiles, convertDeepnoteToJupyterNotebooks, convertDeepnoteToMarimoApps, convertDeepnoteToPercentNotebooks, convertDeepnoteToQuartoDocuments, convertIpynbFilesToDeepnoteFile, convertJupyterNotebookToBlocks, convertJupyterNotebooksToDeepnote, convertMarimoAppToBlocks, convertMarimoAppsToDeepnote, convertMarimoFilesToDeepnoteFile, convertPercentFilesToDeepnoteFile, convertPercentNotebookToBlocks, convertPercentNotebooksToDeepnote, convertQuartoDocumentToBlocks, convertQuartoDocumentsToDeepnote, convertQuartoFilesToDeepnoteFile, detectFormat, parseMarimoFormat, parsePercentFormat, parseQuartoFormat, serializeMarimoFormat, serializePercentFormat, serializeQuartoFormat };
|