archimaid 0.0.0-stage → 0.1.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/CHANGELOG.md +32 -0
- package/FOUNDATION.md +108 -0
- package/LICENSE +21 -0
- package/README.md +271 -2
- package/dist/archimate/catalogue.d.ts +106 -0
- package/dist/archimate/catalogue.js +219 -0
- package/dist/archimate/catalogue.js.map +1 -0
- package/dist/archimate/diagnostics.d.ts +48 -0
- package/dist/archimate/diagnostics.js +64 -0
- package/dist/archimate/diagnostics.js.map +1 -0
- package/dist/archimate/frontmatter.d.ts +13 -0
- package/dist/archimate/frontmatter.js +62 -0
- package/dist/archimate/frontmatter.js.map +1 -0
- package/dist/archimate/grammar.d.ts +60 -0
- package/dist/archimate/grammar.js +273 -0
- package/dist/archimate/grammar.js.map +1 -0
- package/dist/archimate/lexer.d.ts +91 -0
- package/dist/archimate/lexer.js +215 -0
- package/dist/archimate/lexer.js.map +1 -0
- package/dist/archimate/model.d.ts +46 -0
- package/dist/archimate/model.js +2 -0
- package/dist/archimate/model.js.map +1 -0
- package/dist/archimate/nesting.d.ts +14 -0
- package/dist/archimate/nesting.js +84 -0
- package/dist/archimate/nesting.js.map +1 -0
- package/dist/archimate/parser.d.ts +14 -0
- package/dist/archimate/parser.js +53 -0
- package/dist/archimate/parser.js.map +1 -0
- package/dist/archimate/suggestions.d.ts +1 -0
- package/dist/archimate/suggestions.js +44 -0
- package/dist/archimate/suggestions.js.map +1 -0
- package/dist/archimate/validate.d.ts +4 -0
- package/dist/archimate/validate.js +402 -0
- package/dist/archimate/validate.js.map +1 -0
- package/dist/bundle/archimaid.esm.min.mjs +1 -0
- package/dist/bundle/chunks/archimateDiagram-WUCF6KHR.mjs +132 -0
- package/dist/bundle/chunks/chunk-QBMRZFD3.mjs +1 -0
- package/dist/bundle/chunks/elk.bundled-2VSLVJGB.mjs +26 -0
- package/dist/cli/render.d.ts +10 -0
- package/dist/cli/render.js +102 -0
- package/dist/cli/render.js.map +1 -0
- package/dist/cli/report.d.ts +20 -0
- package/dist/cli/report.js +39 -0
- package/dist/cli/report.js.map +1 -0
- package/dist/cli/sources.d.ts +19 -0
- package/dist/cli/sources.js +86 -0
- package/dist/cli/sources.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +137 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/language.d.ts +5 -0
- package/dist/language.js +3 -0
- package/dist/language.js.map +1 -0
- package/dist/mermaid/archimateDetector.d.ts +12 -0
- package/dist/mermaid/archimateDetector.js +29 -0
- package/dist/mermaid/archimateDetector.js.map +1 -0
- package/dist/mermaid/archimateDiagram.d.ts +9 -0
- package/dist/mermaid/archimateDiagram.js +75 -0
- package/dist/mermaid/archimateDiagram.js.map +1 -0
- package/dist/mermaid/archimateRenderer.d.ts +6 -0
- package/dist/mermaid/archimateRenderer.js +40 -0
- package/dist/mermaid/archimateRenderer.js.map +1 -0
- package/dist/mermaid/architectureLayout.d.ts +50 -0
- package/dist/mermaid/architectureLayout.js +144 -0
- package/dist/mermaid/architectureLayout.js.map +1 -0
- package/dist/mermaid/geometry.d.ts +3 -0
- package/dist/mermaid/geometry.js +20 -0
- package/dist/mermaid/geometry.js.map +1 -0
- package/dist/mermaid/hierarchy.d.ts +1 -0
- package/dist/mermaid/hierarchy.js +8 -0
- package/dist/mermaid/hierarchy.js.map +1 -0
- package/dist/mermaid/invariant.d.ts +1 -0
- package/dist/mermaid/invariant.js +7 -0
- package/dist/mermaid/invariant.js.map +1 -0
- package/dist/mermaid/orthogonalRouter.d.ts +4 -0
- package/dist/mermaid/orthogonalRouter.js +249 -0
- package/dist/mermaid/orthogonalRouter.js.map +1 -0
- package/dist/mermaid/relationshipPlacement.d.ts +3 -0
- package/dist/mermaid/relationshipPlacement.js +350 -0
- package/dist/mermaid/relationshipPlacement.js.map +1 -0
- package/dist/mermaid/render/draw.d.ts +17 -0
- package/dist/mermaid/render/draw.js +275 -0
- package/dist/mermaid/render/draw.js.map +1 -0
- package/dist/mermaid/render/elkRoutes.d.ts +6 -0
- package/dist/mermaid/render/elkRoutes.js +216 -0
- package/dist/mermaid/render/elkRoutes.js.map +1 -0
- package/dist/mermaid/render/graph.d.ts +17 -0
- package/dist/mermaid/render/graph.js +200 -0
- package/dist/mermaid/render/graph.js.map +1 -0
- package/dist/mermaid/render/labels.d.ts +12 -0
- package/dist/mermaid/render/labels.js +148 -0
- package/dist/mermaid/render/labels.js.map +1 -0
- package/dist/mermaid/render/layout.d.ts +12 -0
- package/dist/mermaid/render/layout.js +60 -0
- package/dist/mermaid/render/layout.js.map +1 -0
- package/dist/mermaid/render/measure.d.ts +16 -0
- package/dist/mermaid/render/measure.js +96 -0
- package/dist/mermaid/render/measure.js.map +1 -0
- package/dist/mermaid/render/place.d.ts +20 -0
- package/dist/mermaid/render/place.js +63 -0
- package/dist/mermaid/render/place.js.map +1 -0
- package/dist/mermaid/render/route.d.ts +29 -0
- package/dist/mermaid/render/route.js +113 -0
- package/dist/mermaid/render/route.js.map +1 -0
- package/dist/mermaid/render/shared.d.ts +83 -0
- package/dist/mermaid/render/shared.js +52 -0
- package/dist/mermaid/render/shared.js.map +1 -0
- package/dist/mermaid/render/svg.d.ts +6 -0
- package/dist/mermaid/render/svg.js +33 -0
- package/dist/mermaid/render/svg.js.map +1 -0
- package/dist/mermaid/render/viewport.d.ts +14 -0
- package/dist/mermaid/render/viewport.js +58 -0
- package/dist/mermaid/render/viewport.js.map +1 -0
- package/dist/mermaid/routing/anchors.d.ts +14 -0
- package/dist/mermaid/routing/anchors.js +134 -0
- package/dist/mermaid/routing/anchors.js.map +1 -0
- package/dist/mermaid/routing/bundles.d.ts +14 -0
- package/dist/mermaid/routing/bundles.js +94 -0
- package/dist/mermaid/routing/bundles.js.map +1 -0
- package/dist/mermaid/routing/congestion.d.ts +8 -0
- package/dist/mermaid/routing/congestion.js +70 -0
- package/dist/mermaid/routing/congestion.js.map +1 -0
- package/dist/mermaid/routing/constants.d.ts +13 -0
- package/dist/mermaid/routing/constants.js +17 -0
- package/dist/mermaid/routing/constants.js.map +1 -0
- package/dist/mermaid/routing/primitives.d.ts +33 -0
- package/dist/mermaid/routing/primitives.js +110 -0
- package/dist/mermaid/routing/primitives.js.map +1 -0
- package/dist/mermaid/routing/search.d.ts +4 -0
- package/dist/mermaid/routing/search.js +171 -0
- package/dist/mermaid/routing/search.js.map +1 -0
- package/dist/mermaid/routing/shapes.d.ts +8 -0
- package/dist/mermaid/routing/shapes.js +82 -0
- package/dist/mermaid/routing/shapes.js.map +1 -0
- package/dist/mermaid/routing/types.d.ts +37 -0
- package/dist/mermaid/routing/types.js +14 -0
- package/dist/mermaid/routing/types.js.map +1 -0
- package/dist/mermaid/styles.d.ts +89 -0
- package/dist/mermaid/styles.js +166 -0
- package/dist/mermaid/styles.js.map +1 -0
- package/docs/reference.md +86 -0
- package/examples/cross-layer-relationships.mmd +79 -0
- package/examples/cross-layer-relationships.svg +33 -0
- package/examples/element-preview.svg +1 -0
- package/examples/nested-components.mmd +21 -0
- package/examples/nested-components.svg +4 -0
- package/examples/order-fulfilment.mmd +10 -0
- package/examples/order-management.mmd +15 -0
- package/examples/order-management.svg +2 -0
- package/package.json +91 -4
- package/skills/archimaid/SKILL.md +123 -0
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import { elementTypes, getElementType, getRelationshipNotation, relationshipTypes } from './catalogue.js';
|
|
2
|
+
import { accDescrBlock, connectorNotations, metadata, quotedTextPattern } from './lexer.js';
|
|
3
|
+
import { validateNesting } from './nesting.js';
|
|
4
|
+
import { withSuggestion } from './suggestions.js';
|
|
5
|
+
const directionKeys = ['TB', 'TD', 'BT', 'LR', 'RL'];
|
|
6
|
+
const layoutKeys = ['architecture', 'framework', 'graph'];
|
|
7
|
+
const accessModes = ['read', 'write', 'readWrite', 'unspecified'];
|
|
8
|
+
const linkTargets = ['_blank', '_self', '_parent', '_top'];
|
|
9
|
+
const linkSchemes = new Set(['http', 'https', 'mailto']);
|
|
10
|
+
function readDirection(token, report) {
|
|
11
|
+
switch (token.image) {
|
|
12
|
+
case 'TD':
|
|
13
|
+
case 'TB':
|
|
14
|
+
return 'TB';
|
|
15
|
+
case 'BT':
|
|
16
|
+
case 'LR':
|
|
17
|
+
case 'RL':
|
|
18
|
+
return token.image;
|
|
19
|
+
default:
|
|
20
|
+
report('INVALID_DIRECTION', token, withSuggestion('Expected direction TB, TD, BT, LR, or RL.', token.image, directionKeys));
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function readLayout(token, report) {
|
|
25
|
+
const value = layoutKeys.find((key) => key === token.image);
|
|
26
|
+
if (!value) {
|
|
27
|
+
report('INVALID_LAYOUT', token, withSuggestion('Expected layout architecture, framework, or graph.', token.image, layoutKeys));
|
|
28
|
+
}
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
function readAccessMode(token, report) {
|
|
32
|
+
const value = accessModes.find((mode) => mode === token.image);
|
|
33
|
+
if (!value) {
|
|
34
|
+
report('INVALID_RELATIONSHIP_PROPERTY', token, withSuggestion('Expected access mode read, write, readWrite, or unspecified.', token.image, accessModes));
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
function checkXmlText(value, token, report) {
|
|
39
|
+
// XML 1.0 excludes control characters and unpaired UTF-16 surrogate code units.
|
|
40
|
+
// eslint-disable-next-line no-control-regex -- Allows tab, line feed and carriage return as the only control characters.
|
|
41
|
+
if (/[^\u0009\u000A\u000D\u0020-\uD7FF\uE000-\uFFFD\u{10000}-\u{10FFFF}]/u.test(value)) {
|
|
42
|
+
report('INVALID_TEXT', token, 'Text contains a character that cannot be written to SVG.');
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
function readQuotedText(token, report, options = {}) {
|
|
48
|
+
const { emptyMessage, image = token.image } = options;
|
|
49
|
+
const value = JSON.parse(image);
|
|
50
|
+
if (typeof value !== 'string')
|
|
51
|
+
throw new Error('Invalid ArchiMate quoted token.');
|
|
52
|
+
if (emptyMessage !== undefined && value.trim() === '') {
|
|
53
|
+
report('INVALID_TEXT', token, emptyMessage);
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
return checkXmlText(value, token, report);
|
|
57
|
+
}
|
|
58
|
+
function readMetadata(token) {
|
|
59
|
+
if (token.tokenType === accDescrBlock) {
|
|
60
|
+
const value = token.image
|
|
61
|
+
.slice(token.image.indexOf('{') + 1, -1)
|
|
62
|
+
.trim()
|
|
63
|
+
.replace(/[ \t]*(?:\r\n|\r|\n)[ \t]*/g, '\n');
|
|
64
|
+
return { name: 'accDescr', key: 'accDescription', value };
|
|
65
|
+
}
|
|
66
|
+
const separator = token.image.indexOf(':');
|
|
67
|
+
const name = token.image.slice(0, separator).trim();
|
|
68
|
+
const key = name === 'title' ? 'title' : name === 'accTitle' ? 'accTitle' : 'accDescription';
|
|
69
|
+
return { name, key, value: token.image.slice(separator + 1).trim() };
|
|
70
|
+
}
|
|
71
|
+
// A fully quoted metadata value is decoded like other text, so it can hold " %%" or escapes such as \u0025.
|
|
72
|
+
const wholeQuotedText = new RegExp('^' + quotedTextPattern.source + '$');
|
|
73
|
+
function collectSetting(statement, settings, report) {
|
|
74
|
+
switch (statement.kind) {
|
|
75
|
+
case 'direction':
|
|
76
|
+
if (settings.directionDeclared) {
|
|
77
|
+
report('DUPLICATE_DECLARATION', statement.value, 'Direction is already set.');
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
settings.directionDeclared = true;
|
|
81
|
+
settings.direction = readDirection(statement.value, report);
|
|
82
|
+
return;
|
|
83
|
+
case 'layout':
|
|
84
|
+
if (settings.layoutDeclared) {
|
|
85
|
+
report('DUPLICATE_DECLARATION', statement.value, 'Layout is already set.');
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
settings.layoutDeclared = true;
|
|
89
|
+
settings.layout = readLayout(statement.value, report);
|
|
90
|
+
return;
|
|
91
|
+
case 'metadata': {
|
|
92
|
+
const { name, key, value } = readMetadata(statement.value);
|
|
93
|
+
if (settings.declaredMetadata.has(key)) {
|
|
94
|
+
report('DUPLICATE_DECLARATION', statement.value, name + ' is already set.');
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
settings.declaredMetadata.add(key);
|
|
98
|
+
const text = statement.value.tokenType === metadata && wholeQuotedText.test(value)
|
|
99
|
+
? readQuotedText(statement.value, report, { emptyMessage: name + ' must not be empty.', image: value })
|
|
100
|
+
: checkXmlText(value, statement.value, report);
|
|
101
|
+
if (text !== undefined)
|
|
102
|
+
settings.metadata[key] = text;
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function collectEntity(statement, collected, report) {
|
|
108
|
+
if (collected.entities.has(statement.id.image)) {
|
|
109
|
+
report('DUPLICATE_ID', statement.id, 'ID "' + statement.id.image + '" is already declared.');
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
collected.entities.set(statement.id.image, statement);
|
|
113
|
+
if (statement.kind === 'element') {
|
|
114
|
+
if (!getElementType(statement.type.image)) {
|
|
115
|
+
report('UNKNOWN_ELEMENT_TYPE', statement.type, withSuggestion('Unknown element type "' + statement.type.image + '".', statement.type.image, Object.keys(elementTypes)));
|
|
116
|
+
}
|
|
117
|
+
collected.elements.push(statement);
|
|
118
|
+
}
|
|
119
|
+
else if (statement.kind === 'relationship') {
|
|
120
|
+
collected.relationships.push(statement);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
collected.notes.push(statement);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function collectDeclarations(declarations, report) {
|
|
127
|
+
const collected = {
|
|
128
|
+
settings: {
|
|
129
|
+
directionDeclared: false,
|
|
130
|
+
layoutDeclared: false,
|
|
131
|
+
direction: undefined,
|
|
132
|
+
layout: undefined,
|
|
133
|
+
declaredMetadata: new Set(),
|
|
134
|
+
metadata: {},
|
|
135
|
+
},
|
|
136
|
+
entities: new Map(),
|
|
137
|
+
descriptions: new Map(),
|
|
138
|
+
clicks: new Map(),
|
|
139
|
+
elements: [],
|
|
140
|
+
relationships: [],
|
|
141
|
+
notes: [],
|
|
142
|
+
nesting: [],
|
|
143
|
+
};
|
|
144
|
+
for (const statement of declarations) {
|
|
145
|
+
switch (statement.kind) {
|
|
146
|
+
case 'direction':
|
|
147
|
+
case 'layout':
|
|
148
|
+
case 'metadata':
|
|
149
|
+
collectSetting(statement, collected.settings, report);
|
|
150
|
+
break;
|
|
151
|
+
case 'description':
|
|
152
|
+
if (collected.descriptions.has(statement.id.image)) {
|
|
153
|
+
report('DUPLICATE_DECLARATION', statement.id, 'Description is already set for "' + statement.id.image + '".');
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
collected.descriptions.set(statement.id.image, statement);
|
|
157
|
+
break;
|
|
158
|
+
case 'element':
|
|
159
|
+
case 'relationship':
|
|
160
|
+
case 'note':
|
|
161
|
+
collectEntity(statement, collected, report);
|
|
162
|
+
break;
|
|
163
|
+
case 'connector':
|
|
164
|
+
collected.relationships.push(statement);
|
|
165
|
+
break;
|
|
166
|
+
case 'nesting':
|
|
167
|
+
collected.nesting.push(statement);
|
|
168
|
+
break;
|
|
169
|
+
case 'click':
|
|
170
|
+
if (collected.clicks.has(statement.id.image)) {
|
|
171
|
+
report('DUPLICATE_DECLARATION', statement.id, `A link is already set for "${statement.id.image}".`);
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
collected.clicks.set(statement.id.image, statement);
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return collected;
|
|
179
|
+
}
|
|
180
|
+
function checkDescriptionTargets(collected, report) {
|
|
181
|
+
for (const [id, statement] of collected.descriptions) {
|
|
182
|
+
if (collected.entities.get(id)?.kind !== 'element') {
|
|
183
|
+
report('UNKNOWN_ELEMENT', statement.id, 'Description refers to an undeclared element "' + id + '".');
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
for (const [id, statement] of collected.clicks) {
|
|
187
|
+
if (collected.entities.get(id)?.kind !== 'element') {
|
|
188
|
+
report('UNKNOWN_ELEMENT', statement.id, `Link refers to an undeclared element "${id}".`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
// Only web and mail links, and relative ones, so that diagram text cannot run script through a link.
|
|
193
|
+
function readLink(statement, report) {
|
|
194
|
+
const href = readQuotedText(statement.url, report, { emptyMessage: 'Link URL must not be empty.' });
|
|
195
|
+
const tooltip = statement.tooltip && readQuotedText(statement.tooltip, report);
|
|
196
|
+
// Browsers ignore whitespace and control characters in a scheme, so "java\tscript:" must be caught too.
|
|
197
|
+
// eslint-disable-next-line no-control-regex -- Removes the characters a browser ignores.
|
|
198
|
+
const compact = href?.replace(/[\s\u0000-\u001F]/g, '');
|
|
199
|
+
const scheme = compact && /^([a-z][a-z\d+.-]*):/i.exec(compact)?.[1]?.toLowerCase();
|
|
200
|
+
if (scheme !== undefined && !linkSchemes.has(scheme)) {
|
|
201
|
+
report('INVALID_LINK', statement.url, `Link URL scheme "${scheme}:" is not allowed. Use http, https or mailto.`);
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
const targetImage = statement.target?.image;
|
|
205
|
+
const target = linkTargets.find((candidate) => candidate === targetImage);
|
|
206
|
+
if (statement.target && target === undefined) {
|
|
207
|
+
report('INVALID_LINK', statement.target, withSuggestion(`Unknown link target "${statement.target.image}".`, statement.target.image, linkTargets));
|
|
208
|
+
return undefined;
|
|
209
|
+
}
|
|
210
|
+
if (href === undefined)
|
|
211
|
+
return undefined;
|
|
212
|
+
return { href, ...(tooltip !== undefined && { tooltip }), ...(target && { target }) };
|
|
213
|
+
}
|
|
214
|
+
function buildNotes(collected, report) {
|
|
215
|
+
const notes = [];
|
|
216
|
+
for (const statement of collected.notes) {
|
|
217
|
+
if (statement.anchor && collected.entities.get(statement.anchor.image)?.kind !== 'element') {
|
|
218
|
+
report('INVALID_NOTE_TARGET', statement.anchor, 'A note must be placed on a declared ArchiMate element.');
|
|
219
|
+
}
|
|
220
|
+
const text = readQuotedText(statement.text, report, { emptyMessage: 'Note text must not be empty.' });
|
|
221
|
+
if (text !== undefined) {
|
|
222
|
+
notes.push({ id: statement.id.image, text, ...(statement.anchor && { on: statement.anchor.image }) });
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return notes;
|
|
226
|
+
}
|
|
227
|
+
function buildElements(collected, report) {
|
|
228
|
+
const elements = [];
|
|
229
|
+
for (const statement of collected.elements) {
|
|
230
|
+
const name = readQuotedText(statement.name, report, { emptyMessage: 'Element name must not be empty.' });
|
|
231
|
+
const elementDescription = collected.descriptions.get(statement.id.image);
|
|
232
|
+
const descriptionText = elementDescription && readQuotedText(elementDescription.value, report);
|
|
233
|
+
const click = collected.clicks.get(statement.id.image);
|
|
234
|
+
const link = click && readLink(click, report);
|
|
235
|
+
if (name !== undefined) {
|
|
236
|
+
elements.push({
|
|
237
|
+
id: statement.id.image,
|
|
238
|
+
type: statement.type.image,
|
|
239
|
+
name,
|
|
240
|
+
...(descriptionText !== undefined && { description: descriptionText }),
|
|
241
|
+
...(link && { link }),
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return elements;
|
|
246
|
+
}
|
|
247
|
+
function resolveEndpoint(context, token) {
|
|
248
|
+
const entity = context.entities.get(token.image);
|
|
249
|
+
if (!entity) {
|
|
250
|
+
context.unknownEndpointIds.add(token.image);
|
|
251
|
+
context.report('UNKNOWN_ELEMENT', token, 'Unknown element or note "' + token.image + '".');
|
|
252
|
+
return undefined;
|
|
253
|
+
}
|
|
254
|
+
if (entity.kind === 'relationship') {
|
|
255
|
+
context.report('UNSUPPORTED_ENDPOINT', token, 'Relationship endpoints must be elements or notes.');
|
|
256
|
+
return undefined;
|
|
257
|
+
}
|
|
258
|
+
return entity;
|
|
259
|
+
}
|
|
260
|
+
function readLabel(context, token) {
|
|
261
|
+
return (token &&
|
|
262
|
+
readQuotedText(token, context.report, {
|
|
263
|
+
emptyMessage: 'Relationship label must not be empty. Omit the label instead.',
|
|
264
|
+
}));
|
|
265
|
+
}
|
|
266
|
+
function generateRelationshipId(context, source, type, target) {
|
|
267
|
+
const base = source + '__' + type + '__' + target;
|
|
268
|
+
let id = base;
|
|
269
|
+
for (let suffix = 2; context.usedIds.has(id); suffix++)
|
|
270
|
+
id = `${base}_${suffix}`;
|
|
271
|
+
context.usedIds.add(id);
|
|
272
|
+
return id;
|
|
273
|
+
}
|
|
274
|
+
function warnOnRepeatedShorthand(context, statement, labelText) {
|
|
275
|
+
const key = JSON.stringify([
|
|
276
|
+
statement.source.image,
|
|
277
|
+
statement.connector.tokenType.name,
|
|
278
|
+
statement.target.image,
|
|
279
|
+
labelText ?? null,
|
|
280
|
+
]);
|
|
281
|
+
const original = context.shorthandStatements.get(key);
|
|
282
|
+
if (!original) {
|
|
283
|
+
context.shorthandStatements.set(key, statement);
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
context.diagnostics.warning('DUPLICATE_RELATIONSHIP', statement.source, statement.label ?? statement.target, `This relationship repeats the one on line ${context.diagnostics.line(original.source)}. ` +
|
|
287
|
+
'Remove the copy, or use the long form with distinct IDs if both are intended.');
|
|
288
|
+
}
|
|
289
|
+
function specifyShorthand(statement) {
|
|
290
|
+
const notation = connectorNotations.get(statement.connector.tokenType);
|
|
291
|
+
if (!notation)
|
|
292
|
+
throw new Error('Unknown ArchiMate connector token "' + statement.connector.image + '".');
|
|
293
|
+
return {
|
|
294
|
+
notation: 'shorthand',
|
|
295
|
+
type: notation.type,
|
|
296
|
+
source: statement.source,
|
|
297
|
+
target: statement.target,
|
|
298
|
+
access: notation.access,
|
|
299
|
+
directed: notation.directed === true,
|
|
300
|
+
label: statement.label,
|
|
301
|
+
declaredId: undefined,
|
|
302
|
+
knownType: true,
|
|
303
|
+
shorthand: statement,
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
// Property errors are reported here, before endpoints and labels, to keep the established diagnostic order.
|
|
307
|
+
function specifyLongForm(context, statement) {
|
|
308
|
+
const { report } = context;
|
|
309
|
+
const type = statement.type.image;
|
|
310
|
+
const knownType = getRelationshipNotation(type) !== undefined;
|
|
311
|
+
if (!knownType) {
|
|
312
|
+
report('UNKNOWN_RELATIONSHIP_TYPE', statement.type, withSuggestion('Unknown relationship type "' + type + '".', type, relationshipTypes));
|
|
313
|
+
}
|
|
314
|
+
if (statement.mode && type !== 'access') {
|
|
315
|
+
report('INVALID_RELATIONSHIP_PROPERTY', statement.mode, 'Access mode is only valid on access relationships.');
|
|
316
|
+
}
|
|
317
|
+
if (statement.directed && type !== 'association') {
|
|
318
|
+
report('INVALID_RELATIONSHIP_PROPERTY', statement.directed, '"directed" is only valid on association relationships.');
|
|
319
|
+
}
|
|
320
|
+
return {
|
|
321
|
+
notation: 'longForm',
|
|
322
|
+
type,
|
|
323
|
+
source: statement.source,
|
|
324
|
+
target: statement.target,
|
|
325
|
+
access: statement.mode && readAccessMode(statement.mode, report),
|
|
326
|
+
directed: statement.directed !== undefined,
|
|
327
|
+
label: statement.label,
|
|
328
|
+
declaredId: statement.id,
|
|
329
|
+
knownType,
|
|
330
|
+
shorthand: undefined,
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
function resolveRelationship(context, specification) {
|
|
334
|
+
const endpointsValid = [
|
|
335
|
+
resolveEndpoint(context, specification.source),
|
|
336
|
+
resolveEndpoint(context, specification.target),
|
|
337
|
+
].every(Boolean);
|
|
338
|
+
const labelText = readLabel(context, specification.label);
|
|
339
|
+
const source = specification.source.image;
|
|
340
|
+
const target = specification.target.image;
|
|
341
|
+
const id = specification.declaredId?.image ?? generateRelationshipId(context, source, specification.type, target);
|
|
342
|
+
const labelRejected = specification.label !== undefined && labelText === undefined;
|
|
343
|
+
if (!endpointsValid || !specification.knownType) {
|
|
344
|
+
context.invalidRelationshipIds.add(id);
|
|
345
|
+
}
|
|
346
|
+
else if (specification.shorthand && !labelRejected) {
|
|
347
|
+
warnOnRepeatedShorthand(context, specification.shorthand, labelText);
|
|
348
|
+
}
|
|
349
|
+
const access = specification.access === 'unspecified' ? undefined : specification.access;
|
|
350
|
+
return {
|
|
351
|
+
id,
|
|
352
|
+
type: specification.type,
|
|
353
|
+
source,
|
|
354
|
+
target,
|
|
355
|
+
...(access && { access }),
|
|
356
|
+
...(specification.directed && { directed: true }),
|
|
357
|
+
...(labelText !== undefined && { label: labelText }),
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
function buildModel(settings, parts) {
|
|
361
|
+
const selectedLayout = settings.layout ?? (settings.direction === undefined ? 'architecture' : undefined);
|
|
362
|
+
return {
|
|
363
|
+
direction: settings.direction ?? 'TB',
|
|
364
|
+
...(selectedLayout && { layout: selectedLayout }),
|
|
365
|
+
...settings.metadata,
|
|
366
|
+
elements: parts.elements,
|
|
367
|
+
relationships: parts.relationships,
|
|
368
|
+
...(parts.notes.length > 0 && { notes: parts.notes }),
|
|
369
|
+
...(parts.nesting.length > 0 && { nesting: parts.nesting }),
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
// The checks run in a fixed order because parseArchiMate throws the first error found.
|
|
373
|
+
export function validateDeclarations(declarations, diagnostics) {
|
|
374
|
+
const report = (code, token, message) => {
|
|
375
|
+
diagnostics.error(code, token, message);
|
|
376
|
+
};
|
|
377
|
+
const collected = collectDeclarations(declarations, report);
|
|
378
|
+
checkDescriptionTargets(collected, report);
|
|
379
|
+
const notes = buildNotes(collected, report);
|
|
380
|
+
const context = {
|
|
381
|
+
diagnostics,
|
|
382
|
+
report,
|
|
383
|
+
entities: collected.entities,
|
|
384
|
+
usedIds: new Set(collected.entities.keys()),
|
|
385
|
+
invalidRelationshipIds: new Set(),
|
|
386
|
+
unknownEndpointIds: new Set(),
|
|
387
|
+
shorthandStatements: new Map(),
|
|
388
|
+
};
|
|
389
|
+
const relationships = collected.relationships.map((statement) => resolveRelationship(context, statement.kind === 'connector' ? specifyShorthand(statement) : specifyLongForm(context, statement)));
|
|
390
|
+
const nesting = validateNesting(collected.nesting, collected.entities, {
|
|
391
|
+
relationships,
|
|
392
|
+
relationshipsById: new Map(relationships.map((entry) => [entry.id, entry])),
|
|
393
|
+
invalidRelationshipIds: context.invalidRelationshipIds,
|
|
394
|
+
unknownEndpointIds: context.unknownEndpointIds,
|
|
395
|
+
report,
|
|
396
|
+
});
|
|
397
|
+
const elements = buildElements(collected, report);
|
|
398
|
+
if (diagnostics.hasErrors)
|
|
399
|
+
return undefined;
|
|
400
|
+
return buildModel(collected.settings, { elements, relationships, notes, nesting });
|
|
401
|
+
}
|
|
402
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/archimate/validate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAI1G,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAY5F,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AASlD,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AACrD,MAAM,UAAU,GAA+B,CAAC,cAAc,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;AACtF,MAAM,WAAW,GAA0B,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC;AACzF,MAAM,WAAW,GAAmC,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;AA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B;QACtD,kBAAkB,EAAE,OAAO,CAAC,kBAAkB;QAC9C,MAAM;KACP,CAAC,CAAC;IACH,MAAM,QAAQ,GAAG,aAAa,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAClD,IAAI,WAAW,CAAC,SAAS;QAAE,OAAO,SAAS,CAAC;IAC5C,OAAO,UAAU,CAAC,SAAS,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;AACrF,CAAC","sourcesContent":["import type { IToken } from 'chevrotain';\nimport { elementTypes, getElementType, getRelationshipNotation, relationshipTypes } from './catalogue.js';\nimport type { AccessMode } from './catalogue.js';\nimport type { DiagnosticCollector, Report } from './diagnostics.js';\nimport type { ConnectorDeclaration, Declaration, RelationshipDeclaration } from './grammar.js';\nimport { accDescrBlock, connectorNotations, metadata, quotedTextPattern } from './lexer.js';\nimport type {\n ArchiMateDirection,\n ArchiMateElement,\n ArchiMateLayout,\n ArchiMateLink,\n ArchiMateLinkTarget,\n ArchiMateModel,\n ArchiMateNesting,\n ArchiMateNote,\n ArchiMateRelationship,\n} from './model.js';\nimport { validateNesting } from './nesting.js';\nimport type { NestingDeclaration } from './nesting.js';\nimport { withSuggestion } from './suggestions.js';\n\ntype MetadataKey = 'title' | 'accTitle' | 'accDescription';\ntype ElementDeclaration = Extract<Declaration, { kind: 'element' }>;\ntype DescriptionDeclaration = Extract<Declaration, { kind: 'description' }>;\ntype NoteDeclaration = Extract<Declaration, { kind: 'note' }>;\ntype ClickDeclaration = Extract<Declaration, { kind: 'click' }>;\ntype EntityDeclaration = ElementDeclaration | RelationshipDeclaration | NoteDeclaration;\n\nconst directionKeys = ['TB', 'TD', 'BT', 'LR', 'RL'];\nconst layoutKeys: readonly ArchiMateLayout[] = ['architecture', 'framework', 'graph'];\nconst accessModes: readonly AccessMode[] = ['read', 'write', 'readWrite', 'unspecified'];\nconst linkTargets: readonly ArchiMateLinkTarget[] = ['_blank', '_self', '_parent', '_top'];\nconst linkSchemes = new Set(['http', 'https', 'mailto']);\n\nfunction readDirection(token: IToken, report: Report): ArchiMateDirection | undefined {\n switch (token.image) {\n case 'TD':\n case 'TB':\n return 'TB';\n case 'BT':\n case 'LR':\n case 'RL':\n return token.image;\n default:\n report(\n 'INVALID_DIRECTION',\n token,\n withSuggestion('Expected direction TB, TD, BT, LR, or RL.', token.image, directionKeys),\n );\n return undefined;\n }\n}\n\nfunction readLayout(token: IToken, report: Report): ArchiMateLayout | undefined {\n const value = layoutKeys.find((key) => key === token.image);\n if (!value) {\n report(\n 'INVALID_LAYOUT',\n token,\n withSuggestion('Expected layout architecture, framework, or graph.', token.image, layoutKeys),\n );\n }\n return value;\n}\n\nfunction readAccessMode(token: IToken, report: Report): AccessMode | undefined {\n const value = accessModes.find((mode) => mode === token.image);\n if (!value) {\n report(\n 'INVALID_RELATIONSHIP_PROPERTY',\n token,\n withSuggestion('Expected access mode read, write, readWrite, or unspecified.', token.image, accessModes),\n );\n }\n return value;\n}\n\nfunction checkXmlText(value: string, token: IToken, report: Report): string | undefined {\n // XML 1.0 excludes control characters and unpaired UTF-16 surrogate code units.\n // eslint-disable-next-line no-control-regex -- Allows tab, line feed and carriage return as the only control characters.\n if (/[^\\u0009\\u000A\\u000D\\u0020-\\uD7FF\\uE000-\\uFFFD\\u{10000}-\\u{10FFFF}]/u.test(value)) {\n report('INVALID_TEXT', token, 'Text contains a character that cannot be written to SVG.');\n return undefined;\n }\n return value;\n}\n\ninterface QuotedTextOptions {\n // Text that must not be blank names what is missing; omitting it allows blank text.\n readonly emptyMessage?: string;\n // Metadata values are quoted text inside a larger token, so they pass the quoted part separately.\n readonly image?: string;\n}\n\nfunction readQuotedText(token: IToken, report: Report, options: QuotedTextOptions = {}): string | undefined {\n const { emptyMessage, image = token.image } = options;\n const value: unknown = JSON.parse(image);\n if (typeof value !== 'string') throw new Error('Invalid ArchiMate quoted token.');\n if (emptyMessage !== undefined && value.trim() === '') {\n report('INVALID_TEXT', token, emptyMessage);\n return undefined;\n }\n return checkXmlText(value, token, report);\n}\n\nfunction readMetadata(token: IToken): { name: string; key: MetadataKey; value: string } {\n if (token.tokenType === accDescrBlock) {\n const value = token.image\n .slice(token.image.indexOf('{') + 1, -1)\n .trim()\n .replace(/[ \\t]*(?:\\r\\n|\\r|\\n)[ \\t]*/g, '\\n');\n return { name: 'accDescr', key: 'accDescription', value };\n }\n const separator = token.image.indexOf(':');\n const name = token.image.slice(0, separator).trim();\n const key = name === 'title' ? 'title' : name === 'accTitle' ? 'accTitle' : 'accDescription';\n return { name, key, value: token.image.slice(separator + 1).trim() };\n}\n\n// A fully quoted metadata value is decoded like other text, so it can hold \" %%\" or escapes such as \\u0025.\nconst wholeQuotedText = new RegExp('^' + quotedTextPattern.source + '$');\n\ninterface DiagramSettings {\n directionDeclared: boolean;\n layoutDeclared: boolean;\n direction: ArchiMateDirection | undefined;\n layout: ArchiMateLayout | undefined;\n readonly declaredMetadata: Set<MetadataKey>;\n readonly metadata: Partial<Record<MetadataKey, string>>;\n}\n\ninterface CollectedDeclarations {\n readonly settings: DiagramSettings;\n readonly entities: Map<string, EntityDeclaration>;\n readonly descriptions: Map<string, DescriptionDeclaration>;\n readonly clicks: Map<string, ClickDeclaration>;\n readonly elements: ElementDeclaration[];\n readonly relationships: (RelationshipDeclaration | ConnectorDeclaration)[];\n readonly notes: NoteDeclaration[];\n readonly nesting: NestingDeclaration[];\n}\n\ninterface ValidationContext {\n readonly diagnostics: DiagnosticCollector;\n readonly report: Report;\n readonly entities: ReadonlyMap<string, EntityDeclaration>;\n // Generated shorthand IDs must avoid every declared ID and every ID generated before them.\n readonly usedIds: Set<string>;\n readonly invalidRelationshipIds: Set<string>;\n readonly unknownEndpointIds: Set<string>;\n readonly shorthandStatements: Map<string, ConnectorDeclaration>;\n}\n\nfunction collectSetting(\n statement: Extract<Declaration, { kind: 'direction' | 'layout' | 'metadata' }>,\n settings: DiagramSettings,\n report: Report,\n): void {\n switch (statement.kind) {\n case 'direction':\n if (settings.directionDeclared) {\n report('DUPLICATE_DECLARATION', statement.value, 'Direction is already set.');\n return;\n }\n settings.directionDeclared = true;\n settings.direction = readDirection(statement.value, report);\n return;\n case 'layout':\n if (settings.layoutDeclared) {\n report('DUPLICATE_DECLARATION', statement.value, 'Layout is already set.');\n return;\n }\n settings.layoutDeclared = true;\n settings.layout = readLayout(statement.value, report);\n return;\n case 'metadata': {\n const { name, key, value } = readMetadata(statement.value);\n if (settings.declaredMetadata.has(key)) {\n report('DUPLICATE_DECLARATION', statement.value, name + ' is already set.');\n return;\n }\n settings.declaredMetadata.add(key);\n const text =\n statement.value.tokenType === metadata && wholeQuotedText.test(value)\n ? readQuotedText(statement.value, report, { emptyMessage: name + ' must not be empty.', image: value })\n : checkXmlText(value, statement.value, report);\n if (text !== undefined) settings.metadata[key] = text;\n return;\n }\n }\n}\n\nfunction collectEntity(statement: EntityDeclaration, collected: CollectedDeclarations, report: Report): void {\n if (collected.entities.has(statement.id.image)) {\n report('DUPLICATE_ID', statement.id, 'ID \"' + statement.id.image + '\" is already declared.');\n return;\n }\n collected.entities.set(statement.id.image, statement);\n if (statement.kind === 'element') {\n if (!getElementType(statement.type.image)) {\n report(\n 'UNKNOWN_ELEMENT_TYPE',\n statement.type,\n withSuggestion(\n 'Unknown element type \"' + statement.type.image + '\".',\n statement.type.image,\n Object.keys(elementTypes),\n ),\n );\n }\n collected.elements.push(statement);\n } else if (statement.kind === 'relationship') {\n collected.relationships.push(statement);\n } else {\n collected.notes.push(statement);\n }\n}\n\nfunction collectDeclarations(declarations: readonly Declaration[], report: Report): CollectedDeclarations {\n const collected: CollectedDeclarations = {\n settings: {\n directionDeclared: false,\n layoutDeclared: false,\n direction: undefined,\n layout: undefined,\n declaredMetadata: new Set(),\n metadata: {},\n },\n entities: new Map(),\n descriptions: new Map(),\n clicks: new Map(),\n elements: [],\n relationships: [],\n notes: [],\n nesting: [],\n };\n for (const statement of declarations) {\n switch (statement.kind) {\n case 'direction':\n case 'layout':\n case 'metadata':\n collectSetting(statement, collected.settings, report);\n break;\n case 'description':\n if (collected.descriptions.has(statement.id.image)) {\n report('DUPLICATE_DECLARATION', statement.id, 'Description is already set for \"' + statement.id.image + '\".');\n break;\n }\n collected.descriptions.set(statement.id.image, statement);\n break;\n case 'element':\n case 'relationship':\n case 'note':\n collectEntity(statement, collected, report);\n break;\n case 'connector':\n collected.relationships.push(statement);\n break;\n case 'nesting':\n collected.nesting.push(statement);\n break;\n case 'click':\n if (collected.clicks.has(statement.id.image)) {\n report('DUPLICATE_DECLARATION', statement.id, `A link is already set for \"${statement.id.image}\".`);\n break;\n }\n collected.clicks.set(statement.id.image, statement);\n break;\n }\n }\n return collected;\n}\n\nfunction checkDescriptionTargets(collected: CollectedDeclarations, report: Report): void {\n for (const [id, statement] of collected.descriptions) {\n if (collected.entities.get(id)?.kind !== 'element') {\n report('UNKNOWN_ELEMENT', statement.id, 'Description refers to an undeclared element \"' + id + '\".');\n }\n }\n for (const [id, statement] of collected.clicks) {\n if (collected.entities.get(id)?.kind !== 'element') {\n report('UNKNOWN_ELEMENT', statement.id, `Link refers to an undeclared element \"${id}\".`);\n }\n }\n}\n\n// Only web and mail links, and relative ones, so that diagram text cannot run script through a link.\nfunction readLink(statement: ClickDeclaration, report: Report): ArchiMateLink | undefined {\n const href = readQuotedText(statement.url, report, { emptyMessage: 'Link URL must not be empty.' });\n const tooltip = statement.tooltip && readQuotedText(statement.tooltip, report);\n // Browsers ignore whitespace and control characters in a scheme, so \"java\\tscript:\" must be caught too.\n // eslint-disable-next-line no-control-regex -- Removes the characters a browser ignores.\n const compact = href?.replace(/[\\s\\u0000-\\u001F]/g, '');\n const scheme = compact && /^([a-z][a-z\\d+.-]*):/i.exec(compact)?.[1]?.toLowerCase();\n if (scheme !== undefined && !linkSchemes.has(scheme)) {\n report('INVALID_LINK', statement.url, `Link URL scheme \"${scheme}:\" is not allowed. Use http, https or mailto.`);\n return undefined;\n }\n const targetImage = statement.target?.image;\n const target = linkTargets.find((candidate) => candidate === targetImage);\n if (statement.target && target === undefined) {\n report(\n 'INVALID_LINK',\n statement.target,\n withSuggestion(`Unknown link target \"${statement.target.image}\".`, statement.target.image, linkTargets),\n );\n return undefined;\n }\n if (href === undefined) return undefined;\n return { href, ...(tooltip !== undefined && { tooltip }), ...(target && { target }) };\n}\n\nfunction buildNotes(collected: CollectedDeclarations, report: Report): ArchiMateNote[] {\n const notes: ArchiMateNote[] = [];\n for (const statement of collected.notes) {\n if (statement.anchor && collected.entities.get(statement.anchor.image)?.kind !== 'element') {\n report('INVALID_NOTE_TARGET', statement.anchor, 'A note must be placed on a declared ArchiMate element.');\n }\n const text = readQuotedText(statement.text, report, { emptyMessage: 'Note text must not be empty.' });\n if (text !== undefined) {\n notes.push({ id: statement.id.image, text, ...(statement.anchor && { on: statement.anchor.image }) });\n }\n }\n return notes;\n}\n\nfunction buildElements(collected: CollectedDeclarations, report: Report): ArchiMateElement[] {\n const elements: ArchiMateElement[] = [];\n for (const statement of collected.elements) {\n const name = readQuotedText(statement.name, report, { emptyMessage: 'Element name must not be empty.' });\n const elementDescription = collected.descriptions.get(statement.id.image);\n const descriptionText = elementDescription && readQuotedText(elementDescription.value, report);\n const click = collected.clicks.get(statement.id.image);\n const link = click && readLink(click, report);\n if (name !== undefined) {\n elements.push({\n id: statement.id.image,\n type: statement.type.image,\n name,\n ...(descriptionText !== undefined && { description: descriptionText }),\n ...(link && { link }),\n });\n }\n }\n return elements;\n}\n\nfunction resolveEndpoint(context: ValidationContext, token: IToken): ElementDeclaration | NoteDeclaration | undefined {\n const entity = context.entities.get(token.image);\n if (!entity) {\n context.unknownEndpointIds.add(token.image);\n context.report('UNKNOWN_ELEMENT', token, 'Unknown element or note \"' + token.image + '\".');\n return undefined;\n }\n if (entity.kind === 'relationship') {\n context.report('UNSUPPORTED_ENDPOINT', token, 'Relationship endpoints must be elements or notes.');\n return undefined;\n }\n return entity;\n}\n\nfunction readLabel(context: ValidationContext, token: IToken | undefined): string | undefined {\n return (\n token &&\n readQuotedText(token, context.report, {\n emptyMessage: 'Relationship label must not be empty. Omit the label instead.',\n })\n );\n}\n\nfunction generateRelationshipId(context: ValidationContext, source: string, type: string, target: string): string {\n const base = source + '__' + type + '__' + target;\n let id = base;\n for (let suffix = 2; context.usedIds.has(id); suffix++) id = `${base}_${suffix}`;\n context.usedIds.add(id);\n return id;\n}\n\nfunction warnOnRepeatedShorthand(\n context: ValidationContext,\n statement: ConnectorDeclaration,\n labelText: string | undefined,\n): void {\n const key = JSON.stringify([\n statement.source.image,\n statement.connector.tokenType.name,\n statement.target.image,\n labelText ?? null,\n ]);\n const original = context.shorthandStatements.get(key);\n if (!original) {\n context.shorthandStatements.set(key, statement);\n return;\n }\n context.diagnostics.warning(\n 'DUPLICATE_RELATIONSHIP',\n statement.source,\n statement.label ?? statement.target,\n `This relationship repeats the one on line ${context.diagnostics.line(original.source)}. ` +\n 'Remove the copy, or use the long form with distinct IDs if both are intended.',\n );\n}\n\n// Both notations map to this before resolution, so endpoint, label and identity rules exist once.\ninterface RelationshipSpecification {\n readonly notation: 'longForm' | 'shorthand';\n readonly type: string;\n readonly source: IToken;\n readonly target: IToken;\n readonly access: AccessMode | undefined;\n readonly directed: boolean;\n readonly label: IToken | undefined;\n readonly declaredId: IToken | undefined;\n readonly knownType: boolean;\n readonly shorthand: ConnectorDeclaration | undefined;\n}\n\nfunction specifyShorthand(statement: ConnectorDeclaration): RelationshipSpecification {\n const notation = connectorNotations.get(statement.connector.tokenType);\n if (!notation) throw new Error('Unknown ArchiMate connector token \"' + statement.connector.image + '\".');\n return {\n notation: 'shorthand',\n type: notation.type,\n source: statement.source,\n target: statement.target,\n access: notation.access,\n directed: notation.directed === true,\n label: statement.label,\n declaredId: undefined,\n knownType: true,\n shorthand: statement,\n };\n}\n\n// Property errors are reported here, before endpoints and labels, to keep the established diagnostic order.\nfunction specifyLongForm(context: ValidationContext, statement: RelationshipDeclaration): RelationshipSpecification {\n const { report } = context;\n const type = statement.type.image;\n const knownType = getRelationshipNotation(type) !== undefined;\n if (!knownType) {\n report(\n 'UNKNOWN_RELATIONSHIP_TYPE',\n statement.type,\n withSuggestion('Unknown relationship type \"' + type + '\".', type, relationshipTypes),\n );\n }\n if (statement.mode && type !== 'access') {\n report('INVALID_RELATIONSHIP_PROPERTY', statement.mode, 'Access mode is only valid on access relationships.');\n }\n if (statement.directed && type !== 'association') {\n report(\n 'INVALID_RELATIONSHIP_PROPERTY',\n statement.directed,\n '\"directed\" is only valid on association relationships.',\n );\n }\n return {\n notation: 'longForm',\n type,\n source: statement.source,\n target: statement.target,\n access: statement.mode && readAccessMode(statement.mode, report),\n directed: statement.directed !== undefined,\n label: statement.label,\n declaredId: statement.id,\n knownType,\n shorthand: undefined,\n };\n}\n\nfunction resolveRelationship(\n context: ValidationContext,\n specification: RelationshipSpecification,\n): ArchiMateRelationship {\n const endpointsValid = [\n resolveEndpoint(context, specification.source),\n resolveEndpoint(context, specification.target),\n ].every(Boolean);\n const labelText = readLabel(context, specification.label);\n const source = specification.source.image;\n const target = specification.target.image;\n const id = specification.declaredId?.image ?? generateRelationshipId(context, source, specification.type, target);\n const labelRejected = specification.label !== undefined && labelText === undefined;\n if (!endpointsValid || !specification.knownType) {\n context.invalidRelationshipIds.add(id);\n } else if (specification.shorthand && !labelRejected) {\n warnOnRepeatedShorthand(context, specification.shorthand, labelText);\n }\n const access = specification.access === 'unspecified' ? undefined : specification.access;\n return {\n id,\n type: specification.type,\n source,\n target,\n ...(access && { access }),\n ...(specification.directed && { directed: true }),\n ...(labelText !== undefined && { label: labelText }),\n };\n}\n\nfunction buildModel(\n settings: DiagramSettings,\n parts: Pick<ArchiMateModel, 'elements' | 'relationships'> & {\n readonly notes: readonly ArchiMateNote[];\n readonly nesting: readonly ArchiMateNesting[];\n },\n): ArchiMateModel {\n const selectedLayout = settings.layout ?? (settings.direction === undefined ? 'architecture' : undefined);\n return {\n direction: settings.direction ?? 'TB',\n ...(selectedLayout && { layout: selectedLayout }),\n ...settings.metadata,\n elements: parts.elements,\n relationships: parts.relationships,\n ...(parts.notes.length > 0 && { notes: parts.notes }),\n ...(parts.nesting.length > 0 && { nesting: parts.nesting }),\n };\n}\n\n// The checks run in a fixed order because parseArchiMate throws the first error found.\nexport function validateDeclarations(\n declarations: Declaration[],\n diagnostics: DiagnosticCollector,\n): ArchiMateModel | undefined {\n const report: Report = (code, token, message) => {\n diagnostics.error(code, token, message);\n };\n const collected = collectDeclarations(declarations, report);\n checkDescriptionTargets(collected, report);\n const notes = buildNotes(collected, report);\n const context: ValidationContext = {\n diagnostics,\n report,\n entities: collected.entities,\n usedIds: new Set(collected.entities.keys()),\n invalidRelationshipIds: new Set(),\n unknownEndpointIds: new Set(),\n shorthandStatements: new Map(),\n };\n const relationships = collected.relationships.map((statement) =>\n resolveRelationship(\n context,\n statement.kind === 'connector' ? specifyShorthand(statement) : specifyLongForm(context, statement),\n ),\n );\n const nesting = validateNesting(collected.nesting, collected.entities, {\n relationships,\n relationshipsById: new Map(relationships.map((entry) => [entry.id, entry])),\n invalidRelationshipIds: context.invalidRelationshipIds,\n unknownEndpointIds: context.unknownEndpointIds,\n report,\n });\n const elements = buildElements(collected, report);\n if (diagnostics.hasErrors) return undefined;\n return buildModel(collected.settings, { elements, relationships, notes, nesting });\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./chunks/chunk-QBMRZFD3.mjs";var i="archimate";function o({palette:c="modern",diagramPadding:r=24,useMaxWidth:n=!0,maxRowWidth:e=1200,background:t="theme"}={}){if(!Number.isFinite(r)||r<0)throw new RangeError("ArchiMate diagramPadding must be a finite, nonnegative number.");if(typeof e!="number"||Number.isNaN(e)||e<=0)throw new RangeError("ArchiMate maxRowWidth must be a number greater than 0, or Infinity.");if(t!=="theme"&&t!=="transparent")throw new RangeError('ArchiMate background must be "theme" or "transparent".');if(typeof n!="boolean")throw new TypeError("ArchiMate useMaxWidth must be a boolean.");return{id:i,detector:a=>/^\s*archimate-beta(?=\s|$)/u.test(a),async loader(){let{createArchimateDiagram:a}=await import("./chunks/archimateDiagram-WUCF6KHR.mjs"),m=a({palette:c,diagramPadding:r,useMaxWidth:n,maxRowWidth:e,background:t});return{id:i,diagram:m}}}}var h=o();export{h as archimate,o as createArchiMatePlugin};
|