feat(appkit): add the service-principal typed DatabasePlugin API - #526
Open
ditadi wants to merge 1 commit into
Open
feat(appkit): add the service-principal typed DatabasePlugin API#526ditadi wants to merge 1 commit into
ditadi wants to merge 1 commit into
Conversation
Expose the hardened runtime as one service-principal plugin with typed entity clients, transactions, tagged SQL, and schema-derived declarations in the existing typegen flow. Driver, setup, and unclassified failures are logged with their original cause before the safe error replaces them, so operators can diagnose what the client never sees. Signed-off-by: ditadi <victordperd@gmail.com>
ditadi
requested review from
MarioCadenas and
atilafassina
and removed request for
a team
August 10, 2026 22:25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack
Each PR targets the one above it, so the diff shown here is only the delta on top of #525. Review in order.
What
Turns the runtime from #525 into a plugin you can actually use.
database({ schema })publishes one typed client per table, plus transactions and parameterized SQL, and the existing typegen flow learns to derive the declarations that make all of it typed from the schema file alone.This is the first PR in the series with an exported surface. The plugin runs as the app's service principal and registers no HTTP routes — generated CRUD arrives in the next PR, so everything here is reachable only from server code you write.
Changes
The plugin (
plugins/database/)database({ schema })binds one plugin instance to one finalized schema.lifecycle.tsowns setup: it validates the schema, builds the Lakebase pool, and publishes the export surface only once it is ready. Setup is single-flight, and a failure ends the pool rather than leaving a half-open plugin.EntityClientwith a chainable read side —where,order,select,include,limit,offset, terminated bytoArray,first,find, orcount— and the keyed writescreate,update,upsert, anddelete. Every call goes through theDataPathfrom feat(appkit): add the database runtime and harden its schema builder #525, so the bounds, the parameterization, and the private-column projection hold here by construction.transaction(cb)hands the callback a client bound to that transaction; the taggedsqltemplate is available both at the top level and inside a transaction, and interpolates values only.defaults.ts): neither retries, and mutations are never cached.Errors (
database/errors.ts)DatabasePluginErrormaps a small closed set of categories onto stable status codes and client messages. A driver error never reaches the caller: it is classified, and the original is logged with its SQLSTATE before the safe error replaces it. The same is true for schema-validation and setup failures, so an operator can diagnose what the client is deliberately not shown.Schema-derived types (
type-generator/database/)walk-schema.tswalks a finalized schema andgenerate.tsrenders it intoappkit-types/database.d.ts, which augments theDatabaseRegistryinterface. That is what makesappkit.database.notesknow its own columns, filters, and relations. The generator loads the schema file throughjiti(pinned at 2.6.1), so a TypeScript schema needs no build step first.It is wired into both existing entry points — the Vite plugin regenerates on change during development, and
appkit generate-typesemits it in CI — following the same shape the analytics and serving generators already use.Exports
defineSchema, the column builders, anddatabaseare exported from@databricks/appkit/beta;DatabaseRegistryis exported from the root so the generated declaration file can augment it.Verification
pnpm vitest run— 4057 passing, 1 skipped; the new suites cover the plugin lifecycle, the entity client, the generated types, and the schema walkerpnpm -r typecheck— clean across all packagespnpm run generate:types,pnpm run sync:template, andpnpm run docs:buildproduce no driftpnpm install --frozen-lockfile—jitiadds 3 lines to the lockfile and nothing else