You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: MIGRATION.md
+97-78Lines changed: 97 additions & 78 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,95 +4,40 @@ This guide outlines the changes and steps needed to migrate your codebase to the
4
4
5
5
The main changes are that the SDK now relies on the [builtin Web fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) instead of `node-fetch` and has zero dependencies.
6
6
7
+
## Migration CLI
8
+
9
+
Most programs will only need minimal changes, but to assist there is a migration tool that will automatically update your code for the new version.
10
+
To use it, upgrade the `writer-sdk` package, then run `./node_modules/.bin/writer-sdk migrate ./your/src/folders` to update your code.
11
+
To preview the changes without writing them to disk, run the tool with `--dry`.
12
+
7
13
## Environment requirements
8
14
9
15
The minimum supported runtime and tooling versions are now:
10
16
11
-
- Node.js 18.x last LTS (Required for built-in fetch support)
17
+
- Node.js 18.x last LTS (Required for builtin fetch support)
12
18
- This was previously documented as the minimum supported Node.js version but Node.js 16.x mostly worked at runtime; now it will not.
13
19
- TypeScript 4.9
14
20
- Jest 28
15
21
16
-
## Minimum types requirements
17
-
18
-
### DOM
19
-
20
-
`tsconfig.json`
21
-
22
-
```jsonc
23
-
{
24
-
"target":"ES2015", // note: we recommend ES2020 or higher
25
-
"lib": ["DOM", "DOM.Iterable", "ES2018"]
26
-
}
27
-
```
28
-
29
-
### Node.js
30
-
31
-
`tsconfig.json`
32
-
33
-
```jsonc
34
-
{
35
-
"target":"ES2015"// note: we recommend ES2020 or higher
36
-
}
37
-
```
38
-
39
-
`package.json`
40
-
41
-
```json
42
-
{
43
-
"devDependencies": {
44
-
"@types/node": ">= 18.18.7"
45
-
}
46
-
}
47
-
```
48
-
49
-
### Cloudflare Workers
50
-
51
-
`tsconfig.json`
52
-
53
-
```jsonc
54
-
{
55
-
"target":"ES2015", // note: we recommend ES2020 or higher
56
-
"lib": ["ES2020"], // <- needed by @cloudflare/workers-types
57
-
"types": ["@cloudflare/workers-types"]
58
-
}
59
-
```
60
-
61
-
`package.json`
62
-
63
-
```json
64
-
{
65
-
"devDependencies": {
66
-
"@cloudflare/workers-types": ">= 0.20221111.0"
67
-
}
68
-
}
69
-
```
70
-
71
-
### Bun
22
+
## Breaking changes
72
23
73
-
`tsconfig.json`
24
+
### Web types for `withResponse`, `asResponse`, and `APIError.headers`
74
25
75
-
```jsonc
76
-
{
77
-
"target":"ES2015"// note: we recommend ES2020 or higher
78
-
}
79
-
```
80
-
81
-
`package.json`
26
+
Because we now use the builtin Web fetch API on all platforms, if you wrote code that used `withResponse` or `asResponse` and then accessed `node-fetch`-specific properties on the result, you will need to switch to standardized alternatives.
27
+
For example, `body` is now a [Web `ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) rather than a [node `Readable`](https://nodejs.org/api/stream.html#readable-streams).
82
28
83
-
```json
84
-
{
85
-
"devDependencies": {
86
-
"@types/bun": ">= 1.2.0"
87
-
}
88
-
}
29
+
```ts
30
+
// Before:
31
+
const res =awaitclient.example.retrieve('string/with/slash').asResponse();
32
+
res.body.pipe(process.stdout);
33
+
34
+
// After:
35
+
import { Readable } from'node:stream';
36
+
const res =awaitclient.example.retrieve('string/with/slash').asResponse();
37
+
Readable.fromWeb(res.body).pipe(process.stdout);
89
38
```
90
39
91
-
### Deno
92
-
93
-
No config needed!
94
-
95
-
## Breaking changes
40
+
Additionally, the `headers` property on `APIError` objects is now an instance of the Web [Headers](https://developer.mozilla.org/en-US/docs/Web/API/Headers) class. It was previously defined as `Record<string, string | null | undefined>`.
96
41
97
42
### Named path parameters
98
43
@@ -355,6 +300,80 @@ import Writer from 'writer-sdk/src';
355
300
importWriterfrom'writer-sdk';
356
301
```
357
302
358
-
### Headers
303
+
## TypeScript troubleshooting
304
+
305
+
When referencing the library after updating, you may encounter new type errors related to JS features like private properties or fetch classes like Request, Response, and Headers.
306
+
To resolve these issues, configure your tsconfig.json and install the appropriate `@types` packages for your runtime environment using the guidelines below:
307
+
308
+
### Browsers
309
+
310
+
`tsconfig.json`
311
+
312
+
```jsonc
313
+
{
314
+
"target":"ES2018", // note: we recommend ES2020 or higher
315
+
"lib": ["DOM", "DOM.Iterable", "ES2018"]
316
+
}
317
+
```
318
+
319
+
### Node.js
359
320
360
-
The `headers` property on `APIError` objects is now an instance of the Web [Headers](https://developer.mozilla.org/en-US/docs/Web/API/Headers) class. It was previously just `Record<string, string | null | undefined>`.
321
+
`tsconfig.json`
322
+
323
+
```jsonc
324
+
{
325
+
"target":"ES2018"// note: we recommend ES2020 or higher
326
+
}
327
+
```
328
+
329
+
`package.json`
330
+
331
+
```json
332
+
{
333
+
"devDependencies": {
334
+
"@types/node": ">= 18.18.7"
335
+
}
336
+
}
337
+
```
338
+
339
+
### Cloudflare Workers
340
+
341
+
`tsconfig.json`
342
+
343
+
```jsonc
344
+
{
345
+
"target":"ES2018", // note: we recommend ES2020 or higher
346
+
"lib": ["ES2020"], // <- needed by @cloudflare/workers-types
347
+
"types": ["@cloudflare/workers-types"]
348
+
}
349
+
```
350
+
351
+
`package.json`
352
+
353
+
```json
354
+
{
355
+
"devDependencies": {
356
+
"@cloudflare/workers-types": ">= 0.20221111.0"
357
+
}
358
+
}
359
+
```
360
+
361
+
### Bun
362
+
363
+
`tsconfig.json`
364
+
365
+
```jsonc
366
+
{
367
+
"target":"ES2018"// note: we recommend ES2020 or higher
0 commit comments