feat!: useShapeQuery prend le Scope du SDK, et un store se nomme par sa reference

This commit is contained in:
Sylvain Duchesne
2026-09-16 16:47:09 +02:00
parent ee9319f89b
commit d0ca5c5d41
31 changed files with 812 additions and 291 deletions
@@ -32,8 +32,9 @@ import { test, expect, describe, mock, beforeEach } from "bun:test";
import { configure, storeRegistry, readUnion } from "../src/index";
import { configureStoreRegistry } from "../src/shared-wallet/bootstrap";
import { sparqlUpdate } from "../src/surface/docs";
import type { NgLike, Nuri, Scope, UseShapeLike } from "../src/model/types";
import { SESSION, forgetEverything, makeWallet, signIn, type Quad } from "./wallet-fake";
import type { NgLike, Nuri, StoreType, UseShapeLike } from "../src/model/types";
import { listMyEntityDocs } from "../src/shared-wallet/account-registry";
import { SESSION, forgetEverything, makeWallet, signIn, storeOfType, type Quad } from "./wallet-fake";
const SHIM = "urn:ng-eventually:shim";
/** The Main-branch read — "which documents are in this store". */
@@ -74,12 +75,12 @@ function bootPage(quads: Quad[], lostAt: (query: string) => boolean): void {
* Returns the reference she keeps, and the quads the wallet now holds — the durable half
* that outlives the page.
*/
async function aFirstSessionThatCreated(scope: Scope): Promise<{ quads: Quad[]; note: Nuri }> {
async function aFirstSessionThatCreated(scope: StoreType): Promise<{ quads: Quad[]; note: Nuri }> {
const quads: Quad[] = [];
forgetEverything();
bootPage(quads, () => false);
await signIn("alice");
const note = await storeRegistry.createEntityDoc(scope);
const note = await storeRegistry.createEntityDoc(await storeOfType(scope));
await sparqlUpdate(
SESSION.sessionId,
`INSERT DATA { <urn:test:note> <${TITLE}> "the note" }`,
@@ -101,7 +102,7 @@ async function aSecondSessionLosingTheBrokerOn(quads: Quad[], read: string): Pro
armed = true;
}
const ALL_SCOPES: Scope[] = ["public", "protected", "private"];
const ALL_SCOPES: StoreType[] = ["public", "protected", "private"];
beforeEach(() => {
forgetEverything();
@@ -119,7 +120,7 @@ describe("listMyEntityDocs answers a verified listing or surfaces", () => {
bootPage(quads, () => false);
await signIn("alice");
expect(await storeRegistry.listMyEntityDocs(scope)).toContain(note);
expect(await listMyEntityDocs("alice", scope)).toContain(note);
const subjects = await readUnion([note]);
expect(subjects.map((s) => s.props[TITLE]?.[0])).toEqual(["the note"]);
});
@@ -132,10 +133,10 @@ describe("listMyEntityDocs answers a verified listing or surfaces", () => {
const { quads, note } = await aFirstSessionThatCreated(scope);
await aSecondSessionLosingTheBrokerOn(quads, KEY_READ);
await expect(storeRegistry.listMyEntityDocs(scope)).rejects.toThrow(/BrokerError/);
await expect(listMyEntityDocs("alice", scope)).rejects.toThrow(/BrokerError/);
// And the point of the refusal, stated as the caller sees it: nothing came back that
// could be mistaken for "here are your documents".
const answered = await storeRegistry.listMyEntityDocs(scope).catch(() => null);
const answered = await listMyEntityDocs("alice", scope).catch(() => null);
expect(answered).toBeNull();
expect(answered).not.toEqual([note]);
});
@@ -149,8 +150,8 @@ describe("listMyEntityDocs answers a verified listing or surfaces", () => {
const { quads } = await aFirstSessionThatCreated(scope);
await aSecondSessionLosingTheBrokerOn(quads, LISTING_READ);
await expect(storeRegistry.listMyEntityDocs(scope)).rejects.toThrow(/BrokerError/);
const answered = await storeRegistry.listMyEntityDocs(scope).catch(() => null);
await expect(listMyEntityDocs("alice", scope)).rejects.toThrow(/BrokerError/);
const answered = await listMyEntityDocs("alice", scope).catch(() => null);
expect(answered).toBeNull();
expect(answered).not.toEqual([]);
});