Sorry, we couldn't find this page.
17 |18 | But dont worry, you can find some useful things on our homepage. 19 |
20 | Back to homepage 21 |Not affiliated with Cloudflare.
37 | ` 38 | } 39 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 onWidget 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 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@danifoldi/workers-types-site", 3 | "description": "A searchable site for type definitions of Cloudflare Workers", 4 | "version": "1.0.0", 5 | "private": true, 6 | "scripts": { 7 | "dev": "astro dev", 8 | "start": "astro dev", 9 | "build": "astro build", 10 | "preview": "astro preview", 11 | "astro": "astro", 12 | "lint": "eslint .", 13 | "generate": "node ./src/generate.mjs" 14 | }, 15 | "type": "module", 16 | "devDependencies": { 17 | "@astrojs/check": "^0.9.4", 18 | "@astrojs/mdx": "^3.1.9", 19 | "@astrojs/tailwind": "^5.1.5", 20 | "@fontsource/source-code-pro": "^5.2.5", 21 | "@iconify-json/simple-icons": "^1.2.30", 22 | "@iconify-json/tabler": "^1.2.17", 23 | "@tailwindcss/forms": "^0.5.9", 24 | "@tailwindcss/typography": "^0.5.15", 25 | "@types/tar": "^6.1.13", 26 | "astro": "^4.16.7", 27 | "astro-icon": "^1.1.5", 28 | "bundled-eslint-config": "^0.4.25", 29 | "eslint": "^9.24.0", 30 | "knip": "^5.47.0", 31 | "simple-knip-config": "^0.2.4", 32 | "tailwindcss": "^3.4.17", 33 | "tar": "^7.4.3", 34 | "typescript": "^5.8.3" 35 | }, 36 | "packageManager": "pnpm@9.15.6" 37 | } 38 | -------------------------------------------------------------------------------- /public/favicon.svg: -------------------------------------------------------------------------------- 1 | 12 | -------------------------------------------------------------------------------- /src/generate.mjs: -------------------------------------------------------------------------------- 1 | import { createWriteStream } from 'node:fs' 2 | import { mkdir, stat } from 'node:fs/promises' 3 | import { Readable } from 'node:stream' 4 | import { finished } from 'node:stream/promises' 5 | import { x } from 'tar' 6 | 7 | 8 | const data = await fetch('https://registry.npmjs.org/@cloudflare/workers-types', { 9 | headers: { 10 | 'Accept': 'application/vnd.npm.install-v1+json' 11 | } 12 | }).then(response => response.json()) 13 | 14 | // Lazy semver validation warning 15 | const supportedVersions = Object.keys(data.versions).filter(version => version.startsWith('4.')) 16 | 17 | await mkdir('src/tarballs', { recursive: true }) 18 | 19 | await Promise.allSettled(supportedVersions.map(async version => { 20 | if (!await stat(`src/tarballs/${version}.tgz`).catch(() => {})) { 21 | // noinspection JSDeprecatedSymbols, JSUnresolvedReference 22 | const tarball = await fetch(data.versions[version].dist.tarball) 23 | 24 | const download = Readable 25 | .fromWeb(tarball.body) 26 | .pipe(createWriteStream(`src/tarballs/${version}.tgz`, { flags: 'wx' }).on('error', console.error.bind(console))) 27 | await finished(download) 28 | } 29 | 30 | await mkdir(`src/workers-types/${version}`, { recursive: true }) 31 | await x({ 32 | file: `src/tarballs/${version}.tgz`, 33 | C: `src/workers-types/${version}` 34 | }) 35 | })) 36 | -------------------------------------------------------------------------------- /src/config.mjs: -------------------------------------------------------------------------------- 1 | import defaultImage from './assets/images/default.png' 2 | 3 | 4 | const CONFIG = { 5 | name: 'Workers-Types - TypeScript types for Cloudflare Workers', 6 | 7 | origin: 'https://workers-types.pages.dev', 8 | basePathname: '/', 9 | trailingSlash: false, 10 | 11 | title: 'Workers-Types - TypeScript types for Cloudflare Workers', 12 | description: 13 | 'Find type definitions for Cloudflare Workers, bindings, APIs, and more.', 14 | defaultImage: defaultImage, 15 | 16 | defaultTheme: 'system', // Values: "system" | "light" | "dark" | "light:only" | "dark:only" 17 | 18 | language: 'en', 19 | textDirection: 'ltr', 20 | 21 | dateFormatter: new Intl.DateTimeFormat('en', { 22 | year: 'numeric', 23 | month: 'short', 24 | day: 'numeric', 25 | timeZone: 'UTC' 26 | }), 27 | 28 | googleAnalyticsId: false, // or "G-XXXXXXXXXX", 29 | googleSiteVerificationId: '', 30 | 31 | blog: { 32 | disabled: true, 33 | postsPerPage: 4, 34 | 35 | post: { 36 | permalink: '/%slug%', // Variables: %slug%, %year%, %month%, %day%, %hour%, %minute%, %second%, %category% 37 | noindex: false, 38 | disabled: false 39 | }, 40 | 41 | list: { 42 | pathname: 'blog', // Blog main path, you can change this to "articles" (/articles) 43 | noindex: false, 44 | disabled: false 45 | }, 46 | 47 | category: { 48 | pathname: 'category', // Category main path /category/some-category 49 | noindex: true, 50 | disabled: false 51 | }, 52 | 53 | tag: { 54 | pathname: 'tag', // Tag main path /tag/some-tag 55 | noindex: true, 56 | disabled: false 57 | } 58 | } 59 | } 60 | 61 | export const SITE = { ...CONFIG, blog: undefined } 62 | export const BLOG = CONFIG.blog 63 | export const DATE_FORMATTER = CONFIG.dateFormatter 64 | -------------------------------------------------------------------------------- /src/pages/usage.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | layout: src/layouts/CodeLayout.astro 3 | --- 4 | 5 | 6 | ```sh 7 | npm i -D wrangler @cloudflare/workers-types 8 | npx wrangler types 9 | ``` 10 | 11 | ### wrangler.toml 12 | 13 | ```toml 14 | name = 'my-worker' 15 | main = 'src/index.ts' 16 | account_id = '1234' 17 | compatibility_date = '2023-07-01' 18 | compatibility_flags = [ 'nodejs_compat', 'web_socket_compression' ] 19 | workers_dev = false 20 | # logpush = true 21 | 22 | routes = [ 23 | { pattern = 'www.example.com/*', zone_name = 'example.com' }, 24 | { pattern = 'example.com/*', zone_name = 'example.com' } 25 | ] 26 | 27 | # bindings 28 | 29 | # [[migrations]] 30 | # tag = '' 31 | # new_classes = [] 32 | # renamed_classes = [{from = '', to = '' }] 33 | # deleted_classes = [] 34 | ``` 35 | 36 | ### tsconfig.json 37 | 38 | ```json 39 | { 40 | "compilerOptions": { 41 | "alwaysStrict": true, 42 | "baseUrl": "./", 43 | "esModuleInterop": true, 44 | "lib": [ "esnext" ], 45 | "module": "esnext", 46 | "moduleResolution": "node", 47 | "noEmit": true, 48 | "outDir": "./dist", 49 | "preserveConstEnums": true, 50 | "skipLibCheck": true, 51 | "strict": true, 52 | "target": "esnext", 53 | "types": [ "@cloudflare/workers-types/2022-11-30" ] 54 | }, 55 | "include": [ 56 | "src/**/*", 57 | "worker-configuration.d.ts" 58 | ] 59 | } 60 | ``` 61 | 62 | ### src/index.ts 63 | 64 | ```ts 65 | 66 | export default{
340 | tokens.map(token => {
341 | switch (token.type) {
342 | case 'comment':
343 | if ((token.value.includes('\n') || token.value.length > 90) && (token.value.startsWith('/**') || token.value.startsWith('/*!'))) {
344 | const summary = token.value.replace(/^\/*[ !*]+/, '').trimStart().split('\n')[0]
345 |
346 | return {summary}
{token.value}
347 | }
348 |
349 | return {token.value}
350 | case 'string':
351 | return {token.value}
352 | case 'whitespace':
353 | return {token.value}
354 | case 'punctuation':
355 | return {token.value}
356 | case 'keyword':
357 | return {token.value}
358 | case 'identifier':
359 | if (token.defining) {
360 | return {token.value}
361 | }
362 |
363 | const type = isDefined('id' in token ? token.id as string : '')
364 | if (type) {
365 | return {token.value}
366 | }
367 |
368 | return {token.value}
369 |
370 |
371 | case 'argument':
372 | return {token.value}
373 | case 'number':
374 | return {token.value}
375 | case 'type':
376 | return {token.value}
377 | case 'method':
378 | if (token.defining) {
379 | return {token.value}
380 | } else {
381 | const type = isDefined('id' in token ? token.id as string : '')
382 | if (type) {
383 | return {token.value}
384 | }
385 |
386 | return {token.value}
387 |
388 | }
389 |
390 | case 'type_identifier':
391 | if (token.defining) {
392 | return {token.value}
393 | } else {
394 | const type = isDefined('id' in token ? token.id as string : '')
395 | if (type) {
396 | return {token.value}
397 | }
398 |
399 | return {token.value}
400 |
401 | }
402 |
403 | default:
404 | return {token.value}
405 | }
406 | })
407 | }
408 |