@cloudflare/workers-types 0.20230215.0 → 0.20230404.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 @@ 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
  };
@@ -288,12 +289,16 @@ export declare const crypto: Crypto;
288
289
  export declare const caches: CacheStorage;
289
290
  export declare const scheduler: Scheduler;
290
291
  export declare const navigator: Navigator;
292
+ export interface TestController {}
291
293
  export interface ExecutionContext {
292
294
  waitUntil(promise: Promise<any>): void;
293
295
  passThroughOnException(): void;
294
296
  }
295
- export type ExportedHandlerFetchHandler<Env = unknown> = (
296
- request: Request,
297
+ export type ExportedHandlerFetchHandler<
298
+ Env = unknown,
299
+ CfHostMetadata = unknown
300
+ > = (
301
+ request: Request<CfHostMetadata, IncomingRequestCfProperties<CfHostMetadata>>,
297
302
  env: Env,
298
303
  ctx: ExecutionContext
299
304
  ) => Response | Promise<Response>;
@@ -312,11 +317,21 @@ export type ExportedHandlerQueueHandler<Env = unknown, Message = unknown> = (
312
317
  env: Env,
313
318
  ctx: ExecutionContext
314
319
  ) => void | Promise<void>;
315
- export interface ExportedHandler<Env = unknown, QueueMessage = unknown> {
316
- fetch?: ExportedHandlerFetchHandler<Env>;
320
+ export type ExportedHandlerTestHandler<Env = unknown> = (
321
+ controller: TestController,
322
+ env: Env,
323
+ ctx: ExecutionContext
324
+ ) => void | Promise<void>;
325
+ export interface ExportedHandler<
326
+ Env = unknown,
327
+ QueueMessage = unknown,
328
+ CfHostMetadata = unknown
329
+ > {
330
+ fetch?: ExportedHandlerFetchHandler<Env, CfHostMetadata>;
317
331
  trace?: ExportedHandlerTraceHandler<Env>;
318
332
  scheduled?: ExportedHandlerScheduledHandler<Env>;
319
- queue?: ExportedHandlerQueueHandler<Env, QueueMessage>;
333
+ test?: ExportedHandlerTestHandler<Env>;
334
+ queue?: ExportedHandlerQueueHandler<Env, Message>;
320
335
  }
321
336
  export interface StructuredSerializeOptions {
322
337
  transfer?: any[];
@@ -351,13 +366,24 @@ export interface DurableObjectNamespace {
351
366
  id: DurableObjectId,
352
367
  options?: DurableObjectNamespaceGetDurableObjectOptions
353
368
  ): DurableObjectStub;
354
- jurisdiction(jurisdiction: string): DurableObjectNamespace;
369
+ jurisdiction(jurisdiction: DurableObjectJurisdiction): DurableObjectNamespace;
355
370
  }
371
+ export type DurableObjectJurisdiction = "eu" | "fedramp";
356
372
  export interface DurableObjectNamespaceNewUniqueIdOptions {
357
- jurisdiction?: string;
358
- }
373
+ jurisdiction?: DurableObjectJurisdiction;
374
+ }
375
+ export type DurableObjectLocationHint =
376
+ | "wnam"
377
+ | "enam"
378
+ | "sam"
379
+ | "weur"
380
+ | "eeur"
381
+ | "apac"
382
+ | "oc"
383
+ | "afr"
384
+ | "me";
359
385
  export interface DurableObjectNamespaceGetDurableObjectOptions {
360
- locationHint?: string;
386
+ locationHint?: DurableObjectLocationHint;
361
387
  }
362
388
  export interface DurableObjectState {
363
389
  waitUntil(promise: Promise<any>): void;
@@ -987,23 +1013,27 @@ export interface ResponseInit {
987
1013
  webSocket?: WebSocket | null;
988
1014
  encodeBody?: "automatic" | "manual";
989
1015
  }
990
- export type RequestInfo = Request | string | URL;
991
- export declare class Request<CfHostMetadata = unknown> extends Body {
992
- constructor(input: RequestInfo, init?: RequestInit);
993
- clone(): Request<CfHostMetadata>;
1016
+ export type RequestInfo<
1017
+ CfHostMetadata = unknown,
1018
+ Cf = CfProperties<CfHostMetadata>
1019
+ > = Request<CfHostMetadata, Cf> | string | URL;
1020
+ export declare class Request<
1021
+ CfHostMetadata = unknown,
1022
+ Cf = CfProperties<CfHostMetadata>
1023
+ > extends Body {
1024
+ constructor(input: RequestInfo<CfProperties>, init?: RequestInit<Cf>);
1025
+ clone(): Request<CfHostMetadata, Cf>;
994
1026
  get method(): string;
995
1027
  get url(): string;
996
1028
  get headers(): Headers;
997
1029
  get redirect(): string;
998
1030
  get fetcher(): Fetcher | null;
999
1031
  get signal(): AbortSignal;
1000
- get cf(): IncomingRequestCfProperties<CfHostMetadata> | undefined;
1032
+ get cf(): Cf | undefined;
1001
1033
  get integrity(): string;
1002
1034
  get keepalive(): boolean;
1003
1035
  }
1004
- export interface RequestInit<
1005
- CfType = IncomingRequestCfProperties | RequestInitCfProperties
1006
- > {
1036
+ export interface RequestInit<Cf = CfProperties> {
1007
1037
  /** A string to set request's method. */
1008
1038
  method?: string;
1009
1039
  /** A Headers object, an object literal, or an array of two-item arrays to set request's headers. */
@@ -1013,17 +1043,14 @@ export interface RequestInit<
1013
1043
  /** A string indicating whether request follows redirects, results in an error upon encountering a redirect, or returns the redirect (in an opaque fashion). Sets request's redirect. */
1014
1044
  redirect?: string;
1015
1045
  fetcher?: Fetcher | null;
1016
- cf?: CfType;
1046
+ cf?: Cf;
1017
1047
  /** A cryptographic hash of the resource to be fetched by request. Sets request's integrity. */
1018
1048
  integrity?: string;
1019
1049
  /** An AbortSignal to set request's signal. */
1020
1050
  signal?: AbortSignal | null;
1021
1051
  }
1022
1052
  export declare abstract class Fetcher {
1023
- fetch(
1024
- input: RequestInfo,
1025
- init?: RequestInit<RequestInitCfProperties>
1026
- ): Promise<Response>;
1053
+ fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
1027
1054
  }
1028
1055
  export interface FetcherPutOptions {
1029
1056
  expiration?: number;
@@ -1136,6 +1163,33 @@ export interface KVNamespaceGetWithMetadataResult<Value, Metadata> {
1136
1163
  value: Value | null;
1137
1164
  metadata: Metadata | null;
1138
1165
  }
1166
+ export interface Queue<Body> {
1167
+ send(message: Body): Promise<void>;
1168
+ sendBatch(messages: Iterable<MessageSendRequest<Body>>): Promise<void>;
1169
+ }
1170
+ export interface QueueSendOptions {}
1171
+ export interface MessageSendRequest<Body = unknown> {
1172
+ body: Body;
1173
+ }
1174
+ export interface Message<Body = unknown> {
1175
+ readonly id: string;
1176
+ readonly timestamp: Date;
1177
+ readonly body: Body;
1178
+ retry(): void;
1179
+ ack(): void;
1180
+ }
1181
+ export interface QueueEvent<Body = unknown> extends ExtendableEvent {
1182
+ readonly messages: readonly Message<Body>[];
1183
+ readonly queue: string;
1184
+ retryAll(): void;
1185
+ ackAll(): void;
1186
+ }
1187
+ export interface MessageBatch<Body = unknown> {
1188
+ readonly messages: readonly Message<Body>[];
1189
+ readonly queue: string;
1190
+ retryAll(): void;
1191
+ ackAll(): void;
1192
+ }
1139
1193
  export interface R2Error extends Error {
1140
1194
  readonly name: string;
1141
1195
  readonly code: number;
@@ -1287,12 +1341,18 @@ export interface R2HTTPMetadata {
1287
1341
  cacheControl?: string;
1288
1342
  cacheExpiry?: Date;
1289
1343
  }
1290
- export interface R2Objects {
1344
+ export type R2Objects = {
1291
1345
  objects: R2Object[];
1292
- truncated: boolean;
1293
- cursor?: string;
1294
1346
  delimitedPrefixes: string[];
1295
- }
1347
+ } & (
1348
+ | {
1349
+ truncated: true;
1350
+ cursor: string;
1351
+ }
1352
+ | {
1353
+ truncated: false;
1354
+ }
1355
+ );
1296
1356
  export declare abstract class ScheduledEvent extends ExtendableEvent {
1297
1357
  readonly scheduledTime: number;
1298
1358
  readonly cron: string;
@@ -1502,13 +1562,19 @@ export declare class TransformStream<I = any, O = any> {
1502
1562
  get writable(): WritableStream<I>;
1503
1563
  }
1504
1564
  export declare class FixedLengthStream extends IdentityTransformStream {
1505
- constructor(expectedLength: number | bigint);
1565
+ constructor(
1566
+ expectedLength: number | bigint,
1567
+ queuingStrategy?: IdentityTransformStreamQueuingStrategy
1568
+ );
1506
1569
  }
1507
1570
  export declare class IdentityTransformStream extends TransformStream<
1508
1571
  ArrayBuffer | ArrayBufferView,
1509
1572
  Uint8Array
1510
1573
  > {
1511
- constructor();
1574
+ constructor(queuingStrategy?: IdentityTransformStreamQueuingStrategy);
1575
+ }
1576
+ export interface IdentityTransformStreamQueuingStrategy {
1577
+ highWaterMark?: number | bigint;
1512
1578
  }
1513
1579
  export interface ReadableStreamValuesOptions {
1514
1580
  preventCancel?: boolean;
@@ -1517,13 +1583,13 @@ export declare class CompressionStream extends TransformStream<
1517
1583
  ArrayBuffer | ArrayBufferView,
1518
1584
  Uint8Array
1519
1585
  > {
1520
- constructor(format: "gzip" | "deflate");
1586
+ constructor(format: "gzip" | "deflate" | "deflate-raw");
1521
1587
  }
1522
1588
  export declare class DecompressionStream extends TransformStream<
1523
1589
  ArrayBuffer | ArrayBufferView,
1524
1590
  Uint8Array
1525
1591
  > {
1526
- constructor(format: "gzip" | "deflate");
1592
+ constructor(format: "gzip" | "deflate" | "deflate-raw");
1527
1593
  }
1528
1594
  export declare class TextEncoderStream extends TransformStream<
1529
1595
  string,
@@ -1656,11 +1722,13 @@ export declare class URL {
1656
1722
  get searchParams(): URLSearchParams;
1657
1723
  toJSON(): string;
1658
1724
  toString(): string;
1725
+ static canParse(url: string, base?: string): boolean;
1659
1726
  }
1660
1727
  export declare class URLSearchParams {
1661
1728
  constructor(
1662
1729
  init?: Iterable<Iterable<string>> | Record<string, string> | string
1663
1730
  );
1731
+ get size(): number;
1664
1732
  append(name: string, value: string): void;
1665
1733
  delete(name: string): void;
1666
1734
  get(name: string): string | null;
@@ -1859,7 +1927,7 @@ export interface BasicImageTransformationsGravityCoordinates {
1859
1927
  * Note: Currently, these properties cannot be tested in the
1860
1928
  * playground.
1861
1929
  */
1862
- export interface RequestInitCfProperties {
1930
+ export interface RequestInitCfProperties extends Record<string, unknown> {
1863
1931
  cacheEverything?: boolean;
1864
1932
  /**
1865
1933
  * A request's cache key is what determines if two requests are
@@ -2029,6 +2097,49 @@ export interface RequestInitCfPropertiesImage
2029
2097
  * the origin.
2030
2098
  */
2031
2099
  "origin-auth"?: "share-publicly";
2100
+ /**
2101
+ * Adds a border around the image. The border is added after resizing. Border
2102
+ * width takes dpr into account, and can be specified either using a single
2103
+ * width property, or individually for each side.
2104
+ */
2105
+ border?:
2106
+ | {
2107
+ color: string;
2108
+ width: number;
2109
+ }
2110
+ | {
2111
+ color: string;
2112
+ top: number;
2113
+ right: number;
2114
+ bottom: number;
2115
+ left: number;
2116
+ };
2117
+ /**
2118
+ * Increase brightness by a factor. A value of 1.0 equals no change, a value
2119
+ * of 0.5 equals half brightness, and a value of 2.0 equals twice as bright.
2120
+ * 0 is ignored.
2121
+ */
2122
+ brightness?: number;
2123
+ /**
2124
+ * Increase contrast by a factor. A value of 1.0 equals no change, a value of
2125
+ * 0.5 equals low contrast, and a value of 2.0 equals high contrast. 0 is
2126
+ * ignored.
2127
+ */
2128
+ contrast?: number;
2129
+ /**
2130
+ * Increase exposure by a factor. A value of 1.0 equals no change, a value of
2131
+ * 0.5 darkens the image, and a value of 2.0 lightens the image. 0 is ignored.
2132
+ */
2133
+ gamma?: number;
2134
+ /**
2135
+ * Slightly reduces latency on a cache miss by selecting a
2136
+ * quickest-to-compress file format, at a cost of increased file size and
2137
+ * lower image quality. It will usually override the format option and choose
2138
+ * JPEG over WebP or AVIF. We do not recommend using this option, except in
2139
+ * unusual circumstances like resizing uncacheable dynamically-generated
2140
+ * images.
2141
+ */
2142
+ compression?: "fast";
2032
2143
  }
2033
2144
  export interface RequestInitCfPropertiesImageMinify {
2034
2145
  javascript?: boolean;
@@ -2044,7 +2155,8 @@ export type IncomingRequestCfProperties<HostMetadata = unknown> =
2044
2155
  IncomingRequestCfPropertiesCloudflareForSaaSEnterprise<HostMetadata> &
2045
2156
  IncomingRequestCfPropertiesGeographicInformation &
2046
2157
  IncomingRequestCfPropertiesCloudflareAccessOrApiShield;
2047
- export interface IncomingRequestCfPropertiesBase {
2158
+ export interface IncomingRequestCfPropertiesBase
2159
+ extends Record<string, unknown> {
2048
2160
  /**
2049
2161
  * [ASN](https://www.iana.org/assignments/as-numbers/as-numbers.xhtml) of the incoming request.
2050
2162
  *
@@ -2125,8 +2237,7 @@ export interface IncomingRequestCfPropertiesBase {
2125
2237
  export interface IncomingRequestCfPropertiesBotManagementBase {
2126
2238
  /**
2127
2239
  * Cloudflare’s [level of certainty](https://developers.cloudflare.com/bots/concepts/bot-score/) that a request comes from a bot,
2128
- * represented as an integer percentage between `1` (almost certainly human)
2129
- * and `99` (almost certainly a bot).
2240
+ * represented as an integer percentage between `1` (almost certainly a bot) and `99` (almost certainly human).
2130
2241
  *
2131
2242
  * @example 54
2132
2243
  */
@@ -2145,6 +2256,10 @@ export interface IncomingRequestCfPropertiesBotManagementBase {
2145
2256
  * A boolean value that's true if the request matches [file extensions](https://developers.cloudflare.com/bots/reference/static-resources/) for many types of static resources.
2146
2257
  */
2147
2258
  staticResource: boolean;
2259
+ /**
2260
+ * List of IDs that correlate to the Bot Management heuristic detections made on a request (you can have multiple heuristic detections on the same request).
2261
+ */
2262
+ detectionIds: number[];
2148
2263
  }
2149
2264
  export interface IncomingRequestCfPropertiesBotManagement {
2150
2265
  /**
@@ -2233,86 +2348,82 @@ export interface IncomingRequestCfPropertiesExportedAuthenticatorMetadata {
2233
2348
  /**
2234
2349
  * Geographic data about the request's origin.
2235
2350
  */
2236
- export type IncomingRequestCfPropertiesGeographicInformation =
2237
- | {}
2238
- | {
2239
- /** The country code `"T1"` is used for requests originating on TOR */
2240
- country: "T1";
2241
- }
2242
- | {
2243
- /**
2244
- * The [ISO 3166-1 Alpha 2](https://www.iso.org/iso-3166-country-codes.html) country code the request originated from.
2245
- *
2246
- * If your worker is [configured to accept TOR connections](https://support.cloudflare.com/hc/en-us/articles/203306930-Understanding-Cloudflare-Tor-support-and-Onion-Routing), this may also be `"T1"`, indicating a request that originated over TOR.
2247
- *
2248
- * If Cloudflare is unable to determine where the request originated this property is omitted.
2249
- *
2250
- * @example "GB"
2251
- */
2252
- country: Iso3166Alpha2Code;
2253
- /**
2254
- * If present, this property indicates that the request originated in the EU
2255
- *
2256
- * @example "1"
2257
- */
2258
- isEUCountry?: "1";
2259
- /**
2260
- * A two-letter code indicating the continent the request originated from.
2261
- *
2262
- * @example "AN"
2263
- */
2264
- continent: ContinentCode;
2265
- /**
2266
- * The city the request originated from
2267
- *
2268
- * @example "Austin"
2269
- */
2270
- city?: string;
2271
- /**
2272
- * Postal code of the incoming request
2273
- *
2274
- * @example "78701"
2275
- */
2276
- postalCode?: string;
2277
- /**
2278
- * Latitude of the incoming request
2279
- *
2280
- * @example "30.27130"
2281
- */
2282
- latitude?: string;
2283
- /**
2284
- * Longitude of the incoming request
2285
- *
2286
- * @example "-97.74260"
2287
- */
2288
- longitude?: string;
2289
- /**
2290
- * Timezone of the incoming request
2291
- *
2292
- * @example "America/Chicago"
2293
- */
2294
- timezone?: string;
2295
- /**
2296
- * If known, the ISO 3166-2 name for the first level region associated with
2297
- * the IP address of the incoming request
2298
- *
2299
- * @example "Texas"
2300
- */
2301
- region?: string;
2302
- /**
2303
- * If known, the ISO 3166-2 code for the first-level region associated with
2304
- * the IP address of the incoming request
2305
- *
2306
- * @example "TX"
2307
- */
2308
- regionCode?: string;
2309
- /**
2310
- * Metro code (DMA) of the incoming request
2311
- *
2312
- * @example "635"
2313
- */
2314
- metroCode?: string;
2315
- };
2351
+ export interface IncomingRequestCfPropertiesGeographicInformation {
2352
+ /**
2353
+ * The [ISO 3166-1 Alpha 2](https://www.iso.org/iso-3166-country-codes.html) country code the request originated from.
2354
+ *
2355
+ * If your worker is [configured to accept TOR connections](https://support.cloudflare.com/hc/en-us/articles/203306930-Understanding-Cloudflare-Tor-support-and-Onion-Routing), this may also be `"T1"`, indicating a request that originated over TOR.
2356
+ *
2357
+ * If Cloudflare is unable to determine where the request originated this property is omitted.
2358
+ *
2359
+ * The country code `"T1"` is used for requests originating on TOR.
2360
+ *
2361
+ * @example "GB"
2362
+ */
2363
+ country?: Iso3166Alpha2Code | "T1";
2364
+ /**
2365
+ * If present, this property indicates that the request originated in the EU
2366
+ *
2367
+ * @example "1"
2368
+ */
2369
+ isEUCountry?: "1";
2370
+ /**
2371
+ * A two-letter code indicating the continent the request originated from.
2372
+ *
2373
+ * @example "AN"
2374
+ */
2375
+ continent?: ContinentCode;
2376
+ /**
2377
+ * The city the request originated from
2378
+ *
2379
+ * @example "Austin"
2380
+ */
2381
+ city?: string;
2382
+ /**
2383
+ * Postal code of the incoming request
2384
+ *
2385
+ * @example "78701"
2386
+ */
2387
+ postalCode?: string;
2388
+ /**
2389
+ * Latitude of the incoming request
2390
+ *
2391
+ * @example "30.27130"
2392
+ */
2393
+ latitude?: string;
2394
+ /**
2395
+ * Longitude of the incoming request
2396
+ *
2397
+ * @example "-97.74260"
2398
+ */
2399
+ longitude?: string;
2400
+ /**
2401
+ * Timezone of the incoming request
2402
+ *
2403
+ * @example "America/Chicago"
2404
+ */
2405
+ timezone?: string;
2406
+ /**
2407
+ * If known, the ISO 3166-2 name for the first level region associated with
2408
+ * the IP address of the incoming request
2409
+ *
2410
+ * @example "Texas"
2411
+ */
2412
+ region?: string;
2413
+ /**
2414
+ * If known, the ISO 3166-2 code for the first-level region associated with
2415
+ * the IP address of the incoming request
2416
+ *
2417
+ * @example "TX"
2418
+ */
2419
+ regionCode?: string;
2420
+ /**
2421
+ * Metro code (DMA) of the incoming request
2422
+ *
2423
+ * @example "635"
2424
+ */
2425
+ metroCode?: string;
2426
+ }
2316
2427
  /** Data about the incoming request's TLS certificate */
2317
2428
  export interface IncomingRequestCfPropertiesTLSClientAuth {
2318
2429
  /** Always `"1"`, indicating that the certificate was presented */
@@ -2705,6 +2816,9 @@ export type Iso3166Alpha2Code =
2705
2816
  | "ZW";
2706
2817
  /** The 2-letter continent codes Cloudflare uses */
2707
2818
  export type ContinentCode = "AF" | "AN" | "AS" | "EU" | "NA" | "OC" | "SA";
2819
+ export type CfProperties<HostMetadata = unknown> =
2820
+ | IncomingRequestCfProperties<HostMetadata>
2821
+ | RequestInitCfProperties;
2708
2822
  export interface D1Result<T = unknown> {
2709
2823
  results?: T[];
2710
2824
  success: boolean;
@@ -2725,9 +2839,9 @@ export declare abstract class D1PreparedStatement {
2725
2839
  raw<T = unknown>(): Promise<T[]>;
2726
2840
  }
2727
2841
  /**
2728
- * A email message that is sent to a consumer Worker.
2842
+ * An email message that can be sent from a Worker.
2729
2843
  */
2730
- export interface EmailMessage<Body = unknown> {
2844
+ export interface EmailMessage {
2731
2845
  /**
2732
2846
  * Envelope From attribute of the email message.
2733
2847
  */
@@ -2736,14 +2850,19 @@ export interface EmailMessage<Body = unknown> {
2736
2850
  * Envelope To attribute of the email message.
2737
2851
  */
2738
2852
  readonly to: string;
2739
- /**
2740
- * A [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers).
2741
- */
2742
- readonly headers: Headers;
2853
+ }
2854
+ /**
2855
+ * An email message that is sent to a consumer Worker and can be rejected/forwarded.
2856
+ */
2857
+ export interface ForwardableEmailMessage extends EmailMessage {
2743
2858
  /**
2744
2859
  * Stream of the email message content.
2745
2860
  */
2746
2861
  readonly raw: ReadableStream;
2862
+ /**
2863
+ * An [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers).
2864
+ */
2865
+ readonly headers: Headers;
2747
2866
  /**
2748
2867
  * Size of the email message content.
2749
2868
  */
@@ -2762,11 +2881,17 @@ export interface EmailMessage<Body = unknown> {
2762
2881
  */
2763
2882
  forward(rcptTo: string, headers?: Headers): Promise<void>;
2764
2883
  }
2884
+ /**
2885
+ * A binding that allows a Worker to send email messages.
2886
+ */
2887
+ export interface SendEmail {
2888
+ send(message: EmailMessage): Promise<void>;
2889
+ }
2765
2890
  export declare abstract class EmailEvent extends ExtendableEvent {
2766
- readonly message: EmailMessage;
2891
+ readonly message: ForwardableEmailMessage;
2767
2892
  }
2768
2893
  export type EmailExportedHandler<Env = unknown> = (
2769
- message: EmailMessage,
2894
+ message: ForwardableEmailMessage,
2770
2895
  env: Env,
2771
2896
  ctx: ExecutionContext
2772
2897
  ) => void | Promise<void>;
@@ -2847,75 +2972,12 @@ export interface JsonWebKeyWithKid extends JsonWebKey {
2847
2972
  // Key Identifier of the JWK
2848
2973
  readonly kid: string;
2849
2974
  }
2850
- /**
2851
- * A message that is sent to a consumer Worker.
2852
- */
2853
- export interface Message<Body = unknown> {
2854
- /**
2855
- * A unique, system-generated ID for the message.
2856
- */
2857
- readonly id: string;
2858
- /**
2859
- * A timestamp when the message was sent.
2860
- */
2861
- readonly timestamp: Date;
2862
- /**
2863
- * The body of the message.
2864
- */
2865
- readonly body: Body;
2866
- /**
2867
- * Marks message to be retried.
2868
- */
2869
- retry(): void;
2870
- /**
2871
- * Marks message acknowledged.
2872
- */
2873
- ack(): void;
2874
- }
2875
- /**
2876
- * A batch of messages that are sent to a consumer Worker.
2877
- */
2878
- export interface MessageBatch<Body = unknown> {
2879
- /**
2880
- * The name of the Queue that belongs to this batch.
2881
- */
2882
- readonly queue: string;
2883
- /**
2884
- * An array of messages in the batch. Ordering of messages is not guaranteed.
2885
- */
2886
- readonly messages: readonly Message<Body>[];
2887
- /**
2888
- * Marks every message to be retried in the next batch.
2889
- */
2890
- retryAll(): void;
2891
- /**
2892
- * Marks every message acknowledged in the batch.
2893
- */
2894
- ackAll(): void;
2895
- }
2896
- /**
2897
- * A wrapper class used to structure message batches.
2898
- */
2899
- export type MessageSendRequest<Body = unknown> = {
2975
+ // https://developers.cloudflare.com/cloudflare-for-platforms/workers-for-platforms/
2976
+ export interface DispatchNamespace {
2900
2977
  /**
2901
- * The body of the message.
2978
+ * @param name Name of the Worker script.
2979
+ * @returns A Fetcher object that allows you to send requests to the Worker script.
2980
+ * @throws If the Worker script does not exist in this dispatch namespace, an error will be thrown.
2902
2981
  */
2903
- body: Body;
2904
- };
2905
- /**
2906
- * A binding that allows a producer to send messages to a Queue.
2907
- */
2908
- export interface Queue<Body = any> {
2909
- /**
2910
- * Sends a message to the Queue.
2911
- * @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.
2912
- * @returns A promise that resolves when the message is confirmed to be written to disk.
2913
- */
2914
- send(message: Body): Promise<void>;
2915
- /**
2916
- * Sends a batch of messages to the Queue.
2917
- * @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.
2918
- * @returns A promise that resolves when the messages are confirmed to be written to disk.
2919
- */
2920
- sendBatch(messages: Iterable<MessageSendRequest<Body>>): Promise<void>;
2982
+ get(name: string): Fetcher;
2921
2983
  }
package/README.md CHANGED
@@ -81,7 +81,7 @@ To use one of these entrypoints, you need to specify them in your `tsconfig.json
81
81
 
82
82
  ### Importable Types
83
83
 
84
- It's not always possible (or desirable) to modify the `tsconfig.json` settings for a project to include all the Cloudflare Workers types. For use cases like that, this package provides importable versions of it's types, which are usable with no additional `tsconfig.json` setup. For example:
84
+ It's not always possible (or desirable) to modify the `tsconfig.json` settings for a project to include all the Cloudflare Workers types. For use cases like that, this package provides importable versions of its types, which are usable with no additional `tsconfig.json` setup. For example:
85
85
 
86
86
  ```ts
87
87
  import type { Request as WorkerRequest, ExecutionContext } from "@cloudflare/workers-types/experimental"