refactor(cloudflare): extract list + createAndResolve helpers#2
Draft
Thanukamax wants to merge 1 commit into
Draft
refactor(cloudflare): extract list + createAndResolve helpers#2Thanukamax wants to merge 1 commit into
Thanukamax wants to merge 1 commit into
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
De-duplicate the resource provisioning logic in cloudflare.ts:
- Replace six copies of the verbose
`(await wranglerJson<any[]>([...], { allowFail: true })) ?? []`
list expression with named `listD1()` / `listKv()` helpers.
- Fold the repeated "create -> re-list -> resolve -> throw if missing"
idempotent-create dance (duplicated across ensureD1 and ensureKv)
into a single generic `createAndResolve` helper.
Behavior is unchanged: same wrangler calls, same reuse-vs-create paths,
same single batched KV list per run. Purely a readability/DRY refactor.
typecheck, tests, lint, and build all pass.
d2f2608 to
2670a7f
Compare
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.
What
A targeted DRY refactor of
src/cloudflare.ts— the resource-provisioning module that felt over-complicated.Two repeated patterns are factored out:
List boilerplate (×6). The verbose
(await wranglerJson<any[]>([...], { allowFail: true })) ?? []appeared six times across
ensureD1,ensureKv,deleteD1,deleteKv.Now two named helpers:
listD1()andlistKv().The idempotent create dance (×2).
ensureD1andensureKveachhand-rolled the same "create → re-list → find the new entry → throw if
still missing" sequence. Folded into one generic
createAndResolvehelperthat names the intent.
What did not change
Behavior is identical — same wrangler invocations, same reuse-vs-create
branches, same single batched KV list per run (
ensureKvstill lists onceup front, so no extra API calls). The only user-visible change is error-message
wording (
failed to resolve preview D1 ${name} after createvs the old... id for ${name}) — arguably clearer.Honest take: the rest of the codebase is already clean and modular, so I kept
this surgical rather than inventing a big rewrite.
cloudflare.tsis where thereal duplication lived. Happy to take it further (e.g. the R2 create/delete
symmetry, or a
bindingResourceNamemap) if you want a bigger pass.Verification
bun run typecheck✅bun test✅ (9 pass)bun run lint✅ (pre-existinginfoinsync.tsuntouched)bun run build✅ —dist/index.cjsregenerated and matches the pinnedbun 1.3.14bundler output CI enforces.Draft for your review — flip to ready whenever.