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