@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.
package/oldest/index.ts CHANGED
@@ -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
  }
package/package.json CHANGED
@@ -7,5 +7,5 @@
7
7
  },
8
8
  "author": "Cloudflare Workers DevProd Team <workers-devprod@cloudflare.com> (https://workers.cloudflare.com)",
9
9
  "license": "MIT OR Apache-2.0",
10
- "version": "4.20230321.0"
10
+ "version": "4.20230419.0"
11
11
  }