@cloudflare/workers-types 4.20221111.0 → 4.20230115.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.
@@ -229,7 +229,6 @@ declare interface ServiceWorkerGlobalScope extends WorkerGlobalScope {
229
229
  FixedLengthStream: typeof FixedLengthStream;
230
230
  IdentityTransformStream: typeof IdentityTransformStream;
231
231
  HTMLRewriter: typeof HTMLRewriter;
232
- connect(address: string, options?: SocketOptions): Socket;
233
232
  }
234
233
  declare function addEventListener<Type extends keyof WorkerGlobalScopeEventMap>(
235
234
  type: Type,
@@ -283,9 +282,8 @@ declare const crypto: Crypto;
283
282
  declare const caches: CacheStorage;
284
283
  declare const scheduler: Scheduler;
285
284
  declare const navigator: Navigator;
286
- declare function connect(address: string, options?: SocketOptions): Socket;
287
285
  declare interface ExecutionContext {
288
- waitUntil(promise: void | Promise<void>): void;
286
+ waitUntil(promise: Promise<any>): void;
289
287
  passThroughOnException(): void;
290
288
  }
291
289
  declare type ExportedHandlerFetchHandler<Env = unknown> = (
@@ -343,13 +341,20 @@ declare interface DurableObjectNamespace {
343
341
  ): DurableObjectId;
344
342
  idFromName(name: string): DurableObjectId;
345
343
  idFromString(id: string): DurableObjectId;
346
- get(id: DurableObjectId): DurableObjectStub;
344
+ get(
345
+ id: DurableObjectId,
346
+ options?: DurableObjectNamespaceGetDurableObjectOptions
347
+ ): DurableObjectStub;
348
+ jurisdiction(jurisdiction: string): DurableObjectNamespace;
347
349
  }
348
350
  declare interface DurableObjectNamespaceNewUniqueIdOptions {
349
351
  jurisdiction?: string;
350
352
  }
353
+ declare interface DurableObjectNamespaceGetDurableObjectOptions {
354
+ locationHint?: string;
355
+ }
351
356
  declare interface DurableObjectState {
352
- waitUntil(promise: void | Promise<void>): void;
357
+ waitUntil(promise: Promise<any>): void;
353
358
  readonly id: DurableObjectId;
354
359
  readonly storage: DurableObjectStorage;
355
360
  blockConcurrencyWhile<T>(callback: () => Promise<T>): Promise<T>;
@@ -539,7 +544,7 @@ declare interface SchedulerWaitOptions {
539
544
  signal?: AbortSignal;
540
545
  }
541
546
  declare abstract class ExtendableEvent extends Event {
542
- waitUntil(promise: void | Promise<void>): void;
547
+ waitUntil(promise: Promise<any>): void;
543
548
  }
544
549
  declare class Blob {
545
550
  constructor(
@@ -1009,7 +1014,6 @@ declare abstract class Fetcher {
1009
1014
  input: RequestInfo,
1010
1015
  init?: RequestInit<RequestInitCfProperties>
1011
1016
  ): Promise<Response>;
1012
- connect(address: string, options?: SocketOptions): Socket;
1013
1017
  }
1014
1018
  declare interface FetcherPutOptions {
1015
1019
  expiration?: number;
@@ -1157,6 +1161,19 @@ declare abstract class R2Bucket {
1157
1161
  | Blob,
1158
1162
  options?: R2PutOptions
1159
1163
  ): Promise<R2Object>;
1164
+ put(
1165
+ key: string,
1166
+ value:
1167
+ | ReadableStream
1168
+ | ArrayBuffer
1169
+ | ArrayBufferView
1170
+ | string
1171
+ | null
1172
+ | Blob,
1173
+ options?: R2PutOptions & {
1174
+ onlyIf: R2Conditional | Headers;
1175
+ }
1176
+ ): Promise<R2Object | null>;
1160
1177
  createMultipartUpload(
1161
1178
  key: string,
1162
1179
  options?: R2MultipartOptions
@@ -1540,6 +1557,8 @@ declare interface TraceItem {
1540
1557
  | TraceItemFetchEventInfo
1541
1558
  | TraceItemScheduledEventInfo
1542
1559
  | TraceItemAlarmEventInfo
1560
+ | TraceItemQueueEventInfo
1561
+ | TraceItemEmailEventInfo
1543
1562
  | TraceItemCustomEventInfo
1544
1563
  )
1545
1564
  | null;
@@ -1548,6 +1567,7 @@ declare interface TraceItem {
1548
1567
  readonly exceptions: TraceException[];
1549
1568
  readonly scriptName: string | null;
1550
1569
  readonly dispatchNamespace?: string;
1570
+ readonly scriptTags?: string[];
1551
1571
  readonly outcome: string;
1552
1572
  }
1553
1573
  declare interface TraceItemAlarmEventInfo {
@@ -1558,6 +1578,15 @@ declare interface TraceItemScheduledEventInfo {
1558
1578
  readonly scheduledTime: number;
1559
1579
  readonly cron: string;
1560
1580
  }
1581
+ declare interface TraceItemQueueEventInfo {
1582
+ readonly queue: string;
1583
+ readonly batchSize: number;
1584
+ }
1585
+ declare interface TraceItemEmailEventInfo {
1586
+ readonly mailFrom: string;
1587
+ readonly rcptTo: string;
1588
+ readonly rawSize: number;
1589
+ }
1561
1590
  declare interface TraceItemFetchEventInfo {
1562
1591
  readonly response?: TraceItemFetchEventInfoResponse;
1563
1592
  readonly request: TraceItemFetchEventInfoRequest;
@@ -1743,15 +1772,6 @@ declare const WebSocketPair: {
1743
1772
  1: WebSocket;
1744
1773
  };
1745
1774
  };
1746
- declare interface Socket {
1747
- readonly readable: ReadableStream;
1748
- readonly writable: WritableStream;
1749
- readonly closed: Promise<void>;
1750
- close(): Promise<void>;
1751
- }
1752
- declare interface SocketOptions {
1753
- tsl: boolean;
1754
- }
1755
1775
  declare interface BasicImageTransformations {
1756
1776
  /**
1757
1777
  * Maximum width in image pixels. The value must be an integer.
@@ -2696,6 +2716,52 @@ declare abstract class D1PreparedStatement {
2696
2716
  all<T = unknown>(): Promise<D1Result<T>>;
2697
2717
  raw<T = unknown>(): Promise<T[]>;
2698
2718
  }
2719
+ /**
2720
+ * A email message that is sent to a consumer Worker.
2721
+ */
2722
+ declare interface EmailMessage<Body = unknown> {
2723
+ /**
2724
+ * Envelope From attribute of the email message.
2725
+ */
2726
+ readonly from: string;
2727
+ /**
2728
+ * Envelope To attribute of the email message.
2729
+ */
2730
+ readonly to: string;
2731
+ /**
2732
+ * A [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers).
2733
+ */
2734
+ readonly headers: Headers;
2735
+ /**
2736
+ * Stream of the email message content.
2737
+ */
2738
+ readonly raw: ReadableStream;
2739
+ /**
2740
+ * Size of the email message content.
2741
+ */
2742
+ readonly rawSize: number;
2743
+ /**
2744
+ * Reject this email message by returning a permanent SMTP error back to the connecting client including the given reason.
2745
+ * @param reason The reject reason.
2746
+ * @returns void
2747
+ */
2748
+ setReject(reason: string): void;
2749
+ /**
2750
+ * Forward this email message to a verified destination address of the account.
2751
+ * @param rcptTo Verified destination address.
2752
+ * @param headers A [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers).
2753
+ * @returns A promise that resolves when the email message is forwarded.
2754
+ */
2755
+ forward(rcptTo: string, headers?: Headers): Promise<void>;
2756
+ }
2757
+ declare abstract class EmailEvent extends ExtendableEvent {
2758
+ readonly message: EmailMessage;
2759
+ }
2760
+ declare type EmailExportedHandler<Env = unknown> = (
2761
+ message: EmailMessage,
2762
+ env: Env,
2763
+ ctx: ExecutionContext
2764
+ ) => void | Promise<void>;
2699
2765
  declare type Params<P extends string = any> = Record<P, string | string[]>;
2700
2766
  declare type EventContext<Env, P extends string, Data> = {
2701
2767
  request: Request;
@@ -2742,6 +2808,40 @@ declare type PagesPluginFunction<
2742
2808
  declare module "assets:*" {
2743
2809
  export const onRequest: PagesFunction;
2744
2810
  }
2811
+ // https://developers.cloudflare.com/pub-sub/
2812
+ // PubSubMessage represents an incoming PubSub message.
2813
+ // The message includes metadata about the broker, the client, and the payload
2814
+ // itself.
2815
+ declare interface PubSubMessage {
2816
+ // Message ID
2817
+ readonly mid: number;
2818
+ // MQTT broker FQDN in the form mqtts://BROKER.NAMESPACE.cloudflarepubsub.com:PORT
2819
+ readonly broker: string;
2820
+ // The MQTT topic the message was sent on.
2821
+ readonly topic: string;
2822
+ // The client ID of the client that published this message.
2823
+ readonly clientId: string;
2824
+ // The unique identifier (JWT ID) used by the client to authenticate, if token
2825
+ // auth was used.
2826
+ readonly jti?: string;
2827
+ // A Unix timestamp (seconds from Jan 1, 1970), set when the Pub/Sub Broker
2828
+ // received the message from the client.
2829
+ readonly receivedAt: number;
2830
+ // An (optional) string with the MIME type of the payload, if set by the
2831
+ // client.
2832
+ readonly contentType: string;
2833
+ // Set to 1 when the payload is a UTF-8 string
2834
+ // https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901063
2835
+ readonly payloadFormatIndicator: number;
2836
+ // Pub/Sub (MQTT) payloads can be UTF-8 strings, or byte arrays.
2837
+ // You can use payloadFormatIndicator to inspect this before decoding.
2838
+ payload: string | Uint8Array;
2839
+ }
2840
+ // JsonWebKey extended by kid parameter
2841
+ declare interface JsonWebKeyWithKid extends JsonWebKey {
2842
+ // Key Identifier of the JWK
2843
+ readonly kid: string;
2844
+ }
2745
2845
  /**
2746
2846
  * A message that is sent to a consumer Worker.
2747
2847
  */
@@ -2776,6 +2876,15 @@ declare interface MessageBatch<Body = unknown> {
2776
2876
  */
2777
2877
  retryAll(): void;
2778
2878
  }
2879
+ /**
2880
+ * A wrapper class used to structure message batches.
2881
+ */
2882
+ declare type MessageSendRequest<Body = unknown> = {
2883
+ /**
2884
+ * The body of the message.
2885
+ */
2886
+ body: Body;
2887
+ };
2779
2888
  /**
2780
2889
  * A binding that allows a producer to send messages to a Queue.
2781
2890
  */
@@ -2786,4 +2895,10 @@ declare interface Queue<Body = any> {
2786
2895
  * @returns A promise that resolves when the message is confirmed to be written to disk.
2787
2896
  */
2788
2897
  send(message: Body): Promise<void>;
2898
+ /**
2899
+ * Sends a batch of messages to the Queue.
2900
+ * @param messages Each item in the input must be supported by the [structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm#supported_types). A batch can contain up to 100 messages, though items are limited to 128 KB each, and the total size of the array cannot exceed 256 KB.
2901
+ * @returns A promise that resolves when the messages are confirmed to be written to disk.
2902
+ */
2903
+ sendBatch(messages: Iterable<MessageSendRequest<Body>>): Promise<void>;
2789
2904
  }
@@ -229,7 +229,6 @@ export interface ServiceWorkerGlobalScope extends WorkerGlobalScope {
229
229
  FixedLengthStream: typeof FixedLengthStream;
230
230
  IdentityTransformStream: typeof IdentityTransformStream;
231
231
  HTMLRewriter: typeof HTMLRewriter;
232
- connect(address: string, options?: SocketOptions): Socket;
233
232
  }
234
233
  export declare function addEventListener<
235
234
  Type extends keyof WorkerGlobalScopeEventMap
@@ -285,12 +284,8 @@ export declare const crypto: Crypto;
285
284
  export declare const caches: CacheStorage;
286
285
  export declare const scheduler: Scheduler;
287
286
  export declare const navigator: Navigator;
288
- export declare function connect(
289
- address: string,
290
- options?: SocketOptions
291
- ): Socket;
292
287
  export interface ExecutionContext {
293
- waitUntil(promise: void | Promise<void>): void;
288
+ waitUntil(promise: Promise<any>): void;
294
289
  passThroughOnException(): void;
295
290
  }
296
291
  export type ExportedHandlerFetchHandler<Env = unknown> = (
@@ -348,13 +343,20 @@ export interface DurableObjectNamespace {
348
343
  ): DurableObjectId;
349
344
  idFromName(name: string): DurableObjectId;
350
345
  idFromString(id: string): DurableObjectId;
351
- get(id: DurableObjectId): DurableObjectStub;
346
+ get(
347
+ id: DurableObjectId,
348
+ options?: DurableObjectNamespaceGetDurableObjectOptions
349
+ ): DurableObjectStub;
350
+ jurisdiction(jurisdiction: string): DurableObjectNamespace;
352
351
  }
353
352
  export interface DurableObjectNamespaceNewUniqueIdOptions {
354
353
  jurisdiction?: string;
355
354
  }
355
+ export interface DurableObjectNamespaceGetDurableObjectOptions {
356
+ locationHint?: string;
357
+ }
356
358
  export interface DurableObjectState {
357
- waitUntil(promise: void | Promise<void>): void;
359
+ waitUntil(promise: Promise<any>): void;
358
360
  readonly id: DurableObjectId;
359
361
  readonly storage: DurableObjectStorage;
360
362
  blockConcurrencyWhile<T>(callback: () => Promise<T>): Promise<T>;
@@ -544,7 +546,7 @@ export interface SchedulerWaitOptions {
544
546
  signal?: AbortSignal;
545
547
  }
546
548
  export declare abstract class ExtendableEvent extends Event {
547
- waitUntil(promise: void | Promise<void>): void;
549
+ waitUntil(promise: Promise<any>): void;
548
550
  }
549
551
  export declare class Blob {
550
552
  constructor(
@@ -1014,7 +1016,6 @@ export declare abstract class Fetcher {
1014
1016
  input: RequestInfo,
1015
1017
  init?: RequestInit<RequestInitCfProperties>
1016
1018
  ): Promise<Response>;
1017
- connect(address: string, options?: SocketOptions): Socket;
1018
1019
  }
1019
1020
  export interface FetcherPutOptions {
1020
1021
  expiration?: number;
@@ -1162,6 +1163,19 @@ export declare abstract class R2Bucket {
1162
1163
  | Blob,
1163
1164
  options?: R2PutOptions
1164
1165
  ): Promise<R2Object>;
1166
+ put(
1167
+ key: string,
1168
+ value:
1169
+ | ReadableStream
1170
+ | ArrayBuffer
1171
+ | ArrayBufferView
1172
+ | string
1173
+ | null
1174
+ | Blob,
1175
+ options?: R2PutOptions & {
1176
+ onlyIf: R2Conditional | Headers;
1177
+ }
1178
+ ): Promise<R2Object | null>;
1165
1179
  createMultipartUpload(
1166
1180
  key: string,
1167
1181
  options?: R2MultipartOptions
@@ -1548,6 +1562,8 @@ export interface TraceItem {
1548
1562
  | TraceItemFetchEventInfo
1549
1563
  | TraceItemScheduledEventInfo
1550
1564
  | TraceItemAlarmEventInfo
1565
+ | TraceItemQueueEventInfo
1566
+ | TraceItemEmailEventInfo
1551
1567
  | TraceItemCustomEventInfo
1552
1568
  )
1553
1569
  | null;
@@ -1556,6 +1572,7 @@ export interface TraceItem {
1556
1572
  readonly exceptions: TraceException[];
1557
1573
  readonly scriptName: string | null;
1558
1574
  readonly dispatchNamespace?: string;
1575
+ readonly scriptTags?: string[];
1559
1576
  readonly outcome: string;
1560
1577
  }
1561
1578
  export interface TraceItemAlarmEventInfo {
@@ -1566,6 +1583,15 @@ export interface TraceItemScheduledEventInfo {
1566
1583
  readonly scheduledTime: number;
1567
1584
  readonly cron: string;
1568
1585
  }
1586
+ export interface TraceItemQueueEventInfo {
1587
+ readonly queue: string;
1588
+ readonly batchSize: number;
1589
+ }
1590
+ export interface TraceItemEmailEventInfo {
1591
+ readonly mailFrom: string;
1592
+ readonly rcptTo: string;
1593
+ readonly rawSize: number;
1594
+ }
1569
1595
  export interface TraceItemFetchEventInfo {
1570
1596
  readonly response?: TraceItemFetchEventInfoResponse;
1571
1597
  readonly request: TraceItemFetchEventInfoRequest;
@@ -1751,15 +1777,6 @@ export declare const WebSocketPair: {
1751
1777
  1: WebSocket;
1752
1778
  };
1753
1779
  };
1754
- export interface Socket {
1755
- readonly readable: ReadableStream;
1756
- readonly writable: WritableStream;
1757
- readonly closed: Promise<void>;
1758
- close(): Promise<void>;
1759
- }
1760
- export interface SocketOptions {
1761
- tsl: boolean;
1762
- }
1763
1780
  export interface BasicImageTransformations {
1764
1781
  /**
1765
1782
  * Maximum width in image pixels. The value must be an integer.
@@ -2704,6 +2721,52 @@ export declare abstract class D1PreparedStatement {
2704
2721
  all<T = unknown>(): Promise<D1Result<T>>;
2705
2722
  raw<T = unknown>(): Promise<T[]>;
2706
2723
  }
2724
+ /**
2725
+ * A email message that is sent to a consumer Worker.
2726
+ */
2727
+ export interface EmailMessage<Body = unknown> {
2728
+ /**
2729
+ * Envelope From attribute of the email message.
2730
+ */
2731
+ readonly from: string;
2732
+ /**
2733
+ * Envelope To attribute of the email message.
2734
+ */
2735
+ readonly to: string;
2736
+ /**
2737
+ * A [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers).
2738
+ */
2739
+ readonly headers: Headers;
2740
+ /**
2741
+ * Stream of the email message content.
2742
+ */
2743
+ readonly raw: ReadableStream;
2744
+ /**
2745
+ * Size of the email message content.
2746
+ */
2747
+ readonly rawSize: number;
2748
+ /**
2749
+ * Reject this email message by returning a permanent SMTP error back to the connecting client including the given reason.
2750
+ * @param reason The reject reason.
2751
+ * @returns void
2752
+ */
2753
+ setReject(reason: string): void;
2754
+ /**
2755
+ * Forward this email message to a verified destination address of the account.
2756
+ * @param rcptTo Verified destination address.
2757
+ * @param headers A [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers).
2758
+ * @returns A promise that resolves when the email message is forwarded.
2759
+ */
2760
+ forward(rcptTo: string, headers?: Headers): Promise<void>;
2761
+ }
2762
+ export declare abstract class EmailEvent extends ExtendableEvent {
2763
+ readonly message: EmailMessage;
2764
+ }
2765
+ export type EmailExportedHandler<Env = unknown> = (
2766
+ message: EmailMessage,
2767
+ env: Env,
2768
+ ctx: ExecutionContext
2769
+ ) => void | Promise<void>;
2707
2770
  export type Params<P extends string = any> = Record<P, string | string[]>;
2708
2771
  export type EventContext<Env, P extends string, Data> = {
2709
2772
  request: Request;
@@ -2747,6 +2810,40 @@ export type PagesPluginFunction<
2747
2810
  > = (
2748
2811
  context: EventPluginContext<Env, Params, Data, PluginArgs>
2749
2812
  ) => Response | Promise<Response>;
2813
+ // https://developers.cloudflare.com/pub-sub/
2814
+ // PubSubMessage represents an incoming PubSub message.
2815
+ // The message includes metadata about the broker, the client, and the payload
2816
+ // itself.
2817
+ export interface PubSubMessage {
2818
+ // Message ID
2819
+ readonly mid: number;
2820
+ // MQTT broker FQDN in the form mqtts://BROKER.NAMESPACE.cloudflarepubsub.com:PORT
2821
+ readonly broker: string;
2822
+ // The MQTT topic the message was sent on.
2823
+ readonly topic: string;
2824
+ // The client ID of the client that published this message.
2825
+ readonly clientId: string;
2826
+ // The unique identifier (JWT ID) used by the client to authenticate, if token
2827
+ // auth was used.
2828
+ readonly jti?: string;
2829
+ // A Unix timestamp (seconds from Jan 1, 1970), set when the Pub/Sub Broker
2830
+ // received the message from the client.
2831
+ readonly receivedAt: number;
2832
+ // An (optional) string with the MIME type of the payload, if set by the
2833
+ // client.
2834
+ readonly contentType: string;
2835
+ // Set to 1 when the payload is a UTF-8 string
2836
+ // https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901063
2837
+ readonly payloadFormatIndicator: number;
2838
+ // Pub/Sub (MQTT) payloads can be UTF-8 strings, or byte arrays.
2839
+ // You can use payloadFormatIndicator to inspect this before decoding.
2840
+ payload: string | Uint8Array;
2841
+ }
2842
+ // JsonWebKey extended by kid parameter
2843
+ export interface JsonWebKeyWithKid extends JsonWebKey {
2844
+ // Key Identifier of the JWK
2845
+ readonly kid: string;
2846
+ }
2750
2847
  /**
2751
2848
  * A message that is sent to a consumer Worker.
2752
2849
  */
@@ -2781,6 +2878,15 @@ export interface MessageBatch<Body = unknown> {
2781
2878
  */
2782
2879
  retryAll(): void;
2783
2880
  }
2881
+ /**
2882
+ * A wrapper class used to structure message batches.
2883
+ */
2884
+ export type MessageSendRequest<Body = unknown> = {
2885
+ /**
2886
+ * The body of the message.
2887
+ */
2888
+ body: Body;
2889
+ };
2784
2890
  /**
2785
2891
  * A binding that allows a producer to send messages to a Queue.
2786
2892
  */
@@ -2791,4 +2897,10 @@ export interface Queue<Body = any> {
2791
2897
  * @returns A promise that resolves when the message is confirmed to be written to disk.
2792
2898
  */
2793
2899
  send(message: Body): Promise<void>;
2900
+ /**
2901
+ * Sends a batch of messages to the Queue.
2902
+ * @param messages Each item in the input must be supported by the [structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm#supported_types). A batch can contain up to 100 messages, though items are limited to 128 KB each, and the total size of the array cannot exceed 256 KB.
2903
+ * @returns A promise that resolves when the messages are confirmed to be written to disk.
2904
+ */
2905
+ sendBatch(messages: Iterable<MessageSendRequest<Body>>): Promise<void>;
2794
2906
  }