@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.
Files changed (120) hide show
  1. package/dist/{colors.mjs → colors.cjs} +15 -3
  2. package/dist/colors.js +3 -15
  3. package/dist/compute-view/EdgeBuilder.cjs +37 -0
  4. package/dist/compute-view/EdgeBuilder.d.ts +1 -2
  5. package/dist/compute-view/EdgeBuilder.js +10 -18
  6. package/dist/compute-view/compute-ctx.cjs +35 -0
  7. package/dist/compute-view/compute-ctx.js +21 -14
  8. package/dist/compute-view/compute-element-view.cjs +135 -0
  9. package/dist/compute-view/compute-element-view.js +70 -62
  10. package/dist/compute-view/compute-predicates.cjs +363 -0
  11. package/dist/compute-view/compute-predicates.d.ts +1 -1
  12. package/dist/compute-view/compute-predicates.js +81 -115
  13. package/dist/compute-view/compute.cjs +60 -0
  14. package/dist/compute-view/compute.d.ts +13 -4
  15. package/dist/compute-view/compute.js +24 -31
  16. package/dist/compute-view/index.cjs +27 -0
  17. package/dist/compute-view/index.d.ts +2 -3
  18. package/dist/compute-view/index.js +2 -24
  19. package/dist/compute-view/utils/anyPossibleRelations.cjs +18 -0
  20. package/dist/compute-view/utils/anyPossibleRelations.js +6 -12
  21. package/dist/compute-view/utils/applyViewRuleStyles.cjs +57 -0
  22. package/dist/compute-view/utils/applyViewRuleStyles.d.ts +1 -2
  23. package/dist/compute-view/utils/applyViewRuleStyles.js +20 -29
  24. package/dist/compute-view/utils/{sortNodes.mjs → sortNodes.cjs} +19 -9
  25. package/dist/compute-view/utils/sortNodes.js +9 -19
  26. package/dist/errors/_base.cjs +62 -0
  27. package/dist/errors/_base.d.ts +20 -3
  28. package/dist/errors/_base.js +41 -14
  29. package/dist/errors/index.cjs +60 -0
  30. package/dist/errors/index.js +5 -60
  31. package/dist/errors/invariant.cjs +23 -0
  32. package/dist/errors/invariant.d.ts +5 -1
  33. package/dist/errors/invariant.js +9 -12
  34. package/dist/errors/model-index.cjs +23 -0
  35. package/dist/errors/model-index.d.ts +5 -1
  36. package/dist/errors/model-index.js +9 -12
  37. package/dist/errors/non-nullable.cjs +23 -0
  38. package/dist/errors/non-nullable.d.ts +5 -1
  39. package/dist/errors/non-nullable.js +11 -14
  40. package/dist/errors/nonexhaustive.cjs +23 -0
  41. package/dist/errors/nonexhaustive.d.ts +6 -2
  42. package/dist/errors/nonexhaustive.js +12 -13
  43. package/dist/index.cjs +71 -0
  44. package/dist/index.d.ts +2 -5
  45. package/dist/index.js +6 -71
  46. package/dist/model-index/{ModelIndex.mjs → ModelIndex.cjs} +35 -23
  47. package/dist/model-index/ModelIndex.js +23 -35
  48. package/dist/model-index/index.cjs +13 -0
  49. package/dist/model-index/index.js +1 -13
  50. package/dist/types/_common.cjs +1 -0
  51. package/dist/types/_common.js +0 -1
  52. package/dist/types/computed-view.cjs +1 -0
  53. package/dist/types/computed-view.js +0 -1
  54. package/dist/types/diagram.cjs +1 -0
  55. package/dist/types/diagram.js +0 -1
  56. package/dist/types/element.cjs +14 -0
  57. package/dist/types/element.js +3 -12
  58. package/dist/types/expression.cjs +45 -0
  59. package/dist/types/expression.js +11 -26
  60. package/dist/types/index.cjs +132 -0
  61. package/dist/types/index.d.ts +10 -12
  62. package/dist/types/index.js +11 -48
  63. package/dist/types/model.cjs +1 -0
  64. package/dist/types/model.d.ts +1 -1
  65. package/dist/types/model.js +0 -1
  66. package/dist/types/opaque.cjs +1 -0
  67. package/dist/types/opaque.d.ts +1 -1
  68. package/dist/types/opaque.js +0 -1
  69. package/dist/types/relation.cjs +1 -0
  70. package/dist/types/relation.js +0 -1
  71. package/dist/types/theme.cjs +1 -0
  72. package/dist/types/theme.js +0 -1
  73. package/dist/types/view.cjs +17 -0
  74. package/dist/types/view.js +4 -12
  75. package/dist/utils/compute-node-levels.cjs +48 -0
  76. package/dist/utils/compute-node-levels.d.ts +2 -2
  77. package/dist/utils/compute-node-levels.js +7 -24
  78. package/dist/utils/fqn.cjs +80 -0
  79. package/dist/utils/fqn.js +19 -33
  80. package/dist/utils/guards.cjs +22 -0
  81. package/dist/utils/guards.js +7 -16
  82. package/dist/utils/index.cjs +49 -0
  83. package/dist/utils/index.d.ts +1 -1
  84. package/dist/utils/index.js +4 -49
  85. package/dist/utils/relations.cjs +59 -0
  86. package/dist/utils/relations.d.ts +14 -12
  87. package/dist/utils/relations.js +28 -33
  88. package/package.json +63 -25
  89. package/dist/compute-view/EdgeBuilder.mjs +0 -31
  90. package/dist/compute-view/compute-ctx.mjs +0 -42
  91. package/dist/compute-view/compute-element-view.mjs +0 -145
  92. package/dist/compute-view/compute-predicates.mjs +0 -324
  93. package/dist/compute-view/compute.mjs +0 -39
  94. package/dist/compute-view/index.mjs +0 -1
  95. package/dist/compute-view/utils/anyPossibleRelations.mjs +0 -12
  96. package/dist/compute-view/utils/applyViewRuleStyles.mjs +0 -50
  97. package/dist/errors/_base.mjs +0 -4
  98. package/dist/errors/index.mjs +0 -5
  99. package/dist/errors/invariant.mjs +0 -8
  100. package/dist/errors/model-index.mjs +0 -8
  101. package/dist/errors/non-nullable.mjs +0 -8
  102. package/dist/errors/nonexhaustive.mjs +0 -5
  103. package/dist/index.mjs +0 -6
  104. package/dist/model-index/index.mjs +0 -1
  105. package/dist/types/_common.mjs +0 -0
  106. package/dist/types/computed-view.mjs +0 -0
  107. package/dist/types/diagram.mjs +0 -0
  108. package/dist/types/element.mjs +0 -5
  109. package/dist/types/expression.mjs +0 -30
  110. package/dist/types/index.mjs +0 -3
  111. package/dist/types/model.mjs +0 -0
  112. package/dist/types/opaque.mjs +0 -0
  113. package/dist/types/relation.mjs +0 -0
  114. package/dist/types/theme.mjs +0 -0
  115. package/dist/types/view.mjs +0 -9
  116. package/dist/utils/compute-node-levels.mjs +0 -31
  117. package/dist/utils/fqn.mjs +0 -66
  118. package/dist/utils/guards.mjs +0 -13
  119. package/dist/utils/index.mjs +0 -4
  120. 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
- export declare const UnexpectedNullableError: import("modern-errors").ErrorSubclassCore<[], {}, import("modern-errors").CustomClass>;
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
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.UnexpectedNullableError = void 0;
7
- exports.nonNullable = nonNullable;
8
- var _base = require("./_base");
9
- const UnexpectedNullableError = _base.BaseError.subclass("UnexpectedNullableError");
10
- exports.UnexpectedNullableError = UnexpectedNullableError;
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
- export declare const NonExhaustiveError: import("modern-errors").ErrorSubclassCore<[], {}, import("modern-errors").CustomClass>;
2
- export declare function nonexhaustive(arg: never): never;
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
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.NonExhaustiveError = void 0;
7
- exports.nonexhaustive = nonexhaustive;
8
- var _base = require("./_base");
9
- const NonExhaustiveError = _base.BaseError.subclass("NonExhaustiveError");
10
- exports.NonExhaustiveError = NonExhaustiveError;
11
- function nonexhaustive(arg) {
12
- throw new NonExhaustiveError(`NonExhaustive value: ${JSON.stringify(arg)}`);
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 './model-index';
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
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _types = require("./types");
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
- import { pipe, sort, values } from "remeda";
2
- import { InvalidModelError, ensureModel } from "../errors/index.mjs";
3
- import { compareByFqnHierarchically, parentFqn } from "../utils/fqn.mjs";
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 { el } of values(trie.children)) {
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
- export default class ModelIndex {
24
+ class ModelIndex {
17
25
  root = {
18
26
  children: {}
19
27
  };
20
- _elements = /* @__PURE__ */ new Map();
21
- _relations = /* @__PURE__ */ new Map();
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({ elements, relations }) {
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 = (id) => {
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 = (id) => {
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 = (id) => {
82
+ children = id => {
72
83
  return childrenOf(this.locateTrie(id));
73
84
  };
74
- siblings = (id) => {
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((e) => e.id !== id);
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
- "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");
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 = (0, _remeda.pipe)((0, _remeda.values)(elements), (0, _remeda.sort)(_fqn.compareByFqnHierarchically));
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 (0, _remeda.values)(relations)) {
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 _errors.InvalidModelError(`Element already exists with id ${el.id}`);
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
- (0, _errors.ensureModel)(next, `Invalid index, Element not found at path ${name} of ${id}`);
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
- (0, _errors.ensureModel)(el, `Element not found with id ${id}`);
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 = (0, _fqn.parentFqn)(id);
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
- (0, _errors.ensureModel)(next, `Invalid index, Element not found at path ${name} of ${id}`);
93
+ ensureModel(next, `Invalid index, Element not found at path ${name} of ${id}`);
105
94
  trie = next;
106
- (0, _errors.ensureModel)(trie.el, `invalid index, no element ${name} found in ${id}`);
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 _errors.InvalidModelError(`Source of relation not found ${rel.source}`);
121
+ throw new InvalidModelError(`Source of relation not found ${rel.source}`);
133
122
  }
134
123
  if (!this.hasElement(rel.target)) {
135
- throw new _errors.InvalidModelError(`Target of relation not found ${rel.target}`);
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
- "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"));
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";
@@ -1 +0,0 @@
1
- "use strict";
@@ -0,0 +1 @@
1
+ "use strict";
@@ -1 +0,0 @@
1
- "use strict";
@@ -0,0 +1 @@
1
+ "use strict";
@@ -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;
@@ -1,14 +1,5 @@
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) {
1
+ export function AsFqn(name, parent) {
9
2
  return parent ? parent + "." + name : name;
10
3
  }
11
- const DefaultThemeColor = "primary";
12
- exports.DefaultThemeColor = DefaultThemeColor;
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
+ }