@peter.prib/renderengine 0.2.5 → 0.2.7

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.
Files changed (67) hide show
  1. package/README.md +219 -213
  2. package/REFERENCE.md +272 -6
  3. package/dist/renderengine-workspace.umd.js +11980 -7421
  4. package/dist/renderengine.umd.js +8991 -5784
  5. package/examples/archimate.html +68 -66
  6. package/examples/data-model.html +534 -0
  7. package/package.json +70 -68
  8. package/src/bian.js +182 -0
  9. package/src/charting/CheckboxTreeSelector.js +373 -304
  10. package/src/charting/DiagramEditor.js +53 -32
  11. package/src/charting/DiagramTypeRegistry.js +13 -3
  12. package/src/charting/ModelCheckDialog.js +63 -0
  13. package/src/charting/ModelChecker.js +26 -0
  14. package/src/charting/ViewTabStrip.js +94 -81
  15. package/src/charting/archimate/ArchimateCanvasEditor.js +825 -815
  16. package/src/charting/archimate/ArchimateElementTemplate.js +208 -195
  17. package/src/charting/datamodel/BianLandscapeReader.js +185 -0
  18. package/src/charting/datamodel/BianSemanticApiReader.js +183 -0
  19. package/src/charting/datamodel/DataModel.js +645 -0
  20. package/src/charting/datamodel/DataModelChecker.js +92 -0
  21. package/src/charting/datamodel/DataModelCompared.js +127 -0
  22. package/src/charting/datamodel/DataModelContext.js +108 -0
  23. package/src/charting/datamodel/DataModelFileFormat.js +33 -0
  24. package/src/charting/datamodel/DataModelPerspective.js +129 -0
  25. package/src/charting/datamodel/DataType.js +108 -0
  26. package/src/charting/datamodel/EnumerationType.js +51 -0
  27. package/src/charting/datamodel/LevelMapping.js +38 -0
  28. package/src/charting/datamodel/LevelSchema.js +41 -0
  29. package/src/charting/datamodel/ServiceDomain.js +177 -0
  30. package/src/charting/datamodel/ServiceLandscape.js +104 -0
  31. package/src/charting/datamodel/StructuredType.js +63 -0
  32. package/src/charting/datamodel/index.js +15 -0
  33. package/src/charting/diagramModel/MergeModelCommand.js +43 -37
  34. package/src/charting/diagramModel/OpenViewList.js +75 -0
  35. package/src/charting/diagramModel/ViewSetChecker.js +22 -34
  36. package/src/charting/diagrams/DataModelDiagram.js +160 -86
  37. package/src/charting/diagrams/DataModelRelationshipStrategy.js +94 -38
  38. package/src/charting/diagrams/EdgeGeometry.js +578 -553
  39. package/src/charting/diagrams/GraphDiagram.js +11 -1
  40. package/src/charting/diagrams/NodeGeometry.js +169 -158
  41. package/src/charting/diagrams/nesting.js +31 -0
  42. package/src/charting/glyphs/PersonGlyph.js +24 -23
  43. package/src/charting/modelTree/ModelTree.js +202 -164
  44. package/src/charting/modelTree/ModelTreePanel.js +36 -3
  45. package/src/charting/modelTree/TreeViewMode.js +131 -110
  46. package/src/charting/modelTree/modes/FlatTreeMode.js +32 -46
  47. package/src/charting/modelTree/modes/LayerGroupedTreeMode.js +47 -62
  48. package/src/charting/modelTree/modes/TypeGroupedTreeMode.js +46 -60
  49. package/src/datamodel.js +132 -122
  50. package/src/diagramCatalog.js +35 -30
  51. package/src/index.js +2666 -2659
  52. package/src/workspace/EditorShell.js +166 -67
  53. package/src/workspace/PanelLayout.js +56 -0
  54. package/src/workspace/index.js +1 -0
  55. package/src/workspace/layout/TabsNode.js +205 -191
  56. package/src/workspace/parts/ArchimateCanvasPart.js +10 -9
  57. package/src/workspace/parts/ChartPart.js +6 -1
  58. package/src/workspace/parts/DataModelPart.js +544 -0
  59. package/src/workspace/parts/DiagramEditorPart.js +2 -8
  60. package/src/workspace/parts/EditorPart.js +461 -407
  61. package/src/workspace/parts/ModelFile.js +216 -187
  62. package/src/workspace/parts/ModelsPart.js +483 -192
  63. package/src/workspace/storage/BackupFolder.js +145 -0
  64. package/src/workspace/storage/KeyValueStore.js +92 -0
  65. package/src/workspace/storage/ModelLibrary.js +65 -0
  66. package/src/workspace/workArea.js +417 -413
  67. package/src/yaml/YamlReader.js +372 -0
@@ -0,0 +1,183 @@
1
+ import { BianNotation } from '../../bian.js';
2
+ import { YamlReader } from '../../yaml/YamlReader.js';
3
+ import { ServiceDomain } from './ServiceDomain.js';
4
+ import { EnumerationType } from './EnumerationType.js';
5
+ import { StructuredType } from './StructuredType.js';
6
+ import { DataType } from './DataType.js';
7
+
8
+ /** 'CurrentAccountFacility' → 'Current Account Facility'. */
9
+ const spaced = (name) => String(name).replace(/([a-z0-9])([A-Z])/g, '$1 $2').replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2');
10
+ /** 'Current Account Facility' → 'current-account-facility'. */
11
+ const idOf = (name) => spaced(name).toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');
12
+ /** A schema's name from a `$ref` ('#/components/schemas/Amount' → 'Amount'), of an item's for an array. */
13
+ const refName = (prop) => (prop?.$ref ?? prop?.items?.$ref)?.split('/').pop() ?? null;
14
+
15
+ /**
16
+ * BianSemanticApiReader — a service domain from one of BIAN's semantic APIs
17
+ * (an OpenAPI file, YAML or JSON, one per service domain, as BIAN publishes
18
+ * them: the plain ones and those extended with ISO 20022), rather than retyped.
19
+ *
20
+ * Its operations' tags name its control record (`CR - CurrentAccountFacility`)
21
+ * and behaviour qualifiers (`BQ - Interest`); each becomes a logical entity
22
+ * with the attributes its schema has (BIAN's names), the qualifiers joined to
23
+ * the control record. The schemas those attributes are become data types, as
24
+ * deep as `depth` (1: those the attributes name): an `enum` an EnumerationType
25
+ * (each value's meaning from BIAN's description), an object a StructuredType,
26
+ * any other a DataType. A schema named as a logical entity the model already
27
+ * has (`entityNames`) stays a reference to it. Where the ISO 20022 version
28
+ * names an attribute's ISO 20022 type, the attribute (and its data type) keep it.
29
+ *
30
+ * The service domain is named by the API's title, its pattern by the artifact
31
+ * its control record's name ends with (BianNotation.patternOfControlRecord),
32
+ * its asset by the rest of that name.
33
+ */
34
+ export class BianSemanticApiReader {
35
+ /**
36
+ * @param {Object} [options]
37
+ * @param {number} [options.depth] - How deep schemas become data types (0: none)
38
+ * @param {Iterable<string>} [options.entityNames] - Names of logical entities already there (any case)
39
+ */
40
+ constructor({ depth = 1, entityNames = [] } = {}) {
41
+ this.depth = depth;
42
+ this.entityNames = new Set([...entityNames].map(n => String(n).toLowerCase()));
43
+ }
44
+
45
+ /** A specification from a file's text: JSON, else YAML (YamlReader). */
46
+ static parse(text) {
47
+ const body = String(text).replace(/^/, '');
48
+ return /^\s*\{/.test(body) ? JSON.parse(body) : YamlReader.parse(body);
49
+ }
50
+
51
+ /**
52
+ * What a semantic API says, for DataModel#bringCommand.
53
+ * @param {Object} spec - An OpenAPI document (BianSemanticApiReader.parse)
54
+ * @returns {{ serviceDomains: Array<Object>, entities: Array<Object>, relationships: Array<Object>, dataTypes: Array<Object> }}
55
+ */
56
+ read(spec) {
57
+ const title = spec?.info?.title;
58
+ if (!title || !spec.paths) throw new Error('Not an OpenAPI specification (no info.title or paths)');
59
+ const schemas = spec.components?.schemas ?? {};
60
+ const { controlRecords, qualifiers } = BianSemanticApiReader.parts(spec);
61
+ // Some of BIAN's APIs have no control record operations (or none at all): what is there is read.
62
+ const [cr = null] = controlRecords;
63
+ const schemaOf = (name) => schemas[name] ?? ['Retrieve', 'Initiate', 'Update', 'Register', 'Create', 'Evaluate', 'Provide']
64
+ .map(verb => schemas[`${verb}${name}`]).find(Boolean) ?? null;
65
+
66
+ const used = new Map(); // schema name -> depth first reached
67
+ const attributesOf = (schema, depth) => Object.entries(schema?.properties ?? {}).map(([name, prop]) => {
68
+ const ref = refName(prop);
69
+ const iso20022 = BianSemanticApiReader.iso20022Of(prop.description);
70
+ if (ref && !used.has(ref)) used.set(ref, depth);
71
+ return {
72
+ name,
73
+ ...(ref ? { type: ref } : (prop.format || prop.type) && { type: prop.format || prop.type }),
74
+ ...(BianSemanticApiReader.cleanDescription(prop.description) && { description: BianSemanticApiReader.cleanDescription(prop.description) }),
75
+ ...(iso20022 && { iso20022 }),
76
+ };
77
+ });
78
+ const entity = (name) => ({
79
+ id: idOf(name), name: spaced(name),
80
+ ...(BianSemanticApiReader.cleanDescription(schemaOf(name)?.description) && { description: BianSemanticApiReader.cleanDescription(schemaOf(name)?.description) }),
81
+ attributes: attributesOf(schemaOf(name), 1),
82
+ });
83
+ const entities = [...(cr ? [cr] : []), ...qualifiers].map(entity);
84
+ const relationships = !cr ? [] : qualifiers.map(q => ({ id: `${idOf(cr)}-has-${idOf(q)}`, source: idOf(cr), target: idOf(q), name: 'has', sourceCardinality: '1', targetCardinality: '0..*' }));
85
+
86
+ // The schemas the attributes are, then theirs, as deep as asked: data types, unless entities already.
87
+ const dataTypes = [];
88
+ const isoOf = new Map();
89
+ for (const a of entities.flatMap(e => e.attributes)) if (a.iso20022 && a.type && !isoOf.has(a.type)) isoOf.set(a.type, a.iso20022);
90
+ const done = new Set();
91
+ for (let level = 1; level <= this.depth; level++) {
92
+ for (const [name, at] of [...used]) {
93
+ if (at !== level || done.has(name)) continue;
94
+ done.add(name);
95
+ if (this.entityNames.has(name.toLowerCase()) || this.entityNames.has(spaced(name).toLowerCase())) continue;
96
+ const schema = schemas[name];
97
+ if (!schema) continue;
98
+ const type = this.dataType(name, schema, level + 1, attributesOf);
99
+ if (isoOf.has(name) && !type.iso20022) type.iso20022 = isoOf.get(name);
100
+ dataTypes.push(type);
101
+ }
102
+ }
103
+
104
+ // Its pattern by its control record's artifact; with none, by its own name's ('Operations Log').
105
+ const crName = spaced(cr ?? title);
106
+ const pattern = BianNotation.patternOfControlRecord(crName);
107
+ const ending = pattern ? [pattern.artifact, ...pattern.formerArtifacts].find(a => crName.toLowerCase().endsWith(a.toLowerCase())) : null;
108
+ const serviceDomain = {
109
+ kind: ServiceDomain.kind,
110
+ id: `sd-${idOf(title)}`,
111
+ name: title,
112
+ description: BianSemanticApiReader.cleanDescription(spec.info.description),
113
+ asset: ending ? crName.slice(0, -ending.length).trim() : crName,
114
+ pattern: pattern?.name ?? '',
115
+ controlRecord: cr ? idOf(cr) : null,
116
+ qualifiers: qualifiers.map(q => ({ name: spaced(q), entity: idOf(q) })),
117
+ };
118
+ return { serviceDomains: [serviceDomain], entities, relationships, dataTypes };
119
+ }
120
+
121
+ /** A data type spec for a schema: an enumeration, a structure, or a plain type. */
122
+ dataType(name, schema, depth, attributesOf) {
123
+ const base = { id: `bian-${idOf(name)}`, name, ...(BianSemanticApiReader.enumerationMeanings(schema.description).size === 0 && BianSemanticApiReader.cleanDescription(schema.description) && { description: BianSemanticApiReader.cleanDescription(schema.description) }) };
124
+ if (Array.isArray(schema.enum)) {
125
+ const meanings = BianSemanticApiReader.enumerationMeanings(schema.description);
126
+ return { kind: EnumerationType.kind, ...base, values: schema.enum.map(v => ({ name: String(v), ...(meanings.get(String(v)) && { description: meanings.get(String(v)) }) })) };
127
+ }
128
+ if (schema.properties) {
129
+ return { kind: StructuredType.kind, ...base, fields: attributesOf(schema, depth) };
130
+ }
131
+ return { kind: DataType.kind, ...base, ...((schema.format || schema.type) && { basedOn: schema.format || schema.type }) };
132
+ }
133
+
134
+ /** The control records and behaviour qualifiers its operations' tags name, in order. */
135
+ static parts(spec) {
136
+ const controlRecords = [], qualifiers = [];
137
+ for (const path of Object.values(spec.paths ?? {})) {
138
+ for (const op of Object.values(path ?? {})) {
139
+ for (const tag of op?.tags ?? []) {
140
+ const m = /^(CR|BQ)\b[^-]*-\s*(\S+)\s*$/.exec(String(tag));
141
+ if (!m) continue;
142
+ const list = m[1] === 'CR' ? controlRecords : qualifiers;
143
+ if (!list.includes(m[2])) list.push(m[2]);
144
+ }
145
+ }
146
+ }
147
+ return { controlRecords, qualifiers };
148
+ }
149
+
150
+ /** The ISO 20022 type a description links to (`…/standardsrepository/type/CurrencyCode`), or null. */
151
+ static iso20022Of(description) {
152
+ return /iso20022\.org\/standardsrepository\/type\/([A-Za-z0-9_]+)/.exec(String(description ?? ''))?.[1] ?? null;
153
+ }
154
+
155
+ /** What an enumeration's description says each value means: lines "* `Value` - meaning". */
156
+ static enumerationMeanings(description) {
157
+ const meanings = new Map();
158
+ for (const m of String(description ?? '').matchAll(/\*\s*`([^`]+)`\s*-\s*([^\r\n]*)/g)) {
159
+ if (m[2].trim()) meanings.set(m[1], m[2].trim());
160
+ }
161
+ return meanings;
162
+ }
163
+
164
+ /**
165
+ * A description as said: without the ISO 20022 version's "(DDD Entity) - "
166
+ * and "BIAN Service Domain (…) | … |" prefixes, or its trailing
167
+ * "Type|Type ([link])|Standard|ISO20022" reference.
168
+ */
169
+ static cleanDescription(description) {
170
+ let text = String(description ?? '').replace(/\r/g, '').trim();
171
+ if (!text || text.startsWith('>')) return '';
172
+ text = text.replace(/^\(DDD [^)]*\)\s*-\s*/, '');
173
+ if (/^BIAN Service Domain/.test(text)) text = text.slice(text.lastIndexOf('|') + 1).trim();
174
+ const bar = text.indexOf('|');
175
+ if (bar >= 0) {
176
+ // "… instance CashAccountContract|CashAccountContract (link)|Standard|ISO20022": the type named twice goes too.
177
+ const repeated = text.slice(bar + 1).trim().split(/[\s(|]/)[0];
178
+ text = text.slice(0, bar).trim();
179
+ if (repeated && text.endsWith(repeated)) text = text.slice(0, -repeated.length).trim();
180
+ }
181
+ return text.replace(/\s+/g, ' ').trim();
182
+ }
183
+ }