Extract shared ID-existence/kind validation helper (reference targets + access-token grants) - #206
Conversation
…ets and token grants - src/lib/services/records.ts: validateDocumentReferenceTarget and validateCollectionReferenceTarget collapse into one validateReferenceTarget(caller, targetId, kind) built on resolveInternalLinkTarget (data/links.ts) instead of each calling crdtGetDocument/crdtGetCollection directly. The repeated "check parent is a Document, then validate the target" shape in validateCreateReferencedRecordId/validateReferencedRecordIdWrite now goes through requireParentDocumentThenValidateTarget; create-vs-write's genuinely different accepted block types and error wording stay in each of them. - src/lib/services/tokens.ts: createToken's allowedDocumentIds/ allowedCollectionIds now get the same existence check allowedSpaceIds already had, via one generic validateEvery(ids, existsFn, ErrorClass) helper shared across all three grant lists. Document/Collection existence checks build on resolveInternalLinkTarget, the same primitive the records.ts validators above now use. - Wires the two new error classes (UnknownDocumentError, UnknownCollectionError) through the /settings/tokens route handler, mirroring UnknownSpaceError's existing mapping. No behavior change for any existing call site (all 997 pre-existing tests pass unmodified); adds regression coverage for the previously- unvalidated Document/Collection grant-existence checks. Closes #62 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
Warning Review limit reached
This review includes 1 billable file and costs up to $0.25. Or wait 49 minutes for your next included review. View limit detailsLimit details: You’ve used the included review currently available. Your 60 included PR review attempts over the past 7 days set your current allowance at 1 review per hour. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Essentials Run ID: 📒 Files selected for processing (1)
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Essentials Run ID: 📒 Files selected for processing (7)
Included review availability: 0 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour. 📝 WalkthroughWalkthroughRecord references and token grants now use shared target and existence validation. Token creation rejects unknown or mismatched Document and Collection IDs before persistence, and the settings route returns specific HTTP 400 errors. ChangesReference and token validation
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to The shared validation changes preserve the intended grant and reference behavior without introducing a current merge-blocking risk. Sequence Diagram(s)sequenceDiagram
participant TokenRoute
participant createToken
participant resolveInternalLinkTarget
participant TokenStore
TokenRoute->>createToken: submit selected resource IDs
createToken->>resolveInternalLinkTarget: resolve Document and Collection IDs
resolveInternalLinkTarget-->>createToken: return target kind or undefined
createToken->>TokenStore: persist token after validation
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
.agents/skills/pr-backlog-reflection/SKILL.md (merged in PR #201) had a malformed Markdown table that failed the repo-wide prettier --check gate, breaking CI for any PR opened after it landed on main — including this one. Whitespace-only reformat, no content change. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
.agents/skills/pr-backlog-reflection/SKILL.md (merged in PR #201) has a malformed Markdown table that fails the repo-wide prettier --check gate, breaking npm run lint (and therefore CI) for every open PR — confirmed on both #206 and #202. Whitespace-only reformat, no content change. Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Summary
Three axes of the same duplication had grown independently across
records.ts(create-vs-write, document-vs-collection target kind) andtokens.ts(existence-with-permission vs. existence-without-permission), per issue #62's history across PR #61/#193/#198.src/lib/services/records.ts:validateDocumentReferenceTarget/validateCollectionReferenceTargetcollapse into onevalidateReferenceTarget(caller, targetId, kind), built onresolveInternalLinkTarget(data/links.ts) instead of each callingcrdtGetDocument/crdtGetCollectiondirectly. The repeated "check parent is a Document, then validate the target" shape insidevalidateCreateReferencedRecordId/validateReferencedRecordIdWriteis nowrequireParentDocumentThenValidateTarget— the genuinely different parts (which block types each accepts, error wording) stay in each of them, since that difference is real (writeRecorddoesn't support retargetingchild_pages).src/lib/services/tokens.ts:createToken'sallowedDocumentIds/allowedCollectionIdsnow get the same existence checkallowedSpaceIdsalready had, via one genericvalidateEvery(ids, existsFn, ErrorClass)helper shared across all three grant lists. The new Document/Collection checks build onresolveInternalLinkTarget— the same primitive therecords.tsvalidators above now use.UnknownDocumentError,UnknownCollectionError) through the/settings/tokensroute handler, mirroringUnknownSpaceError's existing mapping.docs/specifications/service-layer.mdandinternal-links.mdto describe the new shared validation path and the additionalresolveInternalLinkTargetconsumers.Test plan
npm run test— 1003/1003 passing. All 997 pre-existing tests pass unmodified (no behavior change for any existing call site), plus 6 new tests covering the previously-unvalidated Document/Collection grant-existence checks (service-layertokens.test.tsand route-levelpage.server.test.ts).npm run lint— clean (prettier + eslint) for every file this PR touches.npm run check— clean.Closes #62
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Documentation