38 lines
2.3 KiB
TypeScript
38 lines
2.3 KiB
TypeScript
/**
|
|
* Wrapped `useShape`: the same call the SDK's React hook offers, and the same two
|
|
* arguments. Once the cap emulation is in force, what comes back is a read-filtered VIEW
|
|
* over the RESULT ENVELOPE the hook returns - `data` and `promise` carry only items in
|
|
* documents the current holder has the `ReadCap` of, `subscription` is refused, and the
|
|
* page commands and the load state pass through. A member's DESCRIPTOR answers what
|
|
* reading it answers, so the spread and the inspections built on that call read through
|
|
* the view rather than round it. Before the first cap is issued the real
|
|
* result passes through unchanged. At migration the filtering disappears: the broker only
|
|
* delivers documents whose cap the wallet holds.
|
|
*
|
|
* ── What changed on 2026-09-24, and why it was invisible ──────────────────
|
|
* This wrapped the result in the COLLECTION view (`makeReadFilteredView`), which is
|
|
* written for a `DeepSignalSet`. That was right while the hook returned one - `alpha.18` -
|
|
* and wrong the moment `@ng-org/orm@0.1.2-alpha.21` started returning a `UseShapeResult`
|
|
* around it. Against that shape the collection view threw on `[...result]` and `.size`
|
|
* (an envelope is not iterable) and returned `data`, `promise` and `subscription` RAW,
|
|
* each of them every identity's items. Nothing failed, because no fake in this repository
|
|
* returned the shape the SDK ships.
|
|
*/
|
|
|
|
import type { BaseType, ShapeType } from "@ng-org/shex-orm";
|
|
import type { RdfOrmConfig } from "@ng-org/orm/all";
|
|
import { getConfig, getCaps } from "../shared-wallet/bootstrap";
|
|
import { makeReadFilteredShapeResult } from "../emulated-verifier/read-filter";
|
|
import type { ShapeResult } from "../model/types";
|
|
|
|
// @provenance useShape kind=passthrough level=3 ref=sdk/js/orm/src/frontendAdapters/react/useShape.ts:useShape - forwards to the injected real hook, with its two arguments; the read-filtered view over the result envelope emulates cryptographic isolation
|
|
export function useShape<T extends BaseType>(
|
|
shapeType: ShapeType<T>,
|
|
conf: RdfOrmConfig<T> | string | undefined,
|
|
): ShapeResult {
|
|
const result = getConfig().useShape(shapeType, conf);
|
|
const caps = getCaps();
|
|
if (!caps.isEnforcing()) return result; // no cap issued yet → passthrough
|
|
return makeReadFilteredShapeResult(result, caps);
|
|
}
|