@knkcs/importhub-ui 0.8.0 → 0.9.0

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","sources":["../src/testing/fixtures.ts","../src/testing/stub-client.ts"],"sourcesContent":["import { createHostMembers, type HostIdentity } from \"@knkcs/anker/host\";\nimport type {\n\tApiKey,\n\tEntitySetContent,\n\tImport,\n\tImportCounts,\n\tImportProfileContent,\n\tItemProblem,\n\tMappingContent,\n\tProcessor,\n} from \"../client/importhub-client\";\nimport type { ImporthubBlueprintField } from \"../common/host\";\n\n/** The stub viewer's id. */\nexport const STUB_USER_ID = \"user_stub_ada\";\n/** A second member of the stub workspace, who starts and cancels Imports too. */\nexport const STUB_OTHER_USER_ID = \"user_stub_grace\";\n/** The stub workspace's id. */\nexport const STUB_WORKSPACE_ID = \"ws_stub_main\";\n/** A second workspace, for tests that switch to it. */\nexport const STUB_OTHER_WORKSPACE_ID = \"ws_stub_other\";\n\n/**\n * A `HostIdentity` for anker's `TestHost` or `HostProvider`: Ada, in the stub\n * workspace unless another is named.\n */\nexport function stubIdentity(workspaceId: string = STUB_WORKSPACE_ID): HostIdentity {\n\treturn {\n\t\tuserId: STUB_USER_ID,\n\t\tworkspaceId,\n\t\tmembers: createHostMembers([\n\t\t\t{ userId: STUB_USER_ID, displayName: \"Ada Importer\", email: \"ada@example.com\" },\n\t\t\t{ userId: STUB_OTHER_USER_ID, displayName: \"Grace Hopper\", email: \"grace@example.com\" },\n\t\t]),\n\t};\n}\n\n/** A stub configuration as the stub client is seeded with it: an id and its content. */\nexport interface StubConfiguration<C> {\n\tid: string;\n\tcontent: C;\n\t/** The number of its latest Release; none when unset. */\n\treleaseNumber?: number;\n}\n\n/** A Blueprint Release the stub knows, with the field paths it has. */\nexport interface StubBlueprintRelease {\n\tid: string;\n\tblueprintId: string;\n\tblueprintName: string;\n\tlabel: string;\n\t/** Every field path, nested ones included (`stand.datum`). */\n\tfieldPaths: string[];\n\t/** Its field tree, for the Mapping editor; the paths as text fields when unset. */\n\tfields?: ImporthubBlueprintField[];\n\t/** Its Release Spec fields; none when unset. */\n\treleaseSpecFields?: ImporthubBlueprintField[];\n}\n\nconst field = (\n\tpath: string,\n\tfieldType: string,\n\tlabel: string,\n\tchildren: ImporthubBlueprintField[] = [],\n): ImporthubBlueprintField => ({\n\taccessor: path.split(\".\").pop() ?? path,\n\tpath,\n\tfieldType,\n\tlabel,\n\tchildren,\n});\n\n/** Every path of a field tree, parents before their children. */\nconst pathsOf = (tree: ImporthubBlueprintField[]): string[] =>\n\ttree.flatMap((f) => [f.path, ...pathsOf(f.children)]);\n\nconst gesetzFields = (withFootnote: boolean) => [\n\tfield(\"titel\", \"text\", \"Titel\"),\n\tfield(\"abkuerzung\", \"text\", \"Abkürzung\"),\n\tfield(\"anzeigename\", \"textarea\", \"Anzeigename\"),\n\t...(withFootnote ? [field(\"fussnote\", \"rich_text\", \"Fußnote\")] : []),\n\tfield(\"stand\", \"fieldset\", \"Stand\", [\n\t\tfield(\"stand.datum\", \"date\", \"Datum\"),\n\t\tfield(\"stand.art\", \"select\", \"Art\"),\n\t]),\n];\n\nconst gesetzReleaseSpec = () => [\n\tfield(\"fundstelle\", \"text\", \"Fundstelle\"),\n\tfield(\"ausgabedatum\", \"date\", \"Ausgabedatum\"),\n];\n\n/**\n * Two Releases of the \"Gesetz\" Blueprint, with a fieldset `stand` and two\n * Release Spec fields, the newer of which dropped `fussnote`, and one of\n * \"Entscheidung\".\n */\nexport function stubBlueprintReleases(): StubBlueprintRelease[] {\n\tconst gesetz2 = gesetzFields(false);\n\tconst gesetz1 = gesetzFields(true);\n\tconst entscheidung = [\n\t\tfield(\"aktenzeichen\", \"text\", \"Aktenzeichen\"),\n\t\tfield(\"datum\", \"date\", \"Datum\"),\n\t];\n\treturn [\n\t\t{\n\t\t\tid: \"br_stub_gesetz_2\",\n\t\t\tblueprintId: \"bp_stub_gesetz\",\n\t\t\tblueprintName: \"Gesetz\",\n\t\t\tlabel: \"Release 2\",\n\t\t\tfieldPaths: pathsOf(gesetz2),\n\t\t\tfields: gesetz2,\n\t\t\treleaseSpecFields: gesetzReleaseSpec(),\n\t\t},\n\t\t{\n\t\t\tid: \"br_stub_gesetz_1\",\n\t\t\tblueprintId: \"bp_stub_gesetz\",\n\t\t\tblueprintName: \"Gesetz\",\n\t\t\tlabel: \"Release 1\",\n\t\t\tfieldPaths: pathsOf(gesetz1),\n\t\t\tfields: gesetz1,\n\t\t\treleaseSpecFields: gesetzReleaseSpec(),\n\t\t},\n\t\t{\n\t\t\tid: \"br_stub_entscheidung_1\",\n\t\t\tblueprintId: \"bp_stub_entscheidung\",\n\t\t\tblueprintName: \"Entscheidung\",\n\t\t\tlabel: \"Release 1\",\n\t\t\tfieldPaths: pathsOf(entscheidung),\n\t\t\tfields: entscheidung,\n\t\t},\n\t];\n}\n\n/** The stub workspace's Mappings: one valid and released, one invalid. */\nexport function stubMappings(): StubConfiguration<MappingContent>[] {\n\treturn [\n\t\t{\n\t\t\tid: \"mp_stub_norm\",\n\t\t\treleaseNumber: 1,\n\t\t\tcontent: {\n\t\t\t\tname: \"Gesetz norms\",\n\t\t\t\tdescription: \"One Content per norm\",\n\t\t\t\tblueprintId: \"bp_stub_gesetz\",\n\t\t\t\tblueprintReleaseId: \"br_stub_gesetz_1\",\n\t\t\t\telementSelector: \"//norm\",\n\t\t\t\tsourceKey: { selector: \"@id\" },\n\t\t\t\tfields: [\n\t\t\t\t\t{ name: \"titel\", selector: \"titel\", type: \"text\" },\n\t\t\t\t\t{ name: \"fussnote\", selector: \"fn\", type: \"text\" },\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: \"mp_stub_decision\",\n\t\t\tcontent: {\n\t\t\t\tname: \"Court decisions\",\n\t\t\t\tdescription: \"\",\n\t\t\t\tblueprintId: \"bp_stub_entscheidung\",\n\t\t\t\tblueprintReleaseId: \"br_stub_entscheidung_1\",\n\t\t\t\telementSelector: \"\",\n\t\t\t\tsourceKey: {},\n\t\t\t\tfields: [],\n\t\t\t},\n\t\t},\n\t];\n}\n\n/** The stub workspace's Entity Sets: one. */\nexport function stubEntitySets(): StubConfiguration<EntitySetContent>[] {\n\treturn [\n\t\t{\n\t\t\tid: \"es_stub_latin1\",\n\t\t\treleaseNumber: 1,\n\t\t\tcontent: {\n\t\t\t\tname: \"ISO Latin 1\",\n\t\t\t\tdescription: \"The Latin-1 entities Boorberg's files use\",\n\t\t\t\tentities: { auml: \"ä\", nbsp: \" \" },\n\t\t\t},\n\t\t},\n\t];\n}\n\n/**\n * The stub workspace's Import Profiles: one per kind of Source File. The\n * VRPML one includes the invalid Mapping, so it is invalid too.\n */\nexport function stubImportProfiles(): StubConfiguration<ImportProfileContent>[] {\n\treturn [\n\t\t{\n\t\t\tid: \"ip_stub_gesetz\",\n\t\t\treleaseNumber: 2,\n\t\t\tcontent: {\n\t\t\t\tname: \"Boorberg gesetz\",\n\t\t\t\tdescription: \"Boorberg's law files\",\n\t\t\t\tentitySetId: \"es_stub_latin1\",\n\t\t\t\tpreprocessors: [{ processor: \"rename-element\", settings: { from: \"para\", to: \"absatz\" } }],\n\t\t\t\tmappingIds: [\"mp_stub_norm\"],\n\t\t\t\tpostProcessors: [],\n\t\t\t\tautoPublish: false,\n\t\t\t\tdeleteSourceFileOnSuccess: true,\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: \"ip_stub_vrpml\",\n\t\t\tcontent: {\n\t\t\t\tname: \"VRPML court decisions\",\n\t\t\t\tdescription: \"\",\n\t\t\t\tentitySetId: \"\",\n\t\t\t\tpreprocessors: [],\n\t\t\t\tmappingIds: [\"mp_stub_decision\"],\n\t\t\t\tpostProcessors: [],\n\t\t\t\tautoPublish: false,\n\t\t\t\tdeleteSourceFileOnSuccess: false,\n\t\t\t},\n\t\t},\n\t];\n}\n\nconst text = (accessor: string, name: string, required: boolean, instructions = \"\") => ({\n\tfield_type: \"text\",\n\tconfig: { name, api_accessor: accessor, required, instructions },\n\tsystem: false,\n});\n\n/** The catalogue, a few Processors of each kind and target. */\nexport function stubProcessors(): Processor[] {\n\treturn [\n\t\t{\n\t\t\tname: \"citation-links\",\n\t\t\tkind: \"post_processor\",\n\t\t\ttarget: \"source_file\",\n\t\t\tdescription:\n\t\t\t\t\"Links citations in rich text to the Content they name, through legalcitationhub.\",\n\t\t\tsettingsSpec: [],\n\t\t},\n\t\t{\n\t\t\tname: \"norm-cite\",\n\t\t\tkind: \"preprocessor\",\n\t\t\ttarget: \"rich_text_field\",\n\t\t\tdescription: \"Marks legal norm citations in one rich-text field.\",\n\t\t\tsettingsSpec: [],\n\t\t},\n\t\t{\n\t\t\tname: \"rename-element\",\n\t\t\tkind: \"preprocessor\",\n\t\t\ttarget: \"source_file\",\n\t\t\tdescription: \"Renames every element of one name to another.\",\n\t\t\tsettingsSpec: [\n\t\t\t\ttext(\"from\", \"Element\", true, \"The element's name now.\"),\n\t\t\t\ttext(\"to\", \"New name\", true),\n\t\t\t],\n\t\t},\n\t\t{\n\t\t\tname: \"sentence-detect\",\n\t\t\tkind: \"preprocessor\",\n\t\t\ttarget: \"source_file\",\n\t\t\tdescription: \"Wraps each sentence of an element in its own element.\",\n\t\t\tsettingsSpec: [text(\"element\", \"Element\", false)],\n\t\t},\n\t];\n}\n\n/** A stub Import as the stub client is seeded with it, with its Item Problems. */\nexport interface StubImport extends Import {\n\titemProblems?: ItemProblem[];\n}\n\nconst counts = (c: Partial<ImportCounts> = {}): ImportCounts => ({\n\tmatched: 0,\n\tcreated: 0,\n\tproblems: 0,\n\tplanned: 0,\n\tcorrected: 0,\n\tkept: 0,\n\tunchanged: 0,\n\t...c,\n});\n\n/** The Releases the fixtures' Imports of the gesetz Profile ran with. */\nconst gesetzReleases = (profileRelease: number): Import[\"releases\"] => ({\n\timportProfile: {\n\t\tconfigurationId: \"ip_stub_gesetz\",\n\t\tname: \"Boorberg gesetz\",\n\t\treleaseId: `ip_stub_gesetz_rel${profileRelease}`,\n\t\tnumber: profileRelease,\n\t},\n\tmappings: [\n\t\t{\n\t\t\tconfigurationId: \"mp_stub_norm\",\n\t\t\tname: \"Gesetz norms\",\n\t\t\treleaseId: \"mp_stub_norm_rel1\",\n\t\t\tnumber: 1,\n\t\t},\n\t],\n\tentitySet: {\n\t\tconfigurationId: \"es_stub_latin1\",\n\t\tname: \"ISO Latin 1\",\n\t\treleaseId: \"es_stub_latin1_rel1\",\n\t\tnumber: 1,\n\t},\n});\n\nconst stubImport = (i: Partial<StubImport> & Pick<Import, \"id\">): StubImport => ({\n\timportProfileId: \"ip_stub_gesetz\",\n\timportProfileName: \"Boorberg gesetz\",\n\tsourceFileId: `sf_${i.id}`,\n\tstartedBy: STUB_USER_ID,\n\tphase: \"ended\",\n\tfailureReason: \"\",\n\tprogress: { done: 0, total: 0 },\n\tcounts: counts(),\n\tchangeSetId: \"\",\n\treleases: gesetzReleases(2),\n\tcreateTime: \"2026-11-03T09:00:00.000Z\",\n\tstartTime: \"\",\n\tendTime: \"\",\n\tcancelledBy: \"\",\n\teffectiveDate: \"\",\n\t...i,\n});\n\nconst problem = (\n\tn: number,\n\tmapping: \"norm\" | \"title\",\n\tsourceKey: string,\n\tfield: string,\n\treason: string,\n): ItemProblem => ({\n\tid: `prob_stub_${n}`,\n\tmappingId: mapping === \"norm\" ? \"mp_stub_norm\" : \"mp_stub_title\",\n\tmappingName: mapping === \"norm\" ? \"Gesetz norms\" : \"Gesetz titles\",\n\tsourceKey,\n\tfield,\n\treason,\n});\n\n/**\n * The stub workspace's Imports, newest first: one running, one queued\n * behind it, and one of each Import Outcome.\n */\nexport function stubImports(): StubImport[] {\n\treturn [\n\t\tstubImport({\n\t\t\tid: \"im_stub_running\",\n\t\t\tphase: \"writing\",\n\t\t\tprogress: { done: 48, total: 120 },\n\t\t\tcounts: counts({ matched: 120, created: 40, planned: 8 }),\n\t\t\tchangeSetId: \"cs_stub_running\",\n\t\t\tcreateTime: \"2026-11-04T10:00:00.000Z\",\n\t\t\tstartTime: \"2026-11-04T10:00:05.000Z\",\n\t\t}),\n\t\tstubImport({\n\t\t\tid: \"im_stub_queued\",\n\t\t\tphase: \"queued\",\n\t\t\tstartedBy: STUB_OTHER_USER_ID,\n\t\t\treleases: gesetzReleases(2),\n\t\t\tcreateTime: \"2026-11-04T10:05:00.000Z\",\n\t\t}),\n\t\tstubImport({\n\t\t\tid: \"im_stub_problems\",\n\t\t\toutcome: \"succeeded_with_problems\",\n\t\t\tcounts: counts({\n\t\t\t\tmatched: 212,\n\t\t\t\tcreated: 180,\n\t\t\t\tplanned: 20,\n\t\t\t\tcorrected: 6,\n\t\t\t\tkept: 1,\n\t\t\t\tproblems: 5,\n\t\t\t}),\n\t\t\tchangeSetId: \"cs_stub_problems\",\n\t\t\treleases: {\n\t\t\t\t...gesetzReleases(2),\n\t\t\t\tmappings: [\n\t\t\t\t\t...gesetzReleases(2).mappings,\n\t\t\t\t\t{\n\t\t\t\t\t\tconfigurationId: \"mp_stub_title\",\n\t\t\t\t\t\tname: \"Gesetz titles\",\n\t\t\t\t\t\treleaseId: \"mp_stub_title_rel3\",\n\t\t\t\t\t\tnumber: 3,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t\tcreateTime: \"2026-11-03T09:00:00.000Z\",\n\t\t\tstartTime: \"2026-11-03T09:00:02.000Z\",\n\t\t\tendTime: \"2026-11-03T09:12:40.000Z\",\n\t\t\teffectiveDate: \"2026-10-01\",\n\t\t\tsource: { date: \"2026-09-20\", reference: \"BGBl. 2026 I Nr. 270\" },\n\t\t\titemProblems: [\n\t\t\t\tproblem(1, \"norm\", \"BJNR000010001\", \"stand/datum\", \"“31.02.2026” is not a date.\"),\n\t\t\t\tproblem(2, \"norm\", \"BJNR000010002\", \"\", \"The Version Match found two Releases.\"),\n\t\t\t\tproblem(3, \"title\", \"BJNR000020001\", \"\", \"No Title has the Ausgabe code BY-7.\"),\n\t\t\t\tproblem(4, \"norm\", \"BJNR000030001\", \"titel\", \"The field is required.\"),\n\t\t\t\tproblem(5, \"title\", \"BJNR000030002\", \"\", \"No Title has the Ausgabe code BY-9.\"),\n\t\t\t],\n\t\t}),\n\t\tstubImport({\n\t\t\tid: \"im_stub_succeeded\",\n\t\t\toutcome: \"succeeded\",\n\t\t\tcounts: counts({ matched: 64, created: 64 }),\n\t\t\tchangeSetId: \"cs_stub_succeeded\",\n\t\t\treleases: gesetzReleases(1),\n\t\t\tcreateTime: \"2026-11-02T14:00:00.000Z\",\n\t\t\tstartTime: \"2026-11-02T14:00:01.000Z\",\n\t\t\tendTime: \"2026-11-02T14:03:10.000Z\",\n\t\t}),\n\t\tstubImport({\n\t\t\tid: \"im_stub_failed\",\n\t\t\toutcome: \"failed\",\n\t\t\tfailureReason: \"The worker crashed three times running this Import.\",\n\t\t\tcounts: counts({ matched: 30 }),\n\t\t\treleases: gesetzReleases(1),\n\t\t\tcreateTime: \"2026-11-02T11:00:00.000Z\",\n\t\t\tstartTime: \"2026-11-02T11:00:01.000Z\",\n\t\t\tendTime: \"2026-11-02T11:20:00.000Z\",\n\t\t}),\n\t\tstubImport({\n\t\t\tid: \"im_stub_cancelled\",\n\t\t\toutcome: \"cancelled\",\n\t\t\tcancelledBy: STUB_OTHER_USER_ID,\n\t\t\tcounts: counts({ matched: 12, created: 3 }),\n\t\t\treleases: gesetzReleases(1),\n\t\t\tcreateTime: \"2026-11-01T16:00:00.000Z\",\n\t\t\tstartTime: \"2026-11-01T16:00:01.000Z\",\n\t\t\tendTime: \"2026-11-01T16:01:00.000Z\",\n\t\t}),\n\t];\n}\n\n/**\n * The stub workspace's API keys, newest first: Grace's nightly feed, which\n * never expires, and Ada's pipeline key, which does.\n */\nexport function stubApiKeys(): ApiKey[] {\n\treturn [\n\t\t{\n\t\t\tid: \"key_stub_nightly\",\n\t\t\tname: \"Nightly gesetz feed\",\n\t\t\tkeyPrefix: \"ihk_7Qx2\",\n\t\t\towner: STUB_OTHER_USER_ID,\n\t\t\texpireTime: \"\",\n\t\t\tcreateTime: \"2026-11-20T07:30:00.000Z\",\n\t\t},\n\t\t{\n\t\t\tid: \"key_stub_pipeline\",\n\t\t\tname: \"VRPML pipeline\",\n\t\t\tkeyPrefix: \"ihk_b91F\",\n\t\t\towner: STUB_USER_ID,\n\t\t\texpireTime: \"2027-06-30T21:59:59.000Z\",\n\t\t\tcreateTime: \"2026-11-03T12:00:00.000Z\",\n\t\t},\n\t];\n}\n","// An `ImporthubClient` over in-memory workspaces seeded from the fixtures.\n//\n// importhub takes the workspace from the caller's token, never from an\n// argument, so a real client answers for whichever workspace the host's\n// session is in. The stub does the same: it answers for its active\n// workspace, and a test switches it (`switchWorkspace`) where a host would\n// switch the token, which is how a host's test shows that switching reloads\n// the new workspace's data.\n//\n// It keeps importhub's rules a screen shows (internal/server's handlers):\n// validity reasons with their codes, a delete refused while Import Profiles\n// use the configuration, names unique per kind, a save on a draft that moved\n// refused, and the Blueprint Release check. Its messages are its own, not\n// importhub's.\n//\n// Typed as the whole interface, so a method added to `ImporthubClient`\n// without an answer here fails this package's typecheck, not a host's test.\nimport type {\n\tApiKey,\n\tConfigurationComparison,\n\tConfigurationKind,\n\tConfigurationReleaseRecord,\n\tConfigurationState,\n\tEntitySet,\n\tEntitySetContent,\n\tImport,\n\tImporthubClient,\n\tImportProfile,\n\tImportProfileContent,\n\tMapping,\n\tMappingContent,\n\tProcessor,\n\tProcessorStep,\n\tValidity,\n\tValidityReason,\n} from \"../client/importhub-client\";\nimport {\n\tAPI_KEY_NAME_MAX,\n\tConfigurationInUseError,\n\tNameTakenError,\n\tReleaseRefusedError,\n\tStartRefusedError,\n} from \"../client/importhub-client\";\nimport type { ImporthubBlueprintField, ImporthubBlueprints } from \"../common/host\";\nimport { plainTextFields } from \"../screens/mapping-editor/field-tree\";\nimport {\n\tSTUB_USER_ID,\n\tSTUB_WORKSPACE_ID,\n\ttype StubBlueprintRelease,\n\ttype StubConfiguration,\n\ttype StubImport,\n\tstubApiKeys,\n\tstubBlueprintReleases,\n\tstubEntitySets,\n\tstubImportProfiles,\n\tstubImports,\n\tstubMappings,\n\tstubProcessors,\n} from \"./fixtures\";\n\n/** What one stub workspace holds. */\nexport interface StubWorkspace {\n\timportProfiles?: StubConfiguration<ImportProfileContent>[];\n\tmappings?: StubConfiguration<MappingContent>[];\n\tentitySets?: StubConfiguration<EntitySetContent>[];\n\t/** Its Imports, newest first, each with its Item Problems. */\n\timports?: StubImport[];\n\t/** Its importhub API keys, newest first. */\n\tapiKeys?: ApiKey[];\n}\n\n/** A contenthub right the stub viewer holds, which Start checks. */\nexport type StubContenthubRight = \"editor\" | \"publisher\";\n\nexport interface StubImporthubClientOptions {\n\t/**\n\t * The workspaces by id. Without it, the stub workspace holds the\n\t * fixtures' Import Profiles, Mappings and Entity Sets.\n\t */\n\tworkspaces?: Record<string, StubWorkspace>;\n\t/** The workspace answered for first; the stub workspace by default. */\n\tactiveWorkspaceId?: string;\n\t/** The Processor catalogue; the fixtures' by default. */\n\tprocessors?: Processor[];\n\t/** The Blueprint Releases blueprinthub knows; the fixtures' by default. */\n\tblueprintReleases?: StubBlueprintRelease[];\n\t/**\n\t * The contenthub rights the viewer holds, which Start checks\n\t * (start-an-import:AC4); both by default.\n\t */\n\tcontenthubRights?: StubContenthubRight[];\n\t/** Fail every upload with this error, as an unreachable blob store would. */\n\tuploadFails?: Error;\n\t/** Fail every call with this error, as an unreachable importhub would. */\n\tfail?: Error;\n}\n\nexport interface StubImporthubClient extends ImporthubClient {\n\t/** Answer for another workspace from now on, as a host's new token would. */\n\tswitchWorkspace(workspaceId: string): void;\n\t/**\n\t * Moves an Import on as importhub's worker would: a phase, progress,\n\t * counts, an Outcome. For tests that follow an Import while it runs.\n\t */\n\tupdateImport(id: string, patch: Partial<StubImport>): void;\n\t/** How many calls each method has answered, for tests that count reloads. */\n\treadonly calls: Readonly<Record<keyof ImporthubClient, number>>;\n}\n\n/** One saved Revision of a stored configuration. */\ninterface StoredRevision<C> {\n\tid: string;\n\tcontent: C;\n\tsavedBy: string;\n\tsavedAt: string;\n\t/** As decided at the save; a fixture's is decided when it is read. */\n\tvalidity?: Validity;\n\trestoredFromRevisionId: string;\n}\n\n/**\n * One stored configuration: every Revision, newest last (the draft), and\n * every Release, oldest first, as versionkit's linear mode keeps them.\n */\ninterface Stored<C> {\n\tid: string;\n\t/** The draft's content, which the screens' reads answer with. */\n\tcontent: C;\n\trevisions: StoredRevision<C>[];\n\treleases: ConfigurationReleaseRecord[];\n}\n\ninterface Workspace {\n\timportProfiles: Stored<ImportProfileContent>[];\n\tmappings: Stored<MappingContent>[];\n\tentitySets: Stored<EntitySetContent>[];\n\timports: StubImport[];\n\tapiKeys: ApiKey[];\n}\n\nconst METHODS: (keyof ImporthubClient)[] = [\n\t\"listImportProfiles\",\n\t\"getImportProfile\",\n\t\"createImportProfile\",\n\t\"updateImportProfile\",\n\t\"deleteImportProfile\",\n\t\"listProcessors\",\n\t\"listMappings\",\n\t\"getMapping\",\n\t\"createMapping\",\n\t\"updateMapping\",\n\t\"deleteMapping\",\n\t\"listMappingImportProfiles\",\n\t\"checkMappingBlueprintRelease\",\n\t\"listEntitySets\",\n\t\"getEntitySet\",\n\t\"createEntitySet\",\n\t\"updateEntitySet\",\n\t\"deleteEntitySet\",\n\t\"cutRelease\",\n\t\"listHistory\",\n\t\"compareRevisions\",\n\t\"restoreRevision\",\n\t\"uploadSourceFile\",\n\t\"startImport\",\n\t\"listImports\",\n\t\"getImport\",\n\t\"cancelImport\",\n\t\"listItemProblems\",\n\t\"listApiKeys\",\n\t\"createApiKey\",\n\t\"revokeApiKey\",\n];\n\n// A stub clock: each save and cut is an hour after the last, from the\n// fixtures' first save, so a history reads in order and tests stay stable.\nlet clock = Date.parse(\"2026-11-02T08:00:00Z\");\nconst tick = () => {\n\tclock += 3_600_000;\n\treturn new Date(clock).toISOString();\n};\n\n/**\n * A fixture as stored: released `releaseNumber` times, each Release cut\n * from a Revision of its own, the last of which is the draft; or one\n * unreleased Revision.\n */\nconst seed = <C>(items: StubConfiguration<C>[] = []): Stored<C>[] =>\n\titems.map((i) => {\n\t\tconst count = Math.max(i.releaseNumber ?? 0, 1);\n\t\tconst revisions = Array.from({ length: count }, (_, n) => ({\n\t\t\tid: `${i.id}_r${n + 1}`,\n\t\t\tcontent: structuredClone(i.content),\n\t\t\tsavedBy: STUB_USER_ID,\n\t\t\tsavedAt: tick(),\n\t\t\trestoredFromRevisionId: \"\",\n\t\t}));\n\t\tconst releases = Array.from({ length: i.releaseNumber ?? 0 }, (_, n) => ({\n\t\t\tid: `${i.id}_rel${n + 1}`,\n\t\t\tnumber: n + 1,\n\t\t\trevisionId: `${i.id}_r${n + 1}`,\n\t\t\treleasedBy: STUB_USER_ID,\n\t\t\treleasedAt: tick(),\n\t\t}));\n\t\treturn { id: i.id, content: structuredClone(i.content), revisions, releases };\n\t});\n\nconst draftOf = <C>(s: Stored<C>) => s.revisions[s.revisions.length - 1] as StoredRevision<C>;\nconst latestReleaseOf = <C>(s: Stored<C>) => s.releases[s.releases.length - 1];\n\nconst stateOf = <C>(s: Stored<C>): ConfigurationState => {\n\tconst latest = latestReleaseOf(s);\n\tconst released = s.revisions.find((r) => r.id === latest?.revisionId);\n\treturn {\n\t\tdraftRevisionId: draftOf(s).id,\n\t\t// By content, as importhub compares: a draft that restored the\n\t\t// released content does not differ.\n\t\tdraftDiffersFromRelease:\n\t\t\t!released || JSON.stringify(released.content) !== JSON.stringify(draftOf(s).content),\n\t\t...(latest ? { latestRelease: { id: latest.id, number: latest.number } } : {}),\n\t};\n};\n\n/** A content's top-level keys as importhub's comparison names them. */\nconst snake = (key: string) => key.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`);\nconst protoKeyed = (content: unknown): Record<string, unknown> =>\n\tObject.fromEntries(\n\t\tObject.entries(content as Record<string, unknown>).map(([k, v]) => [snake(k), v]),\n\t);\n\nconst validity = (reasons: ValidityReason[]): Validity => ({\n\tvalid: reasons.length === 0,\n\treasons,\n});\n\nconst byName = <T extends { content: { name: string } }>(items: T[]) =>\n\t[...items].sort((a, b) => a.content.name.localeCompare(b.content.name));\n\nlet created = 0;\n\nexport function createStubImporthubClient(\n\toptions: StubImporthubClientOptions = {},\n): StubImporthubClient {\n\tconst workspaces: Record<string, Workspace> = Object.fromEntries(\n\t\tObject.entries(\n\t\t\toptions.workspaces ?? {\n\t\t\t\t[STUB_WORKSPACE_ID]: {\n\t\t\t\t\timportProfiles: stubImportProfiles(),\n\t\t\t\t\tmappings: stubMappings(),\n\t\t\t\t\tentitySets: stubEntitySets(),\n\t\t\t\t\timports: stubImports(),\n\t\t\t\t\tapiKeys: stubApiKeys(),\n\t\t\t\t},\n\t\t\t},\n\t\t).map(([id, w]) => [\n\t\t\tid,\n\t\t\t{\n\t\t\t\timportProfiles: seed(w.importProfiles),\n\t\t\t\tmappings: seed(w.mappings),\n\t\t\t\tentitySets: seed(w.entitySets),\n\t\t\t\timports: structuredClone(w.imports ?? []),\n\t\t\t\tapiKeys: structuredClone(w.apiKeys ?? []),\n\t\t\t},\n\t\t]),\n\t);\n\tconst processors = options.processors ?? stubProcessors();\n\tconst releases = options.blueprintReleases ?? stubBlueprintReleases();\n\tlet active = options.activeWorkspaceId ?? STUB_WORKSPACE_ID;\n\tconst calls = Object.fromEntries(METHODS.map((m) => [m, 0])) as Record<\n\t\tkeyof ImporthubClient,\n\t\tnumber\n\t>;\n\tconst ws = (): Workspace => {\n\t\tworkspaces[active] ??= {\n\t\t\timportProfiles: [],\n\t\t\tmappings: [],\n\t\t\tentitySets: [],\n\t\t\timports: [],\n\t\t\tapiKeys: [],\n\t\t};\n\t\treturn workspaces[active];\n\t};\n\tconst answer = async <T>(method: keyof ImporthubClient, run: () => T): Promise<T> => {\n\t\tcalls[method]++;\n\t\tif (options.fail) throw options.fail;\n\t\treturn structuredClone(run());\n\t};\n\tconst find = <C>(items: Stored<C>[], id: string, kind: string): Stored<C> => {\n\t\tconst item = items.find((i) => i.id === id);\n\t\tif (!item) throw new Error(`${kind} ${id} not found`);\n\t\treturn item;\n\t};\n\tconst nameFree = <C extends { name: string }>(items: Stored<C>[], name: string, id?: string) => {\n\t\tif (!name.trim()) throw new Error(\"a name is required\");\n\t\tif (items.some((i) => i.id !== id && i.content.name === name)) throw new NameTakenError();\n\t};\n\tconst moved = <C>(item: Stored<C>, draftRevisionId: string) =>\n\t\tdraftRevisionId !== \"\" && draftRevisionId !== draftOf(item).id;\n\t/** Saves content as the item's new draft Revision. */\n\tconst save = <C>(\n\t\titem: Stored<C>,\n\t\tcontent: C,\n\t\tdraftRevisionId: string,\n\t\trestoredFromRevisionId = \"\",\n\t) => {\n\t\tif (moved(item, draftRevisionId)) {\n\t\t\tthrow new Error(\"the draft moved: somebody saved in between\");\n\t\t}\n\t\titem.content = structuredClone(content);\n\t\titem.revisions.push({\n\t\t\tid: `${item.id}_r${item.revisions.length + 1}`,\n\t\t\tcontent: structuredClone(content),\n\t\t\tsavedBy: STUB_USER_ID,\n\t\t\tsavedAt: tick(),\n\t\t\trestoredFromRevisionId,\n\t\t});\n\t};\n\t/** A new configuration, its content the first draft. */\n\tconst stored = <C>(prefix: string, content: C): Stored<C> => {\n\t\tconst id = newId(prefix);\n\t\treturn {\n\t\t\tid,\n\t\t\tcontent: structuredClone(content),\n\t\t\trevisions: [\n\t\t\t\t{\n\t\t\t\t\tid: `${id}_r1`,\n\t\t\t\t\tcontent: structuredClone(content),\n\t\t\t\t\tsavedBy: STUB_USER_ID,\n\t\t\t\t\tsavedAt: tick(),\n\t\t\t\t\trestoredFromRevisionId: \"\",\n\t\t\t\t},\n\t\t\t],\n\t\t\treleases: [],\n\t\t};\n\t};\n\n\tfunction mappingReasons(c: MappingContent): ValidityReason[] {\n\t\tconst out: ValidityReason[] = [];\n\t\tconst release = releases.find((r) => r.id === c.blueprintReleaseId);\n\t\tif (!c.blueprintReleaseId) {\n\t\t\tout.push({\n\t\t\t\tpath: \"/blueprintReleaseId\",\n\t\t\t\tcode: \"no_blueprint_release\",\n\t\t\t\tmessage: \"It pins no Blueprint Release.\",\n\t\t\t});\n\t\t} else if (!release) {\n\t\t\tout.push({\n\t\t\t\tpath: \"/blueprintReleaseId\",\n\t\t\t\tcode: \"blueprint_gone\",\n\t\t\t\tmessage: \"blueprinthub does not know the Blueprint Release it pins.\",\n\t\t\t});\n\t\t} else if (release.blueprintId !== c.blueprintId) {\n\t\t\tout.push({\n\t\t\t\tpath: \"/blueprintReleaseId\",\n\t\t\t\tcode: \"release_of_other_blueprint\",\n\t\t\t\tmessage: \"The pinned Release is of another Blueprint.\",\n\t\t\t});\n\t\t}\n\t\tif (!c.elementSelector) {\n\t\t\tout.push({\n\t\t\t\tpath: \"/elementSelector\",\n\t\t\t\tcode: \"no_element_selector\",\n\t\t\t\tmessage: \"It has no element selector.\",\n\t\t\t});\n\t\t}\n\t\tif (!c.sourceKey?.selector && !c.sourceKey?.template) {\n\t\t\tout.push({ path: \"/sourceKey\", code: \"no_source_key\", message: \"It has no Source Key.\" });\n\t\t}\n\t\tconst xpath = (path: string, expr: unknown) => {\n\t\t\tif (typeof expr === \"string\" && expr !== \"\" && !balanced(expr)) {\n\t\t\t\tout.push({ path, code: \"invalid_xpath\", message: `\"${expr}\" is not an XPath.` });\n\t\t\t}\n\t\t};\n\t\txpath(\"/element_selector\", c.elementSelector);\n\t\txpath(\"/source_key/selector\", c.sourceKey?.selector);\n\t\tconst mapped: string[] = [];\n\t\t(c.fields ?? []).forEach((f, i) => {\n\t\t\tconst at = `/fields/${i}`;\n\t\t\tfor (const { path, rel, mapping } of walk(f, \"\", at)) {\n\t\t\t\tmapped.push(path);\n\t\t\t\txpath(`${rel}/selector`, mapping.selector);\n\t\t\t\tif (release && !release.fieldPaths.includes(path)) {\n\t\t\t\t\tout.push({\n\t\t\t\t\t\tpath: at,\n\t\t\t\t\t\tcode: \"unknown_field_path\",\n\t\t\t\t\t\tmessage: `The pinned Release has no field ${path}.`,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tif (mapping.type === \"select\" && !mapping.selectOptions) {\n\t\t\t\t\tout.push({\n\t\t\t\t\t\tpath: at,\n\t\t\t\t\t\tcode: \"xmlmapper_schema\",\n\t\t\t\t\t\tmessage: `The select field ${path} has no select options.`,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\t(c.versionMatch?.contentFields ?? []).forEach((f, i) => {\n\t\t\tif (!mapped.includes(f)) {\n\t\t\t\tout.push({\n\t\t\t\t\tpath: `/version_match/content_fields/${i}`,\n\t\t\t\t\tcode: \"unknown_version_match_field\",\n\t\t\t\t\tmessage: `The Version Match compares ${f}, which the Mapping does not map.`,\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t\t(c.titleContributions ?? []).forEach((tc, i) => {\n\t\t\tif (!tc.selector || !tc.ausgabeCodeSelector) {\n\t\t\t\tout.push({\n\t\t\t\t\tpath: `/title_contributions/${i}`,\n\t\t\t\t\tcode: \"incomplete_title_contribution\",\n\t\t\t\t\tmessage: \"A Title Contribution needs a selector and an Ausgabe code selector.\",\n\t\t\t\t});\n\t\t\t}\n\t\t\txpath(`/title_contributions/${i}/selector`, tc.selector);\n\t\t});\n\t\t(c.placeholderAssets ?? []).forEach((pa, i) => {\n\t\t\tif (!pa.selector || !pa.assetType || !pa.keyParts?.length || !pa.nameSelector) {\n\t\t\t\tout.push({\n\t\t\t\t\tpath: `/placeholder_assets/${i}`,\n\t\t\t\t\tcode: \"incomplete_placeholder_assets\",\n\t\t\t\t\tmessage:\n\t\t\t\t\t\t\"Placeholder Assets need a selector, an asset type, the key's parts and a name selector.\",\n\t\t\t\t});\n\t\t\t}\n\t\t\txpath(`/placeholder_assets/${i}/selector`, pa.selector);\n\t\t\t(pa.keyParts ?? []).forEach((k, j) => {\n\t\t\t\txpath(`/placeholder_assets/${i}/key_parts/${j}`, k);\n\t\t\t});\n\t\t});\n\t\tout.push(...displayNameReasons(c, release?.fields, mapped));\n\t\treturn out;\n\t}\n\n\tfunction stepReasons(\n\t\tsteps: ProcessorStep[],\n\t\tlist: string,\n\t\tkind: Processor[\"kind\"],\n\t): ValidityReason[] {\n\t\treturn steps.flatMap((s, i): ValidityReason[] => {\n\t\t\tconst path = `/${list}/${i}`;\n\t\t\tconst p = processors.find((x) => x.name === s.processor);\n\t\t\tif (!p)\n\t\t\t\treturn [\n\t\t\t\t\t{ path, code: \"unknown_processor\", message: `No Processor is called ${s.processor}.` },\n\t\t\t\t];\n\t\t\tif (p.target !== \"source_file\") {\n\t\t\t\treturn [\n\t\t\t\t\t{\n\t\t\t\t\t\tpath,\n\t\t\t\t\t\tcode: \"rich_text_processor\",\n\t\t\t\t\t\tmessage: `${p.name} is configured on a rich-text field, not on a Profile.`,\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t}\n\t\t\tif (p.kind !== kind)\n\t\t\t\treturn [{ path, code: \"wrong_processor_kind\", message: `${p.name} does not run here.` }];\n\t\t\tconst missing = p.settingsSpec.filter(\n\t\t\t\t(f) => f.config.required && (s.settings[f.config.api_accessor] ?? \"\") === \"\",\n\t\t\t);\n\t\t\treturn missing.map((f) => ({\n\t\t\t\tpath: `${path}/settings/${f.config.api_accessor}`,\n\t\t\t\tcode: \"invalid_processor_settings\",\n\t\t\t\tmessage: `${p.name}: ${f.config.api_accessor} is required.`,\n\t\t\t}));\n\t\t});\n\t}\n\n\tfunction profileReasons(c: ImportProfileContent): ValidityReason[] {\n\t\tconst w = ws();\n\t\tconst out = [\n\t\t\t...stepReasons(c.preprocessors, \"preprocessors\", \"preprocessor\"),\n\t\t\t...stepReasons(c.postProcessors, \"postProcessors\", \"post_processor\"),\n\t\t];\n\t\tif (c.mappingIds.length === 0) {\n\t\t\tout.push({ path: \"/mappingIds\", code: \"no_mappings\", message: \"It includes no Mapping.\" });\n\t\t}\n\t\tc.mappingIds.forEach((id, i) => {\n\t\t\tconst m = w.mappings.find((x) => x.id === id);\n\t\t\tif (!m) {\n\t\t\t\tout.push({\n\t\t\t\t\tpath: `/mappingIds/${i}`,\n\t\t\t\t\tcode: \"mapping_missing\",\n\t\t\t\t\tmessage: \"It includes a Mapping that does not exist.\",\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst reasons = mappingReasons(m.content);\n\t\t\tif (reasons.length > 0) {\n\t\t\t\tout.push({\n\t\t\t\t\tpath: `/mappingIds/${i}`,\n\t\t\t\t\tcode: \"mapping_invalid\",\n\t\t\t\t\tmessage: `The Mapping ${m.content.name} is invalid: ${reasons.map((r) => r.message).join(\" \")}`,\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t\tif (c.entitySetId && !w.entitySets.some((e) => e.id === c.entitySetId)) {\n\t\t\tout.push({\n\t\t\t\tpath: \"/entitySetId\",\n\t\t\t\tcode: \"entity_set_missing\",\n\t\t\t\tmessage: \"It names an Entity Set that does not exist.\",\n\t\t\t});\n\t\t}\n\t\treturn out;\n\t}\n\n\tconst entitySetReasons = (c: EntitySetContent): ValidityReason[] =>\n\t\tObject.keys(c.entities).length === 0\n\t\t\t? [{ path: \"/entities\", code: \"no_entities\", message: \"It defines no entity.\" }]\n\t\t\t: [];\n\n\tconst profileOf = (s: Stored<ImportProfileContent>): ImportProfile => ({\n\t\tid: s.id,\n\t\tcontent: s.content,\n\t\tvalidity: validity(profileReasons(s.content)),\n\t\tstate: stateOf(s),\n\t});\n\tconst mappingOf = (s: Stored<MappingContent>): Mapping => ({\n\t\tid: s.id,\n\t\tcontent: s.content,\n\t\tvalidity: validity(mappingReasons(s.content)),\n\t\tstate: stateOf(s),\n\t});\n\tconst entitySetOf = (s: Stored<EntitySetContent>): EntitySet => ({\n\t\tid: s.id,\n\t\tcontent: s.content,\n\t\tvalidity: validity(entitySetReasons(s.content)),\n\t\tstate: stateOf(s),\n\t});\n\tconst profilesUsing = (uses: (c: ImportProfileContent) => boolean) =>\n\t\tbyName(ws().importProfiles.filter((p) => uses(p.content))).map((p) => ({\n\t\t\tid: p.id,\n\t\t\tname: p.content.name,\n\t\t}));\n\tconst newId = (prefix: string) => `${prefix}_stub_new_${++created}`;\n\n\t// Each kind's items and rules, for the calls every kind shares.\n\tconst ofKind = (kind: ConfigurationKind) => {\n\t\tconst w = ws();\n\t\tswitch (kind) {\n\t\t\tcase \"importProfile\":\n\t\t\t\treturn {\n\t\t\t\t\titems: w.importProfiles as Stored<unknown>[],\n\t\t\t\t\tname: \"Import Profile\",\n\t\t\t\t\treasons: (c: unknown) => profileReasons(c as ImportProfileContent),\n\t\t\t\t};\n\t\t\tcase \"mapping\":\n\t\t\t\treturn {\n\t\t\t\t\titems: w.mappings as Stored<unknown>[],\n\t\t\t\t\tname: \"Mapping\",\n\t\t\t\t\treasons: (c: unknown) => mappingReasons(c as MappingContent),\n\t\t\t\t};\n\t\t\tcase \"entitySet\":\n\t\t\t\treturn {\n\t\t\t\t\titems: w.entitySets as Stored<unknown>[],\n\t\t\t\t\tname: \"Entity Set\",\n\t\t\t\t\treasons: (c: unknown) => entitySetReasons(c as EntitySetContent),\n\t\t\t\t};\n\t\t}\n\t};\n\t/** The draft's validity, decided as a save decides it. */\n\tconst decide = (kind: ConfigurationKind, item: Stored<unknown>) => {\n\t\tdraftOf(item).validity = validity(ofKind(kind).reasons(item.content));\n\t};\n\tconst revisionIn = (item: Stored<unknown>, revisionId: string) => {\n\t\tconst r = item.revisions.find((x) => x.id === revisionId);\n\t\tif (!r) throw new Error(`Revision ${revisionId} not found`);\n\t\treturn r;\n\t};\n\n\t// The Source Files uploaded, by id: Start reads only those.\n\tconst sourceFiles = new Set<string>();\n\tconst rights = options.contenthubRights ?? [\"editor\", \"publisher\"];\n\tconst findImport = (id: string): StubImport => {\n\t\tconst im = ws().imports.find((i) => i.id === id);\n\t\tif (!im) throw new Error(`Import ${id} not found`);\n\t\treturn im;\n\t};\n\t/**\n\t * What the worker does to an Import somebody asked to cancel: it stops at\n\t * its next item, which in the stub is the next read.\n\t */\n\tconst settle = (im: StubImport) => {\n\t\tif (im.cancelledBy && im.phase !== \"ended\") {\n\t\t\tim.phase = \"ended\";\n\t\t\tim.outcome = \"cancelled\";\n\t\t\tim.endTime = tick();\n\t\t}\n\t};\n\tconst importOf = ({ itemProblems: _, ...im }: StubImport): Import => im;\n\t/** The latest Release of a configuration, as Start pins it; refused when there is none. */\n\tconst pinned = <C extends { name: string }>(item: Stored<C>, kind: string) => {\n\t\tconst latest = latestReleaseOf(item);\n\t\tif (!latest) {\n\t\t\tthrow new StartRefusedError(`the ${kind} ${item.content.name} has no Release yet`);\n\t\t}\n\t\tconst content = item.revisions.find((r) => r.id === latest.revisionId)?.content ?? item.content;\n\t\treturn {\n\t\t\tcontent,\n\t\t\tref: {\n\t\t\t\tconfigurationId: item.id,\n\t\t\t\tname: content.name,\n\t\t\t\treleaseId: latest.id,\n\t\t\t\tnumber: latest.number,\n\t\t\t},\n\t\t};\n\t};\n\n\treturn {\n\t\tcalls,\n\t\tswitchWorkspace(workspaceId) {\n\t\t\tactive = workspaceId;\n\t\t},\n\t\tupdateImport(id, patch) {\n\t\t\tObject.assign(findImport(id), structuredClone(patch));\n\t\t},\n\n\t\tlistImportProfiles: () =>\n\t\t\tanswer(\"listImportProfiles\", () => byName(ws().importProfiles).map(profileOf)),\n\t\tgetImportProfile: (id) =>\n\t\t\tanswer(\"getImportProfile\", () => profileOf(find(ws().importProfiles, id, \"Import Profile\"))),\n\t\tcreateImportProfile: (content) =>\n\t\t\tanswer(\"createImportProfile\", () => {\n\t\t\t\tnameFree(ws().importProfiles, content.name);\n\t\t\t\tconst s = stored(\"ip\", content);\n\t\t\t\tdecide(\"importProfile\", s);\n\t\t\t\tws().importProfiles.push(s);\n\t\t\t\treturn profileOf(s);\n\t\t\t}),\n\t\tupdateImportProfile: (id, content, draftRevisionId) =>\n\t\t\tanswer(\"updateImportProfile\", () => {\n\t\t\t\tconst s = find(ws().importProfiles, id, \"Import Profile\");\n\t\t\t\tnameFree(ws().importProfiles, content.name, id);\n\t\t\t\tsave(s, content, draftRevisionId);\n\t\t\t\tdecide(\"importProfile\", s);\n\t\t\t\treturn profileOf(s);\n\t\t\t}),\n\t\tdeleteImportProfile: (id) =>\n\t\t\tanswer(\"deleteImportProfile\", () => {\n\t\t\t\tfind(ws().importProfiles, id, \"Import Profile\");\n\t\t\t\tws().importProfiles = ws().importProfiles.filter((p) => p.id !== id);\n\t\t\t}),\n\n\t\tlistProcessors: () =>\n\t\t\tanswer(\"listProcessors\", () => [...processors].sort((a, b) => a.name.localeCompare(b.name))),\n\n\t\tlistMappings: () => answer(\"listMappings\", () => byName(ws().mappings).map(mappingOf)),\n\t\tgetMapping: (id) => answer(\"getMapping\", () => mappingOf(find(ws().mappings, id, \"Mapping\"))),\n\t\tcreateMapping: (content) =>\n\t\t\tanswer(\"createMapping\", () => {\n\t\t\t\tnameFree(ws().mappings, content.name);\n\t\t\t\tconst s = stored(\"mp\", content);\n\t\t\t\tdecide(\"mapping\", s);\n\t\t\t\tws().mappings.push(s);\n\t\t\t\treturn mappingOf(s);\n\t\t\t}),\n\t\tupdateMapping: (id, content, draftRevisionId) =>\n\t\t\tanswer(\"updateMapping\", () => {\n\t\t\t\tconst s = find(ws().mappings, id, \"Mapping\");\n\t\t\t\tnameFree(ws().mappings, content.name, id);\n\t\t\t\tsave(s, content, draftRevisionId);\n\t\t\t\tdecide(\"mapping\", s);\n\t\t\t\treturn mappingOf(s);\n\t\t\t}),\n\t\tdeleteMapping: (id) =>\n\t\t\tanswer(\"deleteMapping\", () => {\n\t\t\t\tfind(ws().mappings, id, \"Mapping\");\n\t\t\t\tconst using = profilesUsing((c) => c.mappingIds.includes(id));\n\t\t\t\tif (using.length > 0) {\n\t\t\t\t\tthrow new ConfigurationInUseError(\n\t\t\t\t\t\tusing,\n\t\t\t\t\t\t`the Mapping is included by ${using.map((p) => p.name).join(\", \")}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tws().mappings = ws().mappings.filter((m) => m.id !== id);\n\t\t\t}),\n\t\tlistMappingImportProfiles: (id) =>\n\t\t\tanswer(\"listMappingImportProfiles\", () => {\n\t\t\t\tfind(ws().mappings, id, \"Mapping\");\n\t\t\t\treturn profilesUsing((c) => c.mappingIds.includes(id));\n\t\t\t}),\n\t\tcheckMappingBlueprintRelease: (id, blueprintReleaseId) =>\n\t\t\tanswer(\"checkMappingBlueprintRelease\", () => {\n\t\t\t\tconst m = find(ws().mappings, id, \"Mapping\");\n\t\t\t\tconst release = releases.find((r) => r.id === blueprintReleaseId);\n\t\t\t\tif (!release) throw new Error(`Blueprint Release ${blueprintReleaseId} not found`);\n\t\t\t\tif (release.blueprintId !== m.content.blueprintId) {\n\t\t\t\t\tthrow new Error(\"the Release is of another Blueprint\");\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tblueprintId: release.blueprintId,\n\t\t\t\t\tmissingFieldPaths: (m.content.fields ?? [])\n\t\t\t\t\t\t.flatMap((f, i) => walk(f, \"\", `/fields/${i}`).map((w) => w.path))\n\t\t\t\t\t\t.filter((path) => !release.fieldPaths.includes(path)),\n\t\t\t\t\tmissingReleaseSpecFields: [\n\t\t\t\t\t\t...(m.content.releaseSpec ?? []).map((r) => r.field ?? \"\"),\n\t\t\t\t\t\t...(m.content.versionMatch?.releaseSpecFields ?? []),\n\t\t\t\t\t].filter(\n\t\t\t\t\t\t(f, i, all) =>\n\t\t\t\t\t\t\tf !== \"\" &&\n\t\t\t\t\t\t\tall.indexOf(f) === i &&\n\t\t\t\t\t\t\t!(release.releaseSpecFields ?? []).some((r) => r.path === f),\n\t\t\t\t\t),\n\t\t\t\t};\n\t\t\t}),\n\n\t\tlistEntitySets: () => answer(\"listEntitySets\", () => byName(ws().entitySets).map(entitySetOf)),\n\t\tgetEntitySet: (id) =>\n\t\t\tanswer(\"getEntitySet\", () => entitySetOf(find(ws().entitySets, id, \"Entity Set\"))),\n\t\tcreateEntitySet: (content) =>\n\t\t\tanswer(\"createEntitySet\", () => {\n\t\t\t\tnameFree(ws().entitySets, content.name);\n\t\t\t\tconst s = stored(\"es\", content);\n\t\t\t\tdecide(\"entitySet\", s);\n\t\t\t\tws().entitySets.push(s);\n\t\t\t\treturn entitySetOf(s);\n\t\t\t}),\n\t\tupdateEntitySet: (id, content, draftRevisionId) =>\n\t\t\tanswer(\"updateEntitySet\", () => {\n\t\t\t\tconst s = find(ws().entitySets, id, \"Entity Set\");\n\t\t\t\tnameFree(ws().entitySets, content.name, id);\n\t\t\t\tsave(s, content, draftRevisionId);\n\t\t\t\tdecide(\"entitySet\", s);\n\t\t\t\treturn entitySetOf(s);\n\t\t\t}),\n\t\tdeleteEntitySet: (id) =>\n\t\t\tanswer(\"deleteEntitySet\", () => {\n\t\t\t\tfind(ws().entitySets, id, \"Entity Set\");\n\t\t\t\tconst using = profilesUsing((c) => c.entitySetId === id);\n\t\t\t\tif (using.length > 0) {\n\t\t\t\t\tthrow new ConfigurationInUseError(\n\t\t\t\t\t\tusing,\n\t\t\t\t\t\t`the Entity Set is named by ${using.map((p) => p.name).join(\", \")}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tws().entitySets = ws().entitySets.filter((e) => e.id !== id);\n\t\t\t}),\n\n\t\tcutRelease: (kind, id, draftRevisionId) =>\n\t\t\tanswer(\"cutRelease\", () => {\n\t\t\t\tconst k = ofKind(kind);\n\t\t\t\tconst item = find(k.items, id, k.name);\n\t\t\t\tif (moved(item, draftRevisionId)) {\n\t\t\t\t\tthrow new ReleaseRefusedError(\"the draft moved: somebody saved in between\");\n\t\t\t\t}\n\t\t\t\t// Valid now, as importhub decides it again at the cut.\n\t\t\t\tconst now = validity(k.reasons(item.content));\n\t\t\t\tif (!now.valid) throw new ReleaseRefusedError(\"the draft is invalid\", now);\n\t\t\t\tif (!stateOf(item).draftDiffersFromRelease) {\n\t\t\t\t\tthrow new ReleaseRefusedError(\n\t\t\t\t\t\t\"the draft does not differ from the latest Release: there is nothing to release\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst number = item.releases.length + 1;\n\t\t\t\tconst release: ConfigurationReleaseRecord = {\n\t\t\t\t\tid: `${item.id}_rel${number}`,\n\t\t\t\t\tnumber,\n\t\t\t\t\trevisionId: draftOf(item).id,\n\t\t\t\t\treleasedBy: STUB_USER_ID,\n\t\t\t\t\treleasedAt: tick(),\n\t\t\t\t};\n\t\t\t\titem.releases.push(release);\n\t\t\t\treturn {\n\t\t\t\t\trelease,\n\t\t\t\t\timportProfiles: kind === \"mapping\" ? profilesUsing((c) => c.mappingIds.includes(id)) : [],\n\t\t\t\t};\n\t\t\t}),\n\t\tlistHistory: (kind, id, pageToken) =>\n\t\t\tanswer(\"listHistory\", () => {\n\t\t\t\tconst k = ofKind(kind);\n\t\t\t\tconst item = find(k.items, id, k.name);\n\t\t\t\t// Pages of ten, newest first; the token is the next page's offset.\n\t\t\t\tconst newest = [...item.revisions].reverse();\n\t\t\t\tconst from = Number(pageToken || \"0\");\n\t\t\t\tconst page = newest.slice(from, from + 10);\n\t\t\t\treturn {\n\t\t\t\t\trevisions: page.map((r) => ({\n\t\t\t\t\t\tid: r.id,\n\t\t\t\t\t\tsavedBy: r.savedBy,\n\t\t\t\t\t\tsavedAt: r.savedAt,\n\t\t\t\t\t\tvalidity: r.validity ?? validity(k.reasons(r.content)),\n\t\t\t\t\t\trestoredFromRevisionId: r.restoredFromRevisionId,\n\t\t\t\t\t})),\n\t\t\t\t\treleases: [...item.releases].reverse(),\n\t\t\t\t\tnextPageToken: from + 10 < newest.length ? String(from + 10) : \"\",\n\t\t\t\t};\n\t\t\t}),\n\t\tcompareRevisions: (kind, id, fromRevisionId, toRevisionId) =>\n\t\t\tanswer(\"compareRevisions\", (): ConfigurationComparison => {\n\t\t\t\tconst k = ofKind(kind);\n\t\t\t\tconst item = find(k.items, id, k.name);\n\t\t\t\tconst from = protoKeyed(revisionIn(item, fromRevisionId).content);\n\t\t\t\tconst to = protoKeyed(revisionIn(item, toRevisionId).content);\n\t\t\t\tconst fields = [...new Set([...Object.keys(from), ...Object.keys(to)])].map((field) => {\n\t\t\t\t\tconst a = from[field];\n\t\t\t\t\tconst b = to[field];\n\t\t\t\t\tconst status =\n\t\t\t\t\t\ta === undefined && b !== undefined\n\t\t\t\t\t\t\t? (\"added\" as const)\n\t\t\t\t\t\t\t: a !== undefined && b === undefined\n\t\t\t\t\t\t\t\t? (\"removed\" as const)\n\t\t\t\t\t\t\t\t: JSON.stringify(a) === JSON.stringify(b)\n\t\t\t\t\t\t\t\t\t? (\"unchanged\" as const)\n\t\t\t\t\t\t\t\t\t: (\"changed\" as const);\n\t\t\t\t\treturn { field, status };\n\t\t\t\t});\n\t\t\t\treturn {\n\t\t\t\t\tfrom: { revisionId: fromRevisionId, content: from },\n\t\t\t\t\tto: { revisionId: toRevisionId, content: to },\n\t\t\t\t\tfields,\n\t\t\t\t};\n\t\t\t}),\n\t\trestoreRevision: (kind, id, revisionId, draftRevisionId) =>\n\t\t\tanswer(\"restoreRevision\", () => {\n\t\t\t\tconst k = ofKind(kind);\n\t\t\t\tconst item = find(k.items, id, k.name);\n\t\t\t\tsave(item, revisionIn(item, revisionId).content, draftRevisionId, revisionId);\n\t\t\t\tdecide(kind, item);\n\t\t\t}),\n\n\t\tasync uploadSourceFile(file, onProgress) {\n\t\t\tcalls.uploadSourceFile++;\n\t\t\tif (options.fail) throw options.fail;\n\t\t\t// A few steps apart, so a screen shows the bar move.\n\t\t\tfor (const f of [0.25, 0.5, 0.75]) {\n\t\t\t\tawait new Promise((r) => setTimeout(r, 20));\n\t\t\t\tonProgress(f);\n\t\t\t}\n\t\t\tif (options.uploadFails) throw options.uploadFails;\n\t\t\tonProgress(1);\n\t\t\tconst id = newId(\"sf\");\n\t\t\tsourceFiles.add(id);\n\t\t\treturn { id, fileName: file.name };\n\t\t},\n\t\tstartImport: (input) =>\n\t\t\tanswer(\"startImport\", () => {\n\t\t\t\tconst w = ws();\n\t\t\t\tconst profile = find(w.importProfiles, input.importProfileId, \"Import Profile\");\n\t\t\t\tif (!sourceFiles.has(input.sourceFileId)) {\n\t\t\t\t\tthrow new StartRefusedError(\"nothing was uploaded to the Source File\");\n\t\t\t\t}\n\t\t\t\t// importhub's order: the rights first, then what would run.\n\t\t\t\tif (!rights.includes(\"editor\")) {\n\t\t\t\t\tthrow new StartRefusedError(\n\t\t\t\t\t\t\"starting an Import needs contenthub editor in the workspace\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst p = pinned(profile, \"Import Profile\");\n\t\t\t\tif (p.content.autoPublish && !rights.includes(\"publisher\")) {\n\t\t\t\t\tthrow new StartRefusedError(\n\t\t\t\t\t\t\"the Import Profile has Auto-publish, which needs contenthub publisher\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst reasons = profileReasons(p.content);\n\t\t\t\tif (reasons.length > 0) {\n\t\t\t\t\tthrow new StartRefusedError(\n\t\t\t\t\t\t`the Import Profile ${p.ref.name} is invalid: ${reasons.map((r) => r.message).join(\" \")}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst mappings = p.content.mappingIds.map(\n\t\t\t\t\t(id) => pinned(find(w.mappings, id, \"Mapping\"), \"Mapping\").ref,\n\t\t\t\t);\n\t\t\t\tconst entitySet = p.content.entitySetId\n\t\t\t\t\t? pinned(find(w.entitySets, p.content.entitySetId, \"Entity Set\"), \"Entity Set\").ref\n\t\t\t\t\t: undefined;\n\t\t\t\tconst im: StubImport = {\n\t\t\t\t\tid: newId(\"im\"),\n\t\t\t\t\timportProfileId: profile.id,\n\t\t\t\t\timportProfileName: p.ref.name,\n\t\t\t\t\tsourceFileId: input.sourceFileId,\n\t\t\t\t\tstartedBy: STUB_USER_ID,\n\t\t\t\t\tphase: \"queued\",\n\t\t\t\t\tfailureReason: \"\",\n\t\t\t\t\tprogress: { done: 0, total: 0 },\n\t\t\t\t\tcounts: {\n\t\t\t\t\t\tmatched: 0,\n\t\t\t\t\t\tcreated: 0,\n\t\t\t\t\t\tproblems: 0,\n\t\t\t\t\t\tplanned: 0,\n\t\t\t\t\t\tcorrected: 0,\n\t\t\t\t\t\tkept: 0,\n\t\t\t\t\t\tunchanged: 0,\n\t\t\t\t\t},\n\t\t\t\t\tchangeSetId: \"\",\n\t\t\t\t\treleases: {\n\t\t\t\t\t\timportProfile: p.ref,\n\t\t\t\t\t\tmappings,\n\t\t\t\t\t\t...(entitySet ? { entitySet } : {}),\n\t\t\t\t\t},\n\t\t\t\t\tcreateTime: tick(),\n\t\t\t\t\tstartTime: \"\",\n\t\t\t\t\tendTime: \"\",\n\t\t\t\t\tcancelledBy: \"\",\n\t\t\t\t\teffectiveDate: input.effectiveDate ?? \"\",\n\t\t\t\t\t...(input.source ? { source: input.source } : {}),\n\t\t\t\t\titemProblems: [],\n\t\t\t\t};\n\t\t\t\tw.imports.unshift(im);\n\t\t\t\treturn importOf(im);\n\t\t\t}),\n\t\tlistImports: (pageToken) =>\n\t\t\tanswer(\"listImports\", () => {\n\t\t\t\t// Pages of fifty, newest first; the token is the next page's offset.\n\t\t\t\tconst all = ws().imports;\n\t\t\t\tall.forEach(settle);\n\t\t\t\tconst from = Number(pageToken || \"0\");\n\t\t\t\treturn {\n\t\t\t\t\timports: all.slice(from, from + 50).map(importOf),\n\t\t\t\t\tnextPageToken: from + 50 < all.length ? String(from + 50) : \"\",\n\t\t\t\t};\n\t\t\t}),\n\t\tgetImport: (id) =>\n\t\t\tanswer(\"getImport\", () => {\n\t\t\t\tconst im = findImport(id);\n\t\t\t\tsettle(im);\n\t\t\t\treturn importOf(im);\n\t\t\t}),\n\t\tcancelImport: (id) =>\n\t\t\tanswer(\"cancelImport\", () => {\n\t\t\t\tconst im = findImport(id);\n\t\t\t\tif (im.phase === \"ended\") throw new Error(\"the Import has ended\");\n\t\t\t\tim.cancelledBy ||= STUB_USER_ID;\n\t\t\t\t// A queued Import ends at once; a running one at its next item.\n\t\t\t\tif (im.phase === \"queued\") settle(im);\n\t\t\t\treturn importOf(im);\n\t\t\t}),\n\t\tlistItemProblems: (importId, filter) =>\n\t\t\tanswer(\"listItemProblems\", () => {\n\t\t\t\tconst all = findImport(importId).itemProblems ?? [];\n\t\t\t\tconst query = filter.sourceKeyQuery.toLowerCase();\n\t\t\t\tconst matching = all.filter(\n\t\t\t\t\t(p) =>\n\t\t\t\t\t\t(!filter.mappingId || p.mappingId === filter.mappingId) &&\n\t\t\t\t\t\tp.sourceKey.toLowerCase().includes(query),\n\t\t\t\t);\n\t\t\t\tconst counts = new Map<string, { mappingId: string; mappingName: string; count: number }>();\n\t\t\t\tfor (const p of all) {\n\t\t\t\t\tconst c = counts.get(p.mappingId) ?? {\n\t\t\t\t\t\tmappingId: p.mappingId,\n\t\t\t\t\t\tmappingName: p.mappingName,\n\t\t\t\t\t\tcount: 0,\n\t\t\t\t\t};\n\t\t\t\t\tc.count++;\n\t\t\t\t\tcounts.set(p.mappingId, c);\n\t\t\t\t}\n\t\t\t\tconst from = Number(filter.pageToken || \"0\");\n\t\t\t\treturn {\n\t\t\t\t\titemProblems: matching.slice(from, from + 50),\n\t\t\t\t\ttotalCount: all.length,\n\t\t\t\t\tmatchingCount: matching.length,\n\t\t\t\t\tmappings: [...counts.values()].sort((a, b) => a.mappingName.localeCompare(b.mappingName)),\n\t\t\t\t\tnextPageToken: from + 50 < matching.length ? String(from + 50) : \"\",\n\t\t\t\t};\n\t\t\t}),\n\n\t\tlistApiKeys: () => answer(\"listApiKeys\", () => ws().apiKeys),\n\t\tcreateApiKey: (input) =>\n\t\t\tanswer(\"createApiKey\", () => {\n\t\t\t\t// CreateAPIKey's rules: a name, not too long, and an expiry ahead.\n\t\t\t\tconst name = input.name.trim();\n\t\t\t\tif (!name) throw new Error(\"a name is required\");\n\t\t\t\tif (name.length > API_KEY_NAME_MAX) {\n\t\t\t\t\tthrow new Error(`the name is longer than ${API_KEY_NAME_MAX} characters`);\n\t\t\t\t}\n\t\t\t\tconst expireTime = input.expireTime ? new Date(input.expireTime).toISOString() : \"\";\n\t\t\t\tif (expireTime && Date.parse(expireTime) <= Date.now()) {\n\t\t\t\t\tthrow new Error(\"the expiry must lie in the future\");\n\t\t\t\t}\n\t\t\t\tconst n = ++created;\n\t\t\t\tconst apiKey: ApiKey = {\n\t\t\t\t\tid: `key_stub_new_${n}`,\n\t\t\t\t\tname,\n\t\t\t\t\tkeyPrefix: `ihk_n${String(n).padStart(3, \"0\")}`,\n\t\t\t\t\towner: STUB_USER_ID,\n\t\t\t\t\texpireTime,\n\t\t\t\t\tcreateTime: new Date().toISOString(),\n\t\t\t\t};\n\t\t\t\tws().apiKeys.unshift(apiKey);\n\t\t\t\t// The secret is returned here and kept nowhere, as importhub keeps it.\n\t\t\t\treturn { apiKey, secret: `${apiKey.keyPrefix}_stub_secret_${n}` };\n\t\t\t}),\n\t\trevokeApiKey: (id) =>\n\t\t\tanswer(\"revokeApiKey\", () => {\n\t\t\t\tconst w = ws();\n\t\t\t\tif (!w.apiKeys.some((k) => k.id === id)) throw new Error(`API key ${id} not found`);\n\t\t\t\tw.apiKeys = w.apiKeys.filter((k) => k.id !== id);\n\t\t\t}),\n\t};\n}\n\n/**\n * Whether an XPath's brackets and parentheses pair up: the stub's stand-in\n * for importhub's XPath check, enough to show a reason at its field.\n */\nfunction balanced(expr: string): boolean {\n\tconst open: string[] = [];\n\tconst pairs: Record<string, string> = { \"]\": \"[\", \")\": \"(\" };\n\tfor (const ch of expr) {\n\t\tif (ch === \"[\" || ch === \"(\") open.push(ch);\n\t\telse if (ch in pairs && open.pop() !== pairs[ch]) return false;\n\t}\n\treturn open.length === 0;\n}\n\n/** A field mapping and its children, each with its field path and pointer. */\nfunction walk(\n\tmapping: Record<string, unknown>,\n\tprefix: string,\n\tat: string,\n): { path: string; rel: string; mapping: Record<string, unknown> }[] {\n\tconst path = `${prefix}${String(mapping.name ?? \"\")}`;\n\treturn [\n\t\t{ path, rel: at, mapping },\n\t\t...([\"fields\", \"virtualTableFields\"] as const).flatMap((key) =>\n\t\t\t(Array.isArray(mapping[key]) ? (mapping[key] as Record<string, unknown>[]) : []).flatMap(\n\t\t\t\t(child, j) => walk(child, `${path}.`, `${at}/${key}/${j}`),\n\t\t\t),\n\t\t),\n\t];\n}\n\n/**\n * An `ImporthubBlueprints` over the stub's Blueprint Releases, for a host's\n * `ImporthubHost.blueprints` in tests.\n */\nexport function createStubBlueprints(\n\tblueprintReleases: StubBlueprintRelease[] = stubBlueprintReleases(),\n): ImporthubBlueprints {\n\treturn {\n\t\tasync listBlueprints() {\n\t\t\tconst byId = new Map(blueprintReleases.map((r) => [r.blueprintId, r.blueprintName]));\n\t\t\treturn [...byId]\n\t\t\t\t.map(([id, name]) => ({ id, name }))\n\t\t\t\t.sort((a, b) => a.name.localeCompare(b.name));\n\t\t},\n\t\tasync listReleases(blueprintId) {\n\t\t\treturn blueprintReleases\n\t\t\t\t.filter((r) => r.blueprintId === blueprintId)\n\t\t\t\t.map((r) => ({ id: r.id, label: r.label }));\n\t\t},\n\t\tasync getRelease(releaseId) {\n\t\t\tconst r = blueprintReleases.find((x) => x.id === releaseId);\n\t\t\tif (!r) throw new Error(`Blueprint Release ${releaseId} not found`);\n\t\t\treturn {\n\t\t\t\tid: r.id,\n\t\t\t\tblueprintId: r.blueprintId,\n\t\t\t\tname: r.label,\n\t\t\t\tfields:\n\t\t\t\t\tr.fields ??\n\t\t\t\t\tr.fieldPaths.map((path) => ({\n\t\t\t\t\t\taccessor: path,\n\t\t\t\t\t\tpath,\n\t\t\t\t\t\tfieldType: \"text\",\n\t\t\t\t\t\tlabel: \"\",\n\t\t\t\t\t\tchildren: [],\n\t\t\t\t\t})),\n\t\t\t\treleaseSpecFields: r.releaseSpecFields ?? [],\n\t\t\t};\n\t\t},\n\t};\n}\n\n/**\n * The display name's reasons, as importhub's checkDisplayName gives them\n * (internal/configstore/mapping.go): template and field set together, the\n * field a plain-text one of the pinned Release that no field mapping writes.\n */\nfunction displayNameReasons(\n\tc: MappingContent,\n\ttree: ImporthubBlueprintField[] | undefined,\n\tmapped: string[],\n): ValidityReason[] {\n\tconst template = (c.displayNameTemplate ?? \"\").trim();\n\tconst field = (c.displayNameField ?? \"\").trim();\n\tconst reason = (path: string, code: string, message: string): ValidityReason[] => [\n\t\t{ path, code, message },\n\t];\n\tif (!template && !field) return [];\n\tif (!field) {\n\t\treturn reason(\n\t\t\t\"/display_name_field\",\n\t\t\t\"incomplete_display_name\",\n\t\t\t\"the display-name template names no field to write the display name into\",\n\t\t);\n\t}\n\tif (!template) {\n\t\treturn reason(\n\t\t\t\"/display_name_template\",\n\t\t\t\"incomplete_display_name\",\n\t\t\t`the display-name field \"${field}\" has no display-name template to fill it`,\n\t\t);\n\t}\n\tif (!tree) return [];\n\tconst paths = (fs: ImporthubBlueprintField[]): string[] =>\n\t\tfs.flatMap((f) => [f.path, ...paths(f.children)]);\n\tif (!paths(tree).includes(field)) {\n\t\treturn reason(\n\t\t\t\"/display_name_field\",\n\t\t\t\"unknown_display_name_field\",\n\t\t\t`the Blueprint Release has no field \"${field}\" to write the display name into`,\n\t\t);\n\t}\n\tif (!plainTextFields(tree).some((f) => f.path === field)) {\n\t\treturn reason(\n\t\t\t\"/display_name_field\",\n\t\t\t\"display_name_field_not_plain_text\",\n\t\t\t`the display-name field \"${field}\" is not a plain-text one (text or textarea)`,\n\t\t);\n\t}\n\tif (mapped.includes(field)) {\n\t\treturn reason(\n\t\t\t\"/display_name_field\",\n\t\t\t\"display_name_field_mapped\",\n\t\t\t`the field \"${field}\" is mapped too: it takes the display name or a mapped value, not both`,\n\t\t);\n\t}\n\treturn [];\n}\n"],"names":["STUB_USER_ID","STUB_OTHER_USER_ID","STUB_WORKSPACE_ID","STUB_OTHER_WORKSPACE_ID","stubIdentity","workspaceId","createHostMembers","field","path","fieldType","label","children","pathsOf","tree","f","gesetzFields","withFootnote","gesetzReleaseSpec","stubBlueprintReleases","gesetz2","gesetz1","entscheidung","stubMappings","stubEntitySets","stubImportProfiles","text","accessor","name","required","instructions","stubProcessors","counts","c","gesetzReleases","profileRelease","stubImport","problem","n","mapping","sourceKey","reason","stubImports","stubApiKeys","METHODS","clock","tick","seed","items","i","count","revisions","releases","draftOf","s","latestReleaseOf","stateOf","latest","released","r","snake","key","protoKeyed","content","k","v","validity","reasons","byName","a","b","created","createStubImporthubClient","options","workspaces","id","w","processors","active","calls","m","ws","answer","method","run","find","kind","item","nameFree","NameTakenError","moved","draftRevisionId","save","restoredFromRevisionId","stored","prefix","newId","mappingReasons","out","release","xpath","expr","balanced","mapped","at","rel","walk","tc","pa","j","displayNameReasons","stepReasons","steps","list","p","x","profileReasons","e","entitySetReasons","profileOf","mappingOf","entitySetOf","profilesUsing","uses","ofKind","decide","revisionIn","revisionId","sourceFiles","rights","findImport","im","settle","importOf","_","pinned","StartRefusedError","patch","using","ConfigurationInUseError","blueprintReleaseId","all","ReleaseRefusedError","now","number","pageToken","newest","from","fromRevisionId","toRevisionId","to","fields","status","file","onProgress","input","profile","mappings","entitySet","importId","filter","query","matching","API_KEY_NAME_MAX","expireTime","apiKey","open","pairs","ch","child","createStubBlueprints","blueprintReleases","blueprintId","releaseId","template","code","message","paths","fs","plainTextFields"],"mappings":";;;AAcO,MAAMA,IAAe,iBAEfC,IAAqB,mBAErBC,KAAoB,gBAEpBC,KAA0B;AAMhC,SAASC,GAAaC,IAAsBH,IAAiC;AACnF,SAAO;AAAA,IACN,QAAQF;AAAA,IACR,aAAAK;AAAA,IACA,SAASC,GAAkB;AAAA,MAC1B,EAAE,QAAQN,GAAc,aAAa,gBAAgB,OAAO,kBAAA;AAAA,MAC5D,EAAE,QAAQC,GAAoB,aAAa,gBAAgB,OAAO,oBAAA;AAAA,IAAoB,CACtF;AAAA,EAAA;AAEH;AAwBA,MAAMM,IAAQ,CACbC,GACAC,GACAC,GACAC,IAAsC,CAAA,OACR;AAAA,EAC9B,UAAUH,EAAK,MAAM,GAAG,EAAE,SAASA;AAAA,EACnC,MAAAA;AAAA,EACA,WAAAC;AAAA,EACA,OAAAC;AAAA,EACA,UAAAC;AACD,IAGMC,IAAU,CAACC,MAChBA,EAAK,QAAQ,CAACC,MAAM,CAACA,EAAE,MAAM,GAAGF,EAAQE,EAAE,QAAQ,CAAC,CAAC,GAE/CC,KAAe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,EAAA;AAkB/C;"}
1
+ {"version":3,"file":"testing.js","sources":["../src/testing/fixtures.ts","../src/testing/mapping-test.ts","../src/testing/stub-client.ts"],"sourcesContent":["import { createHostMembers, type HostIdentity } from \"@knkcs/anker/host\";\nimport type {\n\tApiKey,\n\tEntitySetContent,\n\tImport,\n\tImportCounts,\n\tImportProfileContent,\n\tItemProblem,\n\tMappingContent,\n\tProcessor,\n} from \"../client/importhub-client\";\nimport type { ImporthubBlueprintField } from \"../common/host\";\n\n/** The stub viewer's id. */\nexport const STUB_USER_ID = \"user_stub_ada\";\n/** A second member of the stub workspace, who starts and cancels Imports too. */\nexport const STUB_OTHER_USER_ID = \"user_stub_grace\";\n/** The stub workspace's id. */\nexport const STUB_WORKSPACE_ID = \"ws_stub_main\";\n/** A second workspace, for tests that switch to it. */\nexport const STUB_OTHER_WORKSPACE_ID = \"ws_stub_other\";\n\n/**\n * A `HostIdentity` for anker's `TestHost` or `HostProvider`: Ada, in the stub\n * workspace unless another is named.\n */\nexport function stubIdentity(workspaceId: string = STUB_WORKSPACE_ID): HostIdentity {\n\treturn {\n\t\tuserId: STUB_USER_ID,\n\t\tworkspaceId,\n\t\tmembers: createHostMembers([\n\t\t\t{ userId: STUB_USER_ID, displayName: \"Ada Importer\", email: \"ada@example.com\" },\n\t\t\t{ userId: STUB_OTHER_USER_ID, displayName: \"Grace Hopper\", email: \"grace@example.com\" },\n\t\t]),\n\t};\n}\n\n/** A stub configuration as the stub client is seeded with it: an id and its content. */\nexport interface StubConfiguration<C> {\n\tid: string;\n\tcontent: C;\n\t/** The number of its latest Release; none when unset. */\n\treleaseNumber?: number;\n}\n\n/** A Blueprint Release the stub knows, with the field paths it has. */\nexport interface StubBlueprintRelease {\n\tid: string;\n\tblueprintId: string;\n\tblueprintName: string;\n\tlabel: string;\n\t/** Every field path, nested ones included (`stand.datum`). */\n\tfieldPaths: string[];\n\t/** Its field tree, for the Mapping editor; the paths as text fields when unset. */\n\tfields?: ImporthubBlueprintField[];\n\t/** Its Release Spec fields; none when unset. */\n\treleaseSpecFields?: ImporthubBlueprintField[];\n}\n\nconst field = (\n\tpath: string,\n\tfieldType: string,\n\tlabel: string,\n\tchildren: ImporthubBlueprintField[] = [],\n): ImporthubBlueprintField => ({\n\taccessor: path.split(\".\").pop() ?? path,\n\tpath,\n\tfieldType,\n\tlabel,\n\tchildren,\n});\n\n/** Every path of a field tree, parents before their children. */\nconst pathsOf = (tree: ImporthubBlueprintField[]): string[] =>\n\ttree.flatMap((f) => [f.path, ...pathsOf(f.children)]);\n\nconst gesetzFields = (withFootnote: boolean) => [\n\tfield(\"titel\", \"text\", \"Titel\"),\n\tfield(\"abkuerzung\", \"text\", \"Abkürzung\"),\n\tfield(\"anzeigename\", \"textarea\", \"Anzeigename\"),\n\t...(withFootnote ? [field(\"fussnote\", \"rich_text\", \"Fußnote\")] : []),\n\tfield(\"stand\", \"fieldset\", \"Stand\", [\n\t\tfield(\"stand.datum\", \"date\", \"Datum\"),\n\t\tfield(\"stand.art\", \"select\", \"Art\"),\n\t]),\n];\n\nconst gesetzReleaseSpec = () => [\n\tfield(\"fundstelle\", \"text\", \"Fundstelle\"),\n\tfield(\"ausgabedatum\", \"date\", \"Ausgabedatum\"),\n];\n\n/**\n * Two Releases of the \"Gesetz\" Blueprint, with a fieldset `stand` and two\n * Release Spec fields, the newer of which dropped `fussnote`, and one of\n * \"Entscheidung\".\n */\nexport function stubBlueprintReleases(): StubBlueprintRelease[] {\n\tconst gesetz2 = gesetzFields(false);\n\tconst gesetz1 = gesetzFields(true);\n\tconst entscheidung = [\n\t\tfield(\"aktenzeichen\", \"text\", \"Aktenzeichen\"),\n\t\tfield(\"datum\", \"date\", \"Datum\"),\n\t];\n\treturn [\n\t\t{\n\t\t\tid: \"br_stub_gesetz_2\",\n\t\t\tblueprintId: \"bp_stub_gesetz\",\n\t\t\tblueprintName: \"Gesetz\",\n\t\t\tlabel: \"Release 2\",\n\t\t\tfieldPaths: pathsOf(gesetz2),\n\t\t\tfields: gesetz2,\n\t\t\treleaseSpecFields: gesetzReleaseSpec(),\n\t\t},\n\t\t{\n\t\t\tid: \"br_stub_gesetz_1\",\n\t\t\tblueprintId: \"bp_stub_gesetz\",\n\t\t\tblueprintName: \"Gesetz\",\n\t\t\tlabel: \"Release 1\",\n\t\t\tfieldPaths: pathsOf(gesetz1),\n\t\t\tfields: gesetz1,\n\t\t\treleaseSpecFields: gesetzReleaseSpec(),\n\t\t},\n\t\t{\n\t\t\tid: \"br_stub_entscheidung_1\",\n\t\t\tblueprintId: \"bp_stub_entscheidung\",\n\t\t\tblueprintName: \"Entscheidung\",\n\t\t\tlabel: \"Release 1\",\n\t\t\tfieldPaths: pathsOf(entscheidung),\n\t\t\tfields: entscheidung,\n\t\t},\n\t];\n}\n\n/** The stub workspace's Mappings: one valid and released, one invalid. */\nexport function stubMappings(): StubConfiguration<MappingContent>[] {\n\treturn [\n\t\t{\n\t\t\tid: \"mp_stub_norm\",\n\t\t\treleaseNumber: 1,\n\t\t\tcontent: {\n\t\t\t\tname: \"Gesetz norms\",\n\t\t\t\tdescription: \"One Content per norm\",\n\t\t\t\tblueprintId: \"bp_stub_gesetz\",\n\t\t\t\tblueprintReleaseId: \"br_stub_gesetz_1\",\n\t\t\t\telementSelector: \"//norm\",\n\t\t\t\tsourceKey: { selector: \"@id\" },\n\t\t\t\tfields: [\n\t\t\t\t\t{ name: \"titel\", selector: \"titel\", type: \"text\" },\n\t\t\t\t\t{ name: \"fussnote\", selector: \"fn\", type: \"text\" },\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: \"mp_stub_decision\",\n\t\t\tcontent: {\n\t\t\t\tname: \"Court decisions\",\n\t\t\t\tdescription: \"\",\n\t\t\t\tblueprintId: \"bp_stub_entscheidung\",\n\t\t\t\tblueprintReleaseId: \"br_stub_entscheidung_1\",\n\t\t\t\telementSelector: \"\",\n\t\t\t\tsourceKey: {},\n\t\t\t\tfields: [],\n\t\t\t},\n\t\t},\n\t];\n}\n\n/**\n * A sample file for the \"Gesetz norms\" Mapping's Mapping Test: two norms,\n * the second without a footnote.\n */\nexport const stubMappingTestSample = `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<gesetz>\n\t<norm id=\"n1\"><titel>§ 1 Geltungsbereich</titel><fn>Gilt ab 2026.</fn></norm>\n\t<norm id=\"n2\"><titel>§ 2 Begriffsbestimmungen</titel></norm>\n</gesetz>\n`;\n\n/** The stub workspace's Entity Sets: one. */\nexport function stubEntitySets(): StubConfiguration<EntitySetContent>[] {\n\treturn [\n\t\t{\n\t\t\tid: \"es_stub_latin1\",\n\t\t\treleaseNumber: 1,\n\t\t\tcontent: {\n\t\t\t\tname: \"ISO Latin 1\",\n\t\t\t\tdescription: \"The Latin-1 entities Boorberg's files use\",\n\t\t\t\tentities: { auml: \"ä\", nbsp: \" \" },\n\t\t\t},\n\t\t},\n\t];\n}\n\n/**\n * The stub workspace's Import Profiles: one per kind of Source File. The\n * VRPML one includes the invalid Mapping, so it is invalid too.\n */\nexport function stubImportProfiles(): StubConfiguration<ImportProfileContent>[] {\n\treturn [\n\t\t{\n\t\t\tid: \"ip_stub_gesetz\",\n\t\t\treleaseNumber: 2,\n\t\t\tcontent: {\n\t\t\t\tname: \"Boorberg gesetz\",\n\t\t\t\tdescription: \"Boorberg's law files\",\n\t\t\t\tentitySetId: \"es_stub_latin1\",\n\t\t\t\tpreprocessors: [{ processor: \"rename-element\", settings: { from: \"para\", to: \"absatz\" } }],\n\t\t\t\tmappingIds: [\"mp_stub_norm\"],\n\t\t\t\tpostProcessors: [],\n\t\t\t\tautoPublish: false,\n\t\t\t\tdeleteSourceFileOnSuccess: true,\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: \"ip_stub_vrpml\",\n\t\t\tcontent: {\n\t\t\t\tname: \"VRPML court decisions\",\n\t\t\t\tdescription: \"\",\n\t\t\t\tentitySetId: \"\",\n\t\t\t\tpreprocessors: [],\n\t\t\t\tmappingIds: [\"mp_stub_decision\"],\n\t\t\t\tpostProcessors: [],\n\t\t\t\tautoPublish: false,\n\t\t\t\tdeleteSourceFileOnSuccess: false,\n\t\t\t},\n\t\t},\n\t];\n}\n\nconst text = (accessor: string, name: string, required: boolean, instructions = \"\") => ({\n\tfield_type: \"text\",\n\tconfig: { name, api_accessor: accessor, required, instructions },\n\tsystem: false,\n});\n\n/** The catalogue, a few Processors of each kind and target. */\nexport function stubProcessors(): Processor[] {\n\treturn [\n\t\t{\n\t\t\tname: \"citation-links\",\n\t\t\tkind: \"post_processor\",\n\t\t\ttarget: \"source_file\",\n\t\t\tdescription:\n\t\t\t\t\"Links citations in rich text to the Content they name, through legalcitationhub.\",\n\t\t\tsettingsSpec: [],\n\t\t},\n\t\t{\n\t\t\tname: \"norm-cite\",\n\t\t\tkind: \"preprocessor\",\n\t\t\ttarget: \"rich_text_field\",\n\t\t\tdescription: \"Marks legal norm citations in one rich-text field.\",\n\t\t\tsettingsSpec: [],\n\t\t},\n\t\t{\n\t\t\tname: \"rename-element\",\n\t\t\tkind: \"preprocessor\",\n\t\t\ttarget: \"source_file\",\n\t\t\tdescription: \"Renames every element of one name to another.\",\n\t\t\tsettingsSpec: [\n\t\t\t\ttext(\"from\", \"Element\", true, \"The element's name now.\"),\n\t\t\t\ttext(\"to\", \"New name\", true),\n\t\t\t],\n\t\t},\n\t\t{\n\t\t\tname: \"sentence-detect\",\n\t\t\tkind: \"preprocessor\",\n\t\t\ttarget: \"source_file\",\n\t\t\tdescription: \"Wraps each sentence of an element in its own element.\",\n\t\t\tsettingsSpec: [text(\"element\", \"Element\", false)],\n\t\t},\n\t];\n}\n\n/** A stub Import as the stub client is seeded with it, with its Item Problems. */\nexport interface StubImport extends Import {\n\titemProblems?: ItemProblem[];\n}\n\nconst counts = (c: Partial<ImportCounts> = {}): ImportCounts => ({\n\tmatched: 0,\n\tcreated: 0,\n\tproblems: 0,\n\tplanned: 0,\n\tcorrected: 0,\n\tkept: 0,\n\tunchanged: 0,\n\t...c,\n});\n\n/** The Releases the fixtures' Imports of the gesetz Profile ran with. */\nconst gesetzReleases = (profileRelease: number): Import[\"releases\"] => ({\n\timportProfile: {\n\t\tconfigurationId: \"ip_stub_gesetz\",\n\t\tname: \"Boorberg gesetz\",\n\t\treleaseId: `ip_stub_gesetz_rel${profileRelease}`,\n\t\tnumber: profileRelease,\n\t},\n\tmappings: [\n\t\t{\n\t\t\tconfigurationId: \"mp_stub_norm\",\n\t\t\tname: \"Gesetz norms\",\n\t\t\treleaseId: \"mp_stub_norm_rel1\",\n\t\t\tnumber: 1,\n\t\t},\n\t],\n\tentitySet: {\n\t\tconfigurationId: \"es_stub_latin1\",\n\t\tname: \"ISO Latin 1\",\n\t\treleaseId: \"es_stub_latin1_rel1\",\n\t\tnumber: 1,\n\t},\n});\n\nconst stubImport = (i: Partial<StubImport> & Pick<Import, \"id\">): StubImport => ({\n\timportProfileId: \"ip_stub_gesetz\",\n\timportProfileName: \"Boorberg gesetz\",\n\tsourceFileId: `sf_${i.id}`,\n\tstartedBy: STUB_USER_ID,\n\tphase: \"ended\",\n\tfailureReason: \"\",\n\tprogress: { done: 0, total: 0 },\n\tcounts: counts(),\n\tchangeSetId: \"\",\n\treleases: gesetzReleases(2),\n\tcreateTime: \"2026-11-03T09:00:00.000Z\",\n\tstartTime: \"\",\n\tendTime: \"\",\n\tcancelledBy: \"\",\n\teffectiveDate: \"\",\n\t...i,\n});\n\nconst problem = (\n\tn: number,\n\tmapping: \"norm\" | \"title\",\n\tsourceKey: string,\n\tfield: string,\n\treason: string,\n): ItemProblem => ({\n\tid: `prob_stub_${n}`,\n\tmappingId: mapping === \"norm\" ? \"mp_stub_norm\" : \"mp_stub_title\",\n\tmappingName: mapping === \"norm\" ? \"Gesetz norms\" : \"Gesetz titles\",\n\tsourceKey,\n\tfield,\n\treason,\n});\n\n/**\n * The stub workspace's Imports, newest first: one running, one queued\n * behind it, and one of each Import Outcome.\n */\nexport function stubImports(): StubImport[] {\n\treturn [\n\t\tstubImport({\n\t\t\tid: \"im_stub_running\",\n\t\t\tphase: \"writing\",\n\t\t\tprogress: { done: 48, total: 120 },\n\t\t\tcounts: counts({ matched: 120, created: 40, planned: 8 }),\n\t\t\tchangeSetId: \"cs_stub_running\",\n\t\t\tcreateTime: \"2026-11-04T10:00:00.000Z\",\n\t\t\tstartTime: \"2026-11-04T10:00:05.000Z\",\n\t\t}),\n\t\tstubImport({\n\t\t\tid: \"im_stub_queued\",\n\t\t\tphase: \"queued\",\n\t\t\tstartedBy: STUB_OTHER_USER_ID,\n\t\t\treleases: gesetzReleases(2),\n\t\t\tcreateTime: \"2026-11-04T10:05:00.000Z\",\n\t\t}),\n\t\tstubImport({\n\t\t\tid: \"im_stub_problems\",\n\t\t\toutcome: \"succeeded_with_problems\",\n\t\t\tcounts: counts({\n\t\t\t\tmatched: 212,\n\t\t\t\tcreated: 180,\n\t\t\t\tplanned: 20,\n\t\t\t\tcorrected: 6,\n\t\t\t\tkept: 1,\n\t\t\t\tproblems: 5,\n\t\t\t}),\n\t\t\tchangeSetId: \"cs_stub_problems\",\n\t\t\treleases: {\n\t\t\t\t...gesetzReleases(2),\n\t\t\t\tmappings: [\n\t\t\t\t\t...gesetzReleases(2).mappings,\n\t\t\t\t\t{\n\t\t\t\t\t\tconfigurationId: \"mp_stub_title\",\n\t\t\t\t\t\tname: \"Gesetz titles\",\n\t\t\t\t\t\treleaseId: \"mp_stub_title_rel3\",\n\t\t\t\t\t\tnumber: 3,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t\tcreateTime: \"2026-11-03T09:00:00.000Z\",\n\t\t\tstartTime: \"2026-11-03T09:00:02.000Z\",\n\t\t\tendTime: \"2026-11-03T09:12:40.000Z\",\n\t\t\teffectiveDate: \"2026-10-01\",\n\t\t\tsource: { date: \"2026-09-20\", reference: \"BGBl. 2026 I Nr. 270\" },\n\t\t\titemProblems: [\n\t\t\t\tproblem(1, \"norm\", \"BJNR000010001\", \"stand/datum\", \"“31.02.2026” is not a date.\"),\n\t\t\t\tproblem(2, \"norm\", \"BJNR000010002\", \"\", \"The Version Match found two Releases.\"),\n\t\t\t\tproblem(3, \"title\", \"BJNR000020001\", \"\", \"No Title has the Ausgabe code BY-7.\"),\n\t\t\t\tproblem(4, \"norm\", \"BJNR000030001\", \"titel\", \"The field is required.\"),\n\t\t\t\tproblem(5, \"title\", \"BJNR000030002\", \"\", \"No Title has the Ausgabe code BY-9.\"),\n\t\t\t],\n\t\t}),\n\t\tstubImport({\n\t\t\tid: \"im_stub_succeeded\",\n\t\t\toutcome: \"succeeded\",\n\t\t\tcounts: counts({ matched: 64, created: 64 }),\n\t\t\tchangeSetId: \"cs_stub_succeeded\",\n\t\t\treleases: gesetzReleases(1),\n\t\t\tcreateTime: \"2026-11-02T14:00:00.000Z\",\n\t\t\tstartTime: \"2026-11-02T14:00:01.000Z\",\n\t\t\tendTime: \"2026-11-02T14:03:10.000Z\",\n\t\t}),\n\t\tstubImport({\n\t\t\tid: \"im_stub_failed\",\n\t\t\toutcome: \"failed\",\n\t\t\tfailureReason: \"The worker crashed three times running this Import.\",\n\t\t\tcounts: counts({ matched: 30 }),\n\t\t\treleases: gesetzReleases(1),\n\t\t\tcreateTime: \"2026-11-02T11:00:00.000Z\",\n\t\t\tstartTime: \"2026-11-02T11:00:01.000Z\",\n\t\t\tendTime: \"2026-11-02T11:20:00.000Z\",\n\t\t}),\n\t\tstubImport({\n\t\t\tid: \"im_stub_cancelled\",\n\t\t\toutcome: \"cancelled\",\n\t\t\tcancelledBy: STUB_OTHER_USER_ID,\n\t\t\tcounts: counts({ matched: 12, created: 3 }),\n\t\t\treleases: gesetzReleases(1),\n\t\t\tcreateTime: \"2026-11-01T16:00:00.000Z\",\n\t\t\tstartTime: \"2026-11-01T16:00:01.000Z\",\n\t\t\tendTime: \"2026-11-01T16:01:00.000Z\",\n\t\t}),\n\t];\n}\n\n/**\n * The stub workspace's API keys, newest first: Grace's nightly feed, which\n * never expires, and Ada's pipeline key, which does.\n */\nexport function stubApiKeys(): ApiKey[] {\n\treturn [\n\t\t{\n\t\t\tid: \"key_stub_nightly\",\n\t\t\tname: \"Nightly gesetz feed\",\n\t\t\tkeyPrefix: \"ihk_7Qx2\",\n\t\t\towner: STUB_OTHER_USER_ID,\n\t\t\texpireTime: \"\",\n\t\t\tcreateTime: \"2026-11-20T07:30:00.000Z\",\n\t\t},\n\t\t{\n\t\t\tid: \"key_stub_pipeline\",\n\t\t\tname: \"VRPML pipeline\",\n\t\t\tkeyPrefix: \"ihk_b91F\",\n\t\t\towner: STUB_USER_ID,\n\t\t\texpireTime: \"2027-06-30T21:59:59.000Z\",\n\t\t\tcreateTime: \"2026-11-03T12:00:00.000Z\",\n\t\t},\n\t];\n}\n","// The stub's Mapping Test: a small reading of a sample with the DOM's own\n// XPath, enough for a host's test to see a Mapping Test answer what the\n// Mapping as edited selects, not a canned answer. It is not xmlmapper: it\n// reads each field's XPath as a string (fieldsets nested), says a field\n// without a value cannot be mapped unless it is optional, and leaves out\n// everything an Import derives besides (Validity Periods, Release Spec,\n// display names, collection routing). Its messages are its own, not\n// importhub's.\n//\n// It needs a DOM (DOMParser and document.evaluate): a browser, or jsdom,\n// where a host's screen tests run anyway.\nimport {\n\ttype MappingContent,\n\ttype MappingTestElement,\n\ttype MappingTestProblem,\n\tMappingTestRefusedError,\n\ttype MappingTestResult,\n} from \"../client/importhub-client\";\n\n/** The entities XML itself defines, which an Entity Set never replaces. */\nconst XML_ENTITIES = new Set([\"amp\", \"lt\", \"gt\", \"quot\", \"apos\"]);\n\n/** The sample with an Entity Set's entities replaced, as an Import reads it. */\nexport function withEntities(sample: string, entities: Record<string, string>): string {\n\treturn sample.replace(/&([A-Za-z_][\\w.-]*);/g, (whole, name: string) =>\n\t\t!XML_ENTITIES.has(name) && name in entities ? (entities[name] ?? whole) : whole,\n\t);\n}\n\nexport function runStubMappingTest(content: MappingContent, sample: string): MappingTestResult {\n\tif (typeof DOMParser === \"undefined\") {\n\t\tthrow new Error(\"the stub's Mapping Test reads the sample with the DOM: run it in a browser\");\n\t}\n\tconst doc = new DOMParser().parseFromString(sample, \"application/xml\");\n\tconst parseError = doc.getElementsByTagName(\"parsererror\")[0];\n\tif (parseError) {\n\t\tthrow new MappingTestRefusedError(\n\t\t\t`the sample is not XML: ${(parseError.textContent ?? \"\").split(\"\\n\")[0]}`,\n\t\t);\n\t}\n\tconst selector = content.elementSelector?.trim() ?? \"\";\n\tif (!selector) throw new MappingTestRefusedError(\"the Mapping has no element selector\");\n\n\tconst nodes = (() => {\n\t\ttry {\n\t\t\tconst r = doc.evaluate(selector, doc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);\n\t\t\treturn Array.from({ length: r.snapshotLength }, (_, i) => r.snapshotItem(i) as Node);\n\t\t} catch {\n\t\t\tthrow new MappingTestRefusedError(`the element selector ${selector} cannot be evaluated`);\n\t\t}\n\t})();\n\tconst keySelector = content.sourceKey?.selector?.trim() ?? \"\";\n\n\treturn {\n\t\telements: nodes.map((node, i): MappingTestElement => {\n\t\t\tconst problems: MappingTestProblem[] = [];\n\t\t\tlet sourceKey = \"\";\n\t\t\tif (keySelector) {\n\t\t\t\ttry {\n\t\t\t\t\tsourceKey = stringAt(doc, keySelector, node).trim();\n\t\t\t\t} catch {\n\t\t\t\t\tthrow new MappingTestRefusedError(`the Source Key ${keySelector} cannot be evaluated`);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!sourceKey) problems.push({ field: \"\", reason: \"the element has no Source Key\" });\n\t\t\tconst values = mapFields(doc, content.fields ?? [], node, \"\", problems);\n\t\t\treturn {\n\t\t\t\tposition: i + 1,\n\t\t\t\tsourceKey,\n\t\t\t\tvalues,\n\t\t\t\tfirstDay: \"\",\n\t\t\t\tlastDay: \"\",\n\t\t\t\treleaseSpec: {},\n\t\t\t\tdisplayName: \"\",\n\t\t\t\tcollections: [...(content.collections ?? [])],\n\t\t\t\tproblems,\n\t\t\t};\n\t\t}),\n\t};\n}\n\nfunction stringAt(doc: Document, xpath: string, context: Node): string {\n\treturn doc.evaluate(`string(${xpath})`, context, null, XPathResult.STRING_TYPE, null).stringValue;\n}\n\nfunction mapFields(\n\tdoc: Document,\n\tfields: ReadonlyArray<Record<string, unknown>>,\n\tcontext: Node,\n\tprefix: string,\n\tproblems: MappingTestProblem[],\n): Record<string, unknown> {\n\tconst out: Record<string, unknown> = {};\n\tfor (const f of fields) {\n\t\tconst name = typeof f.name === \"string\" ? f.name : \"\";\n\t\tif (!name) continue;\n\t\tconst path = prefix ? `${prefix}.${name}` : name;\n\t\tconst selector = typeof f.selector === \"string\" ? f.selector.trim() : \"\";\n\t\tif (f.type === \"fieldset\") {\n\t\t\tlet inner: Node | null = context;\n\t\t\tif (selector && selector !== \".\") {\n\t\t\t\ttry {\n\t\t\t\t\tinner = doc.evaluate(\n\t\t\t\t\t\tselector,\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t\tnull,\n\t\t\t\t\t\tXPathResult.FIRST_ORDERED_NODE_TYPE,\n\t\t\t\t\t\tnull,\n\t\t\t\t\t).singleNodeValue;\n\t\t\t\t} catch {\n\t\t\t\t\tinner = null;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!inner) {\n\t\t\t\tif (!f.optional) problems.push({ field: path, reason: `nothing at ${selector}` });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst children = Array.isArray(f.fields) ? (f.fields as Record<string, unknown>[]) : [];\n\t\t\tout[name] = mapFields(doc, children, inner, path, problems);\n\t\t\tcontinue;\n\t\t}\n\t\tif (!selector) {\n\t\t\tproblems.push({ field: path, reason: \"the field has no XPath\" });\n\t\t\tcontinue;\n\t\t}\n\t\tlet value: string;\n\t\ttry {\n\t\t\tvalue = stringAt(doc, selector, context).trim();\n\t\t} catch {\n\t\t\tproblems.push({ field: path, reason: `the XPath ${selector} cannot be evaluated` });\n\t\t\tcontinue;\n\t\t}\n\t\tif (!value) {\n\t\t\tif (!f.optional) problems.push({ field: path, reason: `nothing at ${selector}` });\n\t\t\tcontinue;\n\t\t}\n\t\tout[name] = value;\n\t}\n\treturn out;\n}\n","// An `ImporthubClient` over in-memory workspaces seeded from the fixtures.\n//\n// importhub takes the workspace from the caller's token, never from an\n// argument, so a real client answers for whichever workspace the host's\n// session is in. The stub does the same: it answers for its active\n// workspace, and a test switches it (`switchWorkspace`) where a host would\n// switch the token, which is how a host's test shows that switching reloads\n// the new workspace's data.\n//\n// It keeps importhub's rules a screen shows (internal/server's handlers):\n// validity reasons with their codes, a delete refused while Import Profiles\n// use the configuration, names unique per kind, a save on a draft that moved\n// refused, and the Blueprint Release check. Its messages are its own, not\n// importhub's.\n//\n// Typed as the whole interface, so a method added to `ImporthubClient`\n// without an answer here fails this package's typecheck, not a host's test.\nimport type {\n\tApiKey,\n\tConfigurationComparison,\n\tConfigurationKind,\n\tConfigurationReleaseRecord,\n\tConfigurationState,\n\tEntitySet,\n\tEntitySetContent,\n\tImport,\n\tImporthubClient,\n\tImportProfile,\n\tImportProfileContent,\n\tMapping,\n\tMappingContent,\n\tProcessor,\n\tProcessorStep,\n\tValidity,\n\tValidityReason,\n} from \"../client/importhub-client\";\nimport {\n\tAPI_KEY_NAME_MAX,\n\tConfigurationInUseError,\n\tMappingTestRefusedError,\n\tNameTakenError,\n\tReleaseRefusedError,\n\tStartRefusedError,\n} from \"../client/importhub-client\";\nimport type { ImporthubBlueprintField, ImporthubBlueprints } from \"../common/host\";\nimport { plainTextFields } from \"../screens/mapping-editor/field-tree\";\nimport {\n\tSTUB_USER_ID,\n\tSTUB_WORKSPACE_ID,\n\ttype StubBlueprintRelease,\n\ttype StubConfiguration,\n\ttype StubImport,\n\tstubApiKeys,\n\tstubBlueprintReleases,\n\tstubEntitySets,\n\tstubImportProfiles,\n\tstubImports,\n\tstubMappings,\n\tstubProcessors,\n} from \"./fixtures\";\nimport { runStubMappingTest, withEntities } from \"./mapping-test\";\n\n/** What one stub workspace holds. */\nexport interface StubWorkspace {\n\timportProfiles?: StubConfiguration<ImportProfileContent>[];\n\tmappings?: StubConfiguration<MappingContent>[];\n\tentitySets?: StubConfiguration<EntitySetContent>[];\n\t/** Its Imports, newest first, each with its Item Problems. */\n\timports?: StubImport[];\n\t/** Its importhub API keys, newest first. */\n\tapiKeys?: ApiKey[];\n}\n\n/** A contenthub right the stub viewer holds, which Start checks. */\nexport type StubContenthubRight = \"editor\" | \"publisher\";\n\nexport interface StubImporthubClientOptions {\n\t/**\n\t * The workspaces by id. Without it, the stub workspace holds the\n\t * fixtures' Import Profiles, Mappings and Entity Sets.\n\t */\n\tworkspaces?: Record<string, StubWorkspace>;\n\t/** The workspace answered for first; the stub workspace by default. */\n\tactiveWorkspaceId?: string;\n\t/** The Processor catalogue; the fixtures' by default. */\n\tprocessors?: Processor[];\n\t/** The Blueprint Releases blueprinthub knows; the fixtures' by default. */\n\tblueprintReleases?: StubBlueprintRelease[];\n\t/**\n\t * The contenthub rights the viewer holds, which Start checks\n\t * (start-an-import:AC4); both by default.\n\t */\n\tcontenthubRights?: StubContenthubRight[];\n\t/** Fail every upload with this error, as an unreachable blob store would. */\n\tuploadFails?: Error;\n\t/** Fail every call with this error, as an unreachable importhub would. */\n\tfail?: Error;\n}\n\nexport interface StubImporthubClient extends ImporthubClient {\n\t/** Answer for another workspace from now on, as a host's new token would. */\n\tswitchWorkspace(workspaceId: string): void;\n\t/**\n\t * Moves an Import on as importhub's worker would: a phase, progress,\n\t * counts, an Outcome. For tests that follow an Import while it runs.\n\t */\n\tupdateImport(id: string, patch: Partial<StubImport>): void;\n\t/** How many calls each method has answered, for tests that count reloads. */\n\treadonly calls: Readonly<Record<keyof ImporthubClient, number>>;\n}\n\n/** One saved Revision of a stored configuration. */\ninterface StoredRevision<C> {\n\tid: string;\n\tcontent: C;\n\tsavedBy: string;\n\tsavedAt: string;\n\t/** As decided at the save; a fixture's is decided when it is read. */\n\tvalidity?: Validity;\n\trestoredFromRevisionId: string;\n}\n\n/**\n * One stored configuration: every Revision, newest last (the draft), and\n * every Release, oldest first, as versionkit's linear mode keeps them.\n */\ninterface Stored<C> {\n\tid: string;\n\t/** The draft's content, which the screens' reads answer with. */\n\tcontent: C;\n\trevisions: StoredRevision<C>[];\n\treleases: ConfigurationReleaseRecord[];\n}\n\ninterface Workspace {\n\timportProfiles: Stored<ImportProfileContent>[];\n\tmappings: Stored<MappingContent>[];\n\tentitySets: Stored<EntitySetContent>[];\n\timports: StubImport[];\n\tapiKeys: ApiKey[];\n}\n\nconst METHODS: (keyof ImporthubClient)[] = [\n\t\"listImportProfiles\",\n\t\"getImportProfile\",\n\t\"createImportProfile\",\n\t\"updateImportProfile\",\n\t\"deleteImportProfile\",\n\t\"listProcessors\",\n\t\"listMappings\",\n\t\"getMapping\",\n\t\"createMapping\",\n\t\"updateMapping\",\n\t\"deleteMapping\",\n\t\"listMappingImportProfiles\",\n\t\"checkMappingBlueprintRelease\",\n\t\"runMappingTest\",\n\t\"listEntitySets\",\n\t\"getEntitySet\",\n\t\"createEntitySet\",\n\t\"updateEntitySet\",\n\t\"deleteEntitySet\",\n\t\"cutRelease\",\n\t\"listHistory\",\n\t\"compareRevisions\",\n\t\"restoreRevision\",\n\t\"uploadSourceFile\",\n\t\"startImport\",\n\t\"listImports\",\n\t\"getImport\",\n\t\"cancelImport\",\n\t\"listItemProblems\",\n\t\"listApiKeys\",\n\t\"createApiKey\",\n\t\"revokeApiKey\",\n];\n\n// A stub clock: each save and cut is an hour after the last, from the\n// fixtures' first save, so a history reads in order and tests stay stable.\nlet clock = Date.parse(\"2026-11-02T08:00:00Z\");\nconst tick = () => {\n\tclock += 3_600_000;\n\treturn new Date(clock).toISOString();\n};\n\n/**\n * A fixture as stored: released `releaseNumber` times, each Release cut\n * from a Revision of its own, the last of which is the draft; or one\n * unreleased Revision.\n */\nconst seed = <C>(items: StubConfiguration<C>[] = []): Stored<C>[] =>\n\titems.map((i) => {\n\t\tconst count = Math.max(i.releaseNumber ?? 0, 1);\n\t\tconst revisions = Array.from({ length: count }, (_, n) => ({\n\t\t\tid: `${i.id}_r${n + 1}`,\n\t\t\tcontent: structuredClone(i.content),\n\t\t\tsavedBy: STUB_USER_ID,\n\t\t\tsavedAt: tick(),\n\t\t\trestoredFromRevisionId: \"\",\n\t\t}));\n\t\tconst releases = Array.from({ length: i.releaseNumber ?? 0 }, (_, n) => ({\n\t\t\tid: `${i.id}_rel${n + 1}`,\n\t\t\tnumber: n + 1,\n\t\t\trevisionId: `${i.id}_r${n + 1}`,\n\t\t\treleasedBy: STUB_USER_ID,\n\t\t\treleasedAt: tick(),\n\t\t}));\n\t\treturn { id: i.id, content: structuredClone(i.content), revisions, releases };\n\t});\n\nconst draftOf = <C>(s: Stored<C>) => s.revisions[s.revisions.length - 1] as StoredRevision<C>;\nconst latestReleaseOf = <C>(s: Stored<C>) => s.releases[s.releases.length - 1];\n\nconst stateOf = <C>(s: Stored<C>): ConfigurationState => {\n\tconst latest = latestReleaseOf(s);\n\tconst released = s.revisions.find((r) => r.id === latest?.revisionId);\n\treturn {\n\t\tdraftRevisionId: draftOf(s).id,\n\t\t// By content, as importhub compares: a draft that restored the\n\t\t// released content does not differ.\n\t\tdraftDiffersFromRelease:\n\t\t\t!released || JSON.stringify(released.content) !== JSON.stringify(draftOf(s).content),\n\t\t...(latest ? { latestRelease: { id: latest.id, number: latest.number } } : {}),\n\t};\n};\n\n/** A content's top-level keys as importhub's comparison names them. */\nconst snake = (key: string) => key.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`);\nconst protoKeyed = (content: unknown): Record<string, unknown> =>\n\tObject.fromEntries(\n\t\tObject.entries(content as Record<string, unknown>).map(([k, v]) => [snake(k), v]),\n\t);\n\nconst validity = (reasons: ValidityReason[]): Validity => ({\n\tvalid: reasons.length === 0,\n\treasons,\n});\n\nconst byName = <T extends { content: { name: string } }>(items: T[]) =>\n\t[...items].sort((a, b) => a.content.name.localeCompare(b.content.name));\n\nlet created = 0;\n\nexport function createStubImporthubClient(\n\toptions: StubImporthubClientOptions = {},\n): StubImporthubClient {\n\tconst workspaces: Record<string, Workspace> = Object.fromEntries(\n\t\tObject.entries(\n\t\t\toptions.workspaces ?? {\n\t\t\t\t[STUB_WORKSPACE_ID]: {\n\t\t\t\t\timportProfiles: stubImportProfiles(),\n\t\t\t\t\tmappings: stubMappings(),\n\t\t\t\t\tentitySets: stubEntitySets(),\n\t\t\t\t\timports: stubImports(),\n\t\t\t\t\tapiKeys: stubApiKeys(),\n\t\t\t\t},\n\t\t\t},\n\t\t).map(([id, w]) => [\n\t\t\tid,\n\t\t\t{\n\t\t\t\timportProfiles: seed(w.importProfiles),\n\t\t\t\tmappings: seed(w.mappings),\n\t\t\t\tentitySets: seed(w.entitySets),\n\t\t\t\timports: structuredClone(w.imports ?? []),\n\t\t\t\tapiKeys: structuredClone(w.apiKeys ?? []),\n\t\t\t},\n\t\t]),\n\t);\n\tconst processors = options.processors ?? stubProcessors();\n\tconst releases = options.blueprintReleases ?? stubBlueprintReleases();\n\tlet active = options.activeWorkspaceId ?? STUB_WORKSPACE_ID;\n\tconst calls = Object.fromEntries(METHODS.map((m) => [m, 0])) as Record<\n\t\tkeyof ImporthubClient,\n\t\tnumber\n\t>;\n\tconst ws = (): Workspace => {\n\t\tworkspaces[active] ??= {\n\t\t\timportProfiles: [],\n\t\t\tmappings: [],\n\t\t\tentitySets: [],\n\t\t\timports: [],\n\t\t\tapiKeys: [],\n\t\t};\n\t\treturn workspaces[active];\n\t};\n\tconst answer = async <T>(method: keyof ImporthubClient, run: () => T): Promise<T> => {\n\t\tcalls[method]++;\n\t\tif (options.fail) throw options.fail;\n\t\treturn structuredClone(run());\n\t};\n\tconst find = <C>(items: Stored<C>[], id: string, kind: string): Stored<C> => {\n\t\tconst item = items.find((i) => i.id === id);\n\t\tif (!item) throw new Error(`${kind} ${id} not found`);\n\t\treturn item;\n\t};\n\tconst nameFree = <C extends { name: string }>(items: Stored<C>[], name: string, id?: string) => {\n\t\tif (!name.trim()) throw new Error(\"a name is required\");\n\t\tif (items.some((i) => i.id !== id && i.content.name === name)) throw new NameTakenError();\n\t};\n\tconst moved = <C>(item: Stored<C>, draftRevisionId: string) =>\n\t\tdraftRevisionId !== \"\" && draftRevisionId !== draftOf(item).id;\n\t/** Saves content as the item's new draft Revision. */\n\tconst save = <C>(\n\t\titem: Stored<C>,\n\t\tcontent: C,\n\t\tdraftRevisionId: string,\n\t\trestoredFromRevisionId = \"\",\n\t) => {\n\t\tif (moved(item, draftRevisionId)) {\n\t\t\tthrow new Error(\"the draft moved: somebody saved in between\");\n\t\t}\n\t\titem.content = structuredClone(content);\n\t\titem.revisions.push({\n\t\t\tid: `${item.id}_r${item.revisions.length + 1}`,\n\t\t\tcontent: structuredClone(content),\n\t\t\tsavedBy: STUB_USER_ID,\n\t\t\tsavedAt: tick(),\n\t\t\trestoredFromRevisionId,\n\t\t});\n\t};\n\t/** A new configuration, its content the first draft. */\n\tconst stored = <C>(prefix: string, content: C): Stored<C> => {\n\t\tconst id = newId(prefix);\n\t\treturn {\n\t\t\tid,\n\t\t\tcontent: structuredClone(content),\n\t\t\trevisions: [\n\t\t\t\t{\n\t\t\t\t\tid: `${id}_r1`,\n\t\t\t\t\tcontent: structuredClone(content),\n\t\t\t\t\tsavedBy: STUB_USER_ID,\n\t\t\t\t\tsavedAt: tick(),\n\t\t\t\t\trestoredFromRevisionId: \"\",\n\t\t\t\t},\n\t\t\t],\n\t\t\treleases: [],\n\t\t};\n\t};\n\n\tfunction mappingReasons(c: MappingContent): ValidityReason[] {\n\t\tconst out: ValidityReason[] = [];\n\t\tconst release = releases.find((r) => r.id === c.blueprintReleaseId);\n\t\tif (!c.blueprintReleaseId) {\n\t\t\tout.push({\n\t\t\t\tpath: \"/blueprintReleaseId\",\n\t\t\t\tcode: \"no_blueprint_release\",\n\t\t\t\tmessage: \"It pins no Blueprint Release.\",\n\t\t\t});\n\t\t} else if (!release) {\n\t\t\tout.push({\n\t\t\t\tpath: \"/blueprintReleaseId\",\n\t\t\t\tcode: \"blueprint_gone\",\n\t\t\t\tmessage: \"blueprinthub does not know the Blueprint Release it pins.\",\n\t\t\t});\n\t\t} else if (release.blueprintId !== c.blueprintId) {\n\t\t\tout.push({\n\t\t\t\tpath: \"/blueprintReleaseId\",\n\t\t\t\tcode: \"release_of_other_blueprint\",\n\t\t\t\tmessage: \"The pinned Release is of another Blueprint.\",\n\t\t\t});\n\t\t}\n\t\tif (!c.elementSelector) {\n\t\t\tout.push({\n\t\t\t\tpath: \"/elementSelector\",\n\t\t\t\tcode: \"no_element_selector\",\n\t\t\t\tmessage: \"It has no element selector.\",\n\t\t\t});\n\t\t}\n\t\tif (!c.sourceKey?.selector && !c.sourceKey?.template) {\n\t\t\tout.push({ path: \"/sourceKey\", code: \"no_source_key\", message: \"It has no Source Key.\" });\n\t\t}\n\t\tconst xpath = (path: string, expr: unknown) => {\n\t\t\tif (typeof expr === \"string\" && expr !== \"\" && !balanced(expr)) {\n\t\t\t\tout.push({ path, code: \"invalid_xpath\", message: `\"${expr}\" is not an XPath.` });\n\t\t\t}\n\t\t};\n\t\txpath(\"/element_selector\", c.elementSelector);\n\t\txpath(\"/source_key/selector\", c.sourceKey?.selector);\n\t\tconst mapped: string[] = [];\n\t\t(c.fields ?? []).forEach((f, i) => {\n\t\t\tconst at = `/fields/${i}`;\n\t\t\tfor (const { path, rel, mapping } of walk(f, \"\", at)) {\n\t\t\t\tmapped.push(path);\n\t\t\t\txpath(`${rel}/selector`, mapping.selector);\n\t\t\t\tif (release && !release.fieldPaths.includes(path)) {\n\t\t\t\t\tout.push({\n\t\t\t\t\t\tpath: at,\n\t\t\t\t\t\tcode: \"unknown_field_path\",\n\t\t\t\t\t\tmessage: `The pinned Release has no field ${path}.`,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tif (mapping.type === \"select\" && !mapping.selectOptions) {\n\t\t\t\t\tout.push({\n\t\t\t\t\t\tpath: at,\n\t\t\t\t\t\tcode: \"xmlmapper_schema\",\n\t\t\t\t\t\tmessage: `The select field ${path} has no select options.`,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\t(c.versionMatch?.contentFields ?? []).forEach((f, i) => {\n\t\t\tif (!mapped.includes(f)) {\n\t\t\t\tout.push({\n\t\t\t\t\tpath: `/version_match/content_fields/${i}`,\n\t\t\t\t\tcode: \"unknown_version_match_field\",\n\t\t\t\t\tmessage: `The Version Match compares ${f}, which the Mapping does not map.`,\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t\t(c.titleContributions ?? []).forEach((tc, i) => {\n\t\t\tif (!tc.selector || !tc.ausgabeCodeSelector) {\n\t\t\t\tout.push({\n\t\t\t\t\tpath: `/title_contributions/${i}`,\n\t\t\t\t\tcode: \"incomplete_title_contribution\",\n\t\t\t\t\tmessage: \"A Title Contribution needs a selector and an Ausgabe code selector.\",\n\t\t\t\t});\n\t\t\t}\n\t\t\txpath(`/title_contributions/${i}/selector`, tc.selector);\n\t\t});\n\t\t(c.placeholderAssets ?? []).forEach((pa, i) => {\n\t\t\tif (!pa.selector || !pa.assetType || !pa.keyParts?.length || !pa.nameSelector) {\n\t\t\t\tout.push({\n\t\t\t\t\tpath: `/placeholder_assets/${i}`,\n\t\t\t\t\tcode: \"incomplete_placeholder_assets\",\n\t\t\t\t\tmessage:\n\t\t\t\t\t\t\"Placeholder Assets need a selector, an asset type, the key's parts and a name selector.\",\n\t\t\t\t});\n\t\t\t}\n\t\t\txpath(`/placeholder_assets/${i}/selector`, pa.selector);\n\t\t\t(pa.keyParts ?? []).forEach((k, j) => {\n\t\t\t\txpath(`/placeholder_assets/${i}/key_parts/${j}`, k);\n\t\t\t});\n\t\t});\n\t\tout.push(...displayNameReasons(c, release?.fields, mapped));\n\t\treturn out;\n\t}\n\n\tfunction stepReasons(\n\t\tsteps: ProcessorStep[],\n\t\tlist: string,\n\t\tkind: Processor[\"kind\"],\n\t): ValidityReason[] {\n\t\treturn steps.flatMap((s, i): ValidityReason[] => {\n\t\t\tconst path = `/${list}/${i}`;\n\t\t\tconst p = processors.find((x) => x.name === s.processor);\n\t\t\tif (!p)\n\t\t\t\treturn [\n\t\t\t\t\t{ path, code: \"unknown_processor\", message: `No Processor is called ${s.processor}.` },\n\t\t\t\t];\n\t\t\tif (p.target !== \"source_file\") {\n\t\t\t\treturn [\n\t\t\t\t\t{\n\t\t\t\t\t\tpath,\n\t\t\t\t\t\tcode: \"rich_text_processor\",\n\t\t\t\t\t\tmessage: `${p.name} is configured on a rich-text field, not on a Profile.`,\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t}\n\t\t\tif (p.kind !== kind)\n\t\t\t\treturn [{ path, code: \"wrong_processor_kind\", message: `${p.name} does not run here.` }];\n\t\t\tconst missing = p.settingsSpec.filter(\n\t\t\t\t(f) => f.config.required && (s.settings[f.config.api_accessor] ?? \"\") === \"\",\n\t\t\t);\n\t\t\treturn missing.map((f) => ({\n\t\t\t\tpath: `${path}/settings/${f.config.api_accessor}`,\n\t\t\t\tcode: \"invalid_processor_settings\",\n\t\t\t\tmessage: `${p.name}: ${f.config.api_accessor} is required.`,\n\t\t\t}));\n\t\t});\n\t}\n\n\tfunction profileReasons(c: ImportProfileContent): ValidityReason[] {\n\t\tconst w = ws();\n\t\tconst out = [\n\t\t\t...stepReasons(c.preprocessors, \"preprocessors\", \"preprocessor\"),\n\t\t\t...stepReasons(c.postProcessors, \"postProcessors\", \"post_processor\"),\n\t\t];\n\t\tif (c.mappingIds.length === 0) {\n\t\t\tout.push({ path: \"/mappingIds\", code: \"no_mappings\", message: \"It includes no Mapping.\" });\n\t\t}\n\t\tc.mappingIds.forEach((id, i) => {\n\t\t\tconst m = w.mappings.find((x) => x.id === id);\n\t\t\tif (!m) {\n\t\t\t\tout.push({\n\t\t\t\t\tpath: `/mappingIds/${i}`,\n\t\t\t\t\tcode: \"mapping_missing\",\n\t\t\t\t\tmessage: \"It includes a Mapping that does not exist.\",\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst reasons = mappingReasons(m.content);\n\t\t\tif (reasons.length > 0) {\n\t\t\t\tout.push({\n\t\t\t\t\tpath: `/mappingIds/${i}`,\n\t\t\t\t\tcode: \"mapping_invalid\",\n\t\t\t\t\tmessage: `The Mapping ${m.content.name} is invalid: ${reasons.map((r) => r.message).join(\" \")}`,\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t\tif (c.entitySetId && !w.entitySets.some((e) => e.id === c.entitySetId)) {\n\t\t\tout.push({\n\t\t\t\tpath: \"/entitySetId\",\n\t\t\t\tcode: \"entity_set_missing\",\n\t\t\t\tmessage: \"It names an Entity Set that does not exist.\",\n\t\t\t});\n\t\t}\n\t\treturn out;\n\t}\n\n\tconst entitySetReasons = (c: EntitySetContent): ValidityReason[] =>\n\t\tObject.keys(c.entities).length === 0\n\t\t\t? [{ path: \"/entities\", code: \"no_entities\", message: \"It defines no entity.\" }]\n\t\t\t: [];\n\n\tconst profileOf = (s: Stored<ImportProfileContent>): ImportProfile => ({\n\t\tid: s.id,\n\t\tcontent: s.content,\n\t\tvalidity: validity(profileReasons(s.content)),\n\t\tstate: stateOf(s),\n\t});\n\tconst mappingOf = (s: Stored<MappingContent>): Mapping => ({\n\t\tid: s.id,\n\t\tcontent: s.content,\n\t\tvalidity: validity(mappingReasons(s.content)),\n\t\tstate: stateOf(s),\n\t});\n\tconst entitySetOf = (s: Stored<EntitySetContent>): EntitySet => ({\n\t\tid: s.id,\n\t\tcontent: s.content,\n\t\tvalidity: validity(entitySetReasons(s.content)),\n\t\tstate: stateOf(s),\n\t});\n\tconst profilesUsing = (uses: (c: ImportProfileContent) => boolean) =>\n\t\tbyName(ws().importProfiles.filter((p) => uses(p.content))).map((p) => ({\n\t\t\tid: p.id,\n\t\t\tname: p.content.name,\n\t\t}));\n\tconst newId = (prefix: string) => `${prefix}_stub_new_${++created}`;\n\n\t// Each kind's items and rules, for the calls every kind shares.\n\tconst ofKind = (kind: ConfigurationKind) => {\n\t\tconst w = ws();\n\t\tswitch (kind) {\n\t\t\tcase \"importProfile\":\n\t\t\t\treturn {\n\t\t\t\t\titems: w.importProfiles as Stored<unknown>[],\n\t\t\t\t\tname: \"Import Profile\",\n\t\t\t\t\treasons: (c: unknown) => profileReasons(c as ImportProfileContent),\n\t\t\t\t};\n\t\t\tcase \"mapping\":\n\t\t\t\treturn {\n\t\t\t\t\titems: w.mappings as Stored<unknown>[],\n\t\t\t\t\tname: \"Mapping\",\n\t\t\t\t\treasons: (c: unknown) => mappingReasons(c as MappingContent),\n\t\t\t\t};\n\t\t\tcase \"entitySet\":\n\t\t\t\treturn {\n\t\t\t\t\titems: w.entitySets as Stored<unknown>[],\n\t\t\t\t\tname: \"Entity Set\",\n\t\t\t\t\treasons: (c: unknown) => entitySetReasons(c as EntitySetContent),\n\t\t\t\t};\n\t\t}\n\t};\n\t/** The draft's validity, decided as a save decides it. */\n\tconst decide = (kind: ConfigurationKind, item: Stored<unknown>) => {\n\t\tdraftOf(item).validity = validity(ofKind(kind).reasons(item.content));\n\t};\n\tconst revisionIn = (item: Stored<unknown>, revisionId: string) => {\n\t\tconst r = item.revisions.find((x) => x.id === revisionId);\n\t\tif (!r) throw new Error(`Revision ${revisionId} not found`);\n\t\treturn r;\n\t};\n\n\t// The Source Files uploaded, by id: Start reads only those.\n\tconst sourceFiles = new Set<string>();\n\tconst rights = options.contenthubRights ?? [\"editor\", \"publisher\"];\n\tconst findImport = (id: string): StubImport => {\n\t\tconst im = ws().imports.find((i) => i.id === id);\n\t\tif (!im) throw new Error(`Import ${id} not found`);\n\t\treturn im;\n\t};\n\t/**\n\t * What the worker does to an Import somebody asked to cancel: it stops at\n\t * its next item, which in the stub is the next read.\n\t */\n\tconst settle = (im: StubImport) => {\n\t\tif (im.cancelledBy && im.phase !== \"ended\") {\n\t\t\tim.phase = \"ended\";\n\t\t\tim.outcome = \"cancelled\";\n\t\t\tim.endTime = tick();\n\t\t}\n\t};\n\tconst importOf = ({ itemProblems: _, ...im }: StubImport): Import => im;\n\t/** The latest Release of a configuration, as Start pins it; refused when there is none. */\n\tconst pinned = <C extends { name: string }>(item: Stored<C>, kind: string) => {\n\t\tconst latest = latestReleaseOf(item);\n\t\tif (!latest) {\n\t\t\tthrow new StartRefusedError(`the ${kind} ${item.content.name} has no Release yet`);\n\t\t}\n\t\tconst content = item.revisions.find((r) => r.id === latest.revisionId)?.content ?? item.content;\n\t\treturn {\n\t\t\tcontent,\n\t\t\tref: {\n\t\t\t\tconfigurationId: item.id,\n\t\t\t\tname: content.name,\n\t\t\t\treleaseId: latest.id,\n\t\t\t\tnumber: latest.number,\n\t\t\t},\n\t\t};\n\t};\n\n\treturn {\n\t\tcalls,\n\t\tswitchWorkspace(workspaceId) {\n\t\t\tactive = workspaceId;\n\t\t},\n\t\tupdateImport(id, patch) {\n\t\t\tObject.assign(findImport(id), structuredClone(patch));\n\t\t},\n\n\t\tlistImportProfiles: () =>\n\t\t\tanswer(\"listImportProfiles\", () => byName(ws().importProfiles).map(profileOf)),\n\t\tgetImportProfile: (id) =>\n\t\t\tanswer(\"getImportProfile\", () => profileOf(find(ws().importProfiles, id, \"Import Profile\"))),\n\t\tcreateImportProfile: (content) =>\n\t\t\tanswer(\"createImportProfile\", () => {\n\t\t\t\tnameFree(ws().importProfiles, content.name);\n\t\t\t\tconst s = stored(\"ip\", content);\n\t\t\t\tdecide(\"importProfile\", s);\n\t\t\t\tws().importProfiles.push(s);\n\t\t\t\treturn profileOf(s);\n\t\t\t}),\n\t\tupdateImportProfile: (id, content, draftRevisionId) =>\n\t\t\tanswer(\"updateImportProfile\", () => {\n\t\t\t\tconst s = find(ws().importProfiles, id, \"Import Profile\");\n\t\t\t\tnameFree(ws().importProfiles, content.name, id);\n\t\t\t\tsave(s, content, draftRevisionId);\n\t\t\t\tdecide(\"importProfile\", s);\n\t\t\t\treturn profileOf(s);\n\t\t\t}),\n\t\tdeleteImportProfile: (id) =>\n\t\t\tanswer(\"deleteImportProfile\", () => {\n\t\t\t\tfind(ws().importProfiles, id, \"Import Profile\");\n\t\t\t\tws().importProfiles = ws().importProfiles.filter((p) => p.id !== id);\n\t\t\t}),\n\n\t\tlistProcessors: () =>\n\t\t\tanswer(\"listProcessors\", () => [...processors].sort((a, b) => a.name.localeCompare(b.name))),\n\n\t\tlistMappings: () => answer(\"listMappings\", () => byName(ws().mappings).map(mappingOf)),\n\t\tgetMapping: (id) => answer(\"getMapping\", () => mappingOf(find(ws().mappings, id, \"Mapping\"))),\n\t\tcreateMapping: (content) =>\n\t\t\tanswer(\"createMapping\", () => {\n\t\t\t\tnameFree(ws().mappings, content.name);\n\t\t\t\tconst s = stored(\"mp\", content);\n\t\t\t\tdecide(\"mapping\", s);\n\t\t\t\tws().mappings.push(s);\n\t\t\t\treturn mappingOf(s);\n\t\t\t}),\n\t\tupdateMapping: (id, content, draftRevisionId) =>\n\t\t\tanswer(\"updateMapping\", () => {\n\t\t\t\tconst s = find(ws().mappings, id, \"Mapping\");\n\t\t\t\tnameFree(ws().mappings, content.name, id);\n\t\t\t\tsave(s, content, draftRevisionId);\n\t\t\t\tdecide(\"mapping\", s);\n\t\t\t\treturn mappingOf(s);\n\t\t\t}),\n\t\tdeleteMapping: (id) =>\n\t\t\tanswer(\"deleteMapping\", () => {\n\t\t\t\tfind(ws().mappings, id, \"Mapping\");\n\t\t\t\tconst using = profilesUsing((c) => c.mappingIds.includes(id));\n\t\t\t\tif (using.length > 0) {\n\t\t\t\t\tthrow new ConfigurationInUseError(\n\t\t\t\t\t\tusing,\n\t\t\t\t\t\t`the Mapping is included by ${using.map((p) => p.name).join(\", \")}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tws().mappings = ws().mappings.filter((m) => m.id !== id);\n\t\t\t}),\n\t\tlistMappingImportProfiles: (id) =>\n\t\t\tanswer(\"listMappingImportProfiles\", () => {\n\t\t\t\tfind(ws().mappings, id, \"Mapping\");\n\t\t\t\treturn profilesUsing((c) => c.mappingIds.includes(id));\n\t\t\t}),\n\t\tcheckMappingBlueprintRelease: (id, blueprintReleaseId) =>\n\t\t\tanswer(\"checkMappingBlueprintRelease\", () => {\n\t\t\t\tconst m = find(ws().mappings, id, \"Mapping\");\n\t\t\t\tconst release = releases.find((r) => r.id === blueprintReleaseId);\n\t\t\t\tif (!release) throw new Error(`Blueprint Release ${blueprintReleaseId} not found`);\n\t\t\t\tif (release.blueprintId !== m.content.blueprintId) {\n\t\t\t\t\tthrow new Error(\"the Release is of another Blueprint\");\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tblueprintId: release.blueprintId,\n\t\t\t\t\tmissingFieldPaths: (m.content.fields ?? [])\n\t\t\t\t\t\t.flatMap((f, i) => walk(f, \"\", `/fields/${i}`).map((w) => w.path))\n\t\t\t\t\t\t.filter((path) => !release.fieldPaths.includes(path)),\n\t\t\t\t\tmissingReleaseSpecFields: [\n\t\t\t\t\t\t...(m.content.releaseSpec ?? []).map((r) => r.field ?? \"\"),\n\t\t\t\t\t\t...(m.content.versionMatch?.releaseSpecFields ?? []),\n\t\t\t\t\t].filter(\n\t\t\t\t\t\t(f, i, all) =>\n\t\t\t\t\t\t\tf !== \"\" &&\n\t\t\t\t\t\t\tall.indexOf(f) === i &&\n\t\t\t\t\t\t\t!(release.releaseSpecFields ?? []).some((r) => r.path === f),\n\t\t\t\t\t),\n\t\t\t\t};\n\t\t\t}),\n\n\t\trunMappingTest: ({ content, sample, entitySetId }) =>\n\t\t\tanswer(\"runMappingTest\", () => {\n\t\t\t\tlet text = new TextDecoder().decode(sample);\n\t\t\t\tif (entitySetId) {\n\t\t\t\t\t// The Entity Set's draft, as importhub reads it for a test.\n\t\t\t\t\tconst es = ws().entitySets.find((e) => e.id === entitySetId);\n\t\t\t\t\tif (!es) throw new MappingTestRefusedError(`Entity Set ${entitySetId} not found`);\n\t\t\t\t\ttext = withEntities(text, es.content.entities);\n\t\t\t\t}\n\t\t\t\treturn runStubMappingTest(content, text);\n\t\t\t}),\n\n\t\tlistEntitySets: () => answer(\"listEntitySets\", () => byName(ws().entitySets).map(entitySetOf)),\n\t\tgetEntitySet: (id) =>\n\t\t\tanswer(\"getEntitySet\", () => entitySetOf(find(ws().entitySets, id, \"Entity Set\"))),\n\t\tcreateEntitySet: (content) =>\n\t\t\tanswer(\"createEntitySet\", () => {\n\t\t\t\tnameFree(ws().entitySets, content.name);\n\t\t\t\tconst s = stored(\"es\", content);\n\t\t\t\tdecide(\"entitySet\", s);\n\t\t\t\tws().entitySets.push(s);\n\t\t\t\treturn entitySetOf(s);\n\t\t\t}),\n\t\tupdateEntitySet: (id, content, draftRevisionId) =>\n\t\t\tanswer(\"updateEntitySet\", () => {\n\t\t\t\tconst s = find(ws().entitySets, id, \"Entity Set\");\n\t\t\t\tnameFree(ws().entitySets, content.name, id);\n\t\t\t\tsave(s, content, draftRevisionId);\n\t\t\t\tdecide(\"entitySet\", s);\n\t\t\t\treturn entitySetOf(s);\n\t\t\t}),\n\t\tdeleteEntitySet: (id) =>\n\t\t\tanswer(\"deleteEntitySet\", () => {\n\t\t\t\tfind(ws().entitySets, id, \"Entity Set\");\n\t\t\t\tconst using = profilesUsing((c) => c.entitySetId === id);\n\t\t\t\tif (using.length > 0) {\n\t\t\t\t\tthrow new ConfigurationInUseError(\n\t\t\t\t\t\tusing,\n\t\t\t\t\t\t`the Entity Set is named by ${using.map((p) => p.name).join(\", \")}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tws().entitySets = ws().entitySets.filter((e) => e.id !== id);\n\t\t\t}),\n\n\t\tcutRelease: (kind, id, draftRevisionId) =>\n\t\t\tanswer(\"cutRelease\", () => {\n\t\t\t\tconst k = ofKind(kind);\n\t\t\t\tconst item = find(k.items, id, k.name);\n\t\t\t\tif (moved(item, draftRevisionId)) {\n\t\t\t\t\tthrow new ReleaseRefusedError(\"the draft moved: somebody saved in between\");\n\t\t\t\t}\n\t\t\t\t// Valid now, as importhub decides it again at the cut.\n\t\t\t\tconst now = validity(k.reasons(item.content));\n\t\t\t\tif (!now.valid) throw new ReleaseRefusedError(\"the draft is invalid\", now);\n\t\t\t\tif (!stateOf(item).draftDiffersFromRelease) {\n\t\t\t\t\tthrow new ReleaseRefusedError(\n\t\t\t\t\t\t\"the draft does not differ from the latest Release: there is nothing to release\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst number = item.releases.length + 1;\n\t\t\t\tconst release: ConfigurationReleaseRecord = {\n\t\t\t\t\tid: `${item.id}_rel${number}`,\n\t\t\t\t\tnumber,\n\t\t\t\t\trevisionId: draftOf(item).id,\n\t\t\t\t\treleasedBy: STUB_USER_ID,\n\t\t\t\t\treleasedAt: tick(),\n\t\t\t\t};\n\t\t\t\titem.releases.push(release);\n\t\t\t\treturn {\n\t\t\t\t\trelease,\n\t\t\t\t\timportProfiles: kind === \"mapping\" ? profilesUsing((c) => c.mappingIds.includes(id)) : [],\n\t\t\t\t};\n\t\t\t}),\n\t\tlistHistory: (kind, id, pageToken) =>\n\t\t\tanswer(\"listHistory\", () => {\n\t\t\t\tconst k = ofKind(kind);\n\t\t\t\tconst item = find(k.items, id, k.name);\n\t\t\t\t// Pages of ten, newest first; the token is the next page's offset.\n\t\t\t\tconst newest = [...item.revisions].reverse();\n\t\t\t\tconst from = Number(pageToken || \"0\");\n\t\t\t\tconst page = newest.slice(from, from + 10);\n\t\t\t\treturn {\n\t\t\t\t\trevisions: page.map((r) => ({\n\t\t\t\t\t\tid: r.id,\n\t\t\t\t\t\tsavedBy: r.savedBy,\n\t\t\t\t\t\tsavedAt: r.savedAt,\n\t\t\t\t\t\tvalidity: r.validity ?? validity(k.reasons(r.content)),\n\t\t\t\t\t\trestoredFromRevisionId: r.restoredFromRevisionId,\n\t\t\t\t\t})),\n\t\t\t\t\treleases: [...item.releases].reverse(),\n\t\t\t\t\tnextPageToken: from + 10 < newest.length ? String(from + 10) : \"\",\n\t\t\t\t};\n\t\t\t}),\n\t\tcompareRevisions: (kind, id, fromRevisionId, toRevisionId) =>\n\t\t\tanswer(\"compareRevisions\", (): ConfigurationComparison => {\n\t\t\t\tconst k = ofKind(kind);\n\t\t\t\tconst item = find(k.items, id, k.name);\n\t\t\t\tconst from = protoKeyed(revisionIn(item, fromRevisionId).content);\n\t\t\t\tconst to = protoKeyed(revisionIn(item, toRevisionId).content);\n\t\t\t\tconst fields = [...new Set([...Object.keys(from), ...Object.keys(to)])].map((field) => {\n\t\t\t\t\tconst a = from[field];\n\t\t\t\t\tconst b = to[field];\n\t\t\t\t\tconst status =\n\t\t\t\t\t\ta === undefined && b !== undefined\n\t\t\t\t\t\t\t? (\"added\" as const)\n\t\t\t\t\t\t\t: a !== undefined && b === undefined\n\t\t\t\t\t\t\t\t? (\"removed\" as const)\n\t\t\t\t\t\t\t\t: JSON.stringify(a) === JSON.stringify(b)\n\t\t\t\t\t\t\t\t\t? (\"unchanged\" as const)\n\t\t\t\t\t\t\t\t\t: (\"changed\" as const);\n\t\t\t\t\treturn { field, status };\n\t\t\t\t});\n\t\t\t\treturn {\n\t\t\t\t\tfrom: { revisionId: fromRevisionId, content: from },\n\t\t\t\t\tto: { revisionId: toRevisionId, content: to },\n\t\t\t\t\tfields,\n\t\t\t\t};\n\t\t\t}),\n\t\trestoreRevision: (kind, id, revisionId, draftRevisionId) =>\n\t\t\tanswer(\"restoreRevision\", () => {\n\t\t\t\tconst k = ofKind(kind);\n\t\t\t\tconst item = find(k.items, id, k.name);\n\t\t\t\tsave(item, revisionIn(item, revisionId).content, draftRevisionId, revisionId);\n\t\t\t\tdecide(kind, item);\n\t\t\t}),\n\n\t\tasync uploadSourceFile(file, onProgress) {\n\t\t\tcalls.uploadSourceFile++;\n\t\t\tif (options.fail) throw options.fail;\n\t\t\t// A few steps apart, so a screen shows the bar move.\n\t\t\tfor (const f of [0.25, 0.5, 0.75]) {\n\t\t\t\tawait new Promise((r) => setTimeout(r, 20));\n\t\t\t\tonProgress(f);\n\t\t\t}\n\t\t\tif (options.uploadFails) throw options.uploadFails;\n\t\t\tonProgress(1);\n\t\t\tconst id = newId(\"sf\");\n\t\t\tsourceFiles.add(id);\n\t\t\treturn { id, fileName: file.name };\n\t\t},\n\t\tstartImport: (input) =>\n\t\t\tanswer(\"startImport\", () => {\n\t\t\t\tconst w = ws();\n\t\t\t\tconst profile = find(w.importProfiles, input.importProfileId, \"Import Profile\");\n\t\t\t\tif (!sourceFiles.has(input.sourceFileId)) {\n\t\t\t\t\tthrow new StartRefusedError(\"nothing was uploaded to the Source File\");\n\t\t\t\t}\n\t\t\t\t// importhub's order: the rights first, then what would run.\n\t\t\t\tif (!rights.includes(\"editor\")) {\n\t\t\t\t\tthrow new StartRefusedError(\n\t\t\t\t\t\t\"starting an Import needs contenthub editor in the workspace\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst p = pinned(profile, \"Import Profile\");\n\t\t\t\tif (p.content.autoPublish && !rights.includes(\"publisher\")) {\n\t\t\t\t\tthrow new StartRefusedError(\n\t\t\t\t\t\t\"the Import Profile has Auto-publish, which needs contenthub publisher\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst reasons = profileReasons(p.content);\n\t\t\t\tif (reasons.length > 0) {\n\t\t\t\t\tthrow new StartRefusedError(\n\t\t\t\t\t\t`the Import Profile ${p.ref.name} is invalid: ${reasons.map((r) => r.message).join(\" \")}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst mappings = p.content.mappingIds.map(\n\t\t\t\t\t(id) => pinned(find(w.mappings, id, \"Mapping\"), \"Mapping\").ref,\n\t\t\t\t);\n\t\t\t\tconst entitySet = p.content.entitySetId\n\t\t\t\t\t? pinned(find(w.entitySets, p.content.entitySetId, \"Entity Set\"), \"Entity Set\").ref\n\t\t\t\t\t: undefined;\n\t\t\t\tconst im: StubImport = {\n\t\t\t\t\tid: newId(\"im\"),\n\t\t\t\t\timportProfileId: profile.id,\n\t\t\t\t\timportProfileName: p.ref.name,\n\t\t\t\t\tsourceFileId: input.sourceFileId,\n\t\t\t\t\tstartedBy: STUB_USER_ID,\n\t\t\t\t\tphase: \"queued\",\n\t\t\t\t\tfailureReason: \"\",\n\t\t\t\t\tprogress: { done: 0, total: 0 },\n\t\t\t\t\tcounts: {\n\t\t\t\t\t\tmatched: 0,\n\t\t\t\t\t\tcreated: 0,\n\t\t\t\t\t\tproblems: 0,\n\t\t\t\t\t\tplanned: 0,\n\t\t\t\t\t\tcorrected: 0,\n\t\t\t\t\t\tkept: 0,\n\t\t\t\t\t\tunchanged: 0,\n\t\t\t\t\t},\n\t\t\t\t\tchangeSetId: \"\",\n\t\t\t\t\treleases: {\n\t\t\t\t\t\timportProfile: p.ref,\n\t\t\t\t\t\tmappings,\n\t\t\t\t\t\t...(entitySet ? { entitySet } : {}),\n\t\t\t\t\t},\n\t\t\t\t\tcreateTime: tick(),\n\t\t\t\t\tstartTime: \"\",\n\t\t\t\t\tendTime: \"\",\n\t\t\t\t\tcancelledBy: \"\",\n\t\t\t\t\teffectiveDate: input.effectiveDate ?? \"\",\n\t\t\t\t\t...(input.source ? { source: input.source } : {}),\n\t\t\t\t\titemProblems: [],\n\t\t\t\t};\n\t\t\t\tw.imports.unshift(im);\n\t\t\t\treturn importOf(im);\n\t\t\t}),\n\t\tlistImports: (pageToken) =>\n\t\t\tanswer(\"listImports\", () => {\n\t\t\t\t// Pages of fifty, newest first; the token is the next page's offset.\n\t\t\t\tconst all = ws().imports;\n\t\t\t\tall.forEach(settle);\n\t\t\t\tconst from = Number(pageToken || \"0\");\n\t\t\t\treturn {\n\t\t\t\t\timports: all.slice(from, from + 50).map(importOf),\n\t\t\t\t\tnextPageToken: from + 50 < all.length ? String(from + 50) : \"\",\n\t\t\t\t};\n\t\t\t}),\n\t\tgetImport: (id) =>\n\t\t\tanswer(\"getImport\", () => {\n\t\t\t\tconst im = findImport(id);\n\t\t\t\tsettle(im);\n\t\t\t\treturn importOf(im);\n\t\t\t}),\n\t\tcancelImport: (id) =>\n\t\t\tanswer(\"cancelImport\", () => {\n\t\t\t\tconst im = findImport(id);\n\t\t\t\tif (im.phase === \"ended\") throw new Error(\"the Import has ended\");\n\t\t\t\tim.cancelledBy ||= STUB_USER_ID;\n\t\t\t\t// A queued Import ends at once; a running one at its next item.\n\t\t\t\tif (im.phase === \"queued\") settle(im);\n\t\t\t\treturn importOf(im);\n\t\t\t}),\n\t\tlistItemProblems: (importId, filter) =>\n\t\t\tanswer(\"listItemProblems\", () => {\n\t\t\t\tconst all = findImport(importId).itemProblems ?? [];\n\t\t\t\tconst query = filter.sourceKeyQuery.toLowerCase();\n\t\t\t\tconst matching = all.filter(\n\t\t\t\t\t(p) =>\n\t\t\t\t\t\t(!filter.mappingId || p.mappingId === filter.mappingId) &&\n\t\t\t\t\t\tp.sourceKey.toLowerCase().includes(query),\n\t\t\t\t);\n\t\t\t\tconst counts = new Map<string, { mappingId: string; mappingName: string; count: number }>();\n\t\t\t\tfor (const p of all) {\n\t\t\t\t\tconst c = counts.get(p.mappingId) ?? {\n\t\t\t\t\t\tmappingId: p.mappingId,\n\t\t\t\t\t\tmappingName: p.mappingName,\n\t\t\t\t\t\tcount: 0,\n\t\t\t\t\t};\n\t\t\t\t\tc.count++;\n\t\t\t\t\tcounts.set(p.mappingId, c);\n\t\t\t\t}\n\t\t\t\tconst from = Number(filter.pageToken || \"0\");\n\t\t\t\treturn {\n\t\t\t\t\titemProblems: matching.slice(from, from + 50),\n\t\t\t\t\ttotalCount: all.length,\n\t\t\t\t\tmatchingCount: matching.length,\n\t\t\t\t\tmappings: [...counts.values()].sort((a, b) => a.mappingName.localeCompare(b.mappingName)),\n\t\t\t\t\tnextPageToken: from + 50 < matching.length ? String(from + 50) : \"\",\n\t\t\t\t};\n\t\t\t}),\n\n\t\tlistApiKeys: () => answer(\"listApiKeys\", () => ws().apiKeys),\n\t\tcreateApiKey: (input) =>\n\t\t\tanswer(\"createApiKey\", () => {\n\t\t\t\t// CreateAPIKey's rules: a name, not too long, and an expiry ahead.\n\t\t\t\tconst name = input.name.trim();\n\t\t\t\tif (!name) throw new Error(\"a name is required\");\n\t\t\t\tif (name.length > API_KEY_NAME_MAX) {\n\t\t\t\t\tthrow new Error(`the name is longer than ${API_KEY_NAME_MAX} characters`);\n\t\t\t\t}\n\t\t\t\tconst expireTime = input.expireTime ? new Date(input.expireTime).toISOString() : \"\";\n\t\t\t\tif (expireTime && Date.parse(expireTime) <= Date.now()) {\n\t\t\t\t\tthrow new Error(\"the expiry must lie in the future\");\n\t\t\t\t}\n\t\t\t\tconst n = ++created;\n\t\t\t\tconst apiKey: ApiKey = {\n\t\t\t\t\tid: `key_stub_new_${n}`,\n\t\t\t\t\tname,\n\t\t\t\t\tkeyPrefix: `ihk_n${String(n).padStart(3, \"0\")}`,\n\t\t\t\t\towner: STUB_USER_ID,\n\t\t\t\t\texpireTime,\n\t\t\t\t\tcreateTime: new Date().toISOString(),\n\t\t\t\t};\n\t\t\t\tws().apiKeys.unshift(apiKey);\n\t\t\t\t// The secret is returned here and kept nowhere, as importhub keeps it.\n\t\t\t\treturn { apiKey, secret: `${apiKey.keyPrefix}_stub_secret_${n}` };\n\t\t\t}),\n\t\trevokeApiKey: (id) =>\n\t\t\tanswer(\"revokeApiKey\", () => {\n\t\t\t\tconst w = ws();\n\t\t\t\tif (!w.apiKeys.some((k) => k.id === id)) throw new Error(`API key ${id} not found`);\n\t\t\t\tw.apiKeys = w.apiKeys.filter((k) => k.id !== id);\n\t\t\t}),\n\t};\n}\n\n/**\n * Whether an XPath's brackets and parentheses pair up: the stub's stand-in\n * for importhub's XPath check, enough to show a reason at its field.\n */\nfunction balanced(expr: string): boolean {\n\tconst open: string[] = [];\n\tconst pairs: Record<string, string> = { \"]\": \"[\", \")\": \"(\" };\n\tfor (const ch of expr) {\n\t\tif (ch === \"[\" || ch === \"(\") open.push(ch);\n\t\telse if (ch in pairs && open.pop() !== pairs[ch]) return false;\n\t}\n\treturn open.length === 0;\n}\n\n/** A field mapping and its children, each with its field path and pointer. */\nfunction walk(\n\tmapping: Record<string, unknown>,\n\tprefix: string,\n\tat: string,\n): { path: string; rel: string; mapping: Record<string, unknown> }[] {\n\tconst path = `${prefix}${String(mapping.name ?? \"\")}`;\n\treturn [\n\t\t{ path, rel: at, mapping },\n\t\t...([\"fields\", \"virtualTableFields\"] as const).flatMap((key) =>\n\t\t\t(Array.isArray(mapping[key]) ? (mapping[key] as Record<string, unknown>[]) : []).flatMap(\n\t\t\t\t(child, j) => walk(child, `${path}.`, `${at}/${key}/${j}`),\n\t\t\t),\n\t\t),\n\t];\n}\n\n/**\n * An `ImporthubBlueprints` over the stub's Blueprint Releases, for a host's\n * `ImporthubHost.blueprints` in tests.\n */\nexport function createStubBlueprints(\n\tblueprintReleases: StubBlueprintRelease[] = stubBlueprintReleases(),\n): ImporthubBlueprints {\n\treturn {\n\t\tasync listBlueprints() {\n\t\t\tconst byId = new Map(blueprintReleases.map((r) => [r.blueprintId, r.blueprintName]));\n\t\t\treturn [...byId]\n\t\t\t\t.map(([id, name]) => ({ id, name }))\n\t\t\t\t.sort((a, b) => a.name.localeCompare(b.name));\n\t\t},\n\t\tasync listReleases(blueprintId) {\n\t\t\treturn blueprintReleases\n\t\t\t\t.filter((r) => r.blueprintId === blueprintId)\n\t\t\t\t.map((r) => ({ id: r.id, label: r.label }));\n\t\t},\n\t\tasync getRelease(releaseId) {\n\t\t\tconst r = blueprintReleases.find((x) => x.id === releaseId);\n\t\t\tif (!r) throw new Error(`Blueprint Release ${releaseId} not found`);\n\t\t\treturn {\n\t\t\t\tid: r.id,\n\t\t\t\tblueprintId: r.blueprintId,\n\t\t\t\tname: r.label,\n\t\t\t\tfields:\n\t\t\t\t\tr.fields ??\n\t\t\t\t\tr.fieldPaths.map((path) => ({\n\t\t\t\t\t\taccessor: path,\n\t\t\t\t\t\tpath,\n\t\t\t\t\t\tfieldType: \"text\",\n\t\t\t\t\t\tlabel: \"\",\n\t\t\t\t\t\tchildren: [],\n\t\t\t\t\t})),\n\t\t\t\treleaseSpecFields: r.releaseSpecFields ?? [],\n\t\t\t};\n\t\t},\n\t};\n}\n\n/**\n * The display name's reasons, as importhub's checkDisplayName gives them\n * (internal/configstore/mapping.go): template and field set together, the\n * field a plain-text one of the pinned Release that no field mapping writes.\n */\nfunction displayNameReasons(\n\tc: MappingContent,\n\ttree: ImporthubBlueprintField[] | undefined,\n\tmapped: string[],\n): ValidityReason[] {\n\tconst template = (c.displayNameTemplate ?? \"\").trim();\n\tconst field = (c.displayNameField ?? \"\").trim();\n\tconst reason = (path: string, code: string, message: string): ValidityReason[] => [\n\t\t{ path, code, message },\n\t];\n\tif (!template && !field) return [];\n\tif (!field) {\n\t\treturn reason(\n\t\t\t\"/display_name_field\",\n\t\t\t\"incomplete_display_name\",\n\t\t\t\"the display-name template names no field to write the display name into\",\n\t\t);\n\t}\n\tif (!template) {\n\t\treturn reason(\n\t\t\t\"/display_name_template\",\n\t\t\t\"incomplete_display_name\",\n\t\t\t`the display-name field \"${field}\" has no display-name template to fill it`,\n\t\t);\n\t}\n\tif (!tree) return [];\n\tconst paths = (fs: ImporthubBlueprintField[]): string[] =>\n\t\tfs.flatMap((f) => [f.path, ...paths(f.children)]);\n\tif (!paths(tree).includes(field)) {\n\t\treturn reason(\n\t\t\t\"/display_name_field\",\n\t\t\t\"unknown_display_name_field\",\n\t\t\t`the Blueprint Release has no field \"${field}\" to write the display name into`,\n\t\t);\n\t}\n\tif (!plainTextFields(tree).some((f) => f.path === field)) {\n\t\treturn reason(\n\t\t\t\"/display_name_field\",\n\t\t\t\"display_name_field_not_plain_text\",\n\t\t\t`the display-name field \"${field}\" is not a plain-text one (text or textarea)`,\n\t\t);\n\t}\n\tif (mapped.includes(field)) {\n\t\treturn reason(\n\t\t\t\"/display_name_field\",\n\t\t\t\"display_name_field_mapped\",\n\t\t\t`the field \"${field}\" is mapped too: it takes the display name or a mapped value, not both`,\n\t\t);\n\t}\n\treturn [];\n}\n"],"names":["STUB_USER_ID","STUB_OTHER_USER_ID","STUB_WORKSPACE_ID","STUB_OTHER_WORKSPACE_ID","stubIdentity","workspaceId","createHostMembers","field","path","fieldType","label","children","pathsOf","tree","f","gesetzFields","withFootnote","gesetzReleaseSpec","stubBlueprintReleases","gesetz2","gesetz1","entscheidung","stubMappings","stubMappingTestSample","stubEntitySets","stubImportProfiles","text","accessor","name","required","instructions","stubProcessors","counts","c","gesetzReleases","profileRelease","stubImport","i","problem","mapping","sourceKey","reason","stubImports","stubApiKeys","XML_ENTITIES","withEntities","sample","entities","whole","runStubMappingTest","content","doc","parseError","MappingTestRefusedError","selector","nodes","r","_","keySelector","node","problems","stringAt","values","mapFields","xpath","context","fields","prefix","out","inner","value","METHODS","clock","tick","seed","items","count","revisions","n","releases","draftOf","s","latestReleaseOf","stateOf","latest","released","snake","key","protoKeyed","k","v","validity","reasons","byName","b","created","createStubImporthubClient","options","workspaces","id","w","processors","active","calls","m","ws","answer","method","run","find","kind","item","nameFree","NameTakenError","moved","draftRevisionId","save","restoredFromRevisionId","stored","newId","mappingReasons","release","expr","balanced","mapped","at","rel","walk","tc","pa","j","displayNameReasons","stepReasons","steps","list","p","x","profileReasons","e","entitySetReasons","profileOf","mappingOf","entitySetOf","profilesUsing","uses","ofKind","decide","revisionIn","revisionId","sourceFiles","rights","findImport","im","settle","importOf","pinned","StartRefusedError","patch","a","using","ConfigurationInUseError","blueprintReleaseId","all","entitySetId","es","ReleaseRefusedError","now","number","pageToken","newest","from","fromRevisionId","toRevisionId","to","status","file","onProgress","input","profile","mappings","entitySet","importId","filter","query","matching","API_KEY_NAME_MAX","expireTime","apiKey","open","pairs","ch","child","createStubBlueprints","blueprintReleases","blueprintId","releaseId","template","code","message","paths","fs","plainTextFields"],"mappings":";;;AAcO,MAAMA,IAAe,iBAEfC,IAAqB,mBAErBC,KAAoB,gBAEpBC,KAA0B;AAMhC,SAASC,GAAaC,IAAsBH,IAAiC;AACnF,SAAO;AAAA,IACN,QAAQF;AAAA,IACR,aAAAK;AAAA,IACA,SAASC,GAAkB;AAAA,MAC1B,EAAE,QAAQN,GAAc,aAAa,gBAAgB,OAAO,kBAAA;AAAA,MAC5D,EAAE,QAAQC,GAAoB,aAAa,gBAAgB,OAAO,oBAAA;AAAA,IAAoB,CACtF;A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AA;AAClB,QAAM0L,IAAQ,CAACC,MACdA,EAAG,QAAQ,CAAC1L,MAAM,CAACA,EAAE,MAAM,GAAGyL,EAAMzL,EAAE,QAAQ,CAAC,CAAC;AACjD,SAAKyL,EAAM1L,CAAI,EAAE,SAASN,CAAK,IAO1BkM,GAAgB5L,CAAI,EAAE,KAAK,CAACC,MAAMA,EAAE,SAASP,CAAK,IAOnDqH,EAAO,SAASrH,CAAK,IACjBkC;AAAA,IACN;AAAA,IACA;AAAA,IACA,cAAclC,CAAK;AAAA,EAAA,IAGd,CAAA,IAbCkC;AAAA,IACN;AAAA,IACA;AAAA,IACA,2BAA2BlC,CAAK;AAAA,EAAA,IAV1BkC;AAAA,IACN;AAAA,IACA;AAAA,IACA,uCAAuClC,CAAK;AAAA,EAAA;AAkB/C;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knkcs/importhub-ui",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "importhub's screens for knk hosts: Imports, Import Profiles, Mappings and Entity Sets",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "type": "module",