@likec4/core 0.37.1 → 0.41.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 (147) hide show
  1. package/README.md +2 -6
  2. package/dist/cjs/colors/element.d.ts +68 -0
  3. package/dist/{colors.js → cjs/colors/element.js} +24 -46
  4. package/dist/cjs/colors/index.d.ts +132 -0
  5. package/dist/cjs/colors/index.js +27 -0
  6. package/dist/cjs/colors/relationships.d.ts +57 -0
  7. package/dist/cjs/colors/relationships.js +76 -0
  8. package/dist/cjs/errors/index.d.ts +45 -0
  9. package/dist/cjs/errors/index.js +137 -0
  10. package/dist/{index.d.ts → cjs/index.d.ts} +3 -5
  11. package/dist/{index.cjs → cjs/index.js} +16 -38
  12. package/dist/{types → cjs/types}/computed-view.d.ts +11 -7
  13. package/dist/{types → cjs/types}/diagram.d.ts +15 -11
  14. package/dist/{types → cjs/types}/expression.d.ts +1 -1
  15. package/dist/{types/index.cjs → cjs/types/index.js} +10 -10
  16. package/dist/cjs/types/relation.d.ts +22 -0
  17. package/dist/cjs/types/relation.js +12 -0
  18. package/dist/{types → cjs/types}/theme.d.ts +10 -6
  19. package/dist/{types → cjs/types}/view.d.ts +22 -4
  20. package/dist/{types/view.cjs → cjs/types/view.js} +1 -1
  21. package/dist/{utils → cjs/utils}/fqn.d.ts +6 -1
  22. package/dist/{utils/fqn.cjs → cjs/utils/fqn.js} +18 -5
  23. package/dist/{utils → cjs/utils}/guards.d.ts +1 -2
  24. package/dist/cjs/utils/guards.js +20 -0
  25. package/dist/{utils → cjs/utils}/index.d.ts +0 -1
  26. package/dist/{utils/index.cjs → cjs/utils/index.js} +3 -14
  27. package/dist/{utils/relations.cjs → cjs/utils/relations.js} +1 -1
  28. package/dist/esm/colors/element.d.ts +68 -0
  29. package/dist/esm/colors/element.js +82 -0
  30. package/dist/esm/colors/index.d.ts +132 -0
  31. package/dist/esm/colors/index.js +9 -0
  32. package/dist/esm/colors/relationships.d.ts +57 -0
  33. package/dist/esm/colors/relationships.js +64 -0
  34. package/dist/esm/errors/index.d.ts +45 -0
  35. package/dist/esm/errors/index.js +97 -0
  36. package/dist/esm/index.d.ts +6 -0
  37. package/dist/esm/index.js +4 -0
  38. package/dist/esm/types/_common.d.ts +3 -0
  39. package/dist/esm/types/computed-view.d.ts +44 -0
  40. package/dist/esm/types/diagram.d.ts +41 -0
  41. package/dist/esm/types/element.d.ts +29 -0
  42. package/dist/esm/types/expression.d.ts +56 -0
  43. package/dist/esm/types/index.d.ts +11 -0
  44. package/dist/esm/types/model.d.ts +14 -0
  45. package/dist/esm/types/opaque.d.ts +102 -0
  46. package/dist/esm/types/relation.d.ts +22 -0
  47. package/dist/esm/types/relation.js +3 -0
  48. package/dist/esm/types/theme.d.ts +26 -0
  49. package/dist/esm/types/view.d.ts +61 -0
  50. package/dist/{types → esm/types}/view.js +1 -1
  51. package/dist/esm/utils/fqn.d.ts +33 -0
  52. package/dist/{utils → esm/utils}/fqn.js +16 -4
  53. package/dist/esm/utils/guards.d.ts +4 -0
  54. package/dist/esm/utils/guards.js +7 -0
  55. package/dist/esm/utils/index.d.ts +3 -0
  56. package/dist/{utils → esm/utils}/index.js +0 -1
  57. package/dist/esm/utils/relations.d.ts +25 -0
  58. package/package.json +44 -61
  59. package/dist/colors.cjs +0 -124
  60. package/dist/colors.d.ts +0 -148
  61. package/dist/compute-view/EdgeBuilder.cjs +0 -37
  62. package/dist/compute-view/EdgeBuilder.d.ts +0 -6
  63. package/dist/compute-view/EdgeBuilder.js +0 -30
  64. package/dist/compute-view/compute-ctx.cjs +0 -89
  65. package/dist/compute-view/compute-ctx.d.ts +0 -19
  66. package/dist/compute-view/compute-ctx.js +0 -98
  67. package/dist/compute-view/compute-element-view.cjs +0 -91
  68. package/dist/compute-view/compute-element-view.d.ts +0 -3
  69. package/dist/compute-view/compute-element-view.js +0 -86
  70. package/dist/compute-view/compute-predicates.cjs +0 -363
  71. package/dist/compute-view/compute-predicates.d.ts +0 -16
  72. package/dist/compute-view/compute-predicates.js +0 -324
  73. package/dist/compute-view/compute.cjs +0 -46
  74. package/dist/compute-view/compute.d.ts +0 -14
  75. package/dist/compute-view/compute.js +0 -36
  76. package/dist/compute-view/index.cjs +0 -38
  77. package/dist/compute-view/index.d.ts +0 -3
  78. package/dist/compute-view/index.js +0 -3
  79. package/dist/compute-view/resolve-extended-views.cjs +0 -50
  80. package/dist/compute-view/resolve-extended-views.d.ts +0 -6
  81. package/dist/compute-view/resolve-extended-views.js +0 -38
  82. package/dist/compute-view/utils/anyPossibleRelations.cjs +0 -18
  83. package/dist/compute-view/utils/anyPossibleRelations.d.ts +0 -2
  84. package/dist/compute-view/utils/anyPossibleRelations.js +0 -12
  85. package/dist/compute-view/utils/applyViewRuleStyles.cjs +0 -57
  86. package/dist/compute-view/utils/applyViewRuleStyles.d.ts +0 -2
  87. package/dist/compute-view/utils/applyViewRuleStyles.js +0 -50
  88. package/dist/compute-view/utils/sortNodes.cjs +0 -50
  89. package/dist/compute-view/utils/sortNodes.d.ts +0 -2
  90. package/dist/compute-view/utils/sortNodes.js +0 -40
  91. package/dist/errors/_base.cjs +0 -62
  92. package/dist/errors/_base.d.ts +0 -26
  93. package/dist/errors/_base.js +0 -41
  94. package/dist/errors/index.cjs +0 -60
  95. package/dist/errors/index.d.ts +0 -5
  96. package/dist/errors/index.js +0 -5
  97. package/dist/errors/invariant.cjs +0 -23
  98. package/dist/errors/invariant.d.ts +0 -6
  99. package/dist/errors/invariant.js +0 -13
  100. package/dist/errors/model-index.cjs +0 -23
  101. package/dist/errors/model-index.d.ts +0 -6
  102. package/dist/errors/model-index.js +0 -13
  103. package/dist/errors/non-nullable.cjs +0 -23
  104. package/dist/errors/non-nullable.d.ts +0 -6
  105. package/dist/errors/non-nullable.js +0 -13
  106. package/dist/errors/nonexhaustive.cjs +0 -23
  107. package/dist/errors/nonexhaustive.d.ts +0 -6
  108. package/dist/errors/nonexhaustive.js +0 -12
  109. package/dist/index.js +0 -6
  110. package/dist/model-index/ModelIndex.cjs +0 -140
  111. package/dist/model-index/ModelIndex.d.ts +0 -27
  112. package/dist/model-index/ModelIndex.js +0 -128
  113. package/dist/model-index/index.cjs +0 -13
  114. package/dist/model-index/index.d.ts +0 -1
  115. package/dist/model-index/index.js +0 -1
  116. package/dist/types/relation.d.ts +0 -10
  117. package/dist/types/relation.js +0 -0
  118. package/dist/types/theme.cjs +0 -1
  119. package/dist/utils/compute-node-levels.cjs +0 -48
  120. package/dist/utils/compute-node-levels.d.ts +0 -7
  121. package/dist/utils/compute-node-levels.js +0 -31
  122. package/dist/utils/guards.cjs +0 -22
  123. package/dist/utils/guards.js +0 -13
  124. /package/dist/{types → cjs/types}/_common.d.ts +0 -0
  125. /package/dist/{types/_common.cjs → cjs/types/_common.js} +0 -0
  126. /package/dist/{types/computed-view.cjs → cjs/types/computed-view.js} +0 -0
  127. /package/dist/{types/diagram.cjs → cjs/types/diagram.js} +0 -0
  128. /package/dist/{types → cjs/types}/element.d.ts +0 -0
  129. /package/dist/{types/element.cjs → cjs/types/element.js} +0 -0
  130. /package/dist/{types/expression.cjs → cjs/types/expression.js} +0 -0
  131. /package/dist/{types → cjs/types}/index.d.ts +0 -0
  132. /package/dist/{types → cjs/types}/model.d.ts +0 -0
  133. /package/dist/{types/model.cjs → cjs/types/model.js} +0 -0
  134. /package/dist/{types → cjs/types}/opaque.d.ts +0 -0
  135. /package/dist/{types/opaque.cjs → cjs/types/opaque.js} +0 -0
  136. /package/dist/{types/relation.cjs → cjs/types/theme.js} +0 -0
  137. /package/dist/{utils → cjs/utils}/relations.d.ts +0 -0
  138. /package/dist/{types → esm/types}/_common.js +0 -0
  139. /package/dist/{types → esm/types}/computed-view.js +0 -0
  140. /package/dist/{types → esm/types}/diagram.js +0 -0
  141. /package/dist/{types → esm/types}/element.js +0 -0
  142. /package/dist/{types → esm/types}/expression.js +0 -0
  143. /package/dist/{types → esm/types}/index.js +0 -0
  144. /package/dist/{types → esm/types}/model.js +0 -0
  145. /package/dist/{types → esm/types}/opaque.js +0 -0
  146. /package/dist/{types → esm/types}/theme.js +0 -0
  147. /package/dist/{utils → esm/utils}/relations.js +0 -0
@@ -1,5 +0,0 @@
1
- export * from './_base';
2
- export * from './invariant';
3
- export * from './non-nullable';
4
- export * from './nonexhaustive';
5
- export * from './model-index';
@@ -1,5 +0,0 @@
1
- export * from "./_base.js";
2
- export * from "./invariant.js";
3
- export * from "./non-nullable.js";
4
- export * from "./nonexhaustive.js";
5
- export * from "./model-index.js";
@@ -1,23 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.InvariantError = void 0;
7
- exports.invariant = invariant;
8
- var _base = require("./_base.cjs");
9
- class InvariantError extends _base.BaseError {
10
- constructor(message, options) {
11
- super(message, options);
12
- Object.defineProperty(this, "name", {
13
- value: "InvariantError"
14
- });
15
- }
16
- }
17
- exports.InvariantError = InvariantError;
18
- function invariant(condition, message) {
19
- if (condition) {
20
- return;
21
- }
22
- throw new InvariantError(message ?? "Invariant failed");
23
- }
@@ -1,6 +0,0 @@
1
- import type { BaseErrorOptions } from './_base';
2
- import { BaseError } from './_base';
3
- export declare class InvariantError extends BaseError {
4
- constructor(message: string, options?: BaseErrorOptions);
5
- }
6
- export declare function invariant(condition: any, message?: string): asserts condition;
@@ -1,13 +0,0 @@
1
- import { BaseError } from "./_base.js";
2
- export class InvariantError extends BaseError {
3
- constructor(message, options) {
4
- super(message, options);
5
- Object.defineProperty(this, "name", { value: "InvariantError" });
6
- }
7
- }
8
- export function invariant(condition, message) {
9
- if (condition) {
10
- return;
11
- }
12
- throw new InvariantError(message ?? "Invariant failed");
13
- }
@@ -1,23 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.InvalidModelError = void 0;
7
- exports.ensureModel = ensureModel;
8
- var _base = require("./_base.cjs");
9
- class InvalidModelError extends _base.BaseError {
10
- constructor(message, options) {
11
- super(message, options);
12
- Object.defineProperty(this, "name", {
13
- value: "InvalidModelError"
14
- });
15
- }
16
- }
17
- exports.InvalidModelError = InvalidModelError;
18
- function ensureModel(condition, message) {
19
- if (condition) {
20
- return;
21
- }
22
- throw new InvalidModelError(message ?? "ModelIndex Invariant failed");
23
- }
@@ -1,6 +0,0 @@
1
- import type { BaseErrorOptions } from './_base';
2
- import { BaseError } from './_base';
3
- export declare class InvalidModelError extends BaseError {
4
- constructor(message: string, options?: BaseErrorOptions);
5
- }
6
- export declare function ensureModel(condition: any, message?: string): asserts condition;
@@ -1,13 +0,0 @@
1
- import { BaseError } from "./_base.js";
2
- export class InvalidModelError extends BaseError {
3
- constructor(message, options) {
4
- super(message, options);
5
- Object.defineProperty(this, "name", { value: "InvalidModelError" });
6
- }
7
- }
8
- export function ensureModel(condition, message) {
9
- if (condition) {
10
- return;
11
- }
12
- throw new InvalidModelError(message ?? "ModelIndex Invariant failed");
13
- }
@@ -1,23 +0,0 @@
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, message) {
19
- if (typeof value === "undefined" || value == null) {
20
- throw new NullableError(message ?? `Expected defined value, but received ${value}`);
21
- }
22
- return value;
23
- }
@@ -1,6 +0,0 @@
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
- }
6
- export declare function nonNullable<T>(value: T, message?: string): T & {};
@@ -1,13 +0,0 @@
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, message) {
9
- if (typeof value === "undefined" || value == null) {
10
- throw new NullableError(message ?? `Expected defined value, but received ${value}`);
11
- }
12
- return value;
13
- }
@@ -1,23 +0,0 @@
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,6 +0,0 @@
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,12 +0,0 @@
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.js DELETED
@@ -1,6 +0,0 @@
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,140 +0,0 @@
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");
10
- function childrenOf(trie) {
11
- const children = [];
12
- for (const {
13
- el
14
- } of (0, _remeda.values)(trie.children)) {
15
- if (el) {
16
- children.push(el);
17
- }
18
- }
19
- return children;
20
- }
21
- function asPath(id) {
22
- return id.split(".");
23
- }
24
- class ModelIndex {
25
- root = {
26
- children: {}
27
- };
28
- _elements = /* @__PURE__ */new Map();
29
- _relations = /* @__PURE__ */new Map();
30
- // private _taggedElements = new Map<Tag, Set<Element>>()
31
- // private _taggedRelations = new Map<Tag, Set<Relation>>()
32
- get relations() {
33
- return Array.from(this._relations.values());
34
- }
35
- filterRelations(predicate) {
36
- return this.relations.filter(predicate);
37
- }
38
- static from({
39
- elements,
40
- relations
41
- }) {
42
- const index = new ModelIndex();
43
- const sortedElements = (0, _remeda.pipe)((0, _remeda.values)(elements), (0, _remeda.sort)(_utils.compareByFqnHierarchically));
44
- for (const el of sortedElements) {
45
- index.addElement(el);
46
- }
47
- for (const rel of (0, _remeda.values)(relations)) {
48
- index.addRelation(rel);
49
- }
50
- return index;
51
- }
52
- addElement(el) {
53
- if (this.hasElement(el.id)) {
54
- throw new _errors.InvalidModelError(`Element already exists with id ${el.id}`);
55
- }
56
- const path = asPath(el.id);
57
- let scope = this.root;
58
- for (const name of path) {
59
- const next = scope.children[name] ?? {
60
- children: {}
61
- };
62
- scope.children[name] = next;
63
- scope = next;
64
- }
65
- scope.el = el;
66
- this._elements.set(el.id, el);
67
- }
68
- locateTrie = id => {
69
- let scope = this.root;
70
- for (const name of asPath(id)) {
71
- const next = scope.children[name];
72
- (0, _errors.ensureModel)(next, `Invalid index, Element not found at path ${name} of ${id}`);
73
- scope = next;
74
- }
75
- return scope;
76
- };
77
- find = id => {
78
- const el = this._elements.get(id);
79
- (0, _errors.ensureModel)(el, `Element not found with id ${id}`);
80
- return el;
81
- };
82
- children = id => {
83
- return childrenOf(this.locateTrie(id));
84
- };
85
- siblings = id => {
86
- const parent = (0, _utils.parentFqn)(id);
87
- const trie = parent ? this.locateTrie(parent) : this.root;
88
- return childrenOf(trie).filter(e => e.id !== id);
89
- };
90
- /**
91
- * Ancestors from closest parent to root
92
- */
93
- ancestors(id) {
94
- const path = asPath(id);
95
- const ancestors = [];
96
- if (path.length === 1) {
97
- return ancestors;
98
- }
99
- path.pop();
100
- let name = path.shift();
101
- let trie = this.root;
102
- while (name) {
103
- const next = trie.children[name];
104
- (0, _errors.ensureModel)(next, `Invalid index, Element not found at path ${name} of ${id}`);
105
- trie = next;
106
- (0, _errors.ensureModel)(trie.el, `invalid index, no element ${name} found in ${id}`);
107
- ancestors.unshift(trie.el);
108
- name = path.shift();
109
- }
110
- return ancestors;
111
- }
112
- // tagged = (tag?: Tag): TaggedResult => {
113
- // return tag ? {
114
- // elements: [...this._taggedElements.get(tag)?.values() ?? []],
115
- // relations: [...this._taggedRelations.get(tag)?.values() ?? []],
116
- // } : {
117
- // elements: uniq([...this._taggedElements.values()].flatMap(s => [...s.values()])),
118
- // relations: uniq([...this._taggedRelations.values()].flatMap(s => [...s.values()]))
119
- // }
120
- // }
121
- rootElements() {
122
- return childrenOf(this.root);
123
- }
124
- get elements() {
125
- return Array.from(this._elements.values());
126
- }
127
- hasElement(fqn) {
128
- return this._elements.has(fqn);
129
- }
130
- addRelation(rel) {
131
- if (!this.hasElement(rel.source)) {
132
- throw new _errors.InvalidModelError(`Source of relation not found ${rel.source}`);
133
- }
134
- if (!this.hasElement(rel.target)) {
135
- throw new _errors.InvalidModelError(`Target of relation not found ${rel.target}`);
136
- }
137
- this._relations.set(rel.id, rel);
138
- }
139
- }
140
- module.exports = ModelIndex;
@@ -1,27 +0,0 @@
1
- import type { Element, Fqn, Relation, RelationID } from '../types';
2
- type ModelInput = {
3
- elements: Record<Fqn, Element>;
4
- relations: Record<RelationID, Relation>;
5
- };
6
- export default class ModelIndex {
7
- private root;
8
- private _elements;
9
- private _relations;
10
- get relations(): Relation[];
11
- filterRelations(predicate: (r: Relation) => boolean): Relation[];
12
- static from({ elements, relations }: ModelInput): ModelIndex;
13
- addElement(el: Element): void;
14
- private locateTrie;
15
- find: (id: Fqn) => Element;
16
- children: (id: Fqn) => Element[];
17
- siblings: (id: Fqn) => Element[];
18
- /**
19
- * Ancestors from closest parent to root
20
- */
21
- ancestors(id: Fqn): Element[];
22
- rootElements(): Element[];
23
- get elements(): Element[];
24
- hasElement(fqn: Fqn): boolean;
25
- addRelation(rel: Relation): void;
26
- }
27
- export {};
@@ -1,128 +0,0 @@
1
- import { pipe, sort, values } from "remeda";
2
- import { InvalidModelError, ensureModel } from "../errors/index.js";
3
- import { compareByFqnHierarchically, parentFqn } from "../utils/index.js";
4
- function childrenOf(trie) {
5
- const children = [];
6
- for (const { el } of values(trie.children)) {
7
- if (el) {
8
- children.push(el);
9
- }
10
- }
11
- return children;
12
- }
13
- function asPath(id) {
14
- return id.split(".");
15
- }
16
- export default class ModelIndex {
17
- root = {
18
- children: {}
19
- };
20
- _elements = /* @__PURE__ */ new Map();
21
- _relations = /* @__PURE__ */ new Map();
22
- // private _taggedElements = new Map<Tag, Set<Element>>()
23
- // private _taggedRelations = new Map<Tag, Set<Relation>>()
24
- get relations() {
25
- return Array.from(this._relations.values());
26
- }
27
- filterRelations(predicate) {
28
- return this.relations.filter(predicate);
29
- }
30
- static from({ elements, relations }) {
31
- const index = new ModelIndex();
32
- const sortedElements = pipe(values(elements), sort(compareByFqnHierarchically));
33
- for (const el of sortedElements) {
34
- index.addElement(el);
35
- }
36
- for (const rel of values(relations)) {
37
- index.addRelation(rel);
38
- }
39
- return index;
40
- }
41
- addElement(el) {
42
- if (this.hasElement(el.id)) {
43
- throw new InvalidModelError(`Element already exists with id ${el.id}`);
44
- }
45
- const path = asPath(el.id);
46
- let scope = this.root;
47
- for (const name of path) {
48
- const next = scope.children[name] ?? {
49
- children: {}
50
- };
51
- scope.children[name] = next;
52
- scope = next;
53
- }
54
- scope.el = el;
55
- this._elements.set(el.id, el);
56
- }
57
- locateTrie = (id) => {
58
- let scope = this.root;
59
- for (const name of asPath(id)) {
60
- const next = scope.children[name];
61
- ensureModel(next, `Invalid index, Element not found at path ${name} of ${id}`);
62
- scope = next;
63
- }
64
- return scope;
65
- };
66
- find = (id) => {
67
- const el = this._elements.get(id);
68
- ensureModel(el, `Element not found with id ${id}`);
69
- return el;
70
- };
71
- children = (id) => {
72
- return childrenOf(this.locateTrie(id));
73
- };
74
- siblings = (id) => {
75
- const parent = parentFqn(id);
76
- const trie = parent ? this.locateTrie(parent) : this.root;
77
- return childrenOf(trie).filter((e) => e.id !== id);
78
- };
79
- /**
80
- * Ancestors from closest parent to root
81
- */
82
- ancestors(id) {
83
- const path = asPath(id);
84
- const ancestors = [];
85
- if (path.length === 1) {
86
- return ancestors;
87
- }
88
- path.pop();
89
- let name = path.shift();
90
- let trie = this.root;
91
- while (name) {
92
- const next = trie.children[name];
93
- ensureModel(next, `Invalid index, Element not found at path ${name} of ${id}`);
94
- trie = next;
95
- ensureModel(trie.el, `invalid index, no element ${name} found in ${id}`);
96
- ancestors.unshift(trie.el);
97
- name = path.shift();
98
- }
99
- return ancestors;
100
- }
101
- // tagged = (tag?: Tag): TaggedResult => {
102
- // return tag ? {
103
- // elements: [...this._taggedElements.get(tag)?.values() ?? []],
104
- // relations: [...this._taggedRelations.get(tag)?.values() ?? []],
105
- // } : {
106
- // elements: uniq([...this._taggedElements.values()].flatMap(s => [...s.values()])),
107
- // relations: uniq([...this._taggedRelations.values()].flatMap(s => [...s.values()]))
108
- // }
109
- // }
110
- rootElements() {
111
- return childrenOf(this.root);
112
- }
113
- get elements() {
114
- return Array.from(this._elements.values());
115
- }
116
- hasElement(fqn) {
117
- return this._elements.has(fqn);
118
- }
119
- addRelation(rel) {
120
- if (!this.hasElement(rel.source)) {
121
- throw new InvalidModelError(`Source of relation not found ${rel.source}`);
122
- }
123
- if (!this.hasElement(rel.target)) {
124
- throw new InvalidModelError(`Target of relation not found ${rel.target}`);
125
- }
126
- this._relations.set(rel.id, rel);
127
- }
128
- }
@@ -1,13 +0,0 @@
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 +0,0 @@
1
- export { default as ModelIndex } from './ModelIndex';
@@ -1 +0,0 @@
1
- export { default as ModelIndex } from "./ModelIndex.js";
@@ -1,10 +0,0 @@
1
- import type { Opaque } from './opaque';
2
- import type { Fqn, Tag } from './element';
3
- export type RelationID = Opaque<string, 'RelationID'>;
4
- export interface Relation {
5
- readonly id: RelationID;
6
- readonly source: Fqn;
7
- readonly target: Fqn;
8
- readonly title: string;
9
- readonly tags?: Tag[];
10
- }
File without changes
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,48 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.computeNodeLevels = void 0;
7
- var _errors = require("../errors/index.cjs");
8
- const computeNodeLevels = ({
9
- nodes
10
- }) => {
11
- const nodeLevels = {};
12
- const compute = (node, level) => {
13
- let levels = nodeLevels[node.id];
14
- if (levels) {
15
- return levels;
16
- }
17
- if (node.children.length === 0) {
18
- levels = {
19
- level,
20
- depth: 0
21
- };
22
- nodeLevels[node.id] = levels;
23
- return levels;
24
- }
25
- let depth = 1;
26
- for (const childId of node.children) {
27
- const child = nodes.find(n => n.id === childId);
28
- (0, _errors.invariant)(child, `Child ${childId} not found`);
29
- const {
30
- depth: childDepth
31
- } = compute(child, level + 1);
32
- depth = Math.max(childDepth + 1, depth);
33
- }
34
- levels = {
35
- level,
36
- depth
37
- };
38
- nodeLevels[node.id] = levels;
39
- return levels;
40
- };
41
- for (const node of nodes) {
42
- if (!node.parent) {
43
- compute(node, 0);
44
- }
45
- }
46
- return nodeLevels;
47
- };
48
- exports.computeNodeLevels = computeNodeLevels;
@@ -1,7 +0,0 @@
1
- import type { ComputedView } from '../types';
2
- type NodeLevelDepth = {
3
- level: number;
4
- depth: number;
5
- };
6
- export declare const computeNodeLevels: ({ nodes }: ComputedView) => Record<import("../types").Fqn, NodeLevelDepth>;
7
- export {};
@@ -1,31 +0,0 @@
1
- import { invariant } from "../errors/index.js";
2
- export const computeNodeLevels = ({ nodes }) => {
3
- const nodeLevels = {};
4
- const compute = (node, level) => {
5
- let levels = nodeLevels[node.id];
6
- if (levels) {
7
- return levels;
8
- }
9
- if (node.children.length === 0) {
10
- levels = { level, depth: 0 };
11
- nodeLevels[node.id] = levels;
12
- return levels;
13
- }
14
- let depth = 1;
15
- for (const childId of node.children) {
16
- const child = nodes.find((n) => n.id === childId);
17
- invariant(child, `Child ${childId} not found`);
18
- const { depth: childDepth } = compute(child, level + 1);
19
- depth = Math.max(childDepth + 1, depth);
20
- }
21
- levels = { level, depth };
22
- nodeLevels[node.id] = levels;
23
- return levels;
24
- };
25
- for (const node of nodes) {
26
- if (!node.parent) {
27
- compute(node, 0);
28
- }
29
- }
30
- return nodeLevels;
31
- };
@@ -1,22 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.failUnexpected = failUnexpected;
7
- exports.ignoreNeverInRuntime = ignoreNeverInRuntime;
8
- exports.isNonEmptyArray = isNonEmptyArray;
9
- exports.isString = isString;
10
- var _errors = require("../errors/index.cjs");
11
- function isString(value) {
12
- return typeof value === "string";
13
- }
14
- function failUnexpected(arg) {
15
- throw new _errors.NonExhaustiveError(`Unexpected value: ${JSON.stringify(arg)}`);
16
- }
17
- function ignoreNeverInRuntime(arg) {
18
- console.warn(`Unexpected and ignored value: ${JSON.stringify(arg)}`);
19
- }
20
- function isNonEmptyArray(arr) {
21
- return arr.length > 0;
22
- }
@@ -1,13 +0,0 @@
1
- import { NonExhaustiveError } from "../errors/index.js";
2
- export function isString(value) {
3
- return typeof value === "string";
4
- }
5
- export function failUnexpected(arg) {
6
- throw new NonExhaustiveError(`Unexpected value: ${JSON.stringify(arg)}`);
7
- }
8
- export function ignoreNeverInRuntime(arg) {
9
- console.warn(`Unexpected and ignored value: ${JSON.stringify(arg)}`);
10
- }
11
- export function isNonEmptyArray(arr) {
12
- return arr.length > 0;
13
- }
File without changes