diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..ad566aa --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,8 @@ +{ + "recommendations": ["biomejs.biome", "mikestead.dotenv", "EditorConfig.EditorConfig"], + "unwantedRecommendations": [ + // we use Biome for linting and formatting so we don't need these + "dbaeumer.vscode-eslint", + "esbenp.prettier-vscode" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json index 872e73d..46c8a7e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,24 @@ { "typescript.tsdk": "node_modules/typescript/lib", "typescript.enablePromptUseWorkspaceTsdk": true, - "typescript.preferences.importModuleSpecifier": "non-relative" + "typescript.preferences.importModuleSpecifier": "non-relative", + "editor.formatOnSave": true, + "editor.codeActionsOnSave": { + "quickfix.biome": true, + "source.fixAll.biome": true, + "source.organizeImports.biome": true + }, + "editor.defaultFormatter": "biomejs.biome", + "[json]": { + "editor.defaultFormatter": "biomejs.biome" + }, + "[jsonc]": { + "editor.defaultFormatter": "biomejs.biome" + }, + "[typescript]": { + "editor.defaultFormatter": "biomejs.biome" + }, + "[javascript]": { + "editor.defaultFormatter": "biomejs.biome" + } } diff --git a/biome.json b/biome.json new file mode 100644 index 0000000..1e83161 --- /dev/null +++ b/biome.json @@ -0,0 +1,91 @@ +{ + "$schema": "https://biomejs.dev/schemas/1.3.3/schema.json", + "vcs": { + "root": ".", + "enabled": true, + "clientKind": "git" + }, + "files": { + "include": [ + "./**/*.ts", + "./**/*.js", + "./**/*.cjs", + "./**/*.d.ts", + "./**/*.json", + "./**/*.jsonc" + ], + "ignoreUnknown": true, + "ignore": ["node_modules", ".lagon", "_"] + }, + "organizeImports": { + "enabled": false + }, + "formatter": { + "enabled": true, + "lineWidth": 100, + "indentWidth": 2, + "indentStyle": "space", + "formatWithErrors": true, + "include": [ + "./**/*.ts", + "./**/*.js", + "./**/*.cjs", + "./**/*.d.ts", + "./**/*.json", + "./**/*.jsonc" + ] + }, + "linter": { + "enabled": true, + "rules": { + "all": true, + "style": { + "useBlockStatements": "off", + "useSelfClosingElements": "off", + "noUnusedTemplateLiteral": "off" + }, + "nursery": { + "all": true, + "noUnusedImports": "off" + }, + "complexity": { + "useLiteralKeys": "off" + }, + "correctness": { + "noUndeclaredVariables": "off" + }, + "suspicious": { + "noRedeclare": "off", + "noExplicitAny": "off", + "noEmptyInterface": "off" + } + } + }, + "json": { + "parser": { + "allowComments": true + }, + "formatter": { + "enabled": true, + "lineWidth": 100, + "indentWidth": 2 + } + }, + "javascript": { + "parser": { + "unsafeParameterDecoratorsEnabled": true + }, + "formatter": { + "enabled": true, + "lineWidth": 100, + "indentWidth": 2, + "indentStyle": "space", + "quoteStyle": "single", + "trailingComma": "none", + "semicolons": "asNeeded", + "jsxQuoteStyle": "single", + "quoteProperties": "asNeeded", + "arrowParentheses": "asNeeded" + } + } +} diff --git a/bun.lockb b/bun.lockb index 3bdda04..02dc3af 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 20da282..4c237ef 100644 --- a/package.json +++ b/package.json @@ -9,12 +9,16 @@ "dev": "lagon dev --env='.env.dev'", "build": "lagon build", "deploy:preview": "lagon deploy", - "deploy": "lagon deploy --production" + "deploy": "lagon deploy --production", + "lint": "biome check --apply .", + "format": "biome format . --write", + "typecheck": "tsc --project tsconfig.json --noEmit" }, "dependencies": { "graphql": "^16.8.1" }, "devDependencies": { + "@biomejs/biome": "^1.3.3", "bun-types": "^1.0.13", "typescript": "^5.2.2" }, diff --git a/src/graphql/schema.ts b/src/graphql/schema.ts index 0b8efda..f7a4cc2 100644 --- a/src/graphql/schema.ts +++ b/src/graphql/schema.ts @@ -2,7 +2,7 @@ import { printSchema, buildClientSchema, getIntrospectionQuery, - type IntrospectionOptions, + type IntrospectionOptions } from 'graphql' import type { Json } from '#/types.ts' @@ -14,7 +14,7 @@ export function jsonSchemaToSDL(jsonString: string) { export async function fetchJsonSchema({ url, - minimal = true, + minimal = true }: { url: string minimal?: boolean @@ -22,7 +22,7 @@ export async function fetchJsonSchema({ const introspectionOptions = { descriptions: !minimal, directiveIsRepeatable: !minimal, - schemaDescription: !minimal, + schemaDescription: !minimal } satisfies IntrospectionOptions try { const response = await fetch(url, { @@ -30,8 +30,8 @@ export async function fetchJsonSchema({ headers: { 'Content-Type': 'application/json', Accept: 'application/json' }, body: JSON.stringify({ query: getIntrospectionQuery(introspectionOptions), - variable: {}, - }), + variable: {} + }) }) if (!response.ok) throw new Error(`Failed to fetch from ${url}: ${response.statusText}`) diff --git a/src/index.ts b/src/index.ts index 959187e..426253c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -31,7 +31,7 @@ export async function handler(request: Request): Promise { const { htmlPage } = await import('#/graphql/graphiql.html.ts') return new Response(htmlPage({ endpoint: introspectionURL }), { status: 200, - headers: { 'Content-Type': 'text/html' }, + headers: { 'Content-Type': 'text/html' } }) } @@ -42,13 +42,13 @@ export async function handler(request: Request): Promise { return new Response(sdlSchema, { status: sdlSchema.startsWith('Encountered an error') ? 400 : 200, - headers: { 'Content-Type': 'text/plain' }, + headers: { 'Content-Type': 'text/plain' } }) } return new Response(JSON.stringify(jsonSchema), { status: 200, - headers: { 'Content-Type': 'application/json' }, + headers: { 'Content-Type': 'application/json' } }) } catch (error) { const message = error instanceof Error ? error.message : `Encountered an error: ${error}` diff --git a/src/utilities.ts b/src/utilities.ts index 20b1e7b..808250f 100644 --- a/src/utilities.ts +++ b/src/utilities.ts @@ -2,7 +2,7 @@ export const BASE_URL = process.env.BASE_URL ?? 'https://introspect.lagon.dev' export const EXAMPLE_GRAPHQL_URL = 'https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v3' -export const LANDING_MESSAGE = /* md */` +export const LANDING_MESSAGE = /* md */ ` If you want a JSON GraphQL schema, the format is: ${BASE_URL}/json/ @@ -20,11 +20,7 @@ Source code: https://github.com/o-az/introspect ` export function isURL(str: string) { - try { - return !!new URL(str) - } catch { - return false - } + return !!new URL(str) } export function formatMessages(...messages: string[]) {