From 81114acb95b3659e849e53196570f87afef3735d Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Fri, 3 Mar 2023 12:07:47 +0000 Subject: [PATCH] add types-check frontend script add a types check that runs tsc making sure that all typings present in the frontend application are valid --- .github/workflows/PRs.yml | 3 +++ backend/src/activitypub/objects/index.ts | 3 ++- backend/src/database/neon.ts | 2 +- backend/src/utils/httpsigjs/parser.ts | 3 ++- backend/src/utils/sentry.ts | 3 ++- backend/src/webpush/util.ts | 4 ++-- frontend/adaptors/cloudflare-pages/vite.config.ts | 4 ++-- frontend/package.json | 2 ++ functions/api/v1/accounts/update_credentials.ts | 4 ++-- functions/first-login.ts | 4 ++-- package.json | 8 ++++---- 11 files changed, 24 insertions(+), 16 deletions(-) diff --git a/.github/workflows/PRs.yml b/.github/workflows/PRs.yml index 2ebf305..807b7b4 100644 --- a/.github/workflows/PRs.yml +++ b/.github/workflows/PRs.yml @@ -53,6 +53,9 @@ jobs: - name: Check frontend linting run: yarn lint:frontend + - name: Check frontend types + run: yarn --cwd types-check + test-ui: runs-on: ubuntu-latest steps: diff --git a/backend/src/activitypub/objects/index.ts b/backend/src/activitypub/objects/index.ts index 9a1be6c..7d1d0cd 100644 --- a/backend/src/activitypub/objects/index.ts +++ b/backend/src/activitypub/objects/index.ts @@ -270,7 +270,8 @@ function getContentRewriter() { contentRewriter.on('*', { element(el) { if (!['p', 'span', 'br', 'a'].includes(el.tagName)) { - el.tagName = 'p' + const element = el as { tagName: string } + element.tagName = 'p' } if (el.hasAttribute('class')) { diff --git a/backend/src/database/neon.ts b/backend/src/database/neon.ts index 235ded5..6e7e715 100644 --- a/backend/src/database/neon.ts +++ b/backend/src/database/neon.ts @@ -4,7 +4,7 @@ import type { Env } from 'wildebeest/backend/src/types/env' function sqliteToPsql(query: string): string { let c = 0 - return query.replaceAll(/\?([0-9])?/g, (match: string, p1: string) => { + return query.replace(/\?([0-9])?/g, (match: string, p1: string) => { c += 1 return `$${p1 || c}` }) diff --git a/backend/src/utils/httpsigjs/parser.ts b/backend/src/utils/httpsigjs/parser.ts index fa39d2b..cc0a8cd 100644 --- a/backend/src/utils/httpsigjs/parser.ts +++ b/backend/src/utils/httpsigjs/parser.ts @@ -281,11 +281,12 @@ export function parseRequest(request: Request, options?: Options): ParsedSignatu if (h === 'request-line') { if (!options.strict) { + const cf = (request as { cf?: IncomingRequestCfProperties }).cf /* * We allow headers from the older spec drafts if strict parsing isn't * specified in options. */ - parsed.signingString += request.method + ' ' + request.url + ' ' + request.cf?.httpProtocol + parsed.signingString += request.method + ' ' + request.url + ' ' + cf?.httpProtocol } else { /* Strict parsing doesn't allow older draft headers. */ throw new StrictParsingError('request-line is not a valid header ' + 'with strict parsing enabled.') diff --git a/backend/src/utils/sentry.ts b/backend/src/utils/sentry.ts index ff69e4b..019eabd 100644 --- a/backend/src/utils/sentry.ts +++ b/backend/src/utils/sentry.ts @@ -19,7 +19,8 @@ export function initSentry(request: Request, env: Env, context: any) { request, transportOptions: { headers }, }) - const colo = request.cf && request.cf.colo ? request.cf.colo : 'UNKNOWN' + const cf = (request as { cf?: IncomingRequestCfProperties }).cf + const colo = cf?.colo ? cf.colo : 'UNKNOWN' sentry.setTag('colo', colo) // cf-connecting-ip should always be present, but if not we can fallback to XFF. diff --git a/backend/src/webpush/util.ts b/backend/src/webpush/util.ts index 25378af..cc38599 100644 --- a/backend/src/webpush/util.ts +++ b/backend/src/webpush/util.ts @@ -26,12 +26,12 @@ export function arrayBufferToBase64(buffer: ArrayBuffer): string { } export function b64ToUrlEncoded(str: string): string { - return str.replaceAll(/\+/g, '-').replaceAll(/\//g, '_').replace(/=+/g, '') + return str.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+/g, '') } export function urlEncodedToB64(str: string): string { const padding = '='.repeat((4 - (str.length % 4)) % 4) - return str.replaceAll(/-/g, '+').replaceAll(/_/g, '/') + padding + return str.replace(/-/g, '+').replace(/_/g, '/') + padding } export function stringToU8Array(str: string): Uint8Array { diff --git a/frontend/adaptors/cloudflare-pages/vite.config.ts b/frontend/adaptors/cloudflare-pages/vite.config.ts index 34baa4b..af2dd5a 100644 --- a/frontend/adaptors/cloudflare-pages/vite.config.ts +++ b/frontend/adaptors/cloudflare-pages/vite.config.ts @@ -1,4 +1,4 @@ -import { cloudflarePagesAdaptor } from '@builder.io/qwik-city/adaptors/cloudflare-pages/vite' +import { cloudflarePagesAdapter } from '@builder.io/qwik-city/adapters/cloudflare-pages/vite' import { extendConfig } from '@builder.io/qwik-city/vite' import baseConfig from '../../vite.config' @@ -11,7 +11,7 @@ export default extendConfig(baseConfig, () => { }, }, plugins: [ - cloudflarePagesAdaptor({ + cloudflarePagesAdapter({ // Do not SSG as the D1 database is not available at build time, I think. // staticGenerate: true, }), diff --git a/frontend/package.json b/frontend/package.json index 48d8ceb..5e4c646 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -7,6 +7,8 @@ }, "private": true, "scripts": { + "pretypes-check": "yarn build", + "types-check": "tsc", "lint": "eslint src mock-db adaptors", "build": "vite build && vite build -c adaptors/cloudflare-pages/vite.config.ts", "dev": "vite --mode ssr", diff --git a/functions/api/v1/accounts/update_credentials.ts b/functions/api/v1/accounts/update_credentials.ts index e015c97..da30c11 100644 --- a/functions/api/v1/accounts/update_credentials.ts +++ b/functions/api/v1/accounts/update_credentials.ts @@ -59,12 +59,12 @@ export async function handleRequest( if (formData.has('display_name')) { const value = formData.get('display_name')! - await updateActorProperty(db, connectedActor.id, 'name', value) + await updateActorProperty(db, connectedActor.id, 'name', value as string) } if (formData.has('note')) { const value = formData.get('note')! - await updateActorProperty(db, connectedActor.id, 'summary', value) + await updateActorProperty(db, connectedActor.id, 'summary', value as string) } if (formData.has('avatar')) { diff --git a/functions/first-login.ts b/functions/first-login.ts index abccf82..1a9c9e2 100644 --- a/functions/first-login.ts +++ b/functions/first-login.ts @@ -42,11 +42,11 @@ export async function handlePostRequest( const properties: Record = {} if (formData.has('username')) { - properties.preferredUsername = formData.get('username') || '' + properties.preferredUsername = (formData.get('username') as string) || '' } if (formData.has('name')) { - properties.name = formData.get('name') || '' + properties.name = (formData.get('name') as string) || '' } await createPerson(domain, db, userKEK, email, properties) diff --git a/package.json b/package.json index 136d527..2d2bab7 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "http-message-signatures": "^0.1.2", "toucan-js": "^3.1.0" }, - "simple-git-hooks": { - "pre-commit": "yarn lint" - } -} \ No newline at end of file + "simple-git-hooks": { + "pre-commit": "yarn lint" + } +}