feat(apps/demo): use @objectql/driver-turso instead of memory driver#432
feat(apps/demo): use @objectql/driver-turso instead of memory driver#432
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
When TURSO_DATABASE_URL is set, both local dev (objectstack.config.ts) and Vercel serverless (api/[[...route]].ts) use the Turso driver for persistent data. Falls back to MemoryDriver/InMemoryDriver when no Turso env vars are configured. - objectstack.config.ts: environment-aware createDefaultDriver() - api/[[...route]].ts: conditional TursoDriver with connect() lifecycle - package.json: add @objectql/driver-turso workspace dependency - build-vercel.sh: include driver-turso in Vercel build - README.md: document TURSO_* env vars - CHANGELOG.md: add entry for driver switch Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com> Agent-Logs-Url: https://github.com/objectstack-ai/objectql/sessions/2e9116aa-8592-4683-80d3-7ded73f135c5
|
@copilot Cannot find module '@libsql/client'
|
There was a problem hiding this comment.
Pull request overview
Updates apps/demo to support persistent storage by selecting @objectql/driver-turso when TURSO_DATABASE_URL is set, while keeping an in-memory fallback for zero-config local development and deployments without Turso configuration.
Changes:
- Add env-aware driver selection (Turso vs memory) for both local config and Vercel serverless bootstrap.
- Ensure Turso driver is built and included as a workspace dependency for the demo app.
- Document Turso-related environment variables and update changelog entry.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| pnpm-lock.yaml | Adds @objectql/driver-turso workspace link for the demo importer. |
| apps/demo/scripts/build-vercel.sh | Builds @objectql/driver-turso alongside other drivers for Vercel builds. |
| apps/demo/package.json | Adds @objectql/driver-turso to demo dependencies. |
| apps/demo/objectstack.config.ts | Adds createDefaultDriver() env switch and connects driver on start. |
| apps/demo/api/[[...route]].ts | Selects/registers Turso driver when configured and connects before kernel bootstrap. |
| apps/demo/README.md | Documents Turso env vars and updates demo description/architecture notes. |
| CHANGELOG.md | Records the demo driver behavior change and related file updates. |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
apps/demo/objectstack.config.ts
Outdated
| return createTursoDriver({ | ||
| url: tursoUrl, | ||
| authToken: process.env.TURSO_AUTH_TOKEN, | ||
| syncUrl, | ||
| sync: syncUrl | ||
| ? { | ||
| intervalSeconds: Number(process.env.TURSO_SYNC_INTERVAL) || 60, |
There was a problem hiding this comment.
TURSO_SYNC_INTERVAL parsing uses Number(...) || 60, which forces 0 to become 60. The Turso driver config explicitly allows intervalSeconds = 0 (manual-only), so this prevents disabling periodic sync. Parse with an explicit finite-number check and default only when the env var is missing/invalid, while preserving 0.
| return createTursoDriver({ | |
| url: tursoUrl, | |
| authToken: process.env.TURSO_AUTH_TOKEN, | |
| syncUrl, | |
| sync: syncUrl | |
| ? { | |
| intervalSeconds: Number(process.env.TURSO_SYNC_INTERVAL) || 60, | |
| const rawSyncInterval = process.env.TURSO_SYNC_INTERVAL; | |
| const parsedSyncInterval = | |
| rawSyncInterval !== undefined ? Number(rawSyncInterval) : NaN; | |
| const syncIntervalSeconds = Number.isFinite(parsedSyncInterval) | |
| ? parsedSyncInterval | |
| : 60; | |
| return createTursoDriver({ | |
| url: tursoUrl, | |
| authToken: process.env.TURSO_AUTH_TOKEN, | |
| syncUrl, | |
| sync: syncUrl | |
| ? { | |
| intervalSeconds: syncIntervalSeconds, |
apps/demo/objectstack.config.ts
Outdated
| start: async () => { | ||
| // Connect Turso driver if applicable (MemoryDriver.connect() is a no-op) | ||
| if (typeof (defaultDriver as any).connect === 'function') { | ||
| await (defaultDriver as { connect: () => Promise<void> }).connect(); | ||
| } |
There was a problem hiding this comment.
The start hook uses (defaultDriver as any) and a runtime typeof ...connect check, but both MemoryDriver and TursoDriver expose async connect(). Prefer typing defaultDriver against a shared interface/type and calling await defaultDriver.connect() directly to avoid any and keep this type-safe.
| sync: syncUrl | ||
| ? { | ||
| intervalSeconds: Number(process.env.TURSO_SYNC_INTERVAL) || 60, | ||
| onConnect: true, | ||
| } | ||
| : undefined, |
There was a problem hiding this comment.
TURSO_SYNC_INTERVAL parsing uses Number(...) || 60, which forces 0 to become 60. Turso supports intervalSeconds = 0 (manual-only), so this makes it impossible to disable periodic sync via env var. Use an explicit finite-number check and only default when unset/invalid, preserving 0.
apps/demo/api/[[...route]].ts
Outdated
| // DriverPlugin from @objectstack/runtime expects the upstream Driver interface; | ||
| // TursoDriver implements @objectql/types Driver which is structurally compatible. | ||
| await withTimeout(kernel.use(new DriverPlugin(tursoDriver as any, 'turso')), PLUGIN_TIMEOUT_MS, 'DriverPlugin-turso'); | ||
| log('TursoDriver registered.'); |
There was a problem hiding this comment.
Passing tursoDriver as any into DriverPlugin removes type safety and can mask a real interface mismatch between @objectql/types Driver and what @objectstack/runtime expects. Prefer adapting the Turso driver to the expected driver type (e.g., via a small wrapper/adapter with the required surface area) or importing and using the exact Driver type from @objectstack/runtime to ensure compatibility at compile time.
apps/demo/README.md
Outdated
| ObjectStack Kernel | ||
| (ObjectQL + Auth + | ||
| InMemoryDriver) | ||
| TursoDriver) |
There was a problem hiding this comment.
The architecture diagram now shows TursoDriver unconditionally, but this demo still falls back to the in-memory driver when TURSO_DATABASE_URL is not set. Update the diagram to reflect the conditional driver choice (e.g., “TursoDriver / InMemoryDriver”) to keep the docs consistent with the behavior described above.
| TursoDriver) | |
| TursoDriver / InMemoryDriver) |
…cies for Vercel workspace:* packages bypass pnpm's .pnpm virtual store, so their transitive deps are not discovered by patch-symlinks.cjs Phase 1. Add @libsql/client (^0.17.2) and nanoid (^3.3.11) — runtime deps of @objectql/driver-turso — as explicit devDependencies so they are available in node_modules for Vercel bundling. Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com> Agent-Logs-Url: https://github.com/objectstack-ai/objectql/sessions/dcba56f0-451b-4fad-b516-8e636c58947e
Added |
|
@copilot Cannot find module '/var/task/apps/demo/node_modules/@libsql/client/lib-cjs/node.js' |
|
@copilot 继续 |
Fixed in 37016be. The
|
|
|
@copilot The |
…ob exceeded 256-char limit Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com> Agent-Logs-Url: https://github.com/objectstack-ai/objectql/sessions/259b362b-c318-427b-a31b-02f0f6a8467a
|
Deployment failed with the following error: Learn More: https://vercel.com/docs/concepts/projects/project-configuration |
Fixed in 138eccd. Converted |
|
@copilot The |
…evel wildcards to stay under 256 chars Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com> Agent-Logs-Url: https://github.com/objectstack-ai/objectql/sessions/bc5f02b5-94c7-461d-88ad-1b1426c7d9a8
Fixed in 477a1b2. Converted |
|
@copilot Cannot find module '/var/task/apps/demo/node_modules/ws/index.js' |
…nd to vercel.json includeFiles Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com> Agent-Logs-Url: https://github.com/objectstack-ai/objectql/sessions/b6031531-e25c-4d91-b5d7-330a54f53d0c
Fixed in cd08385. Added |
apps/demo/objectstack.config.ts— usecreateTursoDriverfrom@objectql/driver-tursowithMemoryDriverfallbackapps/demo/api/[[...route]].ts— replaceInMemoryDriverwith Turso driver (env-aware), keep memory fallbackapps/demo/package.json— add@objectql/driver-turso,@libsql/client,nanoiddevDependenciesapps/demo/scripts/build-vercel.sh— include@objectql/driver-tursoin the drivers build stepapps/demo/README.md— document Turso env vars and architecture changesCHANGELOG.md— add entry for the driver switch@libsql/clientandnanoidas explicit devDependencies@libsql/clientand its full transitive dependency tree tovercel.jsonincludeFiles— nft traces ESM but compiled CJS needslib-cjs/@libsql/clienttransitive deps as explicit devDependencies for Vercel bundlingNumber.isFinite()to preserve0(manual-only sync)as anytype casts — useconnect?.()and remove unnecessary DriverPlugin castvercel.jsonincludeFiles— single string (165 chars, under 256 limit) with scope-level wildcardsws,cross-fetch,node-fetch— missing transitive deps of@libsql/hrana-client/@libsql/isomorphic-ws✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.