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