├── .changeset ├── README.md └── config.json ├── .github ├── CODEOWNERS └── workflows │ ├── checks.yml │ ├── expand-release-detail.yml │ └── release.yml ├── .gitignore ├── .markdownlint.yml ├── .npmignore ├── .prettierignore ├── .prettierrc ├── .vscode ├── extensions.json └── settings.json ├── CHANGELOG.md ├── LICENSE ├── README.md ├── RELEASE_CHECKLIST.md ├── docs └── kv.md ├── export ├── docs.ts ├── overrides.ts ├── prettydiff.ts └── types.ts ├── index.d.ts ├── manual-ts ├── cf.d.ts └── pages.d.ts ├── overrides ├── cf.d.ts ├── d1.d.ts ├── durableobjects.d.ts ├── encoding.d.ts ├── events.d.ts ├── htmlrewriter.d.ts ├── http.d.ts ├── kv.d.ts ├── stream.d.ts └── websocket.d.ts ├── package-lock.json ├── package.json ├── src ├── schema.json └── workers.json ├── tests ├── durableobjects.ts ├── globals.ts ├── http.ts ├── kv.ts └── websocket.ts └── tsconfig.json /.changeset/README.md: -------------------------------------------------------------------------------- 1 | # Changesets 2 | 3 | Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works 4 | with multi-package repos, or single-package repos to help you version and publish your code. You can 5 | find the full documentation for it [in our repository](https://github.com/changesets/changesets) 6 | 7 | We have a quick list of common questions to get you started engaging with this project in 8 | [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) 9 | -------------------------------------------------------------------------------- /.changeset/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://unpkg.com/@changesets/config@1.6.3/schema.json", 3 | "changelog": [ 4 | "@changesets/changelog-github", 5 | { "repo": "cloudflare/workers-types" } 6 | ], 7 | "commit": false, 8 | "linked": [], 9 | "access": "public", 10 | "baseBranch": "master", 11 | "updateInternalDependencies": "patch", 12 | "ignore": [] 13 | } 14 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @cloudflare/workers-js -------------------------------------------------------------------------------- /.github/workflows/checks.yml: -------------------------------------------------------------------------------- 1 | name: Checks 2 | 3 | on: pull_request 4 | 5 | jobs: 6 | test: 7 | name: "Typechecking" 8 | runs-on: ubuntu-latest 9 | steps: 10 | - name: Checkout 11 | uses: actions/checkout@v2 12 | 13 | - name: Use Node.js 16.7 14 | uses: actions/setup-node@v2 15 | with: 16 | node-version: 16.7 17 | 18 | - name: Install NPM dependencies 19 | run: npm install 20 | 21 | - uses: actions/cache@v2 22 | id: node-modules-cache 23 | with: 24 | path: | 25 | node_modules 26 | */*/node_modules 27 | key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} 28 | 29 | - name: Run Prettier 30 | run: npm run prettier:check 31 | 32 | - name: Run Type Checking 33 | run: tsc 34 | -------------------------------------------------------------------------------- /.github/workflows/expand-release-detail.yml: -------------------------------------------------------------------------------- 1 | name: Add diff to release 2 | on: 3 | release: 4 | types: [published] 5 | 6 | jobs: 7 | show_diff: 8 | name: Show ts diff in release notes 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v1 12 | with: 13 | fetch-depth: 0 14 | 15 | - name: Setup Node 16 | uses: actions/setup-node@v2 17 | 18 | - uses: actions/cache@v2 19 | id: node-modules-cache 20 | with: 21 | path: | 22 | node_modules 23 | */*/node_modules 24 | key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} 25 | 26 | - name: NPM Install 27 | run: npm install 28 | 29 | - name: Generate diff 30 | id: generate_diff 31 | run: npm run --silent generate:diff > diff.md 32 | - name: Read diff.md 33 | id: diff 34 | uses: juliangruber/read-file-action@v1 35 | with: 36 | path: diff.md 37 | 38 | - uses: octokit/request-action@v2.x 39 | id: get_latest_release 40 | with: 41 | route: GET /repos/${{ github.repository }}/releases/latest 42 | env: 43 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 44 | - uses: octokit/request-action@v2.x 45 | id: update_release 46 | with: 47 | route: PATCH /repos/${{ github.repository }}/releases/{release_id} 48 | release_id: ${{ fromJson(steps.get_latest_release.outputs.data).id }} 49 | body: | 50 | | 51 | ${{ fromJson(steps.get_latest_release.outputs.data).body }} 52 | ${{ steps.diff.outputs.content }} 53 | env: 54 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 55 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | release: 10 | if: ${{ github.repository_owner == 'cloudflare' }} 11 | name: Release 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Checkout Repo 15 | uses: actions/checkout@v2 16 | with: 17 | fetch-depth: 0 18 | 19 | - name: Setup Node.js 16.7 20 | uses: actions/setup-node@v2 21 | with: 22 | node-version: 16.7 23 | 24 | - uses: actions/cache@v2 25 | id: node-modules-cache 26 | with: 27 | path: | 28 | node_modules 29 | */*/node_modules 30 | key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} 31 | 32 | - name: Install NPM 33 | run: npm install 34 | 35 | - name: Check Docs 36 | run: npm run export:docs 37 | - name: Check Overrides 38 | run: npm run export:overrides 39 | 40 | - name: Run Prettier 41 | run: npm run prettier:check 42 | 43 | - name: Run Type Checking 44 | run: tsc 45 | 46 | - name: Create Version PR or Publish to NPM 47 | id: changesets 48 | uses: changesets/action@v1 49 | with: 50 | publish: npx changeset publish 51 | env: 52 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 53 | NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }} 54 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | docs.json 4 | overrides.json 5 | -------------------------------------------------------------------------------- /.markdownlint.yml: -------------------------------------------------------------------------------- 1 | # MD013/line-length Line length 2 | MD013: false 3 | 4 | # MD014/commands-show-output Dollar signs used before commands without showing output 5 | MD014: false 6 | 7 | # MD033/no-inline-html Inline HTML (used in README.md) 8 | MD033: 9 | allowed_elements: 10 | - sup 11 | - sub 12 | - code 13 | 14 | # heading duplication is allowed for non-sibling headings (common in change logs) 15 | MD024: 16 | siblings_only: true 17 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | CHANGELOG.md 3 | RELEASE_CHECKLIST.md 4 | tsconfig.json 5 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | CHANGELOG.md -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "proseWrap": "preserve" 3 | } 4 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": ["esbenp.prettier-vscode"] 3 | } 4 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.defaultFormatter": "esbenp.prettier-vscode" 3 | } 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 3.19.0 4 | 5 | ### Minor Changes 6 | 7 | - [`0edd92e`](https://github.com/cloudflare/workers-types/commit/0edd92ef75b20bc9869d06d58ac4a190928f3e91) Thanks [@mrbbot](https://github.com/mrbbot)! - Merge and make optional all `IncomingRequestCfPropertiesGeographicInformation` properties 8 | 9 | ### Patch Changes 10 | 11 | - [#314](https://github.com/cloudflare/workers-types/pull/314) [`59b3f55`](https://github.com/cloudflare/workers-types/commit/59b3f5599dd0240b750fbde4abdb7277178af72b) Thanks [@GregBrimble](https://github.com/GregBrimble)! - feat: Add `passThroughOnException()` to Pages Functions 12 | 13 | ## 3.18.0 14 | 15 | ### Minor Changes 16 | 17 | - [#307](https://github.com/cloudflare/workers-types/pull/307) [`0721beb`](https://github.com/cloudflare/workers-types/commit/0721bebe14bcf4f70e90d24f147dcd805a3f4d5e) Thanks [@autodecl-bot](https://github.com/apps/autodecl-bot)! - Updated auto-generated types @ 2022-10-21 18 | 19 | ### Patch Changes 20 | 21 | - [#301](https://github.com/cloudflare/workers-types/pull/301) [`17b6d16`](https://github.com/cloudflare/workers-types/commit/17b6d16e2b7d0e8605ae0ed2e704336ef89c2c47) Thanks [@caass](https://github.com/caass)! - Improve the `IncomingRequestCfProperties` type. 22 | 23 | Previously, this type was based on our docs, which didn't include some fields. Now we've gone through the code that generates these fields and ensured that every property matches up. 24 | 25 | Additionally, we added examples and documentation for almost everything, so it should be more clear exactly what a certain property is or isn't. 26 | 27 | ## 3.17.0 28 | 29 | ### Minor Changes 30 | 31 | - [#294](https://github.com/cloudflare/workers-types/pull/294) [`fba318b`](https://github.com/cloudflare/workers-types/commit/fba318b33a13be2807e04849aac00b62ca8f0679) Thanks [@Frederik-Baetens](https://github.com/Frederik-Baetens)! - Updated auto-generated types @ 2022-10-13 32 | 33 | ### Patch Changes 34 | 35 | - [#280](https://github.com/cloudflare/workers-types/pull/280) [`6e55069`](https://github.com/cloudflare/workers-types/commit/6e550691955478fac33e960bfafe32738bda6016) Thanks [@WalshyDev](https://github.com/WalshyDev)! - Make clientTcpRtt optional 36 | 37 | * [#288](https://github.com/cloudflare/workers-types/pull/288) [`4fe75b2`](https://github.com/cloudflare/workers-types/commit/4fe75b2cfc2b58f1cc7e84923ce8be47ae0a93eb) Thanks [@florianmartens](https://github.com/florianmartens)! - Add 'origin-auth' to RequestInitCfPropertiesImage interface. This changes fixes types for users attempting to fetch images from authenticated sources. Before this fix, users had to manually extend the fetch interface to satisfy the TS compiler. 38 | 39 | - [#275](https://github.com/cloudflare/workers-types/pull/275) [`c9e2084`](https://github.com/cloudflare/workers-types/commit/c9e2084294d07fccfbcb33c2da281415204083c9) Thanks [@KianNH](https://github.com/KianNH)! - chore: add corporateProxy to request.cf.botManagement 40 | 41 | * [#285](https://github.com/cloudflare/workers-types/pull/285) [`b6a5d1a`](https://github.com/cloudflare/workers-types/commit/b6a5d1a040543ce3a37c3aea71fab30dc8cb90d9) Thanks [@sid405](https://github.com/sid405)! - Fix return type of D1PreparedStatement.all 42 | 43 | ## 3.16.0 44 | 45 | ### Minor Changes 46 | 47 | - [#273](https://github.com/cloudflare/workers-types/pull/273) [`bc80605`](https://github.com/cloudflare/workers-types/commit/bc8060518241fa858765cf5bff48f4115289d009) Thanks [@autodecl-bot](https://github.com/apps/autodecl-bot)! - Updated auto-generated types @ 2022-08-30 48 | 49 | ## 3.15.0 50 | 51 | ### Minor Changes 52 | 53 | - [#265](https://github.com/cloudflare/workers-types/pull/265) [`6cac151`](https://github.com/cloudflare/workers-types/commit/6cac15126701c53b7d988fd4d3dab76d5755b6ce) Thanks [@geelen](https://github.com/geelen)! - Added D1 binding types 54 | 55 | ### Patch Changes 56 | 57 | - [#259](https://github.com/cloudflare/workers-types/pull/259) [`38b7e0f`](https://github.com/cloudflare/workers-types/commit/38b7e0fba83f01654a00b0d805cd01211a419f3d) Thanks [@vlovich](https://github.com/vlovich)! - Fix DurableObject transaction `get` to properly return `Promise` instead of `Promise` 58 | 59 | ## 3.14.1 60 | 61 | ### Patch Changes 62 | 63 | - [#245](https://github.com/cloudflare/workers-types/pull/245) [`bf5d870`](https://github.com/cloudflare/workers-types/commit/bf5d870b4e1466291c3cbdcba3001ab28f3ea400) Thanks [@jacobbednarz](https://github.com/jacobbednarz)! - Added support for `isEUCountry` property on `IncomingRequestCfProperties` 64 | 65 | ## 3.14.0 66 | 67 | ### Minor Changes 68 | 69 | - [#253](https://github.com/cloudflare/workers-types/pull/253) [`f45703c`](https://github.com/cloudflare/workers-types/commit/f45703cca6996f057c3ab1dceaea53f6f760471c) Thanks [@autodecl-bot](https://github.com/apps/autodecl-bot)! - Updated auto-generated types @ 2022-06-20 70 | 71 | * [#256](https://github.com/cloudflare/workers-types/pull/256) [`9b4290b`](https://github.com/cloudflare/workers-types/commit/9b4290b30eef9683209afd32ef14ed208554f32f) Thanks [@Kellel](https://github.com/Kellel)! - Update tlsClientAuth properties 72 | 73 | ## 3.13.0 74 | 75 | ### Minor Changes 76 | 77 | - [#251](https://github.com/cloudflare/workers-types/pull/251) [`e146987`](https://github.com/cloudflare/workers-types/commit/e146987bb996733f67c38313221d71aa47293c76) Thanks [@vlovich](https://github.com/vlovich)! - Updated auto-generated types @ 2022-06-16 78 | 79 | ## 3.12.0 80 | 81 | ### Minor Changes 82 | 83 | - [#247](https://github.com/cloudflare/workers-types/pull/247) [`2cdc8cf`](https://github.com/cloudflare/workers-types/commit/2cdc8cffd7086941e03125d9d95bd9a869a837a3) Thanks [@iveelsm](https://github.com/iveelsm)! - Allow for cacheTags to be passed on fetch requests 84 | 85 | Allowing cacheTags within the workers process to be processed as part of a standard fetch has been a highly requested feature. This new object within the request initialization will allow for supplemental Cache-Tag headers to be returned so that they can be stored with the relevant content. This will allow for better control over Purge by Tag mechanisms within the workers processes. 86 | 87 | Implementation: 88 | 89 | - Adds a new object to the `cf.d.ts` declaration. 90 | 91 | ## 3.11.0 92 | 93 | ### Minor Changes 94 | 95 | - [#236](https://github.com/cloudflare/workers-types/pull/236) [`9409be6`](https://github.com/cloudflare/workers-types/commit/9409be6c83e1f93af074ebf4cd9cdcb3af5cff1c) Thanks [@autodecl-bot](https://github.com/apps/autodecl-bot)! - Updated auto-generated types @ 2022-05-11 96 | 97 | ## 3.10.0 98 | 99 | ### Minor Changes 100 | 101 | - [#230](https://github.com/cloudflare/workers-types/pull/230) [`ceec72b`](https://github.com/cloudflare/workers-types/commit/ceec72b6cb5baad74507d613eb3088f6e12778e4) Thanks [@autodecl-bot](https://github.com/apps/autodecl-bot)! - Updated auto-generated types @ 2022-05-04 102 | 103 | * [#232](https://github.com/cloudflare/workers-types/pull/232) [`97499a2`](https://github.com/cloudflare/workers-types/commit/97499a29c56c345cb92c412bcf03af0f1743293f) Thanks [@autodecl-bot](https://github.com/apps/autodecl-bot)! - Updated auto-generated types @ 2022-05-05 104 | 105 | - [#234](https://github.com/cloudflare/workers-types/pull/234) [`18ca7fc`](https://github.com/cloudflare/workers-types/commit/18ca7fca0e341ef6a337594207c5a65aac75e2d4) Thanks [@GregBrimble](https://github.com/GregBrimble)! - feat: Adds the Pages Functions asset imports type. More info on [our docs](https://developers.cloudflare.com/pages/platform/functions/plugins/). 106 | 107 | ### Patch Changes 108 | 109 | - [#235](https://github.com/cloudflare/workers-types/pull/235) [`a919734`](https://github.com/cloudflare/workers-types/commit/a919734272fae477e5c0409a43ff1f90755fa396) Thanks [@jasnell](https://github.com/jasnell)! - FetchEvent now extends from ExtendableEvent. 110 | 111 | ## 3.9.0 112 | 113 | ### Minor Changes 114 | 115 | - [#228](https://github.com/cloudflare/workers-types/pull/228) [`edaac15`](https://github.com/cloudflare/workers-types/commit/edaac154491a2ef93326ddc0b95c830193abb9f8) Thanks [@autodecl-bot](https://github.com/apps/autodecl-bot)! - Updated auto-generated types @ 2022-04-29 116 | 117 | ## 3.8.0 118 | 119 | ### Minor Changes 120 | 121 | - [#226](https://github.com/cloudflare/workers-types/pull/226) [`c2c7c2e`](https://github.com/cloudflare/workers-types/commit/c2c7c2e0d20b7ad6c269a67cc529eb6fd59d9885) Thanks [@autodecl-bot](https://github.com/apps/autodecl-bot)! - Updated auto-generated types @ 2022-04-27 122 | 123 | ## 3.7.1 124 | 125 | ### Patch Changes 126 | 127 | - [#224](https://github.com/cloudflare/workers-types/pull/224) [`a016b11`](https://github.com/cloudflare/workers-types/commit/a016b11e61cccfafaac7b078ee9a285717ebd930) Thanks [@GregBrimble](https://github.com/GregBrimble)! - feature: Adds the `PagesPluginFunction` type and internal `functionPath` to Functions' context. 128 | 129 | ## 3.7.0 130 | 131 | ### Minor Changes 132 | 133 | - [#222](https://github.com/cloudflare/workers-types/pull/222) [`b96c23c`](https://github.com/cloudflare/workers-types/commit/b96c23cb53502a6a6828efb93266e00d99734264) Thanks [@GregBrimble](https://github.com/GregBrimble)! - feature: Adds the `PagesPluginFunction` type and internal `functionPath` to Functions' context. 134 | 135 | ## 3.6.0 136 | 137 | ### Minor Changes 138 | 139 | - [#218](https://github.com/cloudflare/workers-types/pull/218) [`402e4cc`](https://github.com/cloudflare/workers-types/commit/402e4cc4faf5b0c99fbcd6ad2ca0c95cbe36fd6b) Thanks [@autodecl-bot](https://github.com/apps/autodecl-bot)! - Updated auto-generated types @ 2022-04-15 140 | 141 | ## 3.5.1 142 | 143 | ### Patch Changes 144 | 145 | - [`f776bc6`](https://github.com/cloudflare/workers-types/commit/f776bc6f0ed1851baf46d63ce7e47c3a10e522d2) Thanks [@threepointone](https://github.com/threepointone)! - Fixes for R2 types via https://github.com/cloudflare/workers-types/pull/216 146 | 147 | ## 3.5.0 148 | 149 | ### Minor Changes 150 | 151 | - [#202](https://github.com/cloudflare/workers-types/pull/202) [`921f05a`](https://github.com/cloudflare/workers-types/commit/921f05ae0d26c9557a730efeee3796bc572dc51d) Thanks [@autodecl-bot](https://github.com/apps/autodecl-bot)! - Updated auto-generated types @ 2022-03-07 152 | 153 | * [#210](https://github.com/cloudflare/workers-types/pull/210) [`f498fd9`](https://github.com/cloudflare/workers-types/commit/f498fd94ab13b40e2190f355bfb016e02e6c72a2) Thanks [@autodecl-bot](https://github.com/apps/autodecl-bot)! - Updated auto-generated types @ 2022-04-13 154 | 155 | ## 3.4.0 156 | 157 | ### Minor Changes 158 | 159 | - [#186](https://github.com/cloudflare/workers-types/pull/186) [`c117b5a`](https://github.com/cloudflare/workers-types/commit/c117b5a4874bcd7effdba0bc57fc74878f5faaa1) Thanks [@autodecl-bot](https://github.com/apps/autodecl-bot)! - Updated auto-generated types @ 2022-01-19 160 | 161 | * [#194](https://github.com/cloudflare/workers-types/pull/194) [`74c94f8`](https://github.com/cloudflare/workers-types/commit/74c94f8f96fa427353acd60ebc00d910f8e7cdfe) Thanks [@autodecl-bot](https://github.com/apps/autodecl-bot)! - Updated auto-generated types @ 2022-02-08 162 | 163 | ### Patch Changes 164 | 165 | - [#175](https://github.com/cloudflare/workers-types/pull/175) [`17d21e9`](https://github.com/cloudflare/workers-types/commit/17d21e9ae7cfee0c5d6ca4bf247978e5618c0386) Thanks [@threepointone](https://github.com/threepointone)! - fix: FormData::entries(), FormData::[Symbol.iterator]() 166 | 167 | * [#184](https://github.com/cloudflare/workers-types/pull/184) [`f1c3c40`](https://github.com/cloudflare/workers-types/commit/f1c3c40f4050b7d5b5c74c93ac2b583afc44f350) Thanks [@threepointone](https://github.com/threepointone)! - chore: update marked to 4.0.10 168 | 169 | ## 3.3.1 170 | 171 | ### Patch Changes 172 | 173 | - [`d7c4f73`](https://github.com/cloudflare/workers-types/commit/d7c4f7399594775863454609dffd4aa6349b4c39) Thanks [@threepointone](https://github.com/threepointone)! - via #178, thanks @kulla: Add possibility to narrow down key space of KVNamespace 174 | 175 | * [#170](https://github.com/cloudflare/workers-types/pull/170) [`771ce75`](https://github.com/cloudflare/workers-types/commit/771ce7591e63bf47f36b39d60afb86e1fe8d404b) Thanks [@JacobMGEvans](https://github.com/JacobMGEvans)! - CI/CD Improvements: 176 | 177 | - Added Changeset PR creation & publish Workflows 178 | - Added Typechecking workflow 179 | - Consolidated old workflows as jobs in new workflows 180 | - Added configuration for Changeset CLI 181 | - Installing Changeset bot for non-blocking PR support 182 | 183 | - [#181](https://github.com/cloudflare/workers-types/pull/181) [`0dc3fe4`](https://github.com/cloudflare/workers-types/commit/0dc3fe4def04e4127be065c5d88fd45865caeb64) Thanks [@autodecl-bot](https://github.com/apps/autodecl-bot)! - Updated auto-generated types @ 2022-01-15 184 | 185 | ## 3.3.0 186 | 187 | - **Updated types for 2021-12-14 [vlovich]** 188 | - **Updated types for 2021.12.300 [vlovich]** 189 | - **Updated types for 2021.12.100 [vlovich]** 190 | - **Adds env.ASSETS.fetch typings [@GregBrimble][pull/157]** 191 | - **Adding missing types in RequestInitCfPropertiesImage [@itsmatteomanf][pull/156]** 192 | 193 | ## 3.2.0 194 | 195 | - **Add 'error' WebSocket event types overrides [@bretthoerner], [pull/143] & [pull/150]** 196 | - **Add PagesFunction type [@GregBrimble], [pull/154]** 197 | - **Updated types for 2021.11.400 [@autodecl-bot], [pull/145]** 198 | - **Updated types for 2021.11.700 [@autodecl-bot], [pull/149]** 199 | 200 | ## 3.1.1 201 | 202 | - **Add `polish` key to `RequestInitCfProperties` - [@threepointone], [pull/131]** 203 | - **Added support for gravity: 'auto' to BasicImageTransformations - [@threepointone], [@@jonnedeprez], [pull/132]** 204 | - **Fixup DurableObject options names - [@vlovich], [pull/136]** 205 | - **Fixes for some crypto APIs - [@vlovich], [pull/137]** 206 | 207 | ## 3.1.0 208 | 209 | ### Features 210 | 211 | - **Updated types for 2021.10.800 - [@autodecl-bot], [pull/120]** 212 | - **Preserve the `@deprecated` tag when generating types - [@vlovich], [pull/123]** 213 | - **Cleanup unneeded overrides and replace with standard names - [@vlovich], [pull/123]** 214 | - **Support merging overrides automatically - [@vlovich], [pull/126]** 215 | - **Updated types for 2021.11.0 - [@autodecl-bot], [pull/128]** 216 | 217 | ### Bugfixes 218 | 219 | - **DurableObjectState storage should not be undefined in practice - [@koeninger], [pull/118]** 220 | - **Add `asOrganization` to `IncomingRequestCfProperties` - [@mrkldshv], [pull/111]** 221 | 222 | ## 3.0.0 223 | 224 | ### Features 225 | 226 | - **Types are automatically generated from the runtime - [@mrbbot], [pull/112]** 227 | Types now match exactly what's defined in the runtime source code, meaning `webworker` should be removed from users' `tsconfig.json`s 228 | 229 | [@mrbbot]: https://github.com/mrbbot 230 | [pull/112]: https://github.com/cloudflare/workers-types/pull/112 231 | 232 | ## 2.2.2 233 | 234 | ### Features 235 | 236 | - **Add KVNamespace.get options parameter, with cacheTtl - [@bretthoerner], [pull/87]** 237 | 238 | ### Bugfixes 239 | 240 | - **fix DurableObjectStorage transaction method signature - [@sbfaulkner], [pull/89]** 241 | 242 | ## 2.1.0 243 | 244 | ### Features 245 | 246 | - **Add types for Durable Objects - [@mathew-cf], [pull/63], [issue/64]** 247 | Types for [Durable Objects Beta](https://developers.cloudflare.com/workers/runtime-apis/durable-objects), subject to change. 248 | 249 | [@mathew-cf]: https://github.com/mathew-cf 250 | [pull/63]: https://github.com/cloudflare/workers-types/pull/63 251 | [issue/64]: https://github.com/cloudflare/workers-types/issues/64 252 | 253 | - **Add ScheduledEvent - [@qwtel], [pull/61]** 254 | Types for [Scheduled Events](https://developers.cloudflare.com/workers/runtime-apis/scheduled-event) 255 | 256 | [@qwtel]: https://github.com/qwtel 257 | [pull/61]: https://github.com/cloudflare/workers-types/pull/61 258 | 259 | - **Add AVIF Format for Image Resizing - [@GregBrimble], [pull/59]** 260 | 261 | [@gregbrimble]: https://github.com/GregBrimble 262 | [pull/59]: https://github.com/cloudflare/workers-types/pull/59 263 | 264 | - **Add metadata typings for KV - [@GregBrimble], [pull/54]** 265 | Adds the [new metadata](https://developers.cloudflare.com/workers/runtime-apis/kv#metadata) types to the getWithMetadata, put and list methods on a KV namespace. 266 | 267 | [@gregbrimble]: https://github.com/GregBrimble 268 | [pull/54]: https://github.com/cloudflare/workers-types/pull/54 269 | 270 | - **Complete Image Resizing properties - [@GregBrimble], [pull/50]** 271 | Adds missing options for the Image Resizing API. 272 | 273 | [@gregbrimble]: https://github.com/GregBrimble 274 | [pull/50]: https://github.com/cloudflare/workers-types/pull/50 275 | 276 | - **Add API for async handlers and end handler - [@ObsidianMinor], [pull/48]** 277 | Types for [HTML Rewriter](https://developers.cloudflare.com/workers/runtime-apis/html-rewriter#end) end of document append method 278 | 279 | [@obsidianminor]: https://github.com/ObsidianMinor 280 | [pull/48]: https://github.com/cloudflare/workers-types/pull/48 281 | 282 | ### Bugfixes 283 | 284 | - **Make Element.attributes iterable - [@jdanyow], [pull/47]** 285 | 286 | Fixing a bug in the type definitions that prevents writing valid code like this: 287 | 288 | ```typescript 289 | rewriter.on('bla', { 290 | element: element => { 291 | for (const [name, value] of element.attributes) { 292 | ``` 293 | 294 | [@jdanyow]: https://github.com/jdanyow 295 | [pull/47]: https://github.com/cloudflare/workers-types/pull/47 296 | 297 | ### Maintenance 298 | 299 | - **Update README.md instructions to avoid typescript error - [@jeremistadler], [pull/60]** 300 | Add empty export to bindings.d.ts example to avoid an typescript error 301 | 302 | [@jeremistadler]: https://github.com/jeremistadler 303 | [pull/60]: https://github.com/cloudflare/workers-types/pull/60 304 | 305 | - **Add a GitHub action to lint the Markdown - [@jbampton],[pull/51]** 306 | 307 | [@jbampton]: https://github.com/jbampton 308 | [pull/51]: https://github.com/cloudflare/workers-types/pull/51 309 | 310 | - **Fix spelling - [@jbampton],[pull/50]** 311 | 312 | [@jbampton]: https://github.com/jbampton 313 | [pull/50]: https://github.com/cloudflare/workers-types/pull/50 314 | 315 | - **Add CODEOWNERS - [@ispivey], [pull/49]** 316 | This will ensure we have default reviewers. 317 | 318 | [@ispivey]: https://github.com/ispivey 319 | [pull/48]: https://github.com/cloudflare/workers-types/pull/48 320 | 321 | - **Add prettier and typescript as devDependencies - [@1000hz], [pull/46]** 322 | Automated formatting via prettier 323 | 324 | [@1000hz]: https://github.com/1000hz 325 | [pull/46]: https://github.com/cloudflare/workers-types/pull/46 326 | 327 | ## ⌨️ 2.0.0 328 | 329 | ### Breaking Changes 330 | 331 | - **Types now only provided via automatic type inclusion, rather than explicit import - [@jdanyow], [issue/33], [pull/34]** 332 | 333 | Users should no longer use an empty import to include `workers-types`, which used to be the recommendation in the README. 334 | 335 | Remove this from your code: 336 | 337 | ```typescript 338 | import {} from "@cloudflare/workers-types"; 339 | ``` 340 | 341 | And instead include the types explicitly in your TypeScript configuration compiler options: 342 | 343 | ```json 344 | { 345 | "compilerOptions": { 346 | "types": ["@cloudflare/workers-types"] 347 | } 348 | } 349 | ``` 350 | 351 | [@jdanyow]: https://github.com/jdanyow 352 | [pull/34]: https://github.com/cloudflare/workers-types/pull/34 353 | [issue/33]: https://github.com/cloudflare/workers-types/issues/33 354 | 355 | ### Features 356 | 357 | - **Add Cache behavior modifiers to outbound Requests - [@trjstewart], [issue/22], [pull/17]** 358 | 359 | When constructing a request, you can now include the following cache-manipulating properties in the initializer dictionary: 360 | 361 | ```typescript 362 | // Force response to be cached for 300 seconds. 363 | fetch(event.request, { cf: { cacheTtl: 300 } }); 364 | 365 | // Force response to be cached for 86400 seconds for 200 status codes, 1 second for 404, and do not cache 500 errors 366 | fetch(request, { 367 | cf: { cacheTtlByStatus: { "200-299": 86400, "404": 1, "500-599": 0 } } 368 | }); 369 | ``` 370 | 371 | Read more about these properties in the [`Request` docs](https://developers.cloudflare.com/workers/reference/apis/request/). 372 | 373 | [@trjstewart]: https://github.com/trjstewart 374 | [pull/17]: https://github.com/cloudflare/workers-types/pull/17 375 | [issue/22]: https://github.com/cloudflare/workers-types/issues/22 376 | 377 | - **Add support for `caches.default` - [@ispivey], [@ashnewmanjones], [issue/8], [pull/21]** 378 | 379 | The Workers runtime exposes a default global cache as `caches.default`, accessed like: 380 | 381 | ```typescript 382 | let cache = caches.default; 383 | ``` 384 | 385 | This is an extension to the [Service Workers spec for `CacheStorage`](https://w3c.github.io/ServiceWorker/#cachestorage), and thus needed to be added explicitly to our type definitions. 386 | 387 | [@ispivey]: https://github.com/ispivey 388 | [@ashnewmanjones]: https://github.com/ashnewmanjones 389 | [pull/21]: https://github.com/cloudflare/workers-types/pull/21 390 | [issue/8]: https://github.com/cloudflare/workers-types/issues/8 391 | 392 | - **Add missing properties to inbound `Request` `cf` object - [@ispivey], [@brycematheson1234], [issue/23], [pull/24], [pull/35]** 393 | 394 | Adds: 395 | 396 | - `clientTcpRtt` 397 | - `metroCode` 398 | - `botManagement.score` 399 | - `botManagement.staticResource` 400 | - `botManagement.verifiedBot` 401 | 402 | Makes most geolocation properties optional, because they are not guaranteed to be set on every request. 403 | 404 | Changes the type of `asn` from string to number. 405 | 406 | [@ispivey]: https://github.com/ispivey 407 | [@brycematheson1234]: https://github.com/brycematheson1234 408 | [issue/23]: https://github.com/cloudflare/workers-types/issues/23 409 | [pull/24]: https://github.com/cloudflare/workers-types/pull/24 410 | [pull/35]: https://github.com/cloudflare/workers-types/pull/35 411 | 412 | - **Adds `cf.cacheKey` property to `RequestInit` - [@ispivey], [issue/22], [pull/28]** 413 | 414 | Adds the `cacheKey` property of the `cf` object to the `RequestInit` interface. 415 | 416 | [@ispivey]: https://github.com/ispivey 417 | [pull/28]: https://github.com/cloudflare/workers-types/pull/28 418 | [issue/22]: https://github.com/cloudflare/workers-types/issues/22 419 | 420 | - **Allow passing another Request as the `init` arg to `Request` constructor - [@ispivey], [issue/15], [pull/18]** 421 | 422 | Previously, this pattern wasn't allowed: 423 | 424 | ```typescript 425 | new Request(parsedUrl.toString(), request); 426 | ``` 427 | 428 | This is because the `cf` object on inbound Request objects, and that expected in the `init` dictionary arg to the Request constructor, have a different shape. 429 | 430 | This change creates explicit `IncomingRequestCfProperties` (inbound) and `RequestInitCfProperties` (outbound) interfaces, and updates the `Request` constructor to accept either type: 431 | 432 | ```typescript 433 | interface RequestInit { 434 | cf?: RequestInitCfProperties | IncomingRequestCfProperties; 435 | } 436 | ``` 437 | 438 | Read more about the `Request` constructor in the [`Request` docs](https://developers.cloudflare.com/workers/reference/apis/request/). 439 | 440 | [@ispivey]: https://github.com/ispivey 441 | [pull/18]: https://github.com/cloudflare/workers-types/pull/18 442 | [issue/15]: https://github.com/cloudflare/workers-types/issues/15 443 | 444 | - **Add `CfRequestInit` type - [@third774], [issue/37], [pull/44]** 445 | 446 | Because of the union mentioned above, if an object is declared as `RequestInit` and sets the `cf` property, subproperties of `cf` can not later be reassigned. For this scenario, a more specific `CfRequestInit` type has been introduced to use instead of `RequestInit` that doesn't exhibit the same assignability issues. 447 | 448 | [@third774]: https://github.com/third774 449 | [pull/44]: https://github.com/cloudflare/workers-types/pull/44 450 | [issue/37]: https://github.com/cloudflare/workers-types/issues/37 451 | 452 | - **Add iterable methods to `FormData`, `Headers`, and `URLSearchParams` - [@ispivey], [issue/25], [pull/26]** 453 | 454 | The iterable methods `entries()`, `keys()` and `values()` are not present on these three types in `lib.webworker.d.ts`. They are instead supplied in `lib.dom.iterable.d.ts`. 455 | 456 | However, as discussed in this issue on the TypeScript repo, `lib.dom.d.ts` and `lib.webworker.d.ts` have conflicting type definitions, and the maintainers hope to solve this issue by refactoring shared components into a new `web.iterable.d.ts` lib: [https://github.com/microsoft/TypeScript/issues/32435#issuecomment-624741120](https://github.com/microsoft/TypeScript/issues/32435#issuecomment-624741120) 457 | 458 | Until then, we will include the iterable methods supported by Workers in our own type definitions. 459 | 460 | [@ispivey]: https://github.com/ispivey 461 | [pull/26]: https://github.com/cloudflare/workers-types/pull/26 462 | [issue/25]: https://github.com/cloudflare/workers-types/issues/25 463 | 464 | ### Bugfixes 465 | 466 | - **Remove `selector` parameter from `onDocument()` - [@jdanyow], [pull/41]** 467 | 468 | The type signature for HTMLRewriter's `onDocument()` method previously erroneously included a `selector` parameter as its first argument. This has been removed. 469 | 470 | [@jdanyow]: https://github.com/jdanyow 471 | [pull/41]: https://github.com/cloudflare/workers-types/pull/41 472 | 473 | - **Make `KVNamespace.list()` options argument optional - [@motiejunas], [pull/10]** 474 | 475 | Previously, the `KVNamespace` interface required that callers provide an empty options object when listing all the keys in a namespace, like so: 476 | 477 | ```typescript 478 | await NAMESPACE.list({}); 479 | ``` 480 | 481 | However, this argument is not actually required. This change updates the interface to match the runtime. 482 | 483 | [@motiejunas]: https://github.com/motiejunas 484 | [pull/10]: https://github.com/cloudflare/workers-types/pull/10 485 | 486 | ### Maintenance 487 | 488 | - **Add a Release Checklist - [@ispivey], [issue/20], [pull/27]** 489 | 490 | As we onboard more contributors, we're documenting release procedures. 491 | 492 | [@ispivey]: https://github.com/ispivey 493 | [pull/27]: https://github.com/cloudflare/workers-types/pull/27 494 | [issue/20]: https://github.com/cloudflare/workers-types/issues/20 495 | 496 | - **Add BSD-3 License - [@ispivey], [issue/31], [pull/30], [pull/40]** 497 | 498 | As we transition this to a project supported by the Cloudflare Workers team, we're releasing the code under a BSD-3 license. Thanks to all the contributors for their help! 499 | 500 | [@ispivey]: https://github.com/ispivey 501 | [pull/30]: https://github.com/cloudflare/workers-types/pull/30 502 | [pull/40]: https://github.com/cloudflare/workers-types/pull/40 503 | [issue/31]: https://github.com/cloudflare/workers-types/issues/31 504 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2020, Cloudflare, Inc. and contributors 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cloudflare Workers Types 2 | 3 | :stop_sign: This repository was for `@cloudflare/workers-types` versions ≤ 3 and is no longer maintained. 4 | 5 | Since version 4, types are automatically generated from and in the [`workerd`](https://github.com/cloudflare/workerd) repository. 6 | 7 | Find the [new `README` here](https://github.com/cloudflare/workerd/tree/main/npm/workers-types) and the [new auto-generation scripts here](https://github.com/cloudflare/workerd/tree/main/types). 8 | 9 | Please raise issues with type definitions [in the `workerd` repository](https://github.com/cloudflare/workerd/issues/new/choose), tagging `@cloudflare/workers-types` in your report. 10 | 11 | --- 12 | 13 |
14 | Legacy Documentation 15 | 16 | ## Install 17 | 18 | ```bash 19 | npm install -D @cloudflare/workers-types 20 | -- Or 21 | yarn add -D @cloudflare/workers-types 22 | ``` 23 | 24 | ## Usage 25 | 26 | > :warning: If you're upgrading from version 2, make sure to remove `webworker` from the `lib` array in your 27 | > `tsconfig.json`. These types are now included in `@cloudflare/workers-types`. 28 | 29 | The following is a minimal `tsconfig.json` for use alongside this package: 30 | 31 | **`tsconfig.json`** 32 | 33 | ```json 34 | { 35 | "compilerOptions": { 36 | "target": "ES2020", 37 | "module": "CommonJS", 38 | "lib": ["ES2020"], 39 | "types": ["@cloudflare/workers-types"] 40 | } 41 | } 42 | ``` 43 | 44 | ### Using bindings 45 | 46 | It's recommended that you create an ambient type file for any bindings your Worker uses. Create a file named 47 | `bindings.d.ts` in your src directory: 48 | 49 | **`bindings.d.ts`** 50 | 51 | ```typescript 52 | export {}; 53 | 54 | declare global { 55 | const MY_ENV_VAR: string; 56 | const MY_SECRET: string; 57 | const myKVNamespace: KVNamespace; 58 | } 59 | ``` 60 | 61 | ## Auto-Generation 62 | 63 | Types are automatically generated from the Workers runtime's source code on every release. However, these generated 64 | types don't include any generics or overloads, so to improve ergonomics, some of them are overridden. 65 | 66 | The [`overrides`](./overrides) directory contains partial TypeScript declarations. If an override has a different type 67 | classification than its generated counterpart – for example, an `interface` is declared to override a generated `class` 68 | definition – then the override is used instead of the generated output. However, if they're the same type classification 69 | (e.g. both the override and the generated output are using `class`), then their member properties are merged: 70 | 71 | - Members in the override but not in the generated type are included in the output 72 | - If a member in the override has the same name as one in the generated type, the generated one is removed from the 73 | output, and the override is included instead 74 | - If the member is declared type `never` in the override, it is removed from the output 75 | 76 | If a named type override is declared as a type alias to `never`, that named type is removed from the output. 77 | 78 | JSDoc comments from overrides will also be copied over to the output. 79 | 80 | Comment overrides can also be written in Markdown. The [`docs`](./docs) directory contains these overrides. 81 | 2nd level headings are the names of top level declarations (e.g. ## \`KVNamespace\`), 82 | 3rd level headings are for member names (e.g. ### \`KVNamespace#put\`), and 4th level 83 | headings correspond to JSDoc sections for members: 84 | 85 | - `#### Parameters`: a list with parameters of the form - \`param\`: param description, these will be 86 | formatted as `@param` tags 87 | - `#### Returns`: contents will be copied as-is to the `@returns` tag 88 | - `#### Examples`: fenced code blocks with the language set to `js`, `ts`, `javascript` or `typescript` will be copied 89 | to `@example` tags 90 | 91 |
92 | -------------------------------------------------------------------------------- /RELEASE_CHECKLIST.md: -------------------------------------------------------------------------------- 1 | # Release Checklist 2 | 3 | This is a list of the things that need to happen during a release. 4 | 5 | ## Build a Release 6 | 7 | ### Prepare the Changelog 8 | 9 | 1. Go through the PR history since the last release. You can use this to show all the PRs that are merged on or after 10 | YYY-MM-DD: `https://github.com/issues?q=repo%3Acloudflare%2Fworkers-types+merged%3A%3E%3DYYYY-MM-DD` 11 | 1. Add this release to `CHANGELOG.md`. Use the structure of previous entries. 12 | 13 | ### Start a release PR 14 | 15 | 1. Create a new branch "#.#.#" where "#.#.#" is this release's version (release) or "#.#.#-rc.#" (release candidate) 16 | 1. Update the version number in `package.json`. 17 | 1. Push up a commit with the `CHANGELOG.md` changes. The commit message can just be "#.#.#" (release) or "#.#.#-rc.#" 18 | (release candidate) 19 | 1. Request review from maintainers. 20 | 21 | ### Review 22 | 23 | Most of your comments will be about the changelog. Once the PR is finalized and approved... 24 | 25 | 1. If you made changes, squash or fixup all changes into a single commit. 26 | 1. Run `git push` and wait for CI to pass. 27 | 28 | ### Tag and build release 29 | 30 | 1. Once ready to merge, tag the commit by running `git tag -a v#.#.# -m #.#.#` 31 | 1. Run `git push --tags`. 32 | 1. Wait for CI to pass. 33 | 34 | ### Edit the release 35 | 36 | Draft a new release on the [releases page](https://github.com/cloudflare/workers-types/releases) and update release 37 | notes. 38 | 39 | ### Publish to npm 40 | 41 | Full releases are tagged `latest`. If for some reason you mix up the commands below, follow the troubleshooting guide. 42 | 43 | 1. `npm publish`. 44 | 1. Tweet. 45 | 46 | ## Troubleshooting a release 47 | 48 | Mistakes happen. Most of these release steps are recoverable if you mess up. The goal is not to, but if you find 49 | yourself cursing a fat fingered command, here are some troubleshooting tips. Please feel free to add to this guide. 50 | 51 | ### I pushed the wrong tag 52 | 53 | Tags and releases can be removed in GitHub. First, 54 | [remove the remote tag](https://stackoverflow.com/questions/5480258/how-to-delete-a-remote-tag): 55 | 56 | ```console 57 | $ git push --delete origin tagname 58 | ``` 59 | 60 | This will turn the release into a `draft` and you can delete it from the edit page. 61 | 62 | Make sure you also delete the local tag: 63 | 64 | ```console 65 | $ git tag --delete vX.X.X 66 | ``` 67 | -------------------------------------------------------------------------------- /docs/kv.md: -------------------------------------------------------------------------------- 1 | # KV 2 | 3 | ## `KVNamespace` 4 | 5 | Workers KV is a global, low-latency, key-value data store. It supports exceptionally high read volumes with low-latency, 6 | making it possible to build highly dynamic APIs and websites which respond as quickly as a cached static file would. 7 | 8 | ### `KVNamespace#put` 9 | 10 | Creates a new key-value pair, or updates the value for a particular key. 11 | 12 | #### Parameters 13 | 14 | - `key`: key to associate with the value. A key cannot be empty, `.` or `..`. All other keys are valid. 15 | - `value`: value to store. The type is inferred. The maximum size of a value is 25MB. 16 | 17 | #### Returns 18 | 19 | Returns a `Promise` that you should `await` on in order to verify a successful update. 20 | 21 | #### Examples 22 | 23 | ```js 24 | await NAMESPACE.put(key, value); 25 | ``` 26 | -------------------------------------------------------------------------------- /export/docs.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import * as fs from "fs"; 3 | import * as path from "path"; 4 | // marked is great for this: it includes the raw text in its tokens so 5 | // we don't need to write code that renders tokens back to markdown 6 | import { marked } from "marked"; 7 | import { Comment, CommentParam } from "./types"; 8 | 9 | interface CommentedField { 10 | name: string; 11 | comment?: Comment; 12 | } 13 | 14 | interface CommentedDeclaration { 15 | name: string; 16 | comment?: Comment; 17 | members?: CommentedField[]; 18 | } 19 | 20 | // Get files to build docs from 21 | const docsDir = path.join(__dirname, "..", "docs"); 22 | const filePaths = fs 23 | .readdirSync(docsDir) 24 | .map((fileName) => path.join(docsDir, fileName)); 25 | 26 | // Maps fenced code-block languages to those recognised by declaration renderers 27 | const exampleLangRenames = { 28 | js: "typescript", 29 | ts: "typescript", 30 | javascript: "typescript", 31 | rs: "rust", 32 | }; 33 | 34 | function trimComment(comment?: Comment) { 35 | if (comment === undefined) return; 36 | comment.text = comment.text.trim(); 37 | if (comment.params) { 38 | comment.params = comment.params.map(({ name, text }) => ({ 39 | name, 40 | text: text.trim(), 41 | })); 42 | } 43 | if (comment.returns) { 44 | comment.returns = comment.returns.trim(); 45 | } 46 | } 47 | 48 | const declarations: Record = {}; 49 | let declaration: CommentedDeclaration | undefined = undefined; 50 | let field: CommentedField | undefined = undefined; 51 | 52 | enum FieldState { 53 | // Enum member names must case-sensitive match expected 4th level heading texts 54 | Parameters, 55 | Returns, 56 | Examples, 57 | } 58 | let fieldState: FieldState | undefined = undefined; 59 | 60 | function pushDeclaration() { 61 | /// Adds the current declaration (if any) to the map 62 | if (declaration !== undefined) { 63 | trimComment(declaration.comment); 64 | declarations[declaration.name] = declaration; 65 | 66 | declaration = undefined; 67 | fieldState = undefined; 68 | } 69 | } 70 | 71 | function pushField() { 72 | /// Adds the current field (if any) to the current declaration 73 | if (declaration !== undefined && field !== undefined) { 74 | trimComment(field.comment); 75 | declaration.members ??= []; 76 | declaration.members.push(field); 77 | 78 | field = undefined; 79 | fieldState = undefined; 80 | } 81 | } 82 | 83 | for (const filePath of filePaths) { 84 | const tokens = marked.lexer(fs.readFileSync(filePath, "utf8")); 85 | 86 | for (const token of tokens) { 87 | if (token.type === "heading" && token.depth === 2) { 88 | // New declaration 89 | pushDeclaration(); 90 | // token.text === "`Declaration`" 91 | declaration = { name: token.text.substring(1, token.text.length - 1) }; 92 | continue; 93 | } else if (declaration === undefined) { 94 | // If this isn't a new declaration, wait until we've got a declaration to add to 95 | continue; 96 | } 97 | 98 | if (token.type === "heading" && token.depth === 3) { 99 | // New field 100 | pushField(); 101 | // token.text === "`Declaration.field`" or "`Declaration#field`" 102 | field = { 103 | name: token.text.substring( 104 | 1 + declaration.name.length + 1, 105 | token.text.length - 1 106 | ), 107 | }; 108 | continue; 109 | } 110 | 111 | if (field && token.type === "heading" && token.depth === 4) { 112 | fieldState = undefined; 113 | if (token.text in FieldState) { 114 | fieldState = FieldState[token.text]; 115 | continue; 116 | } 117 | } 118 | 119 | if ( 120 | field && 121 | fieldState === FieldState.Parameters && 122 | token.type === "list" 123 | ) { 124 | // Field parameters 125 | field.comment ??= { text: "" }; 126 | field.comment.params ??= []; 127 | field.comment.params.push( 128 | ...token.items.map((item) => { 129 | // item.text === "`name`: text" (text will be trimmed later by trimComment) 130 | const colon = item.text.indexOf(":"); 131 | return { 132 | name: item.text.substring(1, colon - 1), 133 | text: item.text.substring(colon + 1), 134 | }; 135 | }) 136 | ); 137 | continue; 138 | } 139 | 140 | if (field && fieldState === FieldState.Returns) { 141 | // Field returns 142 | field.comment ??= { text: "" }; 143 | field.comment.returns ??= ""; 144 | field.comment.returns += token.raw; 145 | continue; 146 | } 147 | 148 | if (field && fieldState === FieldState.Examples && token.type === "code") { 149 | // Field examples 150 | if (!token.lang) continue; 151 | let lang = token.lang; 152 | if (lang in exampleLangRenames) lang = exampleLangRenames[lang]; 153 | field.comment ??= { text: "" }; 154 | field.comment.examples ??= {}; 155 | field.comment.examples[lang] ??= []; 156 | field.comment.examples[lang].push(token.text); 157 | continue; 158 | } 159 | 160 | // If we're in a field, add comments to that, otherwise add them to the declaration itself 161 | if (field) { 162 | field.comment ??= { text: "" }; 163 | field.comment.text += token.raw; 164 | } else if (declaration) { 165 | declaration.comment ??= { text: "" }; 166 | declaration.comment.text += token.raw; 167 | } 168 | } 169 | 170 | // Record final field and declaration (if any) 171 | pushField(); 172 | pushDeclaration(); 173 | } 174 | 175 | fs.writeFileSync("docs.json", JSON.stringify(declarations, null, 2), "utf8"); 176 | -------------------------------------------------------------------------------- /export/overrides.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import * as assert from "assert"; 3 | import * as fs from "fs"; 4 | import * as path from "path"; 5 | import * as ts from "typescript"; 6 | import { 7 | Type, 8 | TypeParam, 9 | Comment, 10 | Field, 11 | Class, 12 | Struct, 13 | TypeDef, 14 | Function, 15 | Variable, 16 | } from "./types"; 17 | 18 | // Get files to build overrides from 19 | const publicOverridesDir = path.join(__dirname, "..", "overrides"); 20 | const filePaths = fs 21 | .readdirSync(publicOverridesDir) 22 | .map((fileName) => path.join(publicOverridesDir, fileName)); 23 | // Additional internal overrides 24 | for (const argPath of process.argv.slice(2)) { 25 | const additionalOverridesDir = path.resolve(argPath); 26 | filePaths.push( 27 | ...fs 28 | .readdirSync(additionalOverridesDir) 29 | .map((fileName) => path.join(additionalOverridesDir, fileName)) 30 | ); 31 | } 32 | 33 | // Parse file into AST 34 | const program = ts.createProgram(filePaths, { 35 | noResolve: true, 36 | target: ts.ScriptTarget.Latest, 37 | }); 38 | 39 | const keywordTypes = new Set([ 40 | ts.SyntaxKind.NeverKeyword, 41 | ts.SyntaxKind.VoidKeyword, 42 | ts.SyntaxKind.NullKeyword, 43 | ts.SyntaxKind.UndefinedKeyword, 44 | ts.SyntaxKind.BooleanKeyword, 45 | ts.SyntaxKind.NumberKeyword, 46 | ts.SyntaxKind.StringKeyword, 47 | ts.SyntaxKind.AnyKeyword, 48 | ts.SyntaxKind.UnknownKeyword, 49 | ]); 50 | 51 | type Declaration = Class | Struct | TypeDef | Function | Variable; 52 | const declarations: Record = {}; 53 | 54 | for (const filePath of filePaths) { 55 | const sourceFile = program.getSourceFile(filePath); 56 | assert.ok(sourceFile); 57 | 58 | function getPos(pos: number): string { 59 | assert.ok(sourceFile); 60 | const mapped = sourceFile.getLineAndCharacterOfPosition(pos); 61 | return `${filePath}:${mapped.line + 1}:${mapped.character + 1}`; 62 | } 63 | 64 | function convertType(type?: ts.TypeNode): Type { 65 | if (type === undefined) { 66 | return { name: "any" }; 67 | } else if (keywordTypes.has(type.kind)) { 68 | return { name: type.getText(sourceFile) }; 69 | } else if (ts.isLiteralTypeNode(type)) { 70 | return { name: type.literal.getText(sourceFile) }; 71 | } else if (ts.isTypeReferenceNode(type)) { 72 | return { 73 | name: type.typeName.getText(sourceFile), 74 | args: type.typeArguments?.map(convertType), 75 | }; 76 | } else if (ts.isArrayTypeNode(type)) { 77 | return { 78 | name: "[]", 79 | args: [convertType(type.elementType)], 80 | }; 81 | } else if (ts.isUnionTypeNode(type)) { 82 | return { 83 | name: "|", 84 | args: type.types.map(convertType), 85 | }; 86 | } else if (ts.isTupleTypeNode(type)) { 87 | return { 88 | name: "()", 89 | params: type.elements.map(convertTupleMember), 90 | }; 91 | } else if (ts.isFunctionTypeNode(type)) { 92 | const params = type.parameters.map(convertParameter); 93 | const returns = convertType(type.type); 94 | return { params, returns }; 95 | } else if (ts.isTypeQueryNode(type)) { 96 | return { 97 | name: "typeof", 98 | args: [{ name: type.exprName.getText(sourceFile) }], 99 | }; 100 | } else if ( 101 | ts.isTypeOperatorNode(type) && 102 | type.operator === ts.SyntaxKind.KeyOfKeyword 103 | ) { 104 | return { 105 | name: "keyof", 106 | args: [{ name: type.type.getText(sourceFile) }], 107 | }; 108 | } else if (ts.isTypeLiteralNode(type)) { 109 | return { 110 | members: type.members.map(convertMember), 111 | }; 112 | } else if (ts.isIndexedAccessTypeNode(type)) { 113 | const objectType = convertType(type.objectType); 114 | objectType.index = convertType(type.indexType); 115 | return objectType; 116 | } else if (ts.isParenthesizedTypeNode(type)) { 117 | return convertType(type.type); 118 | } 119 | throw new TypeError( 120 | `unrecognised type at ${getPos(type.pos)}: ${type.getText(sourceFile)}` 121 | ); 122 | } 123 | 124 | function convertTupleMember(node: ts.TypeNode | ts.NamedTupleMember): Field { 125 | if (ts.isNamedTupleMember(node)) { 126 | return { 127 | name: node.name.getText(sourceFile), 128 | type: convertType(node.type), 129 | }; 130 | } else { 131 | return { name: "", type: convertType(node) }; 132 | } 133 | } 134 | 135 | function convertTypeParams( 136 | nodes?: ts.NodeArray 137 | ): TypeParam[] | undefined { 138 | return nodes?.map((node) => ({ 139 | name: node.name.getText(sourceFile), 140 | constraint: node.constraint && convertType(node.constraint), 141 | default: node.default && convertType(node.default), 142 | })); 143 | } 144 | 145 | function convertCommentText( 146 | text?: string | ts.NodeArray 147 | ): string | undefined { 148 | if (text === undefined || typeof text === "string") { 149 | return text?.toString(); 150 | } else { 151 | return text.map((part) => part.text).join(" "); 152 | } 153 | } 154 | 155 | function convertComment(node: ts.Node): Comment | undefined { 156 | // @ts-expect-error jsDoc is marked as @internal 157 | const jsDocs = node.jsDoc as ts.JSDoc[]; 158 | if (jsDocs === undefined || jsDocs.length === 0) return undefined; 159 | const jsDoc = jsDocs[jsDocs.length - 1]; 160 | const comment: Comment = { text: convertCommentText(jsDoc.comment) ?? "" }; 161 | for (const tag of jsDoc.tags ?? []) { 162 | if (ts.isJSDocParameterTag(tag)) { 163 | comment.params ??= []; 164 | comment.params.push({ 165 | name: tag.name.getText(sourceFile), 166 | text: convertCommentText(tag.comment) ?? "", 167 | }); 168 | } else if (ts.isJSDocReturnTag(tag)) { 169 | comment.returns = convertCommentText(tag.comment); 170 | } else if (ts.isJSDocDeprecatedTag(tag)) { 171 | comment.deprecated = convertCommentText(tag.comment); 172 | } else if ( 173 | ts.isJSDocUnknownTag(tag) && 174 | tag.tagName.escapedText === "rename" 175 | ) { 176 | // Typedef is a pure rename. Old name isn't around anymore. 177 | comment.renamed = true; 178 | } else if ( 179 | ts.isJSDocUnknownTag(tag) && 180 | tag.tagName.escapedText === "inline" 181 | ) { 182 | // Typedef is force inlined everywhere and will not be emitted. 183 | comment.inlined = true; 184 | } 185 | } 186 | return comment; 187 | } 188 | 189 | function convertParameter(node: ts.ParameterDeclaration): Field { 190 | const name = node.name.getText(sourceFile); 191 | const type = convertType(node.type); 192 | if (node.dotDotDotToken) type.variadic = true; 193 | type.optional = node.questionToken && true; 194 | return { name, type }; 195 | } 196 | 197 | function convertConstructor(node: ts.ConstructorDeclaration): Field { 198 | const params = node.parameters.map(convertParameter); 199 | const type: Type = { params }; 200 | const comment = convertComment(node); 201 | return { name: "constructor", type, comment }; 202 | } 203 | 204 | function convertFieldMeta( 205 | node: 206 | | ts.MethodSignature 207 | | ts.MethodDeclaration 208 | | ts.PropertySignature 209 | | ts.PropertyDeclaration 210 | | ts.FunctionDeclaration 211 | | ts.ConstructSignatureDeclaration 212 | ): Partial { 213 | const comment = convertComment(node); 214 | const meta: Partial = { comment }; 215 | for (const modifier of node.modifiers ?? []) { 216 | if (modifier.kind == ts.SyntaxKind.StaticKeyword) { 217 | meta.static = true; 218 | } else if (modifier.kind == ts.SyntaxKind.ReadonlyKeyword) { 219 | meta.readonly = true; 220 | } 221 | } 222 | return meta; 223 | } 224 | 225 | function convertMethod( 226 | node: 227 | | ts.MethodSignature 228 | | ts.MethodDeclaration 229 | | ts.FunctionDeclaration 230 | | ts.ConstructSignatureDeclaration 231 | ): Field { 232 | const defaultName = ts.isConstructSignatureDeclaration(node) ? "new" : ""; 233 | const name = node.name?.getText(sourceFile) ?? defaultName; 234 | const params = node.parameters.map(convertParameter); 235 | const returns = convertType(node.type); 236 | const optional = node.questionToken && true; 237 | const type: Type = { params, returns, optional }; 238 | const meta = convertFieldMeta(node); 239 | const typeparams = convertTypeParams(node.typeParameters); 240 | return { name, type, ...meta, typeparams }; 241 | } 242 | 243 | function convertProperty( 244 | node: ts.PropertySignature | ts.PropertyDeclaration 245 | ): Field { 246 | const name = node.name.getText(sourceFile); 247 | const type = convertType(node.type); 248 | type.optional = node.questionToken && true; 249 | const meta = convertFieldMeta(node); 250 | return { name, type, ...meta }; 251 | } 252 | 253 | function convertIndexSignature(node: ts.IndexSignatureDeclaration): Field { 254 | assert.ok(node.parameters.length == 1); 255 | const name = `[${node.parameters[0].getText(sourceFile)}]`; 256 | const type = convertType(node.type); 257 | return { name, type }; 258 | } 259 | 260 | function convertMember(node: ts.Node): Field { 261 | if (ts.isConstructorDeclaration(node)) { 262 | return convertConstructor(node); 263 | } 264 | if ( 265 | ts.isMethodSignature(node) || 266 | ts.isMethodDeclaration(node) || 267 | ts.isConstructSignatureDeclaration(node) 268 | ) { 269 | return convertMethod(node); 270 | } 271 | if (ts.isPropertySignature(node) || ts.isPropertyDeclaration(node)) { 272 | return convertProperty(node); 273 | } 274 | if (ts.isIndexSignatureDeclaration(node)) { 275 | return convertIndexSignature(node); 276 | } 277 | throw new TypeError( 278 | `unrecognised member at ${getPos(node.pos)}: ${node.getText(sourceFile)}` 279 | ); 280 | } 281 | 282 | function convertHeritageClause(node: ts.HeritageClause): Type[] { 283 | return node.types.map((type) => ({ 284 | name: type.expression.getText(sourceFile), 285 | args: type.typeArguments && type.typeArguments.map(convertType), 286 | })); 287 | } 288 | 289 | function convertHeritageClauses( 290 | nodes?: ts.NodeArray 291 | ): Pick { 292 | const heritage: Pick = {}; 293 | for (const node of nodes ?? []) { 294 | if (node.token === ts.SyntaxKind.ExtendsKeyword) { 295 | heritage.extends ??= []; 296 | heritage.extends.push(...convertHeritageClause(node)); 297 | } else if (node.token === ts.SyntaxKind.ImplementsKeyword) { 298 | heritage.implements ??= []; 299 | heritage.implements.push(...convertHeritageClause(node)); 300 | } 301 | } 302 | return heritage; 303 | } 304 | 305 | function convertClass(node: ts.ClassDeclaration): Class { 306 | assert.ok(node.name); 307 | const name = node.name.escapedText.toString(); 308 | const members = node.members.map(convertMember); 309 | const typeparams = convertTypeParams(node.typeParameters); 310 | const heritage = convertHeritageClauses(node.heritageClauses); 311 | const comment = convertComment(node); 312 | return { 313 | kind: "class", 314 | name, 315 | members, 316 | typeparams, 317 | ...heritage, 318 | comment, 319 | }; 320 | } 321 | 322 | function convertStruct(node: ts.InterfaceDeclaration): Struct { 323 | const name = node.name.escapedText.toString(); 324 | const members = node.members.map(convertMember); 325 | const typeparams = convertTypeParams(node.typeParameters); 326 | const heritage = convertHeritageClauses(node.heritageClauses); 327 | const comment = convertComment(node); 328 | return { 329 | kind: "struct", 330 | name, 331 | members, 332 | typeparams, 333 | extends: heritage.extends, 334 | comment, 335 | }; 336 | } 337 | 338 | function convertTypeDef(node: ts.TypeAliasDeclaration): TypeDef { 339 | const name = node.name.escapedText.toString(); 340 | const type = convertType(node.type); 341 | const typeparams = convertTypeParams(node.typeParameters); 342 | const comment = convertComment(node); 343 | return { 344 | kind: "typedef", 345 | name, 346 | type, 347 | typeparams, 348 | comment, 349 | }; 350 | } 351 | 352 | function convertFunction(node: ts.FunctionDeclaration): Function { 353 | const { name, type, typeparams, comment } = convertMethod(node); 354 | return { 355 | kind: "function", 356 | name, 357 | type, 358 | typeparams, 359 | comment, 360 | }; 361 | } 362 | 363 | function convertVariableDeclaration(node: ts.VariableDeclaration): Variable { 364 | const name = node.name.getText(sourceFile); 365 | const type = convertType(node.type); 366 | const comment = convertComment(node); 367 | return { 368 | kind: "variable", 369 | name, 370 | type, 371 | comment, 372 | }; 373 | } 374 | 375 | function convertVariable(node: ts.VariableStatement): Variable[] { 376 | return node.declarationList.declarations.map(convertVariableDeclaration); 377 | } 378 | 379 | function convertStatement(node: ts.Statement): Declaration[] { 380 | if (ts.isClassDeclaration(node)) { 381 | return [convertClass(node)]; 382 | } else if (ts.isInterfaceDeclaration(node)) { 383 | return [convertStruct(node)]; 384 | } else if (ts.isTypeAliasDeclaration(node)) { 385 | return [convertTypeDef(node)]; 386 | } else if (ts.isFunctionDeclaration(node)) { 387 | return [convertFunction(node)]; 388 | } else if (ts.isVariableStatement(node)) { 389 | return convertVariable(node); 390 | } 391 | throw new TypeError( 392 | `unrecognised statement at ${getPos(node.pos)}: ${node.getText( 393 | sourceFile 394 | )}` 395 | ); 396 | } 397 | 398 | /** 399 | * Merge nodes that have the same name. 400 | * @param node1: The current node in the overrides. 401 | * @param node2: The node with the same name we encountered. 402 | * @return True if node2 was merged into node1. False if node1 doesn't exist and thus node2 403 | * just needs to be inserted. 404 | */ 405 | function merge(node1: Declaration | undefined, node2: Declaration): boolean { 406 | if (node1 === undefined) { 407 | return false; 408 | } 409 | 410 | assert.strictEqual(node1.name, node2.name); 411 | 412 | if (node1.kind !== node2.kind) { 413 | throw new TypeError( 414 | `Conflicting types for ${node1.name}: ${node1.kind} vs ${node2.kind}` 415 | ); 416 | } 417 | switch (node1.kind) { 418 | case "typedef": 419 | case "function": 420 | case "variable": 421 | throw new TypeError( 422 | `Two ${node1.kind}s with the same name ${node1.name}` 423 | ); 424 | case "struct": 425 | case "class": 426 | if (node1.extends !== node2.extends) { 427 | throw new TypeError( 428 | `Conflicting extends values for multiple overrides of ${node1.name}` 429 | ); 430 | } 431 | if (node1.implements !== node2.implements) { 432 | throw new TypeError( 433 | `Conflicting extends values for multiple overrides of ${node1.name}` 434 | ); 435 | } 436 | for (const memberToMerge of node2.members) { 437 | node1.members.push(memberToMerge); 438 | } 439 | return true; 440 | default: { 441 | const _never: never = node1; 442 | throw new TypeError("Unexpected state"); 443 | } 444 | } 445 | } 446 | 447 | for (const statement of sourceFile.statements) { 448 | if (ts.isExportDeclaration(statement)) { 449 | // Ignore "export {}" at the end of files, we use this so TypeScript doesn't think 450 | // the override files are lib files causing name collisions 451 | continue; 452 | } 453 | const nodes = convertStatement(statement); 454 | for (const node of nodes) { 455 | let name = node.name; 456 | if (merge(declarations[name], node)) { 457 | continue; 458 | } 459 | declarations[name] = node; 460 | } 461 | } 462 | } 463 | 464 | fs.writeFileSync( 465 | "overrides.json", 466 | JSON.stringify(declarations, null, 2), 467 | "utf8" 468 | ); 469 | -------------------------------------------------------------------------------- /export/prettydiff.ts: -------------------------------------------------------------------------------- 1 | import { execSync } from "node:child_process"; 2 | import { readFileSync } from "node:fs"; 3 | 4 | const types: string = readFileSync("index.d.ts", "utf-8"); 5 | 6 | function findLineNumber(line): number | undefined { 7 | const index = types.indexOf(line.trim()); 8 | if (index !== -1) { 9 | const pre = types.substring(0, index); 10 | const lines = pre.split("\n"); 11 | return lines.length; 12 | } 13 | } 14 | 15 | function printLinkHeading(block: string) { 16 | const withoutBlockComment = block.replace(/^\s*\/\*\*.*\*\/\s*/s, ""); 17 | 18 | const name = 19 | /^( |\+)(export )?(declare function|declare type|declare const|type|declare class|interface|declare abstract class) (?[a-zA-Z0-9]+)/m.exec( 20 | withoutBlockComment 21 | ); 22 | 23 | if (name?.groups?.name) { 24 | const lineNumber = findLineNumber(name[0]); 25 | if (lineNumber) 26 | console.log(`### [${name?.[4]}](/index.d.ts#L${lineNumber})\n`); 27 | } 28 | return withoutBlockComment; 29 | } 30 | 31 | function codeBlock(lang: string, code: string) { 32 | return `\`\`\`${lang} 33 | ${code} 34 | \`\`\` 35 | `; 36 | } 37 | 38 | const lastTag = execSync( 39 | `git for-each-ref --sort=creatordate --format '%(refname)' refs/tags | tail -1` 40 | ).toString(); 41 | 42 | const secondLastTag = execSync( 43 | `git for-each-ref --sort=creatordate --format '%(refname)' refs/tags | tail -2 | head -1` 44 | ).toString(); 45 | 46 | // Get a git diff between the two most recent tags with full context 47 | const diff = execSync( 48 | `git diff --minimal --unified="$(wc -l < index.d.ts)" ${secondLastTag.trim()}:index.d.ts ${lastTag}:index.d.ts | tail -n +5` 49 | ).toString(); 50 | 51 | // Split the diff by empty line (i.e. between type definitions) 52 | // Also split by added newlines and removed newlines 53 | const blocks = diff.split(/(\n \n|\n\+\n|\n-\n)/); 54 | 55 | // Get all type definitions that have changed 56 | const diffedBlocks = blocks.filter((b) => /^(\+|-)/m.test(b)); 57 | 58 | // Get all type definitions that are purely additive 59 | const added = diffedBlocks.filter((b) => /^(\+.*\n?)+$/.test(b)); 60 | if (added.length > 0) { 61 | console.log(`## Added definitions`); 62 | added.forEach((b) => { 63 | printLinkHeading(b); 64 | console.log(codeBlock("ts", b.replace(/^\+(.*)$/gm, "$1"))); 65 | }); 66 | } 67 | 68 | // Get all type definitions that are purely deletions 69 | const removed = diffedBlocks.filter((b) => /^(-.*\n?)+$/.test(b)); 70 | if (removed.length > 0) { 71 | console.log(`## Removed definitions`); 72 | removed.forEach((b) => { 73 | console.log(codeBlock("ts", b.replace(/^-(.*)$/gm, "$1"))); 74 | }); 75 | } 76 | 77 | // Get all changes that are updates to existing definitions 78 | const updated = diffedBlocks.filter((b) => /^ /m.test(b)); 79 | if (updated.length > 0) { 80 | console.log(`## Updated definitions`); 81 | updated.forEach((b) => { 82 | const withoutBlockComment = printLinkHeading(b); 83 | console.log( 84 | codeBlock("diff", withoutBlockComment.replace(/^( .*\n)+/gm, " ...\n")) 85 | ); 86 | }); 87 | } 88 | -------------------------------------------------------------------------------- /export/types.ts: -------------------------------------------------------------------------------- 1 | // Types defined in autodecl/types.py 2 | 3 | export interface Type { 4 | name?: string; 5 | args?: Type[]; 6 | index?: Type; 7 | params?: Field[]; 8 | members?: Field[]; 9 | returns?: Type; 10 | optional?: boolean; 11 | variadic?: boolean; 12 | } 13 | 14 | export interface TypeParam { 15 | name: string; 16 | constraint?: Type; 17 | default?: Type; 18 | } 19 | 20 | export interface CommentParam { 21 | name: string; 22 | text: string; 23 | } 24 | 25 | export interface Comment { 26 | text: string; 27 | deprecated?: string; 28 | renamed?: boolean; 29 | params?: CommentParam[]; 30 | returns?: string; 31 | examples?: { [language: string]: string[] }; 32 | } 33 | 34 | export interface Field { 35 | name: string; 36 | type: Type; 37 | static?: boolean; 38 | readonly?: boolean; 39 | typeparams?: TypeParam[]; 40 | comment?: Comment; 41 | } 42 | 43 | export interface Declaration { 44 | name: string; 45 | typeparams?: TypeParam[]; 46 | comment?: Comment; 47 | kind: Kind; 48 | } 49 | 50 | export interface Class extends Declaration<"class"> { 51 | members: Field[]; 52 | extends?: Type[]; 53 | implements?: Type[]; 54 | } 55 | 56 | export interface Struct extends Declaration<"struct"> { 57 | members: Field[]; 58 | extends?: Type[]; 59 | } 60 | 61 | export interface TypeDef extends Declaration<"typedef"> { 62 | type: Type; 63 | } 64 | 65 | export interface Function extends Declaration<"function"> { 66 | type: Type; 67 | } 68 | 69 | export interface Variable extends Declaration<"variable"> { 70 | type: Type; 71 | } 72 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | // This file is auto-generated. DO NOT MODIFY. 2 | // Please refer to the Auto-Generation section of the README.md. 3 | 4 | declare class AbortController { 5 | constructor(); 6 | readonly signal: AbortSignal; 7 | abort(reason?: any): void; 8 | } 9 | 10 | declare class AbortSignal extends EventTarget { 11 | constructor(); 12 | static abort(reason?: any): AbortSignal; 13 | static timeout(delay: number): AbortSignal; 14 | readonly aborted: boolean; 15 | readonly reason: any; 16 | throwIfAborted(): void; 17 | } 18 | 19 | declare class Blob { 20 | constructor(bits?: BlobBits, options?: BlobOptions); 21 | readonly size: number; 22 | readonly type: string; 23 | slice(start?: number, end?: number, type?: string): Blob; 24 | arrayBuffer(): Promise; 25 | text(): Promise; 26 | stream(): ReadableStream; 27 | } 28 | 29 | declare type BlobBits = (ArrayBuffer | string | Blob)[]; 30 | 31 | interface BlobOptions { 32 | type?: string; 33 | } 34 | 35 | declare abstract class Body { 36 | readonly body: ReadableStream | null; 37 | readonly bodyUsed: boolean; 38 | arrayBuffer(): Promise; 39 | text(): Promise; 40 | json(): Promise; 41 | formData(): Promise; 42 | blob(): Promise; 43 | } 44 | 45 | declare type BodyInit = 46 | | ReadableStream 47 | | string 48 | | ArrayBuffer 49 | | Blob 50 | | URLSearchParams 51 | | FormData; 52 | 53 | /** 54 | * Back compat for code migrating to older definitions. 55 | * @deprecated Use BodyInit instead. 56 | */ 57 | declare type BodyInitializer = BodyInit; 58 | 59 | declare class ByteLengthQueuingStrategy { 60 | constructor(init: QueuingStrategyInit); 61 | readonly highWaterMark: number; 62 | size(chunk?: any): number; 63 | } 64 | 65 | declare abstract class Cache { 66 | delete( 67 | request: Request | string, 68 | options?: CacheQueryOptions 69 | ): Promise; 70 | match( 71 | request: Request | string, 72 | options?: CacheQueryOptions 73 | ): Promise; 74 | put(request: Request | string, response: Response): Promise; 75 | } 76 | 77 | interface CacheQueryOptions { 78 | ignoreMethod?: boolean; 79 | } 80 | 81 | declare abstract class CacheStorage { 82 | open(cacheName: string): Promise; 83 | readonly default: Cache; 84 | } 85 | 86 | interface CfRequestInit extends Omit { 87 | cf?: RequestInitCfProperties; 88 | } 89 | 90 | /** 91 | * Back compat support with older types. 92 | * @deprecated Use CfRequestInit instead. 93 | */ 94 | declare type CfRequestInitializerDict = CfRequestInit; 95 | 96 | declare class CloseEvent extends Event { 97 | constructor(type: string, initializer: CloseEventInit); 98 | readonly code: number; 99 | readonly reason: string; 100 | readonly wasClean: boolean; 101 | } 102 | 103 | interface CloseEventInit { 104 | code?: number; 105 | reason?: string; 106 | wasClean?: boolean; 107 | } 108 | 109 | /** 110 | * Back compat for code migrating from older definitions. 111 | * @deprecated Use CloseEventInit instead. 112 | */ 113 | declare type CloseEventInitializer = CloseEventInit; 114 | 115 | interface Comment { 116 | text: string; 117 | readonly removed: boolean; 118 | before(content: Content, options?: ContentOptions): Comment; 119 | after(content: Content, options?: ContentOptions): Comment; 120 | replace(content: Content, options?: ContentOptions): Comment; 121 | remove(): Comment; 122 | } 123 | 124 | declare class CompressionStream extends TransformStream { 125 | constructor(format: "gzip" | "deflate"); 126 | } 127 | 128 | interface Console { 129 | debug(...data: any[]): void; 130 | error(...data: any[]): void; 131 | info(...data: any[]): void; 132 | log(...data: any[]): void; 133 | warn(...data: any[]): void; 134 | } 135 | 136 | declare type Content = string | ReadableStream | Response; 137 | 138 | interface ContentOptions { 139 | html?: boolean; 140 | } 141 | 142 | declare class CountQueuingStrategy { 143 | constructor(init: QueuingStrategyInit); 144 | readonly highWaterMark: number; 145 | size(chunk?: any): number; 146 | } 147 | 148 | declare abstract class Crypto { 149 | readonly subtle: SubtleCrypto; 150 | getRandomValues< 151 | T extends 152 | | Int8Array 153 | | Uint8Array 154 | | Int16Array 155 | | Uint16Array 156 | | Int32Array 157 | | Uint32Array 158 | | BigInt64Array 159 | | BigUint64Array 160 | >(buffer: T): T; 161 | randomUUID(): string; 162 | DigestStream: typeof DigestStream; 163 | } 164 | 165 | declare abstract class CryptoKey { 166 | readonly type: string; 167 | readonly extractable: boolean; 168 | readonly algorithm: CryptoKeyAlgorithmVariant; 169 | readonly usages: string[]; 170 | } 171 | 172 | interface CryptoKeyAesKeyAlgorithm { 173 | name: string; 174 | length: number; 175 | } 176 | 177 | declare type CryptoKeyAlgorithmVariant = 178 | | CryptoKeyKeyAlgorithm 179 | | CryptoKeyAesKeyAlgorithm 180 | | CryptoKeyHmacKeyAlgorithm 181 | | CryptoKeyRsaKeyAlgorithm 182 | | CryptoKeyEllipticKeyAlgorithm 183 | | CryptoKeyArbitraryKeyAlgorithm; 184 | 185 | interface CryptoKeyArbitraryKeyAlgorithm { 186 | name: string; 187 | hash?: CryptoKeyKeyAlgorithm; 188 | namedCurve?: string; 189 | length?: number; 190 | } 191 | 192 | interface CryptoKeyEllipticKeyAlgorithm { 193 | name: string; 194 | namedCurve: string; 195 | } 196 | 197 | interface CryptoKeyHmacKeyAlgorithm { 198 | name: string; 199 | hash: CryptoKeyKeyAlgorithm; 200 | length: number; 201 | } 202 | 203 | interface CryptoKeyKeyAlgorithm { 204 | name: string; 205 | } 206 | 207 | interface CryptoKeyPair { 208 | publicKey: CryptoKey; 209 | privateKey: CryptoKey; 210 | } 211 | 212 | interface CryptoKeyRsaKeyAlgorithm { 213 | name: string; 214 | modulusLength: number; 215 | publicExponent: ArrayBuffer; 216 | hash?: CryptoKeyKeyAlgorithm; 217 | } 218 | 219 | interface D1Database { 220 | prepare(query: string): D1PreparedStatement; 221 | dump(): Promise; 222 | batch(statements: D1PreparedStatement[]): Promise[]>; 223 | exec(query: string): Promise>; 224 | } 225 | 226 | interface D1PreparedStatement { 227 | bind(...values: any[]): D1PreparedStatement; 228 | first(colName?: string): Promise; 229 | run(): Promise>; 230 | all(): Promise>; 231 | raw(): Promise; 232 | } 233 | 234 | declare type D1Result = { 235 | results?: T[]; 236 | lastRowId: number | null; 237 | changes: number; 238 | duration: number; 239 | error?: string; 240 | }; 241 | 242 | declare class DOMException extends Error { 243 | constructor(message?: string, name?: string); 244 | readonly code: number; 245 | static readonly INDEX_SIZE_ERR: number; 246 | static readonly DOMSTRING_SIZE_ERR: number; 247 | static readonly HIERARCHY_REQUEST_ERR: number; 248 | static readonly WRONG_DOCUMENT_ERR: number; 249 | static readonly INVALID_CHARACTER_ERR: number; 250 | static readonly NO_DATA_ALLOWED_ERR: number; 251 | static readonly NO_MODIFICATION_ALLOWED_ERR: number; 252 | static readonly NOT_FOUND_ERR: number; 253 | static readonly NOT_SUPPORTED_ERR: number; 254 | static readonly INUSE_ATTRIBUTE_ERR: number; 255 | static readonly INVALID_STATE_ERR: number; 256 | static readonly SYNTAX_ERR: number; 257 | static readonly INVALID_MODIFICATION_ERR: number; 258 | static readonly NAMESPACE_ERR: number; 259 | static readonly INVALID_ACCESS_ERR: number; 260 | static readonly VALIDATION_ERR: number; 261 | static readonly TYPE_MISMATCH_ERR: number; 262 | static readonly SECURITY_ERR: number; 263 | static readonly NETWORK_ERR: number; 264 | static readonly ABORT_ERR: number; 265 | static readonly URL_MISMATCH_ERR: number; 266 | static readonly QUOTA_EXCEEDED_ERR: number; 267 | static readonly TIMEOUT_ERR: number; 268 | static readonly INVALID_NODE_TYPE_ERR: number; 269 | static readonly DATA_CLONE_ERR: number; 270 | } 271 | 272 | declare class DecompressionStream extends TransformStream { 273 | constructor(format: "gzip" | "deflate"); 274 | } 275 | 276 | declare class DigestStream extends WritableStream { 277 | constructor(algorithm: string | SubtleCryptoHashAlgorithm); 278 | readonly digest: Promise; 279 | } 280 | 281 | interface Doctype { 282 | readonly name: string | null; 283 | readonly publicId: string | null; 284 | readonly systemId: string | null; 285 | } 286 | 287 | interface DocumentEnd { 288 | append(content: Content, options?: ContentOptions): DocumentEnd; 289 | } 290 | 291 | interface DurableObject { 292 | fetch(request: Request): Promise; 293 | alarm?(): Promise; 294 | } 295 | 296 | interface DurableObjectGetAlarmOptions { 297 | allowConcurrency?: boolean; 298 | } 299 | 300 | interface DurableObjectGetOptions { 301 | allowConcurrency?: boolean; 302 | noCache?: boolean; 303 | } 304 | 305 | interface DurableObjectId { 306 | toString(): string; 307 | equals(other: DurableObjectId): boolean; 308 | readonly name?: string; 309 | } 310 | 311 | interface DurableObjectListOptions { 312 | start?: string; 313 | startAfter?: string; 314 | end?: string; 315 | prefix?: string; 316 | reverse?: boolean; 317 | limit?: number; 318 | allowConcurrency?: boolean; 319 | noCache?: boolean; 320 | } 321 | 322 | interface DurableObjectNamespace { 323 | newUniqueId( 324 | options?: DurableObjectNamespaceNewUniqueIdOptions 325 | ): DurableObjectId; 326 | idFromName(name: string): DurableObjectId; 327 | idFromString(id: string): DurableObjectId; 328 | get(id: DurableObjectId): DurableObjectStub; 329 | } 330 | 331 | interface DurableObjectNamespaceNewUniqueIdOptions { 332 | jurisdiction?: string; 333 | } 334 | 335 | interface DurableObjectPutOptions { 336 | allowConcurrency?: boolean; 337 | allowUnconfirmed?: boolean; 338 | noCache?: boolean; 339 | } 340 | 341 | interface DurableObjectSetAlarmOptions { 342 | allowConcurrency?: boolean; 343 | allowUnconfirmed?: boolean; 344 | } 345 | 346 | interface DurableObjectState { 347 | waitUntil(promise: Promise): void; 348 | id: DurableObjectId; 349 | readonly storage: DurableObjectStorage; 350 | blockConcurrencyWhile(callback: () => Promise): Promise; 351 | } 352 | 353 | interface DurableObjectStorage { 354 | get( 355 | key: string, 356 | options?: DurableObjectGetOptions 357 | ): Promise; 358 | get( 359 | keys: string[], 360 | options?: DurableObjectGetOptions 361 | ): Promise>; 362 | list( 363 | options?: DurableObjectListOptions 364 | ): Promise>; 365 | put( 366 | key: string, 367 | value: T, 368 | options?: DurableObjectPutOptions 369 | ): Promise; 370 | put( 371 | entries: Record, 372 | options?: DurableObjectPutOptions 373 | ): Promise; 374 | delete(key: string, options?: DurableObjectPutOptions): Promise; 375 | delete(keys: string[], options?: DurableObjectPutOptions): Promise; 376 | deleteAll(options?: DurableObjectPutOptions): Promise; 377 | transaction( 378 | closure: (txn: DurableObjectTransaction) => Promise 379 | ): Promise; 380 | getAlarm(options?: DurableObjectGetAlarmOptions): Promise; 381 | setAlarm( 382 | scheduledTime: number | Date, 383 | options?: DurableObjectSetAlarmOptions 384 | ): Promise; 385 | deleteAlarm(options?: DurableObjectSetAlarmOptions): Promise; 386 | sync(): Promise; 387 | } 388 | 389 | /** 390 | * 391 | * @deprecated Don't use. Introduced incidentally in workers-types 3.x. Scheduled for removal. 392 | */ 393 | declare type DurableObjectStorageOperationsGetOptions = DurableObjectGetOptions; 394 | 395 | /** 396 | * 397 | * @deprecated Don't use. Introduced incidentally in workers-types 3.x. Scheduled for removal. 398 | */ 399 | declare type DurableObjectStorageOperationsListOptions = 400 | DurableObjectListOptions; 401 | 402 | /** 403 | * 404 | * @deprecated Don't use. Introduced incidentally in workers-types 3.x. Scheduled for removal. 405 | */ 406 | declare type DurableObjectStorageOperationsPutOptions = DurableObjectPutOptions; 407 | 408 | interface DurableObjectStub extends Fetcher { 409 | readonly id: DurableObjectId; 410 | readonly name?: string; 411 | } 412 | 413 | interface DurableObjectTransaction { 414 | get( 415 | key: string, 416 | options?: DurableObjectGetOptions 417 | ): Promise; 418 | get( 419 | keys: string[], 420 | options?: DurableObjectGetOptions 421 | ): Promise>; 422 | list( 423 | options?: DurableObjectListOptions 424 | ): Promise>; 425 | put( 426 | key: string, 427 | value: T, 428 | options?: DurableObjectPutOptions 429 | ): Promise; 430 | put( 431 | entries: Record, 432 | options?: DurableObjectPutOptions 433 | ): Promise; 434 | delete(key: string, options?: DurableObjectPutOptions): Promise; 435 | delete(keys: string[], options?: DurableObjectPutOptions): Promise; 436 | rollback(): void; 437 | getAlarm(options?: DurableObjectGetAlarmOptions): Promise; 438 | setAlarm( 439 | scheduledTime: number | Date, 440 | options?: DurableObjectSetAlarmOptions 441 | ): Promise; 442 | deleteAlarm(options?: DurableObjectSetAlarmOptions): Promise; 443 | } 444 | 445 | interface Element { 446 | tagName: string; 447 | readonly attributes: IterableIterator; 448 | readonly removed: boolean; 449 | readonly namespaceURI: string; 450 | getAttribute(name: string): string | null; 451 | hasAttribute(name: string): boolean; 452 | setAttribute(name: string, value: string): Element; 453 | removeAttribute(name: string): Element; 454 | before(content: Content, options?: ContentOptions): Element; 455 | after(content: Content, options?: ContentOptions): Element; 456 | prepend(content: Content, options?: ContentOptions): Element; 457 | append(content: Content, options?: ContentOptions): Element; 458 | replace(content: Content, options?: ContentOptions): Element; 459 | remove(): Element; 460 | removeAndKeepContent(): Element; 461 | setInnerContent(content: Content, options?: ContentOptions): Element; 462 | onEndTag(handler: (tag: EndTag) => void | Promise): void; 463 | } 464 | 465 | interface EndTag { 466 | name: string; 467 | before(content: Content, options?: ContentOptions): EndTag; 468 | after(content: Content, options?: ContentOptions): EndTag; 469 | remove(): EndTag; 470 | } 471 | 472 | interface ErrorEvent extends Event { 473 | readonly filename: string; 474 | readonly message: string; 475 | readonly lineno: number; 476 | readonly colno: number; 477 | readonly error: any; 478 | } 479 | 480 | declare class Event { 481 | constructor(type: string, init?: EventInit); 482 | readonly type: string; 483 | readonly eventPhase: number; 484 | readonly composed: boolean; 485 | readonly bubbles: boolean; 486 | readonly cancelable: boolean; 487 | readonly defaultPrevented: boolean; 488 | readonly returnValue: boolean; 489 | readonly currentTarget?: EventTarget; 490 | readonly srcElement?: EventTarget; 491 | readonly timeStamp: number; 492 | readonly isTrusted: boolean; 493 | cancelBubble: boolean; 494 | stopImmediatePropagation(): void; 495 | preventDefault(): void; 496 | stopPropagation(): void; 497 | composedPath(): EventTarget[]; 498 | static readonly NONE: number; 499 | static readonly CAPTURING_PHASE: number; 500 | static readonly AT_TARGET: number; 501 | static readonly BUBBLING_PHASE: number; 502 | } 503 | 504 | interface EventInit { 505 | bubbles?: boolean; 506 | cancelable?: boolean; 507 | composed?: boolean; 508 | } 509 | 510 | declare type EventListener = ( 511 | event: EventType 512 | ) => void; 513 | 514 | interface EventListenerObject { 515 | handleEvent(event: EventType): void; 516 | } 517 | 518 | declare type EventListenerOrEventListenerObject< 519 | EventType extends Event = Event 520 | > = EventListener | EventListenerObject; 521 | 522 | declare class EventTarget< 523 | EventMap extends Record = Record 524 | > { 525 | constructor(); 526 | addEventListener( 527 | type: Type, 528 | handler: EventListenerOrEventListenerObject, 529 | options?: EventTargetAddEventListenerOptions | boolean 530 | ): void; 531 | removeEventListener( 532 | type: Type, 533 | handler: EventListenerOrEventListenerObject, 534 | options?: EventTargetEventListenerOptions | boolean 535 | ): void; 536 | dispatchEvent(event: EventMap[keyof EventMap]): boolean; 537 | } 538 | 539 | interface EventTargetAddEventListenerOptions { 540 | capture?: boolean; 541 | passive?: boolean; 542 | once?: boolean; 543 | signal?: AbortSignal; 544 | } 545 | 546 | interface EventTargetEventListenerOptions { 547 | capture?: boolean; 548 | } 549 | 550 | interface EventTargetHandlerObject { 551 | handleEvent(arg1: Event): any | undefined; 552 | } 553 | 554 | interface ExecutionContext { 555 | waitUntil(promise: Promise): void; 556 | passThroughOnException(): void; 557 | } 558 | 559 | interface ExportedHandler { 560 | fetch?: ExportedHandlerFetchHandler; 561 | scheduled?: ExportedHandlerScheduledHandler; 562 | } 563 | 564 | declare type ExportedHandlerFetchHandler = ( 565 | request: Request, 566 | env: Env, 567 | ctx: ExecutionContext 568 | ) => Response | Promise; 569 | 570 | declare type ExportedHandlerScheduledHandler = ( 571 | controller: ScheduledController, 572 | env: Env, 573 | ctx: ExecutionContext 574 | ) => void | Promise; 575 | 576 | declare class ExtendableEvent extends Event { 577 | constructor(type: string, init?: EventInit); 578 | waitUntil(promise: Promise): void; 579 | } 580 | 581 | declare abstract class FetchEvent extends ExtendableEvent { 582 | readonly request: Request; 583 | respondWith(promise: Response | Promise): void; 584 | passThroughOnException(): void; 585 | } 586 | 587 | declare abstract class Fetcher { 588 | fetch( 589 | requestOrUrl: Request | string, 590 | requestInit?: RequestInit | Request 591 | ): Promise; 592 | } 593 | 594 | declare class File extends Blob { 595 | constructor(bits?: BlobBits, name?: string, options?: FileOptions); 596 | readonly name: string; 597 | readonly lastModified: number; 598 | } 599 | 600 | interface FileOptions { 601 | type?: string; 602 | lastModified?: number; 603 | } 604 | 605 | declare class FixedLengthStream extends IdentityTransformStream { 606 | constructor(expectedLength: number | bigint); 607 | } 608 | 609 | declare class FormData { 610 | constructor(); 611 | append(name: string, value: string): void; 612 | append(name: string, value: Blob, filename?: string): void; 613 | delete(name: string): void; 614 | get(name: string): File | string | null; 615 | getAll(name: string): (File | string)[]; 616 | has(name: string): boolean; 617 | set(name: string, value: string): void; 618 | set(name: string, value: Blob, filename?: string): void; 619 | entries(): IterableIterator<[key: string, value: File | string]>; 620 | keys(): IterableIterator; 621 | values(): IterableIterator; 622 | forEach( 623 | callback: ( 624 | this: This, 625 | value: File | string, 626 | key: string, 627 | parent: FormData 628 | ) => void, 629 | thisArg?: This 630 | ): void; 631 | [Symbol.iterator](): IterableIterator<[key: string, value: File | string]>; 632 | } 633 | 634 | declare class HTMLRewriter { 635 | constructor(); 636 | on( 637 | selector: string, 638 | handlers: HTMLRewriterElementContentHandlers 639 | ): HTMLRewriter; 640 | onDocument(handlers: HTMLRewriterDocumentContentHandlers): HTMLRewriter; 641 | transform(response: Response): Response; 642 | } 643 | 644 | interface HTMLRewriterDocumentContentHandlers { 645 | doctype?(doctype: Doctype): void | Promise; 646 | comments?(comment: Comment): void | Promise; 647 | text?(text: Text): void | Promise; 648 | end?(end: DocumentEnd): void | Promise; 649 | } 650 | 651 | interface HTMLRewriterElementContentHandlers { 652 | element?(element: Element): void | Promise; 653 | comments?(comment: Comment): void | Promise; 654 | text?(text: Text): void | Promise; 655 | } 656 | 657 | declare class Headers { 658 | constructor(init?: HeadersInit); 659 | get(name: string): string | null; 660 | getAll(name: string): string[]; 661 | has(name: string): boolean; 662 | set(name: string, value: string): void; 663 | append(name: string, value: string): void; 664 | delete(name: string): void; 665 | forEach( 666 | callback: (this: This, value: string, key: string, parent: Headers) => void, 667 | thisArg?: This 668 | ): void; 669 | entries(): IterableIterator<[key: string, value: string]>; 670 | keys(): IterableIterator; 671 | values(): IterableIterator; 672 | [Symbol.iterator](): IterableIterator<[key: string, value: string]>; 673 | } 674 | 675 | declare type HeadersInit = 676 | | Headers 677 | | Record 678 | | [key: string, value: string][]; 679 | 680 | /** 681 | * Back compat for code migrating to older definitions. 682 | * @deprecated Use HeadersInit instead. 683 | */ 684 | declare type HeadersInitializer = HeadersInit; 685 | 686 | declare class IdentityTransformStream extends TransformStream { 687 | constructor(); 688 | } 689 | 690 | interface JsonWebKey { 691 | kty: string; 692 | use?: string; 693 | key_ops?: string[]; 694 | alg?: string; 695 | ext?: boolean; 696 | crv?: string; 697 | x?: string; 698 | y?: string; 699 | d?: string; 700 | n?: string; 701 | e?: string; 702 | p?: string; 703 | q?: string; 704 | dp?: string; 705 | dq?: string; 706 | qi?: string; 707 | oth?: RsaOtherPrimesInfo[]; 708 | k?: string; 709 | } 710 | 711 | /** 712 | * Workers KV is a global, low-latency, key-value data store. It supports exceptionally high read volumes with low-latency, 713 | * making it possible to build highly dynamic APIs and websites which respond as quickly as a cached static file would. 714 | */ 715 | interface KVNamespace { 716 | get( 717 | key: K, 718 | options?: Partial> 719 | ): Promise; 720 | get(key: K, type: "text"): Promise; 721 | get( 722 | key: K, 723 | type: "json" 724 | ): Promise; 725 | get(key: K, type: "arrayBuffer"): Promise; 726 | get(key: K, type: "stream"): Promise; 727 | get(key: K, options: KVNamespaceGetOptions<"text">): Promise; 728 | get( 729 | key: string, 730 | options: KVNamespaceGetOptions<"json"> 731 | ): Promise; 732 | get( 733 | key: K, 734 | options: KVNamespaceGetOptions<"arrayBuffer"> 735 | ): Promise; 736 | get( 737 | key: K, 738 | options: KVNamespaceGetOptions<"stream"> 739 | ): Promise; 740 | list( 741 | options?: KVNamespaceListOptions 742 | ): Promise>; 743 | /** 744 | * Creates a new key-value pair, or updates the value for a particular key. 745 | * @param key key to associate with the value. A key cannot be empty, `.` or `..`. All other keys are valid. 746 | * @param value value to store. The type is inferred. The maximum size of a value is 25MB. 747 | * @returns Returns a `Promise` that you should `await` on in order to verify a successful update. 748 | * @example 749 | * await NAMESPACE.put(key, value); 750 | */ 751 | put( 752 | key: K, 753 | value: string | ArrayBuffer | ArrayBufferView | ReadableStream, 754 | options?: KVNamespacePutOptions 755 | ): Promise; 756 | getWithMetadata( 757 | key: K, 758 | options?: Partial> 759 | ): Promise>; 760 | getWithMetadata( 761 | key: K, 762 | type: "text" 763 | ): Promise>; 764 | getWithMetadata( 765 | key: K, 766 | type: "json" 767 | ): Promise>; 768 | getWithMetadata( 769 | key: K, 770 | type: "arrayBuffer" 771 | ): Promise>; 772 | getWithMetadata( 773 | key: K, 774 | type: "stream" 775 | ): Promise>; 776 | getWithMetadata( 777 | key: K, 778 | options: KVNamespaceGetOptions<"text"> 779 | ): Promise>; 780 | getWithMetadata( 781 | key: K, 782 | options: KVNamespaceGetOptions<"json"> 783 | ): Promise>; 784 | getWithMetadata( 785 | key: K, 786 | options: KVNamespaceGetOptions<"arrayBuffer"> 787 | ): Promise>; 788 | getWithMetadata( 789 | key: K, 790 | options: KVNamespaceGetOptions<"stream"> 791 | ): Promise>; 792 | delete(name: string): Promise; 793 | } 794 | 795 | interface KVNamespaceGetOptions { 796 | type: Type; 797 | cacheTtl?: number; 798 | } 799 | 800 | interface KVNamespaceGetWithMetadataResult { 801 | value: Value | null; 802 | metadata: Metadata | null; 803 | } 804 | 805 | interface KVNamespaceListKey { 806 | name: string; 807 | expiration?: number; 808 | metadata?: Metadata; 809 | } 810 | 811 | interface KVNamespaceListOptions { 812 | limit?: number; 813 | prefix?: string | null; 814 | cursor?: string | null; 815 | } 816 | 817 | interface KVNamespaceListResult { 818 | keys: KVNamespaceListKey[]; 819 | list_complete: boolean; 820 | cursor?: string; 821 | } 822 | 823 | interface KVNamespacePutOptions { 824 | expiration?: number; 825 | expirationTtl?: number; 826 | metadata?: any | null; 827 | } 828 | 829 | declare class MessageEvent extends Event { 830 | constructor(type: string, initializer: MessageEventInit); 831 | readonly data: ArrayBuffer | string; 832 | } 833 | 834 | interface MessageEventInit { 835 | data: ArrayBuffer | string; 836 | } 837 | 838 | /** 839 | * Back compat for code migrating from older definitions. 840 | * @deprecated Use MessageEventInit instead. 841 | */ 842 | declare type MessageEventInitializer = MessageEventInit; 843 | 844 | declare abstract class Navigator { 845 | readonly userAgent: string; 846 | } 847 | 848 | /** 849 | * Transitionary name. 850 | * @deprecated Use StreamPipeOptions 851 | */ 852 | interface PipeToOptions { 853 | preventClose?: boolean; 854 | preventAbort?: boolean; 855 | preventCancel?: boolean; 856 | signal?: AbortSignal; 857 | } 858 | 859 | declare abstract class PromiseRejectionEvent extends Event { 860 | readonly promise: Promise; 861 | readonly reason: any; 862 | } 863 | 864 | interface QueuingStrategyInit { 865 | highWaterMark: number; 866 | } 867 | 868 | /** 869 | * An instance of the R2 bucket binding. 870 | */ 871 | interface R2Bucket { 872 | head(key: string): Promise; 873 | get(key: string): Promise; 874 | /** 875 | * Returns R2Object on a failure of the conditional specified in onlyIf. 876 | */ 877 | get( 878 | key: string, 879 | options: R2GetOptions 880 | ): Promise; 881 | get( 882 | key: string, 883 | options?: R2GetOptions 884 | ): Promise; 885 | put( 886 | key: string, 887 | value: 888 | | ReadableStream 889 | | ArrayBuffer 890 | | ArrayBufferView 891 | | string 892 | | null 893 | | Blob, 894 | options?: R2PutOptions 895 | ): Promise; 896 | delete(keys: string | string[]): Promise; 897 | list(options?: R2ListOptions): Promise; 898 | } 899 | 900 | /** 901 | * The checksums associated with the object. 902 | */ 903 | interface R2Checksums { 904 | md5?: ArrayBuffer; 905 | sha1?: ArrayBuffer; 906 | sha256?: ArrayBuffer; 907 | sha384?: ArrayBuffer; 908 | sha512?: ArrayBuffer; 909 | } 910 | 911 | /** 912 | * Perform the operation conditionally based on meeting the defined criteria. 913 | */ 914 | interface R2Conditional { 915 | etagMatches?: string; 916 | etagDoesNotMatch?: string; 917 | uploadedBefore?: Date; 918 | uploadedAfter?: Date; 919 | secondsGranularity?: boolean; 920 | } 921 | 922 | /** 923 | * Options for retrieving the object metadata nad payload. 924 | */ 925 | interface R2GetOptions { 926 | onlyIf?: R2Conditional | Headers; 927 | range?: R2Range | Headers; 928 | } 929 | 930 | /** 931 | * Metadata that's automatically rendered into R2 HTTP API endpoints. 932 | * ``` 933 | * * contentType -> content-type 934 | * * contentLanguage -> content-language 935 | * etc... 936 | * ``` 937 | * This data is echoed back on GET responses based on what was originally 938 | * assigned to the object (and can typically also be overriden when issuing 939 | * the GET request). 940 | */ 941 | interface R2HTTPMetadata { 942 | contentType?: string; 943 | contentLanguage?: string; 944 | contentDisposition?: string; 945 | contentEncoding?: string; 946 | cacheControl?: string; 947 | cacheExpiry?: Date; 948 | } 949 | 950 | interface R2ListOptions { 951 | limit?: number; 952 | prefix?: string; 953 | cursor?: string; 954 | delimiter?: string; 955 | startAfter?: string; 956 | /** 957 | * If you populate this array, then items returned will include this metadata. 958 | * A tradeoff is that fewer results may be returned depending on how big this 959 | * data is. For now the caps are TBD but expect the total memory usage for a list 960 | * operation may need to be <1MB or even <128kb depending on how many list operations 961 | * you are sending into one bucket. Make sure to look at `truncated` for the result 962 | * rather than having logic like 963 | * ``` 964 | * while (listed.length < limit) { 965 | * listed = myBucket.list({ limit, include: ['customMetadata'] }) 966 | * } 967 | * ``` 968 | */ 969 | include?: ("httpMetadata" | "customMetadata")[]; 970 | } 971 | 972 | /** 973 | * The metadata for the object. 974 | */ 975 | declare abstract class R2Object { 976 | readonly key: string; 977 | readonly version: string; 978 | readonly size: number; 979 | readonly etag: string; 980 | readonly httpEtag: string; 981 | readonly checksums: R2Checksums; 982 | readonly uploaded: Date; 983 | readonly httpMetadata?: R2HTTPMetadata; 984 | readonly customMetadata?: Record; 985 | readonly range?: R2Range; 986 | writeHttpMetadata(headers: Headers): void; 987 | } 988 | 989 | /** 990 | * The metadata for the object and the body of the payload. 991 | */ 992 | interface R2ObjectBody extends R2Object { 993 | readonly body: ReadableStream; 994 | readonly bodyUsed: boolean; 995 | arrayBuffer(): Promise; 996 | text(): Promise; 997 | json(): Promise; 998 | blob(): Promise; 999 | } 1000 | 1001 | interface R2Objects { 1002 | objects: R2Object[]; 1003 | truncated: boolean; 1004 | cursor?: string; 1005 | delimitedPrefixes: string[]; 1006 | } 1007 | 1008 | interface R2PutOptions { 1009 | onlyIf?: R2Conditional | Headers; 1010 | httpMetadata?: R2HTTPMetadata | Headers; 1011 | customMetadata?: Record; 1012 | md5?: ArrayBuffer | string; 1013 | sha1?: ArrayBuffer | string; 1014 | sha256?: ArrayBuffer | string; 1015 | sha384?: ArrayBuffer | string; 1016 | sha512?: ArrayBuffer | string; 1017 | } 1018 | 1019 | declare type R2Range = 1020 | | { offset: number; length?: number } 1021 | | { offset?: number; length: number } 1022 | | { suffix: number }; 1023 | 1024 | interface ReadResult { 1025 | value?: any; 1026 | done: boolean; 1027 | } 1028 | 1029 | declare abstract class ReadableByteStreamController { 1030 | readonly byobRequest: ReadableStreamBYOBRequest | null; 1031 | readonly desiredSize: number | null; 1032 | close(): void; 1033 | enqueue(chunk: ArrayBuffer | ArrayBufferView): void; 1034 | error(reason: any): void; 1035 | } 1036 | 1037 | declare class ReadableStream { 1038 | constructor( 1039 | underlyingSource?: UnderlyingSource, 1040 | queuingStrategy?: StreamQueuingStrategy 1041 | ); 1042 | readonly locked: boolean; 1043 | cancel(reason?: any): Promise; 1044 | getReader(options: ReadableStreamGetReaderOptions): ReadableStreamBYOBReader; 1045 | getReader(): ReadableStreamDefaultReader; 1046 | pipeThrough( 1047 | transform: ReadableStreamTransform, 1048 | options?: PipeToOptions 1049 | ): ReadableStream; 1050 | pipeTo(destination: WritableStream, options?: PipeToOptions): Promise; 1051 | tee(): [ReadableStream, ReadableStream]; 1052 | values(options?: ReadableStreamValuesOptions): AsyncIterableIterator; 1053 | [Symbol.asyncIterator]( 1054 | options?: ReadableStreamValuesOptions 1055 | ): AsyncIterableIterator; 1056 | } 1057 | 1058 | declare class ReadableStreamBYOBReader { 1059 | constructor(stream: ReadableStream); 1060 | readonly closed: Promise; 1061 | cancel(reason?: any): Promise; 1062 | read( 1063 | view: T 1064 | ): Promise>; 1065 | releaseLock(): void; 1066 | readAtLeast( 1067 | minBytes: number, 1068 | view: Uint8Array 1069 | ): Promise>; 1070 | } 1071 | 1072 | declare abstract class ReadableStreamBYOBRequest { 1073 | readonly view: Uint8Array | null; 1074 | respond(bytesWritten: number): void; 1075 | respondWithNewView(view: ArrayBuffer | ArrayBufferView): void; 1076 | readonly atLeast: number | null; 1077 | } 1078 | 1079 | declare abstract class ReadableStreamDefaultController { 1080 | readonly desiredSize: number | null; 1081 | close(): void; 1082 | enqueue(chunk?: any): void; 1083 | error(reason: any): void; 1084 | } 1085 | 1086 | declare class ReadableStreamDefaultReader { 1087 | constructor(stream: ReadableStream); 1088 | readonly closed: Promise; 1089 | cancel(reason?: any): Promise; 1090 | read(): Promise>; 1091 | releaseLock(): void; 1092 | } 1093 | 1094 | interface ReadableStreamGetReaderOptions { 1095 | mode: string; 1096 | } 1097 | 1098 | /** 1099 | * Back-compat alias. 1100 | * @deprecated Use StreamPipeOptions 1101 | */ 1102 | declare type ReadableStreamPipeToOptions = PipeToOptions; 1103 | 1104 | declare type ReadableStreamReadResult = 1105 | | { done: true; value: undefined } 1106 | | { done: false; value: T }; 1107 | 1108 | /** 1109 | * Back-compat alias. 1110 | * @deprecated Use ReadableStreamBYOBReader 1111 | */ 1112 | declare type ReadableStreamReadableStreamBYOBReader = ReadableStreamBYOBReader; 1113 | 1114 | /** 1115 | * Back-compat alias. 1116 | * @deprecated Use ReadableStreamDefaultReader 1117 | */ 1118 | declare type ReadableStreamReadableStreamDefaultReader = 1119 | ReadableStreamDefaultReader; 1120 | 1121 | interface ReadableStreamTransform { 1122 | writable: WritableStream; 1123 | readable: ReadableStream; 1124 | } 1125 | 1126 | interface ReadableStreamValuesOptions { 1127 | preventCancel?: boolean; 1128 | } 1129 | 1130 | declare class Request extends Body { 1131 | constructor(input: Request | string, init?: RequestInit | Request); 1132 | clone(): Request; 1133 | readonly method: string; 1134 | readonly url: string; 1135 | readonly headers: Headers; 1136 | readonly redirect: string; 1137 | readonly fetcher: Fetcher | null; 1138 | readonly signal: AbortSignal; 1139 | /** 1140 | * In addition to the properties on the standard `Request` object, 1141 | * the `cf` object contains extra information about the request provided 1142 | * by Cloudflare's edge. 1143 | * 1144 | * Returns undefined when accessed in the playground. 1145 | */ 1146 | readonly cf?: IncomingRequestCfProperties; 1147 | } 1148 | 1149 | interface RequestInit { 1150 | method?: string; 1151 | headers?: HeadersInit; 1152 | body?: BodyInit | null; 1153 | redirect?: string; 1154 | fetcher?: Fetcher | null; 1155 | /** 1156 | * cf is a union of these two types because there are multiple 1157 | * scenarios in which it might be one or the other. 1158 | * 1159 | * IncomingRequestCfProperties is required to allow 1160 | * new Request(someUrl, event.request) 1161 | * 1162 | * RequestInitCfProperties is required to allow 1163 | * new Request(event.request, {cf: { ... } }) 1164 | * fetch(someUrl, {cf: { ... } }) 1165 | */ 1166 | cf?: IncomingRequestCfProperties | RequestInitCfProperties; 1167 | signal?: AbortSignal | null; 1168 | } 1169 | 1170 | /** 1171 | * Back compat for code migrating from older definitions. 1172 | * @deprecated Use RequestInit instead. 1173 | */ 1174 | declare type RequestInitializerDict = RequestInit; 1175 | 1176 | declare class Response extends Body { 1177 | constructor(bodyInit?: BodyInit | null, maybeInit?: ResponseInit | Response); 1178 | static redirect(url: string, status?: number): Response; 1179 | static json(any: any, maybeInit?: ResponseInit | Response): Response; 1180 | clone(): Response; 1181 | readonly status: number; 1182 | readonly statusText: string; 1183 | readonly headers: Headers; 1184 | readonly ok: boolean; 1185 | readonly redirected: boolean; 1186 | readonly url: string; 1187 | readonly webSocket: WebSocket | null; 1188 | readonly cf?: Object; 1189 | } 1190 | 1191 | interface ResponseInit { 1192 | status?: number; 1193 | statusText?: string; 1194 | headers?: HeadersInit; 1195 | cf?: Object; 1196 | webSocket?: WebSocket | null; 1197 | encodeBody?: string; 1198 | } 1199 | 1200 | /** 1201 | * Back compat for code migrating from older definitions. 1202 | * @deprecated Use ResponseInit instead. 1203 | */ 1204 | declare type ResponseInitializerDict = ResponseInit; 1205 | 1206 | interface RsaOtherPrimesInfo { 1207 | r?: string; 1208 | d?: string; 1209 | t?: string; 1210 | } 1211 | 1212 | interface ScheduledController { 1213 | readonly scheduledTime: number; 1214 | readonly cron: string; 1215 | noRetry(): void; 1216 | } 1217 | 1218 | declare abstract class ScheduledEvent extends ExtendableEvent { 1219 | readonly scheduledTime: number; 1220 | readonly cron: string; 1221 | noRetry(): void; 1222 | } 1223 | 1224 | interface Scheduler { 1225 | wait(delay: number, maybeOptions?: SchedulerWaitOptions): Promise; 1226 | } 1227 | 1228 | interface SchedulerWaitOptions { 1229 | signal?: AbortSignal; 1230 | } 1231 | 1232 | interface ServiceWorkerGlobalScope extends WorkerGlobalScope { 1233 | btoa(data: string): string; 1234 | atob(data: string): string; 1235 | setTimeout( 1236 | callback: (...args: Args) => void, 1237 | msDelay?: number, 1238 | ...args: Args 1239 | ): number; 1240 | clearTimeout(timeoutId: number | null): void; 1241 | setInterval( 1242 | callback: (...args: Args) => void, 1243 | msDelay?: number, 1244 | ...args: Args 1245 | ): number; 1246 | clearInterval(timeoutId: number | null): void; 1247 | queueMicrotask(task: Function): void; 1248 | structuredClone( 1249 | value: any, 1250 | options?: ServiceWorkerGlobalScopeStructuredCloneOptions 1251 | ): any; 1252 | fetch( 1253 | request: Request | string, 1254 | requestInitr?: RequestInit | Request 1255 | ): Promise; 1256 | self: ServiceWorkerGlobalScope; 1257 | crypto: Crypto; 1258 | caches: CacheStorage; 1259 | scheduler: Scheduler; 1260 | navigator: Navigator; 1261 | readonly console: Console; 1262 | origin: void; 1263 | } 1264 | 1265 | interface ServiceWorkerGlobalScopeStructuredCloneOptions { 1266 | transfer?: any[]; 1267 | } 1268 | 1269 | declare type StreamPipeOptions = PipeToOptions; 1270 | 1271 | interface StreamQueuingStrategy { 1272 | highWaterMark?: bigint; 1273 | size(chunk: any): number; 1274 | } 1275 | 1276 | declare abstract class SubtleCrypto { 1277 | encrypt( 1278 | algorithm: string | SubtleCryptoEncryptAlgorithm, 1279 | key: CryptoKey, 1280 | plainText: ArrayBuffer | ArrayBufferView 1281 | ): Promise; 1282 | decrypt( 1283 | algorithm: string | SubtleCryptoEncryptAlgorithm, 1284 | key: CryptoKey, 1285 | cipherText: ArrayBuffer | ArrayBufferView 1286 | ): Promise; 1287 | sign( 1288 | algorithm: string | SubtleCryptoSignAlgorithm, 1289 | key: CryptoKey, 1290 | data: ArrayBuffer | ArrayBufferView 1291 | ): Promise; 1292 | verify( 1293 | algorithm: string | SubtleCryptoSignAlgorithm, 1294 | key: CryptoKey, 1295 | signature: ArrayBuffer | ArrayBufferView, 1296 | data: ArrayBuffer | ArrayBufferView 1297 | ): Promise; 1298 | digest( 1299 | algorithm: string | SubtleCryptoHashAlgorithm, 1300 | data: ArrayBuffer | ArrayBufferView 1301 | ): Promise; 1302 | generateKey( 1303 | algorithm: string | SubtleCryptoGenerateKeyAlgorithm, 1304 | extractable: boolean, 1305 | keyUsages: string[] 1306 | ): Promise; 1307 | deriveKey( 1308 | algorithm: string | SubtleCryptoDeriveKeyAlgorithm, 1309 | baseKey: CryptoKey, 1310 | derivedKeyAlgorithm: string | SubtleCryptoImportKeyAlgorithm, 1311 | extractable: boolean, 1312 | keyUsages: string[] 1313 | ): Promise; 1314 | deriveBits( 1315 | algorithm: string | SubtleCryptoDeriveKeyAlgorithm, 1316 | baseKey: CryptoKey, 1317 | length: number | null 1318 | ): Promise; 1319 | importKey( 1320 | format: string, 1321 | keyData: ArrayBuffer | JsonWebKey, 1322 | algorithm: string | SubtleCryptoImportKeyAlgorithm, 1323 | extractable: boolean, 1324 | keyUsages: string[] 1325 | ): Promise; 1326 | exportKey(format: string, key: CryptoKey): Promise; 1327 | wrapKey( 1328 | format: string, 1329 | key: CryptoKey, 1330 | wrappingKey: CryptoKey, 1331 | wrapAlgorithm: string | SubtleCryptoEncryptAlgorithm 1332 | ): Promise; 1333 | unwrapKey( 1334 | format: string, 1335 | wrappedKey: ArrayBuffer | ArrayBufferView, 1336 | unwrappingKey: CryptoKey, 1337 | unwrapAlgorithm: string | SubtleCryptoEncryptAlgorithm, 1338 | unwrappedKeyAlgorithm: string | SubtleCryptoImportKeyAlgorithm, 1339 | extractable: boolean, 1340 | keyUsages: string[] 1341 | ): Promise; 1342 | timingSafeEqual( 1343 | a: ArrayBuffer | ArrayBufferView, 1344 | b: ArrayBuffer | ArrayBufferView 1345 | ): boolean; 1346 | } 1347 | 1348 | interface SubtleCryptoDeriveKeyAlgorithm { 1349 | name: string; 1350 | salt?: ArrayBuffer; 1351 | iterations?: number; 1352 | hash?: string | SubtleCryptoHashAlgorithm; 1353 | public?: CryptoKey; 1354 | info?: ArrayBuffer; 1355 | } 1356 | 1357 | interface SubtleCryptoEncryptAlgorithm { 1358 | name: string; 1359 | iv?: ArrayBuffer; 1360 | additionalData?: ArrayBuffer; 1361 | tagLength?: number; 1362 | counter?: ArrayBuffer; 1363 | length?: number; 1364 | label?: ArrayBuffer; 1365 | } 1366 | 1367 | interface SubtleCryptoGenerateKeyAlgorithm { 1368 | name: string; 1369 | hash?: string | SubtleCryptoHashAlgorithm; 1370 | modulusLength?: number; 1371 | publicExponent?: ArrayBuffer; 1372 | length?: number; 1373 | namedCurve?: string; 1374 | } 1375 | 1376 | interface SubtleCryptoHashAlgorithm { 1377 | name: string; 1378 | } 1379 | 1380 | interface SubtleCryptoImportKeyAlgorithm { 1381 | name: string; 1382 | hash?: string | SubtleCryptoHashAlgorithm; 1383 | length?: number; 1384 | namedCurve?: string; 1385 | compressed?: boolean; 1386 | } 1387 | 1388 | /** 1389 | * 1390 | * @deprecated Don't use. Introduced incidentally in 3.x. Scheduled for removal. 1391 | */ 1392 | declare type SubtleCryptoJsonWebKey = JsonWebKey; 1393 | 1394 | /** 1395 | * 1396 | * @deprecated Don't use. Introduced incidentally in 3.x. Scheduled for removal. 1397 | */ 1398 | declare type SubtleCryptoJsonWebKeyRsaOtherPrimesInfo = RsaOtherPrimesInfo; 1399 | 1400 | interface SubtleCryptoSignAlgorithm { 1401 | name: string; 1402 | hash?: string | SubtleCryptoHashAlgorithm; 1403 | dataLength?: number; 1404 | saltLength?: number; 1405 | } 1406 | 1407 | interface Text { 1408 | readonly text: string; 1409 | readonly lastInTextNode: boolean; 1410 | readonly removed: boolean; 1411 | before(content: Content, options?: ContentOptions): Text; 1412 | after(content: Content, options?: ContentOptions): Text; 1413 | replace(content: Content, options?: ContentOptions): Text; 1414 | remove(): Text; 1415 | } 1416 | 1417 | declare class TextDecoder { 1418 | constructor( 1419 | label?: "utf-8" | "utf8" | "unicode-1-1-utf-8", 1420 | options?: TextDecoderConstructorOptions 1421 | ); 1422 | decode( 1423 | input?: ArrayBuffer | ArrayBufferView, 1424 | options?: TextDecoderDecodeOptions 1425 | ): string; 1426 | readonly encoding: string; 1427 | readonly fatal: boolean; 1428 | readonly ignoreBOM: boolean; 1429 | } 1430 | 1431 | interface TextDecoderConstructorOptions { 1432 | fatal: boolean; 1433 | ignoreBOM: boolean; 1434 | } 1435 | 1436 | interface TextDecoderDecodeOptions { 1437 | stream: boolean; 1438 | } 1439 | 1440 | declare class TextDecoderStream extends TransformStream { 1441 | constructor(label?: string, options?: TextDecoderStreamTextDecoderStreamInit); 1442 | } 1443 | 1444 | interface TextDecoderStreamTextDecoderStreamInit { 1445 | fatal?: boolean; 1446 | } 1447 | 1448 | declare class TextEncoder { 1449 | constructor(); 1450 | encode(input?: string): Uint8Array; 1451 | encodeInto(input: string, buffer: Uint8Array): TextEncoderEncodeIntoResult; 1452 | readonly encoding: string; 1453 | } 1454 | 1455 | interface TextEncoderEncodeIntoResult { 1456 | read: number; 1457 | written: number; 1458 | } 1459 | 1460 | declare class TextEncoderStream extends TransformStream { 1461 | constructor(); 1462 | } 1463 | 1464 | interface TraceEvent extends ExtendableEvent { 1465 | readonly traces: TraceItem[]; 1466 | } 1467 | 1468 | interface TraceException { 1469 | readonly timestamp: number; 1470 | readonly message: string; 1471 | readonly name: string; 1472 | } 1473 | 1474 | interface TraceItem { 1475 | readonly event: TraceItemEventInfo | null; 1476 | readonly eventTimestamp: number | null; 1477 | readonly logs: TraceLog[]; 1478 | readonly exceptions: TraceException[]; 1479 | readonly scriptName: string | null; 1480 | readonly dispatchNamespace?: string; 1481 | readonly outcome: string; 1482 | } 1483 | 1484 | interface TraceItemAlarmEventInfo { 1485 | readonly scheduledTime: Date; 1486 | } 1487 | 1488 | declare type TraceItemEventInfo = 1489 | | TraceItemFetchEventInfo 1490 | | TraceItemScheduledEventInfo 1491 | | TraceItemAlarmEventInfo; 1492 | 1493 | interface TraceItemFetchEventInfo { 1494 | readonly response?: TraceItemFetchEventInfoResponse; 1495 | readonly request: TraceItemFetchEventInfoRequest; 1496 | } 1497 | 1498 | interface TraceItemFetchEventInfoRequest { 1499 | readonly cf?: Object; 1500 | readonly headers: Record; 1501 | readonly method: string; 1502 | readonly url: string; 1503 | getUnredacted(): TraceItemFetchEventInfoRequest; 1504 | } 1505 | 1506 | interface TraceItemFetchEventInfoResponse { 1507 | readonly status: number; 1508 | } 1509 | 1510 | interface TraceItemScheduledEventInfo { 1511 | readonly scheduledTime: number; 1512 | readonly cron: string; 1513 | } 1514 | 1515 | interface TraceLog { 1516 | readonly timestamp: number; 1517 | readonly level: string; 1518 | readonly message: Object; 1519 | } 1520 | 1521 | interface TraceMetrics { 1522 | readonly cpuTime: number; 1523 | readonly wallTime: number; 1524 | } 1525 | 1526 | declare class TransformStream { 1527 | constructor( 1528 | maybeTransformer?: Transformer, 1529 | maybeWritableStrategy?: StreamQueuingStrategy, 1530 | maybeReadableStrategy?: StreamQueuingStrategy 1531 | ); 1532 | readonly readable: ReadableStream; 1533 | readonly writable: WritableStream; 1534 | } 1535 | 1536 | interface TransformStreamDefaultController { 1537 | readonly desiredSize: number | null; 1538 | enqueue(chunk: any): void; 1539 | error(reason: any): void; 1540 | terminate(): void; 1541 | } 1542 | 1543 | interface Transformer { 1544 | readableType?: string; 1545 | writableType?: string; 1546 | start?(controller: TransformStreamDefaultController): any; 1547 | transform?(chunk: any, controller: TransformStreamDefaultController): any; 1548 | flush?(controller: TransformStreamDefaultController): any; 1549 | } 1550 | 1551 | declare class URL { 1552 | constructor(url: string, base?: string); 1553 | href: string; 1554 | readonly origin: string; 1555 | protocol: string; 1556 | username: string; 1557 | password: string; 1558 | host: string; 1559 | hostname: string; 1560 | port: string; 1561 | pathname: string; 1562 | search: string; 1563 | readonly searchParams: URLSearchParams; 1564 | hash: string; 1565 | toString(): string; 1566 | toJSON(): string; 1567 | } 1568 | 1569 | declare class URLPattern { 1570 | constructor(input?: string | URLPatternURLPatternInit, baseURL?: string); 1571 | readonly protocol: string; 1572 | readonly username: string; 1573 | readonly password: string; 1574 | readonly hostname: string; 1575 | readonly port: string; 1576 | readonly pathname: string; 1577 | readonly search: string; 1578 | readonly hash: string; 1579 | test(input?: string | URLPatternURLPatternInit, baseURL?: string): boolean; 1580 | exec( 1581 | input?: string | URLPatternURLPatternInit, 1582 | baseURL?: string 1583 | ): URLPatternURLPatternResult | null; 1584 | } 1585 | 1586 | interface URLPatternURLPatternComponentResult { 1587 | input: string; 1588 | groups: Record; 1589 | } 1590 | 1591 | interface URLPatternURLPatternInit { 1592 | protocol?: string; 1593 | username?: string; 1594 | password?: string; 1595 | hostname?: string; 1596 | port?: string; 1597 | pathname?: string; 1598 | search?: string; 1599 | hash?: string; 1600 | baseURL?: string; 1601 | } 1602 | 1603 | interface URLPatternURLPatternResult { 1604 | inputs: (string | URLPatternURLPatternInit)[]; 1605 | protocol: URLPatternURLPatternComponentResult; 1606 | username: URLPatternURLPatternComponentResult; 1607 | password: URLPatternURLPatternComponentResult; 1608 | hostname: URLPatternURLPatternComponentResult; 1609 | port: URLPatternURLPatternComponentResult; 1610 | pathname: URLPatternURLPatternComponentResult; 1611 | search: URLPatternURLPatternComponentResult; 1612 | hash: URLPatternURLPatternComponentResult; 1613 | } 1614 | 1615 | declare class URLSearchParams { 1616 | constructor(init?: URLSearchParamsInit); 1617 | append(name: string, value: string): void; 1618 | delete(name: string): void; 1619 | get(name: string): string | null; 1620 | getAll(name: string): string[]; 1621 | has(name: string): boolean; 1622 | set(name: string, value: string): void; 1623 | sort(): void; 1624 | entries(): IterableIterator<[key: string, value: string]>; 1625 | keys(): IterableIterator; 1626 | values(): IterableIterator; 1627 | forEach( 1628 | callback: ( 1629 | this: This, 1630 | value: string, 1631 | key: string, 1632 | parent: URLSearchParams 1633 | ) => void, 1634 | thisArg?: This 1635 | ): void; 1636 | [Symbol.iterator](): IterableIterator<[key: string, value: string]>; 1637 | toString(): string; 1638 | } 1639 | 1640 | declare type URLSearchParamsInit = 1641 | | URLSearchParams 1642 | | string 1643 | | Record 1644 | | [key: string, value: string][]; 1645 | 1646 | /** 1647 | * Back compat for code migrating to older definitions. 1648 | * This technically isn't part of a standard either way, but the naming 1649 | * is more consistent. 1650 | * @deprecated Use URLSearchParamsInit instead. 1651 | */ 1652 | declare type URLSearchParamsInitializer = URLSearchParamsInit; 1653 | 1654 | interface UnderlyingSink { 1655 | type?: string; 1656 | start?(controller: WritableStreamDefaultController): any; 1657 | write?(chunk: any, controller: WritableStreamDefaultController): any; 1658 | abort?(reason: any): any; 1659 | close?(): any; 1660 | } 1661 | 1662 | interface UnderlyingSource { 1663 | type?: string; 1664 | autoAllocateChunkSize?: number; 1665 | start?( 1666 | controller: ReadableStreamDefaultController | ReadableByteStreamController 1667 | ): any; 1668 | pull?( 1669 | controller: ReadableStreamDefaultController | ReadableByteStreamController 1670 | ): any; 1671 | cancel?(reason?: any): any; 1672 | } 1673 | 1674 | interface UnsafeTraceMetrics { 1675 | fromTrace(arg4: TraceItem): TraceMetrics; 1676 | } 1677 | 1678 | declare class WebSocket extends EventTarget { 1679 | constructor(url: string, protocols?: string[] | string); 1680 | accept(): void; 1681 | send(message: ArrayBuffer | ArrayBufferView | string): void; 1682 | close(code?: number, reason?: string): void; 1683 | static readonly READY_STATE_CONNECTING: number; 1684 | static readonly READY_STATE_OPEN: number; 1685 | static readonly READY_STATE_CLOSING: number; 1686 | static readonly READY_STATE_CLOSED: number; 1687 | readonly readyState: number; 1688 | readonly url: string | null; 1689 | readonly protocol: string | null; 1690 | readonly extensions: string | null; 1691 | } 1692 | 1693 | declare type WebSocketEventMap = { 1694 | close: CloseEvent; 1695 | message: MessageEvent; 1696 | open: Event; 1697 | error: ErrorEvent; 1698 | }; 1699 | 1700 | declare const WebSocketPair: { new (): { 0: WebSocket; 1: WebSocket } }; 1701 | 1702 | declare abstract class WorkerGlobalScope extends EventTarget {} 1703 | 1704 | declare type WorkerGlobalScopeEventMap = { 1705 | fetch: FetchEvent; 1706 | scheduled: ScheduledEvent; 1707 | unhandledrejection: PromiseRejectionEvent; 1708 | rejectionhandled: PromiseRejectionEvent; 1709 | }; 1710 | 1711 | declare class WritableStream { 1712 | constructor( 1713 | underlyingSink?: UnderlyingSink, 1714 | queuingStrategy?: StreamQueuingStrategy 1715 | ); 1716 | readonly locked: boolean; 1717 | abort(reason: any): Promise; 1718 | close(): Promise; 1719 | getWriter(): WritableStreamDefaultWriter; 1720 | } 1721 | 1722 | declare abstract class WritableStreamDefaultController { 1723 | readonly signal: AbortSignal; 1724 | error(reason?: any): void; 1725 | } 1726 | 1727 | declare class WritableStreamDefaultWriter { 1728 | constructor(stream: WritableStream); 1729 | readonly closed: Promise; 1730 | readonly ready: Promise; 1731 | readonly desiredSize: number | null; 1732 | abort(reason: any): Promise; 1733 | close(): Promise; 1734 | write(chunk: any): Promise; 1735 | releaseLock(): void; 1736 | } 1737 | 1738 | /** 1739 | * Back-compat alias. 1740 | * @deprecated Use WritableStreamDefaultWriter 1741 | */ 1742 | declare type WritableStreamWritableStreamDefaultWriter = 1743 | WritableStreamDefaultWriter; 1744 | 1745 | declare function addEventListener( 1746 | type: Type, 1747 | handler: EventListenerOrEventListenerObject, 1748 | options?: EventTargetAddEventListenerOptions | boolean 1749 | ): void; 1750 | 1751 | declare function atob(data: string): string; 1752 | 1753 | declare function btoa(data: string): string; 1754 | 1755 | declare const caches: CacheStorage; 1756 | 1757 | declare function clearInterval(timeoutId: number | null): void; 1758 | 1759 | declare function clearTimeout(timeoutId: number | null): void; 1760 | 1761 | declare const console: Console; 1762 | 1763 | declare const crypto: Crypto; 1764 | 1765 | declare function dispatchEvent( 1766 | event: WorkerGlobalScopeEventMap[keyof WorkerGlobalScopeEventMap] 1767 | ): boolean; 1768 | 1769 | declare function fetch( 1770 | request: Request | string, 1771 | requestInitr?: RequestInit | Request 1772 | ): Promise; 1773 | 1774 | declare const navigator: Navigator; 1775 | 1776 | declare const origin: void; 1777 | 1778 | declare function queueMicrotask(task: Function): void; 1779 | 1780 | declare function removeEventListener< 1781 | Type extends keyof WorkerGlobalScopeEventMap 1782 | >( 1783 | type: Type, 1784 | handler: EventListenerOrEventListenerObject, 1785 | options?: EventTargetEventListenerOptions | boolean 1786 | ): void; 1787 | 1788 | declare const scheduler: Scheduler; 1789 | 1790 | declare const self: ServiceWorkerGlobalScope; 1791 | 1792 | declare function setInterval( 1793 | callback: (...args: Args) => void, 1794 | msDelay?: number, 1795 | ...args: Args 1796 | ): number; 1797 | 1798 | declare function setTimeout( 1799 | callback: (...args: Args) => void, 1800 | msDelay?: number, 1801 | ...args: Args 1802 | ): number; 1803 | 1804 | declare function structuredClone( 1805 | value: any, 1806 | options?: ServiceWorkerGlobalScopeStructuredCloneOptions 1807 | ): any; 1808 | 1809 | /*** Injected cf.d.ts ***/ 1810 | interface BasicImageTransformations { 1811 | /** 1812 | * Maximum width in image pixels. The value must be an integer. 1813 | */ 1814 | width?: number; 1815 | /** 1816 | * Maximum height in image pixels. The value must be an integer. 1817 | */ 1818 | height?: number; 1819 | /** 1820 | * Resizing mode as a string. It affects interpretation of width and height 1821 | * options: 1822 | * - scale-down: Similar to contain, but the image is never enlarged. If 1823 | * the image is larger than given width or height, it will be resized. 1824 | * Otherwise its original size will be kept. 1825 | * - contain: Resizes to maximum size that fits within the given width and 1826 | * height. If only a single dimension is given (e.g. only width), the 1827 | * image will be shrunk or enlarged to exactly match that dimension. 1828 | * Aspect ratio is always preserved. 1829 | * - cover: Resizes (shrinks or enlarges) to fill the entire area of width 1830 | * and height. If the image has an aspect ratio different from the ratio 1831 | * of width and height, it will be cropped to fit. 1832 | * - crop: The image will be shrunk and cropped to fit within the area 1833 | * specified by width and height. The image will not be enlarged. For images 1834 | * smaller than the given dimensions it's the same as scale-down. For 1835 | * images larger than the given dimensions, it's the same as cover. 1836 | * See also trim. 1837 | * - pad: Resizes to the maximum size that fits within the given width and 1838 | * height, and then fills the remaining area with a background color 1839 | * (white by default). Use of this mode is not recommended, as the same 1840 | * effect can be more efficiently achieved with the contain mode and the 1841 | * CSS object-fit: contain property. 1842 | */ 1843 | fit?: "scale-down" | "contain" | "cover" | "crop" | "pad"; 1844 | /** 1845 | * When cropping with fit: "cover", this defines the side or point that should 1846 | * be left uncropped. The value is either a string 1847 | * "left", "right", "top", "bottom", "auto", or "center" (the default), 1848 | * or an object {x, y} containing focal point coordinates in the original 1849 | * image expressed as fractions ranging from 0.0 (top or left) to 1.0 1850 | * (bottom or right), 0.5 being the center. {fit: "cover", gravity: "top"} will 1851 | * crop bottom or left and right sides as necessary, but won’t crop anything 1852 | * from the top. {fit: "cover", gravity: {x:0.5, y:0.2}} will crop each side to 1853 | * preserve as much as possible around a point at 20% of the height of the 1854 | * source image. 1855 | */ 1856 | gravity?: 1857 | | "left" 1858 | | "right" 1859 | | "top" 1860 | | "bottom" 1861 | | "center" 1862 | | "auto" 1863 | | BasicImageTransformationsGravityCoordinates; 1864 | /** 1865 | * Background color to add underneath the image. Applies only to images with 1866 | * transparency (such as PNG). Accepts any CSS color (#RRGGBB, rgba(…), 1867 | * hsl(…), etc.) 1868 | */ 1869 | background?: string; 1870 | /** 1871 | * Number of degrees (90, 180, 270) to rotate the image by. width and height 1872 | * options refer to axes after rotation. 1873 | */ 1874 | rotate?: 0 | 90 | 180 | 270 | 360; 1875 | } 1876 | 1877 | interface BasicImageTransformationsGravityCoordinates { 1878 | x: number; 1879 | y: number; 1880 | } 1881 | 1882 | /** 1883 | * In addition to the properties you can set in the RequestInit dict 1884 | * that you pass as an argument to the Request constructor, you can 1885 | * set certain properties of a `cf` object to control how Cloudflare 1886 | * features are applied to that new Request. 1887 | * 1888 | * Note: Currently, these properties cannot be tested in the 1889 | * playground. 1890 | */ 1891 | interface RequestInitCfProperties { 1892 | cacheEverything?: boolean; 1893 | /** 1894 | * A request's cache key is what determines if two requests are 1895 | * "the same" for caching purposes. If a request has the same cache key 1896 | * as some previous request, then we can serve the same cached response for 1897 | * both. (e.g. 'some-key') 1898 | * 1899 | * Only available for Enterprise customers. 1900 | */ 1901 | cacheKey?: string; 1902 | /** 1903 | * This allows you to append additional Cache-Tag response headers 1904 | * to the origin response without modifications to the origin server. 1905 | * This will allow for greater control over the Purge by Cache Tag feature 1906 | * utilizing changes only in the Workers process. 1907 | * 1908 | * Only available for Enterprise customers. 1909 | */ 1910 | cacheTags?: string[]; 1911 | /** 1912 | * Force response to be cached for a given number of seconds. (e.g. 300) 1913 | */ 1914 | cacheTtl?: number; 1915 | /** 1916 | * Force response to be cached for a given number of seconds based on the Origin status code. 1917 | * (e.g. { '200-299': 86400, '404': 1, '500-599': 0 }) 1918 | */ 1919 | cacheTtlByStatus?: Record; 1920 | scrapeShield?: boolean; 1921 | apps?: boolean; 1922 | image?: RequestInitCfPropertiesImage; 1923 | minify?: RequestInitCfPropertiesImageMinify; 1924 | mirage?: boolean; 1925 | polish?: "lossy" | "lossless" | "off"; 1926 | /** 1927 | * Redirects the request to an alternate origin server. You can use this, 1928 | * for example, to implement load balancing across several origins. 1929 | * (e.g.us-east.example.com) 1930 | * 1931 | * Note - For security reasons, the hostname set in resolveOverride must 1932 | * be proxied on the same Cloudflare zone of the incoming request. 1933 | * Otherwise, the setting is ignored. CNAME hosts are allowed, so to 1934 | * resolve to a host under a different domain or a DNS only domain first 1935 | * declare a CNAME record within your own zone’s DNS mapping to the 1936 | * external hostname, set proxy on Cloudflare, then set resolveOverride 1937 | * to point to that CNAME record. 1938 | */ 1939 | resolveOverride?: string; 1940 | } 1941 | 1942 | interface RequestInitCfPropertiesImageDraw extends BasicImageTransformations { 1943 | /** 1944 | * Absolute URL of the image file to use for the drawing. It can be any of 1945 | * the supported file formats. For drawing of watermarks or non-rectangular 1946 | * overlays we recommend using PNG or WebP images. 1947 | */ 1948 | url: string; 1949 | /** 1950 | * Floating-point number between 0 (transparent) and 1 (opaque). 1951 | * For example, opacity: 0.5 makes overlay semitransparent. 1952 | */ 1953 | opacity?: number; 1954 | /** 1955 | * - If set to true, the overlay image will be tiled to cover the entire 1956 | * area. This is useful for stock-photo-like watermarks. 1957 | * - If set to "x", the overlay image will be tiled horizontally only 1958 | * (form a line). 1959 | * - If set to "y", the overlay image will be tiled vertically only 1960 | * (form a line). 1961 | */ 1962 | repeat?: true | "x" | "y"; 1963 | /** 1964 | * Position of the overlay image relative to a given edge. Each property is 1965 | * an offset in pixels. 0 aligns exactly to the edge. For example, left: 10 1966 | * positions left side of the overlay 10 pixels from the left edge of the 1967 | * image it's drawn over. bottom: 0 aligns bottom of the overlay with bottom 1968 | * of the background image. 1969 | * 1970 | * Setting both left & right, or both top & bottom is an error. 1971 | * 1972 | * If no position is specified, the image will be centered. 1973 | */ 1974 | top?: number; 1975 | left?: number; 1976 | bottom?: number; 1977 | right?: number; 1978 | } 1979 | 1980 | interface RequestInitCfPropertiesImage extends BasicImageTransformations { 1981 | /** 1982 | * Device Pixel Ratio. Default 1. Multiplier for width/height that makes it 1983 | * easier to specify higher-DPI sizes in . 1984 | */ 1985 | dpr?: number; 1986 | /** 1987 | * An object with four properties {left, top, right, bottom} that specify 1988 | * a number of pixels to cut off on each side. Allows removal of borders 1989 | * or cutting out a specific fragment of an image. Trimming is performed 1990 | * before resizing or rotation. Takes dpr into account. 1991 | */ 1992 | trim?: { 1993 | left?: number; 1994 | top?: number; 1995 | right?: number; 1996 | bottom?: number; 1997 | }; 1998 | /** 1999 | * Quality setting from 1-100 (useful values are in 60-90 range). Lower values 2000 | * make images look worse, but load faster. The default is 85. It applies only 2001 | * to JPEG and WebP images. It doesn’t have any effect on PNG. 2002 | */ 2003 | quality?: number; 2004 | /** 2005 | * Output format to generate. It can be: 2006 | * - avif: generate images in AVIF format. 2007 | * - webp: generate images in Google WebP format. Set quality to 100 to get 2008 | * the WebP-lossless format. 2009 | * - json: instead of generating an image, outputs information about the 2010 | * image, in JSON format. The JSON object will contain image size 2011 | * (before and after resizing), source image’s MIME type, file size, etc. 2012 | * - jpeg: generate images in JPEG format. 2013 | * - png: generate images in PNG format. 2014 | */ 2015 | format?: "avif" | "webp" | "json" | "jpeg" | "png"; 2016 | /** 2017 | * Whether to preserve animation frames from input files. Default is true. 2018 | * Setting it to false reduces animations to still images. This setting is 2019 | * recommended when enlarging images or processing arbitrary user content, 2020 | * because large GIF animations can weigh tens or even hundreds of megabytes. 2021 | * It is also useful to set anim:false when using format:"json" to get the 2022 | * response quicker without the number of frames. 2023 | */ 2024 | anim?: boolean; 2025 | /** 2026 | * What EXIF data should be preserved in the output image. Note that EXIF 2027 | * rotation and embedded color profiles are always applied ("baked in" into 2028 | * the image), and aren't affected by this option. Note that if the Polish 2029 | * feature is enabled, all metadata may have been removed already and this 2030 | * option may have no effect. 2031 | * - keep: Preserve most of EXIF metadata, including GPS location if there's 2032 | * any. 2033 | * - copyright: Only keep the copyright tag, and discard everything else. 2034 | * This is the default behavior for JPEG files. 2035 | * - none: Discard all invisible EXIF metadata. Currently WebP and PNG 2036 | * output formats always discard metadata. 2037 | */ 2038 | metadata?: "keep" | "copyright" | "none"; 2039 | /** 2040 | * Strength of sharpening filter to apply to the image. Floating-point 2041 | * number between 0 (no sharpening, default) and 10 (maximum). 1.0 is a 2042 | * recommended value for downscaled images. 2043 | */ 2044 | sharpen?: number; 2045 | /** 2046 | * Radius of a blur filter (approximate gaussian). Maximum supported radius 2047 | * is 250. 2048 | */ 2049 | blur?: number; 2050 | /** 2051 | * Overlays are drawn in the order they appear in the array (last array 2052 | * entry is the topmost layer). 2053 | */ 2054 | draw?: RequestInitCfPropertiesImageDraw[]; 2055 | /** 2056 | * Fetching image from authenticated origin. Setting this property will 2057 | * pass authentication headers (Authorization, Cookie, etc.) through to 2058 | * the origin. 2059 | */ 2060 | "origin-auth"?: "share-publicly"; 2061 | } 2062 | 2063 | interface RequestInitCfPropertiesImageMinify { 2064 | javascript?: boolean; 2065 | css?: boolean; 2066 | html?: boolean; 2067 | } 2068 | 2069 | /** 2070 | * Request metadata provided by Cloudflare's edge. 2071 | */ 2072 | type IncomingRequestCfProperties = 2073 | IncomingRequestCfPropertiesBase & 2074 | IncomingRequestCfPropertiesBotManagementEnterprise & 2075 | IncomingRequestCfPropertiesCloudflareForSaaSEnterprise & 2076 | IncomingRequestCfPropertiesGeographicInformation & 2077 | IncomingRequestCfPropertiesCloudflareAccessOrApiShield; 2078 | 2079 | interface IncomingRequestCfPropertiesBase { 2080 | /** 2081 | * [ASN](https://www.iana.org/assignments/as-numbers/as-numbers.xhtml) of the incoming request. 2082 | * 2083 | * @example 395747 2084 | */ 2085 | asn: number; 2086 | /** 2087 | * The organization which owns the ASN of the incoming request. 2088 | * 2089 | * @example "Google Cloud" 2090 | */ 2091 | asOrganization: string; 2092 | /** 2093 | * The original value of the `Accept-Encoding` header if Cloudflare modified it. 2094 | * 2095 | * @example "gzip, deflate, br" 2096 | */ 2097 | clientAcceptEncoding?: string; 2098 | /** 2099 | * The number of milliseconds it took for the request to reach your worker. 2100 | * 2101 | * @example 22 2102 | */ 2103 | clientTcpRtt?: number; 2104 | /** 2105 | * The three-letter [IATA](https://en.wikipedia.org/wiki/IATA_airport_code) 2106 | * airport code of the data center that the request hit. 2107 | * 2108 | * @example "DFW" 2109 | */ 2110 | colo: string; 2111 | /** 2112 | * Represents the upstream's response to a 2113 | * [TCP `keepalive` message](https://tldp.org/HOWTO/TCP-Keepalive-HOWTO/overview.html) 2114 | * from cloudflare. 2115 | * 2116 | * For workers with no upstream, this will always be `1`. 2117 | * 2118 | * @example 3 2119 | */ 2120 | edgeRequestKeepAliveStatus: IncomingRequestCfPropertiesEdgeRequestKeepAliveStatus; 2121 | /** 2122 | * The HTTP Protocol the request used. 2123 | * 2124 | * @example "HTTP/2" 2125 | */ 2126 | httpProtocol: string; 2127 | /** 2128 | * The browser-requested prioritization information in the request object. 2129 | * 2130 | * If no information was set, defaults to the empty string `""` 2131 | * 2132 | * @example "weight=192;exclusive=0;group=3;group-weight=127" 2133 | * @default "" 2134 | */ 2135 | requestPriority: string; 2136 | /** 2137 | * The TLS version of the connection to Cloudflare. 2138 | * In requests served over plaintext (without TLS), this property is the empty string `""`. 2139 | * 2140 | * @example "TLSv1.3" 2141 | */ 2142 | tlsVersion: string; 2143 | /** 2144 | * The cipher for the connection to Cloudflare. 2145 | * In requests served over plaintext (without TLS), this property is the empty string `""`. 2146 | * 2147 | * @example "AEAD-AES128-GCM-SHA256" 2148 | */ 2149 | tlsCipher: string; 2150 | /** 2151 | * Metadata containing the [`HELLO`](https://www.rfc-editor.org/rfc/rfc5246#section-7.4.1.2) and [`FINISHED`](https://www.rfc-editor.org/rfc/rfc5246#section-7.4.9) messages from this request's TLS handshake. 2152 | * 2153 | * If the incoming request was served over plaintext (without TLS) this field is undefined. 2154 | */ 2155 | tlsExportedAuthenticator?: IncomingRequestCfPropertiesExportedAuthenticatorMetadata; 2156 | } 2157 | 2158 | interface IncomingRequestCfPropertiesBotManagementBase { 2159 | /** 2160 | * Cloudflare’s [level of certainty](https://developers.cloudflare.com/bots/concepts/bot-score/) that a request comes from a bot, 2161 | * represented as an integer percentage between `1` (almost certainly human) 2162 | * and `99` (almost certainly a bot). 2163 | * 2164 | * @example 54 2165 | */ 2166 | score: number; 2167 | /** 2168 | * A boolean value that is true if the request comes from a good bot, like Google or Bing. 2169 | * Most customers choose to allow this traffic. For more details, see [Traffic from known bots](https://developers.cloudflare.com/firewall/known-issues-and-faq/#how-does-firewall-rules-handle-traffic-from-known-bots). 2170 | */ 2171 | verifiedBot: boolean; 2172 | /** 2173 | * A boolean value that is true if the request originates from a 2174 | * Cloudflare-verified proxy service. 2175 | */ 2176 | corporateProxy: boolean; 2177 | /** 2178 | * 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. 2179 | */ 2180 | staticResource: boolean; 2181 | } 2182 | 2183 | interface IncomingRequestCfPropertiesBotManagement { 2184 | /** 2185 | * Results of Cloudflare's Bot Management analysis 2186 | */ 2187 | botManagement: IncomingRequestCfPropertiesBotManagementBase; 2188 | /** 2189 | * Duplicate of `botManagement.score`. 2190 | * 2191 | * @deprecated 2192 | */ 2193 | clientTrustScore: number; 2194 | } 2195 | 2196 | interface IncomingRequestCfPropertiesBotManagementEnterprise 2197 | extends IncomingRequestCfPropertiesBotManagement { 2198 | /** 2199 | * Results of Cloudflare's Bot Management analysis 2200 | */ 2201 | botManagement: IncomingRequestCfPropertiesBotManagementBase & { 2202 | /** 2203 | * A [JA3 Fingerprint](https://developers.cloudflare.com/bots/concepts/ja3-fingerprint/) to help profile specific SSL/TLS clients 2204 | * across different destination IPs, Ports, and X509 certificates. 2205 | */ 2206 | ja3Hash: string; 2207 | }; 2208 | } 2209 | 2210 | interface IncomingRequestCfPropertiesCloudflareForSaaSEnterprise { 2211 | /** 2212 | * Custom metadata set per-host in [Cloudflare for SaaS](https://developers.cloudflare.com/cloudflare-for-platforms/cloudflare-for-saas/). 2213 | * 2214 | * This field is only present if you have Cloudflare for SaaS enabled on your account 2215 | * and you have followed the [required steps to enable it]((https://developers.cloudflare.com/cloudflare-for-platforms/cloudflare-for-saas/domain-support/custom-metadata/)). 2216 | */ 2217 | hostMetadata: HostMetadata; 2218 | } 2219 | 2220 | interface IncomingRequestCfPropertiesCloudflareAccessOrApiShield { 2221 | /** 2222 | * Information about the client certificate presented to Cloudflare. 2223 | * 2224 | * This is populated when the incoming request is served over TLS using 2225 | * either Cloudflare Access or API Shield (mTLS) 2226 | * and the presented SSL certificate has a valid 2227 | * [Certificate Serial Number](https://ldapwiki.com/wiki/Certificate%20Serial%20Number) 2228 | * (i.e., not `null` or `""`). 2229 | * 2230 | * Otherwise, a set of placeholder values are used. 2231 | * 2232 | * The property `certPresented` will be set to `"1"` when 2233 | * the object is populated (i.e. the above conditions were met). 2234 | */ 2235 | tlsClientAuth: 2236 | | IncomingRequestCfPropertiesTLSClientAuth 2237 | | IncomingRequestCfPropertiesTLSClientAuthPlaceholder; 2238 | } 2239 | 2240 | /** 2241 | * Metadata about the request's TLS handshake 2242 | */ 2243 | interface IncomingRequestCfPropertiesExportedAuthenticatorMetadata { 2244 | /** 2245 | * The client's [`HELLO` message](https://www.rfc-editor.org/rfc/rfc5246#section-7.4.1.2), encoded in hexadecimal 2246 | * 2247 | * @example "44372ba35fa1270921d318f34c12f155dc87b682cf36a790cfaa3ba8737a1b5d" 2248 | */ 2249 | clientHandshake: string; 2250 | /** 2251 | * The server's [`HELLO` message](https://www.rfc-editor.org/rfc/rfc5246#section-7.4.1.2), encoded in hexadecimal 2252 | * 2253 | * @example "44372ba35fa1270921d318f34c12f155dc87b682cf36a790cfaa3ba8737a1b5d" 2254 | */ 2255 | serverHandshake: string; 2256 | /** 2257 | * The client's [`FINISHED` message](https://www.rfc-editor.org/rfc/rfc5246#section-7.4.9), encoded in hexadecimal 2258 | * 2259 | * @example "084ee802fe1348f688220e2a6040a05b2199a761f33cf753abb1b006792d3f8b" 2260 | */ 2261 | clientFinished: string; 2262 | /** 2263 | * The server's [`FINISHED` message](https://www.rfc-editor.org/rfc/rfc5246#section-7.4.9), encoded in hexadecimal 2264 | * 2265 | * @example "084ee802fe1348f688220e2a6040a05b2199a761f33cf753abb1b006792d3f8b" 2266 | */ 2267 | serverFinished: string; 2268 | } 2269 | 2270 | /** 2271 | * Geographic data about the request's origin. 2272 | */ 2273 | type IncomingRequestCfPropertiesGeographicInformation = Partial<{ 2274 | /** 2275 | * The [ISO 3166-1 Alpha 2](https://www.iso.org/iso-3166-country-codes.html) country code the request originated from. 2276 | * 2277 | * 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. 2278 | * 2279 | * If Cloudflare is unable to determine where the request originated this property is omitted. 2280 | * 2281 | * @example "GB" 2282 | * 2283 | */ 2284 | country: Iso3166Alpha2Code | "T1"; 2285 | /** 2286 | * If present, this property indicates that the request originated in the EU 2287 | * 2288 | * @example "1" 2289 | */ 2290 | isEUCountry?: "1"; 2291 | /** 2292 | * A two-letter code indicating the continent the request originated from. 2293 | * 2294 | * @example "AN" 2295 | */ 2296 | continent: ContinentCode; 2297 | /** 2298 | * The city the request originated from 2299 | * 2300 | * @example "Austin" 2301 | */ 2302 | city?: string; 2303 | /** 2304 | * Postal code of the incoming request 2305 | * 2306 | * @example "78701" 2307 | */ 2308 | postalCode?: string; 2309 | /** 2310 | * Latitude of the incoming request 2311 | * 2312 | * @example "30.27130" 2313 | */ 2314 | latitude?: string; 2315 | /** 2316 | * Longitude of the incoming request 2317 | * 2318 | * @example "-97.74260" 2319 | */ 2320 | longitude?: string; 2321 | /** 2322 | * Timezone of the incoming request 2323 | * 2324 | * @example "America/Chicago" 2325 | */ 2326 | timezone?: string; 2327 | /** 2328 | * If known, the ISO 3166-2 name for the first level region associated with 2329 | * the IP address of the incoming request 2330 | * 2331 | * @example "Texas" 2332 | */ 2333 | region?: string; 2334 | /** 2335 | * If known, the ISO 3166-2 code for the first-level region associated with 2336 | * the IP address of the incoming request 2337 | * 2338 | * @example "TX" 2339 | */ 2340 | regionCode?: string; 2341 | /** 2342 | * Metro code (DMA) of the incoming request 2343 | * 2344 | * @example "635" 2345 | */ 2346 | metroCode?: string; 2347 | }>; 2348 | 2349 | /** Data about the incoming request's TLS certificate */ 2350 | interface IncomingRequestCfPropertiesTLSClientAuth { 2351 | /** Always `"1"`, indicating that the certificate was presented */ 2352 | certPresented: "1"; 2353 | /** 2354 | * Result of certificate verification. 2355 | * 2356 | * @example "FAILED:self signed certificate" 2357 | */ 2358 | certVerified: Exclude; 2359 | /** The presented certificate's revokation status. 2360 | * 2361 | * - A value of `"1"` indicates the certificate has been revoked 2362 | * - A value of `"0"` indicates the certificate has not been revoked 2363 | */ 2364 | certRevoked: "1" | "0"; 2365 | /** 2366 | * The certificate issuer's [distinguished name](https://knowledge.digicert.com/generalinformation/INFO1745.html) 2367 | * 2368 | * @example "CN=cloudflareaccess.com, C=US, ST=Texas, L=Austin, O=Cloudflare" 2369 | */ 2370 | certIssuerDN: string; 2371 | /** 2372 | * The certificate subject's [distinguished name](https://knowledge.digicert.com/generalinformation/INFO1745.html) 2373 | * 2374 | * @example "CN=*.cloudflareaccess.com, C=US, ST=Texas, L=Austin, O=Cloudflare" 2375 | */ 2376 | certSubjectDN: string; 2377 | /** 2378 | * The certificate issuer's [distinguished name](https://knowledge.digicert.com/generalinformation/INFO1745.html) ([RFC 2253](https://www.rfc-editor.org/rfc/rfc2253.html) formatted) 2379 | * 2380 | * @example "CN=cloudflareaccess.com, C=US, ST=Texas, L=Austin, O=Cloudflare" 2381 | */ 2382 | certIssuerDNRFC2253: string; 2383 | /** 2384 | * The certificate subject's [distinguished name](https://knowledge.digicert.com/generalinformation/INFO1745.html) ([RFC 2253](https://www.rfc-editor.org/rfc/rfc2253.html) formatted) 2385 | * 2386 | * @example "CN=*.cloudflareaccess.com, C=US, ST=Texas, L=Austin, O=Cloudflare" 2387 | */ 2388 | certSubjectDNRFC2253: string; 2389 | /** The certificate issuer's distinguished name (legacy policies) */ 2390 | certIssuerDNLegacy: string; 2391 | /** The certificate subject's distinguished name (legacy policies) */ 2392 | certSubjectDNLegacy: string; 2393 | /** 2394 | * The certificate's serial number 2395 | * 2396 | * @example "00936EACBE07F201DF" 2397 | */ 2398 | certSerial: string; 2399 | /** 2400 | * The certificate issuer's serial number 2401 | * 2402 | * @example "2489002934BDFEA34" 2403 | */ 2404 | certIssuerSerial: string; 2405 | /** 2406 | * The certificate's Subject Key Identifier 2407 | * 2408 | * @example "BB:AF:7E:02:3D:FA:A6:F1:3C:84:8E:AD:EE:38:98:EC:D9:32:32:D4" 2409 | */ 2410 | certSKI: string; 2411 | /** 2412 | * The certificate issuer's Subject Key Identifier 2413 | * 2414 | * @example "BB:AF:7E:02:3D:FA:A6:F1:3C:84:8E:AD:EE:38:98:EC:D9:32:32:D4" 2415 | */ 2416 | certIssuerSKI: string; 2417 | /** 2418 | * The certificate's SHA-1 fingerprint 2419 | * 2420 | * @example "6b9109f323999e52259cda7373ff0b4d26bd232e" 2421 | */ 2422 | certFingerprintSHA1: string; 2423 | /** 2424 | * The certificate's SHA-256 fingerprint 2425 | * 2426 | * @example "acf77cf37b4156a2708e34c4eb755f9b5dbbe5ebb55adfec8f11493438d19e6ad3f157f81fa3b98278453d5652b0c1fd1d71e5695ae4d709803a4d3f39de9dea" 2427 | */ 2428 | certFingerprintSHA256: string; 2429 | /** 2430 | * The effective starting date of the certificate 2431 | * 2432 | * @example "Dec 22 19:39:00 2018 GMT" 2433 | */ 2434 | certNotBefore: string; 2435 | /** 2436 | * The effective expiration date of the certificate 2437 | * 2438 | * @example "Dec 22 19:39:00 2018 GMT" 2439 | */ 2440 | certNotAfter: string; 2441 | } 2442 | 2443 | /** Placeholder values for TLS Client Authorization */ 2444 | interface IncomingRequestCfPropertiesTLSClientAuthPlaceholder { 2445 | certPresented: "0"; 2446 | certVerified: "NONE"; 2447 | certRevoked: "0"; 2448 | certIssuerDN: ""; 2449 | certSubjectDN: ""; 2450 | certIssuerDNRFC2253: ""; 2451 | certSubjectDNRFC2253: ""; 2452 | certIssuerDNLegacy: ""; 2453 | certSubjectDNLegacy: ""; 2454 | certSerial: ""; 2455 | certIssuerSerial: ""; 2456 | certSKI: ""; 2457 | certIssuerSKI: ""; 2458 | certFingerprintSHA1: ""; 2459 | certFingerprintSHA256: ""; 2460 | certNotBefore: ""; 2461 | certNotAfter: ""; 2462 | } 2463 | 2464 | /** Possible outcomes of TLS verification */ 2465 | declare type CertVerificationStatus = 2466 | /** Authentication succeeded */ 2467 | | "SUCCESS" 2468 | /** No certificate was presented */ 2469 | | "NONE" 2470 | /** Failed because the certificate was self-signed */ 2471 | | "FAILED:self signed certificate" 2472 | /** Failed because the certificate failed a trust chain check */ 2473 | | "FAILED:unable to verify the first certificate" 2474 | /** Failed because the certificate not yet valid */ 2475 | | "FAILED:certificate is not yet valid" 2476 | /** Failed because the certificate is expired */ 2477 | | "FAILED:certificate has expired" 2478 | /** Failed for another unspecified reason */ 2479 | | "FAILED"; 2480 | 2481 | /** 2482 | * An upstream endpoint's response to a TCP `keepalive` message from Cloudflare. 2483 | */ 2484 | declare type IncomingRequestCfPropertiesEdgeRequestKeepAliveStatus = 2485 | | 0 /** Unknown */ 2486 | | 1 /** no keepalives (not found) */ 2487 | | 2 /** no connection re-use, opening keepalive connection failed */ 2488 | | 3 /** no connection re-use, keepalive accepted and saved */ 2489 | | 4 /** connection re-use, refused by the origin server (`TCP FIN`) */ 2490 | | 5; /** connection re-use, accepted by the origin server */ 2491 | 2492 | /** ISO 3166-1 Alpha-2 codes */ 2493 | declare type Iso3166Alpha2Code = 2494 | | "AD" 2495 | | "AE" 2496 | | "AF" 2497 | | "AG" 2498 | | "AI" 2499 | | "AL" 2500 | | "AM" 2501 | | "AO" 2502 | | "AQ" 2503 | | "AR" 2504 | | "AS" 2505 | | "AT" 2506 | | "AU" 2507 | | "AW" 2508 | | "AX" 2509 | | "AZ" 2510 | | "BA" 2511 | | "BB" 2512 | | "BD" 2513 | | "BE" 2514 | | "BF" 2515 | | "BG" 2516 | | "BH" 2517 | | "BI" 2518 | | "BJ" 2519 | | "BL" 2520 | | "BM" 2521 | | "BN" 2522 | | "BO" 2523 | | "BQ" 2524 | | "BR" 2525 | | "BS" 2526 | | "BT" 2527 | | "BV" 2528 | | "BW" 2529 | | "BY" 2530 | | "BZ" 2531 | | "CA" 2532 | | "CC" 2533 | | "CD" 2534 | | "CF" 2535 | | "CG" 2536 | | "CH" 2537 | | "CI" 2538 | | "CK" 2539 | | "CL" 2540 | | "CM" 2541 | | "CN" 2542 | | "CO" 2543 | | "CR" 2544 | | "CU" 2545 | | "CV" 2546 | | "CW" 2547 | | "CX" 2548 | | "CY" 2549 | | "CZ" 2550 | | "DE" 2551 | | "DJ" 2552 | | "DK" 2553 | | "DM" 2554 | | "DO" 2555 | | "DZ" 2556 | | "EC" 2557 | | "EE" 2558 | | "EG" 2559 | | "EH" 2560 | | "ER" 2561 | | "ES" 2562 | | "ET" 2563 | | "FI" 2564 | | "FJ" 2565 | | "FK" 2566 | | "FM" 2567 | | "FO" 2568 | | "FR" 2569 | | "GA" 2570 | | "GB" 2571 | | "GD" 2572 | | "GE" 2573 | | "GF" 2574 | | "GG" 2575 | | "GH" 2576 | | "GI" 2577 | | "GL" 2578 | | "GM" 2579 | | "GN" 2580 | | "GP" 2581 | | "GQ" 2582 | | "GR" 2583 | | "GS" 2584 | | "GT" 2585 | | "GU" 2586 | | "GW" 2587 | | "GY" 2588 | | "HK" 2589 | | "HM" 2590 | | "HN" 2591 | | "HR" 2592 | | "HT" 2593 | | "HU" 2594 | | "ID" 2595 | | "IE" 2596 | | "IL" 2597 | | "IM" 2598 | | "IN" 2599 | | "IO" 2600 | | "IQ" 2601 | | "IR" 2602 | | "IS" 2603 | | "IT" 2604 | | "JE" 2605 | | "JM" 2606 | | "JO" 2607 | | "JP" 2608 | | "KE" 2609 | | "KG" 2610 | | "KH" 2611 | | "KI" 2612 | | "KM" 2613 | | "KN" 2614 | | "KP" 2615 | | "KR" 2616 | | "KW" 2617 | | "KY" 2618 | | "KZ" 2619 | | "LA" 2620 | | "LB" 2621 | | "LC" 2622 | | "LI" 2623 | | "LK" 2624 | | "LR" 2625 | | "LS" 2626 | | "LT" 2627 | | "LU" 2628 | | "LV" 2629 | | "LY" 2630 | | "MA" 2631 | | "MC" 2632 | | "MD" 2633 | | "ME" 2634 | | "MF" 2635 | | "MG" 2636 | | "MH" 2637 | | "MK" 2638 | | "ML" 2639 | | "MM" 2640 | | "MN" 2641 | | "MO" 2642 | | "MP" 2643 | | "MQ" 2644 | | "MR" 2645 | | "MS" 2646 | | "MT" 2647 | | "MU" 2648 | | "MV" 2649 | | "MW" 2650 | | "MX" 2651 | | "MY" 2652 | | "MZ" 2653 | | "NA" 2654 | | "NC" 2655 | | "NE" 2656 | | "NF" 2657 | | "NG" 2658 | | "NI" 2659 | | "NL" 2660 | | "NO" 2661 | | "NP" 2662 | | "NR" 2663 | | "NU" 2664 | | "NZ" 2665 | | "OM" 2666 | | "PA" 2667 | | "PE" 2668 | | "PF" 2669 | | "PG" 2670 | | "PH" 2671 | | "PK" 2672 | | "PL" 2673 | | "PM" 2674 | | "PN" 2675 | | "PR" 2676 | | "PS" 2677 | | "PT" 2678 | | "PW" 2679 | | "PY" 2680 | | "QA" 2681 | | "RE" 2682 | | "RO" 2683 | | "RS" 2684 | | "RU" 2685 | | "RW" 2686 | | "SA" 2687 | | "SB" 2688 | | "SC" 2689 | | "SD" 2690 | | "SE" 2691 | | "SG" 2692 | | "SH" 2693 | | "SI" 2694 | | "SJ" 2695 | | "SK" 2696 | | "SL" 2697 | | "SM" 2698 | | "SN" 2699 | | "SO" 2700 | | "SR" 2701 | | "SS" 2702 | | "ST" 2703 | | "SV" 2704 | | "SX" 2705 | | "SY" 2706 | | "SZ" 2707 | | "TC" 2708 | | "TD" 2709 | | "TF" 2710 | | "TG" 2711 | | "TH" 2712 | | "TJ" 2713 | | "TK" 2714 | | "TL" 2715 | | "TM" 2716 | | "TN" 2717 | | "TO" 2718 | | "TR" 2719 | | "TT" 2720 | | "TV" 2721 | | "TW" 2722 | | "TZ" 2723 | | "UA" 2724 | | "UG" 2725 | | "UM" 2726 | | "US" 2727 | | "UY" 2728 | | "UZ" 2729 | | "VA" 2730 | | "VC" 2731 | | "VE" 2732 | | "VG" 2733 | | "VI" 2734 | | "VN" 2735 | | "VU" 2736 | | "WF" 2737 | | "WS" 2738 | | "YE" 2739 | | "YT" 2740 | | "ZA" 2741 | | "ZM" 2742 | | "ZW"; 2743 | 2744 | /** The 2-letter continent codes Cloudflare uses */ 2745 | declare type ContinentCode = "AF" | "AN" | "AS" | "EU" | "NA" | "OC" | "SA"; 2746 | /*** Injected pages.d.ts ***/ 2747 | type Params

= Record; 2748 | 2749 | type EventContext = { 2750 | request: Request; 2751 | functionPath: string; 2752 | waitUntil: (promise: Promise) => void; 2753 | next: (input?: Request | string, init?: RequestInit) => Promise; 2754 | env: Env & { ASSETS: { fetch: typeof fetch } }; 2755 | params: Params

; 2756 | data: Data; 2757 | }; 2758 | 2759 | declare type PagesFunction< 2760 | Env = unknown, 2761 | Params extends string = any, 2762 | Data extends Record = Record 2763 | > = (context: EventContext) => Response | Promise; 2764 | 2765 | type EventPluginContext = { 2766 | request: Request; 2767 | functionPath: string; 2768 | waitUntil: (promise: Promise) => void; 2769 | next: (input?: Request | string, init?: RequestInit) => Promise; 2770 | env: Env & { ASSETS: { fetch: typeof fetch } }; 2771 | params: Params

; 2772 | data: Data; 2773 | pluginArgs: PluginArgs; 2774 | }; 2775 | 2776 | declare type PagesPluginFunction< 2777 | Env = unknown, 2778 | Params extends string = any, 2779 | Data extends Record = Record, 2780 | PluginArgs = unknown 2781 | > = ( 2782 | context: EventPluginContext 2783 | ) => Response | Promise; 2784 | 2785 | declare module "assets:*" { 2786 | export const onRequest: PagesFunction; 2787 | } 2788 | -------------------------------------------------------------------------------- /manual-ts/cf.d.ts: -------------------------------------------------------------------------------- 1 | interface BasicImageTransformations { 2 | /** 3 | * Maximum width in image pixels. The value must be an integer. 4 | */ 5 | width?: number; 6 | /** 7 | * Maximum height in image pixels. The value must be an integer. 8 | */ 9 | height?: number; 10 | /** 11 | * Resizing mode as a string. It affects interpretation of width and height 12 | * options: 13 | * - scale-down: Similar to contain, but the image is never enlarged. If 14 | * the image is larger than given width or height, it will be resized. 15 | * Otherwise its original size will be kept. 16 | * - contain: Resizes to maximum size that fits within the given width and 17 | * height. If only a single dimension is given (e.g. only width), the 18 | * image will be shrunk or enlarged to exactly match that dimension. 19 | * Aspect ratio is always preserved. 20 | * - cover: Resizes (shrinks or enlarges) to fill the entire area of width 21 | * and height. If the image has an aspect ratio different from the ratio 22 | * of width and height, it will be cropped to fit. 23 | * - crop: The image will be shrunk and cropped to fit within the area 24 | * specified by width and height. The image will not be enlarged. For images 25 | * smaller than the given dimensions it's the same as scale-down. For 26 | * images larger than the given dimensions, it's the same as cover. 27 | * See also trim. 28 | * - pad: Resizes to the maximum size that fits within the given width and 29 | * height, and then fills the remaining area with a background color 30 | * (white by default). Use of this mode is not recommended, as the same 31 | * effect can be more efficiently achieved with the contain mode and the 32 | * CSS object-fit: contain property. 33 | */ 34 | fit?: "scale-down" | "contain" | "cover" | "crop" | "pad"; 35 | /** 36 | * When cropping with fit: "cover", this defines the side or point that should 37 | * be left uncropped. The value is either a string 38 | * "left", "right", "top", "bottom", "auto", or "center" (the default), 39 | * or an object {x, y} containing focal point coordinates in the original 40 | * image expressed as fractions ranging from 0.0 (top or left) to 1.0 41 | * (bottom or right), 0.5 being the center. {fit: "cover", gravity: "top"} will 42 | * crop bottom or left and right sides as necessary, but won’t crop anything 43 | * from the top. {fit: "cover", gravity: {x:0.5, y:0.2}} will crop each side to 44 | * preserve as much as possible around a point at 20% of the height of the 45 | * source image. 46 | */ 47 | gravity?: 48 | | "left" 49 | | "right" 50 | | "top" 51 | | "bottom" 52 | | "center" 53 | | "auto" 54 | | BasicImageTransformationsGravityCoordinates; 55 | /** 56 | * Background color to add underneath the image. Applies only to images with 57 | * transparency (such as PNG). Accepts any CSS color (#RRGGBB, rgba(…), 58 | * hsl(…), etc.) 59 | */ 60 | background?: string; 61 | /** 62 | * Number of degrees (90, 180, 270) to rotate the image by. width and height 63 | * options refer to axes after rotation. 64 | */ 65 | rotate?: 0 | 90 | 180 | 270 | 360; 66 | } 67 | 68 | interface BasicImageTransformationsGravityCoordinates { 69 | x: number; 70 | y: number; 71 | } 72 | 73 | /** 74 | * In addition to the properties you can set in the RequestInit dict 75 | * that you pass as an argument to the Request constructor, you can 76 | * set certain properties of a `cf` object to control how Cloudflare 77 | * features are applied to that new Request. 78 | * 79 | * Note: Currently, these properties cannot be tested in the 80 | * playground. 81 | */ 82 | interface RequestInitCfProperties { 83 | cacheEverything?: boolean; 84 | /** 85 | * A request's cache key is what determines if two requests are 86 | * "the same" for caching purposes. If a request has the same cache key 87 | * as some previous request, then we can serve the same cached response for 88 | * both. (e.g. 'some-key') 89 | * 90 | * Only available for Enterprise customers. 91 | */ 92 | cacheKey?: string; 93 | /** 94 | * This allows you to append additional Cache-Tag response headers 95 | * to the origin response without modifications to the origin server. 96 | * This will allow for greater control over the Purge by Cache Tag feature 97 | * utilizing changes only in the Workers process. 98 | * 99 | * Only available for Enterprise customers. 100 | */ 101 | cacheTags?: string[]; 102 | /** 103 | * Force response to be cached for a given number of seconds. (e.g. 300) 104 | */ 105 | cacheTtl?: number; 106 | /** 107 | * Force response to be cached for a given number of seconds based on the Origin status code. 108 | * (e.g. { '200-299': 86400, '404': 1, '500-599': 0 }) 109 | */ 110 | cacheTtlByStatus?: Record; 111 | scrapeShield?: boolean; 112 | apps?: boolean; 113 | image?: RequestInitCfPropertiesImage; 114 | minify?: RequestInitCfPropertiesImageMinify; 115 | mirage?: boolean; 116 | polish?: "lossy" | "lossless" | "off"; 117 | /** 118 | * Redirects the request to an alternate origin server. You can use this, 119 | * for example, to implement load balancing across several origins. 120 | * (e.g.us-east.example.com) 121 | * 122 | * Note - For security reasons, the hostname set in resolveOverride must 123 | * be proxied on the same Cloudflare zone of the incoming request. 124 | * Otherwise, the setting is ignored. CNAME hosts are allowed, so to 125 | * resolve to a host under a different domain or a DNS only domain first 126 | * declare a CNAME record within your own zone’s DNS mapping to the 127 | * external hostname, set proxy on Cloudflare, then set resolveOverride 128 | * to point to that CNAME record. 129 | */ 130 | resolveOverride?: string; 131 | } 132 | 133 | interface RequestInitCfPropertiesImageDraw extends BasicImageTransformations { 134 | /** 135 | * Absolute URL of the image file to use for the drawing. It can be any of 136 | * the supported file formats. For drawing of watermarks or non-rectangular 137 | * overlays we recommend using PNG or WebP images. 138 | */ 139 | url: string; 140 | /** 141 | * Floating-point number between 0 (transparent) and 1 (opaque). 142 | * For example, opacity: 0.5 makes overlay semitransparent. 143 | */ 144 | opacity?: number; 145 | /** 146 | * - If set to true, the overlay image will be tiled to cover the entire 147 | * area. This is useful for stock-photo-like watermarks. 148 | * - If set to "x", the overlay image will be tiled horizontally only 149 | * (form a line). 150 | * - If set to "y", the overlay image will be tiled vertically only 151 | * (form a line). 152 | */ 153 | repeat?: true | "x" | "y"; 154 | /** 155 | * Position of the overlay image relative to a given edge. Each property is 156 | * an offset in pixels. 0 aligns exactly to the edge. For example, left: 10 157 | * positions left side of the overlay 10 pixels from the left edge of the 158 | * image it's drawn over. bottom: 0 aligns bottom of the overlay with bottom 159 | * of the background image. 160 | * 161 | * Setting both left & right, or both top & bottom is an error. 162 | * 163 | * If no position is specified, the image will be centered. 164 | */ 165 | top?: number; 166 | left?: number; 167 | bottom?: number; 168 | right?: number; 169 | } 170 | 171 | interface RequestInitCfPropertiesImage extends BasicImageTransformations { 172 | /** 173 | * Device Pixel Ratio. Default 1. Multiplier for width/height that makes it 174 | * easier to specify higher-DPI sizes in . 175 | */ 176 | dpr?: number; 177 | /** 178 | * An object with four properties {left, top, right, bottom} that specify 179 | * a number of pixels to cut off on each side. Allows removal of borders 180 | * or cutting out a specific fragment of an image. Trimming is performed 181 | * before resizing or rotation. Takes dpr into account. 182 | */ 183 | trim?: { 184 | left?: number; 185 | top?: number; 186 | right?: number; 187 | bottom?: number; 188 | }; 189 | /** 190 | * Quality setting from 1-100 (useful values are in 60-90 range). Lower values 191 | * make images look worse, but load faster. The default is 85. It applies only 192 | * to JPEG and WebP images. It doesn’t have any effect on PNG. 193 | */ 194 | quality?: number; 195 | /** 196 | * Output format to generate. It can be: 197 | * - avif: generate images in AVIF format. 198 | * - webp: generate images in Google WebP format. Set quality to 100 to get 199 | * the WebP-lossless format. 200 | * - json: instead of generating an image, outputs information about the 201 | * image, in JSON format. The JSON object will contain image size 202 | * (before and after resizing), source image’s MIME type, file size, etc. 203 | * - jpeg: generate images in JPEG format. 204 | * - png: generate images in PNG format. 205 | */ 206 | format?: "avif" | "webp" | "json" | "jpeg" | "png"; 207 | /** 208 | * Whether to preserve animation frames from input files. Default is true. 209 | * Setting it to false reduces animations to still images. This setting is 210 | * recommended when enlarging images or processing arbitrary user content, 211 | * because large GIF animations can weigh tens or even hundreds of megabytes. 212 | * It is also useful to set anim:false when using format:"json" to get the 213 | * response quicker without the number of frames. 214 | */ 215 | anim?: boolean; 216 | /** 217 | * What EXIF data should be preserved in the output image. Note that EXIF 218 | * rotation and embedded color profiles are always applied ("baked in" into 219 | * the image), and aren't affected by this option. Note that if the Polish 220 | * feature is enabled, all metadata may have been removed already and this 221 | * option may have no effect. 222 | * - keep: Preserve most of EXIF metadata, including GPS location if there's 223 | * any. 224 | * - copyright: Only keep the copyright tag, and discard everything else. 225 | * This is the default behavior for JPEG files. 226 | * - none: Discard all invisible EXIF metadata. Currently WebP and PNG 227 | * output formats always discard metadata. 228 | */ 229 | metadata?: "keep" | "copyright" | "none"; 230 | /** 231 | * Strength of sharpening filter to apply to the image. Floating-point 232 | * number between 0 (no sharpening, default) and 10 (maximum). 1.0 is a 233 | * recommended value for downscaled images. 234 | */ 235 | sharpen?: number; 236 | /** 237 | * Radius of a blur filter (approximate gaussian). Maximum supported radius 238 | * is 250. 239 | */ 240 | blur?: number; 241 | /** 242 | * Overlays are drawn in the order they appear in the array (last array 243 | * entry is the topmost layer). 244 | */ 245 | draw?: RequestInitCfPropertiesImageDraw[]; 246 | /** 247 | * Fetching image from authenticated origin. Setting this property will 248 | * pass authentication headers (Authorization, Cookie, etc.) through to 249 | * the origin. 250 | */ 251 | "origin-auth"?: "share-publicly"; 252 | } 253 | 254 | interface RequestInitCfPropertiesImageMinify { 255 | javascript?: boolean; 256 | css?: boolean; 257 | html?: boolean; 258 | } 259 | 260 | /** 261 | * Request metadata provided by Cloudflare's edge. 262 | */ 263 | type IncomingRequestCfProperties = 264 | IncomingRequestCfPropertiesBase & 265 | IncomingRequestCfPropertiesBotManagementEnterprise & 266 | IncomingRequestCfPropertiesCloudflareForSaaSEnterprise & 267 | IncomingRequestCfPropertiesGeographicInformation & 268 | IncomingRequestCfPropertiesCloudflareAccessOrApiShield; 269 | 270 | interface IncomingRequestCfPropertiesBase { 271 | /** 272 | * [ASN](https://www.iana.org/assignments/as-numbers/as-numbers.xhtml) of the incoming request. 273 | * 274 | * @example 395747 275 | */ 276 | asn: number; 277 | /** 278 | * The organization which owns the ASN of the incoming request. 279 | * 280 | * @example "Google Cloud" 281 | */ 282 | asOrganization: string; 283 | /** 284 | * The original value of the `Accept-Encoding` header if Cloudflare modified it. 285 | * 286 | * @example "gzip, deflate, br" 287 | */ 288 | clientAcceptEncoding?: string; 289 | /** 290 | * The number of milliseconds it took for the request to reach your worker. 291 | * 292 | * @example 22 293 | */ 294 | clientTcpRtt?: number; 295 | /** 296 | * The three-letter [IATA](https://en.wikipedia.org/wiki/IATA_airport_code) 297 | * airport code of the data center that the request hit. 298 | * 299 | * @example "DFW" 300 | */ 301 | colo: string; 302 | /** 303 | * Represents the upstream's response to a 304 | * [TCP `keepalive` message](https://tldp.org/HOWTO/TCP-Keepalive-HOWTO/overview.html) 305 | * from cloudflare. 306 | * 307 | * For workers with no upstream, this will always be `1`. 308 | * 309 | * @example 3 310 | */ 311 | edgeRequestKeepAliveStatus: IncomingRequestCfPropertiesEdgeRequestKeepAliveStatus; 312 | /** 313 | * The HTTP Protocol the request used. 314 | * 315 | * @example "HTTP/2" 316 | */ 317 | httpProtocol: string; 318 | /** 319 | * The browser-requested prioritization information in the request object. 320 | * 321 | * If no information was set, defaults to the empty string `""` 322 | * 323 | * @example "weight=192;exclusive=0;group=3;group-weight=127" 324 | * @default "" 325 | */ 326 | requestPriority: string; 327 | /** 328 | * The TLS version of the connection to Cloudflare. 329 | * In requests served over plaintext (without TLS), this property is the empty string `""`. 330 | * 331 | * @example "TLSv1.3" 332 | */ 333 | tlsVersion: string; 334 | /** 335 | * The cipher for the connection to Cloudflare. 336 | * In requests served over plaintext (without TLS), this property is the empty string `""`. 337 | * 338 | * @example "AEAD-AES128-GCM-SHA256" 339 | */ 340 | tlsCipher: string; 341 | /** 342 | * Metadata containing the [`HELLO`](https://www.rfc-editor.org/rfc/rfc5246#section-7.4.1.2) and [`FINISHED`](https://www.rfc-editor.org/rfc/rfc5246#section-7.4.9) messages from this request's TLS handshake. 343 | * 344 | * If the incoming request was served over plaintext (without TLS) this field is undefined. 345 | */ 346 | tlsExportedAuthenticator?: IncomingRequestCfPropertiesExportedAuthenticatorMetadata; 347 | } 348 | 349 | interface IncomingRequestCfPropertiesBotManagementBase { 350 | /** 351 | * Cloudflare’s [level of certainty](https://developers.cloudflare.com/bots/concepts/bot-score/) that a request comes from a bot, 352 | * represented as an integer percentage between `1` (almost certainly human) 353 | * and `99` (almost certainly a bot). 354 | * 355 | * @example 54 356 | */ 357 | score: number; 358 | /** 359 | * A boolean value that is true if the request comes from a good bot, like Google or Bing. 360 | * Most customers choose to allow this traffic. For more details, see [Traffic from known bots](https://developers.cloudflare.com/firewall/known-issues-and-faq/#how-does-firewall-rules-handle-traffic-from-known-bots). 361 | */ 362 | verifiedBot: boolean; 363 | /** 364 | * A boolean value that is true if the request originates from a 365 | * Cloudflare-verified proxy service. 366 | */ 367 | corporateProxy: boolean; 368 | /** 369 | * 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. 370 | */ 371 | staticResource: boolean; 372 | } 373 | 374 | interface IncomingRequestCfPropertiesBotManagement { 375 | /** 376 | * Results of Cloudflare's Bot Management analysis 377 | */ 378 | botManagement: IncomingRequestCfPropertiesBotManagementBase; 379 | /** 380 | * Duplicate of `botManagement.score`. 381 | * 382 | * @deprecated 383 | */ 384 | clientTrustScore: number; 385 | } 386 | 387 | interface IncomingRequestCfPropertiesBotManagementEnterprise 388 | extends IncomingRequestCfPropertiesBotManagement { 389 | /** 390 | * Results of Cloudflare's Bot Management analysis 391 | */ 392 | botManagement: IncomingRequestCfPropertiesBotManagementBase & { 393 | /** 394 | * A [JA3 Fingerprint](https://developers.cloudflare.com/bots/concepts/ja3-fingerprint/) to help profile specific SSL/TLS clients 395 | * across different destination IPs, Ports, and X509 certificates. 396 | */ 397 | ja3Hash: string; 398 | }; 399 | } 400 | 401 | interface IncomingRequestCfPropertiesCloudflareForSaaSEnterprise { 402 | /** 403 | * Custom metadata set per-host in [Cloudflare for SaaS](https://developers.cloudflare.com/cloudflare-for-platforms/cloudflare-for-saas/). 404 | * 405 | * This field is only present if you have Cloudflare for SaaS enabled on your account 406 | * and you have followed the [required steps to enable it]((https://developers.cloudflare.com/cloudflare-for-platforms/cloudflare-for-saas/domain-support/custom-metadata/)). 407 | */ 408 | hostMetadata: HostMetadata; 409 | } 410 | 411 | interface IncomingRequestCfPropertiesCloudflareAccessOrApiShield { 412 | /** 413 | * Information about the client certificate presented to Cloudflare. 414 | * 415 | * This is populated when the incoming request is served over TLS using 416 | * either Cloudflare Access or API Shield (mTLS) 417 | * and the presented SSL certificate has a valid 418 | * [Certificate Serial Number](https://ldapwiki.com/wiki/Certificate%20Serial%20Number) 419 | * (i.e., not `null` or `""`). 420 | * 421 | * Otherwise, a set of placeholder values are used. 422 | * 423 | * The property `certPresented` will be set to `"1"` when 424 | * the object is populated (i.e. the above conditions were met). 425 | */ 426 | tlsClientAuth: 427 | | IncomingRequestCfPropertiesTLSClientAuth 428 | | IncomingRequestCfPropertiesTLSClientAuthPlaceholder; 429 | } 430 | 431 | /** 432 | * Metadata about the request's TLS handshake 433 | */ 434 | interface IncomingRequestCfPropertiesExportedAuthenticatorMetadata { 435 | /** 436 | * The client's [`HELLO` message](https://www.rfc-editor.org/rfc/rfc5246#section-7.4.1.2), encoded in hexadecimal 437 | * 438 | * @example "44372ba35fa1270921d318f34c12f155dc87b682cf36a790cfaa3ba8737a1b5d" 439 | */ 440 | clientHandshake: string; 441 | /** 442 | * The server's [`HELLO` message](https://www.rfc-editor.org/rfc/rfc5246#section-7.4.1.2), encoded in hexadecimal 443 | * 444 | * @example "44372ba35fa1270921d318f34c12f155dc87b682cf36a790cfaa3ba8737a1b5d" 445 | */ 446 | serverHandshake: string; 447 | /** 448 | * The client's [`FINISHED` message](https://www.rfc-editor.org/rfc/rfc5246#section-7.4.9), encoded in hexadecimal 449 | * 450 | * @example "084ee802fe1348f688220e2a6040a05b2199a761f33cf753abb1b006792d3f8b" 451 | */ 452 | clientFinished: string; 453 | /** 454 | * The server's [`FINISHED` message](https://www.rfc-editor.org/rfc/rfc5246#section-7.4.9), encoded in hexadecimal 455 | * 456 | * @example "084ee802fe1348f688220e2a6040a05b2199a761f33cf753abb1b006792d3f8b" 457 | */ 458 | serverFinished: string; 459 | } 460 | 461 | /** 462 | * Geographic data about the request's origin. 463 | */ 464 | type IncomingRequestCfPropertiesGeographicInformation = 465 | | { 466 | /* No geographic data was found for the incoming request. */ 467 | } 468 | | { 469 | /** The country code `"T1"` is used for requests originating on TOR */ 470 | country: "T1"; 471 | } 472 | | { 473 | /** 474 | * The [ISO 3166-1 Alpha 2](https://www.iso.org/iso-3166-country-codes.html) country code the request originated from. 475 | * 476 | * 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. 477 | * 478 | * If Cloudflare is unable to determine where the request originated this property is omitted. 479 | * 480 | * @example "GB" 481 | */ 482 | country: Iso3166Alpha2Code; 483 | /** 484 | * If present, this property indicates that the request originated in the EU 485 | * 486 | * @example "1" 487 | */ 488 | isEUCountry?: "1"; 489 | /** 490 | * A two-letter code indicating the continent the request originated from. 491 | * 492 | * @example "AN" 493 | */ 494 | continent: ContinentCode; 495 | /** 496 | * The city the request originated from 497 | * 498 | * @example "Austin" 499 | */ 500 | city?: string; 501 | /** 502 | * Postal code of the incoming request 503 | * 504 | * @example "78701" 505 | */ 506 | postalCode?: string; 507 | /** 508 | * Latitude of the incoming request 509 | * 510 | * @example "30.27130" 511 | */ 512 | latitude?: string; 513 | /** 514 | * Longitude of the incoming request 515 | * 516 | * @example "-97.74260" 517 | */ 518 | longitude?: string; 519 | /** 520 | * Timezone of the incoming request 521 | * 522 | * @example "America/Chicago" 523 | */ 524 | timezone?: string; 525 | /** 526 | * If known, the ISO 3166-2 name for the first level region associated with 527 | * the IP address of the incoming request 528 | * 529 | * @example "Texas" 530 | */ 531 | region?: string; 532 | /** 533 | * If known, the ISO 3166-2 code for the first-level region associated with 534 | * the IP address of the incoming request 535 | * 536 | * @example "TX" 537 | */ 538 | regionCode?: string; 539 | /** 540 | * Metro code (DMA) of the incoming request 541 | * 542 | * @example "635" 543 | */ 544 | metroCode?: string; 545 | }; 546 | 547 | /** Data about the incoming request's TLS certificate */ 548 | interface IncomingRequestCfPropertiesTLSClientAuth { 549 | /** Always `"1"`, indicating that the certificate was presented */ 550 | certPresented: "1"; 551 | /** 552 | * Result of certificate verification. 553 | * 554 | * @example "FAILED:self signed certificate" 555 | */ 556 | certVerified: Exclude; 557 | /** The presented certificate's revokation status. 558 | * 559 | * - A value of `"1"` indicates the certificate has been revoked 560 | * - A value of `"0"` indicates the certificate has not been revoked 561 | */ 562 | certRevoked: "1" | "0"; 563 | /** 564 | * The certificate issuer's [distinguished name](https://knowledge.digicert.com/generalinformation/INFO1745.html) 565 | * 566 | * @example "CN=cloudflareaccess.com, C=US, ST=Texas, L=Austin, O=Cloudflare" 567 | */ 568 | certIssuerDN: string; 569 | /** 570 | * The certificate subject's [distinguished name](https://knowledge.digicert.com/generalinformation/INFO1745.html) 571 | * 572 | * @example "CN=*.cloudflareaccess.com, C=US, ST=Texas, L=Austin, O=Cloudflare" 573 | */ 574 | certSubjectDN: string; 575 | /** 576 | * The certificate issuer's [distinguished name](https://knowledge.digicert.com/generalinformation/INFO1745.html) ([RFC 2253](https://www.rfc-editor.org/rfc/rfc2253.html) formatted) 577 | * 578 | * @example "CN=cloudflareaccess.com, C=US, ST=Texas, L=Austin, O=Cloudflare" 579 | */ 580 | certIssuerDNRFC2253: string; 581 | /** 582 | * The certificate subject's [distinguished name](https://knowledge.digicert.com/generalinformation/INFO1745.html) ([RFC 2253](https://www.rfc-editor.org/rfc/rfc2253.html) formatted) 583 | * 584 | * @example "CN=*.cloudflareaccess.com, C=US, ST=Texas, L=Austin, O=Cloudflare" 585 | */ 586 | certSubjectDNRFC2253: string; 587 | /** The certificate issuer's distinguished name (legacy policies) */ 588 | certIssuerDNLegacy: string; 589 | /** The certificate subject's distinguished name (legacy policies) */ 590 | certSubjectDNLegacy: string; 591 | /** 592 | * The certificate's serial number 593 | * 594 | * @example "00936EACBE07F201DF" 595 | */ 596 | certSerial: string; 597 | /** 598 | * The certificate issuer's serial number 599 | * 600 | * @example "2489002934BDFEA34" 601 | */ 602 | certIssuerSerial: string; 603 | /** 604 | * The certificate's Subject Key Identifier 605 | * 606 | * @example "BB:AF:7E:02:3D:FA:A6:F1:3C:84:8E:AD:EE:38:98:EC:D9:32:32:D4" 607 | */ 608 | certSKI: string; 609 | /** 610 | * The certificate issuer's Subject Key Identifier 611 | * 612 | * @example "BB:AF:7E:02:3D:FA:A6:F1:3C:84:8E:AD:EE:38:98:EC:D9:32:32:D4" 613 | */ 614 | certIssuerSKI: string; 615 | /** 616 | * The certificate's SHA-1 fingerprint 617 | * 618 | * @example "6b9109f323999e52259cda7373ff0b4d26bd232e" 619 | */ 620 | certFingerprintSHA1: string; 621 | /** 622 | * The certificate's SHA-256 fingerprint 623 | * 624 | * @example "acf77cf37b4156a2708e34c4eb755f9b5dbbe5ebb55adfec8f11493438d19e6ad3f157f81fa3b98278453d5652b0c1fd1d71e5695ae4d709803a4d3f39de9dea" 625 | */ 626 | certFingerprintSHA256: string; 627 | /** 628 | * The effective starting date of the certificate 629 | * 630 | * @example "Dec 22 19:39:00 2018 GMT" 631 | */ 632 | certNotBefore: string; 633 | /** 634 | * The effective expiration date of the certificate 635 | * 636 | * @example "Dec 22 19:39:00 2018 GMT" 637 | */ 638 | certNotAfter: string; 639 | } 640 | 641 | /** Placeholder values for TLS Client Authorization */ 642 | interface IncomingRequestCfPropertiesTLSClientAuthPlaceholder { 643 | certPresented: "0"; 644 | certVerified: "NONE"; 645 | certRevoked: "0"; 646 | certIssuerDN: ""; 647 | certSubjectDN: ""; 648 | certIssuerDNRFC2253: ""; 649 | certSubjectDNRFC2253: ""; 650 | certIssuerDNLegacy: ""; 651 | certSubjectDNLegacy: ""; 652 | certSerial: ""; 653 | certIssuerSerial: ""; 654 | certSKI: ""; 655 | certIssuerSKI: ""; 656 | certFingerprintSHA1: ""; 657 | certFingerprintSHA256: ""; 658 | certNotBefore: ""; 659 | certNotAfter: ""; 660 | } 661 | 662 | /** Possible outcomes of TLS verification */ 663 | declare type CertVerificationStatus = 664 | /** Authentication succeeded */ 665 | | "SUCCESS" 666 | /** No certificate was presented */ 667 | | "NONE" 668 | /** Failed because the certificate was self-signed */ 669 | | "FAILED:self signed certificate" 670 | /** Failed because the certificate failed a trust chain check */ 671 | | "FAILED:unable to verify the first certificate" 672 | /** Failed because the certificate not yet valid */ 673 | | "FAILED:certificate is not yet valid" 674 | /** Failed because the certificate is expired */ 675 | | "FAILED:certificate has expired" 676 | /** Failed for another unspecified reason */ 677 | | "FAILED"; 678 | 679 | /** 680 | * An upstream endpoint's response to a TCP `keepalive` message from Cloudflare. 681 | */ 682 | declare type IncomingRequestCfPropertiesEdgeRequestKeepAliveStatus = 683 | | 0 /** Unknown */ 684 | | 1 /** no keepalives (not found) */ 685 | | 2 /** no connection re-use, opening keepalive connection failed */ 686 | | 3 /** no connection re-use, keepalive accepted and saved */ 687 | | 4 /** connection re-use, refused by the origin server (`TCP FIN`) */ 688 | | 5; /** connection re-use, accepted by the origin server */ 689 | 690 | /** ISO 3166-1 Alpha-2 codes */ 691 | declare type Iso3166Alpha2Code = 692 | | "AD" 693 | | "AE" 694 | | "AF" 695 | | "AG" 696 | | "AI" 697 | | "AL" 698 | | "AM" 699 | | "AO" 700 | | "AQ" 701 | | "AR" 702 | | "AS" 703 | | "AT" 704 | | "AU" 705 | | "AW" 706 | | "AX" 707 | | "AZ" 708 | | "BA" 709 | | "BB" 710 | | "BD" 711 | | "BE" 712 | | "BF" 713 | | "BG" 714 | | "BH" 715 | | "BI" 716 | | "BJ" 717 | | "BL" 718 | | "BM" 719 | | "BN" 720 | | "BO" 721 | | "BQ" 722 | | "BR" 723 | | "BS" 724 | | "BT" 725 | | "BV" 726 | | "BW" 727 | | "BY" 728 | | "BZ" 729 | | "CA" 730 | | "CC" 731 | | "CD" 732 | | "CF" 733 | | "CG" 734 | | "CH" 735 | | "CI" 736 | | "CK" 737 | | "CL" 738 | | "CM" 739 | | "CN" 740 | | "CO" 741 | | "CR" 742 | | "CU" 743 | | "CV" 744 | | "CW" 745 | | "CX" 746 | | "CY" 747 | | "CZ" 748 | | "DE" 749 | | "DJ" 750 | | "DK" 751 | | "DM" 752 | | "DO" 753 | | "DZ" 754 | | "EC" 755 | | "EE" 756 | | "EG" 757 | | "EH" 758 | | "ER" 759 | | "ES" 760 | | "ET" 761 | | "FI" 762 | | "FJ" 763 | | "FK" 764 | | "FM" 765 | | "FO" 766 | | "FR" 767 | | "GA" 768 | | "GB" 769 | | "GD" 770 | | "GE" 771 | | "GF" 772 | | "GG" 773 | | "GH" 774 | | "GI" 775 | | "GL" 776 | | "GM" 777 | | "GN" 778 | | "GP" 779 | | "GQ" 780 | | "GR" 781 | | "GS" 782 | | "GT" 783 | | "GU" 784 | | "GW" 785 | | "GY" 786 | | "HK" 787 | | "HM" 788 | | "HN" 789 | | "HR" 790 | | "HT" 791 | | "HU" 792 | | "ID" 793 | | "IE" 794 | | "IL" 795 | | "IM" 796 | | "IN" 797 | | "IO" 798 | | "IQ" 799 | | "IR" 800 | | "IS" 801 | | "IT" 802 | | "JE" 803 | | "JM" 804 | | "JO" 805 | | "JP" 806 | | "KE" 807 | | "KG" 808 | | "KH" 809 | | "KI" 810 | | "KM" 811 | | "KN" 812 | | "KP" 813 | | "KR" 814 | | "KW" 815 | | "KY" 816 | | "KZ" 817 | | "LA" 818 | | "LB" 819 | | "LC" 820 | | "LI" 821 | | "LK" 822 | | "LR" 823 | | "LS" 824 | | "LT" 825 | | "LU" 826 | | "LV" 827 | | "LY" 828 | | "MA" 829 | | "MC" 830 | | "MD" 831 | | "ME" 832 | | "MF" 833 | | "MG" 834 | | "MH" 835 | | "MK" 836 | | "ML" 837 | | "MM" 838 | | "MN" 839 | | "MO" 840 | | "MP" 841 | | "MQ" 842 | | "MR" 843 | | "MS" 844 | | "MT" 845 | | "MU" 846 | | "MV" 847 | | "MW" 848 | | "MX" 849 | | "MY" 850 | | "MZ" 851 | | "NA" 852 | | "NC" 853 | | "NE" 854 | | "NF" 855 | | "NG" 856 | | "NI" 857 | | "NL" 858 | | "NO" 859 | | "NP" 860 | | "NR" 861 | | "NU" 862 | | "NZ" 863 | | "OM" 864 | | "PA" 865 | | "PE" 866 | | "PF" 867 | | "PG" 868 | | "PH" 869 | | "PK" 870 | | "PL" 871 | | "PM" 872 | | "PN" 873 | | "PR" 874 | | "PS" 875 | | "PT" 876 | | "PW" 877 | | "PY" 878 | | "QA" 879 | | "RE" 880 | | "RO" 881 | | "RS" 882 | | "RU" 883 | | "RW" 884 | | "SA" 885 | | "SB" 886 | | "SC" 887 | | "SD" 888 | | "SE" 889 | | "SG" 890 | | "SH" 891 | | "SI" 892 | | "SJ" 893 | | "SK" 894 | | "SL" 895 | | "SM" 896 | | "SN" 897 | | "SO" 898 | | "SR" 899 | | "SS" 900 | | "ST" 901 | | "SV" 902 | | "SX" 903 | | "SY" 904 | | "SZ" 905 | | "TC" 906 | | "TD" 907 | | "TF" 908 | | "TG" 909 | | "TH" 910 | | "TJ" 911 | | "TK" 912 | | "TL" 913 | | "TM" 914 | | "TN" 915 | | "TO" 916 | | "TR" 917 | | "TT" 918 | | "TV" 919 | | "TW" 920 | | "TZ" 921 | | "UA" 922 | | "UG" 923 | | "UM" 924 | | "US" 925 | | "UY" 926 | | "UZ" 927 | | "VA" 928 | | "VC" 929 | | "VE" 930 | | "VG" 931 | | "VI" 932 | | "VN" 933 | | "VU" 934 | | "WF" 935 | | "WS" 936 | | "YE" 937 | | "YT" 938 | | "ZA" 939 | | "ZM" 940 | | "ZW"; 941 | 942 | /** The 2-letter continent codes Cloudflare uses */ 943 | declare type ContinentCode = "AF" | "AN" | "AS" | "EU" | "NA" | "OC" | "SA"; 944 | -------------------------------------------------------------------------------- /manual-ts/pages.d.ts: -------------------------------------------------------------------------------- 1 | type Params

= Record; 2 | 3 | type EventContext = { 4 | request: Request; 5 | functionPath: string; 6 | waitUntil: (promise: Promise) => void; 7 | passThroughOnException: () => void; 8 | next: (input?: Request | string, init?: RequestInit) => Promise; 9 | env: Env & { ASSETS: { fetch: typeof fetch } }; 10 | params: Params

; 11 | data: Data; 12 | }; 13 | 14 | declare type PagesFunction< 15 | Env = unknown, 16 | Params extends string = any, 17 | Data extends Record = Record 18 | > = (context: EventContext) => Response | Promise; 19 | 20 | type EventPluginContext = { 21 | request: Request; 22 | functionPath: string; 23 | waitUntil: (promise: Promise) => void; 24 | passThroughOnException: () => void; 25 | next: (input?: Request | string, init?: RequestInit) => Promise; 26 | env: Env & { ASSETS: { fetch: typeof fetch } }; 27 | params: Params

; 28 | data: Data; 29 | pluginArgs: PluginArgs; 30 | }; 31 | 32 | declare type PagesPluginFunction< 33 | Env = unknown, 34 | Params extends string = any, 35 | Data extends Record = Record, 36 | PluginArgs = unknown 37 | > = ( 38 | context: EventPluginContext 39 | ) => Response | Promise; 40 | 41 | declare module "assets:*" { 42 | export const onRequest: PagesFunction; 43 | } 44 | -------------------------------------------------------------------------------- /overrides/cf.d.ts: -------------------------------------------------------------------------------- 1 | // TODO: add Response cf object too 2 | 3 | declare class Request extends Body { 4 | /** 5 | * In addition to the properties on the standard `Request` object, 6 | * the `cf` object contains extra information about the request provided 7 | * by Cloudflare's edge. 8 | * 9 | * Returns undefined when accessed in the playground. 10 | */ 11 | readonly cf?: IncomingRequestCfProperties; 12 | } 13 | 14 | interface RequestInit { 15 | /** 16 | * cf is a union of these two types because there are multiple 17 | * scenarios in which it might be one or the other. 18 | * 19 | * IncomingRequestCfProperties is required to allow 20 | * new Request(someUrl, event.request) 21 | * 22 | * RequestInitCfProperties is required to allow 23 | * new Request(event.request, {cf: { ... } }) 24 | * fetch(someUrl, {cf: { ... } }) 25 | */ 26 | cf?: IncomingRequestCfProperties | RequestInitCfProperties; 27 | } 28 | 29 | interface CfRequestInit extends Omit { 30 | cf?: RequestInitCfProperties; 31 | } 32 | 33 | /** 34 | * Back compat support with older types. 35 | * @deprecated Use CfRequestInit instead. 36 | */ 37 | type CfRequestInitializerDict = CfRequestInit; 38 | 39 | export {}; 40 | -------------------------------------------------------------------------------- /overrides/d1.d.ts: -------------------------------------------------------------------------------- 1 | declare type D1Result = { 2 | results?: T[]; 3 | success: boolean; 4 | error?: string; 5 | meta: any; 6 | }; 7 | 8 | declare abstract class D1Database { 9 | prepare(query: string): D1PreparedStatement; 10 | dump(): Promise; 11 | batch(statements: D1PreparedStatement[]): Promise[]>; 12 | exec(query: string): Promise>; 13 | } 14 | 15 | declare abstract class D1PreparedStatement { 16 | bind(...values: any[]): D1PreparedStatement; 17 | first(colName?: string): Promise; 18 | run(): Promise>; 19 | all(): Promise>; 20 | raw(): Promise; 21 | } 22 | -------------------------------------------------------------------------------- /overrides/durableobjects.d.ts: -------------------------------------------------------------------------------- 1 | interface DurableObject { 2 | fetch(request: Request): Promise; 3 | alarm?(): Promise; 4 | } 5 | 6 | declare abstract class DurableObjectStub extends Fetcher { 7 | readonly id: DurableObjectId; 8 | readonly name?: string; 9 | } 10 | 11 | declare abstract class DurableObjectNamespace { 12 | get(id: DurableObjectId): DurableObjectStub; 13 | } 14 | 15 | declare abstract class DurableObjectState { 16 | readonly storage: DurableObjectStorage; 17 | blockConcurrencyWhile(callback: () => Promise): Promise; 18 | } 19 | 20 | declare abstract class DurableObjectStorage { 21 | get( 22 | key: string, 23 | options?: DurableObjectGetOptions 24 | ): Promise; 25 | get( 26 | keys: string[], 27 | options?: DurableObjectGetOptions 28 | ): Promise>; 29 | 30 | list( 31 | options?: DurableObjectListOptions 32 | ): Promise>; 33 | 34 | put( 35 | key: string, 36 | value: T, 37 | options?: DurableObjectPutOptions 38 | ): Promise; 39 | put( 40 | entries: Record, 41 | options?: DurableObjectPutOptions 42 | ): Promise; 43 | 44 | delete(key: string, options?: DurableObjectPutOptions): Promise; 45 | delete(keys: string[], options?: DurableObjectPutOptions): Promise; 46 | 47 | transaction( 48 | closure: (txn: DurableObjectTransaction) => Promise 49 | ): Promise; 50 | } 51 | 52 | declare abstract class DurableObjectTransaction { 53 | get( 54 | key: string, 55 | options?: DurableObjectGetOptions 56 | ): Promise; 57 | get( 58 | keys: string[], 59 | options?: DurableObjectGetOptions 60 | ): Promise>; 61 | 62 | list( 63 | options?: DurableObjectListOptions 64 | ): Promise>; 65 | 66 | put( 67 | key: string, 68 | value: T, 69 | options?: DurableObjectPutOptions 70 | ): Promise; 71 | put( 72 | entries: Record, 73 | options?: DurableObjectPutOptions 74 | ): Promise; 75 | 76 | delete(key: string, options?: DurableObjectPutOptions): Promise; 77 | delete(keys: string[], options?: DurableObjectPutOptions): Promise; 78 | 79 | deleteAll: never; 80 | 81 | rollback(): void; 82 | } 83 | 84 | export {}; 85 | -------------------------------------------------------------------------------- /overrides/encoding.d.ts: -------------------------------------------------------------------------------- 1 | declare class TextDecoder { 2 | constructor( 3 | label?: "utf-8" | "utf8" | "unicode-1-1-utf-8", 4 | options?: TextDecoderConstructorOptions 5 | ); 6 | } 7 | -------------------------------------------------------------------------------- /overrides/events.d.ts: -------------------------------------------------------------------------------- 1 | declare type EventListener = ( 2 | event: EventType 3 | ) => void; 4 | 5 | interface EventListenerObject { 6 | handleEvent(event: EventType): void; 7 | } 8 | 9 | declare type EventListenerOrEventListenerObject< 10 | EventType extends Event = Event 11 | > = EventListener | EventListenerObject; 12 | 13 | declare class EventTarget< 14 | EventMap extends Record = Record 15 | > { 16 | constructor(); 17 | addEventListener( 18 | type: Type, 19 | handler: EventListenerOrEventListenerObject, 20 | options?: EventTargetAddEventListenerOptions | boolean 21 | ): void; 22 | removeEventListener( 23 | type: Type, 24 | handler: EventListenerOrEventListenerObject, 25 | options?: EventTargetEventListenerOptions | boolean 26 | ): void; 27 | dispatchEvent(event: EventMap[keyof EventMap]): boolean; 28 | } 29 | 30 | interface ExportedHandler { 31 | fetch?: ExportedHandlerFetchHandler; 32 | trace?: never; 33 | scheduled?: ExportedHandlerScheduledHandler; 34 | alarm?: never; 35 | } 36 | 37 | declare type ExportedHandlerFetchHandler = ( 38 | request: Request, 39 | env: Env, 40 | ctx: ExecutionContext 41 | ) => Response | Promise; 42 | 43 | declare type ExportedHandlerScheduledHandler = ( 44 | controller: ScheduledController, 45 | env: Env, 46 | ctx: ExecutionContext 47 | ) => void | Promise; 48 | 49 | declare type WorkerGlobalScopeEventMap = { 50 | fetch: FetchEvent; 51 | scheduled: ScheduledEvent; 52 | unhandledrejection: PromiseRejectionEvent; 53 | rejectionhandled: PromiseRejectionEvent; 54 | }; 55 | 56 | declare abstract class WorkerGlobalScope extends EventTarget {} 57 | 58 | export {}; 59 | -------------------------------------------------------------------------------- /overrides/htmlrewriter.d.ts: -------------------------------------------------------------------------------- 1 | declare class HTMLRewriter { 2 | constructor(); 3 | on( 4 | selector: string, 5 | handlers: HTMLRewriterElementContentHandlers 6 | ): HTMLRewriter; 7 | onDocument(handlers: HTMLRewriterDocumentContentHandlers): HTMLRewriter; 8 | transform(response: Response): Response; 9 | } 10 | 11 | interface HTMLRewriterElementContentHandlers { 12 | element?(element: Element): void | Promise; 13 | comments?(comment: Comment): void | Promise; 14 | text?(text: Text): void | Promise; 15 | } 16 | 17 | interface HTMLRewriterDocumentContentHandlers { 18 | doctype?(doctype: Doctype): void | Promise; 19 | comments?(comment: Comment): void | Promise; 20 | text?(text: Text): void | Promise; 21 | end?(end: DocumentEnd): void | Promise; 22 | } 23 | 24 | export {}; 25 | -------------------------------------------------------------------------------- /overrides/http.d.ts: -------------------------------------------------------------------------------- 1 | declare abstract class Body { 2 | json(): Promise; 3 | } 4 | 5 | declare class FormData { 6 | append(name: string, value: string): void; 7 | append(name: string, value: Blob, filename?: string): void; 8 | 9 | set(name: string, value: string): void; 10 | set(name: string, value: Blob, filename?: string): void; 11 | 12 | entries(): IterableIterator<[key: string, value: File | string]>; 13 | [Symbol.iterator](): IterableIterator<[key: string, value: File | string]>; 14 | 15 | keys(): IterableIterator; 16 | values(): IterableIterator; 17 | 18 | forEach( 19 | callback: ( 20 | this: This, 21 | value: File | string, 22 | key: string, 23 | parent: FormData 24 | ) => void, 25 | thisArg?: This 26 | ): void; 27 | } 28 | 29 | declare class Headers { 30 | entries(): IterableIterator<[key: string, value: string]>; 31 | [Symbol.iterator](): IterableIterator<[key: string, value: string]>; 32 | 33 | keys(): IterableIterator; 34 | values(): IterableIterator; 35 | 36 | forEach( 37 | callback: (this: This, value: string, key: string, parent: Headers) => void, 38 | thisArg?: This 39 | ): void; 40 | } 41 | 42 | // This override provides the typing over the tuples as a nicety. 43 | // The inner array is required to have exactly two elements. 44 | declare type HeadersInit = 45 | | Headers 46 | | Record 47 | | [key: string, value: string][]; 48 | 49 | declare class URLSearchParams { 50 | entries(): IterableIterator<[key: string, value: string]>; 51 | [Symbol.iterator](): IterableIterator<[key: string, value: string]>; 52 | 53 | keys(): IterableIterator; 54 | values(): IterableIterator; 55 | 56 | forEach( 57 | callback: ( 58 | this: This, 59 | value: string, 60 | key: string, 61 | parent: URLSearchParams 62 | ) => void, 63 | thisArg?: This 64 | ): void; 65 | } 66 | 67 | // This override provides the typing over the tuples as a nicety. 68 | // The inner array is required to have exactly two elements. 69 | declare type URLSearchParamsInit = 70 | | URLSearchParams 71 | | string 72 | | Record 73 | | [key: string, value: string][]; 74 | 75 | declare class FetchEvent extends ExtendableEvent { 76 | respondWith(promise: Response | Promise): void; 77 | } 78 | 79 | export {}; 80 | -------------------------------------------------------------------------------- /overrides/kv.d.ts: -------------------------------------------------------------------------------- 1 | interface KVNamespaceGetOptions { 2 | type: Type; 3 | cacheTtl?: number; 4 | } 5 | 6 | interface KVNamespaceGetWithMetadataResult { 7 | value: Value | null; 8 | metadata: Metadata | null; 9 | } 10 | 11 | interface KVNamespaceListKey { 12 | name: string; 13 | expiration?: number; 14 | metadata?: Metadata; 15 | } 16 | 17 | interface KVNamespaceListResult { 18 | keys: KVNamespaceListKey[]; 19 | list_complete: boolean; 20 | cursor?: string; 21 | } 22 | 23 | declare class KVNamespace { 24 | get( 25 | key: K, 26 | options?: Partial> 27 | ): Promise; 28 | get(key: K, type: "text"): Promise; 29 | get( 30 | key: K, 31 | type: "json" 32 | ): Promise; 33 | get(key: K, type: "arrayBuffer"): Promise; 34 | get(key: K, type: "stream"): Promise; 35 | 36 | get(key: K, options: KVNamespaceGetOptions<"text">): Promise; 37 | get( 38 | key: string, 39 | options: KVNamespaceGetOptions<"json"> 40 | ): Promise; 41 | get( 42 | key: K, 43 | options: KVNamespaceGetOptions<"arrayBuffer"> 44 | ): Promise; 45 | get( 46 | key: K, 47 | options: KVNamespaceGetOptions<"stream"> 48 | ): Promise; 49 | 50 | getWithMetadata( 51 | key: K, 52 | options?: Partial> 53 | ): Promise>; 54 | getWithMetadata( 55 | key: K, 56 | type: "text" 57 | ): Promise>; 58 | getWithMetadata( 59 | key: K, 60 | type: "json" 61 | ): Promise>; 62 | getWithMetadata( 63 | key: K, 64 | type: "arrayBuffer" 65 | ): Promise>; 66 | getWithMetadata( 67 | key: K, 68 | type: "stream" 69 | ): Promise>; 70 | 71 | getWithMetadata( 72 | key: K, 73 | options: KVNamespaceGetOptions<"text"> 74 | ): Promise>; 75 | getWithMetadata( 76 | key: K, 77 | options: KVNamespaceGetOptions<"json"> 78 | ): Promise>; 79 | getWithMetadata( 80 | key: K, 81 | options: KVNamespaceGetOptions<"arrayBuffer"> 82 | ): Promise>; 83 | getWithMetadata( 84 | key: K, 85 | options: KVNamespaceGetOptions<"stream"> 86 | ): Promise>; 87 | 88 | put( 89 | key: K, 90 | value: string | ArrayBuffer | ArrayBufferView | ReadableStream, 91 | options?: KVNamespacePutOptions 92 | ): Promise; 93 | 94 | list( 95 | options?: KVNamespaceListOptions 96 | ): Promise>; 97 | } 98 | 99 | export {}; 100 | -------------------------------------------------------------------------------- /overrides/stream.d.ts: -------------------------------------------------------------------------------- 1 | // TODO: maybe make Readable/WriteableStreams generic? 2 | 3 | declare abstract class ReadableStream { 4 | tee(): [ReadableStream, ReadableStream]; 5 | } 6 | 7 | interface StreamQueuingStrategy { 8 | size(chunk: any): number; 9 | } 10 | 11 | export {}; 12 | -------------------------------------------------------------------------------- /overrides/websocket.d.ts: -------------------------------------------------------------------------------- 1 | declare class MessageEvent extends Event { 2 | readonly data: ArrayBuffer | string; 3 | } 4 | 5 | interface MessageEventInit { 6 | data: ArrayBuffer | string; 7 | } 8 | 9 | declare type WebSocketEventMap = { 10 | close: CloseEvent; 11 | message: MessageEvent; 12 | open: Event; 13 | error: ErrorEvent; 14 | }; 15 | 16 | declare class WebSocket extends EventTarget {} 17 | 18 | declare const WebSocketPair: { 19 | new (): { 20 | 0: WebSocket; 21 | 1: WebSocket; 22 | }; 23 | }; 24 | 25 | export {}; 26 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@cloudflare/workers-types", 3 | "version": "3.19.0", 4 | "description": "TypeScript typings for Cloudflare Workers", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/cloudflare/workers-types" 8 | }, 9 | "types": "./index.d.ts", 10 | "files": [ 11 | "index.d.ts" 12 | ], 13 | "scripts": { 14 | "export:docs": "node -r esbuild-register export/docs.ts", 15 | "export:overrides": "node -r esbuild-register export/overrides.ts", 16 | "generate:diff": "node -r esbuild-register export/prettydiff.ts", 17 | "prettier:check": "prettier --check '**/*.{md,ts}'", 18 | "prettier": "prettier --write '**/*.{md,ts}'", 19 | "test": "tsc" 20 | }, 21 | "author": "Cloudflare Workers Team (https://workers.cloudflare.com)", 22 | "license": "BSD-3-Clause", 23 | "devDependencies": { 24 | "@changesets/changelog-github": "^0.4.2", 25 | "@changesets/cli": "^2.18.1", 26 | "@types/marked": "^4.0.1", 27 | "@types/node": "^16.6.1", 28 | "esbuild": "^0.12.22", 29 | "esbuild-register": "^3.0.0", 30 | "marked": "^4.0.10", 31 | "prettier": "^2.5.1", 32 | "typescript": "^4.3.5" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json-schema.org/draft/2020-12/schema", 3 | "$id": "./schema.json", 4 | "title": "Intermediate Representation", 5 | "type": "object", 6 | "additionalProperties": { 7 | "oneOf": [ 8 | { "$ref": "#/$defs/class" }, 9 | { "$ref": "#/$defs/struct" }, 10 | { "$ref": "#/$defs/typeDef" }, 11 | { "$ref": "#/$defs/function" }, 12 | { "$ref": "#/$defs/variable" } 13 | ] 14 | }, 15 | "$defs": { 16 | "typeNamed": { 17 | "type": "object", 18 | "properties": { 19 | "name": { 20 | "type": "string", 21 | "pattern": "^[^\\[\\(\\|]" 22 | }, 23 | "args": { 24 | "type": "array", 25 | "items": { "$ref": "#/$defs/type" } 26 | }, 27 | "index": { "$ref": "#/$defs/type" }, 28 | "optional": { "type": "boolean" }, 29 | "variadic": { "type": "boolean" } 30 | }, 31 | "required": ["name"], 32 | "additionalProperties": false 33 | }, 34 | "typeArray": { 35 | "type": "object", 36 | "properties": { 37 | "name": { "enum": ["[]"] }, 38 | "args": { 39 | "type": "array", 40 | "items": { "$ref": "#/$defs/type" }, 41 | "minItems": 1, 42 | "maxItems": 1 43 | }, 44 | "optional": { "type": "boolean" }, 45 | "variadic": { "type": "boolean" } 46 | }, 47 | "required": ["name", "args"], 48 | "additionalProperties": false 49 | }, 50 | "typeTuple": { 51 | "type": "object", 52 | "properties": { 53 | "name": { "enum": ["()"] }, 54 | "params": { 55 | "type": "array", 56 | "items": { "$ref": "#/$defs/param" }, 57 | "minItems": 1 58 | }, 59 | "optional": { "type": "boolean" }, 60 | "variadic": { "type": "boolean" } 61 | }, 62 | "required": ["name", "params"], 63 | "additionalProperties": false 64 | }, 65 | "typeUnion": { 66 | "type": "object", 67 | "properties": { 68 | "name": { "enum": ["|"] }, 69 | "args": { 70 | "type": "array", 71 | "items": { "$ref": "#/$defs/type" }, 72 | "minItems": 2, 73 | "uniqueItems": true 74 | }, 75 | "optional": { "type": "boolean" }, 76 | "variadic": { "type": "boolean" } 77 | }, 78 | "required": ["name", "args"], 79 | "additionalProperties": false 80 | }, 81 | "typeFunction": { 82 | "type": "object", 83 | "properties": { 84 | "params": { 85 | "type": "array", 86 | "items": { "$ref": "#/$defs/param" } 87 | }, 88 | "returns": { "$ref": "#/$defs/type" }, 89 | "optional": { "type": "boolean" } 90 | }, 91 | "required": ["params"], 92 | "additionalProperties": false 93 | }, 94 | "typeLiteral": { 95 | "type": "object", 96 | "properties": { 97 | "members": { 98 | "type": "array", 99 | "items": { "$ref": "#/$defs/field" } 100 | }, 101 | "optional": { "type": "boolean" } 102 | }, 103 | "required": ["members"], 104 | "additionalProperties": false 105 | }, 106 | "type": { 107 | "oneOf": [ 108 | { "$ref": "#/$defs/typeNamed" }, 109 | { "$ref": "#/$defs/typeArray" }, 110 | { "$ref": "#/$defs/typeTuple" }, 111 | { "$ref": "#/$defs/typeUnion" }, 112 | { "$ref": "#/$defs/typeFunction" }, 113 | { "$ref": "#/$defs/typeLiteral" } 114 | ] 115 | }, 116 | "typeParam": { 117 | "type": "object", 118 | "properties": { 119 | "name": { "type": "string" }, 120 | "constraint": { "$ref": "#/$defs/type" }, 121 | "default": { "$ref": "#/$defs/type" } 122 | }, 123 | "required": ["name"], 124 | "additionalProperties": false 125 | }, 126 | "commentParam": { 127 | "type": "object", 128 | "properties": { 129 | "name": { "type": "string" }, 130 | "text": { "type": "string" } 131 | }, 132 | "required": ["name", "text"], 133 | "additionalProperties": false 134 | }, 135 | "comment": { 136 | "type": "object", 137 | "properties": { 138 | "text": { "type": "string" }, 139 | "params": { 140 | "type": "array", 141 | "items": { "$ref": "#/$defs/commentParam" } 142 | }, 143 | "returns": { "type": "string" }, 144 | "examples": { 145 | "type": "object", 146 | "additionalProperties": { 147 | "type": "array", 148 | "items": { "type": "string" } 149 | } 150 | } 151 | }, 152 | "required": ["text"], 153 | "additionalProperties": false 154 | }, 155 | "field": { 156 | "type": "object", 157 | "properties": { 158 | "name": { "type": "string" }, 159 | "type": { "$ref": "#/$defs/type" }, 160 | "static": { "type": "boolean" }, 161 | "readonly": { "type": "boolean" }, 162 | "typeparams": { 163 | "type": "array", 164 | "items": { "$ref": "#/$defs/typeParam" } 165 | }, 166 | "comment": { "$ref": "#/$defs/comment" }, 167 | "throws": { "type": "boolean" } 168 | }, 169 | "required": ["name", "type"], 170 | "additionalProperties": false 171 | }, 172 | "param": { 173 | "type": "object", 174 | "properties": { 175 | "name": { "type": "string" }, 176 | "type": { "$ref": "#/$defs/type" } 177 | }, 178 | "required": ["name", "type"], 179 | "additionalProperties": false 180 | }, 181 | "class": { 182 | "type": "object", 183 | "properties": { 184 | "name": { "type": "string" }, 185 | "typeparams": { 186 | "type": "array", 187 | "items": { "$ref": "#/$defs/typeParam" } 188 | }, 189 | "comment": { "$ref": "#/$defs/comment" }, 190 | "kind": { "enum": ["class"] }, 191 | "members": { 192 | "type": "array", 193 | "items": { "$ref": "#/$defs/field" } 194 | }, 195 | "extends": { 196 | "type": "array", 197 | "items": { "$ref": "#/$defs/typeNamed" } 198 | }, 199 | "implements": { 200 | "type": "array", 201 | "items": { "$ref": "#/$defs/typeNamed" } 202 | } 203 | }, 204 | "required": ["name", "kind", "members"], 205 | "additionalProperties": false 206 | }, 207 | "struct": { 208 | "type": "object", 209 | "properties": { 210 | "name": { "type": "string" }, 211 | "typeparams": { 212 | "type": "array", 213 | "items": { "$ref": "#/$defs/typeParam" } 214 | }, 215 | "comment": { "$ref": "#/$defs/comment" }, 216 | "kind": { "enum": ["struct"] }, 217 | "members": { 218 | "type": "array", 219 | "items": { "$ref": "#/$defs/field" } 220 | }, 221 | "extends": { 222 | "type": "array", 223 | "items": { "$ref": "#/$defs/typeNamed" } 224 | } 225 | }, 226 | "required": ["name", "kind", "members"], 227 | "additionalProperties": false 228 | }, 229 | "typeDef": { 230 | "type": "object", 231 | "properties": { 232 | "name": { "type": "string" }, 233 | "typeparams": { 234 | "type": "array", 235 | "items": { "$ref": "#/$defs/typeParam" } 236 | }, 237 | "comment": { "$ref": "#/$defs/comment" }, 238 | "kind": { "enum": ["typedef"] }, 239 | "type": { "$ref": "#/$defs/type" } 240 | }, 241 | "required": ["name", "kind", "type"], 242 | "additionalProperties": false 243 | }, 244 | "function": { 245 | "type": "object", 246 | "properties": { 247 | "name": { "type": "string" }, 248 | "typeparams": { 249 | "type": "array", 250 | "items": { "$ref": "#/$defs/typeParam" } 251 | }, 252 | "comment": { "$ref": "#/$defs/comment" }, 253 | "kind": { "enum": ["function"] }, 254 | "throws": { "type": "boolean" }, 255 | "type": { "$ref": "#/$defs/typeFunction" } 256 | }, 257 | "required": ["name", "kind", "type"], 258 | "additionalProperties": false 259 | }, 260 | "variable": { 261 | "type": "object", 262 | "properties": { 263 | "name": { "type": "string" }, 264 | "comment": { "$ref": "#/$defs/comment" }, 265 | "kind": { "enum": ["variable"] }, 266 | "type": { "$ref": "#/$defs/type" } 267 | }, 268 | "required": ["name", "kind", "type"], 269 | "additionalProperties": false 270 | } 271 | } 272 | } 273 | -------------------------------------------------------------------------------- /tests/durableobjects.ts: -------------------------------------------------------------------------------- 1 | class MyDurableObject implements DurableObject { 2 | async fetch(request: Request) { 3 | return new Response("Hello, world!"); 4 | } 5 | } 6 | 7 | type MyDurableObjectNamespace = DurableObjectNamespace; 8 | 9 | const MyDurableObjectNamespace: DurableObjectNamespace = undefined as any; 10 | const myDurableObjectStub = MyDurableObjectNamespace.get( 11 | MyDurableObjectNamespace.newUniqueId() 12 | ); 13 | myDurableObjectStub.fetch("/", { method: "POST" }); 14 | 15 | export {}; 16 | -------------------------------------------------------------------------------- /tests/globals.ts: -------------------------------------------------------------------------------- 1 | const init: CfRequestInitializerDict = { 2 | cf: { 3 | cacheEverything: true, 4 | // properties from IncomingRequestCfProperties 5 | // should not be assignable here 6 | // @ts-expect-error 7 | colo: "hi", 8 | }, 9 | }; 10 | 11 | if (init.cf) { 12 | // properties on init.cf are known to be RequestInitCfProperties 13 | init.cf.cacheEverything = false; 14 | } 15 | 16 | // CfRequestInit works with fetch 17 | fetch("hi", init); 18 | 19 | // CfRequestInit works with Request 20 | new Request("hi", init); 21 | 22 | // FetchEvent is manually specified and assignable 23 | addEventListener("fetch", (event: FetchEvent) => { 24 | // RequestInitCfProperties should not be present 25 | // @ts-expect-error 26 | event.request.cf.cacheEverything; 27 | // request from FetchEvent is assignable within request 28 | // constructor as RequestInit 29 | new Request("hi", event.request); 30 | // request from FetchEvent works with handle function 31 | event.respondWith(handle(event.request)); 32 | }); 33 | function handle(request: Request) { 34 | if (!request.cf) return new Response("hi"); 35 | return new Response(request.cf.colo); 36 | } 37 | 38 | addEventListener("scheduled", (event: ScheduledEvent) => {}); 39 | // @ts-expect-error 40 | addEventListener("close", () => {}); 41 | 42 | removeEventListener("fetch", (event: FetchEvent) => {}); 43 | removeEventListener("scheduled", (event: ScheduledEvent) => {}); 44 | // @ts-expect-error 45 | removeEventListener("close", (event) => {}); 46 | 47 | self.addEventListener("fetch", (event: FetchEvent) => {}); 48 | 49 | // @ts-expect-error 50 | dispatchEvent(new FetchEvent("fetch")); 51 | // @ts-expect-error 52 | dispatchEvent(new ScheduledEvent("scheduled")); 53 | // @ts-expect-error 54 | dispatchEvent(new CloseEvent("close")); 55 | 56 | const default1: Cache = caches.default; 57 | const open1: Promise = caches.open(""); 58 | 59 | setTimeout((a: number, b: string) => {}, 1000, 1, "hello"); 60 | // @ts-expect-error 61 | setTimeout((a: number) => {}, 1000, "hello"); 62 | // @ts-expect-error 63 | setInterval((a: number, b: string) => {}, 1000, 1, "hello", true); 64 | 65 | const digest1: Promise = crypto.subtle.digest( 66 | "SHA-256", 67 | new Uint8Array() 68 | ); 69 | 70 | export {}; 71 | -------------------------------------------------------------------------------- /tests/http.ts: -------------------------------------------------------------------------------- 1 | const formData = new FormData(); 2 | 3 | const data: { [key: string]: string | File } = {}; 4 | for (const [key, value] of formData.entries()) { 5 | data[key] = value; 6 | } 7 | 8 | for (const [key, value] of formData) { 9 | data[key] = value; 10 | } 11 | 12 | export {}; 13 | -------------------------------------------------------------------------------- /tests/kv.ts: -------------------------------------------------------------------------------- 1 | const myKVNamespace: KVNamespace = undefined as any; 2 | myKVNamespace.get("foo"); 3 | myKVNamespace.get("foo", { cacheTtl: 60 }); 4 | 5 | myKVNamespace.get("foo", "text"); 6 | myKVNamespace.get("foo", { type: "text" }); 7 | myKVNamespace.get("foo", { cacheTtl: 60, type: "text" }); 8 | 9 | myKVNamespace.get("foo", "json"); 10 | myKVNamespace.get("foo", { type: "json" }); 11 | myKVNamespace.get("foo", { cacheTtl: 60, type: "json" }); 12 | 13 | myKVNamespace.get("foo", "arrayBuffer"); 14 | myKVNamespace.get("foo", { type: "arrayBuffer" }); 15 | myKVNamespace.get("foo", { cacheTtl: 60, type: "arrayBuffer" }); 16 | 17 | myKVNamespace.get("foo", "stream"); 18 | myKVNamespace.get("foo", { type: "stream" }); 19 | myKVNamespace.get("foo", { cacheTtl: 60, type: "stream" }); 20 | 21 | export {}; 22 | -------------------------------------------------------------------------------- /tests/websocket.ts: -------------------------------------------------------------------------------- 1 | // @ts-expect-error 2 | const [client1, server1] = new WebSocketPair(); 3 | 4 | const { 0: client2, 1: server2 } = new WebSocketPair(); 5 | const [client3, server3] = Object.values(new WebSocketPair()); 6 | const webSockets: WebSocket[] = Object.values(new WebSocketPair()); 7 | 8 | export {}; 9 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "strict": true, 4 | "target": "es2020", 5 | "lib": ["es2020"], 6 | "typeRoots": [], 7 | "isolatedModules": true, 8 | "noEmit": true, 9 | "module": "esnext", 10 | "esModuleInterop": true 11 | }, 12 | "include": ["tests/**/*.ts", "index.d.ts"] 13 | } 14 | --------------------------------------------------------------------------------