@likec4/core 0.33.1 → 0.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{colors.mjs → colors.cjs} +15 -3
- package/dist/colors.js +3 -15
- package/dist/compute-view/EdgeBuilder.cjs +37 -0
- package/dist/compute-view/EdgeBuilder.d.ts +1 -2
- package/dist/compute-view/EdgeBuilder.js +10 -18
- package/dist/compute-view/compute-ctx.cjs +35 -0
- package/dist/compute-view/compute-ctx.js +21 -14
- package/dist/compute-view/compute-element-view.cjs +135 -0
- package/dist/compute-view/compute-element-view.js +70 -62
- package/dist/compute-view/compute-predicates.cjs +363 -0
- package/dist/compute-view/compute-predicates.d.ts +1 -1
- package/dist/compute-view/compute-predicates.js +81 -115
- package/dist/compute-view/compute.cjs +60 -0
- package/dist/compute-view/compute.d.ts +13 -4
- package/dist/compute-view/compute.js +24 -31
- package/dist/compute-view/index.cjs +27 -0
- package/dist/compute-view/index.d.ts +2 -3
- package/dist/compute-view/index.js +2 -24
- package/dist/compute-view/utils/anyPossibleRelations.cjs +18 -0
- package/dist/compute-view/utils/anyPossibleRelations.js +6 -12
- package/dist/compute-view/utils/applyViewRuleStyles.cjs +57 -0
- package/dist/compute-view/utils/applyViewRuleStyles.d.ts +1 -2
- package/dist/compute-view/utils/applyViewRuleStyles.js +20 -29
- package/dist/compute-view/utils/{sortNodes.mjs → sortNodes.cjs} +19 -9
- package/dist/compute-view/utils/sortNodes.js +9 -19
- package/dist/errors/_base.cjs +62 -0
- package/dist/errors/_base.d.ts +20 -3
- package/dist/errors/_base.js +41 -14
- package/dist/errors/index.cjs +60 -0
- package/dist/errors/index.js +5 -60
- package/dist/errors/invariant.cjs +23 -0
- package/dist/errors/invariant.d.ts +5 -1
- package/dist/errors/invariant.js +9 -12
- package/dist/errors/model-index.cjs +23 -0
- package/dist/errors/model-index.d.ts +5 -1
- package/dist/errors/model-index.js +9 -12
- package/dist/errors/non-nullable.cjs +23 -0
- package/dist/errors/non-nullable.d.ts +5 -1
- package/dist/errors/non-nullable.js +11 -14
- package/dist/errors/nonexhaustive.cjs +23 -0
- package/dist/errors/nonexhaustive.d.ts +6 -2
- package/dist/errors/nonexhaustive.js +12 -13
- package/dist/index.cjs +71 -0
- package/dist/index.d.ts +2 -5
- package/dist/index.js +6 -71
- package/dist/model-index/{ModelIndex.mjs → ModelIndex.cjs} +35 -23
- package/dist/model-index/ModelIndex.js +23 -35
- package/dist/model-index/index.cjs +13 -0
- package/dist/model-index/index.js +1 -13
- package/dist/types/_common.cjs +1 -0
- package/dist/types/_common.js +0 -1
- package/dist/types/computed-view.cjs +1 -0
- package/dist/types/computed-view.js +0 -1
- package/dist/types/diagram.cjs +1 -0
- package/dist/types/diagram.js +0 -1
- package/dist/types/element.cjs +14 -0
- package/dist/types/element.js +3 -12
- package/dist/types/expression.cjs +45 -0
- package/dist/types/expression.js +11 -26
- package/dist/types/index.cjs +132 -0
- package/dist/types/index.d.ts +10 -12
- package/dist/types/index.js +11 -48
- package/dist/types/model.cjs +1 -0
- package/dist/types/model.d.ts +1 -1
- package/dist/types/model.js +0 -1
- package/dist/types/opaque.cjs +1 -0
- package/dist/types/opaque.d.ts +1 -1
- package/dist/types/opaque.js +0 -1
- package/dist/types/relation.cjs +1 -0
- package/dist/types/relation.js +0 -1
- package/dist/types/theme.cjs +1 -0
- package/dist/types/theme.js +0 -1
- package/dist/types/view.cjs +17 -0
- package/dist/types/view.js +4 -12
- package/dist/utils/compute-node-levels.cjs +48 -0
- package/dist/utils/compute-node-levels.d.ts +2 -2
- package/dist/utils/compute-node-levels.js +7 -24
- package/dist/utils/fqn.cjs +80 -0
- package/dist/utils/fqn.js +19 -33
- package/dist/utils/guards.cjs +22 -0
- package/dist/utils/guards.js +7 -16
- package/dist/utils/index.cjs +49 -0
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +4 -49
- package/dist/utils/relations.cjs +59 -0
- package/dist/utils/relations.d.ts +14 -12
- package/dist/utils/relations.js +28 -33
- package/package.json +63 -25
- package/dist/compute-view/EdgeBuilder.mjs +0 -31
- package/dist/compute-view/compute-ctx.mjs +0 -42
- package/dist/compute-view/compute-element-view.mjs +0 -145
- package/dist/compute-view/compute-predicates.mjs +0 -324
- package/dist/compute-view/compute.mjs +0 -39
- package/dist/compute-view/index.mjs +0 -1
- package/dist/compute-view/utils/anyPossibleRelations.mjs +0 -12
- package/dist/compute-view/utils/applyViewRuleStyles.mjs +0 -50
- package/dist/errors/_base.mjs +0 -4
- package/dist/errors/index.mjs +0 -5
- package/dist/errors/invariant.mjs +0 -8
- package/dist/errors/model-index.mjs +0 -8
- package/dist/errors/non-nullable.mjs +0 -8
- package/dist/errors/nonexhaustive.mjs +0 -5
- package/dist/index.mjs +0 -6
- package/dist/model-index/index.mjs +0 -1
- package/dist/types/_common.mjs +0 -0
- package/dist/types/computed-view.mjs +0 -0
- package/dist/types/diagram.mjs +0 -0
- package/dist/types/element.mjs +0 -5
- package/dist/types/expression.mjs +0 -30
- package/dist/types/index.mjs +0 -3
- package/dist/types/model.mjs +0 -0
- package/dist/types/opaque.mjs +0 -0
- package/dist/types/relation.mjs +0 -0
- package/dist/types/theme.mjs +0 -0
- package/dist/types/view.mjs +0 -9
- package/dist/utils/compute-node-levels.mjs +0 -31
- package/dist/utils/fqn.mjs +0 -66
- package/dist/utils/guards.mjs +0 -13
- package/dist/utils/index.mjs +0 -4
- package/dist/utils/relations.mjs +0 -42
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.NullableError = void 0;
|
|
7
|
+
exports.nonNullable = nonNullable;
|
|
8
|
+
var _base = require("./_base.cjs");
|
|
9
|
+
class NullableError extends _base.BaseError {
|
|
10
|
+
constructor(message, options) {
|
|
11
|
+
super(message, options);
|
|
12
|
+
Object.defineProperty(this, "name", {
|
|
13
|
+
value: "UnexpectedNullableError"
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.NullableError = NullableError;
|
|
18
|
+
function nonNullable(value) {
|
|
19
|
+
if (typeof value === "undefined" || value == null) {
|
|
20
|
+
throw new NullableError(`Expected defined value, but received ${value}`);
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import type { BaseErrorOptions } from './_base';
|
|
2
|
+
import { BaseError } from './_base';
|
|
3
|
+
export declare class NullableError extends BaseError {
|
|
4
|
+
constructor(message: string, options?: BaseErrorOptions);
|
|
5
|
+
}
|
|
2
6
|
export declare function nonNullable<T>(value: T): NonNullable<T>;
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
function nonNullable(value) {
|
|
12
|
-
if (value == null) {
|
|
13
|
-
throw new UnexpectedNullableError("Expected value to not be null or undefined");
|
|
1
|
+
import { BaseError } from "./_base.js";
|
|
2
|
+
export class NullableError extends BaseError {
|
|
3
|
+
constructor(message, options) {
|
|
4
|
+
super(message, options);
|
|
5
|
+
Object.defineProperty(this, "name", { value: "UnexpectedNullableError" });
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export function nonNullable(value) {
|
|
9
|
+
if (typeof value === "undefined" || value == null) {
|
|
10
|
+
throw new NullableError(`Expected defined value, but received ${value}`);
|
|
14
11
|
}
|
|
15
12
|
return value;
|
|
16
|
-
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.NonExhaustiveError = void 0;
|
|
7
|
+
exports.nonexhaustive = nonexhaustive;
|
|
8
|
+
var _safeStableStringify = _interopRequireDefault(require("safe-stable-stringify"));
|
|
9
|
+
var _base = require("./_base.cjs");
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
class NonExhaustiveError extends _base.BaseError {
|
|
12
|
+
constructor(message, options) {
|
|
13
|
+
super(message, options);
|
|
14
|
+
Object.defineProperty(this, "name", {
|
|
15
|
+
value: "NonExhaustiveError"
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.NonExhaustiveError = NonExhaustiveError;
|
|
20
|
+
function nonexhaustive(value) {
|
|
21
|
+
const val = typeof value === "string" ? value : (0, _safeStableStringify.default)(value);
|
|
22
|
+
throw new NonExhaustiveError(`NonExhaustive value: ${val}`);
|
|
23
|
+
}
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { BaseErrorOptions } from './_base';
|
|
2
|
+
import { BaseError } from './_base';
|
|
3
|
+
export declare class NonExhaustiveError extends BaseError {
|
|
4
|
+
constructor(message: string, options?: BaseErrorOptions);
|
|
5
|
+
}
|
|
6
|
+
export declare function nonexhaustive(value: never): never;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
1
|
+
import stringify from "safe-stable-stringify";
|
|
2
|
+
import { BaseError } from "./_base.js";
|
|
3
|
+
export class NonExhaustiveError extends BaseError {
|
|
4
|
+
constructor(message, options) {
|
|
5
|
+
super(message, options);
|
|
6
|
+
Object.defineProperty(this, "name", { value: "NonExhaustiveError" });
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export function nonexhaustive(value) {
|
|
10
|
+
const val = typeof value === "string" ? value : stringify(value);
|
|
11
|
+
throw new NonExhaustiveError(`NonExhaustive value: ${val}`);
|
|
12
|
+
}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _types = require("./types/index.cjs");
|
|
7
|
+
Object.keys(_types).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _types[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _types[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _utils = require("./utils/index.cjs");
|
|
18
|
+
Object.keys(_utils).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _utils[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _utils[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
var _modelIndex = require("./model-index/index.cjs");
|
|
29
|
+
Object.keys(_modelIndex).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _modelIndex[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return _modelIndex[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
var _computeView = require("./compute-view/index.cjs");
|
|
40
|
+
Object.keys(_computeView).forEach(function (key) {
|
|
41
|
+
if (key === "default" || key === "__esModule") return;
|
|
42
|
+
if (key in exports && exports[key] === _computeView[key]) return;
|
|
43
|
+
Object.defineProperty(exports, key, {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () {
|
|
46
|
+
return _computeView[key];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
var _colors = require("./colors.cjs");
|
|
51
|
+
Object.keys(_colors).forEach(function (key) {
|
|
52
|
+
if (key === "default" || key === "__esModule") return;
|
|
53
|
+
if (key in exports && exports[key] === _colors[key]) return;
|
|
54
|
+
Object.defineProperty(exports, key, {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _colors[key];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
var _errors = require("./errors/index.cjs");
|
|
62
|
+
Object.keys(_errors).forEach(function (key) {
|
|
63
|
+
if (key === "default" || key === "__esModule") return;
|
|
64
|
+
if (key in exports && exports[key] === _errors[key]) return;
|
|
65
|
+
Object.defineProperty(exports, key, {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
get: function () {
|
|
68
|
+
return _errors[key];
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
});
|
package/dist/index.d.ts
CHANGED
|
@@ -4,8 +4,5 @@ export * from './model-index';
|
|
|
4
4
|
export * from './compute-view';
|
|
5
5
|
export * from './colors';
|
|
6
6
|
export * from './errors';
|
|
7
|
-
export type * from './types';
|
|
8
|
-
export type * from './
|
|
9
|
-
export type * from './compute-view';
|
|
10
|
-
export type * from './errors';
|
|
11
|
-
export type * from './colors';
|
|
7
|
+
export type * as c4 from './types';
|
|
8
|
+
export type * as likec4 from './types';
|
package/dist/index.js
CHANGED
|
@@ -1,71 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Object.keys(_types).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _types[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _types[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
var _utils = require("./utils");
|
|
18
|
-
Object.keys(_utils).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _utils[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _utils[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
var _modelIndex = require("./model-index");
|
|
29
|
-
Object.keys(_modelIndex).forEach(function (key) {
|
|
30
|
-
if (key === "default" || key === "__esModule") return;
|
|
31
|
-
if (key in exports && exports[key] === _modelIndex[key]) return;
|
|
32
|
-
Object.defineProperty(exports, key, {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
get: function () {
|
|
35
|
-
return _modelIndex[key];
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
var _computeView = require("./compute-view");
|
|
40
|
-
Object.keys(_computeView).forEach(function (key) {
|
|
41
|
-
if (key === "default" || key === "__esModule") return;
|
|
42
|
-
if (key in exports && exports[key] === _computeView[key]) return;
|
|
43
|
-
Object.defineProperty(exports, key, {
|
|
44
|
-
enumerable: true,
|
|
45
|
-
get: function () {
|
|
46
|
-
return _computeView[key];
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
var _colors = require("./colors");
|
|
51
|
-
Object.keys(_colors).forEach(function (key) {
|
|
52
|
-
if (key === "default" || key === "__esModule") return;
|
|
53
|
-
if (key in exports && exports[key] === _colors[key]) return;
|
|
54
|
-
Object.defineProperty(exports, key, {
|
|
55
|
-
enumerable: true,
|
|
56
|
-
get: function () {
|
|
57
|
-
return _colors[key];
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
var _errors = require("./errors");
|
|
62
|
-
Object.keys(_errors).forEach(function (key) {
|
|
63
|
-
if (key === "default" || key === "__esModule") return;
|
|
64
|
-
if (key in exports && exports[key] === _errors[key]) return;
|
|
65
|
-
Object.defineProperty(exports, key, {
|
|
66
|
-
enumerable: true,
|
|
67
|
-
get: function () {
|
|
68
|
-
return _errors[key];
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
});
|
|
1
|
+
export * from "./types/index.js";
|
|
2
|
+
export * from "./utils/index.js";
|
|
3
|
+
export * from "./model-index/index.js";
|
|
4
|
+
export * from "./compute-view/index.js";
|
|
5
|
+
export * from "./colors.js";
|
|
6
|
+
export * from "./errors/index.js";
|
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
module.exports = void 0;
|
|
7
|
+
var _remeda = require("remeda");
|
|
8
|
+
var _errors = require("../errors/index.cjs");
|
|
9
|
+
var _utils = require("../utils/index.cjs");
|
|
4
10
|
function childrenOf(trie) {
|
|
5
11
|
const children = [];
|
|
6
|
-
for (const {
|
|
12
|
+
for (const {
|
|
13
|
+
el
|
|
14
|
+
} of (0, _remeda.values)(trie.children)) {
|
|
7
15
|
if (el) {
|
|
8
16
|
children.push(el);
|
|
9
17
|
}
|
|
@@ -13,12 +21,12 @@ function childrenOf(trie) {
|
|
|
13
21
|
function asPath(id) {
|
|
14
22
|
return id.split(".");
|
|
15
23
|
}
|
|
16
|
-
|
|
24
|
+
class ModelIndex {
|
|
17
25
|
root = {
|
|
18
26
|
children: {}
|
|
19
27
|
};
|
|
20
|
-
_elements = /* @__PURE__ */
|
|
21
|
-
_relations = /* @__PURE__ */
|
|
28
|
+
_elements = /* @__PURE__ */new Map();
|
|
29
|
+
_relations = /* @__PURE__ */new Map();
|
|
22
30
|
// private _taggedElements = new Map<Tag, Set<Element>>()
|
|
23
31
|
// private _taggedRelations = new Map<Tag, Set<Relation>>()
|
|
24
32
|
get relations() {
|
|
@@ -27,20 +35,23 @@ export default class ModelIndex {
|
|
|
27
35
|
filterRelations(predicate) {
|
|
28
36
|
return this.relations.filter(predicate);
|
|
29
37
|
}
|
|
30
|
-
static from({
|
|
38
|
+
static from({
|
|
39
|
+
elements,
|
|
40
|
+
relations
|
|
41
|
+
}) {
|
|
31
42
|
const index = new ModelIndex();
|
|
32
|
-
const sortedElements = pipe(values(elements), sort(compareByFqnHierarchically));
|
|
43
|
+
const sortedElements = (0, _remeda.pipe)((0, _remeda.values)(elements), (0, _remeda.sort)(_utils.compareByFqnHierarchically));
|
|
33
44
|
for (const el of sortedElements) {
|
|
34
45
|
index.addElement(el);
|
|
35
46
|
}
|
|
36
|
-
for (const rel of values(relations)) {
|
|
47
|
+
for (const rel of (0, _remeda.values)(relations)) {
|
|
37
48
|
index.addRelation(rel);
|
|
38
49
|
}
|
|
39
50
|
return index;
|
|
40
51
|
}
|
|
41
52
|
addElement(el) {
|
|
42
53
|
if (this.hasElement(el.id)) {
|
|
43
|
-
throw new InvalidModelError(`Element already exists with id ${el.id}`);
|
|
54
|
+
throw new _errors.InvalidModelError(`Element already exists with id ${el.id}`);
|
|
44
55
|
}
|
|
45
56
|
const path = asPath(el.id);
|
|
46
57
|
let scope = this.root;
|
|
@@ -54,27 +65,27 @@ export default class ModelIndex {
|
|
|
54
65
|
scope.el = el;
|
|
55
66
|
this._elements.set(el.id, el);
|
|
56
67
|
}
|
|
57
|
-
locateTrie =
|
|
68
|
+
locateTrie = id => {
|
|
58
69
|
let scope = this.root;
|
|
59
70
|
for (const name of asPath(id)) {
|
|
60
71
|
const next = scope.children[name];
|
|
61
|
-
ensureModel(next, `Invalid index, Element not found at path ${name} of ${id}`);
|
|
72
|
+
(0, _errors.ensureModel)(next, `Invalid index, Element not found at path ${name} of ${id}`);
|
|
62
73
|
scope = next;
|
|
63
74
|
}
|
|
64
75
|
return scope;
|
|
65
76
|
};
|
|
66
|
-
find =
|
|
77
|
+
find = id => {
|
|
67
78
|
const el = this._elements.get(id);
|
|
68
|
-
ensureModel(el, `Element not found with id ${id}`);
|
|
79
|
+
(0, _errors.ensureModel)(el, `Element not found with id ${id}`);
|
|
69
80
|
return el;
|
|
70
81
|
};
|
|
71
|
-
children =
|
|
82
|
+
children = id => {
|
|
72
83
|
return childrenOf(this.locateTrie(id));
|
|
73
84
|
};
|
|
74
|
-
siblings =
|
|
75
|
-
const parent = parentFqn(id);
|
|
85
|
+
siblings = id => {
|
|
86
|
+
const parent = (0, _utils.parentFqn)(id);
|
|
76
87
|
const trie = parent ? this.locateTrie(parent) : this.root;
|
|
77
|
-
return childrenOf(trie).filter(
|
|
88
|
+
return childrenOf(trie).filter(e => e.id !== id);
|
|
78
89
|
};
|
|
79
90
|
/**
|
|
80
91
|
* Ancestors from closest parent to root
|
|
@@ -90,9 +101,9 @@ export default class ModelIndex {
|
|
|
90
101
|
let trie = this.root;
|
|
91
102
|
while (name) {
|
|
92
103
|
const next = trie.children[name];
|
|
93
|
-
ensureModel(next, `Invalid index, Element not found at path ${name} of ${id}`);
|
|
104
|
+
(0, _errors.ensureModel)(next, `Invalid index, Element not found at path ${name} of ${id}`);
|
|
94
105
|
trie = next;
|
|
95
|
-
ensureModel(trie.el, `invalid index, no element ${name} found in ${id}`);
|
|
106
|
+
(0, _errors.ensureModel)(trie.el, `invalid index, no element ${name} found in ${id}`);
|
|
96
107
|
ancestors.unshift(trie.el);
|
|
97
108
|
name = path.shift();
|
|
98
109
|
}
|
|
@@ -118,11 +129,12 @@ export default class ModelIndex {
|
|
|
118
129
|
}
|
|
119
130
|
addRelation(rel) {
|
|
120
131
|
if (!this.hasElement(rel.source)) {
|
|
121
|
-
throw new InvalidModelError(`Source of relation not found ${rel.source}`);
|
|
132
|
+
throw new _errors.InvalidModelError(`Source of relation not found ${rel.source}`);
|
|
122
133
|
}
|
|
123
134
|
if (!this.hasElement(rel.target)) {
|
|
124
|
-
throw new InvalidModelError(`Target of relation not found ${rel.target}`);
|
|
135
|
+
throw new _errors.InvalidModelError(`Target of relation not found ${rel.target}`);
|
|
125
136
|
}
|
|
126
137
|
this._relations.set(rel.id, rel);
|
|
127
138
|
}
|
|
128
139
|
}
|
|
140
|
+
module.exports = ModelIndex;
|
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
module.exports = void 0;
|
|
7
|
-
var _remeda = require("remeda");
|
|
8
|
-
var _errors = require("../errors");
|
|
9
|
-
var _fqn = require("../utils/fqn");
|
|
1
|
+
import { pipe, sort, values } from "remeda";
|
|
2
|
+
import { InvalidModelError, ensureModel } from "../errors/index.js";
|
|
3
|
+
import { compareByFqnHierarchically, parentFqn } from "../utils/index.js";
|
|
10
4
|
function childrenOf(trie) {
|
|
11
5
|
const children = [];
|
|
12
|
-
for (const {
|
|
13
|
-
el
|
|
14
|
-
} of (0, _remeda.values)(trie.children)) {
|
|
6
|
+
for (const { el } of values(trie.children)) {
|
|
15
7
|
if (el) {
|
|
16
8
|
children.push(el);
|
|
17
9
|
}
|
|
@@ -21,12 +13,12 @@ function childrenOf(trie) {
|
|
|
21
13
|
function asPath(id) {
|
|
22
14
|
return id.split(".");
|
|
23
15
|
}
|
|
24
|
-
class ModelIndex {
|
|
16
|
+
export default class ModelIndex {
|
|
25
17
|
root = {
|
|
26
18
|
children: {}
|
|
27
19
|
};
|
|
28
|
-
_elements = /* @__PURE__ */new Map();
|
|
29
|
-
_relations = /* @__PURE__ */new Map();
|
|
20
|
+
_elements = /* @__PURE__ */ new Map();
|
|
21
|
+
_relations = /* @__PURE__ */ new Map();
|
|
30
22
|
// private _taggedElements = new Map<Tag, Set<Element>>()
|
|
31
23
|
// private _taggedRelations = new Map<Tag, Set<Relation>>()
|
|
32
24
|
get relations() {
|
|
@@ -35,23 +27,20 @@ class ModelIndex {
|
|
|
35
27
|
filterRelations(predicate) {
|
|
36
28
|
return this.relations.filter(predicate);
|
|
37
29
|
}
|
|
38
|
-
static from({
|
|
39
|
-
elements,
|
|
40
|
-
relations
|
|
41
|
-
}) {
|
|
30
|
+
static from({ elements, relations }) {
|
|
42
31
|
const index = new ModelIndex();
|
|
43
|
-
const sortedElements =
|
|
32
|
+
const sortedElements = pipe(values(elements), sort(compareByFqnHierarchically));
|
|
44
33
|
for (const el of sortedElements) {
|
|
45
34
|
index.addElement(el);
|
|
46
35
|
}
|
|
47
|
-
for (const rel of
|
|
36
|
+
for (const rel of values(relations)) {
|
|
48
37
|
index.addRelation(rel);
|
|
49
38
|
}
|
|
50
39
|
return index;
|
|
51
40
|
}
|
|
52
41
|
addElement(el) {
|
|
53
42
|
if (this.hasElement(el.id)) {
|
|
54
|
-
throw new
|
|
43
|
+
throw new InvalidModelError(`Element already exists with id ${el.id}`);
|
|
55
44
|
}
|
|
56
45
|
const path = asPath(el.id);
|
|
57
46
|
let scope = this.root;
|
|
@@ -65,27 +54,27 @@ class ModelIndex {
|
|
|
65
54
|
scope.el = el;
|
|
66
55
|
this._elements.set(el.id, el);
|
|
67
56
|
}
|
|
68
|
-
locateTrie = id => {
|
|
57
|
+
locateTrie = (id) => {
|
|
69
58
|
let scope = this.root;
|
|
70
59
|
for (const name of asPath(id)) {
|
|
71
60
|
const next = scope.children[name];
|
|
72
|
-
|
|
61
|
+
ensureModel(next, `Invalid index, Element not found at path ${name} of ${id}`);
|
|
73
62
|
scope = next;
|
|
74
63
|
}
|
|
75
64
|
return scope;
|
|
76
65
|
};
|
|
77
|
-
find = id => {
|
|
66
|
+
find = (id) => {
|
|
78
67
|
const el = this._elements.get(id);
|
|
79
|
-
|
|
68
|
+
ensureModel(el, `Element not found with id ${id}`);
|
|
80
69
|
return el;
|
|
81
70
|
};
|
|
82
|
-
children = id => {
|
|
71
|
+
children = (id) => {
|
|
83
72
|
return childrenOf(this.locateTrie(id));
|
|
84
73
|
};
|
|
85
|
-
siblings = id => {
|
|
86
|
-
const parent =
|
|
74
|
+
siblings = (id) => {
|
|
75
|
+
const parent = parentFqn(id);
|
|
87
76
|
const trie = parent ? this.locateTrie(parent) : this.root;
|
|
88
|
-
return childrenOf(trie).filter(e => e.id !== id);
|
|
77
|
+
return childrenOf(trie).filter((e) => e.id !== id);
|
|
89
78
|
};
|
|
90
79
|
/**
|
|
91
80
|
* Ancestors from closest parent to root
|
|
@@ -101,9 +90,9 @@ class ModelIndex {
|
|
|
101
90
|
let trie = this.root;
|
|
102
91
|
while (name) {
|
|
103
92
|
const next = trie.children[name];
|
|
104
|
-
|
|
93
|
+
ensureModel(next, `Invalid index, Element not found at path ${name} of ${id}`);
|
|
105
94
|
trie = next;
|
|
106
|
-
|
|
95
|
+
ensureModel(trie.el, `invalid index, no element ${name} found in ${id}`);
|
|
107
96
|
ancestors.unshift(trie.el);
|
|
108
97
|
name = path.shift();
|
|
109
98
|
}
|
|
@@ -129,12 +118,11 @@ class ModelIndex {
|
|
|
129
118
|
}
|
|
130
119
|
addRelation(rel) {
|
|
131
120
|
if (!this.hasElement(rel.source)) {
|
|
132
|
-
throw new
|
|
121
|
+
throw new InvalidModelError(`Source of relation not found ${rel.source}`);
|
|
133
122
|
}
|
|
134
123
|
if (!this.hasElement(rel.target)) {
|
|
135
|
-
throw new
|
|
124
|
+
throw new InvalidModelError(`Target of relation not found ${rel.target}`);
|
|
136
125
|
}
|
|
137
126
|
this._relations.set(rel.id, rel);
|
|
138
127
|
}
|
|
139
128
|
}
|
|
140
|
-
module.exports = ModelIndex;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "ModelIndex", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _ModelIndex.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _ModelIndex = _interopRequireDefault(require("./ModelIndex.cjs"));
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -1,13 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "ModelIndex", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _ModelIndex.default;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
var _ModelIndex = _interopRequireDefault(require("./ModelIndex"));
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1
|
+
export { default as ModelIndex } from "./ModelIndex.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/dist/types/_common.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/dist/types/diagram.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.AsFqn = AsFqn;
|
|
7
|
+
exports.DefaultThemeColor = exports.DefaultElementShape = void 0;
|
|
8
|
+
function AsFqn(name, parent) {
|
|
9
|
+
return parent ? parent + "." + name : name;
|
|
10
|
+
}
|
|
11
|
+
const DefaultThemeColor = "primary";
|
|
12
|
+
exports.DefaultThemeColor = DefaultThemeColor;
|
|
13
|
+
const DefaultElementShape = "rectangle";
|
|
14
|
+
exports.DefaultElementShape = DefaultElementShape;
|
package/dist/types/element.js
CHANGED
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.AsFqn = AsFqn;
|
|
7
|
-
exports.DefaultThemeColor = exports.DefaultElementShape = void 0;
|
|
8
|
-
function AsFqn(name, parent) {
|
|
1
|
+
export function AsFqn(name, parent) {
|
|
9
2
|
return parent ? parent + "." + name : name;
|
|
10
3
|
}
|
|
11
|
-
const DefaultThemeColor = "primary";
|
|
12
|
-
|
|
13
|
-
const DefaultElementShape = "rectangle";
|
|
14
|
-
exports.DefaultElementShape = DefaultElementShape;
|
|
4
|
+
export const DefaultThemeColor = "primary";
|
|
5
|
+
export const DefaultElementShape = "rectangle";
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isAnyRelation = isAnyRelation;
|
|
7
|
+
exports.isElement = isElement;
|
|
8
|
+
exports.isElementKindExpr = isElementKindExpr;
|
|
9
|
+
exports.isElementRef = isElementRef;
|
|
10
|
+
exports.isElementTagExpr = isElementTagExpr;
|
|
11
|
+
exports.isInOut = isInOut;
|
|
12
|
+
exports.isIncoming = isIncoming;
|
|
13
|
+
exports.isOutgoing = isOutgoing;
|
|
14
|
+
exports.isRelation = isRelation;
|
|
15
|
+
exports.isWildcard = isWildcard;
|
|
16
|
+
function isElementRef(expr) {
|
|
17
|
+
return "element" in expr && "isDescedants" in expr;
|
|
18
|
+
}
|
|
19
|
+
function isWildcard(expr) {
|
|
20
|
+
return "wildcard" in expr;
|
|
21
|
+
}
|
|
22
|
+
function isElementKindExpr(expr) {
|
|
23
|
+
return "elementKind" in expr && "isEqual" in expr;
|
|
24
|
+
}
|
|
25
|
+
function isElementTagExpr(expr) {
|
|
26
|
+
return "elementTag" in expr && "isEqual" in expr;
|
|
27
|
+
}
|
|
28
|
+
function isElement(expr) {
|
|
29
|
+
return isElementRef(expr) || isWildcard(expr) || isElementKindExpr(expr) || isElementTagExpr(expr);
|
|
30
|
+
}
|
|
31
|
+
function isRelation(expr) {
|
|
32
|
+
return "source" in expr && "target" in expr;
|
|
33
|
+
}
|
|
34
|
+
function isInOut(expr) {
|
|
35
|
+
return "inout" in expr;
|
|
36
|
+
}
|
|
37
|
+
function isIncoming(expr) {
|
|
38
|
+
return "incoming" in expr;
|
|
39
|
+
}
|
|
40
|
+
function isOutgoing(expr) {
|
|
41
|
+
return "outgoing" in expr;
|
|
42
|
+
}
|
|
43
|
+
function isAnyRelation(expr) {
|
|
44
|
+
return isRelation(expr) || isInOut(expr) || isIncoming(expr) || isOutgoing(expr);
|
|
45
|
+
}
|