@deepnote/convert 2.2.0 → 2.3.1

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/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { DeepnoteBlock, DeepnoteFile, Environment, Execution } from "@deepnote/blocks";
1
+ import { DeepnoteBlock, DeepnoteFile, DeepnoteSnapshot, Environment, Execution } from "@deepnote/blocks";
2
2
 
3
3
  //#region src/types/jupyter.d.ts
4
4
 
@@ -6,6 +6,35 @@ import { DeepnoteBlock, DeepnoteFile, Environment, Execution } from "@deepnote/b
6
6
  * Shared Jupyter Notebook type definitions used by both
7
7
  * deepnote-to-jupyter and jupyter-to-deepnote converters.
8
8
  */
9
+ /**
10
+ * Jupyter output types - used for cell outputs.
11
+ */
12
+ interface JupyterOutputBase {
13
+ output_type: string;
14
+ }
15
+ interface JupyterStreamOutput extends JupyterOutputBase {
16
+ output_type: 'stream';
17
+ name: 'stdout' | 'stderr';
18
+ text: string | string[];
19
+ }
20
+ interface JupyterDisplayDataOutput extends JupyterOutputBase {
21
+ output_type: 'display_data';
22
+ data: Record<string, unknown>;
23
+ metadata?: Record<string, unknown>;
24
+ }
25
+ interface JupyterExecuteResultOutput extends JupyterOutputBase {
26
+ output_type: 'execute_result';
27
+ data: Record<string, unknown>;
28
+ metadata?: Record<string, unknown>;
29
+ execution_count?: number | null;
30
+ }
31
+ interface JupyterErrorOutput extends JupyterOutputBase {
32
+ output_type: 'error';
33
+ ename: string;
34
+ evalue: string;
35
+ traceback: string[];
36
+ }
37
+ type JupyterOutput = JupyterStreamOutput | JupyterDisplayDataOutput | JupyterExecuteResultOutput | JupyterErrorOutput;
9
38
  interface JupyterCell {
10
39
  /** Top-level block_group field present in cloud-exported notebooks */
11
40
  block_group?: string;
@@ -429,6 +458,9 @@ interface ConvertIpynbFilesToDeepnoteFileOptions {
429
458
  outputPath: string;
430
459
  projectName: string;
431
460
  }
461
+ interface ReadAndConvertIpynbFilesOptions {
462
+ projectName: string;
463
+ }
432
464
  interface ConvertJupyterNotebookOptions {
433
465
  /** Custom ID generator function. Defaults to crypto.randomUUID(). */
434
466
  idGenerator?: () => string;
@@ -467,6 +499,15 @@ declare function convertJupyterNotebookToBlocks(notebook: JupyterNotebook, optio
467
499
  declare function convertJupyterNotebooksToDeepnote(notebooks: JupyterNotebookInput[], options: {
468
500
  projectName: string;
469
501
  }): DeepnoteFile;
502
+ /**
503
+ * Reads and converts multiple Jupyter Notebook (.ipynb) files into a DeepnoteFile.
504
+ * This function reads the files and returns the converted DeepnoteFile without writing to disk.
505
+ *
506
+ * @param inputFilePaths - Array of paths to .ipynb files
507
+ * @param options - Conversion options including project name
508
+ * @returns A DeepnoteFile object
509
+ */
510
+ declare function readAndConvertIpynbFiles(inputFilePaths: string[], options: ReadAndConvertIpynbFilesOptions): Promise<DeepnoteFile>;
470
511
  /**
471
512
  * Converts multiple Jupyter Notebook (.ipynb) files into a single Deepnote project file.
472
513
  */
@@ -477,9 +518,14 @@ interface ConvertMarimoFilesToDeepnoteFileOptions {
477
518
  outputPath: string;
478
519
  projectName: string;
479
520
  }
521
+ interface ReadAndConvertMarimoFilesOptions {
522
+ projectName: string;
523
+ }
480
524
  interface ConvertMarimoAppOptions {
481
525
  /** Custom ID generator function. Defaults to crypto.randomUUID(). */
482
526
  idGenerator?: () => string;
527
+ /** Outputs from Marimo session cache, keyed by code_hash */
528
+ outputs?: Map<string, JupyterOutput[]>;
483
529
  }
484
530
  interface MarimoAppInput {
485
531
  filename: string;
@@ -511,7 +557,7 @@ declare function parseMarimoFormat(content: string): MarimoApp;
511
557
  * This is the lowest-level conversion function.
512
558
  *
513
559
  * @param app - The Marimo app object to convert
514
- * @param options - Optional conversion options including custom ID generator
560
+ * @param options - Optional conversion options including custom ID generator and outputs
515
561
  * @returns Array of DeepnoteBlock objects
516
562
  */
517
563
  declare function convertMarimoAppToBlocks(app: MarimoApp, options?: ConvertMarimoAppOptions): DeepnoteBlock[];
@@ -530,6 +576,15 @@ interface ConvertMarimoAppsToDeepnoteOptions {
530
576
  * @returns A DeepnoteFile object
531
577
  */
532
578
  declare function convertMarimoAppsToDeepnote(apps: MarimoAppInput[], options: ConvertMarimoAppsToDeepnoteOptions): DeepnoteFile;
579
+ /**
580
+ * Reads and converts multiple Marimo (.py) files into a DeepnoteFile.
581
+ * This function reads the files and returns the converted DeepnoteFile without writing to disk.
582
+ *
583
+ * @param inputFilePaths - Array of paths to Marimo .py files
584
+ * @param options - Conversion options including project name
585
+ * @returns A DeepnoteFile object
586
+ */
587
+ declare function readAndConvertMarimoFiles(inputFilePaths: string[], options: ReadAndConvertMarimoFilesOptions): Promise<DeepnoteFile>;
533
588
  /**
534
589
  * Converts multiple Marimo (.py) files into a single Deepnote project file.
535
590
  */
@@ -540,6 +595,9 @@ interface ConvertPercentFilesToDeepnoteFileOptions {
540
595
  outputPath: string;
541
596
  projectName: string;
542
597
  }
598
+ interface ReadAndConvertPercentFilesOptions {
599
+ projectName: string;
600
+ }
543
601
  interface ConvertPercentNotebookOptions {
544
602
  /** Custom ID generator function. Defaults to crypto.randomUUID(). */
545
603
  idGenerator?: () => string;
@@ -586,6 +644,15 @@ declare function convertPercentNotebookToBlocks(notebook: PercentNotebook, optio
586
644
  declare function convertPercentNotebooksToDeepnote(notebooks: PercentNotebookInput[], options: {
587
645
  projectName: string;
588
646
  }): DeepnoteFile;
647
+ /**
648
+ * Reads and converts multiple percent format (.py) files into a DeepnoteFile.
649
+ * This function reads the files and returns the converted DeepnoteFile without writing to disk.
650
+ *
651
+ * @param inputFilePaths - Array of paths to percent format .py files
652
+ * @param options - Conversion options including project name
653
+ * @returns A DeepnoteFile object
654
+ */
655
+ declare function readAndConvertPercentFiles(inputFilePaths: string[], options: ReadAndConvertPercentFilesOptions): Promise<DeepnoteFile>;
589
656
  /**
590
657
  * Converts multiple percent format (.py) files into a single Deepnote project file.
591
658
  */
@@ -596,6 +663,9 @@ interface ConvertQuartoFilesToDeepnoteFileOptions {
596
663
  outputPath: string;
597
664
  projectName: string;
598
665
  }
666
+ interface ReadAndConvertQuartoFilesOptions {
667
+ projectName: string;
668
+ }
599
669
  interface ConvertQuartoDocumentOptions {
600
670
  /** Custom ID generator function. Defaults to crypto.randomUUID(). */
601
671
  idGenerator?: () => string;
@@ -646,9 +716,249 @@ declare function convertQuartoDocumentToBlocks(document: QuartoDocument, options
646
716
  declare function convertQuartoDocumentsToDeepnote(documents: QuartoDocumentInput[], options: {
647
717
  projectName: string;
648
718
  }): DeepnoteFile;
719
+ /**
720
+ * Reads and converts multiple Quarto (.qmd) files into a DeepnoteFile.
721
+ * This function reads the files and returns the converted DeepnoteFile without writing to disk.
722
+ *
723
+ * @param inputFilePaths - Array of paths to .qmd files
724
+ * @param options - Conversion options including project name
725
+ * @returns A DeepnoteFile object
726
+ */
727
+ declare function readAndConvertQuartoFiles(inputFilePaths: string[], options: ReadAndConvertQuartoFilesOptions): Promise<DeepnoteFile>;
649
728
  /**
650
729
  * Converts multiple Quarto (.qmd) files into a single Deepnote project file.
651
730
  */
652
731
  declare function convertQuartoFilesToDeepnoteFile(inputFilePaths: string[], options: ConvertQuartoFilesToDeepnoteFileOptions): Promise<void>;
653
732
  //#endregion
654
- 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, convertBlockToJupyterCell, 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 };
733
+ //#region src/snapshot/hash.d.ts
734
+ /**
735
+ * Computes a SHA-256 hash of the given content.
736
+ *
737
+ * @param content - The content to hash
738
+ * @returns Hash string in format 'sha256:{hex}'
739
+ */
740
+ declare function computeContentHash(content: string): string;
741
+ /**
742
+ * Computes a snapshot hash from the file's key properties.
743
+ * The hash is based on: version, environment.hash, integrations, and all block contentHashes.
744
+ *
745
+ * @param file - The DeepnoteFile to compute hash for
746
+ * @returns Hash string in format 'sha256:{hex}'
747
+ */
748
+ declare function computeSnapshotHash(file: DeepnoteFile): string;
749
+ /**
750
+ * Adds content hashes to all blocks in a DeepnoteFile that don't already have them.
751
+ * Returns a new DeepnoteFile with hashes added (does not mutate the input).
752
+ *
753
+ * @param file - The DeepnoteFile to add hashes to
754
+ * @returns A new DeepnoteFile with content hashes added
755
+ */
756
+ declare function addContentHashes(file: DeepnoteFile): DeepnoteFile;
757
+ //#endregion
758
+ //#region src/snapshot/types.d.ts
759
+ /**
760
+ * Options for snapshot operations
761
+ */
762
+ interface SnapshotOptions {
763
+ /** Directory where snapshot files are stored (default: 'snapshots') */
764
+ snapshotDir?: string;
765
+ }
766
+ /**
767
+ * Result of splitting a DeepnoteFile into source and snapshot
768
+ */
769
+ interface SplitResult {
770
+ /** The source file without outputs */
771
+ source: DeepnoteFile;
772
+ /** The snapshot file containing outputs */
773
+ snapshot: DeepnoteSnapshot;
774
+ }
775
+ /**
776
+ * Block output information stored in a snapshot
777
+ */
778
+ interface BlockOutput {
779
+ /** Block ID */
780
+ id: string;
781
+ /** Content hash of the source when output was generated */
782
+ contentHash?: string;
783
+ /** Execution count */
784
+ executionCount?: number | null;
785
+ /** When execution started */
786
+ executionStartedAt?: string;
787
+ /** When execution finished */
788
+ executionFinishedAt?: string;
789
+ /** Output data */
790
+ outputs?: unknown[];
791
+ }
792
+ /**
793
+ * Information about a snapshot file
794
+ */
795
+ interface SnapshotInfo {
796
+ /** Full path to the snapshot file */
797
+ path: string;
798
+ /** Project name slug */
799
+ slug: string;
800
+ /** Project ID */
801
+ projectId: string;
802
+ /** Timestamp or 'latest' */
803
+ timestamp: string;
804
+ }
805
+ /**
806
+ * Options for merging a snapshot into a source file
807
+ */
808
+ interface MergeOptions {
809
+ /** Whether to skip blocks with mismatched content hashes (default: false) */
810
+ skipMismatched?: boolean;
811
+ }
812
+ //#endregion
813
+ //#region src/snapshot/lookup.d.ts
814
+ /**
815
+ * Parses a snapshot filename into its components.
816
+ *
817
+ * @param filename - The snapshot filename to parse
818
+ * @returns Parsed components or null if filename doesn't match pattern
819
+ */
820
+ declare function parseSnapshotFilename(filename: string): {
821
+ slug: string;
822
+ projectId: string;
823
+ timestamp: string;
824
+ } | null;
825
+ /**
826
+ * Finds all snapshot files for a given project.
827
+ *
828
+ * @param projectDir - Directory containing the .deepnote file
829
+ * @param projectId - The project UUID to search for
830
+ * @param options - Snapshot options
831
+ * @returns Array of SnapshotInfo objects, sorted by timestamp (newest first)
832
+ */
833
+ declare function findSnapshotsForProject(projectDir: string, projectId: string, options?: SnapshotOptions): Promise<SnapshotInfo[]>;
834
+ /**
835
+ * Loads the latest snapshot for a project.
836
+ *
837
+ * @param sourceFilePath - Path to the source .deepnote file
838
+ * @param projectId - The project UUID
839
+ * @param options - Snapshot options
840
+ * @returns The parsed DeepnoteSnapshot or null if not found
841
+ */
842
+ declare function loadLatestSnapshot(sourceFilePath: string, projectId: string, options?: SnapshotOptions): Promise<DeepnoteSnapshot | null>;
843
+ /**
844
+ * Loads and parses a snapshot file.
845
+ *
846
+ * @param snapshotPath - Path to the snapshot file
847
+ * @returns The parsed DeepnoteSnapshot
848
+ */
849
+ declare function loadSnapshotFile(snapshotPath: string): Promise<DeepnoteSnapshot>;
850
+ /**
851
+ * Gets the snapshot directory path for a source file.
852
+ *
853
+ * @param sourceFilePath - Path to the source .deepnote file
854
+ * @param options - Snapshot options
855
+ * @returns The snapshot directory path
856
+ */
857
+ declare function getSnapshotDir(sourceFilePath: string, options?: SnapshotOptions): string;
858
+ /**
859
+ * Checks if a snapshot exists for a project.
860
+ *
861
+ * @param sourceFilePath - Path to the source .deepnote file
862
+ * @param projectId - The project UUID
863
+ * @param options - Snapshot options
864
+ * @returns True if at least one snapshot exists
865
+ */
866
+ declare function snapshotExists(sourceFilePath: string, projectId: string, options?: SnapshotOptions): Promise<boolean>;
867
+ /**
868
+ * Extracts project information from a source file path.
869
+ *
870
+ * @param sourceFilePath - Path to the source .deepnote file
871
+ * @returns Object with directory and filename without extension
872
+ */
873
+ declare function parseSourceFilePath(sourceFilePath: string): {
874
+ dir: string;
875
+ name: string;
876
+ };
877
+ //#endregion
878
+ //#region src/snapshot/merge.d.ts
879
+ /**
880
+ * Merges outputs from a snapshot into a source file.
881
+ * Returns a new DeepnoteFile with outputs added from the snapshot.
882
+ *
883
+ * @param source - The source DeepnoteFile (without outputs)
884
+ * @param snapshot - The snapshot containing outputs
885
+ * @param options - Merge options
886
+ * @returns A new DeepnoteFile with outputs merged in
887
+ */
888
+ declare function mergeSnapshotIntoSource(source: DeepnoteFile, snapshot: DeepnoteSnapshot, options?: MergeOptions): DeepnoteFile;
889
+ /**
890
+ * Counts blocks with outputs in a file.
891
+ *
892
+ * @param file - The DeepnoteFile to count outputs in
893
+ * @returns Number of blocks that have outputs
894
+ */
895
+ declare function countBlocksWithOutputs(file: DeepnoteFile): number;
896
+ //#endregion
897
+ //#region src/snapshot/split.d.ts
898
+ /**
899
+ * Creates a slug from a project name.
900
+ * Normalizes accented characters to ASCII equivalents (e.g., é → e),
901
+ * converts to lowercase, replaces spaces and special chars with hyphens,
902
+ * removes consecutive hyphens, and trims leading/trailing hyphens.
903
+ *
904
+ * @param name - The project name to slugify
905
+ * @returns A URL-safe slug
906
+ */
907
+ declare function slugifyProjectName(name: string): string;
908
+ /**
909
+ * Generates a snapshot filename from project info.
910
+ *
911
+ * @param slug - The project name slug
912
+ * @param projectId - The project UUID
913
+ * @param timestamp - Timestamp string or 'latest'
914
+ * @returns Filename in format '{slug}_{projectId}_{timestamp}.snapshot.deepnote'
915
+ */
916
+ declare function generateSnapshotFilename(slug: string, projectId: string, timestamp?: string): string;
917
+ /**
918
+ * Splits a DeepnoteFile into a source file (no outputs) and a snapshot file (outputs only).
919
+ *
920
+ * @param file - The complete DeepnoteFile with outputs
921
+ * @returns Object containing source and snapshot files
922
+ */
923
+ declare function splitDeepnoteFile(file: DeepnoteFile): SplitResult;
924
+ /**
925
+ * Checks if a DeepnoteFile has any outputs.
926
+ *
927
+ * @param file - The DeepnoteFile to check
928
+ * @returns True if any block has outputs
929
+ */
930
+ declare function hasOutputs(file: DeepnoteFile): boolean;
931
+ //#endregion
932
+ //#region src/write-deepnote-file.d.ts
933
+ interface WriteDeepnoteFileOptions {
934
+ /** The DeepnoteFile to write */
935
+ file: DeepnoteFile;
936
+ /** Path where the main .deepnote file should be written */
937
+ outputPath: string;
938
+ /** Project name used for snapshot filename */
939
+ projectName: string;
940
+ /** When true, outputs are included in the main file (disables snapshot mode) */
941
+ singleFile?: boolean;
942
+ }
943
+ interface WriteDeepnoteFileResult {
944
+ /** Path to the written source file */
945
+ sourcePath: string;
946
+ /** Path to the snapshot file (only if outputs were split) */
947
+ snapshotPath?: string;
948
+ }
949
+ /**
950
+ * Writes a DeepnoteFile to disk, optionally splitting outputs into a snapshot file.
951
+ *
952
+ * When singleFile is false (default) and the file contains outputs:
953
+ * - Splits the file in memory into source (no outputs) and snapshot (with outputs)
954
+ * - Writes both files in parallel
955
+ *
956
+ * When singleFile is true or there are no outputs:
957
+ * - Writes the complete file as-is
958
+ *
959
+ * @param options - Write options including the file, output path, and project name
960
+ * @returns Object containing paths to the written files
961
+ */
962
+ declare function writeDeepnoteFile(options: WriteDeepnoteFileOptions): Promise<WriteDeepnoteFileResult>;
963
+ //#endregion
964
+ export { type BlockOutput, 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 MergeOptions, type NotebookFormat, type PercentCell, type PercentNotebook, type PercentNotebookInput, type QuartoCell, type QuartoCellOptions, type QuartoDocument, type QuartoDocumentInput, type QuartoFrontmatter, type ReadAndConvertIpynbFilesOptions, type ReadAndConvertMarimoFilesOptions, type ReadAndConvertPercentFilesOptions, type ReadAndConvertQuartoFilesOptions, type SnapshotInfo, type SnapshotOptions, type SplitResult, type WriteDeepnoteFileOptions, type WriteDeepnoteFileResult, addContentHashes, computeContentHash, computeSnapshotHash, convertBlockToJupyterCell, convertBlocksToJupyterNotebook, convertBlocksToMarimoApp, convertBlocksToPercentNotebook, convertBlocksToQuartoDocument, convertDeepnoteFileToJupyterFiles, convertDeepnoteFileToMarimoFiles, convertDeepnoteFileToPercentFiles, convertDeepnoteFileToQuartoFiles, convertDeepnoteToJupyterNotebooks, convertDeepnoteToMarimoApps, convertDeepnoteToPercentNotebooks, convertDeepnoteToQuartoDocuments, convertIpynbFilesToDeepnoteFile, convertJupyterNotebookToBlocks, convertJupyterNotebooksToDeepnote, convertMarimoAppToBlocks, convertMarimoAppsToDeepnote, convertMarimoFilesToDeepnoteFile, convertPercentFilesToDeepnoteFile, convertPercentNotebookToBlocks, convertPercentNotebooksToDeepnote, convertQuartoDocumentToBlocks, convertQuartoDocumentsToDeepnote, convertQuartoFilesToDeepnoteFile, countBlocksWithOutputs, detectFormat, findSnapshotsForProject, generateSnapshotFilename, getSnapshotDir, hasOutputs, loadLatestSnapshot, loadSnapshotFile, mergeSnapshotIntoSource, parseMarimoFormat, parsePercentFormat, parseQuartoFormat, parseSnapshotFilename, parseSourceFilePath, readAndConvertIpynbFiles, readAndConvertMarimoFiles, readAndConvertPercentFiles, readAndConvertQuartoFiles, serializeMarimoFormat, serializePercentFormat, serializeQuartoFormat, slugifyProjectName, snapshotExists, splitDeepnoteFile, writeDeepnoteFile };