@knkcs/contenthub-ui 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"testing.js","names":["StaleStatusError","NameTakenError","RestrictionUnavailableError","WithheldWorkError","InvalidInputError","ContentArchivedError","CoversReleaseError","CHECK_NOTE_MAX","CheckResultDeniedError","ChangeSetClosedError","inForceOnOrAfter","StatusTransitionRefusedError","StaleHeadError","sameHeads","releaseInForceOn","DAY","AccessDeniedError","headsOf","BlockReasonNameTakenError","ContentBlockedError","PublishRefusedError","GuardianModeRequiredError","ContentRefusedError","STUB_WORKSPACE_ID","STUB_USER_ID","STUB_OTHER_USER_ID","STUB_NOW","stubIdentity","createHostMembers","stubBlockReasons","stubChangeSetStatuses","stubStatusTransitions","stubChangeSets","stubRequiredChecks","stubCollections","stubBlueprints","stubBlueprintReleases","stubResolvedReleases","text","accessor","paragraph","stubRepealedContent","at","stubContents","createStubBlueprintSource","q","query","blueprints","b","ids","releases","r","blueprintId","shiftDay","d","day","by","oneLine","value","raw","what","max","checkedSourceOf","source","checkedBlockReasonName","name","checkedRequiredCheck","input","accessors","a","RECORDERS_WORKSPACE_MODE","WITHHELD_REFUSAL","WORKSPACE_MODE_REFUSAL","notFound","ConnectError","id","Code","copy","cs","stubBlocker","fields","createStubContenthubClient","now","options","userId","statuses","transitions","reasons","changeSets","collections","c","contents","resolved","requiredChecks","authzMode","withheld","refuseWithheld","grants","recorders","recordersOf","checkId","memberIds","admin","checkResults","extraBlockers","pendingMerges","conflicts","stored","wroteUnder","once","key","write","asked","request","kept","answer","publishedWith","savedUnder","next","findContent","each","attributesOf","today","datedContent","revisionsOf","listed","heads","csId","h","dataOf","revisionId","missingRequired","unset","v","f","values","checkEditable","gapReferrersOf","other","e","contentId","byName","taken","except","collectionOrder","findCollection","siblingNamed","parentId","manageable","owns","g","narrowable","saveOnce","chain","open","changeSetId","ch","branchId","branch","expectedHeadId","head","sent","data","saved","fieldMask","stray","k","writeHead","createTime","branchIn","storeMerge","pm","conflict","dropMerge","checkPlan","vp","plan","violations","covered","repropose","previous","p","proposals","propose","same","splitFromReleaseId","its","find","statusName","s","slug","reaches","from","to","seen","subjectsOf","pr","blueprintOf","covers","check","standingsOf","subjects","resultsOn","subject","_","standing","latest","results","stale","out","byNameThenId","blockersOf","current","reviewed","dep","state","st","x","releasesOf","reason","matching","size","start","rawName","checkedSource","updateMask","nextName","nextSource","expectedStatus","status","assigneeIds","target","dependsOnId","published","reviewedHeads","blockers","cut","idempotencyKey","chainId","chains","conflicted","pending","ref","outcome","note","requiredCheckId","recording","named","result","checked","held","recorder","u","restricted","collection","unfiled","acknowledgeDisclosure","collectionId","grantee","level","view","search","rows","readsOf","blueprintReleaseId","copyFrom","sourceRevision","release","n","content","isOpen","found","owner","pageSize","pageToken","_data","all","after","baseId","base","before","changes","strip","page","fromReleases","includeOpenChangeSets","fromBranches","inForce","unique","collectionIds","col","blockReasonId","allowedUserIds","effectiveOn","label","changeSetName","entries","fork","validityPeriod","lastDay","releaseSpec","supersedesReleaseIds","plannedReleaseId","updated","last","tip","paths","resolutions","validOn","entry","plannedRelease","row","matches","hits","fold","needle","createStubStatusSource"],"sources":["../src/testing/fixtures.ts","../src/testing/stub-blueprint-source.ts","../src/testing/stub-client.ts","../src/testing/stub-status-source.ts"],"sourcesContent":["import { createHostMembers, type HostIdentity } from \"@knkcs/anker/host\";\nimport type {\n\tBlockReason,\n\tBlueprintInfo,\n\tBlueprintReleaseInfo,\n\tChangeSet,\n\tChangeSetStatusInfo,\n\tCollection,\n\tContentBlock,\n\tEdge,\n\tPlannedRelease,\n\tRequiredCheck,\n\tResolvedBlueprintRelease,\n\tResolvedField,\n\tRevision,\n\tTimelineEntry,\n} from \"../types\";\n\nexport const STUB_WORKSPACE_ID = \"ws_stub\";\nexport const STUB_USER_ID = \"user_stub\";\n/** A second member of the stub workspace, to assign and filter by. */\nexport const STUB_OTHER_USER_ID = \"user_ben\";\nexport const STUB_NOW = \"2026-10-01T09:00:00.000Z\";\n\n/** Who is looking, for anker's `TestHost` or `<HostProvider identity>`. */\nexport function stubIdentity(): HostIdentity {\n\treturn {\n\t\tuserId: STUB_USER_ID,\n\t\tworkspaceId: STUB_WORKSPACE_ID,\n\t\tmembers: createHostMembers([\n\t\t\t{ userId: STUB_USER_ID, displayName: \"Ada Editor\", email: \"ada@example.com\" },\n\t\t\t{ userId: STUB_OTHER_USER_ID, displayName: \"Ben Reviewer\", email: \"ben@example.com\" },\n\t\t]),\n\t};\n}\n\n/** A legal publisher's Block Reasons, in the service's order (by name). */\nexport function stubBlockReasons(): BlockReason[] {\n\treturn [\n\t\t{\n\t\t\tid: \"br_author\",\n\t\t\tname: \"Being revised by the author\",\n\t\t\tcreateTime: STUB_NOW,\n\t\t\tupdateTime: STUB_NOW,\n\t\t},\n\t\t{\n\t\t\tid: \"br_embargo\",\n\t\t\tname: \"Embargoed until publication\",\n\t\t\tcreateTime: STUB_NOW,\n\t\t\tupdateTime: STUB_NOW,\n\t\t},\n\t];\n}\n\n/**\n * statushub's seed catalogue for `contenthub/change_set` (spec #56, story 9),\n * as the `StatusSource` port answers it. Colours are CSS names: statushub\n * holds whatever CSS colour an admin chose.\n */\nexport function stubChangeSetStatuses(): ChangeSetStatusInfo[] {\n\treturn [\n\t\t{ slug: \"in_progress\", name: \"In Bearbeitung\", color: \"steelblue\" },\n\t\t{ slug: \"in_review\", name: \"In Prüfung\", color: \"orange\" },\n\t\t{ slug: \"ready\", name: \"Bereit\", color: \"seagreen\" },\n\t\t{ slug: \"on_hold\", name: \"Zurückgestellt\", color: \"gray\" },\n\t];\n}\n\n/**\n * The moves the stub's statushub allows, from slug to slugs. Anything else is\n * refused with a reason, as statushub refuses it; a move away from an unknown\n * status is never checked (contenthub ADR 0014).\n */\nexport function stubStatusTransitions(): Record<string, string[]> {\n\treturn {\n\t\tin_progress: [\"in_review\", \"on_hold\"],\n\t\tin_review: [\"in_progress\", \"ready\", \"on_hold\"],\n\t\tready: [\"in_review\", \"on_hold\"],\n\t\ton_hold: [\"in_progress\"],\n\t};\n}\n\n/**\n * A gazette's Change Sets: one open with two Chains (§ 1 amended twice, so\n * two Branches, and a paragraph born in it), one open with nothing in it yet,\n * and one published correction. Newest first, as the service lists them.\n */\nexport function stubChangeSets(): ChangeSet[] {\n\treturn [\n\t\t{\n\t\t\tid: \"cs_bgbl_270\",\n\t\t\tname: \"BGBl. 2026 I Nr. 270\",\n\t\t\tsource: { date: \"2026-09-20\", reference: \"BGBl. 2026 I Nr. 270\" },\n\t\t\tstate: \"open\",\n\t\t\tcreatedBy: STUB_USER_ID,\n\t\t\tcreateTime: \"2026-09-30T08:00:00.000Z\",\n\t\t\tchains: [\n\t\t\t\t{\n\t\t\t\t\tid: \"chain_para_1\",\n\t\t\t\t\tcontentId: \"content_para_1\",\n\t\t\t\t\tborn: false,\n\t\t\t\t\tbranches: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tid: \"br_para_1_a\",\n\t\t\t\t\t\t\tposition: 0,\n\t\t\t\t\t\t\tkind: \"editorial\",\n\t\t\t\t\t\t\theadRevisionId: \"rev_p1_a2\",\n\t\t\t\t\t\t\teffectiveOn: \"2026-07-01\",\n\t\t\t\t\t\t\tcarriedReleaseId: \"rls_p1_1\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tid: \"br_para_1_b\",\n\t\t\t\t\t\t\tposition: 1,\n\t\t\t\t\t\t\tkind: \"editorial\",\n\t\t\t\t\t\t\theadRevisionId: \"rev_p1_b1\",\n\t\t\t\t\t\t\teffectiveOn: \"2026-10-01\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tid: \"chain_para_4a\",\n\t\t\t\t\tcontentId: \"content_para_4a\",\n\t\t\t\t\tborn: true,\n\t\t\t\t\tbranches: [\n\t\t\t\t\t\t{ id: \"br_para_4a\", position: 0, kind: \"editorial\", headRevisionId: \"rev_p4a_1\" },\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t],\n\t\t\tdependsOnChangeSetIds: [],\n\t\t\tstatus: \"in_progress\",\n\t\t\tassigneeIds: [STUB_USER_ID],\n\t\t\tplannedReleases: [\n\t\t\t\t{\n\t\t\t\t\tid: \"rls_p1_2\",\n\t\t\t\t\tcontentId: \"content_para_1\",\n\t\t\t\t\tkind: \"revision\",\n\t\t\t\t\tbranchId: \"br_para_1_b\",\n\t\t\t\t\trevisionId: \"\",\n\t\t\t\t\tvalidityPeriod: { firstDay: \"2026-10-01\", lastDay: \"\" },\n\t\t\t\t\tsupersedesReleaseIds: [],\n\t\t\t\t\tproposed: false,\n\t\t\t\t\tproposedForReleaseId: \"\",\n\t\t\t\t\tsplitFromReleaseId: \"\",\n\t\t\t\t\twithheld: false,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t// The cut ending § 1's Release In Force the day before the\n\t\t\t\t\t// amendment starts: proposed, never planned by hand.\n\t\t\t\t\tid: \"rls_p1_1_cut\",\n\t\t\t\t\tcontentId: \"content_para_1\",\n\t\t\t\t\tkind: \"date_only\",\n\t\t\t\t\tbranchId: \"\",\n\t\t\t\t\trevisionId: \"rev_p1_main\",\n\t\t\t\t\tvalidityPeriod: { firstDay: \"2020-01-01\", lastDay: \"2026-09-30\" },\n\t\t\t\t\tsupersedesReleaseIds: [\"rls_p1_1\"],\n\t\t\t\t\tproposed: true,\n\t\t\t\t\tproposedForReleaseId: \"rls_p1_1\",\n\t\t\t\t\tsplitFromReleaseId: \"\",\n\t\t\t\t\twithheld: false,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tid: \"rls_p4a_1\",\n\t\t\t\t\tcontentId: \"content_para_4a\",\n\t\t\t\t\tkind: \"revision\",\n\t\t\t\t\tbranchId: \"br_para_4a\",\n\t\t\t\t\trevisionId: \"\",\n\t\t\t\t\tvalidityPeriod: { firstDay: \"2026-10-01\", lastDay: \"\" },\n\t\t\t\t\tsupersedesReleaseIds: [],\n\t\t\t\t\tproposed: false,\n\t\t\t\t\tproposedForReleaseId: \"\",\n\t\t\t\t\tsplitFromReleaseId: \"\",\n\t\t\t\t\twithheld: false,\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t\t{\n\t\t\tid: \"cs_bgbl_255\",\n\t\t\tname: \"BGBl. 2026 I Nr. 255\",\n\t\t\tsource: { date: \"2026-09-10\", reference: \"BGBl. 2026 I Nr. 255\" },\n\t\t\tstate: \"open\",\n\t\t\tcreatedBy: STUB_OTHER_USER_ID,\n\t\t\tcreateTime: \"2026-09-25T08:00:00.000Z\",\n\t\t\tchains: [],\n\t\t\tdependsOnChangeSetIds: [],\n\t\t\tstatus: \"\",\n\t\t\tassigneeIds: [STUB_OTHER_USER_ID],\n\t\t\tplannedReleases: [],\n\t\t},\n\t\t{\n\t\t\tid: \"cs_correction_3\",\n\t\t\tname: \"Correction of § 3\",\n\t\t\tstate: \"published\",\n\t\t\tcreatedBy: STUB_USER_ID,\n\t\t\tcreateTime: \"2026-09-01T08:00:00.000Z\",\n\t\t\tcloseTime: \"2026-09-02T08:00:00.000Z\",\n\t\t\tchains: [],\n\t\t\tdependsOnChangeSetIds: [],\n\t\t\tstatus: \"ready\",\n\t\t\tassigneeIds: [],\n\t\t\tplannedReleases: [],\n\t\t},\n\t];\n}\n\n/**\n * A legal publisher's Required Checks, by name: a print round trip once per\n * Change Set, and a lawyer's review of each Branch, by someone who wrote\n * none of it. Both apply to every Blueprint.\n */\nexport function stubRequiredChecks(): RequiredCheck[] {\n\treturn [\n\t\t{\n\t\t\tid: \"rc_print\",\n\t\t\tname: \"Druckprobe\",\n\t\t\tscope: \"change_set\",\n\t\t\tblueprintAccessors: [],\n\t\t\tindependent: false,\n\t\t},\n\t\t{\n\t\t\tid: \"rc_lawyer\",\n\t\t\tname: \"Juristische Prüfung\",\n\t\t\tscope: \"branch\",\n\t\t\tblueprintAccessors: [],\n\t\t\tindependent: true,\n\t\t},\n\t];\n}\n\n/**\n * A legal publisher's Collection tree, by name as the service lists it:\n * Laws holding BGB and StGB, and Commentary beside it.\n */\nexport function stubCollections(): Collection[] {\n\treturn [\n\t\t{ id: \"col_bgb\", name: \"BGB\", parentId: \"col_laws\", restricted: false },\n\t\t{ id: \"col_commentary\", name: \"Commentary\", parentId: \"\", restricted: false },\n\t\t{ id: \"col_laws\", name: \"Laws\", parentId: \"\", restricted: false },\n\t\t{ id: \"col_stgb\", name: \"StGB\", parentId: \"col_laws\", restricted: false },\n\t];\n}\n\n/**\n * The workspace's content Blueprints, as a `BlueprintSource` answers, by\n * name. Commentary has had no Release cut yet, so contenthub's catalog\n * (the stub client's `searchBlueprints`) leaves it out.\n */\nexport function stubBlueprints(): BlueprintInfo[] {\n\treturn [\n\t\t{ id: \"bp_commentary\", name: \"Commentary\" },\n\t\t{ id: \"bp_footnote\", name: \"Footnote\" },\n\t\t{ id: \"bp_paragraph\", name: \"Paragraph\" },\n\t];\n}\n\n/** Their Releases, newest first per Blueprint. */\nexport function stubBlueprintReleases(): BlueprintReleaseInfo[] {\n\treturn [\n\t\t{\n\t\t\tid: \"bpr_paragraph_2\",\n\t\t\tblueprintId: \"bp_paragraph\",\n\t\t\tname: \"2026-10\",\n\t\t\treleaseTime: \"2026-10-01T07:00:00.000Z\",\n\t\t},\n\t\t{\n\t\t\tid: \"bpr_paragraph_1\",\n\t\t\tblueprintId: \"bp_paragraph\",\n\t\t\tname: \"2026-09\",\n\t\t\treleaseTime: \"2026-09-01T07:00:00.000Z\",\n\t\t},\n\t\t{\n\t\t\tid: \"bpr_footnote_1\",\n\t\t\tblueprintId: \"bp_footnote\",\n\t\t\tname: \"2026-08\",\n\t\t\treleaseTime: \"2026-08-01T07:00:00.000Z\",\n\t\t},\n\t];\n}\n\n/** One head of a Content: its Revision, data and when it was written. */\nexport interface StubHead {\n\trevisionId: string;\n\tdata: Record<string, unknown>;\n\t/** ISO 8601. */\n\trevisionCreateTime: string;\n}\n\n/**\n * A Content of the stub workspace, every way the screens can read it. Not a\n * service type: it is what the stub keeps to answer its reads.\n */\nexport interface StubContent {\n\tid: string;\n\tblueprintId: string;\n\tblueprintReleaseId: string;\n\t/** The Collections it is filed in, directly. */\n\tcollectionIds: string[];\n\t/** Who maintains it; none when absent. */\n\tassigneeIds?: string[];\n\t/** Its Block; absent while it is not blocked. */\n\tblock?: ContentBlock;\n\t/** When it was archived, ISO 8601; absent while it is not Archived. */\n\tarchiveTime?: string;\n\t/** Its Main head; absent while it was born in an open Change Set. */\n\tmain?: StubHead;\n\t/** The Release In Force today, and the head it pins; absent for none. */\n\tinForce?: StubHead & { releaseId: string };\n\t/** The head of its Chain's last Branch in each Change Set it is in, by Change Set id. */\n\tbranches: Record<string, StubHead & { branchId: string }>;\n\t/** Its Timeline as known now; none when absent. */\n\ttimeline?: TimelineEntry[];\n\t/** What open (or since closed) Change Sets plan for it, in the order planned. */\n\tplannedReleases?: { changeSetId: string; plannedRelease: PlannedRelease }[];\n\t/** Its Revisions, newest first, beyond what its heads imply; none when absent. */\n\trevisions?: (Revision & { data?: Record<string, unknown> })[];\n\t/** The outgoing edges of its Revisions, each naming the Revision holding it. */\n\tedges?: Edge[];\n}\n\n/**\n * The Resolved Releases contenthub holds for the fixtures' Blueprint\n * Releases, by id, as `getContent` decodes them: a paragraph has a number\n * and a heading, a footnote a text. Both are Dated.\n */\nexport function stubResolvedReleases(): Record<string, ResolvedBlueprintRelease> {\n\tconst text = (accessor: string, name: string): ResolvedField => ({\n\t\tfield_type: \"text\",\n\t\tconfig: { name, api_accessor: accessor, required: false, instructions: \"\" },\n\t\tsystem: false,\n\t});\n\tconst paragraph: ResolvedBlueprintRelease = {\n\t\tdisplayName: \"Paragraph\",\n\t\tdated: true,\n\t\tfields: [text(\"number\", \"Number\"), text(\"heading\", \"Heading\")],\n\t\tparts: {},\n\t};\n\treturn {\n\t\tbpr_paragraph_1: paragraph,\n\t\tbpr_paragraph_2: paragraph,\n\t\tbpr_footnote_1: {\n\t\t\tdisplayName: \"Footnote\",\n\t\t\tdated: true,\n\t\t\tfields: [text(\"text\", \"Text\")],\n\t\t\tparts: {},\n\t\t},\n\t};\n}\n\n/**\n * § 3 BGB, repealed at the end of 2001: published, filed in BGB, with\n * nothing In Force today or later, so it may be archived. Not among\n * `stubContents()`, so the Library's fixtures stay as they are; pass it in\n * with `contents` to a stub that needs it.\n */\nexport function stubRepealedContent(): StubContent {\n\tconst at = \"2001-11-01T08:00:00.000Z\";\n\tconst data = { number: \"§ 3\", heading: \"(weggefallen)\" };\n\treturn {\n\t\tid: \"content_para_3\",\n\t\tblueprintId: \"bp_paragraph\",\n\t\tblueprintReleaseId: \"bpr_paragraph_1\",\n\t\tcollectionIds: [\"col_bgb\"],\n\t\tmain: { revisionId: \"rev_p3_main\", data, revisionCreateTime: at },\n\t\tbranches: {},\n\t\ttimeline: [\n\t\t\t{\n\t\t\t\tordinal: 1,\n\t\t\t\treleaseId: \"rls_p3_repeal\",\n\t\t\t\tkind: \"repeal\",\n\t\t\t\trevisionId: \"rev_p3_main\",\n\t\t\t\tblueprintReleaseId: \"bpr_paragraph_1\",\n\t\t\t\tvalidityPeriod: { firstDay: \"1900-01-01\", lastDay: \"2001-12-31\" },\n\t\t\t\tpublishTime: at,\n\t\t\t\tfirst: true,\n\t\t\t},\n\t\t],\n\t};\n}\n\n/**\n * The Content behind the fixtures' Change Sets: § 1 BGB, amended in\n * BGBl. 2026 I Nr. 270; § 2 BGB; § 4a BGB, born in that Change Set; § 211\n * StGB; and a footnote filed nowhere, published but with no Release In Force\n * yet (dated to start next year).\n */\nexport function stubContents(): StubContent[] {\n\tconst at = \"2026-09-01T08:00:00.000Z\";\n\treturn [\n\t\t{\n\t\t\tid: \"content_fn_1\",\n\t\t\tblueprintId: \"bp_footnote\",\n\t\t\tblueprintReleaseId: \"bpr_footnote_1\",\n\t\t\tcollectionIds: [],\n\t\t\tmain: {\n\t\t\t\trevisionId: \"rev_fn1_main\",\n\t\t\t\tdata: { text: \"Fassung ab 1. Januar 2027\" },\n\t\t\t\trevisionCreateTime: at,\n\t\t\t},\n\t\t\tbranches: {},\n\t\t\ttimeline: [\n\t\t\t\t{\n\t\t\t\t\tordinal: 1,\n\t\t\t\t\treleaseId: \"rls_fn1_1\",\n\t\t\t\t\tkind: \"revision\",\n\t\t\t\t\trevisionId: \"rev_fn1_main\",\n\t\t\t\t\tblueprintReleaseId: \"bpr_footnote_1\",\n\t\t\t\t\tvalidityPeriod: { firstDay: \"2027-01-01\", lastDay: \"\" },\n\t\t\t\t\tpublishTime: at,\n\t\t\t\t\tfirst: true,\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t\t{\n\t\t\tid: \"content_para_1\",\n\t\t\tblueprintId: \"bp_paragraph\",\n\t\t\tblueprintReleaseId: \"bpr_paragraph_1\",\n\t\t\tcollectionIds: [\"col_bgb\"],\n\t\t\tassigneeIds: [STUB_USER_ID, STUB_OTHER_USER_ID],\n\t\t\tmain: {\n\t\t\t\trevisionId: \"rev_p1_main\",\n\t\t\t\tdata: { number: \"§ 1\", heading: \"Beginn der Rechtsfähigkeit\" },\n\t\t\t\trevisionCreateTime: at,\n\t\t\t},\n\t\t\tinForce: {\n\t\t\t\treleaseId: \"rls_p1_1\",\n\t\t\t\trevisionId: \"rev_p1_main\",\n\t\t\t\tdata: { number: \"§ 1\", heading: \"Beginn der Rechtsfähigkeit\" },\n\t\t\t\trevisionCreateTime: at,\n\t\t\t},\n\t\t\tbranches: {\n\t\t\t\tcs_bgbl_270: {\n\t\t\t\t\tbranchId: \"br_para_1_b\",\n\t\t\t\t\trevisionId: \"rev_p1_b1\",\n\t\t\t\t\tdata: { number: \"§ 1\", heading: \"Beginn der Rechtsfähigkeit, Erbfähigkeit\" },\n\t\t\t\t\trevisionCreateTime: \"2026-09-30T09:00:00.000Z\",\n\t\t\t\t},\n\t\t\t},\n\t\t\ttimeline: [\n\t\t\t\t{\n\t\t\t\t\tordinal: 1,\n\t\t\t\t\treleaseId: \"rls_p1_1\",\n\t\t\t\t\tkind: \"revision\",\n\t\t\t\t\trevisionId: \"rev_p1_main\",\n\t\t\t\t\tblueprintReleaseId: \"bpr_paragraph_1\",\n\t\t\t\t\tvalidityPeriod: { firstDay: \"1900-01-01\", lastDay: \"\" },\n\t\t\t\t\tpublishTime: at,\n\t\t\t\t\tfirst: true,\n\t\t\t\t},\n\t\t\t],\n\t\t\tplannedReleases: [\n\t\t\t\t{\n\t\t\t\t\tchangeSetId: \"cs_bgbl_270\",\n\t\t\t\t\tplannedRelease: {\n\t\t\t\t\t\tid: \"rls_p1_270\",\n\t\t\t\t\t\tcontentId: \"content_para_1\",\n\t\t\t\t\t\tkind: \"revision\",\n\t\t\t\t\t\tbranchId: \"br_para_1_b\",\n\t\t\t\t\t\tvalidityPeriod: { firstDay: \"2026-11-01\", lastDay: \"\" },\n\t\t\t\t\t\trevisionId: \"\",\n\t\t\t\t\t\tsupersedesReleaseIds: [],\n\t\t\t\t\t\tproposed: false,\n\t\t\t\t\t\tproposedForReleaseId: \"\",\n\t\t\t\t\t\tsplitFromReleaseId: \"\",\n\t\t\t\t\t\twithheld: false,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t],\n\t\t\t// The amendment's two saves, then the Revision Main holds.\n\t\t\trevisions: [\n\t\t\t\t{\n\t\t\t\t\tid: \"rev_p1_b1\",\n\t\t\t\t\tcontentId: \"content_para_1\",\n\t\t\t\t\tparentId: \"rev_p1_a2\",\n\t\t\t\t\tsecondParentId: \"\",\n\t\t\t\t\tblueprintReleaseId: \"bpr_paragraph_1\",\n\t\t\t\t\tcreateTime: \"2026-09-30T09:00:00.000Z\",\n\t\t\t\t\tauthor: STUB_USER_ID,\n\t\t\t\t\tcause: \"save\",\n\t\t\t\t\tbranchId: \"br_para_1_b\",\n\t\t\t\t\tchangeSetId: \"cs_bgbl_270\",\n\t\t\t\t\tdata: { number: \"§ 1\", heading: \"Beginn der Rechtsfähigkeit, Erbfähigkeit\" },\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tid: \"rev_p1_a2\",\n\t\t\t\t\tcontentId: \"content_para_1\",\n\t\t\t\t\tparentId: \"rev_p1_main\",\n\t\t\t\t\tsecondParentId: \"\",\n\t\t\t\t\tblueprintReleaseId: \"bpr_paragraph_1\",\n\t\t\t\t\tcreateTime: \"2026-09-30T08:30:00.000Z\",\n\t\t\t\t\tauthor: STUB_OTHER_USER_ID,\n\t\t\t\t\tcause: \"save\",\n\t\t\t\t\tbranchId: \"br_para_1_a\",\n\t\t\t\t\tchangeSetId: \"cs_bgbl_270\",\n\t\t\t\t\tdata: { number: \"§ 1\", heading: \"Beginn der Rechtsfähigkeit des Menschen\" },\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tid: \"rev_p1_main\",\n\t\t\t\t\tcontentId: \"content_para_1\",\n\t\t\t\t\tparentId: \"\",\n\t\t\t\t\tsecondParentId: \"\",\n\t\t\t\t\tblueprintReleaseId: \"bpr_paragraph_1\",\n\t\t\t\t\tcreateTime: at,\n\t\t\t\t\tauthor: STUB_USER_ID,\n\t\t\t\t\tcause: \"create\",\n\t\t\t\t\tbranchId: \"br_para_1_main\",\n\t\t\t\t\tchangeSetId: \"cs_correction_3\",\n\t\t\t\t},\n\t\t\t],\n\t\t\t// § 1 cites § 2 at a Release since superseded: an outdated pin.\n\t\t\tedges: [\n\t\t\t\t{\n\t\t\t\t\tsourceContentId: \"content_para_1\",\n\t\t\t\t\tsourceRevisionId: \"rev_p1_main\",\n\t\t\t\t\tpath: \"/see_also\",\n\t\t\t\t\tkind: \"reference\",\n\t\t\t\t\ttargetContentId: \"content_para_2\",\n\t\t\t\t\ttargetAssetId: \"\",\n\t\t\t\t\ttargetBlueprintReleaseId: \"\",\n\t\t\t\t\tpinReleaseId: \"rls_p2_0\",\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t\t{\n\t\t\tid: \"content_para_2\",\n\t\t\tblueprintId: \"bp_paragraph\",\n\t\t\tblueprintReleaseId: \"bpr_paragraph_1\",\n\t\t\tcollectionIds: [\"col_bgb\"],\n\t\t\tmain: {\n\t\t\t\trevisionId: \"rev_p2_main\",\n\t\t\t\tdata: { number: \"§ 2\", heading: \"Eintritt der Volljährigkeit\" },\n\t\t\t\trevisionCreateTime: at,\n\t\t\t},\n\t\t\tinForce: {\n\t\t\t\treleaseId: \"rls_p2_1\",\n\t\t\t\trevisionId: \"rev_p2_main\",\n\t\t\t\tdata: { number: \"§ 2\", heading: \"Eintritt der Volljährigkeit\" },\n\t\t\t\trevisionCreateTime: at,\n\t\t\t},\n\t\t\tbranches: {},\n\t\t\ttimeline: [\n\t\t\t\t{\n\t\t\t\t\tordinal: 1,\n\t\t\t\t\treleaseId: \"rls_p2_1\",\n\t\t\t\t\tkind: \"revision\",\n\t\t\t\t\trevisionId: \"rev_p2_main\",\n\t\t\t\t\tblueprintReleaseId: \"bpr_paragraph_1\",\n\t\t\t\t\tvalidityPeriod: { firstDay: \"1975-01-01\", lastDay: \"\" },\n\t\t\t\t\tpublishTime: at,\n\t\t\t\t\tfirst: false,\n\t\t\t\t},\n\t\t\t],\n\t\t\t// § 2 refers to § 1 as it is In Force: § 1's referrer.\n\t\t\tedges: [\n\t\t\t\t{\n\t\t\t\t\tsourceContentId: \"content_para_2\",\n\t\t\t\t\tsourceRevisionId: \"rev_p2_main\",\n\t\t\t\t\tpath: \"/see_also\",\n\t\t\t\t\tkind: \"reference\",\n\t\t\t\t\ttargetContentId: \"content_para_1\",\n\t\t\t\t\ttargetAssetId: \"\",\n\t\t\t\t\ttargetBlueprintReleaseId: \"\",\n\t\t\t\t\tpinReleaseId: \"\",\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t\t{\n\t\t\tid: \"content_para_4a\",\n\t\t\tblueprintId: \"bp_paragraph\",\n\t\t\tblueprintReleaseId: \"bpr_paragraph_2\",\n\t\t\tcollectionIds: [\"col_bgb\"],\n\t\t\tbranches: {\n\t\t\t\tcs_bgbl_270: {\n\t\t\t\t\tbranchId: \"br_para_4a\",\n\t\t\t\t\trevisionId: \"rev_p4a_1\",\n\t\t\t\t\tdata: { number: \"§ 4a\", heading: \"Elektronische Form\" },\n\t\t\t\t\trevisionCreateTime: \"2026-09-30T10:00:00.000Z\",\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: \"content_stgb_211\",\n\t\t\tblueprintId: \"bp_paragraph\",\n\t\t\tblueprintReleaseId: \"bpr_paragraph_1\",\n\t\t\tcollectionIds: [\"col_stgb\"],\n\t\t\tassigneeIds: [STUB_OTHER_USER_ID],\n\t\t\tmain: {\n\t\t\t\trevisionId: \"rev_s211_main\",\n\t\t\t\tdata: { number: \"§ 211\", heading: \"Mord\" },\n\t\t\t\trevisionCreateTime: at,\n\t\t\t},\n\t\t\tinForce: {\n\t\t\t\treleaseId: \"rls_s211_1\",\n\t\t\t\trevisionId: \"rev_s211_main\",\n\t\t\t\tdata: { number: \"§ 211\", heading: \"Mord\" },\n\t\t\t\trevisionCreateTime: at,\n\t\t\t},\n\t\t\tbranches: {},\n\t\t\ttimeline: [\n\t\t\t\t{\n\t\t\t\t\tordinal: 1,\n\t\t\t\t\treleaseId: \"rls_s211_1\",\n\t\t\t\t\tkind: \"revision\",\n\t\t\t\t\trevisionId: \"rev_s211_main\",\n\t\t\t\t\tblueprintReleaseId: \"bpr_paragraph_1\",\n\t\t\t\t\tvalidityPeriod: { firstDay: \"1941-09-15\", lastDay: \"\" },\n\t\t\t\t\tpublishTime: at,\n\t\t\t\t\tfirst: true,\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t];\n}\n","// A `BlueprintSource` over fixed Blueprints and Releases, for a test that\n// overrides where the screens read Blueprints. Without one they read the\n// client's own catalog (#238), which the stub client serves too.\nimport type { BlueprintInfo, BlueprintReleaseInfo, BlueprintSource } from \"../types\";\nimport { stubBlueprintReleases, stubBlueprints } from \"./fixtures\";\n\nexport function createStubBlueprintSource(\n\tblueprints: BlueprintInfo[] = stubBlueprints(),\n\treleases: BlueprintReleaseInfo[] = stubBlueprintReleases(),\n): BlueprintSource {\n\treturn {\n\t\tasync searchBlueprints({ query }) {\n\t\t\tconst q = query.trim().toLocaleLowerCase();\n\t\t\treturn {\n\t\t\t\tblueprints: blueprints\n\t\t\t\t\t.filter((b) => b.name.toLocaleLowerCase().includes(q))\n\t\t\t\t\t.map((b) => ({ ...b })),\n\t\t\t\tnextPageToken: \"\",\n\t\t\t};\n\t\t},\n\t\tasync getBlueprints(ids) {\n\t\t\treturn blueprints.filter((b) => ids.includes(b.id)).map((b) => ({ ...b }));\n\t\t},\n\t\tasync listReleases(blueprintId) {\n\t\t\treturn releases.filter((r) => r.blueprintId === blueprintId).map((r) => ({ ...r }));\n\t\t},\n\t};\n}\n","// A `ContenthubClient` over an in-memory workspace seeded from the fixtures.\n//\n// It keeps state and applies the service's rules (internal/workspaceconfig,\n// internal/changesets), rather than answering every read with the same\n// fixture, so a screen's writes show up in its next read, and a refusal comes\n// back the way contenthub refuses it.\n//\n// Typed as the whole interface, so a method added to `ContenthubClient`\n// without an answer here fails this package's typecheck, not a host's test.\nimport { Code, ConnectError } from \"@connectrpc/connect\";\nimport {\n\tAccessDeniedError,\n\tBLOCK_REASON_NAME_MAX,\n\tBLUEPRINT_ACCESSOR_MAX,\n\tBlockReasonNameTakenError,\n\tCHANGE_SET_NAME_MAX,\n\tCHECK_NOTE_MAX,\n\tChangeSetClosedError,\n\tCheckResultDeniedError,\n\tCOLLECTION_NAME_MAX,\n\tCONTENT_SEARCH_MAX,\n\tContentArchivedError,\n\tContentBlockedError,\n\ttype ContenthubClient,\n\tContentRefusedError,\n\tCoversReleaseError,\n\tGuardianModeRequiredError,\n\tInvalidInputError,\n\tNameTakenError,\n\tPublishRefusedError,\n\tREQUIRED_CHECK_NAME_MAX,\n\tRestrictionUnavailableError,\n\tSOURCE_REFERENCE_MAX,\n\tStaleHeadError,\n\tStaleStatusError,\n\tStatusTransitionRefusedError,\n\tWithheldWorkError,\n} from \"../client/contenthub-client\";\nimport { headsOf, sameHeads } from \"../common/heads\";\nimport { DAY, inForceOnOrAfter, releaseInForceOn } from \"../common/in-force\";\nimport type {\n\tBlockReason,\n\tBlueprintInfo,\n\tBlueprintReleaseInfo,\n\tChangeSet,\n\tChangeSetStatusInfo,\n\tCheckResult,\n\tCheckStanding,\n\tCollection,\n\tCollectionGrant,\n\tContent,\n\tContentAttributes,\n\tContentView,\n\tEdge,\n\tFieldChange,\n\tMergeField,\n\tPendingMerge,\n\tPendingMergeRef,\n\tPlannedEnd,\n\tPlannedRelease,\n\tPublishBlocker,\n\tReferrer,\n\tReferrerList,\n\tRelease,\n\tRequiredCheck,\n\tRequiredCheckInput,\n\tRequiredCheckRecorders,\n\tResolvedBlueprintRelease,\n\tResolvedField,\n\tRevision,\n\tTimelineEntry,\n} from \"../types\";\nimport {\n\tSTUB_NOW,\n\tSTUB_OTHER_USER_ID,\n\tSTUB_USER_ID,\n\ttype StubContent,\n\tstubBlockReasons,\n\tstubBlueprintReleases,\n\tstubBlueprints,\n\tstubChangeSetStatuses,\n\tstubChangeSets,\n\tstubCollections,\n\tstubContents,\n\tstubRequiredChecks,\n\tstubResolvedReleases,\n\tstubStatusTransitions,\n} from \"./fixtures\";\n\ntype SaveInput = Omit<Parameters<ContenthubClient[\"saveRevision\"]>[0], \"idempotencyKey\">;\n\nexport interface StubContenthubClientOptions {\n\t/** The workspace's Block Reasons to start from; the fixtures' by default. */\n\tblockReasons?: BlockReason[];\n\t/** The workspace's Change Sets to start from, newest first; the fixtures' by default. */\n\tchangeSets?: ChangeSet[];\n\t/**\n\t * statushub's `contenthub/change_set` catalogue the stub checks status\n\t * moves against; the fixtures' by default.\n\t */\n\tstatuses?: ChangeSetStatusInfo[];\n\t/** The moves statushub allows, from slug to slugs; the fixtures' by default. */\n\tstatusTransitions?: Record<string, string[]>;\n\t/** The workspace's Collections, by name; the fixtures' by default. */\n\tcollections?: Collection[];\n\t/** The workspace's Content, every way it can be read; the fixtures' by default. */\n\tcontents?: StubContent[];\n\t/**\n\t * The workspace's content Blueprints Content can be made from, as\n\t * `searchBlueprints` lists them; the fixtures' by default.\n\t */\n\tblueprints?: BlueprintInfo[];\n\t/**\n\t * The Blueprint Releases, newest first per Blueprint, as\n\t * `listBlueprintReleases` lists them; the fixtures' by default.\n\t * `createContent` pins one without `refusals` and refuses the rest, as\n\t * contenthub refuses a Release it can't load.\n\t */\n\tblueprintReleases?: (Pick<BlueprintReleaseInfo, \"id\" | \"blueprintId\"> &\n\t\tPartial<BlueprintReleaseInfo>)[];\n\t/** The Resolved Releases `getContent` answers with, by Blueprint Release id; the fixtures' by default. */\n\tresolvedReleases?: Record<string, ResolvedBlueprintRelease>;\n\t/**\n\t * The workspace's Required Checks; the fixtures' by default. The stub\n\t * reads `blueprintAccessors` as Blueprint ids, the one name its Content\n\t * carries.\n\t */\n\trequiredChecks?: RequiredCheck[];\n\t/** Check Results recorded before, in the order they were recorded. */\n\tcheckResults?: (CheckResult & { changeSetId: string })[];\n\t/**\n\t * Blockers the stub can't derive itself (versionkit's and the Content\n\t * Graph's, such as covers_release or dangling_pin), by Change Set id:\n\t * `validatePublish` and `publish` report them beside the ones it does\n\t * derive (moved_head, the dependencies', outstanding_check).\n\t */\n\tpublishBlockers?: Record<string, PublishBlocker[]>;\n\t/** The Pending Merges `updateFromMain` leaves, by Change Set id; none by default. */\n\tpendingMerges?: Record<string, PendingMergeRef[]>;\n\t/**\n\t * What an Update from Main would meet on a Branch, by Branch id: the\n\t * fields it can't merge and the rest merged. `updateFromMain` stores it\n\t * on the Branch as a Pending Merge; `pending` stores it from the start.\n\t */\n\tconflicts?: Record<string, StubConflict>;\n\t/**\n\t * contenthub's `authz.mode`: \"guardian\" by default. In \"workspace\" every\n\t * restriction and grant is refused, as contenthub refuses them, and\n\t * opening a Restricted Collection again is still allowed.\n\t */\n\tauthzMode?: \"workspace\" | \"guardian\";\n\t/** Grants on Restricted Collections, by Collection id, the owner's included. */\n\tcollectionGrants?: Record<string, CollectionGrant[]>;\n\t/**\n\t * The Change Sets, by id, holding work the caller can't see (Restricted\n\t * Content, ADR 0017): `validatePublish`, `publish`, `discardChangeSet`\n\t * and an `updateFromMain` without `chainId` refuse them with\n\t * `WithheldWorkError`, as contenthub does.\n\t */\n\twithheld?: string[];\n\t/**\n\t * Who records each Required Check, by check id; a check not named here,\n\t * and every new one, is recorded by every member. In guardian mode\n\t * `recordCheckResult` refuses a caller who is no recorder, as contenthub\n\t * does; in workspace mode every member records, and the recorder calls\n\t * are refused.\n\t */\n\trecorders?: Record<string, RequiredCheckRecorders>;\n\t/** The workspace's members, whom a grant may name; the stub identity's two by default. */\n\tmemberIds?: string[];\n\t/**\n\t * Whether the caller is a workspace admin, who manages every Restricted\n\t * Collection's grants; true by default. Otherwise only an owner does.\n\t */\n\tadmin?: boolean;\n\t/** Who the token names: the creator of a new Change Set. STUB_USER_ID by default. */\n\tuserId?: string;\n\t/** The time every write stamps; STUB_NOW by default. */\n\tnow?: () => string;\n}\n\n/** A merge an Update from Main would stop on (see `conflicts`). */\nexport interface StubConflict {\n\ttheirsRevisionId: string;\n\tfields: MergeField[];\n\t/** Every field but `fields`, merged. */\n\tmerged: Record<string, unknown>;\n\treason?: \"conflict\" | \"invalid\";\n\t/** Already stored on the Branch, as an earlier Update from Main left it. */\n\tpending?: boolean;\n}\n\n/** The day after (1) or before (-1) a YYYY-MM-DD day. */\nfunction shiftDay(day: string, by: 1 | -1): string {\n\tconst d = new Date(`${day}T00:00:00Z`);\n\td.setUTCDate(d.getUTCDate() + by);\n\treturn d.toISOString().slice(0, 10);\n}\n\n/** The service's rule for a name: trimmed, not blank, at most `max` characters, one line. */\nfunction oneLine(raw: string, what: string, max: number): string {\n\tconst value = raw.trim();\n\tif (value === \"\") throw new InvalidInputError(`${what} is required`);\n\tif ([...value].length > max) {\n\t\tthrow new InvalidInputError(`${what} is at most ${max} characters`);\n\t}\n\t// biome-ignore lint/suspicious/noControlCharactersInRegex: the rule is exactly \"no control characters\"\n\tif (/[\\u0000-\\u001f\\u007f]/.test(value)) {\n\t\tthrow new InvalidInputError(`${what} is one line of text`);\n\t}\n\treturn value;\n}\n\n/** The service's rule for a Source: a YYYY-MM-DD day and a one-line reference. */\nfunction checkedSourceOf(source: { date: string; reference: string }): {\n\tdate: string;\n\treference: string;\n} {\n\tif (!/^\\d{4}-\\d{2}-\\d{2}$/.test(source.date.trim())) {\n\t\tthrow new InvalidInputError(`source.date \"${source.date}\" is not a day as YYYY-MM-DD`);\n\t}\n\treturn {\n\t\tdate: source.date.trim(),\n\t\treference: oneLine(source.reference, \"source.reference\", SOURCE_REFERENCE_MAX),\n\t};\n}\n\nfunction checkedBlockReasonName(raw: string): string {\n\tconst name = raw.trim();\n\tif (name === \"\") throw new InvalidInputError(\"a Block Reason needs a name\");\n\tif ([...name].length > BLOCK_REASON_NAME_MAX) {\n\t\tthrow new InvalidInputError(\n\t\t\t`a Block Reason's name is at most ${BLOCK_REASON_NAME_MAX} characters`,\n\t\t);\n\t}\n\t// biome-ignore lint/suspicious/noControlCharactersInRegex: the rule is exactly \"no control characters\"\n\tif (/[\\u0000-\\u001f\\u007f]/.test(name)) {\n\t\tthrow new InvalidInputError(\"a Block Reason's name is one line of text\");\n\t}\n\treturn name;\n}\n\n/** The service's rule for a Required Check (internal/workspaceconfig.checkRequiredCheck). */\nfunction checkedRequiredCheck(input: RequiredCheckInput): RequiredCheckInput {\n\tconst name = oneLine(input.name, \"a Required Check's name\", REQUIRED_CHECK_NAME_MAX);\n\tif (input.scope !== \"branch\" && input.scope !== \"change_set\") {\n\t\tthrow new InvalidInputError(\"a Required Check's scope is Branch or Change Set\");\n\t}\n\tconst accessors = input.blueprintAccessors.map((raw) => {\n\t\tconst a = raw.trim();\n\t\t// biome-ignore lint/suspicious/noControlCharactersInRegex: the rule is exactly \"no control characters\"\n\t\tif (a === \"\" || [...a].length > BLUEPRINT_ACCESSOR_MAX || /[\\u0000-\\u001f\\u007f]/.test(a)) {\n\t\t\tthrow new InvalidInputError(`\"${a}\" is not a Blueprint accessor`);\n\t\t}\n\t\treturn a;\n\t});\n\treturn {\n\t\tname,\n\t\tscope: input.scope,\n\t\tblueprintAccessors: [...new Set(accessors)].sort(),\n\t\tindependent: input.independent,\n\t};\n}\n\n/** What contenthub answers to every recorder call in `authz.mode: workspace`. */\nconst RECORDERS_WORKSPACE_MODE =\n\t\"who records a Required Check can be narrowed only in authz.mode guardian: \" +\n\t\"in workspace mode every member records every check (ADR 0017)\";\n\n/** What contenthub answers to every whole-Change-Set write over withheld work. */\nconst WITHHELD_REFUSAL =\n\t\"this Change Set holds work you can't see: publishing, discarding or updating all of it \" +\n\t\"needs you to see every Content in it\";\n\n/** What contenthub answers to every restriction in `authz.mode: workspace`. */\nconst WORKSPACE_MODE_REFUSAL =\n\t\"Restricted Collections need authz.mode guardian: in workspace mode a restriction \" +\n\t\"could not be enforced (ADR 0017)\";\n\nfunction notFound(what: string, id: string): ConnectError {\n\treturn new ConnectError(`${what} ${id}: not found`, Code.NotFound);\n}\n\nconst copy = (cs: ChangeSet): ChangeSet => structuredClone(cs);\n\n/** A blocker naming only what `fields` sets; every other id \"\", as on the wire. */\nexport function stubBlocker(code: string, fields: Partial<PublishBlocker> = {}): PublishBlocker {\n\treturn {\n\t\tcode,\n\t\tcontentId: \"\",\n\t\tbranchId: \"\",\n\t\texpectedHeadId: \"\",\n\t\tcurrentHeadId: \"\",\n\t\treleaseId: \"\",\n\t\toverlapsReleaseId: \"\",\n\t\tdependencyChangeSetId: \"\",\n\t\tpath: \"\",\n\t\ttargetContentId: \"\",\n\t\tassetId: \"\",\n\t\tparentContentIds: [],\n\t\trequiredCheckId: \"\",\n\t\tcoveredReleaseId: \"\",\n\t\trevisionId: \"\",\n\t\t...fields,\n\t};\n}\n\nexport function createStubContenthubClient(\n\toptions: StubContenthubClientOptions = {},\n): ContenthubClient {\n\tconst now = options.now ?? (() => STUB_NOW);\n\tconst userId = options.userId ?? STUB_USER_ID;\n\tconst statuses = options.statuses ?? stubChangeSetStatuses();\n\tconst transitions = options.statusTransitions ?? stubStatusTransitions();\n\tlet reasons = (options.blockReasons ?? stubBlockReasons()).map((r) => ({ ...r }));\n\t// Newest first, the order the service lists them in.\n\tconst changeSets = (options.changeSets ?? stubChangeSets()).map(copy);\n\tconst collections = (options.collections ?? stubCollections()).map((c) => ({ ...c }));\n\tconst contents = structuredClone(options.contents ?? stubContents());\n\tconst blueprints = options.blueprints ?? stubBlueprints();\n\tconst releases = options.blueprintReleases ?? stubBlueprintReleases();\n\tconst resolved = options.resolvedReleases ?? stubResolvedReleases();\n\tlet requiredChecks = structuredClone(options.requiredChecks ?? stubRequiredChecks());\n\tconst authzMode = options.authzMode ?? \"guardian\";\n\tconst withheld = new Set(options.withheld ?? []);\n\t/** Refuses a write over all of Change Set `id` while it holds work the caller can't see. */\n\tconst refuseWithheld = (id: string) => {\n\t\tif (withheld.has(id)) throw new WithheldWorkError(WITHHELD_REFUSAL);\n\t};\n\tconst grants = new Map<string, CollectionGrant[]>(\n\t\tObject.entries(structuredClone(options.collectionGrants ?? {})),\n\t);\n\tconst recorders = new Map<string, RequiredCheckRecorders>(\n\t\tObject.entries(structuredClone(options.recorders ?? {})),\n\t);\n\tconst recordersOf = (checkId: string): RequiredCheckRecorders =>\n\t\trecorders.get(checkId) ?? { everyMember: true, userIds: [] };\n\tconst memberIds = options.memberIds ?? [STUB_USER_ID, STUB_OTHER_USER_ID];\n\tconst admin = options.admin ?? true;\n\tconst checkResults = structuredClone(options.checkResults ?? []);\n\tconst extraBlockers = options.publishBlockers ?? {};\n\tconst pendingMerges = options.pendingMerges ?? {};\n\tconst conflicts = structuredClone(options.conflicts ?? {});\n\t// The Pending Merges stored on Branches, by Branch id.\n\tconst stored = new Map<string, PendingMerge>();\n\t// What each Idempotency Key's write asked and answered, beside the saves'.\n\tconst wroteUnder = new Map<string, { asked: string; answer: unknown }>();\n\t/**\n\t * A write under an Idempotency Key: a repeat answers the first and\n\t * writes nothing, another request under the key is refused.\n\t */\n\tconst once = async <T>(key: string | undefined, request: unknown, write: () => Promise<T>) => {\n\t\tif (!key) return write();\n\t\tconst asked = JSON.stringify(request);\n\t\tconst kept = wroteUnder.get(key);\n\t\tif (kept) {\n\t\t\tif (kept.asked !== asked) {\n\t\t\t\tthrow new InvalidInputError(`idempotency key ${key} names another request`);\n\t\t\t}\n\t\t\treturn structuredClone(kept.answer) as T;\n\t\t}\n\t\tconst answer = await write();\n\t\twroteUnder.set(key, { asked, answer: structuredClone(answer) });\n\t\treturn answer;\n\t};\n\t// The heads each published Change Set was published with, for a repeat.\n\tconst publishedWith = new Map<string, Record<string, string>>();\n\t// What each Idempotency Key's save asked and answered.\n\tconst savedUnder = new Map<string, { asked: string; content: Content }>();\n\tlet next = 1;\n\n\tconst findContent = (id: string): StubContent => {\n\t\tconst c = contents.find((each) => each.id === id);\n\t\tif (!c) throw notFound(\"Content\", id);\n\t\treturn c;\n\t};\n\tconst attributesOf = (c: StubContent): ContentAttributes =>\n\t\tstructuredClone({\n\t\t\tcollectionIds: [...c.collectionIds].sort(),\n\t\t\tassigneeIds: c.assigneeIds ?? [],\n\t\t\tblock: c.block,\n\t\t\tarchiveTime: c.archiveTime,\n\t\t});\n\tconst today = () => now().slice(0, 10);\n\tconst datedContent = (c: StubContent) => resolved[c.blueprintReleaseId]?.dated ?? false;\n\t// Every Revision the stub knows of a Content, newest first, with its data\n\t// where known: those the fixture lists, then each head not among them.\n\tconst revisionsOf = (c: StubContent): (Revision & { data?: Record<string, unknown> })[] => {\n\t\tconst listed = [...(c.revisions ?? [])];\n\t\tconst heads = [\n\t\t\t...Object.entries(c.branches).map(([csId, h]) => ({ ...h, changeSetId: csId })),\n\t\t\t...(c.main ? [{ ...c.main, branchId: \"\", changeSetId: \"\" }] : []),\n\t\t];\n\t\tfor (const h of heads) {\n\t\t\tif (listed.some((r) => r.id === h.revisionId)) continue;\n\t\t\tlisted.push({\n\t\t\t\tid: h.revisionId,\n\t\t\t\tcontentId: c.id,\n\t\t\t\tparentId: \"\",\n\t\t\t\tsecondParentId: \"\",\n\t\t\t\tblueprintReleaseId: c.blueprintReleaseId,\n\t\t\t\tcreateTime: h.revisionCreateTime,\n\t\t\t\tauthor: userId,\n\t\t\t\tcause: \"create\",\n\t\t\t\tbranchId: h.branchId,\n\t\t\t\tchangeSetId: h.changeSetId,\n\t\t\t\tdata: h.data,\n\t\t\t});\n\t\t}\n\t\treturn listed.sort((a, b) =>\n\t\t\ta.createTime < b.createTime ? 1 : a.createTime > b.createTime ? -1 : 0,\n\t\t);\n\t};\n\tconst dataOf = (c: StubContent, revisionId: string): Record<string, unknown> | undefined => {\n\t\tconst heads = [c.main, c.inForce, ...Object.values(c.branches)];\n\t\treturn (\n\t\t\theads.find((h) => h?.revisionId === revisionId)?.data ??\n\t\t\tc.revisions?.find((r) => r.id === revisionId)?.data\n\t\t);\n\t};\n\t/**\n\t * fieldkit's `required`, the one rule of its data contract the stub\n\t * applies: the accessors of the top-level required fields `values`\n\t * leaves Unset.\n\t */\n\tconst missingRequired = (\n\t\tfields: ResolvedField[] | undefined,\n\t\tvalues: Record<string, unknown>,\n\t): string[] => {\n\t\tconst unset = (v: unknown) =>\n\t\t\tv === undefined || v === null || v === \"\" || (Array.isArray(v) && v.length === 0);\n\t\treturn (fields ?? [])\n\t\t\t.filter((f) => f.config.required === true && unset(values[f.config.api_accessor]))\n\t\t\t.map((f) => f.config.api_accessor);\n\t};\n\tconst checkEditable = (c: StubContent) => {\n\t\tif (c.archiveTime) throw new ContentArchivedError(c.id);\n\t\tif (c.block && !c.block.allowedUserIds.includes(userId)) {\n\t\t\tthrow new ContentBlockedError(c.id, c.block.blockReasonId);\n\t\t}\n\t};\n\t/** The unpinned edges of Releases In Force pointing at `contentId`: what a Repeal leaves with a gap. */\n\tconst gapReferrersOf = (contentId: string): PlannedEnd[\"gapReferrers\"] =>\n\t\tcontents.flatMap((other) =>\n\t\t\t(other.edges ?? [])\n\t\t\t\t.filter(\n\t\t\t\t\t(e) =>\n\t\t\t\t\t\te.targetContentId === contentId &&\n\t\t\t\t\t\te.pinReleaseId === \"\" &&\n\t\t\t\t\t\tother.inForce?.revisionId === e.sourceRevisionId,\n\t\t\t\t)\n\t\t\t\t.map((e) => ({ edge: { ...e }, releaseId: other.inForce?.releaseId ?? \"\" })),\n\t\t);\n\n\t// The service orders by name, then id, compared as bytes.\n\tconst byName = (a: BlockReason, b: BlockReason) =>\n\t\ta.name < b.name ? -1 : a.name > b.name ? 1 : a.id < b.id ? -1 : a.id > b.id ? 1 : 0;\n\tconst taken = (name: string, except?: string) =>\n\t\treasons.some((r) => r.name === name && r.id !== except);\n\n\t// The service orders Collections by name, then id, compared as bytes.\n\tconst collectionOrder = (a: Collection, b: Collection) =>\n\t\ta.name < b.name ? -1 : a.name > b.name ? 1 : a.id < b.id ? -1 : a.id > b.id ? 1 : 0;\n\tconst findCollection = (id: string): Collection => {\n\t\tconst c = collections.find((each) => each.id === id);\n\t\tif (!c) throw notFound(\"Collection\", id);\n\t\treturn c;\n\t};\n\tconst siblingNamed = (parentId: string, name: string, except?: string) =>\n\t\tcollections.some((c) => c.parentId === parentId && c.name === name && c.id !== except);\n\t/** Refuses grant management the caller may not do, as the service does. */\n\tconst manageable = (id: string) => {\n\t\tif (authzMode === \"workspace\") throw new RestrictionUnavailableError(WORKSPACE_MODE_REFUSAL);\n\t\tconst c = findCollection(id);\n\t\tif (!c.restricted) {\n\t\t\tthrow new InvalidInputError(\n\t\t\t\t`Collection ${id} is open: only a Restricted Collection takes grants`,\n\t\t\t);\n\t\t}\n\t\tconst owns = (grants.get(id) ?? []).some((g) => g.userId === userId && g.level === \"owner\");\n\t\tif (!admin && !owns) {\n\t\t\tthrow new AccessDeniedError(\"only its owner or a workspace admin manages its grants\");\n\t\t}\n\t};\n\n\t/** Refuses recorder management the service would refuse, and returns the check's recorders. */\n\tconst narrowable = (checkId: string): RequiredCheckRecorders => {\n\t\tif (authzMode === \"workspace\") {\n\t\t\tthrow new GuardianModeRequiredError(\"required_check_recorders\", RECORDERS_WORKSPACE_MODE);\n\t\t}\n\t\tif (!admin) throw new AccessDeniedError(\"permission denied\");\n\t\tif (checkId === \"\") throw new InvalidInputError(\"required_check_id is required\");\n\t\tif (!requiredChecks.some((c) => c.id === checkId)) throw notFound(\"Required Check\", checkId);\n\t\treturn recordersOf(checkId);\n\t};\n\n\t/** One save, as SaveRevision applies it without an Idempotency Key. */\n\tconst saveOnce = async ({\n\t\tchangeSetId,\n\t\tbranchId,\n\t\texpectedHeadId,\n\t\tdata,\n\t\tfieldMask,\n\t}: SaveInput): Promise<Content> => {\n\t\tconst cs = open(changeSetId);\n\t\tconst chain = cs.chains.find((ch) => ch.branches.some((b) => b.id === branchId));\n\t\tconst branch = chain?.branches.find((b) => b.id === branchId);\n\t\tif (!chain || !branch) throw notFound(\"Branch\", branchId);\n\t\tconst c = findContent(chain.contentId);\n\t\tcheckEditable(c);\n\t\tif (stored.has(branchId)) {\n\t\t\tthrow new InvalidInputError(\n\t\t\t\t\"a Pending Merge waits on this Branch: resolve or abort it first\",\n\t\t\t);\n\t\t}\n\t\tif (expectedHeadId === \"\") throw new InvalidInputError(\"expected_head_id is required\");\n\t\tif (branch.headRevisionId !== expectedHeadId) {\n\t\t\tthrow new StaleHeadError({\n\t\t\t\tcontentId: c.id,\n\t\t\t\tbranchId,\n\t\t\t\texpectedHeadId,\n\t\t\t\tcurrentHeadId: branch.headRevisionId,\n\t\t\t});\n\t\t}\n\t\tconst head = dataOf(c, branch.headRevisionId) ?? {};\n\t\t// Through JSON, as the wire carries it: no `undefined` survives.\n\t\tconst sent = JSON.parse(JSON.stringify(data)) as Record<string, unknown>;\n\t\tlet saved: Record<string, unknown>;\n\t\tif (fieldMask) {\n\t\t\tconst stray = Object.keys(sent).filter((k) => !fieldMask.includes(k));\n\t\t\tif (stray.length > 0) {\n\t\t\t\tthrow new InvalidInputError(`data holds ${stray.join(\", \")}, which the mask doesn't name`);\n\t\t\t}\n\t\t\tsaved = structuredClone(head);\n\t\t\tfor (const key of fieldMask) {\n\t\t\t\tif (key in sent) saved[key] = sent[key];\n\t\t\t\telse delete saved[key];\n\t\t\t}\n\t\t} else {\n\t\t\tsaved = sent;\n\t\t}\n\t\t// No rule of fieldkit's data contract is applied: a save may leave\n\t\t// required Fields empty, and Publish asks for them (#180).\n\t\treturn writeHead({ changeSetId, chain, branch, c, data: saved, cause: \"save\" });\n\t};\n\n\t/** Writes a Revision on a Branch, on its head, which it becomes. */\n\tconst writeHead = ({\n\t\tchangeSetId,\n\t\tchain,\n\t\tbranch,\n\t\tc,\n\t\tdata,\n\t\tcause,\n\t\tsecondParentId = \"\",\n\t}: {\n\t\tchangeSetId: string;\n\t\tchain: ChangeSet[\"chains\"][number];\n\t\tbranch: ChangeSet[\"chains\"][number][\"branches\"][number];\n\t\tc: StubContent;\n\t\tdata: Record<string, unknown>;\n\t\tcause: Revision[\"cause\"];\n\t\tsecondParentId?: string;\n\t}): Content => {\n\t\tconst branchId = branch.id;\n\t\tconst n = next++;\n\t\tconst revisionId = `rev_stub_${n}`;\n\t\tconst createTime = now();\n\t\tc.revisions = [\n\t\t\t{\n\t\t\t\tid: revisionId,\n\t\t\t\tcontentId: c.id,\n\t\t\t\tparentId: branch.headRevisionId,\n\t\t\t\tsecondParentId,\n\t\t\t\tblueprintReleaseId: c.blueprintReleaseId,\n\t\t\t\tcreateTime,\n\t\t\t\tauthor: userId,\n\t\t\t\tcause,\n\t\t\t\tbranchId,\n\t\t\t\tchangeSetId,\n\t\t\t\tdata: structuredClone(data),\n\t\t\t},\n\t\t\t...(c.revisions ?? []),\n\t\t];\n\t\tbranch.headRevisionId = revisionId;\n\t\t// The Change Set read holds the head of the Chain's last Branch.\n\t\tif (chain.branches.at(-1)?.id === branchId) {\n\t\t\tc.branches[changeSetId] = {\n\t\t\t\tbranchId,\n\t\t\t\trevisionId,\n\t\t\t\tdata: structuredClone(data),\n\t\t\t\trevisionCreateTime: createTime,\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tid: c.id,\n\t\t\tblueprintId: c.blueprintId,\n\t\t\tblueprintReleaseId: c.blueprintReleaseId,\n\t\t\trevisionId,\n\t\t\tdata: structuredClone(data),\n\t\t\tchangeSetId,\n\t\t\tbranchId,\n\t\t\trevisionCreateTime: createTime,\n\t\t\treleaseId: \"\",\n\t\t};\n\t};\n\n\t/** The Chain and Branch of `branchId` in an open Change Set, and its Content. */\n\tconst branchIn = (changeSetId: string, branchId: string) => {\n\t\tconst cs = open(changeSetId);\n\t\tconst chain = cs.chains.find((ch) => ch.branches.some((b) => b.id === branchId));\n\t\tconst branch = chain?.branches.find((b) => b.id === branchId);\n\t\tif (!chain || !branch) throw notFound(\"Branch\", branchId);\n\t\treturn { cs, chain, branch, c: findContent(chain.contentId) };\n\t};\n\n\t/** Stores what an Update from Main met on a Branch as its Pending Merge. */\n\tconst storeMerge = (branchId: string, conflict: StubConflict) => {\n\t\tfor (const cs of changeSets) {\n\t\t\tfor (const chain of cs.chains) {\n\t\t\t\tconst branch = chain.branches.find((b) => b.id === branchId);\n\t\t\t\tif (!branch) continue;\n\t\t\t\tconst pm: PendingMerge = {\n\t\t\t\t\tbranchId,\n\t\t\t\t\tcontentId: chain.contentId,\n\t\t\t\t\treason: conflict.reason ?? \"conflict\",\n\t\t\t\t\toursRevisionId: branch.headRevisionId,\n\t\t\t\t\ttheirsRevisionId: conflict.theirsRevisionId,\n\t\t\t\t\tcarried: false,\n\t\t\t\t\tfields: structuredClone(conflict.fields),\n\t\t\t\t\tmerged: structuredClone(conflict.merged),\n\t\t\t\t};\n\t\t\t\tstored.set(branchId, pm);\n\t\t\t\tbranch.hasPendingMerge = true;\n\t\t\t\tdelete conflicts[branchId];\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tthrow notFound(\"Branch\", branchId);\n\t};\n\tconst dropMerge = (branchId: string) => {\n\t\tstored.delete(branchId);\n\t\tfor (const cs of changeSets) {\n\t\t\tfor (const chain of cs.chains) {\n\t\t\t\tconst branch = chain.branches.find((b) => b.id === branchId);\n\t\t\t\tif (branch) branch.hasPendingMerge = false;\n\t\t\t}\n\t\t}\n\t};\n\n\t/**\n\t * A plan checked as the service checks it: a Validity Period for Dated\n\t * Content and none for undated, its Release Spec's required values, and\n\t * no Release of the Content covered entirely unless it supersedes it.\n\t */\n\tconst checkPlan = (\n\t\tc: StubContent,\n\t\tplan: Pick<PlannedRelease, \"validityPeriod\" | \"releaseSpec\" | \"supersedesReleaseIds\">,\n\t) => {\n\t\tconst vp = plan.validityPeriod;\n\t\tif (datedContent(c)) {\n\t\t\tif (!vp || !DAY.test(vp.firstDay)) {\n\t\t\t\tthrow new InvalidInputError(\"validity_period.first_day is required for Dated Content\");\n\t\t\t}\n\t\t\tif (vp.lastDay !== \"\" && (!DAY.test(vp.lastDay) || vp.lastDay < vp.firstDay)) {\n\t\t\t\tthrow new InvalidInputError(\"validity_period.last_day is a day on or after first_day\");\n\t\t\t}\n\t\t} else if (vp) {\n\t\t\tthrow new InvalidInputError(\"validity_period is refused for undated Content\");\n\t\t}\n\t\tconst violations = missingRequired(\n\t\t\tresolved[c.blueprintReleaseId]?.releaseSpec,\n\t\t\tplan.releaseSpec ?? {},\n\t\t).map((accessor) => ({ source: \"fieldkit\", code: \"required\", path: `/${accessor}` }));\n\t\tif (violations.length > 0) {\n\t\t\tthrow new ContentRefusedError(\n\t\t\t\t\"the Release Spec values break the Blueprint Release\",\n\t\t\t\tviolations,\n\t\t\t);\n\t\t}\n\t\tif (vp && vp.lastDay !== \"\") {\n\t\t\tconst covered = (c.timeline ?? [])\n\t\t\t\t.filter(\n\t\t\t\t\t(e) =>\n\t\t\t\t\t\te.validityPeriod &&\n\t\t\t\t\t\te.validityPeriod.lastDay !== \"\" &&\n\t\t\t\t\t\tvp.firstDay <= e.validityPeriod.firstDay &&\n\t\t\t\t\t\te.validityPeriod.lastDay <= vp.lastDay &&\n\t\t\t\t\t\t!plan.supersedesReleaseIds.includes(e.releaseId),\n\t\t\t\t)\n\t\t\t\t.map((e) => e.releaseId);\n\t\t\tif (covered.length > 0) throw new CoversReleaseError(c.id, covered);\n\t\t}\n\t};\n\n\t/**\n\t * The Change Set's proposals for a Content, derived again from its plans\n\t * (versionkit ADR 0003): a date-only cut of each Release a planned period\n\t * cuts into, and a tail resuming its wording after a period strictly\n\t * inside it. A proposal keeps its id while it proposes for the same Release.\n\t */\n\tconst repropose = (cs: ChangeSet, c: StubContent) => {\n\t\tconst previous = cs.plannedReleases.filter((p) => p.contentId === c.id && p.proposed);\n\t\tconst kept = cs.plannedReleases.filter((p) => !(p.contentId === c.id && p.proposed));\n\t\tconst proposals: PlannedRelease[] = [];\n\t\tconst propose = (\n\t\t\te: TimelineEntry,\n\t\t\tvalidityPeriod: { firstDay: string; lastDay: string },\n\t\t\tsplitFromReleaseId: string,\n\t\t) => {\n\t\t\tconst same = previous.find(\n\t\t\t\t(p) =>\n\t\t\t\t\tp.proposedForReleaseId === e.releaseId && p.splitFromReleaseId === splitFromReleaseId,\n\t\t\t);\n\t\t\tproposals.push({\n\t\t\t\tid: same?.id ?? `rls_stub_${next++}`,\n\t\t\t\tcontentId: c.id,\n\t\t\t\tkind: \"date_only\",\n\t\t\t\tbranchId: \"\",\n\t\t\t\trevisionId: e.revisionId,\n\t\t\t\tvalidityPeriod,\n\t\t\t\tsupersedesReleaseIds: splitFromReleaseId ? [] : [e.releaseId],\n\t\t\t\tproposed: true,\n\t\t\t\tproposedForReleaseId: e.releaseId,\n\t\t\t\tsplitFromReleaseId,\n\t\t\t\twithheld: false,\n\t\t\t});\n\t\t};\n\t\tfor (const plan of kept) {\n\t\t\tconst vp = plan.validityPeriod;\n\t\t\tif (plan.contentId !== c.id || plan.kind !== \"revision\" || !vp) continue;\n\t\t\tfor (const e of c.timeline ?? []) {\n\t\t\t\tconst its = e.validityPeriod;\n\t\t\t\tif (!its || plan.supersedesReleaseIds.includes(e.releaseId)) continue;\n\t\t\t\tif (!(its.firstDay < vp.firstDay && (its.lastDay === \"\" || its.lastDay >= vp.firstDay))) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tpropose(e, { firstDay: its.firstDay, lastDay: shiftDay(vp.firstDay, -1) }, \"\");\n\t\t\t\tif (vp.lastDay !== \"\" && (its.lastDay === \"\" || its.lastDay > vp.lastDay)) {\n\t\t\t\t\tpropose(e, { firstDay: shiftDay(vp.lastDay, 1), lastDay: its.lastDay }, e.releaseId);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tcs.plannedReleases = [...kept, ...proposals];\n\t};\n\n\tconst find = (id: string): ChangeSet => {\n\t\tconst cs = changeSets.find((c) => c.id === id);\n\t\tif (!cs) throw notFound(\"Change Set\", id);\n\t\treturn cs;\n\t};\n\tconst open = (id: string): ChangeSet => {\n\t\tconst cs = find(id);\n\t\tif (cs.state !== \"open\") throw new ChangeSetClosedError(cs.state);\n\t\treturn cs;\n\t};\n\tconst statusName = (slug: string) => statuses.find((s) => s.slug === slug)?.name ?? slug;\n\t// Whether `from` reaches `to` through dependencies.\n\tconst reaches = (from: string, to: string, seen = new Set<string>()): boolean => {\n\t\tif (from === to) return true;\n\t\tif (seen.has(from)) return false;\n\t\tseen.add(from);\n\t\tconst cs = changeSets.find((c) => c.id === from);\n\t\treturn (cs?.dependsOnChangeSetIds ?? []).some((d) => reaches(d, to, seen));\n\t};\n\n\t// What a Required Check applies to in a Change Set, as the service's\n\t// currentView reads it: every Branch at its head, then every Branch-less\n\t// Planned Release at the Revision it re-pins.\n\tconst subjectsOf = (cs: ChangeSet) => [\n\t\t...cs.chains.flatMap((chain) =>\n\t\t\tchain.branches.map((b) => ({\n\t\t\t\tkey: b.id,\n\t\t\t\tbranchless: false,\n\t\t\t\tcontentId: chain.contentId,\n\t\t\t\trevision: b.headRevisionId,\n\t\t\t})),\n\t\t),\n\t\t...cs.plannedReleases\n\t\t\t.filter((pr) => pr.kind !== \"revision\" && pr.revisionId !== \"\")\n\t\t\t.map((pr) => ({\n\t\t\t\tkey: pr.id,\n\t\t\t\tbranchless: true,\n\t\t\t\tcontentId: pr.contentId,\n\t\t\t\trevision: pr.revisionId,\n\t\t\t})),\n\t];\n\tconst blueprintOf = (contentId: string) => contents.find((c) => c.id === contentId)?.blueprintId;\n\tconst covers = (check: RequiredCheck, contentId: string) =>\n\t\tcheck.blueprintAccessors.length === 0 ||\n\t\tcheck.blueprintAccessors.includes(blueprintOf(contentId) ?? \"\");\n\n\t/** Where each check stands, by name, as ListCheckResults answers. */\n\tconst standingsOf = (cs: ChangeSet): CheckStanding[] => {\n\t\tconst subjects = subjectsOf(cs);\n\t\t// Newest first. A Branch-scope result is about the one head it names,\n\t\t// a Change Set-scope one (\"\" here) about the whole.\n\t\tconst resultsOn = (check: RequiredCheck, subject: string): CheckResult[] =>\n\t\t\tcheckResults\n\t\t\t\t.filter((r) => r.changeSetId === cs.id && r.requiredCheckId === check.id)\n\t\t\t\t.filter((r) => (check.scope === \"change_set\" ? \"\" : Object.keys(r.heads)[0]) === subject)\n\t\t\t\t.reverse()\n\t\t\t\t.map(({ changeSetId: _, ...r }) => structuredClone(r));\n\t\tconst standing = (\n\t\t\tcheck: RequiredCheck,\n\t\t\tat: Pick<CheckStanding, \"contentId\" | \"branchId\" | \"releaseId\" | \"heads\">,\n\t\t\tresults: CheckResult[],\n\t\t): CheckStanding => {\n\t\t\tconst latest = results[0];\n\t\t\tconst stale = latest ? !sameHeads(latest.heads, at.heads) : false;\n\t\t\treturn {\n\t\t\t\tcheck: structuredClone(check),\n\t\t\t\t...at,\n\t\t\t\tresults,\n\t\t\t\tstale,\n\t\t\t\tcleared: !!latest && !stale && latest.outcome !== \"failed\",\n\t\t\t};\n\t\t};\n\t\tconst out: CheckStanding[] = [];\n\t\t// By name, then id, as the service orders them.\n\t\tconst byNameThenId = (a: RequiredCheck, b: RequiredCheck) =>\n\t\t\ta.name < b.name ? -1 : a.name > b.name ? 1 : a.id < b.id ? -1 : a.id > b.id ? 1 : 0;\n\t\tfor (const check of [...requiredChecks].sort(byNameThenId)) {\n\t\t\tconst covered = subjects.filter((s) => covers(check, s.contentId));\n\t\t\tif (check.scope === \"change_set\") {\n\t\t\t\tif (covered.length === 0) continue;\n\t\t\t\tconst heads = Object.fromEntries(subjects.map((s) => [s.key, s.revision]));\n\t\t\t\tout.push(\n\t\t\t\t\tstanding(\n\t\t\t\t\t\tcheck,\n\t\t\t\t\t\t{ contentId: \"\", branchId: \"\", releaseId: \"\", heads },\n\t\t\t\t\t\tresultsOn(check, \"\"),\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (const s of covered) {\n\t\t\t\tout.push(\n\t\t\t\t\tstanding(\n\t\t\t\t\t\tcheck,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcontentId: s.contentId,\n\t\t\t\t\t\t\tbranchId: s.branchless ? \"\" : s.key,\n\t\t\t\t\t\t\treleaseId: s.branchless ? s.key : \"\",\n\t\t\t\t\t\t\theads: { [s.key]: s.revision },\n\t\t\t\t\t\t},\n\t\t\t\t\t\tresultsOn(check, s.key),\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t};\n\n\t/**\n\t * The blockers a Publish of `cs` with `reviewed` meets: moved heads, open\n\t * or discarded dependencies, outstanding checks, top-level required\n\t * Fields a Branch head leaves empty, and what the options add for the\n\t * rest.\n\t */\n\tconst blockersOf = (cs: ChangeSet, reviewed: Record<string, string>): PublishBlocker[] => {\n\t\tconst out: PublishBlocker[] = [];\n\t\tconst current = headsOf(cs);\n\t\tfor (const chain of cs.chains) {\n\t\t\tfor (const b of chain.branches) {\n\t\t\t\tif (reviewed[b.id] !== b.headRevisionId) {\n\t\t\t\t\tout.push(\n\t\t\t\t\t\tstubBlocker(\"moved_head\", {\n\t\t\t\t\t\t\tcontentId: chain.contentId,\n\t\t\t\t\t\t\tbranchId: b.id,\n\t\t\t\t\t\t\texpectedHeadId: reviewed[b.id] ?? \"\",\n\t\t\t\t\t\t\tcurrentHeadId: b.headRevisionId,\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (const [id, head] of Object.entries(reviewed)) {\n\t\t\tif (!(id in current)) {\n\t\t\t\tout.push(stubBlocker(\"moved_head\", { branchId: id, expectedHeadId: head }));\n\t\t\t}\n\t\t}\n\t\tfor (const dep of cs.dependsOnChangeSetIds) {\n\t\t\tconst state = changeSets.find((c) => c.id === dep)?.state;\n\t\t\tif (state === \"open\") {\n\t\t\t\tout.push(stubBlocker(\"unpublished_dependency\", { dependencyChangeSetId: dep }));\n\t\t\t} else if (state === \"discarded\") {\n\t\t\t\tout.push(stubBlocker(\"discarded_dependency\", { dependencyChangeSetId: dep }));\n\t\t\t}\n\t\t}\n\t\tfor (const st of standingsOf(cs)) {\n\t\t\tif (!st.cleared) {\n\t\t\t\tout.push(\n\t\t\t\t\tstubBlocker(\"outstanding_check\", {\n\t\t\t\t\t\trequiredCheckId: st.check.id,\n\t\t\t\t\t\tcontentId: st.contentId,\n\t\t\t\t\t\tbranchId: st.branchId,\n\t\t\t\t\t\treleaseId: st.releaseId,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tfor (const chain of cs.chains) {\n\t\t\tconst c = contents.find((x) => x.id === chain.contentId);\n\t\t\tfor (const b of chain.branches) {\n\t\t\t\tconst data = c && dataOf(c, b.headRevisionId);\n\t\t\t\tif (!c || !data) continue;\n\t\t\t\tfor (const accessor of missingRequired(resolved[c.blueprintReleaseId]?.fields, data)) {\n\t\t\t\t\tout.push(\n\t\t\t\t\t\tstubBlocker(\"missing_required_field\", {\n\t\t\t\t\t\t\tcontentId: c.id,\n\t\t\t\t\t\t\trevisionId: b.headRevisionId,\n\t\t\t\t\t\t\tpath: `/${accessor}`,\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn [...out, ...structuredClone(extraBlockers[cs.id] ?? [])];\n\t};\n\n\t/** The Releases a Publish of `cs` cuts: every Planned Release not withheld. */\n\tconst releasesOf = (cs: ChangeSet): Release[] => {\n\t\tconst current = headsOf(cs);\n\t\treturn cs.plannedReleases\n\t\t\t.filter((pr) => !pr.withheld)\n\t\t\t.map((pr) => ({\n\t\t\t\tid: pr.id,\n\t\t\t\tcontentId: pr.contentId,\n\t\t\t\tkind: pr.kind,\n\t\t\t\tbranchId: pr.branchId,\n\t\t\t\trevisionId: pr.branchId ? (current[pr.branchId] ?? \"\") : pr.revisionId,\n\t\t\t\tfirst: !!cs.chains.find((c) => c.contentId === pr.contentId)?.born,\n\t\t\t\tsupersedesReleaseIds: [...pr.supersedesReleaseIds],\n\t\t\t\tvalidityPeriod: pr.validityPeriod ? { ...pr.validityPeriod } : undefined,\n\t\t\t}));\n\t};\n\n\tfor (const [branchId, conflict] of Object.entries(conflicts)) {\n\t\tif (conflict.pending) storeMerge(branchId, conflict);\n\t}\n\n\treturn {\n\t\tasync listBlockReasons() {\n\t\t\treturn [...reasons].sort(byName).map((r) => ({ ...r }));\n\t\t},\n\t\tasync createBlockReason({ name: raw }) {\n\t\t\tconst name = checkedBlockReasonName(raw);\n\t\t\tif (taken(name)) throw new BlockReasonNameTakenError(name);\n\t\t\tconst reason = { id: `br_stub_${next++}`, name, createTime: now(), updateTime: now() };\n\t\t\treasons.push(reason);\n\t\t\treturn { ...reason };\n\t\t},\n\t\tasync renameBlockReason({ id, name: raw }) {\n\t\t\tconst name = checkedBlockReasonName(raw);\n\t\t\tconst reason = reasons.find((r) => r.id === id);\n\t\t\tif (!reason) throw notFound(\"Block Reason\", id);\n\t\t\tif (taken(name, id)) throw new BlockReasonNameTakenError(name);\n\t\t\treason.name = name;\n\t\t\treason.updateTime = now();\n\t\t\treturn { ...reason };\n\t\t},\n\t\tasync deleteBlockReason({ id }) {\n\t\t\tif (!reasons.some((r) => r.id === id)) throw notFound(\"Block Reason\", id);\n\t\t\treasons = reasons.filter((r) => r.id !== id);\n\t\t},\n\n\t\tasync listChangeSets(input = {}) {\n\t\t\tconst matching = changeSets.filter(\n\t\t\t\t(cs) =>\n\t\t\t\t\t(!input.state || cs.state === input.state) &&\n\t\t\t\t\t(!input.assigneeId || cs.assigneeIds.includes(input.assigneeId)) &&\n\t\t\t\t\t(!input.contentId || cs.chains.some((c) => c.contentId === input.contentId)),\n\t\t\t);\n\t\t\tconst size = Math.min(input.pageSize || 50, 200);\n\t\t\tconst start = input.pageToken ? Number(input.pageToken) : 0;\n\t\t\tconst page = matching.slice(start, start + size);\n\t\t\treturn {\n\t\t\t\t// A list carries no Chains, dependencies or Planned Releases.\n\t\t\t\tchangeSets: page.map((cs) => ({\n\t\t\t\t\t...copy(cs),\n\t\t\t\t\tchains: [],\n\t\t\t\t\tdependsOnChangeSetIds: [],\n\t\t\t\t\tplannedReleases: [],\n\t\t\t\t})),\n\t\t\t\tnextPageToken: start + size < matching.length ? String(start + size) : \"\",\n\t\t\t};\n\t\t},\n\t\tasync createChangeSet({ name: rawName, source }) {\n\t\t\tconst name = oneLine(rawName, \"name\", CHANGE_SET_NAME_MAX);\n\t\t\tconst checkedSource = source ? checkedSourceOf(source) : undefined;\n\t\t\tconst cs: ChangeSet = {\n\t\t\t\tid: `cs_stub_${next++}`,\n\t\t\t\tname,\n\t\t\t\tsource: checkedSource,\n\t\t\t\tstate: \"open\",\n\t\t\t\tcreatedBy: userId,\n\t\t\t\tcreateTime: now(),\n\t\t\t\tchains: [],\n\t\t\t\tdependsOnChangeSetIds: [],\n\t\t\t\tstatus: \"\",\n\t\t\t\tassigneeIds: [],\n\t\t\t\tplannedReleases: [],\n\t\t\t};\n\t\t\tchangeSets.unshift(cs);\n\t\t\treturn copy(cs);\n\t\t},\n\t\tasync getChangeSet(id) {\n\t\t\treturn copy(find(id));\n\t\t},\n\t\tasync updateChangeSet({ id, updateMask, name, source }) {\n\t\t\tconst cs = open(id);\n\t\t\tif (updateMask.length === 0) throw new InvalidInputError(\"update_mask is required\");\n\t\t\t// Checked whole before anything changes, as the service does.\n\t\t\tconst nextName = updateMask.includes(\"name\")\n\t\t\t\t? oneLine(name ?? \"\", \"name\", CHANGE_SET_NAME_MAX)\n\t\t\t\t: cs.name;\n\t\t\tlet nextSource = cs.source;\n\t\t\tif (updateMask.includes(\"source\")) {\n\t\t\t\tnextSource = source ? checkedSourceOf(source) : undefined;\n\t\t\t}\n\t\t\tcs.name = nextName;\n\t\t\tcs.source = nextSource;\n\t\t\treturn copy(cs);\n\t\t},\n\t\tasync setChangeSetStatus({ id, expectedStatus, status }) {\n\t\t\tconst cs = open(id);\n\t\t\tif (cs.status !== expectedStatus) throw new StaleStatusError(cs.status);\n\t\t\t// Already there: nothing to ask statushub, as the service does.\n\t\t\tif (cs.status === status) return copy(cs);\n\t\t\tif (!statuses.some((s) => s.slug === status)) {\n\t\t\t\tthrow new InvalidInputError(`status \"${status}\" is not in the workspace's catalogue`);\n\t\t\t}\n\t\t\t// A move away from an unknown status is never validated, so a Change\n\t\t\t// Set is never stuck on a deleted status (ADR 0014).\n\t\t\tconst known = statuses.some((s) => s.slug === cs.status);\n\t\t\tif (known && !(transitions[cs.status] ?? []).includes(status)) {\n\t\t\t\tthrow new StatusTransitionRefusedError({\n\t\t\t\t\tfromStatus: cs.status,\n\t\t\t\t\ttoStatus: status,\n\t\t\t\t\treason: `There is no transition from ${statusName(cs.status)} to ${statusName(status)}.`,\n\t\t\t\t\trequiresPermission: false,\n\t\t\t\t});\n\t\t\t}\n\t\t\tcs.status = status;\n\t\t\treturn copy(cs);\n\t\t},\n\t\tasync setChangeSetAssignees({ id, assigneeIds }) {\n\t\t\tconst cs = find(id);\n\t\t\tif (new Set(assigneeIds).size !== assigneeIds.length) {\n\t\t\t\tthrow new InvalidInputError(\"each assignee is given once\");\n\t\t\t}\n\t\t\tif (assigneeIds.length > 50) throw new InvalidInputError(\"at most 50 assignees\");\n\t\t\tcs.assigneeIds = [...assigneeIds];\n\t\t\treturn copy(cs);\n\t\t},\n\t\tasync addDependency({ id, dependsOnId }) {\n\t\t\tconst cs = open(id);\n\t\t\tconst target = find(dependsOnId);\n\t\t\tif (target.state !== \"open\") {\n\t\t\t\tthrow new InvalidInputError(`Change Set ${dependsOnId} is ${target.state}`);\n\t\t\t}\n\t\t\tif (reaches(dependsOnId, id)) {\n\t\t\t\tthrow new InvalidInputError(\"the dependency would close a cycle\");\n\t\t\t}\n\t\t\tif (!cs.dependsOnChangeSetIds.includes(dependsOnId)) {\n\t\t\t\tcs.dependsOnChangeSetIds.push(dependsOnId);\n\t\t\t}\n\t\t\treturn copy(cs);\n\t\t},\n\t\tasync removeDependency({ id, dependsOnId }) {\n\t\t\tconst cs = open(id);\n\t\t\tif (!cs.dependsOnChangeSetIds.includes(dependsOnId)) {\n\t\t\t\tthrow notFound(`dependency of Change Set ${id} on`, dependsOnId);\n\t\t\t}\n\t\t\tcs.dependsOnChangeSetIds = cs.dependsOnChangeSetIds.filter((d) => d !== dependsOnId);\n\t\t\treturn copy(cs);\n\t\t},\n\t\tasync validatePublish({ id, reviewedHeads }) {\n\t\t\tconst cs = find(id);\n\t\t\trefuseWithheld(id);\n\t\t\tconst published = publishedWith.get(id);\n\t\t\t// Published with these heads: the stored outcome. With others, it is closed.\n\t\t\tif (published && sameHeads(published, reviewedHeads)) {\n\t\t\t\treturn {\n\t\t\t\t\tblockers: [],\n\t\t\t\t\treleases: releasesOf(cs),\n\t\t\t\t\tpublished: true,\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (cs.state !== \"open\") throw new ChangeSetClosedError(cs.state);\n\t\t\treturn {\n\t\t\t\tblockers: blockersOf(cs, reviewedHeads),\n\t\t\t\treleases: releasesOf(cs),\n\t\t\t\tpublished: false,\n\t\t\t};\n\t\t},\n\t\tasync publish({ id, reviewedHeads }) {\n\t\t\tconst cs = find(id);\n\t\t\trefuseWithheld(id);\n\t\t\tconst published = publishedWith.get(id);\n\t\t\t// A repeat with the same heads returns the stored outcome.\n\t\t\tif (published && sameHeads(published, reviewedHeads)) {\n\t\t\t\treturn {\n\t\t\t\t\tchangeSet: copy(cs),\n\t\t\t\t\tpublishTime: cs.closeTime ?? now(),\n\t\t\t\t\treleases: releasesOf(cs),\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (cs.state !== \"open\") throw new ChangeSetClosedError(cs.state);\n\t\t\tconst blockers = blockersOf(cs, reviewedHeads);\n\t\t\tif (blockers.length > 0) throw new PublishRefusedError(blockers);\n\t\t\tconst cut = releasesOf(cs);\n\t\t\tcs.state = \"published\";\n\t\t\tcs.closeTime = now();\n\t\t\tpublishedWith.set(id, { ...reviewedHeads });\n\t\t\treturn { changeSet: copy(cs), publishTime: cs.closeTime, releases: cut };\n\t\t},\n\t\tasync updateFromMain({ id, chainId, idempotencyKey }) {\n\t\t\treturn once(idempotencyKey, [\"updateFromMain\", id, chainId], async () => {\n\t\t\t\tconst cs = open(id);\n\t\t\t\tif (!chainId) refuseWithheld(id);\n\t\t\t\tconst chains = chainId ? cs.chains.filter((ch) => ch.id === chainId) : cs.chains;\n\t\t\t\tif (chainId && chains.length === 0) throw notFound(\"Chain\", chainId);\n\t\t\t\tconst conflicted: PendingMergeRef[] = structuredClone(pendingMerges[id] ?? []);\n\t\t\t\tconst pending: PendingMergeRef[] = [];\n\t\t\t\tfor (const chain of chains) {\n\t\t\t\t\tfor (const b of chain.branches) {\n\t\t\t\t\t\tconst ref = { branchId: b.id, contentId: chain.contentId };\n\t\t\t\t\t\tconst conflict = conflicts[b.id];\n\t\t\t\t\t\tif (stored.has(b.id)) pending.push(ref);\n\t\t\t\t\t\telse if (conflict) {\n\t\t\t\t\t\t\tstoreMerge(b.id, conflict);\n\t\t\t\t\t\t\tconflicted.push(ref);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tchangeSet: copy(cs),\n\t\t\t\t\tmergedBranchIds: [],\n\t\t\t\t\tconflicted,\n\t\t\t\t\tpending,\n\t\t\t\t\tendedBranchIds: [],\n\t\t\t\t};\n\t\t\t});\n\t\t},\n\t\tasync discardChangeSet(id) {\n\t\t\tconst cs = open(id);\n\t\t\trefuseWithheld(id);\n\t\t\tcs.state = \"discarded\";\n\t\t\tcs.closeTime = now();\n\t\t\t// The Content born in it is gone, and its Chains with it.\n\t\t\tcs.chains = [];\n\t\t\treturn copy(cs);\n\t\t},\n\t\tasync listCheckResults(changeSetId) {\n\t\t\treturn standingsOf(find(changeSetId));\n\t\t},\n\t\tasync recordCheckResult({ changeSetId, requiredCheckId, heads, outcome, note }) {\n\t\t\tconst cs = open(changeSetId);\n\t\t\tif (outcome === \"waived\" && note.trim() === \"\") {\n\t\t\t\tthrow new InvalidInputError(\"a waived result needs a note saying why\");\n\t\t\t}\n\t\t\tif ([...note].length > CHECK_NOTE_MAX) {\n\t\t\t\tthrow new InvalidInputError(`a note is at most ${CHECK_NOTE_MAX} characters`);\n\t\t\t}\n\t\t\tconst check = requiredChecks.find((c) => c.id === requiredCheckId);\n\t\t\tif (!check) throw notFound(\"Required Check\", requiredCheckId);\n\t\t\tconst recording = recordersOf(requiredCheckId);\n\t\t\t// The caller is a member: the stub has no other kind of caller.\n\t\t\tif (\n\t\t\t\tauthzMode === \"guardian\" &&\n\t\t\t\t!recording.everyMember &&\n\t\t\t\t!recording.userIds.includes(userId)\n\t\t\t) {\n\t\t\t\tthrow new CheckResultDeniedError(\n\t\t\t\t\t`recording results of Required Check ${requiredCheckId} needs its recorder relation`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst subjects = subjectsOf(cs);\n\t\t\tconst named = Object.keys(heads);\n\t\t\tif (check.scope === \"branch\" && named.length !== 1) {\n\t\t\t\tthrow new InvalidInputError(\"a Branch-scope result names one head\");\n\t\t\t}\n\t\t\tif (check.scope === \"change_set\" && named.length !== subjects.length) {\n\t\t\t\tthrow new InvalidInputError(\"a Change Set-scope result names every head of the Change Set\");\n\t\t\t}\n\t\t\tfor (const key of named) {\n\t\t\t\tconst s = subjects.find((each) => each.key === key);\n\t\t\t\tif (!s)\n\t\t\t\t\tthrow new InvalidInputError(`heads name ${key}, which this Change Set doesn't hold`);\n\t\t\t\tif (s.revision !== heads[key]) {\n\t\t\t\t\tthrow new StaleHeadError({\n\t\t\t\t\t\tcontentId: s.contentId,\n\t\t\t\t\t\tbranchId: s.branchless ? \"\" : s.key,\n\t\t\t\t\t\texpectedHeadId: heads[key],\n\t\t\t\t\t\tcurrentHeadId: s.revision,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst result = {\n\t\t\t\tid: `cr_stub_${next++}`,\n\t\t\t\trequiredCheckId,\n\t\t\t\theads: { ...heads },\n\t\t\t\toutcome,\n\t\t\t\tnote,\n\t\t\t\trecordedBy: userId,\n\t\t\t\trecordTime: now(),\n\t\t\t};\n\t\t\tcheckResults.push({ ...result, changeSetId });\n\t\t\treturn structuredClone(result);\n\t\t},\n\n\t\tasync listRequiredChecks() {\n\t\t\tconst byNameThenId = (a: RequiredCheck, b: RequiredCheck) =>\n\t\t\t\ta.name < b.name ? -1 : a.name > b.name ? 1 : a.id < b.id ? -1 : a.id > b.id ? 1 : 0;\n\t\t\treturn structuredClone([...requiredChecks].sort(byNameThenId));\n\t\t},\n\t\tasync createRequiredCheck(input) {\n\t\t\tconst checked = checkedRequiredCheck(input);\n\t\t\tif (requiredChecks.some((c) => c.name === checked.name)) {\n\t\t\t\tthrow new NameTakenError(checked.name);\n\t\t\t}\n\t\t\tconst check: RequiredCheck = { id: `rc_stub_${next++}`, ...checked };\n\t\t\trequiredChecks.push(check);\n\t\t\treturn structuredClone(check);\n\t\t},\n\t\tasync updateRequiredCheck({ id, ...input }) {\n\t\t\tconst checked = checkedRequiredCheck(input);\n\t\t\tconst check = requiredChecks.find((c) => c.id === id);\n\t\t\tif (!check) throw notFound(\"Required Check\", id);\n\t\t\tif (requiredChecks.some((c) => c.name === checked.name && c.id !== id)) {\n\t\t\t\tthrow new NameTakenError(checked.name);\n\t\t\t}\n\t\t\tObject.assign(check, checked);\n\t\t\treturn structuredClone(check);\n\t\t},\n\t\tasync deleteRequiredCheck({ id }) {\n\t\t\tif (!requiredChecks.some((c) => c.id === id)) throw notFound(\"Required Check\", id);\n\t\t\trequiredChecks = requiredChecks.filter((c) => c.id !== id);\n\t\t\trecorders.delete(id);\n\t\t},\n\t\tasync listRequiredCheckRecorders(requiredCheckId) {\n\t\t\treturn structuredClone(narrowable(requiredCheckId));\n\t\t},\n\t\tasync grantRequiredCheckRecorder({ requiredCheckId, recorder }) {\n\t\t\tconst held = narrowable(requiredCheckId);\n\t\t\tif (\"everyMember\" in recorder) {\n\t\t\t\trecorders.set(requiredCheckId, { ...held, everyMember: true });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!memberIds.includes(recorder.userId)) {\n\t\t\t\tthrow new InvalidInputError(`user ${recorder.userId} is not a member of the workspace`);\n\t\t\t}\n\t\t\trecorders.set(requiredCheckId, {\n\t\t\t\t...held,\n\t\t\t\tuserIds: [...new Set([...held.userIds, recorder.userId])].sort(),\n\t\t\t});\n\t\t},\n\t\tasync revokeRequiredCheckRecorder({ requiredCheckId, recorder }) {\n\t\t\tconst held = narrowable(requiredCheckId);\n\t\t\trecorders.set(\n\t\t\t\trequiredCheckId,\n\t\t\t\t\"everyMember\" in recorder\n\t\t\t\t\t? { ...held, everyMember: false }\n\t\t\t\t\t: { ...held, userIds: held.userIds.filter((u) => u !== recorder.userId) },\n\t\t\t);\n\t\t},\n\n\t\tasync searchBlueprints({ query }) {\n\t\t\tconst q = query.trim().toLocaleLowerCase();\n\t\t\treturn {\n\t\t\t\tblueprints: blueprints\n\t\t\t\t\t.filter((b) => b.name.toLocaleLowerCase().includes(q))\n\t\t\t\t\t.filter((b) => releases.some((r) => r.blueprintId === b.id))\n\t\t\t\t\t.map((b) => ({ ...b })),\n\t\t\t\tnextPageToken: \"\",\n\t\t\t};\n\t\t},\n\t\tasync listBlueprintReleases(blueprintId) {\n\t\t\treturn releases\n\t\t\t\t.filter((r) => r.blueprintId === blueprintId)\n\t\t\t\t.map((r) => ({\n\t\t\t\t\tid: r.id,\n\t\t\t\t\tblueprintId: r.blueprintId,\n\t\t\t\t\tname: r.name ?? r.id,\n\t\t\t\t\treleaseTime: r.releaseTime ?? STUB_NOW,\n\t\t\t\t\trefusals: (r.refusals ?? []).map((v) => ({ ...v })),\n\t\t\t\t}));\n\t\t},\n\n\t\tasync listCollections() {\n\t\t\treturn [...collections].sort(collectionOrder).map((c) => ({ ...c }));\n\t\t},\n\t\tasync createCollection({ name: raw, parentId = \"\", restricted = false }) {\n\t\t\tconst name = oneLine(raw, \"a Collection's name\", COLLECTION_NAME_MAX);\n\t\t\tif (parentId !== \"\") findCollection(parentId);\n\t\t\tif (restricted && authzMode === \"workspace\") {\n\t\t\t\tthrow new RestrictionUnavailableError(WORKSPACE_MODE_REFUSAL);\n\t\t\t}\n\t\t\tif (siblingNamed(parentId, name)) throw new NameTakenError(name);\n\t\t\tconst collection: Collection = { id: `col_stub_${next++}`, name, parentId, restricted };\n\t\t\tcollections.push(collection);\n\t\t\tif (restricted) grants.set(collection.id, [{ userId, level: \"owner\" }]);\n\t\t\treturn { ...collection };\n\t\t},\n\t\tasync renameCollection({ id, name: raw }) {\n\t\t\tconst name = oneLine(raw, \"a Collection's name\", COLLECTION_NAME_MAX);\n\t\t\tconst collection = findCollection(id);\n\t\t\tif (siblingNamed(collection.parentId, name, id)) throw new NameTakenError(name);\n\t\t\tcollection.name = name;\n\t\t\treturn { ...collection };\n\t\t},\n\t\tasync moveCollection({ id, parentId }) {\n\t\t\tconst collection = findCollection(id);\n\t\t\tfor (let at = parentId; at !== \"\"; at = findCollection(at).parentId) {\n\t\t\t\tif (at === id) {\n\t\t\t\t\tthrow new InvalidInputError(\n\t\t\t\t\t\t`Collection ${id} can't move under itself or a Collection under it`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\t// As over the wire: a move sends no name, so the refusal names none.\n\t\t\tif (siblingNamed(parentId, collection.name, id)) throw new NameTakenError(\"\");\n\t\t\tcollection.parentId = parentId;\n\t\t\treturn { ...collection };\n\t\t},\n\t\tasync removeCollection({ id }) {\n\t\t\tfindCollection(id);\n\t\t\tif (collections.some((c) => c.parentId === id)) {\n\t\t\t\tthrow new InvalidInputError(\n\t\t\t\t\t`Collection ${id} has Collections under it: remove or move those first`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcollections.splice(\n\t\t\t\tcollections.findIndex((c) => c.id === id),\n\t\t\t\t1,\n\t\t\t);\n\t\t\tgrants.delete(id);\n\t\t\tconst unfiled: string[] = [];\n\t\t\tfor (const c of contents) {\n\t\t\t\tif (c.collectionIds.includes(id)) {\n\t\t\t\t\tc.collectionIds = c.collectionIds.filter((each) => each !== id);\n\t\t\t\t\tunfiled.push(c.id);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn unfiled;\n\t\t},\n\t\tasync setCollectionRestricted({ id, restricted, acknowledgeDisclosure = false }) {\n\t\t\tif (restricted && authzMode === \"workspace\") {\n\t\t\t\tthrow new RestrictionUnavailableError(WORKSPACE_MODE_REFUSAL);\n\t\t\t}\n\t\t\tconst collection = findCollection(id);\n\t\t\tif (collection.restricted === restricted) return { ...collection };\n\t\t\tif (!restricted && !acknowledgeDisclosure) {\n\t\t\t\tthrow new InvalidInputError(\n\t\t\t\t\t`unrestricting Collection ${id} discloses its Content to every viewer: ` +\n\t\t\t\t\t\t\"confirm it with acknowledge_disclosure\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tcollection.restricted = restricted;\n\t\t\t// The one who restricts it owns it; opening it clears every grant.\n\t\t\tif (restricted) grants.set(id, [{ userId, level: \"owner\" }]);\n\t\t\telse grants.delete(id);\n\t\t\treturn { ...collection };\n\t\t},\n\t\tasync listCollectionGrants(collectionId) {\n\t\t\tmanageable(collectionId);\n\t\t\treturn structuredClone(grants.get(collectionId) ?? []).sort((a, b) =>\n\t\t\t\ta.userId < b.userId ? -1 : a.userId > b.userId ? 1 : 0,\n\t\t\t);\n\t\t},\n\t\tasync grantCollectionAccess({ collectionId, userId: grantee, level }) {\n\t\t\tmanageable(collectionId);\n\t\t\tif (level !== \"viewer\" && level !== \"editor\") {\n\t\t\t\tthrow new InvalidInputError(\"a grant is viewer or editor\");\n\t\t\t}\n\t\t\tif (!memberIds.includes(grantee)) {\n\t\t\t\tthrow new InvalidInputError(`${grantee} is not a member of the workspace`);\n\t\t\t}\n\t\t\tconst held = grants.get(collectionId) ?? [];\n\t\t\t// The owner stays owner: a grant never lowers what restricting gave.\n\t\t\tif (held.some((g) => g.level === \"owner\" && g.userId === grantee)) return;\n\t\t\tgrants.set(collectionId, [\n\t\t\t\t...held.filter((g) => g.userId !== grantee),\n\t\t\t\t{ userId: grantee, level },\n\t\t\t]);\n\t\t},\n\t\tasync revokeCollectionAccess({ collectionId, userId: grantee }) {\n\t\t\tmanageable(collectionId);\n\t\t\tgrants.set(\n\t\t\t\tcollectionId,\n\t\t\t\t(grants.get(collectionId) ?? []).filter((g) => g.userId !== grantee || g.level === \"owner\"),\n\t\t\t);\n\t\t},\n\t\tasync listContents(input = {}) {\n\t\t\tconst view: ContentView = input.view ?? { kind: \"main\" };\n\t\t\tconst search = (input.search ?? \"\").trim();\n\t\t\tif (search !== \"\" && view.kind === \"in_force\") {\n\t\t\t\tthrow new InvalidInputError(\n\t\t\t\t\t\"filter.search: Editor Search covers Main and open Branch heads, never Releases\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif ([...search].length > CONTENT_SEARCH_MAX) {\n\t\t\t\tthrow new InvalidInputError(`filter.search is at most ${CONTENT_SEARCH_MAX} characters`);\n\t\t\t}\n\t\t\tif (input.collectionId && !collections.some((c) => c.id === input.collectionId)) {\n\t\t\t\tthrow notFound(\"Collection\", input.collectionId);\n\t\t\t}\n\t\t\tif (view.kind === \"change_set\") find(view.changeSetId);\n\n\t\t\tconst rows = contents\n\t\t\t\t// Archived Content is put aside: every view leaves it out (ADR 0015).\n\t\t\t\t.filter((c) => !c.archiveTime)\n\t\t\t\t.filter((c) => !input.collectionId || c.collectionIds.includes(input.collectionId))\n\t\t\t\t.filter((c) => !input.blueprintIds?.length || input.blueprintIds.includes(c.blueprintId))\n\t\t\t\t.filter((c) => !input.assigneeId || (c.assigneeIds ?? []).includes(input.assigneeId))\n\t\t\t\t.sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0))\n\t\t\t\t.flatMap((c) => readsOf(c, view, search));\n\t\t\tconst size = Math.min(input.pageSize || 50, 200);\n\t\t\tconst start = input.pageToken ? Number(input.pageToken) : 0;\n\t\t\treturn {\n\t\t\t\tcontents: rows.slice(start, start + size),\n\t\t\t\tnextPageToken: start + size < rows.length ? String(start + size) : \"\",\n\t\t\t};\n\t\t},\n\t\tasync createContent({ changeSetId, blueprintReleaseId: asked, copyFrom }) {\n\t\t\tconst cs = open(changeSetId);\n\t\t\tlet data: Record<string, unknown> = {};\n\t\t\tlet blueprintReleaseId = asked;\n\t\t\tif (copyFrom) {\n\t\t\t\tconst sourceRevision =\n\t\t\t\t\t\"revisionId\" in copyFrom\n\t\t\t\t\t\t? copyFrom.revisionId\n\t\t\t\t\t\t: contents.find((c) => c.inForce?.releaseId === copyFrom.releaseId)?.inForce\n\t\t\t\t\t\t\t\t?.revisionId;\n\t\t\t\tconst source = contents.find((c) => sourceRevision && dataOf(c, sourceRevision));\n\t\t\t\tif (!source || !sourceRevision) {\n\t\t\t\t\tthrow notFound(\"copy source\", JSON.stringify(copyFrom));\n\t\t\t\t}\n\t\t\t\tdata = structuredClone(dataOf(source, sourceRevision) ?? {});\n\t\t\t\tblueprintReleaseId = asked || source.blueprintReleaseId;\n\t\t\t}\n\t\t\tconst release = releases.find((r) => r.id === blueprintReleaseId);\n\t\t\tif (!release) {\n\t\t\t\tthrow new ContentRefusedError(`Blueprint Release ${blueprintReleaseId} can't be loaded`, [\n\t\t\t\t\t{ source: \"contenthub\", code: \"release_not_found\", path: \"\" },\n\t\t\t\t]);\n\t\t\t}\n\t\t\tif (release.refusals?.length) {\n\t\t\t\tthrow new ContentRefusedError(\n\t\t\t\t\t`Blueprint Release ${blueprintReleaseId} can't be loaded`,\n\t\t\t\t\trelease.refusals.map((r) => ({ ...r })),\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst n = next++;\n\t\t\tconst id = `content_stub_${n}`;\n\t\t\tconst branchId = `br_stub_${n}`;\n\t\t\tconst revisionId = `rev_stub_${n}`;\n\t\t\tcontents.push({\n\t\t\t\tid,\n\t\t\t\tblueprintId: release.blueprintId,\n\t\t\t\tblueprintReleaseId,\n\t\t\t\tcollectionIds: [],\n\t\t\t\tbranches: {\n\t\t\t\t\t[changeSetId]: { branchId, revisionId, data, revisionCreateTime: now() },\n\t\t\t\t},\n\t\t\t});\n\t\t\tcs.chains.push({\n\t\t\t\tid: `chain_stub_${n}`,\n\t\t\t\tcontentId: id,\n\t\t\t\tborn: true,\n\t\t\t\tbranches: [{ id: branchId, position: 0, kind: \"editorial\", headRevisionId: revisionId }],\n\t\t\t});\n\t\t\treturn {\n\t\t\t\tid,\n\t\t\t\tblueprintId: release.blueprintId,\n\t\t\t\tblueprintReleaseId,\n\t\t\t\trevisionId,\n\t\t\t\tdata: structuredClone(data),\n\t\t\t\tchangeSetId,\n\t\t\t\tbranchId,\n\t\t\t\trevisionCreateTime: now(),\n\t\t\t\treleaseId: \"\",\n\t\t\t};\n\t\t},\n\n\t\tasync saveRevision({ idempotencyKey, ...request }) {\n\t\t\tif (!idempotencyKey) return saveOnce(request);\n\t\t\t// A repeat answers the first save and writes nothing; another\n\t\t\t// request under the same key is refused (CONTEXT.md, Idempotency Key).\n\t\t\tconst asked = JSON.stringify(request);\n\t\t\tconst kept = savedUnder.get(idempotencyKey);\n\t\t\tif (kept) {\n\t\t\t\tif (kept.asked !== asked) {\n\t\t\t\t\tthrow new InvalidInputError(`idempotency key ${idempotencyKey} names another save`);\n\t\t\t\t}\n\t\t\t\treturn structuredClone(kept.content);\n\t\t\t}\n\t\t\tconst content = await saveOnce(request);\n\t\t\tsavedUnder.set(idempotencyKey, { asked, content: structuredClone(content) });\n\t\t\treturn content;\n\t\t},\n\n\t\tasync getContent({ id, changeSetId }) {\n\t\t\tconst c = findContent(id);\n\t\t\tconst view: ContentView = changeSetId\n\t\t\t\t? { kind: \"change_set\", changeSetId }\n\t\t\t\t: { kind: \"main\" };\n\t\t\t// Born in an open Change Set, it exists only there, as the service says.\n\t\t\tconst [content] = readsOf(c, view, \"\");\n\t\t\tif (!content) throw notFound(\"Content\", id);\n\t\t\tconst release = resolved[c.blueprintReleaseId];\n\t\t\treturn {\n\t\t\t\tcontent,\n\t\t\t\tblueprintRelease: release ? structuredClone(release) : undefined,\n\t\t\t\tattributes: attributesOf(c),\n\t\t\t};\n\t\t},\n\t\tasync getTimeline(contentId) {\n\t\t\tconst c = findContent(contentId);\n\t\t\tconst isOpen = (csId: string) => changeSets.find((cs) => cs.id === csId)?.state === \"open\";\n\t\t\treturn structuredClone({\n\t\t\t\tentries: c.timeline ?? [],\n\t\t\t\tplannedReleases: (c.plannedReleases ?? []).filter((p) => isOpen(p.changeSetId)),\n\t\t\t});\n\t\t},\n\t\tasync listRevisions({ target, pageSize, pageToken }) {\n\t\t\tlet found: (Revision & { data?: unknown })[];\n\t\t\tif (\"contentId\" in target) {\n\t\t\t\tconst c = findContent(target.contentId);\n\t\t\t\t// versionkit lists by Item only once it is published (#65).\n\t\t\t\tif (!c.main) throw notFound(\"Content\", target.contentId);\n\t\t\t\tfound = revisionsOf(c);\n\t\t\t} else {\n\t\t\t\tconst owner = contents.find((c) =>\n\t\t\t\t\trevisionsOf(c).some((r) => r.branchId === target.branchId),\n\t\t\t\t);\n\t\t\t\tif (!owner) throw notFound(\"Branch\", target.branchId);\n\t\t\t\tfound = revisionsOf(owner).filter((r) => r.branchId === target.branchId);\n\t\t\t}\n\t\t\tconst size = Math.min(pageSize || 50, 200);\n\t\t\tconst start = pageToken ? Number(pageToken) : 0;\n\t\t\treturn {\n\t\t\t\trevisions: found.slice(start, start + size).map(({ data: _data, ...r }) => r),\n\t\t\t\tnextPageToken: start + size < found.length ? String(start + size) : \"\",\n\t\t\t};\n\t\t},\n\t\tasync compare({ revisionId, base }) {\n\t\t\tconst c = contents.find((each) => revisionsOf(each).some((r) => r.id === revisionId));\n\t\t\tif (!c) throw notFound(\"Revision\", revisionId);\n\t\t\tconst all = revisionsOf(c);\n\t\t\tconst after = all.find((r) => r.id === revisionId) as Revision;\n\t\t\tlet baseId: string;\n\t\t\tif (base.kind === \"revision\") baseId = base.revisionId;\n\t\t\telse if (base.kind === \"main_head\") {\n\t\t\t\tif (!c.main) {\n\t\t\t\t\tthrow new InvalidInputError(\"the Content is not published: it has no Main Branch\");\n\t\t\t\t}\n\t\t\t\tbaseId = c.main.revisionId;\n\t\t\t} else baseId = all.find((r) => r.branchId === base.branchId)?.parentId ?? \"\";\n\t\t\tconst before = all.find((r) => r.id === baseId);\n\t\t\tif (!before) throw notFound(\"Revision\", baseId);\n\t\t\tconst a = dataOf(c, after.id) ?? {};\n\t\t\tconst b = dataOf(c, before.id) ?? {};\n\t\t\tconst changes: FieldChange[] = [];\n\t\t\tfor (const key of [...new Set([...Object.keys(a), ...Object.keys(b)])]) {\n\t\t\t\tif (!(key in b)) changes.push({ path: `/${key}`, kind: \"added\", after: a[key] });\n\t\t\t\telse if (!(key in a)) changes.push({ path: `/${key}`, kind: \"removed\", before: b[key] });\n\t\t\t\telse if (JSON.stringify(a[key]) !== JSON.stringify(b[key])) {\n\t\t\t\t\tchanges.push({ path: `/${key}`, kind: \"changed\", before: b[key], after: a[key] });\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst strip = ({ data: _data, ...r }: Revision & { data?: unknown }) => r;\n\t\t\treturn { base: strip(before), revision: strip(after), changes };\n\t\t},\n\t\tasync listReferences({ contentId, revisionId }) {\n\t\t\tconst c = findContent(contentId);\n\t\t\treturn (c.edges ?? [])\n\t\t\t\t.filter((e) => e.sourceRevisionId === revisionId)\n\t\t\t\t.map((e) => ({ ...e }));\n\t\t},\n\t\tasync listReferrers({ contentId, includeOpenChangeSets, pageSize, pageToken }) {\n\t\t\tfindContent(contentId);\n\t\t\t// Paged as the service pages, by position in its order.\n\t\t\tconst page = (rows: Referrer[]): ReferrerList => {\n\t\t\t\tconst size = Math.min(pageSize || 100, 1000);\n\t\t\t\tconst start = pageToken ? Number(pageToken) : 0;\n\t\t\t\treturn {\n\t\t\t\t\treferrers: rows.slice(start, start + size),\n\t\t\t\t\tnextPageToken: start + size < rows.length ? String(start + size) : \"\",\n\t\t\t\t};\n\t\t\t};\n\t\t\tconst fromReleases = contents.flatMap((other) =>\n\t\t\t\t(other.edges ?? [])\n\t\t\t\t\t.filter(\n\t\t\t\t\t\t(e) =>\n\t\t\t\t\t\t\te.targetContentId === contentId && other.inForce?.revisionId === e.sourceRevisionId,\n\t\t\t\t\t)\n\t\t\t\t\t.map((e) => ({\n\t\t\t\t\t\tedge: { ...e },\n\t\t\t\t\t\treleaseId: other.inForce?.releaseId ?? \"\",\n\t\t\t\t\t\tchangeSetId: \"\",\n\t\t\t\t\t\tbranchId: \"\",\n\t\t\t\t\t})),\n\t\t\t);\n\t\t\tif (!includeOpenChangeSets) return page(fromReleases);\n\t\t\tconst fromBranches = contents.flatMap((other) =>\n\t\t\t\tObject.entries(other.branches).flatMap(([csId, head]) =>\n\t\t\t\t\tchangeSets.find((cs) => cs.id === csId)?.state !== \"open\"\n\t\t\t\t\t\t? []\n\t\t\t\t\t\t: (other.edges ?? [])\n\t\t\t\t\t\t\t\t.filter(\n\t\t\t\t\t\t\t\t\t(e) => e.targetContentId === contentId && e.sourceRevisionId === head.revisionId,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t.map((e) => ({\n\t\t\t\t\t\t\t\t\tedge: { ...e },\n\t\t\t\t\t\t\t\t\treleaseId: \"\",\n\t\t\t\t\t\t\t\t\tchangeSetId: csId,\n\t\t\t\t\t\t\t\t\tbranchId: head.branchId,\n\t\t\t\t\t\t\t\t})),\n\t\t\t\t),\n\t\t\t);\n\t\t\treturn page([...fromReleases, ...fromBranches]);\n\t\t},\n\t\tasync listOutdatedPins(input) {\n\t\t\tlet revisionId: string | undefined;\n\t\t\tif (\"revisionId\" in input) revisionId = input.revisionId;\n\t\t\telse {\n\t\t\t\tfor (const c of contents) {\n\t\t\t\t\tconst head = Object.values(c.branches).find((h) => h.branchId === input.branchId);\n\t\t\t\t\tif (head) revisionId = head.revisionId;\n\t\t\t\t}\n\t\t\t\tif (!revisionId) throw notFound(\"Branch\", input.branchId);\n\t\t\t}\n\t\t\tconst edges: Edge[] = contents.flatMap((c) =>\n\t\t\t\t(c.edges ?? []).filter((e) => e.sourceRevisionId === revisionId),\n\t\t\t);\n\t\t\treturn edges\n\t\t\t\t.filter((e) => e.pinReleaseId !== \"\")\n\t\t\t\t.flatMap((e) => {\n\t\t\t\t\tconst target = contents.find((c) => c.id === e.targetContentId);\n\t\t\t\t\tconst inForce = target?.inForce?.releaseId ?? \"\";\n\t\t\t\t\tif (inForce === e.pinReleaseId) return [];\n\t\t\t\t\treturn [{ edge: { ...e }, supersededByReleaseId: inForce, inForceReleaseId: inForce }];\n\t\t\t\t});\n\t\t},\n\n\t\tasync setContentCollections({ contentId, collectionIds }) {\n\t\t\tconst c = findContent(contentId);\n\t\t\tconst unique = [...new Set(collectionIds)];\n\t\t\tif (unique.length > 100) throw new InvalidInputError(\"at most 100 Collections\");\n\t\t\tfor (const id of unique) {\n\t\t\t\tif (!collections.some((col) => col.id === id)) throw notFound(\"Collection\", id);\n\t\t\t}\n\t\t\tc.collectionIds = unique.sort();\n\t\t\treturn [...c.collectionIds];\n\t\t},\n\t\tasync setContentAssignees({ contentId, assigneeIds }) {\n\t\t\tconst c = findContent(contentId);\n\t\t\tif (new Set(assigneeIds).size !== assigneeIds.length) {\n\t\t\t\tthrow new InvalidInputError(\"each assignee is given once\");\n\t\t\t}\n\t\t\tif (assigneeIds.length > 50) throw new InvalidInputError(\"at most 50 assignees\");\n\t\t\tc.assigneeIds = [...assigneeIds];\n\t\t\treturn attributesOf(c);\n\t\t},\n\t\tasync blockContent({ contentId, blockReasonId, allowedUserIds }) {\n\t\t\tconst c = findContent(contentId);\n\t\t\tif (!reasons.some((r) => r.id === blockReasonId)) {\n\t\t\t\tthrow notFound(\"Block Reason\", blockReasonId);\n\t\t\t}\n\t\t\tif (new Set(allowedUserIds).size !== allowedUserIds.length) {\n\t\t\t\tthrow new InvalidInputError(\"each allowed user is given once\");\n\t\t\t}\n\t\t\tc.block = {\n\t\t\t\tblockReasonId,\n\t\t\t\tallowedUserIds: [...allowedUserIds],\n\t\t\t\tblockedBy: userId,\n\t\t\t\tblockTime: now(),\n\t\t\t};\n\t\t\treturn attributesOf(c);\n\t\t},\n\t\tasync unblockContent(contentId) {\n\t\t\tconst c = findContent(contentId);\n\t\t\tc.block = undefined;\n\t\t\treturn attributesOf(c);\n\t\t},\n\t\tasync archiveContent(contentId) {\n\t\t\tconst c = findContent(contentId);\n\t\t\tif (c.archiveTime) return attributesOf(c);\n\t\t\tif (!c.main) {\n\t\t\t\tthrow new InvalidInputError(\n\t\t\t\t\t`Content ${contentId} is not published: discard its Change Set instead of archiving it`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (inForceOnOrAfter(c.timeline ?? [], today())) {\n\t\t\t\tthrow new InvalidInputError(\n\t\t\t\t\t`Content ${contentId} has a Release In Force today or later: end its force first`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tc.archiveTime = now();\n\t\t\treturn attributesOf(c);\n\t\t},\n\t\tasync unarchiveContent(contentId) {\n\t\t\tconst c = findContent(contentId);\n\t\t\tc.archiveTime = undefined;\n\t\t\treturn attributesOf(c);\n\t\t},\n\n\t\tasync startEditing({ contentId, changeSetId, effectiveOn = \"\", changeSetName = \"\" }) {\n\t\t\tconst c = findContent(contentId);\n\t\t\tif (!c.main) {\n\t\t\t\tthrow new InvalidInputError(`Content ${contentId} is not published`);\n\t\t\t}\n\t\t\tcheckEditable(c);\n\t\t\tif (datedContent(c) && !DAY.test(effectiveOn)) {\n\t\t\t\tthrow new InvalidInputError(\"effective_on is required for Dated Content, as YYYY-MM-DD\");\n\t\t\t}\n\t\t\tif (!datedContent(c) && effectiveOn !== \"\") {\n\t\t\t\tthrow new InvalidInputError(\"effective_on is refused for undated Content\");\n\t\t\t}\n\t\t\tlet cs: ChangeSet;\n\t\t\tif (changeSetId) {\n\t\t\t\tcs = open(changeSetId);\n\t\t\t\tif (cs.chains.some((chain) => chain.contentId === contentId)) {\n\t\t\t\t\tthrow new InvalidInputError(\n\t\t\t\t\t\t`Content ${contentId} already has a Chain in this Change Set`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst label = Object.values(c.main.data)\n\t\t\t\t\t.filter((v): v is string => typeof v === \"string\")\n\t\t\t\t\t.slice(0, 2)\n\t\t\t\t\t.join(\" \");\n\t\t\t\tcs = {\n\t\t\t\t\tid: `cs_stub_${next++}`,\n\t\t\t\t\tname: changeSetName.trim()\n\t\t\t\t\t\t? oneLine(changeSetName, \"change_set_name\", CHANGE_SET_NAME_MAX)\n\t\t\t\t\t\t: label || contentId,\n\t\t\t\t\tstate: \"open\",\n\t\t\t\t\tcreatedBy: userId,\n\t\t\t\t\tcreateTime: now(),\n\t\t\t\t\tchains: [],\n\t\t\t\t\tdependsOnChangeSetIds: [],\n\t\t\t\t\tstatus: \"\",\n\t\t\t\t\tassigneeIds: [],\n\t\t\t\t\tplannedReleases: [],\n\t\t\t\t};\n\t\t\t\tchangeSets.unshift(cs);\n\t\t\t}\n\t\t\tconst n = next++;\n\t\t\tconst branchId = `br_stub_${n}`;\n\t\t\t// A Branch started on an existing Revision writes none.\n\t\t\tconst head = { ...structuredClone(c.main), branchId };\n\t\t\tc.branches[cs.id] = head;\n\t\t\tcs.chains.push({\n\t\t\t\tid: `chain_stub_${n}`,\n\t\t\t\tcontentId,\n\t\t\t\tborn: false,\n\t\t\t\tbranches: [\n\t\t\t\t\t{ id: branchId, position: 0, kind: \"editorial\", headRevisionId: head.revisionId },\n\t\t\t\t],\n\t\t\t});\n\t\t\tconst [content] = readsOf(c, { kind: \"change_set\", changeSetId: cs.id }, \"\");\n\t\t\treturn { changeSet: copy(cs), content };\n\t\t},\n\t\tasync previewChain({ changeSetId, contentId, effectiveOn, validityPeriod }) {\n\t\t\topen(changeSetId);\n\t\t\tconst c = findContent(contentId);\n\t\t\tif (!c.main) throw new InvalidInputError(`Content ${contentId} is not published`);\n\t\t\tif (!datedContent(c)) throw new InvalidInputError(\"undated Content's Chain takes no date\");\n\t\t\tif (!DAY.test(effectiveOn)) throw new InvalidInputError(\"effective_on is YYYY-MM-DD\");\n\t\t\tconst entries = c.timeline ?? [];\n\t\t\tconst fork = entries.find(\n\t\t\t\t(e) =>\n\t\t\t\t\te.validityPeriod &&\n\t\t\t\t\te.validityPeriod.firstDay <= effectiveOn &&\n\t\t\t\t\t(e.validityPeriod.lastDay === \"\" || effectiveOn <= e.validityPeriod.lastDay),\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tforkReleaseId: fork?.releaseId ?? \"\",\n\t\t\t\tcarryForwardReleaseIds: entries\n\t\t\t\t\t.filter((e) => e.validityPeriod && e.validityPeriod.firstDay > effectiveOn)\n\t\t\t\t\t.map((e) => e.releaseId),\n\t\t\t\tmergesMain: false,\n\t\t\t\tcutIntoReleaseIds: fork ? [fork.releaseId] : [],\n\t\t\t\t// Only a period with a last day covers a Release: an open end\n\t\t\t\t// ends where the next Release starts.\n\t\t\t\tcoveredReleaseIds:\n\t\t\t\t\tvalidityPeriod && validityPeriod.lastDay !== \"\"\n\t\t\t\t\t\t? entries\n\t\t\t\t\t\t\t\t.filter(\n\t\t\t\t\t\t\t\t\t(e) =>\n\t\t\t\t\t\t\t\t\t\te.validityPeriod &&\n\t\t\t\t\t\t\t\t\t\te.validityPeriod.lastDay !== \"\" &&\n\t\t\t\t\t\t\t\t\t\tvalidityPeriod.firstDay <= e.validityPeriod.firstDay &&\n\t\t\t\t\t\t\t\t\t\te.validityPeriod.lastDay <= validityPeriod.lastDay,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t.map((e) => e.releaseId)\n\t\t\t\t\t\t: [],\n\t\t\t};\n\t\t},\n\t\tasync planRepeal({ changeSetId, contentId, lastDay }) {\n\t\t\topen(changeSetId);\n\t\t\tconst c = findContent(contentId);\n\t\t\tcheckEditable(c);\n\t\t\tif (!datedContent(c)) throw new InvalidInputError(\"a Repeal is for Dated Content\");\n\t\t\tif (!DAY.test(lastDay)) throw new InvalidInputError(\"last_day is YYYY-MM-DD\");\n\t\t\tconst inForce = releaseInForceOn(c.timeline ?? [], lastDay);\n\t\t\treturn plan(c, changeSetId, {\n\t\t\t\tkind: \"repeal\",\n\t\t\t\tvalidityPeriod: { firstDay: inForce?.validityPeriod?.firstDay ?? lastDay, lastDay },\n\t\t\t});\n\t\t},\n\t\tasync planWithdrawal({ changeSetId, contentId }) {\n\t\t\topen(changeSetId);\n\t\t\tconst c = findContent(contentId);\n\t\t\tcheckEditable(c);\n\t\t\tif (datedContent(c)) throw new InvalidInputError(\"a Withdrawal is for undated Content\");\n\t\t\treturn plan(c, changeSetId, { kind: \"withdrawal\" });\n\t\t},\n\n\t\tasync planRelease({ idempotencyKey, ...request }) {\n\t\t\treturn once(idempotencyKey, [\"planRelease\", request], async () => {\n\t\t\t\tconst { changeSetId, branchId, validityPeriod, releaseSpec, supersedesReleaseIds } =\n\t\t\t\t\trequest;\n\t\t\t\tconst { cs, chain, branch, c } = branchIn(changeSetId, branchId);\n\t\t\t\tcheckEditable(c);\n\t\t\t\tif (branch.kind !== \"editorial\") {\n\t\t\t\t\tthrow new InvalidInputError(\"only an editorial Branch's head is released\");\n\t\t\t\t}\n\t\t\t\tif (cs.plannedReleases.some((p) => p.branchId === branchId)) {\n\t\t\t\t\tthrow new InvalidInputError(`Branch ${branchId} is planned already`);\n\t\t\t\t}\n\t\t\t\tconst plan: PlannedRelease = {\n\t\t\t\t\tid: `rls_stub_${next++}`,\n\t\t\t\t\tcontentId: chain.contentId,\n\t\t\t\t\tkind: \"revision\",\n\t\t\t\t\tbranchId,\n\t\t\t\t\trevisionId: \"\",\n\t\t\t\t\tvalidityPeriod: validityPeriod ? { ...validityPeriod } : undefined,\n\t\t\t\t\treleaseSpec: structuredClone(releaseSpec ?? {}),\n\t\t\t\t\tsupersedesReleaseIds: [...(supersedesReleaseIds ?? [])],\n\t\t\t\t\tproposed: false,\n\t\t\t\t\tproposedForReleaseId: \"\",\n\t\t\t\t\tsplitFromReleaseId: \"\",\n\t\t\t\t\twithheld: false,\n\t\t\t\t};\n\t\t\t\tcheckPlan(c, plan);\n\t\t\t\tcs.plannedReleases.push(plan);\n\t\t\t\trepropose(cs, c);\n\t\t\t\treturn structuredClone(plan);\n\t\t\t});\n\t\t},\n\t\tasync updatePlannedRelease({ idempotencyKey, ...request }) {\n\t\t\treturn once(idempotencyKey, [\"updatePlannedRelease\", request], async () => {\n\t\t\t\tconst { changeSetId, plannedReleaseId, validityPeriod, releaseSpec, supersedesReleaseIds } =\n\t\t\t\t\trequest;\n\t\t\t\tconst cs = open(changeSetId);\n\t\t\t\tconst at = cs.plannedReleases.findIndex((p) => p.id === plannedReleaseId);\n\t\t\t\tif (at < 0) throw notFound(\"Planned Release\", plannedReleaseId);\n\t\t\t\tconst current = cs.plannedReleases[at];\n\t\t\t\tif (current.proposed) {\n\t\t\t\t\tthrow new InvalidInputError(\"a proposal is derived from the plans and can't be set\");\n\t\t\t\t}\n\t\t\t\tconst c = findContent(current.contentId);\n\t\t\t\tcheckEditable(c);\n\t\t\t\tconst updated: PlannedRelease = {\n\t\t\t\t\t...structuredClone(current),\n\t\t\t\t\t...(validityPeriod ? { validityPeriod: { ...validityPeriod } } : {}),\n\t\t\t\t\t...(releaseSpec ? { releaseSpec: structuredClone(releaseSpec) } : {}),\n\t\t\t\t\t...(supersedesReleaseIds ? { supersedesReleaseIds: [...supersedesReleaseIds] } : {}),\n\t\t\t\t};\n\t\t\t\tcheckPlan(c, updated);\n\t\t\t\tcs.plannedReleases[at] = updated;\n\t\t\t\trepropose(cs, c);\n\t\t\t\treturn structuredClone(updated);\n\t\t\t});\n\t\t},\n\t\tasync appendBranch({ idempotencyKey, ...request }) {\n\t\t\treturn once(idempotencyKey, [\"appendBranch\", request], async () => {\n\t\t\t\tconst { changeSetId, chainId, effectiveOn } = request;\n\t\t\t\tconst cs = open(changeSetId);\n\t\t\t\tconst chain = cs.chains.find((ch) => ch.id === chainId);\n\t\t\t\tif (!chain) throw notFound(\"Chain\", chainId);\n\t\t\t\tconst c = findContent(chain.contentId);\n\t\t\t\tif (chain.born || !datedContent(c)) {\n\t\t\t\t\tthrow new InvalidInputError(\"only a Chain on published Dated Content takes dates\");\n\t\t\t\t}\n\t\t\t\tconst last = chain.branches.filter((b) => b.kind === \"editorial\").at(-1);\n\t\t\t\tif (!DAY.test(effectiveOn) || (last?.effectiveOn && effectiveOn <= last.effectiveOn)) {\n\t\t\t\t\tthrow new InvalidInputError(\n\t\t\t\t\t\t\"effective_on is a day after the Chain's last editorial Branch's\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst tip = chain.branches.at(-1);\n\t\t\t\tconst n = next++;\n\t\t\t\tconst branchId = `br_stub_${n}`;\n\t\t\t\tchain.branches.push({\n\t\t\t\t\tid: branchId,\n\t\t\t\t\tposition: chain.branches.length,\n\t\t\t\t\tkind: \"editorial\",\n\t\t\t\t\t// A Branch starts at the head of the one before: no Revision written.\n\t\t\t\t\theadRevisionId: tip?.headRevisionId ?? \"\",\n\t\t\t\t\teffectiveOn,\n\t\t\t\t});\n\t\t\t\tconst head = c.branches[changeSetId];\n\t\t\t\tif (head) c.branches[changeSetId] = { ...head, branchId };\n\t\t\t\treturn { changeSet: copy(cs), branchId };\n\t\t\t});\n\t\t},\n\t\tasync dropChain({ idempotencyKey, ...request }) {\n\t\t\treturn once(idempotencyKey, [\"dropChain\", request], async () => {\n\t\t\t\tconst { changeSetId, chainId } = request;\n\t\t\t\tconst cs = open(changeSetId);\n\t\t\t\tconst chain = cs.chains.find((ch) => ch.id === chainId);\n\t\t\t\tif (!chain) throw notFound(\"Chain\", chainId);\n\t\t\t\tif (chain.born) {\n\t\t\t\t\tthrow new InvalidInputError(\n\t\t\t\t\t\t\"the Chain of Content born in the Change Set can't be dropped: discard the Change Set\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tfor (const b of chain.branches) dropMerge(b.id);\n\t\t\t\tcs.chains = cs.chains.filter((ch) => ch.id !== chainId);\n\t\t\t\tcs.plannedReleases = cs.plannedReleases.filter((p) => p.contentId !== chain.contentId);\n\t\t\t\tdelete findContent(chain.contentId).branches[changeSetId];\n\t\t\t\treturn copy(cs);\n\t\t\t});\n\t\t},\n\t\tasync getPendingMerge(branchId) {\n\t\t\tconst pm = stored.get(branchId);\n\t\t\treturn pm ? structuredClone(pm) : null;\n\t\t},\n\t\tasync resolveMerge({ idempotencyKey, ...request }) {\n\t\t\treturn once(idempotencyKey, [\"resolveMerge\", request], async () => {\n\t\t\t\tconst { changeSetId, branchId, expectedHeadId, resolutions } = request;\n\t\t\t\tconst { chain, branch, c } = branchIn(changeSetId, branchId);\n\t\t\t\tconst pm = stored.get(branchId);\n\t\t\t\tif (!pm) throw new InvalidInputError(`Branch ${branchId} has no Pending Merge`);\n\t\t\t\tif (branch.headRevisionId !== expectedHeadId) {\n\t\t\t\t\tthrow new StaleHeadError({\n\t\t\t\t\t\tcontentId: c.id,\n\t\t\t\t\t\tbranchId,\n\t\t\t\t\t\texpectedHeadId,\n\t\t\t\t\t\tcurrentHeadId: branch.headRevisionId,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tconst paths = resolutions.map((r) => r.path);\n\t\t\t\tconst listed = pm.fields.map((f) => f.path);\n\t\t\t\tif (\n\t\t\t\t\tnew Set(paths).size !== paths.length ||\n\t\t\t\t\tpaths.some((p) => !listed.includes(p)) ||\n\t\t\t\t\tlisted.some((p) => !paths.includes(p))\n\t\t\t\t) {\n\t\t\t\t\tthrow new InvalidInputError(\"decide every field the Pending Merge lists, once\");\n\t\t\t\t}\n\t\t\t\tconst data = structuredClone(pm.merged);\n\t\t\t\tfor (const r of resolutions) {\n\t\t\t\t\tconst f = pm.fields.find((each) => each.path === r.path) as MergeField;\n\t\t\t\t\tconst value = \"side\" in r ? (r.side === \"ours\" ? f.ours : f.theirs) : r.value;\n\t\t\t\t\tconst key = r.path.replace(/^\\//, \"\");\n\t\t\t\t\tif (value === undefined) delete data[key];\n\t\t\t\t\telse data[key] = structuredClone(value);\n\t\t\t\t}\n\t\t\t\tconst content = writeHead({\n\t\t\t\t\tchangeSetId,\n\t\t\t\t\tchain,\n\t\t\t\t\tbranch,\n\t\t\t\t\tc,\n\t\t\t\t\tdata,\n\t\t\t\t\tcause: \"resolve\",\n\t\t\t\t\tsecondParentId: pm.theirsRevisionId,\n\t\t\t\t});\n\t\t\t\tdropMerge(branchId);\n\t\t\t\treturn content;\n\t\t\t});\n\t\t},\n\t\tasync abortMerge({ idempotencyKey, ...request }) {\n\t\t\treturn once(idempotencyKey, [\"abortMerge\", request], async () => {\n\t\t\t\tbranchIn(request.changeSetId, request.branchId);\n\t\t\t\tif (!stored.has(request.branchId)) {\n\t\t\t\t\tthrow new InvalidInputError(`Branch ${request.branchId} has no Pending Merge`);\n\t\t\t\t}\n\t\t\t\tdropMerge(request.branchId);\n\t\t\t});\n\t\t},\n\t\tasync previewInForce({ contentId, changeSetId, validOn }) {\n\t\t\tconst cs = open(changeSetId);\n\t\t\tconst c = findContent(contentId);\n\t\t\tconst day = validOn || today();\n\t\t\tconst chain = cs.chains.find((ch) => ch.contentId === contentId);\n\t\t\tconst covers = (p: PlannedRelease) =>\n\t\t\t\t!p.validityPeriod ||\n\t\t\t\t(p.validityPeriod.firstDay <= day &&\n\t\t\t\t\t(p.validityPeriod.lastDay === \"\" || day <= p.validityPeriod.lastDay));\n\t\t\t// The Change Set's own plans first, read as if published now.\n\t\t\tconst plan = cs.plannedReleases.find(\n\t\t\t\t(p) => p.contentId === contentId && p.kind !== \"repeal\" && covers(p),\n\t\t\t);\n\t\t\tif (plan) {\n\t\t\t\tconst revisionId = plan.branchId\n\t\t\t\t\t? (chain?.branches.find((b) => b.id === plan.branchId)?.headRevisionId ?? \"\")\n\t\t\t\t\t: plan.revisionId;\n\t\t\t\treturn {\n\t\t\t\t\treleaseId: plan.id,\n\t\t\t\t\trevisionId,\n\t\t\t\t\tplanned: true,\n\t\t\t\t\twithheld: false,\n\t\t\t\t\tvalidityPeriod: plan.validityPeriod ? { ...plan.validityPeriod } : undefined,\n\t\t\t\t\tdata: structuredClone(dataOf(c, revisionId) ?? {}),\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst entry = releaseInForceOn(c.timeline ?? [], day);\n\t\t\tif (!entry) return null;\n\t\t\treturn {\n\t\t\t\treleaseId: entry.releaseId,\n\t\t\t\trevisionId: entry.revisionId,\n\t\t\t\tplanned: false,\n\t\t\t\twithheld: false,\n\t\t\t\tvalidityPeriod: entry.validityPeriod ? { ...entry.validityPeriod } : undefined,\n\t\t\t\tdata: structuredClone(dataOf(c, entry.revisionId) ?? {}),\n\t\t\t};\n\t\t},\n\t};\n\n\t/** Plans a Release ending a Content's force in a Change Set, warning of the gap it leaves. */\n\tfunction plan(\n\t\tc: StubContent,\n\t\tchangeSetId: string,\n\t\twhat: Pick<PlannedEnd[\"plannedRelease\"], \"kind\" | \"validityPeriod\">,\n\t): PlannedEnd {\n\t\tconst plannedRelease = {\n\t\t\tid: `rls_stub_${next++}`,\n\t\t\tcontentId: c.id,\n\t\t\tbranchId: \"\",\n\t\t\t// A Repeal or Withdrawal re-pins the Revision In Force.\n\t\t\trevisionId: c.inForce?.revisionId ?? c.main?.revisionId ?? \"\",\n\t\t\tsupersedesReleaseIds: [],\n\t\t\tproposed: false,\n\t\t\tproposedForReleaseId: \"\",\n\t\t\tsplitFromReleaseId: \"\",\n\t\t\twithheld: false,\n\t\t\t...what,\n\t\t};\n\t\tc.plannedReleases = [...(c.plannedReleases ?? []), { changeSetId, plannedRelease }];\n\t\treturn structuredClone({ plannedRelease, gapReferrers: gapReferrersOf(c.id) });\n\t}\n\n\t/**\n\t * Every row one Content gives in a view: its Main head on Main, its\n\t * Release on In Force, its head in a Change Set there. A search on Main\n\t * also reads every open Branch head, one row per head that matched, as\n\t * Editor Search does (ADR 0019).\n\t */\n\tfunction readsOf(c: StubContent, view: ContentView, search: string): Content[] {\n\t\tconst row = (\n\t\t\thead: { revisionId: string; data: Record<string, unknown>; revisionCreateTime: string },\n\t\t\tat: { changeSetId?: string; branchId?: string; releaseId?: string },\n\t\t): Content => ({\n\t\t\tid: c.id,\n\t\t\tblueprintId: c.blueprintId,\n\t\t\tblueprintReleaseId: c.blueprintReleaseId,\n\t\t\trevisionId: head.revisionId,\n\t\t\tdata: structuredClone(head.data),\n\t\t\tchangeSetId: at.changeSetId ?? \"\",\n\t\t\tbranchId: at.branchId ?? \"\",\n\t\t\trevisionCreateTime: head.revisionCreateTime,\n\t\t\treleaseId: at.releaseId ?? \"\",\n\t\t});\n\t\tif (view.kind === \"in_force\") {\n\t\t\treturn c.inForce ? [row(c.inForce, { releaseId: c.inForce.releaseId })] : [];\n\t\t}\n\t\tif (view.kind === \"change_set\") {\n\t\t\tconst head = c.branches[view.changeSetId];\n\t\t\tif (!head || (search && !matches(head.data, search))) return [];\n\t\t\treturn [row(head, { changeSetId: view.changeSetId, branchId: head.branchId })];\n\t\t}\n\t\tif (!search) return c.main ? [row(c.main, {})] : [];\n\t\tconst hits: Content[] = [];\n\t\tif (c.main && matches(c.main.data, search)) hits.push(row(c.main, {}));\n\t\tfor (const [csId, head] of Object.entries(c.branches).sort(([, a], [, b]) =>\n\t\t\ta.branchId < b.branchId ? -1 : 1,\n\t\t)) {\n\t\t\tconst inOpen = changeSets.find((cs) => cs.id === csId)?.state === \"open\";\n\t\t\tif (inOpen && matches(head.data, search)) {\n\t\t\t\thits.push(row(head, { changeSetId: csId, branchId: head.branchId }));\n\t\t\t}\n\t\t}\n\t\treturn hits;\n\t}\n}\n\n/** Editor Search's match: within one field, ignoring case, any run of whitespace for any run. */\nfunction matches(data: Record<string, unknown>, search: string): boolean {\n\tconst fold = (s: string) => s.toLocaleLowerCase().replace(/\\s+/g, \" \");\n\tconst needle = fold(search);\n\treturn Object.values(data).some((v) => typeof v === \"string\" && fold(v).includes(needle));\n}\n","// A `StatusSource` over a fixed catalogue: the port a host fills with\n// statushub (ADR 0020), stubbed so a host's tests need no statushub.\nimport type { ChangeSetStatusInfo, StatusSource } from \"../types\";\nimport { stubChangeSetStatuses } from \"./fixtures\";\n\nexport function createStubStatusSource(\n\tstatuses: ChangeSetStatusInfo[] = stubChangeSetStatuses(),\n): StatusSource {\n\treturn {\n\t\tasync listChangeSetStatuses() {\n\t\t\treturn statuses.map((s) => ({ ...s }));\n\t\t},\n\t};\n}\n"],"mappings":";;;;AAkBA,IAAauB,IAAoB,WACpBC,IAAe,aAEfC,IAAqB,YACrBC,IAAW;AAGxB,SAAgBC,IAA6B;CAC5C,OAAO;EACN,QAAQH;EACR,aAAaD;EACb,SAASK,EAAkB,CAC1B;GAAE,QAAQJ;GAAc,aAAa;GAAc,OAAO;EAAkB,GAC5E;GAAE,QAAQC;GAAoB,aAAa;GAAgB,OAAO;EAAkB,CACrF,CAAC;CACF;AACD;AAGA,SAAgBI,KAAkC;CACjD,OAAO,CACN;EACC,IAAI;EACJ,MAAM;EACN,YAAYH;EACZ,YAAYA;CACb,GACA;EACC,IAAI;EACJ,MAAM;EACN,YAAYA;EACZ,YAAYA;CACb,CACD;AACD;AAOA,SAAgBI,KAA+C;CAC9D,OAAO;EACN;GAAE,MAAM;GAAe,MAAM;GAAkB,OAAO;EAAY;EAClE;GAAE,MAAM;GAAa,MAAM;GAAc,OAAO;EAAS;EACzD;GAAE,MAAM;GAAS,MAAM;GAAU,OAAO;EAAW;EACnD;GAAE,MAAM;GAAW,MAAM;GAAkB,OAAO;EAAO;CAC1D;AACD;AAOA,SAAgBC,KAAkD;CACjE,OAAO;EACN,aAAa,CAAC,aAAa,SAAS;EAC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,EAAK;GAAS,CAAC,CAAC;EAC9E;EACA,IAAI,CAACqG,GAAQ,OAAO3K,EAAE,OAAO,CAAC6N,EAAI7N,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;EAClD,IAAM+N,IAAkB,CAAC;EACzB,AAAI/N,EAAE,QAAQ8N,EAAQ9N,EAAE,KAAK,MAAM2K,CAAM,KAAGoD,EAAK,KAAKF,EAAI7N,EAAE,MAAM,CAAC,CAAC,CAAC;EACrE,KAAK,IAAM,CAACqC,GAAMiC,MAAS,OAAO,QAAQtE,EAAE,QAAQ,CAAC,CAAC,MAAM,GAAGrB,IAAI,GAAGrB,OACrEqB,EAAE,WAAWrB,EAAE,WAAW,KAAK,CAChC,GAEC,AADewC,EAAW,MAAM,MAAOV,EAAG,OAAOiD,CAAI,CAAC,EAAE,UAAU,UACpDyL,EAAQxJ,EAAK,MAAMqG,CAAM,KACtCoD,EAAK,KAAKF,EAAIvJ,GAAM;GAAE,aAAajC;GAAM,UAAUiC,EAAK;EAAS,CAAC,CAAC;EAGrE,OAAOyJ;CACR;AACD;AAGA,SAASD,EAAQ,GAA+B,GAAyB;CACxE,IAAME,KAAQ,MAAc7H,EAAE,kBAAkB,CAAC,CAAC,QAAQ,QAAQ,GAAG,GAC/D8H,IAASD,EAAKrD,CAAM;CAC1B,OAAO,OAAO,OAAOnG,CAAI,CAAC,CAAC,MAAM,MAAM,OAAO7B,KAAM,YAAYqL,EAAKrL,CAAC,CAAC,CAAC,SAASsL,CAAM,CAAC;AACzF;;;AC7iEA,SAAgBC,EACf,IAAkC9R,GAAsB,GACzC;CACf,OAAO,EACN,MAAM,wBAAwB;EAC7B,OAAOuD,EAAS,KAAK,OAAO,EAAE,GAAGwG,EAAE,EAAE;CACtC,EACD;AACD"}
1
+ {"version":3,"file":"testing.js","names":["StaleHeadError","MAX_BLUEPRINT_IDS","RestrictionUnavailableError","StatusTransitionRefusedError","WithheldWorkError","InvalidInputError","PublishRefusedError","ContentArchivedError","CoversReleaseError","CHECK_NOTE_MAX","CheckResultDeniedError","ChangeSetClosedError","inForceOnOrAfter","StaleStatusError","sameHeads","releaseInForceOn","DAY","AccessDeniedError","headsOf","BlockReasonNameTakenError","ContentBlockedError","NameTakenError","GuardianModeRequiredError","ContentRefusedError","STUB_WORKSPACE_ID","STUB_USER_ID","STUB_OTHER_USER_ID","STUB_NOW","stubIdentity","createHostMembers","stubBlockReasons","stubChangeSetStatuses","stubStatusTransitions","stubChangeSets","stubRequiredChecks","stubCollections","stubBlueprints","stubBlueprintReleases","stubResolvedReleases","text","accessor","paragraph","stubRepealedContent","at","stubContents","createStubBlueprintSource","q","query","blueprints","b","ids","releases","r","blueprintId","shiftDay","d","day","by","oneLine","value","raw","what","max","checkedSourceOf","source","checkedBlockReasonName","name","checkedRequiredCheck","input","accessors","a","RECORDERS_WORKSPACE_MODE","WITHHELD_REFUSAL","WORKSPACE_MODE_REFUSAL","notFound","ConnectError","id","Code","copy","cs","stubBlocker","fields","createStubContenthubClient","now","options","userId","statuses","transitions","reasons","changeSets","collections","c","contents","resolved","requiredChecks","authzMode","withheld","refuseWithheld","grants","recorders","recordersOf","checkId","memberIds","admin","checkResults","extraBlockers","pendingMerges","conflicts","stored","wroteUnder","once","key","write","asked","request","kept","answer","publishedWith","savedUnder","next","findContent","each","attributesOf","today","datedContent","revisionsOf","listed","heads","csId","h","dataOf","revisionId","missingRequired","unset","v","f","values","checkEditable","gapReferrersOf","other","e","contentId","byName","taken","except","collectionOrder","findCollection","siblingNamed","parentId","manageable","owns","g","narrowable","saveOnce","chain","open","changeSetId","ch","branchId","branch","expectedHeadId","head","sent","data","saved","fieldMask","stray","k","writeHead","createTime","branchIn","storeMerge","pm","conflict","dropMerge","checkPlan","vp","plan","violations","covered","repropose","previous","p","proposals","propose","same","splitFromReleaseId","its","find","statusName","s","slug","reaches","from","to","seen","subjectsOf","pr","blueprintOf","covers","check","standingsOf","subjects","resultsOn","subject","_","standing","latest","results","stale","out","byNameThenId","blockersOf","current","reviewed","dep","state","st","x","releasesOf","reason","matching","size","start","rawName","checkedSource","updateMask","nextName","nextSource","expectedStatus","status","assigneeIds","target","dependsOnId","published","reviewedHeads","blockers","cut","idempotencyKey","chainId","chains","conflicted","pending","ref","outcome","note","requiredCheckId","recording","named","result","checked","held","recorder","u","restricted","collection","unfiled","acknowledgeDisclosure","collectionId","grantee","level","view","search","rows","readsOf","blueprintReleaseId","copyFrom","sourceRevision","release","n","content","rev","isOpen","found","owner","pageSize","pageToken","_data","all","after","baseId","base","before","changes","strip","page","fromReleases","includeOpenChangeSets","fromBranches","inForce","unique","collectionIds","col","blockReasonId","allowedUserIds","effectiveOn","label","changeSetName","entries","fork","validityPeriod","lastDay","releaseSpec","supersedesReleaseIds","plannedReleaseId","updated","last","tip","paths","resolutions","validOn","entry","plannedRelease","row","matches","hits","fold","needle","createStubStatusSource"],"sources":["../src/testing/fixtures.ts","../src/testing/stub-blueprint-source.ts","../src/testing/stub-client.ts","../src/testing/stub-status-source.ts"],"sourcesContent":["import { createHostMembers, type HostIdentity } from \"@knkcs/anker/host\";\nimport type {\n\tBlockReason,\n\tBlueprintInfo,\n\tBlueprintReleaseInfo,\n\tChangeSet,\n\tChangeSetStatusInfo,\n\tCollection,\n\tContentBlock,\n\tEdge,\n\tPlannedRelease,\n\tRequiredCheck,\n\tResolvedBlueprintRelease,\n\tResolvedField,\n\tRevision,\n\tTimelineEntry,\n} from \"../types\";\n\nexport const STUB_WORKSPACE_ID = \"ws_stub\";\nexport const STUB_USER_ID = \"user_stub\";\n/** A second member of the stub workspace, to assign and filter by. */\nexport const STUB_OTHER_USER_ID = \"user_ben\";\nexport const STUB_NOW = \"2026-10-01T09:00:00.000Z\";\n\n/** Who is looking, for anker's `TestHost` or `<HostProvider identity>`. */\nexport function stubIdentity(): HostIdentity {\n\treturn {\n\t\tuserId: STUB_USER_ID,\n\t\tworkspaceId: STUB_WORKSPACE_ID,\n\t\tmembers: createHostMembers([\n\t\t\t{ userId: STUB_USER_ID, displayName: \"Ada Editor\", email: \"ada@example.com\" },\n\t\t\t{ userId: STUB_OTHER_USER_ID, displayName: \"Ben Reviewer\", email: \"ben@example.com\" },\n\t\t]),\n\t};\n}\n\n/** A legal publisher's Block Reasons, in the service's order (by name). */\nexport function stubBlockReasons(): BlockReason[] {\n\treturn [\n\t\t{\n\t\t\tid: \"br_author\",\n\t\t\tname: \"Being revised by the author\",\n\t\t\tcreateTime: STUB_NOW,\n\t\t\tupdateTime: STUB_NOW,\n\t\t},\n\t\t{\n\t\t\tid: \"br_embargo\",\n\t\t\tname: \"Embargoed until publication\",\n\t\t\tcreateTime: STUB_NOW,\n\t\t\tupdateTime: STUB_NOW,\n\t\t},\n\t];\n}\n\n/**\n * statushub's seed catalogue for `contenthub/change_set` (spec #56, story 9),\n * as the `StatusSource` port answers it. Colours are CSS names: statushub\n * holds whatever CSS colour an admin chose.\n */\nexport function stubChangeSetStatuses(): ChangeSetStatusInfo[] {\n\treturn [\n\t\t{ slug: \"in_progress\", name: \"In Bearbeitung\", color: \"steelblue\", isDefault: true },\n\t\t{ slug: \"in_review\", name: \"In Prüfung\", color: \"orange\" },\n\t\t{ slug: \"ready\", name: \"Bereit\", color: \"seagreen\" },\n\t\t{ slug: \"on_hold\", name: \"Zurückgestellt\", color: \"gray\" },\n\t];\n}\n\n/**\n * The moves the stub's statushub allows, from slug to slugs. Anything else is\n * refused with a reason, as statushub refuses it; a move away from an unknown\n * status is never checked (contenthub ADR 0014).\n */\nexport function stubStatusTransitions(): Record<string, string[]> {\n\treturn {\n\t\tin_progress: [\"in_review\", \"on_hold\"],\n\t\tin_review: [\"in_progress\", \"ready\", \"on_hold\"],\n\t\tready: [\"in_review\", \"on_hold\"],\n\t\ton_hold: [\"in_progress\"],\n\t};\n}\n\n/**\n * A gazette's Change Sets: one open with two Chains (§ 1 amended twice, so\n * two Branches, and a paragraph born in it), one open with nothing in it yet,\n * and one published correction. Newest first, as the service lists them.\n */\nexport function stubChangeSets(): ChangeSet[] {\n\treturn [\n\t\t{\n\t\t\tid: \"cs_bgbl_270\",\n\t\t\tname: \"BGBl. 2026 I Nr. 270\",\n\t\t\tsource: { date: \"2026-09-20\", reference: \"BGBl. 2026 I Nr. 270\" },\n\t\t\tstate: \"open\",\n\t\t\tcreatedBy: STUB_USER_ID,\n\t\t\tcreateTime: \"2026-09-30T08:00:00.000Z\",\n\t\t\tchains: [\n\t\t\t\t{\n\t\t\t\t\tid: \"chain_para_1\",\n\t\t\t\t\tcontentId: \"content_para_1\",\n\t\t\t\t\tborn: false,\n\t\t\t\t\tbranches: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tid: \"br_para_1_a\",\n\t\t\t\t\t\t\tposition: 0,\n\t\t\t\t\t\t\tkind: \"editorial\",\n\t\t\t\t\t\t\theadRevisionId: \"rev_p1_a2\",\n\t\t\t\t\t\t\teffectiveOn: \"2026-07-01\",\n\t\t\t\t\t\t\tcarriedReleaseId: \"rls_p1_1\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tid: \"br_para_1_b\",\n\t\t\t\t\t\t\tposition: 1,\n\t\t\t\t\t\t\tkind: \"editorial\",\n\t\t\t\t\t\t\theadRevisionId: \"rev_p1_b1\",\n\t\t\t\t\t\t\teffectiveOn: \"2026-10-01\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tid: \"chain_para_4a\",\n\t\t\t\t\tcontentId: \"content_para_4a\",\n\t\t\t\t\tborn: true,\n\t\t\t\t\tbranches: [\n\t\t\t\t\t\t{ id: \"br_para_4a\", position: 0, kind: \"editorial\", headRevisionId: \"rev_p4a_1\" },\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t],\n\t\t\tdependsOnChangeSetIds: [],\n\t\t\tstatus: \"in_progress\",\n\t\t\tassigneeIds: [STUB_USER_ID],\n\t\t\tplannedReleases: [\n\t\t\t\t{\n\t\t\t\t\tid: \"rls_p1_2\",\n\t\t\t\t\tcontentId: \"content_para_1\",\n\t\t\t\t\tkind: \"revision\",\n\t\t\t\t\tbranchId: \"br_para_1_b\",\n\t\t\t\t\trevisionId: \"\",\n\t\t\t\t\tvalidityPeriod: { firstDay: \"2026-10-01\", lastDay: \"\" },\n\t\t\t\t\tsupersedesReleaseIds: [],\n\t\t\t\t\tproposed: false,\n\t\t\t\t\tproposedForReleaseId: \"\",\n\t\t\t\t\tsplitFromReleaseId: \"\",\n\t\t\t\t\twithheld: false,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t// The cut ending § 1's Release In Force the day before the\n\t\t\t\t\t// amendment starts: proposed, never planned by hand.\n\t\t\t\t\tid: \"rls_p1_1_cut\",\n\t\t\t\t\tcontentId: \"content_para_1\",\n\t\t\t\t\tkind: \"date_only\",\n\t\t\t\t\tbranchId: \"\",\n\t\t\t\t\trevisionId: \"rev_p1_main\",\n\t\t\t\t\tvalidityPeriod: { firstDay: \"2020-01-01\", lastDay: \"2026-09-30\" },\n\t\t\t\t\tsupersedesReleaseIds: [\"rls_p1_1\"],\n\t\t\t\t\tproposed: true,\n\t\t\t\t\tproposedForReleaseId: \"rls_p1_1\",\n\t\t\t\t\tsplitFromReleaseId: \"\",\n\t\t\t\t\twithheld: false,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tid: \"rls_p4a_1\",\n\t\t\t\t\tcontentId: \"content_para_4a\",\n\t\t\t\t\tkind: \"revision\",\n\t\t\t\t\tbranchId: \"br_para_4a\",\n\t\t\t\t\trevisionId: \"\",\n\t\t\t\t\tvalidityPeriod: { firstDay: \"2026-10-01\", lastDay: \"\" },\n\t\t\t\t\tsupersedesReleaseIds: [],\n\t\t\t\t\tproposed: false,\n\t\t\t\t\tproposedForReleaseId: \"\",\n\t\t\t\t\tsplitFromReleaseId: \"\",\n\t\t\t\t\twithheld: false,\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t\t{\n\t\t\tid: \"cs_bgbl_255\",\n\t\t\tname: \"BGBl. 2026 I Nr. 255\",\n\t\t\tsource: { date: \"2026-09-10\", reference: \"BGBl. 2026 I Nr. 255\" },\n\t\t\tstate: \"open\",\n\t\t\tcreatedBy: STUB_OTHER_USER_ID,\n\t\t\tcreateTime: \"2026-09-25T08:00:00.000Z\",\n\t\t\tchains: [],\n\t\t\tdependsOnChangeSetIds: [],\n\t\t\tstatus: \"\",\n\t\t\tassigneeIds: [STUB_OTHER_USER_ID],\n\t\t\tplannedReleases: [],\n\t\t},\n\t\t{\n\t\t\tid: \"cs_correction_3\",\n\t\t\tname: \"Correction of § 3\",\n\t\t\tstate: \"published\",\n\t\t\tcreatedBy: STUB_USER_ID,\n\t\t\tcreateTime: \"2026-09-01T08:00:00.000Z\",\n\t\t\tcloseTime: \"2026-09-02T08:00:00.000Z\",\n\t\t\tchains: [],\n\t\t\tdependsOnChangeSetIds: [],\n\t\t\tstatus: \"ready\",\n\t\t\tassigneeIds: [],\n\t\t\tplannedReleases: [],\n\t\t},\n\t];\n}\n\n/**\n * A legal publisher's Required Checks, by name: a print round trip once per\n * Change Set, and a lawyer's review of each Branch, by someone who wrote\n * none of it. Both apply to every Blueprint.\n */\nexport function stubRequiredChecks(): RequiredCheck[] {\n\treturn [\n\t\t{\n\t\t\tid: \"rc_print\",\n\t\t\tname: \"Druckprobe\",\n\t\t\tscope: \"change_set\",\n\t\t\tblueprintAccessors: [],\n\t\t\tindependent: false,\n\t\t},\n\t\t{\n\t\t\tid: \"rc_lawyer\",\n\t\t\tname: \"Juristische Prüfung\",\n\t\t\tscope: \"branch\",\n\t\t\tblueprintAccessors: [],\n\t\t\tindependent: true,\n\t\t},\n\t];\n}\n\n/**\n * A legal publisher's Collection tree, by name as the service lists it:\n * Laws holding BGB and StGB, and Commentary beside it.\n */\nexport function stubCollections(): Collection[] {\n\treturn [\n\t\t{ id: \"col_bgb\", name: \"BGB\", parentId: \"col_laws\", restricted: false },\n\t\t{ id: \"col_commentary\", name: \"Commentary\", parentId: \"\", restricted: false },\n\t\t{ id: \"col_laws\", name: \"Laws\", parentId: \"\", restricted: false },\n\t\t{ id: \"col_stgb\", name: \"StGB\", parentId: \"col_laws\", restricted: false },\n\t];\n}\n\n/**\n * The workspace's content Blueprints, as a `BlueprintSource` answers, by\n * name. Commentary has had no Release cut yet, so contenthub's catalog\n * (the stub client's `searchBlueprints`) leaves it out.\n */\nexport function stubBlueprints(): BlueprintInfo[] {\n\treturn [\n\t\t{ id: \"bp_commentary\", name: \"Commentary\" },\n\t\t{ id: \"bp_footnote\", name: \"Footnote\" },\n\t\t{ id: \"bp_paragraph\", name: \"Paragraph\" },\n\t];\n}\n\n/** Their Releases, newest first per Blueprint. */\nexport function stubBlueprintReleases(): BlueprintReleaseInfo[] {\n\treturn [\n\t\t{\n\t\t\tid: \"bpr_paragraph_2\",\n\t\t\tblueprintId: \"bp_paragraph\",\n\t\t\tname: \"2026-10\",\n\t\t\treleaseTime: \"2026-10-01T07:00:00.000Z\",\n\t\t},\n\t\t{\n\t\t\tid: \"bpr_paragraph_1\",\n\t\t\tblueprintId: \"bp_paragraph\",\n\t\t\tname: \"2026-09\",\n\t\t\treleaseTime: \"2026-09-01T07:00:00.000Z\",\n\t\t},\n\t\t{\n\t\t\tid: \"bpr_footnote_1\",\n\t\t\tblueprintId: \"bp_footnote\",\n\t\t\tname: \"2026-08\",\n\t\t\treleaseTime: \"2026-08-01T07:00:00.000Z\",\n\t\t},\n\t];\n}\n\n/** One head of a Content: its Revision, data and when it was written. */\nexport interface StubHead {\n\trevisionId: string;\n\tdata: Record<string, unknown>;\n\t/** ISO 8601. */\n\trevisionCreateTime: string;\n}\n\n/**\n * A Content of the stub workspace, every way the screens can read it. Not a\n * service type: it is what the stub keeps to answer its reads.\n */\nexport interface StubContent {\n\tid: string;\n\tblueprintId: string;\n\tblueprintReleaseId: string;\n\t/** The Collections it is filed in, directly. */\n\tcollectionIds: string[];\n\t/** Who maintains it; none when absent. */\n\tassigneeIds?: string[];\n\t/** Its Block; absent while it is not blocked. */\n\tblock?: ContentBlock;\n\t/** When it was archived, ISO 8601; absent while it is not Archived. */\n\tarchiveTime?: string;\n\t/** Its Main head; absent while it was born in an open Change Set. */\n\tmain?: StubHead;\n\t/** The Release In Force today, and the head it pins; absent for none. */\n\tinForce?: StubHead & { releaseId: string };\n\t/** The head of its Chain's last Branch in each Change Set it is in, by Change Set id. */\n\tbranches: Record<string, StubHead & { branchId: string }>;\n\t/** Its Timeline as known now; none when absent. */\n\ttimeline?: TimelineEntry[];\n\t/** What open (or since closed) Change Sets plan for it, in the order planned. */\n\tplannedReleases?: { changeSetId: string; plannedRelease: PlannedRelease }[];\n\t/** Its Revisions, newest first, beyond what its heads imply; none when absent. */\n\trevisions?: (Revision & { data?: Record<string, unknown> })[];\n\t/** The outgoing edges of its Revisions, each naming the Revision holding it. */\n\tedges?: Edge[];\n}\n\n/**\n * The Resolved Releases contenthub holds for the fixtures' Blueprint\n * Releases, by id, as `getContent` decodes them: a paragraph has a number\n * and a heading, a footnote a text. Both are Dated.\n */\nexport function stubResolvedReleases(): Record<string, ResolvedBlueprintRelease> {\n\tconst text = (accessor: string, name: string): ResolvedField => ({\n\t\tfield_type: \"text\",\n\t\tconfig: { name, api_accessor: accessor, required: false, instructions: \"\" },\n\t\tsystem: false,\n\t});\n\tconst paragraph: ResolvedBlueprintRelease = {\n\t\tdisplayName: \"Paragraph\",\n\t\tdated: true,\n\t\tfields: [text(\"number\", \"Number\"), text(\"heading\", \"Heading\")],\n\t\tparts: {},\n\t};\n\treturn {\n\t\tbpr_paragraph_1: paragraph,\n\t\tbpr_paragraph_2: paragraph,\n\t\tbpr_footnote_1: {\n\t\t\tdisplayName: \"Footnote\",\n\t\t\tdated: true,\n\t\t\tfields: [text(\"text\", \"Text\")],\n\t\t\tparts: {},\n\t\t},\n\t};\n}\n\n/**\n * § 3 BGB, repealed at the end of 2001: published, filed in BGB, with\n * nothing In Force today or later, so it may be archived. Not among\n * `stubContents()`, so the Library's fixtures stay as they are; pass it in\n * with `contents` to a stub that needs it.\n */\nexport function stubRepealedContent(): StubContent {\n\tconst at = \"2001-11-01T08:00:00.000Z\";\n\tconst data = { number: \"§ 3\", heading: \"(weggefallen)\" };\n\treturn {\n\t\tid: \"content_para_3\",\n\t\tblueprintId: \"bp_paragraph\",\n\t\tblueprintReleaseId: \"bpr_paragraph_1\",\n\t\tcollectionIds: [\"col_bgb\"],\n\t\tmain: { revisionId: \"rev_p3_main\", data, revisionCreateTime: at },\n\t\tbranches: {},\n\t\ttimeline: [\n\t\t\t{\n\t\t\t\tordinal: 1,\n\t\t\t\treleaseId: \"rls_p3_repeal\",\n\t\t\t\tkind: \"repeal\",\n\t\t\t\trevisionId: \"rev_p3_main\",\n\t\t\t\tblueprintReleaseId: \"bpr_paragraph_1\",\n\t\t\t\tvalidityPeriod: { firstDay: \"1900-01-01\", lastDay: \"2001-12-31\" },\n\t\t\t\tpublishTime: at,\n\t\t\t\tfirst: true,\n\t\t\t},\n\t\t],\n\t};\n}\n\n/**\n * The Content behind the fixtures' Change Sets: § 1 BGB, amended in\n * BGBl. 2026 I Nr. 270; § 2 BGB; § 4a BGB, born in that Change Set; § 211\n * StGB; and a footnote filed nowhere, published but with no Release In Force\n * yet (dated to start next year).\n */\nexport function stubContents(): StubContent[] {\n\tconst at = \"2026-09-01T08:00:00.000Z\";\n\treturn [\n\t\t{\n\t\t\tid: \"content_fn_1\",\n\t\t\tblueprintId: \"bp_footnote\",\n\t\t\tblueprintReleaseId: \"bpr_footnote_1\",\n\t\t\tcollectionIds: [],\n\t\t\tmain: {\n\t\t\t\trevisionId: \"rev_fn1_main\",\n\t\t\t\tdata: { text: \"Fassung ab 1. Januar 2027\" },\n\t\t\t\trevisionCreateTime: at,\n\t\t\t},\n\t\t\tbranches: {},\n\t\t\ttimeline: [\n\t\t\t\t{\n\t\t\t\t\tordinal: 1,\n\t\t\t\t\treleaseId: \"rls_fn1_1\",\n\t\t\t\t\tkind: \"revision\",\n\t\t\t\t\trevisionId: \"rev_fn1_main\",\n\t\t\t\t\tblueprintReleaseId: \"bpr_footnote_1\",\n\t\t\t\t\tvalidityPeriod: { firstDay: \"2027-01-01\", lastDay: \"\" },\n\t\t\t\t\tpublishTime: at,\n\t\t\t\t\tfirst: true,\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t\t{\n\t\t\tid: \"content_para_1\",\n\t\t\tblueprintId: \"bp_paragraph\",\n\t\t\tblueprintReleaseId: \"bpr_paragraph_1\",\n\t\t\tcollectionIds: [\"col_bgb\"],\n\t\t\tassigneeIds: [STUB_USER_ID, STUB_OTHER_USER_ID],\n\t\t\tmain: {\n\t\t\t\trevisionId: \"rev_p1_main\",\n\t\t\t\tdata: { number: \"§ 1\", heading: \"Beginn der Rechtsfähigkeit\" },\n\t\t\t\trevisionCreateTime: at,\n\t\t\t},\n\t\t\tinForce: {\n\t\t\t\treleaseId: \"rls_p1_1\",\n\t\t\t\trevisionId: \"rev_p1_main\",\n\t\t\t\tdata: { number: \"§ 1\", heading: \"Beginn der Rechtsfähigkeit\" },\n\t\t\t\trevisionCreateTime: at,\n\t\t\t},\n\t\t\tbranches: {\n\t\t\t\tcs_bgbl_270: {\n\t\t\t\t\tbranchId: \"br_para_1_b\",\n\t\t\t\t\trevisionId: \"rev_p1_b1\",\n\t\t\t\t\tdata: { number: \"§ 1\", heading: \"Beginn der Rechtsfähigkeit, Erbfähigkeit\" },\n\t\t\t\t\trevisionCreateTime: \"2026-09-30T09:00:00.000Z\",\n\t\t\t\t},\n\t\t\t},\n\t\t\ttimeline: [\n\t\t\t\t{\n\t\t\t\t\tordinal: 1,\n\t\t\t\t\treleaseId: \"rls_p1_1\",\n\t\t\t\t\tkind: \"revision\",\n\t\t\t\t\trevisionId: \"rev_p1_main\",\n\t\t\t\t\tblueprintReleaseId: \"bpr_paragraph_1\",\n\t\t\t\t\tvalidityPeriod: { firstDay: \"1900-01-01\", lastDay: \"\" },\n\t\t\t\t\tpublishTime: at,\n\t\t\t\t\tfirst: true,\n\t\t\t\t},\n\t\t\t],\n\t\t\tplannedReleases: [\n\t\t\t\t{\n\t\t\t\t\tchangeSetId: \"cs_bgbl_270\",\n\t\t\t\t\tplannedRelease: {\n\t\t\t\t\t\tid: \"rls_p1_270\",\n\t\t\t\t\t\tcontentId: \"content_para_1\",\n\t\t\t\t\t\tkind: \"revision\",\n\t\t\t\t\t\tbranchId: \"br_para_1_b\",\n\t\t\t\t\t\tvalidityPeriod: { firstDay: \"2026-11-01\", lastDay: \"\" },\n\t\t\t\t\t\trevisionId: \"\",\n\t\t\t\t\t\tsupersedesReleaseIds: [],\n\t\t\t\t\t\tproposed: false,\n\t\t\t\t\t\tproposedForReleaseId: \"\",\n\t\t\t\t\t\tsplitFromReleaseId: \"\",\n\t\t\t\t\t\twithheld: false,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t],\n\t\t\t// The amendment's two saves, then the Revision Main holds.\n\t\t\trevisions: [\n\t\t\t\t{\n\t\t\t\t\tid: \"rev_p1_b1\",\n\t\t\t\t\tcontentId: \"content_para_1\",\n\t\t\t\t\tparentId: \"rev_p1_a2\",\n\t\t\t\t\tsecondParentId: \"\",\n\t\t\t\t\tblueprintReleaseId: \"bpr_paragraph_1\",\n\t\t\t\t\tcreateTime: \"2026-09-30T09:00:00.000Z\",\n\t\t\t\t\tauthor: STUB_USER_ID,\n\t\t\t\t\tcause: \"save\",\n\t\t\t\t\tbranchId: \"br_para_1_b\",\n\t\t\t\t\tchangeSetId: \"cs_bgbl_270\",\n\t\t\t\t\tdata: { number: \"§ 1\", heading: \"Beginn der Rechtsfähigkeit, Erbfähigkeit\" },\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tid: \"rev_p1_a2\",\n\t\t\t\t\tcontentId: \"content_para_1\",\n\t\t\t\t\tparentId: \"rev_p1_main\",\n\t\t\t\t\tsecondParentId: \"\",\n\t\t\t\t\tblueprintReleaseId: \"bpr_paragraph_1\",\n\t\t\t\t\tcreateTime: \"2026-09-30T08:30:00.000Z\",\n\t\t\t\t\tauthor: STUB_OTHER_USER_ID,\n\t\t\t\t\tcause: \"save\",\n\t\t\t\t\tbranchId: \"br_para_1_a\",\n\t\t\t\t\tchangeSetId: \"cs_bgbl_270\",\n\t\t\t\t\tdata: { number: \"§ 1\", heading: \"Beginn der Rechtsfähigkeit des Menschen\" },\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tid: \"rev_p1_main\",\n\t\t\t\t\tcontentId: \"content_para_1\",\n\t\t\t\t\tparentId: \"\",\n\t\t\t\t\tsecondParentId: \"\",\n\t\t\t\t\tblueprintReleaseId: \"bpr_paragraph_1\",\n\t\t\t\t\tcreateTime: at,\n\t\t\t\t\tauthor: STUB_USER_ID,\n\t\t\t\t\tcause: \"create\",\n\t\t\t\t\tbranchId: \"br_para_1_main\",\n\t\t\t\t\tchangeSetId: \"cs_correction_3\",\n\t\t\t\t},\n\t\t\t],\n\t\t\t// § 1 cites § 2 at a Release since superseded: an outdated pin.\n\t\t\tedges: [\n\t\t\t\t{\n\t\t\t\t\tsourceContentId: \"content_para_1\",\n\t\t\t\t\tsourceRevisionId: \"rev_p1_main\",\n\t\t\t\t\tpath: \"/see_also\",\n\t\t\t\t\tkind: \"reference\",\n\t\t\t\t\ttargetContentId: \"content_para_2\",\n\t\t\t\t\ttargetAssetId: \"\",\n\t\t\t\t\ttargetBlueprintReleaseId: \"\",\n\t\t\t\t\tpinReleaseId: \"rls_p2_0\",\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t\t{\n\t\t\tid: \"content_para_2\",\n\t\t\tblueprintId: \"bp_paragraph\",\n\t\t\tblueprintReleaseId: \"bpr_paragraph_1\",\n\t\t\tcollectionIds: [\"col_bgb\"],\n\t\t\tmain: {\n\t\t\t\trevisionId: \"rev_p2_main\",\n\t\t\t\tdata: { number: \"§ 2\", heading: \"Eintritt der Volljährigkeit\" },\n\t\t\t\trevisionCreateTime: at,\n\t\t\t},\n\t\t\tinForce: {\n\t\t\t\treleaseId: \"rls_p2_1\",\n\t\t\t\trevisionId: \"rev_p2_main\",\n\t\t\t\tdata: { number: \"§ 2\", heading: \"Eintritt der Volljährigkeit\" },\n\t\t\t\trevisionCreateTime: at,\n\t\t\t},\n\t\t\tbranches: {},\n\t\t\ttimeline: [\n\t\t\t\t{\n\t\t\t\t\tordinal: 1,\n\t\t\t\t\treleaseId: \"rls_p2_1\",\n\t\t\t\t\tkind: \"revision\",\n\t\t\t\t\trevisionId: \"rev_p2_main\",\n\t\t\t\t\tblueprintReleaseId: \"bpr_paragraph_1\",\n\t\t\t\t\tvalidityPeriod: { firstDay: \"1975-01-01\", lastDay: \"\" },\n\t\t\t\t\tpublishTime: at,\n\t\t\t\t\tfirst: false,\n\t\t\t\t},\n\t\t\t],\n\t\t\t// § 2 refers to § 1 as it is In Force: § 1's referrer.\n\t\t\tedges: [\n\t\t\t\t{\n\t\t\t\t\tsourceContentId: \"content_para_2\",\n\t\t\t\t\tsourceRevisionId: \"rev_p2_main\",\n\t\t\t\t\tpath: \"/see_also\",\n\t\t\t\t\tkind: \"reference\",\n\t\t\t\t\ttargetContentId: \"content_para_1\",\n\t\t\t\t\ttargetAssetId: \"\",\n\t\t\t\t\ttargetBlueprintReleaseId: \"\",\n\t\t\t\t\tpinReleaseId: \"\",\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t\t{\n\t\t\tid: \"content_para_4a\",\n\t\t\tblueprintId: \"bp_paragraph\",\n\t\t\tblueprintReleaseId: \"bpr_paragraph_2\",\n\t\t\tcollectionIds: [\"col_bgb\"],\n\t\t\tbranches: {\n\t\t\t\tcs_bgbl_270: {\n\t\t\t\t\tbranchId: \"br_para_4a\",\n\t\t\t\t\trevisionId: \"rev_p4a_1\",\n\t\t\t\t\tdata: { number: \"§ 4a\", heading: \"Elektronische Form\" },\n\t\t\t\t\trevisionCreateTime: \"2026-09-30T10:00:00.000Z\",\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: \"content_stgb_211\",\n\t\t\tblueprintId: \"bp_paragraph\",\n\t\t\tblueprintReleaseId: \"bpr_paragraph_1\",\n\t\t\tcollectionIds: [\"col_stgb\"],\n\t\t\tassigneeIds: [STUB_OTHER_USER_ID],\n\t\t\tmain: {\n\t\t\t\trevisionId: \"rev_s211_main\",\n\t\t\t\tdata: { number: \"§ 211\", heading: \"Mord\" },\n\t\t\t\trevisionCreateTime: at,\n\t\t\t},\n\t\t\tinForce: {\n\t\t\t\treleaseId: \"rls_s211_1\",\n\t\t\t\trevisionId: \"rev_s211_main\",\n\t\t\t\tdata: { number: \"§ 211\", heading: \"Mord\" },\n\t\t\t\trevisionCreateTime: at,\n\t\t\t},\n\t\t\tbranches: {},\n\t\t\ttimeline: [\n\t\t\t\t{\n\t\t\t\t\tordinal: 1,\n\t\t\t\t\treleaseId: \"rls_s211_1\",\n\t\t\t\t\tkind: \"revision\",\n\t\t\t\t\trevisionId: \"rev_s211_main\",\n\t\t\t\t\tblueprintReleaseId: \"bpr_paragraph_1\",\n\t\t\t\t\tvalidityPeriod: { firstDay: \"1941-09-15\", lastDay: \"\" },\n\t\t\t\t\tpublishTime: at,\n\t\t\t\t\tfirst: true,\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t];\n}\n","// A `BlueprintSource` over fixed Blueprints and Releases, for a test that\n// overrides where the screens read Blueprints. Without one they read the\n// client's own catalog (#238), which the stub client serves too.\nimport type { BlueprintInfo, BlueprintReleaseInfo, BlueprintSource } from \"../types\";\nimport { stubBlueprintReleases, stubBlueprints } from \"./fixtures\";\n\nexport function createStubBlueprintSource(\n\tblueprints: BlueprintInfo[] = stubBlueprints(),\n\treleases: BlueprintReleaseInfo[] = stubBlueprintReleases(),\n): BlueprintSource {\n\treturn {\n\t\tasync searchBlueprints({ query }) {\n\t\t\tconst q = query.trim().toLocaleLowerCase();\n\t\t\treturn {\n\t\t\t\tblueprints: blueprints\n\t\t\t\t\t.filter((b) => b.name.toLocaleLowerCase().includes(q))\n\t\t\t\t\t.map((b) => ({ ...b })),\n\t\t\t\tnextPageToken: \"\",\n\t\t\t};\n\t\t},\n\t\tasync getBlueprints(ids) {\n\t\t\treturn blueprints.filter((b) => ids.includes(b.id)).map((b) => ({ ...b }));\n\t\t},\n\t\tasync listReleases(blueprintId) {\n\t\t\treturn releases.filter((r) => r.blueprintId === blueprintId).map((r) => ({ ...r }));\n\t\t},\n\t};\n}\n","// A `ContenthubClient` over an in-memory workspace seeded from the fixtures.\n//\n// It keeps state and applies the service's rules (internal/workspaceconfig,\n// internal/changesets), rather than answering every read with the same\n// fixture, so a screen's writes show up in its next read, and a refusal comes\n// back the way contenthub refuses it.\n//\n// Typed as the whole interface, so a method added to `ContenthubClient`\n// without an answer here fails this package's typecheck, not a host's test.\nimport { Code, ConnectError } from \"@connectrpc/connect\";\nimport {\n\tAccessDeniedError,\n\tBLOCK_REASON_NAME_MAX,\n\tBLUEPRINT_ACCESSOR_MAX,\n\tBlockReasonNameTakenError,\n\tCHANGE_SET_NAME_MAX,\n\tCHECK_NOTE_MAX,\n\tChangeSetClosedError,\n\tCheckResultDeniedError,\n\tCOLLECTION_NAME_MAX,\n\tCONTENT_SEARCH_MAX,\n\tContentArchivedError,\n\tContentBlockedError,\n\ttype ContenthubClient,\n\tContentRefusedError,\n\tCoversReleaseError,\n\tGuardianModeRequiredError,\n\tInvalidInputError,\n\tMAX_BLUEPRINT_IDS,\n\tNameTakenError,\n\tPublishRefusedError,\n\tREQUIRED_CHECK_NAME_MAX,\n\tRestrictionUnavailableError,\n\tSOURCE_REFERENCE_MAX,\n\tStaleHeadError,\n\tStaleStatusError,\n\tStatusTransitionRefusedError,\n\tWithheldWorkError,\n} from \"../client/contenthub-client\";\nimport { headsOf, sameHeads } from \"../common/heads\";\nimport { DAY, inForceOnOrAfter, releaseInForceOn } from \"../common/in-force\";\nimport type {\n\tBlockReason,\n\tBlueprintInfo,\n\tBlueprintReleaseInfo,\n\tChangeSet,\n\tChangeSetStatusInfo,\n\tCheckResult,\n\tCheckStanding,\n\tCollection,\n\tCollectionGrant,\n\tContent,\n\tContentAttributes,\n\tContentView,\n\tEdge,\n\tFieldChange,\n\tMergeField,\n\tPendingMerge,\n\tPendingMergeRef,\n\tPlannedEnd,\n\tPlannedRelease,\n\tPublishBlocker,\n\tReferrer,\n\tReferrerList,\n\tRelease,\n\tRequiredCheck,\n\tRequiredCheckInput,\n\tRequiredCheckRecorders,\n\tResolvedBlueprintRelease,\n\tResolvedField,\n\tRevision,\n\tTimelineEntry,\n} from \"../types\";\nimport {\n\tSTUB_NOW,\n\tSTUB_OTHER_USER_ID,\n\tSTUB_USER_ID,\n\ttype StubContent,\n\tstubBlockReasons,\n\tstubBlueprintReleases,\n\tstubBlueprints,\n\tstubChangeSetStatuses,\n\tstubChangeSets,\n\tstubCollections,\n\tstubContents,\n\tstubRequiredChecks,\n\tstubResolvedReleases,\n\tstubStatusTransitions,\n} from \"./fixtures\";\n\ntype SaveInput = Omit<Parameters<ContenthubClient[\"saveRevision\"]>[0], \"idempotencyKey\">;\n\nexport interface StubContenthubClientOptions {\n\t/** The workspace's Block Reasons to start from; the fixtures' by default. */\n\tblockReasons?: BlockReason[];\n\t/** The workspace's Change Sets to start from, newest first; the fixtures' by default. */\n\tchangeSets?: ChangeSet[];\n\t/**\n\t * statushub's `contenthub/change_set` catalogue the stub checks status\n\t * moves against; the fixtures' by default.\n\t */\n\tstatuses?: ChangeSetStatusInfo[];\n\t/** The moves statushub allows, from slug to slugs; the fixtures' by default. */\n\tstatusTransitions?: Record<string, string[]>;\n\t/** The workspace's Collections, by name; the fixtures' by default. */\n\tcollections?: Collection[];\n\t/** The workspace's Content, every way it can be read; the fixtures' by default. */\n\tcontents?: StubContent[];\n\t/**\n\t * The workspace's content Blueprints, as `getBlueprints` names them;\n\t * the fixtures' by default. `searchBlueprints` lists those Content can\n\t * be made from: not `archived`, with a Release.\n\t */\n\tblueprints?: (BlueprintInfo & { archived?: boolean })[];\n\t/**\n\t * The Blueprint Releases, newest first per Blueprint, as\n\t * `listBlueprintReleases` lists them; the fixtures' by default.\n\t * `createContent` pins one without `refusals` and refuses the rest, as\n\t * contenthub refuses a Release it can't load.\n\t */\n\tblueprintReleases?: (Pick<BlueprintReleaseInfo, \"id\" | \"blueprintId\"> &\n\t\tPartial<BlueprintReleaseInfo>)[];\n\t/** The Resolved Releases `getContent` answers with, by Blueprint Release id; the fixtures' by default. */\n\tresolvedReleases?: Record<string, ResolvedBlueprintRelease>;\n\t/**\n\t * The workspace's Required Checks; the fixtures' by default. The stub\n\t * reads `blueprintAccessors` as Blueprint ids, the one name its Content\n\t * carries.\n\t */\n\trequiredChecks?: RequiredCheck[];\n\t/** Check Results recorded before, in the order they were recorded. */\n\tcheckResults?: (CheckResult & { changeSetId: string })[];\n\t/**\n\t * Blockers the stub can't derive itself (versionkit's and the Content\n\t * Graph's, such as covers_release or dangling_pin), by Change Set id:\n\t * `validatePublish` and `publish` report them beside the ones it does\n\t * derive (moved_head, the dependencies', outstanding_check).\n\t */\n\tpublishBlockers?: Record<string, PublishBlocker[]>;\n\t/** The Pending Merges `updateFromMain` leaves, by Change Set id; none by default. */\n\tpendingMerges?: Record<string, PendingMergeRef[]>;\n\t/**\n\t * What an Update from Main would meet on a Branch, by Branch id: the\n\t * fields it can't merge and the rest merged. `updateFromMain` stores it\n\t * on the Branch as a Pending Merge; `pending` stores it from the start.\n\t */\n\tconflicts?: Record<string, StubConflict>;\n\t/**\n\t * contenthub's `authz.mode`: \"guardian\" by default. In \"workspace\" every\n\t * restriction and grant is refused, as contenthub refuses them, and\n\t * opening a Restricted Collection again is still allowed.\n\t */\n\tauthzMode?: \"workspace\" | \"guardian\";\n\t/** Grants on Restricted Collections, by Collection id, the owner's included. */\n\tcollectionGrants?: Record<string, CollectionGrant[]>;\n\t/**\n\t * The Change Sets, by id, holding work the caller can't see (Restricted\n\t * Content, ADR 0017): `validatePublish`, `publish`, `discardChangeSet`\n\t * and an `updateFromMain` without `chainId` refuse them with\n\t * `WithheldWorkError`, as contenthub does.\n\t */\n\twithheld?: string[];\n\t/**\n\t * Who records each Required Check, by check id; a check not named here,\n\t * and every new one, is recorded by every member. In guardian mode\n\t * `recordCheckResult` refuses a caller who is no recorder, as contenthub\n\t * does; in workspace mode every member records, and the recorder calls\n\t * are refused.\n\t */\n\trecorders?: Record<string, RequiredCheckRecorders>;\n\t/** The workspace's members, whom a grant may name; the stub identity's two by default. */\n\tmemberIds?: string[];\n\t/**\n\t * Whether the caller is a workspace admin, who manages every Restricted\n\t * Collection's grants; true by default. Otherwise only an owner does.\n\t */\n\tadmin?: boolean;\n\t/** Who the token names: the creator of a new Change Set. STUB_USER_ID by default. */\n\tuserId?: string;\n\t/** The time every write stamps; STUB_NOW by default. */\n\tnow?: () => string;\n}\n\n/** A merge an Update from Main would stop on (see `conflicts`). */\nexport interface StubConflict {\n\ttheirsRevisionId: string;\n\tfields: MergeField[];\n\t/** Every field but `fields`, merged. */\n\tmerged: Record<string, unknown>;\n\treason?: \"conflict\" | \"invalid\";\n\t/** Already stored on the Branch, as an earlier Update from Main left it. */\n\tpending?: boolean;\n}\n\n/** The day after (1) or before (-1) a YYYY-MM-DD day. */\nfunction shiftDay(day: string, by: 1 | -1): string {\n\tconst d = new Date(`${day}T00:00:00Z`);\n\td.setUTCDate(d.getUTCDate() + by);\n\treturn d.toISOString().slice(0, 10);\n}\n\n/** The service's rule for a name: trimmed, not blank, at most `max` characters, one line. */\nfunction oneLine(raw: string, what: string, max: number): string {\n\tconst value = raw.trim();\n\tif (value === \"\") throw new InvalidInputError(`${what} is required`);\n\tif ([...value].length > max) {\n\t\tthrow new InvalidInputError(`${what} is at most ${max} characters`);\n\t}\n\t// biome-ignore lint/suspicious/noControlCharactersInRegex: the rule is exactly \"no control characters\"\n\tif (/[\\u0000-\\u001f\\u007f]/.test(value)) {\n\t\tthrow new InvalidInputError(`${what} is one line of text`);\n\t}\n\treturn value;\n}\n\n/** The service's rule for a Source: a YYYY-MM-DD day and a one-line reference. */\nfunction checkedSourceOf(source: { date: string; reference: string }): {\n\tdate: string;\n\treference: string;\n} {\n\tif (!/^\\d{4}-\\d{2}-\\d{2}$/.test(source.date.trim())) {\n\t\tthrow new InvalidInputError(`source.date \"${source.date}\" is not a day as YYYY-MM-DD`);\n\t}\n\treturn {\n\t\tdate: source.date.trim(),\n\t\treference: oneLine(source.reference, \"source.reference\", SOURCE_REFERENCE_MAX),\n\t};\n}\n\nfunction checkedBlockReasonName(raw: string): string {\n\tconst name = raw.trim();\n\tif (name === \"\") throw new InvalidInputError(\"a Block Reason needs a name\");\n\tif ([...name].length > BLOCK_REASON_NAME_MAX) {\n\t\tthrow new InvalidInputError(\n\t\t\t`a Block Reason's name is at most ${BLOCK_REASON_NAME_MAX} characters`,\n\t\t);\n\t}\n\t// biome-ignore lint/suspicious/noControlCharactersInRegex: the rule is exactly \"no control characters\"\n\tif (/[\\u0000-\\u001f\\u007f]/.test(name)) {\n\t\tthrow new InvalidInputError(\"a Block Reason's name is one line of text\");\n\t}\n\treturn name;\n}\n\n/** The service's rule for a Required Check (internal/workspaceconfig.checkRequiredCheck). */\nfunction checkedRequiredCheck(input: RequiredCheckInput): RequiredCheckInput {\n\tconst name = oneLine(input.name, \"a Required Check's name\", REQUIRED_CHECK_NAME_MAX);\n\tif (input.scope !== \"branch\" && input.scope !== \"change_set\") {\n\t\tthrow new InvalidInputError(\"a Required Check's scope is Branch or Change Set\");\n\t}\n\tconst accessors = input.blueprintAccessors.map((raw) => {\n\t\tconst a = raw.trim();\n\t\t// biome-ignore lint/suspicious/noControlCharactersInRegex: the rule is exactly \"no control characters\"\n\t\tif (a === \"\" || [...a].length > BLUEPRINT_ACCESSOR_MAX || /[\\u0000-\\u001f\\u007f]/.test(a)) {\n\t\t\tthrow new InvalidInputError(`\"${a}\" is not a Blueprint accessor`);\n\t\t}\n\t\treturn a;\n\t});\n\treturn {\n\t\tname,\n\t\tscope: input.scope,\n\t\tblueprintAccessors: [...new Set(accessors)].sort(),\n\t\tindependent: input.independent,\n\t};\n}\n\n/** What contenthub answers to every recorder call in `authz.mode: workspace`. */\nconst RECORDERS_WORKSPACE_MODE =\n\t\"who records a Required Check can be narrowed only in authz.mode guardian: \" +\n\t\"in workspace mode every member records every check (ADR 0017)\";\n\n/** What contenthub answers to every whole-Change-Set write over withheld work. */\nconst WITHHELD_REFUSAL =\n\t\"this Change Set holds work you can't see: publishing, discarding or updating all of it \" +\n\t\"needs you to see every Content in it\";\n\n/** What contenthub answers to every restriction in `authz.mode: workspace`. */\nconst WORKSPACE_MODE_REFUSAL =\n\t\"Restricted Collections need authz.mode guardian: in workspace mode a restriction \" +\n\t\"could not be enforced (ADR 0017)\";\n\nfunction notFound(what: string, id: string): ConnectError {\n\treturn new ConnectError(`${what} ${id}: not found`, Code.NotFound);\n}\n\nconst copy = (cs: ChangeSet): ChangeSet => structuredClone(cs);\n\n/** A blocker naming only what `fields` sets; every other id \"\", as on the wire. */\nexport function stubBlocker(code: string, fields: Partial<PublishBlocker> = {}): PublishBlocker {\n\treturn {\n\t\tcode,\n\t\tcontentId: \"\",\n\t\tbranchId: \"\",\n\t\texpectedHeadId: \"\",\n\t\tcurrentHeadId: \"\",\n\t\treleaseId: \"\",\n\t\toverlapsReleaseId: \"\",\n\t\tdependencyChangeSetId: \"\",\n\t\tpath: \"\",\n\t\ttargetContentId: \"\",\n\t\tassetId: \"\",\n\t\tparentContentIds: [],\n\t\trequiredCheckId: \"\",\n\t\tcoveredReleaseId: \"\",\n\t\trevisionId: \"\",\n\t\t...fields,\n\t};\n}\n\nexport function createStubContenthubClient(\n\toptions: StubContenthubClientOptions = {},\n): ContenthubClient {\n\tconst now = options.now ?? (() => STUB_NOW);\n\tconst userId = options.userId ?? STUB_USER_ID;\n\tconst statuses = options.statuses ?? stubChangeSetStatuses();\n\tconst transitions = options.statusTransitions ?? stubStatusTransitions();\n\tlet reasons = (options.blockReasons ?? stubBlockReasons()).map((r) => ({ ...r }));\n\t// Newest first, the order the service lists them in.\n\tconst changeSets = (options.changeSets ?? stubChangeSets()).map(copy);\n\tconst collections = (options.collections ?? stubCollections()).map((c) => ({ ...c }));\n\tconst contents = structuredClone(options.contents ?? stubContents());\n\tconst blueprints: (BlueprintInfo & { archived?: boolean })[] =\n\t\toptions.blueprints ?? stubBlueprints();\n\tconst releases = options.blueprintReleases ?? stubBlueprintReleases();\n\tconst resolved = options.resolvedReleases ?? stubResolvedReleases();\n\tlet requiredChecks = structuredClone(options.requiredChecks ?? stubRequiredChecks());\n\tconst authzMode = options.authzMode ?? \"guardian\";\n\tconst withheld = new Set(options.withheld ?? []);\n\t/** Refuses a write over all of Change Set `id` while it holds work the caller can't see. */\n\tconst refuseWithheld = (id: string) => {\n\t\tif (withheld.has(id)) throw new WithheldWorkError(WITHHELD_REFUSAL);\n\t};\n\tconst grants = new Map<string, CollectionGrant[]>(\n\t\tObject.entries(structuredClone(options.collectionGrants ?? {})),\n\t);\n\tconst recorders = new Map<string, RequiredCheckRecorders>(\n\t\tObject.entries(structuredClone(options.recorders ?? {})),\n\t);\n\tconst recordersOf = (checkId: string): RequiredCheckRecorders =>\n\t\trecorders.get(checkId) ?? { everyMember: true, userIds: [] };\n\tconst memberIds = options.memberIds ?? [STUB_USER_ID, STUB_OTHER_USER_ID];\n\tconst admin = options.admin ?? true;\n\tconst checkResults = structuredClone(options.checkResults ?? []);\n\tconst extraBlockers = options.publishBlockers ?? {};\n\tconst pendingMerges = options.pendingMerges ?? {};\n\tconst conflicts = structuredClone(options.conflicts ?? {});\n\t// The Pending Merges stored on Branches, by Branch id.\n\tconst stored = new Map<string, PendingMerge>();\n\t// What each Idempotency Key's write asked and answered, beside the saves'.\n\tconst wroteUnder = new Map<string, { asked: string; answer: unknown }>();\n\t/**\n\t * A write under an Idempotency Key: a repeat answers the first and\n\t * writes nothing, another request under the key is refused.\n\t */\n\tconst once = async <T>(key: string | undefined, request: unknown, write: () => Promise<T>) => {\n\t\tif (!key) return write();\n\t\tconst asked = JSON.stringify(request);\n\t\tconst kept = wroteUnder.get(key);\n\t\tif (kept) {\n\t\t\tif (kept.asked !== asked) {\n\t\t\t\tthrow new InvalidInputError(`idempotency key ${key} names another request`);\n\t\t\t}\n\t\t\treturn structuredClone(kept.answer) as T;\n\t\t}\n\t\tconst answer = await write();\n\t\twroteUnder.set(key, { asked, answer: structuredClone(answer) });\n\t\treturn answer;\n\t};\n\t// The heads each published Change Set was published with, for a repeat.\n\tconst publishedWith = new Map<string, Record<string, string>>();\n\t// What each Idempotency Key's save asked and answered.\n\tconst savedUnder = new Map<string, { asked: string; content: Content }>();\n\tlet next = 1;\n\n\tconst findContent = (id: string): StubContent => {\n\t\tconst c = contents.find((each) => each.id === id);\n\t\tif (!c) throw notFound(\"Content\", id);\n\t\treturn c;\n\t};\n\tconst attributesOf = (c: StubContent): ContentAttributes =>\n\t\tstructuredClone({\n\t\t\tcollectionIds: [...c.collectionIds].sort(),\n\t\t\tassigneeIds: c.assigneeIds ?? [],\n\t\t\tblock: c.block,\n\t\t\tarchiveTime: c.archiveTime,\n\t\t});\n\tconst today = () => now().slice(0, 10);\n\tconst datedContent = (c: StubContent) => resolved[c.blueprintReleaseId]?.dated ?? false;\n\t// Every Revision the stub knows of a Content, newest first, with its data\n\t// where known: those the fixture lists, then each head not among them.\n\tconst revisionsOf = (c: StubContent): (Revision & { data?: Record<string, unknown> })[] => {\n\t\tconst listed = [...(c.revisions ?? [])];\n\t\tconst heads = [\n\t\t\t...Object.entries(c.branches).map(([csId, h]) => ({ ...h, changeSetId: csId })),\n\t\t\t...(c.main ? [{ ...c.main, branchId: \"\", changeSetId: \"\" }] : []),\n\t\t];\n\t\tfor (const h of heads) {\n\t\t\tif (listed.some((r) => r.id === h.revisionId)) continue;\n\t\t\tlisted.push({\n\t\t\t\tid: h.revisionId,\n\t\t\t\tcontentId: c.id,\n\t\t\t\tparentId: \"\",\n\t\t\t\tsecondParentId: \"\",\n\t\t\t\tblueprintReleaseId: c.blueprintReleaseId,\n\t\t\t\tcreateTime: h.revisionCreateTime,\n\t\t\t\tauthor: userId,\n\t\t\t\tcause: \"create\",\n\t\t\t\tbranchId: h.branchId,\n\t\t\t\tchangeSetId: h.changeSetId,\n\t\t\t\tdata: h.data,\n\t\t\t});\n\t\t}\n\t\treturn listed.sort((a, b) =>\n\t\t\ta.createTime < b.createTime ? 1 : a.createTime > b.createTime ? -1 : 0,\n\t\t);\n\t};\n\tconst dataOf = (c: StubContent, revisionId: string): Record<string, unknown> | undefined => {\n\t\tconst heads = [c.main, c.inForce, ...Object.values(c.branches)];\n\t\treturn (\n\t\t\theads.find((h) => h?.revisionId === revisionId)?.data ??\n\t\t\tc.revisions?.find((r) => r.id === revisionId)?.data\n\t\t);\n\t};\n\t/**\n\t * fieldkit's `required`, the one rule of its data contract the stub\n\t * applies: the accessors of the top-level required fields `values`\n\t * leaves Unset.\n\t */\n\tconst missingRequired = (\n\t\tfields: ResolvedField[] | undefined,\n\t\tvalues: Record<string, unknown>,\n\t): string[] => {\n\t\tconst unset = (v: unknown) =>\n\t\t\tv === undefined || v === null || v === \"\" || (Array.isArray(v) && v.length === 0);\n\t\treturn (fields ?? [])\n\t\t\t.filter((f) => f.config.required === true && unset(values[f.config.api_accessor]))\n\t\t\t.map((f) => f.config.api_accessor);\n\t};\n\tconst checkEditable = (c: StubContent) => {\n\t\tif (c.archiveTime) throw new ContentArchivedError(c.id);\n\t\tif (c.block && !c.block.allowedUserIds.includes(userId)) {\n\t\t\tthrow new ContentBlockedError(c.id, c.block.blockReasonId);\n\t\t}\n\t};\n\t/** The unpinned edges of Releases In Force pointing at `contentId`: what a Repeal leaves with a gap. */\n\tconst gapReferrersOf = (contentId: string): PlannedEnd[\"gapReferrers\"] =>\n\t\tcontents.flatMap((other) =>\n\t\t\t(other.edges ?? [])\n\t\t\t\t.filter(\n\t\t\t\t\t(e) =>\n\t\t\t\t\t\te.targetContentId === contentId &&\n\t\t\t\t\t\te.pinReleaseId === \"\" &&\n\t\t\t\t\t\tother.inForce?.revisionId === e.sourceRevisionId,\n\t\t\t\t)\n\t\t\t\t.map((e) => ({ edge: { ...e }, releaseId: other.inForce?.releaseId ?? \"\" })),\n\t\t);\n\n\t// The service orders by name, then id, compared as bytes.\n\tconst byName = (a: BlockReason, b: BlockReason) =>\n\t\ta.name < b.name ? -1 : a.name > b.name ? 1 : a.id < b.id ? -1 : a.id > b.id ? 1 : 0;\n\tconst taken = (name: string, except?: string) =>\n\t\treasons.some((r) => r.name === name && r.id !== except);\n\n\t// The service orders Collections by name, then id, compared as bytes.\n\tconst collectionOrder = (a: Collection, b: Collection) =>\n\t\ta.name < b.name ? -1 : a.name > b.name ? 1 : a.id < b.id ? -1 : a.id > b.id ? 1 : 0;\n\tconst findCollection = (id: string): Collection => {\n\t\tconst c = collections.find((each) => each.id === id);\n\t\tif (!c) throw notFound(\"Collection\", id);\n\t\treturn c;\n\t};\n\tconst siblingNamed = (parentId: string, name: string, except?: string) =>\n\t\tcollections.some((c) => c.parentId === parentId && c.name === name && c.id !== except);\n\t/** Refuses grant management the caller may not do, as the service does. */\n\tconst manageable = (id: string) => {\n\t\tif (authzMode === \"workspace\") throw new RestrictionUnavailableError(WORKSPACE_MODE_REFUSAL);\n\t\tconst c = findCollection(id);\n\t\tif (!c.restricted) {\n\t\t\tthrow new InvalidInputError(\n\t\t\t\t`Collection ${id} is open: only a Restricted Collection takes grants`,\n\t\t\t);\n\t\t}\n\t\tconst owns = (grants.get(id) ?? []).some((g) => g.userId === userId && g.level === \"owner\");\n\t\tif (!admin && !owns) {\n\t\t\tthrow new AccessDeniedError(\"only its owner or a workspace admin manages its grants\");\n\t\t}\n\t};\n\n\t/** Refuses recorder management the service would refuse, and returns the check's recorders. */\n\tconst narrowable = (checkId: string): RequiredCheckRecorders => {\n\t\tif (authzMode === \"workspace\") {\n\t\t\tthrow new GuardianModeRequiredError(\"required_check_recorders\", RECORDERS_WORKSPACE_MODE);\n\t\t}\n\t\tif (!admin) throw new AccessDeniedError(\"permission denied\");\n\t\tif (checkId === \"\") throw new InvalidInputError(\"required_check_id is required\");\n\t\tif (!requiredChecks.some((c) => c.id === checkId)) throw notFound(\"Required Check\", checkId);\n\t\treturn recordersOf(checkId);\n\t};\n\n\t/** One save, as SaveRevision applies it without an Idempotency Key. */\n\tconst saveOnce = async ({\n\t\tchangeSetId,\n\t\tbranchId,\n\t\texpectedHeadId,\n\t\tdata,\n\t\tfieldMask,\n\t}: SaveInput): Promise<Content> => {\n\t\tconst cs = open(changeSetId);\n\t\tconst chain = cs.chains.find((ch) => ch.branches.some((b) => b.id === branchId));\n\t\tconst branch = chain?.branches.find((b) => b.id === branchId);\n\t\tif (!chain || !branch) throw notFound(\"Branch\", branchId);\n\t\tconst c = findContent(chain.contentId);\n\t\tcheckEditable(c);\n\t\tif (stored.has(branchId)) {\n\t\t\tthrow new InvalidInputError(\n\t\t\t\t\"a Pending Merge waits on this Branch: resolve or abort it first\",\n\t\t\t);\n\t\t}\n\t\tif (expectedHeadId === \"\") throw new InvalidInputError(\"expected_head_id is required\");\n\t\tif (branch.headRevisionId !== expectedHeadId) {\n\t\t\tthrow new StaleHeadError({\n\t\t\t\tcontentId: c.id,\n\t\t\t\tbranchId,\n\t\t\t\texpectedHeadId,\n\t\t\t\tcurrentHeadId: branch.headRevisionId,\n\t\t\t});\n\t\t}\n\t\tconst head = dataOf(c, branch.headRevisionId) ?? {};\n\t\t// Through JSON, as the wire carries it: no `undefined` survives.\n\t\tconst sent = JSON.parse(JSON.stringify(data)) as Record<string, unknown>;\n\t\tlet saved: Record<string, unknown>;\n\t\tif (fieldMask) {\n\t\t\tconst stray = Object.keys(sent).filter((k) => !fieldMask.includes(k));\n\t\t\tif (stray.length > 0) {\n\t\t\t\tthrow new InvalidInputError(`data holds ${stray.join(\", \")}, which the mask doesn't name`);\n\t\t\t}\n\t\t\tsaved = structuredClone(head);\n\t\t\tfor (const key of fieldMask) {\n\t\t\t\tif (key in sent) saved[key] = sent[key];\n\t\t\t\telse delete saved[key];\n\t\t\t}\n\t\t} else {\n\t\t\tsaved = sent;\n\t\t}\n\t\t// No rule of fieldkit's data contract is applied: a save may leave\n\t\t// required Fields empty, and Publish asks for them (#180).\n\t\treturn writeHead({ changeSetId, chain, branch, c, data: saved, cause: \"save\" });\n\t};\n\n\t/** Writes a Revision on a Branch, on its head, which it becomes. */\n\tconst writeHead = ({\n\t\tchangeSetId,\n\t\tchain,\n\t\tbranch,\n\t\tc,\n\t\tdata,\n\t\tcause,\n\t\tsecondParentId = \"\",\n\t}: {\n\t\tchangeSetId: string;\n\t\tchain: ChangeSet[\"chains\"][number];\n\t\tbranch: ChangeSet[\"chains\"][number][\"branches\"][number];\n\t\tc: StubContent;\n\t\tdata: Record<string, unknown>;\n\t\tcause: Revision[\"cause\"];\n\t\tsecondParentId?: string;\n\t}): Content => {\n\t\tconst branchId = branch.id;\n\t\tconst n = next++;\n\t\tconst revisionId = `rev_stub_${n}`;\n\t\tconst createTime = now();\n\t\tc.revisions = [\n\t\t\t{\n\t\t\t\tid: revisionId,\n\t\t\t\tcontentId: c.id,\n\t\t\t\tparentId: branch.headRevisionId,\n\t\t\t\tsecondParentId,\n\t\t\t\tblueprintReleaseId: c.blueprintReleaseId,\n\t\t\t\tcreateTime,\n\t\t\t\tauthor: userId,\n\t\t\t\tcause,\n\t\t\t\tbranchId,\n\t\t\t\tchangeSetId,\n\t\t\t\tdata: structuredClone(data),\n\t\t\t},\n\t\t\t...(c.revisions ?? []),\n\t\t];\n\t\tbranch.headRevisionId = revisionId;\n\t\t// The Change Set read holds the head of the Chain's last Branch.\n\t\tif (chain.branches.at(-1)?.id === branchId) {\n\t\t\tc.branches[changeSetId] = {\n\t\t\t\tbranchId,\n\t\t\t\trevisionId,\n\t\t\t\tdata: structuredClone(data),\n\t\t\t\trevisionCreateTime: createTime,\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tid: c.id,\n\t\t\tblueprintId: c.blueprintId,\n\t\t\tblueprintReleaseId: c.blueprintReleaseId,\n\t\t\trevisionId,\n\t\t\tdata: structuredClone(data),\n\t\t\tchangeSetId,\n\t\t\tbranchId,\n\t\t\trevisionCreateTime: createTime,\n\t\t\treleaseId: \"\",\n\t\t};\n\t};\n\n\t/** The Chain and Branch of `branchId` in an open Change Set, and its Content. */\n\tconst branchIn = (changeSetId: string, branchId: string) => {\n\t\tconst cs = open(changeSetId);\n\t\tconst chain = cs.chains.find((ch) => ch.branches.some((b) => b.id === branchId));\n\t\tconst branch = chain?.branches.find((b) => b.id === branchId);\n\t\tif (!chain || !branch) throw notFound(\"Branch\", branchId);\n\t\treturn { cs, chain, branch, c: findContent(chain.contentId) };\n\t};\n\n\t/** Stores what an Update from Main met on a Branch as its Pending Merge. */\n\tconst storeMerge = (branchId: string, conflict: StubConflict) => {\n\t\tfor (const cs of changeSets) {\n\t\t\tfor (const chain of cs.chains) {\n\t\t\t\tconst branch = chain.branches.find((b) => b.id === branchId);\n\t\t\t\tif (!branch) continue;\n\t\t\t\tconst pm: PendingMerge = {\n\t\t\t\t\tbranchId,\n\t\t\t\t\tcontentId: chain.contentId,\n\t\t\t\t\treason: conflict.reason ?? \"conflict\",\n\t\t\t\t\toursRevisionId: branch.headRevisionId,\n\t\t\t\t\ttheirsRevisionId: conflict.theirsRevisionId,\n\t\t\t\t\tcarried: false,\n\t\t\t\t\tfields: structuredClone(conflict.fields),\n\t\t\t\t\tmerged: structuredClone(conflict.merged),\n\t\t\t\t};\n\t\t\t\tstored.set(branchId, pm);\n\t\t\t\tbranch.hasPendingMerge = true;\n\t\t\t\tdelete conflicts[branchId];\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tthrow notFound(\"Branch\", branchId);\n\t};\n\tconst dropMerge = (branchId: string) => {\n\t\tstored.delete(branchId);\n\t\tfor (const cs of changeSets) {\n\t\t\tfor (const chain of cs.chains) {\n\t\t\t\tconst branch = chain.branches.find((b) => b.id === branchId);\n\t\t\t\tif (branch) branch.hasPendingMerge = false;\n\t\t\t}\n\t\t}\n\t};\n\n\t/**\n\t * A plan checked as the service checks it: a Validity Period for Dated\n\t * Content and none for undated, its Release Spec's required values, and\n\t * no Release of the Content covered entirely unless it supersedes it.\n\t */\n\tconst checkPlan = (\n\t\tc: StubContent,\n\t\tplan: Pick<PlannedRelease, \"validityPeriod\" | \"releaseSpec\" | \"supersedesReleaseIds\">,\n\t) => {\n\t\tconst vp = plan.validityPeriod;\n\t\tif (datedContent(c)) {\n\t\t\tif (!vp || !DAY.test(vp.firstDay)) {\n\t\t\t\tthrow new InvalidInputError(\"validity_period.first_day is required for Dated Content\");\n\t\t\t}\n\t\t\tif (vp.lastDay !== \"\" && (!DAY.test(vp.lastDay) || vp.lastDay < vp.firstDay)) {\n\t\t\t\tthrow new InvalidInputError(\"validity_period.last_day is a day on or after first_day\");\n\t\t\t}\n\t\t} else if (vp) {\n\t\t\tthrow new InvalidInputError(\"validity_period is refused for undated Content\");\n\t\t}\n\t\tconst violations = missingRequired(\n\t\t\tresolved[c.blueprintReleaseId]?.releaseSpec,\n\t\t\tplan.releaseSpec ?? {},\n\t\t).map((accessor) => ({ source: \"fieldkit\", code: \"required\", path: `/${accessor}` }));\n\t\tif (violations.length > 0) {\n\t\t\tthrow new ContentRefusedError(\n\t\t\t\t\"the Release Spec values break the Blueprint Release\",\n\t\t\t\tviolations,\n\t\t\t);\n\t\t}\n\t\tif (vp && vp.lastDay !== \"\") {\n\t\t\tconst covered = (c.timeline ?? [])\n\t\t\t\t.filter(\n\t\t\t\t\t(e) =>\n\t\t\t\t\t\te.validityPeriod &&\n\t\t\t\t\t\te.validityPeriod.lastDay !== \"\" &&\n\t\t\t\t\t\tvp.firstDay <= e.validityPeriod.firstDay &&\n\t\t\t\t\t\te.validityPeriod.lastDay <= vp.lastDay &&\n\t\t\t\t\t\t!plan.supersedesReleaseIds.includes(e.releaseId),\n\t\t\t\t)\n\t\t\t\t.map((e) => e.releaseId);\n\t\t\tif (covered.length > 0) throw new CoversReleaseError(c.id, covered);\n\t\t}\n\t};\n\n\t/**\n\t * The Change Set's proposals for a Content, derived again from its plans\n\t * (versionkit ADR 0003): a date-only cut of each Release a planned period\n\t * cuts into, and a tail resuming its wording after a period strictly\n\t * inside it. A proposal keeps its id while it proposes for the same Release.\n\t */\n\tconst repropose = (cs: ChangeSet, c: StubContent) => {\n\t\tconst previous = cs.plannedReleases.filter((p) => p.contentId === c.id && p.proposed);\n\t\tconst kept = cs.plannedReleases.filter((p) => !(p.contentId === c.id && p.proposed));\n\t\tconst proposals: PlannedRelease[] = [];\n\t\tconst propose = (\n\t\t\te: TimelineEntry,\n\t\t\tvalidityPeriod: { firstDay: string; lastDay: string },\n\t\t\tsplitFromReleaseId: string,\n\t\t) => {\n\t\t\tconst same = previous.find(\n\t\t\t\t(p) =>\n\t\t\t\t\tp.proposedForReleaseId === e.releaseId && p.splitFromReleaseId === splitFromReleaseId,\n\t\t\t);\n\t\t\tproposals.push({\n\t\t\t\tid: same?.id ?? `rls_stub_${next++}`,\n\t\t\t\tcontentId: c.id,\n\t\t\t\tkind: \"date_only\",\n\t\t\t\tbranchId: \"\",\n\t\t\t\trevisionId: e.revisionId,\n\t\t\t\tvalidityPeriod,\n\t\t\t\tsupersedesReleaseIds: splitFromReleaseId ? [] : [e.releaseId],\n\t\t\t\tproposed: true,\n\t\t\t\tproposedForReleaseId: e.releaseId,\n\t\t\t\tsplitFromReleaseId,\n\t\t\t\twithheld: false,\n\t\t\t});\n\t\t};\n\t\tfor (const plan of kept) {\n\t\t\tconst vp = plan.validityPeriod;\n\t\t\tif (plan.contentId !== c.id || plan.kind !== \"revision\" || !vp) continue;\n\t\t\tfor (const e of c.timeline ?? []) {\n\t\t\t\tconst its = e.validityPeriod;\n\t\t\t\tif (!its || plan.supersedesReleaseIds.includes(e.releaseId)) continue;\n\t\t\t\tif (!(its.firstDay < vp.firstDay && (its.lastDay === \"\" || its.lastDay >= vp.firstDay))) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tpropose(e, { firstDay: its.firstDay, lastDay: shiftDay(vp.firstDay, -1) }, \"\");\n\t\t\t\tif (vp.lastDay !== \"\" && (its.lastDay === \"\" || its.lastDay > vp.lastDay)) {\n\t\t\t\t\tpropose(e, { firstDay: shiftDay(vp.lastDay, 1), lastDay: its.lastDay }, e.releaseId);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tcs.plannedReleases = [...kept, ...proposals];\n\t};\n\n\tconst find = (id: string): ChangeSet => {\n\t\tconst cs = changeSets.find((c) => c.id === id);\n\t\tif (!cs) throw notFound(\"Change Set\", id);\n\t\treturn cs;\n\t};\n\tconst open = (id: string): ChangeSet => {\n\t\tconst cs = find(id);\n\t\tif (cs.state !== \"open\") throw new ChangeSetClosedError(cs.state);\n\t\treturn cs;\n\t};\n\tconst statusName = (slug: string) => statuses.find((s) => s.slug === slug)?.name ?? slug;\n\t// Whether `from` reaches `to` through dependencies.\n\tconst reaches = (from: string, to: string, seen = new Set<string>()): boolean => {\n\t\tif (from === to) return true;\n\t\tif (seen.has(from)) return false;\n\t\tseen.add(from);\n\t\tconst cs = changeSets.find((c) => c.id === from);\n\t\treturn (cs?.dependsOnChangeSetIds ?? []).some((d) => reaches(d, to, seen));\n\t};\n\n\t// What a Required Check applies to in a Change Set, as the service's\n\t// currentView reads it: every Branch at its head, then every Branch-less\n\t// Planned Release at the Revision it re-pins.\n\tconst subjectsOf = (cs: ChangeSet) => [\n\t\t...cs.chains.flatMap((chain) =>\n\t\t\tchain.branches.map((b) => ({\n\t\t\t\tkey: b.id,\n\t\t\t\tbranchless: false,\n\t\t\t\tcontentId: chain.contentId,\n\t\t\t\trevision: b.headRevisionId,\n\t\t\t})),\n\t\t),\n\t\t...cs.plannedReleases\n\t\t\t.filter((pr) => pr.kind !== \"revision\" && pr.revisionId !== \"\")\n\t\t\t.map((pr) => ({\n\t\t\t\tkey: pr.id,\n\t\t\t\tbranchless: true,\n\t\t\t\tcontentId: pr.contentId,\n\t\t\t\trevision: pr.revisionId,\n\t\t\t})),\n\t];\n\tconst blueprintOf = (contentId: string) => contents.find((c) => c.id === contentId)?.blueprintId;\n\tconst covers = (check: RequiredCheck, contentId: string) =>\n\t\tcheck.blueprintAccessors.length === 0 ||\n\t\tcheck.blueprintAccessors.includes(blueprintOf(contentId) ?? \"\");\n\n\t/** Where each check stands, by name, as ListCheckResults answers. */\n\tconst standingsOf = (cs: ChangeSet): CheckStanding[] => {\n\t\tconst subjects = subjectsOf(cs);\n\t\t// Newest first. A Branch-scope result is about the one head it names,\n\t\t// a Change Set-scope one (\"\" here) about the whole.\n\t\tconst resultsOn = (check: RequiredCheck, subject: string): CheckResult[] =>\n\t\t\tcheckResults\n\t\t\t\t.filter((r) => r.changeSetId === cs.id && r.requiredCheckId === check.id)\n\t\t\t\t.filter((r) => (check.scope === \"change_set\" ? \"\" : Object.keys(r.heads)[0]) === subject)\n\t\t\t\t.reverse()\n\t\t\t\t.map(({ changeSetId: _, ...r }) => structuredClone(r));\n\t\tconst standing = (\n\t\t\tcheck: RequiredCheck,\n\t\t\tat: Pick<CheckStanding, \"contentId\" | \"branchId\" | \"releaseId\" | \"heads\">,\n\t\t\tresults: CheckResult[],\n\t\t): CheckStanding => {\n\t\t\tconst latest = results[0];\n\t\t\tconst stale = latest ? !sameHeads(latest.heads, at.heads) : false;\n\t\t\treturn {\n\t\t\t\tcheck: structuredClone(check),\n\t\t\t\t...at,\n\t\t\t\tresults,\n\t\t\t\tstale,\n\t\t\t\tcleared: !!latest && !stale && latest.outcome !== \"failed\",\n\t\t\t};\n\t\t};\n\t\tconst out: CheckStanding[] = [];\n\t\t// By name, then id, as the service orders them.\n\t\tconst byNameThenId = (a: RequiredCheck, b: RequiredCheck) =>\n\t\t\ta.name < b.name ? -1 : a.name > b.name ? 1 : a.id < b.id ? -1 : a.id > b.id ? 1 : 0;\n\t\tfor (const check of [...requiredChecks].sort(byNameThenId)) {\n\t\t\tconst covered = subjects.filter((s) => covers(check, s.contentId));\n\t\t\tif (check.scope === \"change_set\") {\n\t\t\t\tif (covered.length === 0) continue;\n\t\t\t\tconst heads = Object.fromEntries(subjects.map((s) => [s.key, s.revision]));\n\t\t\t\tout.push(\n\t\t\t\t\tstanding(\n\t\t\t\t\t\tcheck,\n\t\t\t\t\t\t{ contentId: \"\", branchId: \"\", releaseId: \"\", heads },\n\t\t\t\t\t\tresultsOn(check, \"\"),\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (const s of covered) {\n\t\t\t\tout.push(\n\t\t\t\t\tstanding(\n\t\t\t\t\t\tcheck,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcontentId: s.contentId,\n\t\t\t\t\t\t\tbranchId: s.branchless ? \"\" : s.key,\n\t\t\t\t\t\t\treleaseId: s.branchless ? s.key : \"\",\n\t\t\t\t\t\t\theads: { [s.key]: s.revision },\n\t\t\t\t\t\t},\n\t\t\t\t\t\tresultsOn(check, s.key),\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t};\n\n\t/**\n\t * The blockers a Publish of `cs` with `reviewed` meets: moved heads, open\n\t * or discarded dependencies, outstanding checks, top-level required\n\t * Fields a Branch head leaves empty, and what the options add for the\n\t * rest.\n\t */\n\tconst blockersOf = (cs: ChangeSet, reviewed: Record<string, string>): PublishBlocker[] => {\n\t\tconst out: PublishBlocker[] = [];\n\t\tconst current = headsOf(cs);\n\t\tfor (const chain of cs.chains) {\n\t\t\tfor (const b of chain.branches) {\n\t\t\t\tif (reviewed[b.id] !== b.headRevisionId) {\n\t\t\t\t\tout.push(\n\t\t\t\t\t\tstubBlocker(\"moved_head\", {\n\t\t\t\t\t\t\tcontentId: chain.contentId,\n\t\t\t\t\t\t\tbranchId: b.id,\n\t\t\t\t\t\t\texpectedHeadId: reviewed[b.id] ?? \"\",\n\t\t\t\t\t\t\tcurrentHeadId: b.headRevisionId,\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (const [id, head] of Object.entries(reviewed)) {\n\t\t\tif (!(id in current)) {\n\t\t\t\tout.push(stubBlocker(\"moved_head\", { branchId: id, expectedHeadId: head }));\n\t\t\t}\n\t\t}\n\t\tfor (const dep of cs.dependsOnChangeSetIds) {\n\t\t\tconst state = changeSets.find((c) => c.id === dep)?.state;\n\t\t\tif (state === \"open\") {\n\t\t\t\tout.push(stubBlocker(\"unpublished_dependency\", { dependencyChangeSetId: dep }));\n\t\t\t} else if (state === \"discarded\") {\n\t\t\t\tout.push(stubBlocker(\"discarded_dependency\", { dependencyChangeSetId: dep }));\n\t\t\t}\n\t\t}\n\t\tfor (const st of standingsOf(cs)) {\n\t\t\tif (!st.cleared) {\n\t\t\t\tout.push(\n\t\t\t\t\tstubBlocker(\"outstanding_check\", {\n\t\t\t\t\t\trequiredCheckId: st.check.id,\n\t\t\t\t\t\tcontentId: st.contentId,\n\t\t\t\t\t\tbranchId: st.branchId,\n\t\t\t\t\t\treleaseId: st.releaseId,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tfor (const chain of cs.chains) {\n\t\t\tconst c = contents.find((x) => x.id === chain.contentId);\n\t\t\tfor (const b of chain.branches) {\n\t\t\t\tconst data = c && dataOf(c, b.headRevisionId);\n\t\t\t\tif (!c || !data) continue;\n\t\t\t\tfor (const accessor of missingRequired(resolved[c.blueprintReleaseId]?.fields, data)) {\n\t\t\t\t\tout.push(\n\t\t\t\t\t\tstubBlocker(\"missing_required_field\", {\n\t\t\t\t\t\t\tcontentId: c.id,\n\t\t\t\t\t\t\trevisionId: b.headRevisionId,\n\t\t\t\t\t\t\tpath: `/${accessor}`,\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn [...out, ...structuredClone(extraBlockers[cs.id] ?? [])];\n\t};\n\n\t/** The Releases a Publish of `cs` cuts: every Planned Release not withheld. */\n\tconst releasesOf = (cs: ChangeSet): Release[] => {\n\t\tconst current = headsOf(cs);\n\t\treturn cs.plannedReleases\n\t\t\t.filter((pr) => !pr.withheld)\n\t\t\t.map((pr) => ({\n\t\t\t\tid: pr.id,\n\t\t\t\tcontentId: pr.contentId,\n\t\t\t\tkind: pr.kind,\n\t\t\t\tbranchId: pr.branchId,\n\t\t\t\trevisionId: pr.branchId ? (current[pr.branchId] ?? \"\") : pr.revisionId,\n\t\t\t\tfirst: !!cs.chains.find((c) => c.contentId === pr.contentId)?.born,\n\t\t\t\tsupersedesReleaseIds: [...pr.supersedesReleaseIds],\n\t\t\t\tvalidityPeriod: pr.validityPeriod ? { ...pr.validityPeriod } : undefined,\n\t\t\t}));\n\t};\n\n\tfor (const [branchId, conflict] of Object.entries(conflicts)) {\n\t\tif (conflict.pending) storeMerge(branchId, conflict);\n\t}\n\n\treturn {\n\t\tasync listBlockReasons() {\n\t\t\treturn [...reasons].sort(byName).map((r) => ({ ...r }));\n\t\t},\n\t\tasync createBlockReason({ name: raw }) {\n\t\t\tconst name = checkedBlockReasonName(raw);\n\t\t\tif (taken(name)) throw new BlockReasonNameTakenError(name);\n\t\t\tconst reason = { id: `br_stub_${next++}`, name, createTime: now(), updateTime: now() };\n\t\t\treasons.push(reason);\n\t\t\treturn { ...reason };\n\t\t},\n\t\tasync renameBlockReason({ id, name: raw }) {\n\t\t\tconst name = checkedBlockReasonName(raw);\n\t\t\tconst reason = reasons.find((r) => r.id === id);\n\t\t\tif (!reason) throw notFound(\"Block Reason\", id);\n\t\t\tif (taken(name, id)) throw new BlockReasonNameTakenError(name);\n\t\t\treason.name = name;\n\t\t\treason.updateTime = now();\n\t\t\treturn { ...reason };\n\t\t},\n\t\tasync deleteBlockReason({ id }) {\n\t\t\tif (!reasons.some((r) => r.id === id)) throw notFound(\"Block Reason\", id);\n\t\t\treasons = reasons.filter((r) => r.id !== id);\n\t\t},\n\n\t\tasync listChangeSets(input = {}) {\n\t\t\tconst matching = changeSets.filter(\n\t\t\t\t(cs) =>\n\t\t\t\t\t(!input.state || cs.state === input.state) &&\n\t\t\t\t\t(!input.assigneeId || cs.assigneeIds.includes(input.assigneeId)) &&\n\t\t\t\t\t(!input.contentId || cs.chains.some((c) => c.contentId === input.contentId)),\n\t\t\t);\n\t\t\tconst size = Math.min(input.pageSize || 50, 200);\n\t\t\tconst start = input.pageToken ? Number(input.pageToken) : 0;\n\t\t\tconst page = matching.slice(start, start + size);\n\t\t\treturn {\n\t\t\t\t// A list carries no Chains, dependencies or Planned Releases.\n\t\t\t\tchangeSets: page.map((cs) => ({\n\t\t\t\t\t...copy(cs),\n\t\t\t\t\tchains: [],\n\t\t\t\t\tdependsOnChangeSetIds: [],\n\t\t\t\t\tplannedReleases: [],\n\t\t\t\t})),\n\t\t\t\tnextPageToken: start + size < matching.length ? String(start + size) : \"\",\n\t\t\t};\n\t\t},\n\t\tasync createChangeSet({ name: rawName, source }) {\n\t\t\tconst name = oneLine(rawName, \"name\", CHANGE_SET_NAME_MAX);\n\t\t\tconst checkedSource = source ? checkedSourceOf(source) : undefined;\n\t\t\tconst cs: ChangeSet = {\n\t\t\t\tid: `cs_stub_${next++}`,\n\t\t\t\tname,\n\t\t\t\tsource: checkedSource,\n\t\t\t\tstate: \"open\",\n\t\t\t\tcreatedBy: userId,\n\t\t\t\tcreateTime: now(),\n\t\t\t\tchains: [],\n\t\t\t\tdependsOnChangeSetIds: [],\n\t\t\t\tstatus: \"\",\n\t\t\t\tassigneeIds: [],\n\t\t\t\tplannedReleases: [],\n\t\t\t};\n\t\t\tchangeSets.unshift(cs);\n\t\t\treturn copy(cs);\n\t\t},\n\t\tasync getChangeSet(id) {\n\t\t\treturn copy(find(id));\n\t\t},\n\t\tasync updateChangeSet({ id, updateMask, name, source }) {\n\t\t\tconst cs = open(id);\n\t\t\tif (updateMask.length === 0) throw new InvalidInputError(\"update_mask is required\");\n\t\t\t// Checked whole before anything changes, as the service does.\n\t\t\tconst nextName = updateMask.includes(\"name\")\n\t\t\t\t? oneLine(name ?? \"\", \"name\", CHANGE_SET_NAME_MAX)\n\t\t\t\t: cs.name;\n\t\t\tlet nextSource = cs.source;\n\t\t\tif (updateMask.includes(\"source\")) {\n\t\t\t\tnextSource = source ? checkedSourceOf(source) : undefined;\n\t\t\t}\n\t\t\tcs.name = nextName;\n\t\t\tcs.source = nextSource;\n\t\t\treturn copy(cs);\n\t\t},\n\t\tasync setChangeSetStatus({ id, expectedStatus, status }) {\n\t\t\tconst cs = open(id);\n\t\t\tif (cs.status !== expectedStatus) throw new StaleStatusError(cs.status);\n\t\t\t// Already there: nothing to ask statushub, as the service does.\n\t\t\tif (cs.status === status) return copy(cs);\n\t\t\tif (!statuses.some((s) => s.slug === status)) {\n\t\t\t\tthrow new InvalidInputError(`status \"${status}\" is not in the workspace's catalogue`);\n\t\t\t}\n\t\t\t// A move away from an unknown status is never validated, so a Change\n\t\t\t// Set is never stuck on a deleted status (ADR 0014).\n\t\t\tconst known = statuses.some((s) => s.slug === cs.status);\n\t\t\tif (known && !(transitions[cs.status] ?? []).includes(status)) {\n\t\t\t\tthrow new StatusTransitionRefusedError({\n\t\t\t\t\tfromStatus: cs.status,\n\t\t\t\t\ttoStatus: status,\n\t\t\t\t\treason: `There is no transition from ${statusName(cs.status)} to ${statusName(status)}.`,\n\t\t\t\t\trequiresPermission: false,\n\t\t\t\t});\n\t\t\t}\n\t\t\tcs.status = status;\n\t\t\treturn copy(cs);\n\t\t},\n\t\tasync setChangeSetAssignees({ id, assigneeIds }) {\n\t\t\tconst cs = find(id);\n\t\t\tif (new Set(assigneeIds).size !== assigneeIds.length) {\n\t\t\t\tthrow new InvalidInputError(\"each assignee is given once\");\n\t\t\t}\n\t\t\tif (assigneeIds.length > 50) throw new InvalidInputError(\"at most 50 assignees\");\n\t\t\tcs.assigneeIds = [...assigneeIds];\n\t\t\treturn copy(cs);\n\t\t},\n\t\tasync addDependency({ id, dependsOnId }) {\n\t\t\tconst cs = open(id);\n\t\t\tconst target = find(dependsOnId);\n\t\t\tif (target.state !== \"open\") {\n\t\t\t\tthrow new InvalidInputError(`Change Set ${dependsOnId} is ${target.state}`);\n\t\t\t}\n\t\t\tif (reaches(dependsOnId, id)) {\n\t\t\t\tthrow new InvalidInputError(\"the dependency would close a cycle\");\n\t\t\t}\n\t\t\tif (!cs.dependsOnChangeSetIds.includes(dependsOnId)) {\n\t\t\t\tcs.dependsOnChangeSetIds.push(dependsOnId);\n\t\t\t}\n\t\t\treturn copy(cs);\n\t\t},\n\t\tasync removeDependency({ id, dependsOnId }) {\n\t\t\tconst cs = open(id);\n\t\t\tif (!cs.dependsOnChangeSetIds.includes(dependsOnId)) {\n\t\t\t\tthrow notFound(`dependency of Change Set ${id} on`, dependsOnId);\n\t\t\t}\n\t\t\tcs.dependsOnChangeSetIds = cs.dependsOnChangeSetIds.filter((d) => d !== dependsOnId);\n\t\t\treturn copy(cs);\n\t\t},\n\t\tasync validatePublish({ id, reviewedHeads }) {\n\t\t\tconst cs = find(id);\n\t\t\trefuseWithheld(id);\n\t\t\tconst published = publishedWith.get(id);\n\t\t\t// Published with these heads: the stored outcome. With others, it is closed.\n\t\t\tif (published && sameHeads(published, reviewedHeads)) {\n\t\t\t\treturn {\n\t\t\t\t\tblockers: [],\n\t\t\t\t\treleases: releasesOf(cs),\n\t\t\t\t\tpublished: true,\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (cs.state !== \"open\") throw new ChangeSetClosedError(cs.state);\n\t\t\treturn {\n\t\t\t\tblockers: blockersOf(cs, reviewedHeads),\n\t\t\t\treleases: releasesOf(cs),\n\t\t\t\tpublished: false,\n\t\t\t};\n\t\t},\n\t\tasync publish({ id, reviewedHeads }) {\n\t\t\tconst cs = find(id);\n\t\t\trefuseWithheld(id);\n\t\t\tconst published = publishedWith.get(id);\n\t\t\t// A repeat with the same heads returns the stored outcome.\n\t\t\tif (published && sameHeads(published, reviewedHeads)) {\n\t\t\t\treturn {\n\t\t\t\t\tchangeSet: copy(cs),\n\t\t\t\t\tpublishTime: cs.closeTime ?? now(),\n\t\t\t\t\treleases: releasesOf(cs),\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (cs.state !== \"open\") throw new ChangeSetClosedError(cs.state);\n\t\t\tconst blockers = blockersOf(cs, reviewedHeads);\n\t\t\tif (blockers.length > 0) throw new PublishRefusedError(blockers);\n\t\t\tconst cut = releasesOf(cs);\n\t\t\tcs.state = \"published\";\n\t\t\tcs.closeTime = now();\n\t\t\tpublishedWith.set(id, { ...reviewedHeads });\n\t\t\treturn { changeSet: copy(cs), publishTime: cs.closeTime, releases: cut };\n\t\t},\n\t\tasync updateFromMain({ id, chainId, idempotencyKey }) {\n\t\t\treturn once(idempotencyKey, [\"updateFromMain\", id, chainId], async () => {\n\t\t\t\tconst cs = open(id);\n\t\t\t\tif (!chainId) refuseWithheld(id);\n\t\t\t\tconst chains = chainId ? cs.chains.filter((ch) => ch.id === chainId) : cs.chains;\n\t\t\t\tif (chainId && chains.length === 0) throw notFound(\"Chain\", chainId);\n\t\t\t\tconst conflicted: PendingMergeRef[] = structuredClone(pendingMerges[id] ?? []);\n\t\t\t\tconst pending: PendingMergeRef[] = [];\n\t\t\t\tfor (const chain of chains) {\n\t\t\t\t\tfor (const b of chain.branches) {\n\t\t\t\t\t\tconst ref = { branchId: b.id, contentId: chain.contentId };\n\t\t\t\t\t\tconst conflict = conflicts[b.id];\n\t\t\t\t\t\tif (stored.has(b.id)) pending.push(ref);\n\t\t\t\t\t\telse if (conflict) {\n\t\t\t\t\t\t\tstoreMerge(b.id, conflict);\n\t\t\t\t\t\t\tconflicted.push(ref);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tchangeSet: copy(cs),\n\t\t\t\t\tmergedBranchIds: [],\n\t\t\t\t\tconflicted,\n\t\t\t\t\tpending,\n\t\t\t\t\tendedBranchIds: [],\n\t\t\t\t};\n\t\t\t});\n\t\t},\n\t\tasync discardChangeSet(id) {\n\t\t\tconst cs = open(id);\n\t\t\trefuseWithheld(id);\n\t\t\tcs.state = \"discarded\";\n\t\t\tcs.closeTime = now();\n\t\t\t// The Content born in it is gone, and its Chains with it.\n\t\t\tcs.chains = [];\n\t\t\treturn copy(cs);\n\t\t},\n\t\tasync listCheckResults(changeSetId) {\n\t\t\treturn standingsOf(find(changeSetId));\n\t\t},\n\t\tasync recordCheckResult({ changeSetId, requiredCheckId, heads, outcome, note }) {\n\t\t\tconst cs = open(changeSetId);\n\t\t\tif (outcome === \"waived\" && note.trim() === \"\") {\n\t\t\t\tthrow new InvalidInputError(\"a waived result needs a note saying why\");\n\t\t\t}\n\t\t\tif ([...note].length > CHECK_NOTE_MAX) {\n\t\t\t\tthrow new InvalidInputError(`a note is at most ${CHECK_NOTE_MAX} characters`);\n\t\t\t}\n\t\t\tconst check = requiredChecks.find((c) => c.id === requiredCheckId);\n\t\t\tif (!check) throw notFound(\"Required Check\", requiredCheckId);\n\t\t\tconst recording = recordersOf(requiredCheckId);\n\t\t\t// The caller is a member: the stub has no other kind of caller.\n\t\t\tif (\n\t\t\t\tauthzMode === \"guardian\" &&\n\t\t\t\t!recording.everyMember &&\n\t\t\t\t!recording.userIds.includes(userId)\n\t\t\t) {\n\t\t\t\tthrow new CheckResultDeniedError(\n\t\t\t\t\t`recording results of Required Check ${requiredCheckId} needs its recorder relation`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst subjects = subjectsOf(cs);\n\t\t\tconst named = Object.keys(heads);\n\t\t\tif (check.scope === \"branch\" && named.length !== 1) {\n\t\t\t\tthrow new InvalidInputError(\"a Branch-scope result names one head\");\n\t\t\t}\n\t\t\tif (check.scope === \"change_set\" && named.length !== subjects.length) {\n\t\t\t\tthrow new InvalidInputError(\"a Change Set-scope result names every head of the Change Set\");\n\t\t\t}\n\t\t\tfor (const key of named) {\n\t\t\t\tconst s = subjects.find((each) => each.key === key);\n\t\t\t\tif (!s)\n\t\t\t\t\tthrow new InvalidInputError(`heads name ${key}, which this Change Set doesn't hold`);\n\t\t\t\tif (s.revision !== heads[key]) {\n\t\t\t\t\tthrow new StaleHeadError({\n\t\t\t\t\t\tcontentId: s.contentId,\n\t\t\t\t\t\tbranchId: s.branchless ? \"\" : s.key,\n\t\t\t\t\t\texpectedHeadId: heads[key],\n\t\t\t\t\t\tcurrentHeadId: s.revision,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst result = {\n\t\t\t\tid: `cr_stub_${next++}`,\n\t\t\t\trequiredCheckId,\n\t\t\t\theads: { ...heads },\n\t\t\t\toutcome,\n\t\t\t\tnote,\n\t\t\t\trecordedBy: userId,\n\t\t\t\trecordTime: now(),\n\t\t\t};\n\t\t\tcheckResults.push({ ...result, changeSetId });\n\t\t\treturn structuredClone(result);\n\t\t},\n\n\t\tasync listRequiredChecks() {\n\t\t\tconst byNameThenId = (a: RequiredCheck, b: RequiredCheck) =>\n\t\t\t\ta.name < b.name ? -1 : a.name > b.name ? 1 : a.id < b.id ? -1 : a.id > b.id ? 1 : 0;\n\t\t\treturn structuredClone([...requiredChecks].sort(byNameThenId));\n\t\t},\n\t\tasync createRequiredCheck(input) {\n\t\t\tconst checked = checkedRequiredCheck(input);\n\t\t\tif (requiredChecks.some((c) => c.name === checked.name)) {\n\t\t\t\tthrow new NameTakenError(checked.name);\n\t\t\t}\n\t\t\tconst check: RequiredCheck = { id: `rc_stub_${next++}`, ...checked };\n\t\t\trequiredChecks.push(check);\n\t\t\treturn structuredClone(check);\n\t\t},\n\t\tasync updateRequiredCheck({ id, ...input }) {\n\t\t\tconst checked = checkedRequiredCheck(input);\n\t\t\tconst check = requiredChecks.find((c) => c.id === id);\n\t\t\tif (!check) throw notFound(\"Required Check\", id);\n\t\t\tif (requiredChecks.some((c) => c.name === checked.name && c.id !== id)) {\n\t\t\t\tthrow new NameTakenError(checked.name);\n\t\t\t}\n\t\t\tObject.assign(check, checked);\n\t\t\treturn structuredClone(check);\n\t\t},\n\t\tasync deleteRequiredCheck({ id }) {\n\t\t\tif (!requiredChecks.some((c) => c.id === id)) throw notFound(\"Required Check\", id);\n\t\t\trequiredChecks = requiredChecks.filter((c) => c.id !== id);\n\t\t\trecorders.delete(id);\n\t\t},\n\t\tasync listRequiredCheckRecorders(requiredCheckId) {\n\t\t\treturn structuredClone(narrowable(requiredCheckId));\n\t\t},\n\t\tasync grantRequiredCheckRecorder({ requiredCheckId, recorder }) {\n\t\t\tconst held = narrowable(requiredCheckId);\n\t\t\tif (\"everyMember\" in recorder) {\n\t\t\t\trecorders.set(requiredCheckId, { ...held, everyMember: true });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!memberIds.includes(recorder.userId)) {\n\t\t\t\tthrow new InvalidInputError(`user ${recorder.userId} is not a member of the workspace`);\n\t\t\t}\n\t\t\trecorders.set(requiredCheckId, {\n\t\t\t\t...held,\n\t\t\t\tuserIds: [...new Set([...held.userIds, recorder.userId])].sort(),\n\t\t\t});\n\t\t},\n\t\tasync revokeRequiredCheckRecorder({ requiredCheckId, recorder }) {\n\t\t\tconst held = narrowable(requiredCheckId);\n\t\t\trecorders.set(\n\t\t\t\trequiredCheckId,\n\t\t\t\t\"everyMember\" in recorder\n\t\t\t\t\t? { ...held, everyMember: false }\n\t\t\t\t\t: { ...held, userIds: held.userIds.filter((u) => u !== recorder.userId) },\n\t\t\t);\n\t\t},\n\n\t\tasync searchBlueprints({ query }) {\n\t\t\tconst q = query.trim().toLocaleLowerCase();\n\t\t\treturn {\n\t\t\t\tblueprints: blueprints\n\t\t\t\t\t.filter((b) => !b.archived)\n\t\t\t\t\t.filter((b) => b.name.toLocaleLowerCase().includes(q))\n\t\t\t\t\t.filter((b) => releases.some((r) => r.blueprintId === b.id))\n\t\t\t\t\t.map((b) => ({ id: b.id, name: b.name })),\n\t\t\t\tnextPageToken: \"\",\n\t\t\t};\n\t\t},\n\t\tasync getBlueprints(ids) {\n\t\t\tif (ids.length > MAX_BLUEPRINT_IDS) {\n\t\t\t\tthrow new InvalidInputError(`at most ${MAX_BLUEPRINT_IDS} Blueprint ids`);\n\t\t\t}\n\t\t\treturn blueprints.filter((b) => ids.includes(b.id)).map((b) => ({ id: b.id, name: b.name }));\n\t\t},\n\t\tasync listBlueprintReleases(blueprintId) {\n\t\t\treturn releases\n\t\t\t\t.filter((r) => r.blueprintId === blueprintId)\n\t\t\t\t.map((r) => ({\n\t\t\t\t\tid: r.id,\n\t\t\t\t\tblueprintId: r.blueprintId,\n\t\t\t\t\tname: r.name ?? r.id,\n\t\t\t\t\treleaseTime: r.releaseTime ?? STUB_NOW,\n\t\t\t\t\trefusals: (r.refusals ?? []).map((v) => ({ ...v })),\n\t\t\t\t}));\n\t\t},\n\n\t\tasync listCollections() {\n\t\t\treturn [...collections].sort(collectionOrder).map((c) => ({ ...c }));\n\t\t},\n\t\tasync createCollection({ name: raw, parentId = \"\", restricted = false }) {\n\t\t\tconst name = oneLine(raw, \"a Collection's name\", COLLECTION_NAME_MAX);\n\t\t\tif (parentId !== \"\") findCollection(parentId);\n\t\t\tif (restricted && authzMode === \"workspace\") {\n\t\t\t\tthrow new RestrictionUnavailableError(WORKSPACE_MODE_REFUSAL);\n\t\t\t}\n\t\t\tif (siblingNamed(parentId, name)) throw new NameTakenError(name);\n\t\t\tconst collection: Collection = { id: `col_stub_${next++}`, name, parentId, restricted };\n\t\t\tcollections.push(collection);\n\t\t\tif (restricted) grants.set(collection.id, [{ userId, level: \"owner\" }]);\n\t\t\treturn { ...collection };\n\t\t},\n\t\tasync renameCollection({ id, name: raw }) {\n\t\t\tconst name = oneLine(raw, \"a Collection's name\", COLLECTION_NAME_MAX);\n\t\t\tconst collection = findCollection(id);\n\t\t\tif (siblingNamed(collection.parentId, name, id)) throw new NameTakenError(name);\n\t\t\tcollection.name = name;\n\t\t\treturn { ...collection };\n\t\t},\n\t\tasync moveCollection({ id, parentId }) {\n\t\t\tconst collection = findCollection(id);\n\t\t\tfor (let at = parentId; at !== \"\"; at = findCollection(at).parentId) {\n\t\t\t\tif (at === id) {\n\t\t\t\t\tthrow new InvalidInputError(\n\t\t\t\t\t\t`Collection ${id} can't move under itself or a Collection under it`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\t// As over the wire: a move sends no name, so the refusal names none.\n\t\t\tif (siblingNamed(parentId, collection.name, id)) throw new NameTakenError(\"\");\n\t\t\tcollection.parentId = parentId;\n\t\t\treturn { ...collection };\n\t\t},\n\t\tasync removeCollection({ id }) {\n\t\t\tfindCollection(id);\n\t\t\tif (collections.some((c) => c.parentId === id)) {\n\t\t\t\tthrow new InvalidInputError(\n\t\t\t\t\t`Collection ${id} has Collections under it: remove or move those first`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcollections.splice(\n\t\t\t\tcollections.findIndex((c) => c.id === id),\n\t\t\t\t1,\n\t\t\t);\n\t\t\tgrants.delete(id);\n\t\t\tconst unfiled: string[] = [];\n\t\t\tfor (const c of contents) {\n\t\t\t\tif (c.collectionIds.includes(id)) {\n\t\t\t\t\tc.collectionIds = c.collectionIds.filter((each) => each !== id);\n\t\t\t\t\tunfiled.push(c.id);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn unfiled;\n\t\t},\n\t\tasync setCollectionRestricted({ id, restricted, acknowledgeDisclosure = false }) {\n\t\t\tif (restricted && authzMode === \"workspace\") {\n\t\t\t\tthrow new RestrictionUnavailableError(WORKSPACE_MODE_REFUSAL);\n\t\t\t}\n\t\t\tconst collection = findCollection(id);\n\t\t\tif (collection.restricted === restricted) return { ...collection };\n\t\t\tif (!restricted && !acknowledgeDisclosure) {\n\t\t\t\tthrow new InvalidInputError(\n\t\t\t\t\t`unrestricting Collection ${id} discloses its Content to every viewer: ` +\n\t\t\t\t\t\t\"confirm it with acknowledge_disclosure\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tcollection.restricted = restricted;\n\t\t\t// The one who restricts it owns it; opening it clears every grant.\n\t\t\tif (restricted) grants.set(id, [{ userId, level: \"owner\" }]);\n\t\t\telse grants.delete(id);\n\t\t\treturn { ...collection };\n\t\t},\n\t\tasync listCollectionGrants(collectionId) {\n\t\t\tmanageable(collectionId);\n\t\t\treturn structuredClone(grants.get(collectionId) ?? []).sort((a, b) =>\n\t\t\t\ta.userId < b.userId ? -1 : a.userId > b.userId ? 1 : 0,\n\t\t\t);\n\t\t},\n\t\tasync grantCollectionAccess({ collectionId, userId: grantee, level }) {\n\t\t\tmanageable(collectionId);\n\t\t\tif (level !== \"viewer\" && level !== \"editor\") {\n\t\t\t\tthrow new InvalidInputError(\"a grant is viewer or editor\");\n\t\t\t}\n\t\t\tif (!memberIds.includes(grantee)) {\n\t\t\t\tthrow new InvalidInputError(`${grantee} is not a member of the workspace`);\n\t\t\t}\n\t\t\tconst held = grants.get(collectionId) ?? [];\n\t\t\t// The owner stays owner: a grant never lowers what restricting gave.\n\t\t\tif (held.some((g) => g.level === \"owner\" && g.userId === grantee)) return;\n\t\t\tgrants.set(collectionId, [\n\t\t\t\t...held.filter((g) => g.userId !== grantee),\n\t\t\t\t{ userId: grantee, level },\n\t\t\t]);\n\t\t},\n\t\tasync revokeCollectionAccess({ collectionId, userId: grantee }) {\n\t\t\tmanageable(collectionId);\n\t\t\tgrants.set(\n\t\t\t\tcollectionId,\n\t\t\t\t(grants.get(collectionId) ?? []).filter((g) => g.userId !== grantee || g.level === \"owner\"),\n\t\t\t);\n\t\t},\n\t\tasync listContents(input = {}) {\n\t\t\tconst view: ContentView = input.view ?? { kind: \"main\" };\n\t\t\tconst search = (input.search ?? \"\").trim();\n\t\t\tif (search !== \"\" && view.kind === \"in_force\") {\n\t\t\t\tthrow new InvalidInputError(\n\t\t\t\t\t\"filter.search: Editor Search covers Main and open Branch heads, never Releases\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif ([...search].length > CONTENT_SEARCH_MAX) {\n\t\t\t\tthrow new InvalidInputError(`filter.search is at most ${CONTENT_SEARCH_MAX} characters`);\n\t\t\t}\n\t\t\tif (input.collectionId && !collections.some((c) => c.id === input.collectionId)) {\n\t\t\t\tthrow notFound(\"Collection\", input.collectionId);\n\t\t\t}\n\t\t\tif (view.kind === \"change_set\") find(view.changeSetId);\n\n\t\t\tconst rows = contents\n\t\t\t\t// Archived Content is put aside: every view leaves it out (ADR 0015).\n\t\t\t\t.filter((c) => !c.archiveTime)\n\t\t\t\t.filter((c) => !input.collectionId || c.collectionIds.includes(input.collectionId))\n\t\t\t\t.filter((c) => !input.blueprintIds?.length || input.blueprintIds.includes(c.blueprintId))\n\t\t\t\t.filter((c) => !input.assigneeId || (c.assigneeIds ?? []).includes(input.assigneeId))\n\t\t\t\t.sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0))\n\t\t\t\t.flatMap((c) => readsOf(c, view, search));\n\t\t\tconst size = Math.min(input.pageSize || 50, 200);\n\t\t\tconst start = input.pageToken ? Number(input.pageToken) : 0;\n\t\t\treturn {\n\t\t\t\tcontents: rows.slice(start, start + size),\n\t\t\t\tnextPageToken: start + size < rows.length ? String(start + size) : \"\",\n\t\t\t};\n\t\t},\n\t\tasync createContent({ changeSetId, blueprintReleaseId: asked, copyFrom }) {\n\t\t\tconst cs = open(changeSetId);\n\t\t\tlet data: Record<string, unknown> = {};\n\t\t\tlet blueprintReleaseId = asked;\n\t\t\tif (copyFrom) {\n\t\t\t\tconst sourceRevision =\n\t\t\t\t\t\"revisionId\" in copyFrom\n\t\t\t\t\t\t? copyFrom.revisionId\n\t\t\t\t\t\t: contents.find((c) => c.inForce?.releaseId === copyFrom.releaseId)?.inForce\n\t\t\t\t\t\t\t\t?.revisionId;\n\t\t\t\tconst source = contents.find((c) => sourceRevision && dataOf(c, sourceRevision));\n\t\t\t\tif (!source || !sourceRevision) {\n\t\t\t\t\tthrow notFound(\"copy source\", JSON.stringify(copyFrom));\n\t\t\t\t}\n\t\t\t\tdata = structuredClone(dataOf(source, sourceRevision) ?? {});\n\t\t\t\tblueprintReleaseId = asked || source.blueprintReleaseId;\n\t\t\t}\n\t\t\tconst release = releases.find((r) => r.id === blueprintReleaseId);\n\t\t\tif (!release) {\n\t\t\t\tthrow new ContentRefusedError(`Blueprint Release ${blueprintReleaseId} can't be loaded`, [\n\t\t\t\t\t{ source: \"contenthub\", code: \"release_not_found\", path: \"\" },\n\t\t\t\t]);\n\t\t\t}\n\t\t\tif (release.refusals?.length) {\n\t\t\t\tthrow new ContentRefusedError(\n\t\t\t\t\t`Blueprint Release ${blueprintReleaseId} can't be loaded`,\n\t\t\t\t\trelease.refusals.map((r) => ({ ...r })),\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst n = next++;\n\t\t\tconst id = `content_stub_${n}`;\n\t\t\tconst branchId = `br_stub_${n}`;\n\t\t\tconst revisionId = `rev_stub_${n}`;\n\t\t\tcontents.push({\n\t\t\t\tid,\n\t\t\t\tblueprintId: release.blueprintId,\n\t\t\t\tblueprintReleaseId,\n\t\t\t\tcollectionIds: [],\n\t\t\t\tbranches: {\n\t\t\t\t\t[changeSetId]: { branchId, revisionId, data, revisionCreateTime: now() },\n\t\t\t\t},\n\t\t\t});\n\t\t\tcs.chains.push({\n\t\t\t\tid: `chain_stub_${n}`,\n\t\t\t\tcontentId: id,\n\t\t\t\tborn: true,\n\t\t\t\tbranches: [{ id: branchId, position: 0, kind: \"editorial\", headRevisionId: revisionId }],\n\t\t\t});\n\t\t\treturn {\n\t\t\t\tid,\n\t\t\t\tblueprintId: release.blueprintId,\n\t\t\t\tblueprintReleaseId,\n\t\t\t\trevisionId,\n\t\t\t\tdata: structuredClone(data),\n\t\t\t\tchangeSetId,\n\t\t\t\tbranchId,\n\t\t\t\trevisionCreateTime: now(),\n\t\t\t\treleaseId: \"\",\n\t\t\t};\n\t\t},\n\n\t\tasync saveRevision({ idempotencyKey, ...request }) {\n\t\t\tif (!idempotencyKey) return saveOnce(request);\n\t\t\t// A repeat answers the first save and writes nothing; another\n\t\t\t// request under the same key is refused (CONTEXT.md, Idempotency Key).\n\t\t\tconst asked = JSON.stringify(request);\n\t\t\tconst kept = savedUnder.get(idempotencyKey);\n\t\t\tif (kept) {\n\t\t\t\tif (kept.asked !== asked) {\n\t\t\t\t\tthrow new InvalidInputError(`idempotency key ${idempotencyKey} names another save`);\n\t\t\t\t}\n\t\t\t\treturn structuredClone(kept.content);\n\t\t\t}\n\t\t\tconst content = await saveOnce(request);\n\t\t\tsavedUnder.set(idempotencyKey, { asked, content: structuredClone(content) });\n\t\t\treturn content;\n\t\t},\n\n\t\tasync getContent({ id, changeSetId, branchId }) {\n\t\t\tconst c = findContent(id);\n\t\t\tconst view: ContentView = changeSetId\n\t\t\t\t? { kind: \"change_set\", changeSetId }\n\t\t\t\t: { kind: \"main\" };\n\t\t\tif (branchId && !changeSetId) {\n\t\t\t\tthrow new InvalidInputError(\n\t\t\t\t\t\"branch_id names a Branch of a Change Set: give its change_set_id too\",\n\t\t\t\t);\n\t\t\t}\n\t\t\t// Born in an open Change Set, it exists only there, as the service says.\n\t\t\tlet [content] = readsOf(c, view, \"\");\n\t\t\tif (!content) throw notFound(\"Content\", id);\n\t\t\tif (branchId && branchId !== content.branchId) {\n\t\t\t\t// An earlier Branch of the Chain, at its own head.\n\t\t\t\tconst branch = changeSets\n\t\t\t\t\t.find((cs) => cs.id === changeSetId)\n\t\t\t\t\t?.chains.find((ch) => ch.contentId === id)\n\t\t\t\t\t?.branches.find((b) => b.id === branchId);\n\t\t\t\tif (!branch) throw notFound(\"Branch\", branchId);\n\t\t\t\tconst rev = revisionsOf(c).find((r) => r.id === branch.headRevisionId);\n\t\t\t\tconst data = rev?.data ?? (c.main?.revisionId === branch.headRevisionId ? c.main.data : {});\n\t\t\t\tcontent = {\n\t\t\t\t\t...content,\n\t\t\t\t\trevisionId: branch.headRevisionId,\n\t\t\t\t\tdata: structuredClone(data),\n\t\t\t\t\tbranchId,\n\t\t\t\t\trevisionCreateTime: rev?.createTime ?? content.revisionCreateTime,\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst release = resolved[c.blueprintReleaseId];\n\t\t\treturn {\n\t\t\t\tcontent,\n\t\t\t\tblueprintRelease: release ? structuredClone(release) : undefined,\n\t\t\t\tattributes: attributesOf(c),\n\t\t\t};\n\t\t},\n\t\tasync getTimeline(contentId) {\n\t\t\tconst c = findContent(contentId);\n\t\t\tconst isOpen = (csId: string) => changeSets.find((cs) => cs.id === csId)?.state === \"open\";\n\t\t\treturn structuredClone({\n\t\t\t\tentries: c.timeline ?? [],\n\t\t\t\tplannedReleases: (c.plannedReleases ?? []).filter((p) => isOpen(p.changeSetId)),\n\t\t\t});\n\t\t},\n\t\tasync listRevisions({ target, pageSize, pageToken }) {\n\t\t\tlet found: (Revision & { data?: unknown })[];\n\t\t\tif (\"contentId\" in target) {\n\t\t\t\tconst c = findContent(target.contentId);\n\t\t\t\t// versionkit lists by Item only once it is published (#65).\n\t\t\t\tif (!c.main) throw notFound(\"Content\", target.contentId);\n\t\t\t\tfound = revisionsOf(c);\n\t\t\t} else {\n\t\t\t\tconst owner = contents.find((c) =>\n\t\t\t\t\trevisionsOf(c).some((r) => r.branchId === target.branchId),\n\t\t\t\t);\n\t\t\t\tif (!owner) throw notFound(\"Branch\", target.branchId);\n\t\t\t\tfound = revisionsOf(owner).filter((r) => r.branchId === target.branchId);\n\t\t\t}\n\t\t\tconst size = Math.min(pageSize || 50, 200);\n\t\t\tconst start = pageToken ? Number(pageToken) : 0;\n\t\t\treturn {\n\t\t\t\trevisions: found.slice(start, start + size).map(({ data: _data, ...r }) => r),\n\t\t\t\tnextPageToken: start + size < found.length ? String(start + size) : \"\",\n\t\t\t};\n\t\t},\n\t\tasync compare({ revisionId, base }) {\n\t\t\tconst c = contents.find((each) => revisionsOf(each).some((r) => r.id === revisionId));\n\t\t\tif (!c) throw notFound(\"Revision\", revisionId);\n\t\t\tconst all = revisionsOf(c);\n\t\t\tconst after = all.find((r) => r.id === revisionId) as Revision;\n\t\t\tlet baseId: string;\n\t\t\tif (base.kind === \"revision\") baseId = base.revisionId;\n\t\t\telse if (base.kind === \"main_head\") {\n\t\t\t\tif (!c.main) {\n\t\t\t\t\tthrow new InvalidInputError(\"the Content is not published: it has no Main Branch\");\n\t\t\t\t}\n\t\t\t\tbaseId = c.main.revisionId;\n\t\t\t} else baseId = all.find((r) => r.branchId === base.branchId)?.parentId ?? \"\";\n\t\t\tconst before = all.find((r) => r.id === baseId);\n\t\t\tif (!before) throw notFound(\"Revision\", baseId);\n\t\t\tconst a = dataOf(c, after.id) ?? {};\n\t\t\tconst b = dataOf(c, before.id) ?? {};\n\t\t\tconst changes: FieldChange[] = [];\n\t\t\tfor (const key of [...new Set([...Object.keys(a), ...Object.keys(b)])]) {\n\t\t\t\tif (!(key in b)) changes.push({ path: `/${key}`, kind: \"added\", after: a[key] });\n\t\t\t\telse if (!(key in a)) changes.push({ path: `/${key}`, kind: \"removed\", before: b[key] });\n\t\t\t\telse if (JSON.stringify(a[key]) !== JSON.stringify(b[key])) {\n\t\t\t\t\tchanges.push({ path: `/${key}`, kind: \"changed\", before: b[key], after: a[key] });\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst strip = ({ data: _data, ...r }: Revision & { data?: unknown }) => r;\n\t\t\treturn { base: strip(before), revision: strip(after), changes };\n\t\t},\n\t\tasync listReferences({ contentId, revisionId }) {\n\t\t\tconst c = findContent(contentId);\n\t\t\treturn (c.edges ?? [])\n\t\t\t\t.filter((e) => e.sourceRevisionId === revisionId)\n\t\t\t\t.map((e) => ({ ...e }));\n\t\t},\n\t\tasync listReferrers({ contentId, includeOpenChangeSets, pageSize, pageToken }) {\n\t\t\tfindContent(contentId);\n\t\t\t// Paged as the service pages, by position in its order.\n\t\t\tconst page = (rows: Referrer[]): ReferrerList => {\n\t\t\t\tconst size = Math.min(pageSize || 100, 1000);\n\t\t\t\tconst start = pageToken ? Number(pageToken) : 0;\n\t\t\t\treturn {\n\t\t\t\t\treferrers: rows.slice(start, start + size),\n\t\t\t\t\tnextPageToken: start + size < rows.length ? String(start + size) : \"\",\n\t\t\t\t};\n\t\t\t};\n\t\t\tconst fromReleases = contents.flatMap((other) =>\n\t\t\t\t(other.edges ?? [])\n\t\t\t\t\t.filter(\n\t\t\t\t\t\t(e) =>\n\t\t\t\t\t\t\te.targetContentId === contentId && other.inForce?.revisionId === e.sourceRevisionId,\n\t\t\t\t\t)\n\t\t\t\t\t.map((e) => ({\n\t\t\t\t\t\tedge: { ...e },\n\t\t\t\t\t\treleaseId: other.inForce?.releaseId ?? \"\",\n\t\t\t\t\t\tchangeSetId: \"\",\n\t\t\t\t\t\tbranchId: \"\",\n\t\t\t\t\t})),\n\t\t\t);\n\t\t\tif (!includeOpenChangeSets) return page(fromReleases);\n\t\t\tconst fromBranches = contents.flatMap((other) =>\n\t\t\t\tObject.entries(other.branches).flatMap(([csId, head]) =>\n\t\t\t\t\tchangeSets.find((cs) => cs.id === csId)?.state !== \"open\"\n\t\t\t\t\t\t? []\n\t\t\t\t\t\t: (other.edges ?? [])\n\t\t\t\t\t\t\t\t.filter(\n\t\t\t\t\t\t\t\t\t(e) => e.targetContentId === contentId && e.sourceRevisionId === head.revisionId,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t.map((e) => ({\n\t\t\t\t\t\t\t\t\tedge: { ...e },\n\t\t\t\t\t\t\t\t\treleaseId: \"\",\n\t\t\t\t\t\t\t\t\tchangeSetId: csId,\n\t\t\t\t\t\t\t\t\tbranchId: head.branchId,\n\t\t\t\t\t\t\t\t})),\n\t\t\t\t),\n\t\t\t);\n\t\t\treturn page([...fromReleases, ...fromBranches]);\n\t\t},\n\t\tasync listOutdatedPins(input) {\n\t\t\tlet revisionId: string | undefined;\n\t\t\tif (\"revisionId\" in input) revisionId = input.revisionId;\n\t\t\telse {\n\t\t\t\tfor (const c of contents) {\n\t\t\t\t\tconst head = Object.values(c.branches).find((h) => h.branchId === input.branchId);\n\t\t\t\t\tif (head) revisionId = head.revisionId;\n\t\t\t\t}\n\t\t\t\tif (!revisionId) throw notFound(\"Branch\", input.branchId);\n\t\t\t}\n\t\t\tconst edges: Edge[] = contents.flatMap((c) =>\n\t\t\t\t(c.edges ?? []).filter((e) => e.sourceRevisionId === revisionId),\n\t\t\t);\n\t\t\treturn edges\n\t\t\t\t.filter((e) => e.pinReleaseId !== \"\")\n\t\t\t\t.flatMap((e) => {\n\t\t\t\t\tconst target = contents.find((c) => c.id === e.targetContentId);\n\t\t\t\t\tconst inForce = target?.inForce?.releaseId ?? \"\";\n\t\t\t\t\tif (inForce === e.pinReleaseId) return [];\n\t\t\t\t\treturn [{ edge: { ...e }, supersededByReleaseId: inForce, inForceReleaseId: inForce }];\n\t\t\t\t});\n\t\t},\n\n\t\tasync setContentCollections({ contentId, collectionIds }) {\n\t\t\tconst c = findContent(contentId);\n\t\t\tconst unique = [...new Set(collectionIds)];\n\t\t\tif (unique.length > 100) throw new InvalidInputError(\"at most 100 Collections\");\n\t\t\tfor (const id of unique) {\n\t\t\t\tif (!collections.some((col) => col.id === id)) throw notFound(\"Collection\", id);\n\t\t\t}\n\t\t\tc.collectionIds = unique.sort();\n\t\t\treturn [...c.collectionIds];\n\t\t},\n\t\tasync setContentAssignees({ contentId, assigneeIds }) {\n\t\t\tconst c = findContent(contentId);\n\t\t\tif (new Set(assigneeIds).size !== assigneeIds.length) {\n\t\t\t\tthrow new InvalidInputError(\"each assignee is given once\");\n\t\t\t}\n\t\t\tif (assigneeIds.length > 50) throw new InvalidInputError(\"at most 50 assignees\");\n\t\t\tc.assigneeIds = [...assigneeIds];\n\t\t\treturn attributesOf(c);\n\t\t},\n\t\tasync blockContent({ contentId, blockReasonId, allowedUserIds }) {\n\t\t\tconst c = findContent(contentId);\n\t\t\tif (!reasons.some((r) => r.id === blockReasonId)) {\n\t\t\t\tthrow notFound(\"Block Reason\", blockReasonId);\n\t\t\t}\n\t\t\tif (new Set(allowedUserIds).size !== allowedUserIds.length) {\n\t\t\t\tthrow new InvalidInputError(\"each allowed user is given once\");\n\t\t\t}\n\t\t\tc.block = {\n\t\t\t\tblockReasonId,\n\t\t\t\tallowedUserIds: [...allowedUserIds],\n\t\t\t\tblockedBy: userId,\n\t\t\t\tblockTime: now(),\n\t\t\t};\n\t\t\treturn attributesOf(c);\n\t\t},\n\t\tasync unblockContent(contentId) {\n\t\t\tconst c = findContent(contentId);\n\t\t\tc.block = undefined;\n\t\t\treturn attributesOf(c);\n\t\t},\n\t\tasync archiveContent(contentId) {\n\t\t\tconst c = findContent(contentId);\n\t\t\tif (c.archiveTime) return attributesOf(c);\n\t\t\tif (!c.main) {\n\t\t\t\tthrow new InvalidInputError(\n\t\t\t\t\t`Content ${contentId} is not published: discard its Change Set instead of archiving it`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (inForceOnOrAfter(c.timeline ?? [], today())) {\n\t\t\t\tthrow new InvalidInputError(\n\t\t\t\t\t`Content ${contentId} has a Release In Force today or later: end its force first`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tc.archiveTime = now();\n\t\t\treturn attributesOf(c);\n\t\t},\n\t\tasync unarchiveContent(contentId) {\n\t\t\tconst c = findContent(contentId);\n\t\t\tc.archiveTime = undefined;\n\t\t\treturn attributesOf(c);\n\t\t},\n\n\t\tasync startEditing({ contentId, changeSetId, effectiveOn = \"\", changeSetName = \"\" }) {\n\t\t\tconst c = findContent(contentId);\n\t\t\tif (!c.main) {\n\t\t\t\tthrow new InvalidInputError(`Content ${contentId} is not published`);\n\t\t\t}\n\t\t\tcheckEditable(c);\n\t\t\tif (datedContent(c) && !DAY.test(effectiveOn)) {\n\t\t\t\tthrow new InvalidInputError(\"effective_on is required for Dated Content, as YYYY-MM-DD\");\n\t\t\t}\n\t\t\tif (!datedContent(c) && effectiveOn !== \"\") {\n\t\t\t\tthrow new InvalidInputError(\"effective_on is refused for undated Content\");\n\t\t\t}\n\t\t\tlet cs: ChangeSet;\n\t\t\tif (changeSetId) {\n\t\t\t\tcs = open(changeSetId);\n\t\t\t\tif (cs.chains.some((chain) => chain.contentId === contentId)) {\n\t\t\t\t\tthrow new InvalidInputError(\n\t\t\t\t\t\t`Content ${contentId} already has a Chain in this Change Set`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst label = Object.values(c.main.data)\n\t\t\t\t\t.filter((v): v is string => typeof v === \"string\")\n\t\t\t\t\t.slice(0, 2)\n\t\t\t\t\t.join(\" \");\n\t\t\t\tcs = {\n\t\t\t\t\tid: `cs_stub_${next++}`,\n\t\t\t\t\tname: changeSetName.trim()\n\t\t\t\t\t\t? oneLine(changeSetName, \"change_set_name\", CHANGE_SET_NAME_MAX)\n\t\t\t\t\t\t: label || contentId,\n\t\t\t\t\tstate: \"open\",\n\t\t\t\t\tcreatedBy: userId,\n\t\t\t\t\tcreateTime: now(),\n\t\t\t\t\tchains: [],\n\t\t\t\t\tdependsOnChangeSetIds: [],\n\t\t\t\t\tstatus: \"\",\n\t\t\t\t\tassigneeIds: [],\n\t\t\t\t\tplannedReleases: [],\n\t\t\t\t};\n\t\t\t\tchangeSets.unshift(cs);\n\t\t\t}\n\t\t\tconst n = next++;\n\t\t\tconst branchId = `br_stub_${n}`;\n\t\t\t// A Branch started on an existing Revision writes none.\n\t\t\tconst head = { ...structuredClone(c.main), branchId };\n\t\t\tc.branches[cs.id] = head;\n\t\t\tcs.chains.push({\n\t\t\t\tid: `chain_stub_${n}`,\n\t\t\t\tcontentId,\n\t\t\t\tborn: false,\n\t\t\t\tbranches: [\n\t\t\t\t\t{ id: branchId, position: 0, kind: \"editorial\", headRevisionId: head.revisionId },\n\t\t\t\t],\n\t\t\t});\n\t\t\tconst [content] = readsOf(c, { kind: \"change_set\", changeSetId: cs.id }, \"\");\n\t\t\treturn { changeSet: copy(cs), content };\n\t\t},\n\t\tasync previewChain({ changeSetId, contentId, effectiveOn, validityPeriod }) {\n\t\t\topen(changeSetId);\n\t\t\tconst c = findContent(contentId);\n\t\t\tif (!c.main) throw new InvalidInputError(`Content ${contentId} is not published`);\n\t\t\tif (!datedContent(c)) throw new InvalidInputError(\"undated Content's Chain takes no date\");\n\t\t\tif (!DAY.test(effectiveOn)) throw new InvalidInputError(\"effective_on is YYYY-MM-DD\");\n\t\t\tconst entries = c.timeline ?? [];\n\t\t\tconst fork = entries.find(\n\t\t\t\t(e) =>\n\t\t\t\t\te.validityPeriod &&\n\t\t\t\t\te.validityPeriod.firstDay <= effectiveOn &&\n\t\t\t\t\t(e.validityPeriod.lastDay === \"\" || effectiveOn <= e.validityPeriod.lastDay),\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tforkReleaseId: fork?.releaseId ?? \"\",\n\t\t\t\tcarryForwardReleaseIds: entries\n\t\t\t\t\t.filter((e) => e.validityPeriod && e.validityPeriod.firstDay > effectiveOn)\n\t\t\t\t\t.map((e) => e.releaseId),\n\t\t\t\tmergesMain: false,\n\t\t\t\tcutIntoReleaseIds: fork ? [fork.releaseId] : [],\n\t\t\t\t// Only a period with a last day covers a Release: an open end\n\t\t\t\t// ends where the next Release starts.\n\t\t\t\tcoveredReleaseIds:\n\t\t\t\t\tvalidityPeriod && validityPeriod.lastDay !== \"\"\n\t\t\t\t\t\t? entries\n\t\t\t\t\t\t\t\t.filter(\n\t\t\t\t\t\t\t\t\t(e) =>\n\t\t\t\t\t\t\t\t\t\te.validityPeriod &&\n\t\t\t\t\t\t\t\t\t\te.validityPeriod.lastDay !== \"\" &&\n\t\t\t\t\t\t\t\t\t\tvalidityPeriod.firstDay <= e.validityPeriod.firstDay &&\n\t\t\t\t\t\t\t\t\t\te.validityPeriod.lastDay <= validityPeriod.lastDay,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t.map((e) => e.releaseId)\n\t\t\t\t\t\t: [],\n\t\t\t};\n\t\t},\n\t\tasync planRepeal({ changeSetId, contentId, lastDay }) {\n\t\t\topen(changeSetId);\n\t\t\tconst c = findContent(contentId);\n\t\t\tcheckEditable(c);\n\t\t\tif (!datedContent(c)) throw new InvalidInputError(\"a Repeal is for Dated Content\");\n\t\t\tif (!DAY.test(lastDay)) throw new InvalidInputError(\"last_day is YYYY-MM-DD\");\n\t\t\tconst inForce = releaseInForceOn(c.timeline ?? [], lastDay);\n\t\t\treturn plan(c, changeSetId, {\n\t\t\t\tkind: \"repeal\",\n\t\t\t\tvalidityPeriod: { firstDay: inForce?.validityPeriod?.firstDay ?? lastDay, lastDay },\n\t\t\t});\n\t\t},\n\t\tasync planWithdrawal({ changeSetId, contentId }) {\n\t\t\topen(changeSetId);\n\t\t\tconst c = findContent(contentId);\n\t\t\tcheckEditable(c);\n\t\t\tif (datedContent(c)) throw new InvalidInputError(\"a Withdrawal is for undated Content\");\n\t\t\treturn plan(c, changeSetId, { kind: \"withdrawal\" });\n\t\t},\n\n\t\tasync planRelease({ idempotencyKey, ...request }) {\n\t\t\treturn once(idempotencyKey, [\"planRelease\", request], async () => {\n\t\t\t\tconst { changeSetId, branchId, validityPeriod, releaseSpec, supersedesReleaseIds } =\n\t\t\t\t\trequest;\n\t\t\t\tconst { cs, chain, branch, c } = branchIn(changeSetId, branchId);\n\t\t\t\tcheckEditable(c);\n\t\t\t\tif (branch.kind !== \"editorial\") {\n\t\t\t\t\tthrow new InvalidInputError(\"only an editorial Branch's head is released\");\n\t\t\t\t}\n\t\t\t\tif (cs.plannedReleases.some((p) => p.branchId === branchId)) {\n\t\t\t\t\tthrow new InvalidInputError(`Branch ${branchId} is planned already`);\n\t\t\t\t}\n\t\t\t\tconst plan: PlannedRelease = {\n\t\t\t\t\tid: `rls_stub_${next++}`,\n\t\t\t\t\tcontentId: chain.contentId,\n\t\t\t\t\tkind: \"revision\",\n\t\t\t\t\tbranchId,\n\t\t\t\t\trevisionId: \"\",\n\t\t\t\t\tvalidityPeriod: validityPeriod ? { ...validityPeriod } : undefined,\n\t\t\t\t\treleaseSpec: structuredClone(releaseSpec ?? {}),\n\t\t\t\t\tsupersedesReleaseIds: [...(supersedesReleaseIds ?? [])],\n\t\t\t\t\tproposed: false,\n\t\t\t\t\tproposedForReleaseId: \"\",\n\t\t\t\t\tsplitFromReleaseId: \"\",\n\t\t\t\t\twithheld: false,\n\t\t\t\t};\n\t\t\t\tcheckPlan(c, plan);\n\t\t\t\tcs.plannedReleases.push(plan);\n\t\t\t\trepropose(cs, c);\n\t\t\t\treturn structuredClone(plan);\n\t\t\t});\n\t\t},\n\t\tasync updatePlannedRelease({ idempotencyKey, ...request }) {\n\t\t\treturn once(idempotencyKey, [\"updatePlannedRelease\", request], async () => {\n\t\t\t\tconst { changeSetId, plannedReleaseId, validityPeriod, releaseSpec, supersedesReleaseIds } =\n\t\t\t\t\trequest;\n\t\t\t\tconst cs = open(changeSetId);\n\t\t\t\tconst at = cs.plannedReleases.findIndex((p) => p.id === plannedReleaseId);\n\t\t\t\tif (at < 0) throw notFound(\"Planned Release\", plannedReleaseId);\n\t\t\t\tconst current = cs.plannedReleases[at];\n\t\t\t\tif (current.proposed) {\n\t\t\t\t\tthrow new InvalidInputError(\"a proposal is derived from the plans and can't be set\");\n\t\t\t\t}\n\t\t\t\tconst c = findContent(current.contentId);\n\t\t\t\tcheckEditable(c);\n\t\t\t\tconst updated: PlannedRelease = {\n\t\t\t\t\t...structuredClone(current),\n\t\t\t\t\t...(validityPeriod ? { validityPeriod: { ...validityPeriod } } : {}),\n\t\t\t\t\t...(releaseSpec ? { releaseSpec: structuredClone(releaseSpec) } : {}),\n\t\t\t\t\t...(supersedesReleaseIds ? { supersedesReleaseIds: [...supersedesReleaseIds] } : {}),\n\t\t\t\t};\n\t\t\t\tcheckPlan(c, updated);\n\t\t\t\tcs.plannedReleases[at] = updated;\n\t\t\t\trepropose(cs, c);\n\t\t\t\treturn structuredClone(updated);\n\t\t\t});\n\t\t},\n\t\tasync appendBranch({ idempotencyKey, ...request }) {\n\t\t\treturn once(idempotencyKey, [\"appendBranch\", request], async () => {\n\t\t\t\tconst { changeSetId, chainId, effectiveOn } = request;\n\t\t\t\tconst cs = open(changeSetId);\n\t\t\t\tconst chain = cs.chains.find((ch) => ch.id === chainId);\n\t\t\t\tif (!chain) throw notFound(\"Chain\", chainId);\n\t\t\t\tconst c = findContent(chain.contentId);\n\t\t\t\tif (chain.born || !datedContent(c)) {\n\t\t\t\t\tthrow new InvalidInputError(\"only a Chain on published Dated Content takes dates\");\n\t\t\t\t}\n\t\t\t\tconst last = chain.branches.filter((b) => b.kind === \"editorial\").at(-1);\n\t\t\t\tif (!DAY.test(effectiveOn) || (last?.effectiveOn && effectiveOn <= last.effectiveOn)) {\n\t\t\t\t\tthrow new InvalidInputError(\n\t\t\t\t\t\t\"effective_on is a day after the Chain's last editorial Branch's\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst tip = chain.branches.at(-1);\n\t\t\t\tconst n = next++;\n\t\t\t\tconst branchId = `br_stub_${n}`;\n\t\t\t\tchain.branches.push({\n\t\t\t\t\tid: branchId,\n\t\t\t\t\tposition: chain.branches.length,\n\t\t\t\t\tkind: \"editorial\",\n\t\t\t\t\t// A Branch starts at the head of the one before: no Revision written.\n\t\t\t\t\theadRevisionId: tip?.headRevisionId ?? \"\",\n\t\t\t\t\teffectiveOn,\n\t\t\t\t});\n\t\t\t\tconst head = c.branches[changeSetId];\n\t\t\t\tif (head) c.branches[changeSetId] = { ...head, branchId };\n\t\t\t\treturn { changeSet: copy(cs), branchId };\n\t\t\t});\n\t\t},\n\t\tasync dropChain({ idempotencyKey, ...request }) {\n\t\t\treturn once(idempotencyKey, [\"dropChain\", request], async () => {\n\t\t\t\tconst { changeSetId, chainId } = request;\n\t\t\t\tconst cs = open(changeSetId);\n\t\t\t\tconst chain = cs.chains.find((ch) => ch.id === chainId);\n\t\t\t\tif (!chain) throw notFound(\"Chain\", chainId);\n\t\t\t\tif (chain.born) {\n\t\t\t\t\tthrow new InvalidInputError(\n\t\t\t\t\t\t\"the Chain of Content born in the Change Set can't be dropped: discard the Change Set\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tfor (const b of chain.branches) dropMerge(b.id);\n\t\t\t\tcs.chains = cs.chains.filter((ch) => ch.id !== chainId);\n\t\t\t\tcs.plannedReleases = cs.plannedReleases.filter((p) => p.contentId !== chain.contentId);\n\t\t\t\tdelete findContent(chain.contentId).branches[changeSetId];\n\t\t\t\treturn copy(cs);\n\t\t\t});\n\t\t},\n\t\tasync getPendingMerge(branchId) {\n\t\t\tconst pm = stored.get(branchId);\n\t\t\treturn pm ? structuredClone(pm) : null;\n\t\t},\n\t\tasync resolveMerge({ idempotencyKey, ...request }) {\n\t\t\treturn once(idempotencyKey, [\"resolveMerge\", request], async () => {\n\t\t\t\tconst { changeSetId, branchId, expectedHeadId, resolutions } = request;\n\t\t\t\tconst { chain, branch, c } = branchIn(changeSetId, branchId);\n\t\t\t\tconst pm = stored.get(branchId);\n\t\t\t\tif (!pm) throw new InvalidInputError(`Branch ${branchId} has no Pending Merge`);\n\t\t\t\tif (branch.headRevisionId !== expectedHeadId) {\n\t\t\t\t\tthrow new StaleHeadError({\n\t\t\t\t\t\tcontentId: c.id,\n\t\t\t\t\t\tbranchId,\n\t\t\t\t\t\texpectedHeadId,\n\t\t\t\t\t\tcurrentHeadId: branch.headRevisionId,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tconst paths = resolutions.map((r) => r.path);\n\t\t\t\tconst listed = pm.fields.map((f) => f.path);\n\t\t\t\tif (\n\t\t\t\t\tnew Set(paths).size !== paths.length ||\n\t\t\t\t\tpaths.some((p) => !listed.includes(p)) ||\n\t\t\t\t\tlisted.some((p) => !paths.includes(p))\n\t\t\t\t) {\n\t\t\t\t\tthrow new InvalidInputError(\"decide every field the Pending Merge lists, once\");\n\t\t\t\t}\n\t\t\t\tconst data = structuredClone(pm.merged);\n\t\t\t\tfor (const r of resolutions) {\n\t\t\t\t\tconst f = pm.fields.find((each) => each.path === r.path) as MergeField;\n\t\t\t\t\tconst value = \"side\" in r ? (r.side === \"ours\" ? f.ours : f.theirs) : r.value;\n\t\t\t\t\tconst key = r.path.replace(/^\\//, \"\");\n\t\t\t\t\tif (value === undefined) delete data[key];\n\t\t\t\t\telse data[key] = structuredClone(value);\n\t\t\t\t}\n\t\t\t\tconst content = writeHead({\n\t\t\t\t\tchangeSetId,\n\t\t\t\t\tchain,\n\t\t\t\t\tbranch,\n\t\t\t\t\tc,\n\t\t\t\t\tdata,\n\t\t\t\t\tcause: \"resolve\",\n\t\t\t\t\tsecondParentId: pm.theirsRevisionId,\n\t\t\t\t});\n\t\t\t\tdropMerge(branchId);\n\t\t\t\treturn content;\n\t\t\t});\n\t\t},\n\t\tasync abortMerge({ idempotencyKey, ...request }) {\n\t\t\treturn once(idempotencyKey, [\"abortMerge\", request], async () => {\n\t\t\t\tbranchIn(request.changeSetId, request.branchId);\n\t\t\t\tif (!stored.has(request.branchId)) {\n\t\t\t\t\tthrow new InvalidInputError(`Branch ${request.branchId} has no Pending Merge`);\n\t\t\t\t}\n\t\t\t\tdropMerge(request.branchId);\n\t\t\t});\n\t\t},\n\t\tasync previewInForce({ contentId, changeSetId, validOn }) {\n\t\t\tconst cs = open(changeSetId);\n\t\t\tconst c = findContent(contentId);\n\t\t\tconst day = validOn || today();\n\t\t\tconst chain = cs.chains.find((ch) => ch.contentId === contentId);\n\t\t\tconst covers = (p: PlannedRelease) =>\n\t\t\t\t!p.validityPeriod ||\n\t\t\t\t(p.validityPeriod.firstDay <= day &&\n\t\t\t\t\t(p.validityPeriod.lastDay === \"\" || day <= p.validityPeriod.lastDay));\n\t\t\t// The Change Set's own plans first, read as if published now.\n\t\t\tconst plan = cs.plannedReleases.find(\n\t\t\t\t(p) => p.contentId === contentId && p.kind !== \"repeal\" && covers(p),\n\t\t\t);\n\t\t\tif (plan) {\n\t\t\t\tconst revisionId = plan.branchId\n\t\t\t\t\t? (chain?.branches.find((b) => b.id === plan.branchId)?.headRevisionId ?? \"\")\n\t\t\t\t\t: plan.revisionId;\n\t\t\t\treturn {\n\t\t\t\t\treleaseId: plan.id,\n\t\t\t\t\trevisionId,\n\t\t\t\t\tplanned: true,\n\t\t\t\t\twithheld: false,\n\t\t\t\t\tvalidityPeriod: plan.validityPeriod ? { ...plan.validityPeriod } : undefined,\n\t\t\t\t\tdata: structuredClone(dataOf(c, revisionId) ?? {}),\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst entry = releaseInForceOn(c.timeline ?? [], day);\n\t\t\tif (!entry) return null;\n\t\t\treturn {\n\t\t\t\treleaseId: entry.releaseId,\n\t\t\t\trevisionId: entry.revisionId,\n\t\t\t\tplanned: false,\n\t\t\t\twithheld: false,\n\t\t\t\tvalidityPeriod: entry.validityPeriod ? { ...entry.validityPeriod } : undefined,\n\t\t\t\tdata: structuredClone(dataOf(c, entry.revisionId) ?? {}),\n\t\t\t};\n\t\t},\n\t};\n\n\t/** Plans a Release ending a Content's force in a Change Set, warning of the gap it leaves. */\n\tfunction plan(\n\t\tc: StubContent,\n\t\tchangeSetId: string,\n\t\twhat: Pick<PlannedEnd[\"plannedRelease\"], \"kind\" | \"validityPeriod\">,\n\t): PlannedEnd {\n\t\tconst plannedRelease = {\n\t\t\tid: `rls_stub_${next++}`,\n\t\t\tcontentId: c.id,\n\t\t\tbranchId: \"\",\n\t\t\t// A Repeal or Withdrawal re-pins the Revision In Force.\n\t\t\trevisionId: c.inForce?.revisionId ?? c.main?.revisionId ?? \"\",\n\t\t\tsupersedesReleaseIds: [],\n\t\t\tproposed: false,\n\t\t\tproposedForReleaseId: \"\",\n\t\t\tsplitFromReleaseId: \"\",\n\t\t\twithheld: false,\n\t\t\t...what,\n\t\t};\n\t\tc.plannedReleases = [...(c.plannedReleases ?? []), { changeSetId, plannedRelease }];\n\t\treturn structuredClone({ plannedRelease, gapReferrers: gapReferrersOf(c.id) });\n\t}\n\n\t/**\n\t * Every row one Content gives in a view: its Main head on Main, its\n\t * Release on In Force, its head in a Change Set there. A search on Main\n\t * also reads every open Branch head, one row per head that matched, as\n\t * Editor Search does (ADR 0019).\n\t */\n\tfunction readsOf(c: StubContent, view: ContentView, search: string): Content[] {\n\t\tconst row = (\n\t\t\thead: { revisionId: string; data: Record<string, unknown>; revisionCreateTime: string },\n\t\t\tat: { changeSetId?: string; branchId?: string; releaseId?: string },\n\t\t): Content => ({\n\t\t\tid: c.id,\n\t\t\tblueprintId: c.blueprintId,\n\t\t\tblueprintReleaseId: c.blueprintReleaseId,\n\t\t\trevisionId: head.revisionId,\n\t\t\tdata: structuredClone(head.data),\n\t\t\tchangeSetId: at.changeSetId ?? \"\",\n\t\t\tbranchId: at.branchId ?? \"\",\n\t\t\trevisionCreateTime: head.revisionCreateTime,\n\t\t\treleaseId: at.releaseId ?? \"\",\n\t\t});\n\t\tif (view.kind === \"in_force\") {\n\t\t\treturn c.inForce ? [row(c.inForce, { releaseId: c.inForce.releaseId })] : [];\n\t\t}\n\t\tif (view.kind === \"change_set\") {\n\t\t\tconst head = c.branches[view.changeSetId];\n\t\t\tif (!head || (search && !matches(head.data, search))) return [];\n\t\t\treturn [row(head, { changeSetId: view.changeSetId, branchId: head.branchId })];\n\t\t}\n\t\tif (!search) return c.main ? [row(c.main, {})] : [];\n\t\tconst hits: Content[] = [];\n\t\tif (c.main && matches(c.main.data, search)) hits.push(row(c.main, {}));\n\t\tfor (const [csId, head] of Object.entries(c.branches).sort(([, a], [, b]) =>\n\t\t\ta.branchId < b.branchId ? -1 : 1,\n\t\t)) {\n\t\t\tconst inOpen = changeSets.find((cs) => cs.id === csId)?.state === \"open\";\n\t\t\tif (inOpen && matches(head.data, search)) {\n\t\t\t\thits.push(row(head, { changeSetId: csId, branchId: head.branchId }));\n\t\t\t}\n\t\t}\n\t\treturn hits;\n\t}\n}\n\n/** Editor Search's match: within one field, ignoring case, any run of whitespace for any run. */\nfunction matches(data: Record<string, unknown>, search: string): boolean {\n\tconst fold = (s: string) => s.toLocaleLowerCase().replace(/\\s+/g, \" \");\n\tconst needle = fold(search);\n\treturn Object.values(data).some((v) => typeof v === \"string\" && fold(v).includes(needle));\n}\n","// A `StatusSource` over a fixed catalogue: the port a host fills with\n// statushub (ADR 0020), stubbed so a host's tests need no statushub.\nimport type { ChangeSetStatusInfo, StatusSource } from \"../types\";\nimport { stubChangeSetStatuses } from \"./fixtures\";\n\nexport function createStubStatusSource(\n\tstatuses: ChangeSetStatusInfo[] = stubChangeSetStatuses(),\n): StatusSource {\n\treturn {\n\t\tasync listChangeSetStatuses() {\n\t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