@deepnote/blocks
Advanced tools
+106
-9
@@ -31,2 +31,44 @@ //#region rolldown:runtime | ||
| //#region src/blocks.ts | ||
| var UnsupportedBlockTypeError = class extends Error { | ||
| constructor(message) { | ||
| super(message); | ||
| this.name = "UnsupportedBlockTypeError"; | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/blocks/executable-blocks.ts | ||
| const executableBlockTypes = new Set([ | ||
| "code", | ||
| "sql", | ||
| "notebook-function", | ||
| "visualization", | ||
| "button", | ||
| "big-number", | ||
| "input-text", | ||
| "input-textarea", | ||
| "input-checkbox", | ||
| "input-select", | ||
| "input-slider", | ||
| "input-date", | ||
| "input-date-range", | ||
| "input-file" | ||
| ]); | ||
| /** | ||
| * Type guard to check if a block is an executable block. | ||
| * Executable blocks can have outputs and be executed by the runtime. | ||
| */ | ||
| function isExecutableBlock(block) { | ||
| return executableBlockTypes.has(block.type); | ||
| } | ||
| /** | ||
| * Checks if a block type string represents an executable block. | ||
| * Convenience function for when you only have the type string. | ||
| */ | ||
| function isExecutableBlockType(type) { | ||
| return executableBlockTypes.has(type); | ||
| } | ||
| //#endregion | ||
| //#region src/deserialize-file/deepnote-file-schema.ts | ||
@@ -424,2 +466,13 @@ /** Preprocesses any content value to empty string for blocks that don't use content */ | ||
| }); | ||
| const deepnoteSnapshotSchema = deepnoteFileSchema.extend({ | ||
| environment: environmentSchema.unwrap(), | ||
| execution: executionSchema.unwrap(), | ||
| metadata: zod.z.object({ | ||
| checksum: zod.z.string().optional(), | ||
| createdAt: zod.z.string(), | ||
| exportedAt: zod.z.string().optional(), | ||
| modifiedAt: zod.z.string().optional(), | ||
| snapshotHash: zod.z.string() | ||
| }) | ||
| }); | ||
@@ -535,11 +588,2 @@ //#endregion | ||
| //#endregion | ||
| //#region src/blocks.ts | ||
| var UnsupportedBlockTypeError = class extends Error { | ||
| constructor(message) { | ||
| super(message); | ||
| this.name = "UnsupportedBlockTypeError"; | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/blocks/image-blocks.ts | ||
@@ -945,2 +989,49 @@ function escapeHtmlAttribute(value) { | ||
| //#endregion | ||
| //#region src/blocks/notebook-function-blocks.ts | ||
| function isNotebookFunctionBlock(block) { | ||
| return block.type === "notebook-function"; | ||
| } | ||
| function createPythonCodeForNotebookFunctionBlock(block) { | ||
| const notebookId = block.metadata?.function_notebook_id; | ||
| const inputs = block.metadata?.function_notebook_inputs ?? {}; | ||
| const exportMappings = block.metadata?.function_notebook_export_mappings ?? {}; | ||
| if (!notebookId) return ts_dedent.dedent` | ||
| # Notebook Function: Not configured | ||
| pass | ||
| `; | ||
| const enabledExports = Object.entries(exportMappings).filter(([, mapping]) => mapping.enabled); | ||
| const inputsAsString = JSON.stringify(inputs); | ||
| const exportMappingsDict = {}; | ||
| for (const [exportName, mapping] of enabledExports) exportMappingsDict[exportName] = mapping.variable_name; | ||
| const exportMappingsAsString = JSON.stringify(exportMappingsDict); | ||
| const inputsComment = `Inputs: ${inputsAsString}`; | ||
| const exportsComment = enabledExports.length > 0 ? `Exports: ${enabledExports.map(([name, mapping]) => `${name} -> ${mapping.variable_name}`).join(", ")}` : "Exports: (none)"; | ||
| const functionCall = ts_dedent.dedent` | ||
| _dntk.run_notebook_function( | ||
| ${escapePythonString(notebookId)}, | ||
| inputs=${inputsAsString}, | ||
| export_mappings=${exportMappingsAsString} | ||
| ) | ||
| `; | ||
| if (enabledExports.length === 0) return ts_dedent.dedent` | ||
| # Notebook Function: ${notebookId} | ||
| # ${inputsComment} | ||
| # ${exportsComment} | ||
| ${functionCall} | ||
| `; | ||
| if (enabledExports.length === 1) return ts_dedent.dedent` | ||
| # Notebook Function: ${notebookId} | ||
| # ${inputsComment} | ||
| # ${exportsComment} | ||
| ${enabledExports[0][1]?.variable_name} = ${functionCall} | ||
| `; | ||
| return ts_dedent.dedent` | ||
| # Notebook Function: ${notebookId} | ||
| # ${inputsComment} | ||
| # ${exportsComment} | ||
| ${enabledExports.map(([, mapping]) => mapping.variable_name).join(", ")} = ${functionCall} | ||
| `; | ||
| } | ||
| //#endregion | ||
| //#region src/blocks/sql-utils.ts | ||
@@ -1020,2 +1111,3 @@ function convertToEnvironmentVariableName(str) { | ||
| if (isBigNumberBlock(block)) return createPythonCodeForBigNumberBlock(block); | ||
| if (isNotebookFunctionBlock(block)) return createPythonCodeForNotebookFunctionBlock(block); | ||
| throw new UnsupportedBlockTypeError(`Creating python code from block type ${block.type} is not supported yet.`); | ||
@@ -1025,2 +1117,3 @@ } | ||
| //#endregion | ||
| exports.UnsupportedBlockTypeError = UnsupportedBlockTypeError; | ||
| exports.createMarkdown = createMarkdown; | ||
@@ -1031,2 +1124,3 @@ exports.createPythonCode = createPythonCode; | ||
| exports.deepnoteFileSchema = deepnoteFileSchema; | ||
| exports.deepnoteSnapshotSchema = deepnoteSnapshotSchema; | ||
| exports.deserializeDeepnoteFile = deserializeDeepnoteFile; | ||
@@ -1037,2 +1131,5 @@ exports.environmentSchema = environmentSchema; | ||
| exports.executionSummarySchema = executionSummarySchema; | ||
| exports.isExecutableBlock = isExecutableBlock; | ||
| exports.isExecutableBlockType = isExecutableBlockType; | ||
| exports.parseYaml = parseYaml; | ||
| exports.stripMarkdown = stripMarkdown; |
+102
-10
@@ -5,2 +5,44 @@ import { z } from "zod"; | ||
| //#region src/blocks.ts | ||
| var UnsupportedBlockTypeError = class extends Error { | ||
| constructor(message) { | ||
| super(message); | ||
| this.name = "UnsupportedBlockTypeError"; | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/blocks/executable-blocks.ts | ||
| const executableBlockTypes = new Set([ | ||
| "code", | ||
| "sql", | ||
| "notebook-function", | ||
| "visualization", | ||
| "button", | ||
| "big-number", | ||
| "input-text", | ||
| "input-textarea", | ||
| "input-checkbox", | ||
| "input-select", | ||
| "input-slider", | ||
| "input-date", | ||
| "input-date-range", | ||
| "input-file" | ||
| ]); | ||
| /** | ||
| * Type guard to check if a block is an executable block. | ||
| * Executable blocks can have outputs and be executed by the runtime. | ||
| */ | ||
| function isExecutableBlock(block) { | ||
| return executableBlockTypes.has(block.type); | ||
| } | ||
| /** | ||
| * Checks if a block type string represents an executable block. | ||
| * Convenience function for when you only have the type string. | ||
| */ | ||
| function isExecutableBlockType(type) { | ||
| return executableBlockTypes.has(type); | ||
| } | ||
| //#endregion | ||
| //#region src/deserialize-file/deepnote-file-schema.ts | ||
@@ -398,2 +440,13 @@ /** Preprocesses any content value to empty string for blocks that don't use content */ | ||
| }); | ||
| const deepnoteSnapshotSchema = deepnoteFileSchema.extend({ | ||
| environment: environmentSchema.unwrap(), | ||
| execution: executionSchema.unwrap(), | ||
| metadata: z.object({ | ||
| checksum: z.string().optional(), | ||
| createdAt: z.string(), | ||
| exportedAt: z.string().optional(), | ||
| modifiedAt: z.string().optional(), | ||
| snapshotHash: z.string() | ||
| }) | ||
| }); | ||
@@ -509,11 +562,2 @@ //#endregion | ||
| //#endregion | ||
| //#region src/blocks.ts | ||
| var UnsupportedBlockTypeError = class extends Error { | ||
| constructor(message) { | ||
| super(message); | ||
| this.name = "UnsupportedBlockTypeError"; | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/blocks/image-blocks.ts | ||
@@ -919,2 +963,49 @@ function escapeHtmlAttribute(value) { | ||
| //#endregion | ||
| //#region src/blocks/notebook-function-blocks.ts | ||
| function isNotebookFunctionBlock(block) { | ||
| return block.type === "notebook-function"; | ||
| } | ||
| function createPythonCodeForNotebookFunctionBlock(block) { | ||
| const notebookId = block.metadata?.function_notebook_id; | ||
| const inputs = block.metadata?.function_notebook_inputs ?? {}; | ||
| const exportMappings = block.metadata?.function_notebook_export_mappings ?? {}; | ||
| if (!notebookId) return dedent` | ||
| # Notebook Function: Not configured | ||
| pass | ||
| `; | ||
| const enabledExports = Object.entries(exportMappings).filter(([, mapping]) => mapping.enabled); | ||
| const inputsAsString = JSON.stringify(inputs); | ||
| const exportMappingsDict = {}; | ||
| for (const [exportName, mapping] of enabledExports) exportMappingsDict[exportName] = mapping.variable_name; | ||
| const exportMappingsAsString = JSON.stringify(exportMappingsDict); | ||
| const inputsComment = `Inputs: ${inputsAsString}`; | ||
| const exportsComment = enabledExports.length > 0 ? `Exports: ${enabledExports.map(([name, mapping]) => `${name} -> ${mapping.variable_name}`).join(", ")}` : "Exports: (none)"; | ||
| const functionCall = dedent` | ||
| _dntk.run_notebook_function( | ||
| ${escapePythonString(notebookId)}, | ||
| inputs=${inputsAsString}, | ||
| export_mappings=${exportMappingsAsString} | ||
| ) | ||
| `; | ||
| if (enabledExports.length === 0) return dedent` | ||
| # Notebook Function: ${notebookId} | ||
| # ${inputsComment} | ||
| # ${exportsComment} | ||
| ${functionCall} | ||
| `; | ||
| if (enabledExports.length === 1) return dedent` | ||
| # Notebook Function: ${notebookId} | ||
| # ${inputsComment} | ||
| # ${exportsComment} | ||
| ${enabledExports[0][1]?.variable_name} = ${functionCall} | ||
| `; | ||
| return dedent` | ||
| # Notebook Function: ${notebookId} | ||
| # ${inputsComment} | ||
| # ${exportsComment} | ||
| ${enabledExports.map(([, mapping]) => mapping.variable_name).join(", ")} = ${functionCall} | ||
| `; | ||
| } | ||
| //#endregion | ||
| //#region src/blocks/sql-utils.ts | ||
@@ -994,2 +1085,3 @@ function convertToEnvironmentVariableName(str) { | ||
| if (isBigNumberBlock(block)) return createPythonCodeForBigNumberBlock(block); | ||
| if (isNotebookFunctionBlock(block)) return createPythonCodeForNotebookFunctionBlock(block); | ||
| throw new UnsupportedBlockTypeError(`Creating python code from block type ${block.type} is not supported yet.`); | ||
@@ -999,2 +1091,2 @@ } | ||
| //#endregion | ||
| export { createMarkdown, createPythonCode, decodeUtf8NoBom, deepnoteBlockSchema, deepnoteFileSchema, deserializeDeepnoteFile, environmentSchema, executionErrorSchema, executionSchema, executionSummarySchema, stripMarkdown }; | ||
| export { UnsupportedBlockTypeError, createMarkdown, createPythonCode, decodeUtf8NoBom, deepnoteBlockSchema, deepnoteFileSchema, deepnoteSnapshotSchema, deserializeDeepnoteFile, environmentSchema, executionErrorSchema, executionSchema, executionSummarySchema, isExecutableBlock, isExecutableBlockType, parseYaml, stripMarkdown }; |
+1
-1
| { | ||
| "name": "@deepnote/blocks", | ||
| "version": "3.0.1", | ||
| "version": "3.2.1", | ||
| "description": "", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
2523528
87.18%25636
80.71%