Skip to content

feat(apps/demo): use @objectql/driver-turso instead of memory driver#432

Merged
hotlong merged 8 commits intomainfrom
copilot/use-objectql-driver-turso
Mar 21, 2026
Merged

feat(apps/demo): use @objectql/driver-turso instead of memory driver#432
hotlong merged 8 commits intomainfrom
copilot/use-objectql-driver-turso

Conversation

Copy link
Contributor

Copilot AI commented Mar 21, 2026

  • Update apps/demo/objectstack.config.ts — use createTursoDriver from @objectql/driver-turso with MemoryDriver fallback
  • Update apps/demo/api/[[...route]].ts — replace InMemoryDriver with Turso driver (env-aware), keep memory fallback
  • Update apps/demo/package.json — add @objectql/driver-turso, @libsql/client, nanoid devDependencies
  • Update apps/demo/scripts/build-vercel.sh — include @objectql/driver-turso in the drivers build step
  • Update apps/demo/README.md — document Turso env vars and architecture changes
  • Update CHANGELOG.md — add entry for the driver switch
  • Build and verify changes compile
  • Fix: add @libsql/client and nanoid as explicit devDependencies
  • Fix: add @libsql/client and its full transitive dependency tree to vercel.json includeFiles — nft traces ESM but compiled CJS needs lib-cjs/
  • Fix: add @libsql/client transitive deps as explicit devDependencies for Vercel bundling
  • Fix: TURSO_SYNC_INTERVAL parsing — use Number.isFinite() to preserve 0 (manual-only sync)
  • Fix: remove as any type casts — use connect?.() and remove unnecessary DriverPlugin cast
  • Fix: README architecture diagram — show conditional driver choice (TursoDriver / InMemoryDriver)
  • Fix: vercel.json includeFiles — single string (165 chars, under 256 limit) with scope-level wildcards
  • Fix: add ws, cross-fetch, node-fetch — missing transitive deps of @libsql/hrana-client / @libsql/isomorphic-ws
  • Security scan — no vulnerabilities found in new dependencies

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@vercel
Copy link

vercel bot commented Mar 21, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
objectql Ready Ready Preview, Comment Mar 21, 2026 11:57am
objectql-demo Ready Ready Preview, Comment Mar 21, 2026 11:57am

Request Review

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 AI changed the title [WIP] Update Vercel app to use @objectql/driver-turso feat(apps/demo): use @objectql/driver-turso instead of memory driver Mar 21, 2026
Copilot AI requested a review from hotlong March 21, 2026 08:07
@hotlong hotlong marked this pull request as ready for review March 21, 2026 08:39
Copilot AI review requested due to automatic review settings March 21, 2026 08:39
@hotlong
Copy link
Contributor

hotlong commented Mar 21, 2026

@copilot Cannot find module '@libsql/client'
Require stack:

  • /var/task/apps/demo/node_modules/@objectql/driver-turso/dist/turso-driver.js
  • /var/task/apps/demo/node_modules/@objectql/driver-turso/dist/index.js
    Did you forget to add it to "dependencies" in package.json?
    Node.js process exited with exit status: 1. The logs above can help with debugging the issue.
    Cannot find module '@libsql/client'
    Require stack:
  • /var/task/apps/demo/node_modules/@objectql/driver-turso/dist/turso-driver.js
  • /var/task/apps/demo/node_modules/@objectql/driver-turso/dist/index.js
    Did you forget to add it to "dependencies" in package.json?
    Node.js process exited with exit status: 1. The logs above can help with debugging the issue.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines +43 to +49
return createTursoDriver({
url: tursoUrl,
authToken: process.env.TURSO_AUTH_TOKEN,
syncUrl,
sync: syncUrl
? {
intervalSeconds: Number(process.env.TURSO_SYNC_INTERVAL) || 60,
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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,

Copilot uses AI. Check for mistakes.
Comment on lines +85 to +89
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();
}
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +295 to +300
sync: syncUrl
? {
intervalSeconds: Number(process.env.TURSO_SYNC_INTERVAL) || 60,
onConnect: true,
}
: undefined,
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +302 to +305
// 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.');
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
ObjectStack Kernel
(ObjectQL + Auth +
InMemoryDriver)
TursoDriver)
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
TursoDriver)
TursoDriver / InMemoryDriver)

Copilot uses AI. Check for mistakes.
…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
Copy link
Contributor Author

Copilot AI commented Mar 21, 2026

@copilot Cannot find module '@libsql/client'
Require stack:

  • /var/task/apps/demo/node_modules/@objectql/driver-turso/dist/turso-driver.js...

Added @libsql/client (^0.17.2) and nanoid (^3.3.11) as explicit devDependencies in apps/demo/package.json. Since @objectql/driver-turso is a workspace:* package, its transitive deps bypass pnpm's .pnpm virtual store and aren't discovered by patch-symlinks.cjs Phase 1. Fixed in d2c37c5.

@hotlong
Copy link
Contributor

hotlong commented Mar 21, 2026

@copilot Cannot find module '/var/task/apps/demo/node_modules/@libsql/client/lib-cjs/node.js'
Did you forget to add it to "dependencies" in package.json?
Node.js process exited with exit status: 1. The logs above can help with debugging the issue.
Cannot find module '/var/task/apps/demo/node_modules/@libsql/client/lib-cjs/node.js'
Did you forget to add it to "dependencies" in package.json?
Node.js process exited with exit status: 1. The logs above can help with debugging the issue.

@hotlong
Copy link
Contributor

hotlong commented Mar 21, 2026

@copilot 继续

Copy link
Contributor Author

Copilot AI commented Mar 21, 2026

@copilot 继续

Fixed in 37016be. The lib-cjs/node.js was missing because Vercel's nft traces ESM paths (lib-esm/) but the compiled @objectql/driver-turso uses CJS require() which resolves to lib-cjs/node.js via conditional exports. Changes:

  1. vercel.json includeFiles — added @libsql scope, libsql, @neon-rs, detect-libc, js-base64, promise-limit, nanoid to force Vercel to bundle both CJS and ESM paths
  2. package.json — added @libsql/client's full transitive dep tree (@libsql/core, @libsql/hrana-client, @libsql/isomorphic-ws, @neon-rs/load, detect-libc, js-base64, libsql, promise-limit) as explicit devDependencies
  3. Also addressed review comments: fixed TURSO_SYNC_INTERVAL parsing (preserves 0), removed as any casts, updated README diagram

@github-actions
Copy link
Contributor

⚠️ No Changeset Found

This PR does not include a changeset file.
If this PR includes user-facing changes, please add a changeset by running:

pnpm changeset

@hotlong
Copy link
Contributor

hotlong commented Mar 21, 2026

@copilot The vercel.json schema validation failed with the following message: functions.api/**/*.ts.includeFiles should NOT be longer than 256 characters

…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
@vercel
Copy link

vercel bot commented Mar 21, 2026

Deployment failed with the following error:

The `vercel.json` schema validation failed with the following message: `functions.api/**/*.ts.includeFiles` should be string

Learn More: https://vercel.com/docs/concepts/projects/project-configuration

Copy link
Contributor Author

Copilot AI commented Mar 21, 2026

@copilot The vercel.json schema validation failed with the following message: functions.api/**/*.ts.includeFiles should NOT be longer than 256 characters

Fixed in 138eccd. Converted includeFiles from a single brace-expanded glob (373 chars) to an array of 12 individual patterns (longest is 54 chars). Vercel's schema validates each array element independently, so this stays well within the 256-character limit.

@hotlong
Copy link
Contributor

hotlong commented Mar 21, 2026

@copilot The vercel.json schema validation failed with the following message: functions.api/**/*.ts.includeFiles should be string

…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
Copy link
Contributor Author

Copilot AI commented Mar 21, 2026

@copilot The vercel.json schema validation failed with the following message: functions.api/**/*.ts.includeFiles should be string

Fixed in 477a1b2. Converted includeFiles back to a single string using scope-level wildcards (@objectql/*/dist instead of listing each package individually). The resulting glob is 139 characters — well under the 256-char limit:

node_modules/{@object-ui/*/dist,@objectstack/*/dist,@objectql/*/dist,@libsql,@neon-rs,libsql,detect-libc,js-base64,promise-limit,nanoid}/**

@hotlong
Copy link
Contributor

hotlong commented Mar 21, 2026

@copilot Cannot find module '/var/task/apps/demo/node_modules/ws/index.js'
Did you forget to add it to "dependencies" in package.json?
Node.js process exited with exit status: 1. The logs above can help with debugging the issue.
Cannot find module '/var/task/apps/demo/node_modules/ws/index.js'
Did you forget to add it to "dependencies" in package.json?
Node.js process exited with exit status: 1. The logs above can help with debugging the issue.

…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
Copy link
Contributor Author

Copilot AI commented Mar 21, 2026

@copilot Cannot find module '/var/task/apps/demo/node_modules/ws/index.js'
Did you forget to add it to "dependencies" in package.json?
Node.js process exited with exit status: 1. The logs above can ...

Fixed in cd08385. Added ws (^8.19.0), cross-fetch (^4.1.0), and node-fetch (^2.7.0) as explicit devDependencies and to the vercel.json includeFiles glob. These are transitive deps of @libsql/isomorphic-ws and @libsql/hrana-client that Vercel's nft misses because they're resolved through conditional exports at runtime.

@hotlong hotlong merged commit bf91b0d into main Mar 21, 2026
4 checks passed
@hotlong hotlong deleted the copilot/use-objectql-driver-turso branch March 21, 2026 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants