From 3e91597dca06250eaceecc6e9b71e8e66def370b Mon Sep 17 00:00:00 2001 From: Avior Date: Mon, 9 Sep 2024 14:27:46 +0200 Subject: [PATCH] feat: multiple changes Signed-off-by: Avior --- .github/workflows/lint.yml | 2 +- astro.config.mjs => astro.config.ts | 12 +- biome.json | 10 +- e2e/example.spec.ts | 4 +- hooks/routing.ts | 9 +- playwright.config.ts | 35 +++-- src/components/global/Button.astro | 7 +- src/components/global/Picture.astro | 35 +++-- src/components/global/Range.astro | 1 - src/components/global/Select.astro | 2 +- src/components/global/Table/TableUtil.ts | 4 +- src/components/layouts/Favicon/Favicon.astro | 3 +- src/components/layouts/Favicon/Manifest.ts | 36 ----- src/components/layouts/Footer.astro | 4 +- src/components/layouts/Header.astro | 6 +- src/content/_config.ts | 34 ++--- src/env.d.ts | 6 +- src/layouts/Head.astro | 15 +- src/layouts/MainLayout.astro | 2 +- src/libs/Component.ts | 4 +- src/libs/HTTP/StatusCode.ts | 3 +- src/libs/RFCs/RFC7807.ts | 136 ++++++++++--------- src/libs/ResponseBuilder.ts | 1 - src/middleware/index.ts | 2 +- src/middleware/logger.ts | 19 ++- src/models/Dao.ts | 15 +- src/models/DaoFactory.ts | 6 +- src/pages/404.astro | 4 +- tailwind.config.cjs | 6 +- tests/basic.test.ts | 8 +- vitest.config.ts | 8 +- 31 files changed, 216 insertions(+), 223 deletions(-) rename astro.config.mjs => astro.config.ts (91%) delete mode 100644 src/components/layouts/Favicon/Manifest.ts diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 7aea722..98a6d6d 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -19,7 +19,7 @@ jobs: run: npm ci - name: Run BiomeJS - run: npm run lint + run: npx biome ci . # - uses: mongolyy/reviewdog-action-biome@v1 # with: # github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/astro.config.mjs b/astro.config.ts similarity index 91% rename from astro.config.mjs rename to astro.config.ts index db7cbf2..9171c5d 100644 --- a/astro.config.mjs +++ b/astro.config.ts @@ -1,6 +1,6 @@ +import node from '@astrojs/node' +import tailwind from '@astrojs/tailwind' import { defineConfig } from 'astro/config' -import tailwind from "@astrojs/tailwind" -import node from "@astrojs/node" import routing from './hooks/routing' // const faviconHook = { @@ -18,7 +18,7 @@ import routing from './hooks/routing' export default defineConfig({ // Use the NodeJS adapter adapter: node({ - mode: "standalone" + mode: 'standalone' }), // some settings to the build output @@ -66,7 +66,5 @@ export default defineConfig({ usePolling: !!(process.env.USE_POLLING ?? process.env.WSL_DISTRO_NAME) } } - }, - - - }) + } +}) diff --git a/biome.json b/biome.json index 39e53e9..37e8f1d 100644 --- a/biome.json +++ b/biome.json @@ -24,7 +24,8 @@ "noStaticOnlyClass": "warn", "noUselessTypeConstraint": "warn", "noVoid": "error", - "useSimplifiedLogicExpression": "warn" + "useSimplifiedLogicExpression": "warn", + "noForEach": "off" }, "performance": { "noBarrelFile": "error", @@ -46,7 +47,7 @@ "options": { "strictCase": true, "requireAscii": true, - "filenameCases": ["camelCase", "export"] + "filenameCases": ["camelCase", "PascalCase", "export"] } }, "useForOf": "error", @@ -61,6 +62,9 @@ "useNodeAssertStrict": "warn", "useNumberNamespace": "warn", "useSingleCaseStatement": "warn" + }, + "suspicious": { + "noEmptyInterface": "off" } } }, @@ -74,7 +78,7 @@ "semicolons": "asNeeded", "quoteStyle": "single", "trailingComma": "none", - "lineWidth": 200, + "lineWidth": 120, "bracketSameLine": true } } diff --git a/e2e/example.spec.ts b/e2e/example.spec.ts index 86f27e9..8dbf10a 100644 --- a/e2e/example.spec.ts +++ b/e2e/example.spec.ts @@ -1,8 +1,8 @@ import { expect, test } from '@playwright/test' test('has title', async ({ page }) => { - await page.goto('/'); + await page.goto('/') // Expect a title "to contain" a substring. - await expect(page).toHaveTitle(/Dzeio/); + await expect(page).toHaveTitle(/Dzeio/) }) diff --git a/hooks/routing.ts b/hooks/routing.ts index 3a6c7a2..9d019ec 100644 --- a/hooks/routing.ts +++ b/hooks/routing.ts @@ -53,14 +53,14 @@ async function updateRoutes(output: string, routes: Array) { let file = baseFile file += `\n\nexport type Routes = ${routes.map((it) => `'${it}'`).join(' | ')}` - file += '\n\nexport default function route(route: Routes, query?: Record) {' + file += + '\n\nexport default function route(route: Routes, query?: Record) {' file += '\n\treturn formatRoute(route, query)' file += '\n}\n' await fs.writeFile(output, file) } - /** * format the path back to an url usable by the app * @@ -141,7 +141,6 @@ const integration: () => AstroIntegration = () => ({ await updateRoutes(outputFile, files) }, 'astro:server:setup': async ({ server }) => { - // get the files list const files = (await Promise.all([ await getFiles(pagesFolder).then((ev) => ev.map((it) => formatPath(pagesFolder, it))), @@ -158,7 +157,7 @@ const integration: () => AstroIntegration = () => ({ let removeExtension = true let folder = pagesFolder - if(path.startsWith(publicFolder)) { + if (path.startsWith(publicFolder)) { removeExtension = false folder = publicFolder } else if (!path.startsWith(folder)) { @@ -178,7 +177,7 @@ const integration: () => AstroIntegration = () => ({ path = path.replace(/\\/g, '/') let removeExtension = true let folder = pagesFolder - if(path.startsWith(publicFolder)) { + if (path.startsWith(publicFolder)) { removeExtension = false folder = publicFolder } diff --git a/playwright.config.ts b/playwright.config.ts index 389ab53..144c156 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -12,32 +12,39 @@ export default defineConfig({ fullyParallel: true, forbidOnly: !!process.env.CI, retries: process.env.CI ? 2 : 0, - workers: process.env.CI ? 1 : undefined as any, - reporter: process.env.CI ? 'list' : [['html', { - outputFolder: './playwright/report', - open: 'never' - }]], + workers: process.env.CI ? 1 : (undefined as any), + reporter: process.env.CI + ? 'list' + : [ + [ + 'html', + { + outputFolder: './playwright/report', + open: 'never' + } + ] + ], use: { baseURL: 'http://localhost:3000', - trace: 'on-first-retry', + trace: 'on-first-retry' }, /* Configure projects for major browsers */ projects: [ { - name: 'chromium', - use: { ...devices['Desktop Chrome'] }, + name: 'chromium', + use: { ...devices['Desktop Chrome'] } }, { - name: 'firefox', - use: { ...devices['Desktop Firefox'] }, + name: 'firefox', + use: { ...devices['Desktop Firefox'] } }, { - name: 'webkit', - use: { ...devices['Desktop Safari'] }, - }, + name: 'webkit', + use: { ...devices['Desktop Safari'] } + } /* Test against mobile viewports. */ // { @@ -58,5 +65,5 @@ export default defineConfig({ // name: 'Google Chrome', // use: { ...devices['Desktop Chrome'], channel: 'chrome' }, // }, - ], + ] }) diff --git a/src/components/global/Button.astro b/src/components/global/Button.astro index ac135aa..d92ce7b 100644 --- a/src/components/global/Button.astro +++ b/src/components/global/Button.astro @@ -7,12 +7,11 @@ export interface Props extends astroHTML.JSX.AnchorHTMLAttributes { } const classes = [ - "button", - {outline: Astro.props.outline}, - {ghost: Astro.props.ghost}, + 'button', + { outline: Astro.props.outline }, + { ghost: Astro.props.ghost }, Astro.props.class ] - --- {'href' in Astro.props && ( diff --git a/src/components/global/Picture.astro b/src/components/global/Picture.astro index cb919de..fd7e2e5 100644 --- a/src/components/global/Picture.astro +++ b/src/components/global/Picture.astro @@ -1,12 +1,9 @@ --- import { getImage } from 'astro:assets' -import AstroUtils from '../../libs/AstroUtils' import { objectOmit } from '@dzeio/object-util' +import AstroUtils from '../../libs/AstroUtils' -const formats = [ - 'avif', - 'webp' -] +const formats = ['avif', 'webp'] export interface Props extends Omit { src: ImageMetadata | string @@ -17,7 +14,7 @@ export interface Props extends Omit { type PictureResult = { format: 'new' - formats: Array<{format: string, img: Awaited>}> + formats: Array<{ format: string, img: Awaited> }> src: Awaited> } | { format: 'raw' @@ -38,14 +35,25 @@ async function resolvePicture(image: ImageMetadata | string): Promise>}> = await Promise.all( - formats.map(async (it) => ({ - img: await getImage({src: Astro.props.src, format: it, width: Astro.props.width, height: Astro.props.height}), - format: it - })) - ) + const imageFormats: Array<{ format: string, img: Awaited> }> = + await Promise.all( + formats.map(async (it) => ({ + img: await getImage({ + src: Astro.props.src, + format: it, + width: Astro.props.width, + height: Astro.props.height + }), + format: it + })) + ) - const orig = await getImage({src: Astro.props.src, format: ext, width: Astro.props.width, height: Astro.props.height}) + const orig = await getImage({ + src: Astro.props.src, + format: ext, + width: Astro.props.width, + height: Astro.props.height + }) return { format: 'new', @@ -62,7 +70,6 @@ const res = await AstroUtils.wrap(async () => { }) const props = objectOmit(Astro.props, 'src', 'srcDark', 'class') - --- {res.light.format === 'new' && ( diff --git a/src/components/global/Range.astro b/src/components/global/Range.astro index c0d306a..787404a 100644 --- a/src/components/global/Range.astro +++ b/src/components/global/Range.astro @@ -6,7 +6,6 @@ interface Props extends Omit { } const baseProps = objectOmit(Astro.props, 'label', 'block') - ---
diff --git a/src/components/global/Select.astro b/src/components/global/Select.astro index a77e00f..1f0d5db 100644 --- a/src/components/global/Select.astro +++ b/src/components/global/Select.astro @@ -7,7 +7,7 @@ export interface Props extends Omit { block?: boolean suffix?: string prefix?: string - options: Array + options: Array } const baseProps = objectOmit(Astro.props, 'label', 'block', 'suffix', 'prefix', 'options') diff --git a/src/components/global/Table/TableUtil.ts b/src/components/global/Table/TableUtil.ts index 22c72f6..e9789c9 100644 --- a/src/components/global/Table/TableUtil.ts +++ b/src/components/global/Table/TableUtil.ts @@ -87,8 +87,8 @@ export function setOnTableClick(table: HTMLTableElement, fn: (row: number, cell: table.querySelectorAll('td').forEach((it) => { it.addEventListener('click', () => { const row = it.parentElement as HTMLTableRowElement - const rowIdx = parseInt(row.dataset.row as string) - const cellIdx = parseInt(it.dataset.cell as string) + const rowIdx = Number.parseInt(row.dataset.row as string) + const cellIdx = Number.parseInt(it.dataset.cell as string) fn(rowIdx, cellIdx) }) }) diff --git a/src/components/layouts/Favicon/Favicon.astro b/src/components/layouts/Favicon/Favicon.astro index a75bbb6..cf555f8 100644 --- a/src/components/layouts/Favicon/Favicon.astro +++ b/src/components/layouts/Favicon/Favicon.astro @@ -9,10 +9,9 @@ export interface Props { if (Astro.props.icoPath !== '/favicon.ico') { console.warn('It is recommanded that the ICO file should be located at /favicon.ico') - } -const appleTouch = await getImage({src: Astro.props.png, width: 180, height: 180}) +const appleTouch = await getImage({ src: Astro.props.png, width: 180, height: 180 }) --- <> diff --git a/src/components/layouts/Favicon/Manifest.ts b/src/components/layouts/Favicon/Manifest.ts deleted file mode 100644 index ea1503c..0000000 --- a/src/components/layouts/Favicon/Manifest.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { getImage } from 'astro:assets' - -export default class Manifest { - static async create(baseImage: ImageMetadata, options: { - name: string - color?: string - images?: Array - }) { - const [ - i192, - i512 - ] = await Promise.all([ - getImage({src: baseImage, format: 'png', width: 192, height: 192}), - getImage({src: baseImage, format: 'png', width: 512, height: 512}) - ]) - return JSON.stringify({ - name: options.name, - short_name: options.name, - icons: [ - { - src: i192.src, - sizes: "192x192", - type: "image/png" - }, - { - src: i512.src, - sizes: "512x512", - type: "image/png" - } - ], - theme_color: options.color ?? "#fff", - background_color: options.color ?? "#fff", - display: "standalone" - }) - } -} diff --git a/src/components/layouts/Footer.astro b/src/components/layouts/Footer.astro index ecfc0be..6ca2826 100644 --- a/src/components/layouts/Footer.astro +++ b/src/components/layouts/Footer.astro @@ -2,8 +2,8 @@ const year = new Date().getFullYear() export interface Props { - links?: Array<{href: string, target?: string, display: string}> - socials?: Array<{href: string, target?: string, icon: any}> + links?: Array<{ href: string, target?: string, display: string }> + socials?: Array<{ href: string, target?: string, icon: any }> } --- diff --git a/src/components/layouts/Header.astro b/src/components/layouts/Header.astro index 8a4c4f6..24af56f 100644 --- a/src/components/layouts/Header.astro +++ b/src/components/layouts/Header.astro @@ -1,8 +1,8 @@ --- -import Logo from 'assets/components/layouts/Header/logo.svg' -import Picture from 'components/global/Picture.astro' -import Button from 'components/global/Button.astro' import { objectMap } from '@dzeio/object-util' +import Logo from 'assets/components/layouts/Header/logo.svg' +import Button from 'components/global/Button.astro' +import Picture from 'components/global/Picture.astro' export interface Props { right?: Record diff --git a/src/content/_config.ts b/src/content/_config.ts index ee2ea89..c613b5f 100644 --- a/src/content/_config.ts +++ b/src/content/_config.ts @@ -4,24 +4,26 @@ import { defineCollection, z } from 'astro:content' // 2. Define your collection(s) const projectsCollection = defineCollection({ type: 'content', - schema: ({ image }) => z.object({ - title: z.string(), - description: z.string().optional(), - image: image().optional(), - link: z.object({ - href: z.string(), - rel: z.string().optional(), - text: z.string().optional(), - target: z.string().optional() - }).optional(), - disabled: z.string().optional(), - created: z.date().optional(), - updated: z.date().optional(), - techs: z.string().array().optional() - }) + schema: ({ image }) => + z.object({ + title: z.string(), + description: z.string().optional(), + image: image().optional(), + link: z + .object({ + href: z.string(), + rel: z.string().optional(), + text: z.string().optional(), + target: z.string().optional() + }) + .optional(), + disabled: z.string().optional(), + created: z.date().optional(), + updated: z.date().optional(), + techs: z.string().array().optional() + }) }) - // 3. Export a single `collections` object to register your collection(s) // This key should match your collection directory name in "src/content" export const collections = { diff --git a/src/env.d.ts b/src/env.d.ts index 651ee79..6dc7db8 100644 --- a/src/env.d.ts +++ b/src/env.d.ts @@ -4,14 +4,12 @@ /** * Environment variables declaration */ -interface ImportMetaEnv { -} +interface ImportMetaEnv {} interface ImportMeta { - readonly env: ImportMetaEnv; + readonly env: ImportMetaEnv } - declare namespace App { /** * Middlewares variables diff --git a/src/layouts/Head.astro b/src/layouts/Head.astro index 05ce73c..56f2120 100644 --- a/src/layouts/Head.astro +++ b/src/layouts/Head.astro @@ -1,7 +1,7 @@ --- -import Favicon from 'components/layouts/Favicon/Favicon.astro' +import type IconPNG from 'assets/layouts/Head/favicon.png' import IconSVG from 'assets/layouts/Head/favicon.svg' -import IconPNG from 'assets/layouts/Head/favicon.png' +import Favicon from 'components/layouts/Favicon/Favicon.astro' export interface Props { /** @@ -29,7 +29,7 @@ export interface Props { */ twitter?: { title?: string | undefined - card?: "summary" | "summary_large_image" | "app" | "player" | undefined + card?: 'summary' | 'summary_large_image' | 'app' | 'player' | undefined site?: string | undefined creator?: string | undefined } | undefined @@ -46,9 +46,14 @@ export interface Props { const props = Astro.props -const image = props.image ? Array.isArray(props.image) ? props.image : [props.image] : undefined +const image = props.image ? (Array.isArray(props.image) ? props.image : [props.image]) : undefined -const canonical = typeof Astro.props.canonical === 'string' ? Astro.props.canonical : Astro.props.canonical === false ? undefined : Astro.url.href +const canonical = + typeof Astro.props.canonical === 'string' + ? Astro.props.canonical + : Astro.props.canonical === false + ? undefined + : Astro.url.href --- diff --git a/src/layouts/MainLayout.astro b/src/layouts/MainLayout.astro index 0fbbe09..ba86389 100644 --- a/src/layouts/MainLayout.astro +++ b/src/layouts/MainLayout.astro @@ -1,9 +1,9 @@ --- import Footer from 'components/layouts/Footer.astro' -import Base, { type Props as BaseProps } from './Base.astro' import Header from 'components/layouts/Header.astro' import { Mail, Phone } from 'lucide-astro' import { Github, Linkedin } from 'simple-icons-astro' +import Base, { type Props as BaseProps } from './Base.astro' export interface Props extends BaseProps { /** diff --git a/src/libs/Component.ts b/src/libs/Component.ts index a638172..cf6bd6f 100644 --- a/src/libs/Component.ts +++ b/src/libs/Component.ts @@ -4,9 +4,7 @@ type Fn = (el: Component) => void | Promise * Component client side initialisation class */ export default class Component { - private constructor( - public element: T - ) {} + private constructor(public element: T) {} public handled(value: boolean): this public handled(): boolean diff --git a/src/libs/HTTP/StatusCode.ts b/src/libs/HTTP/StatusCode.ts index 31dc45d..0cd2cc8 100644 --- a/src/libs/HTTP/StatusCode.ts +++ b/src/libs/HTTP/StatusCode.ts @@ -4,7 +4,6 @@ * Following https://developer.mozilla.org/en-US/docs/Web/HTTP/Status an extension of the RFC9110 */ enum StatusCode { - /**************** * 1xx Requests * ****************/ @@ -283,7 +282,7 @@ enum StatusCode { /** * Indicates that the client needs to authenticate to gain network access. */ - NETWORK_AUTHENTIFICATION_REQUIRED, + NETWORK_AUTHENTIFICATION_REQUIRED } export default StatusCode diff --git a/src/libs/RFCs/RFC7807.ts b/src/libs/RFCs/RFC7807.ts index c7cfb10..4bd396d 100644 --- a/src/libs/RFCs/RFC7807.ts +++ b/src/libs/RFCs/RFC7807.ts @@ -1,66 +1,70 @@ -import ResponseBuilder from '../ResponseBuilder' - -/** - * Add headers: - * Content-Type: application/problem+json - * - * following https://www.rfc-editor.org/rfc/rfc7807.html - */ -export default interface RFC7807 { - /** - * A URI reference [RFC3986] that identifies the - * problem type. - * - * This specification encourages that, when - * dereferenced, it provide human-readable documentation for the - * problem type (e.g., using HTML [W3C.REC-html5-20141028]). - * - * When - * this member is not present, its value is assumed to be - * "about:blank" - */ - type?: string - - /** - * A short, human-readable summary of the problem - * type. - * - * It SHOULD NOT change from occurrence to occurrence of the - * problem, except for purposes of localization (e.g., using - * proactive content negotiation; see [RFC7231], Section 3.4). - */ - title?: string - - /** - * The HTTP status code ([RFC7231], Section 6) - * generated by the origin server for this occurrence of the problem. - */ - status?: number - - /** - * A human-readable explanation specific to this - * occurrence of the problem. - */ - details?: string - - /** - * A URI reference that identifies the specific - * occurrence of the problem. - * - * It may or may not yield further - * information if dereferenced. - */ - instance?: string -} - -/** - * - * @param error the error (base items are type, status, title details and instance) - * @returns - */ -export function buildRFC7807(error: RFC7807 & Record, response: ResponseBuilder = new ResponseBuilder()): Response { - response.addHeader('Content-Type', 'application/problem+json') - .body(JSON.stringify(error)) - .status(error.status ?? 500) - return response.build() -} +import ResponseBuilder from '../ResponseBuilder' + +/** + * Add headers: + * Content-Type: application/problem+json + * + * following https://www.rfc-editor.org/rfc/rfc7807.html + */ +export default interface RFC7807 { + /** + * A URI reference [RFC3986] that identifies the + * problem type. + * + * This specification encourages that, when + * dereferenced, it provide human-readable documentation for the + * problem type (e.g., using HTML [W3C.REC-html5-20141028]). + * + * When + * this member is not present, its value is assumed to be + * "about:blank" + */ + type?: string + + /** + * A short, human-readable summary of the problem + * type. + * + * It SHOULD NOT change from occurrence to occurrence of the + * problem, except for purposes of localization (e.g., using + * proactive content negotiation; see [RFC7231], Section 3.4). + */ + title?: string + + /** + * The HTTP status code ([RFC7231], Section 6) + * generated by the origin server for this occurrence of the problem. + */ + status?: number + + /** + * A human-readable explanation specific to this + * occurrence of the problem. + */ + details?: string + + /** + * A URI reference that identifies the specific + * occurrence of the problem. + * + * It may or may not yield further + * information if dereferenced. + */ + instance?: string +} + +/** + * + * @param error the error (base items are type, status, title details and instance) + * @returns + */ +export function buildRFC7807( + error: RFC7807 & Record, + response: ResponseBuilder = new ResponseBuilder() +): Response { + return response + .addHeader('Content-Type', 'application/problem+json') + .body(JSON.stringify(error)) + .status(error.status ?? 500) + .build() +} diff --git a/src/libs/ResponseBuilder.ts b/src/libs/ResponseBuilder.ts index 67abd2c..b47f08a 100644 --- a/src/libs/ResponseBuilder.ts +++ b/src/libs/ResponseBuilder.ts @@ -5,7 +5,6 @@ import StatusCode from './HTTP/StatusCode' * Simple builde to create a new Response object */ export default class ResponseBuilder { - public static redirect(location: string, statusCode: number = StatusCode.FOUND) { const resp = new ResponseBuilder() resp.addHeader('Location', location) diff --git a/src/middleware/index.ts b/src/middleware/index.ts index 0b7c96c..9f7c0fb 100644 --- a/src/middleware/index.ts +++ b/src/middleware/index.ts @@ -1,4 +1,4 @@ -import { sequence } from "astro/middleware" +import { sequence } from 'astro/middleware' import logger from './logger' diff --git a/src/middleware/logger.ts b/src/middleware/logger.ts index a7c4d2d..0ec49cb 100644 --- a/src/middleware/logger.ts +++ b/src/middleware/logger.ts @@ -1,4 +1,4 @@ -import { defineMiddleware } from "astro/middleware" +import { defineMiddleware } from 'astro/middleware' import ResponseBuilder from 'libs/ResponseBuilder' /** @@ -7,7 +7,10 @@ import ResponseBuilder from 'libs/ResponseBuilder' export default defineMiddleware(async ({ request, url }, next) => { const now = new Date() // Date of request User-Agent 32 first chars request Method - let prefix = `\x1b[2m${now.toISOString()}\x1b[22m ${request.headers.get('user-agent')?.slice(0, 32).padEnd(32)} ${request.method.padEnd(7)}` + let prefix = `\x1b[2m${now.toISOString()}\x1b[22m ${request.headers + .get('user-agent') + ?.slice(0, 32) + .padEnd(32)} ${request.method.padEnd(7)}` const fullURL = url.toString() const path = fullURL.slice(fullURL.indexOf(url.pathname, fullURL.indexOf(url.host))) @@ -26,14 +29,22 @@ export default defineMiddleware(async ({ request, url }, next) => { if (import.meta.env.PROD) { // HTTP Status time to execute path of request - console.log(`${prefix} \x1b[34m[${res.status}]\x1b[0m \x1b[2m${(new Date().getTime() - now.getTime()).toFixed(0).padStart(5, ' ')}ms\x1b[22m ${path}`) + console.log( + `${prefix} \x1b[34m[${res.status}]\x1b[0m \x1b[2m${(new Date().getTime() - now.getTime()) + .toFixed(0) + .padStart(5, ' ')}ms\x1b[22m ${path}` + ) } return res } catch (e) { if (import.meta.env.PROD) { // time to execute path of request - console.log(`${prefix} \x1b[34m[500]\x1b[0m \x1b[2m${(new Date().getTime() - now.getTime()).toFixed(0).padStart(5, ' ')}ms\x1b[22m ${path}`) + console.log( + `${prefix} \x1b[34m[500]\x1b[0m \x1b[2m${(new Date().getTime() - now.getTime()) + .toFixed(0) + .padStart(5, ' ')}ms\x1b[22m ${path}` + ) } // add a full line dash to not miss it diff --git a/src/models/Dao.ts b/src/models/Dao.ts index 811a20e..d222900 100644 --- a/src/models/Dao.ts +++ b/src/models/Dao.ts @@ -4,7 +4,6 @@ * you MUST call it through the `DaoFactory` file */ export default abstract class Dao { - /** * insert a new object into the source * @@ -19,7 +18,8 @@ export default abstract class Dao { * @param obj the object to create * @returns the object with it's id filled if create or null otherwise */ - public insert: Dao['create'] = (obj: Parameters['create']>[0]) => this.create(obj) + public insert: Dao['create'] = (obj: Parameters['create']>[0]) => + this.create(obj) /** * find the list of objects having elements from the query @@ -35,7 +35,8 @@ export default abstract class Dao { * @param query a partial object which filter depending on the elements, if not set it will fetch everything * @returns an array containing the list of elements that match with the query */ - public find: Dao['findAll'] = (query: Parameters['findAll']>[0]) => this.findAll(query) + public find: Dao['findAll'] = (query: Parameters['findAll']>[0]) => + this.findAll(query) /** * find an object by it's id @@ -46,7 +47,7 @@ export default abstract class Dao { * @returns */ public findById(id: Object['id']): Promise { - return this.findOne({id: id} as Partial) + return this.findOne({ id: id } as Partial) } /** @@ -91,14 +92,16 @@ export default abstract class Dao { if (!query) { return null } - return await this.update({...query, ...changes}) + return await this.update({ ...query, ...changes }) } /** * update the remote reference of the object or create it if not found * @param obj the object to update/insert * @returns the object is updated/inserted or null otherwise */ - public async upsert(object: Object | Omit): Promise { + public async upsert( + object: Object | Omit + ): Promise { if ('id' in object) { return this.update(object) } diff --git a/src/models/DaoFactory.ts b/src/models/DaoFactory.ts index 960b057..fbdce8f 100644 --- a/src/models/DaoFactory.ts +++ b/src/models/DaoFactory.ts @@ -9,8 +9,7 @@ * * Touch this interface to define which key is linked to which Dao */ -interface DaoItem { -} +interface DaoItem {} /** * Class to get any DAO @@ -48,7 +47,8 @@ export default class DaoFactory { */ private static initDao(item: keyof DaoItem): any | undefined { switch (item) { - default: return undefined + default: + return undefined } } } diff --git a/src/pages/404.astro b/src/pages/404.astro index a300d60..ff3b71f 100644 --- a/src/pages/404.astro +++ b/src/pages/404.astro @@ -1,9 +1,9 @@ --- -import MainLayout from 'layouts/MainLayout.astro' -import I404 from 'assets/pages/404/404.svg' import I404Light from 'assets/pages/404/404.light.svg' +import I404 from 'assets/pages/404/404.svg' import Button from 'components/global/Button.astro' import Picture from 'components/global/Picture.astro' +import MainLayout from 'layouts/MainLayout.astro' --- diff --git a/tailwind.config.cjs b/tailwind.config.cjs index 4528fbb..b325ff5 100644 --- a/tailwind.config.cjs +++ b/tailwind.config.cjs @@ -7,7 +7,7 @@ module.exports = { theme: { fontFamily: { // add your default font below - 'sans': ['Font Name', ...defaultTheme.fontFamily.sans] + sans: ['Font Name', ...defaultTheme.fontFamily.sans] }, extend: { colors: { @@ -21,7 +21,7 @@ module.exports = { // add a default padding to the container DEFAULT: '1rem' } - }, - }, + } + } } } diff --git a/tests/basic.test.ts b/tests/basic.test.ts index 6c43f34..99b42e8 100644 --- a/tests/basic.test.ts +++ b/tests/basic.test.ts @@ -3,7 +3,7 @@ import { expect, test } from 'vitest' // Edit an assertion and save to see HMR in action test('Math.sqrt()', () => { - expect(Math.sqrt(4)).toBe(2); - expect(Math.sqrt(144)).toBe(12); - expect(Math.sqrt(2)).toBe(Math.SQRT2); -}); + expect(Math.sqrt(4)).toBe(2) + expect(Math.sqrt(144)).toBe(12) + expect(Math.sqrt(2)).toBe(Math.SQRT2) +}) diff --git a/vitest.config.ts b/vitest.config.ts index ca11782..9fee874 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -4,10 +4,8 @@ import { getViteConfig } from 'astro/config' export default getViteConfig({ test: { - include: [ - './tests/**.ts' - ] + include: ['./tests/**.ts'] /* for example, use global to avoid globals imports (describe, test, expect): */ // globals: true, - }, -}); + } +})