@likec4/core 1.19.0 → 1.19.2

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 (47) hide show
  1. package/dist/builder/index.d.mts +3 -3
  2. package/dist/builder/index.d.ts +3 -3
  3. package/dist/builder/index.js +2 -2
  4. package/dist/compute-view/index.d.mts +2 -2
  5. package/dist/compute-view/index.d.ts +2 -2
  6. package/dist/compute-view/index.js +3 -3
  7. package/dist/index.d.mts +3 -3
  8. package/dist/index.d.ts +3 -3
  9. package/dist/index.js +3 -3
  10. package/dist/model/index.d.mts +8 -3
  11. package/dist/model/index.d.ts +8 -3
  12. package/dist/model/index.js +1 -1
  13. package/dist/shared/{core.BZ9Msq7w.d.mts → core.2I-l5UtM.d.mts} +5 -1
  14. package/dist/shared/{core.CmYMqgha.d.mts → core.BL1oTk7-.d.mts} +13 -3
  15. package/dist/shared/{core.BIfgabEw.d.ts → core.CqXs9Frh.d.ts} +5 -1
  16. package/dist/shared/{core.C05RDLhi.d.ts → core.DyJ41fBO.d.ts} +13 -3
  17. package/dist/shared/{index.-BdzdI2C.js → index.KOeaSlL8.js} +333 -209
  18. package/dist/shared/{view.CyZrG8BJ.js → view.DrmaOfjr.js} +3 -0
  19. package/dist/types/index.d.mts +2 -2
  20. package/dist/types/index.d.ts +2 -2
  21. package/dist/types/index.js +1 -1
  22. package/dist/utils/index.d.mts +16 -1
  23. package/dist/utils/index.d.ts +16 -1
  24. package/dist/utils/index.js +18 -1
  25. package/package.json +9 -9
  26. package/src/builder/Builder.view-common.ts +1 -0
  27. package/src/compute-view/deployment-view/__test__/fixture.ts +31 -3
  28. package/src/compute-view/deployment-view/_types.ts +2 -1
  29. package/src/compute-view/deployment-view/compute.ts +4 -36
  30. package/src/compute-view/deployment-view/predicates/index.ts +8 -0
  31. package/src/compute-view/deployment-view/predicates/relation-direct.ts +117 -88
  32. package/src/compute-view/deployment-view/predicates/relation-in-out.ts +16 -8
  33. package/src/compute-view/deployment-view/predicates/relation-incoming.ts +18 -12
  34. package/src/compute-view/deployment-view/predicates/relation-outgoing.ts +16 -9
  35. package/src/compute-view/deployment-view/predicates/relation-where.ts +18 -0
  36. package/src/compute-view/deployment-view/predicates/utils.ts +183 -0
  37. package/src/compute-view/memory/ops.ts +1 -1
  38. package/src/model/DeploymentElementModel.ts +14 -1
  39. package/src/model/RelationModel.ts +4 -0
  40. package/src/model/connection/deployment/DeploymentConnectionModel.ts +11 -1
  41. package/src/types/deployments.ts +1 -0
  42. package/src/types/expression-v2.ts +12 -0
  43. package/src/types/index.ts +1 -0
  44. package/src/types/operators.ts +5 -5
  45. package/src/utils/index.ts +1 -0
  46. package/src/utils/iterable/find.ts +36 -0
  47. package/src/utils/iterable/index.ts +1 -0
@@ -11,6 +11,7 @@ import {
11
11
  type ElementShape as C4ElementShape,
12
12
  type IteratorLike,
13
13
  type Link,
14
+ type RelationshipKind,
14
15
  type Tag,
15
16
  type Tag as C4Tag,
16
17
  type ThemeColor,
@@ -62,6 +63,10 @@ abstract class AbstractDeploymentElementModel<M extends AnyAux = AnyAux> {
62
63
  return this.$node.tags ?? []
63
64
  }
64
65
 
66
+ get kind(): DeploymentNodeKind | string | null {
67
+ return this.$node.kind ?? null
68
+ }
69
+
65
70
  get description(): string | null {
66
71
  return this.$node.description ?? null
67
72
  }
@@ -223,7 +228,7 @@ export class DeploymentNodeModel<M extends AnyAux = AnyAux> extends AbstractDepl
223
228
  return this.$model.parent(this)
224
229
  }
225
230
 
226
- get kind(): DeploymentNodeKind {
231
+ override get kind(): DeploymentNodeKind {
227
232
  return this.$node.kind
228
233
  }
229
234
 
@@ -367,6 +372,10 @@ export class DeployedInstanceModel<M extends AnyAux = AnyAux> extends AbstractDe
367
372
  return this.$instance.tags ?? []
368
373
  }
369
374
 
375
+ override get kind(): string | null {
376
+ return this.$instance.kind ?? null
377
+ }
378
+
370
379
  override get description(): string | null {
371
380
  return this.$instance.description ?? this.element.description
372
381
  }
@@ -514,6 +523,10 @@ export class DeploymentRelationModel<M extends AnyAux = AnyAux> {
514
523
  return this.$relationship.tags ?? []
515
524
  }
516
525
 
526
+ get kind(): RelationshipKind | null {
527
+ return this.$relationship.kind ?? null
528
+ }
529
+
517
530
  get navigateTo(): LikeC4ViewModel<M> | null {
518
531
  return this.$relationship.navigateTo ? this.$model.$model.view(this.$relationship.navigateTo) : null
519
532
  }
@@ -67,6 +67,10 @@ export class RelationshipModel<M extends AnyAux = AnyAux> {
67
67
  return this.$relationship.tags ?? []
68
68
  }
69
69
 
70
+ get kind(): string | null {
71
+ return this.$relationship.kind ?? null
72
+ }
73
+
70
74
  get links(): ReadonlyArray<Link> {
71
75
  return this.$relationship.links ?? []
72
76
  }
@@ -110,11 +110,21 @@ export class DeploymentConnectionModel<M extends AnyAux = AnyAux>
110
110
  yield* this.relations.deployment
111
111
  }
112
112
 
113
+ /**
114
+ * Merge with another connections, if it has the same source and target.
115
+ * Returns new connection with union of relationships.
116
+ */
117
+ public mergeWith(others: DeploymentConnectionModel<M>[]): DeploymentConnectionModel<M>
113
118
  /**
114
119
  * Merge with another connection, if it has the same source and target.
115
120
  * Returns new connection with union of relationships.
116
121
  */
117
- public mergeWith(other: DeploymentConnectionModel<M>) {
122
+ public mergeWith(other: DeploymentConnectionModel<M>): DeploymentConnectionModel<M>
123
+ public mergeWith(other: DeploymentConnectionModel<M> | DeploymentConnectionModel<M>[]): DeploymentConnectionModel<M> {
124
+ if (Array.isArray(other)) {
125
+ return other.reduce((acc, o) => acc.mergeWith(o), this)
126
+ }
127
+
118
128
  invariant(this.source.id === other.source.id, 'Cannot merge connections with different sources')
119
129
  invariant(this.target.id === other.target.id, 'Cannot merge connections with different targets')
120
130
  return new DeploymentConnectionModel(
@@ -42,6 +42,7 @@ export interface DeployedInstance {
42
42
  readonly title?: string
43
43
  readonly description?: string | null
44
44
  readonly technology?: string | null
45
+ readonly kind?: string | null // TODO: ensure the property is set
45
46
  readonly tags?: NonEmptyArray<Tag> | null
46
47
  readonly links?: NonEmptyArray<Link> | null
47
48
  readonly style?: DeploymentElementStyle
@@ -2,6 +2,7 @@ import { invariant } from '../errors'
2
2
  import type { ExclusiveUnion } from './_common'
3
3
  import type { DeploymentRef as DeploymentModelRef, PredicateSelector } from './deployments'
4
4
  import type { Fqn } from './element'
5
+ import type { WhereOperator } from './operators'
5
6
 
6
7
  export namespace FqnRef {
7
8
  /**
@@ -131,6 +132,15 @@ export namespace RelationExpr {
131
132
  export const isInOut = (expr: ExpressionV2): expr is InOut => {
132
133
  return 'inout' in expr
133
134
  }
135
+ export type Where<D = Fqn, M = Fqn> = {
136
+ where: {
137
+ expr: ExpressionV2<D, M>
138
+ condition: WhereOperator<string, string>
139
+ }
140
+ }
141
+ export const isWhere = (expr: ExpressionV2): expr is Where => {
142
+ return 'where' in expr
143
+ }
134
144
  }
135
145
 
136
146
  export type RelationExpr<D = Fqn, M = Fqn> = ExclusiveUnion<{
@@ -138,6 +148,7 @@ export type RelationExpr<D = Fqn, M = Fqn> = ExclusiveUnion<{
138
148
  Incoming: RelationExpr.Incoming<D, M>
139
149
  Outgoing: RelationExpr.Outgoing<D, M>
140
150
  InOut: RelationExpr.InOut<D, M>
151
+ Where: RelationExpr.Where<D, M>
141
152
  }>
142
153
 
143
154
  /**
@@ -154,6 +165,7 @@ export type ExpressionV2<D = Fqn, M = Fqn> = ExclusiveUnion<{
154
165
  Incoming: RelationExpr.Incoming<D, M>
155
166
  Outgoing: RelationExpr.Outgoing<D, M>
156
167
  InOut: RelationExpr.InOut<D, M>
168
+ RelationPredicateOrWhere: RelationExpr.Where<D, M>
157
169
  }>
158
170
 
159
171
  export namespace ExpressionV2 {
@@ -121,6 +121,7 @@ export type {
121
121
  Filterable,
122
122
  KindEqual,
123
123
  NotOperator,
124
+ OperatorPredicate,
124
125
  OrOperator,
125
126
  TagEqual,
126
127
  WhereOperator,
@@ -61,19 +61,19 @@ export type WhereOperator<Tag, Kind> =
61
61
  | OrOperator<Tag, Kind>
62
62
 
63
63
  export type Filterable<
64
- FTag extends string = string,
65
- FKind extends string = string
64
+ FTag extends string | null = string | null,
65
+ FKind extends string | null = string | null,
66
66
  > = {
67
67
  tags?: readonly FTag[] | null
68
68
  kind?: FKind
69
69
  }
70
70
 
71
- type OperatorPredicate<V extends Filterable> = (value: V) => boolean
71
+ export type OperatorPredicate<V extends Filterable> = (value: V) => boolean
72
72
 
73
73
  export function whereOperatorAsPredicate<
74
74
  FTag extends string = string,
75
- FKind extends string = string
76
- >(operator: WhereOperator<FTag, FKind>): OperatorPredicate<Filterable<FTag, FKind>> {
75
+ FKind extends string = string,
76
+ >(operator: WhereOperator<FTag, FKind>): OperatorPredicate<Filterable> {
77
77
  switch (true) {
78
78
  case isTagEqual(operator): {
79
79
  if ('eq' in operator.tag) {
@@ -40,6 +40,7 @@ export {
40
40
  } from './guards'
41
41
  export {
42
42
  ifilter,
43
+ ifind,
43
44
  iflat,
44
45
  imap,
45
46
  ireduce,
@@ -0,0 +1,36 @@
1
+ import { isFunction } from 'remeda'
2
+ import { invariant } from '../../errors'
3
+
4
+ /**
5
+ * Finds the first element in the iterable that satisfies the predicate.
6
+ * Composable first version of `find`.
7
+ * @signature
8
+ * ifind(predicate)(data)
9
+ */
10
+ export function ifind<T>(predicate: (item: T) => boolean): (iterable: Iterable<T>) => T | undefined
11
+ /**
12
+ * Finds the first element in the iterable that satisfies the predicate.
13
+ * Data first version of `find`.
14
+ * @signature
15
+ * ifind(data, predicate)
16
+ */
17
+ export function ifind<T>(iterable: Iterable<T>, predicate: (item: T) => boolean): T | undefined
18
+
19
+ export function ifind(arg1: unknown, arg2?: unknown) {
20
+ const pred = (arg2 ?? arg1) as (v: any) => boolean
21
+ invariant(isFunction(pred))
22
+
23
+ function _find(iter: Iterable<unknown>) {
24
+ for (const value of iter) {
25
+ if (pred(value)) {
26
+ return value
27
+ }
28
+ }
29
+ return
30
+ }
31
+
32
+ if (!arg2) {
33
+ return _find
34
+ }
35
+ return _find(arg1 as Iterable<unknown>)
36
+ }
@@ -4,6 +4,7 @@ export { isIterable } from './_types'
4
4
  * operators
5
5
  */
6
6
  export { ifilter } from './filter'
7
+ export { ifind } from './find'
7
8
  export { iflat } from './flat'
8
9
  export { imap } from './map'
9
10
  export { ireduce } from './reduce'