88d96857fb
Model the read filter on NextGraph's real ReadCap mechanism instead of an invented per-item grant. Verified in nextgraph-rs: there is no Document type (document = repo); a store is a container repo referencing other repos by RDF overlay; holding a store's cap does NOT grant the repos it contains (each repo needs its own cap; no read-cap inheritance). So the access unit is the DOCUMENT = an item's `@graph`, never the item. - caps.ts: CapRegistry (read/write caps per document NURI + public docs; open/grantRead/grantWrite/makePublic/canRead/canWrite/governsRead/ hasReadPolicy). Replaces access.ts (Grant). - read-filter.ts: filter keeps an item iff its `@graph` document is readable (held cap or public); items with no `@graph` or in an ungoverned document are kept. No injected grantOf — the filter reads `@graph` and consults the registry (automatic, domain-agnostic). - polyfill.ts: getCaps()/resetCaps() replace setGrantOf/getGrantOf; useShape filters only when caps.hasReadPolicy() (else passthrough, no regression). - tests: caps.test.ts (6) + read-filter.test.ts (4), incl. no-inheritance between documents. 10 pass; tsc rc=0. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
18 lines
782 B
TypeScript
18 lines
782 B
TypeScript
/**
|
|
* Wrapped `useShape`: same signature as `@ng-org/orm`. When a read-cap policy is
|
|
* declared, the returned set is a read-filtered VIEW (only items in documents the
|
|
* current user holds a ReadCap for); otherwise it passes the real set through
|
|
* unchanged. At migration the filtering disappears — the broker only delivers
|
|
* authorized documents.
|
|
*/
|
|
|
|
import { getConfig, getCurrentUser, getCaps } from "./polyfill";
|
|
import { makeReadFilteredView } from "./read-filter";
|
|
|
|
export function useShape(shapeType: unknown, scope: unknown): unknown {
|
|
const set = getConfig().useShape(shapeType, scope) as object;
|
|
const caps = getCaps();
|
|
if (!caps.hasReadPolicy()) return set; // no policy configured → passthrough
|
|
return makeReadFilteredView(set, caps, getCurrentUser);
|
|
}
|