@polagram/core 0.1.2 → 0.3.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/README.md CHANGED
@@ -73,40 +73,37 @@ Polagram's core strength is its ability to transform diagrams. You can define **
73
73
 
74
74
  ### Concepts
75
75
 
76
- - **Action**: A primitive operation on the AST (e.g., `remove`, `focus`, `resolve`).
77
- - **Selector**: A criteria to select nodes (e.g., `participant: { name: "Logger" }`).
78
- - **Layer**: A combination of an Action and a Selector.
76
+ - **Action**: A primitive operation on the AST.
77
+ - `remove`: Removes matching participants (and their messages).
78
+ - `focus`: Keeps only matching participants (removes everyone else).
79
+ - `merge`: Combines multiple participants into a single one (hides internal details).
80
+ - **Selector**: A criteria to select nodes.
81
+ - **Layer**: A configuration object defining an action and a selector.
79
82
  - **Lens**: A collection of Layers applied sequentially.
80
83
 
81
- ### Example: Creating a "Client View"
84
+ ### Example: Creating a "Client View" (Remove & Resolve)
82
85
 
83
86
  ```typescript
84
- import { Transformer, Lens, Layer } from '@polagram/core';
87
+ import { TransformationEngine, Layer } from '@polagram/core';
85
88
 
86
89
  // 1. Define Layers
87
- const removeLogger = new Layer('remove', {
88
- kind: 'participant',
89
- name: 'Logger' // Text or Regex
90
- });
91
-
92
- const resolveSuccess = new Layer('resolve', {
93
- kind: 'fragment',
94
- condition: 'Success' // Keeps only the 'Success' branch of alt/opt
95
- });
90
+ const layers: Layer[] = [
91
+ {
92
+ action: 'remove',
93
+ selector: { kind: 'participant', name: 'Logger' }
94
+ },
95
+ {
96
+ action: 'resolve',
97
+ selector: { kind: 'fragment', condition: 'Success' }
98
+ }
99
+ ];
96
100
 
97
- // 2. Create a Lens
98
- const clientViewLens = new Lens('client-view', [
99
- removeLogger,
100
- resolveSuccess
101
- ]);
101
+ // 2. Transform
102
+ const engine = new TransformationEngine();
103
+ const newAst = engine.transform(ast, layers);
104
+ ```
102
105
 
103
- // 3. Transform
104
- const transformer = new Transformer(ast);
105
- const newAst = transformer.apply(clientViewLens);
106
106
 
107
- // 4. Generate Code
108
- const newCode = GeneratorFactory.getGenerator('mermaid').generate(newAst);
109
- ```
110
107
 
111
108
  ## Development
112
109
 
package/dist/index.d.ts CHANGED
@@ -151,7 +151,7 @@ export declare interface GroupSelector {
151
151
  name?: TextMatcher;
152
152
  }
153
153
 
154
- export declare type Layer = ResolveLayer | FocusLayer | RemoveLayer;
154
+ export declare type Layer = ResolveLayer | FocusLayer | RemoveLayer | MergeLayer;
155
155
 
156
156
  export declare interface Lens {
157
157
  name?: string;
@@ -164,20 +164,36 @@ export declare type LensConfig = z.infer<typeof LensSchema>;
164
164
  declare const LensSchema: z.ZodObject<{
165
165
  name: z.ZodString;
166
166
  suffix: z.ZodOptional<z.ZodString>;
167
- layers: z.ZodArray<z.ZodObject<{
168
- action: z.ZodEnum<{
169
- resolve: "resolve";
170
- focus: "focus";
171
- remove: "remove";
172
- }>;
173
- selector: z.ZodDiscriminatedUnion<[z.ZodObject<{
167
+ layers: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
168
+ action: z.ZodLiteral<"resolve">;
169
+ selector: z.ZodObject<{
174
170
  kind: z.ZodLiteral<"fragment">;
175
171
  condition: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
176
172
  pattern: z.ZodString;
177
173
  flags: z.ZodOptional<z.ZodString>;
178
174
  }, z.core.$strip>]>>;
179
175
  operator: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
180
- }, z.core.$strip>, z.ZodObject<{
176
+ }, z.core.$strip>;
177
+ }, z.core.$strip>, z.ZodObject<{
178
+ action: z.ZodLiteral<"focus">;
179
+ selector: z.ZodObject<{
180
+ kind: z.ZodLiteral<"participant">;
181
+ name: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
182
+ pattern: z.ZodString;
183
+ flags: z.ZodOptional<z.ZodString>;
184
+ }, z.core.$strip>]>>;
185
+ id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
186
+ pattern: z.ZodString;
187
+ flags: z.ZodOptional<z.ZodString>;
188
+ }, z.core.$strip>]>>;
189
+ stereotype: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
190
+ pattern: z.ZodString;
191
+ flags: z.ZodOptional<z.ZodString>;
192
+ }, z.core.$strip>]>>;
193
+ }, z.core.$strip>;
194
+ }, z.core.$strip>, z.ZodObject<{
195
+ action: z.ZodLiteral<"remove">;
196
+ selector: z.ZodUnion<readonly [z.ZodObject<{
181
197
  kind: z.ZodLiteral<"participant">;
182
198
  name: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
183
199
  pattern: z.ZodString;
@@ -211,10 +227,42 @@ declare const LensSchema: z.ZodObject<{
211
227
  pattern: z.ZodString;
212
228
  flags: z.ZodOptional<z.ZodString>;
213
229
  }, z.core.$strip>]>>;
214
- }, z.core.$strip>], "kind">;
215
- }, z.core.$strip>>;
230
+ }, z.core.$strip>]>;
231
+ }, z.core.$strip>, z.ZodObject<{
232
+ action: z.ZodLiteral<"merge">;
233
+ into: z.ZodOptional<z.ZodObject<{
234
+ name: z.ZodOptional<z.ZodString>;
235
+ id: z.ZodOptional<z.ZodString>;
236
+ stereotype: z.ZodOptional<z.ZodString>;
237
+ }, z.core.$strip>>;
238
+ selector: z.ZodObject<{
239
+ kind: z.ZodLiteral<"participant">;
240
+ name: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
241
+ pattern: z.ZodString;
242
+ flags: z.ZodOptional<z.ZodString>;
243
+ }, z.core.$strip>]>>;
244
+ id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
245
+ pattern: z.ZodString;
246
+ flags: z.ZodOptional<z.ZodString>;
247
+ }, z.core.$strip>]>>;
248
+ stereotype: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
249
+ pattern: z.ZodString;
250
+ flags: z.ZodOptional<z.ZodString>;
251
+ }, z.core.$strip>]>>;
252
+ }, z.core.$strip>;
253
+ }, z.core.$strip>], "action">>;
216
254
  }, z.core.$strip>;
217
255
 
256
+ export declare interface MergeLayer {
257
+ action: 'merge';
258
+ into?: {
259
+ name?: string;
260
+ id?: string;
261
+ stereotype?: string;
262
+ };
263
+ selector: ParticipantSelector;
264
+ }
265
+
218
266
  /**
219
267
  * Visitor implementation that generates Mermaid code.
220
268
  */
@@ -438,20 +486,36 @@ export declare const PolagramConfigSchema: z.ZodObject<{
438
486
  lenses: z.ZodArray<z.ZodObject<{
439
487
  name: z.ZodString;
440
488
  suffix: z.ZodOptional<z.ZodString>;
441
- layers: z.ZodArray<z.ZodObject<{
442
- action: z.ZodEnum<{
443
- resolve: "resolve";
444
- focus: "focus";
445
- remove: "remove";
446
- }>;
447
- selector: z.ZodDiscriminatedUnion<[z.ZodObject<{
489
+ layers: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
490
+ action: z.ZodLiteral<"resolve">;
491
+ selector: z.ZodObject<{
448
492
  kind: z.ZodLiteral<"fragment">;
449
493
  condition: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
450
494
  pattern: z.ZodString;
451
495
  flags: z.ZodOptional<z.ZodString>;
452
496
  }, z.core.$strip>]>>;
453
497
  operator: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
454
- }, z.core.$strip>, z.ZodObject<{
498
+ }, z.core.$strip>;
499
+ }, z.core.$strip>, z.ZodObject<{
500
+ action: z.ZodLiteral<"focus">;
501
+ selector: z.ZodObject<{
502
+ kind: z.ZodLiteral<"participant">;
503
+ name: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
504
+ pattern: z.ZodString;
505
+ flags: z.ZodOptional<z.ZodString>;
506
+ }, z.core.$strip>]>>;
507
+ id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
508
+ pattern: z.ZodString;
509
+ flags: z.ZodOptional<z.ZodString>;
510
+ }, z.core.$strip>]>>;
511
+ stereotype: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
512
+ pattern: z.ZodString;
513
+ flags: z.ZodOptional<z.ZodString>;
514
+ }, z.core.$strip>]>>;
515
+ }, z.core.$strip>;
516
+ }, z.core.$strip>, z.ZodObject<{
517
+ action: z.ZodLiteral<"remove">;
518
+ selector: z.ZodUnion<readonly [z.ZodObject<{
455
519
  kind: z.ZodLiteral<"participant">;
456
520
  name: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
457
521
  pattern: z.ZodString;
@@ -485,8 +549,30 @@ export declare const PolagramConfigSchema: z.ZodObject<{
485
549
  pattern: z.ZodString;
486
550
  flags: z.ZodOptional<z.ZodString>;
487
551
  }, z.core.$strip>]>>;
488
- }, z.core.$strip>], "kind">;
489
- }, z.core.$strip>>;
552
+ }, z.core.$strip>]>;
553
+ }, z.core.$strip>, z.ZodObject<{
554
+ action: z.ZodLiteral<"merge">;
555
+ into: z.ZodOptional<z.ZodObject<{
556
+ name: z.ZodOptional<z.ZodString>;
557
+ id: z.ZodOptional<z.ZodString>;
558
+ stereotype: z.ZodOptional<z.ZodString>;
559
+ }, z.core.$strip>>;
560
+ selector: z.ZodObject<{
561
+ kind: z.ZodLiteral<"participant">;
562
+ name: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
563
+ pattern: z.ZodString;
564
+ flags: z.ZodOptional<z.ZodString>;
565
+ }, z.core.$strip>]>>;
566
+ id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
567
+ pattern: z.ZodString;
568
+ flags: z.ZodOptional<z.ZodString>;
569
+ }, z.core.$strip>]>>;
570
+ stereotype: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
571
+ pattern: z.ZodString;
572
+ flags: z.ZodOptional<z.ZodString>;
573
+ }, z.core.$strip>]>>;
574
+ }, z.core.$strip>;
575
+ }, z.core.$strip>], "action">>;
490
576
  }, z.core.$strip>>;
491
577
  format: z.ZodOptional<z.ZodEnum<{
492
578
  mermaid: "mermaid";
@@ -577,20 +663,36 @@ declare const TargetConfigSchema: z.ZodObject<{
577
663
  lenses: z.ZodArray<z.ZodObject<{
578
664
  name: z.ZodString;
579
665
  suffix: z.ZodOptional<z.ZodString>;
580
- layers: z.ZodArray<z.ZodObject<{
581
- action: z.ZodEnum<{
582
- resolve: "resolve";
583
- focus: "focus";
584
- remove: "remove";
585
- }>;
586
- selector: z.ZodDiscriminatedUnion<[z.ZodObject<{
666
+ layers: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
667
+ action: z.ZodLiteral<"resolve">;
668
+ selector: z.ZodObject<{
587
669
  kind: z.ZodLiteral<"fragment">;
588
670
  condition: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
589
671
  pattern: z.ZodString;
590
672
  flags: z.ZodOptional<z.ZodString>;
591
673
  }, z.core.$strip>]>>;
592
674
  operator: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
593
- }, z.core.$strip>, z.ZodObject<{
675
+ }, z.core.$strip>;
676
+ }, z.core.$strip>, z.ZodObject<{
677
+ action: z.ZodLiteral<"focus">;
678
+ selector: z.ZodObject<{
679
+ kind: z.ZodLiteral<"participant">;
680
+ name: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
681
+ pattern: z.ZodString;
682
+ flags: z.ZodOptional<z.ZodString>;
683
+ }, z.core.$strip>]>>;
684
+ id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
685
+ pattern: z.ZodString;
686
+ flags: z.ZodOptional<z.ZodString>;
687
+ }, z.core.$strip>]>>;
688
+ stereotype: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
689
+ pattern: z.ZodString;
690
+ flags: z.ZodOptional<z.ZodString>;
691
+ }, z.core.$strip>]>>;
692
+ }, z.core.$strip>;
693
+ }, z.core.$strip>, z.ZodObject<{
694
+ action: z.ZodLiteral<"remove">;
695
+ selector: z.ZodUnion<readonly [z.ZodObject<{
594
696
  kind: z.ZodLiteral<"participant">;
595
697
  name: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
596
698
  pattern: z.ZodString;
@@ -624,8 +726,30 @@ declare const TargetConfigSchema: z.ZodObject<{
624
726
  pattern: z.ZodString;
625
727
  flags: z.ZodOptional<z.ZodString>;
626
728
  }, z.core.$strip>]>>;
627
- }, z.core.$strip>], "kind">;
628
- }, z.core.$strip>>;
729
+ }, z.core.$strip>]>;
730
+ }, z.core.$strip>, z.ZodObject<{
731
+ action: z.ZodLiteral<"merge">;
732
+ into: z.ZodOptional<z.ZodObject<{
733
+ name: z.ZodOptional<z.ZodString>;
734
+ id: z.ZodOptional<z.ZodString>;
735
+ stereotype: z.ZodOptional<z.ZodString>;
736
+ }, z.core.$strip>>;
737
+ selector: z.ZodObject<{
738
+ kind: z.ZodLiteral<"participant">;
739
+ name: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
740
+ pattern: z.ZodString;
741
+ flags: z.ZodOptional<z.ZodString>;
742
+ }, z.core.$strip>]>>;
743
+ id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
744
+ pattern: z.ZodString;
745
+ flags: z.ZodOptional<z.ZodString>;
746
+ }, z.core.$strip>]>>;
747
+ stereotype: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
748
+ pattern: z.ZodString;
749
+ flags: z.ZodOptional<z.ZodString>;
750
+ }, z.core.$strip>]>>;
751
+ }, z.core.$strip>;
752
+ }, z.core.$strip>], "action">>;
629
753
  }, z.core.$strip>>;
630
754
  format: z.ZodOptional<z.ZodEnum<{
631
755
  mermaid: "mermaid";