Skip to content

Commit 4706114

Browse files
committed
chore: fix types and TypeScript
- updates TypeScript to version 5.8.3 - always uses Headers from undici - Fix TypeScript compilation error by imporing AssertionError from node:assert
1 parent d84f907 commit 4706114

File tree

9 files changed

+21
-17
lines changed

9 files changed

+21
-17
lines changed

package-lock.json

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"globals": "^15.14.0",
5656
"prettier": "^3.4.1",
5757
"tsx": "^4.19.2",
58-
"typescript": "^5.7.2",
58+
"typescript": "^5.8.3",
5959
"typescript-eslint": "^8.16.0"
6060
},
6161
"dependencies": {

src/files.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import { LangflowClient } from "./index.js";
1616
import { UserFile } from "./user_file.js";
1717
import { LangflowUploadResponseUserFile } from "./types.js";
18-
import { FormData } from "undici";
18+
import { FormData, Headers } from "undici";
1919

2020
export class Files {
2121
client: LangflowClient;
@@ -46,7 +46,7 @@ export class Files {
4646
headers.set("Accept", "application/json");
4747
const { signal } = options;
4848
const response = (await this.client.request({
49-
path: `/v2/files`,
49+
path: "/v2/files",
5050
method: "GET",
5151
headers,
5252
signal,

src/flow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { FormData } from "undici";
15+
import { FormData, Headers } from "undici";
1616

1717
import { LangflowClient } from "./index.js";
1818
import { FlowResponse } from "./flow_response.js";

src/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { fetch } from "undici";
15+
import { fetch, Headers } from "undici";
1616

1717
import pkg from "../package.json" with { type: "json" };
1818
import { LangflowError, LangflowRequestError } from "./errors.js";
@@ -111,14 +111,16 @@ export class LangflowClient {
111111
}
112112
}
113113

114-
#setHeaders(headers: Headers) {
114+
#setHeaders(headers: Headers | Record<string, string>) {
115+
const newHeaders =
116+
headers instanceof Headers ? headers : new Headers(headers);
115117
for (const [header, value] of this.defaultHeaders.entries()) {
116-
if (!headers.has(header)) {
117-
headers.set(header, value);
118+
if (!newHeaders.has(header)) {
119+
newHeaders.set(header, value);
118120
}
119121
}
120122
if (this.apiKey) {
121-
this.#setApiKey(this.apiKey, headers);
123+
this.#setApiKey(this.apiKey, newHeaders);
122124
}
123125
}
124126

src/test/files.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import * as assert from "node:assert/strict";
1717
import { readFile } from "node:fs/promises";
1818
import { LangflowClient } from "../index.js";
1919
import { createMockFetch, assertBlobEqual } from "./utils.js";
20-
import { Headers } from "undici";
20+
import { Headers, FormData } from "undici";
2121
import { UserFile } from "../user_file.js";
2222

2323
const baseUrl = "http://localhost:3000";

src/test/flow.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,10 @@ describe("Flow", () => {
114114
}
115115
);
116116

117-
const file = await readFile(
117+
const buffer = await readFile(
118118
join(import.meta.dirname, "fixtures", "bodi.jpg")
119119
);
120+
const file = new File([buffer], "bodi.jpg", { type: "image/jpeg" });
120121

121122
const client = new LangflowClient({
122123
baseUrl: "http://localhost:7860",

src/test/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
import { type Response, Request, RequestInit } from "undici";
16-
import { AssertionError } from "node:assert/strict";
16+
import { AssertionError } from "node:assert";
1717

1818
type RequestInfo = string | URL | Request;
1919

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { fetch, FormData } from "undici";
15+
import type { fetch, FormData, Headers } from "undici";
1616

1717
import { InputTypes, OutputTypes } from "./consts.js";
1818

0 commit comments

Comments
 (0)