@kestra-io/ui-libs 0.0.188 → 0.0.190
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/FlowYamlUtils-BfpB1rP0.cjs +2 -0
- package/dist/FlowYamlUtils-BfpB1rP0.cjs.map +1 -0
- package/dist/FlowYamlUtils-f85Q_6sk.js +1802 -0
- package/dist/FlowYamlUtils-f85Q_6sk.js.map +1 -0
- package/dist/kestra-flowyamlutils.cjs.js +1 -1
- package/dist/kestra-flowyamlutils.cjs.js.map +1 -1
- package/dist/kestra-flowyamlutils.es.js +32 -507
- package/dist/kestra-flowyamlutils.es.js.map +1 -1
- package/dist/kestra-index.cjs.js +17 -17
- package/dist/kestra-index.cjs.js.map +1 -1
- package/dist/kestra-index.es.js +6364 -7613
- package/dist/kestra-index.es.js.map +1 -1
- package/dist/utils/FlowYamlUtils.d.ts +5 -3
- package/dist/utils/FlowYamlUtils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/utils/FlowYamlUtils.test.ts +275 -0
- package/src/utils/FlowYamlUtils.ts +6 -8
- package/src/utils/YamlUtilsLegacy.test.ts +72 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { YAMLMap } from "yaml";
|
|
1
|
+
import { YAMLMap, Range } from "yaml";
|
|
2
2
|
export declare function parse<T = any>(item?: string, throwIfError?: boolean): T | undefined;
|
|
3
3
|
export declare function stringify(item: any): string;
|
|
4
4
|
export declare function sort(value: Record<string, any>): string[];
|
|
@@ -79,7 +79,9 @@ export declare function insertErrorInFlowable(source: string, errorTask: string,
|
|
|
79
79
|
* will take a single argument which is the path of each parent property starting from the root doc (joined with ".")
|
|
80
80
|
* "my.parent.task" will mean that the field was retrieved in my -> parent -> task path.
|
|
81
81
|
*/
|
|
82
|
-
export declare function extractFieldFromMaps<T extends string>(source: string, fieldName: T, parentPathPredicate?: (_: any, __?: any) => boolean, valuePredicate?: (_: any) => boolean): any
|
|
82
|
+
export declare function extractFieldFromMaps<T extends string>(source: string, fieldName: T, parentPathPredicate?: (_: any, __?: any) => boolean, valuePredicate?: (_: any) => boolean): (Record<T, any> & {
|
|
83
|
+
range: Range;
|
|
84
|
+
})[];
|
|
83
85
|
/**
|
|
84
86
|
* Get task type at cursor position.
|
|
85
87
|
* Useful to display/update the live docs
|
|
@@ -87,7 +89,7 @@ export declare function extractFieldFromMaps<T extends string>(source: string, f
|
|
|
87
89
|
export declare function getTypeAtPosition(source: string, position: {
|
|
88
90
|
lineNumber: number;
|
|
89
91
|
column: number;
|
|
90
|
-
}, validTypes: any):
|
|
92
|
+
}, validTypes: any): any;
|
|
91
93
|
export type YamlElement = {
|
|
92
94
|
key?: string;
|
|
93
95
|
value: Record<string, any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FlowYamlUtils.d.ts","sourceRoot":"","sources":["../../src/utils/FlowYamlUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"FlowYamlUtils.d.ts","sourceRoot":"","sources":["../../src/utils/FlowYamlUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAEH,OAAO,EAWP,KAAK,EACR,MAAM,MAAM,CAAC;AAGd,wBAAgB,KAAK,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,YAAY,UAAO,GAAG,CAAC,GAAG,SAAS,CAShF;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,GAAG,UAWlC;AAiBD,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,YAU9C;AAED,wBAAgB,UAAU,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,6BAUvC;AA0CD,wBAAgB,YAAY,CAAC,EAAC,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAC,EAAE;IAC1D,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,GAA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C,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;IAC/B,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;CACpC,CAAC;AAEF,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,WAAW,CAiDzF;AAID,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,YAmB1C;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,OA+BlG"}
|
package/package.json
CHANGED
|
@@ -428,3 +428,278 @@ describe("insertBlock", () => {
|
|
|
428
428
|
`)
|
|
429
429
|
})
|
|
430
430
|
})
|
|
431
|
+
|
|
432
|
+
describe("deleteBlock", () => {
|
|
433
|
+
test("deleting a trigger", () => {
|
|
434
|
+
const yamlString = `
|
|
435
|
+
triggers:
|
|
436
|
+
- id: plugin1
|
|
437
|
+
type: type1
|
|
438
|
+
name: Plugin 1
|
|
439
|
+
- id: plugin2
|
|
440
|
+
type: type2
|
|
441
|
+
name: Plugin 2
|
|
442
|
+
`;
|
|
443
|
+
const result = YamlUtils.deleteBlock({
|
|
444
|
+
source: yamlString,
|
|
445
|
+
section: "triggers",
|
|
446
|
+
key: "plugin1"
|
|
447
|
+
});
|
|
448
|
+
expect(result).not.toContain("- id: plugin1");
|
|
449
|
+
})
|
|
450
|
+
|
|
451
|
+
test("deleting a task", () => {
|
|
452
|
+
const yamlString = `
|
|
453
|
+
tasks:
|
|
454
|
+
- id: plugin1
|
|
455
|
+
type: type1
|
|
456
|
+
name: Plugin 1
|
|
457
|
+
- id: plugin2
|
|
458
|
+
type: type2
|
|
459
|
+
name: Plugin 2
|
|
460
|
+
`;
|
|
461
|
+
const result = YamlUtils.deleteBlock({
|
|
462
|
+
source: yamlString,
|
|
463
|
+
section: "tasks",
|
|
464
|
+
key: "plugin1"
|
|
465
|
+
});
|
|
466
|
+
expect(result).not.toContain("- id: plugin1");
|
|
467
|
+
})
|
|
468
|
+
|
|
469
|
+
test("deleting a task with subtask", () => {
|
|
470
|
+
const yamlString = `
|
|
471
|
+
tasks:
|
|
472
|
+
- id: plugin1
|
|
473
|
+
type: type1
|
|
474
|
+
name: Plugin 1
|
|
475
|
+
tasks:
|
|
476
|
+
- id: plugin2
|
|
477
|
+
type: type2
|
|
478
|
+
name: Plugin 2
|
|
479
|
+
- id: plugin3
|
|
480
|
+
type: type3
|
|
481
|
+
name: Plugin 3
|
|
482
|
+
`;
|
|
483
|
+
const result = YamlUtils.deleteBlock({
|
|
484
|
+
source: yamlString,
|
|
485
|
+
section: "tasks",
|
|
486
|
+
key: "plugin1"
|
|
487
|
+
});
|
|
488
|
+
expect(result).not.toContain("- id: plugin1");
|
|
489
|
+
})
|
|
490
|
+
|
|
491
|
+
test("deleting a pluginDefaults", () => {
|
|
492
|
+
const yamlString = `
|
|
493
|
+
pluginDefaults:
|
|
494
|
+
- type: type1
|
|
495
|
+
name: Plugin 1
|
|
496
|
+
- type: type2
|
|
497
|
+
name: Plugin 2
|
|
498
|
+
`;
|
|
499
|
+
const result = YamlUtils.deleteBlock({
|
|
500
|
+
source: yamlString,
|
|
501
|
+
section: "pluginDefaults",
|
|
502
|
+
key: "type1",
|
|
503
|
+
keyName: "type"
|
|
504
|
+
});
|
|
505
|
+
expect(result).not.toContain("- type: type1");
|
|
506
|
+
})
|
|
507
|
+
|
|
508
|
+
test("deleting a pluginDefaults", () => {
|
|
509
|
+
const yamlString = `
|
|
510
|
+
pluginDefaults:
|
|
511
|
+
- type: type1
|
|
512
|
+
values:
|
|
513
|
+
- going: nuts
|
|
514
|
+
- going: bananas
|
|
515
|
+
|
|
516
|
+
- type: type2
|
|
517
|
+
name: Plugin 2
|
|
518
|
+
`;
|
|
519
|
+
const result = YamlUtils.deleteBlock({
|
|
520
|
+
source: yamlString,
|
|
521
|
+
section: "pluginDefaults",
|
|
522
|
+
key: "type1",
|
|
523
|
+
keyName: "type"
|
|
524
|
+
});
|
|
525
|
+
expect(result).not.toContain("- type: type1");
|
|
526
|
+
})
|
|
527
|
+
})
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
describe("extractFieldFromMaps", () => {
|
|
531
|
+
test("extracts field from maps", () => {
|
|
532
|
+
const yamlSrc = `
|
|
533
|
+
tasks:
|
|
534
|
+
- id: task1
|
|
535
|
+
type: io.kestra.plugin.core.log.Log
|
|
536
|
+
labels:
|
|
537
|
+
key1: value1
|
|
538
|
+
key2: value2
|
|
539
|
+
- id: task2
|
|
540
|
+
type: io.kestra.plugin.core.log.Log
|
|
541
|
+
labels:
|
|
542
|
+
key1: value3
|
|
543
|
+
key2: value4
|
|
544
|
+
`;
|
|
545
|
+
const result = YamlUtils.extractFieldFromMaps(yamlSrc, "labels");
|
|
546
|
+
expect(result).toMatchInlineSnapshot(`
|
|
547
|
+
[
|
|
548
|
+
{
|
|
549
|
+
"labels": [
|
|
550
|
+
{
|
|
551
|
+
"key1": "value1",
|
|
552
|
+
},
|
|
553
|
+
{
|
|
554
|
+
"key2": "value2",
|
|
555
|
+
},
|
|
556
|
+
],
|
|
557
|
+
"range": [
|
|
558
|
+
36,
|
|
559
|
+
184,
|
|
560
|
+
184,
|
|
561
|
+
],
|
|
562
|
+
},
|
|
563
|
+
{
|
|
564
|
+
"labels": [
|
|
565
|
+
{
|
|
566
|
+
"key1": "value3",
|
|
567
|
+
},
|
|
568
|
+
{
|
|
569
|
+
"key2": "value4",
|
|
570
|
+
},
|
|
571
|
+
],
|
|
572
|
+
"range": [
|
|
573
|
+
200,
|
|
574
|
+
348,
|
|
575
|
+
348,
|
|
576
|
+
],
|
|
577
|
+
},
|
|
578
|
+
]
|
|
579
|
+
`);
|
|
580
|
+
})
|
|
581
|
+
|
|
582
|
+
test("returns empty object if field not found", () => {
|
|
583
|
+
const yaml = `
|
|
584
|
+
tasks:
|
|
585
|
+
- id: task1
|
|
586
|
+
type: io.kestra.plugin.core.log.Log
|
|
587
|
+
`;
|
|
588
|
+
const result = YamlUtils.extractFieldFromMaps(yaml, "labels");
|
|
589
|
+
expect(result).toEqual([]);
|
|
590
|
+
});
|
|
591
|
+
test("returns empty object if no maps found", () => {
|
|
592
|
+
const yaml = `
|
|
593
|
+
tasks:
|
|
594
|
+
- id: task1
|
|
595
|
+
type: io.kestra.plugin.core.log.Log
|
|
596
|
+
`;
|
|
597
|
+
const result = YamlUtils.extractFieldFromMaps(yaml, "labels");
|
|
598
|
+
expect(result).toEqual([]);
|
|
599
|
+
})
|
|
600
|
+
})
|
|
601
|
+
|
|
602
|
+
describe("getLastBlock", () => {
|
|
603
|
+
test("get last task", () => {
|
|
604
|
+
const yamlString = `
|
|
605
|
+
tasks:
|
|
606
|
+
- id: plugin1
|
|
607
|
+
type: type1
|
|
608
|
+
name: Plugin 1
|
|
609
|
+
- id: plugin2
|
|
610
|
+
type: type2
|
|
611
|
+
name: Plugin 2
|
|
612
|
+
`;
|
|
613
|
+
const result = YamlUtils.getLastBlock({
|
|
614
|
+
source: yamlString,
|
|
615
|
+
section: "tasks"
|
|
616
|
+
});
|
|
617
|
+
expect(result).toBe("plugin2");
|
|
618
|
+
})
|
|
619
|
+
|
|
620
|
+
test("get last trigger", () => {
|
|
621
|
+
const yamlString = `
|
|
622
|
+
tasks:
|
|
623
|
+
- id: plugin1
|
|
624
|
+
type: type1
|
|
625
|
+
name: Plugin 1
|
|
626
|
+
triggers:
|
|
627
|
+
- id: plugin1
|
|
628
|
+
type: trigger1
|
|
629
|
+
name: Trigger 1
|
|
630
|
+
- id: plugin2
|
|
631
|
+
type: trigger2
|
|
632
|
+
name: Trigger 2
|
|
633
|
+
`;
|
|
634
|
+
const result = YamlUtils.getLastBlock({
|
|
635
|
+
source: yamlString,
|
|
636
|
+
section: "triggers"
|
|
637
|
+
});
|
|
638
|
+
expect(result).toBe("plugin2");
|
|
639
|
+
})
|
|
640
|
+
|
|
641
|
+
test("get last pluginDefaults", () => {
|
|
642
|
+
const yamlString = `
|
|
643
|
+
tasks:
|
|
644
|
+
- id: plugin1
|
|
645
|
+
type: type1
|
|
646
|
+
name: Plugin 1
|
|
647
|
+
pluginDefaults:
|
|
648
|
+
- type: type1
|
|
649
|
+
name: Plugin Default 1
|
|
650
|
+
- type: type2
|
|
651
|
+
name: Plugin Default 2
|
|
652
|
+
`;
|
|
653
|
+
const result = YamlUtils.getLastBlock({
|
|
654
|
+
source: yamlString,
|
|
655
|
+
section: "pluginDefaults",
|
|
656
|
+
keyName: "type"
|
|
657
|
+
});
|
|
658
|
+
expect(result).toBe("type2");
|
|
659
|
+
})
|
|
660
|
+
|
|
661
|
+
test("get last subtask", () => {
|
|
662
|
+
const yamlString = `
|
|
663
|
+
tasks:
|
|
664
|
+
- id: plugin1
|
|
665
|
+
type: type1
|
|
666
|
+
name: Plugin 1
|
|
667
|
+
tasks:
|
|
668
|
+
- id: plugin2
|
|
669
|
+
type: type2
|
|
670
|
+
name: Plugin 2
|
|
671
|
+
- id: plugin3
|
|
672
|
+
type: type3
|
|
673
|
+
name: Plugin 3
|
|
674
|
+
`;
|
|
675
|
+
const result = YamlUtils.getLastBlock({
|
|
676
|
+
source: yamlString,
|
|
677
|
+
section: "tasks",
|
|
678
|
+
parentKey: "plugin1"
|
|
679
|
+
});
|
|
680
|
+
expect(result).toBe("plugin3");
|
|
681
|
+
})
|
|
682
|
+
|
|
683
|
+
test("get last condition in trigger", () => {
|
|
684
|
+
const yamlString = `
|
|
685
|
+
triggers:
|
|
686
|
+
- id: plugin1
|
|
687
|
+
type: trigger1
|
|
688
|
+
name: Trigger 1
|
|
689
|
+
conditions:
|
|
690
|
+
- id: plugin2
|
|
691
|
+
type: condition1
|
|
692
|
+
name: Condition 1
|
|
693
|
+
- id: plugin3
|
|
694
|
+
type: condition2
|
|
695
|
+
name: Condition 2
|
|
696
|
+
`;
|
|
697
|
+
const result = YamlUtils.getLastBlock({
|
|
698
|
+
source: yamlString,
|
|
699
|
+
section: "triggers",
|
|
700
|
+
parentKey: "plugin1",
|
|
701
|
+
subBlockName: "conditions"
|
|
702
|
+
});
|
|
703
|
+
expect(result).toBe("plugin3");
|
|
704
|
+
})
|
|
705
|
+
})
|
|
@@ -12,7 +12,9 @@ import {
|
|
|
12
12
|
isMap,
|
|
13
13
|
isSeq,
|
|
14
14
|
visit,
|
|
15
|
+
Range,
|
|
15
16
|
} from "yaml";
|
|
17
|
+
import cloneDeep from "lodash/cloneDeep";
|
|
16
18
|
|
|
17
19
|
export function parse<T = any>(item?: string, throwIfError = true): T | undefined {
|
|
18
20
|
if (item === undefined) return undefined;
|
|
@@ -28,7 +30,7 @@ export function parse<T = any>(item?: string, throwIfError = true): T | undefine
|
|
|
28
30
|
export function stringify(item: any) {
|
|
29
31
|
if (item === undefined) return "";
|
|
30
32
|
|
|
31
|
-
const clonedValue =
|
|
33
|
+
const clonedValue = cloneDeep(item);
|
|
32
34
|
delete clonedValue.deleted;
|
|
33
35
|
|
|
34
36
|
return dump(transform(clonedValue), {
|
|
@@ -514,7 +516,7 @@ export function getLastBlock({source, section, parentKey, keyName, subBlockName}
|
|
|
514
516
|
|
|
515
517
|
const parsed = parse(source);
|
|
516
518
|
|
|
517
|
-
return parsed
|
|
519
|
+
return parsed[section]?.[parsed?.[section]?.length - 1]?.[keyName];
|
|
518
520
|
}
|
|
519
521
|
|
|
520
522
|
export function updateMetadata(source: string, metadata: Record<string, any>) {
|
|
@@ -689,7 +691,7 @@ export function extractFieldFromMaps<T extends string>(
|
|
|
689
691
|
fieldName: T,
|
|
690
692
|
parentPathPredicate = (_: any, __?: any) => true,
|
|
691
693
|
valuePredicate = (_: any) => true
|
|
692
|
-
): any[] {
|
|
694
|
+
): (Record<T, any> & {range: Range})[] {
|
|
693
695
|
const yamlDoc = parseDocument(source) as any;
|
|
694
696
|
const maps: any[] = [];
|
|
695
697
|
visit(yamlDoc, {
|
|
@@ -705,7 +707,6 @@ export function extractFieldFromMaps<T extends string>(
|
|
|
705
707
|
) {
|
|
706
708
|
for (const item of map.items as any[]) {
|
|
707
709
|
if (item?.key?.value === fieldName) {
|
|
708
|
-
|
|
709
710
|
const fieldValue = item?.value?.value ?? item.value?.items;
|
|
710
711
|
if (valuePredicate(fieldValue)) {
|
|
711
712
|
maps.push({
|
|
@@ -721,10 +722,7 @@ export function extractFieldFromMaps<T extends string>(
|
|
|
721
722
|
return maps;
|
|
722
723
|
}
|
|
723
724
|
|
|
724
|
-
function extractAllTypes(source: string, validTypes: string[] = [])
|
|
725
|
-
type: string;
|
|
726
|
-
range: [number, number, number]
|
|
727
|
-
}[] {
|
|
725
|
+
function extractAllTypes(source: string, validTypes: string[] = []){
|
|
728
726
|
return extractFieldFromMaps(source, "type", () => true, (value) =>
|
|
729
727
|
validTypes.some((t) => t === value)
|
|
730
728
|
);
|
|
@@ -1324,4 +1324,76 @@ tasks:
|
|
|
1324
1324
|
const result = YamlUtils.deleteSection(yaml, "finally", "finally1");
|
|
1325
1325
|
expect(result).not.toContain("finally");
|
|
1326
1326
|
})
|
|
1327
|
+
})
|
|
1328
|
+
|
|
1329
|
+
describe("extractFieldFromMaps", () => {
|
|
1330
|
+
test("extracts field from maps", () => {
|
|
1331
|
+
const yamlSrc = `
|
|
1332
|
+
tasks:
|
|
1333
|
+
- id: task1
|
|
1334
|
+
type: io.kestra.plugin.core.log.Log
|
|
1335
|
+
labels:
|
|
1336
|
+
key1: value1
|
|
1337
|
+
key2: value2
|
|
1338
|
+
- id: task2
|
|
1339
|
+
type: io.kestra.plugin.core.log.Log
|
|
1340
|
+
labels:
|
|
1341
|
+
key1: value3
|
|
1342
|
+
key2: value4
|
|
1343
|
+
`;
|
|
1344
|
+
const result = YamlUtils.extractFieldFromMaps(yamlSrc, "labels");
|
|
1345
|
+
expect(result).toMatchInlineSnapshot(`
|
|
1346
|
+
[
|
|
1347
|
+
{
|
|
1348
|
+
"labels": [
|
|
1349
|
+
{
|
|
1350
|
+
"key1": "value1",
|
|
1351
|
+
},
|
|
1352
|
+
{
|
|
1353
|
+
"key2": "value2",
|
|
1354
|
+
},
|
|
1355
|
+
],
|
|
1356
|
+
"range": [
|
|
1357
|
+
28,
|
|
1358
|
+
160,
|
|
1359
|
+
160,
|
|
1360
|
+
],
|
|
1361
|
+
},
|
|
1362
|
+
{
|
|
1363
|
+
"labels": [
|
|
1364
|
+
{
|
|
1365
|
+
"key1": "value3",
|
|
1366
|
+
},
|
|
1367
|
+
{
|
|
1368
|
+
"key2": "value4",
|
|
1369
|
+
},
|
|
1370
|
+
],
|
|
1371
|
+
"range": [
|
|
1372
|
+
172,
|
|
1373
|
+
304,
|
|
1374
|
+
304,
|
|
1375
|
+
],
|
|
1376
|
+
},
|
|
1377
|
+
]
|
|
1378
|
+
`);
|
|
1379
|
+
});
|
|
1380
|
+
|
|
1381
|
+
test("returns empty object if field not found", () => {
|
|
1382
|
+
const yaml = `
|
|
1383
|
+
tasks:
|
|
1384
|
+
- id: task1
|
|
1385
|
+
type: io.kestra.plugin.core.log.Log
|
|
1386
|
+
`;
|
|
1387
|
+
const result = YamlUtils.extractFieldFromMaps(yaml, "labels");
|
|
1388
|
+
expect(result).toEqual([]);
|
|
1389
|
+
});
|
|
1390
|
+
test("returns empty object if no maps found", () => {
|
|
1391
|
+
const yaml = `
|
|
1392
|
+
tasks:
|
|
1393
|
+
- id: task1
|
|
1394
|
+
type: io.kestra.plugin.core.log.Log
|
|
1395
|
+
`;
|
|
1396
|
+
const result = YamlUtils.extractFieldFromMaps(yaml, "labels");
|
|
1397
|
+
expect(result).toEqual([]);
|
|
1398
|
+
})
|
|
1327
1399
|
})
|