@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/index.d.ts CHANGED
@@ -1,26 +1,16 @@
1
- interface FetchEvent {
2
- passThroughOnException: () => void;
1
+ // This file is auto-generated. DO NOT MODIFY.
2
+ // Please refer to the Auto-Generation section of the README.md.
3
+
4
+ declare class AbortController {
5
+ constructor();
6
+ readonly signal: AbortSignal;
7
+ abort(): void;
3
8
  }
4
9
 
5
- interface ScheduledEvent {
6
- /**
7
- * The type of event. This will always return `"scheduled"`.
8
- */
9
- type: string;
10
- /**
11
- * The time the `ScheduledEvent` was scheduled to be executed in
12
- * milliseconds since January 1, 1970, UTC.
13
- * It can be parsed as `new Date(event.scheduledTime)`
14
- */
15
- scheduledTime: number;
16
- /**
17
- * Use this method to notify the runtime to wait for asynchronous tasks
18
- * (e.g. logging, analytics to third-party services, streaming and caching).
19
- * The first `event.waitUntil` to fail will be observed and recorded as the
20
- * status in the Cron Trigger Past Events table. Otherwise, it will be
21
- * reported as a Success.
22
- */
23
- waitUntil(promise: Promise<any>): void;
10
+ declare class AbortSignal extends EventTarget {
11
+ constructor();
12
+ static abort(): AbortSignal;
13
+ readonly aborted: boolean;
24
14
  }
25
15
 
26
16
  interface BasicImageTransformations {
@@ -55,7 +45,7 @@ interface BasicImageTransformations {
55
45
  * effect can be more efficiently achieved with the contain mode and the
56
46
  * CSS object-fit: contain property.
57
47
  */
58
- fit?: 'scale-down' | 'contain' | 'cover' | 'crop' | 'pad';
48
+ fit?: "scale-down" | "contain" | "cover" | "crop" | "pad";
59
49
  /**
60
50
  * When cropping with fit: "cover", this defines the side or point that should
61
51
  * be left uncropped. The value is either a string
@@ -68,7 +58,7 @@ interface BasicImageTransformations {
68
58
  * preserve as much as possible around a point at 20% of the height of the
69
59
  * source image.
70
60
  */
71
- gravity?: 'left' | 'right' | 'top' | 'bottom' | 'center' | { x: number; y: number };
61
+ gravity?: "left" | "right" | "top" | "bottom" | "center" | BasicImageTransformationsGravityCoordinates;
72
62
  /**
73
63
  * Background color to add underneath the image. Applies only to images with
74
64
  * transparency (such as PNG). Accepts any CSS color (#RRGGBB, rgba(…),
@@ -82,155 +72,481 @@ interface BasicImageTransformations {
82
72
  rotate?: 0 | 90 | 180 | 270 | 360;
83
73
  }
84
74
 
85
- interface RequestInitCfProperties {
86
- /**
87
- * In addition to the properties you can set in the RequestInit dict
88
- * that you pass as an argument to the Request constructor, you can
89
- * set certain properties of a `cf` object to control how Cloudflare
90
- * features are applied to that new Request.
91
- *
92
- * Note: Currently, these properties cannot be tested in the
93
- * playground.
94
- */
95
- cacheEverything?: boolean;
96
- /**
97
- * A request's cache key is what determines if two requests are
98
- * "the same" for caching purposes. If a request has the same cache key
99
- * as some previous request, then we can serve the same cached response for
100
- * both. (e.g. 'some-key')
101
- *
102
- * Only available for Enterprise customers.
103
- */
104
- cacheKey?: string;
105
- /**
106
- * Force response to be cached for a given number of seconds. (e.g. 300)
107
- */
108
- cacheTtl?: number;
109
- /**
110
- * Force response to be cached for a given number of seconds based on the Origin status code.
111
- * (e.g. { '200-299': 86400, '404': 1, '500-599': 0 })
112
- */
113
- cacheTtlByStatus?: { [key: string]: number };
114
- scrapeShield?: boolean;
115
- apps?: boolean;
116
- image?: BasicImageTransformations & {
117
- /**
118
- * Device Pixel Ratio. Default 1. Multiplier for width/height that makes it
119
- * easier to specify higher-DPI sizes in <img srcset>.
120
- */
121
- dpr?: number;
122
- /**
123
- * Quality setting from 1-100 (useful values are in 60-90 range). Lower values
124
- * make images look worse, but load faster. The default is 85. It applies only
125
- * to JPEG and WebP images. It doesn’t have any effect on PNG.
126
- */
127
- quality?: number;
128
- /**
129
- * Output format to generate. It can be:
130
- * - avif: generate images in AVIF format.
131
- * - webp: generate images in Google WebP format. Set quality to 100 to get
132
- * the WebP-lossless format.
133
- * - json: instead of generating an image, outputs information about the
134
- * image, in JSON format. The JSON object will contain image size
135
- * (before and after resizing), source image’s MIME type, file size, etc.
136
- */
137
- format?: 'avif' | 'webp' | 'json';
138
- /**
139
- * What EXIF data should be preserved in the output image. Note that EXIF
140
- * rotation and embedded color profiles are always applied ("baked in" into
141
- * the image), and aren't affected by this option. Note that if the Polish
142
- * feature is enabled, all metadata may have been removed already and this
143
- * option may have no effect.
144
- * - keep: Preserve most of EXIF metadata, including GPS location if there's
145
- * any.
146
- * - copyright: Only keep the copyright tag, and discard everything else.
147
- * This is the default behavior for JPEG files.
148
- * - none: Discard all invisible EXIF metadata. Currently WebP and PNG
149
- * output formats always discard metadata.
150
- */
151
- metadata?: 'keep' | 'copyright' | 'none';
152
- /**
153
- * Overlays are drawn in the order they appear in the array (last array
154
- * entry is the topmost layer).
155
- */
156
- draw?: (BasicImageTransformations & {
157
- /**
158
- * Absolute URL of the image file to use for the drawing. It can be any of
159
- * the supported file formats. For drawing of watermarks or non-rectangular
160
- * overlays we recommend using PNG or WebP images.
161
- */
162
- url: string;
163
- /**
164
- * Floating-point number between 0 (transparent) and 1 (opaque).
165
- * For example, opacity: 0.5 makes overlay semitransparent.
166
- */
167
- opacity?: number;
168
- /**
169
- * - If set to true, the overlay image will be tiled to cover the entire
170
- * area. This is useful for stock-photo-like watermarks.
171
- * - If set to "x", the overlay image will be tiled horizontally only
172
- * (form a line).
173
- * - If set to "y", the overlay image will be tiled vertically only
174
- * (form a line).
175
- */
176
- repeat?: true | 'x' | 'y';
177
- /**
178
- * Position of the overlay image relative to a given edge. Each property is
179
- * an offset in pixels. 0 aligns exactly to the edge. For example, left: 10
180
- * positions left side of the overlay 10 pixels from the left edge of the
181
- * image it's drawn over. bottom: 0 aligns bottom of the overlay with bottom
182
- * of the background image.
183
- *
184
- * Setting both left & right, or both top & bottom is an error.
185
- *
186
- * If no position is specified, the image will be centered.
187
- */
188
- top?: number;
189
- left?: number;
190
- bottom?: number;
191
- right?: number;
192
- })[];
193
- };
194
- minify?: {
195
- javascript?: boolean;
196
- css?: boolean;
197
- html?: boolean;
198
- };
199
- mirage?: boolean;
200
- /**
201
- * Redirects the request to an alternate origin server. You can use this,
202
- * for example, to implement load balancing across several origins.
203
- * (e.g.us-east.example.com)
204
- *
205
- * Note - For security reasons, the hostname set in resolveOverride must
206
- * be proxied on the same Cloudflare zone of the incoming request.
207
- * Otherwise, the setting is ignored. CNAME hosts are allowed, so to
208
- * resolve to a host under a different domain or a DNS only domain first
209
- * declare a CNAME record within your own zone’s DNS mapping to the
210
- * external hostname, set proxy on Cloudflare, then set resolveOverride
211
- * to point to that CNAME record.
212
- */
213
- resolveOverride?: string;
75
+ interface BasicImageTransformationsGravityCoordinates {
76
+ x: number;
77
+ y: number;
78
+ }
79
+
80
+ declare class Blob {
81
+ constructor(bits?: BlobBits, options?: BlobOptions);
82
+ readonly size: number;
83
+ readonly type: string;
84
+ slice(start?: number, end?: number, type?: string): Blob;
85
+ arrayBuffer(): Promise<ArrayBuffer>;
86
+ text(): Promise<string>;
87
+ stream(): ReadableStream;
88
+ }
89
+
90
+ declare type BlobBits = (ArrayBuffer | string | Blob)[];
91
+
92
+ interface BlobOptions {
93
+ type?: string;
94
+ }
95
+
96
+ declare abstract class Body {
97
+ readonly body: ReadableStream | null;
98
+ readonly bodyUsed: boolean;
99
+ arrayBuffer(): Promise<ArrayBuffer>;
100
+ text(): Promise<string>;
101
+ json<T>(): Promise<T>;
102
+ formData(): Promise<FormData>;
103
+ blob(): Promise<Blob>;
104
+ }
105
+
106
+ declare type BodyInit = ReadableStream | string | ArrayBuffer | Blob | URLSearchParams | FormData;
107
+
108
+ /**
109
+ * Back compat for code migrating to older definitions.
110
+ * @deprecated Use BodyInit instead.
111
+ */
112
+ declare type BodyInitializer = BodyInit;
113
+
114
+ declare abstract class Cache {
115
+ delete(request: Request | string, options?: CacheQueryOptions): Promise<boolean>;
116
+ match(request: Request | string, options?: CacheQueryOptions): Promise<Response | undefined>;
117
+ put(request: Request | string, response: Response): Promise<void>;
118
+ }
119
+
120
+ interface CacheQueryOptions {
121
+ ignoreMethod?: boolean;
122
+ }
123
+
124
+ declare abstract class CacheStorage {
125
+ open(cacheName: string): Promise<Cache>;
126
+ readonly default: Cache;
127
+ }
128
+
129
+ interface CfRequestInit extends Omit<RequestInit, "cf"> {
130
+ cf?: RequestInitCfProperties;
131
+ }
132
+
133
+ /**
134
+ * Back compat support with older types.
135
+ * @deprecated Use CfRequestInit instead.
136
+ */
137
+ declare type CfRequestInitializerDict = CfRequestInit;
138
+
139
+ declare class CloseEvent extends Event {
140
+ constructor(type: string, initializer: CloseEventInit);
141
+ readonly code: number;
142
+ readonly reason: string;
143
+ readonly wasClean: boolean;
144
+ }
145
+
146
+ interface CloseEventInit {
147
+ code?: number;
148
+ reason?: string;
149
+ wasClean?: boolean;
150
+ }
151
+
152
+ /**
153
+ * Back compat for code migrating from older definitions.
154
+ * @deprecated Use CloseEventInit instead.
155
+ */
156
+ declare type CloseEventInitializer = CloseEventInit;
157
+
158
+ interface Comment {
159
+ text: string;
160
+ readonly removed: boolean;
161
+ before(content: Content, options?: ContentOptions): Comment;
162
+ after(content: Content, options?: ContentOptions): Comment;
163
+ replace(content: Content, options?: ContentOptions): Comment;
164
+ remove(): Comment;
165
+ }
166
+
167
+ interface Console {
168
+ debug(...data: any[]): void;
169
+ error(...data: any[]): void;
170
+ info(...data: any[]): void;
171
+ log(...data: any[]): void;
172
+ warn(...data: any[]): void;
173
+ }
174
+
175
+ declare type Content = string | ReadableStream | Response;
176
+
177
+ interface ContentOptions {
178
+ html?: boolean;
179
+ }
180
+
181
+ declare abstract class Crypto {
182
+ readonly subtle: SubtleCrypto;
183
+ getRandomValues(buffer: ArrayBufferView): ArrayBufferView;
184
+ randomUUID(): string;
185
+ }
186
+
187
+ declare abstract class CryptoKey {
188
+ readonly type: string;
189
+ readonly extractable: boolean;
190
+ readonly algorithm: CryptoKeyAlgorithmVariant;
191
+ readonly usages: string[];
192
+ }
193
+
194
+ interface CryptoKeyAesKeyAlgorithm {
195
+ name: string;
196
+ length: number;
197
+ }
198
+
199
+ declare type CryptoKeyAlgorithmVariant = CryptoKeyKeyAlgorithm | CryptoKeyAesKeyAlgorithm | CryptoKeyHmacKeyAlgorithm | CryptoKeyRsaKeyAlgorithm | CryptoKeyEllipticKeyAlgorithm | CryptoKeyVoprfKeyAlgorithm | CryptoKeyOprfKeyAlgorithm;
200
+
201
+ interface CryptoKeyEllipticKeyAlgorithm {
202
+ name: string;
203
+ namedCurve: string;
204
+ }
205
+
206
+ interface CryptoKeyHmacKeyAlgorithm {
207
+ name: string;
208
+ hash: CryptoKeyKeyAlgorithm;
209
+ length: number;
210
+ }
211
+
212
+ interface CryptoKeyKeyAlgorithm {
213
+ name: string;
214
+ }
215
+
216
+ interface CryptoKeyOprfKeyAlgorithm {
217
+ name: string;
218
+ namedCurve: string;
219
+ }
220
+
221
+ interface CryptoKeyPair {
222
+ publicKey: CryptoKey;
223
+ privateKey: CryptoKey;
224
+ }
225
+
226
+ interface CryptoKeyRsaKeyAlgorithm {
227
+ name: string;
228
+ modulusLength: number;
229
+ publicExponent: ArrayBuffer;
230
+ hash?: CryptoKeyKeyAlgorithm;
231
+ }
232
+
233
+ interface CryptoKeyVoprfKeyAlgorithm {
234
+ name: string;
235
+ hash: CryptoKeyKeyAlgorithm;
236
+ namedCurve: string;
237
+ }
238
+
239
+ declare class DOMException extends Error {
240
+ constructor(message?: string, name?: string);
241
+ readonly code: number;
242
+ static readonly INDEX_SIZE_ERR: number;
243
+ static readonly DOMSTRING_SIZE_ERR: number;
244
+ static readonly HIERARCHY_REQUEST_ERR: number;
245
+ static readonly WRONG_DOCUMENT_ERR: number;
246
+ static readonly INVALID_CHARACTER_ERR: number;
247
+ static readonly NO_DATA_ALLOWED_ERR: number;
248
+ static readonly NO_MODIFICATION_ALLOWED_ERR: number;
249
+ static readonly NOT_FOUND_ERR: number;
250
+ static readonly NOT_SUPPORTED_ERR: number;
251
+ static readonly INUSE_ATTRIBUTE_ERR: number;
252
+ static readonly INVALID_STATE_ERR: number;
253
+ static readonly SYNTAX_ERR: number;
254
+ static readonly INVALID_MODIFICATION_ERR: number;
255
+ static readonly NAMESPACE_ERR: number;
256
+ static readonly INVALID_ACCESS_ERR: number;
257
+ static readonly VALIDATION_ERR: number;
258
+ static readonly TYPE_MISMATCH_ERR: number;
259
+ static readonly SECURITY_ERR: number;
260
+ static readonly NETWORK_ERR: number;
261
+ static readonly ABORT_ERR: number;
262
+ static readonly URL_MISMATCH_ERR: number;
263
+ static readonly QUOTA_EXCEEDED_ERR: number;
264
+ static readonly TIMEOUT_ERR: number;
265
+ static readonly INVALID_NODE_TYPE_ERR: number;
266
+ static readonly DATA_CLONE_ERR: number;
267
+ }
268
+
269
+ interface Doctype {
270
+ readonly name: string | null;
271
+ readonly publicId: string | null;
272
+ readonly systemId: string | null;
273
+ }
274
+
275
+ interface DocumentEnd {
276
+ append(content: Content, options?: ContentOptions): DocumentEnd;
277
+ }
278
+
279
+ interface DurableObject {
280
+ fetch(request: Request): Promise<Response>;
281
+ }
282
+
283
+ interface DurableObjectId {
284
+ toString(): string;
285
+ equals(other: DurableObjectId): boolean;
286
+ readonly name?: string;
287
+ }
288
+
289
+ interface DurableObjectNamespace {
290
+ newUniqueId(options?: DurableObjectNamespaceNewUniqueIdOptions): DurableObjectId;
291
+ idFromName(name: string): DurableObjectId;
292
+ idFromString(id: string): DurableObjectId;
293
+ get(id: DurableObjectId): DurableObjectStub;
214
294
  }
215
295
 
296
+ interface DurableObjectNamespaceNewUniqueIdOptions {
297
+ jurisdiction?: string;
298
+ }
299
+
300
+ interface DurableObjectState {
301
+ waitUntil(promise: Promise<any>): void;
302
+ readonly id: DurableObjectId | string;
303
+ readonly storage: DurableObjectStorage;
304
+ blockConcurrencyWhile<T>(callback: () => Promise<T>): Promise<T>;
305
+ }
306
+
307
+ interface DurableObjectStorage {
308
+ get<T = unknown>(key: string, options?: DurableObjectStorageOperationsGetOptions): Promise<T | undefined>;
309
+ get<T = unknown>(keys: string[], options?: DurableObjectStorageOperationsGetOptions): Promise<Map<string, T>>;
310
+ list<T = unknown>(options?: DurableObjectStorageOperationsListOptions): Promise<Map<string, T>>;
311
+ put<T>(key: string, value: T, options?: DurableObjectStorageOperationsPutOptions): Promise<void>;
312
+ put<T>(entries: Record<string, T>, options?: DurableObjectStorageOperationsPutOptions): Promise<void>;
313
+ delete(key: string, options?: DurableObjectStorageOperationsPutOptions): Promise<boolean>;
314
+ delete(keys: string[], options?: DurableObjectStorageOperationsPutOptions): Promise<number>;
315
+ deleteAll(options?: DurableObjectStorageOperationsPutOptions): Promise<void>;
316
+ transaction<T>(closure: (txn: DurableObjectTransaction) => Promise<T>): Promise<T>;
317
+ }
318
+
319
+ interface DurableObjectStorageOperationsGetOptions {
320
+ allowConcurrency?: boolean;
321
+ noCache?: boolean;
322
+ }
323
+
324
+ interface DurableObjectStorageOperationsListOptions {
325
+ start?: string;
326
+ end?: string;
327
+ prefix?: string;
328
+ reverse?: boolean;
329
+ limit?: number;
330
+ allowConcurrency?: boolean;
331
+ noCache?: boolean;
332
+ }
333
+
334
+ interface DurableObjectStorageOperationsPutOptions {
335
+ allowConcurrency?: boolean;
336
+ allowUnconfirmed?: boolean;
337
+ noCache?: boolean;
338
+ }
339
+
340
+ interface DurableObjectStub extends Fetcher {
341
+ readonly id: DurableObjectId;
342
+ readonly name?: string;
343
+ }
344
+
345
+ interface DurableObjectTransaction {
346
+ get<T = unknown>(key: string, options?: DurableObjectStorageOperationsGetOptions): Promise<T>;
347
+ get<T = unknown>(keys: string[], options?: DurableObjectStorageOperationsGetOptions): Promise<Map<string, T>>;
348
+ list<T = unknown>(options?: DurableObjectStorageOperationsListOptions): Promise<Map<string, T>>;
349
+ put<T>(key: string, value: T, options?: DurableObjectStorageOperationsPutOptions): Promise<void>;
350
+ put<T>(entries: Record<string, T>, options?: DurableObjectStorageOperationsPutOptions): Promise<void>;
351
+ delete(key: string, options?: DurableObjectStorageOperationsPutOptions): Promise<boolean>;
352
+ delete(keys: string[], options?: DurableObjectStorageOperationsPutOptions): Promise<number>;
353
+ rollback(): void;
354
+ }
355
+
356
+ interface Element {
357
+ tagName: string;
358
+ readonly attributes: IterableIterator<string[]>;
359
+ readonly removed: boolean;
360
+ readonly namespaceURI: string;
361
+ getAttribute(name: string): string | null;
362
+ hasAttribute(name: string): boolean;
363
+ setAttribute(name: string, value: string): Element;
364
+ removeAttribute(name: string): Element;
365
+ before(content: Content, options?: ContentOptions): Element;
366
+ after(content: Content, options?: ContentOptions): Element;
367
+ prepend(content: Content, options?: ContentOptions): Element;
368
+ append(content: Content, options?: ContentOptions): Element;
369
+ replace(content: Content, options?: ContentOptions): Element;
370
+ remove(): Element;
371
+ removeAndKeepContent(): Element;
372
+ setInnerContent(content: Content, options?: ContentOptions): Element;
373
+ }
374
+
375
+ declare class Event {
376
+ constructor(type: string, init?: EventInit);
377
+ readonly type: string;
378
+ readonly eventPhase: number;
379
+ readonly composed: boolean;
380
+ readonly bubbles: boolean;
381
+ readonly cancelable: boolean;
382
+ readonly defaultPrevented: boolean;
383
+ readonly returnValue: boolean;
384
+ readonly currentTarget?: EventTarget;
385
+ readonly srcElement?: EventTarget;
386
+ readonly timeStamp: number;
387
+ readonly isTrusted: boolean;
388
+ cancelBubble: boolean;
389
+ stopImmediatePropagation(): void;
390
+ preventDefault(): void;
391
+ stopPropagation(): void;
392
+ composedPath(): EventTarget[];
393
+ static readonly NONE: number;
394
+ static readonly CAPTURING_PHASE: number;
395
+ static readonly AT_TARGET: number;
396
+ static readonly BUBBLING_PHASE: number;
397
+ }
398
+
399
+ interface EventInit {
400
+ bubbles?: boolean;
401
+ cancelable?: boolean;
402
+ composed?: boolean;
403
+ }
404
+
405
+ declare type EventListener<EventType extends Event = Event> = (event: EventType) => void;
406
+
407
+ interface EventListenerObject<EventType extends Event = Event> {
408
+ handleEvent(event: EventType): void;
409
+ }
410
+
411
+ declare type EventListenerOrEventListenerObject<EventType extends Event = Event> = EventListener<EventType> | EventListenerObject<EventType>;
412
+
413
+ declare class EventTarget<EventMap extends Record<string, Event> = Record<string, Event>> {
414
+ constructor();
415
+ addEventListener<Type extends keyof EventMap>(type: Type, handler: EventListenerOrEventListenerObject<EventMap[Type]>, options?: EventTargetAddEventListenerOptions | boolean): void;
416
+ removeEventListener<Type extends keyof EventMap>(type: Type, handler: EventListenerOrEventListenerObject<EventMap[Type]>, options?: EventTargetEventListenerOptions | boolean): void;
417
+ dispatchEvent(event: EventMap[keyof EventMap]): boolean;
418
+ }
419
+
420
+ interface EventTargetAddEventListenerOptions {
421
+ capture?: boolean;
422
+ passive?: boolean;
423
+ once?: boolean;
424
+ signal?: AbortSignal;
425
+ }
426
+
427
+ interface EventTargetEventListenerOptions {
428
+ capture?: boolean;
429
+ }
430
+
431
+ interface ExecutionContext {
432
+ waitUntil(promise: Promise<any>): void;
433
+ passThroughOnException(): void;
434
+ }
435
+
436
+ interface ExportedHandler<Env = unknown> {
437
+ fetch?: ExportedHandlerFetchHandler<Env>;
438
+ scheduled?: ExportedHandlerScheduledHandler<Env>;
439
+ }
440
+
441
+ declare type ExportedHandlerFetchHandler<Env = unknown> = (request: Request, env: Env, ctx: ExecutionContext) => Response | Promise<Response>;
442
+
443
+ declare type ExportedHandlerScheduledHandler<Env = unknown> = (controller: ScheduledController, env: Env, ctx: ExecutionContext) => void | Promise<void>;
444
+
445
+ declare abstract class FetchEvent extends Event {
446
+ readonly request: Request;
447
+ respondWith(promise: Response | Promise<Response>): void;
448
+ passThroughOnException(): void;
449
+ waitUntil(promise: Promise<any>): void;
450
+ }
451
+
452
+ declare abstract class Fetcher {
453
+ fetch(requestOrUrl: Request | string, requestInit?: RequestInit | Request): Promise<Response>;
454
+ }
455
+
456
+ declare class File extends Blob {
457
+ constructor(bits?: BlobBits, name?: string, options?: FileOptions);
458
+ readonly name: string;
459
+ readonly lastModified: number;
460
+ }
461
+
462
+ interface FileOptions {
463
+ type?: string;
464
+ lastModified?: number;
465
+ }
466
+
467
+ declare class FixedLengthStream extends TransformStream {
468
+ constructor(expectedLength: number);
469
+ }
470
+
471
+ declare class FormData {
472
+ constructor();
473
+ append(name: string, value: string): void;
474
+ append(name: string, value: Blob, filename?: string): void;
475
+ delete(name: string): void;
476
+ get(name: string): File | string | null;
477
+ getAll(name: string): (File | string)[];
478
+ has(name: string): boolean;
479
+ set(name: string, value: string): void;
480
+ set(name: string, value: Blob, filename?: string): void;
481
+ entries(): IterableIterator<([key: string, value: File | string])[]>;
482
+ keys(): IterableIterator<string>;
483
+ values(): IterableIterator<File | string>;
484
+ forEach<This = unknown>(callback: (this: This, key: string, value: File | string, parent: FormData) => void, thisArg?: This): void;
485
+ [Symbol.iterator](): IterableIterator<([key: string, value: File | string])[]>;
486
+ }
487
+
488
+ declare class HTMLRewriter {
489
+ constructor();
490
+ on(selector: string, handlers: HTMLRewriterElementContentHandlers): HTMLRewriter;
491
+ onDocument(handlers: HTMLRewriterDocumentContentHandlers): HTMLRewriter;
492
+ transform(response: Response): Response;
493
+ }
494
+
495
+ interface HTMLRewriterDocumentContentHandlers {
496
+ doctype?(doctype: Doctype): void | Promise<void>;
497
+ comments?(comment: Comment): void | Promise<void>;
498
+ text?(text: Text): void | Promise<void>;
499
+ end?(end: DocumentEnd): void | Promise<void>;
500
+ }
501
+
502
+ interface HTMLRewriterElementContentHandlers {
503
+ element?(element: Element): void | Promise<void>;
504
+ comments?(comment: Comment): void | Promise<void>;
505
+ text?(text: Text): void | Promise<void>;
506
+ }
507
+
508
+ declare class Headers {
509
+ constructor(init?: HeadersInit);
510
+ get(name: string): string | null;
511
+ getAll(name: string): string[];
512
+ has(name: string): boolean;
513
+ set(name: string, value: string): void;
514
+ append(name: string, value: string): void;
515
+ delete(name: string): void;
516
+ forEach<This = unknown>(callback: (this: This, key: string, value: string, parent: Headers) => void, thisArg?: This): void;
517
+ entries(): IterableIterator<[key: string, value: string]>;
518
+ keys(): IterableIterator<string>;
519
+ values(): IterableIterator<string>;
520
+ [Symbol.iterator](): IterableIterator<[key: string, value: string]>;
521
+ }
522
+
523
+ declare type HeadersInit = Headers | Record<string, string> | ([key: string, value: string])[];
524
+
525
+ /**
526
+ * Back compat for code migrating to older definitions.
527
+ * @deprecated Use HeadersInit instead.
528
+ */
529
+ declare type HeadersInitializer = HeadersInit;
530
+
531
+ /**
532
+ * In addition to the properties on the standard Request object,
533
+ * the cf object contains extra information about the request provided
534
+ * by Cloudflare's edge.
535
+ *
536
+ * Note: Currently, settings in the cf object cannot be accessed in the
537
+ * playground.
538
+ */
216
539
  interface IncomingRequestCfProperties {
217
540
  /**
218
- * In addition to the properties on the standard Request object,
219
- * the cf object contains extra information about the request provided
220
- * by Cloudflare's edge.
221
- *
222
- * Note: Currently, settings in the cf object cannot be accessed in the
223
- * playground.
541
+ * (e.g. 395747)
224
542
  */
543
+ asn: number;
225
544
  /**
226
- * (e.g. 395747)
545
+ * The organisation which owns the ASN of the incoming request.
546
+ * (e.g. Google Cloud)
227
547
  */
228
- asn: number;
229
- botManagement?: {
230
- score: number;
231
- staticResource: boolean;
232
- verifiedBot: boolean;
233
- };
548
+ asOrganization: string;
549
+ botManagement?: IncomingRequestCfPropertiesBotManagement;
234
550
  city?: string;
235
551
  clientTcpRtt: number;
236
552
  clientTrustScore?: number;
@@ -251,7 +567,7 @@ interface IncomingRequestCfProperties {
251
567
  /**
252
568
  * DMA metro code from which the request was issued, e.g. "635"
253
569
  */
254
- metroCode?: number;
570
+ metroCode?: string;
255
571
  postalCode?: string;
256
572
  /**
257
573
  * e.g. "Texas"
@@ -271,430 +587,683 @@ interface IncomingRequestCfProperties {
271
587
  timezone?: string;
272
588
  tlsVersion: string;
273
589
  tlsCipher: string;
274
- tlsClientAuth: {
275
- certIssuerDNLegacy: string;
276
- certIssuerDN: string;
277
- certPresented: '0' | '1';
278
- certSubjectDNLegacy: string;
279
- certSubjectDN: string;
280
- certNotBefore: string; // In format "Dec 22 19:39:00 2018 GMT"
281
- certNotAfter: string; // In format "Dec 22 19:39:00 2018 GMT"
282
- certSerial: string;
283
- certFingerprintSHA1: string;
284
- certVerified: string; // “SUCCESS”, “FAILED:reason”, “NONE”
285
- };
286
- }
287
-
288
- interface CfRequestInit extends Omit<RequestInit, 'cf'> {
289
- cf?: RequestInitCfProperties;
590
+ tlsClientAuth: IncomingRequestCfPropertiesTLSClientAuth;
290
591
  }
291
592
 
292
- interface RequestInit {
293
- /**
294
- * cf is a union of these two types because there are multiple
295
- * scenarios in which it might be one or the other. If you need
296
- * a type that only contains RequestInitCfProperties, use the
297
- * CfRequestInit type.
298
- *
299
- * IncomingRequestCfProperties is required to allow
300
- * new Request(someUrl, event.request)
301
- *
302
- * RequestInitCfProperties is required to allow
303
- * new Request(event.request, {cf: { ... } })
304
- * fetch(someUrl, {cf: { ... } })
305
- */
306
- cf?: IncomingRequestCfProperties | RequestInitCfProperties;
307
- }
308
-
309
- declare function addEventListener(type: 'fetch', handler: (event: FetchEvent) => void): void;
310
- declare function addEventListener(type: 'scheduled', handler: (event: ScheduledEvent) => void): void;
311
-
312
- interface Request {
313
- cf: IncomingRequestCfProperties;
593
+ interface IncomingRequestCfPropertiesBotManagement {
594
+ score: number;
595
+ staticResource: boolean;
596
+ verifiedBot: boolean;
314
597
  }
315
598
 
316
- interface FormData {
317
- [Symbol.iterator](): IterableIterator<[string, FormDataEntryValue]>;
599
+ interface IncomingRequestCfPropertiesTLSClientAuth {
600
+ certIssuerDNLegacy: string;
601
+ certIssuerDN: string;
602
+ certPresented: "0" | "1";
603
+ certSubjectDNLegacy: string;
604
+ certSubjectDN: string;
318
605
  /**
319
- * Returns an array of key, value pairs for every entry in the list.
606
+ * In format "Dec 22 19:39:00 2018 GMT"
320
607
  */
321
- entries(): IterableIterator<[string, FormDataEntryValue]>;
608
+ certNotBefore: string;
322
609
  /**
323
- * Returns a list of keys in the list.
610
+ * In format "Dec 22 19:39:00 2018 GMT"
324
611
  */
325
- keys(): IterableIterator<string>;
612
+ certNotAfter: string;
613
+ certSerial: string;
614
+ certFingerprintSHA1: string;
326
615
  /**
327
- * Returns a list of values in the list.
616
+ * "SUCCESS", "FAILED:reason", "NONE"
328
617
  */
329
- values(): IterableIterator<FormDataEntryValue>;
618
+ certVerified: string;
330
619
  }
331
620
 
332
- interface Headers {
333
- [Symbol.iterator](): IterableIterator<[string, string]>;
334
- /**
335
- * Returns an iterator allowing to go through all key/value pairs contained in this object.
336
- */
337
- entries(): IterableIterator<[string, string]>;
338
- /**
339
- * Returns an iterator allowing to go through all keys of the key/value pairs contained in this object.
340
- */
341
- keys(): IterableIterator<string>;
342
- /**
343
- * Returns an iterator allowing to go through all values of the key/value pairs contained in this object.
344
- */
345
- values(): IterableIterator<string>;
621
+ /**
622
+ * Workers KV is a global, low-latency, key-value data store. It supports exceptionally high read volumes with low-latency,
623
+ * making it possible to build highly dynamic APIs and websites which respond as quickly as a cached static file would.
624
+ */
625
+ interface KVNamespace {
626
+ get(key: string, options?: Partial<KVNamespaceGetOptions<undefined>>): Promise<string | null>;
627
+ get(key: string, type: "text"): Promise<string | null>;
628
+ get<ExpectedValue = unknown>(key: string, type: "json"): Promise<ExpectedValue | null>;
629
+ get(key: string, type: "arrayBuffer"): Promise<ArrayBuffer | null>;
630
+ get(key: string, type: "stream"): Promise<ReadableStream | null>;
631
+ get(key: string, options: KVNamespaceGetOptions<"text">): Promise<string | null>;
632
+ get<ExpectedValue = unknown>(key: string, options: KVNamespaceGetOptions<"json">): Promise<ExpectedValue | null>;
633
+ get(key: string, options: KVNamespaceGetOptions<"arrayBuffer">): Promise<ArrayBuffer | null>;
634
+ get(key: string, options: KVNamespaceGetOptions<"stream">): Promise<ReadableStream | null>;
635
+ list<Metadata = unknown>(options?: KVNamespaceListOptions): Promise<KVNamespaceListResult<Metadata>>;
636
+ /**
637
+ * Creates a new key-value pair, or updates the value for a particular key.
638
+ * @param key key to associate with the value. A key cannot be empty, `.` or `..`. All other keys are valid.
639
+ * @param value value to store. The type is inferred. The maximum size of a value is 25MB.
640
+ * @returns Returns a `Promise` that you should `await` on in order to verify a successful update.
641
+ * @example
642
+ * await NAMESPACE.put(key, value)
643
+ */
644
+ put(key: string, value: string | ArrayBuffer | ArrayBufferView | ReadableStream, options?: KVNamespacePutOptions): Promise<void>;
645
+ getWithMetadata<Metadata = unknown>(key: string, options?: Partial<KVNamespaceGetOptions<undefined>>): Promise<KVNamespaceGetWithMetadataResult<string, Metadata>>;
646
+ getWithMetadata<Metadata = unknown>(key: string, type: "text"): Promise<KVNamespaceGetWithMetadataResult<string, Metadata>>;
647
+ getWithMetadata<ExpectedValue = unknown, Metadata = unknown>(key: string, type: "json"): Promise<KVNamespaceGetWithMetadataResult<ExpectedValue, Metadata>>;
648
+ getWithMetadata<Metadata = unknown>(key: string, type: "arrayBuffer"): Promise<KVNamespaceGetWithMetadataResult<ArrayBuffer, Metadata>>;
649
+ getWithMetadata<Metadata = unknown>(key: string, type: "stream"): Promise<KVNamespaceGetWithMetadataResult<ReadableStream, Metadata>>;
650
+ getWithMetadata<Metadata = unknown>(key: string, options: KVNamespaceGetOptions<"text">): Promise<KVNamespaceGetWithMetadataResult<string, Metadata>>;
651
+ getWithMetadata<ExpectedValue = unknown, Metadata = unknown>(key: string, options: KVNamespaceGetOptions<"json">): Promise<KVNamespaceGetWithMetadataResult<ExpectedValue, Metadata>>;
652
+ getWithMetadata<Metadata = unknown>(key: string, options: KVNamespaceGetOptions<"arrayBuffer">): Promise<KVNamespaceGetWithMetadataResult<ArrayBuffer, Metadata>>;
653
+ getWithMetadata<Metadata = unknown>(key: string, options: KVNamespaceGetOptions<"stream">): Promise<KVNamespaceGetWithMetadataResult<ReadableStream, Metadata>>;
654
+ delete(name: string): Promise<void>;
346
655
  }
347
656
 
348
- interface URLSearchParams {
349
- [Symbol.iterator](): IterableIterator<[string, string]>;
350
- /**
351
- * Returns an array of key, value pairs for every entry in the search params.
352
- */
353
- entries(): IterableIterator<[string, string]>;
354
- /**
355
- * Returns a list of keys in the search params.
356
- */
357
- keys(): IterableIterator<string>;
358
- /**
359
- * Returns a list of values in the search params.
360
- */
361
- values(): IterableIterator<string>;
657
+ interface KVNamespaceGetOptions<Type> {
658
+ type: Type;
659
+ cacheTtl?: number;
362
660
  }
363
661
 
364
- interface ContentOptions {
365
- /**
366
- * Controls the way the HTMLRewriter treats inserted content.
367
- *
368
- * - true: Raw HTML
369
- * - false: (Default) Text and any HTML will be escaped
370
- */
371
- html: boolean;
662
+ interface KVNamespaceGetWithMetadataResult<Value, Metadata> {
663
+ value: Value | null;
664
+ metadata: Metadata | null;
372
665
  }
373
666
 
374
- interface Element {
375
- /**
376
- * The namespace URI of the element according to Infra Spec
377
- * (https://infra.spec.whatwg.org/#namespaces).
378
- */
379
- namespaceURI: string;
380
- /**
381
- * e.g. "div"
382
- */
383
- tagName: string;
384
- /**
385
- * Read-Only - key/value pairs of attributes.
386
- */
387
- readonly attributes: IterableIterator<[string, string]>;
388
- /**
389
- * Indicates whether the element was removed/replaced in a previous handler
390
- */
391
- removed: boolean;
667
+ interface KVNamespaceListKey<Metadata> {
668
+ name: string;
669
+ expiration?: number;
670
+ metadata?: Metadata;
671
+ }
392
672
 
673
+ interface KVNamespaceListOptions {
674
+ limit?: number;
675
+ prefix?: string | null;
676
+ cursor?: string | null;
677
+ }
678
+
679
+ interface KVNamespaceListResult<Metadata> {
680
+ keys: KVNamespaceListKey<Metadata>[];
681
+ list_complete: boolean;
682
+ cursor?: string;
683
+ }
684
+
685
+ interface KVNamespacePutOptions {
686
+ expiration?: number;
687
+ expirationTtl?: number;
688
+ metadata?: any | null;
689
+ }
690
+
691
+ declare class MessageEvent extends Event {
692
+ constructor(type: string, initializer: MessageEventInit);
693
+ readonly data: ArrayBuffer | string;
694
+ }
695
+
696
+ interface MessageEventInit {
697
+ data: ArrayBuffer | string;
698
+ }
699
+
700
+ /**
701
+ * Back compat for code migrating from older definitions.
702
+ * @deprecated Use MessageEventInit instead.
703
+ */
704
+ declare type MessageEventInitializer = MessageEventInit;
705
+
706
+ /**
707
+ * Transitionary name.
708
+ * @deprecated Use StreamPipeOptions
709
+ */
710
+ interface PipeToOptions {
711
+ preventClose?: boolean;
712
+ preventAbort?: boolean;
713
+ preventCancel?: boolean;
714
+ }
715
+
716
+ declare abstract class PromiseRejectionEvent extends Event {
717
+ readonly promise: Promise<any>;
718
+ readonly reason: any;
719
+ }
720
+
721
+ interface ReadResult {
722
+ value?: any;
723
+ done: boolean;
724
+ }
725
+
726
+ declare abstract class ReadableStream {
727
+ readonly locked: boolean;
728
+ cancel(reason?: any): Promise<void>;
729
+ getReader(options: ReadableStreamGetReaderOptions): ReadableStreamBYOBReader;
730
+ getReader(): ReadableStreamDefaultReader;
731
+ pipeThrough(transform: ReadableStreamTransform, options?: PipeToOptions): ReadableStream;
732
+ pipeTo(destination: WritableStream, options?: PipeToOptions): Promise<void>;
733
+ tee(): [ReadableStream, ReadableStream];
734
+ }
735
+
736
+ declare class ReadableStreamBYOBReader {
737
+ constructor(stream: ReadableStream);
738
+ readonly closed: Promise<void>;
739
+ cancel(reason?: any): Promise<void>;
740
+ read<T extends ArrayBufferView>(view: T): Promise<ReadableStreamReadResult<T>>;
741
+ releaseLock(): void;
742
+ readAtLeast(minBytes: number, view: Uint8Array): Promise<ReadableStreamReadResult<Uint8Array>>;
743
+ }
744
+
745
+ declare class ReadableStreamDefaultReader {
746
+ constructor(stream: ReadableStream);
747
+ readonly closed: Promise<void>;
748
+ cancel(reason?: any): Promise<void>;
749
+ read(): Promise<ReadableStreamReadResult<any>>;
750
+ releaseLock(): void;
751
+ }
752
+
753
+ interface ReadableStreamGetReaderOptions {
754
+ mode: string;
755
+ }
756
+
757
+ /**
758
+ * Back-compat alias.
759
+ * @deprecated Use StreamPipeOptions
760
+ */
761
+ declare type ReadableStreamPipeToOptions = PipeToOptions;
762
+
763
+ declare type ReadableStreamReadResult<T = any> = { done: true; value: undefined; } | { done: false; value: T; };
764
+
765
+ /**
766
+ * Back-compat alias.
767
+ * @deprecated Use ReadableStreamBYOBReader
768
+ */
769
+ declare type ReadableStreamReadableStreamBYOBReader = ReadableStreamBYOBReader;
770
+
771
+ /**
772
+ * Back-compat alias.
773
+ * @deprecated Use ReadableStreamDefaultReader
774
+ */
775
+ declare type ReadableStreamReadableStreamDefaultReader = ReadableStreamDefaultReader;
776
+
777
+ interface ReadableStreamTransform {
778
+ writable: WritableStream;
779
+ readable: ReadableStream;
780
+ }
781
+
782
+ declare class Request extends Body {
783
+ constructor(input: Request | string, init?: RequestInit | Request);
784
+ clone(): Request;
785
+ readonly method: string;
786
+ readonly url: string;
787
+ readonly headers: Headers;
788
+ readonly redirect: string;
789
+ readonly fetcher: Fetcher | null;
790
+ readonly signal: AbortSignal;
791
+ readonly cf?: IncomingRequestCfProperties;
792
+ }
793
+
794
+ interface RequestInit {
795
+ method?: string;
796
+ headers?: HeadersInit;
797
+ body?: BodyInit | null;
798
+ redirect?: string;
799
+ fetcher?: Fetcher | null;
393
800
  /**
394
- * Returns the value for a given attribute name on the element, or null if it isn’t found.
395
- */
396
- getAttribute(name: string): string | null;
397
- /**
398
- * Returns a boolean indicating whether an attribute exists on the element.
399
- */
400
- hasAttribute(name: string): boolean;
401
- /**
402
- * Sets an attribute to a provided value, creating the attribute if it doesn’t exist.
801
+ * cf is a union of these two types because there are multiple
802
+ * scenarios in which it might be one or the other.
803
+ *
804
+ * IncomingRequestCfProperties is required to allow
805
+ * new Request(someUrl, event.request)
806
+ *
807
+ * RequestInitCfProperties is required to allow
808
+ * new Request(event.request, {cf: { ... } })
809
+ * fetch(someUrl, {cf: { ... } })
403
810
  */
404
- setAttribute(name: string, value: string): Element;
811
+ cf?: IncomingRequestCfProperties | RequestInitCfProperties;
812
+ signal?: AbortSignal | null;
813
+ }
814
+
815
+ /**
816
+ * In addition to the properties you can set in the RequestInit dict
817
+ * that you pass as an argument to the Request constructor, you can
818
+ * set certain properties of a `cf` object to control how Cloudflare
819
+ * features are applied to that new Request.
820
+ *
821
+ * Note: Currently, these properties cannot be tested in the
822
+ * playground.
823
+ */
824
+ interface RequestInitCfProperties {
825
+ cacheEverything?: boolean;
405
826
  /**
406
- * Removes the attribute.
827
+ * A request's cache key is what determines if two requests are
828
+ * "the same" for caching purposes. If a request has the same cache key
829
+ * as some previous request, then we can serve the same cached response for
830
+ * both. (e.g. 'some-key')
831
+ *
832
+ * Only available for Enterprise customers.
407
833
  */
408
- removeAttribute(name: string): Element;
834
+ cacheKey?: string;
409
835
  /**
410
- * Inserts content before the element.
836
+ * Force response to be cached for a given number of seconds. (e.g. 300)
411
837
  */
412
- before(content: string, options?: ContentOptions): Element;
838
+ cacheTtl?: number;
413
839
  /**
414
- * Inserts content right after the element.
840
+ * Force response to be cached for a given number of seconds based on the Origin status code.
841
+ * (e.g. { '200-299': 86400, '404': 1, '500-599': 0 })
415
842
  */
416
- after(content: string, options?: ContentOptions): Element;
843
+ cacheTtlByStatus?: Record<string, number>;
844
+ scrapeShield?: boolean;
845
+ apps?: boolean;
846
+ image?: RequestInitCfPropertiesImage;
847
+ minify?: RequestInitCfPropertiesImageMinify;
848
+ mirage?: boolean;
417
849
  /**
418
- * Inserts content right after the start tag of the element.
850
+ * Redirects the request to an alternate origin server. You can use this,
851
+ * for example, to implement load balancing across several origins.
852
+ * (e.g.us-east.example.com)
853
+ *
854
+ * Note - For security reasons, the hostname set in resolveOverride must
855
+ * be proxied on the same Cloudflare zone of the incoming request.
856
+ * Otherwise, the setting is ignored. CNAME hosts are allowed, so to
857
+ * resolve to a host under a different domain or a DNS only domain first
858
+ * declare a CNAME record within your own zone’s DNS mapping to the
859
+ * external hostname, set proxy on Cloudflare, then set resolveOverride
860
+ * to point to that CNAME record.
419
861
  */
420
- prepend(content: string, options?: ContentOptions): Element;
862
+ resolveOverride?: string;
863
+ }
864
+
865
+ interface RequestInitCfPropertiesImage extends BasicImageTransformations {
421
866
  /**
422
- * Inserts content right before the end tag of the element.
867
+ * Device Pixel Ratio. Default 1. Multiplier for width/height that makes it
868
+ * easier to specify higher-DPI sizes in <img srcset>.
423
869
  */
424
- append(content: string, options?: ContentOptions): Element;
870
+ dpr?: number;
425
871
  /**
426
- * Removes the element and inserts content in place of it.
872
+ * Quality setting from 1-100 (useful values are in 60-90 range). Lower values
873
+ * make images look worse, but load faster. The default is 85. It applies only
874
+ * to JPEG and WebP images. It doesn’t have any effect on PNG.
427
875
  */
428
- replace(content: string, options?: ContentOptions): Element;
876
+ quality?: number;
429
877
  /**
430
- * Replaces content of the element.
878
+ * Output format to generate. It can be:
879
+ * - avif: generate images in AVIF format.
880
+ * - webp: generate images in Google WebP format. Set quality to 100 to get
881
+ * the WebP-lossless format.
882
+ * - json: instead of generating an image, outputs information about the
883
+ * image, in JSON format. The JSON object will contain image size
884
+ * (before and after resizing), source image’s MIME type, file size, etc.
431
885
  */
432
- setInnerContent(content: string, options?: ContentOptions): Element;
886
+ format?: "avif" | "webp" | "json";
433
887
  /**
434
- * Removes the element with all its content.
888
+ * What EXIF data should be preserved in the output image. Note that EXIF
889
+ * rotation and embedded color profiles are always applied ("baked in" into
890
+ * the image), and aren't affected by this option. Note that if the Polish
891
+ * feature is enabled, all metadata may have been removed already and this
892
+ * option may have no effect.
893
+ * - keep: Preserve most of EXIF metadata, including GPS location if there's
894
+ * any.
895
+ * - copyright: Only keep the copyright tag, and discard everything else.
896
+ * This is the default behavior for JPEG files.
897
+ * - none: Discard all invisible EXIF metadata. Currently WebP and PNG
898
+ * output formats always discard metadata.
435
899
  */
436
- remove(): Element;
900
+ metadata?: "keep" | "copyright" | "none";
437
901
  /**
438
- * Removes the start tag and end tag of the element, but keeps its inner content intact.
902
+ * Overlays are drawn in the order they appear in the array (last array
903
+ * entry is the topmost layer).
439
904
  */
440
- removeAndKeepContent(): Element;
905
+ draw?: RequestInitCfPropertiesImageDraw[];
441
906
  }
442
907
 
443
- interface Text {
444
- /**
445
- * Indicates whether the element was removed/replaced in a previous handler.
446
- */
447
- removed: boolean;
448
- /**
449
- * Read-Only - The text contents of the chunk. Could be empty if the chunk
450
- * is the last chunk of the text node.
451
- */
452
- readonly text: string;
453
- /**
454
- * Read-Only - indicates whether the chunk is the last chunk of the text node.
455
- */
456
- readonly lastInTextNode: boolean;
908
+ interface RequestInitCfPropertiesImageDraw extends BasicImageTransformations {
909
+ /**
910
+ * Absolute URL of the image file to use for the drawing. It can be any of
911
+ * the supported file formats. For drawing of watermarks or non-rectangular
912
+ * overlays we recommend using PNG or WebP images.
913
+ */
914
+ url: string;
915
+ /**
916
+ * Floating-point number between 0 (transparent) and 1 (opaque).
917
+ * For example, opacity: 0.5 makes overlay semitransparent.
918
+ */
919
+ opacity?: number;
920
+ /**
921
+ * - If set to true, the overlay image will be tiled to cover the entire
922
+ * area. This is useful for stock-photo-like watermarks.
923
+ * - If set to "x", the overlay image will be tiled horizontally only
924
+ * (form a line).
925
+ * - If set to "y", the overlay image will be tiled vertically only
926
+ * (form a line).
927
+ */
928
+ repeat?: true | "x" | "y";
929
+ /**
930
+ * Position of the overlay image relative to a given edge. Each property is
931
+ * an offset in pixels. 0 aligns exactly to the edge. For example, left: 10
932
+ * positions left side of the overlay 10 pixels from the left edge of the
933
+ * image it's drawn over. bottom: 0 aligns bottom of the overlay with bottom
934
+ * of the background image.
935
+ *
936
+ * Setting both left & right, or both top & bottom is an error.
937
+ *
938
+ * If no position is specified, the image will be centered.
939
+ */
940
+ top?: number;
941
+ left?: number;
942
+ bottom?: number;
943
+ right?: number;
944
+ }
457
945
 
458
- /**
459
- * Inserts content before the element.
460
- */
461
- before(content: string, options?: ContentOptions): Element;
462
- /**
463
- * Inserts content right after the element.
464
- */
465
- after(content: string, options?: ContentOptions): Element;
466
- /**
467
- * Removes the element and inserts content in place of it.
468
- */
469
- replace(content: string, options?: ContentOptions): Element;
470
- /**
471
- * Removes the element with all its content.
472
- */
473
- remove(): Element;
946
+ interface RequestInitCfPropertiesImageMinify {
947
+ javascript?: boolean;
948
+ css?: boolean;
949
+ html?: boolean;
474
950
  }
475
951
 
476
- interface Comment {
477
- /**
478
- * Indicates whether the element was removed/replaced in a previous handler.
479
- */
480
- removed: boolean;
481
- /**
482
- * This property can be assigned different values, to modify comment’s text.
483
- */
484
- text: string;
952
+ /**
953
+ * Back compat for code migrating from older definitions.
954
+ * @deprecated Use RequestInit instead.
955
+ */
956
+ declare type RequestInitializerDict = RequestInit;
485
957
 
486
- /**
487
- * Inserts content before the element.
488
- */
489
- before(content: string, options?: ContentOptions): Element;
490
- /**
491
- * Inserts content right after the element.
492
- */
493
- after(content: string, options?: ContentOptions): Element;
494
- /**
495
- * Removes the element and inserts content in place of it.
496
- */
497
- replace(content: string, options?: ContentOptions): Element;
498
- /**
499
- * Removes the element with all its content.
500
- */
501
- remove(): Element;
958
+ declare class Response extends Body {
959
+ constructor(bodyInit?: BodyInit | null, maybeInit?: ResponseInit | Response);
960
+ static redirect(url: string, status?: number): Response;
961
+ clone(): Response;
962
+ readonly status: number;
963
+ readonly statusText: string;
964
+ readonly headers: Headers;
965
+ readonly ok: boolean;
966
+ readonly redirected: boolean;
967
+ readonly url: string;
968
+ readonly webSocket: WebSocket | null;
969
+ readonly cf?: Object;
502
970
  }
503
971
 
504
- interface Doctype {
505
- readonly name: string | null;
506
- /**
507
- * Read-Only, The quoted string in the doctype after the PUBLIC atom.
508
- */
509
- readonly publicId: string | null;
510
- /**
511
- * Read-Only, The quoted string in the doctype after the SYSTEM atom or immediately after the publicId.
512
- */
513
- readonly systemId: string | null;
972
+ interface ResponseInit {
973
+ status?: number;
974
+ statusText?: string;
975
+ headers?: HeadersInit;
976
+ cf?: Object;
977
+ webSocket?: WebSocket | null;
978
+ encodeBody?: string;
514
979
  }
515
980
 
516
- interface DocumentEnd {
517
- /**
518
- * Inserts content right after the end of the document.
519
- */
520
- append(content: string, options?: ContentOptions): DocumentEnd;
981
+ /**
982
+ * Back compat for code migrating from older definitions.
983
+ * @deprecated Use ResponseInit instead.
984
+ */
985
+ declare type ResponseInitializerDict = ResponseInit;
986
+
987
+ interface ScheduledController {
988
+ readonly scheduledTime: number;
989
+ readonly cron: string;
990
+ noRetry(): void;
521
991
  }
522
992
 
523
- interface ElementHandlerOptionals {
524
- /**
525
- * An incoming element, such as `div`
526
- */
527
- element?(element: Element): void | Promise<void>;
528
- /**
529
- * An incoming comment
530
- */
531
- comments?(comment: Comment): void | Promise<void>;
532
- /**
533
- * An incoming piece of text
534
- */
535
- text?(text: Text): void | Promise<void>;
993
+ declare abstract class ScheduledEvent extends Event {
994
+ readonly scheduledTime: number;
995
+ readonly cron: string;
996
+ noRetry(): void;
997
+ waitUntil(promise: Promise<any>): void;
536
998
  }
537
999
 
538
- // See https://stackoverflow.com/a/49725198
539
- type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> &
540
- {
541
- [K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>;
542
- }[Keys];
1000
+ interface ServiceWorkerGlobalScope extends WorkerGlobalScope {
1001
+ btoa(data: string): string;
1002
+ atob(data: string): string;
1003
+ setTimeout<Args extends any[]>(callback: (...args: Args) => void, msDelay?: number, ...args: Args): number;
1004
+ clearTimeout(timeoutId: number | null): void;
1005
+ setInterval<Args extends any[]>(callback: (...args: Args) => void, msDelay?: number, ...args: Args): number;
1006
+ clearInterval(timeoutId: number | null): void;
1007
+ queueMicrotask(task: Function): void;
1008
+ fetch(request: Request | string, requestInitr?: RequestInit | Request): Promise<Response>;
1009
+ readonly self: ServiceWorkerGlobalScope;
1010
+ readonly crypto: Crypto;
1011
+ readonly caches: CacheStorage;
1012
+ readonly console: Console;
1013
+ }
543
1014
 
544
- type ElementHandler = RequireAtLeastOne<ElementHandlerOptionals, 'element' | 'comments' | 'text'>;
1015
+ declare type StreamPipeOptions = PipeToOptions;
545
1016
 
546
- interface DocumentHandler {
547
- /**
548
- * An incoming doctype, such as <!DOCTYPE html>
549
- */
550
- doctype(doctype: Doctype): void | Promise<void>;
551
- /**
552
- * An incoming comment
553
- */
554
- comments(comment: Comment): void | Promise<void>;
555
- /**
556
- * An incoming piece of text
557
- */
558
- text(text: Text): void | Promise<void>;
559
- /**
560
- * The ending of the document
561
- */
562
- end(end: DocumentEnd): void | Promise<void>;
1017
+ interface StreamQueuingStrategy {
1018
+ highWaterMark?: number;
1019
+ size(chunk: ArrayBuffer): number;
563
1020
  }
564
1021
 
565
- declare class HTMLRewriter {
566
- constructor();
567
- public on(selector: string, handlers: ElementHandler): HTMLRewriter;
568
- public onDocument(handlers: DocumentHandler): HTMLRewriter;
569
- public transform(response: Response): Response;
1022
+ declare abstract class SubtleCrypto {
1023
+ encrypt(algorithm: string | SubtleCryptoEncryptAlgorithm, key: CryptoKey, plainText: ArrayBuffer): Promise<ArrayBuffer>;
1024
+ decrypt(algorithm: string | SubtleCryptoEncryptAlgorithm, key: CryptoKey, cipherText: ArrayBuffer): Promise<ArrayBuffer>;
1025
+ sign(algorithm: string | SubtleCryptoSignAlgorithm, key: CryptoKey, data: ArrayBuffer): Promise<ArrayBuffer>;
1026
+ verify(algorithm: string | SubtleCryptoSignAlgorithm, key: CryptoKey, signature: ArrayBuffer, data: ArrayBuffer): Promise<boolean>;
1027
+ digest(algorithm: string | SubtleCryptoHashAlgorithm, data: ArrayBuffer): Promise<ArrayBuffer>;
1028
+ generateKey(algorithm: string | SubtleCryptoGenerateKeyAlgorithm, extractable: boolean, keyUsages: string[]): Promise<CryptoKey | CryptoKeyPair>;
1029
+ deriveKey(algorithm: string | SubtleCryptoDeriveKeyAlgorithm, baseKey: CryptoKey, derivedKeyAlgorithm: string | SubtleCryptoImportKeyAlgorithm, extractable: boolean, keyUsages: string[]): Promise<CryptoKey>;
1030
+ deriveBits(algorithm: string | SubtleCryptoDeriveKeyAlgorithm, baseKey: CryptoKey, length: number | null): Promise<ArrayBuffer>;
1031
+ importKey(format: string, keyData: ArrayBuffer | SubtleCryptoJsonWebKey, algorithm: string | SubtleCryptoImportKeyAlgorithm, extractable: boolean, keyUsages: string[]): Promise<CryptoKey>;
1032
+ exportKey(format: string, key: CryptoKey): Promise<ArrayBuffer | SubtleCryptoJsonWebKey>;
1033
+ wrapKey(format: string, key: CryptoKey, wrappingKey: CryptoKey, wrapAlgorithm: string | SubtleCryptoEncryptAlgorithm): Promise<ArrayBuffer>;
1034
+ unwrapKey(format: string, wrappedKey: ArrayBuffer, unwrappingKey: CryptoKey, unwrapAlgorithm: string | SubtleCryptoEncryptAlgorithm, unwrappedKeyAlgorithm: string | SubtleCryptoImportKeyAlgorithm, extractable: boolean, keyUsages: string[]): Promise<CryptoKey>;
570
1035
  }
571
1036
 
572
- declare interface CacheStorage {
573
- default: Cache;
1037
+ interface SubtleCryptoDeriveKeyAlgorithm {
1038
+ name: string;
1039
+ salt?: ArrayBuffer;
1040
+ iterations?: number;
1041
+ hash?: string | SubtleCryptoHashAlgorithm;
1042
+ public?: CryptoKey;
1043
+ info?: ArrayBuffer;
574
1044
  }
575
1045
 
576
- type KVValue<Value> = Promise<Value | null>;
577
- type KVValueWithMetadata<Value, Metadata> = Promise<{
578
- value: Value | null;
579
- metadata: Metadata | null;
580
- }>;
1046
+ interface SubtleCryptoEncryptAlgorithm {
1047
+ name: string;
1048
+ iv?: ArrayBuffer;
1049
+ additionalData?: ArrayBuffer;
1050
+ tagLength?: number;
1051
+ counter?: ArrayBuffer;
1052
+ length?: number;
1053
+ label?: ArrayBuffer;
1054
+ }
581
1055
 
582
- interface KVNamespace {
583
- get(key: string): KVValue<string>;
584
- get(key: string, type: 'text'): KVValue<string>;
585
- get<ExpectedValue = unknown>(key: string, type: 'json'): KVValue<ExpectedValue>;
586
- get(key: string, type: 'arrayBuffer'): KVValue<ArrayBuffer>;
587
- get(key: string, type: 'stream'): KVValue<ReadableStream>;
588
-
589
- getWithMetadata<Metadata = unknown>(key: string): KVValueWithMetadata<string, Metadata>;
590
- getWithMetadata<Metadata = unknown>(
591
- key: string,
592
- type: 'text'
593
- ): KVValueWithMetadata<string, Metadata>;
594
- getWithMetadata<ExpectedValue = unknown, Metadata = unknown>(
595
- key: string,
596
- type: 'json'
597
- ): KVValueWithMetadata<ExpectedValue, Metadata>;
598
- getWithMetadata<Metadata = unknown>(
599
- key: string,
600
- type: 'arrayBuffer'
601
- ): KVValueWithMetadata<ArrayBuffer, Metadata>;
602
- getWithMetadata<Metadata = unknown>(
603
- key: string,
604
- type: 'stream'
605
- ): KVValueWithMetadata<ReadableStream, Metadata>;
606
-
607
- put(
608
- key: string,
609
- value: string | ReadableStream | ArrayBuffer | FormData,
610
- options?: {
611
- expiration?: string | number;
612
- expirationTtl?: string | number;
613
- metadata?: any;
614
- }
615
- ): Promise<void>;
616
-
617
- delete(key: string): Promise<void>;
618
-
619
- list(options?: {
620
- prefix?: string;
621
- limit?: number;
622
- cursor?: string;
623
- }): Promise<{
624
- keys: { name: string; expiration?: number; metadata?: unknown }[];
625
- list_complete: boolean;
626
- cursor?: string;
627
- }>;
628
- }
629
-
630
- interface DurableObjectEntries<T> {
631
- [key: string]: T;
632
- }
633
-
634
- interface DurableObjectListOptions {
635
- start?: string;
636
- end?: string;
637
- reverse?: boolean;
638
- limit?: number;
639
- prefix?: string;
1056
+ interface SubtleCryptoGenerateKeyAlgorithm {
1057
+ name: string;
1058
+ hash?: string | SubtleCryptoHashAlgorithm;
1059
+ modulusLength?: number;
1060
+ publicExponent?: ArrayBuffer;
1061
+ length?: number;
1062
+ namedCurve?: string;
640
1063
  }
641
1064
 
642
- interface DurableObjectOperator {
643
- get<T = unknown>(key: string): Promise<T>;
644
- get<T = unknown>(keys: Array<string>): Promise<Map<string, T>>;
645
- put<T = unknown>(key: string, value: T): Promise<void>;
646
- put<T = unknown>(entries: DurableObjectEntries<T>): Promise<void>;
647
- delete(key: string): Promise<boolean>;
648
- delete(keys: Array<string>): Promise<number>;
649
- deleteAll(): Promise<void>;
650
- list<T = unknown>(options?: DurableObjectListOptions): Promise<Map<string, T>>;
1065
+ interface SubtleCryptoHashAlgorithm {
1066
+ name: string;
651
1067
  }
652
1068
 
653
- interface DurableObjectTransaction extends DurableObjectOperator {
654
- rollback(): void;
1069
+ interface SubtleCryptoImportKeyAlgorithm {
1070
+ name: string;
1071
+ hash?: string | SubtleCryptoHashAlgorithm;
1072
+ length?: number;
1073
+ namedCurve?: string;
1074
+ compressed?: boolean;
655
1075
  }
656
1076
 
657
- interface DurableObjectStorage extends DurableObjectOperator {
658
- transaction(
659
- closure: (txn: DurableObjectStorage) => Promise<void>
660
- ): Promise<void>;
1077
+ interface SubtleCryptoJsonWebKey {
1078
+ kty: string;
1079
+ use?: string;
1080
+ key_ops?: string[];
1081
+ alg?: string;
1082
+ ext?: boolean;
1083
+ crv?: string;
1084
+ x?: string;
1085
+ y?: string;
1086
+ d?: string;
1087
+ n?: string;
1088
+ e?: string;
1089
+ p?: string;
1090
+ q?: string;
1091
+ dp?: string;
1092
+ dq?: string;
1093
+ qi?: string;
1094
+ oth?: SubtleCryptoJsonWebKeyRsaOtherPrimesInfo[];
1095
+ k?: string;
661
1096
  }
662
1097
 
663
- interface DurableObjectState {
664
- id: DurableObjectId;
665
- storage: DurableObjectStorage;
666
- /**
667
- * Use this method to notify the runtime to wait for asynchronous tasks
668
- * (e.g. logging, analytics to third-party services, streaming and caching).
669
- */
670
- waitUntil(promise: Promise<any>): void;
1098
+ interface SubtleCryptoJsonWebKeyRsaOtherPrimesInfo {
1099
+ r?: string;
1100
+ d?: string;
1101
+ t?: string;
671
1102
  }
672
1103
 
673
- /**
674
- * DurableObject is a class that defines a template for creating Durable Objects
675
- */
676
- interface DurableObject {
677
- fetch: (request: Request) => Promise<Response>;
1104
+ interface SubtleCryptoSignAlgorithm {
1105
+ name: string;
1106
+ hash?: string | SubtleCryptoHashAlgorithm;
1107
+ dataLength?: number;
1108
+ saltLength?: number;
1109
+ }
1110
+
1111
+ interface Text {
1112
+ readonly text: string;
1113
+ readonly lastInTextNode: boolean;
1114
+ readonly removed: boolean;
1115
+ before(content: Content, options?: ContentOptions): Text;
1116
+ after(content: Content, options?: ContentOptions): Text;
1117
+ replace(content: Content, options?: ContentOptions): Text;
1118
+ remove(): Text;
1119
+ }
1120
+
1121
+ declare class TextDecoder {
1122
+ constructor(label?: "utf-8" | "utf8" | "unicode-1-1-utf-8", options?: TextDecoderConstructorOptions);
1123
+ decode(input?: ArrayBuffer, options?: TextDecoderDecodeOptions): string;
1124
+ readonly encoding: string;
1125
+ readonly fatal: boolean;
1126
+ readonly ignoreBOM: boolean;
1127
+ }
1128
+
1129
+ interface TextDecoderConstructorOptions {
1130
+ fatal: boolean;
1131
+ ignoreBOM: boolean;
1132
+ }
1133
+
1134
+ interface TextDecoderDecodeOptions {
1135
+ stream: boolean;
1136
+ }
1137
+
1138
+ declare class TextEncoder {
1139
+ constructor();
1140
+ encode(input?: string): Uint8Array;
1141
+ encodeInto(input: string, buffer: Uint8Array): TextEncoderEncodeIntoResult;
1142
+ readonly encoding: string;
678
1143
  }
679
1144
 
1145
+ interface TextEncoderEncodeIntoResult {
1146
+ read: number;
1147
+ written: number;
1148
+ }
1149
+
1150
+ declare class TransformStream {
1151
+ constructor();
1152
+ readonly readable: ReadableStream;
1153
+ readonly writable: WritableStream;
1154
+ }
1155
+
1156
+ declare class URL {
1157
+ constructor(url: string, base?: string);
1158
+ href: string;
1159
+ readonly origin: string;
1160
+ protocol: string;
1161
+ username: string;
1162
+ password: string;
1163
+ host: string;
1164
+ hostname: string;
1165
+ port: string;
1166
+ pathname: string;
1167
+ search: string;
1168
+ readonly searchParams: URLSearchParams;
1169
+ hash: string;
1170
+ toString(): string;
1171
+ toJSON(): string;
1172
+ }
1173
+
1174
+ declare class URLSearchParams {
1175
+ constructor(init?: URLSearchParamsInit);
1176
+ append(name: string, value: string): void;
1177
+ delete(name: string): void;
1178
+ get(name: string): string | null;
1179
+ getAll(name: string): string[];
1180
+ has(name: string): boolean;
1181
+ set(name: string, value: string): void;
1182
+ sort(): void;
1183
+ entries(): IterableIterator<[key: string, value: string]>;
1184
+ keys(): IterableIterator<string>;
1185
+ values(): IterableIterator<string>;
1186
+ forEach<This = unknown>(callback: (this: This, key: string, value: string, parent: URLSearchParams) => void, thisArg?: This): void;
1187
+ [Symbol.iterator](): IterableIterator<[key: string, value: string]>;
1188
+ toString(): string;
1189
+ }
1190
+
1191
+ declare type URLSearchParamsInit = URLSearchParams | string | Record<string, string> | ([key: string, value: string])[];
1192
+
680
1193
  /**
681
- * DurableObjectStub is a client object used to send requests to a remote Durable Object
1194
+ * Back compat for code migrating to older definitions.
1195
+ * This technically isn't part of a standard either way, but the naming
1196
+ * is more consistent.
1197
+ * @deprecated Use URLSearchParamsInit instead.
682
1198
  */
683
- interface DurableObjectStub {
684
- name?: string;
685
- id: DurableObjectId;
686
- fetch: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
1199
+ declare type URLSearchParamsInitializer = URLSearchParamsInit;
1200
+
1201
+ declare abstract class WebSocket extends EventTarget<WebSocketEventMap> {
1202
+ accept(): void;
1203
+ send(message: ArrayBuffer | string): void;
1204
+ close(code?: number, reason?: string): void;
687
1205
  }
688
1206
 
689
- interface DurableObjectId {
690
- name?: string;
691
- toString: () => string;
1207
+ declare type WebSocketEventMap = { close: CloseEvent; message: MessageEvent; };
1208
+
1209
+ declare const WebSocketPair: { new(): { 0: WebSocket; 1: WebSocket; }; };
1210
+
1211
+ declare abstract class WorkerGlobalScope extends EventTarget<WorkerGlobalScopeEventMap> {
1212
+
692
1213
  }
693
1214
 
694
- interface DurableObjectNamespace {
695
- newUniqueId: () => DurableObjectId;
696
- idFromName: (name: string) => DurableObjectId;
697
- idFromString: (hexId: string) => DurableObjectId;
1215
+ declare type WorkerGlobalScopeEventMap = { fetch: FetchEvent; scheduled: ScheduledEvent; unhandledrejection: PromiseRejectionEvent; rejectionhandled: PromiseRejectionEvent; };
1216
+
1217
+ declare abstract class WritableStream {
1218
+ readonly locked: boolean;
1219
+ abort(reason: any): Promise<void>;
1220
+ close(): Promise<void>;
1221
+ getWriter(): WritableStreamDefaultWriter;
1222
+ }
698
1223
 
699
- get: (id: DurableObjectId) => DurableObjectStub;
1224
+ declare class WritableStreamDefaultWriter {
1225
+ constructor(stream: WritableStream);
1226
+ readonly closed: Promise<void>;
1227
+ readonly desiredSize: number | null;
1228
+ abort(reason: any): Promise<void>;
1229
+ close(): Promise<void>;
1230
+ write(chunk: any): Promise<void>;
1231
+ releaseLock(): void;
700
1232
  }
1233
+
1234
+ /**
1235
+ * Back-compat alias.
1236
+ * @deprecated Use WritableStreamDefaultWriter
1237
+ */
1238
+ declare type WritableStreamWritableStreamDefaultWriter = WritableStreamDefaultWriter;
1239
+
1240
+ declare function addEventListener<Type extends keyof WorkerGlobalScopeEventMap>(type: Type, handler: EventListenerOrEventListenerObject<WorkerGlobalScopeEventMap[Type]>, options?: EventTargetAddEventListenerOptions | boolean): void;
1241
+
1242
+ declare function atob(data: string): string;
1243
+
1244
+ declare function btoa(data: string): string;
1245
+
1246
+ declare const caches: CacheStorage;
1247
+
1248
+ declare function clearInterval(timeoutId: number | null): void;
1249
+
1250
+ declare function clearTimeout(timeoutId: number | null): void;
1251
+
1252
+ declare const console: Console;
1253
+
1254
+ declare const crypto: Crypto;
1255
+
1256
+ declare function dispatchEvent(event: WorkerGlobalScopeEventMap[keyof WorkerGlobalScopeEventMap]): boolean;
1257
+
1258
+ declare function fetch(request: Request | string, requestInitr?: RequestInit | Request): Promise<Response>;
1259
+
1260
+ declare function queueMicrotask(task: Function): void;
1261
+
1262
+ declare function removeEventListener<Type extends keyof WorkerGlobalScopeEventMap>(type: Type, handler: EventListenerOrEventListenerObject<WorkerGlobalScopeEventMap[Type]>, options?: EventTargetEventListenerOptions | boolean): void;
1263
+
1264
+ declare const self: ServiceWorkerGlobalScope;
1265
+
1266
+ declare function setInterval<Args extends any[]>(callback: (...args: Args) => void, msDelay?: number, ...args: Args): number;
1267
+
1268
+ declare function setTimeout<Args extends any[]>(callback: (...args: Args) => void, msDelay?: number, ...args: Args): number;
1269
+