Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/style.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ With `verbatimModuleSyntax`, a type is imported with `import type` or
- **Many subjects are written at once.** A write of many subjects to a
dataset sets them with `setThings` or one edit (`editOf` in
[datasetEdit.ts](../packages/solid/src/datasetEdit.ts)), and takes
them out with `removeThings`. A `setThing` or `removeThing` at each
copies the whole document every time. A subject's many values for one
property are set in one call of its builder (`setIriAll`,
`setStringAll`), not an add or a remove at each, which copies the
values so far.
them out with `removeThings`. Setting or removing the subjects one
call at a time copies the whole document every time. A subject's
many values for one property are set in one call of its builder
(`setIriAll`, `setStringAll`), not an add or a remove at each, which
copies the values so far.
- **Avoid `any`**, and use a non-null assertion (`!`) only where the code
has checked the value right before, or in a test.
- **Tests** sit beside their module, as `name.test.ts`, and keep every
Expand Down
2 changes: 1 addition & 1 deletion docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,7 @@ Dependency inversion gives every layer a seam for its fakes:

| Layer | Seam | Technique |
|---|---|---|
| Domain | none needed | Pure functions; inputs (including `now: Date`) passed as parameters. Plain assertions. What runs over a whole deck or log is timed at two sizes in its own process's CPU time: eight times the input must take under four times as long as an eighth of it done eight times (a linear pass gives about one, work growing with the input about eight). The growth tests (`growth` in `src/testing/growth.ts`, `growthAsync` for work that awaits, `growthAfterSetup` for work that changes what it works on, set up afresh before each run and not timed) time `queryCards` over 5,000 cards, `lapseIndex`, `chainIndexOf` and `statisticsOf` over years of answers, `instanceGraphOf` over an instance's cards and answers and over a document thousands of folders deep, a course's outline (`courseOutlineFromRecords`) over its chapters and steps, the learner's progress in it (`courseProgress`) over a chapter's steps, the release check's course rules (`courseProblems`), a draft's outline (`draftOutline`) over the chapters and steps, a draft's cards with their wrong options, as the Studio's outline and its step, chapter and question pages show them (`draftCardOf`), over many cards and many wrong options of one card, and the changes to a card's many wrong options (`distractorChanges`), the deck health's cards that say the same (`duplicateCardsOf`) over many cards alike, a JSON-LD copy (`jsonLdOf` in `solid`) over many values of one property, the search of a Turtle text for its base and prefix declarations (`writeTurtle` in `solid`), the shape check's report on a pod document and its check of a write (`createShaclShapeValidator` in `solid`, over an engine that answers at once) over a catalog's many links that aren't members and many dates it can't read, the notes on a release's making (`makingNotesOf`) over many in one language, a merge of drafts (`mergedDraft`) over many statements of one subject, the blank nodes a removal takes along (`withOnlyTheirBlankNodes` in `solid`) over many of one subject and many subjects naming one, a catalog's decks (`toDecks` in `solid`) and a deck file's refusal (`readDeckFile`) over many decks and agents, a catalog written over many licenses it no longer states (`withCatalog` in `solid`), a deck's cards added from a release, removed and brought to this app's format, one card's many distractors added and changed, a deck removed from a cards document another app wrote in, catalog entries and review states brought to this app's format, review states removed, a day's answers removed, many month summaries dropped from the digest, and many review states' snapshots dropped, decks removed and one deck's unreadable dates dropped by the instance check's repair, against a pod in memory (`importDeck`, `applyCardChanges`, `removeDeck`, `upgradeCards`, `upgradeDecks`, `upgradeReviewStates`, `applyReviewChanges`, `removeDay`, `updateDigest` and `applyRepairs` in `solid`), the repairs planned from a check of many subjects (`planRepair`), a subject's many values set or removed in one call (`setIriAll`, `setStringAll` and `removeLiteralAll`, in the client modules' contract tests), the Studio's graph layout and routes over a deck's cards, and its cut of a label (`drawnLabel`), which must not grow with the label at all, over one millions of characters long. |
| Domain | none needed | Pure functions; inputs (including `now: Date`) passed as parameters. Plain assertions. What runs over a whole deck or log is timed at two sizes in its own process's CPU time: eight times the input must take under four times as long as an eighth of it done eight times (a linear pass gives about one, work growing with the input about eight). The growth tests (`growth` in `src/testing/growth.ts`, `growthAsync` for work that awaits, `growthAfterSetup` for work that changes what it works on, set up afresh before each run and not timed) time `queryCards` over 5,000 cards, `lapseIndex`, `chainIndexOf` and `statisticsOf` over years of answers, `instanceGraphOf` over an instance's cards and answers and over a document thousands of folders deep, a course's outline (`courseOutlineFromRecords`) over its chapters and steps, the learner's progress in it (`courseProgress`) over a chapter's steps, the release check's course rules (`courseProblems`), a draft's outline (`draftOutline`) over the chapters and steps, a draft's cards with their wrong options, as the Studio's outline and its step, chapter and question pages show them (`draftCardOf`), over many cards and many wrong options of one card, and the changes to a card's many wrong options (`distractorChanges`), the deck health's cards that say the same (`duplicateCardsOf`) over many cards alike, a JSON-LD copy (`jsonLdOf` in `solid`) over many values of one property, the search of a Turtle text for its base and prefix declarations (`writeTurtle` in `solid`), the shape check's report on a pod document and its check of a write (`createShaclShapeValidator` in `solid`, over an engine that answers at once) over a catalog's many links that aren't members and many dates it can't read, the notes on a release's making (`makingNotesOf`) over many in one language, a merge of drafts (`mergedDraft`) over many statements of one subject, the blank nodes a removal takes along (`withOnlyTheirBlankNodes` in `solid`) over many of one subject and many subjects naming one, a catalog's decks (`toDecks` in `solid`) and a deck file's refusal (`readDeckFile`) over many decks and agents, a catalog written over many licenses it no longer states (`withCatalog` in `solid`), a deck's cards added from a release, removed and brought to this app's format, one card's many distractors added and changed, a deck removed from a cards document another app wrote in, catalog entries and review states brought to this app's format, review states removed, a day's answers removed, many month summaries dropped from the digest, and many review states' snapshots dropped, decks removed and one deck's unreadable dates dropped by the instance check's repair, and many registrations of an instance renamed and removed in a type index, against a pod in memory (`importDeck`, `applyCardChanges`, `removeDeck`, `upgradeCards`, `upgradeDecks`, `upgradeReviewStates`, `applyReviewChanges`, `removeDay`, `updateDigest`, `applyRepairs`, `renameInstanceRegistrations` and `removeInstanceRegistrations` in `solid`), the repairs planned from a check of many subjects (`planRepair`), a subject's many values set or removed in one call (`setIriAll`, `setStringAll` and `removeLiteralAll`, in the client modules' contract tests), the Studio's graph layout and routes over a deck's cards, and its cut of a label (`drawnLabel`), which must not grow with the label at all, over one millions of characters long. |
| Application | ports | Fake ports are injected (`vi.fn` per method): the fixtures and fake ports in [fakePorts.ts](../packages/application/src/testing/fakePorts.ts), and `NO_PORTS` ([noPorts.ts](../packages/application/src/testing/noPorts.ts)), which other packages' tests spread too, for the ports a test doesn't use. Each slice is tested in its own `<feature>.test.ts`, the stores the slices share in theirs. No module mocking. |
| UI | `UseCases` prop | Screens render with a fake `UseCases`: `makeUseCasesFake` ([useCasesFake.ts](../packages/ui/src/test/useCasesFake.ts)) makes every slice's fake ([test/fakes/](../packages/ui/src/test/fakes/)) in one object, each calling the others through it. A screen that takes a slice (the trial's) can be given that slice's fake alone. Assertions use testing-library queries. Query-dependent components get a fresh `QueryClient` (retries off). |
| Infrastructure mappers | none needed | Pure `Dataset`/`Subject` → domain functions, fed in-memory datasets built with `datasetFrom`/`buildThing` ([datasets.ts](../packages/solid/src/testing/datasets.ts)). |
Expand Down
4 changes: 2 additions & 2 deletions packages/solid-memo-client/src/dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import type { Changes, Dataset, Subject } from "@solid-memo/solid/client/interfa
* - A dataset holds the subjects of its default graph by IRI (`_:label`
* for a blank node), the quads of any named graph as they were read, the
* document it came from, and its edits as a chain of steps (setThing,
* removeThing), each pointing to the one before: changesOf replays them
* when it is asked, so an edit costs only what it changes.
* setThings, removeThings), each pointing to the one before: changesOf
* replays them when it is asked, so an edit costs only what it changes.
*/

const { blankNode, literal, namedNode, quad: makeQuad, defaultGraph } = DataFactory;
Expand Down
19 changes: 11 additions & 8 deletions packages/solid-memo-client/src/rdf.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ describe("getThing and createThing", () => {
});
});

describe("removeThing", () => {
describe("removeThings, of one subject", () => {
const thing = rdf
.buildThing(rdf.createThing({ url: `${URL_}#a` }))
.addStringNoLocale(P, "x")
Expand All @@ -141,7 +141,7 @@ describe("removeThing", () => {
it("removes a subject given as text or as itself, its quads deleted", () => {
const dataset = rdf.withQuads(rdf.datasetAt(URL_), [quadOf(`${URL_}#a`, term("x"))]);
for (const subject of [`${URL_}#a`, thing]) {
const removed = rdf.removeThing(dataset, subject);
const removed = rdf.removeThings(dataset, [subject]);
expect(rdf.isEmptyDataset(removed)).toBe(true);
expect(rdf.changesOf(removed)!.deletions.map((one) => one.object.value)).toEqual(["x"]);
}
Expand All @@ -153,25 +153,28 @@ describe("removeThing", () => {
.addStringNoLocale(P, "x")
.build();
const dataset = rdf.withQuads(rdf.datasetAt(URL_), [quadOf(`${URL_}#a`, term("x"))]);
expect(rdf.isEmptyDataset(rdf.removeThing(dataset, named.url))).toBe(true);
expect(rdf.isEmptyDataset(rdf.removeThing(dataset, named))).toBe(false);
expect(rdf.isEmptyDataset(rdf.removeThings(dataset, [named.url]))).toBe(true);
expect(rdf.isEmptyDataset(rdf.removeThings(dataset, [named]))).toBe(false);
const local = rdf.setThing(rdf.createSolidDataset(), named);
expect(rdf.isEmptyDataset(rdf.removeThing(local, named))).toBe(true);
expect(rdf.isEmptyDataset(rdf.removeThings(local, [named]))).toBe(true);
});

it("changes nothing for a subject the dataset says nothing of", () => {
const dataset = rdf.datasetAt(URL_);
expect(rdf.changesOf(rdf.removeThing(dataset, thing))).toEqual({
expect(rdf.changesOf(rdf.removeThings(dataset, [thing]))).toEqual({
additions: [],
deletions: [],
});
});

it("makes no change of a subject set and then removed, nor of one removed and then set again", () => {
const added = rdf.setThing(rdf.datasetAt(URL_), thing);
expect(rdf.changesOf(rdf.removeThing(added, thing))).toEqual({ additions: [], deletions: [] });
expect(rdf.changesOf(rdf.removeThings(added, [thing]))).toEqual({
additions: [],
deletions: [],
});
const read = rdf.withQuads(rdf.datasetAt(URL_), [quadOf(`${URL_}#a`, term("x"))]);
const back = rdf.setThing(rdf.removeThing(read, thing), thing);
const back = rdf.setThing(rdf.removeThings(read, [thing]), thing);
expect(rdf.changesOf(back)).toEqual({ additions: [], deletions: [] });
});
});
Expand Down
12 changes: 3 additions & 9 deletions packages/solid-memo-client/src/rdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function expectUrl(value: string, what: string): void {
}

/**
* The changes made to a dataset, as setThing and removeThing record
* The changes made to a dataset, as setThings and removeThings record
* them; undefined for a dataset no change was ever made to.
*/
export function changesOf(dataset: Dataset): Changes | undefined {
Expand Down Expand Up @@ -204,15 +204,9 @@ export function setThings<T extends Dataset>(dataset: T, subjects: Iterable<Subj
return updated as unknown as T;
}

/** The dataset without what it said of `subject`, the change recorded (changesOf). */
export function removeThing<T extends Dataset>(dataset: T, subject: string | Subject): T {
return removeThings(dataset, [subject]);
}

/**
* The dataset without what it said of each of `subjects`, as removeThing
* removes one, each change recorded: the subjects are copied once, not
* once a subject.
* The dataset without what it said of each of `subjects`, each change
* recorded: the subjects are copied once, not once a subject.
*/
export function removeThings<T extends Dataset>(
dataset: T,
Expand Down
4 changes: 2 additions & 2 deletions packages/solid/src/client/rdf.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe("propertiesOf, of the library's subjects", () => {
});
});

describe("setThing and removeThing, beside the library's own", () => {
describe("setThing and removeThings, beside the library's own", () => {
/** A dataset's quads and its changes, each as sorted lines. */
const stateOf = (dataset: rdf.Dataset) => {
const lines = (quads: Iterable<Quad>) =>
Expand Down Expand Up @@ -85,7 +85,7 @@ describe("setThing and removeThing, beside the library's own", () => {
.buildThing(rdf.createThing({ name: "n" }))
.addIri(`${EX}p`, a)
.build();
const ours = rdf.removeThing(rdf.setThing(rdf.setThing(read, changed), named), `${URL_}#a`);
const ours = rdf.removeThings(rdf.setThing(rdf.setThing(read, changed), named), [`${URL_}#a`]);
const data = read as unknown as SolidDataset;
const theirs = libraryRemoveThing(
librarySetThing(librarySetThing(data, changed as never), named as never),
Expand Down
14 changes: 5 additions & 9 deletions packages/solid/src/client/rdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export type {
} from "./interface";

/**
* The changes made to a dataset, as setThing and removeThing record
* The changes made to a dataset, as setThings and removeThings record
* them; undefined for a dataset no change was ever made to.
*/
export function changesOf(dataset: Dataset): Changes | undefined {
Expand Down Expand Up @@ -219,11 +219,6 @@ export function setThing<T extends Dataset>(dataset: T, subject: Subject): T {
return setThings(dataset, [subject]);
}

/** The dataset without what it said of `subject`, the change recorded (changesOf), as removeThings removes one. */
export function removeThing<T extends Dataset>(dataset: T, subject: string | Subject): T {
return removeThings(dataset, [subject]);
}

/**
* The dataset with each of `subjects` set in turn, as setThing sets one,
* each change recorded (changesOf). The library's setThing copies the
Expand All @@ -248,9 +243,10 @@ export function setThings<T extends Dataset>(dataset: T, subjects: Iterable<Subj
}

/**
* The dataset without what it said of each of `subjects`, as removeThing
* removes one, each change recorded (changesOf): in time that grows with
* the subjects and the dataset, not their product (setThings).
* The dataset without what it said of each of `subjects`, each change
* recorded (changesOf), as the library's removeThing removes one: in
* time that grows with the subjects and the dataset, not their product
* (setThings).
*/
export function removeThings<T extends Dataset>(
dataset: T,
Expand Down
4 changes: 2 additions & 2 deletions packages/solid/src/datasets.patch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
datasetFromQuads,
getThing,
localNameOf,
removeThing,
removeThings,
setThing,
toRdfJsDataset,
withQuads,
Expand Down Expand Up @@ -58,7 +58,7 @@ function edit(before: Quad[], after: Quad[]): Dataset {
);
for (const id of ids) {
const subject = getThing(next, id);
dataset = subject === null ? removeThing(dataset, id) : setThing(dataset, subject);
dataset = subject === null ? removeThings(dataset, [id]) : setThing(dataset, subject);
}
return dataset;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/solid/src/mappers/deckMapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
getThingAll,
getUrlAll,
type NamedSubject,
removeThing,
removeThings,
setThing,
setThings,
type SubjectBuilder,
Expand Down Expand Up @@ -862,7 +862,7 @@ describe("the catalog node", () => {
expect(typeOf(dataset, CC0)).toEqual([DCTERMS.LicenseDocument]);

// One another app stated without describing it: nothing to let go of.
dataset = removeThing(withCatalog(dataset, CATALOG, { ...catalog, license: BY }), BY);
dataset = removeThings(withCatalog(dataset, CATALOG, { ...catalog, license: BY }), [BY]);
dataset = withCatalog(dataset, CATALOG, catalog);
expect(typeOf(dataset, BY)).toBeNull();
expect(toCatalog(dataset, CATALOG)).toEqual(catalog);
Expand Down Expand Up @@ -935,7 +935,7 @@ describe("the catalog node", () => {
const untyped = buildThing(node).removeUrl(RDF.type, DCTERMS.LicenseDocument).build();
updated =
getPropertyAll(untyped).length === 0
? removeThing(updated, license)
? removeThings(updated, [license])
: setThing(updated, untyped);
}
if (catalog.license !== undefined) {
Expand Down
13 changes: 7 additions & 6 deletions packages/solid/src/solidRepairRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,13 @@ const MEMBERSHIP = [
* The document with its repairs applied in turn, each to the subject as
* the repairs before it left it, in one edit of the document (editOf)
* and one removal of the subjects removed (removeThings): many repairs
* take time that grows with them and the document, where a setThing or
* removeThing at each would copy the whole document every time, in the
* square of its subjects. A removal makes the other apps' subjects be
* found again at the next drop-dangling-members repair, so the two
* kinds alternating in one call take longer; the instance check never
* plans a removal, and each removal the user confirms comes alone.
* take time that grows with them and the document, where setting or
* removing the subjects one call at a time would copy the whole document
* every time, in the square of its subjects. A removal makes the other
* apps' subjects be found again at the next drop-dangling-members
* repair, so the two kinds alternating in one call take longer; the
* instance check never plans a removal, and each removal the user
* confirms comes alone.
*/
function repaired(dataset: Dataset, documentUrl: string, repairs: readonly Repair[]): Dataset {
const edit = editOf(dataset);
Expand Down
Loading
Loading