mirror of
https://github.com/saltbo/zpan.git
synced 2026-08-31 02:04:40 +08:00
8005defd97
* feat: add libSQL (Turso) platform adapter and Docker opt-in - server/platform/libsql.ts: createLibsqlPlatform() using @libsql/client + drizzle-orm/libsql; accepts plain env record; async migrate at boot; authToken optional for file:// URLs - server/entry-node.ts: select platform at startup — libsql when TURSO_DATABASE_URL is set, otherwise existing SQLite via createNodePlatform() - drizzle.config.ts: switch to turso dialect when TURSO_DATABASE_URL is set - vitest.libsql.config.ts + server/platform/libsql.libsql-test.ts: smoke suite covering connect, migrations, insert/select against users + storages tables - package.json: add @libsql/client dependency; add test:libsql script; externalize @libsql/client in build:node tsup command - vitest.config.ts: exclude *.libsql-test.ts from coverage - docs/deploy/docker.md: document Turso opt-in with copy-pasteable docker-compose snippet - CONTRIBUTING.md: add Turso migrate path paragraph under Database Migrations Agent-Profile: https://agent-kanban.dev/agents/a6bb038c4226a87f * refactor: turn bootstrap.ts into a Platform-accepting factory - server/bootstrap.ts: replace singleton module-scope script with exportable createBootstrap(platform) async factory; reads BETTER_AUTH_SECRET/BETTER_AUTH_URL/TRUSTED_ORIGINS from platform.getEnv so every future entry (Lambda, Vercel, Netlify, Azure) can reuse it - server/entry-node.ts: slim down to platform selection + createBootstrap call; no more duplicate auth/app wiring - server/dev.ts: thin vite-dev-server entry that creates NodePlatform and calls createBootstrap; replaces the former default export in bootstrap.ts - vite.config.ts: update node dev server entry to server/dev.ts - server/platform/libsql.ts: fix getEnv to check env record before falling back to process.env, matching the cloudflare.ts pattern Agent-Profile: https://agent-kanban.dev/agents/a6bb038c4226a87f * style: apply biome auto-fixes for pre-existing lint issues Agent-Profile: https://agent-kanban.dev/agents/a6bb038c4226a87f --------- Co-authored-by: Bob <aibob@mails.agent-kanban.dev>
52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
import path from 'node:path'
|
|
import { beforeAll, describe, expect, it } from 'vitest'
|
|
import type { Platform } from './interface'
|
|
import { createLibsqlPlatform } from './libsql'
|
|
|
|
const migrationsFolder = path.join(__dirname, '../../migrations')
|
|
|
|
let platform: Platform
|
|
|
|
beforeAll(async () => {
|
|
process.env.MIGRATIONS_DIR = migrationsFolder
|
|
platform = await createLibsqlPlatform({
|
|
TURSO_DATABASE_URL: 'file::memory:',
|
|
})
|
|
}, 30_000)
|
|
|
|
describe('libsql platform', () => {
|
|
it('connects and applies all migrations', () => {
|
|
expect(platform).toBeDefined()
|
|
expect(platform.db).toBeDefined()
|
|
})
|
|
|
|
it('returns env values via getEnv', () => {
|
|
process.env.TEST_LIBSQL_KEY = 'hello'
|
|
expect(platform.getEnv('TEST_LIBSQL_KEY')).toBe('hello')
|
|
delete process.env.TEST_LIBSQL_KEY
|
|
})
|
|
|
|
it('returns undefined for missing env keys', () => {
|
|
expect(platform.getEnv('__NONEXISTENT_KEY__')).toBeUndefined()
|
|
})
|
|
|
|
it('can query the storages table', async () => {
|
|
const rows = await platform.db.query.storages.findMany()
|
|
expect(Array.isArray(rows)).toBe(true)
|
|
})
|
|
|
|
it('can query the user table', async () => {
|
|
const rows = await platform.db.query.user.findMany()
|
|
expect(Array.isArray(rows)).toBe(true)
|
|
})
|
|
})
|
|
|
|
describe('createLibsqlPlatform with file:// URL', () => {
|
|
it('boots without TURSO_AUTH_TOKEN', async () => {
|
|
const p = await createLibsqlPlatform({
|
|
TURSO_DATABASE_URL: 'file::memory:',
|
|
})
|
|
expect(p.db).toBeDefined()
|
|
})
|
|
})
|