diff --git a/.zed/settings.json b/.zed/settings.json new file mode 100644 index 0000000..1b9ae30 --- /dev/null +++ b/.zed/settings.json @@ -0,0 +1,9 @@ +{ + "lsp": { + "biome": { + "settings": { + "config_path": "./biome.json" + } + } + } +} diff --git a/assets/env.d.ts b/assets/env.d.ts index 9fa8bba..5f10758 100644 --- a/assets/env.d.ts +++ b/assets/env.d.ts @@ -1,14 +1,12 @@ -import type { TypedPocketbase } from "../../../src/lib/pocketbase/schemas"; -import type { helpersFrom } from "astro-pocketbase-continue"; +import type { TypedPocketbase } from '../../../src/lib/pocketbase/schemas' +import type { helpersFrom } from 'astro-pocketbase-continue' declare global { - namespace App { - interface Locals { - pocketbase: TypedPocketbase; - getRecord: ReturnType["getRecord"]; - getRecords: ReturnType["getRecords"]; - } - } + namespace App { + interface Locals { + pocketbase: TypedPocketbase + getRecord: ReturnType['getRecord'] + getRecords: ReturnType['getRecords'] + } + } } - -export {}; diff --git a/assets/loader.ts b/assets/loader.ts index 09268eb..f77e512 100644 --- a/assets/loader.ts +++ b/assets/loader.ts @@ -1,59 +1,69 @@ // This file was automatically generated by Astro PocketBase. -import type { Collection, TypedPocketbase } from "./schemas"; -import type { LoaderContext } from "astro/loaders"; -import Pocketbase from "pocketbase"; -import Client from "pocketbase"; -import type { RecordAuthResponse, } from "pocketbase"; +import type { LoaderContext } from 'astro/loaders' +import type Client from 'pocketbase' +import type { RecordAuthResponse } from 'pocketbase' +import Pocketbase from 'pocketbase' +import type { Collection, TypedPocketbase } from './schemas' -let pocketbase: TypedPocketbase; -let auth: Promise>; -let isAuthenticating = false; +let pocketbase: TypedPocketbase +let auth: Promise> +let isAuthenticating = false export function pocketbaseLoader({ collection }: PocketbaseLoaderOptions) { - return { - name: "pocketbase-loader", - load: async ({ store, logger, meta, parseData }: LoaderContext) => { - const { ASTRO_POCKETBASE_ADMIN_EMAIL, ASTRO_POCKETBASE_ADMIN_PASSWORD, PUBLIC_ASTRO_POCKETBASE_URL } = import.meta.env; - if (!ASTRO_POCKETBASE_ADMIN_EMAIL || !ASTRO_POCKETBASE_ADMIN_PASSWORD || !PUBLIC_ASTRO_POCKETBASE_URL) - return logger.error("Environment variables not set"); + return { + name: 'pocketbase-loader', + load: async ({ store, logger, meta, parseData }: LoaderContext) => { + const { + ASTRO_POCKETBASE_ADMIN_EMAIL, + ASTRO_POCKETBASE_ADMIN_PASSWORD, + PUBLIC_ASTRO_POCKETBASE_URL, + } = import.meta.env + if ( + !ASTRO_POCKETBASE_ADMIN_EMAIL || + !ASTRO_POCKETBASE_ADMIN_PASSWORD || + !PUBLIC_ASTRO_POCKETBASE_URL + ) + return logger.error('Environment variables not set') - logger.info(`Loading ${collection}`); + logger.info(`Loading ${collection}`) - if (!pocketbase) pocketbase = new Pocketbase(PUBLIC_ASTRO_POCKETBASE_URL); + if (!pocketbase) pocketbase = new Pocketbase(PUBLIC_ASTRO_POCKETBASE_URL) - try { - if (!isAuthenticating && !pocketbase.authStore.isValid) { - isAuthenticating = true; - auth = pocketbase.collection("_superusers").authWithPassword(ASTRO_POCKETBASE_ADMIN_EMAIL, ASTRO_POCKETBASE_ADMIN_PASSWORD); - } - await auth; + try { + if (!isAuthenticating && !pocketbase.authStore.isValid) { + isAuthenticating = true + auth = pocketbase + .collection('_superusers') + .authWithPassword(ASTRO_POCKETBASE_ADMIN_EMAIL, ASTRO_POCKETBASE_ADMIN_PASSWORD) + } + await auth - const lastUpdatedItems = await pocketbase - .collection(collection) - .getList(1, 1, { fields: "updated", skipTotal: true, sort: "updated", order: "desc" }); - const lastUpdated = lastUpdatedItems.items[0]?.updated; + const lastUpdatedItems = await pocketbase + .collection(collection) + .getList(1, 1, { fields: 'updated', skipTotal: true, sort: 'updated', order: 'desc' }) + const lastUpdated = lastUpdatedItems.items[0]?.updated - if (lastUpdated !== meta.get("last-updated")) { - logger.info(`Refreshing ${collection}`); + if (lastUpdated !== meta.get('last-updated')) { + logger.info(`Refreshing ${collection}`) - meta.set("last-updated", lastUpdated); - const items = await pocketbase.collection(collection).getFullList(); - for (const { id, updated, ...rest } of items) { - const data = await parseData({ id, data: { id, updated, ...rest } }); - store.set({ data, digest: updated, id }); - } - } + meta.set('last-updated', lastUpdated) + const items = await pocketbase.collection(collection).getFullList() + for (const { id, updated, ...rest } of items) { + const data = await parseData({ id, data: { id, updated, ...rest } }) + store.set({ data, digest: updated, id }) + } + } - logger.info(`Loaded ${collection}`); - } catch (error) { - logger.error(`Error fetching ${collection}: ${error}`); - return; - } - }, - }; + logger.info(`Loaded ${collection}`) + } catch (error) { + logger.error(`Error fetching ${collection}: ${error}`) + return + } + }, + } } export type PocketbaseLoaderOptions = { - collection: Collection; -}; + collection: Collection +} diff --git a/assets/middleware.ts b/assets/middleware.ts index 1877606..1838ffa 100644 --- a/assets/middleware.ts +++ b/assets/middleware.ts @@ -1,17 +1,17 @@ // This file was automatically generated by Astro PocketBase. -import { defineMiddleware } from "astro:middleware"; -import { helpersFrom } from "astro-pocketbase-continue"; -import PocketBase from "pocketbase"; +import { defineMiddleware } from 'astro:middleware' +import { helpersFrom } from 'astro-pocketbase-continue' +import PocketBase from 'pocketbase' const middleware = defineMiddleware((context, next) => { - const pocketbase = new PocketBase(import.meta.env.PUBLIC_ASTRO_POCKETBASE_URL); - const { getRecord, getRecords } = helpersFrom({ pocketbase }); - context.locals.pocketbase = pocketbase; - context.locals.getRecord = getRecord; - context.locals.getRecords = getRecords; - return next(); -}); + const pocketbase = new PocketBase(import.meta.env.PUBLIC_ASTRO_POCKETBASE_URL) + const { getRecord, getRecords } = helpersFrom({ pocketbase }) + context.locals.pocketbase = pocketbase + context.locals.getRecord = getRecord + context.locals.getRecords = getRecords + return next() +}) // You should NOT change the exported name as it is used by the Astro PocketBase integration. -export { middleware as onRequest }; +export { middleware as onRequest } diff --git a/assets/toolbar.ts b/assets/toolbar.ts index 7f4ae3b..e48b2ee 100644 --- a/assets/toolbar.ts +++ b/assets/toolbar.ts @@ -1,17 +1,17 @@ -import { defineToolbarApp } from "astro/toolbar"; +import { defineToolbarApp } from 'astro/toolbar' export default defineToolbarApp({ - init(_canvas, app, server) { - let pending = false; + init(_canvas, app, server) { + let pending = false - // const button = document.querySelector("astro-dev-toolbar")?.shadowRoot.querySelector("button[data-app-id='astro-pocketbase-continue']"); + // const button = document.querySelector("astro-dev-toolbar")?.shadowRoot.querySelector("button[data-app-id='astro-pocketbase-continue']"); - app.onToggled(({ state }) => { - if (!state) return; - app.toggleNotification({ level: "error", state: true }); - if (pending) return; - pending = true; - server.send("astro-pocketbase-continue:refresh", undefined); - }); - }, -}); + app.onToggled(({ state }) => { + if (!state) return + app.toggleNotification({ level: 'error', state: true }) + if (pending) return + pending = true + server.send('astro-pocketbase-continue:refresh', undefined) + }) + }, +}) diff --git a/biome.json b/biome.json new file mode 100644 index 0000000..45de3ff --- /dev/null +++ b/biome.json @@ -0,0 +1,53 @@ +{ + "$schema": "https://biomejs.dev/schemas/2.2.6/schema.json", + "vcs": { + "enabled": false, + "clientKind": "git", + "useIgnoreFile": false + }, + "files": { + "ignoreUnknown": false, + "includes": ["**", "!**/node_modules", "!**/dist"] + }, + "formatter": { + "enabled": true, + "formatWithErrors": false, + "indentStyle": "tab", + "indentWidth": 2, + "lineEnding": "lf", + "lineWidth": 100, + "attributePosition": "auto", + "bracketSameLine": false, + "bracketSpacing": true, + "expand": "auto", + "useEditorconfig": true + }, + "linter": { + "enabled": true, + "rules": { + "recommended": true + } + }, + "javascript": { + "formatter": { + "jsxQuoteStyle": "double", + "quoteProperties": "asNeeded", + "trailingCommas": "all", + "semicolons": "asNeeded", + "arrowParentheses": "always", + "bracketSameLine": false, + "quoteStyle": "single", + "attributePosition": "auto", + "bracketSpacing": true + } + }, + "overrides": [{ "includes": ["**/*.ts", "**/*.tsx"] }], + "assist": { + "enabled": true, + "actions": { + "source": { + "organizeImports": "on" + } + } + } +} diff --git a/bun.lock b/bun.lock index 2bec127..7aae310 100644 --- a/bun.lock +++ b/bun.lock @@ -7,20 +7,21 @@ "astro-integration-kit": "^0.19.0", "dotenv": "^17.2.3", "es-toolkit": "^1.30.1", - "zod-pocketbase-continue": "^0.5.0", + "zod-pocketbase-continue": "^0.6.0", }, "devDependencies": { + "@biomejs/biome": "2.2.6", "@changesets/cli": "^2.29.7", "@typescript-eslint/eslint-plugin": "^8.46.1", "@typescript-eslint/parser": "^8.46.1", "pocketbase": "^0.26.2", "tsdown": "^0.15.7", - "zod": "^3.25.76", + "zod": "^4.1.12", }, "peerDependencies": { "astro": "^5.14.4", "pocketbase": "^0.26.2", - "zod": "^3.25.76", + "zod": "^4.1.12", }, }, }, @@ -47,6 +48,24 @@ "@babel/types": ["@babel/types@7.28.4", "", { "dependencies": { "@babel/helper-string-parser": "^7.27.1", "@babel/helper-validator-identifier": "^7.27.1" } }, "sha512-bkFqkLhh3pMBUQQkpVgWDWq/lqzc2678eUyDlTBhRqhCHFguYYGM0Efga7tYk4TogG/3x0EEl66/OQ+WGbWB/Q=="], + "@biomejs/biome": ["@biomejs/biome@2.2.6", "", { "optionalDependencies": { "@biomejs/cli-darwin-arm64": "2.2.6", "@biomejs/cli-darwin-x64": "2.2.6", "@biomejs/cli-linux-arm64": "2.2.6", "@biomejs/cli-linux-arm64-musl": "2.2.6", "@biomejs/cli-linux-x64": "2.2.6", "@biomejs/cli-linux-x64-musl": "2.2.6", "@biomejs/cli-win32-arm64": "2.2.6", "@biomejs/cli-win32-x64": "2.2.6" }, "bin": { "biome": "bin/biome" } }, "sha512-yKTCNGhek0rL5OEW1jbLeZX8LHaM8yk7+3JRGv08my+gkpmtb5dDE+54r2ZjZx0ediFEn1pYBOJSmOdDP9xtFw=="], + + "@biomejs/cli-darwin-arm64": ["@biomejs/cli-darwin-arm64@2.2.6", "", { "os": "darwin", "cpu": "arm64" }, "sha512-UZPmn3M45CjTYulgcrFJFZv7YmK3pTxTJDrFYlNElT2FNnkkX4fsxjExTSMeWKQYoZjvekpH5cvrYZZlWu3yfA=="], + + "@biomejs/cli-darwin-x64": ["@biomejs/cli-darwin-x64@2.2.6", "", { "os": "darwin", "cpu": "x64" }, "sha512-HOUIquhHVgh/jvxyClpwlpl/oeMqntlteL89YqjuFDiZ091P0vhHccwz+8muu3nTyHWM5FQslt+4Jdcd67+xWQ=="], + + "@biomejs/cli-linux-arm64": ["@biomejs/cli-linux-arm64@2.2.6", "", { "os": "linux", "cpu": "arm64" }, "sha512-BpGtuMJGN+o8pQjvYsUKZ+4JEErxdSmcRD/JG3mXoWc6zrcA7OkuyGFN1mDggO0Q1n7qXxo/PcupHk8gzijt5g=="], + + "@biomejs/cli-linux-arm64-musl": ["@biomejs/cli-linux-arm64-musl@2.2.6", "", { "os": "linux", "cpu": "arm64" }, "sha512-TjCenQq3N6g1C+5UT3jE1bIiJb5MWQvulpUngTIpFsL4StVAUXucWD0SL9MCW89Tm6awWfeXBbZBAhJwjyFbRQ=="], + + "@biomejs/cli-linux-x64": ["@biomejs/cli-linux-x64@2.2.6", "", { "os": "linux", "cpu": "x64" }, "sha512-1HaM/dpI/1Z68zp8ZdT6EiBq+/O/z97a2AiHMl+VAdv5/ELckFt9EvRb8hDHpk8hUMoz03gXkC7VPXOVtU7faA=="], + + "@biomejs/cli-linux-x64-musl": ["@biomejs/cli-linux-x64-musl@2.2.6", "", { "os": "linux", "cpu": "x64" }, "sha512-1ZcBux8zVM3JhWN2ZCPaYf0+ogxXG316uaoXJdgoPZcdK/rmRcRY7PqHdAos2ExzvjIdvhQp72UcveI98hgOog=="], + + "@biomejs/cli-win32-arm64": ["@biomejs/cli-win32-arm64@2.2.6", "", { "os": "win32", "cpu": "arm64" }, "sha512-h3A88G8PGM1ryTeZyLlSdfC/gz3e95EJw9BZmA6Po412DRqwqPBa2Y9U+4ZSGUAXCsnSQE00jLV8Pyrh0d+jQw=="], + + "@biomejs/cli-win32-x64": ["@biomejs/cli-win32-x64@2.2.6", "", { "os": "win32", "cpu": "x64" }, "sha512-yx0CqeOhPjYQ5ZXgPfu8QYkgBhVJyvWe36as7jRuPrKPO5ylVDfwVtPQ+K/mooNTADW0IhxOZm3aPu16dP8yNQ=="], + "@capsizecss/unpack": ["@capsizecss/unpack@3.0.0", "", { "dependencies": { "fontkit": "^2.0.2" } }, "sha512-+ntATQe1AlL7nTOYjwjj6w3299CgRot48wL761TUGYpYgAou3AaONZazp0PKZyCyWhudWsjhq1nvRHOvbMzhTA=="], "@changesets/apply-release-plan": ["@changesets/apply-release-plan@7.0.13", "", { "dependencies": { "@changesets/config": "^3.1.1", "@changesets/get-version-range-type": "^0.4.0", "@changesets/git": "^3.0.4", "@changesets/should-skip-package": "^0.1.2", "@changesets/types": "^6.1.0", "@manypkg/get-packages": "^1.1.3", "detect-indent": "^6.0.0", "fs-extra": "^7.0.1", "lodash.startcase": "^4.4.0", "outdent": "^0.5.0", "prettier": "^2.7.1", "resolve-from": "^5.0.0", "semver": "^7.5.3" } }, "sha512-BIW7bofD2yAWoE8H4V40FikC+1nNFEKBisMECccS16W1rt6qqhNTBDmIw5HaqmMgtLNz9e7oiALiEUuKrQ4oHg=="], @@ -435,7 +454,7 @@ "brotli": ["brotli@1.3.3", "", { "dependencies": { "base64-js": "^1.1.2" } }, "sha512-oTKjJdShmDuGW94SyyaoQvAjf30dZaHnjJ8uAF+u2/vGJkJbJPJAT1gDiOJP5v1Zb6f9KEyW/1HpuaWIXtGHPg=="], - "c12": ["c12@3.3.0", "", { "dependencies": { "chokidar": "^4.0.3", "confbox": "^0.2.2", "defu": "^6.1.4", "dotenv": "^17.2.2", "exsolve": "^1.0.7", "giget": "^2.0.0", "jiti": "^2.5.1", "ohash": "^2.0.11", "pathe": "^2.0.3", "perfect-debounce": "^2.0.0", "pkg-types": "^2.3.0", "rc9": "^2.1.2" }, "peerDependencies": { "magicast": "^0.3.5" }, "optionalPeers": ["magicast"] }, "sha512-K9ZkuyeJQeqLEyqldbYLG3wjqwpw4BVaAqvmxq3GYKK0b1A/yYQdIcJxkzAOWcNVWhJpRXAPfZFueekiY/L8Dw=="], + "c12": ["c12@3.3.1", "", { "dependencies": { "chokidar": "^4.0.3", "confbox": "^0.2.2", "defu": "^6.1.4", "dotenv": "^17.2.3", "exsolve": "^1.0.7", "giget": "^2.0.0", "jiti": "^2.6.1", "ohash": "^2.0.11", "pathe": "^2.0.3", "perfect-debounce": "^2.0.0", "pkg-types": "^2.3.0", "rc9": "^2.1.2" }, "peerDependencies": { "magicast": "^0.3.5" }, "optionalPeers": ["magicast"] }, "sha512-LcWQ01LT9tkoUINHgpIOv3mMs+Abv7oVCrtpMRi1PaapVEpWoMga5WuT7/DqFTu7URP9ftbOmimNw1KNIGh9DQ=="], "cac": ["cac@6.7.14", "", {}, "sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ=="], @@ -1113,9 +1132,9 @@ "yoctocolors": ["yoctocolors@2.1.2", "", {}, "sha512-CzhO+pFNo8ajLM2d2IW/R93ipy99LWjtwblvC1RsoSUMZgyLbYFr221TnSNT7GjGdYui6P459mw9JH/g/zW2ug=="], - "zod": ["zod@3.25.76", "", {}, "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ=="], + "zod": ["zod@4.1.12", "", {}, "sha512-JInaHOamG8pt5+Ey8kGmdcAcg3OL9reK8ltczgHTAwNhMys/6ThXHityHxVV2p3fkw/c+MAvBHFVYHFZDmjMCQ=="], - "zod-pocketbase-continue": ["zod-pocketbase-continue@0.5.0", "", { "dependencies": { "@clack/prompts": "^0.11.0", "c12": "^3.3.0", "citty": "^0.1.6", "es-toolkit": "^1.40.0" }, "peerDependencies": { "pocketbase": "^0.26.2", "zod": "^3.25.76" }, "bin": { "zod-pocketbase-continue": "dist/server/cli.js" } }, "sha512-4Wag9RSpozpnMqXthOtAn3F52SNhfWvMdTv9LOOTK1C1Lps4TYoafiWEWTwWnFFDLNA6HQ+WmEsfTdsG+CJINg=="], + "zod-pocketbase-continue": ["zod-pocketbase-continue@0.6.0", "", { "dependencies": { "@clack/prompts": "^0.11.0", "c12": "^3.3.1", "citty": "^0.1.6", "es-toolkit": "^1.40.0" }, "peerDependencies": { "pocketbase": "^0.26.2", "zod": "^4.1.12" }, "bin": { "zod-pocketbase-continue": "dist/server/cli.js" } }, "sha512-znZa/bYWulC9v2WYxgHs95OakHs+SYoZz2WC2lxFq9VFr5O9ZO1MrIgVBYt33EAGPGXceb0HE/IrQzoP5vBvWQ=="], "zod-to-json-schema": ["zod-to-json-schema@3.24.6", "", { "peerDependencies": { "zod": "^3.24.1" } }, "sha512-h/z3PKvcTcTetyjl1fkj79MHNEjm+HpD6NXheWjzOekY7kV+lwDYnHw+ivHkijnCSMz1yJaWBD9vu/Fcmk+vEg=="], @@ -1159,6 +1178,8 @@ "astro/package-manager-detector": ["package-manager-detector@1.4.0", "", {}, "sha512-rRZ+pR1Usc+ND9M2NkmCvE/LYJS+8ORVV9X0KuNSY/gFsp7RBHJM/ADh9LYq4Vvfq6QkKrW6/weuh8SMEtN5gw=="], + "astro/zod": ["zod@3.25.76", "", {}, "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ=="], + "boxen/chalk": ["chalk@5.6.2", "", {}, "sha512-7NzBL0rN6fMUW+f7A6Io4h40qQlG+xGmtMxfbnH/K7TAtt8JQWVQK+6g0UXKMeVJoyV5EkkNsErQ8pVD3bLHbA=="], "c12/pathe": ["pathe@2.0.3", "", {}, "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w=="], diff --git a/eslint.config.mjs b/eslint.config.mjs deleted file mode 100644 index cd95294..0000000 --- a/eslint.config.mjs +++ /dev/null @@ -1,22 +0,0 @@ -import typescript from "@typescript-eslint/eslint-plugin"; -import typescriptParser from "@typescript-eslint/parser"; - -export default [ - { - files: ["**/*.ts", "**/*.tsx"], - languageOptions: { - parser: typescriptParser, - parserOptions: { - ecmaVersion: "latest", - sourceType: "module", - project: "./tsconfig.json", - }, - }, - plugins: { - "@typescript-eslint": typescript, - }, - rules: { - ...typescript.configs.recommended.rules, - }, - }, -]; diff --git a/package.json b/package.json index 6831672..307472b 100644 --- a/package.json +++ b/package.json @@ -1,67 +1,67 @@ { - "name": "astro-pocketbase-continue", - "version": "0.12.1", - "description": "Astro integration to ease the use of PocketBase in your Astro projects", - "author": { - "email": "garandplg@garandplg.com", - "name": "Garand_PLG", - "url": "https://gitea.garandplg.com" - }, - "license": "MIT", - "keywords": [ - "astro-integration", - "astro-component", - "withastro", - "astro", - "pocketbase", - "tooling", - "utils", - "utility" - ], - "homepage": "https://gitea.garandplg.com/GarandPLG/astro-pocketbase-continue", - "publishConfig": { - "access": "public" - }, - "type": "module", - "sideEffects": false, - "packageManager": "bun@1.3.0", - "engines": { - "node": ">=24.9.0" - }, - "main": "dist/index.js", - "exports": { - ".": { - "types": "./dist/index.d.ts", - "default": "./dist/index.js" - } - }, - "files": [ - "dist", - "assets" - ], - "scripts": { - "dev": "tsdown --watch", - "build": "tsdown", - "changeset": "changeset", - "release": "bun scripts/release.mjs" - }, - "dependencies": { - "astro-integration-kit": "^0.19.0", - "dotenv": "^17.2.3", - "es-toolkit": "^1.30.1", - "zod-pocketbase-continue": "^0.5.0" - }, - "devDependencies": { - "@changesets/cli": "^2.29.7", - "@typescript-eslint/eslint-plugin": "^8.46.1", - "@typescript-eslint/parser": "^8.46.1", - "pocketbase": "^0.26.2", - "tsdown": "^0.15.7", - "zod": "^3.25.76" - }, - "peerDependencies": { - "astro": "^5.14.4", - "pocketbase": "^0.26.2", - "zod": "^3.25.76" - } + "name": "astro-pocketbase-continue", + "version": "0.12.1", + "description": "Astro integration to ease the use of PocketBase in your Astro projects", + "author": { + "email": "garandplg@garandplg.com", + "name": "Garand_PLG", + "url": "https://gitea.garandplg.com" + }, + "license": "MIT", + "keywords": [ + "astro-integration", + "astro-component", + "withastro", + "astro", + "pocketbase", + "tooling", + "utils", + "utility" + ], + "homepage": "https://gitea.garandplg.com/GarandPLG/astro-pocketbase-continue", + "publishConfig": { + "access": "public" + }, + "type": "module", + "sideEffects": false, + "packageManager": "bun@1.3.0", + "engines": { + "node": ">=24.9.0" + }, + "main": "dist/index.js", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + } + }, + "files": ["dist", "assets"], + "scripts": { + "dev": "tsdown --watch", + "build": "tsdown", + "changeset": "changeset", + "release": "bun scripts/release.mjs", + "lint": "biome check .", + "lint:w": "biome check --write .", + "format": "biome format .", + "format:w": "biome format --write ." + }, + "dependencies": { + "astro-integration-kit": "^0.19.0", + "dotenv": "^17.2.3", + "es-toolkit": "^1.30.1", + "zod-pocketbase-continue": "^0.6.0" + }, + "devDependencies": { + "@biomejs/biome": "2.2.6", + "@changesets/cli": "^2.29.7", + "pocketbase": "^0.26.2", + "tsdown": "^0.15.7", + "zod": "^4.1.12" + }, + "peerDependencies": { + "astro": "^5.14.4", + "pocketbase": "^0.26.2", + "zod": "^4.1.12" + } } diff --git a/prettier.config.mjs b/prettier.config.mjs deleted file mode 100644 index 95f039a..0000000 --- a/prettier.config.mjs +++ /dev/null @@ -1,4 +0,0 @@ -/** @type {import("prettier").Config} */ -export default { - printWidth: 140, -}; diff --git a/scripts/release.mjs b/scripts/release.mjs index 71a0371..187b70c 100644 --- a/scripts/release.mjs +++ b/scripts/release.mjs @@ -1,5 +1,5 @@ -import { spawn } from "node:child_process"; -import { resolve } from "node:path"; +import { spawn } from 'node:child_process' +import { resolve } from 'node:path' /** * @@ -9,41 +9,41 @@ import { resolve } from "node:path"; * @returns {Promise} */ const run = async (command, ...args) => { - const cwd = resolve(); - return new Promise((resolve) => { - const cmd = spawn(command, args, { - stdio: ["inherit", "pipe", "pipe"], // Inherit stdin, pipe stdout, pipe stderr - shell: true, - cwd, - }); + const cwd = resolve() + return new Promise((resolve) => { + const cmd = spawn(command, args, { + stdio: ['inherit', 'pipe', 'pipe'], // Inherit stdin, pipe stdout, pipe stderr + shell: true, + cwd, + }) - let output = ""; + let output = '' - cmd.stdout.on("data", (data) => { - process.stdout.write(data.toString()); - output += data.toString(); - }); + cmd.stdout.on('data', (data) => { + process.stdout.write(data.toString()) + output += data.toString() + }) - cmd.stderr.on("data", (data) => { - process.stderr.write(data.toString()); - }); + cmd.stderr.on('data', (data) => { + process.stderr.write(data.toString()) + }) - cmd.on("close", () => { - resolve(output); - }); - }); -}; + cmd.on('close', () => { + resolve(output) + }) + }) +} const main = async () => { - await run("bun changeset version"); - await run("git add ."); - await run('git commit -m "chore: update version"'); - await run("git push"); - await run("bun run build"); - await run("bun changeset publish"); - await run("git push --follow-tags"); - const tag = (await run("git describe --abbrev=0")).replace("\n", ""); - await run(`tea releases create --tag ${tag} --title "${tag}"`); -}; + await run('bun changeset version') + await run('git add .') + await run('git commit -m "chore: update version"') + await run('git push') + await run('bun run build') + await run('bun changeset publish') + await run('git push --follow-tags') + const tag = (await run('git describe --abbrev=0')).replace('\n', '') + await run(`tea releases create --tag ${tag} --title "${tag}"`) +} -main(); +main() diff --git a/src/index.ts b/src/index.ts index 4bd28ba..76a93d5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ -import { integration } from "@/integration.js"; -export * from "zod-pocketbase-continue"; +import { integration } from '@/integration.js' -export default integration; +export * from 'zod-pocketbase-continue' + +export default integration diff --git a/src/integration.ts b/src/integration.ts index a28437f..8411061 100644 --- a/src/integration.ts +++ b/src/integration.ts @@ -1,74 +1,83 @@ -import { createResolver, defineIntegration } from "astro-integration-kit"; -import dotenv from "dotenv"; -import { readFileSync, writeFileSync, existsSync } from "node:fs"; -import type { CollectionModel } from "pocketbase"; -import { Config, Credentials, defaultConfig, fetchCollections } from "zod-pocketbase-continue"; -import { generate } from "zod-pocketbase-continue/server"; +import { existsSync, readFileSync, writeFileSync } from 'node:fs' +import { createResolver, defineIntegration } from 'astro-integration-kit' +import dotenv from 'dotenv' +import type { CollectionModel } from 'pocketbase' +import { Config, Credentials, defaultConfig, fetchCollections } from 'zod-pocketbase-continue' +import { generate } from 'zod-pocketbase-continue/server' -dotenv.config(); +dotenv.config() export const integration = defineIntegration({ - name: "astro-pocketbase-continue", - optionsSchema: Config.omit({ adminEmail: true, adminPassword: true, output: true, url: true }).default(defaultConfig), - setup({ options }) { - const { resolve } = createResolver(import.meta.url); + name: 'astro-pocketbase-continue', + optionsSchema: Config.omit({ + adminEmail: true, + adminPassword: true, + output: true, + url: true, + }).default(defaultConfig), + setup({ options }) { + const { resolve } = createResolver(import.meta.url) - let collections: CollectionModel[] = []; + let collections: CollectionModel[] = [] - return { - hooks: { - "astro:config:setup": async (params) => { - const { addDevToolbarApp, addMiddleware, config, logger } = params; - const { srcDir } = config; + return { + hooks: { + 'astro:config:setup': async (params) => { + const { addDevToolbarApp, addMiddleware, config, logger } = params + const { srcDir } = config - const { - ASTRO_POCKETBASE_ADMIN_EMAIL: adminEmail, - ASTRO_POCKETBASE_ADMIN_PASSWORD: adminPassword, - PUBLIC_ASTRO_POCKETBASE_URL: url, - } = process.env; + const { + ASTRO_POCKETBASE_ADMIN_EMAIL: adminEmail, + ASTRO_POCKETBASE_ADMIN_PASSWORD: adminPassword, + PUBLIC_ASTRO_POCKETBASE_URL: url, + } = process.env - try { - const output = `${srcDir.pathname}lib/pocketbase/schemas.ts`; - const config = Config.parse({ ...options, adminEmail, adminPassword, url, output }); - const credentials = Credentials.parse(config); - const allCollections = await fetchCollections(credentials); - collections = allCollections.filter(({ name }) => !config.ignore.includes(name)); - await generate(collections, config); - } catch (error) { - logger.error(error instanceof Error ? error.message : "unknown error"); - } + try { + const output = `${srcDir.pathname}lib/pocketbase/schemas.ts` + const config = Config.parse({ ...options, adminEmail, adminPassword, url, output }) + const credentials = Credentials.parse(config) + const allCollections = await fetchCollections(credentials) + collections = allCollections.filter(({ name }) => !config.ignore.includes(name)) + await generate(collections, config) + } catch (error) { + logger.error(error instanceof Error ? error.message : 'unknown error') + } - if (!existsSync(new URL("lib/pocketbase/loader.ts", srcDir))) { - const loaderContent = readFileSync(resolve("../assets/loader.ts"), "utf-8"); - writeFileSync(new URL("lib/pocketbase/loader.ts", srcDir), loaderContent); - } + if (!existsSync(new URL('lib/pocketbase/loader.ts', srcDir))) { + const loaderContent = readFileSync(resolve('../assets/loader.ts'), 'utf-8') + writeFileSync(new URL('lib/pocketbase/loader.ts', srcDir), loaderContent) + } - if (!existsSync(new URL("lib/pocketbase/middleware.ts", srcDir))) { - const middlewareContent = readFileSync(resolve("../assets/middleware.ts"), "utf-8"); - writeFileSync(new URL("lib/pocketbase/middleware.ts", srcDir), middlewareContent); - } - addMiddleware({ entrypoint: new URL("lib/pocketbase/middleware.ts", srcDir), order: "pre" }); + if (!existsSync(new URL('lib/pocketbase/middleware.ts', srcDir))) { + const middlewareContent = readFileSync(resolve('../assets/middleware.ts'), 'utf-8') + writeFileSync(new URL('lib/pocketbase/middleware.ts', srcDir), middlewareContent) + } + addMiddleware({ + entrypoint: new URL('lib/pocketbase/middleware.ts', srcDir), + order: 'pre', + }) - addDevToolbarApp({ - id: "astro-pocketbase-continue", - name: "Astro PocketBase Continued", - icon: `PocketBase`, - entrypoint: resolve("../assets/toolbar.ts"), - }); - }, + addDevToolbarApp({ + id: 'astro-pocketbase-continue', + name: 'Astro PocketBase Continued', + icon: `PocketBase`, + entrypoint: resolve('../assets/toolbar.ts'), + }) + }, - "astro:config:done": ({ injectTypes }) => { - const content = readFileSync(resolve("../assets/env.d.ts"), "utf-8"); - injectTypes({ filename: "env.d.ts", content }); - }, + 'astro:config:done': ({ injectTypes }) => { + const content = readFileSync(resolve('../assets/env.d.ts'), 'utf-8') + injectTypes({ filename: 'env.d.ts', content }) + }, - "astro:server:setup": ({ refreshContent, toolbar }) => { - toolbar.on("astro-pocketbase-continue:refresh", async () => { - if (!refreshContent) console.warn("Content can only be refreshed in Astro v5.0.0 or higher"); - await refreshContent?.({ loaders: ["pocketbase-loader"] }); - }); - }, - }, - }; - }, -}); + 'astro:server:setup': ({ refreshContent, toolbar }) => { + toolbar.on('astro-pocketbase-continue:refresh', async () => { + if (!refreshContent) + console.warn('Content can only be refreshed in Astro v5.0.0 or higher') + await refreshContent?.({ loaders: ['pocketbase-loader'] }) + }) + }, + }, + } + }, +}) diff --git a/tsconfig.json b/tsconfig.json index 3a72fb8..cfa5839 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,57 +1,57 @@ { "extends": "astro/tsconfigs/strictest", "$schema": "https://json.schemastore.org/tsconfig", - "compilerOptions": { - // Enable top-level await, and other modern ESM features. - "target": "ESNext", - "module": "NodeNext", - // Enable module resolution without file extensions on relative paths, for things like npm package imports. - "moduleResolution": "nodenext", - // Allow importing TypeScript files using their native extension (.ts(x)). - "allowImportingTsExtensions": true, - // Enable JSON imports. - "resolveJsonModule": true, - // Enforce the usage of type-only imports when needed, which helps avoiding bundling issues. - "verbatimModuleSyntax": true, - // Ensure that each file can be transpiled without relying on other imports. - // This is redundant with the previous option, however it ensures that it's on even if someone disable `verbatimModuleSyntax` - "isolatedModules": true, - // Astro directly run TypeScript code, no transpilation needed. - "noEmit": true, - // Report an error when importing a file using a casing different from another import of the same file. - "forceConsistentCasingInFileNames": true, - // Properly support importing CJS modules in ESM - "esModuleInterop": true, - // Skip typechecking libraries and .d.ts files - "skipLibCheck": true, - // Allow JavaScript files to be imported - "allowJs": true, - // Allow JSX files (or files that are internally considered JSX, like Astro files) to be imported inside `.js` and `.ts` files. - "jsx": "preserve", - // Enable strict mode. This enables a few options at a time, see https://www.typescriptlang.org/tsconfig#strict for a list. - "strict": true, - // Report errors for fallthrough cases in switch statements - "noFallthroughCasesInSwitch": true, - // Force functions designed to override their parent class to be specified as `override`. - "noImplicitOverride": true, - // Force functions to specify that they can return `undefined` if a possible code path does not return a value. - "noImplicitReturns": true, - // Report an error when a variable is declared but never used. - "noUnusedLocals": true, - // Report an error when a parameter is declared but never used. - "noUnusedParameters": true, - // Force the usage of the indexed syntax to access fields declared using an index signature. - "noUncheckedIndexedAccess": true, - // Report an error when the value `undefined` is given to an optional property that doesn't specify `undefined` as a valid value. - "exactOptionalPropertyTypes": true, - // Report an error for unreachable code instead of just a warning. - "allowUnreachableCode": false, - // Report an error for unused labels instead of just a warning. - "allowUnusedLabels": false, - "baseUrl": ".", - "paths": { - "@/*": ["./src/*"] - } - }, - "exclude": ["dist"] + "compilerOptions": { + // Enable top-level await, and other modern ESM features. + "target": "ESNext", + "module": "NodeNext", + // Enable module resolution without file extensions on relative paths, for things like npm package imports. + "moduleResolution": "nodenext", + // Allow importing TypeScript files using their native extension (.ts(x)). + "allowImportingTsExtensions": true, + // Enable JSON imports. + "resolveJsonModule": true, + // Enforce the usage of type-only imports when needed, which helps avoiding bundling issues. + "verbatimModuleSyntax": true, + // Ensure that each file can be transpiled without relying on other imports. + // This is redundant with the previous option, however it ensures that it's on even if someone disable `verbatimModuleSyntax` + "isolatedModules": true, + // Astro directly run TypeScript code, no transpilation needed. + "noEmit": true, + // Report an error when importing a file using a casing different from another import of the same file. + "forceConsistentCasingInFileNames": true, + // Properly support importing CJS modules in ESM + "esModuleInterop": true, + // Skip typechecking libraries and .d.ts files + "skipLibCheck": true, + // Allow JavaScript files to be imported + "allowJs": true, + // Allow JSX files (or files that are internally considered JSX, like Astro files) to be imported inside `.js` and `.ts` files. + "jsx": "preserve", + // Enable strict mode. This enables a few options at a time, see https://www.typescriptlang.org/tsconfig#strict for a list. + "strict": true, + // Report errors for fallthrough cases in switch statements + "noFallthroughCasesInSwitch": true, + // Force functions designed to override their parent class to be specified as `override`. + "noImplicitOverride": true, + // Force functions to specify that they can return `undefined` if a possible code path does not return a value. + "noImplicitReturns": true, + // Report an error when a variable is declared but never used. + "noUnusedLocals": true, + // Report an error when a parameter is declared but never used. + "noUnusedParameters": true, + // Force the usage of the indexed syntax to access fields declared using an index signature. + "noUncheckedIndexedAccess": true, + // Report an error when the value `undefined` is given to an optional property that doesn't specify `undefined` as a valid value. + "exactOptionalPropertyTypes": true, + // Report an error for unreachable code instead of just a warning. + "allowUnreachableCode": false, + // Report an error for unused labels instead of just a warning. + "allowUnusedLabels": false, + "baseUrl": ".", + "paths": { + "@/*": ["./src/*"] + } + }, + "exclude": ["dist"] } diff --git a/tsdown.config.ts b/tsdown.config.ts index 2606886..8dea0e2 100644 --- a/tsdown.config.ts +++ b/tsdown.config.ts @@ -1,19 +1,19 @@ -import { defineConfig } from "tsdown"; -import { peerDependencies } from "./package.json" with { type: "json" }; +import { defineConfig } from 'tsdown' +import { peerDependencies } from './package.json' with { type: 'json' } export default defineConfig((options) => { - const dev = !!options.watch; - return { - entry: ["src/**/*.(ts|js)"], - format: ["esm"], - target: "node24", - unbundle: true, - dts: true, - sourcemap: true, - clean: true, - splitting: false, - minify: !dev, - external: [...Object.keys(peerDependencies)], - tsconfig: "tsconfig.json", - }; -}); + const dev = !!options.watch + return { + entry: ['src/**/*.(ts|js)'], + format: ['esm'], + target: 'node24', + unbundle: true, + dts: true, + sourcemap: true, + clean: true, + splitting: false, + minify: !dev, + external: [...Object.keys(peerDependencies)], + tsconfig: 'tsconfig.json', + } +})