This repository has been archived by the owner on Feb 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathindex.d.ts
2787 lines (2548 loc) · 74.2 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// This file is auto-generated. DO NOT MODIFY.
// Please refer to the Auto-Generation section of the README.md.
declare class AbortController {
constructor();
readonly signal: AbortSignal;
abort(reason?: any): void;
}
declare class AbortSignal extends EventTarget {
constructor();
static abort(reason?: any): AbortSignal;
static timeout(delay: number): AbortSignal;
readonly aborted: boolean;
readonly reason: any;
throwIfAborted(): void;
}
declare class Blob {
constructor(bits?: BlobBits, options?: BlobOptions);
readonly size: number;
readonly type: string;
slice(start?: number, end?: number, type?: string): Blob;
arrayBuffer(): Promise<ArrayBuffer>;
text(): Promise<string>;
stream(): ReadableStream;
}
declare type BlobBits = (ArrayBuffer | string | Blob)[];
interface BlobOptions {
type?: string;
}
declare abstract class Body {
readonly body: ReadableStream | null;
readonly bodyUsed: boolean;
arrayBuffer(): Promise<ArrayBuffer>;
text(): Promise<string>;
json<T>(): Promise<T>;
formData(): Promise<FormData>;
blob(): Promise<Blob>;
}
declare type BodyInit =
| ReadableStream
| string
| ArrayBuffer
| Blob
| URLSearchParams
| FormData;
/**
* Back compat for code migrating to older definitions.
* @deprecated Use BodyInit instead.
*/
declare type BodyInitializer = BodyInit;
declare class ByteLengthQueuingStrategy {
constructor(init: QueuingStrategyInit);
readonly highWaterMark: number;
size(chunk?: any): number;
}
declare abstract class Cache {
delete(
request: Request | string,
options?: CacheQueryOptions
): Promise<boolean>;
match(
request: Request | string,
options?: CacheQueryOptions
): Promise<Response | undefined>;
put(request: Request | string, response: Response): Promise<void>;
}
interface CacheQueryOptions {
ignoreMethod?: boolean;
}
declare abstract class CacheStorage {
open(cacheName: string): Promise<Cache>;
readonly default: Cache;
}
interface CfRequestInit extends Omit<RequestInit, "cf"> {
cf?: RequestInitCfProperties;
}
/**
* Back compat support with older types.
* @deprecated Use CfRequestInit instead.
*/
declare type CfRequestInitializerDict = CfRequestInit;
declare class CloseEvent extends Event {
constructor(type: string, initializer: CloseEventInit);
readonly code: number;
readonly reason: string;
readonly wasClean: boolean;
}
interface CloseEventInit {
code?: number;
reason?: string;
wasClean?: boolean;
}
/**
* Back compat for code migrating from older definitions.
* @deprecated Use CloseEventInit instead.
*/
declare type CloseEventInitializer = CloseEventInit;
interface Comment {
text: string;
readonly removed: boolean;
before(content: Content, options?: ContentOptions): Comment;
after(content: Content, options?: ContentOptions): Comment;
replace(content: Content, options?: ContentOptions): Comment;
remove(): Comment;
}
declare class CompressionStream extends TransformStream {
constructor(format: "gzip" | "deflate");
}
interface Console {
debug(...data: any[]): void;
error(...data: any[]): void;
info(...data: any[]): void;
log(...data: any[]): void;
warn(...data: any[]): void;
}
declare type Content = string | ReadableStream | Response;
interface ContentOptions {
html?: boolean;
}
declare class CountQueuingStrategy {
constructor(init: QueuingStrategyInit);
readonly highWaterMark: number;
size(chunk?: any): number;
}
declare abstract class Crypto {
readonly subtle: SubtleCrypto;
getRandomValues<
T extends
| Int8Array
| Uint8Array
| Int16Array
| Uint16Array
| Int32Array
| Uint32Array
| BigInt64Array
| BigUint64Array
>(buffer: T): T;
randomUUID(): string;
DigestStream: typeof DigestStream;
}
declare abstract class CryptoKey {
readonly type: string;
readonly extractable: boolean;
readonly algorithm: CryptoKeyAlgorithmVariant;
readonly usages: string[];
}
interface CryptoKeyAesKeyAlgorithm {
name: string;
length: number;
}
declare type CryptoKeyAlgorithmVariant =
| CryptoKeyKeyAlgorithm
| CryptoKeyAesKeyAlgorithm
| CryptoKeyHmacKeyAlgorithm
| CryptoKeyRsaKeyAlgorithm
| CryptoKeyEllipticKeyAlgorithm
| CryptoKeyArbitraryKeyAlgorithm;
interface CryptoKeyArbitraryKeyAlgorithm {
name: string;
hash?: CryptoKeyKeyAlgorithm;
namedCurve?: string;
length?: number;
}
interface CryptoKeyEllipticKeyAlgorithm {
name: string;
namedCurve: string;
}
interface CryptoKeyHmacKeyAlgorithm {
name: string;
hash: CryptoKeyKeyAlgorithm;
length: number;
}
interface CryptoKeyKeyAlgorithm {
name: string;
}
interface CryptoKeyPair {
publicKey: CryptoKey;
privateKey: CryptoKey;
}
interface CryptoKeyRsaKeyAlgorithm {
name: string;
modulusLength: number;
publicExponent: ArrayBuffer;
hash?: CryptoKeyKeyAlgorithm;
}
interface D1Database {
prepare(query: string): D1PreparedStatement;
dump(): Promise<ArrayBuffer>;
batch<T = unknown>(statements: D1PreparedStatement[]): Promise<D1Result<T>[]>;
exec<T = unknown>(query: string): Promise<D1Result<T>>;
}
interface D1PreparedStatement {
bind(...values: any[]): D1PreparedStatement;
first<T = unknown>(colName?: string): Promise<T>;
run<T = unknown>(): Promise<D1Result<T>>;
all<T = unknown>(): Promise<D1Result<T>>;
raw<T = unknown>(): Promise<T[]>;
}
declare type D1Result<T = unknown> = {
results?: T[];
lastRowId: number | null;
changes: number;
duration: number;
error?: string;
};
declare class DOMException extends Error {
constructor(message?: string, name?: string);
readonly code: number;
static readonly INDEX_SIZE_ERR: number;
static readonly DOMSTRING_SIZE_ERR: number;
static readonly HIERARCHY_REQUEST_ERR: number;
static readonly WRONG_DOCUMENT_ERR: number;
static readonly INVALID_CHARACTER_ERR: number;
static readonly NO_DATA_ALLOWED_ERR: number;
static readonly NO_MODIFICATION_ALLOWED_ERR: number;
static readonly NOT_FOUND_ERR: number;
static readonly NOT_SUPPORTED_ERR: number;
static readonly INUSE_ATTRIBUTE_ERR: number;
static readonly INVALID_STATE_ERR: number;
static readonly SYNTAX_ERR: number;
static readonly INVALID_MODIFICATION_ERR: number;
static readonly NAMESPACE_ERR: number;
static readonly INVALID_ACCESS_ERR: number;
static readonly VALIDATION_ERR: number;
static readonly TYPE_MISMATCH_ERR: number;
static readonly SECURITY_ERR: number;
static readonly NETWORK_ERR: number;
static readonly ABORT_ERR: number;
static readonly URL_MISMATCH_ERR: number;
static readonly QUOTA_EXCEEDED_ERR: number;
static readonly TIMEOUT_ERR: number;
static readonly INVALID_NODE_TYPE_ERR: number;
static readonly DATA_CLONE_ERR: number;
}
declare class DecompressionStream extends TransformStream {
constructor(format: "gzip" | "deflate");
}
declare class DigestStream extends WritableStream {
constructor(algorithm: string | SubtleCryptoHashAlgorithm);
readonly digest: Promise<ArrayBuffer>;
}
interface Doctype {
readonly name: string | null;
readonly publicId: string | null;
readonly systemId: string | null;
}
interface DocumentEnd {
append(content: Content, options?: ContentOptions): DocumentEnd;
}
interface DurableObject {
fetch(request: Request): Promise<Response>;
alarm?(): Promise<void>;
}
interface DurableObjectGetAlarmOptions {
allowConcurrency?: boolean;
}
interface DurableObjectGetOptions {
allowConcurrency?: boolean;
noCache?: boolean;
}
interface DurableObjectId {
toString(): string;
equals(other: DurableObjectId): boolean;
readonly name?: string;
}
interface DurableObjectListOptions {
start?: string;
startAfter?: string;
end?: string;
prefix?: string;
reverse?: boolean;
limit?: number;
allowConcurrency?: boolean;
noCache?: boolean;
}
interface DurableObjectNamespace {
newUniqueId(
options?: DurableObjectNamespaceNewUniqueIdOptions
): DurableObjectId;
idFromName(name: string): DurableObjectId;
idFromString(id: string): DurableObjectId;
get(id: DurableObjectId): DurableObjectStub;
}
interface DurableObjectNamespaceNewUniqueIdOptions {
jurisdiction?: string;
}
interface DurableObjectPutOptions {
allowConcurrency?: boolean;
allowUnconfirmed?: boolean;
noCache?: boolean;
}
interface DurableObjectSetAlarmOptions {
allowConcurrency?: boolean;
allowUnconfirmed?: boolean;
}
interface DurableObjectState {
waitUntil(promise: Promise<any>): void;
id: DurableObjectId;
readonly storage: DurableObjectStorage;
blockConcurrencyWhile<T>(callback: () => Promise<T>): Promise<T>;
}
interface DurableObjectStorage {
get<T = unknown>(
key: string,
options?: DurableObjectGetOptions
): Promise<T | undefined>;
get<T = unknown>(
keys: string[],
options?: DurableObjectGetOptions
): Promise<Map<string, T>>;
list<T = unknown>(
options?: DurableObjectListOptions
): Promise<Map<string, T>>;
put<T>(
key: string,
value: T,
options?: DurableObjectPutOptions
): Promise<void>;
put<T>(
entries: Record<string, T>,
options?: DurableObjectPutOptions
): Promise<void>;
delete(key: string, options?: DurableObjectPutOptions): Promise<boolean>;
delete(keys: string[], options?: DurableObjectPutOptions): Promise<number>;
deleteAll(options?: DurableObjectPutOptions): Promise<void>;
transaction<T>(
closure: (txn: DurableObjectTransaction) => Promise<T>
): Promise<T>;
getAlarm(options?: DurableObjectGetAlarmOptions): Promise<number | null>;
setAlarm(
scheduledTime: number | Date,
options?: DurableObjectSetAlarmOptions
): Promise<void>;
deleteAlarm(options?: DurableObjectSetAlarmOptions): Promise<void>;
sync(): Promise<void>;
}
/**
*
* @deprecated Don't use. Introduced incidentally in workers-types 3.x. Scheduled for removal.
*/
declare type DurableObjectStorageOperationsGetOptions = DurableObjectGetOptions;
/**
*
* @deprecated Don't use. Introduced incidentally in workers-types 3.x. Scheduled for removal.
*/
declare type DurableObjectStorageOperationsListOptions =
DurableObjectListOptions;
/**
*
* @deprecated Don't use. Introduced incidentally in workers-types 3.x. Scheduled for removal.
*/
declare type DurableObjectStorageOperationsPutOptions = DurableObjectPutOptions;
interface DurableObjectStub extends Fetcher {
readonly id: DurableObjectId;
readonly name?: string;
}
interface DurableObjectTransaction {
get<T = unknown>(
key: string,
options?: DurableObjectGetOptions
): Promise<T | undefined>;
get<T = unknown>(
keys: string[],
options?: DurableObjectGetOptions
): Promise<Map<string, T>>;
list<T = unknown>(
options?: DurableObjectListOptions
): Promise<Map<string, T>>;
put<T>(
key: string,
value: T,
options?: DurableObjectPutOptions
): Promise<void>;
put<T>(
entries: Record<string, T>,
options?: DurableObjectPutOptions
): Promise<void>;
delete(key: string, options?: DurableObjectPutOptions): Promise<boolean>;
delete(keys: string[], options?: DurableObjectPutOptions): Promise<number>;
rollback(): void;
getAlarm(options?: DurableObjectGetAlarmOptions): Promise<number | null>;
setAlarm(
scheduledTime: number | Date,
options?: DurableObjectSetAlarmOptions
): Promise<void>;
deleteAlarm(options?: DurableObjectSetAlarmOptions): Promise<void>;
}
interface Element {
tagName: string;
readonly attributes: IterableIterator<string[]>;
readonly removed: boolean;
readonly namespaceURI: string;
getAttribute(name: string): string | null;
hasAttribute(name: string): boolean;
setAttribute(name: string, value: string): Element;
removeAttribute(name: string): Element;
before(content: Content, options?: ContentOptions): Element;
after(content: Content, options?: ContentOptions): Element;
prepend(content: Content, options?: ContentOptions): Element;
append(content: Content, options?: ContentOptions): Element;
replace(content: Content, options?: ContentOptions): Element;
remove(): Element;
removeAndKeepContent(): Element;
setInnerContent(content: Content, options?: ContentOptions): Element;
onEndTag(handler: (tag: EndTag) => void | Promise<void>): void;
}
interface EndTag {
name: string;
before(content: Content, options?: ContentOptions): EndTag;
after(content: Content, options?: ContentOptions): EndTag;
remove(): EndTag;
}
interface ErrorEvent extends Event {
readonly filename: string;
readonly message: string;
readonly lineno: number;
readonly colno: number;
readonly error: any;
}
declare class Event {
constructor(type: string, init?: EventInit);
readonly type: string;
readonly eventPhase: number;
readonly composed: boolean;
readonly bubbles: boolean;
readonly cancelable: boolean;
readonly defaultPrevented: boolean;
readonly returnValue: boolean;
readonly currentTarget?: EventTarget;
readonly srcElement?: EventTarget;
readonly timeStamp: number;
readonly isTrusted: boolean;
cancelBubble: boolean;
stopImmediatePropagation(): void;
preventDefault(): void;
stopPropagation(): void;
composedPath(): EventTarget[];
static readonly NONE: number;
static readonly CAPTURING_PHASE: number;
static readonly AT_TARGET: number;
static readonly BUBBLING_PHASE: number;
}
interface EventInit {
bubbles?: boolean;
cancelable?: boolean;
composed?: boolean;
}
declare type EventListener<EventType extends Event = Event> = (
event: EventType
) => void;
interface EventListenerObject<EventType extends Event = Event> {
handleEvent(event: EventType): void;
}
declare type EventListenerOrEventListenerObject<
EventType extends Event = Event
> = EventListener<EventType> | EventListenerObject<EventType>;
declare class EventTarget<
EventMap extends Record<string, Event> = Record<string, Event>
> {
constructor();
addEventListener<Type extends keyof EventMap>(
type: Type,
handler: EventListenerOrEventListenerObject<EventMap[Type]>,
options?: EventTargetAddEventListenerOptions | boolean
): void;
removeEventListener<Type extends keyof EventMap>(
type: Type,
handler: EventListenerOrEventListenerObject<EventMap[Type]>,
options?: EventTargetEventListenerOptions | boolean
): void;
dispatchEvent(event: EventMap[keyof EventMap]): boolean;
}
interface EventTargetAddEventListenerOptions {
capture?: boolean;
passive?: boolean;
once?: boolean;
signal?: AbortSignal;
}
interface EventTargetEventListenerOptions {
capture?: boolean;
}
interface EventTargetHandlerObject {
handleEvent(arg1: Event): any | undefined;
}
interface ExecutionContext {
waitUntil(promise: Promise<any>): void;
passThroughOnException(): void;
}
interface ExportedHandler<Env = unknown> {
fetch?: ExportedHandlerFetchHandler<Env>;
scheduled?: ExportedHandlerScheduledHandler<Env>;
}
declare type ExportedHandlerFetchHandler<Env = unknown> = (
request: Request,
env: Env,
ctx: ExecutionContext
) => Response | Promise<Response>;
declare type ExportedHandlerScheduledHandler<Env = unknown> = (
controller: ScheduledController,
env: Env,
ctx: ExecutionContext
) => void | Promise<void>;
declare class ExtendableEvent extends Event {
constructor(type: string, init?: EventInit);
waitUntil(promise: Promise<any>): void;
}
declare abstract class FetchEvent extends ExtendableEvent {
readonly request: Request;
respondWith(promise: Response | Promise<Response>): void;
passThroughOnException(): void;
}
declare abstract class Fetcher {
fetch(
requestOrUrl: Request | string,
requestInit?: RequestInit | Request
): Promise<Response>;
}
declare class File extends Blob {
constructor(bits?: BlobBits, name?: string, options?: FileOptions);
readonly name: string;
readonly lastModified: number;
}
interface FileOptions {
type?: string;
lastModified?: number;
}
declare class FixedLengthStream extends IdentityTransformStream {
constructor(expectedLength: number | bigint);
}
declare class FormData {
constructor();
append(name: string, value: string): void;
append(name: string, value: Blob, filename?: string): void;
delete(name: string): void;
get(name: string): File | string | null;
getAll(name: string): (File | string)[];
has(name: string): boolean;
set(name: string, value: string): void;
set(name: string, value: Blob, filename?: string): void;
entries(): IterableIterator<[key: string, value: File | string]>;
keys(): IterableIterator<string>;
values(): IterableIterator<string | File>;
forEach<This = unknown>(
callback: (
this: This,
value: File | string,
key: string,
parent: FormData
) => void,
thisArg?: This
): void;
[Symbol.iterator](): IterableIterator<[key: string, value: File | string]>;
}
declare class HTMLRewriter {
constructor();
on(
selector: string,
handlers: HTMLRewriterElementContentHandlers
): HTMLRewriter;
onDocument(handlers: HTMLRewriterDocumentContentHandlers): HTMLRewriter;
transform(response: Response): Response;
}
interface HTMLRewriterDocumentContentHandlers {
doctype?(doctype: Doctype): void | Promise<void>;
comments?(comment: Comment): void | Promise<void>;
text?(text: Text): void | Promise<void>;
end?(end: DocumentEnd): void | Promise<void>;
}
interface HTMLRewriterElementContentHandlers {
element?(element: Element): void | Promise<void>;
comments?(comment: Comment): void | Promise<void>;
text?(text: Text): void | Promise<void>;
}
declare class Headers {
constructor(init?: HeadersInit);
get(name: string): string | null;
getAll(name: string): string[];
has(name: string): boolean;
set(name: string, value: string): void;
append(name: string, value: string): void;
delete(name: string): void;
forEach<This = unknown>(
callback: (this: This, value: string, key: string, parent: Headers) => void,
thisArg?: This
): void;
entries(): IterableIterator<[key: string, value: string]>;
keys(): IterableIterator<string>;
values(): IterableIterator<string>;
[Symbol.iterator](): IterableIterator<[key: string, value: string]>;
}
declare type HeadersInit =
| Headers
| Record<string, string>
| [key: string, value: string][];
/**
* Back compat for code migrating to older definitions.
* @deprecated Use HeadersInit instead.
*/
declare type HeadersInitializer = HeadersInit;
declare class IdentityTransformStream extends TransformStream {
constructor();
}
interface JsonWebKey {
kty: string;
use?: string;
key_ops?: string[];
alg?: string;
ext?: boolean;
crv?: string;
x?: string;
y?: string;
d?: string;
n?: string;
e?: string;
p?: string;
q?: string;
dp?: string;
dq?: string;
qi?: string;
oth?: RsaOtherPrimesInfo[];
k?: string;
}
/**
* Workers KV is a global, low-latency, key-value data store. It supports exceptionally high read volumes with low-latency,
* making it possible to build highly dynamic APIs and websites which respond as quickly as a cached static file would.
*/
interface KVNamespace<K extends string = string> {
get(
key: K,
options?: Partial<KVNamespaceGetOptions<undefined>>
): Promise<string | null>;
get(key: K, type: "text"): Promise<string | null>;
get<ExpectedValue = unknown>(
key: K,
type: "json"
): Promise<ExpectedValue | null>;
get(key: K, type: "arrayBuffer"): Promise<ArrayBuffer | null>;
get(key: K, type: "stream"): Promise<ReadableStream | null>;
get(key: K, options: KVNamespaceGetOptions<"text">): Promise<string | null>;
get<ExpectedValue = unknown>(
key: string,
options: KVNamespaceGetOptions<"json">
): Promise<ExpectedValue | null>;
get(
key: K,
options: KVNamespaceGetOptions<"arrayBuffer">
): Promise<ArrayBuffer | null>;
get(
key: K,
options: KVNamespaceGetOptions<"stream">
): Promise<ReadableStream | null>;
list<Metadata = unknown>(
options?: KVNamespaceListOptions
): Promise<KVNamespaceListResult<Metadata>>;
/**
* Creates a new key-value pair, or updates the value for a particular key.
* @param key key to associate with the value. A key cannot be empty, `.` or `..`. All other keys are valid.
* @param value value to store. The type is inferred. The maximum size of a value is 25MB.
* @returns Returns a `Promise` that you should `await` on in order to verify a successful update.
* @example
* await NAMESPACE.put(key, value);
*/
put(
key: K,
value: string | ArrayBuffer | ArrayBufferView | ReadableStream,
options?: KVNamespacePutOptions
): Promise<void>;
getWithMetadata<Metadata = unknown>(
key: K,
options?: Partial<KVNamespaceGetOptions<undefined>>
): Promise<KVNamespaceGetWithMetadataResult<string, Metadata>>;
getWithMetadata<Metadata = unknown>(
key: K,
type: "text"
): Promise<KVNamespaceGetWithMetadataResult<string, Metadata>>;
getWithMetadata<ExpectedValue = unknown, Metadata = unknown>(
key: K,
type: "json"
): Promise<KVNamespaceGetWithMetadataResult<ExpectedValue, Metadata>>;
getWithMetadata<Metadata = unknown>(
key: K,
type: "arrayBuffer"
): Promise<KVNamespaceGetWithMetadataResult<ArrayBuffer, Metadata>>;
getWithMetadata<Metadata = unknown>(
key: K,
type: "stream"
): Promise<KVNamespaceGetWithMetadataResult<ReadableStream, Metadata>>;
getWithMetadata<Metadata = unknown>(
key: K,
options: KVNamespaceGetOptions<"text">
): Promise<KVNamespaceGetWithMetadataResult<string, Metadata>>;
getWithMetadata<ExpectedValue = unknown, Metadata = unknown>(
key: K,
options: KVNamespaceGetOptions<"json">
): Promise<KVNamespaceGetWithMetadataResult<ExpectedValue, Metadata>>;
getWithMetadata<Metadata = unknown>(
key: K,
options: KVNamespaceGetOptions<"arrayBuffer">
): Promise<KVNamespaceGetWithMetadataResult<ArrayBuffer, Metadata>>;
getWithMetadata<Metadata = unknown>(
key: K,
options: KVNamespaceGetOptions<"stream">
): Promise<KVNamespaceGetWithMetadataResult<ReadableStream, Metadata>>;
delete(name: string): Promise<void>;
}
interface KVNamespaceGetOptions<Type> {
type: Type;
cacheTtl?: number;
}
interface KVNamespaceGetWithMetadataResult<Value, Metadata> {
value: Value | null;
metadata: Metadata | null;
}
interface KVNamespaceListKey<Metadata> {
name: string;
expiration?: number;
metadata?: Metadata;
}
interface KVNamespaceListOptions {
limit?: number;
prefix?: string | null;
cursor?: string | null;
}
interface KVNamespaceListResult<Metadata> {
keys: KVNamespaceListKey<Metadata>[];
list_complete: boolean;
cursor?: string;
}
interface KVNamespacePutOptions {
expiration?: number;
expirationTtl?: number;
metadata?: any | null;
}
declare class MessageEvent extends Event {
constructor(type: string, initializer: MessageEventInit);
readonly data: ArrayBuffer | string;
}
interface MessageEventInit {
data: ArrayBuffer | string;
}
/**
* Back compat for code migrating from older definitions.
* @deprecated Use MessageEventInit instead.
*/
declare type MessageEventInitializer = MessageEventInit;
declare abstract class Navigator {
readonly userAgent: string;
}
/**
* Transitionary name.
* @deprecated Use StreamPipeOptions
*/
interface PipeToOptions {
preventClose?: boolean;
preventAbort?: boolean;
preventCancel?: boolean;
signal?: AbortSignal;
}
declare abstract class PromiseRejectionEvent extends Event {
readonly promise: Promise<any>;
readonly reason: any;
}
interface QueuingStrategyInit {
highWaterMark: number;
}
/**
* An instance of the R2 bucket binding.
*/
interface R2Bucket {
head(key: string): Promise<R2Object | null>;
get(key: string): Promise<R2ObjectBody | null>;
/**
* Returns R2Object on a failure of the conditional specified in onlyIf.
*/
get(
key: string,
options: R2GetOptions
): Promise<R2ObjectBody | R2Object | null>;
get(
key: string,
options?: R2GetOptions
): Promise<R2ObjectBody | R2Object | null>;
put(
key: string,
value:
| ReadableStream
| ArrayBuffer
| ArrayBufferView
| string
| null
| Blob,
options?: R2PutOptions
): Promise<R2Object>;
delete(keys: string | string[]): Promise<void>;
list(options?: R2ListOptions): Promise<R2Objects>;
}
/**
* The checksums associated with the object.
*/
interface R2Checksums {
md5?: ArrayBuffer;
sha1?: ArrayBuffer;
sha256?: ArrayBuffer;
sha384?: ArrayBuffer;
sha512?: ArrayBuffer;
}
/**
* Perform the operation conditionally based on meeting the defined criteria.
*/
interface R2Conditional {
etagMatches?: string;
etagDoesNotMatch?: string;
uploadedBefore?: Date;
uploadedAfter?: Date;
secondsGranularity?: boolean;
}
/**
* Options for retrieving the object metadata nad payload.
*/
interface R2GetOptions {
onlyIf?: R2Conditional | Headers;
range?: R2Range | Headers;
}
/**
* Metadata that's automatically rendered into R2 HTTP API endpoints.
* ```
* * contentType -> content-type
* * contentLanguage -> content-language
* etc...
* ```
* This data is echoed back on GET responses based on what was originally
* assigned to the object (and can typically also be overriden when issuing
* the GET request).
*/
interface R2HTTPMetadata {
contentType?: string;
contentLanguage?: string;
contentDisposition?: string;
contentEncoding?: string;
cacheControl?: string;
cacheExpiry?: Date;
}
interface R2ListOptions {
limit?: number;
prefix?: string;
cursor?: string;
delimiter?: string;
startAfter?: string;
/**
* If you populate this array, then items returned will include this metadata.
* A tradeoff is that fewer results may be returned depending on how big this
* data is. For now the caps are TBD but expect the total memory usage for a list
* operation may need to be <1MB or even <128kb depending on how many list operations
* you are sending into one bucket. Make sure to look at `truncated` for the result
* rather than having logic like
* ```
* while (listed.length < limit) {
* listed = myBucket.list({ limit, include: ['customMetadata'] })
* }
* ```
*/
include?: ("httpMetadata" | "customMetadata")[];
}
/**
* The metadata for the object.
*/
declare abstract class R2Object {
readonly key: string;
readonly version: string;
readonly size: number;
readonly etag: string;
readonly httpEtag: string;
readonly checksums: R2Checksums;
readonly uploaded: Date;
readonly httpMetadata?: R2HTTPMetadata;
readonly customMetadata?: Record<string, string>;
readonly range?: R2Range;
writeHttpMetadata(headers: Headers): void;
}
/**
* The metadata for the object and the body of the payload.
*/
interface R2ObjectBody extends R2Object {
readonly body: ReadableStream;
readonly bodyUsed: boolean;
arrayBuffer(): Promise<ArrayBuffer>;
text(): Promise<string>;
json<T>(): Promise<T>;
blob(): Promise<Blob>;
}