@likec4/core 1.19.2 → 1.20.1

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 (80) hide show
  1. package/dist/builder/index.cjs +881 -0
  2. package/dist/builder/index.d.cts +503 -0
  3. package/dist/builder/index.d.mts +4 -3
  4. package/dist/builder/index.d.ts +4 -3
  5. package/dist/builder/{index.js → index.mjs} +14 -4
  6. package/dist/compute-view/index.cjs +86 -0
  7. package/dist/compute-view/index.d.cts +23 -0
  8. package/dist/compute-view/index.d.mts +3 -2
  9. package/dist/compute-view/index.d.ts +3 -2
  10. package/dist/compute-view/{index.js → index.mjs} +6 -5
  11. package/dist/index.cjs +4320 -0
  12. package/dist/index.d.cts +270 -0
  13. package/dist/index.d.mts +130 -4
  14. package/dist/index.d.ts +130 -4
  15. package/dist/{index.js → index.mjs} +512 -7
  16. package/dist/model/index.cjs +40 -0
  17. package/dist/model/index.d.cts +259 -0
  18. package/dist/model/index.d.mts +3 -3
  19. package/dist/model/index.d.ts +3 -3
  20. package/dist/model/index.mjs +1 -0
  21. package/dist/shared/core.B2QYWlYe.cjs +435 -0
  22. package/dist/shared/core.B72vUaNB.d.cts +850 -0
  23. package/dist/shared/core.BGus30EM.cjs +8027 -0
  24. package/dist/shared/core.BRuJ3Wzf.d.mts +12 -0
  25. package/dist/shared/{core.CqXs9Frh.d.ts → core.BdbFkE_p.d.cts} +10 -4
  26. package/dist/shared/core.BvdNMbcA.d.cts +12 -0
  27. package/dist/shared/{object_hash.CE_oF3I3.js → core.BxvDITEI.mjs} +26 -389
  28. package/dist/shared/core.ByNgh-mC.d.cts +127 -0
  29. package/dist/shared/core.C9DCnJh8.cjs +908 -0
  30. package/dist/shared/{index.KOeaSlL8.js → core.CqCTxzMY.mjs} +787 -372
  31. package/dist/shared/core.D74xkKkG.d.cts +148 -0
  32. package/dist/shared/{core.DyJ41fBO.d.ts → core.D_Gc58Gt.d.ts} +12 -4
  33. package/dist/shared/core.Damrzla-.d.ts +12 -0
  34. package/dist/shared/{core.BL1oTk7-.d.mts → core.Dfzrh1VA.d.mts} +12 -4
  35. package/dist/shared/core.DsoCu540.cjs +26 -0
  36. package/dist/shared/{view.DrmaOfjr.js → core.DunIMHRf.mjs} +24 -1
  37. package/dist/shared/{core.2I-l5UtM.d.mts → core.ZWiGANIJ.d.ts} +10 -4
  38. package/dist/shared/core.gv1bMwCC.cjs +39 -0
  39. package/dist/shared/core.jy6z2iRn.d.mts +729 -0
  40. package/dist/shared/core.m3rCQAv6.mjs +37 -0
  41. package/dist/types/index.cjs +107 -0
  42. package/dist/types/index.d.cts +72 -0
  43. package/dist/types/index.d.mts +2 -2
  44. package/dist/types/index.d.ts +2 -2
  45. package/dist/types/{index.js → index.mjs} +1 -1
  46. package/dist/utils/index.cjs +95 -0
  47. package/dist/utils/index.d.cts +356 -0
  48. package/dist/utils/index.d.mts +1 -64
  49. package/dist/utils/index.d.ts +1 -64
  50. package/dist/utils/index.mjs +56 -0
  51. package/package.json +51 -25
  52. package/src/builder/Builder.view-common.ts +20 -1
  53. package/src/compute-view/deployment-view/predicates/relation-direct.ts +26 -29
  54. package/src/compute-view/deployment-view/predicates/relation-incoming.ts +1 -1
  55. package/src/compute-view/deployment-view/predicates/utils.ts +47 -16
  56. package/src/compute-view/element-view/__test__/fixture.ts +17 -4
  57. package/src/compute-view/element-view/compute.ts +3 -2
  58. package/src/compute-view/element-view/predicates.ts +520 -0
  59. package/src/compute-view/element-view/utils.ts +11 -7
  60. package/src/compute-view/index.ts +1 -0
  61. package/src/compute-view/relationships-view/_types.ts +16 -0
  62. package/src/compute-view/relationships-view/compute.ts +74 -0
  63. package/src/compute-view/relationships-view/layout.ts +357 -0
  64. package/src/compute-view/relationships-view/utils.ts +40 -0
  65. package/src/compute-view/utils/relationExpressionToPredicates.ts +11 -4
  66. package/src/index.ts +16 -0
  67. package/src/model/DeploymentElementModel.ts +4 -0
  68. package/src/model/ElementModel.ts +13 -0
  69. package/src/model/LikeC4Model.ts +2 -2
  70. package/src/model/RelationModel.ts +5 -0
  71. package/src/model/guards.ts +17 -1
  72. package/src/model/view/LikeC4ViewModel.ts +7 -1
  73. package/src/model/view/NodeModel.ts +5 -0
  74. package/src/types/operators.ts +42 -2
  75. package/src/types/view.ts +2 -2
  76. package/src/utils/index.ts +0 -5
  77. package/src/utils/iterable/unique.ts +1 -7
  78. package/dist/model/index.js +0 -1
  79. package/dist/utils/index.js +0 -347
  80. /package/dist/shared/{chunk-RAAYCPUM.M-JWF7SS.js → core.M-JWF7SS.mjs} +0 -0
@@ -1,6 +1,6 @@
1
1
  import { LastArrayElement, Split, Simplify, Writable, IfNever, Tagged, IsLiteral, IsStringLiteral as IsStringLiteral$1, TupleToUnion } from 'type-fest';
2
- import { d as LikeC4Model } from '../shared/core.2I-l5UtM.mjs';
3
- import { D as DeploymentElement, i as DeploymentRelation, at as ModelRelation, bs as ViewRuleStyle, aT as AutoLayoutDirection, A as CustomElementExpr, B as CustomRelationExpr, X as ExpressionV2, N as Expression, L as LikeC4View, b0 as DeploymentView, bd as ElementView, ax as RelationshipKindSpecification, g as DeploymentNodeKindSpecification, av as RelationshipArrowType, ay as RelationshipLineType, a9 as ParsedLikeC4Model } from '../shared/core.BL1oTk7-.mjs';
2
+ import { L as LikeC4Model } from '../shared/core.jy6z2iRn.mjs';
3
+ import { D as DeploymentElement, i as DeploymentRelation, at as ModelRelation, bs as ViewRuleStyle, aT as AutoLayoutDirection, bx as Participant, A as CustomElementExpr, B as CustomRelationExpr, X as ExpressionV2, N as Expression, L as LikeC4View, b0 as DeploymentView, bd as ElementView, ax as RelationshipKindSpecification, g as DeploymentNodeKindSpecification, av as RelationshipArrowType, ay as RelationshipLineType, a9 as ParsedLikeC4Model } from '../shared/core.Dfzrh1VA.mjs';
4
4
  import { F as Fqn, i as Element, N as NonEmptyArray, j as ElementKindSpecification, l as ElementShape, s as Color, h as BorderStyle, K as KeysOf } from '../shared/core.D74xkKkG.mjs';
5
5
  import { IsStringLiteral } from 'type-fest/source/is-literal';
6
6
 
@@ -147,7 +147,8 @@ declare namespace ViewPredicate {
147
147
  type DeploymentConnectionExpression<T extends AnyTypes> = T extends Types<any, any, any, any, any, any, any, infer F extends string> ? `${F} -> ${F}` : never;
148
148
  type WhereTag<Tag extends string> = `tag ${'is' | 'is not'} #${Tag}`;
149
149
  type WhereKind<Kind extends string> = `kind ${'is' | 'is not'} ${Kind}`;
150
- type WhereEq<Types extends AnyTypes> = ViewPredicate.WhereTag<Types['Tag']> | ViewPredicate.WhereKind<Types['ElementKind']>;
150
+ type WhereParticipant<Types extends AnyTypes> = `${Participant}.${WhereTag<Types['Tag']> | WhereKind<Types['ElementKind']>}`;
151
+ type WhereEq<Types extends AnyTypes> = ViewPredicate.WhereTag<Types['Tag']> | ViewPredicate.WhereKind<Types['ElementKind']> | ViewPredicate.WhereParticipant<Types>;
151
152
  type WhereOperator<Types extends AnyTypes> = ViewPredicate.WhereEq<Types> | {
152
153
  and: NonEmptyArray<ViewPredicate.WhereOperator<Types>>;
153
154
  or?: never;
@@ -1,6 +1,6 @@
1
1
  import { LastArrayElement, Split, Simplify, Writable, IfNever, Tagged, IsLiteral, IsStringLiteral as IsStringLiteral$1, TupleToUnion } from 'type-fest';
2
- import { d as LikeC4Model } from '../shared/core.CqXs9Frh.js';
3
- import { D as DeploymentElement, i as DeploymentRelation, at as ModelRelation, bs as ViewRuleStyle, aT as AutoLayoutDirection, A as CustomElementExpr, B as CustomRelationExpr, X as ExpressionV2, N as Expression, L as LikeC4View, b0 as DeploymentView, bd as ElementView, ax as RelationshipKindSpecification, g as DeploymentNodeKindSpecification, av as RelationshipArrowType, ay as RelationshipLineType, a9 as ParsedLikeC4Model } from '../shared/core.DyJ41fBO.js';
2
+ import { L as LikeC4Model } from '../shared/core.ZWiGANIJ.js';
3
+ import { D as DeploymentElement, i as DeploymentRelation, at as ModelRelation, bs as ViewRuleStyle, aT as AutoLayoutDirection, bx as Participant, A as CustomElementExpr, B as CustomRelationExpr, X as ExpressionV2, N as Expression, L as LikeC4View, b0 as DeploymentView, bd as ElementView, ax as RelationshipKindSpecification, g as DeploymentNodeKindSpecification, av as RelationshipArrowType, ay as RelationshipLineType, a9 as ParsedLikeC4Model } from '../shared/core.D_Gc58Gt.js';
4
4
  import { F as Fqn, i as Element, N as NonEmptyArray, j as ElementKindSpecification, l as ElementShape, s as Color, h as BorderStyle, K as KeysOf } from '../shared/core.D74xkKkG.js';
5
5
  import { IsStringLiteral } from 'type-fest/source/is-literal';
6
6
 
@@ -147,7 +147,8 @@ declare namespace ViewPredicate {
147
147
  type DeploymentConnectionExpression<T extends AnyTypes> = T extends Types<any, any, any, any, any, any, any, infer F extends string> ? `${F} -> ${F}` : never;
148
148
  type WhereTag<Tag extends string> = `tag ${'is' | 'is not'} #${Tag}`;
149
149
  type WhereKind<Kind extends string> = `kind ${'is' | 'is not'} ${Kind}`;
150
- type WhereEq<Types extends AnyTypes> = ViewPredicate.WhereTag<Types['Tag']> | ViewPredicate.WhereKind<Types['ElementKind']>;
150
+ type WhereParticipant<Types extends AnyTypes> = `${Participant}.${WhereTag<Types['Tag']> | WhereKind<Types['ElementKind']>}`;
151
+ type WhereEq<Types extends AnyTypes> = ViewPredicate.WhereTag<Types['Tag']> | ViewPredicate.WhereKind<Types['ElementKind']> | ViewPredicate.WhereParticipant<Types>;
151
152
  type WhereOperator<Types extends AnyTypes> = ViewPredicate.WhereEq<Types> | {
152
153
  and: NonEmptyArray<ViewPredicate.WhereOperator<Types>>;
153
154
  or?: never;
@@ -1,7 +1,7 @@
1
- import { l, L as LikeC4Model, i, d } from '../shared/index.KOeaSlL8.js';
2
- import { t, m, p as parentFqn, a as isSameHierarchy, n as nameFromFqn, i as i$1, l as l$1, b as t$1 } from '../shared/object_hash.CE_oF3I3.js';
3
- import { b as isElementPredicateExpr, o, c as isScopedElementView, D as DeploymentElement, n as n$1, d as DefaultThemeColor, e as DefaultElementShape } from '../shared/view.DrmaOfjr.js';
4
- import { u, i as invariant } from '../shared/chunk-RAAYCPUM.M-JWF7SS.js';
1
+ import { l, L as LikeC4Model, i, d } from '../shared/core.CqCTxzMY.mjs';
2
+ import { b as t, m, p as parentFqn, c as isSameHierarchy, n as nameFromFqn, a as i$1, l as l$1, d as t$1 } from '../shared/core.BxvDITEI.mjs';
3
+ import { b as isElementPredicateExpr, o, c as isScopedElementView, D as DeploymentElement, n as n$1, d as DefaultThemeColor, e as DefaultElementShape } from '../shared/core.DunIMHRf.mjs';
4
+ import { u, i as invariant } from '../shared/core.M-JWF7SS.mjs';
5
5
 
6
6
  function n(...r){return u(Object.fromEntries,r)}
7
7
 
@@ -89,6 +89,16 @@ function parseWhere(where) {
89
89
  eq: op.replace("kind is ", "")
90
90
  }
91
91
  };
92
+ case op.startsWith("source."):
93
+ return {
94
+ operator: parseWhere(op.replace("source.", "")),
95
+ participant: "source"
96
+ };
97
+ case op.startsWith("target."):
98
+ return {
99
+ operator: parseWhere(op.replace("target.", "")),
100
+ participant: "target"
101
+ };
92
102
  default:
93
103
  throw new Error(`Unknown where operator: ${where}`);
94
104
  }
@@ -0,0 +1,86 @@
1
+ 'use strict';
2
+
3
+ const model_index = require('../shared/core.BGus30EM.cjs');
4
+ const compute = require('../shared/core.gv1bMwCC.cjs');
5
+ const view = require('../shared/core.B2QYWlYe.cjs');
6
+ const object_hash = require('../shared/core.C9DCnJh8.cjs');
7
+ const chunkRAAYCPUM = require('../shared/core.DsoCu540.cjs');
8
+
9
+ function y(...t){return chunkRAAYCPUM.u(f,t)}function f(t,e){if(!object_hash.i(e,1))return {...t};if(!object_hash.i(e,2)){let{[e[0]]:r,...m}=t;return m}let o={...t};for(let r of e)delete o[r];return o}
10
+
11
+ function resolveRulesExtendedViews(unresolvedViews) {
12
+ const g = new model_index.Graph({
13
+ type: "directed"
14
+ });
15
+ const extendedViews = [];
16
+ for (const view$1 of model_index.r(unresolvedViews)) {
17
+ g.addNode(view$1.id, { view: view$1 });
18
+ if (view.isExtendsElementView(view$1)) {
19
+ extendedViews.push(view$1);
20
+ }
21
+ }
22
+ if (extendedViews.length === 0) {
23
+ return unresolvedViews;
24
+ }
25
+ for (const view of extendedViews) {
26
+ if (!g.hasNode(view.extends)) {
27
+ console.warn(`View "${view.id}" extends from "${view.extends}" which does not exist`);
28
+ continue;
29
+ }
30
+ if (model_index.willCreateCycle(g, view.id, view.extends)) {
31
+ console.warn(`View "${view.id}" extends from "${view.extends}" which creates a cycle`);
32
+ continue;
33
+ }
34
+ g.addDirectedEdge(view.id, view.extends);
35
+ }
36
+ const sorted = model_index.topologicalSortExports.topologicalSort(g).reverse();
37
+ return sorted.reduce((acc, id) => {
38
+ const view$1 = g.getNodeAttribute(id, "view");
39
+ if (!view.isExtendsElementView(view$1)) {
40
+ acc[view$1.id] = view$1;
41
+ return acc;
42
+ }
43
+ const extendsFrom = acc[view$1.extends];
44
+ if (!extendsFrom || !view.isElementView(extendsFrom)) {
45
+ return acc;
46
+ }
47
+ acc[view$1.id] = {
48
+ ...extendsFrom,
49
+ ...view$1,
50
+ rules: [...extendsFrom.rules, ...view$1.rules]
51
+ };
52
+ return acc;
53
+ }, {});
54
+ }
55
+
56
+ function withReadableEdges({ edges, nodes, ...view }, separator = ":") {
57
+ const edgeids = model_index.l(edges, (e) => [e.id, `${e.source}${separator}${e.target}`]);
58
+ return {
59
+ ...view,
60
+ edges: edges.map((e) => ({
61
+ ...e,
62
+ id: edgeids[e.id]
63
+ })),
64
+ nodes: nodes.map((n) => ({
65
+ ...n,
66
+ inEdges: object_hash.m(n.inEdges, (e) => edgeids[e]),
67
+ outEdges: object_hash.m(n.outEdges, (e) => edgeids[e])
68
+ })),
69
+ nodeIds: nodes.map((n) => n.id),
70
+ edgeIds: edges.map((e) => edgeids[e.id])
71
+ };
72
+ }
73
+ function viewsWithReadableEdges({ views, ...model }) {
74
+ return {
75
+ ...model,
76
+ views: model_index.i(views, (v) => y(withReadableEdges(v), ["nodeIds", "edgeIds"]))
77
+ };
78
+ }
79
+
80
+ exports.computeView = model_index.computeView;
81
+ exports.computeViews = model_index.computeViews;
82
+ exports.unsafeComputeView = model_index.unsafeComputeView;
83
+ exports.computeRelationshipsView = compute.computeRelationshipsView;
84
+ exports.resolveRulesExtendedViews = resolveRulesExtendedViews;
85
+ exports.viewsWithReadableEdges = viewsWithReadableEdges;
86
+ exports.withReadableEdges = withReadableEdges;
@@ -0,0 +1,23 @@
1
+ export { C as ComputeViewResult, c as computeView, a as computeViews, u as unsafeComputeView } from '../shared/core.BdbFkE_p.cjs';
2
+ export { c as computeRelationshipsView } from '../shared/core.BvdNMbcA.cjs';
3
+ import { L as LikeC4View, C as ComputedView, a as ComputedLikeC4Model } from '../shared/core.B72vUaNB.cjs';
4
+ import 'type-fest';
5
+ import '../shared/core.D74xkKkG.cjs';
6
+
7
+ /**
8
+ * Resolve rules of extended views
9
+ * (Removes invalid views)
10
+ */
11
+ declare function resolveRulesExtendedViews<V extends Record<any, LikeC4View>>(unresolvedViews: V): V;
12
+
13
+ /**
14
+ * Convert hashed edge ids to human-readable
15
+ * Mostly for testing purposes
16
+ */
17
+ declare function withReadableEdges<T extends ComputedView>({ edges, nodes, ...view }: T, separator?: string): T & {
18
+ nodeIds: string[];
19
+ edgeIds: string[];
20
+ };
21
+ declare function viewsWithReadableEdges<M extends ComputedLikeC4Model>({ views, ...model }: M): M;
22
+
23
+ export { resolveRulesExtendedViews, viewsWithReadableEdges, withReadableEdges };
@@ -1,5 +1,6 @@
1
- export { C as ComputeViewResult, c as computeView, a as computeViews, u as unsafeComputeView } from '../shared/core.2I-l5UtM.mjs';
2
- import { L as LikeC4View, C as ComputedView, a as ComputedLikeC4Model } from '../shared/core.BL1oTk7-.mjs';
1
+ export { C as ComputeViewResult, c as computeView, a as computeViews, u as unsafeComputeView } from '../shared/core.jy6z2iRn.mjs';
2
+ export { c as computeRelationshipsView } from '../shared/core.BRuJ3Wzf.mjs';
3
+ import { L as LikeC4View, C as ComputedView, a as ComputedLikeC4Model } from '../shared/core.Dfzrh1VA.mjs';
3
4
  import 'type-fest';
4
5
  import '../shared/core.D74xkKkG.mjs';
5
6
 
@@ -1,5 +1,6 @@
1
- export { C as ComputeViewResult, c as computeView, a as computeViews, u as unsafeComputeView } from '../shared/core.CqXs9Frh.js';
2
- import { L as LikeC4View, C as ComputedView, a as ComputedLikeC4Model } from '../shared/core.DyJ41fBO.js';
1
+ export { C as ComputeViewResult, c as computeView, a as computeViews, u as unsafeComputeView } from '../shared/core.ZWiGANIJ.js';
2
+ export { c as computeRelationshipsView } from '../shared/core.Damrzla-.js';
3
+ import { L as LikeC4View, C as ComputedView, a as ComputedLikeC4Model } from '../shared/core.D_Gc58Gt.js';
3
4
  import 'type-fest';
4
5
  import '../shared/core.D74xkKkG.js';
5
6
 
@@ -1,8 +1,9 @@
1
- import { G as Graph, r, w as willCreateCycle, t as topologicalSortExports, l, i as i$1 } from '../shared/index.KOeaSlL8.js';
2
- export { c as computeView, a as computeViews, u as unsafeComputeView } from '../shared/index.KOeaSlL8.js';
3
- import { i as isExtendsElementView, a as isElementView } from '../shared/view.DrmaOfjr.js';
4
- import { i, m } from '../shared/object_hash.CE_oF3I3.js';
5
- import { u } from '../shared/chunk-RAAYCPUM.M-JWF7SS.js';
1
+ import { G as Graph, r, w as willCreateCycle, t as topologicalSortExports, l, i as i$1 } from '../shared/core.CqCTxzMY.mjs';
2
+ export { c as computeView, a as computeViews, u as unsafeComputeView } from '../shared/core.CqCTxzMY.mjs';
3
+ export { c as computeRelationshipsView } from '../shared/core.m3rCQAv6.mjs';
4
+ import { i as isExtendsElementView, a as isElementView } from '../shared/core.DunIMHRf.mjs';
5
+ import { a as i, m } from '../shared/core.BxvDITEI.mjs';
6
+ import { u } from '../shared/core.M-JWF7SS.mjs';
6
7
 
7
8
  function y(...t){return u(f,t)}function f(t,e){if(!i(e,1))return {...t};if(!i(e,2)){let{[e[0]]:r,...m}=t;return m}let o={...t};for(let r of e)delete o[r];return o}
8
9