@cloudflare/workers-types 2.2.2 → 3.2.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.2",
3
+ "version": "3.2.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,272 +0,0 @@
1
- # Changelog
2
-
3
- ## 2.2.2
4
-
5
- ### Features
6
-
7
- - **Add KVNamespace.get options parameter, with cacheTtl - [@bretthoerner], [pull/87]**
8
-
9
- ### Bugfixes
10
-
11
- - **fix DurableObjectStorage transaction method signature - [@sbfaulkner], [pull/89]**
12
-
13
- ## 2.1.0
14
-
15
- ### Features
16
-
17
- - **Add types for Durable Objects - [@mathew-cf], [pull/63], [issue/64]**
18
- Types for [Durable Objects Beta](https://developers.cloudflare.com/workers/runtime-apis/durable-objects), subject to change.
19
-
20
- [@mathew-cf]: https://github.com/mathew-cf
21
- [pull/63]: https://github.com/cloudflare/workers-types/pull/63
22
- [issue/64]: https://github.com/cloudflare/workers-types/issues/64
23
-
24
- - **Add ScheduledEvent - [@qwtel], [pull/61]**
25
- Types for [Scheduled Events](https://developers.cloudflare.com/workers/runtime-apis/scheduled-event)
26
-
27
- [@qwtel]: https://github.com/qwtel
28
- [pull/61]: https://github.com/cloudflare/workers-types/pull/61
29
-
30
- - **Add AVIF Format for Image Resizing - [@GregBrimble], [pull/59]**
31
-
32
- [@GregBrimble]: https://github.com/GregBrimble
33
- [pull/59]: https://github.com/cloudflare/workers-types/pull/59
34
-
35
- - **Add metadata typings for KV - [@GregBrimble], [pull/54]**
36
- 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.
37
-
38
- [@GregBrimble]: https://github.com/GregBrimble
39
- [pull/54]: https://github.com/cloudflare/workers-types/pull/54
40
-
41
- - **Complete Image Resizing properties - [@GregBrimble], [pull/50]**
42
- Adds missing options for the Image Resizing API.
43
-
44
- [@GregBrimble]: https://github.com/GregBrimble
45
- [pull/50]: https://github.com/cloudflare/workers-types/pull/50
46
-
47
- - **Add API for async handlers and end handler - [@ObsidianMinor], [pull/48]**
48
- Types for [HTML Rewriter](https://developers.cloudflare.com/workers/runtime-apis/html-rewriter#end) end of document append method
49
-
50
- [@ObsidianMinor]: https://github.com/ObsidianMinor
51
- [pull/48]: https://github.com/cloudflare/workers-types/pull/48
52
-
53
- ### Bugfixes
54
-
55
- - **Make Element.attributes iterable - [@jdanyow], [pull/47]**
56
-
57
- Fixing a bug in the type definitions that prevents writing valid code like this:
58
-
59
- ```typescript
60
- rewriter.on('bla', {
61
- element: element => {
62
- for (const [name, value] of element.attributes) {
63
- ```
64
-
65
- [@jdanyow]: https://github.com/jdanyow
66
- [pull/47]: https://github.com/cloudflare/workers-types/pull/47
67
-
68
- ### Maintenance
69
-
70
- - **Update README.md instructions to avoid typescript error - [@jeremistadler], [pull/60]**
71
- Add empty export to bindings.d.ts example to avoid an typescript error
72
-
73
- [@jeremistadler]: https://github.com/jeremistadler
74
- [pull/60]: https://github.com/cloudflare/workers-types/pull/60
75
-
76
- - **Add a GitHub action to lint the Markdown - [@jbampton],[pull/51]**
77
-
78
- [@jbampton]: https://github.com/jbampton
79
- [pull/51]: https://github.com/cloudflare/workers-types/pull/51
80
-
81
- - **Fix spelling - [@jbampton],[pull/50]**
82
-
83
- [@jbampton]: https://github.com/jbampton
84
- [pull/50]: https://github.com/cloudflare/workers-types/pull/50
85
-
86
- - **Add CODEOWNERS - [@ispivey], [pull/49]**
87
- This will ensure we have default reviewers.
88
-
89
- [@ispivey]: https://github.com/ispivey
90
- [pull/48]: https://github.com/cloudflare/workers-types/pull/48
91
-
92
- - **Add prettier and typescript as devDependencies - [@1000hz], [pull/46]**
93
- Automated formatting via prettier
94
-
95
- [@1000hz]: https://github.com/1000hz
96
- [pull/46]: https://github.com/cloudflare/workers-types/pull/46
97
-
98
- ## ⌨️ 2.0.0
99
-
100
- ### Breaking Changes
101
-
102
- - **Types now only provided via automatic type inclusion, rather than explicit import - [@jdanyow], [issue/33], [pull/34]**
103
-
104
- Users should no longer use an empty import to include `workers-types`, which used to be the recommendation in the README.
105
-
106
- Remove this from your code:
107
-
108
- ```typescript
109
- import {} from '@cloudflare/workers-types'
110
- ```
111
-
112
- And instead include the types explicitly in your TypeScript configuration compiler options:
113
-
114
- ```json
115
- {
116
- "compilerOptions": {
117
- "types": ["@cloudflare/workers-types"]
118
- }
119
- }
120
- ```
121
-
122
- [@jdanyow]: https://github.com/jdanyow
123
- [pull/34]: https://github.com/cloudflare/workers-types/pull/34
124
- [issue/33]: https://github.com/cloudflare/workers-types/issues/33
125
-
126
- ### Features
127
-
128
- - **Add Cache behavior modifiers to outbound Requests - [@trjstewart], [issue/22], [pull/17]**
129
-
130
- When constructing a request, you can now include the following cache-manipulating properties in the initializer dictionary:
131
-
132
- ```typescript
133
- // Force response to be cached for 300 seconds.
134
- fetch(event.request, { cf: { cacheTtl: 300 } })
135
-
136
- // Force response to be cached for 86400 seconds for 200 status codes, 1 second for 404, and do not cache 500 errors
137
- fetch(request, { cf: { cacheTtlByStatus: { '200-299': 86400, '404': 1, '500-599': 0 } } })
138
- ```
139
-
140
- Read more about these properties in the [`Request` docs](https://developers.cloudflare.com/workers/reference/apis/request/).
141
-
142
- [@trjstewart]: https://github.com/trjstewart
143
- [pull/17]: https://github.com/cloudflare/workers-types/pull/17
144
- [issue/22]: https://github.com/cloudflare/workers-types/issues/22
145
-
146
- - **Add support for `caches.default` - [@ispivey], [@ashnewmanjones], [issue/8], [pull/21]**
147
-
148
- The Workers runtime exposes a default global cache as `caches.default`, accessed like:
149
-
150
- ```typescript
151
- let cache = caches.default
152
- ```
153
-
154
- 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.
155
-
156
- [@ispivey]: https://github.com/ispivey
157
- [@ashnewmanjones]: https://github.com/ashnewmanjones
158
- [pull/21]: https://github.com/cloudflare/workers-types/pull/21
159
- [issue/8]: https://github.com/cloudflare/workers-types/issues/8
160
-
161
- - **Add missing properties to inbound `Request` `cf` object - [@ispivey], [@brycematheson1234], [issue/23], [pull/24], [pull/35]**
162
-
163
- Adds:
164
-
165
- - `clientTcpRtt`
166
- - `metroCode`
167
- - `botManagement.score`
168
- - `botManagement.staticResource`
169
- - `botManagement.verifiedBot`
170
-
171
- Makes most geolocation properties optional, because they are not guaranteed to be set on every request.
172
-
173
- Changes the type of `asn` from string to number.
174
-
175
- [@ispivey]: https://github.com/ispivey
176
- [@brycematheson1234]: https://github.com/brycematheson1234
177
- [issue/23]: https://github.com/cloudflare/workers-types/issues/23
178
- [pull/24]: https://github.com/cloudflare/workers-types/pull/24
179
- [pull/35]: https://github.com/cloudflare/workers-types/pull/35
180
-
181
- - **Adds `cf.cacheKey` property to `RequestInit` - [@ispivey], [issue/22], [pull/28]**
182
-
183
- Adds the `cacheKey` property of the `cf` object to the `RequestInit` interface.
184
-
185
- [@ispivey]: https://github.com/ispivey
186
- [pull/28]: https://github.com/cloudflare/workers-types/pull/28
187
- [issue/22]: https://github.com/cloudflare/workers-types/issues/22
188
-
189
- - **Allow passing another Request as the `init` arg to `Request` constructor - [@ispivey], [issue/15], [pull/18]**
190
-
191
- Previously, this pattern wasn't allowed:
192
-
193
- ```typescript
194
- new Request(parsedUrl.toString(), request)
195
- ```
196
-
197
- 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.
198
-
199
- This change creates explicit `IncomingRequestCfProperties` (inbound) and `RequestInitCfProperties` (outbound) interfaces, and updates the `Request` constructor to accept either type:
200
-
201
- ```typescript
202
- interface RequestInit {
203
- cf?: RequestInitCfProperties | IncomingRequestCfProperties
204
- }
205
- ```
206
-
207
- Read more about the `Request` constructor in the [`Request` docs](https://developers.cloudflare.com/workers/reference/apis/request/).
208
-
209
- [@ispivey]: https://github.com/ispivey
210
- [pull/18]: https://github.com/cloudflare/workers-types/pull/18
211
- [issue/15]: https://github.com/cloudflare/workers-types/issues/15
212
-
213
- - **Add `CfRequestInit` type - [@third774], [issue/37], [pull/44]**
214
-
215
- 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.
216
-
217
- [@third774]: https://github.com/third774
218
- [pull/44]: https://github.com/cloudflare/workers-types/pull/44
219
- [issue/37]: https://github.com/cloudflare/workers-types/issues/37
220
-
221
- - **Add iterable methods to `FormData`, `Headers`, and `URLSearchParams` - [@ispivey], [issue/25], [pull/26]**
222
-
223
- 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`.
224
-
225
- 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)
226
-
227
- Until then, we will include the iterable methods supported by Workers in our own type definitions.
228
-
229
- [@ispivey]: https://github.com/ispivey
230
- [pull/26]: https://github.com/cloudflare/workers-types/pull/26
231
- [issue/25]: https://github.com/cloudflare/workers-types/issues/25
232
-
233
- ### Bugfixes
234
-
235
- - **Remove `selector` parameter from `onDocument()` - [@jdanyow], [pull/41]**
236
-
237
- The type signature for HTMLRewriter's `onDocument()` method previously erroneously included a `selector` parameter as its first argument. This has been removed.
238
-
239
- [@jdanyow]: https://github.com/jdanyow
240
- [pull/41]: https://github.com/cloudflare/workers-types/pull/41
241
-
242
- - **Make `KVNamespace.list()` options argument optional - [@motiejunas], [pull/10]**
243
-
244
- Previously, the `KVNamespace` interface required that callers provide an empty options object when listing all the keys in a namespace, like so:
245
-
246
- ```typescript
247
- await NAMESPACE.list({})
248
- ```
249
-
250
- However, this argument is not actually required. This change updates the interface to match the runtime.
251
-
252
- [@motiejunas]: https://github.com/motiejunas
253
- [pull/10]: https://github.com/cloudflare/workers-types/pull/10
254
-
255
- ### Maintenance
256
-
257
- - **Add a Release Checklist - [@ispivey], [issue/20], [pull/27]**
258
-
259
- As we onboard more contributors, we're documenting release procedures.
260
-
261
- [@ispivey]: https://github.com/ispivey
262
- [pull/27]: https://github.com/cloudflare/workers-types/pull/27
263
- [issue/20]: https://github.com/cloudflare/workers-types/issues/20
264
-
265
- - **Add BSD-3 License - [@ispivey], [issue/31], [pull/30], [pull/40]**
266
-
267
- 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!
268
-
269
- [@ispivey]: https://github.com/ispivey
270
- [pull/30]: https://github.com/cloudflare/workers-types/pull/30
271
- [pull/40]: https://github.com/cloudflare/workers-types/pull/40
272
- [issue/31]: https://github.com/cloudflare/workers-types/issues/31
package/test.ts DELETED
@@ -1,61 +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' })
50
-
51
- const myKVNamespace: KVNamespace = undefined as any;
52
- myKVNamespace.get("foo");
53
- myKVNamespace.get("foo", {cacheTtl: 60});
54
- myKVNamespace.get("foo", {cacheTtl: 60, type: "text"});
55
- myKVNamespace.get("foo", {type: "text"});
56
- myKVNamespace.get("foo", {cacheTtl: 60, type: "json"});
57
- myKVNamespace.get("foo", {type: "json"});
58
- myKVNamespace.get("foo", {cacheTtl: 60, type: "arrayBuffer"});
59
- myKVNamespace.get("foo", {type: "arrayBuffer"});
60
- myKVNamespace.get("foo", {cacheTtl: 60, type: "stream"});
61
- myKVNamespace.get("foo", {type: "stream"});