Skip to content

feat(database): expose KV connect database id; fix --json stdout discipline#117

Open
tcerqueira wants to merge 3 commits into
mainfrom
tc/database-kv-connect-id
Open

feat(database): expose KV connect database id; fix --json stdout discipline#117
tcerqueira wants to merge 3 commits into
mainfrom
tc/database-kv-connect-id

Conversation

@tcerqueira

Copy link
Copy Markdown
Member

What

Two related improvements to deploy/database.ts:

1. Expose the Deno KV connect database id (closes #106)

database list exposed only the generated clientId and dropped the
per-environment Deno KV connect UUID that agents need to build
Deno.openKv("https://api.deno.com/v2/databases/<id>/connect"). The backend
already returns it per environment as databases[].metadata.td_id.

Now each KV environment in --json includes databaseId and a derived
connectUrl, and the table output gains a DATABASE ID column:

{
  "name": "f89123-production",
  "status": "ready",
  "databaseId": "",
  "connectUrl": "https://api.deno.com/v2/databases/…/connect"
}

Verified live: Deno.openKv against the produced connectUrl (with the org
token as DENO_KV_ACCESS_TOKEN) connects and round-trips set/get/delete.

2. Mutation --json stdout discipline

provision/link/assign/detach/delete printed human text to stdout
and never emitted a JSON result. They now emit a single JSON result via
writeJsonResult on stdout under --json, and route success/status text to
stderr otherwise.

Note on overlap

Sibling PR #105 (issue #104) also edits the link command (option declarations,
--port type, payload key). This PR leaves those untouched and only adds the
JSON/stderr branching around link's success messages — should rebase cleanly.

`database list` dropped the per-environment Deno KV connect database UUID
(metadata.td_id), so agents could not build the
`Deno.openKv("https://api.deno.com/v2/databases/<id>/connect")` URL without
opening the Console UI.

Surface it per KV environment: `--json` now includes `databaseId` and a derived
`connectUrl`, and the table gains a DATABASE ID column.

Closes #106
…ions

provision/link/assign/detach/delete printed human text to stdout and never
emitted a JSON result, breaking stdout discipline under `--json`. They now write
a single JSON result via writeJsonResult on stdout in `--json` mode and route the
success/status text to stderr otherwise.
…sults

provision/link/delete emitted the database name under `name` while
assign/detach used `database`, forcing consumers to special-case the key per
subcommand. Standardize all mutation JSON results on `database`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose Deno KV connect database IDs in database list

1 participant