Download chakra-ui/packages/cli/src/utils/fetch.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 949 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/f5071caa249115f3b590492f1c8eb471e02aae4b/chakra-ui/packages/cli/src/utils/fetch.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@f5071caa249115f3b590492f1c8eb471e02aae4b/chakra-ui/packages/cli/src/utils/fetch.ts
-
curl -L -o fetch.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/f5071caa249115f3b590492f1c8eb471e02aae4b/chakra-ui/packages/cli/src/utils/fetch.ts
949 Bytes
| import { HttpsProxyAgent } from "https-proxy-agent" | |
| import fetch from "node-fetch" | |
| import { | |
| compositionFileSchema, | |
| compositionIndexSchema, | |
| processEnvSchema, | |
| } from "./schema" | |
| const env = processEnvSchema.parse(process.env) | |
| const agent = env.HTTPS_PROXY ? new HttpsProxyAgent(env.HTTPS_PROXY) : undefined | |
| export async function fetchCompositions() { | |
| const res = await fetch(`${env.REGISTRY_URL}/compositions/index.json`, { | |
| agent, | |
| }) | |
| const json = await res.json() | |
| return compositionIndexSchema.parse(json) | |
| } | |
| export async function fetchComposition(id: string) { | |
| try { | |
| const res = await fetch(`${env.REGISTRY_URL}/compositions/${id}.json`, { | |
| agent, | |
| }) | |
| const json = await res.json() | |
| return compositionFileSchema.parse(json) | |
| } catch (error) { | |
| throw new Error( | |
| `Failed to fetch snippet "${id}". Make sure the id is correct or run @chakra-ui/cli snippet list to see available snippets.`, | |
| ) | |
| } | |
| } | |