A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
Replace `convert_types.sh` with cross-platform `convert_types.js` (#6476)
Trevor Manzdd4661fb9a4e
diff --git a/packages/openapi/convert_types.js b/packages/openapi/convert_types.jsnew file mode 100644index 0000000000..d4aab91dc3--- /dev/null+++ b/packages/openapi/convert_types.js@@ -0,0 +1,51 @@+// @ts-check+import * as fs from "node:fs";+import * as process from "node:process";++/**+ * Make an assertion.+ *+ * @param {unknown} expression - The expression to test.+ * @param {string=} msg - The optional message to display if the assertion fails.+ * @returns {asserts expression}+ * @throws an {@link Error} if `expression` is not truthy.+ */+function assert(expression, msg = "") {+ if (!expression) {+ console.error(msg);+ process.exit(1);+ }+}++function main() {+ const paths = process.argv.slice(2);++ if (paths.length === 0) {+ console.error("Usage: node convert_types.js file1.ts [file2.ts ...]");+ process.exit(1);+ }++ for (const filePath of paths) {+ assert(fs.existsSync(filePath), `Expected ${filePath} to exist`);+ assert(+ filePath.endsWith(".ts"),+ `Expected ${filePath} to have .ts extension`,+ );+ const stats = fs.statSync(filePath);+ assert(stats.isFile(), `Expected ${filePath} to be a file`);++ const content = fs.readFileSync(filePath, "utf8");+ const newContent = content.replace(+ /Record<string, never>/g,+ "Record<string, any>",+ );+ if (content !== newContent) {+ fs.writeFileSync(filePath, newContent);+ console.log(`Updated: ${filePath}`);+ } else {+ console.log(`No changes made to: ${filePath}`);+ }+ }+}++main();diff --git a/packages/openapi/convert_types.sh b/packages/openapi/convert_types.shdeleted file mode 100755index 61bbf25f89..0000000000--- a/packages/openapi/convert_types.sh+++ /dev/null@@ -1,34 +0,0 @@-#!/usr/bin/env bash--# Usage: ./convert_types.sh <path>-# Replaces all occurrences of 'Record<string, never>' with 'Record<string, any>' in the given file or recursively in a directory.--set -euo pipefail--if [ $# -ne 1 ]; then- echo "Usage: $0 <file-or-directory>"- exit 1-fi--TARGET="$1"--# Detect OS and set sed in-place flag accordingly-if [[ "$OSTYPE" == "darwin"* ]]; then- # macOS requires empty string for backup- SED_INPLACE=(-i '')-else- # Linux doesn't use backup extension- SED_INPLACE=(-i)-fi--if [ -d "$TARGET" ]; then- # Recursively find .ts files and replace in-place- find "$TARGET" -type f -name "*.ts" -print0 | xargs -0 sed "${SED_INPLACE[@]}" -e 's/Record<string, never>/Record<string, any>/g'-elif [ -f "$TARGET" ]; then- sed "${SED_INPLACE[@]}" -e 's/Record<string, never>/Record<string, any>/g' "$TARGET"-else- echo "Error: $TARGET is not a file or directory"- exit 1-fi--echo "Replacement complete."diff --git a/packages/openapi/package.json b/packages/openapi/package.jsonindex 8bc2357971..908b65b8bc 100644--- a/packages/openapi/package.json+++ b/packages/openapi/package.json@@ -11,7 +11,7 @@],"scripts": {"codegen": "pnpm run \"/^codegen:.*/\"",- "codegen:api": "openapi-typescript ./api.yaml --default-non-nullable=false -o ./src/api.ts && ./convert_types.sh ./src/api.ts",+ "codegen:api": "openapi-typescript ./api.yaml --default-non-nullable=false -o ./src/api.ts && node ./convert_types.js ./src/api.ts","codegen:session": "openapi-typescript ../../marimo/_schemas/generated/session.yaml -o ./src/session.ts","codegen:notebook": "openapi-typescript ../../marimo/_schemas/generated/notebook.yaml -o ./src/notebook.ts"},