Skip to content

Commit

Permalink
fix(#134): add notebookdata typeguard
Browse files Browse the repository at this point in the history
  • Loading branch information
AnWeber committed Oct 26, 2024
1 parent 74ef83b commit 526a9f4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 3.2.5 (2024-10-26)

### Fix

- add typeguard for NotebookData check (#134)


## 3.2.4 (2024-09-22)

### Fix
Expand Down
22 changes: 11 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "httpbook",
"displayName": "httpBook - Rest Client",
"description": "Quickly and easily send REST, Soap, GraphQL, GRPC, MQTT and WebSocket requests directly within Visual Studio Code",
"version": "3.2.4",
"version": "3.2.5",
"publisher": "anweber",
"homepage": "https://github.com/AnWeber/httpbook",
"repository": {
Expand Down Expand Up @@ -167,7 +167,7 @@
"watch": "npm run esbuild -- --watch"
},
"devDependencies": {
"@types/node": "^22.5.5",
"@types/node": "^22.8.1",
"@types/react": "^18.3.8",
"@types/vscode": "1.71.0",
"@types/vscode-notebook-renderer": "^1.72.3",
Expand All @@ -182,7 +182,7 @@
"lint-staged": "^15.2.10",
"lockfile-lint": "^4.14.0",
"prettier": "^3.3.3",
"typescript": "^5.6.2"
"typescript": "^5.6.3"
},
"dependencies": {
"preact": "^10.24.3"
Expand Down
10 changes: 9 additions & 1 deletion src/extension/notebook/httpNotebookSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export class HttpNotebookSerializer implements vscode.NotebookSerializer {
}

private getNotebookCells(document: vscode.NotebookData | vscode.NotebookDocument): Array<HttpCell> {
if (document instanceof vscode.NotebookData) {
if (this.isNotebookData(document)) {
return document.cells.map(obj => {
const result: HttpCell = {
value: obj.value,
Expand Down Expand Up @@ -223,4 +223,12 @@ export class HttpNotebookSerializer implements vscode.NotebookSerializer {
version
);
}

private isNotebookData(document: vscode.NotebookData | vscode.NotebookDocument): document is vscode.NotebookData {
if (document instanceof vscode.NotebookData) {
return true;
}
const obj = document as unknown as Record<string, unknown>;
return Array.isArray(obj.cells) && !obj.getCells;
}
}

0 comments on commit 526a9f4

Please sign in to comment.