New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@likec4/core

Package Overview
Dependencies
Maintainers
0
Versions
128
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@likec4/core - npm Package Compare versions

Comparing version 1.12.2 to 1.13.0

dist/shared/core.BJDxVHFh.mjs

2

dist/types/index.d.ts

@@ -1,2 +0,2 @@

export { at as AndOperator, A as AsFqn, aS as AutoLayoutDirection, bq as BBox, aY as BasicElementView, aX as BasicView, q as BorderStyle, B as BorderStyles, e as Color, aH as ColorLiteral, bn as ComputedDynamicView, f as ComputedEdge, bm as ComputedElementView, g as ComputedLikeC4Model, b as ComputedNode, C as ComputedView, p as CustomColor, b8 as CustomColorDefinitions, M as CustomElementExpr, ag as CustomRelationExpr, aD as DefaultArrowType, t as DefaultElementShape, aC as DefaultLineStyle, aE as DefaultRelationshipColor, s as DefaultThemeColor, l as DiagramEdge, k as DiagramNode, D as DiagramView, b6 as DynamicView, b3 as DynamicViewIncludeRule, b1 as DynamicViewParallelSteps, b5 as DynamicViewRule, b0 as DynamicViewStep, b2 as DynamicViewStepOrParallel, E as EdgeId, h as Element, _ as ElementExpression, c as ElementKind, S as ElementKindExpr, y as ElementKindSpecification, x as ElementKindSpecificationStyle, bu as ElementNotation, a2 as ElementPredicateExpression, z as ElementRefExpr, d as ElementShape, r as ElementShapes, u as ElementStyle, Y as ElementTagExpr, aJ as ElementThemeColorValues, aK as ElementThemeColors, a$ as ElementView, a0 as ElementWhereExpr, am as EqualOperator, J as ExpandedElementExpr, ak as Expression, a_ as ExtendsElementView, F as Fqn, H as HexColorLiteral, I as IconUrl, a6 as InOutExpr, a8 as IncomingExpr, ap as KindEqual, L as LayoutedLikeC4Model, aN as LikeC4Theme, b9 as LikeC4View, w as Link, N as NodeId, m as NonEmptyArray, o as NonEmptyReadonlyArray, ar as NotOperator, av as OrOperator, aa as OutgoingExpr, az as OverviewGraph, al as ParsedLikeC4Model, P as Point, i as Relation, a4 as RelationExpr, ac as RelationExpression, R as RelationID, ai as RelationPredicateExpression, ae as RelationWhereExpr, aB as RelationshipArrowType, j as RelationshipKind, aF as RelationshipKindSpecification, aA as RelationshipLineType, aL as RelationshipThemeColorValues, aM as RelationshipThemeColors, aZ as ScopedElementView, bf as StepEdgeId, be as StepEdgeIdLiteral, a as Tag, an as TagEqual, v as TagSpec, aG as ThemeColor, T as ThemeColorValues, bl as ViewAutoLayout, bt as ViewChange, V as ViewID, bs as ViewManualLayout, aW as ViewRule, aU as ViewRuleAutoLayout, aO as ViewRulePredicate, aQ as ViewRuleStyle, bj as ViewWithHash, bk as ViewWithNotation, ax as WhereOperator, W as WildcardExpr, X as XYPoint, bh as extractStep, br as getBBoxCenter, bi as getParallelStepsPrefix, au as isAndOperator, aT as isAutoLayoutDirection, bo as isComputedDynamicView, bp as isComputedElementView, O as isCustomElement, ah as isCustomRelationExpr, ba as isDynamicView, b4 as isDynamicViewIncludeRule, b7 as isDynamicViewParallelSteps, $ as isElement, U as isElementKindExpr, a3 as isElementPredicateExpr, G as isElementRef, Z as isElementTagExpr, bb as isElementView, a1 as isElementWhere, K as isExpandedElementExpr, bc as isExtendsElementView, a7 as isInOut, a9 as isIncoming, aq as isKindEqual, as as isNotOperator, aw as isOrOperator, ab as isOutgoing, a5 as isRelation, ad as isRelationExpression, aj as isRelationPredicateExpr, af as isRelationWhere, bd as isScopedElementView, bg as isStepEdgeId, ao as isTagEqual, aI as isThemeColor, aV as isViewRuleAutoLayout, aP as isViewRulePredicate, aR as isViewRuleStyle, Q as isWildcard, ay as whereOperatorAsPredicate } from '../shared/core.dY8efyk0.js';
export { aA as AndOperator, G as AsFqn, A as AutoLayoutDirection, br as BBox, a_ as BasicElementView, aZ as BasicView, B as BorderStyle, J as BorderStyles, C as Color, aL as ColorLiteral, bo as ComputedDynamicView, q as ComputedEdge, bn as ComputedElementView, r as ComputedLikeC4Model, n as ComputedNode, l as ComputedView, y as CustomColor, ba as CustomColorDefinitions, g as CustomElementExpr, h as CustomRelationExpr, aI as DefaultArrowType, O as DefaultElementShape, aH as DefaultLineStyle, aJ as DefaultRelationshipColor, M as DefaultThemeColor, v as DiagramEdge, u as DiagramNode, D as DiagramView, b8 as DynamicView, b5 as DynamicViewIncludeRule, b3 as DynamicViewParallelSteps, b7 as DynamicViewRule, b2 as DynamicViewStep, b4 as DynamicViewStepOrParallel, k as EdgeId, d as Element, a8 as ElementExpression, p as ElementKind, a4 as ElementKindExpr, E as ElementKindSpecification, Y as ElementKindSpecificationStyle, bv as ElementNotation, ac as ElementPredicateExpression, Z as ElementRefExpr, a as ElementShape, K as ElementShapes, Q as ElementStyle, a6 as ElementTagExpr, aN as ElementThemeColorValues, aO as ElementThemeColors, b1 as ElementView, aa as ElementWhereExpr, at as EqualOperator, $ as ExpandedElementExpr, f as Expression, b0 as ExtendsElementView, F as Fqn, H as HexColorLiteral, I as IconUrl, ag as InOutExpr, ai as IncomingExpr, aw as KindEqual, s as LayoutedLikeC4Model, aR as LikeC4Theme, L as LikeC4View, U as Link, o as NodeId, N as NonEmptyArray, x as NonEmptyReadonlyArray, ay as NotOperator, aC as OrOperator, ak as OutgoingExpr, aG as OverviewGraph, P as ParsedLikeC4Model, z as Point, e as Relation, ae as RelationExpr, am as RelationExpression, i as RelationID, ar as RelationPredicateExpression, ao as RelationWhereExpr, b as RelationshipArrowType, t as RelationshipKind, R as RelationshipKindSpecification, c as RelationshipLineType, aP as RelationshipThemeColorValues, aQ as RelationshipThemeColors, a$ as ScopedElementView, bg as StepEdgeId, bf as StepEdgeIdLiteral, m as Tag, au as TagEqual, S as TagSpec, aK as ThemeColor, T as ThemeColorValues, W as TypedElement, bm as ViewAutoLayout, bu as ViewChange, j as ViewID, bt as ViewManualLayout, aY as ViewRule, aW as ViewRuleAutoLayout, aS as ViewRulePredicate, V as ViewRuleStyle, bk as ViewWithHash, bl as ViewWithNotation, aE as WhereOperator, a2 as WildcardExpr, X as XYPoint, bi as extractStep, bs as getBBoxCenter, bj as getParallelStepsPrefix, aB as isAndOperator, aV as isAutoLayoutDirection, bp as isComputedDynamicView, bq as isComputedElementView, a1 as isCustomElement, aq as isCustomRelationExpr, bb as isDynamicView, b6 as isDynamicViewIncludeRule, b9 as isDynamicViewParallelSteps, a9 as isElement, a5 as isElementKindExpr, ad as isElementPredicateExpr, _ as isElementRef, a7 as isElementTagExpr, bc as isElementView, ab as isElementWhere, a0 as isExpandedElementExpr, bd as isExtendsElementView, ah as isInOut, aj as isIncoming, ax as isKindEqual, az as isNotOperator, aD as isOrOperator, al as isOutgoing, af as isRelation, an as isRelationExpression, as as isRelationPredicateExpr, ap as isRelationWhere, be as isScopedElementView, bh as isStepEdgeId, av as isTagEqual, aM as isThemeColor, aX as isViewRuleAutoLayout, aT as isViewRulePredicate, aU as isViewRuleStyle, a3 as isWildcard, aF as whereOperatorAsPredicate } from '../shared/core.C4jDMQ1i.js';
import 'type-fest';
{
"name": "@likec4/core",
"version": "1.12.2",
"version": "1.13.0",
"license": "MIT",

@@ -79,6 +79,7 @@ "homepage": "https://likec4.dev",

"dependencies": {
"defu": "^6.1.4",
"type-fest": "4.26.1"
},
"devDependencies": {
"@likec4/tsconfig": "1.12.2",
"@likec4/tsconfig": "1.13.0",
"@mantine/colors-generator": "^7.13.2",

@@ -91,3 +92,3 @@ "@types/natural-compare-lite": "^1.4.2",

"turbo": "^2.1.3",
"typescript": "^5.6.2",
"typescript": "^5.6.3",
"unbuild": "^3.0.0-rc.11",

@@ -94,0 +95,0 @@ "vitest": "^2.1.2"

@@ -0,4 +1,8 @@

export * from './builder'
export { Builder } from './builder'
export type * from './builder'
export * from './colors'
export * from './errors'
export * from './model'
export * from './types'

@@ -5,0 +9,0 @@ export * from './utils/compare-natural'

@@ -252,2 +252,7 @@ import { mapToObj } from 'remeda'

rel({
source: 'customer',
target: 'cloud.frontend',
title: 'uses frontend'
}),
rel({
source: 'cloud.backend.graphql',

@@ -254,0 +259,0 @@ target: 'cloud.backend.storage',

@@ -18,7 +18,7 @@ import { isNullish } from 'remeda'

export class LikeC4DiagramModel {
private _rootElements = new Set<LikeC4DiagramModel.Element>()
private readonly _rootElements = new Set<LikeC4DiagramModel.Element>()
private _elements = new Map<Fqn, LikeC4DiagramModel.Element>()
private readonly _elements = new Map<Fqn, LikeC4DiagramModel.Element>()
private _connections: Map<EdgeId, LikeC4DiagramModel.Connection>
private readonly _connections: Map<EdgeId, LikeC4DiagramModel.Connection>

@@ -202,3 +202,3 @@ constructor(

public readonly node: DiagramNode,
private view: LikeC4DiagramModel
private readonly view: LikeC4DiagramModel
) {

@@ -309,3 +309,3 @@ }

public readonly edge: DiagramEdge,
private view: LikeC4DiagramModel
private readonly view: LikeC4DiagramModel
) {

@@ -312,0 +312,0 @@ }

import { isString, isTruthy, values } from 'remeda'
import type { Class } from 'type-fest'
import { nonNullable } from '../errors'
import { DefaultElementShape, DefaultThemeColor } from '../types/element'
import type {

@@ -8,5 +8,5 @@ Element as C4Element,

ElementShape as C4ElementShape,
Fqn as C4Fqn,
Tag as C4Tag
} from '../types/element'
import { DefaultElementShape, DefaultThemeColor } from '../types/element'
import type {

@@ -21,4 +21,4 @@ ComputedLikeC4Model as C4ComputedLikeC4Model,

import { LikeC4ViewModel } from './LikeC4ViewModel'
import type { ElementOrFqn, Fqn, IncomingFilter, OutgoingFilter, RelationID, ViewID } from './types'
import { getId } from './types'
import type { ElementOrFqn, Fqn, IncomingFilter, OutgoingFilter, RelationID, ViewID } from './types'

@@ -53,43 +53,11 @@ type PickBySource<Source> = Source extends LikeC4Model.Layouted.SourceModel ? LikeC4Model.Layouted

private _views = new Map<Fqn, M>()
private _views: Map<Fqn, M>
static create(source: LikeC4Model.SourceModel): PickBySource<typeof source> {
// static create<MM extends LikeC4Model>(source: MM['s']): PickBySource<typeof source> {
if (source.__ === 'layouted') {
return LikeC4Model.layouted(source)
}
return LikeC4Model.computed(source)
}
static computed(source: C4ComputedLikeC4Model): LikeC4Model<LikeC4ViewModel> {
const instance = new LikeC4Model<LikeC4ViewModel>(
'computed',
source,
values(source.elements),
values(source.relations)
)
for (const view of values(source.views)) {
instance._views.set(view.id, new LikeC4ViewModel(view, instance))
}
return instance
}
static layouted(source: C4LayoutedLikeC4Model): LikeC4Model<LikeC4DiagramModel> {
const instance = new LikeC4Model<LikeC4DiagramModel>(
'layouted',
source,
values(source.elements),
values(source.relations)
)
for (const view of values(source.views)) {
instance._views.set(view.id, new LikeC4DiagramModel(view, instance))
}
return instance
}
protected constructor(
constructor(
public readonly type: LikeC4Model.ModelType<M>,
public readonly sourcemodel: LikeC4Model.SourceModel<M>,
elements: C4Element[],
relations: C4Relation[]
relations: C4Relation[],
views: LikeC4Model.SourceModel<M>['views'],
ViewModelClass: Class<M>
) {

@@ -102,2 +70,5 @@ for (const el of elements) {

}
this._views = new Map(
values(views).map(view => [view.id, new ViewModelClass(view, this)] as [Fqn, M])
)
}

@@ -235,3 +206,3 @@

): ReadonlyArray<LikeC4Model.ElementModel<M>> {
return this.incoming(element, filter).map(r => r.source)
return [...new Set(this.incoming(element, filter).map(r => r.source))]
}

@@ -267,3 +238,3 @@

): ReadonlyArray<LikeC4Model.ElementModel<M>> {
return this.outgoing(element, filter).map(r => r.target)
return [...new Set(this.outgoing(element, filter).map(r => r.target))]
}

@@ -389,2 +360,32 @@

export namespace LikeC4Model {
export function create(source: LikeC4Model.SourceModel): PickBySource<typeof source> {
// static create<MM extends LikeC4Model>(source: MM['s']): PickBySource<typeof source> {
if (source.__ === 'layouted') {
return LikeC4Model.layouted(source)
}
return LikeC4Model.computed(source)
}
export function computed(source: C4ComputedLikeC4Model): LikeC4Model<LikeC4ViewModel> {
return new LikeC4Model(
'computed',
source,
values(source.elements),
values(source.relations),
source.views,
LikeC4ViewModel
)
}
export function layouted(source: C4LayoutedLikeC4Model): LikeC4Model<LikeC4DiagramModel> {
return new LikeC4Model(
'layouted',
source,
values(source.elements),
values(source.relations),
source.views,
LikeC4DiagramModel
)
}
export function isModel(model: any): model is LikeC4Model {

@@ -399,2 +400,3 @@ return model instanceof LikeC4Model

export namespace ViewModel {
export type ElementModel = LikeC4ViewModel.Element | LikeC4DiagramModel.Element
export type Relationship = LikeC4Model.Relationship<ViewModel>

@@ -427,6 +429,6 @@

export class Relationship<M extends ViewModel> {
export class Relationship<M extends ViewModel = ViewModel> {
constructor(
public readonly relationship: C4Relation,
private model: LikeC4Model<M>
private readonly model: LikeC4Model<M>
) {

@@ -471,6 +473,6 @@ }

// Class renamed to ElementModel, otherwise generated DTS will be incorrect
export class ElementModel<M extends ViewModel> {
export class ElementModel<M extends ViewModel = ViewModel> {
constructor(
public readonly element: C4Element,
private model: LikeC4Model<M>
private readonly model: LikeC4Model<M>
) {

@@ -542,2 +544,9 @@ }

/**
* All views 'view of' current element
*/
public viewsOf() {
return this.model.views().filter(v => v.viewOf?.id === this.id)
}
/**
* Views that contain this element

@@ -569,2 +578,10 @@ */

/**
* Resolve siblings of the element and siblings of ancestors
* (from closest to root)
*/
public ascendingSiblings() {
return this.model.ascendingSiblings(this)
}
// public *descendants(): IterableIterator<LikeC4Element> {

@@ -571,0 +588,0 @@ // return

@@ -17,7 +17,7 @@ import { isNullish } from 'remeda'

export class LikeC4ViewModel {
private _rootElements = new Set<LikeC4ViewModel.Element>()
private readonly _rootElements = new Set<LikeC4ViewModel.Element>()
private _elements = new Map<Fqn, LikeC4ViewModel.Element>()
private readonly _elements = new Map<Fqn, LikeC4ViewModel.Element>()
private _connections: Map<EdgeId, LikeC4ViewModel.Connection>
private readonly _connections: Map<EdgeId, LikeC4ViewModel.Connection>

@@ -155,3 +155,3 @@ constructor(

): ReadonlyArray<LikeC4ViewModel.Element> {
return this.incoming(element, filter).map(r => r.source)
return [...new Set(this.incoming(element, filter).map(r => r.source))]
}

@@ -185,3 +185,3 @@

): ReadonlyArray<LikeC4ViewModel.Element> {
return this.outgoing(element, filter).map(r => r.target)
return [...new Set(this.outgoing(element, filter).map(r => r.target))]
}

@@ -198,3 +198,3 @@ }

public readonly node: ComputedNode,
private viewmodel: LikeC4ViewModel
private readonly viewmodel: LikeC4ViewModel
) {

@@ -297,3 +297,3 @@ }

public readonly edge: ComputedEdge,
private viewmodel: LikeC4ViewModel
private readonly viewmodel: LikeC4ViewModel
) {

@@ -300,0 +300,0 @@ }

@@ -1,2 +0,2 @@

import type { Tagged } from 'type-fest'
import type { IfNever, Tagged, TupleToUnion } from 'type-fest'
import type { IconUrl, NonEmptyArray } from './_common'

@@ -6,3 +6,3 @@ import type { Color, ThemeColor } from './theme'

// Full-qualified-name
export type Fqn = Tagged<string, 'Fqn'>
export type Fqn<Id extends string = string> = Tagged<Id, 'Fqn'>

@@ -15,5 +15,5 @@ export function AsFqn(name: string, parent?: Fqn | null) {

export type BorderStyle = typeof BorderStyles[number]
export type BorderStyle = TupleToUnion<typeof BorderStyles>
export type ElementKind = Tagged<string, 'ElementKind'>
export type ElementKind<Kinds extends string = string> = Tagged<Kinds, 'ElementKind'>
export const ElementShapes = [

@@ -29,3 +29,3 @@ 'rectangle',

export type ElementShape = typeof ElementShapes[number]
export type ElementShape = TupleToUnion<typeof ElementShapes>
export const DefaultThemeColor = 'primary' satisfies ThemeColor

@@ -40,3 +40,3 @@ export const DefaultElementShape = 'rectangle' satisfies ElementShape

export type Tag = Tagged<string, 'Tag'>
export type Tag<Tags extends string = string> = Tagged<Tags, 'Tag'>

@@ -56,9 +56,14 @@ export interface TagSpec {

export interface Element {
readonly id: Fqn
readonly kind: ElementKind
export interface TypedElement<
Ids extends string,
Kinds extends string,
Tags extends string,
MetadataKeys extends string = never
> {
readonly id: Fqn<Ids>
readonly kind: ElementKind<Kinds>
readonly title: string
readonly description: string | null
readonly technology: string | null
readonly tags: NonEmptyArray<Tag> | null
readonly tags: NonEmptyArray<Tag<Tags>> | null
readonly links: NonEmptyArray<Link> | null

@@ -70,5 +75,8 @@ readonly icon?: IconUrl

readonly notation?: string
readonly metadata?: { [key: string]: string }
readonly metadata?: Record<MetadataKeys, string>
}
export interface Element extends TypedElement<string, string, string, string> {
}
export interface ElementKindSpecificationStyle {

@@ -75,0 +83,0 @@ shape?: ElementShape

@@ -1,3 +0,2 @@

import type { UnwrapTagged } from 'type-fest'
import type { Element, ElementKind, ElementKindSpecification, Fqn, Tag } from './element'
import type { ElementKindSpecification, Tag, TypedElement } from './element'
import type { Relation, RelationID, RelationshipKindSpecification } from './relation'

@@ -9,11 +8,17 @@ import type { ComputedView, DiagramView, LikeC4View, ViewID } from './view'

*/
export interface ParsedLikeC4Model {
export interface ParsedLikeC4Model<
ElementKinds extends string = string,
RelationKinds extends string = string,
Tags extends string = string,
Fqns extends string = string,
Views extends string = string
> {
specification: {
tags: Tag[]
elements: Record<UnwrapTagged<ElementKind>, ElementKindSpecification>
relationships: Record<UnwrapTagged<ElementKind>, RelationshipKindSpecification>
tags: Tag<Tags>[]
elements: Record<ElementKinds, ElementKindSpecification>
relationships: Record<RelationKinds, RelationshipKindSpecification>
}
elements: Record<Fqn, Element>
elements: Record<Fqns, TypedElement<Fqns, ElementKinds, Tags>>
relations: Record<RelationID, Relation>
views: Record<ViewID, LikeC4View>
views: Record<Views, LikeC4View<Views, Tags>>
}

@@ -20,0 +25,0 @@

@@ -8,3 +8,3 @@ import type { Tagged } from 'type-fest'

export type RelationID = Tagged<string, 'RelationID'>
export type RelationshipKind = Tagged<string, 'RelationshipKind'>
export type RelationshipKind<Kinds extends string = string> = Tagged<Kinds, 'RelationshipKind'>

@@ -11,0 +11,0 @@ export type RelationshipLineType = 'dashed' | 'solid' | 'dotted'

import type { NonEmptyArray } from './_common'
import type { BorderStyle, ElementShape, Fqn } from './element'
import type { ThemeColor } from './theme'
import type { ViewManualLayout, ViewRuleAutoLayout } from './view'
import type { AutoLayoutDirection, ViewManualLayout } from './view'

@@ -25,5 +25,9 @@ export namespace ViewChange {

op: 'change-autolayout'
layout: ViewRuleAutoLayout
layout: {
direction: AutoLayoutDirection
nodeSep?: number | null
rankSep?: number | null
}
}
}
export type ViewChange = ViewChange.ChangeElementStyle | ViewChange.SaveManualLayout | ViewChange.ChangeAutoLayout

@@ -10,4 +10,3 @@ import { isArray, isNullish } from 'remeda'

// Full-qualified-name
export type ViewID = Tagged<string, 'ViewID'>
export type ViewID<Id extends string = string> = Tagged<Id, 'ViewID'>

@@ -59,8 +58,12 @@ export type ViewRulePredicate =

export interface BasicView<ViewType extends 'element' | 'dynamic'> {
export interface BasicView<
ViewType extends 'element' | 'dynamic',
ViewIDs extends string,
Tags extends string
> {
readonly __?: ViewType
readonly id: ViewID
readonly id: ViewID<ViewIDs>
readonly title: string | null
readonly description: string | null
readonly tags: NonEmptyArray<Tag> | null
readonly tags: NonEmptyArray<Tag<Tags>> | null
readonly links: NonEmptyArray<Link> | null

@@ -91,14 +94,26 @@

export interface BasicElementView extends BasicView<'element'> {
export interface BasicElementView<ViewIDs extends string, Tags extends string>
extends BasicView<'element', ViewIDs, Tags>
{
readonly viewOf?: Fqn
readonly rules: ViewRule[]
}
export interface ScopedElementView extends BasicElementView {
export interface ScopedElementView<ViewIDs extends string, Tags extends string>
extends BasicElementView<ViewIDs, Tags>
{
readonly viewOf: Fqn
}
export interface ExtendsElementView extends BasicElementView {
readonly extends: ViewID
export interface ExtendsElementView<ViewIDs extends string, Tags extends string>
extends BasicElementView<ViewIDs, Tags>
{
readonly extends: ViewID<ViewIDs>
}
export type ElementView = ScopedElementView | ExtendsElementView | BasicElementView
export type ElementView<
ViewIDs extends string = string,
Tags extends string = string
> =
| ScopedElementView<ViewIDs, Tags>
| ExtendsElementView<ViewIDs, Tags>
| BasicElementView<ViewIDs, Tags>

@@ -139,3 +154,6 @@ export interface DynamicViewStep {

export type DynamicViewRule = DynamicViewIncludeRule | ViewRuleStyle | ViewRuleAutoLayout
export interface DynamicView extends BasicView<'dynamic'> {
export interface DynamicView<
ViewIDs extends string = string,
Tags extends string = string
> extends BasicView<'dynamic', ViewIDs, Tags> {
readonly __: 'dynamic'

@@ -154,3 +172,6 @@

export type LikeC4View = ElementView | DynamicView
export type LikeC4View<
ViewIDs extends string = string,
Tags extends string = string
> = ElementView<ViewIDs, Tags> | DynamicView<ViewIDs, Tags>

@@ -164,11 +185,11 @@ export function isDynamicView(view: LikeC4View): view is DynamicView {

export function isExtendsElementView(view: LikeC4View): view is ExtendsElementView {
export function isExtendsElementView(view: LikeC4View): view is ExtendsElementView<string, string> {
return isElementView(view) && 'extends' in view
}
export function isScopedElementView(view: LikeC4View): view is ScopedElementView {
export function isScopedElementView(view: LikeC4View): view is ScopedElementView<string, string> {
return isElementView(view) && 'viewOf' in view
}
export type NodeId = Tagged<string, 'Fqn'>
export type NodeId<IDs extends string = string> = Tagged<IDs, 'Fqn'>

@@ -285,4 +306,7 @@ export type EdgeId = Tagged<string, 'EdgeId'>

}
export interface ComputedElementView extends Omit<ElementView, 'rules' | 'docUri'>, ViewWithHash, ViewWithNotation {
readonly extends?: ViewID
export interface ComputedElementView<
ViewIDs extends string = string,
Tags extends string = string
> extends Omit<ElementView<ViewIDs, Tags>, 'rules' | 'docUri'>, ViewWithHash, ViewWithNotation {
readonly extends?: ViewID<ViewIDs>
readonly autoLayout: ViewAutoLayout

@@ -294,5 +318,6 @@ readonly nodes: ComputedNode[]

}
export interface ComputedDynamicView
extends Omit<DynamicView, 'rules' | 'steps' | 'docUri'>, ViewWithHash, ViewWithNotation
{
export interface ComputedDynamicView<
ViewIDs extends string = string,
Tags extends string = string
> extends Omit<DynamicView<ViewIDs, Tags>, 'rules' | 'steps' | 'docUri'>, ViewWithHash, ViewWithNotation {
readonly autoLayout: ViewAutoLayout

@@ -309,3 +334,6 @@ readonly nodes: ComputedNode[]

export type ComputedView = ComputedElementView | ComputedDynamicView
export type ComputedView<
ViewIDs extends string = string,
Tags extends string = string
> = ComputedElementView<ViewIDs, Tags> | ComputedDynamicView<ViewIDs, Tags>

@@ -355,3 +383,6 @@ export function isComputedElementView(view: ComputedView): view is ComputedElementView {

export interface DiagramView extends Omit<ComputedView, 'nodes' | 'edges' | 'manualLayout'> {
export interface DiagramView<
ViewIDs extends string = string,
Tags extends string = string
> extends Omit<ComputedView<ViewIDs, Tags>, 'nodes' | 'edges' | 'manualLayout'> {
readonly nodes: DiagramNode[]

@@ -358,0 +389,0 @@ readonly edges: DiagramEdge[]

@@ -0,1 +1,2 @@

import type { LiteralUnion } from 'type-fest'
import type { Element, Fqn } from '../types'

@@ -7,3 +8,3 @@ import { compareNatural } from './compare-natural'

export function nameFromFqn(fqn: Fqn) {
export function nameFromFqn(fqn: LiteralUnion<Fqn, string>) {
const lastDot = fqn.lastIndexOf('.')

@@ -41,3 +42,3 @@ if (lastDot > 0) {

export function commonAncestor(first: Fqn, second: Fqn) {
export function commonAncestor<IDs extends string>(first: Fqn<IDs>, second: Fqn<IDs>) {
const parentA = parentFqn(first)

@@ -54,6 +55,6 @@ const parentB = parentFqn(second)

const b = second.split('.')
let ancestor: Fqn | null = null
let ancestor: Fqn<IDs> | null = null
while (a.length > 1 && b.length > 1 && !!a[0] && a[0] === b[0]) {
ancestor = (ancestor ? `${ancestor}.${a[0]}` : a[0]) as Fqn
ancestor = (ancestor ? `${ancestor}.${a[0]}` : a[0]) as Fqn<IDs>
a.shift()

@@ -65,6 +66,6 @@ b.shift()

export function parentFqn(fqn: Fqn): Fqn | null {
export function parentFqn<IDs extends string>(fqn: Fqn<IDs>): Fqn<IDs> | null {
const lastDot = fqn.lastIndexOf('.')
if (lastDot > 0) {
return fqn.slice(0, lastDot) as Fqn
return fqn.slice(0, lastDot) as Fqn<IDs>
}

@@ -83,4 +84,4 @@ return null

*/
export function ancestorsFqn(fqn: Fqn): Fqn[] {
const path = fqn.split('.')
export function ancestorsFqn<IDs extends string>(fqn: Fqn<IDs>): Fqn<IDs>[] {
const path = fqn.split('.') as Fqn<IDs>[]
path.pop()

@@ -92,8 +93,8 @@ if (path.length === 0) {

if (idx === 0) {
acc.push(part as Fqn)
acc.push(part)
return acc
}
acc.unshift(`${acc[0]}.${part}` as Fqn)
acc.unshift(`${acc[0]}.${part}` as Fqn<IDs>)
return acc
}, [] as Fqn[])
}, [] as Fqn<IDs>[])
}

@@ -100,0 +101,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc