@likec4/generators 1.57.0 → 1.58.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/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { CompositeGeneratorNode, NL, expandToNode, joinToNode, toString } from "langium/generate";
2
- import { isEmptyish, isNullish, keys, map, pipe, values } from "remeda";
2
+ import { filter, isEmptyish, isNullish, isTruthy, keys, map, pipe, sort, unique, values } from "remeda";
3
3
  import { LikeC4Styles, nonexhaustive } from "@likec4/core";
4
4
  import { RichText, flattenMarkdownOrString } from "@likec4/core/types";
5
5
  import pako from "pako";
@@ -2375,14 +2375,19 @@ function generateMermaid(viewmodel) {
2375
2375
  }
2376
2376
  //#endregion
2377
2377
  //#region src/model/generate-aux.ts
2378
+ /**
2379
+ * Converts an array of strings or a record keys to a TypeScript union type string
2380
+ * Handles empty arrays/records by returning 'never'
2381
+ */
2378
2382
  function toUnion(elements) {
2379
- if (elements.length === 0) return "never";
2380
- return elements.sort(compareNatural).map((v) => ` | ${JSON.stringify(v)}`).join("\n").trimStart();
2383
+ if (isEmptyish(elements)) return "never";
2384
+ if (typeof elements === "object" && !Array.isArray(elements)) elements = keys(elements);
2385
+ return pipe(elements, unique(), sort(compareNatural), map((v) => ` | ${JSON.stringify(v)}`)).join("\n").trimStart();
2381
2386
  }
2382
- function elementIdToUnion(_elements) {
2383
- const elements = values(_elements);
2384
- if (elements.length === 0) return "never";
2385
- return pipe(elements, sortNaturalByFqn, map((v) => ` | ${JSON.stringify(v.id)}`)).join("\n").trimStart();
2387
+ function elementIdToUnion(elements) {
2388
+ let union = pipe(elements, values(), filter((i) => !!i && isTruthy(i.id)), sortNaturalByFqn, map((v) => ` | ${JSON.stringify(v.id)}`));
2389
+ if (union.length === 0) return "never";
2390
+ return union.join("\n").trimStart();
2386
2391
  }
2387
2392
  function generateAux(model, options = {}) {
2388
2393
  const { useCorePackage = false } = options;
@@ -2391,15 +2396,15 @@ import type { Aux, SpecAux } from '${useCorePackage ? "@likec4/core/types" : "li
2391
2396
 
2392
2397
  export type $Specs = SpecAux<
2393
2398
  // Element kinds
2394
- ${toUnion(keys(model.specification.elements))},
2399
+ ${toUnion(model.specification.elements)},
2395
2400
  // Deployment kinds
2396
- ${toUnion(keys(model.specification.deployments ?? {}))},
2401
+ ${toUnion(model.specification.deployments)},
2397
2402
  // Relationship kinds
2398
- ${toUnion(keys(model.specification.relationships ?? {}))},
2403
+ ${toUnion(model.specification.relationships)},
2399
2404
  // Tags
2400
- ${toUnion(keys(model.specification.tags ?? {}))},
2405
+ ${toUnion(model.specification.tags)},
2401
2406
  // Metadata keys
2402
- ${toUnion(model.specification.metadataKeys ?? [])}
2407
+ ${toUnion(model.specification.metadataKeys)}
2403
2408
  >
2404
2409
 
2405
2410
  export type $Aux = Aux<
@@ -2409,7 +2414,7 @@ export type $Aux = Aux<
2409
2414
  // Deployments
2410
2415
  ${elementIdToUnion(model.$data.deployments.elements)},
2411
2416
  // Views
2412
- ${toUnion(keys(model.$data.views))},
2417
+ ${toUnion(model.$data.views)},
2413
2418
  // Project ID
2414
2419
  ${JSON.stringify(model.projectId)},
2415
2420
  $Specs
@@ -107830,111 +107830,7 @@ declare const schemas: {
107830
107830
  }, z.core.$strip>]>>>;
107831
107831
  project: z.ZodOptional<z.ZodObject<{
107832
107832
  id: z.ZodString;
107833
- styles: z.ZodOptional<z.ZodNullable<z.ZodPipe<z.ZodObject<{
107834
- theme: z.ZodOptional<z.ZodPipe<z.ZodObject<{
107835
- colors: z.ZodOptional<z.ZodPipe<z.ZodRecord<z.ZodPipe<z.ZodUnion<[z.ZodEnum<{
107836
- [x: string]: any;
107837
- }>, z.ZodPipe<z.ZodCustom<string & Record<never, never>, string & Record<never, never>>, z.ZodTransform<any, string & Record<never, never>>>]>, z.ZodTransform<any, any>> & z.core.$partial, z.ZodPipe<z.ZodUnion<[z.ZodPipe<z.ZodObject<{
107838
- elements: z.ZodUnion<[z.ZodPipe<z.ZodObject<{
107839
- fill: z.ZodString;
107840
- stroke: z.ZodString;
107841
- hiContrast: z.ZodString;
107842
- loContrast: z.ZodString;
107843
- }, z.core.$strict>, z.ZodTransform<any, {
107844
- fill: string;
107845
- stroke: string;
107846
- hiContrast: string;
107847
- loContrast: string;
107848
- }>>, z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>]>;
107849
- relationships: z.ZodUnion<[z.ZodPipe<z.ZodObject<{
107850
- line: z.ZodString;
107851
- label: z.ZodString;
107852
- labelBg: z.ZodDefault<z.ZodOptional<z.ZodString>>;
107853
- }, z.core.$strict>, z.ZodTransform<any, {
107854
- line: string;
107855
- label: string;
107856
- labelBg: string;
107857
- }>>, z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>]>;
107858
- }, z.core.$strict>, z.ZodTransform<any, {
107859
- elements: any;
107860
- relationships: any;
107861
- }>>, z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>]>, z.ZodTransform<any, any>>>, z.ZodTransform<Record<ThemeColor, ThemeColorValues>, Partial<Record<any, any>>>>>;
107862
- sizes: z.ZodOptional<z.ZodRecord<z.ZodEnum<{
107863
- [x: string]: any;
107864
- }> & z.core.$partial, z.ZodObject<{
107865
- width: z.ZodNumber;
107866
- height: z.ZodNumber;
107867
- }, z.core.$strict>>>;
107868
- }, z.core.$strict>, z.ZodTransform<any, {
107869
- colors?: Record<ThemeColor, ThemeColorValues> | undefined;
107870
- sizes?: Partial<Record<any, {
107871
- width: number;
107872
- height: number;
107873
- }>> | undefined;
107874
- }>>>;
107875
- defaults: z.ZodOptional<z.ZodObject<{
107876
- color: z.ZodOptional<z.ZodPipe<z.ZodUnion<[z.ZodEnum<{
107877
- [x: string]: any;
107878
- }>, z.ZodPipe<z.ZodCustom<string & Record<never, never>, string & Record<never, never>>, z.ZodTransform<any, string & Record<never, never>>>]>, z.ZodTransform<any, any>>>;
107879
- opacity: z.ZodOptional<z.ZodInt>;
107880
- border: z.ZodOptional<z.ZodEnum<{
107881
- [x: string]: any;
107882
- }>>;
107883
- size: z.ZodOptional<z.ZodEnum<{
107884
- [x: string]: any;
107885
- }>>;
107886
- shape: z.ZodOptional<z.ZodEnum<{
107887
- [x: string]: any;
107888
- }>>;
107889
- iconPosition: z.ZodOptional<z.ZodEnum<{
107890
- [x: string]: any;
107891
- }>>;
107892
- group: z.ZodOptional<z.ZodObject<{
107893
- color: z.ZodOptional<z.ZodPipe<z.ZodUnion<[z.ZodEnum<{
107894
- [x: string]: any;
107895
- }>, z.ZodPipe<z.ZodCustom<string & Record<never, never>, string & Record<never, never>>, z.ZodTransform<any, string & Record<never, never>>>]>, z.ZodTransform<any, any>>>;
107896
- opacity: z.ZodOptional<z.ZodInt>;
107897
- border: z.ZodOptional<z.ZodEnum<{
107898
- [x: string]: any;
107899
- }>>;
107900
- }, z.core.$strict>>;
107901
- relationship: z.ZodOptional<z.ZodObject<{
107902
- color: z.ZodOptional<z.ZodPipe<z.ZodUnion<[z.ZodEnum<{
107903
- [x: string]: any;
107904
- }>, z.ZodPipe<z.ZodCustom<string & Record<never, never>, string & Record<never, never>>, z.ZodTransform<any, string & Record<never, never>>>]>, z.ZodTransform<any, any>>>;
107905
- line: z.ZodOptional<z.ZodEnum<{
107906
- dashed: "dashed";
107907
- solid: "solid";
107908
- dotted: "dotted";
107909
- }>>;
107910
- arrow: z.ZodOptional<z.ZodEnum<{
107911
- [x: string]: any;
107912
- }>>;
107913
- }, z.core.$strict>>;
107914
- }, z.core.$strict>>;
107915
- customCss: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
107916
- }, z.core.$strict>, z.ZodTransform<any, {
107917
- theme?: any;
107918
- defaults?: {
107919
- color?: any;
107920
- opacity?: number | undefined;
107921
- border?: any;
107922
- size?: any;
107923
- shape?: any;
107924
- iconPosition?: any;
107925
- group?: {
107926
- color?: any;
107927
- opacity?: number | undefined;
107928
- border?: any;
107929
- } | undefined;
107930
- relationship?: {
107931
- color?: any;
107932
- line?: "dashed" | "solid" | "dotted" | undefined;
107933
- arrow?: any;
107934
- } | undefined;
107935
- } | undefined;
107936
- customCss?: string | string[] | undefined;
107937
- }>>>>;
107833
+ styles: any;
107938
107834
  }, z.core.$strip>>;
107939
107835
  deployment: z.ZodOptional<z.ZodObject<{
107940
107836
  elements: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodRecord<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodReadonly<z.ZodObject<{
@@ -109816,8 +109712,8 @@ declare const schemas: {
109816
109712
  rules?: any[] | undefined;
109817
109713
  }> | undefined;
109818
109714
  project?: {
109715
+ [x: string]: any;
109819
109716
  id: string;
109820
- styles?: any;
109821
109717
  } | undefined;
109822
109718
  deployment?: {
109823
109719
  elements?: Record<any, {
@@ -109901,8 +109797,8 @@ declare const schemas: {
109901
109797
  rules?: any[] | undefined;
109902
109798
  }> | undefined;
109903
109799
  project?: {
109800
+ [x: string]: any;
109904
109801
  id: string;
109905
- styles?: any;
109906
109802
  } | undefined;
109907
109803
  deployment?: {
109908
109804
  elements?: Record<any, {
@@ -144208,47 +144104,8 @@ declare const likec4data: <A extends Readonly<{
144208
144104
  })[] | undefined;
144209
144105
  }> | undefined;
144210
144106
  project?: {
144107
+ [x: string]: any;
144211
144108
  id: string;
144212
- styles?: {
144213
- theme?: {
144214
- colors?: Partial<Record<any, string | {
144215
- elements: string | {
144216
- fill: string;
144217
- stroke: string;
144218
- hiContrast: string;
144219
- loContrast: string;
144220
- };
144221
- relationships: string | {
144222
- line: string;
144223
- label: string;
144224
- labelBg?: string | undefined;
144225
- };
144226
- }>> | undefined;
144227
- sizes?: Partial<Record<any, {
144228
- width: number;
144229
- height: number;
144230
- }>> | undefined;
144231
- } | undefined;
144232
- defaults?: {
144233
- color?: any;
144234
- opacity?: number | undefined;
144235
- border?: any;
144236
- size?: any;
144237
- shape?: any;
144238
- iconPosition?: any;
144239
- group?: {
144240
- color?: any;
144241
- opacity?: number | undefined;
144242
- border?: any;
144243
- } | undefined;
144244
- relationship?: {
144245
- color?: any;
144246
- line?: "dashed" | "solid" | "dotted" | undefined;
144247
- arrow?: any;
144248
- } | undefined;
144249
- } | undefined;
144250
- customCss?: string | string[] | undefined;
144251
- } | null | undefined;
144252
144109
  } | undefined;
144253
144110
  deployment?: {
144254
144111
  elements?: Record<string, Readonly<{
@@ -155464,47 +155321,8 @@ declare const likec4data: <A extends Readonly<{
155464
155321
  })[] | undefined;
155465
155322
  }> | undefined;
155466
155323
  project?: {
155324
+ [x: string]: any;
155467
155325
  id: string;
155468
- styles?: {
155469
- theme?: {
155470
- colors?: Partial<Record<any, string | {
155471
- elements: string | {
155472
- fill: string;
155473
- stroke: string;
155474
- hiContrast: string;
155475
- loContrast: string;
155476
- };
155477
- relationships: string | {
155478
- line: string;
155479
- label: string;
155480
- labelBg?: string | undefined;
155481
- };
155482
- }>> | undefined;
155483
- sizes?: Partial<Record<any, {
155484
- width: number;
155485
- height: number;
155486
- }>> | undefined;
155487
- } | undefined;
155488
- defaults?: {
155489
- color?: any;
155490
- opacity?: number | undefined;
155491
- border?: any;
155492
- size?: any;
155493
- shape?: any;
155494
- iconPosition?: any;
155495
- group?: {
155496
- color?: any;
155497
- opacity?: number | undefined;
155498
- border?: any;
155499
- } | undefined;
155500
- relationship?: {
155501
- color?: any;
155502
- line?: "dashed" | "solid" | "dotted" | undefined;
155503
- arrow?: any;
155504
- } | undefined;
155505
- } | undefined;
155506
- customCss?: string | string[] | undefined;
155507
- } | null | undefined;
155508
155326
  } | undefined;
155509
155327
  deployment?: {
155510
155328
  elements?: Record<string, Readonly<{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@likec4/generators",
3
- "version": "1.57.0",
3
+ "version": "1.58.0",
4
4
  "license": "MIT",
5
5
  "bugs": "https://github.com/likec4/likec4/issues",
6
6
  "homepage": "https://likec4.dev",
@@ -47,25 +47,25 @@
47
47
  "dependencies": {
48
48
  "langium": "3.5.0",
49
49
  "pako": "^2.1.0",
50
- "remeda": "^2.33.7",
51
- "immer": "^11.1.4",
50
+ "remeda": "^2.37.0",
51
+ "immer": "^11.1.8",
52
52
  "json5": "^2.2.3",
53
53
  "type-fest": "^4.41.0",
54
54
  "indent-string": "^5.0.0",
55
55
  "strip-indent": "^4.1.1",
56
- "zod": "^4.3.6",
57
- "@likec4/core": "1.57.0",
58
- "@likec4/config": "1.57.0",
59
- "@likec4/log": "1.57.0"
56
+ "zod": "^4.4.3",
57
+ "@likec4/config": "1.58.0",
58
+ "@likec4/log": "1.58.0",
59
+ "@likec4/core": "1.58.0"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@types/node": "~22.19.19",
63
63
  "@types/pako": "^2.0.4",
64
- "typescript": "5.9.3",
64
+ "typescript": "6.0.3",
65
65
  "obuild": "0.4.31",
66
- "vitest": "4.1.3",
67
- "@likec4/tsconfig": "1.57.0",
68
- "@likec4/devops": "1.57.0"
66
+ "vitest": "4.1.8",
67
+ "@likec4/tsconfig": "1.58.0",
68
+ "@likec4/devops": "1.58.0"
69
69
  },
70
70
  "scripts": {
71
71
  "typecheck": "tsc -b --verbose",
@@ -3,28 +3,39 @@ import {
3
3
  compareNatural,
4
4
  sortNaturalByFqn,
5
5
  } from '@likec4/core/utils'
6
- import { keys, map, pipe, values } from 'remeda'
6
+ import { filter, isEmptyish, isTruthy, keys, map, pipe, sort, unique, values } from 'remeda'
7
7
 
8
- function toUnion(elements: string[]) {
9
- if (elements.length === 0) {
8
+ /**
9
+ * Converts an array of strings or a record keys to a TypeScript union type string
10
+ * Handles empty arrays/records by returning 'never'
11
+ */
12
+ function toUnion(elements: string[] | Record<string, unknown> | undefined) {
13
+ if (isEmptyish(elements)) {
10
14
  return 'never'
11
15
  }
12
- let union = elements
13
- .sort(compareNatural)
14
- .map(v => ` | ${JSON.stringify(v)}`)
16
+ if (typeof elements === 'object' && !Array.isArray(elements)) {
17
+ elements = keys(elements)
18
+ }
19
+ let union = pipe(
20
+ elements,
21
+ unique(),
22
+ sort(compareNatural),
23
+ map(v => ` | ${JSON.stringify(v)}`),
24
+ )
15
25
  return union.join('\n').trimStart()
16
26
  }
17
27
 
18
- function elementIdToUnion(_elements: Record<string, { id: string }>) {
19
- const elements = values(_elements)
20
- if (elements.length === 0) {
21
- return 'never'
22
- }
28
+ function elementIdToUnion(elements: Record<string, { id: string }>) {
23
29
  let union = pipe(
24
30
  elements,
31
+ values(),
32
+ filter(i => !!i && isTruthy(i.id)),
25
33
  sortNaturalByFqn,
26
34
  map(v => ` | ${JSON.stringify(v.id)}`),
27
35
  )
36
+ if (union.length === 0) {
37
+ return 'never'
38
+ }
28
39
  return union.join('\n').trimStart()
29
40
  }
30
41
 
@@ -35,15 +46,15 @@ import type { Aux, SpecAux } from '${useCorePackage ? '@likec4/core/types' : 'li
35
46
 
36
47
  export type $Specs = SpecAux<
37
48
  // Element kinds
38
- ${toUnion(keys(model.specification.elements))},
49
+ ${toUnion(model.specification.elements)},
39
50
  // Deployment kinds
40
- ${toUnion(keys(model.specification.deployments ?? {}))},
51
+ ${toUnion(model.specification.deployments)},
41
52
  // Relationship kinds
42
- ${toUnion(keys(model.specification.relationships ?? {}))},
53
+ ${toUnion(model.specification.relationships)},
43
54
  // Tags
44
- ${toUnion(keys(model.specification.tags ?? {}))},
55
+ ${toUnion(model.specification.tags)},
45
56
  // Metadata keys
46
- ${toUnion(model.specification.metadataKeys ?? [])}
57
+ ${toUnion(model.specification.metadataKeys)}
47
58
  >
48
59
 
49
60
  export type $Aux = Aux<
@@ -53,7 +64,7 @@ export type $Aux = Aux<
53
64
  // Deployments
54
65
  ${elementIdToUnion(model.$data.deployments.elements)},
55
66
  // Views
56
- ${toUnion(keys(model.$data.views))},
67
+ ${toUnion(model.$data.views)},
57
68
  // Project ID
58
69
  ${JSON.stringify(model.projectId)},
59
70
  $Specs