├── .eslintrc ├── .github ├── actions │ └── setup │ │ └── action.yml └── workflows │ ├── ci.yml │ └── release.yml ├── .gitignore ├── .prettierrc.json ├── LICENSE ├── README.md ├── example ├── .prettierrc ├── package-lock.json ├── package.json ├── src │ └── worker.ts ├── tsconfig.json └── wrangler.toml ├── package.json ├── pnpm-lock.yaml ├── src ├── cookie.ts ├── index.ts ├── middleware │ ├── zod-validation.test.ts │ └── zod-validation.ts ├── request.test.ts ├── request.ts ├── response.ts ├── router.test.ts ├── router.ts ├── types.ts └── utils │ ├── enum.ts │ └── to-object.ts ├── test └── helpers.ts ├── tsconfig.json └── tsup.config.ts /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@ocavue/eslint-config" 3 | } 4 | -------------------------------------------------------------------------------- /.github/actions/setup/action.yml: -------------------------------------------------------------------------------- 1 | name: Setup 2 | description: Setup the environment 3 | 4 | inputs: 5 | node-version: 6 | description: The version of node.js 7 | required: false 8 | default: '18' 9 | 10 | runs: 11 | using: composite 12 | steps: 13 | - name: Install pnpm 14 | uses: pnpm/action-setup@v2 15 | with: 16 | run_install: false 17 | 18 | - name: Setup node 19 | uses: actions/setup-node@v3 20 | with: 21 | node-version: ${{ inputs.node-version }} 22 | cache: pnpm 23 | registry-url: 'https://registry.npmjs.org' 24 | 25 | - name: Setup ni 26 | run: npm i -g @antfu/ni 27 | shell: bash 28 | 29 | - name: Install 30 | run: ni 31 | shell: bash 32 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | pull_request: 9 | branches: 10 | - master 11 | 12 | jobs: 13 | lint: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v3 17 | 18 | - uses: ./.github/actions/setup 19 | 20 | - name: Lint 21 | run: nr lint 22 | 23 | typecheck: 24 | runs-on: ubuntu-latest 25 | steps: 26 | - uses: actions/checkout@v3 27 | 28 | - uses: ./.github/actions/setup 29 | 30 | - name: Typecheck 31 | run: nr typecheck 32 | 33 | test: 34 | runs-on: ${{ matrix.os }} 35 | 36 | strategy: 37 | matrix: 38 | node: [18.x] 39 | os: [ubuntu-latest] 40 | fail-fast: false 41 | 42 | steps: 43 | - uses: actions/checkout@v3 44 | 45 | - uses: ./.github/actions/setup 46 | with: 47 | node-version: ${{ matrix.node }} 48 | 49 | - name: Build 50 | run: nr build 51 | 52 | - name: Test 53 | run: nr test 54 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | version: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: google-github-actions/release-please-action@v3 13 | id: release-please 14 | with: 15 | release-type: node 16 | outputs: 17 | release_created: ${{ steps.release-please.outputs.release_created }} 18 | 19 | publish: 20 | runs-on: ubuntu-latest 21 | needs: [version] 22 | if: ${{ needs.version.outputs.release_created }} 23 | steps: 24 | - uses: actions/checkout@v3 25 | 26 | - uses: ./.github/actions/setup 27 | 28 | - name: Build 29 | run: nr build 30 | 31 | - name: Publish to NPM 32 | run: npm publish 33 | env: 34 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 35 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .cache 2 | .DS_Store 3 | .idea 4 | *.log 5 | *.tgz 6 | coverage 7 | dist 8 | lib-cov 9 | logs 10 | node_modules 11 | temp 12 | -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "semi": false, 3 | "singleQuote": true 4 | } 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Alex MacCaw 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cloudflare-basics 2 | 3 | [![NPM version](https://img.shields.io/npm/v/cloudflare-basics?color=a1b858&label=)](https://www.npmjs.com/package/cloudflare-basics) 4 | 5 | Just the basics and nothing more. 6 | 7 | - Simple Router 8 | - Simple request body parsing 9 | - Simple zod validation 10 | 11 | See also: 12 | 13 | - [cloudflare-basics-ai-plugin](https://github.com/maccman/cloudflare-basics-ai-plugin) for ChatGPT plugins. 14 | 15 | # Requirements 16 | 17 | - Requires Node 18.x 18 | - Technically built for Cloudflare Workers, but you can use it in Node.js too 19 | 20 | ## Usage 21 | 22 | ```ts 23 | import { Router, json } from 'cloudflare-basics' 24 | 25 | export default { 26 | async fetch( 27 | request: Request, 28 | env: Env, 29 | ctx: ExecutionContext 30 | ): Promise { 31 | const router = new Router() 32 | 33 | router.get('/', async ({ request }) => { 34 | return new Response('Hello World!') 35 | }) 36 | 37 | router.post('/books', async ({ request }) => { 38 | const data = await request.body<{ foo: string }>() 39 | 40 | return json({ data }) 41 | }) 42 | 43 | router.get('/books/:id', async ({ params }) => { 44 | const bookId = params?.id 45 | 46 | return json({ bookId }) 47 | }) 48 | 49 | return ( 50 | router.handle(request, env, ctx) ?? 51 | new Response('Not Found', { status: 404 }) 52 | ) 53 | }, 54 | } 55 | ``` 56 | 57 | ## Zod Validation 58 | 59 | ```ts 60 | const schema = z.object({ 61 | name: z.string(), 62 | }) 63 | 64 | type schemaType = z.infer 65 | 66 | const MyRoute = withZod(schema, async (options) => { 67 | console.log(options.data) //=> { name: 'test' } 68 | return new Response('ok') 69 | }) 70 | 71 | router.post('/', MyRoute) 72 | ``` 73 | 74 | ## License 75 | 76 | MIT 77 | -------------------------------------------------------------------------------- /example/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 140, 3 | "singleQuote": true, 4 | "semi": false 5 | } 6 | -------------------------------------------------------------------------------- /example/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cloudflare-basics-example", 3 | "version": "0.0.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "cloudflare-basics-example", 9 | "version": "0.0.0", 10 | "dependencies": { 11 | "cloudflare-basics": "^0.0.1" 12 | }, 13 | "devDependencies": { 14 | "@cloudflare/workers-types": "^4.20230419.0", 15 | "typescript": "^5.0.4", 16 | "wrangler": "^3.0.0" 17 | } 18 | }, 19 | "node_modules/@cloudflare/kv-asset-handler": { 20 | "version": "0.2.0", 21 | "resolved": "https://registry.npmjs.org/@cloudflare/kv-asset-handler/-/kv-asset-handler-0.2.0.tgz", 22 | "integrity": "sha512-MVbXLbTcAotOPUj0pAMhVtJ+3/kFkwJqc5qNOleOZTv6QkZZABDMS21dSrSlVswEHwrpWC03e4fWytjqKvuE2A==", 23 | "dev": true, 24 | "dependencies": { 25 | "mime": "^3.0.0" 26 | } 27 | }, 28 | "node_modules/@cloudflare/workerd-darwin-64": { 29 | "version": "1.20230512.0", 30 | "resolved": "https://registry.npmjs.org/@cloudflare/workerd-darwin-64/-/workerd-darwin-64-1.20230512.0.tgz", 31 | "integrity": "sha512-V80DswMTu0hiVue5BmjlC0cVufXLKk0KbkesbJ0IywHiuGk0f9uEOgwwL91ioOhPu+3Ss/ka5BNxwPXDxKkG3g==", 32 | "cpu": [ 33 | "x64" 34 | ], 35 | "dev": true, 36 | "optional": true, 37 | "os": [ 38 | "darwin" 39 | ], 40 | "engines": { 41 | "node": ">=16" 42 | } 43 | }, 44 | "node_modules/@cloudflare/workerd-darwin-arm64": { 45 | "version": "1.20230512.0", 46 | "resolved": "https://registry.npmjs.org/@cloudflare/workerd-darwin-arm64/-/workerd-darwin-arm64-1.20230512.0.tgz", 47 | "integrity": "sha512-HojEqgtCW8FCRQq/ENPsBVv1YoxJVp2kDrC27D7xfwOa2+LCmxh55c2cckxZuGTNAsBIqk6lczq4yQx9xcfSdg==", 48 | "cpu": [ 49 | "arm64" 50 | ], 51 | "dev": true, 52 | "optional": true, 53 | "os": [ 54 | "darwin" 55 | ], 56 | "engines": { 57 | "node": ">=16" 58 | } 59 | }, 60 | "node_modules/@cloudflare/workerd-linux-64": { 61 | "version": "1.20230512.0", 62 | "resolved": "https://registry.npmjs.org/@cloudflare/workerd-linux-64/-/workerd-linux-64-1.20230512.0.tgz", 63 | "integrity": "sha512-zhu61wFAyjbO+MtiQjcKDv+HUXYnW3GhGCKW8xKUsCktaXKr/l2Vp/t3VFzF+M8CuFMML5xmE/1gopHB9pIUcA==", 64 | "cpu": [ 65 | "x64" 66 | ], 67 | "dev": true, 68 | "optional": true, 69 | "os": [ 70 | "linux" 71 | ], 72 | "engines": { 73 | "node": ">=16" 74 | } 75 | }, 76 | "node_modules/@cloudflare/workerd-linux-arm64": { 77 | "version": "1.20230512.0", 78 | "resolved": "https://registry.npmjs.org/@cloudflare/workerd-linux-arm64/-/workerd-linux-arm64-1.20230512.0.tgz", 79 | "integrity": "sha512-LvW/DFz35ISnkgagE6qra1CyFmak5sPJcOZ01fovtHIQdwtgUrU5Q+mTAoDZy+8yQnVIM8HCXJxe5gKxM9hnxQ==", 80 | "cpu": [ 81 | "arm64" 82 | ], 83 | "dev": true, 84 | "optional": true, 85 | "os": [ 86 | "linux" 87 | ], 88 | "engines": { 89 | "node": ">=16" 90 | } 91 | }, 92 | "node_modules/@cloudflare/workerd-windows-64": { 93 | "version": "1.20230512.0", 94 | "resolved": "https://registry.npmjs.org/@cloudflare/workerd-windows-64/-/workerd-windows-64-1.20230512.0.tgz", 95 | "integrity": "sha512-OgRmn5FjroPSha/2JgcM8AQg5NpTig8TqDXgdM61Y/7DCCCEuOuMsZSqU1IrYkPU7gtOFvZSQZLgFA4XxbePbA==", 96 | "cpu": [ 97 | "x64" 98 | ], 99 | "dev": true, 100 | "optional": true, 101 | "os": [ 102 | "win32" 103 | ], 104 | "engines": { 105 | "node": ">=16" 106 | } 107 | }, 108 | "node_modules/@cloudflare/workers-types": { 109 | "version": "4.20230511.0", 110 | "resolved": "https://registry.npmjs.org/@cloudflare/workers-types/-/workers-types-4.20230511.0.tgz", 111 | "integrity": "sha512-Br4i/8+t60HDJIo8o7O9Rrmp03bhdejRW9klb0bK9EfG5Ii7qz5G3PJO12gUz+Vu9m1v9tZ9KOh3Gg8oshXtug==", 112 | "dev": true 113 | }, 114 | "node_modules/@esbuild-plugins/node-globals-polyfill": { 115 | "version": "0.1.1", 116 | "resolved": "https://registry.npmjs.org/@esbuild-plugins/node-globals-polyfill/-/node-globals-polyfill-0.1.1.tgz", 117 | "integrity": "sha512-MR0oAA+mlnJWrt1RQVQ+4VYuRJW/P2YmRTv1AsplObyvuBMnPHiizUF95HHYiSsMGLhyGtWufaq2XQg6+iurBg==", 118 | "dev": true, 119 | "peerDependencies": { 120 | "esbuild": "*" 121 | } 122 | }, 123 | "node_modules/@esbuild-plugins/node-modules-polyfill": { 124 | "version": "0.1.4", 125 | "resolved": "https://registry.npmjs.org/@esbuild-plugins/node-modules-polyfill/-/node-modules-polyfill-0.1.4.tgz", 126 | "integrity": "sha512-uZbcXi0zbmKC/050p3gJnne5Qdzw8vkXIv+c2BW0Lsc1ji1SkrxbKPUy5Efr0blbTu1SL8w4eyfpnSdPg3G0Qg==", 127 | "dev": true, 128 | "dependencies": { 129 | "escape-string-regexp": "^4.0.0", 130 | "rollup-plugin-node-polyfills": "^0.2.1" 131 | }, 132 | "peerDependencies": { 133 | "esbuild": "*" 134 | } 135 | }, 136 | "node_modules/@esbuild/android-arm": { 137 | "version": "0.16.3", 138 | "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.16.3.tgz", 139 | "integrity": "sha512-mueuEoh+s1eRbSJqq9KNBQwI4QhQV6sRXIfTyLXSHGMpyew61rOK4qY21uKbXl1iBoMb0AdL1deWFCQVlN2qHA==", 140 | "cpu": [ 141 | "arm" 142 | ], 143 | "dev": true, 144 | "optional": true, 145 | "os": [ 146 | "android" 147 | ], 148 | "engines": { 149 | "node": ">=12" 150 | } 151 | }, 152 | "node_modules/@esbuild/android-arm64": { 153 | "version": "0.16.3", 154 | "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.16.3.tgz", 155 | "integrity": "sha512-RolFVeinkeraDvN/OoRf1F/lP0KUfGNb5jxy/vkIMeRRChkrX/HTYN6TYZosRJs3a1+8wqpxAo5PI5hFmxyPRg==", 156 | "cpu": [ 157 | "arm64" 158 | ], 159 | "dev": true, 160 | "optional": true, 161 | "os": [ 162 | "android" 163 | ], 164 | "engines": { 165 | "node": ">=12" 166 | } 167 | }, 168 | "node_modules/@esbuild/android-x64": { 169 | "version": "0.16.3", 170 | "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.16.3.tgz", 171 | "integrity": "sha512-SFpTUcIT1bIJuCCBMCQWq1bL2gPTjWoLZdjmIhjdcQHaUfV41OQfho6Ici5uvvkMmZRXIUGpM3GxysP/EU7ifQ==", 172 | "cpu": [ 173 | "x64" 174 | ], 175 | "dev": true, 176 | "optional": true, 177 | "os": [ 178 | "android" 179 | ], 180 | "engines": { 181 | "node": ">=12" 182 | } 183 | }, 184 | "node_modules/@esbuild/darwin-arm64": { 185 | "version": "0.16.3", 186 | "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.16.3.tgz", 187 | "integrity": "sha512-DO8WykMyB+N9mIDfI/Hug70Dk1KipavlGAecxS3jDUwAbTpDXj0Lcwzw9svkhxfpCagDmpaTMgxWK8/C/XcXvw==", 188 | "cpu": [ 189 | "arm64" 190 | ], 191 | "dev": true, 192 | "optional": true, 193 | "os": [ 194 | "darwin" 195 | ], 196 | "engines": { 197 | "node": ">=12" 198 | } 199 | }, 200 | "node_modules/@esbuild/darwin-x64": { 201 | "version": "0.16.3", 202 | "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.16.3.tgz", 203 | "integrity": "sha512-uEqZQ2omc6BvWqdCiyZ5+XmxuHEi1SPzpVxXCSSV2+Sh7sbXbpeNhHIeFrIpRjAs0lI1FmA1iIOxFozKBhKgRQ==", 204 | "cpu": [ 205 | "x64" 206 | ], 207 | "dev": true, 208 | "optional": true, 209 | "os": [ 210 | "darwin" 211 | ], 212 | "engines": { 213 | "node": ">=12" 214 | } 215 | }, 216 | "node_modules/@esbuild/freebsd-arm64": { 217 | "version": "0.16.3", 218 | "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.16.3.tgz", 219 | "integrity": "sha512-nJansp3sSXakNkOD5i5mIz2Is/HjzIhFs49b1tjrPrpCmwgBmH9SSzhC/Z1UqlkivqMYkhfPwMw1dGFUuwmXhw==", 220 | "cpu": [ 221 | "arm64" 222 | ], 223 | "dev": true, 224 | "optional": true, 225 | "os": [ 226 | "freebsd" 227 | ], 228 | "engines": { 229 | "node": ">=12" 230 | } 231 | }, 232 | "node_modules/@esbuild/freebsd-x64": { 233 | "version": "0.16.3", 234 | "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.16.3.tgz", 235 | "integrity": "sha512-TfoDzLw+QHfc4a8aKtGSQ96Wa+6eimljjkq9HKR0rHlU83vw8aldMOUSJTUDxbcUdcgnJzPaX8/vGWm7vyV7ug==", 236 | "cpu": [ 237 | "x64" 238 | ], 239 | "dev": true, 240 | "optional": true, 241 | "os": [ 242 | "freebsd" 243 | ], 244 | "engines": { 245 | "node": ">=12" 246 | } 247 | }, 248 | "node_modules/@esbuild/linux-arm": { 249 | "version": "0.16.3", 250 | "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.16.3.tgz", 251 | "integrity": "sha512-VwswmSYwVAAq6LysV59Fyqk3UIjbhuc6wb3vEcJ7HEJUtFuLK9uXWuFoH1lulEbE4+5GjtHi3MHX+w1gNHdOWQ==", 252 | "cpu": [ 253 | "arm" 254 | ], 255 | "dev": true, 256 | "optional": true, 257 | "os": [ 258 | "linux" 259 | ], 260 | "engines": { 261 | "node": ">=12" 262 | } 263 | }, 264 | "node_modules/@esbuild/linux-arm64": { 265 | "version": "0.16.3", 266 | "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.16.3.tgz", 267 | "integrity": "sha512-7I3RlsnxEFCHVZNBLb2w7unamgZ5sVwO0/ikE2GaYvYuUQs9Qte/w7TqWcXHtCwxvZx/2+F97ndiUQAWs47ZfQ==", 268 | "cpu": [ 269 | "arm64" 270 | ], 271 | "dev": true, 272 | "optional": true, 273 | "os": [ 274 | "linux" 275 | ], 276 | "engines": { 277 | "node": ">=12" 278 | } 279 | }, 280 | "node_modules/@esbuild/linux-ia32": { 281 | "version": "0.16.3", 282 | "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.16.3.tgz", 283 | "integrity": "sha512-X8FDDxM9cqda2rJE+iblQhIMYY49LfvW4kaEjoFbTTQ4Go8G96Smj2w3BRTwA8IHGoi9dPOPGAX63dhuv19UqA==", 284 | "cpu": [ 285 | "ia32" 286 | ], 287 | "dev": true, 288 | "optional": true, 289 | "os": [ 290 | "linux" 291 | ], 292 | "engines": { 293 | "node": ">=12" 294 | } 295 | }, 296 | "node_modules/@esbuild/linux-loong64": { 297 | "version": "0.16.3", 298 | "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.16.3.tgz", 299 | "integrity": "sha512-hIbeejCOyO0X9ujfIIOKjBjNAs9XD/YdJ9JXAy1lHA+8UXuOqbFe4ErMCqMr8dhlMGBuvcQYGF7+kO7waj2KHw==", 300 | "cpu": [ 301 | "loong64" 302 | ], 303 | "dev": true, 304 | "optional": true, 305 | "os": [ 306 | "linux" 307 | ], 308 | "engines": { 309 | "node": ">=12" 310 | } 311 | }, 312 | "node_modules/@esbuild/linux-mips64el": { 313 | "version": "0.16.3", 314 | "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.16.3.tgz", 315 | "integrity": "sha512-znFRzICT/V8VZQMt6rjb21MtAVJv/3dmKRMlohlShrbVXdBuOdDrGb+C2cZGQAR8RFyRe7HS6klmHq103WpmVw==", 316 | "cpu": [ 317 | "mips64el" 318 | ], 319 | "dev": true, 320 | "optional": true, 321 | "os": [ 322 | "linux" 323 | ], 324 | "engines": { 325 | "node": ">=12" 326 | } 327 | }, 328 | "node_modules/@esbuild/linux-ppc64": { 329 | "version": "0.16.3", 330 | "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.16.3.tgz", 331 | "integrity": "sha512-EV7LuEybxhXrVTDpbqWF2yehYRNz5e5p+u3oQUS2+ZFpknyi1NXxr8URk4ykR8Efm7iu04//4sBg249yNOwy5Q==", 332 | "cpu": [ 333 | "ppc64" 334 | ], 335 | "dev": true, 336 | "optional": true, 337 | "os": [ 338 | "linux" 339 | ], 340 | "engines": { 341 | "node": ">=12" 342 | } 343 | }, 344 | "node_modules/@esbuild/linux-riscv64": { 345 | "version": "0.16.3", 346 | "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.16.3.tgz", 347 | "integrity": "sha512-uDxqFOcLzFIJ+r/pkTTSE9lsCEaV/Y6rMlQjUI9BkzASEChYL/aSQjZjchtEmdnVxDKETnUAmsaZ4pqK1eE5BQ==", 348 | "cpu": [ 349 | "riscv64" 350 | ], 351 | "dev": true, 352 | "optional": true, 353 | "os": [ 354 | "linux" 355 | ], 356 | "engines": { 357 | "node": ">=12" 358 | } 359 | }, 360 | "node_modules/@esbuild/linux-s390x": { 361 | "version": "0.16.3", 362 | "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.16.3.tgz", 363 | "integrity": "sha512-NbeREhzSxYwFhnCAQOQZmajsPYtX71Ufej3IQ8W2Gxskfz9DK58ENEju4SbpIj48VenktRASC52N5Fhyf/aliQ==", 364 | "cpu": [ 365 | "s390x" 366 | ], 367 | "dev": true, 368 | "optional": true, 369 | "os": [ 370 | "linux" 371 | ], 372 | "engines": { 373 | "node": ">=12" 374 | } 375 | }, 376 | "node_modules/@esbuild/linux-x64": { 377 | "version": "0.16.3", 378 | "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.16.3.tgz", 379 | "integrity": "sha512-SDiG0nCixYO9JgpehoKgScwic7vXXndfasjnD5DLbp1xltANzqZ425l7LSdHynt19UWOcDjG9wJJzSElsPvk0w==", 380 | "cpu": [ 381 | "x64" 382 | ], 383 | "dev": true, 384 | "optional": true, 385 | "os": [ 386 | "linux" 387 | ], 388 | "engines": { 389 | "node": ">=12" 390 | } 391 | }, 392 | "node_modules/@esbuild/netbsd-x64": { 393 | "version": "0.16.3", 394 | "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.16.3.tgz", 395 | "integrity": "sha512-AzbsJqiHEq1I/tUvOfAzCY15h4/7Ivp3ff/o1GpP16n48JMNAtbW0qui2WCgoIZArEHD0SUQ95gvR0oSO7ZbdA==", 396 | "cpu": [ 397 | "x64" 398 | ], 399 | "dev": true, 400 | "optional": true, 401 | "os": [ 402 | "netbsd" 403 | ], 404 | "engines": { 405 | "node": ">=12" 406 | } 407 | }, 408 | "node_modules/@esbuild/openbsd-x64": { 409 | "version": "0.16.3", 410 | "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.16.3.tgz", 411 | "integrity": "sha512-gSABi8qHl8k3Cbi/4toAzHiykuBuWLZs43JomTcXkjMZVkp0gj3gg9mO+9HJW/8GB5H89RX/V0QP4JGL7YEEVg==", 412 | "cpu": [ 413 | "x64" 414 | ], 415 | "dev": true, 416 | "optional": true, 417 | "os": [ 418 | "openbsd" 419 | ], 420 | "engines": { 421 | "node": ">=12" 422 | } 423 | }, 424 | "node_modules/@esbuild/sunos-x64": { 425 | "version": "0.16.3", 426 | "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.16.3.tgz", 427 | "integrity": "sha512-SF9Kch5Ete4reovvRO6yNjMxrvlfT0F0Flm+NPoUw5Z4Q3r1d23LFTgaLwm3Cp0iGbrU/MoUI+ZqwCv5XJijCw==", 428 | "cpu": [ 429 | "x64" 430 | ], 431 | "dev": true, 432 | "optional": true, 433 | "os": [ 434 | "sunos" 435 | ], 436 | "engines": { 437 | "node": ">=12" 438 | } 439 | }, 440 | "node_modules/@esbuild/win32-arm64": { 441 | "version": "0.16.3", 442 | "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.16.3.tgz", 443 | "integrity": "sha512-u5aBonZIyGopAZyOnoPAA6fGsDeHByZ9CnEzyML9NqntK6D/xl5jteZUKm/p6nD09+v3pTM6TuUIqSPcChk5gg==", 444 | "cpu": [ 445 | "arm64" 446 | ], 447 | "dev": true, 448 | "optional": true, 449 | "os": [ 450 | "win32" 451 | ], 452 | "engines": { 453 | "node": ">=12" 454 | } 455 | }, 456 | "node_modules/@esbuild/win32-ia32": { 457 | "version": "0.16.3", 458 | "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.16.3.tgz", 459 | "integrity": "sha512-GlgVq1WpvOEhNioh74TKelwla9KDuAaLZrdxuuUgsP2vayxeLgVc+rbpIv0IYF4+tlIzq2vRhofV+KGLD+37EQ==", 460 | "cpu": [ 461 | "ia32" 462 | ], 463 | "dev": true, 464 | "optional": true, 465 | "os": [ 466 | "win32" 467 | ], 468 | "engines": { 469 | "node": ">=12" 470 | } 471 | }, 472 | "node_modules/@esbuild/win32-x64": { 473 | "version": "0.16.3", 474 | "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.16.3.tgz", 475 | "integrity": "sha512-5/JuTd8OWW8UzEtyf19fbrtMJENza+C9JoPIkvItgTBQ1FO2ZLvjbPO6Xs54vk0s5JB5QsfieUEshRQfu7ZHow==", 476 | "cpu": [ 477 | "x64" 478 | ], 479 | "dev": true, 480 | "optional": true, 481 | "os": [ 482 | "win32" 483 | ], 484 | "engines": { 485 | "node": ">=12" 486 | } 487 | }, 488 | "node_modules/acorn": { 489 | "version": "8.8.2", 490 | "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.2.tgz", 491 | "integrity": "sha512-xjIYgE8HBrkpd/sJqOGNspf8uHG+NOHGOw6a/Urj8taM2EXfdNAH2oFcPeIFfsv3+kz/mJrS5VuMqbNLjCa2vw==", 492 | "dev": true, 493 | "bin": { 494 | "acorn": "bin/acorn" 495 | }, 496 | "engines": { 497 | "node": ">=0.4.0" 498 | } 499 | }, 500 | "node_modules/acorn-walk": { 501 | "version": "8.2.0", 502 | "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz", 503 | "integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==", 504 | "dev": true, 505 | "engines": { 506 | "node": ">=0.4.0" 507 | } 508 | }, 509 | "node_modules/anymatch": { 510 | "version": "3.1.3", 511 | "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", 512 | "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", 513 | "dev": true, 514 | "dependencies": { 515 | "normalize-path": "^3.0.0", 516 | "picomatch": "^2.0.4" 517 | }, 518 | "engines": { 519 | "node": ">= 8" 520 | } 521 | }, 522 | "node_modules/as-table": { 523 | "version": "1.0.55", 524 | "resolved": "https://registry.npmjs.org/as-table/-/as-table-1.0.55.tgz", 525 | "integrity": "sha512-xvsWESUJn0JN421Xb9MQw6AsMHRCUknCe0Wjlxvjud80mU4E6hQf1A6NzQKcYNmYw62MfzEtXc+badstZP3JpQ==", 526 | "dev": true, 527 | "dependencies": { 528 | "printable-characters": "^1.0.42" 529 | } 530 | }, 531 | "node_modules/base64-js": { 532 | "version": "1.5.1", 533 | "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", 534 | "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", 535 | "dev": true, 536 | "funding": [ 537 | { 538 | "type": "github", 539 | "url": "https://github.com/sponsors/feross" 540 | }, 541 | { 542 | "type": "patreon", 543 | "url": "https://www.patreon.com/feross" 544 | }, 545 | { 546 | "type": "consulting", 547 | "url": "https://feross.org/support" 548 | } 549 | ] 550 | }, 551 | "node_modules/better-sqlite3": { 552 | "version": "8.3.0", 553 | "resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-8.3.0.tgz", 554 | "integrity": "sha512-JTmvBZL/JLTc+3Msbvq6gK6elbU9/wVMqiudplHrVJpr7sVMR9KJrNhZAbW+RhXKlpMcuEhYkdcHa3TXKNXQ1w==", 555 | "dev": true, 556 | "hasInstallScript": true, 557 | "dependencies": { 558 | "bindings": "^1.5.0", 559 | "prebuild-install": "^7.1.0" 560 | } 561 | }, 562 | "node_modules/binary-extensions": { 563 | "version": "2.2.0", 564 | "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", 565 | "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", 566 | "dev": true, 567 | "engines": { 568 | "node": ">=8" 569 | } 570 | }, 571 | "node_modules/bindings": { 572 | "version": "1.5.0", 573 | "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", 574 | "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", 575 | "dev": true, 576 | "dependencies": { 577 | "file-uri-to-path": "1.0.0" 578 | } 579 | }, 580 | "node_modules/bl": { 581 | "version": "4.1.0", 582 | "resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz", 583 | "integrity": "sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==", 584 | "dev": true, 585 | "dependencies": { 586 | "buffer": "^5.5.0", 587 | "inherits": "^2.0.4", 588 | "readable-stream": "^3.4.0" 589 | } 590 | }, 591 | "node_modules/blake3-wasm": { 592 | "version": "2.1.5", 593 | "resolved": "https://registry.npmjs.org/blake3-wasm/-/blake3-wasm-2.1.5.tgz", 594 | "integrity": "sha512-F1+K8EbfOZE49dtoPtmxUQrpXaBIl3ICvasLh+nJta0xkz+9kF/7uet9fLnwKqhDrmj6g+6K3Tw9yQPUg2ka5g==", 595 | "dev": true 596 | }, 597 | "node_modules/braces": { 598 | "version": "3.0.2", 599 | "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", 600 | "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", 601 | "dev": true, 602 | "dependencies": { 603 | "fill-range": "^7.0.1" 604 | }, 605 | "engines": { 606 | "node": ">=8" 607 | } 608 | }, 609 | "node_modules/buffer": { 610 | "version": "5.7.1", 611 | "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", 612 | "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", 613 | "dev": true, 614 | "funding": [ 615 | { 616 | "type": "github", 617 | "url": "https://github.com/sponsors/feross" 618 | }, 619 | { 620 | "type": "patreon", 621 | "url": "https://www.patreon.com/feross" 622 | }, 623 | { 624 | "type": "consulting", 625 | "url": "https://feross.org/support" 626 | } 627 | ], 628 | "dependencies": { 629 | "base64-js": "^1.3.1", 630 | "ieee754": "^1.1.13" 631 | } 632 | }, 633 | "node_modules/buffer-from": { 634 | "version": "1.1.2", 635 | "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", 636 | "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", 637 | "dev": true 638 | }, 639 | "node_modules/busboy": { 640 | "version": "1.6.0", 641 | "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz", 642 | "integrity": "sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==", 643 | "dev": true, 644 | "dependencies": { 645 | "streamsearch": "^1.1.0" 646 | }, 647 | "engines": { 648 | "node": ">=10.16.0" 649 | } 650 | }, 651 | "node_modules/capnp-ts": { 652 | "version": "0.7.0", 653 | "resolved": "https://registry.npmjs.org/capnp-ts/-/capnp-ts-0.7.0.tgz", 654 | "integrity": "sha512-XKxXAC3HVPv7r674zP0VC3RTXz+/JKhfyw94ljvF80yynK6VkTnqE3jMuN8b3dUVmmc43TjyxjW4KTsmB3c86g==", 655 | "dev": true, 656 | "dependencies": { 657 | "debug": "^4.3.1", 658 | "tslib": "^2.2.0" 659 | } 660 | }, 661 | "node_modules/chokidar": { 662 | "version": "3.5.3", 663 | "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", 664 | "integrity": "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==", 665 | "dev": true, 666 | "funding": [ 667 | { 668 | "type": "individual", 669 | "url": "https://paulmillr.com/funding/" 670 | } 671 | ], 672 | "dependencies": { 673 | "anymatch": "~3.1.2", 674 | "braces": "~3.0.2", 675 | "glob-parent": "~5.1.2", 676 | "is-binary-path": "~2.1.0", 677 | "is-glob": "~4.0.1", 678 | "normalize-path": "~3.0.0", 679 | "readdirp": "~3.6.0" 680 | }, 681 | "engines": { 682 | "node": ">= 8.10.0" 683 | }, 684 | "optionalDependencies": { 685 | "fsevents": "~2.3.2" 686 | } 687 | }, 688 | "node_modules/chownr": { 689 | "version": "1.1.4", 690 | "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.4.tgz", 691 | "integrity": "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg==", 692 | "dev": true 693 | }, 694 | "node_modules/cloudflare-basics": { 695 | "version": "0.0.1", 696 | "resolved": "https://registry.npmjs.org/cloudflare-basics/-/cloudflare-basics-0.0.1.tgz", 697 | "integrity": "sha512-fDkagG9L2YMaDUcdl/6wjjHototvXgHTscAfMZ48D5cxbC6khRB5e4Ecjh7gun3B3mCj5MWhse57v6bYNM+DBg==", 698 | "dependencies": { 699 | "zod": "^3.21.4" 700 | } 701 | }, 702 | "node_modules/cookie": { 703 | "version": "0.5.0", 704 | "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.5.0.tgz", 705 | "integrity": "sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==", 706 | "dev": true, 707 | "engines": { 708 | "node": ">= 0.6" 709 | } 710 | }, 711 | "node_modules/data-uri-to-buffer": { 712 | "version": "2.0.2", 713 | "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-2.0.2.tgz", 714 | "integrity": "sha512-ND9qDTLc6diwj+Xe5cdAgVTbLVdXbtxTJRXRhli8Mowuaan+0EJOtdqJ0QCHNSSPyoXGx9HX2/VMnKeC34AChA==", 715 | "dev": true 716 | }, 717 | "node_modules/debug": { 718 | "version": "4.3.4", 719 | "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", 720 | "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", 721 | "dev": true, 722 | "dependencies": { 723 | "ms": "2.1.2" 724 | }, 725 | "engines": { 726 | "node": ">=6.0" 727 | }, 728 | "peerDependenciesMeta": { 729 | "supports-color": { 730 | "optional": true 731 | } 732 | } 733 | }, 734 | "node_modules/decompress-response": { 735 | "version": "6.0.0", 736 | "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-6.0.0.tgz", 737 | "integrity": "sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ==", 738 | "dev": true, 739 | "dependencies": { 740 | "mimic-response": "^3.1.0" 741 | }, 742 | "engines": { 743 | "node": ">=10" 744 | }, 745 | "funding": { 746 | "url": "https://github.com/sponsors/sindresorhus" 747 | } 748 | }, 749 | "node_modules/deep-extend": { 750 | "version": "0.6.0", 751 | "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz", 752 | "integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==", 753 | "dev": true, 754 | "engines": { 755 | "node": ">=4.0.0" 756 | } 757 | }, 758 | "node_modules/detect-libc": { 759 | "version": "2.0.1", 760 | "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.1.tgz", 761 | "integrity": "sha512-463v3ZeIrcWtdgIg6vI6XUncguvr2TnGl4SzDXinkt9mSLpBJKXT3mW6xT3VQdDN11+WVs29pgvivTc4Lp8v+w==", 762 | "dev": true, 763 | "engines": { 764 | "node": ">=8" 765 | } 766 | }, 767 | "node_modules/end-of-stream": { 768 | "version": "1.4.4", 769 | "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", 770 | "integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==", 771 | "dev": true, 772 | "dependencies": { 773 | "once": "^1.4.0" 774 | } 775 | }, 776 | "node_modules/esbuild": { 777 | "version": "0.16.3", 778 | "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.16.3.tgz", 779 | "integrity": "sha512-71f7EjPWTiSguen8X/kxEpkAS7BFHwtQKisCDDV3Y4GLGWBaoSCyD5uXkaUew6JDzA9FEN1W23mdnSwW9kqCeg==", 780 | "dev": true, 781 | "hasInstallScript": true, 782 | "bin": { 783 | "esbuild": "bin/esbuild" 784 | }, 785 | "engines": { 786 | "node": ">=12" 787 | }, 788 | "optionalDependencies": { 789 | "@esbuild/android-arm": "0.16.3", 790 | "@esbuild/android-arm64": "0.16.3", 791 | "@esbuild/android-x64": "0.16.3", 792 | "@esbuild/darwin-arm64": "0.16.3", 793 | "@esbuild/darwin-x64": "0.16.3", 794 | "@esbuild/freebsd-arm64": "0.16.3", 795 | "@esbuild/freebsd-x64": "0.16.3", 796 | "@esbuild/linux-arm": "0.16.3", 797 | "@esbuild/linux-arm64": "0.16.3", 798 | "@esbuild/linux-ia32": "0.16.3", 799 | "@esbuild/linux-loong64": "0.16.3", 800 | "@esbuild/linux-mips64el": "0.16.3", 801 | "@esbuild/linux-ppc64": "0.16.3", 802 | "@esbuild/linux-riscv64": "0.16.3", 803 | "@esbuild/linux-s390x": "0.16.3", 804 | "@esbuild/linux-x64": "0.16.3", 805 | "@esbuild/netbsd-x64": "0.16.3", 806 | "@esbuild/openbsd-x64": "0.16.3", 807 | "@esbuild/sunos-x64": "0.16.3", 808 | "@esbuild/win32-arm64": "0.16.3", 809 | "@esbuild/win32-ia32": "0.16.3", 810 | "@esbuild/win32-x64": "0.16.3" 811 | } 812 | }, 813 | "node_modules/escape-string-regexp": { 814 | "version": "4.0.0", 815 | "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", 816 | "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", 817 | "dev": true, 818 | "engines": { 819 | "node": ">=10" 820 | }, 821 | "funding": { 822 | "url": "https://github.com/sponsors/sindresorhus" 823 | } 824 | }, 825 | "node_modules/estree-walker": { 826 | "version": "0.6.1", 827 | "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.1.tgz", 828 | "integrity": "sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==", 829 | "dev": true 830 | }, 831 | "node_modules/exit-hook": { 832 | "version": "2.2.1", 833 | "resolved": "https://registry.npmjs.org/exit-hook/-/exit-hook-2.2.1.tgz", 834 | "integrity": "sha512-eNTPlAD67BmP31LDINZ3U7HSF8l57TxOY2PmBJ1shpCvpnxBF93mWCE8YHBnXs8qiUZJc9WDcWIeC3a2HIAMfw==", 835 | "dev": true, 836 | "engines": { 837 | "node": ">=6" 838 | }, 839 | "funding": { 840 | "url": "https://github.com/sponsors/sindresorhus" 841 | } 842 | }, 843 | "node_modules/expand-template": { 844 | "version": "2.0.3", 845 | "resolved": "https://registry.npmjs.org/expand-template/-/expand-template-2.0.3.tgz", 846 | "integrity": "sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg==", 847 | "dev": true, 848 | "engines": { 849 | "node": ">=6" 850 | } 851 | }, 852 | "node_modules/file-uri-to-path": { 853 | "version": "1.0.0", 854 | "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", 855 | "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==", 856 | "dev": true 857 | }, 858 | "node_modules/fill-range": { 859 | "version": "7.0.1", 860 | "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", 861 | "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", 862 | "dev": true, 863 | "dependencies": { 864 | "to-regex-range": "^5.0.1" 865 | }, 866 | "engines": { 867 | "node": ">=8" 868 | } 869 | }, 870 | "node_modules/fs-constants": { 871 | "version": "1.0.0", 872 | "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", 873 | "integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==", 874 | "dev": true 875 | }, 876 | "node_modules/fsevents": { 877 | "version": "2.3.2", 878 | "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", 879 | "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", 880 | "dev": true, 881 | "hasInstallScript": true, 882 | "optional": true, 883 | "os": [ 884 | "darwin" 885 | ], 886 | "engines": { 887 | "node": "^8.16.0 || ^10.6.0 || >=11.0.0" 888 | } 889 | }, 890 | "node_modules/get-source": { 891 | "version": "2.0.12", 892 | "resolved": "https://registry.npmjs.org/get-source/-/get-source-2.0.12.tgz", 893 | "integrity": "sha512-X5+4+iD+HoSeEED+uwrQ07BOQr0kEDFMVqqpBuI+RaZBpBpHCuXxo70bjar6f0b0u/DQJsJ7ssurpP0V60Az+w==", 894 | "dev": true, 895 | "dependencies": { 896 | "data-uri-to-buffer": "^2.0.0", 897 | "source-map": "^0.6.1" 898 | } 899 | }, 900 | "node_modules/get-source/node_modules/source-map": { 901 | "version": "0.6.1", 902 | "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", 903 | "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", 904 | "dev": true, 905 | "engines": { 906 | "node": ">=0.10.0" 907 | } 908 | }, 909 | "node_modules/github-from-package": { 910 | "version": "0.0.0", 911 | "resolved": "https://registry.npmjs.org/github-from-package/-/github-from-package-0.0.0.tgz", 912 | "integrity": "sha512-SyHy3T1v2NUXn29OsWdxmK6RwHD+vkj3v8en8AOBZ1wBQ/hCAQ5bAQTD02kW4W9tUp/3Qh6J8r9EvntiyCmOOw==", 913 | "dev": true 914 | }, 915 | "node_modules/glob-parent": { 916 | "version": "5.1.2", 917 | "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", 918 | "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", 919 | "dev": true, 920 | "dependencies": { 921 | "is-glob": "^4.0.1" 922 | }, 923 | "engines": { 924 | "node": ">= 6" 925 | } 926 | }, 927 | "node_modules/glob-to-regexp": { 928 | "version": "0.4.1", 929 | "resolved": "https://registry.npmjs.org/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz", 930 | "integrity": "sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw==", 931 | "dev": true 932 | }, 933 | "node_modules/http-cache-semantics": { 934 | "version": "4.1.1", 935 | "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz", 936 | "integrity": "sha512-er295DKPVsV82j5kw1Gjt+ADA/XYHsajl82cGNQG2eyoPkvgUhX+nDIyelzhIWbbsXP39EHcI6l5tYs2FYqYXQ==", 937 | "dev": true 938 | }, 939 | "node_modules/ieee754": { 940 | "version": "1.2.1", 941 | "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", 942 | "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", 943 | "dev": true, 944 | "funding": [ 945 | { 946 | "type": "github", 947 | "url": "https://github.com/sponsors/feross" 948 | }, 949 | { 950 | "type": "patreon", 951 | "url": "https://www.patreon.com/feross" 952 | }, 953 | { 954 | "type": "consulting", 955 | "url": "https://feross.org/support" 956 | } 957 | ] 958 | }, 959 | "node_modules/inherits": { 960 | "version": "2.0.4", 961 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", 962 | "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", 963 | "dev": true 964 | }, 965 | "node_modules/ini": { 966 | "version": "1.3.8", 967 | "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz", 968 | "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==", 969 | "dev": true 970 | }, 971 | "node_modules/is-binary-path": { 972 | "version": "2.1.0", 973 | "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", 974 | "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", 975 | "dev": true, 976 | "dependencies": { 977 | "binary-extensions": "^2.0.0" 978 | }, 979 | "engines": { 980 | "node": ">=8" 981 | } 982 | }, 983 | "node_modules/is-extglob": { 984 | "version": "2.1.1", 985 | "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", 986 | "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", 987 | "dev": true, 988 | "engines": { 989 | "node": ">=0.10.0" 990 | } 991 | }, 992 | "node_modules/is-glob": { 993 | "version": "4.0.3", 994 | "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", 995 | "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", 996 | "dev": true, 997 | "dependencies": { 998 | "is-extglob": "^2.1.1" 999 | }, 1000 | "engines": { 1001 | "node": ">=0.10.0" 1002 | } 1003 | }, 1004 | "node_modules/is-number": { 1005 | "version": "7.0.0", 1006 | "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", 1007 | "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", 1008 | "dev": true, 1009 | "engines": { 1010 | "node": ">=0.12.0" 1011 | } 1012 | }, 1013 | "node_modules/kleur": { 1014 | "version": "4.1.5", 1015 | "resolved": "https://registry.npmjs.org/kleur/-/kleur-4.1.5.tgz", 1016 | "integrity": "sha512-o+NO+8WrRiQEE4/7nwRJhN1HWpVmJm511pBHUxPLtp0BUISzlBplORYSmTclCnJvQq2tKu/sgl3xVpkc7ZWuQQ==", 1017 | "dev": true, 1018 | "engines": { 1019 | "node": ">=6" 1020 | } 1021 | }, 1022 | "node_modules/lru-cache": { 1023 | "version": "6.0.0", 1024 | "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", 1025 | "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", 1026 | "dev": true, 1027 | "dependencies": { 1028 | "yallist": "^4.0.0" 1029 | }, 1030 | "engines": { 1031 | "node": ">=10" 1032 | } 1033 | }, 1034 | "node_modules/magic-string": { 1035 | "version": "0.25.9", 1036 | "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.9.tgz", 1037 | "integrity": "sha512-RmF0AsMzgt25qzqqLc1+MbHmhdx0ojF2Fvs4XnOqz2ZOBXzzkEwc/dJQZCYHAn7v1jbVOjAZfK8msRn4BxO4VQ==", 1038 | "dev": true, 1039 | "dependencies": { 1040 | "sourcemap-codec": "^1.4.8" 1041 | } 1042 | }, 1043 | "node_modules/mime": { 1044 | "version": "3.0.0", 1045 | "resolved": "https://registry.npmjs.org/mime/-/mime-3.0.0.tgz", 1046 | "integrity": "sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A==", 1047 | "dev": true, 1048 | "bin": { 1049 | "mime": "cli.js" 1050 | }, 1051 | "engines": { 1052 | "node": ">=10.0.0" 1053 | } 1054 | }, 1055 | "node_modules/mimic-response": { 1056 | "version": "3.1.0", 1057 | "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz", 1058 | "integrity": "sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ==", 1059 | "dev": true, 1060 | "engines": { 1061 | "node": ">=10" 1062 | }, 1063 | "funding": { 1064 | "url": "https://github.com/sponsors/sindresorhus" 1065 | } 1066 | }, 1067 | "node_modules/miniflare": { 1068 | "version": "3.0.0", 1069 | "resolved": "https://registry.npmjs.org/miniflare/-/miniflare-3.0.0.tgz", 1070 | "integrity": "sha512-CW8yS00pQCbq2o4K8drePzJBkE0heL9cCY/O8DcYJOHd4M0RVutjrp+LqUP4hfzweZ+LqrLo8+Rzy4cORisQoQ==", 1071 | "dev": true, 1072 | "dependencies": { 1073 | "acorn": "^8.8.0", 1074 | "acorn-walk": "^8.2.0", 1075 | "better-sqlite3": "^8.1.0", 1076 | "capnp-ts": "^0.7.0", 1077 | "exit-hook": "^2.2.1", 1078 | "glob-to-regexp": "^0.4.1", 1079 | "http-cache-semantics": "^4.1.0", 1080 | "kleur": "^4.1.5", 1081 | "source-map-support": "0.5.21", 1082 | "stoppable": "^1.1.0", 1083 | "undici": "^5.13.0", 1084 | "workerd": "^1.20230512.0", 1085 | "ws": "^8.11.0", 1086 | "youch": "^3.2.2", 1087 | "zod": "^3.20.6" 1088 | }, 1089 | "engines": { 1090 | "node": ">=16.13" 1091 | } 1092 | }, 1093 | "node_modules/minimist": { 1094 | "version": "1.2.8", 1095 | "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", 1096 | "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", 1097 | "dev": true, 1098 | "funding": { 1099 | "url": "https://github.com/sponsors/ljharb" 1100 | } 1101 | }, 1102 | "node_modules/mkdirp-classic": { 1103 | "version": "0.5.3", 1104 | "resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz", 1105 | "integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==", 1106 | "dev": true 1107 | }, 1108 | "node_modules/ms": { 1109 | "version": "2.1.2", 1110 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", 1111 | "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", 1112 | "dev": true 1113 | }, 1114 | "node_modules/mustache": { 1115 | "version": "4.2.0", 1116 | "resolved": "https://registry.npmjs.org/mustache/-/mustache-4.2.0.tgz", 1117 | "integrity": "sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ==", 1118 | "dev": true, 1119 | "bin": { 1120 | "mustache": "bin/mustache" 1121 | } 1122 | }, 1123 | "node_modules/nanoid": { 1124 | "version": "3.3.6", 1125 | "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz", 1126 | "integrity": "sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==", 1127 | "dev": true, 1128 | "funding": [ 1129 | { 1130 | "type": "github", 1131 | "url": "https://github.com/sponsors/ai" 1132 | } 1133 | ], 1134 | "bin": { 1135 | "nanoid": "bin/nanoid.cjs" 1136 | }, 1137 | "engines": { 1138 | "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" 1139 | } 1140 | }, 1141 | "node_modules/napi-build-utils": { 1142 | "version": "1.0.2", 1143 | "resolved": "https://registry.npmjs.org/napi-build-utils/-/napi-build-utils-1.0.2.tgz", 1144 | "integrity": "sha512-ONmRUqK7zj7DWX0D9ADe03wbwOBZxNAfF20PlGfCWQcD3+/MakShIHrMqx9YwPTfxDdF1zLeL+RGZiR9kGMLdg==", 1145 | "dev": true 1146 | }, 1147 | "node_modules/node-abi": { 1148 | "version": "3.40.0", 1149 | "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.40.0.tgz", 1150 | "integrity": "sha512-zNy02qivjjRosswoYmPi8hIKJRr8MpQyeKT6qlcq/OnOgA3Rhoae+IYOqsM9V5+JnHWmxKnWOT2GxvtqdtOCXA==", 1151 | "dev": true, 1152 | "dependencies": { 1153 | "semver": "^7.3.5" 1154 | }, 1155 | "engines": { 1156 | "node": ">=10" 1157 | } 1158 | }, 1159 | "node_modules/node-forge": { 1160 | "version": "1.3.1", 1161 | "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.3.1.tgz", 1162 | "integrity": "sha512-dPEtOeMvF9VMcYV/1Wb8CPoVAXtp6MKMlcbAt4ddqmGqUJ6fQZFXkNZNkNlfevtNkGtaSoXf/vNNNSvgrdXwtA==", 1163 | "dev": true, 1164 | "engines": { 1165 | "node": ">= 6.13.0" 1166 | } 1167 | }, 1168 | "node_modules/normalize-path": { 1169 | "version": "3.0.0", 1170 | "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", 1171 | "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", 1172 | "dev": true, 1173 | "engines": { 1174 | "node": ">=0.10.0" 1175 | } 1176 | }, 1177 | "node_modules/once": { 1178 | "version": "1.4.0", 1179 | "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", 1180 | "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", 1181 | "dev": true, 1182 | "dependencies": { 1183 | "wrappy": "1" 1184 | } 1185 | }, 1186 | "node_modules/path-to-regexp": { 1187 | "version": "6.2.1", 1188 | "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-6.2.1.tgz", 1189 | "integrity": "sha512-JLyh7xT1kizaEvcaXOQwOc2/Yhw6KZOvPf1S8401UyLk86CU79LN3vl7ztXGm/pZ+YjoyAJ4rxmHwbkBXJX+yw==", 1190 | "dev": true 1191 | }, 1192 | "node_modules/picomatch": { 1193 | "version": "2.3.1", 1194 | "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", 1195 | "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", 1196 | "dev": true, 1197 | "engines": { 1198 | "node": ">=8.6" 1199 | }, 1200 | "funding": { 1201 | "url": "https://github.com/sponsors/jonschlinkert" 1202 | } 1203 | }, 1204 | "node_modules/prebuild-install": { 1205 | "version": "7.1.1", 1206 | "resolved": "https://registry.npmjs.org/prebuild-install/-/prebuild-install-7.1.1.tgz", 1207 | "integrity": "sha512-jAXscXWMcCK8GgCoHOfIr0ODh5ai8mj63L2nWrjuAgXE6tDyYGnx4/8o/rCgU+B4JSyZBKbeZqzhtwtC3ovxjw==", 1208 | "dev": true, 1209 | "dependencies": { 1210 | "detect-libc": "^2.0.0", 1211 | "expand-template": "^2.0.3", 1212 | "github-from-package": "0.0.0", 1213 | "minimist": "^1.2.3", 1214 | "mkdirp-classic": "^0.5.3", 1215 | "napi-build-utils": "^1.0.1", 1216 | "node-abi": "^3.3.0", 1217 | "pump": "^3.0.0", 1218 | "rc": "^1.2.7", 1219 | "simple-get": "^4.0.0", 1220 | "tar-fs": "^2.0.0", 1221 | "tunnel-agent": "^0.6.0" 1222 | }, 1223 | "bin": { 1224 | "prebuild-install": "bin.js" 1225 | }, 1226 | "engines": { 1227 | "node": ">=10" 1228 | } 1229 | }, 1230 | "node_modules/printable-characters": { 1231 | "version": "1.0.42", 1232 | "resolved": "https://registry.npmjs.org/printable-characters/-/printable-characters-1.0.42.tgz", 1233 | "integrity": "sha512-dKp+C4iXWK4vVYZmYSd0KBH5F/h1HoZRsbJ82AVKRO3PEo8L4lBS/vLwhVtpwwuYcoIsVY+1JYKR268yn480uQ==", 1234 | "dev": true 1235 | }, 1236 | "node_modules/pump": { 1237 | "version": "3.0.0", 1238 | "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", 1239 | "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", 1240 | "dev": true, 1241 | "dependencies": { 1242 | "end-of-stream": "^1.1.0", 1243 | "once": "^1.3.1" 1244 | } 1245 | }, 1246 | "node_modules/rc": { 1247 | "version": "1.2.8", 1248 | "resolved": "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz", 1249 | "integrity": "sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==", 1250 | "dev": true, 1251 | "dependencies": { 1252 | "deep-extend": "^0.6.0", 1253 | "ini": "~1.3.0", 1254 | "minimist": "^1.2.0", 1255 | "strip-json-comments": "~2.0.1" 1256 | }, 1257 | "bin": { 1258 | "rc": "cli.js" 1259 | } 1260 | }, 1261 | "node_modules/readable-stream": { 1262 | "version": "3.6.2", 1263 | "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", 1264 | "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", 1265 | "dev": true, 1266 | "dependencies": { 1267 | "inherits": "^2.0.3", 1268 | "string_decoder": "^1.1.1", 1269 | "util-deprecate": "^1.0.1" 1270 | }, 1271 | "engines": { 1272 | "node": ">= 6" 1273 | } 1274 | }, 1275 | "node_modules/readdirp": { 1276 | "version": "3.6.0", 1277 | "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", 1278 | "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", 1279 | "dev": true, 1280 | "dependencies": { 1281 | "picomatch": "^2.2.1" 1282 | }, 1283 | "engines": { 1284 | "node": ">=8.10.0" 1285 | } 1286 | }, 1287 | "node_modules/rollup-plugin-inject": { 1288 | "version": "3.0.2", 1289 | "resolved": "https://registry.npmjs.org/rollup-plugin-inject/-/rollup-plugin-inject-3.0.2.tgz", 1290 | "integrity": "sha512-ptg9PQwzs3orn4jkgXJ74bfs5vYz1NCZlSQMBUA0wKcGp5i5pA1AO3fOUEte8enhGUC+iapTCzEWw2jEFFUO/w==", 1291 | "deprecated": "This package has been deprecated and is no longer maintained. Please use @rollup/plugin-inject.", 1292 | "dev": true, 1293 | "dependencies": { 1294 | "estree-walker": "^0.6.1", 1295 | "magic-string": "^0.25.3", 1296 | "rollup-pluginutils": "^2.8.1" 1297 | } 1298 | }, 1299 | "node_modules/rollup-plugin-node-polyfills": { 1300 | "version": "0.2.1", 1301 | "resolved": "https://registry.npmjs.org/rollup-plugin-node-polyfills/-/rollup-plugin-node-polyfills-0.2.1.tgz", 1302 | "integrity": "sha512-4kCrKPTJ6sK4/gLL/U5QzVT8cxJcofO0OU74tnB19F40cmuAKSzH5/siithxlofFEjwvw1YAhPmbvGNA6jEroA==", 1303 | "dev": true, 1304 | "dependencies": { 1305 | "rollup-plugin-inject": "^3.0.0" 1306 | } 1307 | }, 1308 | "node_modules/rollup-pluginutils": { 1309 | "version": "2.8.2", 1310 | "resolved": "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz", 1311 | "integrity": "sha512-EEp9NhnUkwY8aif6bxgovPHMoMoNr2FulJziTndpt5H9RdwC47GSGuII9XxpSdzVGM0GWrNPHV6ie1LTNJPaLQ==", 1312 | "dev": true, 1313 | "dependencies": { 1314 | "estree-walker": "^0.6.1" 1315 | } 1316 | }, 1317 | "node_modules/safe-buffer": { 1318 | "version": "5.2.1", 1319 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", 1320 | "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", 1321 | "dev": true, 1322 | "funding": [ 1323 | { 1324 | "type": "github", 1325 | "url": "https://github.com/sponsors/feross" 1326 | }, 1327 | { 1328 | "type": "patreon", 1329 | "url": "https://www.patreon.com/feross" 1330 | }, 1331 | { 1332 | "type": "consulting", 1333 | "url": "https://feross.org/support" 1334 | } 1335 | ] 1336 | }, 1337 | "node_modules/selfsigned": { 1338 | "version": "2.1.1", 1339 | "resolved": "https://registry.npmjs.org/selfsigned/-/selfsigned-2.1.1.tgz", 1340 | "integrity": "sha512-GSL3aowiF7wa/WtSFwnUrludWFoNhftq8bUkH9pkzjpN2XSPOAYEgg6e0sS9s0rZwgJzJiQRPU18A6clnoW5wQ==", 1341 | "dev": true, 1342 | "dependencies": { 1343 | "node-forge": "^1" 1344 | }, 1345 | "engines": { 1346 | "node": ">=10" 1347 | } 1348 | }, 1349 | "node_modules/semver": { 1350 | "version": "7.5.1", 1351 | "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.1.tgz", 1352 | "integrity": "sha512-Wvss5ivl8TMRZXXESstBA4uR5iXgEN/VC5/sOcuXdVLzcdkz4HWetIoRfG5gb5X+ij/G9rw9YoGn3QoQ8OCSpw==", 1353 | "dev": true, 1354 | "dependencies": { 1355 | "lru-cache": "^6.0.0" 1356 | }, 1357 | "bin": { 1358 | "semver": "bin/semver.js" 1359 | }, 1360 | "engines": { 1361 | "node": ">=10" 1362 | } 1363 | }, 1364 | "node_modules/simple-concat": { 1365 | "version": "1.0.1", 1366 | "resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.1.tgz", 1367 | "integrity": "sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q==", 1368 | "dev": true, 1369 | "funding": [ 1370 | { 1371 | "type": "github", 1372 | "url": "https://github.com/sponsors/feross" 1373 | }, 1374 | { 1375 | "type": "patreon", 1376 | "url": "https://www.patreon.com/feross" 1377 | }, 1378 | { 1379 | "type": "consulting", 1380 | "url": "https://feross.org/support" 1381 | } 1382 | ] 1383 | }, 1384 | "node_modules/simple-get": { 1385 | "version": "4.0.1", 1386 | "resolved": "https://registry.npmjs.org/simple-get/-/simple-get-4.0.1.tgz", 1387 | "integrity": "sha512-brv7p5WgH0jmQJr1ZDDfKDOSeWWg+OVypG99A/5vYGPqJ6pxiaHLy8nxtFjBA7oMa01ebA9gfh1uMCFqOuXxvA==", 1388 | "dev": true, 1389 | "funding": [ 1390 | { 1391 | "type": "github", 1392 | "url": "https://github.com/sponsors/feross" 1393 | }, 1394 | { 1395 | "type": "patreon", 1396 | "url": "https://www.patreon.com/feross" 1397 | }, 1398 | { 1399 | "type": "consulting", 1400 | "url": "https://feross.org/support" 1401 | } 1402 | ], 1403 | "dependencies": { 1404 | "decompress-response": "^6.0.0", 1405 | "once": "^1.3.1", 1406 | "simple-concat": "^1.0.0" 1407 | } 1408 | }, 1409 | "node_modules/source-map": { 1410 | "version": "0.7.4", 1411 | "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.4.tgz", 1412 | "integrity": "sha512-l3BikUxvPOcn5E74dZiq5BGsTb5yEwhaTSzccU6t4sDOH8NWJCstKO5QT2CvtFoK6F0saL7p9xHAqHOlCPJygA==", 1413 | "dev": true, 1414 | "engines": { 1415 | "node": ">= 8" 1416 | } 1417 | }, 1418 | "node_modules/source-map-support": { 1419 | "version": "0.5.21", 1420 | "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz", 1421 | "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==", 1422 | "dev": true, 1423 | "dependencies": { 1424 | "buffer-from": "^1.0.0", 1425 | "source-map": "^0.6.0" 1426 | } 1427 | }, 1428 | "node_modules/source-map-support/node_modules/source-map": { 1429 | "version": "0.6.1", 1430 | "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", 1431 | "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", 1432 | "dev": true, 1433 | "engines": { 1434 | "node": ">=0.10.0" 1435 | } 1436 | }, 1437 | "node_modules/sourcemap-codec": { 1438 | "version": "1.4.8", 1439 | "resolved": "https://registry.npmjs.org/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz", 1440 | "integrity": "sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==", 1441 | "deprecated": "Please use @jridgewell/sourcemap-codec instead", 1442 | "dev": true 1443 | }, 1444 | "node_modules/stacktracey": { 1445 | "version": "2.1.8", 1446 | "resolved": "https://registry.npmjs.org/stacktracey/-/stacktracey-2.1.8.tgz", 1447 | "integrity": "sha512-Kpij9riA+UNg7TnphqjH7/CzctQ/owJGNbFkfEeve4Z4uxT5+JapVLFXcsurIfN34gnTWZNJ/f7NMG0E8JDzTw==", 1448 | "dev": true, 1449 | "dependencies": { 1450 | "as-table": "^1.0.36", 1451 | "get-source": "^2.0.12" 1452 | } 1453 | }, 1454 | "node_modules/stoppable": { 1455 | "version": "1.1.0", 1456 | "resolved": "https://registry.npmjs.org/stoppable/-/stoppable-1.1.0.tgz", 1457 | "integrity": "sha512-KXDYZ9dszj6bzvnEMRYvxgeTHU74QBFL54XKtP3nyMuJ81CFYtABZ3bAzL2EdFUaEwJOBOgENyFj3R7oTzDyyw==", 1458 | "dev": true, 1459 | "engines": { 1460 | "node": ">=4", 1461 | "npm": ">=6" 1462 | } 1463 | }, 1464 | "node_modules/streamsearch": { 1465 | "version": "1.1.0", 1466 | "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz", 1467 | "integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==", 1468 | "dev": true, 1469 | "engines": { 1470 | "node": ">=10.0.0" 1471 | } 1472 | }, 1473 | "node_modules/string_decoder": { 1474 | "version": "1.3.0", 1475 | "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", 1476 | "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", 1477 | "dev": true, 1478 | "dependencies": { 1479 | "safe-buffer": "~5.2.0" 1480 | } 1481 | }, 1482 | "node_modules/strip-json-comments": { 1483 | "version": "2.0.1", 1484 | "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", 1485 | "integrity": "sha512-4gB8na07fecVVkOI6Rs4e7T6NOTki5EmL7TUduTs6bu3EdnSycntVJ4re8kgZA+wx9IueI2Y11bfbgwtzuE0KQ==", 1486 | "dev": true, 1487 | "engines": { 1488 | "node": ">=0.10.0" 1489 | } 1490 | }, 1491 | "node_modules/tar-fs": { 1492 | "version": "2.1.1", 1493 | "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.1.tgz", 1494 | "integrity": "sha512-V0r2Y9scmbDRLCNex/+hYzvp/zyYjvFbHPNgVTKfQvVrb6guiE/fxP+XblDNR011utopbkex2nM4dHNV6GDsng==", 1495 | "dev": true, 1496 | "dependencies": { 1497 | "chownr": "^1.1.1", 1498 | "mkdirp-classic": "^0.5.2", 1499 | "pump": "^3.0.0", 1500 | "tar-stream": "^2.1.4" 1501 | } 1502 | }, 1503 | "node_modules/tar-stream": { 1504 | "version": "2.2.0", 1505 | "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.2.0.tgz", 1506 | "integrity": "sha512-ujeqbceABgwMZxEJnk2HDY2DlnUZ+9oEcb1KzTVfYHio0UE6dG71n60d8D2I4qNvleWrrXpmjpt7vZeF1LnMZQ==", 1507 | "dev": true, 1508 | "dependencies": { 1509 | "bl": "^4.0.3", 1510 | "end-of-stream": "^1.4.1", 1511 | "fs-constants": "^1.0.0", 1512 | "inherits": "^2.0.3", 1513 | "readable-stream": "^3.1.1" 1514 | }, 1515 | "engines": { 1516 | "node": ">=6" 1517 | } 1518 | }, 1519 | "node_modules/to-regex-range": { 1520 | "version": "5.0.1", 1521 | "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", 1522 | "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", 1523 | "dev": true, 1524 | "dependencies": { 1525 | "is-number": "^7.0.0" 1526 | }, 1527 | "engines": { 1528 | "node": ">=8.0" 1529 | } 1530 | }, 1531 | "node_modules/tslib": { 1532 | "version": "2.5.2", 1533 | "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.5.2.tgz", 1534 | "integrity": "sha512-5svOrSA2w3iGFDs1HibEVBGbDrAY82bFQ3HZ3ixB+88nsbsWQoKqDRb5UBYAUPEzbBn6dAp5gRNXglySbx1MlA==", 1535 | "dev": true 1536 | }, 1537 | "node_modules/tunnel-agent": { 1538 | "version": "0.6.0", 1539 | "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", 1540 | "integrity": "sha512-McnNiV1l8RYeY8tBgEpuodCC1mLUdbSN+CYBL7kJsJNInOP8UjDDEwdk6Mw60vdLLrr5NHKZhMAOSrR2NZuQ+w==", 1541 | "dev": true, 1542 | "dependencies": { 1543 | "safe-buffer": "^5.0.1" 1544 | }, 1545 | "engines": { 1546 | "node": "*" 1547 | } 1548 | }, 1549 | "node_modules/typescript": { 1550 | "version": "5.0.4", 1551 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz", 1552 | "integrity": "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==", 1553 | "dev": true, 1554 | "bin": { 1555 | "tsc": "bin/tsc", 1556 | "tsserver": "bin/tsserver" 1557 | }, 1558 | "engines": { 1559 | "node": ">=12.20" 1560 | } 1561 | }, 1562 | "node_modules/undici": { 1563 | "version": "5.22.1", 1564 | "resolved": "https://registry.npmjs.org/undici/-/undici-5.22.1.tgz", 1565 | "integrity": "sha512-Ji2IJhFXZY0x/0tVBXeQwgPlLWw13GVzpsWPQ3rV50IFMMof2I55PZZxtm4P6iNq+L5znYN9nSTAq0ZyE6lSJw==", 1566 | "dev": true, 1567 | "dependencies": { 1568 | "busboy": "^1.6.0" 1569 | }, 1570 | "engines": { 1571 | "node": ">=14.0" 1572 | } 1573 | }, 1574 | "node_modules/util-deprecate": { 1575 | "version": "1.0.2", 1576 | "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", 1577 | "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", 1578 | "dev": true 1579 | }, 1580 | "node_modules/workerd": { 1581 | "version": "1.20230512.0", 1582 | "resolved": "https://registry.npmjs.org/workerd/-/workerd-1.20230512.0.tgz", 1583 | "integrity": "sha512-rueIsVxLTVlqWyaSVHlDKFZRLkDAMmUhxiKXE+guMR3fauwPPsuzs/VKWUqX2sqR2UKF+1JxrUtH9OvaIqoHhA==", 1584 | "dev": true, 1585 | "hasInstallScript": true, 1586 | "bin": { 1587 | "workerd": "bin/workerd" 1588 | }, 1589 | "engines": { 1590 | "node": ">=16" 1591 | }, 1592 | "optionalDependencies": { 1593 | "@cloudflare/workerd-darwin-64": "1.20230512.0", 1594 | "@cloudflare/workerd-darwin-arm64": "1.20230512.0", 1595 | "@cloudflare/workerd-linux-64": "1.20230512.0", 1596 | "@cloudflare/workerd-linux-arm64": "1.20230512.0", 1597 | "@cloudflare/workerd-windows-64": "1.20230512.0" 1598 | } 1599 | }, 1600 | "node_modules/wrangler": { 1601 | "version": "3.0.0", 1602 | "resolved": "https://registry.npmjs.org/wrangler/-/wrangler-3.0.0.tgz", 1603 | "integrity": "sha512-azppXJjEQeaVg3wxFZJOGDGtpR8e9clHr2aHuanGHOk9vX3gvesCv97BF/n8qh1Y1d7vDKOBdfQW3UOYZNFGNw==", 1604 | "dev": true, 1605 | "dependencies": { 1606 | "@cloudflare/kv-asset-handler": "^0.2.0", 1607 | "@esbuild-plugins/node-globals-polyfill": "^0.1.1", 1608 | "@esbuild-plugins/node-modules-polyfill": "^0.1.4", 1609 | "blake3-wasm": "^2.1.5", 1610 | "chokidar": "^3.5.3", 1611 | "esbuild": "0.16.3", 1612 | "miniflare": "^3.0.0", 1613 | "nanoid": "^3.3.3", 1614 | "path-to-regexp": "^6.2.0", 1615 | "selfsigned": "^2.0.1", 1616 | "source-map": "^0.7.4", 1617 | "xxhash-wasm": "^1.0.1" 1618 | }, 1619 | "bin": { 1620 | "wrangler": "bin/wrangler.js", 1621 | "wrangler2": "bin/wrangler.js" 1622 | }, 1623 | "engines": { 1624 | "node": ">=16.13.0" 1625 | }, 1626 | "optionalDependencies": { 1627 | "fsevents": "~2.3.2" 1628 | } 1629 | }, 1630 | "node_modules/wrappy": { 1631 | "version": "1.0.2", 1632 | "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", 1633 | "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", 1634 | "dev": true 1635 | }, 1636 | "node_modules/ws": { 1637 | "version": "8.13.0", 1638 | "resolved": "https://registry.npmjs.org/ws/-/ws-8.13.0.tgz", 1639 | "integrity": "sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==", 1640 | "dev": true, 1641 | "engines": { 1642 | "node": ">=10.0.0" 1643 | }, 1644 | "peerDependencies": { 1645 | "bufferutil": "^4.0.1", 1646 | "utf-8-validate": ">=5.0.2" 1647 | }, 1648 | "peerDependenciesMeta": { 1649 | "bufferutil": { 1650 | "optional": true 1651 | }, 1652 | "utf-8-validate": { 1653 | "optional": true 1654 | } 1655 | } 1656 | }, 1657 | "node_modules/xxhash-wasm": { 1658 | "version": "1.0.2", 1659 | "resolved": "https://registry.npmjs.org/xxhash-wasm/-/xxhash-wasm-1.0.2.tgz", 1660 | "integrity": "sha512-ibF0Or+FivM9lNrg+HGJfVX8WJqgo+kCLDc4vx6xMeTce7Aj+DLttKbxxRR/gNLSAelRc1omAPlJ77N/Jem07A==", 1661 | "dev": true 1662 | }, 1663 | "node_modules/yallist": { 1664 | "version": "4.0.0", 1665 | "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", 1666 | "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", 1667 | "dev": true 1668 | }, 1669 | "node_modules/youch": { 1670 | "version": "3.2.3", 1671 | "resolved": "https://registry.npmjs.org/youch/-/youch-3.2.3.tgz", 1672 | "integrity": "sha512-ZBcWz/uzZaQVdCvfV4uk616Bbpf2ee+F/AvuKDR5EwX/Y4v06xWdtMluqTD7+KlZdM93lLm9gMZYo0sKBS0pgw==", 1673 | "dev": true, 1674 | "dependencies": { 1675 | "cookie": "^0.5.0", 1676 | "mustache": "^4.2.0", 1677 | "stacktracey": "^2.1.8" 1678 | } 1679 | }, 1680 | "node_modules/zod": { 1681 | "version": "3.21.4", 1682 | "resolved": "https://registry.npmjs.org/zod/-/zod-3.21.4.tgz", 1683 | "integrity": "sha512-m46AKbrzKVzOzs/DZgVnG5H55N1sv1M8qZU3A8RIKbs3mrACDNeIOeilDymVb2HdmP8uwshOCF4uJ8uM9rCqJw==", 1684 | "funding": { 1685 | "url": "https://github.com/sponsors/colinhacks" 1686 | } 1687 | } 1688 | } 1689 | } 1690 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cloudflare-basics-example", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "deploy": "wrangler deploy", 7 | "start": "wrangler dev" 8 | }, 9 | "eslintConfig": { 10 | "rules": { 11 | "semi": [ 12 | "error", 13 | "never" 14 | ] 15 | } 16 | }, 17 | "devDependencies": { 18 | "@cloudflare/workers-types": "^4.20230419.0", 19 | "typescript": "^5.0.4", 20 | "wrangler": "^3.0.0" 21 | }, 22 | "dependencies": { 23 | "cloudflare-basics": "^0.0.1" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /example/src/worker.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-unused-vars */ 2 | import { RouteHandler, Router, json } from 'cloudflare-basics' 3 | 4 | /** 5 | * Welcome to Cloudflare Workers! This is your first worker. 6 | * 7 | * - Run `npm run dev` in your terminal to start a development server 8 | * - Open a browser tab at http://localhost:8787/ to see your worker in action 9 | * - Run `npm run deploy` to publish your worker 10 | * 11 | * Learn more at https://developers.cloudflare.com/workers/ 12 | */ 13 | 14 | export interface Env { 15 | // Example binding to KV. Learn more at https://developers.cloudflare.com/workers/runtime-apis/kv/ 16 | // MY_KV_NAMESPACE: KVNamespace; 17 | // 18 | // Example binding to Durable Object. Learn more at https://developers.cloudflare.com/workers/runtime-apis/durable-objects/ 19 | // MY_DURABLE_OBJECT: DurableObjectNamespace; 20 | // 21 | // Example binding to R2. Learn more at https://developers.cloudflare.com/workers/runtime-apis/r2/ 22 | // MY_BUCKET: R2Bucket; 23 | // 24 | // Example binding to a Service. Learn more at https://developers.cloudflare.com/workers/runtime-apis/service-bindings/ 25 | // MY_SERVICE: Fetcher; 26 | // 27 | // Example binding to a Queue. Learn more at https://developers.cloudflare.com/queues/javascript-apis/ 28 | // MY_QUEUE: Queue; 29 | 30 | FOO: string 31 | } 32 | 33 | export default { 34 | async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise { 35 | const router = new Router() 36 | 37 | router.get('/', async ({ request }) => { 38 | return new Response('Hello World!') 39 | }) 40 | 41 | router.post('/books', async ({ request }) => { 42 | const data = await request.body() 43 | 44 | return json({ data }) 45 | }) 46 | 47 | const MyHandler: RouteHandler = async ({ params }) => { 48 | const bookId = params?.id 49 | 50 | return json({ bookId }) 51 | } 52 | 53 | router.get('/books/:id', MyHandler) 54 | 55 | return router.handle(request, env, ctx) ?? new Response('Not Found', { status: 404 }) 56 | }, 57 | } 58 | -------------------------------------------------------------------------------- /example/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Visit https://aka.ms/tsconfig.json to read more about this file */ 4 | 5 | /* Projects */ 6 | // "incremental": true, /* Enable incremental compilation */ 7 | // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ 8 | // "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */ 9 | // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */ 10 | // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ 11 | // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ 12 | 13 | /* Language and Environment */ 14 | "target": "es2021" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, 15 | "lib": ["es2021"] /* Specify a set of bundled library declaration files that describe the target runtime environment. */, 16 | "jsx": "react" /* Specify what JSX code is generated. */, 17 | // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ 18 | // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ 19 | // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */ 20 | // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ 21 | // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */ 22 | // "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */ 23 | // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ 24 | // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ 25 | 26 | /* Modules */ 27 | "module": "es2022" /* Specify what module code is generated. */, 28 | // "rootDir": "./", /* Specify the root folder within your source files. */ 29 | "moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */, 30 | // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ 31 | // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ 32 | // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ 33 | // "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */ 34 | "types": ["@cloudflare/workers-types"] /* Specify type package names to be included without being referenced in a source file. */, 35 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 36 | "resolveJsonModule": true /* Enable importing .json files */, 37 | // "noResolve": true, /* Disallow `import`s, `require`s or ``s from expanding the number of files TypeScript should add to a project. */ 38 | 39 | /* JavaScript Support */ 40 | "allowJs": true /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */, 41 | "checkJs": false /* Enable error reporting in type-checked JavaScript files. */, 42 | // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */ 43 | 44 | /* Emit */ 45 | // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ 46 | // "declarationMap": true, /* Create sourcemaps for d.ts files. */ 47 | // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ 48 | // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ 49 | // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ 50 | // "outDir": "./", /* Specify an output folder for all emitted files. */ 51 | // "removeComments": true, /* Disable emitting comments. */ 52 | "noEmit": true /* Disable emitting files from a compilation. */, 53 | // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ 54 | // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */ 55 | // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ 56 | // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ 57 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 58 | // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ 59 | // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ 60 | // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ 61 | // "newLine": "crlf", /* Set the newline character for emitting files. */ 62 | // "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */ 63 | // "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */ 64 | // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ 65 | // "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */ 66 | // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ 67 | // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ 68 | 69 | /* Interop Constraints */ 70 | "isolatedModules": true /* Ensure that each file can be safely transpiled without relying on other imports. */, 71 | "allowSyntheticDefaultImports": true /* Allow 'import x from y' when a module doesn't have a default export. */, 72 | // "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */, 73 | // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ 74 | "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, 75 | 76 | /* Type Checking */ 77 | "strict": true /* Enable all strict type-checking options. */, 78 | // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */ 79 | // "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */ 80 | // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ 81 | // "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */ 82 | // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ 83 | // "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */ 84 | // "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */ 85 | // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ 86 | // "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */ 87 | // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */ 88 | // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ 89 | // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ 90 | // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ 91 | // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ 92 | // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ 93 | // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */ 94 | // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ 95 | // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ 96 | 97 | /* Completeness */ 98 | // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ 99 | "skipLibCheck": true /* Skip type checking all .d.ts files. */ 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /example/wrangler.toml: -------------------------------------------------------------------------------- 1 | name = "cloudflare-basics-example" 2 | main = "src/worker.ts" 3 | compatibility_date = "2023-05-20" 4 | 5 | # # KV Namespace binding - For more information: https://developers.cloudflare.com/workers/runtime-apis/kv 6 | # [[kv_namespaces]] 7 | # binding = "MY_KV_NAMESPACE" 8 | # id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 9 | 10 | # # Durable Object binding - For more information: https://developers.cloudflare.com/workers/runtime-apis/durable-objects 11 | # [[durable_objects]] 12 | # binding = "MY_DURABLE_OBJECT" 13 | # class_name = "MyDurableObject" 14 | 15 | # # Bucket binding - For more information: https://developers.cloudflare.com/workers/runtime-apis/kv#bucket 16 | # [[buckets]] 17 | # binding = "MY_BUCKET" 18 | # name = "my-bucket" 19 | # bucket_id = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy" 20 | 21 | # # Service binding - For more information: https://developers.cloudflare.com/workers/platform/services 22 | # [[routes]] 23 | # binding = "MY_SERVICE" 24 | # pattern = "/api/*" 25 | # script = "api.js" 26 | 27 | # # Queue binding - For more information: https://developers.cloudflare.com/workers/runtime-apis/queues 28 | # [[queues]] 29 | # binding = "MY_QUEUE" 30 | # name = "my-queue" 31 | # zone_id = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" 32 | 33 | # [env.production] 34 | # MY_VARIABLE = "production_value" 35 | 36 | # [env.staging] 37 | # MY_VARIABLE = "staging_value" 38 | 39 | # [env.shared] 40 | # SHARED_VARIABLE = "shared_value" 41 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cloudflare-basics", 3 | "type": "module", 4 | "version": "0.0.9", 5 | "packageManager": "pnpm@8.5.1", 6 | "description": "", 7 | "author": "Alex MaccCaw ", 8 | "license": "MIT", 9 | "homepage": "https://github.com/maccman/cloudflare-basics#readme", 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/maccman/cloudflare-basics.git" 13 | }, 14 | "bugs": "https://github.com/maccman/cloudflare-basics/issues", 15 | "keywords": [], 16 | "sideEffects": false, 17 | "main": "./dist/index.cjs", 18 | "module": "./dist/index.js", 19 | "types": "./dist/index.d.ts", 20 | "exports": { 21 | ".": { 22 | "types": "./dist/index.d.ts", 23 | "require": "./dist/index.cjs", 24 | "import": "./dist/index.js" 25 | }, 26 | "./middleware/zod-validation": { 27 | "types": "./dist/middleware/zod-validation.d.ts", 28 | "import": "./dist/middleware/zod-validation.js", 29 | "default": "./dist/middleware/zod-validation.js" 30 | } 31 | }, 32 | "typesVersions": { 33 | "*": { 34 | "*": [ 35 | "./dist/*", 36 | "./dist/index.d.ts" 37 | ], 38 | "middleware/zod-validation": [ 39 | "dist/middleware/zod-validation.d.ts" 40 | ] 41 | } 42 | }, 43 | "files": [ 44 | "dist" 45 | ], 46 | "scripts": { 47 | "build": "tsup", 48 | "dev": "tsup --watch", 49 | "lint": "eslint .", 50 | "prepublishOnly": "nr build", 51 | "start": "esno src/index.ts", 52 | "test": "vitest", 53 | "typecheck": "tsc --noEmit" 54 | }, 55 | "devDependencies": { 56 | "@antfu/ni": "^0.21.12", 57 | "@cloudflare/workers-types": "^4.20240502.0", 58 | "@ocavue/eslint-config": "^1.5.0", 59 | "@types/node": "^20.12.11", 60 | "eslint": "^9.2.0", 61 | "esno": "^4.7.0", 62 | "prettier": "^3.2.5", 63 | "tsup": "^8.0.2", 64 | "typescript": "^5.4.5", 65 | "urlpattern-polyfill": "^10.0.0", 66 | "vite": "^5.2.11", 67 | "vitest": "^1.6.0", 68 | "zod": "^3.23.8" 69 | }, 70 | "renovate": { 71 | "extends": [ 72 | "github>ocavue/config-renovate" 73 | ] 74 | }, 75 | "peerDependencies": { 76 | "zod": "^3.22.1" 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/cookie.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Parses a cookie string and returns an object containing the key-value pairs. 4 | * @param {string} cookieString - A string containing the cookies in the "key=value; key2=value2" format. 5 | * @returns {Record} - An object containing the key-value pairs of the cookies. 6 | * @example 7 | * const cookieString = "name=John; age=25; city=New York"; 8 | * parseCookie(cookieString) //=> { name: "John", age: "25", city: "New York" } 9 | **/ 10 | export function parseCookie(cookieString: string): Record { 11 | const cookies = cookieString.split(';') 12 | const result: Record = {} 13 | 14 | for (const cookie of cookies) { 15 | const [name, value] = cookie.split('=') 16 | result[name.trim()] = decodeURIComponent(value) 17 | } 18 | 19 | return result 20 | } 21 | 22 | interface StringifyOptions { 23 | value: string 24 | maxage: number 25 | expires: Date 26 | samesite: 'Lax' | 'Strict' | 'None' 27 | secure: boolean 28 | httponly: boolean 29 | domain: string 30 | path: string 31 | } 32 | 33 | /** 34 | * 35 | * Stringifies a cookie, including its name, value, and options. 36 | * @param {string} name - The name of the cookie. 37 | * @param {string} value - The value of the cookie. 38 | * @param {Partial} [options={}] - An object containing optional cookie attributes: 39 | * @param {string} options.value - The value of the cookie. 40 | * @param {number} options.maxage - The maximum age of the cookie (in seconds). 41 | * @param {Date} options.expires - The expiration date of the cookie. 42 | * @param {'Lax' | 'Strict' | 'None'} options.samesite - The SameSite attribute of the cookie. 43 | * @param {boolean} options.secure - Whether the cookie should be sent only over HTTPS. 44 | * @param {boolean} options.httponly - Whether the cookie should be HTTP-only. 45 | * @param {string} options.domain - The domain of the cookie. 46 | * @param {string} options.path - The path of the cookie. 47 | * @returns {string} The stringified cookie. 48 | * 49 | * @example 50 | * 51 | * stringifyCookie('name', 'John', { 52 | * maxage: 60 * 60 * 24 * 365, // 1 year 53 | * }) //=> "name=John; Max-Age=31536000" 54 | * 55 | **/ 56 | export function stringifyCookie( 57 | name: string, 58 | value: string, 59 | options: Partial = {} 60 | ): string { 61 | let str = name + '=' + encodeURIComponent(value) 62 | 63 | if (options.expires) { 64 | str += '; Expires=' + new Date(options.expires).toUTCString() 65 | } 66 | 67 | if (options.maxage != null && options.maxage >= 0) { 68 | str += '; Max-Age=' + (options.maxage | 0) 69 | } 70 | 71 | if (options.domain) { 72 | str += '; Domain=' + options.domain 73 | } 74 | 75 | if (options.path) { 76 | str += '; Path=' + options.path 77 | } 78 | 79 | if (options.samesite) { 80 | str += '; SameSite=' + options.samesite 81 | } 82 | 83 | if (options.secure || options.samesite === 'None') { 84 | str += '; Secure' 85 | } 86 | 87 | if (options.httponly) { 88 | str += '; HttpOnly' 89 | } 90 | 91 | return str 92 | } 93 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './cookie' 2 | export * from './request' 3 | export * from './response' 4 | export * from './router' 5 | export * from './types' 6 | export * from './middleware/zod-validation' 7 | -------------------------------------------------------------------------------- /src/middleware/zod-validation.test.ts: -------------------------------------------------------------------------------- 1 | import { describe, expect, it } from 'vitest' 2 | import { withZod } from './zod-validation' 3 | import { z } from 'zod' 4 | import { execRoute, buildRequest } from '../../test/helpers' 5 | 6 | describe('zod-validation', () => { 7 | type Env = { 8 | foo: string 9 | } 10 | 11 | const schema = z.object({ 12 | name: z.string(), 13 | }) 14 | 15 | type schemaType = z.infer 16 | 17 | it('should pass through json', async () => { 18 | const route = withZod(schema, async (options) => { 19 | expect(options.data).toEqual({ name: 'test' }) 20 | return new Response('ok') 21 | }) 22 | 23 | const response = await execRoute( 24 | route, 25 | buildRequest('https://example.com', { 26 | method: 'POST', 27 | headers: { 'content-type': 'application/json' }, 28 | body: JSON.stringify({ name: 'test' }), 29 | }) 30 | ) 31 | 32 | expect(response.status).toBe(200) 33 | }) 34 | 35 | it('should pass through query', async () => { 36 | const route = withZod(schema, async (options) => { 37 | expect(options.data).toEqual({ name: 'test' }) 38 | return new Response('ok') 39 | }) 40 | 41 | const response = await execRoute( 42 | route, 43 | buildRequest('https://example.com?name=test', { 44 | method: 'GET', 45 | }) 46 | ) 47 | 48 | expect(response.status).toBe(200) 49 | }) 50 | 51 | it('should pass through form parms', async () => { 52 | const route = withZod(schema, async (options) => { 53 | expect(options.data).toEqual({ name: 'test' }) 54 | return new Response('ok') 55 | }) 56 | 57 | const response = await execRoute( 58 | route, 59 | buildRequest('https://example.com?name=test', { 60 | method: 'POST', 61 | headers: { 'content-type': 'application/x-www-form-urlencoded' }, 62 | body: 'name=test', 63 | }) 64 | ) 65 | 66 | expect(response.status).toBe(200) 67 | }) 68 | 69 | it('should should a validation error', async () => { 70 | const route = withZod(schema, async (options) => { 71 | expect(options.data).toEqual({ bar: 'test' }) 72 | return new Response('ok') 73 | }) 74 | 75 | const response = await execRoute( 76 | route, 77 | buildRequest('https://example.com', { 78 | method: 'POST', 79 | headers: { 'content-type': 'application/json' }, 80 | body: JSON.stringify({ bar: 'test' }), 81 | }) 82 | ) 83 | 84 | expect(response.status).toBe(400) 85 | expect(await response.json()).toMatchInlineSnapshot(` 86 | { 87 | "error": { 88 | "message": "name required", 89 | "type": "invalid_type", 90 | }, 91 | } 92 | `) 93 | }) 94 | }) 95 | -------------------------------------------------------------------------------- /src/middleware/zod-validation.ts: -------------------------------------------------------------------------------- 1 | import z from 'zod' 2 | import { RouteOptions, ZodRouteHandler } from '../types' 3 | import { error } from '../response' 4 | 5 | /** 6 | * Creates a route handler that validates the request data and parameters using the Zod schema. 7 | * If validation fails, it returns a 400 json error with a detailed message. 8 | * 9 | * @param {z.Schema} schema - A Zod schema used to validate the incoming request data and parameters. 10 | * @param {ZodRouteHandler} callback - The main callback that will be executed after validation is successful. 11 | * 12 | * @return {ZodRouteHandler} 13 | * 14 | * @example 15 | * const schema = z.object({ 16 | * name: z.string(), 17 | * }) 18 | * 19 | * type schemaType = z.infer 20 | * 21 | * withZod(schema, async (options) => { 22 | * console.log(options.data) //=> { name: 'test' } 23 | * return new Response('ok') 24 | * }) 25 | * 26 | */ 27 | export function withZod( 28 | schema: z.Schema, 29 | callback: ZodRouteHandler 30 | ) { 31 | return async (options: RouteOptions) => { 32 | const { request } = options 33 | 34 | const queryParams = request.query 35 | const bodyParams = (await request.body()) ?? {} 36 | const existingParams = options.params ?? {} 37 | 38 | const params = { 39 | ...queryParams, 40 | ...bodyParams, 41 | ...existingParams, 42 | } 43 | 44 | const result = schema.safeParse(params) 45 | 46 | if (!result.success) { 47 | const firstError = result.error?.errors?.[0] 48 | 49 | if (firstError) { 50 | return error(`${firstError.path} ${firstError.message}`, { 51 | type: firstError.code, 52 | status: 400, 53 | }) 54 | } else { 55 | return error('invalid_request') 56 | } 57 | } 58 | 59 | return callback({ 60 | ...options, 61 | data: result.data, 62 | }) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/request.test.ts: -------------------------------------------------------------------------------- 1 | import { describe, it, expect } from 'vitest' 2 | import { BasicRequest } from './request' 3 | 4 | describe('request', () => { 5 | it('parses query params', () => { 6 | const request = new BasicRequest( 7 | new Request('https://example.com/test?foo=bar') 8 | ) 9 | 10 | expect(request.query).toEqual({ foo: 'bar' }) 11 | }) 12 | 13 | it('parses cookies', () => { 14 | const request = new BasicRequest( 15 | new Request('https://example.com/test', { 16 | headers: { 17 | cookie: 'foo=bar', 18 | }, 19 | }) 20 | ) 21 | 22 | expect(request.cookies).toEqual({ foo: 'bar' }) 23 | }) 24 | 25 | it('parses headers', () => { 26 | const request = new BasicRequest( 27 | new Request('https://example.com/test', { 28 | headers: { 29 | 'content-type': 'application/json', 30 | }, 31 | }) 32 | ) 33 | 34 | expect(request.headers.get('content-type')).toBe('application/json') 35 | }) 36 | 37 | it('parses origin', () => { 38 | const request = new BasicRequest( 39 | new Request('https://example.com/test', { 40 | headers: { 41 | 'content-type': 'application/json', 42 | }, 43 | }) 44 | ) 45 | 46 | expect(request.origin).toBe('https://example.com') 47 | }) 48 | 49 | it('parses json', async () => { 50 | const request = new BasicRequest( 51 | new Request('https://example.com/test', { 52 | method: 'POST', 53 | headers: { 54 | 'content-type': 'application/json', 55 | }, 56 | body: JSON.stringify({ foo: 'bar' }), 57 | }) 58 | ) 59 | 60 | expect(await request.body()).toEqual({ foo: 'bar' }) 61 | }) 62 | 63 | it('parses forms', async () => { 64 | const request = new BasicRequest( 65 | new Request('https://example.com/test', { 66 | method: 'POST', 67 | headers: { 68 | 'content-type': 'application/x-www-form-urlencoded', 69 | }, 70 | body: 'foo=bar', 71 | }) 72 | ) 73 | 74 | expect(await request.body()).toEqual({ foo: 'bar' }) 75 | }) 76 | }) 77 | -------------------------------------------------------------------------------- /src/request.ts: -------------------------------------------------------------------------------- 1 | import { parseCookie } from './cookie' 2 | import { RequestMethod, RequestMethodEnum } from './types' 3 | import { enumFromString } from './utils/enum' 4 | import { toObject } from './utils/to-object' 5 | 6 | export class BasicRequest { 7 | url: URL 8 | 9 | constructor(public request: Request) { 10 | this.url = new URL(request.url) 11 | } 12 | 13 | /** 14 | * Returns the request method as a lowercase string. 15 | */ 16 | get method(): RequestMethod { 17 | return enumFromString( 18 | RequestMethodEnum, 19 | this.request.method.toLowerCase() 20 | ) 21 | } 22 | 23 | /** 24 | * Returns the cookies sent by the client. 25 | */ 26 | get cookies(): Record { 27 | const cookieString = this.headers.get('cookie') 28 | 29 | if (!cookieString) { 30 | return {} 31 | } 32 | 33 | return parseCookie(cookieString) 34 | } 35 | 36 | /** 37 | * Returns the query parameters sent by the client. 38 | */ 39 | get query() { 40 | return toObject(this.url.searchParams) 41 | } 42 | 43 | get headers() { 44 | return this.request.headers 45 | } 46 | 47 | get origin() { 48 | return this.url.origin 49 | } 50 | 51 | /** 52 | * A helper to parse the request body. 53 | * @returns {Promise} The parsed request body as an object. 54 | */ 55 | async body(): Promise { 56 | const ct = this.contentType 57 | const rq = this.request 58 | 59 | if (!rq.body || !ct) { 60 | return 61 | } 62 | 63 | if (~ct.indexOf('application/json')) { 64 | return rq.json() as Promise 65 | } 66 | 67 | if (~ct.indexOf('multipart/form-data')) { 68 | return rq.formData().then(toObject) as Promise 69 | } 70 | 71 | if (~ct.indexOf('application/x-www-form-urlencoded')) { 72 | return rq.formData().then(toObject) as Promise 73 | } 74 | 75 | return 76 | } 77 | 78 | /** 79 | * Returns the content type of the request. 80 | */ 81 | get contentType() { 82 | return this.request.headers.get('content-type') 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/response.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Shorthand for creating a JSON response with an error message. 3 | * 4 | * @param message error message 5 | * @param options { 6 | * type: error type, defaults to 'invalid_request' 7 | * status: status code, defaults to 400 8 | * } 9 | * @returns Response 10 | */ 11 | 12 | export function error( 13 | message: string, 14 | { type = 'invalid_request', status = 400 } = {} 15 | ) { 16 | return json({ error: { message, type } }, status) 17 | } 18 | 19 | /** 20 | * A shortcut for creating a JSON response. 21 | * 22 | * @param data An object to be JSON stringified. 23 | * @param status optional status code, defaults to 200 24 | * @returns Response 25 | */ 26 | export function json(data: any, status = 200) { 27 | return new Response(JSON.stringify(data, null, 2), { 28 | status, 29 | headers: { 30 | 'content-type': 'application/json;charset=UTF-8', 31 | }, 32 | }) 33 | } 34 | -------------------------------------------------------------------------------- /src/router.test.ts: -------------------------------------------------------------------------------- 1 | import { describe, it, expect } from 'vitest' 2 | import { Router } from './router' 3 | 4 | import 'urlpattern-polyfill' 5 | 6 | describe('router', () => { 7 | type Env = { 8 | foo: string 9 | } 10 | 11 | it('handles routes', async () => { 12 | const router = new Router() 13 | 14 | router.register(async ({ request }) => { 15 | expect(request.url.href).toBe('https://example.com/test') 16 | return new Response('ok') 17 | }, '/test') 18 | 19 | const response = await router.handle( 20 | new Request('https://example.com/test'), 21 | { foo: 'bar' }, 22 | {} as any 23 | ) 24 | 25 | expect(response?.status).toBe(200) 26 | }) 27 | 28 | it('handles post routes', async () => { 29 | const router = new Router() 30 | 31 | router.post('/test', async ({ request }) => { 32 | expect(request.url.href).toBe('https://example.com/test') 33 | return new Response('ok') 34 | }) 35 | 36 | const response = await router.handle( 37 | new Request('https://example.com/test', { method: 'POST' }), 38 | { foo: 'bar' }, 39 | {} as any 40 | ) 41 | 42 | expect(response?.status).toBe(200) 43 | }) 44 | }) 45 | -------------------------------------------------------------------------------- /src/router.ts: -------------------------------------------------------------------------------- 1 | import { BasicRequest } from './request' 2 | import { RequestMethod, Route, RouteHandler } from './types' 3 | 4 | export class Router { 5 | routes: Route[] = [] 6 | 7 | /** 8 | * Handles a request by matching it against the registered routes. 9 | * @param request Request 10 | * @param env Environment 11 | * @param ctx Context (for Workers) 12 | * @returns Response 13 | **/ 14 | handle(rawRequest: Request, env: Env, ctx: ExecutionContext) { 15 | const request = new BasicRequest(rawRequest) 16 | 17 | for (const route of this.routes) { 18 | const match = route[0](request) 19 | 20 | if (match) { 21 | return route[1]({ request, env, ctx, params: match.params }) 22 | } 23 | } 24 | 25 | const match = this.routes.find(([matcher]) => matcher(request)) 26 | 27 | if (match) { 28 | return match[1]({ request, env, ctx }) 29 | } 30 | } 31 | 32 | /** 33 | * Registers a new route. 34 | * @param handler RouteHandler 35 | * @param path Path to match 36 | * @param method HTTP method to match 37 | * 38 | * @example 39 | * const router = new Router() 40 | * 41 | * router.register(async ({ request }) => { 42 | * return new Response('ok') 43 | * }, '/test') 44 | */ 45 | register(handler: RouteHandler, path: string, method?: RequestMethod) { 46 | const urlPattern = new URLPattern({ pathname: path }) 47 | 48 | this.routes.push([ 49 | (request) => { 50 | if (!method || request.method === method) { 51 | const match = urlPattern.exec({ 52 | pathname: request.url.pathname, 53 | }) 54 | 55 | if (match) { 56 | return { params: match.pathname.groups } 57 | } 58 | } 59 | }, 60 | 61 | handler, 62 | ]) 63 | } 64 | 65 | options(path: string, handler: RouteHandler) { 66 | this.register(handler, path, 'options') 67 | } 68 | 69 | head(path: string, handler: RouteHandler) { 70 | this.register(handler, path, 'head') 71 | } 72 | 73 | /** 74 | * Register a new GET route. 75 | * @param path 76 | * @param handler 77 | * 78 | * @example 79 | * const router = new Router() 80 | * 81 | * router.get('/test', async ({ request }) => { 82 | * return new Response('ok') 83 | * }) 84 | */ 85 | get(path: string, handler: RouteHandler) { 86 | this.register(handler, path, 'get') 87 | } 88 | 89 | post(path: string, handler: RouteHandler) { 90 | this.register(handler, path, 'post') 91 | } 92 | 93 | put(path: string, handler: RouteHandler) { 94 | this.register(handler, path, 'put') 95 | } 96 | 97 | patch(path: string, handler: RouteHandler) { 98 | this.register(handler, path, 'patch') 99 | } 100 | 101 | delete(path: string, handler: RouteHandler) { 102 | this.register(handler, path, 'delete') 103 | } 104 | 105 | /** 106 | * Registers a new route for all HTTP methods. 107 | * @param path 108 | * @param handler 109 | */ 110 | all(path: string, handler: RouteHandler) { 111 | this.register(handler, path) 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /src/types.ts: -------------------------------------------------------------------------------- 1 | import { BasicRequest } from './request' 2 | 3 | export type RouteMatcher = ( 4 | request: BasicRequest 5 | ) => { params: Record } | undefined 6 | 7 | export type RouteOptions = { 8 | request: BasicRequest 9 | env: Env 10 | ctx: ExecutionContext 11 | params?: Record 12 | } 13 | 14 | export type RouteHandler = ( 15 | options: RouteOptions 16 | ) => Promise 17 | 18 | export type ZodRouteHandler = ( 19 | options: RouteOptions & { data: Schema } 20 | ) => Promise 21 | 22 | export type Route = [RouteMatcher, RouteHandler] 23 | 24 | export enum RequestMethodEnum { 25 | options = 'options', 26 | head = 'head', 27 | get = 'get', 28 | post = 'post', 29 | put = 'put', 30 | delete = 'delete', 31 | patch = 'patch', 32 | } 33 | 34 | export type RequestMethod = keyof typeof RequestMethodEnum 35 | -------------------------------------------------------------------------------- /src/utils/enum.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Converts string to enum. Returns undefined if enum doesn't contain the value. 3 | * 4 | */ 5 | export function enumFromString( 6 | enm: { [s: string]: T }, 7 | value: string | undefined | null 8 | ): T { 9 | if (!value) { 10 | throw new Error('Value is undefined or null') 11 | } 12 | 13 | const validValues = Object.values(enm) as unknown as string[] 14 | const isValid = validValues.includes(value) 15 | 16 | if (isValid) { 17 | return value as unknown as T 18 | } else { 19 | throw new Error(`Invalid value: ${value}`) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/utils/to-object.ts: -------------------------------------------------------------------------------- 1 | // Taken from https://github.com/lukeed/worktop/tree/master 2 | // MIT License Luke Edwards (lukeed.com) 3 | 4 | type Arrayable = T | Array 5 | type DataObject = Record> 6 | 7 | export function toObject( 8 | iter: Headers | FormData | URLSearchParams 9 | ): DataObject { 10 | let key, val, tmp: Arrayable 11 | const out: DataObject = {} 12 | 13 | for ([key, val] of iter) { 14 | out[key] = 15 | (tmp = out[key]) !== void 0 16 | ? ([] as FormDataEntryValue[]).concat(tmp, val) 17 | : val 18 | } 19 | 20 | return out 21 | } 22 | -------------------------------------------------------------------------------- /test/helpers.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-empty-function */ 2 | import { BasicRequest } from '../src/request' 3 | 4 | export function buildRequest(url: string, options: RequestInit) { 5 | return new BasicRequest(new Request(url, options)) 6 | } 7 | export function execRoute( 8 | route: (arg0: { 9 | request: BasicRequest 10 | env: Env 11 | ctx: ExecutionContext 12 | }) => Promise, 13 | request: BasicRequest 14 | ) { 15 | return route({ 16 | request, 17 | env: {} as Env, 18 | ctx: { 19 | waitUntil: () => {}, 20 | passThroughOnException: () => {}, 21 | }, 22 | }) 23 | } 24 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2021", 4 | "module": "es2022", 5 | "lib": ["es2021", "dom", "dom.iterable"], 6 | "moduleResolution": "node", 7 | "esModuleInterop": true, 8 | "strict": true, 9 | "strictNullChecks": true, 10 | "resolveJsonModule": true, 11 | "skipLibCheck": true, 12 | "skipDefaultLibCheck": true, 13 | "types": ["@cloudflare/workers-types"], 14 | "outDir": "./dist" 15 | }, 16 | "exclude": ["example", "node_modules", "dist"], 17 | "include": ["src/**/*"] 18 | } 19 | -------------------------------------------------------------------------------- /tsup.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'tsup' 2 | 3 | export default defineConfig({ 4 | entry: ['src/index.ts', 'src/middleware/zod-validation.ts'], 5 | format: ['esm', 'cjs'], 6 | clean: true, 7 | dts: true, 8 | }) 9 | --------------------------------------------------------------------------------