Skip to content

feat(miniflare): Add implementation for local explorer D1 API#12208

Closed
NuroDev wants to merge 30 commits intomainfrom
NuroDev/local-explorer-d1-api
Closed

feat(miniflare): Add implementation for local explorer D1 API#12208
NuroDev wants to merge 30 commits intomainfrom
NuroDev/local-explorer-d1-api

Conversation

@NuroDev
Copy link
Copy Markdown
Member

@NuroDev NuroDev commented Jan 28, 2026

This PR follows on from #12152 and adds a D1 compatible API to the local explorer API worker. That includes adding the following endpoints with their respective handling logic:

  • GET /d1/database - Returns a list of D1 databases.
  • GET /d1/database/{database_id} - Returns the specified D1 database.
  • POST /d1/database/{database_id}/raw - Returns the query result rows as arrays rather than objects.

  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: Experimental WIP project

A picture of a cute animal (not mandatory, but encouraged)

Screenshot 2026-01-28 at 3 22 30 pm

@NuroDev NuroDev self-assigned this Jan 28, 2026
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jan 28, 2026

🦋 Changeset detected

Latest commit: 62994d5

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jan 28, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@12208

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@12208

miniflare

npm i https://pkg.pr.new/miniflare@12208

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@12208

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@12208

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@12208

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@12208

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@12208

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@12208

wrangler

npm i https://pkg.pr.new/wrangler@12208

commit: d4eccb8

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Jan 28, 2026

Claude encountered an error —— View job


Changeset Review

Reviewing changeset file for this PR...

Todo List:

  • Read changeset guidelines
  • Read the changeset file
  • Validate changeset content
  • Check for cute animal image
  • Post findings

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This change might be a bit overkill for the fixture. Happy to revert if needed.

Comment on lines +32 to +37
"migrations": [
{
"new_sqlite_classes": ["MyDurableObject"],
"tag": "v1",
},
],
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Running the fixture just complained about this so may as well fix this now.

Comment on lines +1099 to +1110
if (!innerBinding || !("service" in innerBinding))
throw new MiniflareCoreError(
"ERR_INVALID_WRAPPED",
"No or invalid inner binding service property"
);

const databaseId = innerBinding.service?.name?.replace("d1:db:", "");
if (!databaseId)
throw new MiniflareCoreError(
"ERR_INVALID_WRAPPED",
"No inner binding service database ID"
);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I am uncertain about the error handling for this. Checking out USER_ERROR_CODES and SYSTEM_ERROR_CODES nothing really seems to fit this error. Do we want to throw here or just skip the D1 binding in question?

const IDToBindingName: { kv: Record<string, string> } = { kv: {} };
// Maps binding names to their actual resource IDs
const IDToBindingName: {
d1: Record<string, string>;
Copy link
Copy Markdown
Member Author

@NuroDev NuroDev Jan 29, 2026

Choose a reason for hiding this comment

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

I would have preferred to make this into a Map but TIL that JSON.stringify cannot serialise a nested Map without explicitly transforming it. For example:

JSON.stringify({ d1: new Map([ ['foo', 1] ]) })
// '{ "d1": {} }'
JSON.stringify({ d1: Object.fromEntries(new Map([ ['foo', 1] ])) })
// '{ "d1": { "foo": 1 } }'

@NuroDev NuroDev force-pushed the NuroDev/local-explorer-d1-api branch from d4eccb8 to 8d40724 Compare January 29, 2026 13:41
@NuroDev NuroDev closed this Jan 29, 2026
@github-project-automation github-project-automation Bot moved this from Untriaged to Done in workers-sdk Jan 29, 2026
@NuroDev NuroDev deleted the NuroDev/local-explorer-d1-api branch January 29, 2026 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants