@knkcs/importhub-ui 0.1.0 → 0.3.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.
package/dist/testing.d.ts CHANGED
@@ -1,31 +1,273 @@
1
1
  import { HostIdentity } from '@knkcs/anker/host';
2
+ import { Schema } from '@knkcs/fieldkit/schema';
3
+
4
+ /** What moving a Mapping's draft to another Blueprint Release would lose. */
5
+ declare interface BlueprintReleaseCheck {
6
+ blueprintId: string;
7
+ /** Every mapped field path the Release does not have. */
8
+ missingFieldPaths: string[];
9
+ /** Every Release Spec field read or matched on that it does not have. */
10
+ missingReleaseSpecFields: string[];
11
+ }
12
+
13
+ /** Two Revisions of one configuration, and how each top-level field differs. */
14
+ declare interface ConfigurationComparison {
15
+ from: ConfigurationVersion;
16
+ to: ConfigurationVersion;
17
+ fields: {
18
+ field: string;
19
+ status: FieldComparisonStatus;
20
+ }[];
21
+ }
22
+
23
+ /** One page of a configuration's history. */
24
+ declare interface ConfigurationHistoryPage {
25
+ /** This page's Revisions, newest first. */
26
+ revisions: ConfigurationRevision[];
27
+ /** Every Release, newest first, on every page. */
28
+ releases: ConfigurationReleaseRecord[];
29
+ /** The token of the next page; "" on the last. */
30
+ nextPageToken: string;
31
+ }
32
+
33
+ /** The kinds of versioned configuration (ADR 0016). */
34
+ declare type ConfigurationKind = "importProfile" | "mapping" | "entitySet";
35
+
36
+ /** A Configuration Release, as a list names it: "Release 3". */
37
+ declare interface ConfigurationRelease {
38
+ id: string;
39
+ number: number;
40
+ }
41
+
42
+ /** A Configuration Release as the history lists it: who cut it, when, from what. */
43
+ declare interface ConfigurationReleaseRecord extends ConfigurationRelease {
44
+ /** The Revision it pins. */
45
+ revisionId: string;
46
+ /** The odon user id of the admin who cut it. */
47
+ releasedBy: string;
48
+ /** When it was cut, as an ISO 8601 timestamp. */
49
+ releasedAt: string;
50
+ }
51
+
52
+ /** One saved Revision of a configuration, as its history lists it. */
53
+ declare interface ConfigurationRevision {
54
+ id: string;
55
+ /** The odon user id of who saved it; the host's members name them. */
56
+ savedBy: string;
57
+ /** When it was saved, as an ISO 8601 timestamp. */
58
+ savedAt: string;
59
+ /** Whether it could be released, as decided when it was saved. */
60
+ validity: Validity;
61
+ /** The Revision it restored; "" for an ordinary save. */
62
+ restoredFromRevisionId: string;
63
+ }
64
+
65
+ /** Where a configuration stands: its draft and its latest Release. */
66
+ declare interface ConfigurationState {
67
+ draftRevisionId: string;
68
+ /** Unset while the configuration has none. */
69
+ latestRelease?: ConfigurationRelease;
70
+ /** True when the draft differs from the latest Release, and while there is none. */
71
+ draftDiffersFromRelease: boolean;
72
+ }
73
+
74
+ /**
75
+ * One side of a comparison: a Revision's content, keyed as importhub keys
76
+ * the compared fields (the proto's field names, such as `mapping_ids`).
77
+ */
78
+ declare interface ConfigurationVersion {
79
+ revisionId: string;
80
+ content: Record<string, unknown>;
81
+ }
82
+
83
+ /** One configuration of a kind, at its draft. */
84
+ declare interface Configured<C> {
85
+ id: string;
86
+ /** The draft's content. */
87
+ content: C;
88
+ /**
89
+ * Whether it is valid now: for Profiles and Mappings the service's
90
+ * `current_validity`, which counts what changed since the save (an
91
+ * included Mapping turned invalid, a Blueprint gone); for Entity Sets the
92
+ * validity as saved, the only one they have.
93
+ */
94
+ validity: Validity;
95
+ state: ConfigurationState;
96
+ }
97
+
98
+ /**
99
+ * An `ImporthubBlueprints` over the stub's Blueprint Releases, for a host's
100
+ * `ImporthubHost.blueprints` in tests.
101
+ */
102
+ export declare function createStubBlueprints(blueprintReleases?: StubBlueprintRelease[]): ImporthubBlueprints;
2
103
 
3
104
  export declare function createStubImporthubClient(options?: StubImporthubClientOptions): StubImporthubClient;
4
105
 
5
- /** An Entity Set, as a list names it: its draft's name. */
6
- declare interface EntitySetSummary {
106
+ /** A Release cut, and for a Mapping the Import Profiles that take it. */
107
+ declare interface CutReleaseResult {
108
+ release: ConfigurationReleaseRecord;
109
+ /** The Profiles that include the Mapping; empty for other kinds. */
110
+ importProfiles: ImportProfileRef[];
111
+ }
112
+
113
+ declare type EntitySet = Configured<EntitySetContent>;
114
+
115
+ /** What an admin edits of an Entity Set. */
116
+ declare interface EntitySetContent {
117
+ name: string;
118
+ description: string;
119
+ /** Entity names without `&` and `;`, to the text each stands for. */
120
+ entities: Record<string, string>;
121
+ }
122
+
123
+ declare type FieldComparisonStatus = "unchanged" | "added" | "removed" | "changed";
124
+
125
+ /** A Blueprint, as a Mapping's target is picked and named. */
126
+ declare interface ImporthubBlueprint {
7
127
  id: string;
8
128
  name: string;
9
129
  }
10
130
 
131
+ /** A Blueprint Release, as a Mapping pins it: `label` names it, such as "Release 3". */
132
+ declare interface ImporthubBlueprintRelease {
133
+ id: string;
134
+ label: string;
135
+ }
136
+
137
+ /**
138
+ * Where the screens find Blueprints and their Releases, which live in
139
+ * blueprinthub, not importhub: importhub stores only their ids. A host that
140
+ * reaches blueprinthub (core does) answers from it; one that does not leaves
141
+ * `ImporthubHost.blueprints` out, and the Mapping screens then take and show
142
+ * the two as labelled ids, the technical detail anker's id rule allows.
143
+ */
144
+ declare interface ImporthubBlueprints {
145
+ /** The workspace's Blueprints a Mapping may target, by name. */
146
+ listBlueprints(): Promise<ImporthubBlueprint[]>;
147
+ /** A Blueprint's Releases, newest first. */
148
+ listReleases(blueprintId: string): Promise<ImporthubBlueprintRelease[]>;
149
+ }
150
+
11
151
  /**
12
152
  * What the screens ask of importhub. Every call acts on the caller's
13
153
  * workspace, which importhub takes from the token's active workspace and
14
154
  * never from an argument: a host switches workspace by switching the token.
155
+ * An update names the draft it was made on, and is refused when somebody
156
+ * saved in between.
15
157
  */
16
158
  declare interface ImporthubClient {
17
159
  /** Every Import Profile of the workspace, by name. */
18
- listImportProfiles(): Promise<ImportProfileSummary[]>;
160
+ listImportProfiles(): Promise<ImportProfile[]>;
161
+ getImportProfile(id: string): Promise<ImportProfile>;
162
+ createImportProfile(content: ImportProfileContent): Promise<ImportProfile>;
163
+ updateImportProfile(id: string, content: ImportProfileContent, draftRevisionId: string): Promise<ImportProfile>;
164
+ deleteImportProfile(id: string): Promise<void>;
165
+ /** The Processor catalogue, by name; the same in every workspace. */
166
+ listProcessors(): Promise<Processor[]>;
167
+ /** Every Mapping of the workspace, by name. */
168
+ listMappings(): Promise<Mapping[]>;
169
+ getMapping(id: string): Promise<Mapping>;
170
+ createMapping(content: MappingContent): Promise<Mapping>;
171
+ updateMapping(id: string, content: MappingContent, draftRevisionId: string): Promise<Mapping>;
172
+ /** Throws ConfigurationInUseError while a Profile includes it. */
173
+ deleteMapping(id: string): Promise<void>;
174
+ /** The Import Profiles whose draft or latest Release includes it. */
175
+ listMappingImportProfiles(id: string): Promise<ImportProfileRef[]>;
176
+ /** Checks moving the draft to another Blueprint Release, saving nothing. */
177
+ checkMappingBlueprintRelease(id: string, blueprintReleaseId: string): Promise<BlueprintReleaseCheck>;
19
178
  /** Every Entity Set of the workspace, by name. */
20
- listEntitySets(): Promise<EntitySetSummary[]>;
179
+ listEntitySets(): Promise<EntitySet[]>;
180
+ getEntitySet(id: string): Promise<EntitySet>;
181
+ createEntitySet(content: EntitySetContent): Promise<EntitySet>;
182
+ updateEntitySet(id: string, content: EntitySetContent, draftRevisionId: string): Promise<EntitySet>;
183
+ /** Throws ConfigurationInUseError while a Profile names it. */
184
+ deleteEntitySet(id: string): Promise<void>;
185
+ /**
186
+ * Cuts a Configuration Release from the draft named. Throws
187
+ * ReleaseRefusedError, with the reasons when the draft is invalid.
188
+ */
189
+ cutRelease(kind: ConfigurationKind, id: string, draftRevisionId: string): Promise<CutReleaseResult>;
190
+ /** One page of the history; pageToken "" for the first. */
191
+ listHistory(kind: ConfigurationKind, id: string, pageToken: string): Promise<ConfigurationHistoryPage>;
192
+ compareRevisions(kind: ConfigurationKind, id: string, fromRevisionId: string, toRevisionId: string): Promise<ConfigurationComparison>;
193
+ /** Saves an older Revision's content as a new draft, on the draft named. */
194
+ restoreRevision(kind: ConfigurationKind, id: string, revisionId: string, draftRevisionId: string): Promise<void>;
21
195
  }
22
196
 
23
- /** An Import Profile, as a list names it. */
24
- declare interface ImportProfileSummary {
197
+ declare type ImportProfile = Configured<ImportProfileContent>;
198
+
199
+ /** What an admin edits of an Import Profile. */
200
+ declare interface ImportProfileContent {
201
+ name: string;
202
+ description: string;
203
+ /** The Entity Set the Source File is read with; "" for none. */
204
+ entitySetId: string;
205
+ /** In the order they run. */
206
+ preprocessors: ProcessorStep[];
207
+ /** The Mappings it includes, by id, in the order they run. */
208
+ mappingIds: string[];
209
+ /** In the order they run. */
210
+ postProcessors: ProcessorStep[];
211
+ autoPublish: boolean;
212
+ deleteSourceFileOnSuccess: boolean;
213
+ }
214
+
215
+ /** An Import Profile, named where another configuration is used. */
216
+ declare interface ImportProfileRef {
25
217
  id: string;
26
218
  name: string;
27
219
  }
28
220
 
221
+ declare type Mapping = Configured<MappingContent>;
222
+
223
+ /**
224
+ * What an admin edits of a Mapping, in the JSON shape of importhub.v1's
225
+ * MappingContent (its camelCase keys). The screens here edit only the
226
+ * fields they name; every other setting (field mappings, Version Match,
227
+ * Title Contributions, …) is the structured editor's (F4), and travels
228
+ * through as given, so a save here never drops it.
229
+ */
230
+ declare interface MappingContent {
231
+ name: string;
232
+ description?: string;
233
+ blueprintId: string;
234
+ blueprintReleaseId: string;
235
+ elementSelector?: string;
236
+ sourceKey?: {
237
+ selector?: string;
238
+ template?: string;
239
+ [key: string]: unknown;
240
+ };
241
+ /** Each an xmlmapper FieldMapping; `name` is the field path. */
242
+ fields?: Array<Record<string, unknown>>;
243
+ [key: string]: unknown;
244
+ }
245
+
246
+ /** One entry of the Processor catalogue. */
247
+ declare interface Processor {
248
+ /** How a Profile names it, such as `entity-element`. */
249
+ name: string;
250
+ kind: ProcessorKind;
251
+ /** What it works on: a Profile lists only `source_file` ones. */
252
+ target: ProcessorTarget;
253
+ /** In English, from the service. */
254
+ description: string;
255
+ /** Its settings as fieldkit Fields, in form order; empty for none. */
256
+ settingsSpec: Schema;
257
+ }
258
+
259
+ declare type ProcessorKind = "preprocessor" | "post_processor";
260
+
261
+ /** One Processor in a Profile's pipeline, with its settings. */
262
+ declare interface ProcessorStep {
263
+ /** The Processor, by its name in the catalogue. */
264
+ processor: string;
265
+ /** One value per setting of its settings spec, by `api_accessor`. */
266
+ settings: Record<string, unknown>;
267
+ }
268
+
269
+ declare type ProcessorTarget = "source_file" | "rich_text_field";
270
+
29
271
  /** A second workspace, for tests that switch to it. */
30
272
  export declare const STUB_OTHER_WORKSPACE_ID = "ws_stub_other";
31
273
 
@@ -35,8 +277,31 @@ export declare const STUB_USER_ID = "user_stub_ada";
35
277
  /** The stub workspace's id. */
36
278
  export declare const STUB_WORKSPACE_ID = "ws_stub_main";
37
279
 
280
+ /** A Blueprint Release the stub knows, with the field paths it has. */
281
+ export declare interface StubBlueprintRelease {
282
+ id: string;
283
+ blueprintId: string;
284
+ blueprintName: string;
285
+ label: string;
286
+ fieldPaths: string[];
287
+ }
288
+
289
+ /**
290
+ * Two Releases of the "Gesetz" Blueprint, the newer of which dropped
291
+ * `fussnote`, and one of "Entscheidung".
292
+ */
293
+ export declare function stubBlueprintReleases(): StubBlueprintRelease[];
294
+
295
+ /** A stub configuration as the stub client is seeded with it: an id and its content. */
296
+ export declare interface StubConfiguration<C> {
297
+ id: string;
298
+ content: C;
299
+ /** The number of its latest Release; none when unset. */
300
+ releaseNumber?: number;
301
+ }
302
+
38
303
  /** The stub workspace's Entity Sets: one. */
39
- export declare function stubEntitySets(): EntitySetSummary[];
304
+ export declare function stubEntitySets(): StubConfiguration<EntitySetContent>[];
40
305
 
41
306
  /**
42
307
  * A `HostIdentity` for anker's `TestHost` or `HostProvider`: Ada, in the stub
@@ -47,29 +312,59 @@ export declare function stubIdentity(workspaceId?: string): HostIdentity;
47
312
  export declare interface StubImporthubClient extends ImporthubClient {
48
313
  /** Answer for another workspace from now on, as a host's new token would. */
49
314
  switchWorkspace(workspaceId: string): void;
50
- /** How many reads each method has answered, for tests that count reloads. */
315
+ /** How many calls each method has answered, for tests that count reloads. */
51
316
  readonly calls: Readonly<Record<keyof ImporthubClient, number>>;
52
317
  }
53
318
 
54
319
  export declare interface StubImporthubClientOptions {
55
320
  /**
56
321
  * The workspaces by id. Without it, the stub workspace holds the
57
- * fixtures' Import Profiles and Entity Sets.
322
+ * fixtures' Import Profiles, Mappings and Entity Sets.
58
323
  */
59
324
  workspaces?: Record<string, StubWorkspace>;
60
325
  /** The workspace answered for first; the stub workspace by default. */
61
326
  activeWorkspaceId?: string;
62
- /** Fail every read with this error, as an unreachable importhub would. */
327
+ /** The Processor catalogue; the fixtures' by default. */
328
+ processors?: Processor[];
329
+ /** The Blueprint Releases blueprinthub knows; the fixtures' by default. */
330
+ blueprintReleases?: StubBlueprintRelease[];
331
+ /** Fail every call with this error, as an unreachable importhub would. */
63
332
  fail?: Error;
64
333
  }
65
334
 
66
- /** The stub workspace's Import Profiles: two, one per kind of Source File. */
67
- export declare function stubImportProfiles(): ImportProfileSummary[];
335
+ /**
336
+ * The stub workspace's Import Profiles: one per kind of Source File. The
337
+ * VRPML one includes the invalid Mapping, so it is invalid too.
338
+ */
339
+ export declare function stubImportProfiles(): StubConfiguration<ImportProfileContent>[];
340
+
341
+ /** The stub workspace's Mappings: one valid and released, one invalid. */
342
+ export declare function stubMappings(): StubConfiguration<MappingContent>[];
343
+
344
+ /** The catalogue, a few Processors of each kind and target. */
345
+ export declare function stubProcessors(): Processor[];
68
346
 
69
347
  /** What one stub workspace holds. */
70
348
  export declare interface StubWorkspace {
71
- importProfiles?: ImportProfileSummary[];
72
- entitySets?: EntitySetSummary[];
349
+ importProfiles?: StubConfiguration<ImportProfileContent>[];
350
+ mappings?: StubConfiguration<MappingContent>[];
351
+ entitySets?: StubConfiguration<EntitySetContent>[];
352
+ }
353
+
354
+ /** Whether a configuration may be released, and if not, why. */
355
+ declare interface Validity {
356
+ valid: boolean;
357
+ reasons: ValidityReason[];
358
+ }
359
+
360
+ /** One thing that makes a configuration invalid (importhub.v1.ValidityReason). */
361
+ declare interface ValidityReason {
362
+ /** Where, as a JSON Pointer into the content; empty for the whole. */
363
+ path: string;
364
+ /** A stable code, such as `no_mappings`; the type's service lists them. */
365
+ code: string;
366
+ /** What is wrong, in English, for a person. */
367
+ message: string;
73
368
  }
74
369
 
75
370
  export { }