@polagram/core 0.1.1 → 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 +22 -25
- package/dist/index.d.ts +140 -33
- package/dist/polagram-core.js +811 -694
- package/dist/polagram-core.umd.cjs +17 -17
- package/package.json +1 -1
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
|
|
77
|
-
-
|
|
78
|
-
-
|
|
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 {
|
|
87
|
+
import { TransformationEngine, Layer } from '@polagram/core';
|
|
85
88
|
|
|
86
89
|
// 1. Define Layers
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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.
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
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.
|
|
169
|
-
|
|
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
|
|
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>]
|
|
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
|
*/
|
|
@@ -223,10 +263,10 @@ export declare class MermaidGeneratorVisitor implements PolagramVisitor {
|
|
|
223
263
|
private indentLevel;
|
|
224
264
|
private traverser;
|
|
225
265
|
constructor();
|
|
266
|
+
visitParticipantGroup(_node: ParticipantGroup): void;
|
|
226
267
|
generate(ast: PolagramRoot): string;
|
|
227
268
|
visitRoot(node: PolagramRoot): void;
|
|
228
269
|
visitParticipant(node: Participant): void;
|
|
229
|
-
visitParticipantGroup(node: ParticipantGroup): void;
|
|
230
270
|
visitMessage(node: MessageNode): void;
|
|
231
271
|
visitFragment(node: FragmentNode): void;
|
|
232
272
|
visitNote(node: NoteNode): void;
|
|
@@ -333,7 +373,6 @@ export declare class PlantUMLGeneratorVisitor implements PolagramVisitor {
|
|
|
333
373
|
visitRoot(node: PolagramRoot): void;
|
|
334
374
|
visitParticipant(node: Participant): void;
|
|
335
375
|
visitParticipantGroup(_node: ParticipantGroup): void;
|
|
336
|
-
private visitGroup;
|
|
337
376
|
visitMessage(node: MessageNode): void;
|
|
338
377
|
visitFragment(node: FragmentNode): void;
|
|
339
378
|
visitNote(node: NoteNode): void;
|
|
@@ -439,20 +478,36 @@ export declare const PolagramConfigSchema: z.ZodObject<{
|
|
|
439
478
|
lenses: z.ZodArray<z.ZodObject<{
|
|
440
479
|
name: z.ZodString;
|
|
441
480
|
suffix: z.ZodOptional<z.ZodString>;
|
|
442
|
-
layers: z.ZodArray<z.ZodObject<{
|
|
443
|
-
action: z.
|
|
444
|
-
|
|
445
|
-
focus: "focus";
|
|
446
|
-
remove: "remove";
|
|
447
|
-
}>;
|
|
448
|
-
selector: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
481
|
+
layers: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
482
|
+
action: z.ZodLiteral<"resolve">;
|
|
483
|
+
selector: z.ZodObject<{
|
|
449
484
|
kind: z.ZodLiteral<"fragment">;
|
|
450
485
|
condition: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
451
486
|
pattern: z.ZodString;
|
|
452
487
|
flags: z.ZodOptional<z.ZodString>;
|
|
453
488
|
}, z.core.$strip>]>>;
|
|
454
489
|
operator: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
455
|
-
}, z.core.$strip
|
|
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<{
|
|
456
511
|
kind: z.ZodLiteral<"participant">;
|
|
457
512
|
name: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
458
513
|
pattern: z.ZodString;
|
|
@@ -486,8 +541,26 @@ export declare const PolagramConfigSchema: z.ZodObject<{
|
|
|
486
541
|
pattern: z.ZodString;
|
|
487
542
|
flags: z.ZodOptional<z.ZodString>;
|
|
488
543
|
}, z.core.$strip>]>>;
|
|
489
|
-
}, z.core.$strip>]
|
|
490
|
-
}, 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">>;
|
|
491
564
|
}, z.core.$strip>>;
|
|
492
565
|
format: z.ZodOptional<z.ZodEnum<{
|
|
493
566
|
mermaid: "mermaid";
|
|
@@ -578,20 +651,36 @@ declare const TargetConfigSchema: z.ZodObject<{
|
|
|
578
651
|
lenses: z.ZodArray<z.ZodObject<{
|
|
579
652
|
name: z.ZodString;
|
|
580
653
|
suffix: z.ZodOptional<z.ZodString>;
|
|
581
|
-
layers: z.ZodArray<z.ZodObject<{
|
|
582
|
-
action: z.
|
|
583
|
-
|
|
584
|
-
focus: "focus";
|
|
585
|
-
remove: "remove";
|
|
586
|
-
}>;
|
|
587
|
-
selector: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
654
|
+
layers: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
655
|
+
action: z.ZodLiteral<"resolve">;
|
|
656
|
+
selector: z.ZodObject<{
|
|
588
657
|
kind: z.ZodLiteral<"fragment">;
|
|
589
658
|
condition: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
590
659
|
pattern: z.ZodString;
|
|
591
660
|
flags: z.ZodOptional<z.ZodString>;
|
|
592
661
|
}, z.core.$strip>]>>;
|
|
593
662
|
operator: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
594
|
-
}, z.core.$strip
|
|
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<{
|
|
595
684
|
kind: z.ZodLiteral<"participant">;
|
|
596
685
|
name: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
597
686
|
pattern: z.ZodString;
|
|
@@ -625,8 +714,26 @@ declare const TargetConfigSchema: z.ZodObject<{
|
|
|
625
714
|
pattern: z.ZodString;
|
|
626
715
|
flags: z.ZodOptional<z.ZodString>;
|
|
627
716
|
}, z.core.$strip>]>>;
|
|
628
|
-
}, z.core.$strip>]
|
|
629
|
-
}, 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">>;
|
|
630
737
|
}, z.core.$strip>>;
|
|
631
738
|
format: z.ZodOptional<z.ZodEnum<{
|
|
632
739
|
mermaid: "mermaid";
|