🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@deepnote/blocks

Package Overview
Dependencies
Maintainers
4
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@deepnote/blocks - npm Package Compare versions

Comparing version
3.2.1
to
4.0.0
+107
-42
dist/index.cjs

@@ -31,19 +31,66 @@ //#region rolldown:runtime

//#region src/blocks.ts
var UnsupportedBlockTypeError = class extends Error {
constructor(message) {
super(message);
this.name = "UnsupportedBlockTypeError";
//#region src/errors.ts
/**
* Base error class for all Deepnote errors.
*/
var DeepnoteError = class extends Error {
constructor(message, options) {
super(message, options);
this.name = this.constructor.name;
}
};
/**
* Generic parse failure, optionally associated with a file path.
*/
var ParseError = class extends DeepnoteError {
filePath;
constructor(message, options) {
super(message, options);
this.filePath = options?.filePath;
}
};
/**
* YAML syntax or duplicate key errors.
*/
var YamlParseError = class extends ParseError {};
/**
* BOM or invalid UTF-8 encoding errors.
*/
var EncodingError = class extends ParseError {};
/**
* Zod schema validation failures.
*/
var SchemaValidationError = class extends ParseError {};
/**
* Prohibited YAML features: anchors, aliases, merge keys, tags.
*/
var ProhibitedYamlFeatureError = class extends ParseError {
feature;
constructor(message, options) {
super(message, options);
this.feature = options.feature;
}
};
/**
* Thrown when a block type is not supported.
*/
var UnsupportedBlockTypeError = class extends DeepnoteError {};
/**
* Thrown when a value is invalid (e.g., slider value, date interval).
*/
var InvalidValueError = class extends DeepnoteError {
value;
constructor(message, options) {
super(message, options);
this.value = options.value;
}
};
//#endregion
//#region src/blocks/executable-blocks.ts
const executableBlockTypes = new Set([
"code",
"sql",
"notebook-function",
"visualization",
"button",
"big-number",
/**
* Block types that represent user input widgets.
* These blocks capture user input and define variables.
*/
const INPUT_BLOCK_TYPES = new Set([
"input-text",

@@ -58,2 +105,11 @@ "input-textarea",

]);
const executableBlockTypes = new Set([
"code",
"sql",
"notebook-function",
"visualization",
"button",
"big-number",
...INPUT_BLOCK_TYPES
]);
/**

@@ -75,2 +131,11 @@ * Type guard to check if a block is an executable block.

//#endregion
//#region src/blocks/sql-utils.ts
function convertToEnvironmentVariableName(str) {
return (/^\d/.test(str) ? `_${str}` : str).toUpperCase().replace(/[^\w]/g, "_");
}
function getSqlEnvVarName(integrationId) {
return `SQL_${integrationId}`;
}
//#endregion
//#region src/deserialize-file/deepnote-file-schema.ts

@@ -488,3 +553,3 @@ /** Preprocesses any content value to empty string for blocks that don't use content */

* @returns Decoded UTF-8 string without BOM
* @throws Error if BOM detected or invalid UTF-8 encoding
* @throws EncodingError if BOM detected or invalid UTF-8 encoding
*

@@ -499,7 +564,7 @@ * @example

function decodeUtf8NoBom(bytes) {
if (bytes.length >= 3 && bytes[0] === 239 && bytes[1] === 187 && bytes[2] === 191) throw new Error("UTF-8 BOM detected in Deepnote file - files must be UTF-8 without BOM");
if (bytes.length >= 3 && bytes[0] === 239 && bytes[1] === 187 && bytes[2] === 191) throw new EncodingError("UTF-8 BOM detected in Deepnote file - files must be UTF-8 without BOM");
try {
return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
} catch {
throw new Error("Invalid UTF-8 encoding detected in Deepnote file");
throw new EncodingError("Invalid UTF-8 encoding detected in Deepnote file");
}

@@ -514,6 +579,6 @@ }

* @param yamlContent - Already-decoded YAML string
* @throws Error if BOM prefix detected
* @throws EncodingError if BOM prefix detected
*/
function validateNoBomPrefix(yamlContent) {
if (yamlContent.charCodeAt(0) === 65279) throw new Error("UTF-8 BOM detected in Deepnote file - files must be UTF-8 without BOM");
if (yamlContent.charCodeAt(0) === 65279) throw new EncodingError("UTF-8 BOM detected in Deepnote file - files must be UTF-8 without BOM");
}

@@ -527,9 +592,9 @@ /**

function validateYamlStructure(yamlContent) {
if (/(?:^|\n)\s*(?:-\s+|[\w-]+:\s*)&\w+/.test(yamlContent)) throw new Error("YAML anchors (&) are not allowed in Deepnote files");
if (/(?:^|\n)\s*(?:-\s+|[\w-]+:\s*)\*\w+/.test(yamlContent)) throw new Error("YAML aliases (*) are not allowed in Deepnote files");
if (/<<:/.test(yamlContent)) throw new Error("YAML merge keys (<<) are not allowed in Deepnote files");
if (/(?:^|\n)\s*(?:-\s+|[\w-]+:\s*)&\w+/.test(yamlContent)) throw new ProhibitedYamlFeatureError("YAML anchors (&) are not allowed in Deepnote files", { feature: "anchor" });
if (/(?:^|\n)\s*(?:-\s+|[\w-]+:\s*)\*\w+/.test(yamlContent)) throw new ProhibitedYamlFeatureError("YAML aliases (*) are not allowed in Deepnote files", { feature: "alias" });
if (/<<:/.test(yamlContent)) throw new ProhibitedYamlFeatureError("YAML merge keys (<<) are not allowed in Deepnote files", { feature: "merge-key" });
const matches = yamlContent.match(/(?:^|\n)\s*(?:-\s+|[\w-]+:\s*)(![\w/-]+)/gm);
if (matches) {
const tags = matches.map((m) => m.match(/(![\w/-]+)/)?.[1]).filter(Boolean);
if (tags.length > 0) throw new Error(`YAML tags are not allowed in Deepnote files: ${tags.join(", ")}`);
if (tags.length > 0) throw new ProhibitedYamlFeatureError(`YAML tags are not allowed in Deepnote files: ${tags.join(", ")}`, { feature: "tag" });
}

@@ -549,4 +614,4 @@ }

const duplicateKeyError = doc.errors.find((err) => err.message.includes("duplicate") || err.message.includes("key"));
if (duplicateKeyError) throw new Error(`Duplicate keys detected in Deepnote file: ${duplicateKeyError.message}`);
throw new Error(`YAML parsing error: ${doc.errors[0].message}`);
if (duplicateKeyError) throw new YamlParseError(`Duplicate keys detected in Deepnote file: ${duplicateKeyError.message}`);
throw new YamlParseError(`YAML parsing error: ${doc.errors[0].message}`);
}

@@ -570,4 +635,4 @@ return doc.toJS();

} catch (error) {
const message = error instanceof Error ? error.message : String(error);
throw new Error(`Failed to parse Deepnote file: ${message}`);
if (error instanceof DeepnoteError) throw error;
throw new ParseError(`Failed to parse Deepnote file: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
}

@@ -586,6 +651,5 @@ }

const issue = result.error.issues[0];
if (!issue) throw new Error("Invalid Deepnote file.");
if (!issue) throw new SchemaValidationError("Invalid Deepnote file.");
const path = issue.path.join(".");
const message = path ? `${path}: ${issue.message}` : issue.message;
throw new Error(`Failed to parse the Deepnote file: ${message}.`);
throw new SchemaValidationError(`Failed to parse the Deepnote file: ${path ? `${path}: ${issue.message}` : issue.message}.`);
}

@@ -642,3 +706,3 @@ return result.data;

if (block.type === "text-cell-p") return escapeMarkdown(content);
throw new Error("Unhandled block type.");
throw new UnsupportedBlockTypeError("Unhandled block type.");
}

@@ -654,3 +718,3 @@ function stripMarkdownFromTextBlock(block) {

if (block.type === "text-cell-p") return content.trim();
throw new Error("Unhandled block type.");
throw new UnsupportedBlockTypeError("Unhandled block type.");
}

@@ -929,5 +993,5 @@ function createMarkdownForSeparatorBlock(_block) {

const value = block.metadata.deepnote_variable_value;
if (!/^-?\d+\.?\d*$|^-?\d*\.\d+$/.test(value)) throw new Error(`Invalid numeric value for slider input: "${value}". Expected a valid number (integer or float).`);
if (!/^-?\d+\.?\d*$|^-?\d*\.\d+$/.test(value)) throw new InvalidValueError(`Invalid numeric value for slider input: "${value}". Expected a valid number (integer or float).`, { value });
const numericValue = Number(value);
if (!Number.isFinite(numericValue)) throw new Error(`Invalid numeric value for slider input: "${value}". Value must be finite.`);
if (!Number.isFinite(numericValue)) throw new InvalidValueError(`Invalid numeric value for slider input: "${value}". Value must be finite.`, { value });
return `${sanitizedPythonVariableName} = ${numericValue}`;

@@ -966,3 +1030,3 @@ }

const range = DATE_RANGE_INPUT_RELATIVE_RANGES.find((range$1) => range$1.value === block.metadata.deepnote_variable_value);
if (!range) throw new Error(`Invalid relative date interval: "${block.metadata.deepnote_variable_value}". Expected one of: ${DATE_RANGE_INPUT_RELATIVE_RANGES.map((r) => r.value).join(", ")}.`);
if (!range) throw new InvalidValueError(`Invalid relative date interval: "${block.metadata.deepnote_variable_value}". Expected one of: ${DATE_RANGE_INPUT_RELATIVE_RANGES.map((r) => r.value).join(", ")}.`, { value: block.metadata.deepnote_variable_value });
return ts_dedent.dedent`

@@ -1047,11 +1111,2 @@ ${range.pythonCode(sanitizedPythonVariableName)}`;

//#endregion
//#region src/blocks/sql-utils.ts
function convertToEnvironmentVariableName(str) {
return (/^\d/.test(str) ? `_${str}` : str).toUpperCase().replace(/[^\w]/g, "_");
}
function getSqlEnvVarName(integrationId) {
return `SQL_${integrationId}`;
}
//#endregion
//#region src/blocks/sql-blocks.ts

@@ -1127,3 +1182,12 @@ function createPythonCodeForSqlBlock(block) {

//#endregion
exports.DeepnoteError = DeepnoteError;
exports.EncodingError = EncodingError;
exports.INPUT_BLOCK_TYPES = INPUT_BLOCK_TYPES;
exports.InvalidValueError = InvalidValueError;
exports.ParseError = ParseError;
exports.ProhibitedYamlFeatureError = ProhibitedYamlFeatureError;
exports.SchemaValidationError = SchemaValidationError;
exports.UnsupportedBlockTypeError = UnsupportedBlockTypeError;
exports.YamlParseError = YamlParseError;
exports.convertToEnvironmentVariableName = convertToEnvironmentVariableName;
exports.createMarkdown = createMarkdown;

@@ -1140,2 +1204,3 @@ exports.createPythonCode = createPythonCode;

exports.executionSummarySchema = executionSummarySchema;
exports.getSqlEnvVarName = getSqlEnvVarName;
exports.isExecutableBlock = isExecutableBlock;

@@ -1142,0 +1207,0 @@ exports.isExecutableBlockType = isExecutableBlockType;

@@ -5,19 +5,66 @@ import { z } from "zod";

//#region src/blocks.ts
var UnsupportedBlockTypeError = class extends Error {
constructor(message) {
super(message);
this.name = "UnsupportedBlockTypeError";
//#region src/errors.ts
/**
* Base error class for all Deepnote errors.
*/
var DeepnoteError = class extends Error {
constructor(message, options) {
super(message, options);
this.name = this.constructor.name;
}
};
/**
* Generic parse failure, optionally associated with a file path.
*/
var ParseError = class extends DeepnoteError {
filePath;
constructor(message, options) {
super(message, options);
this.filePath = options?.filePath;
}
};
/**
* YAML syntax or duplicate key errors.
*/
var YamlParseError = class extends ParseError {};
/**
* BOM or invalid UTF-8 encoding errors.
*/
var EncodingError = class extends ParseError {};
/**
* Zod schema validation failures.
*/
var SchemaValidationError = class extends ParseError {};
/**
* Prohibited YAML features: anchors, aliases, merge keys, tags.
*/
var ProhibitedYamlFeatureError = class extends ParseError {
feature;
constructor(message, options) {
super(message, options);
this.feature = options.feature;
}
};
/**
* Thrown when a block type is not supported.
*/
var UnsupportedBlockTypeError = class extends DeepnoteError {};
/**
* Thrown when a value is invalid (e.g., slider value, date interval).
*/
var InvalidValueError = class extends DeepnoteError {
value;
constructor(message, options) {
super(message, options);
this.value = options.value;
}
};
//#endregion
//#region src/blocks/executable-blocks.ts
const executableBlockTypes = new Set([
"code",
"sql",
"notebook-function",
"visualization",
"button",
"big-number",
/**
* Block types that represent user input widgets.
* These blocks capture user input and define variables.
*/
const INPUT_BLOCK_TYPES = new Set([
"input-text",

@@ -32,2 +79,11 @@ "input-textarea",

]);
const executableBlockTypes = new Set([
"code",
"sql",
"notebook-function",
"visualization",
"button",
"big-number",
...INPUT_BLOCK_TYPES
]);
/**

@@ -49,2 +105,11 @@ * Type guard to check if a block is an executable block.

//#endregion
//#region src/blocks/sql-utils.ts
function convertToEnvironmentVariableName(str) {
return (/^\d/.test(str) ? `_${str}` : str).toUpperCase().replace(/[^\w]/g, "_");
}
function getSqlEnvVarName(integrationId) {
return `SQL_${integrationId}`;
}
//#endregion
//#region src/deserialize-file/deepnote-file-schema.ts

@@ -462,3 +527,3 @@ /** Preprocesses any content value to empty string for blocks that don't use content */

* @returns Decoded UTF-8 string without BOM
* @throws Error if BOM detected or invalid UTF-8 encoding
* @throws EncodingError if BOM detected or invalid UTF-8 encoding
*

@@ -473,7 +538,7 @@ * @example

function decodeUtf8NoBom(bytes) {
if (bytes.length >= 3 && bytes[0] === 239 && bytes[1] === 187 && bytes[2] === 191) throw new Error("UTF-8 BOM detected in Deepnote file - files must be UTF-8 without BOM");
if (bytes.length >= 3 && bytes[0] === 239 && bytes[1] === 187 && bytes[2] === 191) throw new EncodingError("UTF-8 BOM detected in Deepnote file - files must be UTF-8 without BOM");
try {
return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
} catch {
throw new Error("Invalid UTF-8 encoding detected in Deepnote file");
throw new EncodingError("Invalid UTF-8 encoding detected in Deepnote file");
}

@@ -488,6 +553,6 @@ }

* @param yamlContent - Already-decoded YAML string
* @throws Error if BOM prefix detected
* @throws EncodingError if BOM prefix detected
*/
function validateNoBomPrefix(yamlContent) {
if (yamlContent.charCodeAt(0) === 65279) throw new Error("UTF-8 BOM detected in Deepnote file - files must be UTF-8 without BOM");
if (yamlContent.charCodeAt(0) === 65279) throw new EncodingError("UTF-8 BOM detected in Deepnote file - files must be UTF-8 without BOM");
}

@@ -501,9 +566,9 @@ /**

function validateYamlStructure(yamlContent) {
if (/(?:^|\n)\s*(?:-\s+|[\w-]+:\s*)&\w+/.test(yamlContent)) throw new Error("YAML anchors (&) are not allowed in Deepnote files");
if (/(?:^|\n)\s*(?:-\s+|[\w-]+:\s*)\*\w+/.test(yamlContent)) throw new Error("YAML aliases (*) are not allowed in Deepnote files");
if (/<<:/.test(yamlContent)) throw new Error("YAML merge keys (<<) are not allowed in Deepnote files");
if (/(?:^|\n)\s*(?:-\s+|[\w-]+:\s*)&\w+/.test(yamlContent)) throw new ProhibitedYamlFeatureError("YAML anchors (&) are not allowed in Deepnote files", { feature: "anchor" });
if (/(?:^|\n)\s*(?:-\s+|[\w-]+:\s*)\*\w+/.test(yamlContent)) throw new ProhibitedYamlFeatureError("YAML aliases (*) are not allowed in Deepnote files", { feature: "alias" });
if (/<<:/.test(yamlContent)) throw new ProhibitedYamlFeatureError("YAML merge keys (<<) are not allowed in Deepnote files", { feature: "merge-key" });
const matches = yamlContent.match(/(?:^|\n)\s*(?:-\s+|[\w-]+:\s*)(![\w/-]+)/gm);
if (matches) {
const tags = matches.map((m) => m.match(/(![\w/-]+)/)?.[1]).filter(Boolean);
if (tags.length > 0) throw new Error(`YAML tags are not allowed in Deepnote files: ${tags.join(", ")}`);
if (tags.length > 0) throw new ProhibitedYamlFeatureError(`YAML tags are not allowed in Deepnote files: ${tags.join(", ")}`, { feature: "tag" });
}

@@ -523,4 +588,4 @@ }

const duplicateKeyError = doc.errors.find((err) => err.message.includes("duplicate") || err.message.includes("key"));
if (duplicateKeyError) throw new Error(`Duplicate keys detected in Deepnote file: ${duplicateKeyError.message}`);
throw new Error(`YAML parsing error: ${doc.errors[0].message}`);
if (duplicateKeyError) throw new YamlParseError(`Duplicate keys detected in Deepnote file: ${duplicateKeyError.message}`);
throw new YamlParseError(`YAML parsing error: ${doc.errors[0].message}`);
}

@@ -544,4 +609,4 @@ return doc.toJS();

} catch (error) {
const message = error instanceof Error ? error.message : String(error);
throw new Error(`Failed to parse Deepnote file: ${message}`);
if (error instanceof DeepnoteError) throw error;
throw new ParseError(`Failed to parse Deepnote file: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
}

@@ -560,6 +625,5 @@ }

const issue = result.error.issues[0];
if (!issue) throw new Error("Invalid Deepnote file.");
if (!issue) throw new SchemaValidationError("Invalid Deepnote file.");
const path = issue.path.join(".");
const message = path ? `${path}: ${issue.message}` : issue.message;
throw new Error(`Failed to parse the Deepnote file: ${message}.`);
throw new SchemaValidationError(`Failed to parse the Deepnote file: ${path ? `${path}: ${issue.message}` : issue.message}.`);
}

@@ -616,3 +680,3 @@ return result.data;

if (block.type === "text-cell-p") return escapeMarkdown(content);
throw new Error("Unhandled block type.");
throw new UnsupportedBlockTypeError("Unhandled block type.");
}

@@ -628,3 +692,3 @@ function stripMarkdownFromTextBlock(block) {

if (block.type === "text-cell-p") return content.trim();
throw new Error("Unhandled block type.");
throw new UnsupportedBlockTypeError("Unhandled block type.");
}

@@ -903,5 +967,5 @@ function createMarkdownForSeparatorBlock(_block) {

const value = block.metadata.deepnote_variable_value;
if (!/^-?\d+\.?\d*$|^-?\d*\.\d+$/.test(value)) throw new Error(`Invalid numeric value for slider input: "${value}". Expected a valid number (integer or float).`);
if (!/^-?\d+\.?\d*$|^-?\d*\.\d+$/.test(value)) throw new InvalidValueError(`Invalid numeric value for slider input: "${value}". Expected a valid number (integer or float).`, { value });
const numericValue = Number(value);
if (!Number.isFinite(numericValue)) throw new Error(`Invalid numeric value for slider input: "${value}". Value must be finite.`);
if (!Number.isFinite(numericValue)) throw new InvalidValueError(`Invalid numeric value for slider input: "${value}". Value must be finite.`, { value });
return `${sanitizedPythonVariableName} = ${numericValue}`;

@@ -940,3 +1004,3 @@ }

const range = DATE_RANGE_INPUT_RELATIVE_RANGES.find((range$1) => range$1.value === block.metadata.deepnote_variable_value);
if (!range) throw new Error(`Invalid relative date interval: "${block.metadata.deepnote_variable_value}". Expected one of: ${DATE_RANGE_INPUT_RELATIVE_RANGES.map((r) => r.value).join(", ")}.`);
if (!range) throw new InvalidValueError(`Invalid relative date interval: "${block.metadata.deepnote_variable_value}". Expected one of: ${DATE_RANGE_INPUT_RELATIVE_RANGES.map((r) => r.value).join(", ")}.`, { value: block.metadata.deepnote_variable_value });
return dedent`

@@ -1021,11 +1085,2 @@ ${range.pythonCode(sanitizedPythonVariableName)}`;

//#endregion
//#region src/blocks/sql-utils.ts
function convertToEnvironmentVariableName(str) {
return (/^\d/.test(str) ? `_${str}` : str).toUpperCase().replace(/[^\w]/g, "_");
}
function getSqlEnvVarName(integrationId) {
return `SQL_${integrationId}`;
}
//#endregion
//#region src/blocks/sql-blocks.ts

@@ -1101,2 +1156,2 @@ function createPythonCodeForSqlBlock(block) {

//#endregion
export { UnsupportedBlockTypeError, createMarkdown, createPythonCode, decodeUtf8NoBom, deepnoteBlockSchema, deepnoteFileSchema, deepnoteSnapshotSchema, deserializeDeepnoteFile, environmentSchema, executionErrorSchema, executionSchema, executionSummarySchema, isExecutableBlock, isExecutableBlockType, parseYaml, stripMarkdown };
export { DeepnoteError, EncodingError, INPUT_BLOCK_TYPES, InvalidValueError, ParseError, ProhibitedYamlFeatureError, SchemaValidationError, UnsupportedBlockTypeError, YamlParseError, convertToEnvironmentVariableName, createMarkdown, createPythonCode, decodeUtf8NoBom, deepnoteBlockSchema, deepnoteFileSchema, deepnoteSnapshotSchema, deserializeDeepnoteFile, environmentSchema, executionErrorSchema, executionSchema, executionSummarySchema, getSqlEnvVarName, isExecutableBlock, isExecutableBlockType, parseYaml, stripMarkdown };
{
"name": "@deepnote/blocks",
"version": "3.2.1",
"version": "4.0.0",
"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