@cloudflare/workers-types 2.2.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,20 +1,29 @@
1
1
  {
2
2
  "name": "@cloudflare/workers-types",
3
- "version": "2.2.0",
3
+ "version": "3.1.0",
4
4
  "description": "TypeScript typings for Cloudflare Workers",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/cloudflare/workers-types"
8
8
  },
9
- "main": "index.js",
10
9
  "types": "./index.d.ts",
10
+ "files": [
11
+ "index.d.ts"
12
+ ],
11
13
  "scripts": {
12
- "test": "echo \"Error: no test specified\" && exit 1"
14
+ "export:docs": "node -r esbuild-register export/docs.ts",
15
+ "export:overrides": "node -r esbuild-register export/overrides.ts",
16
+ "test": "tsc"
13
17
  },
14
- "author": "John Fawcett",
18
+ "author": "Cloudflare Workers Team <workers@cloudflare.com> (https://workers.cloudflare.com)",
15
19
  "license": "BSD-3-Clause",
16
20
  "devDependencies": {
21
+ "@types/marked": "^3.0.0",
22
+ "@types/node": "^16.6.1",
23
+ "esbuild": "^0.12.22",
24
+ "esbuild-register": "^3.0.0",
25
+ "marked": "^3.0.2",
17
26
  "prettier": "2.0.5",
18
- "typescript": "^3.9.5"
27
+ "typescript": "^4.3.5"
19
28
  }
20
29
  }
@@ -1 +0,0 @@
1
- * @cloudflare/workers-js
@@ -1,15 +0,0 @@
1
- name: Lint Markdown
2
-
3
- on: [push, pull_request]
4
-
5
- jobs:
6
- build:
7
- runs-on: ubuntu-18.04
8
- steps:
9
- - uses: actions/checkout@v2
10
- - name: Use Node.js
11
- uses: actions/setup-node@v1
12
- with:
13
- node-version: '12.x'
14
- - run: npm install -g markdownlint-cli@0.23.2
15
- - run: markdownlint '**/*.md' --ignore node_modules
package/.markdownlint.yml DELETED
@@ -1,9 +0,0 @@
1
- # MD013/line-length Line length
2
- MD013: false
3
-
4
- # MD014/commands-show-output Dollar signs used before commands without showing output
5
- MD014: false
6
-
7
- # heading duplication is allowed for non-sibling headings (common in change logs)
8
- MD024:
9
- siblings_only: true
package/.prettierrc DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "singleQuote": true,
3
- "printWidth": 100
4
- }
package/CHANGELOG.md DELETED
@@ -1,262 +0,0 @@
1
- # Changelog
2
-
3
- ## 2.1.0
4
-
5
- ### Features
6
-
7
- - **Add types for Durable Objects - [@mathew-cf], [pull/63], [issue/64]**
8
- Types for [Durable Objects Beta](https://developers.cloudflare.com/workers/runtime-apis/durable-objects), subject to change.
9
-
10
- [@mathew-cf]: https://github.com/mathew-cf
11
- [pull/63]: https://github.com/cloudflare/workers-types/pull/63
12
- [issue/64]: https://github.com/cloudflare/workers-types/issues/64
13
-
14
- - **Add ScheduledEvent - [@qwtel], [pull/61]**
15
- Types for [Scheduled Events](https://developers.cloudflare.com/workers/runtime-apis/scheduled-event)
16
-
17
- [@qwtel]: https://github.com/qwtel
18
- [pull/61]: https://github.com/cloudflare/workers-types/pull/61
19
-
20
- - **Add AVIF Format for Image Resizing - [@GregBrimble], [pull/59]**
21
-
22
- [@GregBrimble]: https://github.com/GregBrimble
23
- [pull/59]: https://github.com/cloudflare/workers-types/pull/59
24
-
25
- - **Add metadata typings for KV - [@GregBrimble], [pull/54]**
26
- Adds the [new metadata](https://developers.cloudflare.com/workers/runtime-apis/kv#metadata) types to the getWithMetadata, put and list methods on a KV namespace.
27
-
28
- [@GregBrimble]: https://github.com/GregBrimble
29
- [pull/54]: https://github.com/cloudflare/workers-types/pull/54
30
-
31
- - **Complete Image Resizing properties - [@GregBrimble], [pull/50]**
32
- Adds missing options for the Image Resizing API.
33
-
34
- [@GregBrimble]: https://github.com/GregBrimble
35
- [pull/50]: https://github.com/cloudflare/workers-types/pull/50
36
-
37
- - **Add API for async handlers and end handler - [@ObsidianMinor], [pull/48]**
38
- Types for [HTML Rewriter](https://developers.cloudflare.com/workers/runtime-apis/html-rewriter#end) end of document append method
39
-
40
- [@ObsidianMinor]: https://github.com/ObsidianMinor
41
- [pull/48]: https://github.com/cloudflare/workers-types/pull/48
42
-
43
- ### Bugfixes
44
-
45
- - **Make Element.attributes iterable - [@jdanyow], [pull/47]**
46
-
47
- Fixing a bug in the type definitions that prevents writing valid code like this:
48
-
49
- ```typescript
50
- rewriter.on('bla', {
51
- element: element => {
52
- for (const [name, value] of element.attributes) {
53
- ```
54
-
55
- [@jdanyow]: https://github.com/jdanyow
56
- [pull/47]: https://github.com/cloudflare/workers-types/pull/47
57
-
58
- ### Maintenance
59
-
60
- - **Update README.md instructions to avoid typescript error - [@jeremistadler], [pull/60]**
61
- Add empty export to bindings.d.ts example to avoid an typescript error
62
-
63
- [@jeremistadler]: https://github.com/jeremistadler
64
- [pull/60]: https://github.com/cloudflare/workers-types/pull/60
65
-
66
- - **Add a GitHub action to lint the Markdown - [@jbampton],[pull/51]**
67
-
68
- [@jbampton]: https://github.com/jbampton
69
- [pull/51]: https://github.com/cloudflare/workers-types/pull/51
70
-
71
- - **Fix spelling - [@jbampton],[pull/50]**
72
-
73
- [@jbampton]: https://github.com/jbampton
74
- [pull/50]: https://github.com/cloudflare/workers-types/pull/50
75
-
76
- - **Add CODEOWNERS - [@ispivey], [pull/49]**
77
- This will ensure we have default reviewers.
78
-
79
- [@ispivey]: https://github.com/ispivey
80
- [pull/48]: https://github.com/cloudflare/workers-types/pull/48
81
-
82
- - **Add prettier and typescript as devDependencies - [@1000hz], [pull/46]**
83
- Automated formatting via prettier
84
-
85
- [@1000hz]: https://github.com/1000hz
86
- [pull/46]: https://github.com/cloudflare/workers-types/pull/46
87
-
88
- ## ⌨️ 2.0.0
89
-
90
- ### Breaking Changes
91
-
92
- - **Types now only provided via automatic type inclusion, rather than explicit import - [@jdanyow], [issue/33], [pull/34]**
93
-
94
- Users should no longer use an empty import to include `workers-types`, which used to be the recommendation in the README.
95
-
96
- Remove this from your code:
97
-
98
- ```typescript
99
- import {} from '@cloudflare/workers-types'
100
- ```
101
-
102
- And instead include the types explicitly in your TypeScript configuration compiler options:
103
-
104
- ```json
105
- {
106
- "compilerOptions": {
107
- "types": ["@cloudflare/workers-types"]
108
- }
109
- }
110
- ```
111
-
112
- [@jdanyow]: https://github.com/jdanyow
113
- [pull/34]: https://github.com/cloudflare/workers-types/pull/34
114
- [issue/33]: https://github.com/cloudflare/workers-types/issues/33
115
-
116
- ### Features
117
-
118
- - **Add Cache behavior modifiers to outbound Requests - [@trjstewart], [issue/22], [pull/17]**
119
-
120
- When constructing a request, you can now include the following cache-manipulating properties in the initializer dictionary:
121
-
122
- ```typescript
123
- // Force response to be cached for 300 seconds.
124
- fetch(event.request, { cf: { cacheTtl: 300 } })
125
-
126
- // Force response to be cached for 86400 seconds for 200 status codes, 1 second for 404, and do not cache 500 errors
127
- fetch(request, { cf: { cacheTtlByStatus: { '200-299': 86400, '404': 1, '500-599': 0 } } })
128
- ```
129
-
130
- Read more about these properties in the [`Request` docs](https://developers.cloudflare.com/workers/reference/apis/request/).
131
-
132
- [@trjstewart]: https://github.com/trjstewart
133
- [pull/17]: https://github.com/cloudflare/workers-types/pull/17
134
- [issue/22]: https://github.com/cloudflare/workers-types/issues/22
135
-
136
- - **Add support for `caches.default` - [@ispivey], [@ashnewmanjones], [issue/8], [pull/21]**
137
-
138
- The Workers runtime exposes a default global cache as `caches.default`, accessed like:
139
-
140
- ```typescript
141
- let cache = caches.default
142
- ```
143
-
144
- This is an extension to the [Service Workers spec for `CacheStorage`](https://w3c.github.io/ServiceWorker/#cachestorage), and thus needed to be added explicitly to our type definitions.
145
-
146
- [@ispivey]: https://github.com/ispivey
147
- [@ashnewmanjones]: https://github.com/ashnewmanjones
148
- [pull/21]: https://github.com/cloudflare/workers-types/pull/21
149
- [issue/8]: https://github.com/cloudflare/workers-types/issues/8
150
-
151
- - **Add missing properties to inbound `Request` `cf` object - [@ispivey], [@brycematheson1234], [issue/23], [pull/24], [pull/35]**
152
-
153
- Adds:
154
-
155
- - `clientTcpRtt`
156
- - `metroCode`
157
- - `botManagement.score`
158
- - `botManagement.staticResource`
159
- - `botManagement.verifiedBot`
160
-
161
- Makes most geolocation properties optional, because they are not guaranteed to be set on every request.
162
-
163
- Changes the type of `asn` from string to number.
164
-
165
- [@ispivey]: https://github.com/ispivey
166
- [@brycematheson1234]: https://github.com/brycematheson1234
167
- [issue/23]: https://github.com/cloudflare/workers-types/issues/23
168
- [pull/24]: https://github.com/cloudflare/workers-types/pull/24
169
- [pull/35]: https://github.com/cloudflare/workers-types/pull/35
170
-
171
- - **Adds `cf.cacheKey` property to `RequestInit` - [@ispivey], [issue/22], [pull/28]**
172
-
173
- Adds the `cacheKey` property of the `cf` object to the `RequestInit` interface.
174
-
175
- [@ispivey]: https://github.com/ispivey
176
- [pull/28]: https://github.com/cloudflare/workers-types/pull/28
177
- [issue/22]: https://github.com/cloudflare/workers-types/issues/22
178
-
179
- - **Allow passing another Request as the `init` arg to `Request` constructor - [@ispivey], [issue/15], [pull/18]**
180
-
181
- Previously, this pattern wasn't allowed:
182
-
183
- ```typescript
184
- new Request(parsedUrl.toString(), request)
185
- ```
186
-
187
- This is because the `cf` object on inbound Request objects, and that expected in the `init` dictionary arg to the Request constructor, have a different shape.
188
-
189
- This change creates explicit `IncomingRequestCfProperties` (inbound) and `RequestInitCfProperties` (outbound) interfaces, and updates the `Request` constructor to accept either type:
190
-
191
- ```typescript
192
- interface RequestInit {
193
- cf?: RequestInitCfProperties | IncomingRequestCfProperties
194
- }
195
- ```
196
-
197
- Read more about the `Request` constructor in the [`Request` docs](https://developers.cloudflare.com/workers/reference/apis/request/).
198
-
199
- [@ispivey]: https://github.com/ispivey
200
- [pull/18]: https://github.com/cloudflare/workers-types/pull/18
201
- [issue/15]: https://github.com/cloudflare/workers-types/issues/15
202
-
203
- - **Add `CfRequestInit` type - [@third774], [issue/37], [pull/44]**
204
-
205
- Because of the union mentioned above, if an object is declared as `RequestInit` and sets the `cf` property, subproperties of `cf` can not later be reassigned. For this scenario, a more specific `CfRequestInit` type has been introduced to use instead of `RequestInit` that doesn't exhibit the same assignability issues.
206
-
207
- [@third774]: https://github.com/third774
208
- [pull/44]: https://github.com/cloudflare/workers-types/pull/44
209
- [issue/37]: https://github.com/cloudflare/workers-types/issues/37
210
-
211
- - **Add iterable methods to `FormData`, `Headers`, and `URLSearchParams` - [@ispivey], [issue/25], [pull/26]**
212
-
213
- The iterable methods `entries()`, `keys()` and `values()` are not present on these three types in `lib.webworker.d.ts`. They are instead supplied in `lib.dom.iterable.d.ts`.
214
-
215
- However, as discussed in this issue on the TypeScript repo, `lib.dom.d.ts` and `lib.webworker.d.ts` have conflicting type definitions, and the maintainers hope to solve this issue by refactoring shared components into a new `web.iterable.d.ts` lib: [https://github.com/microsoft/TypeScript/issues/32435#issuecomment-624741120](https://github.com/microsoft/TypeScript/issues/32435#issuecomment-624741120)
216
-
217
- Until then, we will include the iterable methods supported by Workers in our own type definitions.
218
-
219
- [@ispivey]: https://github.com/ispivey
220
- [pull/26]: https://github.com/cloudflare/workers-types/pull/26
221
- [issue/25]: https://github.com/cloudflare/workers-types/issues/25
222
-
223
- ### Bugfixes
224
-
225
- - **Remove `selector` parameter from `onDocument()` - [@jdanyow], [pull/41]**
226
-
227
- The type signature for HTMLRewriter's `onDocument()` method previously erroneously included a `selector` parameter as its first argument. This has been removed.
228
-
229
- [@jdanyow]: https://github.com/jdanyow
230
- [pull/41]: https://github.com/cloudflare/workers-types/pull/41
231
-
232
- - **Make `KVNamespace.list()` options argument optional - [@motiejunas], [pull/10]**
233
-
234
- Previously, the `KVNamespace` interface required that callers provide an empty options object when listing all the keys in a namespace, like so:
235
-
236
- ```typescript
237
- await NAMESPACE.list({})
238
- ```
239
-
240
- However, this argument is not actually required. This change updates the interface to match the runtime.
241
-
242
- [@motiejunas]: https://github.com/motiejunas
243
- [pull/10]: https://github.com/cloudflare/workers-types/pull/10
244
-
245
- ### Maintenance
246
-
247
- - **Add a Release Checklist - [@ispivey], [issue/20], [pull/27]**
248
-
249
- As we onboard more contributors, we're documenting release procedures.
250
-
251
- [@ispivey]: https://github.com/ispivey
252
- [pull/27]: https://github.com/cloudflare/workers-types/pull/27
253
- [issue/20]: https://github.com/cloudflare/workers-types/issues/20
254
-
255
- - **Add BSD-3 License - [@ispivey], [issue/31], [pull/30], [pull/40]**
256
-
257
- As we transition this to a project supported by the Cloudflare Workers team, we're releasing the code under a BSD-3 license. Thanks to all the contributors for their help!
258
-
259
- [@ispivey]: https://github.com/ispivey
260
- [pull/30]: https://github.com/cloudflare/workers-types/pull/30
261
- [pull/40]: https://github.com/cloudflare/workers-types/pull/40
262
- [issue/31]: https://github.com/cloudflare/workers-types/issues/31
package/test.ts DELETED
@@ -1,49 +0,0 @@
1
- const init: CfRequestInit = {
2
- cf: {
3
- cacheEverything: true,
4
- // properties from IncomingRequestCfProperties
5
- // should not be assignable here
6
- // @ts-expect-error
7
- colo: 'hi',
8
- },
9
- }
10
-
11
- if (init.cf) {
12
- // properties on init.cf are known to be RequestInitCfProperties
13
- init.cf.cacheEverything = false
14
- }
15
-
16
- // CfRequestInit works with fetch
17
- fetch('hi', init)
18
-
19
- // CfRequestInit works with Request
20
- new Request('hi', init)
21
-
22
- // FetchEvent is manually specified and assignable
23
- addEventListener('fetch', (event: FetchEvent) => {
24
- // RequestInitCfProperties should not be present
25
- // @ts-expect-error
26
- event.request.cf.cacheEverything
27
- // request from FetchEvent is assignable within request
28
- // constructor as RequestInit
29
- new Request('hi', event.request)
30
- // request from FetchEvent works with handle function
31
- event.respondWith(handle(event.request))
32
- })
33
-
34
- function handle(request: Request) {
35
- if (!request.cf) return new Response('hi')
36
- return new Response(request.cf.colo)
37
- }
38
-
39
- class MyDurableObject implements DurableObject {
40
- async fetch(request: Request) {
41
- return new Response("Hello, world!")
42
- }
43
- }
44
-
45
- type MyDurableObjectNamespace = DurableObjectNamespace
46
-
47
- const MyDurableObjectNamespace: DurableObjectNamespace = undefined as any
48
- const myDurableObjectStub = MyDurableObjectNamespace.get(MyDurableObjectNamespace.newUniqueId())
49
- myDurableObjectStub.fetch('/', { method: 'POST' })