@standarx/graph 0.0.0-stage → 1.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/LICENSE +21 -0
- package/README.fr.md +438 -0
- package/README.md +437 -2
- package/THIRD_PARTY_NOTICES.md +22 -0
- package/assets/fonts/Inter-Regular.ttf +0 -0
- package/assets/fonts/Inter-SemiBold.ttf +0 -0
- package/assets/fonts/OFL.txt +92 -0
- package/dist/adapter-0bggwh8x.js +393 -0
- package/dist/cli-4m00785g.js +20 -0
- package/dist/cli-5v9761s9.js +330 -0
- package/dist/cli-9f1pdw5q.js +462 -0
- package/dist/cli-a4ax1vkc.js +172 -0
- package/dist/cli-abzdy8pn.js +1144 -0
- package/dist/cli-gh5166k6.js +1565 -0
- package/dist/cli-m29a3wgx.js +579 -0
- package/dist/cli-mzmjkk5v.js +11 -0
- package/dist/cli-nhmh6yxk.js +2485 -0
- package/dist/cli-nyckgf1t.js +4 -0
- package/dist/cli-sfdqkbd1.js +433 -0
- package/dist/cli-txrzzr2q.js +0 -0
- package/dist/cli-vecew2na.js +709 -0
- package/dist/cli-wt9dmbhm.js +560 -0
- package/dist/cli-ywgtv1cg.js +39 -0
- package/dist/cli-z3ccx2y4.js +141 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +413 -0
- package/dist/core/index.d.ts +6 -0
- package/dist/core/index.js +91 -0
- package/dist/core/spatial.d.ts +16 -0
- package/dist/core/threshold.d.ts +1 -0
- package/dist/core/view.d.ts +80 -0
- package/dist/export/index.d.ts +18 -0
- package/dist/export/index.js +170 -0
- package/dist/export/pdf.d.ts +5 -0
- package/dist/export/png.d.ts +4 -0
- package/dist/format/index.d.ts +4 -0
- package/dist/format/index.js +69 -0
- package/dist/format/json-schema.d.ts +2 -0
- package/dist/format/schema.d.ts +787 -0
- package/dist/format/semantic/er.d.ts +3 -0
- package/dist/format/semantic/graph.d.ts +3 -0
- package/dist/format/semantic/sequence.d.ts +3 -0
- package/dist/format/semantic/shared.d.ts +14 -0
- package/dist/format/semantic/state.d.ts +3 -0
- package/dist/format/semantic/tree.d.ts +3 -0
- package/dist/format/transition-label.d.ts +2 -0
- package/dist/format/validate.d.ts +11 -0
- package/dist/html/index.d.ts +3 -0
- package/dist/html/index.js +125 -0
- package/dist/html/layout-worker.d.ts +1 -0
- package/dist/html/layout-worker.generated.d.ts +1 -0
- package/dist/html/mount.d.ts +12 -0
- package/dist/html/page.d.ts +14 -0
- package/dist/html/render.d.ts +7 -0
- package/dist/html/runtime.d.ts +1 -0
- package/dist/html/runtime.generated.d.ts +1 -0
- package/dist/html/shell.d.ts +10 -0
- package/dist/html/svg-adapter.d.ts +8 -0
- package/dist/html/ui.d.ts +34 -0
- package/dist/language/actions.d.ts +3 -0
- package/dist/language/analysis.d.ts +38 -0
- package/dist/language/complete.d.ts +3 -0
- package/dist/language/diagnostics.d.ts +14 -0
- package/dist/language/docs.d.ts +11 -0
- package/dist/language/format.d.ts +17 -0
- package/dist/language/hover.d.ts +3 -0
- package/dist/language/index.d.ts +8 -0
- package/dist/language/index.js +1560 -0
- package/dist/language/navigation.d.ts +9 -0
- package/dist/language/positions.d.ts +7 -0
- package/dist/language/symbols.d.ts +3 -0
- package/dist/language/types.d.ts +46 -0
- package/dist/layout/elk.d.ts +35 -0
- package/dist/layout/er.d.ts +3 -0
- package/dist/layout/font-metrics.d.ts +9 -0
- package/dist/layout/graph.d.ts +3 -0
- package/dist/layout/index.d.ts +5 -0
- package/dist/layout/index.js +16 -0
- package/dist/layout/measure.d.ts +10 -0
- package/dist/layout/sequence.d.ts +3 -0
- package/dist/layout/shapes.d.ts +16 -0
- package/dist/layout/shared.d.ts +31 -0
- package/dist/layout/state.d.ts +3 -0
- package/dist/layout/tree.d.ts +3 -0
- package/dist/layout/types.d.ts +198 -0
- package/dist/layout-worker.generated-xsmtzrfj.js +34 -0
- package/dist/mermaid/common.d.ts +36 -0
- package/dist/mermaid/er.d.ts +3 -0
- package/dist/mermaid/graph.d.ts +4 -0
- package/dist/mermaid/index.d.ts +6 -0
- package/dist/mermaid/index.js +6 -0
- package/dist/mermaid/mindmap.d.ts +3 -0
- package/dist/mermaid/sequence.d.ts +3 -0
- package/dist/mermaid/state.d.ts +3 -0
- package/dist/remark/index.d.ts +9 -0
- package/dist/remark/index.js +102 -0
- package/dist/shared/errors.d.ts +6 -0
- package/dist/shared/package-root.d.ts +5 -0
- package/dist/svg/escape.d.ts +1 -0
- package/dist/svg/index.d.ts +3 -0
- package/dist/svg/index.js +25 -0
- package/dist/svg/render.d.ts +9 -0
- package/dist/svg/theme.d.ts +62 -0
- package/dist/svg-adapter-gq5vmp6q.js +227 -0
- package/dist/text/build.d.ts +10 -0
- package/dist/text/canonical.d.ts +10 -0
- package/dist/text/errors.d.ts +33 -0
- package/dist/text/highlight.d.ts +13 -0
- package/dist/text/index.d.ts +33 -0
- package/dist/text/index.js +25 -0
- package/dist/text/lexer.d.ts +29 -0
- package/dist/text/parser.d.ts +160 -0
- package/dist/text/print.d.ts +6 -0
- package/dist/text/slug.d.ts +1 -0
- package/dist/text/syntax.d.ts +8 -0
- package/dist/version.d.ts +1 -0
- package/dist/webgl/adapter.d.ts +4 -0
- package/dist/webgl/index.d.ts +7 -0
- package/dist/webgl/index.js +15 -0
- package/dist/webgl/runtime.d.ts +1 -0
- package/dist/webgl/runtime.generated.d.ts +1 -0
- package/grammars/standargraph.tmLanguage.json +599 -0
- package/language-configuration.json +35 -0
- package/licenses/EPL-2.0.txt +277 -0
- package/licenses/MPL-2.0.txt +373 -0
- package/package.json +133 -4
- package/schema/graph-document.v1.json +1737 -0
|
@@ -0,0 +1,579 @@
|
|
|
1
|
+
// src/format/schema.ts
|
|
2
|
+
import { Type } from "@sinclair/typebox";
|
|
3
|
+
var FORMAT_VERSION2 = 1;
|
|
4
|
+
var Id = Type.String({ minLength: 1 });
|
|
5
|
+
var ProvenanceSchema2 = Type.Object({
|
|
6
|
+
source: Type.String({ minLength: 1 }),
|
|
7
|
+
confidence: Type.Optional(Type.Union([
|
|
8
|
+
Type.Literal("confirmed"),
|
|
9
|
+
Type.Literal("inferred"),
|
|
10
|
+
Type.Literal("unknown")
|
|
11
|
+
])),
|
|
12
|
+
tool: Type.Optional(Type.String())
|
|
13
|
+
}, { additionalProperties: false });
|
|
14
|
+
var MetaSchema2 = Type.Object({
|
|
15
|
+
provenance: Type.Optional(ProvenanceSchema2),
|
|
16
|
+
coverage: Type.Optional(Type.Number({ minimum: 0, maximum: 1 })),
|
|
17
|
+
freshness: Type.Optional(Type.String({ format: "date-time" })),
|
|
18
|
+
data: Type.Optional(Type.Record(Type.String(), Type.Union([Type.String(), Type.Number(), Type.Boolean()])))
|
|
19
|
+
}, { additionalProperties: false });
|
|
20
|
+
var SHAPES2 = [
|
|
21
|
+
"box",
|
|
22
|
+
"rect",
|
|
23
|
+
"pill",
|
|
24
|
+
"diamond",
|
|
25
|
+
"circle",
|
|
26
|
+
"ellipse",
|
|
27
|
+
"hexagon",
|
|
28
|
+
"parallelogram",
|
|
29
|
+
"cylinder",
|
|
30
|
+
"document",
|
|
31
|
+
"subroutine"
|
|
32
|
+
];
|
|
33
|
+
var ShapeSchema2 = Type.Union(SHAPES2.map((shape) => Type.Literal(shape)));
|
|
34
|
+
var NodeSchema2 = Type.Object({
|
|
35
|
+
id: Id,
|
|
36
|
+
label: Type.Optional(Type.String()),
|
|
37
|
+
type: Type.Optional(Type.String()),
|
|
38
|
+
shape: Type.Optional(ShapeSchema2),
|
|
39
|
+
group: Type.Optional(Type.String()),
|
|
40
|
+
description: Type.Optional(Type.String()),
|
|
41
|
+
link: Type.Optional(Type.String()),
|
|
42
|
+
position: Type.Optional(Type.Object({ x: Type.Number(), y: Type.Number() }, { additionalProperties: false })),
|
|
43
|
+
meta: Type.Optional(MetaSchema2)
|
|
44
|
+
}, { additionalProperties: false });
|
|
45
|
+
var EdgeSchema2 = Type.Object({
|
|
46
|
+
id: Type.Optional(Id),
|
|
47
|
+
from: Type.String(),
|
|
48
|
+
to: Type.String(),
|
|
49
|
+
label: Type.Optional(Type.String()),
|
|
50
|
+
type: Type.Optional(Type.String()),
|
|
51
|
+
directed: Type.Optional(Type.Boolean()),
|
|
52
|
+
meta: Type.Optional(MetaSchema2)
|
|
53
|
+
}, { additionalProperties: false });
|
|
54
|
+
var GroupSchema2 = Type.Object({
|
|
55
|
+
id: Id,
|
|
56
|
+
label: Type.Optional(Type.String()),
|
|
57
|
+
parent: Type.Optional(Type.String()),
|
|
58
|
+
meta: Type.Optional(MetaSchema2)
|
|
59
|
+
}, { additionalProperties: false });
|
|
60
|
+
var DirectionSchema2 = Type.Union([
|
|
61
|
+
Type.Literal("down"),
|
|
62
|
+
Type.Literal("right"),
|
|
63
|
+
Type.Literal("up"),
|
|
64
|
+
Type.Literal("left")
|
|
65
|
+
]);
|
|
66
|
+
var GraphDocumentSchema2 = Type.Object({
|
|
67
|
+
$schema: Type.Optional(Type.String()),
|
|
68
|
+
version: Type.Literal(FORMAT_VERSION2),
|
|
69
|
+
kind: Type.Literal("graph"),
|
|
70
|
+
title: Type.Optional(Type.String()),
|
|
71
|
+
direction: Type.Optional(DirectionSchema2),
|
|
72
|
+
nodes: Type.Array(NodeSchema2),
|
|
73
|
+
edges: Type.Optional(Type.Array(EdgeSchema2)),
|
|
74
|
+
groups: Type.Optional(Type.Array(GroupSchema2)),
|
|
75
|
+
meta: Type.Optional(MetaSchema2)
|
|
76
|
+
}, { additionalProperties: false });
|
|
77
|
+
var ParticipantSchema2 = Type.Object({
|
|
78
|
+
id: Id,
|
|
79
|
+
label: Type.Optional(Type.String()),
|
|
80
|
+
type: Type.Optional(Type.String()),
|
|
81
|
+
meta: Type.Optional(MetaSchema2)
|
|
82
|
+
}, { additionalProperties: false });
|
|
83
|
+
var MessageSchema2 = Type.Object({
|
|
84
|
+
from: Type.String(),
|
|
85
|
+
to: Type.String(),
|
|
86
|
+
label: Type.Optional(Type.String()),
|
|
87
|
+
style: Type.Optional(Type.Union([
|
|
88
|
+
Type.Literal("sync"),
|
|
89
|
+
Type.Literal("async"),
|
|
90
|
+
Type.Literal("reply")
|
|
91
|
+
])),
|
|
92
|
+
meta: Type.Optional(MetaSchema2)
|
|
93
|
+
}, { additionalProperties: false });
|
|
94
|
+
var SequenceDocumentSchema2 = Type.Object({
|
|
95
|
+
$schema: Type.Optional(Type.String()),
|
|
96
|
+
version: Type.Literal(FORMAT_VERSION2),
|
|
97
|
+
kind: Type.Literal("sequence"),
|
|
98
|
+
title: Type.Optional(Type.String()),
|
|
99
|
+
participants: Type.Array(ParticipantSchema2, { minItems: 1 }),
|
|
100
|
+
messages: Type.Array(MessageSchema2),
|
|
101
|
+
meta: Type.Optional(MetaSchema2)
|
|
102
|
+
}, { additionalProperties: false });
|
|
103
|
+
var PSEUDO2 = ["initial", "final", "choice", "fork", "join", "history"];
|
|
104
|
+
var StateSchema2 = Type.Object({
|
|
105
|
+
id: Id,
|
|
106
|
+
label: Type.Optional(Type.String()),
|
|
107
|
+
type: Type.Optional(Type.String()),
|
|
108
|
+
pseudo: Type.Optional(Type.Union(PSEUDO2.map((pseudo) => Type.Literal(pseudo)))),
|
|
109
|
+
parent: Type.Optional(Type.String()),
|
|
110
|
+
actions: Type.Optional(Type.Array(Type.String())),
|
|
111
|
+
description: Type.Optional(Type.String()),
|
|
112
|
+
link: Type.Optional(Type.String()),
|
|
113
|
+
meta: Type.Optional(MetaSchema2)
|
|
114
|
+
}, { additionalProperties: false });
|
|
115
|
+
var TransitionSchema2 = Type.Object({
|
|
116
|
+
id: Type.Optional(Id),
|
|
117
|
+
from: Type.String(),
|
|
118
|
+
to: Type.String(),
|
|
119
|
+
event: Type.Optional(Type.String()),
|
|
120
|
+
guard: Type.Optional(Type.String()),
|
|
121
|
+
action: Type.Optional(Type.String()),
|
|
122
|
+
type: Type.Optional(Type.String()),
|
|
123
|
+
meta: Type.Optional(MetaSchema2)
|
|
124
|
+
}, { additionalProperties: false });
|
|
125
|
+
var StateDocumentSchema2 = Type.Object({
|
|
126
|
+
$schema: Type.Optional(Type.String()),
|
|
127
|
+
version: Type.Literal(FORMAT_VERSION2),
|
|
128
|
+
kind: Type.Literal("state"),
|
|
129
|
+
title: Type.Optional(Type.String()),
|
|
130
|
+
direction: Type.Optional(DirectionSchema2),
|
|
131
|
+
states: Type.Array(StateSchema2, { minItems: 1 }),
|
|
132
|
+
transitions: Type.Optional(Type.Array(TransitionSchema2)),
|
|
133
|
+
meta: Type.Optional(MetaSchema2)
|
|
134
|
+
}, { additionalProperties: false });
|
|
135
|
+
var KEYS2 = ["pk", "fk", "uk"];
|
|
136
|
+
var CARDINALITIES3 = ["one", "zero-or-one", "one-or-more", "zero-or-more"];
|
|
137
|
+
var AttributeSchema2 = Type.Object({
|
|
138
|
+
name: Type.String({ minLength: 1 }),
|
|
139
|
+
type: Type.Optional(Type.String()),
|
|
140
|
+
keys: Type.Optional(Type.Array(Type.Union(KEYS2.map((key) => Type.Literal(key))))),
|
|
141
|
+
nullable: Type.Optional(Type.Boolean()),
|
|
142
|
+
note: Type.Optional(Type.String())
|
|
143
|
+
}, { additionalProperties: false });
|
|
144
|
+
var EntitySchema2 = Type.Object({
|
|
145
|
+
id: Id,
|
|
146
|
+
label: Type.Optional(Type.String()),
|
|
147
|
+
type: Type.Optional(Type.String()),
|
|
148
|
+
description: Type.Optional(Type.String()),
|
|
149
|
+
link: Type.Optional(Type.String()),
|
|
150
|
+
attributes: Type.Optional(Type.Array(AttributeSchema2)),
|
|
151
|
+
meta: Type.Optional(MetaSchema2)
|
|
152
|
+
}, { additionalProperties: false });
|
|
153
|
+
var CardinalitySchema = Type.Union(CARDINALITIES3.map((cardinality) => Type.Literal(cardinality)));
|
|
154
|
+
var RelationSchema2 = Type.Object({
|
|
155
|
+
id: Type.Optional(Id),
|
|
156
|
+
from: Type.String(),
|
|
157
|
+
to: Type.String(),
|
|
158
|
+
fromCardinality: Type.Optional(CardinalitySchema),
|
|
159
|
+
toCardinality: Type.Optional(CardinalitySchema),
|
|
160
|
+
label: Type.Optional(Type.String()),
|
|
161
|
+
identifying: Type.Optional(Type.Boolean()),
|
|
162
|
+
type: Type.Optional(Type.String()),
|
|
163
|
+
meta: Type.Optional(MetaSchema2)
|
|
164
|
+
}, { additionalProperties: false });
|
|
165
|
+
var ErDocumentSchema2 = Type.Object({
|
|
166
|
+
$schema: Type.Optional(Type.String()),
|
|
167
|
+
version: Type.Literal(FORMAT_VERSION2),
|
|
168
|
+
kind: Type.Literal("er"),
|
|
169
|
+
title: Type.Optional(Type.String()),
|
|
170
|
+
direction: Type.Optional(DirectionSchema2),
|
|
171
|
+
entities: Type.Array(EntitySchema2, { minItems: 1 }),
|
|
172
|
+
relations: Type.Optional(Type.Array(RelationSchema2)),
|
|
173
|
+
meta: Type.Optional(MetaSchema2)
|
|
174
|
+
}, { additionalProperties: false });
|
|
175
|
+
var TREE_LAYOUTS2 = ["tree", "mindmap"];
|
|
176
|
+
var TreeNodeSchema2 = Type.Object({
|
|
177
|
+
id: Id,
|
|
178
|
+
label: Type.String(),
|
|
179
|
+
parent: Type.Optional(Type.String()),
|
|
180
|
+
type: Type.Optional(Type.String()),
|
|
181
|
+
shape: Type.Optional(ShapeSchema2),
|
|
182
|
+
description: Type.Optional(Type.String()),
|
|
183
|
+
link: Type.Optional(Type.String()),
|
|
184
|
+
meta: Type.Optional(MetaSchema2)
|
|
185
|
+
}, { additionalProperties: false });
|
|
186
|
+
var TreeDocumentSchema2 = Type.Object({
|
|
187
|
+
$schema: Type.Optional(Type.String()),
|
|
188
|
+
version: Type.Literal(FORMAT_VERSION2),
|
|
189
|
+
kind: Type.Literal("tree"),
|
|
190
|
+
title: Type.Optional(Type.String()),
|
|
191
|
+
layout: Type.Optional(Type.Union(TREE_LAYOUTS2.map((layout) => Type.Literal(layout)))),
|
|
192
|
+
direction: Type.Optional(DirectionSchema2),
|
|
193
|
+
nodes: Type.Array(TreeNodeSchema2, { minItems: 1 }),
|
|
194
|
+
meta: Type.Optional(MetaSchema2)
|
|
195
|
+
}, { additionalProperties: false });
|
|
196
|
+
var DocumentSchema2 = Type.Union([
|
|
197
|
+
GraphDocumentSchema2,
|
|
198
|
+
SequenceDocumentSchema2,
|
|
199
|
+
StateDocumentSchema2,
|
|
200
|
+
ErDocumentSchema2,
|
|
201
|
+
TreeDocumentSchema2
|
|
202
|
+
], {
|
|
203
|
+
$id: "urn:standargraph:graph-document:v1",
|
|
204
|
+
title: "Standargraph document v1"
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
// src/format/validate.ts
|
|
208
|
+
import { FormatRegistry } from "@sinclair/typebox";
|
|
209
|
+
import { Value, ValueErrorType } from "@sinclair/typebox/value";
|
|
210
|
+
|
|
211
|
+
// src/format/semantic/shared.ts
|
|
212
|
+
function checkUnique(items, collection, label, errors) {
|
|
213
|
+
const seen = new Set;
|
|
214
|
+
items.forEach((item, index) => {
|
|
215
|
+
if (item.id === undefined)
|
|
216
|
+
return;
|
|
217
|
+
if (seen.has(item.id)) {
|
|
218
|
+
errors.push({
|
|
219
|
+
path: `/${collection}/${index}/id`,
|
|
220
|
+
message: `Duplicate ${label} id "${item.id}"`
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
seen.add(item.id);
|
|
224
|
+
});
|
|
225
|
+
return seen;
|
|
226
|
+
}
|
|
227
|
+
function parentCycles(items) {
|
|
228
|
+
const ids = new Set(items.map((item) => item.id));
|
|
229
|
+
const parentOf = new Map;
|
|
230
|
+
for (const item of items) {
|
|
231
|
+
if (item.parent !== undefined && ids.has(item.parent)) {
|
|
232
|
+
parentOf.set(item.id, item.parent);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
const firstIndex = new Map;
|
|
236
|
+
items.forEach((item, index) => {
|
|
237
|
+
if (!firstIndex.has(item.id))
|
|
238
|
+
firstIndex.set(item.id, index);
|
|
239
|
+
});
|
|
240
|
+
const state = new Map;
|
|
241
|
+
const found = [];
|
|
242
|
+
for (const item of items) {
|
|
243
|
+
if (state.has(item.id))
|
|
244
|
+
continue;
|
|
245
|
+
const path = [];
|
|
246
|
+
const position = new Map;
|
|
247
|
+
let current = item.id;
|
|
248
|
+
while (current !== undefined && !state.has(current)) {
|
|
249
|
+
state.set(current, 1);
|
|
250
|
+
position.set(current, path.length);
|
|
251
|
+
path.push(current);
|
|
252
|
+
current = parentOf.get(current);
|
|
253
|
+
}
|
|
254
|
+
if (current !== undefined && state.get(current) === 1) {
|
|
255
|
+
const members = path.slice(position.get(current));
|
|
256
|
+
let start = 0;
|
|
257
|
+
members.forEach((id, at) => {
|
|
258
|
+
if (firstIndex.get(id) < firstIndex.get(members[start]))
|
|
259
|
+
start = at;
|
|
260
|
+
});
|
|
261
|
+
const cycle = [...members.slice(start), ...members.slice(0, start)];
|
|
262
|
+
found.push({ index: firstIndex.get(cycle[0]), cycle: [...cycle, cycle[0]] });
|
|
263
|
+
}
|
|
264
|
+
for (const id of path)
|
|
265
|
+
state.set(id, 2);
|
|
266
|
+
}
|
|
267
|
+
return found.sort((a, b) => a.index - b.index);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// src/format/semantic/er.ts
|
|
271
|
+
function semanticErErrors(doc) {
|
|
272
|
+
const errors = [];
|
|
273
|
+
const entityIds = checkUnique(doc.entities, "entities", "entity", errors);
|
|
274
|
+
const relations = doc.relations ?? [];
|
|
275
|
+
checkUnique(relations, "relations", "relation", errors);
|
|
276
|
+
relations.forEach((relation, index) => {
|
|
277
|
+
if (!entityIds.has(relation.from)) {
|
|
278
|
+
errors.push({
|
|
279
|
+
path: `/relations/${index}/from`,
|
|
280
|
+
message: `Relation source "${relation.from}" is not a known entity id`
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
if (!entityIds.has(relation.to)) {
|
|
284
|
+
errors.push({
|
|
285
|
+
path: `/relations/${index}/to`,
|
|
286
|
+
message: `Relation target "${relation.to}" is not a known entity id`
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
doc.entities.forEach((entity, index) => {
|
|
291
|
+
const names = new Set;
|
|
292
|
+
(entity.attributes ?? []).forEach((attribute, position) => {
|
|
293
|
+
const base = `/entities/${index}/attributes/${position}`;
|
|
294
|
+
if (names.has(attribute.name)) {
|
|
295
|
+
errors.push({
|
|
296
|
+
path: `${base}/name`,
|
|
297
|
+
message: `Duplicate attribute "${attribute.name}" in entity "${entity.id}"`
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
names.add(attribute.name);
|
|
301
|
+
const keys = new Set;
|
|
302
|
+
(attribute.keys ?? []).forEach((key, slot) => {
|
|
303
|
+
if (keys.has(key)) {
|
|
304
|
+
errors.push({ path: `${base}/keys/${slot}`, message: `Duplicate key "${key}"` });
|
|
305
|
+
}
|
|
306
|
+
keys.add(key);
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
return errors;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// src/format/semantic/graph.ts
|
|
314
|
+
function semanticGraphErrors(doc) {
|
|
315
|
+
const errors = [];
|
|
316
|
+
const nodeIds = checkUnique(doc.nodes, "nodes", "node", errors);
|
|
317
|
+
const groups = doc.groups ?? [];
|
|
318
|
+
const groupIds = checkUnique(groups, "groups", "group", errors);
|
|
319
|
+
const edges = doc.edges ?? [];
|
|
320
|
+
checkUnique(edges, "edges", "edge", errors);
|
|
321
|
+
edges.forEach((edge, index) => {
|
|
322
|
+
if (!nodeIds.has(edge.from)) {
|
|
323
|
+
errors.push({
|
|
324
|
+
path: `/edges/${index}/from`,
|
|
325
|
+
message: `Edge source "${edge.from}" is not a known node id`
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
if (!nodeIds.has(edge.to)) {
|
|
329
|
+
errors.push({
|
|
330
|
+
path: `/edges/${index}/to`,
|
|
331
|
+
message: `Edge target "${edge.to}" is not a known node id`
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
doc.nodes.forEach((node, index) => {
|
|
336
|
+
if (node.group !== undefined && !groupIds.has(node.group)) {
|
|
337
|
+
errors.push({
|
|
338
|
+
path: `/nodes/${index}/group`,
|
|
339
|
+
message: `Group "${node.group}" is not a known group id`
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
groups.forEach((group, index) => {
|
|
344
|
+
if (group.parent !== undefined && !groupIds.has(group.parent)) {
|
|
345
|
+
errors.push({
|
|
346
|
+
path: `/groups/${index}/parent`,
|
|
347
|
+
message: `Parent group "${group.parent}" is not a known group id`
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
for (const { index, cycle } of parentCycles(groups)) {
|
|
352
|
+
errors.push({
|
|
353
|
+
path: `/groups/${index}/parent`,
|
|
354
|
+
message: `Group parent cycle: ${cycle.join(" -> ")}`
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
return errors;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// src/format/semantic/sequence.ts
|
|
361
|
+
function semanticSequenceErrors(doc) {
|
|
362
|
+
const errors = [];
|
|
363
|
+
const ids = checkUnique(doc.participants, "participants", "participant", errors);
|
|
364
|
+
doc.messages.forEach((message, index) => {
|
|
365
|
+
if (!ids.has(message.from)) {
|
|
366
|
+
errors.push({
|
|
367
|
+
path: `/messages/${index}/from`,
|
|
368
|
+
message: `Message sender "${message.from}" is not a known participant id`
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
if (!ids.has(message.to)) {
|
|
372
|
+
errors.push({
|
|
373
|
+
path: `/messages/${index}/to`,
|
|
374
|
+
message: `Message recipient "${message.to}" is not a known participant id`
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
return errors;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// src/format/semantic/state.ts
|
|
382
|
+
function semanticStateErrors(doc) {
|
|
383
|
+
const errors = [];
|
|
384
|
+
const stateIds = checkUnique(doc.states, "states", "state", errors);
|
|
385
|
+
const transitions = doc.transitions ?? [];
|
|
386
|
+
checkUnique(transitions, "transitions", "transition", errors);
|
|
387
|
+
const pseudoOf = new Map;
|
|
388
|
+
for (const state of doc.states) {
|
|
389
|
+
if (!pseudoOf.has(state.id))
|
|
390
|
+
pseudoOf.set(state.id, state.pseudo);
|
|
391
|
+
}
|
|
392
|
+
const outgoing = new Map;
|
|
393
|
+
transitions.forEach((transition, index) => {
|
|
394
|
+
outgoing.set(transition.from, (outgoing.get(transition.from) ?? 0) + 1);
|
|
395
|
+
if (!stateIds.has(transition.from)) {
|
|
396
|
+
errors.push({
|
|
397
|
+
path: `/transitions/${index}/from`,
|
|
398
|
+
message: `Transition source "${transition.from}" is not a known state id`
|
|
399
|
+
});
|
|
400
|
+
} else if (pseudoOf.get(transition.from) === "final") {
|
|
401
|
+
errors.push({
|
|
402
|
+
path: `/transitions/${index}/from`,
|
|
403
|
+
message: `Transition out of a final pseudo-state "${transition.from}"`
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
if (!stateIds.has(transition.to)) {
|
|
407
|
+
errors.push({
|
|
408
|
+
path: `/transitions/${index}/to`,
|
|
409
|
+
message: `Transition target "${transition.to}" is not a known state id`
|
|
410
|
+
});
|
|
411
|
+
} else if (pseudoOf.get(transition.to) === "initial") {
|
|
412
|
+
errors.push({
|
|
413
|
+
path: `/transitions/${index}/to`,
|
|
414
|
+
message: `Transition into an initial pseudo-state "${transition.to}"`
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
const initialRegions = new Set;
|
|
419
|
+
doc.states.forEach((state, index) => {
|
|
420
|
+
if (state.parent !== undefined) {
|
|
421
|
+
if (!stateIds.has(state.parent)) {
|
|
422
|
+
errors.push({
|
|
423
|
+
path: `/states/${index}/parent`,
|
|
424
|
+
message: `Parent state "${state.parent}" is not a known state id`
|
|
425
|
+
});
|
|
426
|
+
} else if (pseudoOf.get(state.parent) !== undefined) {
|
|
427
|
+
errors.push({
|
|
428
|
+
path: `/states/${index}/parent`,
|
|
429
|
+
message: `Parent state "${state.parent}" is a pseudo-state and cannot contain states`
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
if (state.pseudo !== undefined && state.actions !== undefined && state.actions.length > 0) {
|
|
434
|
+
errors.push({
|
|
435
|
+
path: `/states/${index}/actions`,
|
|
436
|
+
message: "Pseudo-states carry no actions"
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
if (state.pseudo === "initial") {
|
|
440
|
+
const found = outgoing.get(state.id) ?? 0;
|
|
441
|
+
if (found !== 1) {
|
|
442
|
+
errors.push({
|
|
443
|
+
path: `/states/${index}`,
|
|
444
|
+
message: `Initial pseudo-state "${state.id}" needs exactly one outgoing transition (found ${found})`
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
const region = state.parent ?? "root";
|
|
448
|
+
if (initialRegions.has(region)) {
|
|
449
|
+
errors.push({
|
|
450
|
+
path: `/states/${index}/pseudo`,
|
|
451
|
+
message: `More than one initial pseudo-state in region "${region}"`
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
initialRegions.add(region);
|
|
455
|
+
}
|
|
456
|
+
});
|
|
457
|
+
for (const { index, cycle } of parentCycles(doc.states)) {
|
|
458
|
+
errors.push({
|
|
459
|
+
path: `/states/${index}/parent`,
|
|
460
|
+
message: `State parent cycle: ${cycle.join(" -> ")}`
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
return errors;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// src/format/semantic/tree.ts
|
|
467
|
+
function semanticTreeErrors(doc) {
|
|
468
|
+
const errors = [];
|
|
469
|
+
const nodeIds = checkUnique(doc.nodes, "nodes", "node", errors);
|
|
470
|
+
doc.nodes.forEach((node, index) => {
|
|
471
|
+
if (node.parent !== undefined && !nodeIds.has(node.parent)) {
|
|
472
|
+
errors.push({
|
|
473
|
+
path: `/nodes/${index}/parent`,
|
|
474
|
+
message: `Parent node "${node.parent}" is not a known node id`
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
for (const { index, cycle } of parentCycles(doc.nodes)) {
|
|
479
|
+
errors.push({
|
|
480
|
+
path: `/nodes/${index}/parent`,
|
|
481
|
+
message: `Node parent cycle: ${cycle.join(" -> ")}`
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
let first;
|
|
485
|
+
doc.nodes.forEach((node, index) => {
|
|
486
|
+
if (node.parent !== undefined)
|
|
487
|
+
return;
|
|
488
|
+
if (first === undefined) {
|
|
489
|
+
first = node.id;
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
errors.push({
|
|
493
|
+
path: `/nodes/${index}`,
|
|
494
|
+
message: `Second root "${node.id}": a tree has exactly one node without parent (first: "${first}")`
|
|
495
|
+
});
|
|
496
|
+
});
|
|
497
|
+
if (first === undefined) {
|
|
498
|
+
errors.push({
|
|
499
|
+
path: "/nodes",
|
|
500
|
+
message: "A tree needs exactly one root (a node without parent): found none"
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
if (doc.layout === "mindmap" && doc.direction !== undefined) {
|
|
504
|
+
errors.push({
|
|
505
|
+
path: "/direction",
|
|
506
|
+
message: 'direction does not apply to layout "mindmap"'
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
return errors;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// src/format/validate.ts
|
|
513
|
+
var DATE_TIME = /^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}:\d{2}(\.\d+)?([Zz]|[+-]\d{2}:\d{2})$/;
|
|
514
|
+
var VERSION_MESSAGE = `Missing or unsupported version: this tool supports version ${FORMAT_VERSION2} only`;
|
|
515
|
+
if (!FormatRegistry.Has("date-time")) {
|
|
516
|
+
FormatRegistry.Set("date-time", (value) => DATE_TIME.test(value) && !Number.isNaN(Date.parse(value)));
|
|
517
|
+
}
|
|
518
|
+
function isRecord(value) {
|
|
519
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
520
|
+
}
|
|
521
|
+
function handler(schema, semantic) {
|
|
522
|
+
return { schema, semantic };
|
|
523
|
+
}
|
|
524
|
+
var KINDS = {
|
|
525
|
+
graph: handler(GraphDocumentSchema2, semanticGraphErrors),
|
|
526
|
+
sequence: handler(SequenceDocumentSchema2, semanticSequenceErrors),
|
|
527
|
+
state: handler(StateDocumentSchema2, semanticStateErrors),
|
|
528
|
+
er: handler(ErDocumentSchema2, semanticErErrors),
|
|
529
|
+
tree: handler(TreeDocumentSchema2, semanticTreeErrors)
|
|
530
|
+
};
|
|
531
|
+
var KIND_NAMES = Object.keys(KINDS).map((name) => JSON.stringify(name)).join(", ");
|
|
532
|
+
function structuralErrors(schema, input) {
|
|
533
|
+
const errors = [];
|
|
534
|
+
for (const error of Value.Errors(schema, input)) {
|
|
535
|
+
let message = error.message;
|
|
536
|
+
if (error.path === "/version") {
|
|
537
|
+
message = VERSION_MESSAGE;
|
|
538
|
+
} else if (error.type === ValueErrorType.Union) {
|
|
539
|
+
message = error.path.endsWith("/shape") ? `Expected one of ${SHAPES2.join(", ")}` : error.path.endsWith("/pseudo") ? `Expected one of ${PSEUDO2.join(", ")}` : error.path.endsWith("Cardinality") ? `Expected one of ${CARDINALITIES3.join(", ")}` : /\/keys\/\d+$/.test(error.path) ? `Expected one of ${KEYS2.join(", ")}` : error.path === "/layout" ? `Expected one of ${TREE_LAYOUTS2.join(", ")}` : "Expected a string, a number or a boolean";
|
|
540
|
+
} else if (error.type === ValueErrorType.ObjectAdditionalProperties) {
|
|
541
|
+
message = "Unexpected property";
|
|
542
|
+
} else if (error.type === ValueErrorType.StringFormat) {
|
|
543
|
+
message = `Expected a valid ${String(error.schema.format)} string`;
|
|
544
|
+
}
|
|
545
|
+
errors.push({ path: error.path, message });
|
|
546
|
+
}
|
|
547
|
+
return errors;
|
|
548
|
+
}
|
|
549
|
+
function validate2(input) {
|
|
550
|
+
if (!isRecord(input)) {
|
|
551
|
+
return {
|
|
552
|
+
ok: false,
|
|
553
|
+
errors: [{ path: "", message: "Expected a JSON object" }]
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
const { kind } = input;
|
|
557
|
+
const entry = typeof kind === "string" && Object.hasOwn(KINDS, kind) ? KINDS[kind] : undefined;
|
|
558
|
+
if (entry === undefined) {
|
|
559
|
+
const errors = [
|
|
560
|
+
{
|
|
561
|
+
path: "/kind",
|
|
562
|
+
message: kind === undefined ? `Missing kind: expected one of ${KIND_NAMES}` : `Unknown kind ${JSON.stringify(kind)}: expected one of ${KIND_NAMES}`
|
|
563
|
+
}
|
|
564
|
+
];
|
|
565
|
+
if (input.version !== FORMAT_VERSION2) {
|
|
566
|
+
errors.push({ path: "/version", message: VERSION_MESSAGE });
|
|
567
|
+
}
|
|
568
|
+
return { ok: false, errors };
|
|
569
|
+
}
|
|
570
|
+
const structural = structuralErrors(entry.schema, input);
|
|
571
|
+
if (structural.length > 0)
|
|
572
|
+
return { ok: false, errors: structural };
|
|
573
|
+
const semantic = entry.semantic(input);
|
|
574
|
+
if (semantic.length > 0)
|
|
575
|
+
return { ok: false, errors: semantic };
|
|
576
|
+
return { ok: true, document: input };
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
export { FORMAT_VERSION2, ProvenanceSchema2, MetaSchema2, SHAPES2, ShapeSchema2, NodeSchema2, EdgeSchema2, GroupSchema2, DirectionSchema2, GraphDocumentSchema2, ParticipantSchema2, MessageSchema2, SequenceDocumentSchema2, PSEUDO2, StateSchema2, TransitionSchema2, StateDocumentSchema2, KEYS2, CARDINALITIES3, AttributeSchema2, EntitySchema2, RelationSchema2, ErDocumentSchema2, TREE_LAYOUTS2, TreeNodeSchema2, TreeDocumentSchema2, DocumentSchema2, validate2 };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/format/transition-label.ts
|
|
2
|
+
function transitionLabel2(transition) {
|
|
3
|
+
const { event, guard, action } = transition;
|
|
4
|
+
return [
|
|
5
|
+
event,
|
|
6
|
+
guard === undefined ? undefined : `[${guard}]`,
|
|
7
|
+
action === undefined ? undefined : `/ ${action}`
|
|
8
|
+
].filter((part) => part !== undefined).join(" ");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { transitionLabel2 };
|