Move _grant's grantee into content, add listGrants()/revoke() (#57)#99
Merged
Conversation
…ke() (#57) grant() stamped the grantee into record.entityId, the field that means "author" everywhere else — the owner creates a grant for Alice, and the record says Alice authored it, an entity who may never have touched the stack. This polluted "everything this entity authored" queries with grants merely naming them, and made hasGrant's -own check resolve to "is the grantee" instead of "authored it" for grant records specifically. GrantContent gains an optional granteeEntityId; grant() writes it there and stops stamping entityId, so a grant record is owner-authored like any other system record it creates. hasGrant() reads content.granteeEntityId instead of record.entityId. No version bump — additive field, no install base yet, per #57. Also promotes the issue's own follow-up comment to landed: listGrants(entityId?) and revoke(entityId, grants) round out the read/undo side of grant management now that the grantee is a queryable content field. revoke() is a soft delete like any other mutation, so an accidental revocation is undeletable the same way. Fixes #57 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KDmUW3oNxPSCLf2ftqaF8q
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.
Summary
Stack.grant()wrote the grantee intorecord.entityId— the field that means "author" everywhere else. The owner creates a grant for Alice, and the record said Alice authored it, even though she may never have touched the stack. Concretely this meant:filter: { entityId: 'alice' }— "everything Alice wrote") returned grants about Alice, not by her.RecordVersion.entityIdinherited the same lie on any future grant edit.hasGrant's-owncheck, applied to a_grantrecord itself, resolved to "is the grantee" rather than "authored it."Changes
GrantContentgains optionalgranteeEntityId?: string. Absent = default grant (unchanged semantics).grant()writes the grantee into content and no longer stampsrecord.entityId— a grant record is now owner-authored like any other system record the owner creates, closing the gap where every grant record violated the "owner records carry no entityId" invariant.hasGrant()readscontent.granteeEntityIdfor the grantee comparison instead ofrecord.entityId._grant@1— additive optional field, no install base yet (per the standing policy this issue itself established).listGrants(entityId?)andrevoke(entityId, grants)round out grant management now that the grantee is a queryable content field.revoke()matches bytypeIdbaseId + action set (the same granularitygrant()writes at) and soft-deletes — an accidental revocation is undeletable like any other mutation.docs/spec.mdGrant section updated:granteeEntityIdin the content shape, the authorship invariant now holding for grant records too, and the newlistGrants()/revoke()API.Test plan
packages/coretypecheck cleanpackages/corelint cleanpackages/coretest suite passing (419/419), including:granttests assertingentityIdis always absent and the grantee lives in contentfilter: { entityId }) no longer picks up grants naming that entityScopedStackfor its named grantee (regression check)listGrants(): no-arg returns all,nullreturns only defaults, a specific entity returns grants naming them plus every default grantrevoke(): exact-match deletion by entity+typeId+action-set, leaves other entities/action-sets/defaults untouched, matches across type-family versions by baseId, soft-delete is undeletableGenerated by Claude Code