@cloudflare/workers-types 4.20230228.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.
package/index.ts CHANGED
@@ -286,8 +286,11 @@ export interface ExecutionContext {
286
286
  waitUntil(promise: Promise<any>): void;
287
287
  passThroughOnException(): void;
288
288
  }
289
- export type ExportedHandlerFetchHandler<Env = unknown> = (
290
- request: Request,
289
+ export type ExportedHandlerFetchHandler<
290
+ Env = unknown,
291
+ CfHostMetadata = unknown
292
+ > = (
293
+ request: Request<CfHostMetadata, IncomingRequestCfProperties<CfHostMetadata>>,
291
294
  env: Env,
292
295
  ctx: ExecutionContext
293
296
  ) => Response | Promise<Response>;
@@ -311,8 +314,12 @@ export type ExportedHandlerTestHandler<Env = unknown> = (
311
314
  env: Env,
312
315
  ctx: ExecutionContext
313
316
  ) => void | Promise<void>;
314
- export interface ExportedHandler<Env = unknown, QueueMessage = unknown> {
315
- fetch?: ExportedHandlerFetchHandler<Env>;
317
+ export interface ExportedHandler<
318
+ Env = unknown,
319
+ QueueMessage = unknown,
320
+ CfHostMetadata = unknown
321
+ > {
322
+ fetch?: ExportedHandlerFetchHandler<Env, CfHostMetadata>;
316
323
  trace?: ExportedHandlerTraceHandler<Env>;
317
324
  scheduled?: ExportedHandlerScheduledHandler<Env>;
318
325
  test?: ExportedHandlerTestHandler<Env>;
@@ -997,10 +1004,16 @@ export interface ResponseInit {
997
1004
  webSocket?: WebSocket | null;
998
1005
  encodeBody?: "automatic" | "manual";
999
1006
  }
1000
- export type RequestInfo = Request | string | URL;
1001
- export declare class Request<CfHostMetadata = unknown> extends Body {
1002
- constructor(input: RequestInfo, init?: RequestInit);
1003
- clone(): Request<CfHostMetadata>;
1007
+ export type RequestInfo<
1008
+ CfHostMetadata = unknown,
1009
+ Cf = CfProperties<CfHostMetadata>
1010
+ > = Request<CfHostMetadata, Cf> | string | URL;
1011
+ export declare class Request<
1012
+ CfHostMetadata = unknown,
1013
+ Cf = CfProperties<CfHostMetadata>
1014
+ > extends Body {
1015
+ constructor(input: RequestInfo<CfProperties>, init?: RequestInit<Cf>);
1016
+ clone(): Request<CfHostMetadata, Cf>;
1004
1017
  /** Returns request's HTTP method, which is "GET" by default. */
1005
1018
  readonly method: string;
1006
1019
  /** Returns the URL of request as a string. */
@@ -1012,15 +1025,13 @@ export declare class Request<CfHostMetadata = unknown> extends Body {
1012
1025
  readonly fetcher: Fetcher | null;
1013
1026
  /** Returns the signal associated with request, which is an AbortSignal object indicating whether or not request has been aborted, and its abort event handler. */
1014
1027
  readonly signal: AbortSignal;
1015
- readonly cf?: IncomingRequestCfProperties<CfHostMetadata>;
1028
+ readonly cf?: Cf;
1016
1029
  /** Returns request's subresource integrity metadata, which is a cryptographic hash of the resource being fetched. Its value consists of multiple hashes separated by whitespace. [SRI] */
1017
1030
  readonly integrity: string;
1018
1031
  /** Returns a boolean indicating whether or not request can outlive the global in which it was created. */
1019
1032
  readonly keepalive: boolean;
1020
1033
  }
1021
- export interface RequestInit<
1022
- CfType = IncomingRequestCfProperties | RequestInitCfProperties
1023
- > {
1034
+ export interface RequestInit<Cf = CfProperties> {
1024
1035
  /** A string to set request's method. */
1025
1036
  method?: string;
1026
1037
  /** A Headers object, an object literal, or an array of two-item arrays to set request's headers. */
@@ -1030,17 +1041,14 @@ export interface RequestInit<
1030
1041
  /** 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. */
1031
1042
  redirect?: string;
1032
1043
  fetcher?: Fetcher | null;
1033
- cf?: CfType;
1044
+ cf?: Cf;
1034
1045
  /** A cryptographic hash of the resource to be fetched by request. Sets request's integrity. */
1035
1046
  integrity?: string;
1036
1047
  /** An AbortSignal to set request's signal. */
1037
1048
  signal?: AbortSignal | null;
1038
1049
  }
1039
1050
  export declare abstract class Fetcher {
1040
- fetch(
1041
- input: RequestInfo,
1042
- init?: RequestInit<RequestInitCfProperties>
1043
- ): Promise<Response>;
1051
+ fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
1044
1052
  }
1045
1053
  export interface FetcherPutOptions {
1046
1054
  expiration?: number;
@@ -1875,7 +1883,7 @@ export interface BasicImageTransformationsGravityCoordinates {
1875
1883
  * Note: Currently, these properties cannot be tested in the
1876
1884
  * playground.
1877
1885
  */
1878
- export interface RequestInitCfProperties {
1886
+ export interface RequestInitCfProperties extends Record<string, unknown> {
1879
1887
  cacheEverything?: boolean;
1880
1888
  /**
1881
1889
  * A request's cache key is what determines if two requests are
@@ -2045,6 +2053,49 @@ export interface RequestInitCfPropertiesImage
2045
2053
  * the origin.
2046
2054
  */
2047
2055
  "origin-auth"?: "share-publicly";
2056
+ /**
2057
+ * Adds a border around the image. The border is added after resizing. Border
2058
+ * width takes dpr into account, and can be specified either using a single
2059
+ * width property, or individually for each side.
2060
+ */
2061
+ border?:
2062
+ | {
2063
+ color: string;
2064
+ width: number;
2065
+ }
2066
+ | {
2067
+ color: string;
2068
+ top: number;
2069
+ right: number;
2070
+ bottom: number;
2071
+ left: number;
2072
+ };
2073
+ /**
2074
+ * Increase brightness by a factor. A value of 1.0 equals no change, a value
2075
+ * of 0.5 equals half brightness, and a value of 2.0 equals twice as bright.
2076
+ * 0 is ignored.
2077
+ */
2078
+ brightness?: number;
2079
+ /**
2080
+ * Increase contrast by a factor. A value of 1.0 equals no change, a value of
2081
+ * 0.5 equals low contrast, and a value of 2.0 equals high contrast. 0 is
2082
+ * ignored.
2083
+ */
2084
+ contrast?: number;
2085
+ /**
2086
+ * Increase exposure by a factor. A value of 1.0 equals no change, a value of
2087
+ * 0.5 darkens the image, and a value of 2.0 lightens the image. 0 is ignored.
2088
+ */
2089
+ gamma?: number;
2090
+ /**
2091
+ * Slightly reduces latency on a cache miss by selecting a
2092
+ * quickest-to-compress file format, at a cost of increased file size and
2093
+ * lower image quality. It will usually override the format option and choose
2094
+ * JPEG over WebP or AVIF. We do not recommend using this option, except in
2095
+ * unusual circumstances like resizing uncacheable dynamically-generated
2096
+ * images.
2097
+ */
2098
+ compression?: "fast";
2048
2099
  }
2049
2100
  export interface RequestInitCfPropertiesImageMinify {
2050
2101
  javascript?: boolean;
@@ -2060,7 +2111,8 @@ export type IncomingRequestCfProperties<HostMetadata = unknown> =
2060
2111
  IncomingRequestCfPropertiesCloudflareForSaaSEnterprise<HostMetadata> &
2061
2112
  IncomingRequestCfPropertiesGeographicInformation &
2062
2113
  IncomingRequestCfPropertiesCloudflareAccessOrApiShield;
2063
- export interface IncomingRequestCfPropertiesBase {
2114
+ export interface IncomingRequestCfPropertiesBase
2115
+ extends Record<string, unknown> {
2064
2116
  /**
2065
2117
  * [ASN](https://www.iana.org/assignments/as-numbers/as-numbers.xhtml) of the incoming request.
2066
2118
  *
@@ -2253,86 +2305,82 @@ export interface IncomingRequestCfPropertiesExportedAuthenticatorMetadata {
2253
2305
  /**
2254
2306
  * Geographic data about the request's origin.
2255
2307
  */
2256
- export type IncomingRequestCfPropertiesGeographicInformation =
2257
- | {}
2258
- | {
2259
- /** The country code `"T1"` is used for requests originating on TOR */
2260
- country: "T1";
2261
- }
2262
- | {
2263
- /**
2264
- * The [ISO 3166-1 Alpha 2](https://www.iso.org/iso-3166-country-codes.html) country code the request originated from.
2265
- *
2266
- * 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.
2267
- *
2268
- * If Cloudflare is unable to determine where the request originated this property is omitted.
2269
- *
2270
- * @example "GB"
2271
- */
2272
- country: Iso3166Alpha2Code;
2273
- /**
2274
- * If present, this property indicates that the request originated in the EU
2275
- *
2276
- * @example "1"
2277
- */
2278
- isEUCountry?: "1";
2279
- /**
2280
- * A two-letter code indicating the continent the request originated from.
2281
- *
2282
- * @example "AN"
2283
- */
2284
- continent: ContinentCode;
2285
- /**
2286
- * The city the request originated from
2287
- *
2288
- * @example "Austin"
2289
- */
2290
- city?: string;
2291
- /**
2292
- * Postal code of the incoming request
2293
- *
2294
- * @example "78701"
2295
- */
2296
- postalCode?: string;
2297
- /**
2298
- * Latitude of the incoming request
2299
- *
2300
- * @example "30.27130"
2301
- */
2302
- latitude?: string;
2303
- /**
2304
- * Longitude of the incoming request
2305
- *
2306
- * @example "-97.74260"
2307
- */
2308
- longitude?: string;
2309
- /**
2310
- * Timezone of the incoming request
2311
- *
2312
- * @example "America/Chicago"
2313
- */
2314
- timezone?: string;
2315
- /**
2316
- * If known, the ISO 3166-2 name for the first level region associated with
2317
- * the IP address of the incoming request
2318
- *
2319
- * @example "Texas"
2320
- */
2321
- region?: string;
2322
- /**
2323
- * If known, the ISO 3166-2 code for the first-level region associated with
2324
- * the IP address of the incoming request
2325
- *
2326
- * @example "TX"
2327
- */
2328
- regionCode?: string;
2329
- /**
2330
- * Metro code (DMA) of the incoming request
2331
- *
2332
- * @example "635"
2333
- */
2334
- metroCode?: string;
2335
- };
2308
+ export interface IncomingRequestCfPropertiesGeographicInformation {
2309
+ /**
2310
+ * The [ISO 3166-1 Alpha 2](https://www.iso.org/iso-3166-country-codes.html) country code the request originated from.
2311
+ *
2312
+ * 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.
2313
+ *
2314
+ * If Cloudflare is unable to determine where the request originated this property is omitted.
2315
+ *
2316
+ * The country code `"T1"` is used for requests originating on TOR.
2317
+ *
2318
+ * @example "GB"
2319
+ */
2320
+ country?: Iso3166Alpha2Code | "T1";
2321
+ /**
2322
+ * If present, this property indicates that the request originated in the EU
2323
+ *
2324
+ * @example "1"
2325
+ */
2326
+ isEUCountry?: "1";
2327
+ /**
2328
+ * A two-letter code indicating the continent the request originated from.
2329
+ *
2330
+ * @example "AN"
2331
+ */
2332
+ continent?: ContinentCode;
2333
+ /**
2334
+ * The city the request originated from
2335
+ *
2336
+ * @example "Austin"
2337
+ */
2338
+ city?: string;
2339
+ /**
2340
+ * Postal code of the incoming request
2341
+ *
2342
+ * @example "78701"
2343
+ */
2344
+ postalCode?: string;
2345
+ /**
2346
+ * Latitude of the incoming request
2347
+ *
2348
+ * @example "30.27130"
2349
+ */
2350
+ latitude?: string;
2351
+ /**
2352
+ * Longitude of the incoming request
2353
+ *
2354
+ * @example "-97.74260"
2355
+ */
2356
+ longitude?: string;
2357
+ /**
2358
+ * Timezone of the incoming request
2359
+ *
2360
+ * @example "America/Chicago"
2361
+ */
2362
+ timezone?: string;
2363
+ /**
2364
+ * If known, the ISO 3166-2 name for the first level region associated with
2365
+ * the IP address of the incoming request
2366
+ *
2367
+ * @example "Texas"
2368
+ */
2369
+ region?: string;
2370
+ /**
2371
+ * If known, the ISO 3166-2 code for the first-level region associated with
2372
+ * the IP address of the incoming request
2373
+ *
2374
+ * @example "TX"
2375
+ */
2376
+ regionCode?: string;
2377
+ /**
2378
+ * Metro code (DMA) of the incoming request
2379
+ *
2380
+ * @example "635"
2381
+ */
2382
+ metroCode?: string;
2383
+ }
2336
2384
  /** Data about the incoming request's TLS certificate */
2337
2385
  export interface IncomingRequestCfPropertiesTLSClientAuth {
2338
2386
  /** Always `"1"`, indicating that the certificate was presented */
@@ -2725,6 +2773,9 @@ export type Iso3166Alpha2Code =
2725
2773
  | "ZW";
2726
2774
  /** The 2-letter continent codes Cloudflare uses */
2727
2775
  export type ContinentCode = "AF" | "AN" | "AS" | "EU" | "NA" | "OC" | "SA";
2776
+ export type CfProperties<HostMetadata = unknown> =
2777
+ | IncomingRequestCfProperties<HostMetadata>
2778
+ | RequestInitCfProperties;
2728
2779
  export interface D1Result<T = unknown> {
2729
2780
  results?: T[];
2730
2781
  success: boolean;
@@ -2747,7 +2798,7 @@ export declare abstract class D1PreparedStatement {
2747
2798
  /**
2748
2799
  * A email message that is sent to a consumer Worker.
2749
2800
  */
2750
- export interface EmailMessage<Body = unknown> {
2801
+ export interface EmailMessage {
2751
2802
  /**
2752
2803
  * Envelope From attribute of the email message.
2753
2804
  */