@likec4/core 1.0.0-next.2 → 1.0.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.
- package/dist/{cjs/errors → errors}/index.d.ts +1 -2
- package/dist/errors/index.js +0 -11
- package/dist/types/{types/expression.d.ts → expression.d.ts} +7 -2
- package/dist/types/expression.js +8 -1
- package/dist/types/index.d.ts +11 -7
- package/dist/{cjs/utils → utils}/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/promises.d.ts +1 -0
- package/dist/utils/promises.js +8 -0
- package/package.json +24 -39
- package/dist/cjs/colors/element.js +0 -82
- package/dist/cjs/colors/index.js +0 -27
- package/dist/cjs/colors/relationships.js +0 -76
- package/dist/cjs/errors/index.js +0 -118
- package/dist/cjs/index.js +0 -49
- package/dist/cjs/log.d.ts +0 -3
- package/dist/cjs/log.js +0 -10
- package/dist/cjs/reset.d.ts +0 -2
- package/dist/cjs/types/_common.js +0 -1
- package/dist/cjs/types/computed-view.js +0 -1
- package/dist/cjs/types/diagram.js +0 -1
- package/dist/cjs/types/element.js +0 -16
- package/dist/cjs/types/expression.d.ts +0 -71
- package/dist/cjs/types/expression.js +0 -49
- package/dist/cjs/types/index.d.ts +0 -11
- package/dist/cjs/types/index.js +0 -132
- package/dist/cjs/types/model.js +0 -1
- package/dist/cjs/types/opaque.js +0 -1
- package/dist/cjs/types/relation.js +0 -12
- package/dist/cjs/types/theme.js +0 -1
- package/dist/cjs/types/view.js +0 -25
- package/dist/cjs/utils/fqn.js +0 -101
- package/dist/cjs/utils/guards.js +0 -20
- package/dist/cjs/utils/index.js +0 -38
- package/dist/cjs/utils/relations.js +0 -77
- package/dist/esm/colors/element.d.ts +0 -68
- package/dist/esm/colors/element.js +0 -75
- package/dist/esm/colors/index.d.ts +0 -132
- package/dist/esm/colors/index.js +0 -9
- package/dist/esm/colors/relationships.d.ts +0 -57
- package/dist/esm/colors/relationships.js +0 -64
- package/dist/esm/errors/index.d.ts +0 -39
- package/dist/esm/errors/index.js +0 -82
- package/dist/esm/index.d.ts +0 -6
- package/dist/esm/index.js +0 -4
- package/dist/esm/log.d.ts +0 -3
- package/dist/esm/log.js +0 -5
- package/dist/esm/reset.d.ts +0 -2
- package/dist/esm/types/_common.d.ts +0 -3
- package/dist/esm/types/_common.js +0 -0
- package/dist/esm/types/computed-view.d.ts +0 -45
- package/dist/esm/types/computed-view.js +0 -0
- package/dist/esm/types/diagram.d.ts +0 -40
- package/dist/esm/types/diagram.js +0 -0
- package/dist/esm/types/element.d.ts +0 -30
- package/dist/esm/types/element.js +0 -14
- package/dist/esm/types/expression.d.ts +0 -71
- package/dist/esm/types/expression.js +0 -33
- package/dist/esm/types/index.d.ts +0 -11
- package/dist/esm/types/index.js +0 -11
- package/dist/esm/types/model.d.ts +0 -14
- package/dist/esm/types/model.js +0 -0
- package/dist/esm/types/opaque.d.ts +0 -102
- package/dist/esm/types/opaque.js +0 -0
- package/dist/esm/types/relation.d.ts +0 -24
- package/dist/esm/types/relation.js +0 -3
- package/dist/esm/types/theme.d.ts +0 -26
- package/dist/esm/types/theme.js +0 -0
- package/dist/esm/types/view.d.ts +0 -62
- package/dist/esm/types/view.js +0 -15
- package/dist/esm/utils/fqn.d.ts +0 -33
- package/dist/esm/utils/fqn.js +0 -83
- package/dist/esm/utils/guards.d.ts +0 -4
- package/dist/esm/utils/guards.js +0 -7
- package/dist/esm/utils/index.d.ts +0 -3
- package/dist/esm/utils/index.js +0 -3
- package/dist/esm/utils/relations.d.ts +0 -29
- package/dist/esm/utils/relations.js +0 -69
- package/dist/types/colors/element.d.ts +0 -69
- package/dist/types/colors/index.d.ts +0 -133
- package/dist/types/colors/relationships.d.ts +0 -58
- package/dist/types/errors/index.d.ts +0 -40
- package/dist/types/log.d.ts +0 -4
- package/dist/types/types/_common.d.ts +0 -4
- package/dist/types/types/computed-view.d.ts +0 -46
- package/dist/types/types/diagram.d.ts +0 -41
- package/dist/types/types/element.d.ts +0 -31
- package/dist/types/types/index.d.ts +0 -12
- package/dist/types/types/model.d.ts +0 -15
- package/dist/types/types/opaque.d.ts +0 -103
- package/dist/types/types/relation.d.ts +0 -25
- package/dist/types/types/theme.d.ts +0 -27
- package/dist/types/types/view.d.ts +0 -63
- package/dist/types/utils/fqn.d.ts +0 -34
- package/dist/types/utils/guards.d.ts +0 -5
- package/dist/types/utils/index.d.ts +0 -4
- package/dist/types/utils/relations.d.ts +0 -30
- /package/dist/{cjs/colors → colors}/element.d.ts +0 -0
- /package/dist/{cjs/colors → colors}/index.d.ts +0 -0
- /package/dist/{cjs/colors → colors}/relationships.d.ts +0 -0
- /package/dist/{cjs/index.d.ts → index.d.ts} +0 -0
- /package/dist/{cjs/types → types}/_common.d.ts +0 -0
- /package/dist/{cjs/types → types}/computed-view.d.ts +0 -0
- /package/dist/{cjs/types → types}/diagram.d.ts +0 -0
- /package/dist/{cjs/types → types}/element.d.ts +0 -0
- /package/dist/{cjs/types → types}/model.d.ts +0 -0
- /package/dist/{cjs/types → types}/opaque.d.ts +0 -0
- /package/dist/{cjs/types → types}/relation.d.ts +0 -0
- /package/dist/{cjs/types → types}/theme.d.ts +0 -0
- /package/dist/{cjs/types → types}/view.d.ts +0 -0
- /package/dist/{cjs/utils → utils}/fqn.d.ts +0 -0
- /package/dist/{cjs/utils → utils}/guards.d.ts +0 -0
- /package/dist/{cjs/utils → utils}/relations.d.ts +0 -0
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import type { ElementKind, ElementShape, Fqn, Tag } from './element';
|
|
2
|
-
import type { ThemeColor } from './theme';
|
|
3
|
-
import type { ViewID } from './view';
|
|
4
|
-
interface BaseExpr {
|
|
5
|
-
element?: never;
|
|
6
|
-
custom?: never;
|
|
7
|
-
elementKind?: never;
|
|
8
|
-
elementTag?: never;
|
|
9
|
-
isEqual?: never;
|
|
10
|
-
isDescedants?: never;
|
|
11
|
-
wildcard?: never;
|
|
12
|
-
source?: never;
|
|
13
|
-
target?: never;
|
|
14
|
-
inout?: never;
|
|
15
|
-
incoming?: never;
|
|
16
|
-
outgoing?: never;
|
|
17
|
-
}
|
|
18
|
-
export interface ElementRefExpr extends Omit<BaseExpr, 'element' | 'isDescedants'> {
|
|
19
|
-
element: Fqn;
|
|
20
|
-
isDescedants?: boolean;
|
|
21
|
-
}
|
|
22
|
-
export declare function isElementRef(expr: Expression): expr is ElementRefExpr;
|
|
23
|
-
export interface CustomElementExpr extends Omit<BaseExpr, 'custom'> {
|
|
24
|
-
custom: {
|
|
25
|
-
element: Fqn;
|
|
26
|
-
title?: string;
|
|
27
|
-
description?: string;
|
|
28
|
-
technology?: string;
|
|
29
|
-
shape?: ElementShape;
|
|
30
|
-
color?: ThemeColor;
|
|
31
|
-
navigateTo?: ViewID;
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
export declare function isCustomElement(expr: Expression): expr is CustomElementExpr;
|
|
35
|
-
export interface WildcardExpr extends Omit<BaseExpr, 'wildcard'> {
|
|
36
|
-
wildcard: true;
|
|
37
|
-
}
|
|
38
|
-
export declare function isWildcard(expr: Expression): expr is WildcardExpr;
|
|
39
|
-
export interface ElementKindExpr extends Omit<BaseExpr, 'elementKind' | 'isEqual'> {
|
|
40
|
-
elementKind: ElementKind;
|
|
41
|
-
isEqual: boolean;
|
|
42
|
-
}
|
|
43
|
-
export declare function isElementKindExpr(expr: Expression): expr is ElementKindExpr;
|
|
44
|
-
export interface ElementTagExpr extends Omit<BaseExpr, 'elementTag' | 'isEqual'> {
|
|
45
|
-
elementTag: Tag;
|
|
46
|
-
isEqual: boolean;
|
|
47
|
-
}
|
|
48
|
-
export declare function isElementTagExpr(expr: Expression): expr is ElementTagExpr;
|
|
49
|
-
export type ElementExpression = ElementRefExpr | WildcardExpr | ElementKindExpr | ElementTagExpr;
|
|
50
|
-
export declare function isElement(expr: Expression): expr is ElementExpression;
|
|
51
|
-
export interface RelationExpr extends Omit<BaseExpr, 'source' | 'target'> {
|
|
52
|
-
source: ElementExpression;
|
|
53
|
-
target: ElementExpression;
|
|
54
|
-
}
|
|
55
|
-
export declare function isRelation(expr: Expression): expr is RelationExpr;
|
|
56
|
-
export interface InOutExpr extends Omit<BaseExpr, 'inout'> {
|
|
57
|
-
inout: ElementExpression;
|
|
58
|
-
}
|
|
59
|
-
export declare function isInOut(expr: Expression): expr is InOutExpr;
|
|
60
|
-
export interface IncomingExpr extends Omit<BaseExpr, 'incoming'> {
|
|
61
|
-
incoming: ElementExpression;
|
|
62
|
-
}
|
|
63
|
-
export declare function isIncoming(expr: Expression): expr is IncomingExpr;
|
|
64
|
-
export interface OutgoingExpr extends Omit<BaseExpr, 'outgoing'> {
|
|
65
|
-
outgoing: ElementExpression;
|
|
66
|
-
}
|
|
67
|
-
export declare function isOutgoing(expr: Expression): expr is OutgoingExpr;
|
|
68
|
-
export type AnyRelationExpression = RelationExpr | InOutExpr | IncomingExpr | OutgoingExpr;
|
|
69
|
-
export declare function isAnyRelation(expr: Expression): expr is AnyRelationExpression;
|
|
70
|
-
export type Expression = ElementExpression | CustomElementExpr | AnyRelationExpression;
|
|
71
|
-
export {};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
export function isElementRef(expr) {
|
|
2
|
-
return "element" in expr;
|
|
3
|
-
}
|
|
4
|
-
export function isCustomElement(expr) {
|
|
5
|
-
return "custom" in expr;
|
|
6
|
-
}
|
|
7
|
-
export function isWildcard(expr) {
|
|
8
|
-
return "wildcard" in expr;
|
|
9
|
-
}
|
|
10
|
-
export function isElementKindExpr(expr) {
|
|
11
|
-
return "elementKind" in expr && "isEqual" in expr;
|
|
12
|
-
}
|
|
13
|
-
export function isElementTagExpr(expr) {
|
|
14
|
-
return "elementTag" in expr && "isEqual" in expr;
|
|
15
|
-
}
|
|
16
|
-
export function isElement(expr) {
|
|
17
|
-
return isElementRef(expr) || isWildcard(expr) || isElementKindExpr(expr) || isElementTagExpr(expr);
|
|
18
|
-
}
|
|
19
|
-
export function isRelation(expr) {
|
|
20
|
-
return "source" in expr && "target" in expr;
|
|
21
|
-
}
|
|
22
|
-
export function isInOut(expr) {
|
|
23
|
-
return "inout" in expr;
|
|
24
|
-
}
|
|
25
|
-
export function isIncoming(expr) {
|
|
26
|
-
return "incoming" in expr;
|
|
27
|
-
}
|
|
28
|
-
export function isOutgoing(expr) {
|
|
29
|
-
return "outgoing" in expr;
|
|
30
|
-
}
|
|
31
|
-
export function isAnyRelation(expr) {
|
|
32
|
-
return isRelation(expr) || isInOut(expr) || isIncoming(expr) || isOutgoing(expr);
|
|
33
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export * from './_common';
|
|
2
|
-
export * from './computed-view';
|
|
3
|
-
export * from './diagram';
|
|
4
|
-
export * from './element';
|
|
5
|
-
export * from './expression';
|
|
6
|
-
export * from './model';
|
|
7
|
-
export * from './opaque';
|
|
8
|
-
export * from './relation';
|
|
9
|
-
export * from './theme';
|
|
10
|
-
export * from './view';
|
|
11
|
-
export * as Expr from './expression';
|
package/dist/esm/types/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export * from "./_common.js";
|
|
2
|
-
export * from "./computed-view.js";
|
|
3
|
-
export * from "./diagram.js";
|
|
4
|
-
export * from "./element.js";
|
|
5
|
-
export * from "./expression.js";
|
|
6
|
-
export * from "./model.js";
|
|
7
|
-
export * from "./opaque.js";
|
|
8
|
-
export * from "./relation.js";
|
|
9
|
-
export * from "./theme.js";
|
|
10
|
-
export * from "./view.js";
|
|
11
|
-
export * as Expr from "./expression.js";
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { ComputedView } from './computed-view';
|
|
2
|
-
import type { Element, Fqn } from './element';
|
|
3
|
-
import type { Relation, RelationID } from './relation';
|
|
4
|
-
import type { ElementView, ViewID } from './view';
|
|
5
|
-
export interface LikeC4Model {
|
|
6
|
-
elements: Record<Fqn, Element>;
|
|
7
|
-
relations: Record<RelationID, Relation>;
|
|
8
|
-
views: Record<ViewID, ElementView>;
|
|
9
|
-
}
|
|
10
|
-
export interface LikeC4ComputedModel {
|
|
11
|
-
elements: Record<Fqn, Element>;
|
|
12
|
-
relations: Record<RelationID, Relation>;
|
|
13
|
-
views: Record<ViewID, ComputedView>;
|
|
14
|
-
}
|
package/dist/esm/types/model.js
DELETED
|
File without changes
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
declare const tag: unique symbol;
|
|
2
|
-
type Tagged<Token> = {
|
|
3
|
-
readonly [tag]: Token;
|
|
4
|
-
};
|
|
5
|
-
/**
|
|
6
|
-
Create an opaque type, which hides its internal details from the public, and can only be created by being used explicitly.
|
|
7
|
-
|
|
8
|
-
The generic type parameter can be anything. It doesn't have to be an object.
|
|
9
|
-
|
|
10
|
-
[Read more about opaque types.](https://codemix.com/opaque-types-in-javascript/)
|
|
11
|
-
|
|
12
|
-
There have been several discussions about adding this feature to TypeScript via the `opaque type` operator, similar to how Flow does it. Unfortunately, nothing has (yet) moved forward:
|
|
13
|
-
- [Microsoft/TypeScript#202](https://github.com/microsoft/TypeScript/issues/202)
|
|
14
|
-
- [Microsoft/TypeScript#15408](https://github.com/Microsoft/TypeScript/issues/15408)
|
|
15
|
-
- [Microsoft/TypeScript#15807](https://github.com/Microsoft/TypeScript/issues/15807)
|
|
16
|
-
|
|
17
|
-
@example
|
|
18
|
-
```
|
|
19
|
-
import type {Opaque} from 'type-fest';
|
|
20
|
-
|
|
21
|
-
type AccountNumber = Opaque<number, 'AccountNumber'>;
|
|
22
|
-
type AccountBalance = Opaque<number, 'AccountBalance'>;
|
|
23
|
-
|
|
24
|
-
// The `Token` parameter allows the compiler to differentiate between types, whereas "unknown" will not. For example, consider the following structures:
|
|
25
|
-
type ThingOne = Opaque<string>;
|
|
26
|
-
type ThingTwo = Opaque<string>;
|
|
27
|
-
|
|
28
|
-
// To the compiler, these types are allowed to be cast to each other as they have the same underlying type. They are both `string & { __opaque__: unknown }`.
|
|
29
|
-
// To avoid this behaviour, you would instead pass the "Token" parameter, like so.
|
|
30
|
-
type NewThingOne = Opaque<string, 'ThingOne'>;
|
|
31
|
-
type NewThingTwo = Opaque<string, 'ThingTwo'>;
|
|
32
|
-
|
|
33
|
-
// Now they're completely separate types, so the following will fail to compile.
|
|
34
|
-
function createNewThingOne (): NewThingOne {
|
|
35
|
-
// As you can see, casting from a string is still allowed. However, you may not cast NewThingOne to NewThingTwo, and vice versa.
|
|
36
|
-
return 'new thing one' as NewThingOne;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// This will fail to compile, as they are fundamentally different types.
|
|
40
|
-
const thingTwo = createNewThingOne() as NewThingTwo;
|
|
41
|
-
|
|
42
|
-
// Here's another example of opaque typing.
|
|
43
|
-
function createAccountNumber(): AccountNumber {
|
|
44
|
-
return 2 as AccountNumber;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function getMoneyForAccount(accountNumber: AccountNumber): AccountBalance {
|
|
48
|
-
return 4 as AccountBalance;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// This will compile successfully.
|
|
52
|
-
getMoneyForAccount(createAccountNumber());
|
|
53
|
-
|
|
54
|
-
// But this won't, because it has to be explicitly passed as an `AccountNumber` type.
|
|
55
|
-
getMoneyForAccount(2);
|
|
56
|
-
|
|
57
|
-
// You can use opaque values like they aren't opaque too.
|
|
58
|
-
const accountNumber = createAccountNumber();
|
|
59
|
-
|
|
60
|
-
// This will not compile successfully.
|
|
61
|
-
const newAccountNumber = accountNumber + 2;
|
|
62
|
-
|
|
63
|
-
// As a side note, you can (and should) use recursive types for your opaque types to make them stronger and hopefully easier to type.
|
|
64
|
-
type Person = {
|
|
65
|
-
id: Opaque<number, Person>;
|
|
66
|
-
name: string;
|
|
67
|
-
};
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
@category Type
|
|
71
|
-
*/
|
|
72
|
-
export type Opaque<Type, Token = unknown> = Type & Tagged<Token>;
|
|
73
|
-
/**
|
|
74
|
-
Revert an opaque type back to its original type by removing the readonly `[tag]`.
|
|
75
|
-
|
|
76
|
-
Why is this necessary?
|
|
77
|
-
|
|
78
|
-
1. Use an `Opaque` type as object keys
|
|
79
|
-
2. Prevent TS4058 error: "Return type of exported function has or is using name X from external module Y but cannot be named"
|
|
80
|
-
|
|
81
|
-
@example
|
|
82
|
-
```
|
|
83
|
-
import type {Opaque, UnwrapOpaque} from 'type-fest';
|
|
84
|
-
|
|
85
|
-
type AccountType = Opaque<'SAVINGS' | 'CHECKING', 'AccountType'>;
|
|
86
|
-
|
|
87
|
-
const moneyByAccountType: Record<UnwrapOpaque<AccountType>, number> = {
|
|
88
|
-
SAVINGS: 99,
|
|
89
|
-
CHECKING: 0.1
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
// Without UnwrapOpaque, the following expression would throw a type error.
|
|
93
|
-
const money = moneyByAccountType.SAVINGS; // TS error: Property 'SAVINGS' does not exist
|
|
94
|
-
|
|
95
|
-
// Attempting to pass an non-Opaque type to UnwrapOpaque will raise a type error.
|
|
96
|
-
type WontWork = UnwrapOpaque<string>;
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
@category Type
|
|
100
|
-
*/
|
|
101
|
-
export type UnwrapOpaque<OpaqueType extends Tagged<unknown>> = OpaqueType extends Opaque<infer Type, OpaqueType[typeof tag]> ? Type : OpaqueType;
|
|
102
|
-
export {};
|
package/dist/esm/types/opaque.js
DELETED
|
File without changes
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { NonEmptyArray } from './_common';
|
|
2
|
-
import type { Fqn, Tag } from './element';
|
|
3
|
-
import type { Opaque } from './opaque';
|
|
4
|
-
import type { ThemeColor } from './theme';
|
|
5
|
-
export type RelationID = Opaque<string, 'RelationID'>;
|
|
6
|
-
export type RelationshipKind = Opaque<string, 'RelationshipKind'>;
|
|
7
|
-
export type RelationshipLineType = 'dashed' | 'solid' | 'dotted';
|
|
8
|
-
export type RelationshipArrowType = 'none' | 'normal' | 'onormal' | 'diamond' | 'odiamond' | 'crow' | 'open' | 'vee';
|
|
9
|
-
export declare const DefaultLineStyle = "dashed";
|
|
10
|
-
export declare const DefaultArrowType = "normal";
|
|
11
|
-
export declare const DefaultRelationshipColor = "gray";
|
|
12
|
-
export interface Relation {
|
|
13
|
-
readonly id: RelationID;
|
|
14
|
-
readonly source: Fqn;
|
|
15
|
-
readonly target: Fqn;
|
|
16
|
-
readonly title: string;
|
|
17
|
-
readonly tags?: NonEmptyArray<Tag>;
|
|
18
|
-
readonly kind?: RelationshipKind;
|
|
19
|
-
readonly color?: ThemeColor;
|
|
20
|
-
readonly line?: RelationshipLineType;
|
|
21
|
-
readonly head?: RelationshipArrowType;
|
|
22
|
-
readonly tail?: RelationshipArrowType;
|
|
23
|
-
readonly links?: NonEmptyArray<string>;
|
|
24
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export type ThemeColor = 'amber' | 'blue' | 'gray' | 'slate' | 'green' | 'indigo' | 'muted' | 'primary' | 'red' | 'secondary' | 'sky';
|
|
2
|
-
export type HexColorLiteral = `#${string}`;
|
|
3
|
-
export type ColorLiteral = HexColorLiteral;
|
|
4
|
-
export interface ElementThemeColorValues {
|
|
5
|
-
fill: ColorLiteral;
|
|
6
|
-
stroke: ColorLiteral;
|
|
7
|
-
hiContrast: ColorLiteral;
|
|
8
|
-
loContrast: ColorLiteral;
|
|
9
|
-
}
|
|
10
|
-
export type ElementThemeColors = {
|
|
11
|
-
[key in ThemeColor]: ElementThemeColorValues;
|
|
12
|
-
};
|
|
13
|
-
export interface RelationshipThemeColorValues {
|
|
14
|
-
lineColor: ColorLiteral;
|
|
15
|
-
labelBgColor: ColorLiteral;
|
|
16
|
-
labelColor: ColorLiteral;
|
|
17
|
-
}
|
|
18
|
-
export type RelationshipThemeColors = {
|
|
19
|
-
[key in ThemeColor]: RelationshipThemeColorValues;
|
|
20
|
-
};
|
|
21
|
-
export interface LikeC4Theme {
|
|
22
|
-
font: 'Helvetica';
|
|
23
|
-
shadow: ColorLiteral;
|
|
24
|
-
relationships: RelationshipThemeColors;
|
|
25
|
-
elements: ElementThemeColors;
|
|
26
|
-
}
|
package/dist/esm/types/theme.js
DELETED
|
File without changes
|
package/dist/esm/types/view.d.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import type { IconUrl, NonEmptyArray } from './_common';
|
|
2
|
-
import type { ElementShape, Fqn, Tag } from './element';
|
|
3
|
-
import type { ElementExpression, Expression } from './expression';
|
|
4
|
-
import type { Opaque } from './opaque';
|
|
5
|
-
import type { ThemeColor } from './theme';
|
|
6
|
-
export type ViewID = Opaque<string, 'ViewID'>;
|
|
7
|
-
export type ViewRuleExpression = {
|
|
8
|
-
include: Expression[];
|
|
9
|
-
exclude?: never;
|
|
10
|
-
} | {
|
|
11
|
-
include?: never;
|
|
12
|
-
exclude: Expression[];
|
|
13
|
-
};
|
|
14
|
-
export declare function isViewRuleExpression(rule: ViewRule): rule is ViewRuleExpression;
|
|
15
|
-
export interface ViewRuleStyle {
|
|
16
|
-
targets: ElementExpression[];
|
|
17
|
-
style: {
|
|
18
|
-
color?: ThemeColor;
|
|
19
|
-
shape?: ElementShape;
|
|
20
|
-
icon?: IconUrl;
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
export declare function isViewRuleStyle(rule: ViewRule): rule is ViewRuleStyle;
|
|
24
|
-
export type AutoLayoutDirection = 'TB' | 'BT' | 'LR' | 'RL';
|
|
25
|
-
export interface ViewRuleAutoLayout {
|
|
26
|
-
autoLayout: AutoLayoutDirection;
|
|
27
|
-
}
|
|
28
|
-
export declare function isViewRuleAutoLayout(rule: ViewRule): rule is ViewRuleAutoLayout;
|
|
29
|
-
export type ViewRule = ViewRuleExpression | ViewRuleStyle | ViewRuleAutoLayout;
|
|
30
|
-
export interface BasicElementView {
|
|
31
|
-
readonly id: ViewID;
|
|
32
|
-
readonly viewOf?: Fqn;
|
|
33
|
-
readonly title: string | null;
|
|
34
|
-
readonly description: string | null;
|
|
35
|
-
readonly tags: NonEmptyArray<Tag> | null;
|
|
36
|
-
readonly links: NonEmptyArray<string> | null;
|
|
37
|
-
readonly rules: ViewRule[];
|
|
38
|
-
/**
|
|
39
|
-
* URI to the source file of this view.
|
|
40
|
-
* Undefined if the view is auto-generated.
|
|
41
|
-
*/
|
|
42
|
-
readonly docUri?: string;
|
|
43
|
-
/**
|
|
44
|
-
* For all views we find common ancestor path.
|
|
45
|
-
* This is used to generate relative paths, i.e.:
|
|
46
|
-
* - "" for views in the common ancestor directory (or root)
|
|
47
|
-
* - "subdir" for views in "<root>/subdir"
|
|
48
|
-
* - "subdir/subdir1" for views in "<root>/subdir/subdir1"
|
|
49
|
-
*
|
|
50
|
-
* Undefined if the view is auto-generated.
|
|
51
|
-
*/
|
|
52
|
-
readonly relativePath?: string;
|
|
53
|
-
}
|
|
54
|
-
export interface StrictElementView extends BasicElementView {
|
|
55
|
-
readonly viewOf: Fqn;
|
|
56
|
-
}
|
|
57
|
-
export declare function isStrictElementView(view: ElementView): view is StrictElementView;
|
|
58
|
-
export interface ExtendsElementView extends BasicElementView {
|
|
59
|
-
readonly extends: ViewID;
|
|
60
|
-
}
|
|
61
|
-
export declare function isExtendsElementView(view: ElementView): view is ExtendsElementView;
|
|
62
|
-
export type ElementView = StrictElementView | ExtendsElementView | BasicElementView;
|
package/dist/esm/types/view.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export function isViewRuleExpression(rule) {
|
|
2
|
-
return "include" in rule && Array.isArray(rule.include) || "exclude" in rule && Array.isArray(rule.exclude);
|
|
3
|
-
}
|
|
4
|
-
export function isViewRuleStyle(rule) {
|
|
5
|
-
return "style" in rule && "targets" in rule;
|
|
6
|
-
}
|
|
7
|
-
export function isViewRuleAutoLayout(rule) {
|
|
8
|
-
return "autoLayout" in rule;
|
|
9
|
-
}
|
|
10
|
-
export function isStrictElementView(view) {
|
|
11
|
-
return "viewOf" in view;
|
|
12
|
-
}
|
|
13
|
-
export function isExtendsElementView(view) {
|
|
14
|
-
return "extends" in view;
|
|
15
|
-
}
|
package/dist/esm/utils/fqn.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { Element, Fqn } from '../types';
|
|
2
|
-
export declare function nameFromFqn(fqn: Fqn): string;
|
|
3
|
-
export declare function isAncestor<E extends {
|
|
4
|
-
id: Fqn;
|
|
5
|
-
}>(...args: [ancestor: string, another: string] | [ancestor: E, another: E]): boolean;
|
|
6
|
-
export declare function isSameHierarchy<E extends {
|
|
7
|
-
id: Fqn;
|
|
8
|
-
}>(one: E | Fqn, another: E | Fqn): boolean;
|
|
9
|
-
export declare function isDescendantOf<E extends {
|
|
10
|
-
id: Fqn;
|
|
11
|
-
}>(ancestors: E[]): (e: E) => boolean;
|
|
12
|
-
export declare function notDescendantOf(ancestors: Element[]): (e: Element) => boolean;
|
|
13
|
-
export declare function commonAncestor(first: Fqn, second: Fqn): Fqn | null;
|
|
14
|
-
export declare function parentFqn(fqn: Fqn): Fqn | null;
|
|
15
|
-
/**
|
|
16
|
-
* Get all ancestor elements (i.e. parent, parent’s parent, etc.)
|
|
17
|
-
* (from closest to root)
|
|
18
|
-
*/
|
|
19
|
-
export declare function ancestorsFqn(fqn: Fqn): Fqn[];
|
|
20
|
-
/**
|
|
21
|
-
* Compares two fully qualified names (fqns) hierarchically based on their depth.
|
|
22
|
-
* From parent nodes to leaves
|
|
23
|
-
*
|
|
24
|
-
* @param {string} a - The first fqn to compare.
|
|
25
|
-
* @param {string} b - The second fqn to compare.
|
|
26
|
-
* @returns {number} - 0 if the fqns have the same depth.
|
|
27
|
-
* - Positive number if a is deeper than b.
|
|
28
|
-
* - Negative number if b is deeper than a.
|
|
29
|
-
*/
|
|
30
|
-
export declare function compareFqnHierarchically<T extends string = string>(a: T, b: T): number;
|
|
31
|
-
export declare function compareByFqnHierarchically<T extends {
|
|
32
|
-
id: string;
|
|
33
|
-
}>(a: T, b: T): number;
|
package/dist/esm/utils/fqn.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { isString } from "./guards.js";
|
|
2
|
-
export function nameFromFqn(fqn) {
|
|
3
|
-
const lastDot = fqn.lastIndexOf(".");
|
|
4
|
-
if (lastDot > 0) {
|
|
5
|
-
return fqn.slice(lastDot + 1);
|
|
6
|
-
} else {
|
|
7
|
-
return fqn;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
export function isAncestor(...args) {
|
|
11
|
-
const ancestor = isString(args[0]) ? args[0] : args[0].id;
|
|
12
|
-
const another = isString(args[1]) ? args[1] : args[1].id;
|
|
13
|
-
return another.startsWith(ancestor + ".");
|
|
14
|
-
}
|
|
15
|
-
export function isSameHierarchy(one, another) {
|
|
16
|
-
const first = isString(one) ? one : one.id;
|
|
17
|
-
const second = isString(another) ? another : another.id;
|
|
18
|
-
return first === second || second.startsWith(first + ".") || first.startsWith(second + ".");
|
|
19
|
-
}
|
|
20
|
-
export function isDescendantOf(ancestors) {
|
|
21
|
-
const predicates = ancestors.flatMap((a) => [(e) => e.id === a.id, (e) => isAncestor(a, e)]);
|
|
22
|
-
return (e) => predicates.some((p) => p(e));
|
|
23
|
-
}
|
|
24
|
-
export function notDescendantOf(ancestors) {
|
|
25
|
-
const isDescendant = isDescendantOf(ancestors);
|
|
26
|
-
return (e) => !isDescendant(e);
|
|
27
|
-
}
|
|
28
|
-
export function commonAncestor(first, second) {
|
|
29
|
-
const parentA = parentFqn(first);
|
|
30
|
-
const parentB = parentFqn(second);
|
|
31
|
-
if (parentA === parentB) {
|
|
32
|
-
return parentA;
|
|
33
|
-
}
|
|
34
|
-
if (!parentA || !parentB) {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
const a = first.split(".");
|
|
38
|
-
const b = second.split(".");
|
|
39
|
-
let ancestor = null;
|
|
40
|
-
while (a.length > 1 && b.length > 1 && !!a[0] && a[0] === b[0]) {
|
|
41
|
-
ancestor = ancestor ? `${ancestor}.${a[0]}` : a[0];
|
|
42
|
-
a.shift();
|
|
43
|
-
b.shift();
|
|
44
|
-
}
|
|
45
|
-
return ancestor;
|
|
46
|
-
}
|
|
47
|
-
export function parentFqn(fqn) {
|
|
48
|
-
const lastDot = fqn.lastIndexOf(".");
|
|
49
|
-
if (lastDot > 0) {
|
|
50
|
-
return fqn.substring(0, lastDot);
|
|
51
|
-
}
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
export function ancestorsFqn(fqn) {
|
|
55
|
-
const path = fqn.split(".");
|
|
56
|
-
path.pop();
|
|
57
|
-
if (path.length === 0) {
|
|
58
|
-
return [];
|
|
59
|
-
}
|
|
60
|
-
return path.reduce((acc, _, idx) => {
|
|
61
|
-
const ancestor = path.slice(0, idx + 1).join(".");
|
|
62
|
-
acc.unshift(ancestor);
|
|
63
|
-
return acc;
|
|
64
|
-
}, []);
|
|
65
|
-
}
|
|
66
|
-
export function compareFqnHierarchically(a, b) {
|
|
67
|
-
const depthA = a.split(".").length;
|
|
68
|
-
const depthB = b.split(".").length;
|
|
69
|
-
switch (true) {
|
|
70
|
-
case depthA > depthB: {
|
|
71
|
-
return 1;
|
|
72
|
-
}
|
|
73
|
-
case depthA < depthB: {
|
|
74
|
-
return -1;
|
|
75
|
-
}
|
|
76
|
-
default: {
|
|
77
|
-
return 0;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
export function compareByFqnHierarchically(a, b) {
|
|
82
|
-
return compareFqnHierarchically(a.id, b.id);
|
|
83
|
-
}
|
package/dist/esm/utils/guards.js
DELETED
package/dist/esm/utils/index.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { Fqn } from '../types';
|
|
2
|
-
type Relation = {
|
|
3
|
-
source: string;
|
|
4
|
-
target: string;
|
|
5
|
-
};
|
|
6
|
-
type RelationPredicate = (rel: Relation) => boolean;
|
|
7
|
-
/**
|
|
8
|
-
* Compares two relations hierarchically.
|
|
9
|
-
* From the most general (implicit) to the most specific.
|
|
10
|
-
*/
|
|
11
|
-
export declare const compareRelations: <T extends {
|
|
12
|
-
source: string;
|
|
13
|
-
target: string;
|
|
14
|
-
}>(a: T, b: T) => number;
|
|
15
|
-
export declare const Relations: {
|
|
16
|
-
readonly isInside: (parent: Fqn) => RelationPredicate;
|
|
17
|
-
readonly isBetween: (source: Fqn, target: Fqn) => RelationPredicate;
|
|
18
|
-
readonly isAnyBetween: (source: Fqn, target: Fqn) => RelationPredicate;
|
|
19
|
-
readonly isIncoming: (target: Fqn) => RelationPredicate;
|
|
20
|
-
readonly isOutgoing: (source: Fqn) => RelationPredicate;
|
|
21
|
-
readonly isAnyInOut: (source: Fqn) => RelationPredicate;
|
|
22
|
-
readonly hasRelation: <R extends {
|
|
23
|
-
source: Fqn;
|
|
24
|
-
target: Fqn;
|
|
25
|
-
}>(rel: R) => <E extends {
|
|
26
|
-
id: Fqn;
|
|
27
|
-
}>(element: E) => boolean;
|
|
28
|
-
};
|
|
29
|
-
export {};
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { commonAncestor, compareFqnHierarchically, isAncestor } from "./fqn.js";
|
|
2
|
-
export const compareRelations = (a, b) => {
|
|
3
|
-
const parentA = commonAncestor(a.source, a.target);
|
|
4
|
-
const parentB = commonAncestor(b.source, b.target);
|
|
5
|
-
if (parentA && !parentB) {
|
|
6
|
-
return 1;
|
|
7
|
-
}
|
|
8
|
-
if (!parentA && parentB) {
|
|
9
|
-
return -1;
|
|
10
|
-
}
|
|
11
|
-
const compareParents = parentA && parentB ? compareFqnHierarchically(parentA, parentB) : 0;
|
|
12
|
-
if (compareParents === 0) {
|
|
13
|
-
const compareSource = compareFqnHierarchically(a.source, b.source);
|
|
14
|
-
if (compareSource !== 0) {
|
|
15
|
-
return compareSource;
|
|
16
|
-
}
|
|
17
|
-
return compareFqnHierarchically(a.target, b.target);
|
|
18
|
-
}
|
|
19
|
-
return compareParents;
|
|
20
|
-
};
|
|
21
|
-
const isInside = (parent) => {
|
|
22
|
-
const prefix = parent + ".";
|
|
23
|
-
return (rel) => {
|
|
24
|
-
return rel.source.startsWith(prefix) && rel.target.startsWith(prefix);
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
const isBetween = (source, target) => {
|
|
28
|
-
const sourcePrefix = source + ".";
|
|
29
|
-
const targetPrefix = target + ".";
|
|
30
|
-
return (rel) => {
|
|
31
|
-
return (rel.source === source || (rel.source + ".").startsWith(sourcePrefix)) && (rel.target === target || (rel.target + ".").startsWith(targetPrefix));
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
const isAnyBetween = (source, target) => {
|
|
35
|
-
const predicates = [isBetween(source, target), isBetween(target, source)];
|
|
36
|
-
return (rel) => predicates.some((p) => p(rel));
|
|
37
|
-
};
|
|
38
|
-
const isIncoming = (target) => {
|
|
39
|
-
const targetPrefix = target + ".";
|
|
40
|
-
return (rel) => {
|
|
41
|
-
return !(rel.source + ".").startsWith(targetPrefix) && (rel.target === target || (rel.target + ".").startsWith(targetPrefix));
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
const isOutgoing = (source) => {
|
|
45
|
-
const sourcePrefix = source + ".";
|
|
46
|
-
return (rel) => {
|
|
47
|
-
return (rel.source === source || (rel.source + ".").startsWith(sourcePrefix)) && !(rel.target + ".").startsWith(sourcePrefix);
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
const isAnyInOut = (source) => {
|
|
51
|
-
const predicates = [isIncoming(source), isOutgoing(source)];
|
|
52
|
-
return (rel) => {
|
|
53
|
-
return predicates.some((p) => p(rel));
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
const hasRelation = (rel) => {
|
|
57
|
-
return (element) => {
|
|
58
|
-
return rel.source === element.id || rel.target === element.id || isAncestor(element.id, rel.source) || isAncestor(element.id, rel.target);
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
export const Relations = {
|
|
62
|
-
isInside,
|
|
63
|
-
isBetween,
|
|
64
|
-
isAnyBetween,
|
|
65
|
-
isIncoming,
|
|
66
|
-
isOutgoing,
|
|
67
|
-
isAnyInOut,
|
|
68
|
-
hasRelation
|
|
69
|
-
};
|