@knkcs/importhub-ui 0.2.0 → 0.4.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.js CHANGED
@@ -1,41 +1,68 @@
1
- import { createHostMembers as j } from "@knkcs/anker/host";
2
- import { C as O, N as F } from "./importhub-client-CYqd7Eeq.js";
3
- const z = "user_stub_ada", k = "ws_stub_main", V = "ws_stub_other";
4
- function J(r = k) {
1
+ import { createHostMembers as ne } from "@knkcs/anker/host";
2
+ import { R as K, C as V, N as ie } from "./importhub-client-CrS-3Zuu.js";
3
+ const S = "user_stub_ada", U = "ws_stub_main", he = "ws_stub_other";
4
+ function be(i = U) {
5
5
  return {
6
- userId: z,
7
- workspaceId: r,
8
- members: j([
9
- { userId: z, displayName: "Ada Importer", email: "ada@example.com" }
6
+ userId: S,
7
+ workspaceId: i,
8
+ members: ne([
9
+ { userId: S, displayName: "Ada Importer", email: "ada@example.com" }
10
10
  ])
11
11
  };
12
12
  }
13
- function x() {
13
+ const h = (i, o, a, d = []) => ({
14
+ accessor: i.split(".").pop() ?? i,
15
+ path: i,
16
+ fieldType: o,
17
+ label: a,
18
+ children: d
19
+ }), F = (i) => i.flatMap((o) => [o.path, ...F(o.children)]), Z = (i) => [
20
+ h("titel", "text", "Titel"),
21
+ h("abkuerzung", "text", "Abkürzung"),
22
+ ...i ? [h("fussnote", "rich_text", "Fußnote")] : [],
23
+ h("stand", "fieldset", "Stand", [
24
+ h("stand.datum", "date", "Datum"),
25
+ h("stand.art", "select", "Art")
26
+ ])
27
+ ], X = () => [
28
+ h("fundstelle", "text", "Fundstelle"),
29
+ h("ausgabedatum", "date", "Ausgabedatum")
30
+ ];
31
+ function ee() {
32
+ const i = Z(!1), o = Z(!0), a = [
33
+ h("aktenzeichen", "text", "Aktenzeichen"),
34
+ h("datum", "date", "Datum")
35
+ ];
14
36
  return [
15
37
  {
16
38
  id: "br_stub_gesetz_2",
17
39
  blueprintId: "bp_stub_gesetz",
18
40
  blueprintName: "Gesetz",
19
41
  label: "Release 2",
20
- fieldPaths: ["titel", "abkuerzung"]
42
+ fieldPaths: F(i),
43
+ fields: i,
44
+ releaseSpecFields: X()
21
45
  },
22
46
  {
23
47
  id: "br_stub_gesetz_1",
24
48
  blueprintId: "bp_stub_gesetz",
25
49
  blueprintName: "Gesetz",
26
50
  label: "Release 1",
27
- fieldPaths: ["titel", "abkuerzung", "fussnote"]
51
+ fieldPaths: F(o),
52
+ fields: o,
53
+ releaseSpecFields: X()
28
54
  },
29
55
  {
30
56
  id: "br_stub_entscheidung_1",
31
57
  blueprintId: "bp_stub_entscheidung",
32
58
  blueprintName: "Entscheidung",
33
59
  label: "Release 1",
34
- fieldPaths: ["aktenzeichen", "datum"]
60
+ fieldPaths: F(a),
61
+ fields: a
35
62
  }
36
63
  ];
37
64
  }
38
- function U() {
65
+ function re() {
39
66
  return [
40
67
  {
41
68
  id: "mp_stub_norm",
@@ -67,7 +94,7 @@ function U() {
67
94
  }
68
95
  ];
69
96
  }
70
- function D() {
97
+ function oe() {
71
98
  return [
72
99
  {
73
100
  id: "es_stub_latin1",
@@ -80,7 +107,7 @@ function D() {
80
107
  }
81
108
  ];
82
109
  }
83
- function W() {
110
+ function ae() {
84
111
  return [
85
112
  {
86
113
  id: "ip_stub_gesetz",
@@ -111,12 +138,12 @@ function W() {
111
138
  }
112
139
  ];
113
140
  }
114
- const w = (r, p, o, d = "") => ({
141
+ const D = (i, o, a, d = "") => ({
115
142
  field_type: "text",
116
- config: { name: p, api_accessor: r, required: o, instructions: d },
143
+ config: { name: o, api_accessor: i, required: a, instructions: d },
117
144
  system: !1
118
145
  });
119
- function L() {
146
+ function le() {
120
147
  return [
121
148
  {
122
149
  name: "citation-links",
@@ -138,8 +165,8 @@ function L() {
138
165
  target: "source_file",
139
166
  description: "Renames every element of one name to another.",
140
167
  settingsSpec: [
141
- w("from", "Element", !0, "The element's name now."),
142
- w("to", "New name", !0)
168
+ D("from", "Element", !0, "The element's name now."),
169
+ D("to", "New name", !0)
143
170
  ]
144
171
  },
145
172
  {
@@ -147,11 +174,11 @@ function L() {
147
174
  kind: "preprocessor",
148
175
  target: "source_file",
149
176
  description: "Wraps each sentence of an element in its own element.",
150
- settingsSpec: [w("element", "Element", !1)]
177
+ settingsSpec: [D("element", "Element", !1)]
151
178
  }
152
179
  ];
153
180
  }
154
- const q = [
181
+ const pe = [
155
182
  "listImportProfiles",
156
183
  "getImportProfile",
157
184
  "createImportProfile",
@@ -169,60 +196,104 @@ const q = [
169
196
  "getEntitySet",
170
197
  "createEntitySet",
171
198
  "updateEntitySet",
172
- "deleteEntitySet"
173
- ], v = (r = []) => r.map((p) => ({
174
- id: p.id,
175
- content: structuredClone(p.content),
176
- revision: 1,
177
- releaseNumber: p.releaseNumber,
178
- releasedRevision: p.releaseNumber ? 1 : void 0
179
- })), y = (r) => ({
180
- draftRevisionId: `${r.id}_r${r.revision}`,
181
- draftDiffersFromRelease: r.releasedRevision !== r.revision,
182
- ...r.releaseNumber ? { latestRelease: { id: `${r.id}_rel${r.releaseNumber}`, number: r.releaseNumber } } : {}
183
- }), $ = (r) => ({
184
- valid: r.length === 0,
185
- reasons: r
186
- }), S = (r) => [...r].sort((p, o) => p.content.name.localeCompare(o.content.name));
187
- let A = 0;
188
- function Q(r = {}) {
189
- const p = Object.fromEntries(
199
+ "deleteEntitySet",
200
+ "cutRelease",
201
+ "listHistory",
202
+ "compareRevisions",
203
+ "restoreRevision"
204
+ ];
205
+ let Q = Date.parse("2026-11-02T08:00:00Z");
206
+ const R = () => (Q += 36e5, new Date(Q).toISOString()), H = (i = []) => i.map((o) => {
207
+ const a = Math.max(o.releaseNumber ?? 0, 1), d = Array.from({ length: a }, (I, p) => ({
208
+ id: `${o.id}_r${p + 1}`,
209
+ content: structuredClone(o.content),
210
+ savedBy: S,
211
+ savedAt: R(),
212
+ restoredFromRevisionId: ""
213
+ })), b = Array.from({ length: o.releaseNumber ?? 0 }, (I, p) => ({
214
+ id: `${o.id}_rel${p + 1}`,
215
+ number: p + 1,
216
+ revisionId: `${o.id}_r${p + 1}`,
217
+ releasedBy: S,
218
+ releasedAt: R()
219
+ }));
220
+ return { id: o.id, content: structuredClone(o.content), revisions: d, releases: b };
221
+ }), E = (i) => i.revisions[i.revisions.length - 1], ce = (i) => i.releases[i.releases.length - 1], x = (i) => {
222
+ const o = ce(i), a = i.revisions.find((d) => d.id === o?.revisionId);
223
+ return {
224
+ draftRevisionId: E(i).id,
225
+ // By content, as importhub compares: a draft that restored the
226
+ // released content does not differ.
227
+ draftDiffersFromRelease: !a || JSON.stringify(a.content) !== JSON.stringify(E(i).content),
228
+ ...o ? { latestRelease: { id: o.id, number: o.number } } : {}
229
+ };
230
+ }, de = (i) => i.replace(/[A-Z]/g, (o) => `_${o.toLowerCase()}`), Y = (i) => Object.fromEntries(
231
+ Object.entries(i).map(([o, a]) => [de(o), a])
232
+ ), P = (i) => ({
233
+ valid: i.length === 0,
234
+ reasons: i
235
+ }), C = (i) => [...i].sort((o, a) => o.content.name.localeCompare(a.content.name));
236
+ let me = 0;
237
+ function _e(i = {}) {
238
+ const o = Object.fromEntries(
190
239
  Object.entries(
191
- r.workspaces ?? {
192
- [k]: {
193
- importProfiles: W(),
194
- mappings: U(),
195
- entitySets: D()
240
+ i.workspaces ?? {
241
+ [U]: {
242
+ importProfiles: ae(),
243
+ mappings: re(),
244
+ entitySets: oe()
196
245
  }
197
246
  }
198
247
  ).map(([e, t]) => [
199
248
  e,
200
249
  {
201
- importProfiles: v(t.importProfiles),
202
- mappings: v(t.mappings),
203
- entitySets: v(t.entitySets)
250
+ importProfiles: H(t.importProfiles),
251
+ mappings: H(t.mappings),
252
+ entitySets: H(t.entitySets)
204
253
  }
205
254
  ])
206
- ), o = r.processors ?? L(), d = r.blueprintReleases ?? x();
207
- let P = r.activeWorkspaceId ?? k;
208
- const N = Object.fromEntries(q.map((e) => [e, 0])), s = () => (p[P] ??= { importProfiles: [], mappings: [], entitySets: [] }, p[P]), a = async (e, t) => {
209
- if (N[e]++, r.fail) throw r.fail;
255
+ ), a = i.processors ?? le(), d = i.blueprintReleases ?? ee();
256
+ let b = i.activeWorkspaceId ?? U;
257
+ const I = Object.fromEntries(pe.map((e) => [e, 0])), p = () => (o[b] ??= { importProfiles: [], mappings: [], entitySets: [] }, o[b]), u = async (e, t) => {
258
+ if (I[e]++, i.fail) throw i.fail;
210
259
  return structuredClone(t());
211
- }, c = (e, t, n) => {
212
- const i = e.find((l) => l.id === t);
213
- if (!i) throw new Error(`${n} ${t} not found`);
214
- return i;
215
- }, g = (e, t, n) => {
260
+ }, g = (e, t, s) => {
261
+ const n = e.find((c) => c.id === t);
262
+ if (!n) throw new Error(`${s} ${t} not found`);
263
+ return n;
264
+ }, v = (e, t, s) => {
216
265
  if (!t.trim()) throw new Error("a name is required");
217
- if (e.some((i) => i.id !== n && i.content.name === t)) throw new F();
218
- }, E = (e, t, n) => {
219
- if (n && n !== y(e).draftRevisionId)
266
+ if (e.some((n) => n.id !== s && n.content.name === t)) throw new ie();
267
+ }, W = (e, t) => t !== "" && t !== E(e).id, M = (e, t, s, n = "") => {
268
+ if (W(e, s))
220
269
  throw new Error("the draft moved: somebody saved in between");
221
- e.content = structuredClone(t), e.revision++;
270
+ e.content = structuredClone(t), e.revisions.push({
271
+ id: `${e.id}_r${e.revisions.length + 1}`,
272
+ content: structuredClone(t),
273
+ savedBy: S,
274
+ savedAt: R(),
275
+ restoredFromRevisionId: n
276
+ });
277
+ }, z = (e, t) => {
278
+ const s = te(e);
279
+ return {
280
+ id: s,
281
+ content: structuredClone(t),
282
+ revisions: [
283
+ {
284
+ id: `${s}_r1`,
285
+ content: structuredClone(t),
286
+ savedBy: S,
287
+ savedAt: R(),
288
+ restoredFromRevisionId: ""
289
+ }
290
+ ],
291
+ releases: []
292
+ };
222
293
  };
223
- function B(e) {
224
- const t = [], n = d.find((i) => i.id === e.blueprintReleaseId);
225
- return e.blueprintReleaseId ? n ? n.blueprintId !== e.blueprintId && t.push({
294
+ function N(e) {
295
+ const t = [], s = d.find((r) => r.id === e.blueprintReleaseId);
296
+ e.blueprintReleaseId ? s ? s.blueprintId !== e.blueprintId && t.push({
226
297
  path: "/blueprintReleaseId",
227
298
  code: "release_of_other_blueprint",
228
299
  message: "The pinned Release is of another Blueprint."
@@ -238,190 +309,328 @@ function Q(r = {}) {
238
309
  path: "/elementSelector",
239
310
  code: "no_element_selector",
240
311
  message: "It has no element selector."
241
- }), !e.sourceKey?.selector && !e.sourceKey?.template && t.push({ path: "/sourceKey", code: "no_source_key", message: "It has no Source Key." }), (e.fields ?? []).forEach((i, l) => {
242
- const m = String(i.name ?? "");
243
- n && !n.fieldPaths.includes(m) && t.push({
244
- path: `/fields/${l}`,
245
- code: "unknown_field_path",
246
- message: `The pinned Release has no field ${m}.`
312
+ }), !e.sourceKey?.selector && !e.sourceKey?.template && t.push({ path: "/sourceKey", code: "no_source_key", message: "It has no Source Key." });
313
+ const n = (r, l) => {
314
+ typeof l == "string" && l !== "" && !ue(l) && t.push({ path: r, code: "invalid_xpath", message: `"${l}" is not an XPath.` });
315
+ };
316
+ n("/element_selector", e.elementSelector), n("/source_key/selector", e.sourceKey?.selector);
317
+ const c = [];
318
+ return (e.fields ?? []).forEach((r, l) => {
319
+ const f = `/fields/${l}`;
320
+ for (const { path: m, rel: $, mapping: y } of L(r, "", f))
321
+ c.push(m), n(`${$}/selector`, y.selector), s && !s.fieldPaths.includes(m) && t.push({
322
+ path: f,
323
+ code: "unknown_field_path",
324
+ message: `The pinned Release has no field ${m}.`
325
+ }), y.type === "select" && !y.selectOptions && t.push({
326
+ path: f,
327
+ code: "xmlmapper_schema",
328
+ message: `The select field ${m} has no select options.`
329
+ });
330
+ }), (e.versionMatch?.contentFields ?? []).forEach((r, l) => {
331
+ c.includes(r) || t.push({
332
+ path: `/version_match/content_fields/${l}`,
333
+ code: "unknown_version_match_field",
334
+ message: `The Version Match compares ${r}, which the Mapping does not map.`
335
+ });
336
+ }), (e.titleContributions ?? []).forEach((r, l) => {
337
+ (!r.selector || !r.ausgabeCodeSelector) && t.push({
338
+ path: `/title_contributions/${l}`,
339
+ code: "incomplete_title_contribution",
340
+ message: "A Title Contribution needs a selector and an Ausgabe code selector."
341
+ }), n(`/title_contributions/${l}/selector`, r.selector);
342
+ }), (e.placeholderAssets ?? []).forEach((r, l) => {
343
+ (!r.selector || !r.assetType || !r.keyParts?.length || !r.nameSelector) && t.push({
344
+ path: `/placeholder_assets/${l}`,
345
+ code: "incomplete_placeholder_assets",
346
+ message: "Placeholder Assets need a selector, an asset type, the key's parts and a name selector."
347
+ }), n(`/placeholder_assets/${l}/selector`, r.selector), (r.keyParts ?? []).forEach((f, m) => {
348
+ n(`/placeholder_assets/${l}/key_parts/${m}`, f);
247
349
  });
248
350
  }), t;
249
351
  }
250
- function C(e, t, n) {
251
- return e.flatMap((i, l) => {
252
- const m = `/${t}/${l}`, u = o.find((f) => f.name === i.processor);
253
- return u ? u.target !== "source_file" ? [
352
+ function J(e, t, s) {
353
+ return e.flatMap((n, c) => {
354
+ const r = `/${t}/${c}`, l = a.find((m) => m.name === n.processor);
355
+ return l ? l.target !== "source_file" ? [
254
356
  {
255
- path: m,
357
+ path: r,
256
358
  code: "rich_text_processor",
257
- message: `${u.name} is configured on a rich-text field, not on a Profile.`
359
+ message: `${l.name} is configured on a rich-text field, not on a Profile.`
258
360
  }
259
- ] : u.kind !== n ? [{ path: m, code: "wrong_processor_kind", message: `${u.name} does not run here.` }] : u.settingsSpec.filter(
260
- (f) => f.config.required && (i.settings[f.config.api_accessor] ?? "") === ""
261
- ).map((f) => ({
262
- path: `${m}/settings/${f.config.api_accessor}`,
361
+ ] : l.kind !== s ? [{ path: r, code: "wrong_processor_kind", message: `${l.name} does not run here.` }] : l.settingsSpec.filter(
362
+ (m) => m.config.required && (n.settings[m.config.api_accessor] ?? "") === ""
363
+ ).map((m) => ({
364
+ path: `${r}/settings/${m.config.api_accessor}`,
263
365
  code: "invalid_processor_settings",
264
- message: `${u.name}: ${f.config.api_accessor} is required.`
366
+ message: `${l.name}: ${m.config.api_accessor} is required.`
265
367
  })) : [
266
- { path: m, code: "unknown_processor", message: `No Processor is called ${i.processor}.` }
368
+ { path: r, code: "unknown_processor", message: `No Processor is called ${n.processor}.` }
267
369
  ];
268
370
  });
269
371
  }
270
- function T(e) {
271
- const t = s(), n = [
272
- ...C(e.preprocessors, "preprocessors", "preprocessor"),
273
- ...C(e.postProcessors, "postProcessors", "post_processor")
372
+ function q(e) {
373
+ const t = p(), s = [
374
+ ...J(e.preprocessors, "preprocessors", "preprocessor"),
375
+ ...J(e.postProcessors, "postProcessors", "post_processor")
274
376
  ];
275
- return e.mappingIds.length === 0 && n.push({ path: "/mappingIds", code: "no_mappings", message: "It includes no Mapping." }), e.mappingIds.forEach((i, l) => {
276
- const m = t.mappings.find((I) => I.id === i);
277
- if (!m) {
278
- n.push({
279
- path: `/mappingIds/${l}`,
377
+ return e.mappingIds.length === 0 && s.push({ path: "/mappingIds", code: "no_mappings", message: "It includes no Mapping." }), e.mappingIds.forEach((n, c) => {
378
+ const r = t.mappings.find((f) => f.id === n);
379
+ if (!r) {
380
+ s.push({
381
+ path: `/mappingIds/${c}`,
280
382
  code: "mapping_missing",
281
383
  message: "It includes a Mapping that does not exist."
282
384
  });
283
385
  return;
284
386
  }
285
- const u = B(m.content);
286
- u.length > 0 && n.push({
287
- path: `/mappingIds/${l}`,
387
+ const l = N(r.content);
388
+ l.length > 0 && s.push({
389
+ path: `/mappingIds/${c}`,
288
390
  code: "mapping_invalid",
289
- message: `The Mapping ${m.content.name} is invalid: ${u.map((I) => I.message).join(" ")}`
391
+ message: `The Mapping ${r.content.name} is invalid: ${l.map((f) => f.message).join(" ")}`
290
392
  });
291
- }), e.entitySetId && !t.entitySets.some((i) => i.id === e.entitySetId) && n.push({
393
+ }), e.entitySetId && !t.entitySets.some((n) => n.id === e.entitySetId) && s.push({
292
394
  path: "/entitySetId",
293
395
  code: "entity_set_missing",
294
396
  message: "It names an Entity Set that does not exist."
295
- }), n;
397
+ }), s;
296
398
  }
297
- const K = (e) => Object.keys(e.entities).length === 0 ? [{ path: "/entities", code: "no_entities", message: "It defines no entity." }] : [], b = (e) => ({
399
+ const G = (e) => Object.keys(e.entities).length === 0 ? [{ path: "/entities", code: "no_entities", message: "It defines no entity." }] : [], k = (e) => ({
298
400
  id: e.id,
299
401
  content: e.content,
300
- validity: $(T(e.content)),
301
- state: y(e)
302
- }), h = (e) => ({
402
+ validity: P(q(e.content)),
403
+ state: x(e)
404
+ }), O = (e) => ({
303
405
  id: e.id,
304
406
  content: e.content,
305
- validity: $(B(e.content)),
306
- state: y(e)
307
- }), _ = (e) => ({
407
+ validity: P(N(e.content)),
408
+ state: x(e)
409
+ }), B = (e) => ({
308
410
  id: e.id,
309
411
  content: e.content,
310
- validity: $(K(e.content)),
311
- state: y(e)
312
- }), M = (e) => S(s().importProfiles.filter((t) => e(t.content))).map((t) => ({
412
+ validity: P(G(e.content)),
413
+ state: x(e)
414
+ }), A = (e) => C(p().importProfiles.filter((t) => e(t.content))).map((t) => ({
313
415
  id: t.id,
314
416
  name: t.content.name
315
- })), R = (e) => `${e}_stub_new_${++A}`;
417
+ })), te = (e) => `${e}_stub_new_${++me}`, w = (e) => {
418
+ const t = p();
419
+ switch (e) {
420
+ case "importProfile":
421
+ return {
422
+ items: t.importProfiles,
423
+ name: "Import Profile",
424
+ reasons: (s) => q(s)
425
+ };
426
+ case "mapping":
427
+ return {
428
+ items: t.mappings,
429
+ name: "Mapping",
430
+ reasons: (s) => N(s)
431
+ };
432
+ case "entitySet":
433
+ return {
434
+ items: t.entitySets,
435
+ name: "Entity Set",
436
+ reasons: (s) => G(s)
437
+ };
438
+ }
439
+ }, _ = (e, t) => {
440
+ E(t).validity = P(w(e).reasons(t.content));
441
+ }, T = (e, t) => {
442
+ const s = e.revisions.find((n) => n.id === t);
443
+ if (!s) throw new Error(`Revision ${t} not found`);
444
+ return s;
445
+ };
316
446
  return {
317
- calls: N,
447
+ calls: I,
318
448
  switchWorkspace(e) {
319
- P = e;
449
+ b = e;
320
450
  },
321
- listImportProfiles: () => a("listImportProfiles", () => S(s().importProfiles).map(b)),
322
- getImportProfile: (e) => a("getImportProfile", () => b(c(s().importProfiles, e, "Import Profile"))),
323
- createImportProfile: (e) => a("createImportProfile", () => {
324
- g(s().importProfiles, e.name);
325
- const t = {
326
- id: R("ip"),
327
- content: structuredClone(e),
328
- revision: 1
329
- };
330
- return s().importProfiles.push(t), b(t);
451
+ listImportProfiles: () => u("listImportProfiles", () => C(p().importProfiles).map(k)),
452
+ getImportProfile: (e) => u("getImportProfile", () => k(g(p().importProfiles, e, "Import Profile"))),
453
+ createImportProfile: (e) => u("createImportProfile", () => {
454
+ v(p().importProfiles, e.name);
455
+ const t = z("ip", e);
456
+ return _("importProfile", t), p().importProfiles.push(t), k(t);
331
457
  }),
332
- updateImportProfile: (e, t, n) => a("updateImportProfile", () => {
333
- const i = c(s().importProfiles, e, "Import Profile");
334
- return g(s().importProfiles, t.name, e), E(i, t, n), b(i);
458
+ updateImportProfile: (e, t, s) => u("updateImportProfile", () => {
459
+ const n = g(p().importProfiles, e, "Import Profile");
460
+ return v(p().importProfiles, t.name, e), M(n, t, s), _("importProfile", n), k(n);
335
461
  }),
336
- deleteImportProfile: (e) => a("deleteImportProfile", () => {
337
- c(s().importProfiles, e, "Import Profile"), s().importProfiles = s().importProfiles.filter((t) => t.id !== e);
462
+ deleteImportProfile: (e) => u("deleteImportProfile", () => {
463
+ g(p().importProfiles, e, "Import Profile"), p().importProfiles = p().importProfiles.filter((t) => t.id !== e);
338
464
  }),
339
- listProcessors: () => a("listProcessors", () => [...o].sort((e, t) => e.name.localeCompare(t.name))),
340
- listMappings: () => a("listMappings", () => S(s().mappings).map(h)),
341
- getMapping: (e) => a("getMapping", () => h(c(s().mappings, e, "Mapping"))),
342
- createMapping: (e) => a("createMapping", () => {
343
- g(s().mappings, e.name);
344
- const t = {
345
- id: R("mp"),
346
- content: structuredClone(e),
347
- revision: 1
348
- };
349
- return s().mappings.push(t), h(t);
465
+ listProcessors: () => u("listProcessors", () => [...a].sort((e, t) => e.name.localeCompare(t.name))),
466
+ listMappings: () => u("listMappings", () => C(p().mappings).map(O)),
467
+ getMapping: (e) => u("getMapping", () => O(g(p().mappings, e, "Mapping"))),
468
+ createMapping: (e) => u("createMapping", () => {
469
+ v(p().mappings, e.name);
470
+ const t = z("mp", e);
471
+ return _("mapping", t), p().mappings.push(t), O(t);
350
472
  }),
351
- updateMapping: (e, t, n) => a("updateMapping", () => {
352
- const i = c(s().mappings, e, "Mapping");
353
- return g(s().mappings, t.name, e), E(i, t, n), h(i);
473
+ updateMapping: (e, t, s) => u("updateMapping", () => {
474
+ const n = g(p().mappings, e, "Mapping");
475
+ return v(p().mappings, t.name, e), M(n, t, s), _("mapping", n), O(n);
354
476
  }),
355
- deleteMapping: (e) => a("deleteMapping", () => {
356
- c(s().mappings, e, "Mapping");
357
- const t = M((n) => n.mappingIds.includes(e));
477
+ deleteMapping: (e) => u("deleteMapping", () => {
478
+ g(p().mappings, e, "Mapping");
479
+ const t = A((s) => s.mappingIds.includes(e));
358
480
  if (t.length > 0)
359
- throw new O(
481
+ throw new V(
360
482
  t,
361
- `the Mapping is included by ${t.map((n) => n.name).join(", ")}`
483
+ `the Mapping is included by ${t.map((s) => s.name).join(", ")}`
362
484
  );
363
- s().mappings = s().mappings.filter((n) => n.id !== e);
485
+ p().mappings = p().mappings.filter((s) => s.id !== e);
364
486
  }),
365
- listMappingImportProfiles: (e) => a("listMappingImportProfiles", () => (c(s().mappings, e, "Mapping"), M((t) => t.mappingIds.includes(e)))),
366
- checkMappingBlueprintRelease: (e, t) => a("checkMappingBlueprintRelease", () => {
367
- const n = c(s().mappings, e, "Mapping"), i = d.find((l) => l.id === t);
368
- if (!i) throw new Error(`Blueprint Release ${t} not found`);
369
- if (i.blueprintId !== n.content.blueprintId)
487
+ listMappingImportProfiles: (e) => u("listMappingImportProfiles", () => (g(p().mappings, e, "Mapping"), A((t) => t.mappingIds.includes(e)))),
488
+ checkMappingBlueprintRelease: (e, t) => u("checkMappingBlueprintRelease", () => {
489
+ const s = g(p().mappings, e, "Mapping"), n = d.find((c) => c.id === t);
490
+ if (!n) throw new Error(`Blueprint Release ${t} not found`);
491
+ if (n.blueprintId !== s.content.blueprintId)
370
492
  throw new Error("the Release is of another Blueprint");
371
493
  return {
372
- blueprintId: i.blueprintId,
373
- missingFieldPaths: (n.content.fields ?? []).map((l) => String(l.name ?? "")).filter((l) => !i.fieldPaths.includes(l)),
374
- missingReleaseSpecFields: []
494
+ blueprintId: n.blueprintId,
495
+ missingFieldPaths: (s.content.fields ?? []).flatMap((c, r) => L(c, "", `/fields/${r}`).map((l) => l.path)).filter((c) => !n.fieldPaths.includes(c)),
496
+ missingReleaseSpecFields: [
497
+ ...(s.content.releaseSpec ?? []).map((c) => c.field ?? ""),
498
+ ...s.content.versionMatch?.releaseSpecFields ?? []
499
+ ].filter(
500
+ (c, r, l) => c !== "" && l.indexOf(c) === r && !(n.releaseSpecFields ?? []).some((f) => f.path === c)
501
+ )
375
502
  };
376
503
  }),
377
- listEntitySets: () => a("listEntitySets", () => S(s().entitySets).map(_)),
378
- getEntitySet: (e) => a("getEntitySet", () => _(c(s().entitySets, e, "Entity Set"))),
379
- createEntitySet: (e) => a("createEntitySet", () => {
380
- g(s().entitySets, e.name);
381
- const t = {
382
- id: R("es"),
383
- content: structuredClone(e),
384
- revision: 1
385
- };
386
- return s().entitySets.push(t), _(t);
504
+ listEntitySets: () => u("listEntitySets", () => C(p().entitySets).map(B)),
505
+ getEntitySet: (e) => u("getEntitySet", () => B(g(p().entitySets, e, "Entity Set"))),
506
+ createEntitySet: (e) => u("createEntitySet", () => {
507
+ v(p().entitySets, e.name);
508
+ const t = z("es", e);
509
+ return _("entitySet", t), p().entitySets.push(t), B(t);
387
510
  }),
388
- updateEntitySet: (e, t, n) => a("updateEntitySet", () => {
389
- const i = c(s().entitySets, e, "Entity Set");
390
- return g(s().entitySets, t.name, e), E(i, t, n), _(i);
511
+ updateEntitySet: (e, t, s) => u("updateEntitySet", () => {
512
+ const n = g(p().entitySets, e, "Entity Set");
513
+ return v(p().entitySets, t.name, e), M(n, t, s), _("entitySet", n), B(n);
391
514
  }),
392
- deleteEntitySet: (e) => a("deleteEntitySet", () => {
393
- c(s().entitySets, e, "Entity Set");
394
- const t = M((n) => n.entitySetId === e);
515
+ deleteEntitySet: (e) => u("deleteEntitySet", () => {
516
+ g(p().entitySets, e, "Entity Set");
517
+ const t = A((s) => s.entitySetId === e);
395
518
  if (t.length > 0)
396
- throw new O(
519
+ throw new V(
397
520
  t,
398
- `the Entity Set is named by ${t.map((n) => n.name).join(", ")}`
521
+ `the Entity Set is named by ${t.map((s) => s.name).join(", ")}`
522
+ );
523
+ p().entitySets = p().entitySets.filter((s) => s.id !== e);
524
+ }),
525
+ cutRelease: (e, t, s) => u("cutRelease", () => {
526
+ const n = w(e), c = g(n.items, t, n.name);
527
+ if (W(c, s))
528
+ throw new K("the draft moved: somebody saved in between");
529
+ const r = P(n.reasons(c.content));
530
+ if (!r.valid) throw new K("the draft is invalid", r);
531
+ if (!x(c).draftDiffersFromRelease)
532
+ throw new K(
533
+ "the draft does not differ from the latest Release: there is nothing to release"
399
534
  );
400
- s().entitySets = s().entitySets.filter((n) => n.id !== e);
535
+ const l = c.releases.length + 1, f = {
536
+ id: `${c.id}_rel${l}`,
537
+ number: l,
538
+ revisionId: E(c).id,
539
+ releasedBy: S,
540
+ releasedAt: R()
541
+ };
542
+ return c.releases.push(f), {
543
+ release: f,
544
+ importProfiles: e === "mapping" ? A((m) => m.mappingIds.includes(t)) : []
545
+ };
546
+ }),
547
+ listHistory: (e, t, s) => u("listHistory", () => {
548
+ const n = w(e), c = g(n.items, t, n.name), r = [...c.revisions].reverse(), l = Number(s || "0");
549
+ return {
550
+ revisions: r.slice(l, l + 10).map((m) => ({
551
+ id: m.id,
552
+ savedBy: m.savedBy,
553
+ savedAt: m.savedAt,
554
+ validity: m.validity ?? P(n.reasons(m.content)),
555
+ restoredFromRevisionId: m.restoredFromRevisionId
556
+ })),
557
+ releases: [...c.releases].reverse(),
558
+ nextPageToken: l + 10 < r.length ? String(l + 10) : ""
559
+ };
560
+ }),
561
+ compareRevisions: (e, t, s, n) => u("compareRevisions", () => {
562
+ const c = w(e), r = g(c.items, t, c.name), l = Y(T(r, s).content), f = Y(T(r, n).content), m = [.../* @__PURE__ */ new Set([...Object.keys(l), ...Object.keys(f)])].map(($) => {
563
+ const y = l[$], j = f[$], se = y === void 0 && j !== void 0 ? "added" : y !== void 0 && j === void 0 ? "removed" : JSON.stringify(y) === JSON.stringify(j) ? "unchanged" : "changed";
564
+ return { field: $, status: se };
565
+ });
566
+ return {
567
+ from: { revisionId: s, content: l },
568
+ to: { revisionId: n, content: f },
569
+ fields: m
570
+ };
571
+ }),
572
+ restoreRevision: (e, t, s, n) => u("restoreRevision", () => {
573
+ const c = w(e), r = g(c.items, t, c.name);
574
+ M(r, T(r, s).content, n, s), _(e, r);
401
575
  })
402
576
  };
403
577
  }
404
- function X(r = x()) {
578
+ function ue(i) {
579
+ const o = [], a = { "]": "[", ")": "(" };
580
+ for (const d of i)
581
+ if (d === "[" || d === "(") o.push(d);
582
+ else if (d in a && o.pop() !== a[d]) return !1;
583
+ return o.length === 0;
584
+ }
585
+ function L(i, o, a) {
586
+ const d = `${o}${String(i.name ?? "")}`;
587
+ return [
588
+ { path: d, rel: a, mapping: i },
589
+ ...["fields", "virtualTableFields"].flatMap(
590
+ (b) => (Array.isArray(i[b]) ? i[b] : []).flatMap(
591
+ (I, p) => L(I, `${d}.`, `${a}/${b}/${p}`)
592
+ )
593
+ )
594
+ ];
595
+ }
596
+ function ye(i = ee()) {
405
597
  return {
406
598
  async listBlueprints() {
407
- return [...new Map(r.map((o) => [o.blueprintId, o.blueprintName]))].map(([o, d]) => ({ id: o, name: d })).sort((o, d) => o.name.localeCompare(d.name));
599
+ return [...new Map(i.map((a) => [a.blueprintId, a.blueprintName]))].map(([a, d]) => ({ id: a, name: d })).sort((a, d) => a.name.localeCompare(d.name));
600
+ },
601
+ async listReleases(o) {
602
+ return i.filter((a) => a.blueprintId === o).map((a) => ({ id: a.id, label: a.label }));
408
603
  },
409
- async listReleases(p) {
410
- return r.filter((o) => o.blueprintId === p).map((o) => ({ id: o.id, label: o.label }));
604
+ async getRelease(o) {
605
+ const a = i.find((d) => d.id === o);
606
+ if (!a) throw new Error(`Blueprint Release ${o} not found`);
607
+ return {
608
+ id: a.id,
609
+ blueprintId: a.blueprintId,
610
+ name: a.label,
611
+ fields: a.fields ?? a.fieldPaths.map((d) => ({
612
+ accessor: d,
613
+ path: d,
614
+ fieldType: "text",
615
+ label: "",
616
+ children: []
617
+ })),
618
+ releaseSpecFields: a.releaseSpecFields ?? []
619
+ };
411
620
  }
412
621
  };
413
622
  }
414
623
  export {
415
- V as STUB_OTHER_WORKSPACE_ID,
416
- z as STUB_USER_ID,
417
- k as STUB_WORKSPACE_ID,
418
- X as createStubBlueprints,
419
- Q as createStubImporthubClient,
420
- x as stubBlueprintReleases,
421
- D as stubEntitySets,
422
- J as stubIdentity,
423
- W as stubImportProfiles,
424
- U as stubMappings,
425
- L as stubProcessors
624
+ he as STUB_OTHER_WORKSPACE_ID,
625
+ S as STUB_USER_ID,
626
+ U as STUB_WORKSPACE_ID,
627
+ ye as createStubBlueprints,
628
+ _e as createStubImporthubClient,
629
+ ee as stubBlueprintReleases,
630
+ oe as stubEntitySets,
631
+ be as stubIdentity,
632
+ ae as stubImportProfiles,
633
+ re as stubMappings,
634
+ le as stubProcessors
426
635
  };
427
636
  //# sourceMappingURL=testing.js.map