@likec4/core 1.9.0 → 1.10.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.
package/dist/index.d.cts CHANGED
@@ -1,157 +1,5 @@
1
- import { P as Primitive, H as HexColorLiteral, T as ThemeColorValues, L as LiteralUnion, F as Fqn$1, R as RelationID$1, V as ViewID$1, E as EdgeId$1, C as ComputedView, a as Tag, b as ComputedNode, N as NodeId, c as ElementKind, d as ElementShape, e as Color, f as ComputedEdge, g as ComputedLikeC4Model, h as Element, i as Relation, j as RelationshipKind, k as NonEmptyArray } from './shared/core.9l7eW3pn.cjs';
2
- export { aq as AndOperator, A as AsFqn, aP as AutoLayoutDirection, bh as BBox, aU as BasicElementView, aT as BasicView, o as BorderStyle, B as BorderStyles, aE as ColorLiteral, be as ComputedDynamicView, bd as ComputedElementView, m as CustomColor, b1 as CustomColorDefinitions, G as CustomElementExpr, ad as CustomRelationExpr, aA as DefaultArrowType, q as DefaultElementShape, az as DefaultLineStyle, aB as DefaultRelationshipColor, D as DefaultThemeColor, bk as DiagramEdge, bj as DiagramNode, bl as DiagramView, b0 as DynamicView, aZ as DynamicViewIncludeRule, a$ as DynamicViewRule, aY as DynamicViewStep, U as ElementExpression, M as ElementKindExpr, v as ElementKindSpecification, u as ElementKindSpecificationStyle, bo as ElementNotation, $ as ElementPredicateExpression, w as ElementRefExpr, p as ElementShapes, r as ElementStyle, Q as ElementTagExpr, aG as ElementThemeColorValues, aH as ElementThemeColors, aX as ElementView, Z as ElementWhereExpr, aj as EqualOperator, y as ExpandedElementExpr, l as Expr, ah as Expression, aW as ExtendsElementView, I as IconUrl, a3 as InOutExpr, a5 as IncomingExpr, am as KindEqual, aK as LikeC4Theme, b2 as LikeC4View, t as Link, ao as NotOperator, as as OrOperator, a7 as OutgoingExpr, aw as OverviewGraph, ai as ParsedLikeC4Model, n as Point, a1 as RelationExpr, a9 as RelationExpression, af as RelationPredicateExpression, ab as RelationWhereExpr, ay as RelationshipArrowType, aC as RelationshipKindSpecification, ax as RelationshipLineType, aI as RelationshipThemeColorValues, aJ as RelationshipThemeColors, aV as ScopedElementView, b8 as StepEdgeId, b7 as StepEdgeIdLiteral, ak as TagEqual, s as TagSpec, aD as ThemeColor, bn as ViewChange, bm as ViewManualLayout, aS as ViewRule, aQ as ViewRuleAutoLayout, aL as ViewRulePredicate, aN as ViewRuleStyle, bb as ViewWithHash, bc as ViewWithNotation, au as WhereOperator, W as WildcardExpr, X as XYPoint, ba as extractStep, bi as getBBoxCenter, ar as isAndOperator, bf as isComputedDynamicView, bg as isComputedElementView, J as isCustomElement, ae as isCustomRelationExpr, b3 as isDynamicView, a_ as isDynamicViewIncludeRule, Y as isElement, O as isElementKindExpr, a0 as isElementPredicateExpr, x as isElementRef, S as isElementTagExpr, b4 as isElementView, _ as isElementWhere, z as isExpandedElementExpr, b5 as isExtendsElementView, a4 as isInOut, a6 as isIncoming, an as isKindEqual, ap as isNotOperator, at as isOrOperator, a8 as isOutgoing, a2 as isRelation, aa as isRelationExpression, ag as isRelationPredicateExpr, ac as isRelationWhere, b6 as isScopedElementView, b9 as isStepEdgeId, al as isTagEqual, aF as isThemeColor, aR as isViewRuleAutoLayout, aM as isViewRulePredicate, aO as isViewRuleStyle, K as isWildcard, av as whereOperatorAsPredicate } from './shared/core.9l7eW3pn.cjs';
3
-
4
- type Numeric = number | bigint;
5
-
6
- /**
7
- Returns a boolean for whether the given type is `never`.
8
-
9
- @link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
10
- @link https://stackoverflow.com/a/53984913/10292952
11
- @link https://www.zhenghao.io/posts/ts-never
12
-
13
- Useful in type utilities, such as checking if something does not occur.
14
-
15
- @example
16
- ```
17
- import type {IsNever, And} from 'type-fest';
18
-
19
- // https://github.com/andnp/SimplyTyped/blob/master/src/types/strings.ts
20
- type AreStringsEqual<A extends string, B extends string> =
21
- And<
22
- IsNever<Exclude<A, B>> extends true ? true : false,
23
- IsNever<Exclude<B, A>> extends true ? true : false
24
- >;
25
-
26
- type EndIfEqual<I extends string, O extends string> =
27
- AreStringsEqual<I, O> extends true
28
- ? never
29
- : void;
30
-
31
- function endIfEqual<I extends string, O extends string>(input: I, output: O): EndIfEqual<I, O> {
32
- if (input === output) {
33
- process.exit(0);
34
- }
35
- }
36
-
37
- endIfEqual('abc', 'abc');
38
- //=> never
39
-
40
- endIfEqual('abc', '123');
41
- //=> void
42
- ```
43
-
44
- @category Type Guard
45
- @category Utilities
46
- */
47
- type IsNever<T> = [T] extends [never] ? true : false;
48
-
49
- /**
50
- Returns a boolean for whether the given type `T` is the specified `LiteralType`.
51
-
52
- @link https://stackoverflow.com/a/52806744/10292952
53
-
54
- @example
55
- ```
56
- LiteralCheck<1, number>
57
- //=> true
58
-
59
- LiteralCheck<number, number>
60
- //=> false
61
-
62
- LiteralCheck<1, string>
63
- //=> false
64
- ```
65
- */
66
- type LiteralCheck<T, LiteralType extends Primitive> = (
67
- IsNever<T> extends false // Must be wider than `never`
68
- ? [T] extends [LiteralType & infer U] // Remove any branding
69
- ? [U] extends [LiteralType] // Must be narrower than `LiteralType`
70
- ? [LiteralType] extends [U] // Cannot be wider than `LiteralType`
71
- ? false
72
- : true
73
- : false
74
- : false
75
- : false
76
- );
77
-
78
- /**
79
- Returns a boolean for whether the given type `T` is one of the specified literal types in `LiteralUnionType`.
80
-
81
- @example
82
- ```
83
- LiteralChecks<1, Numeric>
84
- //=> true
85
-
86
- LiteralChecks<1n, Numeric>
87
- //=> true
88
-
89
- LiteralChecks<bigint, Numeric>
90
- //=> false
91
- ```
92
- */
93
- type LiteralChecks<T, LiteralUnionType> = (
94
- // Conditional type to force union distribution.
95
- // If `T` is none of the literal types in the union `LiteralUnionType`, then `LiteralCheck<T, LiteralType>` will evaluate to `false` for the whole union.
96
- // If `T` is one of the literal types in the union, it will evaluate to `boolean` (i.e. `true | false`)
97
- IsNotFalse<LiteralUnionType extends Primitive
98
- ? LiteralCheck<T, LiteralUnionType>
99
- : never
100
- >
101
- );
102
-
103
- /**
104
- Returns a boolean for whether the given type is a `number` or `bigint` [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types).
105
-
106
- Useful for:
107
- - providing strongly-typed functions when given literal arguments
108
- - type utilities, such as when constructing parsers and ASTs
109
-
110
- @example
111
- ```
112
- import type {IsNumericLiteral} from 'type-fest';
113
-
114
- // https://github.com/inocan-group/inferred-types/blob/master/src/types/boolean-logic/EndsWith.ts
115
- type EndsWith<TValue, TEndsWith extends string> =
116
- TValue extends string
117
- ? IsStringLiteral<TEndsWith> extends true
118
- ? IsStringLiteral<TValue> extends true
119
- ? TValue extends `${string}${TEndsWith}`
120
- ? true
121
- : false
122
- : boolean
123
- : boolean
124
- : TValue extends number
125
- ? IsNumericLiteral<TValue> extends true
126
- ? EndsWith<`${TValue}`, TEndsWith>
127
- : false
128
- : false;
129
-
130
- function endsWith<Input extends string | number, End extends string>(input: Input, end: End) {
131
- return `${input}`.endsWith(end) as EndsWith<Input, End>;
132
- }
133
-
134
- endsWith('abc', 'c');
135
- //=> true
136
-
137
- endsWith(123456, '456');
138
- //=> true
139
-
140
- const end = '123' as string;
141
-
142
- endsWith('abc123', end);
143
- //=> boolean
144
- ```
145
-
146
- @category Type Guard
147
- @category Utilities
148
- */
149
- type IsNumericLiteral<T> = LiteralChecks<T, Numeric>;
150
-
151
- /**
152
- Returns a boolean for whether the given `boolean` is not `false`.
153
- */
154
- type IsNotFalse<T extends boolean> = [T] extends [false] ? false : true;
1
+ import { H as HexColorLiteral, T as ThemeColorValues, L as LiteralUnion, F as Fqn$1, R as RelationID$1, V as ViewID$1, E as EdgeId$1, C as ComputedView, a as Tag, b as ComputedNode, N as NodeId, c as ElementKind, d as ElementShape, e as Color, f as ComputedEdge, g as ComputedLikeC4Model, h as Element, i as Relation, j as RelationshipKind, k as NonEmptyArray } from './shared/core.Czd51Dd8.cjs';
2
+ export { aq as AndOperator, A as AsFqn, aP as AutoLayoutDirection, bl as BBox, aU as BasicElementView, aT as BasicView, o as BorderStyle, B as BorderStyles, aE as ColorLiteral, bi as ComputedDynamicView, bh as ComputedElementView, n as CustomColor, b4 as CustomColorDefinitions, G as CustomElementExpr, ad as CustomRelationExpr, aA as DefaultArrowType, q as DefaultElementShape, az as DefaultLineStyle, aB as DefaultRelationshipColor, D as DefaultThemeColor, bo as DiagramEdge, bn as DiagramNode, bp as DiagramView, b2 as DynamicView, a$ as DynamicViewIncludeRule, aZ as DynamicViewParallelSteps, b1 as DynamicViewRule, aY as DynamicViewStep, a_ as DynamicViewStepOrParallel, U as ElementExpression, M as ElementKindExpr, v as ElementKindSpecification, u as ElementKindSpecificationStyle, bs as ElementNotation, $ as ElementPredicateExpression, w as ElementRefExpr, p as ElementShapes, r as ElementStyle, Q as ElementTagExpr, aG as ElementThemeColorValues, aH as ElementThemeColors, aX as ElementView, Z as ElementWhereExpr, aj as EqualOperator, y as ExpandedElementExpr, l as Expr, ah as Expression, aW as ExtendsElementView, I as IconUrl, a3 as InOutExpr, a5 as IncomingExpr, am as KindEqual, aK as LikeC4Theme, b5 as LikeC4View, t as Link, m as NonEmptyReadonlyArray, ao as NotOperator, as as OrOperator, a7 as OutgoingExpr, aw as OverviewGraph, ai as ParsedLikeC4Model, P as Point, a1 as RelationExpr, a9 as RelationExpression, af as RelationPredicateExpression, ab as RelationWhereExpr, ay as RelationshipArrowType, aC as RelationshipKindSpecification, ax as RelationshipLineType, aI as RelationshipThemeColorValues, aJ as RelationshipThemeColors, aV as ScopedElementView, bb as StepEdgeId, ba as StepEdgeIdLiteral, ak as TagEqual, s as TagSpec, aD as ThemeColor, br as ViewChange, bq as ViewManualLayout, aS as ViewRule, aQ as ViewRuleAutoLayout, aL as ViewRulePredicate, aN as ViewRuleStyle, bf as ViewWithHash, bg as ViewWithNotation, au as WhereOperator, W as WildcardExpr, X as XYPoint, bd as extractStep, bm as getBBoxCenter, be as getParallelStepsPrefix, ar as isAndOperator, bj as isComputedDynamicView, bk as isComputedElementView, J as isCustomElement, ae as isCustomRelationExpr, b6 as isDynamicView, b0 as isDynamicViewIncludeRule, b3 as isDynamicViewParallelSteps, Y as isElement, O as isElementKindExpr, a0 as isElementPredicateExpr, x as isElementRef, S as isElementTagExpr, b7 as isElementView, _ as isElementWhere, z as isExpandedElementExpr, b8 as isExtendsElementView, a4 as isInOut, a6 as isIncoming, an as isKindEqual, ap as isNotOperator, at as isOrOperator, a8 as isOutgoing, a2 as isRelation, aa as isRelationExpression, ag as isRelationPredicateExpr, ac as isRelationWhere, b9 as isScopedElementView, bc as isStepEdgeId, al as isTagEqual, aF as isThemeColor, aR as isViewRuleAutoLayout, aM as isViewRulePredicate, aO as isViewRuleStyle, K as isWildcard, av as whereOperatorAsPredicate } from './shared/core.Czd51Dd8.cjs';
155
3
 
156
4
  declare const ElementColors: {
157
5
  readonly primary: {
@@ -650,6 +498,8 @@ declare namespace LikeC4Model {
650
498
  }
651
499
  }
652
500
 
501
+ declare function compareNatural(a: string | undefined, b: string | undefined): -1 | 0 | 1;
502
+
653
503
  type Predicate<T> = (x: T) => boolean;
654
504
  declare function nameFromFqn(fqn: Fqn$1): string;
655
505
  declare function isAncestor<E extends {
@@ -682,10 +532,193 @@ declare function ancestorsFqn(fqn: Fqn$1): Fqn$1[];
682
532
  * - Positive number if a is deeper than b.
683
533
  * - Negative number if b is deeper than a.
684
534
  */
685
- declare function compareFqnHierarchically<T extends string = string>(a: T, b: T): number;
535
+ declare function compareFqnHierarchically<T extends string = string>(a: T, b: T): -1 | 0 | 1;
686
536
  declare function compareByFqnHierarchically<T extends {
687
537
  id: string;
688
- }>(a: T, b: T): number;
538
+ }>(a: T, b: T): 0 | 1 | -1;
539
+ type IterableContainer$1<T = unknown> = ReadonlyArray<T> | readonly [];
540
+ type ReorderedArray<T extends IterableContainer$1> = {
541
+ -readonly [P in keyof T]: T[number];
542
+ };
543
+ declare function sortByFqnHierarchically<T extends {
544
+ id: string;
545
+ }, A extends IterableContainer$1<T>>(array: A): ReorderedArray<A>;
546
+ declare function sortNaturalByFqn<T extends {
547
+ id: string;
548
+ }, A extends IterableContainer$1<T>>(array: A): ReorderedArray<A>;
549
+
550
+ /**
551
+ Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
552
+
553
+ @category Type
554
+ */
555
+ type Primitive =
556
+ | null
557
+ | undefined
558
+ | string
559
+ | number
560
+ | boolean
561
+ | symbol
562
+ | bigint;
563
+
564
+ declare global {
565
+ // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
566
+ interface SymbolConstructor {
567
+ readonly observable: symbol;
568
+ }
569
+ }
570
+
571
+ type Numeric = number | bigint;
572
+
573
+ /**
574
+ Returns a boolean for whether the given type is `never`.
575
+
576
+ @link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
577
+ @link https://stackoverflow.com/a/53984913/10292952
578
+ @link https://www.zhenghao.io/posts/ts-never
579
+
580
+ Useful in type utilities, such as checking if something does not occur.
581
+
582
+ @example
583
+ ```
584
+ import type {IsNever, And} from 'type-fest';
585
+
586
+ // https://github.com/andnp/SimplyTyped/blob/master/src/types/strings.ts
587
+ type AreStringsEqual<A extends string, B extends string> =
588
+ And<
589
+ IsNever<Exclude<A, B>> extends true ? true : false,
590
+ IsNever<Exclude<B, A>> extends true ? true : false
591
+ >;
592
+
593
+ type EndIfEqual<I extends string, O extends string> =
594
+ AreStringsEqual<I, O> extends true
595
+ ? never
596
+ : void;
597
+
598
+ function endIfEqual<I extends string, O extends string>(input: I, output: O): EndIfEqual<I, O> {
599
+ if (input === output) {
600
+ process.exit(0);
601
+ }
602
+ }
603
+
604
+ endIfEqual('abc', 'abc');
605
+ //=> never
606
+
607
+ endIfEqual('abc', '123');
608
+ //=> void
609
+ ```
610
+
611
+ @category Type Guard
612
+ @category Utilities
613
+ */
614
+ type IsNever<T> = [T] extends [never] ? true : false;
615
+
616
+ /**
617
+ Returns a boolean for whether the given type `T` is the specified `LiteralType`.
618
+
619
+ @link https://stackoverflow.com/a/52806744/10292952
620
+
621
+ @example
622
+ ```
623
+ LiteralCheck<1, number>
624
+ //=> true
625
+
626
+ LiteralCheck<number, number>
627
+ //=> false
628
+
629
+ LiteralCheck<1, string>
630
+ //=> false
631
+ ```
632
+ */
633
+ type LiteralCheck<T, LiteralType extends Primitive> = (
634
+ IsNever<T> extends false // Must be wider than `never`
635
+ ? [T] extends [LiteralType & infer U] // Remove any branding
636
+ ? [U] extends [LiteralType] // Must be narrower than `LiteralType`
637
+ ? [LiteralType] extends [U] // Cannot be wider than `LiteralType`
638
+ ? false
639
+ : true
640
+ : false
641
+ : false
642
+ : false
643
+ );
644
+
645
+ /**
646
+ Returns a boolean for whether the given type `T` is one of the specified literal types in `LiteralUnionType`.
647
+
648
+ @example
649
+ ```
650
+ LiteralChecks<1, Numeric>
651
+ //=> true
652
+
653
+ LiteralChecks<1n, Numeric>
654
+ //=> true
655
+
656
+ LiteralChecks<bigint, Numeric>
657
+ //=> false
658
+ ```
659
+ */
660
+ type LiteralChecks<T, LiteralUnionType> = (
661
+ // Conditional type to force union distribution.
662
+ // If `T` is none of the literal types in the union `LiteralUnionType`, then `LiteralCheck<T, LiteralType>` will evaluate to `false` for the whole union.
663
+ // If `T` is one of the literal types in the union, it will evaluate to `boolean` (i.e. `true | false`)
664
+ IsNotFalse<LiteralUnionType extends Primitive
665
+ ? LiteralCheck<T, LiteralUnionType>
666
+ : never
667
+ >
668
+ );
669
+
670
+ /**
671
+ Returns a boolean for whether the given type is a `number` or `bigint` [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types).
672
+
673
+ Useful for:
674
+ - providing strongly-typed functions when given literal arguments
675
+ - type utilities, such as when constructing parsers and ASTs
676
+
677
+ @example
678
+ ```
679
+ import type {IsNumericLiteral} from 'type-fest';
680
+
681
+ // https://github.com/inocan-group/inferred-types/blob/master/src/types/boolean-logic/EndsWith.ts
682
+ type EndsWith<TValue, TEndsWith extends string> =
683
+ TValue extends string
684
+ ? IsStringLiteral<TEndsWith> extends true
685
+ ? IsStringLiteral<TValue> extends true
686
+ ? TValue extends `${string}${TEndsWith}`
687
+ ? true
688
+ : false
689
+ : boolean
690
+ : boolean
691
+ : TValue extends number
692
+ ? IsNumericLiteral<TValue> extends true
693
+ ? EndsWith<`${TValue}`, TEndsWith>
694
+ : false
695
+ : false;
696
+
697
+ function endsWith<Input extends string | number, End extends string>(input: Input, end: End) {
698
+ return `${input}`.endsWith(end) as EndsWith<Input, End>;
699
+ }
700
+
701
+ endsWith('abc', 'c');
702
+ //=> true
703
+
704
+ endsWith(123456, '456');
705
+ //=> true
706
+
707
+ const end = '123' as string;
708
+
709
+ endsWith('abc123', end);
710
+ //=> boolean
711
+ ```
712
+
713
+ @category Type Guard
714
+ @category Utilities
715
+ */
716
+ type IsNumericLiteral<T> = LiteralChecks<T, Numeric>;
717
+
718
+ /**
719
+ Returns a boolean for whether the given `boolean` is not `false`.
720
+ */
721
+ type IsNotFalse<T extends boolean> = [T] extends [false] ? false : true;
689
722
 
690
723
  /**
691
724
  * This should only be used for defining generics which extend any kind of JS
@@ -776,6 +809,6 @@ declare function delay(ms?: number): Promise<unknown>;
776
809
  declare const compareRelations: <T extends {
777
810
  source: string;
778
811
  target: string;
779
- }>(a: T, b: T) => number;
812
+ }>(a: T, b: T) => 0 | 1 | -1;
780
813
 
781
- export { Color, ComputedEdge, ComputedLikeC4Model, ComputedNode, ComputedView, EdgeId$1 as EdgeId, Element, ElementColors, ElementKind, ElementShape, Fqn$1 as Fqn, HexColorLiteral, LikeC4Model, LikeC4ViewModel, NodeId, NonEmptyArray, Relation, RelationID$1 as RelationID, RelationshipColors, RelationshipKind, Tag, ThemeColorValues, ViewID$1 as ViewID, ancestorsFqn, commonAncestor, compareByFqnHierarchically, compareFqnHierarchically, compareRelations, computeColorValues, defaultTheme, delay, hasAtLeast, invariant, isAncestor, isDescendantOf, isNonEmptyArray, isSameHierarchy, isString, nameFromFqn, nonNullable, nonexhaustive, notDescendantOf, parentFqn, parentFqnPredicate };
814
+ export { Color, ComputedEdge, ComputedLikeC4Model, ComputedNode, ComputedView, EdgeId$1 as EdgeId, Element, ElementColors, ElementKind, ElementShape, Fqn$1 as Fqn, HexColorLiteral, LikeC4Model, LikeC4ViewModel, NodeId, NonEmptyArray, Relation, RelationID$1 as RelationID, RelationshipColors, RelationshipKind, Tag, ThemeColorValues, ViewID$1 as ViewID, ancestorsFqn, commonAncestor, compareByFqnHierarchically, compareFqnHierarchically, compareNatural, compareRelations, computeColorValues, defaultTheme, delay, hasAtLeast, invariant, isAncestor, isDescendantOf, isNonEmptyArray, isSameHierarchy, isString, nameFromFqn, nonNullable, nonexhaustive, notDescendantOf, parentFqn, parentFqnPredicate, sortByFqnHierarchically, sortNaturalByFqn };