@cloudflare/workers-types 3.0.0 → 3.3.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.
Files changed (3) hide show
  1. package/index.d.ts +406 -197
  2. package/package.json +1 -1
  3. package/CHANGELOG.md +0 -282
package/index.d.ts CHANGED
@@ -1,13 +1,19 @@
1
+ // This file is auto-generated. DO NOT MODIFY.
2
+ // Please refer to the Auto-Generation section of the README.md.
3
+
1
4
  declare class AbortController {
2
5
  constructor();
3
6
  readonly signal: AbortSignal;
4
- abort(): void;
7
+ abort(reason?: any): void;
5
8
  }
6
9
 
7
10
  declare class AbortSignal extends EventTarget {
8
11
  constructor();
9
- static abort(): AbortSignal;
12
+ static abort(reason?: any): AbortSignal;
13
+ static timeout(delay: number): AbortSignal;
10
14
  readonly aborted: boolean;
15
+ readonly reason: any;
16
+ throwIfAborted(): void;
11
17
  }
12
18
 
13
19
  interface BasicImageTransformations {
@@ -32,10 +38,11 @@ interface BasicImageTransformations {
32
38
  * - cover: Resizes (shrinks or enlarges) to fill the entire area of width
33
39
  * and height. If the image has an aspect ratio different from the ratio
34
40
  * of width and height, it will be cropped to fit.
35
- * - crop: The image will shrunk and cropped to fit within the area
36
- * specified by width and height. The image won’t be enlarged. For images
37
- * smaller than the given dimensions its the same as scale-down. For
38
- * images larger than the given dimensions, its the same as cover.
41
+ * - crop: The image will be shrunk and cropped to fit within the area
42
+ * specified by width and height. The image will not be enlarged. For images
43
+ * smaller than the given dimensions it's the same as scale-down. For
44
+ * images larger than the given dimensions, it's the same as cover.
45
+ * See also trim.
39
46
  * - pad: Resizes to the maximum size that fits within the given width and
40
47
  * height, and then fills the remaining area with a background color
41
48
  * (white by default). Use of this mode is not recommended, as the same
@@ -46,7 +53,7 @@ interface BasicImageTransformations {
46
53
  /**
47
54
  * When cropping with fit: "cover", this defines the side or point that should
48
55
  * be left uncropped. The value is either a string
49
- * "left", "right", "top", "bottom" or "center" (the default),
56
+ * "left", "right", "top", "bottom", "auto", or "center" (the default),
50
57
  * or an object {x, y} containing focal point coordinates in the original
51
58
  * image expressed as fractions ranging from 0.0 (top or left) to 1.0
52
59
  * (bottom or right), 0.5 being the center. {fit: "cover", gravity: "top"} will
@@ -55,7 +62,7 @@ interface BasicImageTransformations {
55
62
  * preserve as much as possible around a point at 20% of the height of the
56
63
  * source image.
57
64
  */
58
- gravity?: "left" | "right" | "top" | "bottom" | "center" | BasicImageTransformationsGravityCoordinates;
65
+ gravity?: "left" | "right" | "top" | "bottom" | "center" | "auto" | BasicImageTransformationsGravityCoordinates;
59
66
  /**
60
67
  * Background color to add underneath the image. Applies only to images with
61
68
  * transparency (such as PNG). Accepts any CSS color (#RRGGBB, rgba(…),
@@ -100,7 +107,13 @@ declare abstract class Body {
100
107
  blob(): Promise<Blob>;
101
108
  }
102
109
 
103
- declare type BodyInitializer = ReadableStream | string | ArrayBuffer | Blob | URLSearchParams | FormData;
110
+ declare type BodyInit = ReadableStream | string | ArrayBuffer | Blob | URLSearchParams | FormData;
111
+
112
+ /**
113
+ * Back compat for code migrating to older definitions.
114
+ * @deprecated Use BodyInit instead.
115
+ */
116
+ declare type BodyInitializer = BodyInit;
104
117
 
105
118
  declare abstract class Cache {
106
119
  delete(request: Request | string, options?: CacheQueryOptions): Promise<boolean>;
@@ -117,24 +130,36 @@ declare abstract class CacheStorage {
117
130
  readonly default: Cache;
118
131
  }
119
132
 
120
- interface CfRequestInitializerDict extends Omit<RequestInitializerDict, "cf"> {
133
+ interface CfRequestInit extends Omit<RequestInit, "cf"> {
121
134
  cf?: RequestInitCfProperties;
122
135
  }
123
136
 
137
+ /**
138
+ * Back compat support with older types.
139
+ * @deprecated Use CfRequestInit instead.
140
+ */
141
+ declare type CfRequestInitializerDict = CfRequestInit;
142
+
124
143
  declare class CloseEvent extends Event {
125
- constructor(type: string, initializer: CloseEventInitializer);
144
+ constructor(type: string, initializer: CloseEventInit);
126
145
  readonly code: number;
127
146
  readonly reason: string;
128
147
  readonly wasClean: boolean;
129
148
  }
130
149
 
131
- interface CloseEventInitializer {
150
+ interface CloseEventInit {
132
151
  code?: number;
133
152
  reason?: string;
134
153
  wasClean?: boolean;
135
154
  }
136
155
 
137
- declare abstract class Comment {
156
+ /**
157
+ * Back compat for code migrating from older definitions.
158
+ * @deprecated Use CloseEventInit instead.
159
+ */
160
+ declare type CloseEventInitializer = CloseEventInit;
161
+
162
+ interface Comment {
138
163
  text: string;
139
164
  readonly removed: boolean;
140
165
  before(content: Content, options?: ContentOptions): Comment;
@@ -159,7 +184,7 @@ interface ContentOptions {
159
184
 
160
185
  declare abstract class Crypto {
161
186
  readonly subtle: SubtleCrypto;
162
- getRandomValues(buffer: ArrayBufferView): ArrayBufferView;
187
+ getRandomValues<T extends Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array>(buffer: T): T;
163
188
  randomUUID(): string;
164
189
  }
165
190
 
@@ -245,13 +270,18 @@ declare class DOMException extends Error {
245
270
  static readonly DATA_CLONE_ERR: number;
246
271
  }
247
272
 
248
- declare abstract class Doctype {
273
+ declare class DigestStream extends WritableStream {
274
+ constructor(algorithm: string | SubtleCryptoHashAlgorithm);
275
+ readonly digest: Promise<ArrayBuffer>;
276
+ }
277
+
278
+ interface Doctype {
249
279
  readonly name: string | null;
250
280
  readonly publicId: string | null;
251
281
  readonly systemId: string | null;
252
282
  }
253
283
 
254
- declare abstract class DocumentEnd {
284
+ interface DocumentEnd {
255
285
  append(content: Content, options?: ContentOptions): DocumentEnd;
256
286
  }
257
287
 
@@ -259,13 +289,28 @@ interface DurableObject {
259
289
  fetch(request: Request): Promise<Response>;
260
290
  }
261
291
 
262
- declare abstract class DurableObjectId {
292
+ interface DurableObjectGetOptions {
293
+ allowConcurrency?: boolean;
294
+ noCache?: boolean;
295
+ }
296
+
297
+ interface DurableObjectId {
263
298
  toString(): string;
264
299
  equals(other: DurableObjectId): boolean;
265
300
  readonly name?: string;
266
301
  }
267
302
 
268
- declare abstract class DurableObjectNamespace {
303
+ interface DurableObjectListOptions {
304
+ start?: string;
305
+ end?: string;
306
+ prefix?: string;
307
+ reverse?: boolean;
308
+ limit?: number;
309
+ allowConcurrency?: boolean;
310
+ noCache?: boolean;
311
+ }
312
+
313
+ interface DurableObjectNamespace {
269
314
  newUniqueId(options?: DurableObjectNamespaceNewUniqueIdOptions): DurableObjectId;
270
315
  idFromName(name: string): DurableObjectId;
271
316
  idFromString(id: string): DurableObjectId;
@@ -276,63 +321,66 @@ interface DurableObjectNamespaceNewUniqueIdOptions {
276
321
  jurisdiction?: string;
277
322
  }
278
323
 
279
- declare abstract class DurableObjectState {
280
- waitUntil(promise: Promise<void>): void;
324
+ interface DurableObjectPutOptions {
325
+ allowConcurrency?: boolean;
326
+ allowUnconfirmed?: boolean;
327
+ noCache?: boolean;
328
+ }
329
+
330
+ interface DurableObjectState {
331
+ waitUntil(promise: Promise<any>): void;
281
332
  readonly id: DurableObjectId | string;
282
- readonly storage?: DurableObjectStorage;
333
+ readonly storage: DurableObjectStorage;
283
334
  blockConcurrencyWhile<T>(callback: () => Promise<T>): Promise<T>;
284
335
  }
285
336
 
286
- declare abstract class DurableObjectStorage {
287
- get<T = unknown>(key: string, options?: DurableObjectStorageOperationsGetOptions): Promise<T | undefined>;
288
- get<T = unknown>(keys: string[], options?: DurableObjectStorageOperationsGetOptions): Promise<Map<string, T>>;
289
- list<T = unknown>(options?: DurableObjectStorageOperationsListOptions): Promise<Map<string, T>>;
290
- put<T>(key: string, value: T, options?: DurableObjectStorageOperationsPutOptions): Promise<void>;
291
- put<T>(entries: Record<string, T>, options?: DurableObjectStorageOperationsPutOptions): Promise<void>;
292
- delete(key: string, options?: DurableObjectStorageOperationsPutOptions): Promise<boolean>;
293
- delete(keys: string[], options?: DurableObjectStorageOperationsPutOptions): Promise<number>;
294
- deleteAll(options?: DurableObjectStorageOperationsPutOptions): Promise<void>;
337
+ interface DurableObjectStorage {
338
+ get<T = unknown>(key: string, options?: DurableObjectGetOptions): Promise<T | undefined>;
339
+ get<T = unknown>(keys: string[], options?: DurableObjectGetOptions): Promise<Map<string, T>>;
340
+ list<T = unknown>(options?: DurableObjectListOptions): Promise<Map<string, T>>;
341
+ put<T>(key: string, value: T, options?: DurableObjectPutOptions): Promise<void>;
342
+ put<T>(entries: Record<string, T>, options?: DurableObjectPutOptions): Promise<void>;
343
+ delete(key: string, options?: DurableObjectPutOptions): Promise<boolean>;
344
+ delete(keys: string[], options?: DurableObjectPutOptions): Promise<number>;
345
+ deleteAll(options?: DurableObjectPutOptions): Promise<void>;
295
346
  transaction<T>(closure: (txn: DurableObjectTransaction) => Promise<T>): Promise<T>;
296
347
  }
297
348
 
298
- interface DurableObjectStorageOperationsGetOptions {
299
- allowConcurrency?: boolean;
300
- noCache?: boolean;
301
- }
349
+ /**
350
+ *
351
+ * @deprecated Don't use. Introduced incidentally in 3.x. Scheduled for removal.
352
+ */
353
+ declare type DurableObjectStorageOperationsGetOptions = DurableObjectGetOptions;
302
354
 
303
- interface DurableObjectStorageOperationsListOptions {
304
- start?: string;
305
- end?: string;
306
- prefix?: string;
307
- reverse?: boolean;
308
- limit?: number;
309
- allowConcurrency?: boolean;
310
- noCache?: boolean;
311
- }
355
+ /**
356
+ *
357
+ * @deprecated Don't use. Introduced incidentally in 3.x. Scheduled for removal.
358
+ */
359
+ declare type DurableObjectStorageOperationsListOptions = DurableObjectListOptions;
312
360
 
313
- interface DurableObjectStorageOperationsPutOptions {
314
- allowConcurrency?: boolean;
315
- allowUnconfirmed?: boolean;
316
- noCache?: boolean;
317
- }
361
+ /**
362
+ *
363
+ * @deprecated Don't use. Introduced incidentally in 3.x. Scheduled for removal.
364
+ */
365
+ declare type DurableObjectStorageOperationsPutOptions = DurableObjectPutOptions;
318
366
 
319
- declare abstract class DurableObjectStub extends Fetcher {
367
+ interface DurableObjectStub extends Fetcher {
320
368
  readonly id: DurableObjectId;
321
369
  readonly name?: string;
322
370
  }
323
371
 
324
- declare abstract class DurableObjectTransaction {
325
- get<T = unknown>(key: string, options?: DurableObjectStorageOperationsGetOptions): Promise<T>;
326
- get<T = unknown>(keys: string[], options?: DurableObjectStorageOperationsGetOptions): Promise<Map<string, T>>;
327
- list<T = unknown>(options?: DurableObjectStorageOperationsListOptions): Promise<Map<string, T>>;
328
- put<T>(key: string, value: T, options?: DurableObjectStorageOperationsPutOptions): Promise<void>;
329
- put<T>(entries: Record<string, T>, options?: DurableObjectStorageOperationsPutOptions): Promise<void>;
330
- delete(key: string, options?: DurableObjectStorageOperationsPutOptions): Promise<boolean>;
331
- delete(keys: string[], options?: DurableObjectStorageOperationsPutOptions): Promise<number>;
372
+ interface DurableObjectTransaction {
373
+ get<T = unknown>(key: string, options?: DurableObjectGetOptions): Promise<T>;
374
+ get<T = unknown>(keys: string[], options?: DurableObjectGetOptions): Promise<Map<string, T>>;
375
+ list<T = unknown>(options?: DurableObjectListOptions): Promise<Map<string, T>>;
376
+ put<T>(key: string, value: T, options?: DurableObjectPutOptions): Promise<void>;
377
+ put<T>(entries: Record<string, T>, options?: DurableObjectPutOptions): Promise<void>;
378
+ delete(key: string, options?: DurableObjectPutOptions): Promise<boolean>;
379
+ delete(keys: string[], options?: DurableObjectPutOptions): Promise<number>;
332
380
  rollback(): void;
333
381
  }
334
382
 
335
- declare abstract class Element {
383
+ interface Element {
336
384
  tagName: string;
337
385
  readonly attributes: IterableIterator<string[]>;
338
386
  readonly removed: boolean;
@@ -400,14 +448,15 @@ interface EventTargetAddEventListenerOptions {
400
448
  capture?: boolean;
401
449
  passive?: boolean;
402
450
  once?: boolean;
451
+ signal?: AbortSignal;
403
452
  }
404
453
 
405
454
  interface EventTargetEventListenerOptions {
406
455
  capture?: boolean;
407
456
  }
408
457
 
409
- declare abstract class ExecutionContext {
410
- waitUntil(promise: Promise<void>): void;
458
+ interface ExecutionContext {
459
+ waitUntil(promise: Promise<any>): void;
411
460
  passThroughOnException(): void;
412
461
  }
413
462
 
@@ -420,16 +469,15 @@ declare type ExportedHandlerFetchHandler<Env = unknown> = (request: Request, env
420
469
 
421
470
  declare type ExportedHandlerScheduledHandler<Env = unknown> = (controller: ScheduledController, env: Env, ctx: ExecutionContext) => void | Promise<void>;
422
471
 
423
- declare class FetchEvent extends Event {
424
- constructor(type: string);
472
+ declare abstract class FetchEvent extends Event {
425
473
  readonly request: Request;
426
474
  respondWith(promise: Response | Promise<Response>): void;
427
475
  passThroughOnException(): void;
428
- waitUntil(promise: Promise<void>): void;
476
+ waitUntil(promise: Promise<any>): void;
429
477
  }
430
478
 
431
479
  declare abstract class Fetcher {
432
- fetch(requestOrUrl: Request | string, requestInit?: RequestInitializerDict | Request): Promise<Response>;
480
+ fetch(requestOrUrl: Request | string, requestInit?: RequestInit | Request): Promise<Response>;
433
481
  }
434
482
 
435
483
  declare class File extends Blob {
@@ -485,7 +533,7 @@ interface HTMLRewriterElementContentHandlers {
485
533
  }
486
534
 
487
535
  declare class Headers {
488
- constructor(init?: HeadersInitializer);
536
+ constructor(init?: HeadersInit);
489
537
  get(name: string): string | null;
490
538
  getAll(name: string): string[];
491
539
  has(name: string): boolean;
@@ -499,13 +547,19 @@ declare class Headers {
499
547
  [Symbol.iterator](): IterableIterator<[key: string, value: string]>;
500
548
  }
501
549
 
502
- declare type HeadersInitializer = Headers | Record<string, string> | ([key: string, value: string])[];
550
+ declare type HeadersInit = Headers | Record<string, string> | ([key: string, value: string])[];
551
+
552
+ /**
553
+ * Back compat for code migrating to older definitions.
554
+ * @deprecated Use HeadersInit instead.
555
+ */
556
+ declare type HeadersInitializer = HeadersInit;
503
557
 
504
558
  /**
505
559
  * In addition to the properties on the standard Request object,
506
560
  * the cf object contains extra information about the request provided
507
561
  * by Cloudflare's edge.
508
- *
562
+ *
509
563
  * Note: Currently, settings in the cf object cannot be accessed in the
510
564
  * playground.
511
565
  */
@@ -514,6 +568,11 @@ interface IncomingRequestCfProperties {
514
568
  * (e.g. 395747)
515
569
  */
516
570
  asn: number;
571
+ /**
572
+ * The organisation which owns the ASN of the incoming request.
573
+ * (e.g. Google Cloud)
574
+ */
575
+ asOrganization: string;
517
576
  botManagement?: IncomingRequestCfPropertiesBotManagement;
518
577
  city?: string;
519
578
  clientTcpRtt: number;
@@ -586,11 +645,32 @@ interface IncomingRequestCfPropertiesTLSClientAuth {
586
645
  certVerified: string;
587
646
  }
588
647
 
648
+ interface JsonWebKey {
649
+ kty: string;
650
+ use?: string;
651
+ key_ops?: string[];
652
+ alg?: string;
653
+ ext?: boolean;
654
+ crv?: string;
655
+ x?: string;
656
+ y?: string;
657
+ d?: string;
658
+ n?: string;
659
+ e?: string;
660
+ p?: string;
661
+ q?: string;
662
+ dp?: string;
663
+ dq?: string;
664
+ qi?: string;
665
+ oth?: RsaOtherPrimesInfo[];
666
+ k?: string;
667
+ }
668
+
589
669
  /**
590
670
  * Workers KV is a global, low-latency, key-value data store. It supports exceptionally high read volumes with low-latency,
591
671
  * making it possible to build highly dynamic APIs and websites which respond as quickly as a cached static file would.
592
672
  */
593
- declare abstract class KVNamespace {
673
+ interface KVNamespace {
594
674
  get(key: string, options?: Partial<KVNamespaceGetOptions<undefined>>): Promise<string | null>;
595
675
  get(key: string, type: "text"): Promise<string | null>;
596
676
  get<ExpectedValue = unknown>(key: string, type: "json"): Promise<ExpectedValue | null>;
@@ -657,52 +737,121 @@ interface KVNamespacePutOptions {
657
737
  }
658
738
 
659
739
  declare class MessageEvent extends Event {
660
- constructor(type: string, initializer: MessageEventInitializer);
740
+ constructor(type: string, initializer: MessageEventInit);
661
741
  readonly data: ArrayBuffer | string;
662
742
  }
663
743
 
664
- interface MessageEventInitializer {
744
+ interface MessageEventInit {
665
745
  data: ArrayBuffer | string;
666
746
  }
667
747
 
668
- declare abstract class ReadableStream {
748
+ /**
749
+ * Back compat for code migrating from older definitions.
750
+ * @deprecated Use MessageEventInit instead.
751
+ */
752
+ declare type MessageEventInitializer = MessageEventInit;
753
+
754
+ /**
755
+ * Transitionary name.
756
+ * @deprecated Use StreamPipeOptions
757
+ */
758
+ interface PipeToOptions {
759
+ preventClose?: boolean;
760
+ preventAbort?: boolean;
761
+ preventCancel?: boolean;
762
+ }
763
+
764
+ declare abstract class PromiseRejectionEvent extends Event {
765
+ readonly promise: Promise<any>;
766
+ readonly reason: any;
767
+ }
768
+
769
+ interface ReadResult {
770
+ value?: any;
771
+ done: boolean;
772
+ }
773
+
774
+ interface ReadableByteStreamController {
775
+ readonly byobRequest: ReadableStreamBYOBRequest | null;
776
+ readonly desiredSize: number | null;
777
+ close(): void;
778
+ enqueue(chunk: ArrayBufferView): void;
779
+ error(reason: any): void;
780
+ }
781
+
782
+ declare class ReadableStream {
783
+ constructor(underlyingSource?: Object, queuingStrategy?: Object);
669
784
  readonly locked: boolean;
670
785
  cancel(reason?: any): Promise<void>;
671
- getReader(options?: ReadableStreamGetReaderOptions): ReadableStreamReader;
672
- pipeThrough(transform: ReadableStreamTransform, options?: ReadableStreamPipeToOptions): ReadableStream;
673
- pipeTo(destination: WritableStream, options?: ReadableStreamPipeToOptions): Promise<void>;
786
+ getReader(options: ReadableStreamGetReaderOptions): ReadableStreamBYOBReader;
787
+ getReader(): ReadableStreamDefaultReader;
788
+ pipeThrough(transform: ReadableStreamTransform, options?: PipeToOptions): ReadableStream;
789
+ pipeTo(destination: WritableStream, options?: PipeToOptions): Promise<void>;
674
790
  tee(): [ReadableStream, ReadableStream];
675
791
  }
676
792
 
677
- interface ReadableStreamGetReaderOptions {
678
- mode?: string;
793
+ declare class ReadableStreamBYOBReader {
794
+ constructor(stream: ReadableStream);
795
+ readonly closed: Promise<void>;
796
+ cancel(reason?: any): Promise<void>;
797
+ read<T extends ArrayBufferView>(view: T): Promise<ReadableStreamReadResult<T>>;
798
+ releaseLock(): void;
799
+ readAtLeast(minBytes: number, view: Uint8Array): Promise<ReadableStreamReadResult<Uint8Array>>;
679
800
  }
680
801
 
681
- interface ReadableStreamPipeToOptions {
682
- preventClose?: boolean;
683
- preventAbort?: boolean;
684
- preventCancel?: boolean;
802
+ interface ReadableStreamBYOBRequest {
803
+ readonly view: Uint8Array | null;
804
+ respond(bytesWritten: number): void;
805
+ respondWithNewView(view: ArrayBufferView): void;
806
+ readonly atLeast: number | null;
685
807
  }
686
808
 
687
- declare abstract class ReadableStreamReader {
809
+ interface ReadableStreamDefaultController {
810
+ readonly desiredSize: number | null;
811
+ close(): void;
812
+ enqueue(chunk?: any): void;
813
+ error(reason: any): void;
814
+ }
815
+
816
+ declare class ReadableStreamDefaultReader {
817
+ constructor(stream: ReadableStream);
688
818
  readonly closed: Promise<void>;
689
819
  cancel(reason?: any): Promise<void>;
690
- read(byobBuffer?: ArrayBufferView): Promise<ReadableStreamReaderReadResult>;
820
+ read(): Promise<ReadableStreamReadResult<any>>;
691
821
  releaseLock(): void;
692
822
  }
693
823
 
694
- interface ReadableStreamReaderReadResult {
695
- value?: any;
696
- done: boolean;
824
+ interface ReadableStreamGetReaderOptions {
825
+ mode: string;
697
826
  }
698
827
 
828
+ /**
829
+ * Back-compat alias.
830
+ * @deprecated Use StreamPipeOptions
831
+ */
832
+ declare type ReadableStreamPipeToOptions = PipeToOptions;
833
+
834
+ declare type ReadableStreamReadResult<T = any> = { done: true; value: undefined; } | { done: false; value: T; };
835
+
836
+ /**
837
+ * Back-compat alias.
838
+ * @deprecated Use ReadableStreamBYOBReader
839
+ */
840
+ declare type ReadableStreamReadableStreamBYOBReader = ReadableStreamBYOBReader;
841
+
842
+ /**
843
+ * Back-compat alias.
844
+ * @deprecated Use ReadableStreamDefaultReader
845
+ */
846
+ declare type ReadableStreamReadableStreamDefaultReader = ReadableStreamDefaultReader;
847
+
699
848
  interface ReadableStreamTransform {
700
849
  writable: WritableStream;
701
850
  readable: ReadableStream;
702
851
  }
703
852
 
704
853
  declare class Request extends Body {
705
- constructor(input: Request | string, init?: RequestInitializerDict | Request);
854
+ constructor(input: Request | string, init?: RequestInit | Request);
706
855
  clone(): Request;
707
856
  readonly method: string;
708
857
  readonly url: string;
@@ -713,12 +862,33 @@ declare class Request extends Body {
713
862
  readonly cf?: IncomingRequestCfProperties;
714
863
  }
715
864
 
865
+ interface RequestInit {
866
+ method?: string;
867
+ headers?: HeadersInit;
868
+ body?: BodyInit | null;
869
+ redirect?: string;
870
+ fetcher?: Fetcher | null;
871
+ /**
872
+ * cf is a union of these two types because there are multiple
873
+ * scenarios in which it might be one or the other.
874
+ *
875
+ * IncomingRequestCfProperties is required to allow
876
+ * new Request(someUrl, event.request)
877
+ *
878
+ * RequestInitCfProperties is required to allow
879
+ * new Request(event.request, {cf: { ... } })
880
+ * fetch(someUrl, {cf: { ... } })
881
+ */
882
+ cf?: IncomingRequestCfProperties | RequestInitCfProperties;
883
+ signal?: AbortSignal | null;
884
+ }
885
+
716
886
  /**
717
887
  * In addition to the properties you can set in the RequestInit dict
718
888
  * that you pass as an argument to the Request constructor, you can
719
889
  * set certain properties of a `cf` object to control how Cloudflare
720
890
  * features are applied to that new Request.
721
- *
891
+ *
722
892
  * Note: Currently, these properties cannot be tested in the
723
893
  * playground.
724
894
  */
@@ -729,7 +899,7 @@ interface RequestInitCfProperties {
729
899
  * "the same" for caching purposes. If a request has the same cache key
730
900
  * as some previous request, then we can serve the same cached response for
731
901
  * both. (e.g. 'some-key')
732
- *
902
+ *
733
903
  * Only available for Enterprise customers.
734
904
  */
735
905
  cacheKey?: string;
@@ -747,11 +917,12 @@ interface RequestInitCfProperties {
747
917
  image?: RequestInitCfPropertiesImage;
748
918
  minify?: RequestInitCfPropertiesImageMinify;
749
919
  mirage?: boolean;
920
+ polish?: 'lossy' | 'lossless' | 'off';
750
921
  /**
751
922
  * Redirects the request to an alternate origin server. You can use this,
752
923
  * for example, to implement load balancing across several origins.
753
924
  * (e.g.us-east.example.com)
754
- *
925
+ *
755
926
  * Note - For security reasons, the hostname set in resolveOverride must
756
927
  * be proxied on the same Cloudflare zone of the incoming request.
757
928
  * Otherwise, the setting is ignored. CNAME hosts are allowed, so to
@@ -769,6 +940,13 @@ interface RequestInitCfPropertiesImage extends BasicImageTransformations {
769
940
  * easier to specify higher-DPI sizes in <img srcset>.
770
941
  */
771
942
  dpr?: number;
943
+ /**
944
+ * An object with four properties {left, top, right, bottom} that specify
945
+ * a number of pixels to cut off on each side. Allows removal of borders
946
+ * or cutting out a specific fragment of an image. Trimming is performed
947
+ * before resizing or rotation. Takes dpr into account.
948
+ */
949
+ trim?: { left?: number; top?: number; right?: number; bottom?: number; };
772
950
  /**
773
951
  * Quality setting from 1-100 (useful values are in 60-90 range). Lower values
774
952
  * make images look worse, but load faster. The default is 85. It applies only
@@ -785,6 +963,15 @@ interface RequestInitCfPropertiesImage extends BasicImageTransformations {
785
963
  * (before and after resizing), source image’s MIME type, file size, etc.
786
964
  */
787
965
  format?: "avif" | "webp" | "json";
966
+ /**
967
+ * Whether to preserve animation frames from input files. Default is true.
968
+ * Setting it to false reduces animations to still images. This setting is
969
+ * recommended when enlarging images or processing arbitrary user content,
970
+ * because large GIF animations can weigh tens or even hundreds of megabytes.
971
+ * It is also useful to set anim:false when using format:"json" to get the
972
+ * response quicker without the number of frames.
973
+ */
974
+ anim?: boolean;
788
975
  /**
789
976
  * What EXIF data should be preserved in the output image. Note that EXIF
790
977
  * rotation and embedded color profiles are always applied ("baked in" into
@@ -799,6 +986,17 @@ interface RequestInitCfPropertiesImage extends BasicImageTransformations {
799
986
  * output formats always discard metadata.
800
987
  */
801
988
  metadata?: "keep" | "copyright" | "none";
989
+ /**
990
+ * Strength of sharpening filter to apply to the image. Floating-point
991
+ * number between 0 (no sharpening, default) and 10 (maximum). 1.0 is a
992
+ * recommended value for downscaled images.
993
+ */
994
+ sharpen?: number;
995
+ /**
996
+ * Radius of a blur filter (approximate gaussian). Maximum supported radius
997
+ * is 250.
998
+ */
999
+ blur?: number;
802
1000
  /**
803
1001
  * Overlays are drawn in the order they appear in the array (last array
804
1002
  * entry is the topmost layer).
@@ -833,9 +1031,9 @@ interface RequestInitCfPropertiesImageDraw extends BasicImageTransformations {
833
1031
  * positions left side of the overlay 10 pixels from the left edge of the
834
1032
  * image it's drawn over. bottom: 0 aligns bottom of the overlay with bottom
835
1033
  * of the background image.
836
- *
1034
+ *
837
1035
  * Setting both left & right, or both top & bottom is an error.
838
- *
1036
+ *
839
1037
  * If no position is specified, the image will be centered.
840
1038
  */
841
1039
  top?: number;
@@ -850,29 +1048,14 @@ interface RequestInitCfPropertiesImageMinify {
850
1048
  html?: boolean;
851
1049
  }
852
1050
 
853
- interface RequestInitializerDict {
854
- method?: string;
855
- headers?: HeadersInitializer;
856
- body?: BodyInitializer | null;
857
- redirect?: string;
858
- fetcher?: Fetcher | null;
859
- /**
860
- * cf is a union of these two types because there are multiple
861
- * scenarios in which it might be one or the other.
862
- *
863
- * IncomingRequestCfProperties is required to allow
864
- * new Request(someUrl, event.request)
865
- *
866
- * RequestInitCfProperties is required to allow
867
- * new Request(event.request, {cf: { ... } })
868
- * fetch(someUrl, {cf: { ... } })
869
- */
870
- cf?: IncomingRequestCfProperties | RequestInitCfProperties;
871
- signal?: AbortSignal | null;
872
- }
1051
+ /**
1052
+ * Back compat for code migrating from older definitions.
1053
+ * @deprecated Use RequestInit instead.
1054
+ */
1055
+ declare type RequestInitializerDict = RequestInit;
873
1056
 
874
1057
  declare class Response extends Body {
875
- constructor(bodyInit?: BodyInitializer | null, maybeInit?: ResponseInitializerDict | Response);
1058
+ constructor(bodyInit?: BodyInit | null, maybeInit?: ResponseInit | Response);
876
1059
  static redirect(url: string, status?: number): Response;
877
1060
  clone(): Response;
878
1061
  readonly status: number;
@@ -885,33 +1068,49 @@ declare class Response extends Body {
885
1068
  readonly cf?: Object;
886
1069
  }
887
1070
 
888
- interface ResponseInitializerDict {
1071
+ interface ResponseInit {
889
1072
  status?: number;
890
1073
  statusText?: string;
891
- headers?: HeadersInitializer;
1074
+ headers?: HeadersInit;
892
1075
  cf?: Object;
893
1076
  webSocket?: WebSocket | null;
894
1077
  encodeBody?: string;
895
1078
  }
896
1079
 
897
- declare abstract class ScheduledController {
1080
+ /**
1081
+ * Back compat for code migrating from older definitions.
1082
+ * @deprecated Use ResponseInit instead.
1083
+ */
1084
+ declare type ResponseInitializerDict = ResponseInit;
1085
+
1086
+ interface RsaOtherPrimesInfo {
1087
+ r?: string;
1088
+ d?: string;
1089
+ t?: string;
1090
+ }
1091
+
1092
+ interface ScheduledController {
898
1093
  readonly scheduledTime: number;
899
1094
  readonly cron: string;
900
1095
  noRetry(): void;
901
1096
  }
902
1097
 
903
- declare class ScheduledEvent extends Event {
904
- constructor(type: string);
1098
+ declare abstract class ScheduledEvent extends Event {
905
1099
  readonly scheduledTime: number;
906
1100
  readonly cron: string;
907
1101
  noRetry(): void;
908
- waitUntil(promise: Promise<void>): void;
1102
+ waitUntil(promise: Promise<any>): void;
909
1103
  }
910
1104
 
911
- declare class ServiceWorkerGlobalScope extends WorkerGlobalScope {
912
- constructor();
913
- static readonly DOMException: typeof DOMException;
914
- static readonly WorkerGlobalScope: typeof WorkerGlobalScope;
1105
+ interface Scheduler {
1106
+ wait(delay: number, maybeOptions?: SchedulerWaitOptions): Promise<void>;
1107
+ }
1108
+
1109
+ interface SchedulerWaitOptions {
1110
+ signal?: AbortSignal;
1111
+ }
1112
+
1113
+ interface ServiceWorkerGlobalScope extends WorkerGlobalScope {
915
1114
  btoa(data: string): string;
916
1115
  atob(data: string): string;
917
1116
  setTimeout<Args extends any[]>(callback: (...args: Args) => void, msDelay?: number, ...args: Args): number;
@@ -919,46 +1118,25 @@ declare class ServiceWorkerGlobalScope extends WorkerGlobalScope {
919
1118
  setInterval<Args extends any[]>(callback: (...args: Args) => void, msDelay?: number, ...args: Args): number;
920
1119
  clearInterval(timeoutId: number | null): void;
921
1120
  queueMicrotask(task: Function): void;
922
- fetch(request: Request | string, requestInitr?: RequestInitializerDict | Request): Promise<Response>;
923
- readonly self: ServiceWorkerGlobalScope;
924
- readonly crypto: Crypto;
925
- readonly caches: CacheStorage;
926
- static readonly Event: typeof Event;
927
- static readonly FetchEvent: typeof FetchEvent;
928
- static readonly ScheduledEvent: typeof ScheduledEvent;
929
- static readonly MessageEvent: typeof MessageEvent;
930
- static readonly CloseEvent: typeof CloseEvent;
931
- static readonly ReadableStream: typeof ReadableStream;
932
- static readonly WritableStream: typeof WritableStream;
933
- static readonly TransformStream: typeof TransformStream;
934
- static readonly Headers: typeof Headers;
935
- static readonly Body: typeof Body;
936
- static readonly Request: typeof Request;
937
- static readonly Response: typeof Response;
938
- static readonly WebSocket: typeof WebSocket;
939
- static readonly WebSocketPair: typeof WebSocketPair;
940
- static readonly AbortController: typeof AbortController;
941
- static readonly AbortSignal: typeof AbortSignal;
942
- static readonly TextDecoder: typeof TextDecoder;
943
- static readonly TextEncoder: typeof TextEncoder;
944
- static readonly URL: typeof URL;
945
- static readonly URLSearchParams: typeof URLSearchParams;
946
- static readonly Blob: typeof Blob;
947
- static readonly File: typeof File;
948
- static readonly FormData: typeof FormData;
949
- static readonly Crypto: typeof Crypto;
950
- static readonly SubtleCrypto: typeof SubtleCrypto;
951
- static readonly CryptoKey: typeof CryptoKey;
952
- static readonly CacheStorage: typeof CacheStorage;
953
- static readonly Cache: typeof Cache;
954
- static readonly FixedLengthStream: typeof FixedLengthStream;
955
- static readonly HTMLRewriter: typeof HTMLRewriter;
1121
+ structuredClone(value: any, options?: ServiceWorkerGlobalScopeStructuredCloneOptions): any;
1122
+ fetch(request: Request | string, requestInitr?: RequestInit | Request): Promise<Response>;
1123
+ self: ServiceWorkerGlobalScope;
1124
+ crypto: Crypto;
1125
+ caches: CacheStorage;
1126
+ scheduler: Scheduler;
956
1127
  readonly console: Console;
1128
+ origin: void;
1129
+ }
1130
+
1131
+ interface ServiceWorkerGlobalScopeStructuredCloneOptions {
1132
+ transfer?: any[];
957
1133
  }
958
1134
 
1135
+ declare type StreamPipeOptions = PipeToOptions;
1136
+
959
1137
  interface StreamQueuingStrategy {
960
- highWaterMark: number;
961
- size(arg1: any): number;
1138
+ highWaterMark?: number;
1139
+ size(chunk: ArrayBuffer): number;
962
1140
  }
963
1141
 
964
1142
  declare abstract class SubtleCrypto {
@@ -970,8 +1148,8 @@ declare abstract class SubtleCrypto {
970
1148
  generateKey(algorithm: string | SubtleCryptoGenerateKeyAlgorithm, extractable: boolean, keyUsages: string[]): Promise<CryptoKey | CryptoKeyPair>;
971
1149
  deriveKey(algorithm: string | SubtleCryptoDeriveKeyAlgorithm, baseKey: CryptoKey, derivedKeyAlgorithm: string | SubtleCryptoImportKeyAlgorithm, extractable: boolean, keyUsages: string[]): Promise<CryptoKey>;
972
1150
  deriveBits(algorithm: string | SubtleCryptoDeriveKeyAlgorithm, baseKey: CryptoKey, length: number | null): Promise<ArrayBuffer>;
973
- importKey(format: string, keyData: ArrayBuffer | SubtleCryptoJsonWebKey, algorithm: string | SubtleCryptoImportKeyAlgorithm, extractable: boolean, keyUsages: string[]): Promise<CryptoKey>;
974
- exportKey(format: string, key: CryptoKey): Promise<ArrayBuffer | SubtleCryptoJsonWebKey>;
1151
+ importKey(format: string, keyData: ArrayBuffer | JsonWebKey, algorithm: string | SubtleCryptoImportKeyAlgorithm, extractable: boolean, keyUsages: string[]): Promise<CryptoKey>;
1152
+ exportKey(format: string, key: CryptoKey): Promise<ArrayBuffer | JsonWebKey>;
975
1153
  wrapKey(format: string, key: CryptoKey, wrappingKey: CryptoKey, wrapAlgorithm: string | SubtleCryptoEncryptAlgorithm): Promise<ArrayBuffer>;
976
1154
  unwrapKey(format: string, wrappedKey: ArrayBuffer, unwrappingKey: CryptoKey, unwrapAlgorithm: string | SubtleCryptoEncryptAlgorithm, unwrappedKeyAlgorithm: string | SubtleCryptoImportKeyAlgorithm, extractable: boolean, keyUsages: string[]): Promise<CryptoKey>;
977
1155
  }
@@ -1016,32 +1194,17 @@ interface SubtleCryptoImportKeyAlgorithm {
1016
1194
  compressed?: boolean;
1017
1195
  }
1018
1196
 
1019
- interface SubtleCryptoJsonWebKey {
1020
- kty: string;
1021
- use?: string;
1022
- key_ops?: string[];
1023
- alg?: string;
1024
- ext?: boolean;
1025
- crv?: string;
1026
- x?: string;
1027
- y?: string;
1028
- d?: string;
1029
- n?: string;
1030
- e?: string;
1031
- p?: string;
1032
- q?: string;
1033
- dp?: string;
1034
- dq?: string;
1035
- qi?: string;
1036
- oth?: SubtleCryptoJsonWebKeyRsaOtherPrimesInfo[];
1037
- k?: string;
1038
- }
1197
+ /**
1198
+ *
1199
+ * @deprecated Don't use. Introduced incidentally in 3.x. Scheduled for removal.
1200
+ */
1201
+ declare type SubtleCryptoJsonWebKey = JsonWebKey;
1039
1202
 
1040
- interface SubtleCryptoJsonWebKeyRsaOtherPrimesInfo {
1041
- r?: string;
1042
- d?: string;
1043
- t?: string;
1044
- }
1203
+ /**
1204
+ *
1205
+ * @deprecated Don't use. Introduced incidentally in 3.x. Scheduled for removal.
1206
+ */
1207
+ declare type SubtleCryptoJsonWebKeyRsaOtherPrimesInfo = RsaOtherPrimesInfo;
1045
1208
 
1046
1209
  interface SubtleCryptoSignAlgorithm {
1047
1210
  name: string;
@@ -1050,7 +1213,7 @@ interface SubtleCryptoSignAlgorithm {
1050
1213
  saltLength?: number;
1051
1214
  }
1052
1215
 
1053
- declare abstract class Text {
1216
+ interface Text {
1054
1217
  readonly text: string;
1055
1218
  readonly lastInTextNode: boolean;
1056
1219
  readonly removed: boolean;
@@ -1114,7 +1277,7 @@ declare class URL {
1114
1277
  }
1115
1278
 
1116
1279
  declare class URLSearchParams {
1117
- constructor(init?: URLSearchParamsInitializer);
1280
+ constructor(init?: URLSearchParamsInit);
1118
1281
  append(name: string, value: string): void;
1119
1282
  delete(name: string): void;
1120
1283
  get(name: string): string | null;
@@ -1130,7 +1293,15 @@ declare class URLSearchParams {
1130
1293
  toString(): string;
1131
1294
  }
1132
1295
 
1133
- declare type URLSearchParamsInitializer = URLSearchParams | string | Record<string, string> | ([key: string, value: string])[];
1296
+ declare type URLSearchParamsInit = URLSearchParams | string | Record<string, string> | ([key: string, value: string])[];
1297
+
1298
+ /**
1299
+ * Back compat for code migrating to older definitions.
1300
+ * This technically isn't part of a standard either way, but the naming
1301
+ * is more consistent.
1302
+ * @deprecated Use URLSearchParamsInit instead.
1303
+ */
1304
+ declare type URLSearchParamsInitializer = URLSearchParamsInit;
1134
1305
 
1135
1306
  declare abstract class WebSocket extends EventTarget<WebSocketEventMap> {
1136
1307
  accept(): void;
@@ -1138,25 +1309,33 @@ declare abstract class WebSocket extends EventTarget<WebSocketEventMap> {
1138
1309
  close(code?: number, reason?: string): void;
1139
1310
  }
1140
1311
 
1141
- declare type WebSocketEventMap = { close: CloseEvent; message: MessageEvent; };
1312
+ declare type WebSocketEventMap = { close: CloseEvent; message: MessageEvent; error: Event; };
1142
1313
 
1143
1314
  declare const WebSocketPair: { new(): { 0: WebSocket; 1: WebSocket; }; };
1144
1315
 
1145
- declare class WorkerGlobalScope extends EventTarget<WorkerGlobalScopeEventMap> {
1146
- constructor();
1147
- static readonly EventTarget: typeof EventTarget;
1316
+ declare abstract class WorkerGlobalScope extends EventTarget<WorkerGlobalScopeEventMap> {
1317
+
1148
1318
  }
1149
1319
 
1150
- declare type WorkerGlobalScopeEventMap = { fetch: FetchEvent; scheduled: ScheduledEvent; };
1320
+ declare type WorkerGlobalScopeEventMap = { fetch: FetchEvent; scheduled: ScheduledEvent; unhandledrejection: PromiseRejectionEvent; rejectionhandled: PromiseRejectionEvent; };
1151
1321
 
1152
- declare abstract class WritableStream {
1322
+ declare class WritableStream {
1323
+ constructor(underlyingSink?: Object, queuingStrategy?: Object);
1153
1324
  readonly locked: boolean;
1154
1325
  abort(reason: any): Promise<void>;
1155
- getWriter(): WritableStreamWriter;
1326
+ close(): Promise<void>;
1327
+ getWriter(): WritableStreamDefaultWriter;
1328
+ }
1329
+
1330
+ interface WritableStreamDefaultController {
1331
+ readonly signal: AbortSignal;
1332
+ error(reason?: any): void;
1156
1333
  }
1157
1334
 
1158
- declare abstract class WritableStreamWriter {
1335
+ declare class WritableStreamDefaultWriter {
1336
+ constructor(stream: WritableStream);
1159
1337
  readonly closed: Promise<void>;
1338
+ readonly ready: Promise<void>;
1160
1339
  readonly desiredSize: number | null;
1161
1340
  abort(reason: any): Promise<void>;
1162
1341
  close(): Promise<void>;
@@ -1164,6 +1343,12 @@ declare abstract class WritableStreamWriter {
1164
1343
  releaseLock(): void;
1165
1344
  }
1166
1345
 
1346
+ /**
1347
+ * Back-compat alias.
1348
+ * @deprecated Use WritableStreamDefaultWriter
1349
+ */
1350
+ declare type WritableStreamWritableStreamDefaultWriter = WritableStreamDefaultWriter;
1351
+
1167
1352
  declare function addEventListener<Type extends keyof WorkerGlobalScopeEventMap>(type: Type, handler: EventListenerOrEventListenerObject<WorkerGlobalScopeEventMap[Type]>, options?: EventTargetAddEventListenerOptions | boolean): void;
1168
1353
 
1169
1354
  declare function atob(data: string): string;
@@ -1182,14 +1367,38 @@ declare const crypto: Crypto;
1182
1367
 
1183
1368
  declare function dispatchEvent(event: WorkerGlobalScopeEventMap[keyof WorkerGlobalScopeEventMap]): boolean;
1184
1369
 
1185
- declare function fetch(request: Request | string, requestInitr?: RequestInitializerDict | Request): Promise<Response>;
1370
+ declare function fetch(request: Request | string, requestInitr?: RequestInit | Request): Promise<Response>;
1371
+
1372
+ declare const origin: void;
1186
1373
 
1187
1374
  declare function queueMicrotask(task: Function): void;
1188
1375
 
1189
1376
  declare function removeEventListener<Type extends keyof WorkerGlobalScopeEventMap>(type: Type, handler: EventListenerOrEventListenerObject<WorkerGlobalScopeEventMap[Type]>, options?: EventTargetEventListenerOptions | boolean): void;
1190
1377
 
1378
+ declare const scheduler: Scheduler;
1379
+
1191
1380
  declare const self: ServiceWorkerGlobalScope;
1192
1381
 
1193
1382
  declare function setInterval<Args extends any[]>(callback: (...args: Args) => void, msDelay?: number, ...args: Args): number;
1194
1383
 
1195
1384
  declare function setTimeout<Args extends any[]>(callback: (...args: Args) => void, msDelay?: number, ...args: Args): number;
1385
+
1386
+ declare function structuredClone(value: any, options?: ServiceWorkerGlobalScopeStructuredCloneOptions): any;
1387
+
1388
+ /*** Injected pages.d.ts ***/
1389
+ type Params<P extends string = any> = Record<P, string | string[]>;
1390
+
1391
+ type EventContext<Env, P extends string, Data> = {
1392
+ request: Request;
1393
+ waitUntil: (promise: Promise<any>) => void;
1394
+ next: (input?: Request | string, init?: RequestInit) => Promise<Response>;
1395
+ env: Env & { ASSETS: { fetch: typeof fetch }};
1396
+ params: Params<P>;
1397
+ data: Data;
1398
+ };
1399
+
1400
+ declare type PagesFunction<
1401
+ Env = unknown,
1402
+ Params extends string = any,
1403
+ Data extends Record<string, unknown> = Record<string, unknown>
1404
+ > = (context: EventContext<Env, Params, Data>) => Response | Promise<Response>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudflare/workers-types",
3
- "version": "3.0.0",
3
+ "version": "3.3.0",
4
4
  "description": "TypeScript typings for Cloudflare Workers",
5
5
  "repository": {
6
6
  "type": "git",
package/CHANGELOG.md DELETED
@@ -1,282 +0,0 @@
1
- # Changelog
2
-
3
- ## 3.0.0
4
-
5
- ### Features
6
-
7
- - **Types are automatically generated from the runtime - [@mrbbot], [pull/112]**
8
- Types now match exactly what's defined in the runtime source code, meaning `webworker` should be removed from users' `tsconfig.json`s
9
-
10
- [@mrbbot]: https://github.com/mrbbot
11
- [pull/112]: https://github.com/cloudflare/workers-types/pull/112
12
-
13
- ## 2.2.2
14
-
15
- ### Features
16
-
17
- - **Add KVNamespace.get options parameter, with cacheTtl - [@bretthoerner], [pull/87]**
18
-
19
- ### Bugfixes
20
-
21
- - **fix DurableObjectStorage transaction method signature - [@sbfaulkner], [pull/89]**
22
-
23
- ## 2.1.0
24
-
25
- ### Features
26
-
27
- - **Add types for Durable Objects - [@mathew-cf], [pull/63], [issue/64]**
28
- Types for [Durable Objects Beta](https://developers.cloudflare.com/workers/runtime-apis/durable-objects), subject to change.
29
-
30
- [@mathew-cf]: https://github.com/mathew-cf
31
- [pull/63]: https://github.com/cloudflare/workers-types/pull/63
32
- [issue/64]: https://github.com/cloudflare/workers-types/issues/64
33
-
34
- - **Add ScheduledEvent - [@qwtel], [pull/61]**
35
- Types for [Scheduled Events](https://developers.cloudflare.com/workers/runtime-apis/scheduled-event)
36
-
37
- [@qwtel]: https://github.com/qwtel
38
- [pull/61]: https://github.com/cloudflare/workers-types/pull/61
39
-
40
- - **Add AVIF Format for Image Resizing - [@GregBrimble], [pull/59]**
41
-
42
- [@GregBrimble]: https://github.com/GregBrimble
43
- [pull/59]: https://github.com/cloudflare/workers-types/pull/59
44
-
45
- - **Add metadata typings for KV - [@GregBrimble], [pull/54]**
46
- 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.
47
-
48
- [@GregBrimble]: https://github.com/GregBrimble
49
- [pull/54]: https://github.com/cloudflare/workers-types/pull/54
50
-
51
- - **Complete Image Resizing properties - [@GregBrimble], [pull/50]**
52
- Adds missing options for the Image Resizing API.
53
-
54
- [@GregBrimble]: https://github.com/GregBrimble
55
- [pull/50]: https://github.com/cloudflare/workers-types/pull/50
56
-
57
- - **Add API for async handlers and end handler - [@ObsidianMinor], [pull/48]**
58
- Types for [HTML Rewriter](https://developers.cloudflare.com/workers/runtime-apis/html-rewriter#end) end of document append method
59
-
60
- [@ObsidianMinor]: https://github.com/ObsidianMinor
61
- [pull/48]: https://github.com/cloudflare/workers-types/pull/48
62
-
63
- ### Bugfixes
64
-
65
- - **Make Element.attributes iterable - [@jdanyow], [pull/47]**
66
-
67
- Fixing a bug in the type definitions that prevents writing valid code like this:
68
-
69
- ```typescript
70
- rewriter.on('bla', {
71
- element: element => {
72
- for (const [name, value] of element.attributes) {
73
- ```
74
-
75
- [@jdanyow]: https://github.com/jdanyow
76
- [pull/47]: https://github.com/cloudflare/workers-types/pull/47
77
-
78
- ### Maintenance
79
-
80
- - **Update README.md instructions to avoid typescript error - [@jeremistadler], [pull/60]**
81
- Add empty export to bindings.d.ts example to avoid an typescript error
82
-
83
- [@jeremistadler]: https://github.com/jeremistadler
84
- [pull/60]: https://github.com/cloudflare/workers-types/pull/60
85
-
86
- - **Add a GitHub action to lint the Markdown - [@jbampton],[pull/51]**
87
-
88
- [@jbampton]: https://github.com/jbampton
89
- [pull/51]: https://github.com/cloudflare/workers-types/pull/51
90
-
91
- - **Fix spelling - [@jbampton],[pull/50]**
92
-
93
- [@jbampton]: https://github.com/jbampton
94
- [pull/50]: https://github.com/cloudflare/workers-types/pull/50
95
-
96
- - **Add CODEOWNERS - [@ispivey], [pull/49]**
97
- This will ensure we have default reviewers.
98
-
99
- [@ispivey]: https://github.com/ispivey
100
- [pull/48]: https://github.com/cloudflare/workers-types/pull/48
101
-
102
- - **Add prettier and typescript as devDependencies - [@1000hz], [pull/46]**
103
- Automated formatting via prettier
104
-
105
- [@1000hz]: https://github.com/1000hz
106
- [pull/46]: https://github.com/cloudflare/workers-types/pull/46
107
-
108
- ## ⌨️ 2.0.0
109
-
110
- ### Breaking Changes
111
-
112
- - **Types now only provided via automatic type inclusion, rather than explicit import - [@jdanyow], [issue/33], [pull/34]**
113
-
114
- Users should no longer use an empty import to include `workers-types`, which used to be the recommendation in the README.
115
-
116
- Remove this from your code:
117
-
118
- ```typescript
119
- import {} from '@cloudflare/workers-types'
120
- ```
121
-
122
- And instead include the types explicitly in your TypeScript configuration compiler options:
123
-
124
- ```json
125
- {
126
- "compilerOptions": {
127
- "types": ["@cloudflare/workers-types"]
128
- }
129
- }
130
- ```
131
-
132
- [@jdanyow]: https://github.com/jdanyow
133
- [pull/34]: https://github.com/cloudflare/workers-types/pull/34
134
- [issue/33]: https://github.com/cloudflare/workers-types/issues/33
135
-
136
- ### Features
137
-
138
- - **Add Cache behavior modifiers to outbound Requests - [@trjstewart], [issue/22], [pull/17]**
139
-
140
- When constructing a request, you can now include the following cache-manipulating properties in the initializer dictionary:
141
-
142
- ```typescript
143
- // Force response to be cached for 300 seconds.
144
- fetch(event.request, { cf: { cacheTtl: 300 } })
145
-
146
- // Force response to be cached for 86400 seconds for 200 status codes, 1 second for 404, and do not cache 500 errors
147
- fetch(request, { cf: { cacheTtlByStatus: { '200-299': 86400, '404': 1, '500-599': 0 } } })
148
- ```
149
-
150
- Read more about these properties in the [`Request` docs](https://developers.cloudflare.com/workers/reference/apis/request/).
151
-
152
- [@trjstewart]: https://github.com/trjstewart
153
- [pull/17]: https://github.com/cloudflare/workers-types/pull/17
154
- [issue/22]: https://github.com/cloudflare/workers-types/issues/22
155
-
156
- - **Add support for `caches.default` - [@ispivey], [@ashnewmanjones], [issue/8], [pull/21]**
157
-
158
- The Workers runtime exposes a default global cache as `caches.default`, accessed like:
159
-
160
- ```typescript
161
- let cache = caches.default
162
- ```
163
-
164
- 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.
165
-
166
- [@ispivey]: https://github.com/ispivey
167
- [@ashnewmanjones]: https://github.com/ashnewmanjones
168
- [pull/21]: https://github.com/cloudflare/workers-types/pull/21
169
- [issue/8]: https://github.com/cloudflare/workers-types/issues/8
170
-
171
- - **Add missing properties to inbound `Request` `cf` object - [@ispivey], [@brycematheson1234], [issue/23], [pull/24], [pull/35]**
172
-
173
- Adds:
174
-
175
- - `clientTcpRtt`
176
- - `metroCode`
177
- - `botManagement.score`
178
- - `botManagement.staticResource`
179
- - `botManagement.verifiedBot`
180
-
181
- Makes most geolocation properties optional, because they are not guaranteed to be set on every request.
182
-
183
- Changes the type of `asn` from string to number.
184
-
185
- [@ispivey]: https://github.com/ispivey
186
- [@brycematheson1234]: https://github.com/brycematheson1234
187
- [issue/23]: https://github.com/cloudflare/workers-types/issues/23
188
- [pull/24]: https://github.com/cloudflare/workers-types/pull/24
189
- [pull/35]: https://github.com/cloudflare/workers-types/pull/35
190
-
191
- - **Adds `cf.cacheKey` property to `RequestInit` - [@ispivey], [issue/22], [pull/28]**
192
-
193
- Adds the `cacheKey` property of the `cf` object to the `RequestInit` interface.
194
-
195
- [@ispivey]: https://github.com/ispivey
196
- [pull/28]: https://github.com/cloudflare/workers-types/pull/28
197
- [issue/22]: https://github.com/cloudflare/workers-types/issues/22
198
-
199
- - **Allow passing another Request as the `init` arg to `Request` constructor - [@ispivey], [issue/15], [pull/18]**
200
-
201
- Previously, this pattern wasn't allowed:
202
-
203
- ```typescript
204
- new Request(parsedUrl.toString(), request)
205
- ```
206
-
207
- 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.
208
-
209
- This change creates explicit `IncomingRequestCfProperties` (inbound) and `RequestInitCfProperties` (outbound) interfaces, and updates the `Request` constructor to accept either type:
210
-
211
- ```typescript
212
- interface RequestInit {
213
- cf?: RequestInitCfProperties | IncomingRequestCfProperties
214
- }
215
- ```
216
-
217
- Read more about the `Request` constructor in the [`Request` docs](https://developers.cloudflare.com/workers/reference/apis/request/).
218
-
219
- [@ispivey]: https://github.com/ispivey
220
- [pull/18]: https://github.com/cloudflare/workers-types/pull/18
221
- [issue/15]: https://github.com/cloudflare/workers-types/issues/15
222
-
223
- - **Add `CfRequestInit` type - [@third774], [issue/37], [pull/44]**
224
-
225
- 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.
226
-
227
- [@third774]: https://github.com/third774
228
- [pull/44]: https://github.com/cloudflare/workers-types/pull/44
229
- [issue/37]: https://github.com/cloudflare/workers-types/issues/37
230
-
231
- - **Add iterable methods to `FormData`, `Headers`, and `URLSearchParams` - [@ispivey], [issue/25], [pull/26]**
232
-
233
- 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`.
234
-
235
- 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)
236
-
237
- Until then, we will include the iterable methods supported by Workers in our own type definitions.
238
-
239
- [@ispivey]: https://github.com/ispivey
240
- [pull/26]: https://github.com/cloudflare/workers-types/pull/26
241
- [issue/25]: https://github.com/cloudflare/workers-types/issues/25
242
-
243
- ### Bugfixes
244
-
245
- - **Remove `selector` parameter from `onDocument()` - [@jdanyow], [pull/41]**
246
-
247
- The type signature for HTMLRewriter's `onDocument()` method previously erroneously included a `selector` parameter as its first argument. This has been removed.
248
-
249
- [@jdanyow]: https://github.com/jdanyow
250
- [pull/41]: https://github.com/cloudflare/workers-types/pull/41
251
-
252
- - **Make `KVNamespace.list()` options argument optional - [@motiejunas], [pull/10]**
253
-
254
- Previously, the `KVNamespace` interface required that callers provide an empty options object when listing all the keys in a namespace, like so:
255
-
256
- ```typescript
257
- await NAMESPACE.list({})
258
- ```
259
-
260
- However, this argument is not actually required. This change updates the interface to match the runtime.
261
-
262
- [@motiejunas]: https://github.com/motiejunas
263
- [pull/10]: https://github.com/cloudflare/workers-types/pull/10
264
-
265
- ### Maintenance
266
-
267
- - **Add a Release Checklist - [@ispivey], [issue/20], [pull/27]**
268
-
269
- As we onboard more contributors, we're documenting release procedures.
270
-
271
- [@ispivey]: https://github.com/ispivey
272
- [pull/27]: https://github.com/cloudflare/workers-types/pull/27
273
- [issue/20]: https://github.com/cloudflare/workers-types/issues/20
274
-
275
- - **Add BSD-3 License - [@ispivey], [issue/31], [pull/30], [pull/40]**
276
-
277
- 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!
278
-
279
- [@ispivey]: https://github.com/ispivey
280
- [pull/30]: https://github.com/cloudflare/workers-types/pull/30
281
- [pull/40]: https://github.com/cloudflare/workers-types/pull/40
282
- [issue/31]: https://github.com/cloudflare/workers-types/issues/31