@cloudflare/workers-types 4.20230307.0 → 4.20230321.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.
@@ -291,8 +291,11 @@ declare interface ExecutionContext {
291
291
  waitUntil(promise: Promise<any>): void;
292
292
  passThroughOnException(): void;
293
293
  }
294
- declare type ExportedHandlerFetchHandler<Env = unknown> = (
295
- request: Request,
294
+ declare type ExportedHandlerFetchHandler<
295
+ Env = unknown,
296
+ CfHostMetadata = unknown
297
+ > = (
298
+ request: Request<CfHostMetadata, IncomingRequestCfProperties<CfHostMetadata>>,
296
299
  env: Env,
297
300
  ctx: ExecutionContext
298
301
  ) => Response | Promise<Response>;
@@ -316,8 +319,12 @@ declare type ExportedHandlerTestHandler<Env = unknown> = (
316
319
  env: Env,
317
320
  ctx: ExecutionContext
318
321
  ) => void | Promise<void>;
319
- declare interface ExportedHandler<Env = unknown, QueueMessage = unknown> {
320
- fetch?: ExportedHandlerFetchHandler<Env>;
322
+ declare interface ExportedHandler<
323
+ Env = unknown,
324
+ QueueMessage = unknown,
325
+ CfHostMetadata = unknown
326
+ > {
327
+ fetch?: ExportedHandlerFetchHandler<Env, CfHostMetadata>;
321
328
  trace?: ExportedHandlerTraceHandler<Env>;
322
329
  scheduled?: ExportedHandlerScheduledHandler<Env>;
323
330
  test?: ExportedHandlerTestHandler<Env>;
@@ -992,23 +999,27 @@ declare interface ResponseInit {
992
999
  webSocket?: WebSocket | null;
993
1000
  encodeBody?: "automatic" | "manual";
994
1001
  }
995
- declare type RequestInfo = Request | string | URL;
996
- declare class Request<CfHostMetadata = unknown> extends Body {
997
- constructor(input: RequestInfo, init?: RequestInit);
998
- clone(): Request<CfHostMetadata>;
1002
+ declare type RequestInfo<
1003
+ CfHostMetadata = unknown,
1004
+ Cf = CfProperties<CfHostMetadata>
1005
+ > = Request<CfHostMetadata, Cf> | string | URL;
1006
+ declare class Request<
1007
+ CfHostMetadata = unknown,
1008
+ Cf = CfProperties<CfHostMetadata>
1009
+ > extends Body {
1010
+ constructor(input: RequestInfo<CfProperties>, init?: RequestInit<Cf>);
1011
+ clone(): Request<CfHostMetadata, Cf>;
999
1012
  get method(): string;
1000
1013
  get url(): string;
1001
1014
  get headers(): Headers;
1002
1015
  get redirect(): string;
1003
1016
  get fetcher(): Fetcher | null;
1004
1017
  get signal(): AbortSignal;
1005
- get cf(): IncomingRequestCfProperties<CfHostMetadata> | undefined;
1018
+ get cf(): Cf | undefined;
1006
1019
  get integrity(): string;
1007
1020
  get keepalive(): boolean;
1008
1021
  }
1009
- declare interface RequestInit<
1010
- CfType = IncomingRequestCfProperties | RequestInitCfProperties
1011
- > {
1022
+ declare interface RequestInit<Cf = CfProperties> {
1012
1023
  /** A string to set request's method. */
1013
1024
  method?: string;
1014
1025
  /** A Headers object, an object literal, or an array of two-item arrays to set request's headers. */
@@ -1018,17 +1029,14 @@ declare interface RequestInit<
1018
1029
  /** 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. */
1019
1030
  redirect?: string;
1020
1031
  fetcher?: Fetcher | null;
1021
- cf?: CfType;
1032
+ cf?: Cf;
1022
1033
  /** A cryptographic hash of the resource to be fetched by request. Sets request's integrity. */
1023
1034
  integrity?: string;
1024
1035
  /** An AbortSignal to set request's signal. */
1025
1036
  signal?: AbortSignal | null;
1026
1037
  }
1027
1038
  declare abstract class Fetcher {
1028
- fetch(
1029
- input: RequestInfo,
1030
- init?: RequestInit<RequestInitCfProperties>
1031
- ): Promise<Response>;
1039
+ fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
1032
1040
  }
1033
1041
  declare interface FetcherPutOptions {
1034
1042
  expiration?: number;
@@ -1658,6 +1666,7 @@ declare class URL {
1658
1666
  get searchParams(): URLSearchParams;
1659
1667
  toJSON(): string;
1660
1668
  toString(): string;
1669
+ static canParse(url: string, base?: string): boolean;
1661
1670
  }
1662
1671
  declare class URLSearchParams {
1663
1672
  constructor(
@@ -1862,7 +1871,7 @@ declare interface BasicImageTransformationsGravityCoordinates {
1862
1871
  * Note: Currently, these properties cannot be tested in the
1863
1872
  * playground.
1864
1873
  */
1865
- declare interface RequestInitCfProperties {
1874
+ declare interface RequestInitCfProperties extends Record<string, unknown> {
1866
1875
  cacheEverything?: boolean;
1867
1876
  /**
1868
1877
  * A request's cache key is what determines if two requests are
@@ -2032,6 +2041,49 @@ declare interface RequestInitCfPropertiesImage
2032
2041
  * the origin.
2033
2042
  */
2034
2043
  "origin-auth"?: "share-publicly";
2044
+ /**
2045
+ * Adds a border around the image. The border is added after resizing. Border
2046
+ * width takes dpr into account, and can be specified either using a single
2047
+ * width property, or individually for each side.
2048
+ */
2049
+ border?:
2050
+ | {
2051
+ color: string;
2052
+ width: number;
2053
+ }
2054
+ | {
2055
+ color: string;
2056
+ top: number;
2057
+ right: number;
2058
+ bottom: number;
2059
+ left: number;
2060
+ };
2061
+ /**
2062
+ * Increase brightness by a factor. A value of 1.0 equals no change, a value
2063
+ * of 0.5 equals half brightness, and a value of 2.0 equals twice as bright.
2064
+ * 0 is ignored.
2065
+ */
2066
+ brightness?: number;
2067
+ /**
2068
+ * Increase contrast by a factor. A value of 1.0 equals no change, a value of
2069
+ * 0.5 equals low contrast, and a value of 2.0 equals high contrast. 0 is
2070
+ * ignored.
2071
+ */
2072
+ contrast?: number;
2073
+ /**
2074
+ * Increase exposure by a factor. A value of 1.0 equals no change, a value of
2075
+ * 0.5 darkens the image, and a value of 2.0 lightens the image. 0 is ignored.
2076
+ */
2077
+ gamma?: number;
2078
+ /**
2079
+ * Slightly reduces latency on a cache miss by selecting a
2080
+ * quickest-to-compress file format, at a cost of increased file size and
2081
+ * lower image quality. It will usually override the format option and choose
2082
+ * JPEG over WebP or AVIF. We do not recommend using this option, except in
2083
+ * unusual circumstances like resizing uncacheable dynamically-generated
2084
+ * images.
2085
+ */
2086
+ compression?: "fast";
2035
2087
  }
2036
2088
  declare interface RequestInitCfPropertiesImageMinify {
2037
2089
  javascript?: boolean;
@@ -2047,7 +2099,8 @@ declare type IncomingRequestCfProperties<HostMetadata = unknown> =
2047
2099
  IncomingRequestCfPropertiesCloudflareForSaaSEnterprise<HostMetadata> &
2048
2100
  IncomingRequestCfPropertiesGeographicInformation &
2049
2101
  IncomingRequestCfPropertiesCloudflareAccessOrApiShield;
2050
- declare interface IncomingRequestCfPropertiesBase {
2102
+ declare interface IncomingRequestCfPropertiesBase
2103
+ extends Record<string, unknown> {
2051
2104
  /**
2052
2105
  * [ASN](https://www.iana.org/assignments/as-numbers/as-numbers.xhtml) of the incoming request.
2053
2106
  *
@@ -2240,86 +2293,82 @@ declare interface IncomingRequestCfPropertiesExportedAuthenticatorMetadata {
2240
2293
  /**
2241
2294
  * Geographic data about the request's origin.
2242
2295
  */
2243
- declare type IncomingRequestCfPropertiesGeographicInformation =
2244
- | {}
2245
- | {
2246
- /** The country code `"T1"` is used for requests originating on TOR */
2247
- country: "T1";
2248
- }
2249
- | {
2250
- /**
2251
- * The [ISO 3166-1 Alpha 2](https://www.iso.org/iso-3166-country-codes.html) country code the request originated from.
2252
- *
2253
- * 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.
2254
- *
2255
- * If Cloudflare is unable to determine where the request originated this property is omitted.
2256
- *
2257
- * @example "GB"
2258
- */
2259
- country: Iso3166Alpha2Code;
2260
- /**
2261
- * If present, this property indicates that the request originated in the EU
2262
- *
2263
- * @example "1"
2264
- */
2265
- isEUCountry?: "1";
2266
- /**
2267
- * A two-letter code indicating the continent the request originated from.
2268
- *
2269
- * @example "AN"
2270
- */
2271
- continent: ContinentCode;
2272
- /**
2273
- * The city the request originated from
2274
- *
2275
- * @example "Austin"
2276
- */
2277
- city?: string;
2278
- /**
2279
- * Postal code of the incoming request
2280
- *
2281
- * @example "78701"
2282
- */
2283
- postalCode?: string;
2284
- /**
2285
- * Latitude of the incoming request
2286
- *
2287
- * @example "30.27130"
2288
- */
2289
- latitude?: string;
2290
- /**
2291
- * Longitude of the incoming request
2292
- *
2293
- * @example "-97.74260"
2294
- */
2295
- longitude?: string;
2296
- /**
2297
- * Timezone of the incoming request
2298
- *
2299
- * @example "America/Chicago"
2300
- */
2301
- timezone?: string;
2302
- /**
2303
- * If known, the ISO 3166-2 name for the first level region associated with
2304
- * the IP address of the incoming request
2305
- *
2306
- * @example "Texas"
2307
- */
2308
- region?: string;
2309
- /**
2310
- * If known, the ISO 3166-2 code for the first-level region associated with
2311
- * the IP address of the incoming request
2312
- *
2313
- * @example "TX"
2314
- */
2315
- regionCode?: string;
2316
- /**
2317
- * Metro code (DMA) of the incoming request
2318
- *
2319
- * @example "635"
2320
- */
2321
- metroCode?: string;
2322
- };
2296
+ declare interface IncomingRequestCfPropertiesGeographicInformation {
2297
+ /**
2298
+ * The [ISO 3166-1 Alpha 2](https://www.iso.org/iso-3166-country-codes.html) country code the request originated from.
2299
+ *
2300
+ * 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.
2301
+ *
2302
+ * If Cloudflare is unable to determine where the request originated this property is omitted.
2303
+ *
2304
+ * The country code `"T1"` is used for requests originating on TOR.
2305
+ *
2306
+ * @example "GB"
2307
+ */
2308
+ country?: Iso3166Alpha2Code | "T1";
2309
+ /**
2310
+ * If present, this property indicates that the request originated in the EU
2311
+ *
2312
+ * @example "1"
2313
+ */
2314
+ isEUCountry?: "1";
2315
+ /**
2316
+ * A two-letter code indicating the continent the request originated from.
2317
+ *
2318
+ * @example "AN"
2319
+ */
2320
+ continent?: ContinentCode;
2321
+ /**
2322
+ * The city the request originated from
2323
+ *
2324
+ * @example "Austin"
2325
+ */
2326
+ city?: string;
2327
+ /**
2328
+ * Postal code of the incoming request
2329
+ *
2330
+ * @example "78701"
2331
+ */
2332
+ postalCode?: string;
2333
+ /**
2334
+ * Latitude of the incoming request
2335
+ *
2336
+ * @example "30.27130"
2337
+ */
2338
+ latitude?: string;
2339
+ /**
2340
+ * Longitude of the incoming request
2341
+ *
2342
+ * @example "-97.74260"
2343
+ */
2344
+ longitude?: string;
2345
+ /**
2346
+ * Timezone of the incoming request
2347
+ *
2348
+ * @example "America/Chicago"
2349
+ */
2350
+ timezone?: string;
2351
+ /**
2352
+ * If known, the ISO 3166-2 name for the first level region associated with
2353
+ * the IP address of the incoming request
2354
+ *
2355
+ * @example "Texas"
2356
+ */
2357
+ region?: string;
2358
+ /**
2359
+ * If known, the ISO 3166-2 code for the first-level region associated with
2360
+ * the IP address of the incoming request
2361
+ *
2362
+ * @example "TX"
2363
+ */
2364
+ regionCode?: string;
2365
+ /**
2366
+ * Metro code (DMA) of the incoming request
2367
+ *
2368
+ * @example "635"
2369
+ */
2370
+ metroCode?: string;
2371
+ }
2323
2372
  /** Data about the incoming request's TLS certificate */
2324
2373
  declare interface IncomingRequestCfPropertiesTLSClientAuth {
2325
2374
  /** Always `"1"`, indicating that the certificate was presented */
@@ -2712,6 +2761,9 @@ declare type Iso3166Alpha2Code =
2712
2761
  | "ZW";
2713
2762
  /** The 2-letter continent codes Cloudflare uses */
2714
2763
  declare type ContinentCode = "AF" | "AN" | "AS" | "EU" | "NA" | "OC" | "SA";
2764
+ declare type CfProperties<HostMetadata = unknown> =
2765
+ | IncomingRequestCfProperties<HostMetadata>
2766
+ | RequestInitCfProperties;
2715
2767
  declare interface D1Result<T = unknown> {
2716
2768
  results?: T[];
2717
2769
  success: boolean;
@@ -2734,7 +2786,7 @@ declare abstract class D1PreparedStatement {
2734
2786
  /**
2735
2787
  * A email message that is sent to a consumer Worker.
2736
2788
  */
2737
- declare interface EmailMessage<Body = unknown> {
2789
+ declare interface EmailMessage {
2738
2790
  /**
2739
2791
  * Envelope From attribute of the email message.
2740
2792
  */