@cloudflare/workers-types 4.20230321.0 → 4.20230419.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.
@@ -49,6 +49,7 @@ declare class DOMException extends Error {
49
49
  declare type WorkerGlobalScopeEventMap = {
50
50
  fetch: FetchEvent;
51
51
  scheduled: ScheduledEvent;
52
+ queue: QueueEvent;
52
53
  unhandledrejection: PromiseRejectionEvent;
53
54
  rejectionhandled: PromiseRejectionEvent;
54
55
  };
@@ -187,7 +188,8 @@ declare interface ServiceWorkerGlobalScope extends WorkerGlobalScope {
187
188
  ExtendableEvent: typeof ExtendableEvent;
188
189
  PromiseRejectionEvent: typeof PromiseRejectionEvent;
189
190
  FetchEvent: typeof FetchEvent;
190
- TraceEvent: typeof TraceEvent;
191
+ TailEvent: typeof TailEvent;
192
+ TraceEvent: typeof TailEvent;
191
193
  ScheduledEvent: typeof ScheduledEvent;
192
194
  MessageEvent: typeof MessageEvent;
193
195
  CloseEvent: typeof CloseEvent;
@@ -292,6 +294,11 @@ declare type ExportedHandlerFetchHandler<
292
294
  env: Env,
293
295
  ctx: ExecutionContext
294
296
  ) => Response | Promise<Response>;
297
+ declare type ExportedHandlerTailHandler<Env = unknown> = (
298
+ events: TraceItem[],
299
+ env: Env,
300
+ ctx: ExecutionContext
301
+ ) => void | Promise<void>;
295
302
  declare type ExportedHandlerTraceHandler<Env = unknown> = (
296
303
  traces: TraceItem[],
297
304
  env: Env,
@@ -318,10 +325,11 @@ declare interface ExportedHandler<
318
325
  CfHostMetadata = unknown
319
326
  > {
320
327
  fetch?: ExportedHandlerFetchHandler<Env, CfHostMetadata>;
328
+ tail?: ExportedHandlerTailHandler<Env>;
321
329
  trace?: ExportedHandlerTraceHandler<Env>;
322
330
  scheduled?: ExportedHandlerScheduledHandler<Env>;
323
331
  test?: ExportedHandlerTestHandler<Env>;
324
- queue?: ExportedHandlerQueueHandler<Env, QueueMessage>;
332
+ queue?: ExportedHandlerQueueHandler<Env, Message>;
325
333
  }
326
334
  declare interface StructuredSerializeOptions {
327
335
  transfer?: any[];
@@ -353,13 +361,24 @@ declare interface DurableObjectNamespace {
353
361
  id: DurableObjectId,
354
362
  options?: DurableObjectNamespaceGetDurableObjectOptions
355
363
  ): DurableObjectStub;
356
- jurisdiction(jurisdiction: string): DurableObjectNamespace;
364
+ jurisdiction(jurisdiction: DurableObjectJurisdiction): DurableObjectNamespace;
357
365
  }
366
+ declare type DurableObjectJurisdiction = "eu" | "fedramp";
358
367
  declare interface DurableObjectNamespaceNewUniqueIdOptions {
359
- jurisdiction?: string;
360
- }
368
+ jurisdiction?: DurableObjectJurisdiction;
369
+ }
370
+ declare type DurableObjectLocationHint =
371
+ | "wnam"
372
+ | "enam"
373
+ | "sam"
374
+ | "weur"
375
+ | "eeur"
376
+ | "apac"
377
+ | "oc"
378
+ | "afr"
379
+ | "me";
361
380
  declare interface DurableObjectNamespaceGetDurableObjectOptions {
362
- locationHint?: string;
381
+ locationHint?: DurableObjectLocationHint;
363
382
  }
364
383
  declare interface DurableObjectState {
365
384
  waitUntil(promise: Promise<any>): void;
@@ -1159,6 +1178,33 @@ declare interface KVNamespaceGetWithMetadataResult<Value, Metadata> {
1159
1178
  value: Value | null;
1160
1179
  metadata: Metadata | null;
1161
1180
  }
1181
+ declare interface Queue<Body> {
1182
+ send(message: Body): Promise<void>;
1183
+ sendBatch(messages: Iterable<MessageSendRequest<Body>>): Promise<void>;
1184
+ }
1185
+ declare interface QueueSendOptions {}
1186
+ declare interface MessageSendRequest<Body = unknown> {
1187
+ body: Body;
1188
+ }
1189
+ declare interface Message<Body = unknown> {
1190
+ readonly id: string;
1191
+ readonly timestamp: Date;
1192
+ readonly body: Body;
1193
+ retry(): void;
1194
+ ack(): void;
1195
+ }
1196
+ declare interface QueueEvent<Body = unknown> extends ExtendableEvent {
1197
+ readonly messages: readonly Message<Body>[];
1198
+ readonly queue: string;
1199
+ retryAll(): void;
1200
+ ackAll(): void;
1201
+ }
1202
+ declare interface MessageBatch<Body = unknown> {
1203
+ readonly messages: readonly Message<Body>[];
1204
+ readonly queue: string;
1205
+ retryAll(): void;
1206
+ ackAll(): void;
1207
+ }
1162
1208
  declare interface R2Error extends Error {
1163
1209
  readonly name: string;
1164
1210
  readonly code: number;
@@ -1309,12 +1355,18 @@ declare interface R2HTTPMetadata {
1309
1355
  cacheControl?: string;
1310
1356
  cacheExpiry?: Date;
1311
1357
  }
1312
- declare interface R2Objects {
1358
+ declare type R2Objects = {
1313
1359
  objects: R2Object[];
1314
- truncated: boolean;
1315
- cursor?: string;
1316
1360
  delimitedPrefixes: string[];
1317
- }
1361
+ } & (
1362
+ | {
1363
+ truncated: true;
1364
+ cursor: string;
1365
+ }
1366
+ | {
1367
+ truncated: false;
1368
+ }
1369
+ );
1318
1370
  declare abstract class ScheduledEvent extends ExtendableEvent {
1319
1371
  readonly scheduledTime: number;
1320
1372
  readonly cron: string;
@@ -1525,13 +1577,19 @@ declare class TransformStream<I = any, O = any> {
1525
1577
  readonly writable: WritableStream<I>;
1526
1578
  }
1527
1579
  declare class FixedLengthStream extends IdentityTransformStream {
1528
- constructor(expectedLength: number | bigint);
1580
+ constructor(
1581
+ expectedLength: number | bigint,
1582
+ queuingStrategy?: IdentityTransformStreamQueuingStrategy
1583
+ );
1529
1584
  }
1530
1585
  declare class IdentityTransformStream extends TransformStream<
1531
1586
  ArrayBuffer | ArrayBufferView,
1532
1587
  Uint8Array
1533
1588
  > {
1534
- constructor();
1589
+ constructor(queuingStrategy?: IdentityTransformStreamQueuingStrategy);
1590
+ }
1591
+ declare interface IdentityTransformStreamQueuingStrategy {
1592
+ highWaterMark?: number | bigint;
1535
1593
  }
1536
1594
  declare interface ReadableStreamValuesOptions {
1537
1595
  preventCancel?: boolean;
@@ -1580,7 +1638,8 @@ declare interface QueuingStrategyInit {
1580
1638
  */
1581
1639
  highWaterMark: number;
1582
1640
  }
1583
- declare abstract class TraceEvent extends ExtendableEvent {
1641
+ declare abstract class TailEvent extends ExtendableEvent {
1642
+ readonly events: TraceItem[];
1584
1643
  readonly traces: TraceItem[];
1585
1644
  }
1586
1645
  declare interface TraceItem {
@@ -2188,8 +2247,7 @@ declare interface IncomingRequestCfPropertiesBase
2188
2247
  declare interface IncomingRequestCfPropertiesBotManagementBase {
2189
2248
  /**
2190
2249
  * Cloudflare’s [level of certainty](https://developers.cloudflare.com/bots/concepts/bot-score/) that a request comes from a bot,
2191
- * represented as an integer percentage between `1` (almost certainly human)
2192
- * and `99` (almost certainly a bot).
2250
+ * represented as an integer percentage between `1` (almost certainly a bot) and `99` (almost certainly human).
2193
2251
  *
2194
2252
  * @example 54
2195
2253
  */
@@ -2791,7 +2849,7 @@ declare abstract class D1PreparedStatement {
2791
2849
  raw<T = unknown>(): Promise<T[]>;
2792
2850
  }
2793
2851
  /**
2794
- * A email message that is sent to a consumer Worker.
2852
+ * An email message that can be sent from a Worker.
2795
2853
  */
2796
2854
  declare interface EmailMessage {
2797
2855
  /**
@@ -2802,14 +2860,19 @@ declare interface EmailMessage {
2802
2860
  * Envelope To attribute of the email message.
2803
2861
  */
2804
2862
  readonly to: string;
2805
- /**
2806
- * A [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers).
2807
- */
2808
- readonly headers: Headers;
2863
+ }
2864
+ /**
2865
+ * An email message that is sent to a consumer Worker and can be rejected/forwarded.
2866
+ */
2867
+ declare interface ForwardableEmailMessage extends EmailMessage {
2809
2868
  /**
2810
2869
  * Stream of the email message content.
2811
2870
  */
2812
2871
  readonly raw: ReadableStream;
2872
+ /**
2873
+ * An [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers).
2874
+ */
2875
+ readonly headers: Headers;
2813
2876
  /**
2814
2877
  * Size of the email message content.
2815
2878
  */
@@ -2828,14 +2891,27 @@ declare interface EmailMessage {
2828
2891
  */
2829
2892
  forward(rcptTo: string, headers?: Headers): Promise<void>;
2830
2893
  }
2894
+ /**
2895
+ * A binding that allows a Worker to send email messages.
2896
+ */
2897
+ declare interface SendEmail {
2898
+ send(message: EmailMessage): Promise<void>;
2899
+ }
2831
2900
  declare abstract class EmailEvent extends ExtendableEvent {
2832
- readonly message: EmailMessage;
2901
+ readonly message: ForwardableEmailMessage;
2833
2902
  }
2834
2903
  declare type EmailExportedHandler<Env = unknown> = (
2835
- message: EmailMessage,
2904
+ message: ForwardableEmailMessage,
2836
2905
  env: Env,
2837
2906
  ctx: ExecutionContext
2838
2907
  ) => void | Promise<void>;
2908
+ declare module "cloudflare:email" {
2909
+ let _EmailMessage: {
2910
+ prototype: EmailMessage;
2911
+ new (from: string, to: string, raw: ReadableStream | string): EmailMessage;
2912
+ };
2913
+ export { _EmailMessage as EmailMessage };
2914
+ }
2839
2915
  declare type Params<P extends string = any> = Record<P, string | string[]>;
2840
2916
  declare type EventContext<Env, P extends string, Data> = {
2841
2917
  request: Request;
@@ -2916,75 +2992,12 @@ declare interface JsonWebKeyWithKid extends JsonWebKey {
2916
2992
  // Key Identifier of the JWK
2917
2993
  readonly kid: string;
2918
2994
  }
2919
- /**
2920
- * A message that is sent to a consumer Worker.
2921
- */
2922
- declare interface Message<Body = unknown> {
2923
- /**
2924
- * A unique, system-generated ID for the message.
2925
- */
2926
- readonly id: string;
2927
- /**
2928
- * A timestamp when the message was sent.
2929
- */
2930
- readonly timestamp: Date;
2931
- /**
2932
- * The body of the message.
2933
- */
2934
- readonly body: Body;
2935
- /**
2936
- * Marks message to be retried.
2937
- */
2938
- retry(): void;
2939
- /**
2940
- * Marks message acknowledged.
2941
- */
2942
- ack(): void;
2943
- }
2944
- /**
2945
- * A batch of messages that are sent to a consumer Worker.
2946
- */
2947
- declare interface MessageBatch<Body = unknown> {
2948
- /**
2949
- * The name of the Queue that belongs to this batch.
2950
- */
2951
- readonly queue: string;
2952
- /**
2953
- * An array of messages in the batch. Ordering of messages is not guaranteed.
2954
- */
2955
- readonly messages: readonly Message<Body>[];
2956
- /**
2957
- * Marks every message to be retried in the next batch.
2958
- */
2959
- retryAll(): void;
2960
- /**
2961
- * Marks every message acknowledged in the batch.
2962
- */
2963
- ackAll(): void;
2964
- }
2965
- /**
2966
- * A wrapper class used to structure message batches.
2967
- */
2968
- declare type MessageSendRequest<Body = unknown> = {
2969
- /**
2970
- * The body of the message.
2971
- */
2972
- body: Body;
2973
- };
2974
- /**
2975
- * A binding that allows a producer to send messages to a Queue.
2976
- */
2977
- declare interface Queue<Body = any> {
2978
- /**
2979
- * Sends a message to the Queue.
2980
- * @param message The message can be any type supported by the [structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm#supported_types), as long as its size is less than 128 KB.
2981
- * @returns A promise that resolves when the message is confirmed to be written to disk.
2982
- */
2983
- send(message: Body): Promise<void>;
2995
+ // https://developers.cloudflare.com/cloudflare-for-platforms/workers-for-platforms/
2996
+ declare interface DispatchNamespace {
2984
2997
  /**
2985
- * Sends a batch of messages to the Queue.
2986
- * @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.
2987
- * @returns A promise that resolves when the messages are confirmed to be written to disk.
2998
+ * @param name Name of the Worker script.
2999
+ * @returns A Fetcher object that allows you to send requests to the Worker script.
3000
+ * @throws If the Worker script does not exist in this dispatch namespace, an error will be thrown.
2988
3001
  */
2989
- sendBatch(messages: Iterable<MessageSendRequest<Body>>): Promise<void>;
3002
+ get(name: string): Fetcher;
2990
3003
  }
@@ -49,6 +49,7 @@ export declare class DOMException extends Error {
49
49
  export type WorkerGlobalScopeEventMap = {
50
50
  fetch: FetchEvent;
51
51
  scheduled: ScheduledEvent;
52
+ queue: QueueEvent;
52
53
  unhandledrejection: PromiseRejectionEvent;
53
54
  rejectionhandled: PromiseRejectionEvent;
54
55
  };
@@ -187,7 +188,8 @@ export interface ServiceWorkerGlobalScope extends WorkerGlobalScope {
187
188
  ExtendableEvent: typeof ExtendableEvent;
188
189
  PromiseRejectionEvent: typeof PromiseRejectionEvent;
189
190
  FetchEvent: typeof FetchEvent;
190
- TraceEvent: typeof TraceEvent;
191
+ TailEvent: typeof TailEvent;
192
+ TraceEvent: typeof TailEvent;
191
193
  ScheduledEvent: typeof ScheduledEvent;
192
194
  MessageEvent: typeof MessageEvent;
193
195
  CloseEvent: typeof CloseEvent;
@@ -294,6 +296,11 @@ export type ExportedHandlerFetchHandler<
294
296
  env: Env,
295
297
  ctx: ExecutionContext
296
298
  ) => Response | Promise<Response>;
299
+ export type ExportedHandlerTailHandler<Env = unknown> = (
300
+ events: TraceItem[],
301
+ env: Env,
302
+ ctx: ExecutionContext
303
+ ) => void | Promise<void>;
297
304
  export type ExportedHandlerTraceHandler<Env = unknown> = (
298
305
  traces: TraceItem[],
299
306
  env: Env,
@@ -320,10 +327,11 @@ export interface ExportedHandler<
320
327
  CfHostMetadata = unknown
321
328
  > {
322
329
  fetch?: ExportedHandlerFetchHandler<Env, CfHostMetadata>;
330
+ tail?: ExportedHandlerTailHandler<Env>;
323
331
  trace?: ExportedHandlerTraceHandler<Env>;
324
332
  scheduled?: ExportedHandlerScheduledHandler<Env>;
325
333
  test?: ExportedHandlerTestHandler<Env>;
326
- queue?: ExportedHandlerQueueHandler<Env, QueueMessage>;
334
+ queue?: ExportedHandlerQueueHandler<Env, Message>;
327
335
  }
328
336
  export interface StructuredSerializeOptions {
329
337
  transfer?: any[];
@@ -355,13 +363,24 @@ export interface DurableObjectNamespace {
355
363
  id: DurableObjectId,
356
364
  options?: DurableObjectNamespaceGetDurableObjectOptions
357
365
  ): DurableObjectStub;
358
- jurisdiction(jurisdiction: string): DurableObjectNamespace;
366
+ jurisdiction(jurisdiction: DurableObjectJurisdiction): DurableObjectNamespace;
359
367
  }
368
+ export type DurableObjectJurisdiction = "eu" | "fedramp";
360
369
  export interface DurableObjectNamespaceNewUniqueIdOptions {
361
- jurisdiction?: string;
362
- }
370
+ jurisdiction?: DurableObjectJurisdiction;
371
+ }
372
+ export type DurableObjectLocationHint =
373
+ | "wnam"
374
+ | "enam"
375
+ | "sam"
376
+ | "weur"
377
+ | "eeur"
378
+ | "apac"
379
+ | "oc"
380
+ | "afr"
381
+ | "me";
363
382
  export interface DurableObjectNamespaceGetDurableObjectOptions {
364
- locationHint?: string;
383
+ locationHint?: DurableObjectLocationHint;
365
384
  }
366
385
  export interface DurableObjectState {
367
386
  waitUntil(promise: Promise<any>): void;
@@ -1161,6 +1180,33 @@ export interface KVNamespaceGetWithMetadataResult<Value, Metadata> {
1161
1180
  value: Value | null;
1162
1181
  metadata: Metadata | null;
1163
1182
  }
1183
+ export interface Queue<Body> {
1184
+ send(message: Body): Promise<void>;
1185
+ sendBatch(messages: Iterable<MessageSendRequest<Body>>): Promise<void>;
1186
+ }
1187
+ export interface QueueSendOptions {}
1188
+ export interface MessageSendRequest<Body = unknown> {
1189
+ body: Body;
1190
+ }
1191
+ export interface Message<Body = unknown> {
1192
+ readonly id: string;
1193
+ readonly timestamp: Date;
1194
+ readonly body: Body;
1195
+ retry(): void;
1196
+ ack(): void;
1197
+ }
1198
+ export interface QueueEvent<Body = unknown> extends ExtendableEvent {
1199
+ readonly messages: readonly Message<Body>[];
1200
+ readonly queue: string;
1201
+ retryAll(): void;
1202
+ ackAll(): void;
1203
+ }
1204
+ export interface MessageBatch<Body = unknown> {
1205
+ readonly messages: readonly Message<Body>[];
1206
+ readonly queue: string;
1207
+ retryAll(): void;
1208
+ ackAll(): void;
1209
+ }
1164
1210
  export interface R2Error extends Error {
1165
1211
  readonly name: string;
1166
1212
  readonly code: number;
@@ -1311,12 +1357,18 @@ export interface R2HTTPMetadata {
1311
1357
  cacheControl?: string;
1312
1358
  cacheExpiry?: Date;
1313
1359
  }
1314
- export interface R2Objects {
1360
+ export type R2Objects = {
1315
1361
  objects: R2Object[];
1316
- truncated: boolean;
1317
- cursor?: string;
1318
1362
  delimitedPrefixes: string[];
1319
- }
1363
+ } & (
1364
+ | {
1365
+ truncated: true;
1366
+ cursor: string;
1367
+ }
1368
+ | {
1369
+ truncated: false;
1370
+ }
1371
+ );
1320
1372
  export declare abstract class ScheduledEvent extends ExtendableEvent {
1321
1373
  readonly scheduledTime: number;
1322
1374
  readonly cron: string;
@@ -1527,13 +1579,19 @@ export declare class TransformStream<I = any, O = any> {
1527
1579
  readonly writable: WritableStream<I>;
1528
1580
  }
1529
1581
  export declare class FixedLengthStream extends IdentityTransformStream {
1530
- constructor(expectedLength: number | bigint);
1582
+ constructor(
1583
+ expectedLength: number | bigint,
1584
+ queuingStrategy?: IdentityTransformStreamQueuingStrategy
1585
+ );
1531
1586
  }
1532
1587
  export declare class IdentityTransformStream extends TransformStream<
1533
1588
  ArrayBuffer | ArrayBufferView,
1534
1589
  Uint8Array
1535
1590
  > {
1536
- constructor();
1591
+ constructor(queuingStrategy?: IdentityTransformStreamQueuingStrategy);
1592
+ }
1593
+ export interface IdentityTransformStreamQueuingStrategy {
1594
+ highWaterMark?: number | bigint;
1537
1595
  }
1538
1596
  export interface ReadableStreamValuesOptions {
1539
1597
  preventCancel?: boolean;
@@ -1585,7 +1643,8 @@ export interface QueuingStrategyInit {
1585
1643
  */
1586
1644
  highWaterMark: number;
1587
1645
  }
1588
- export declare abstract class TraceEvent extends ExtendableEvent {
1646
+ export declare abstract class TailEvent extends ExtendableEvent {
1647
+ readonly events: TraceItem[];
1589
1648
  readonly traces: TraceItem[];
1590
1649
  }
1591
1650
  export interface TraceItem {
@@ -2193,8 +2252,7 @@ export interface IncomingRequestCfPropertiesBase
2193
2252
  export interface IncomingRequestCfPropertiesBotManagementBase {
2194
2253
  /**
2195
2254
  * Cloudflare’s [level of certainty](https://developers.cloudflare.com/bots/concepts/bot-score/) that a request comes from a bot,
2196
- * represented as an integer percentage between `1` (almost certainly human)
2197
- * and `99` (almost certainly a bot).
2255
+ * represented as an integer percentage between `1` (almost certainly a bot) and `99` (almost certainly human).
2198
2256
  *
2199
2257
  * @example 54
2200
2258
  */
@@ -2796,7 +2854,7 @@ export declare abstract class D1PreparedStatement {
2796
2854
  raw<T = unknown>(): Promise<T[]>;
2797
2855
  }
2798
2856
  /**
2799
- * A email message that is sent to a consumer Worker.
2857
+ * An email message that can be sent from a Worker.
2800
2858
  */
2801
2859
  export interface EmailMessage {
2802
2860
  /**
@@ -2807,14 +2865,19 @@ export interface EmailMessage {
2807
2865
  * Envelope To attribute of the email message.
2808
2866
  */
2809
2867
  readonly to: string;
2810
- /**
2811
- * A [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers).
2812
- */
2813
- readonly headers: Headers;
2868
+ }
2869
+ /**
2870
+ * An email message that is sent to a consumer Worker and can be rejected/forwarded.
2871
+ */
2872
+ export interface ForwardableEmailMessage extends EmailMessage {
2814
2873
  /**
2815
2874
  * Stream of the email message content.
2816
2875
  */
2817
2876
  readonly raw: ReadableStream;
2877
+ /**
2878
+ * An [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers).
2879
+ */
2880
+ readonly headers: Headers;
2818
2881
  /**
2819
2882
  * Size of the email message content.
2820
2883
  */
@@ -2833,11 +2896,17 @@ export interface EmailMessage {
2833
2896
  */
2834
2897
  forward(rcptTo: string, headers?: Headers): Promise<void>;
2835
2898
  }
2899
+ /**
2900
+ * A binding that allows a Worker to send email messages.
2901
+ */
2902
+ export interface SendEmail {
2903
+ send(message: EmailMessage): Promise<void>;
2904
+ }
2836
2905
  export declare abstract class EmailEvent extends ExtendableEvent {
2837
- readonly message: EmailMessage;
2906
+ readonly message: ForwardableEmailMessage;
2838
2907
  }
2839
2908
  export type EmailExportedHandler<Env = unknown> = (
2840
- message: EmailMessage,
2909
+ message: ForwardableEmailMessage,
2841
2910
  env: Env,
2842
2911
  ctx: ExecutionContext
2843
2912
  ) => void | Promise<void>;
@@ -2918,75 +2987,12 @@ export interface JsonWebKeyWithKid extends JsonWebKey {
2918
2987
  // Key Identifier of the JWK
2919
2988
  readonly kid: string;
2920
2989
  }
2921
- /**
2922
- * A message that is sent to a consumer Worker.
2923
- */
2924
- export interface Message<Body = unknown> {
2990
+ // https://developers.cloudflare.com/cloudflare-for-platforms/workers-for-platforms/
2991
+ export interface DispatchNamespace {
2925
2992
  /**
2926
- * A unique, system-generated ID for the message.
2993
+ * @param name Name of the Worker script.
2994
+ * @returns A Fetcher object that allows you to send requests to the Worker script.
2995
+ * @throws If the Worker script does not exist in this dispatch namespace, an error will be thrown.
2927
2996
  */
2928
- readonly id: string;
2929
- /**
2930
- * A timestamp when the message was sent.
2931
- */
2932
- readonly timestamp: Date;
2933
- /**
2934
- * The body of the message.
2935
- */
2936
- readonly body: Body;
2937
- /**
2938
- * Marks message to be retried.
2939
- */
2940
- retry(): void;
2941
- /**
2942
- * Marks message acknowledged.
2943
- */
2944
- ack(): void;
2945
- }
2946
- /**
2947
- * A batch of messages that are sent to a consumer Worker.
2948
- */
2949
- export interface MessageBatch<Body = unknown> {
2950
- /**
2951
- * The name of the Queue that belongs to this batch.
2952
- */
2953
- readonly queue: string;
2954
- /**
2955
- * An array of messages in the batch. Ordering of messages is not guaranteed.
2956
- */
2957
- readonly messages: readonly Message<Body>[];
2958
- /**
2959
- * Marks every message to be retried in the next batch.
2960
- */
2961
- retryAll(): void;
2962
- /**
2963
- * Marks every message acknowledged in the batch.
2964
- */
2965
- ackAll(): void;
2966
- }
2967
- /**
2968
- * A wrapper class used to structure message batches.
2969
- */
2970
- export type MessageSendRequest<Body = unknown> = {
2971
- /**
2972
- * The body of the message.
2973
- */
2974
- body: Body;
2975
- };
2976
- /**
2977
- * A binding that allows a producer to send messages to a Queue.
2978
- */
2979
- export interface Queue<Body = any> {
2980
- /**
2981
- * Sends a message to the Queue.
2982
- * @param message The message can be any type supported by the [structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm#supported_types), as long as its size is less than 128 KB.
2983
- * @returns A promise that resolves when the message is confirmed to be written to disk.
2984
- */
2985
- send(message: Body): Promise<void>;
2986
- /**
2987
- * Sends a batch of messages to the Queue.
2988
- * @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.
2989
- * @returns A promise that resolves when the messages are confirmed to be written to disk.
2990
- */
2991
- sendBatch(messages: Iterable<MessageSendRequest<Body>>): Promise<void>;
2997
+ get(name: string): Fetcher;
2992
2998
  }