@polagram/core 0.1.2 → 0.2.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,34 @@ 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
+ newName: z.ZodString;
234
+ selector: z.ZodObject<{
235
+ kind: z.ZodLiteral<"participant">;
236
+ name: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
237
+ pattern: z.ZodString;
238
+ flags: z.ZodOptional<z.ZodString>;
239
+ }, z.core.$strip>]>>;
240
+ id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
241
+ pattern: z.ZodString;
242
+ flags: z.ZodOptional<z.ZodString>;
243
+ }, z.core.$strip>]>>;
244
+ stereotype: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
245
+ pattern: z.ZodString;
246
+ flags: z.ZodOptional<z.ZodString>;
247
+ }, z.core.$strip>]>>;
248
+ }, z.core.$strip>;
249
+ }, z.core.$strip>], "action">>;
216
250
  }, z.core.$strip>;
217
251
 
252
+ export declare interface MergeLayer {
253
+ action: 'merge';
254
+ newName: string;
255
+ selector: ParticipantSelector;
256
+ }
257
+
218
258
  /**
219
259
  * Visitor implementation that generates Mermaid code.
220
260
  */
@@ -438,20 +478,36 @@ export declare const PolagramConfigSchema: z.ZodObject<{
438
478
  lenses: z.ZodArray<z.ZodObject<{
439
479
  name: z.ZodString;
440
480
  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<{
481
+ layers: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
482
+ action: z.ZodLiteral<"resolve">;
483
+ selector: z.ZodObject<{
448
484
  kind: z.ZodLiteral<"fragment">;
449
485
  condition: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
450
486
  pattern: z.ZodString;
451
487
  flags: z.ZodOptional<z.ZodString>;
452
488
  }, z.core.$strip>]>>;
453
489
  operator: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
454
- }, z.core.$strip>, z.ZodObject<{
490
+ }, z.core.$strip>;
491
+ }, z.core.$strip>, z.ZodObject<{
492
+ action: z.ZodLiteral<"focus">;
493
+ selector: z.ZodObject<{
494
+ kind: z.ZodLiteral<"participant">;
495
+ name: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
496
+ pattern: z.ZodString;
497
+ flags: z.ZodOptional<z.ZodString>;
498
+ }, z.core.$strip>]>>;
499
+ id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
500
+ pattern: z.ZodString;
501
+ flags: z.ZodOptional<z.ZodString>;
502
+ }, z.core.$strip>]>>;
503
+ stereotype: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
504
+ pattern: z.ZodString;
505
+ flags: z.ZodOptional<z.ZodString>;
506
+ }, z.core.$strip>]>>;
507
+ }, z.core.$strip>;
508
+ }, z.core.$strip>, z.ZodObject<{
509
+ action: z.ZodLiteral<"remove">;
510
+ selector: z.ZodUnion<readonly [z.ZodObject<{
455
511
  kind: z.ZodLiteral<"participant">;
456
512
  name: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
457
513
  pattern: z.ZodString;
@@ -485,8 +541,26 @@ export declare const PolagramConfigSchema: z.ZodObject<{
485
541
  pattern: z.ZodString;
486
542
  flags: z.ZodOptional<z.ZodString>;
487
543
  }, z.core.$strip>]>>;
488
- }, z.core.$strip>], "kind">;
489
- }, z.core.$strip>>;
544
+ }, z.core.$strip>]>;
545
+ }, z.core.$strip>, z.ZodObject<{
546
+ action: z.ZodLiteral<"merge">;
547
+ newName: z.ZodString;
548
+ selector: z.ZodObject<{
549
+ kind: z.ZodLiteral<"participant">;
550
+ name: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
551
+ pattern: z.ZodString;
552
+ flags: z.ZodOptional<z.ZodString>;
553
+ }, z.core.$strip>]>>;
554
+ id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
555
+ pattern: z.ZodString;
556
+ flags: z.ZodOptional<z.ZodString>;
557
+ }, z.core.$strip>]>>;
558
+ stereotype: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
559
+ pattern: z.ZodString;
560
+ flags: z.ZodOptional<z.ZodString>;
561
+ }, z.core.$strip>]>>;
562
+ }, z.core.$strip>;
563
+ }, z.core.$strip>], "action">>;
490
564
  }, z.core.$strip>>;
491
565
  format: z.ZodOptional<z.ZodEnum<{
492
566
  mermaid: "mermaid";
@@ -577,20 +651,36 @@ declare const TargetConfigSchema: z.ZodObject<{
577
651
  lenses: z.ZodArray<z.ZodObject<{
578
652
  name: z.ZodString;
579
653
  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<{
654
+ layers: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
655
+ action: z.ZodLiteral<"resolve">;
656
+ selector: z.ZodObject<{
587
657
  kind: z.ZodLiteral<"fragment">;
588
658
  condition: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
589
659
  pattern: z.ZodString;
590
660
  flags: z.ZodOptional<z.ZodString>;
591
661
  }, z.core.$strip>]>>;
592
662
  operator: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
593
- }, z.core.$strip>, z.ZodObject<{
663
+ }, z.core.$strip>;
664
+ }, z.core.$strip>, z.ZodObject<{
665
+ action: z.ZodLiteral<"focus">;
666
+ selector: z.ZodObject<{
667
+ kind: z.ZodLiteral<"participant">;
668
+ name: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
669
+ pattern: z.ZodString;
670
+ flags: z.ZodOptional<z.ZodString>;
671
+ }, z.core.$strip>]>>;
672
+ id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
673
+ pattern: z.ZodString;
674
+ flags: z.ZodOptional<z.ZodString>;
675
+ }, z.core.$strip>]>>;
676
+ stereotype: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
677
+ pattern: z.ZodString;
678
+ flags: z.ZodOptional<z.ZodString>;
679
+ }, z.core.$strip>]>>;
680
+ }, z.core.$strip>;
681
+ }, z.core.$strip>, z.ZodObject<{
682
+ action: z.ZodLiteral<"remove">;
683
+ selector: z.ZodUnion<readonly [z.ZodObject<{
594
684
  kind: z.ZodLiteral<"participant">;
595
685
  name: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
596
686
  pattern: z.ZodString;
@@ -624,8 +714,26 @@ declare const TargetConfigSchema: z.ZodObject<{
624
714
  pattern: z.ZodString;
625
715
  flags: z.ZodOptional<z.ZodString>;
626
716
  }, z.core.$strip>]>>;
627
- }, z.core.$strip>], "kind">;
628
- }, z.core.$strip>>;
717
+ }, z.core.$strip>]>;
718
+ }, z.core.$strip>, z.ZodObject<{
719
+ action: z.ZodLiteral<"merge">;
720
+ newName: z.ZodString;
721
+ selector: z.ZodObject<{
722
+ kind: z.ZodLiteral<"participant">;
723
+ name: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
724
+ pattern: z.ZodString;
725
+ flags: z.ZodOptional<z.ZodString>;
726
+ }, z.core.$strip>]>>;
727
+ id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
728
+ pattern: z.ZodString;
729
+ flags: z.ZodOptional<z.ZodString>;
730
+ }, z.core.$strip>]>>;
731
+ stereotype: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
732
+ pattern: z.ZodString;
733
+ flags: z.ZodOptional<z.ZodString>;
734
+ }, z.core.$strip>]>>;
735
+ }, z.core.$strip>;
736
+ }, z.core.$strip>], "action">>;
629
737
  }, z.core.$strip>>;
630
738
  format: z.ZodOptional<z.ZodEnum<{
631
739
  mermaid: "mermaid";