@kestra-io/ui-libs 0.0.191 → 0.0.193
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-f85Q_6sk.js → FlowYamlUtils-E3EN5bb4.js} +972 -900
- package/dist/{FlowYamlUtils-f85Q_6sk.js.map → FlowYamlUtils-E3EN5bb4.js.map} +1 -1
- package/dist/FlowYamlUtils-wL6s2KD7.cjs +2 -0
- package/dist/{FlowYamlUtils-BfpB1rP0.cjs.map → FlowYamlUtils-wL6s2KD7.cjs.map} +1 -1
- package/dist/kestra-flowyamlutils.cjs.js +1 -1
- package/dist/kestra-flowyamlutils.es.js +27 -22
- package/dist/kestra-index.cjs.js +1 -1
- package/dist/kestra-index.es.js +1 -1
- package/dist/utils/FlowYamlUtils.d.ts +21 -0
- package/dist/utils/FlowYamlUtils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/utils/FlowYamlUtils.test.ts +440 -1
- package/src/utils/FlowYamlUtils.ts +147 -3
- package/dist/FlowYamlUtils-BfpB1rP0.cjs +0 -2
package/dist/kestra-index.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import js, { Document as zs, YAMLMap as hr } from "yaml";
|
|
2
|
-
import { e as Vp, d as Up, r as Hp, a as Gp, f as pf, b as Bp, g as Wp, c as jp, u as zp, h as Kp, i as Yp, j as Xp, l as Zp, k as Jp, m as Qp, s as em, p as tm, n as nm, o as rm, q as mf, t as im, v as am, w as Ks, x as Ys, y as om, z as sm, A as vn, B as gf, C as ls, D as lm, E as Bn, F as um, G as us, H as cs, I as He, J as Wn, K as jn, L as _n, M as Vt, N as ds, O as zn, P as fs, Q as cm, R as vf, S as hs, T as dm, U as Ut, V as _f, W as fm, X as yf, Y as hm, Z as pm, _ as Ef, $ as ps, a0 as mm, a1 as gm, a2 as vm, a3 as Kn, a4 as _m, a5 as ym, a6 as Em, a7 as bm, a8 as Cm, a9 as wm, aa as bf, ab as Sm, ac as km, ad as Lm } from "./FlowYamlUtils-
|
|
2
|
+
import { e as Vp, d as Up, r as Hp, a as Gp, f as pf, b as Bp, g as Wp, c as jp, u as zp, h as Kp, i as Yp, j as Xp, l as Zp, k as Jp, m as Qp, s as em, p as tm, n as nm, o as rm, q as mf, t as im, v as am, w as Ks, x as Ys, y as om, z as sm, A as vn, B as gf, C as ls, D as lm, E as Bn, F as um, G as us, H as cs, I as He, J as Wn, K as jn, L as _n, M as Vt, N as ds, O as zn, P as fs, Q as cm, R as vf, S as hs, T as dm, U as Ut, V as _f, W as fm, X as yf, Y as hm, Z as pm, _ as Ef, $ as ps, a0 as mm, a1 as gm, a2 as vm, a3 as Kn, a4 as _m, a5 as ym, a6 as Em, a7 as bm, a8 as Cm, a9 as wm, aa as bf, ab as Sm, ac as km, ad as Lm } from "./FlowYamlUtils-E3EN5bb4.js";
|
|
3
3
|
import { createElementBlock as k, openBlock as E, mergeProps as ie, createElementVNode as O, createCommentVNode as M, toDisplayString as z, getCurrentInstance as tn, inject as Tm, ref as _e, shallowRef as In, computed as pe, watch as ct, onMounted as Yn, onUnmounted as Cf, defineComponent as Re, h as nn, createVNode as K, Text as dn, Fragment as Me, nextTick as ms, onBeforeUnmount as wf, renderSlot as ye, createTextVNode as Et, normalizeClass as he, createBlock as ue, withCtx as te, normalizeStyle as fn, unref as W, toRef as Xs, resolveComponent as An, effectScope as Om, reactive as Sf, resolveDynamicComponent as Ht, renderList as _t, createSlots as kf, normalizeProps as Nm, guardReactiveProps as Im, withModifiers as Lf, withAsyncContext as Zs, toRaw as Am, defineAsyncComponent as Rm, Comment as Dm, Suspense as Pm } from "vue";
|
|
4
4
|
import Mm from "humanize-duration";
|
|
5
5
|
import cn from "moment";
|
|
@@ -9,6 +9,15 @@ export declare function extractBlock({ source, section, key, keyName }: {
|
|
|
9
9
|
key: string;
|
|
10
10
|
keyName?: string;
|
|
11
11
|
}): string | undefined;
|
|
12
|
+
export declare function extractBlockWithPath({ source, path }: {
|
|
13
|
+
source: string;
|
|
14
|
+
path: string;
|
|
15
|
+
}): string | undefined;
|
|
16
|
+
export declare function replaceBlockWithPath({ source, path, newContent }: {
|
|
17
|
+
source: string;
|
|
18
|
+
path: string;
|
|
19
|
+
newContent: string;
|
|
20
|
+
}): string;
|
|
12
21
|
export declare function replaceBlockInDocument({ source, section, keyName, key, newContent }: {
|
|
13
22
|
source: string;
|
|
14
23
|
section: string;
|
|
@@ -33,12 +42,24 @@ export declare function insertBlock({ source, section, newBlock, refKey, positio
|
|
|
33
42
|
keyName?: string;
|
|
34
43
|
subBlockName?: string;
|
|
35
44
|
}): string;
|
|
45
|
+
export declare function parsePath(path: string): (string | number)[];
|
|
46
|
+
export declare function insertBlockWithPath({ source, newBlock, refPath, position, parentPath, }: {
|
|
47
|
+
source: string;
|
|
48
|
+
parentPath: string;
|
|
49
|
+
newBlock: string;
|
|
50
|
+
refPath?: string | number;
|
|
51
|
+
position?: "before" | "after";
|
|
52
|
+
}): string;
|
|
36
53
|
export declare function deleteBlock({ source, section, key, keyName }: {
|
|
37
54
|
source: string;
|
|
38
55
|
section: string;
|
|
39
56
|
key: string;
|
|
40
57
|
keyName?: string;
|
|
41
58
|
}): any;
|
|
59
|
+
export declare function deleteBlockWithPath({ source, path }: {
|
|
60
|
+
source: string;
|
|
61
|
+
path: string;
|
|
62
|
+
}): string;
|
|
42
63
|
export declare function isParentChildrenRelation({ source, sections, key1, key2, keyName }: {
|
|
43
64
|
source: string;
|
|
44
65
|
sections: string[];
|
|
@@ -1 +1 @@
|
|
|
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,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MAAM,EAAE,MAAM,CAAA;CAAE,EAChD,UAAU,EAAE,GAAG,OAelB;AAuDD,MAAM,MAAM,WAAW,GAAG;IACtB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC,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
|
@@ -702,4 +702,443 @@ describe("getLastBlock", () => {
|
|
|
702
702
|
});
|
|
703
703
|
expect(result).toBe("plugin3");
|
|
704
704
|
})
|
|
705
|
-
})
|
|
705
|
+
})
|
|
706
|
+
|
|
707
|
+
describe("insertBlockWithPath", () => {
|
|
708
|
+
const srcWithTasks = `
|
|
709
|
+
tasks:
|
|
710
|
+
- id: plugin1
|
|
711
|
+
type: type1
|
|
712
|
+
name: Plugin 1
|
|
713
|
+
- id: plugin2
|
|
714
|
+
type: type2
|
|
715
|
+
name: Plugin 2
|
|
716
|
+
`;
|
|
717
|
+
const newValue = `
|
|
718
|
+
id: plugin3
|
|
719
|
+
type: type3
|
|
720
|
+
name: Plugin 3
|
|
721
|
+
`;
|
|
722
|
+
|
|
723
|
+
test("inserting a task", () => {
|
|
724
|
+
|
|
725
|
+
const result = YamlUtils.insertBlockWithPath({
|
|
726
|
+
source: srcWithTasks,
|
|
727
|
+
parentPath: "tasks",
|
|
728
|
+
newBlock: newValue,
|
|
729
|
+
refPath: 0,
|
|
730
|
+
position: "after"
|
|
731
|
+
});
|
|
732
|
+
expect(result).toMatchInlineSnapshot(`
|
|
733
|
+
"tasks:
|
|
734
|
+
- id: plugin1
|
|
735
|
+
type: type1
|
|
736
|
+
name: Plugin 1
|
|
737
|
+
- id: plugin3
|
|
738
|
+
type: type3
|
|
739
|
+
name: Plugin 3
|
|
740
|
+
- id: plugin2
|
|
741
|
+
type: type2
|
|
742
|
+
name: Plugin 2
|
|
743
|
+
"
|
|
744
|
+
`)
|
|
745
|
+
})
|
|
746
|
+
|
|
747
|
+
test("inserting a task when no tasks section is present", () => {
|
|
748
|
+
const srcWithTriggers = `
|
|
749
|
+
triggers:
|
|
750
|
+
- id: plugin1
|
|
751
|
+
type: type1
|
|
752
|
+
name: Plugin 1
|
|
753
|
+
- id: plugin2
|
|
754
|
+
type: type2
|
|
755
|
+
name: Plugin 2
|
|
756
|
+
`;
|
|
757
|
+
|
|
758
|
+
const result = YamlUtils.insertBlockWithPath({
|
|
759
|
+
source: srcWithTriggers,
|
|
760
|
+
parentPath: "tasks",
|
|
761
|
+
newBlock: newValue,
|
|
762
|
+
});;
|
|
763
|
+
expect(result).toMatchInlineSnapshot(`
|
|
764
|
+
"triggers:
|
|
765
|
+
- id: plugin1
|
|
766
|
+
type: type1
|
|
767
|
+
name: Plugin 1
|
|
768
|
+
- id: plugin2
|
|
769
|
+
type: type2
|
|
770
|
+
name: Plugin 2
|
|
771
|
+
tasks:
|
|
772
|
+
- id: plugin3
|
|
773
|
+
type: type3
|
|
774
|
+
name: Plugin 3
|
|
775
|
+
"
|
|
776
|
+
`)
|
|
777
|
+
})
|
|
778
|
+
|
|
779
|
+
test("inserting a task as a subBlock of another task", () => {
|
|
780
|
+
const srcWithSubTasks = `
|
|
781
|
+
tasks:
|
|
782
|
+
- id: plugin1
|
|
783
|
+
type: type1
|
|
784
|
+
name: Plugin 1
|
|
785
|
+
tasks:
|
|
786
|
+
- id: plugin2
|
|
787
|
+
type: type2
|
|
788
|
+
name: Plugin 2
|
|
789
|
+
- id: plugin5
|
|
790
|
+
type: type5
|
|
791
|
+
name: Plugin 5
|
|
792
|
+
- id: plugin3
|
|
793
|
+
type: type3
|
|
794
|
+
name: Plugin 3
|
|
795
|
+
`;
|
|
796
|
+
const newValue = `
|
|
797
|
+
id: plugin4
|
|
798
|
+
type: type4
|
|
799
|
+
name: Plugin 4
|
|
800
|
+
`;
|
|
801
|
+
const result = YamlUtils.insertBlockWithPath({
|
|
802
|
+
source: srcWithSubTasks,
|
|
803
|
+
newBlock: newValue,
|
|
804
|
+
parentPath: "tasks[0].tasks",
|
|
805
|
+
refPath: 0,
|
|
806
|
+
position: "before"
|
|
807
|
+
});
|
|
808
|
+
expect(result).toMatchInlineSnapshot(`
|
|
809
|
+
"tasks:
|
|
810
|
+
- id: plugin1
|
|
811
|
+
type: type1
|
|
812
|
+
name: Plugin 1
|
|
813
|
+
tasks:
|
|
814
|
+
- id: plugin4
|
|
815
|
+
type: type4
|
|
816
|
+
name: Plugin 4
|
|
817
|
+
- id: plugin2
|
|
818
|
+
type: type2
|
|
819
|
+
name: Plugin 2
|
|
820
|
+
- id: plugin5
|
|
821
|
+
type: type5
|
|
822
|
+
name: Plugin 5
|
|
823
|
+
- id: plugin3
|
|
824
|
+
type: type3
|
|
825
|
+
name: Plugin 3
|
|
826
|
+
"
|
|
827
|
+
`)
|
|
828
|
+
})
|
|
829
|
+
|
|
830
|
+
test("inserting a condition on a trigger", () => {
|
|
831
|
+
const srcWithTriggers = `
|
|
832
|
+
triggers:
|
|
833
|
+
- id: plugin1
|
|
834
|
+
type: type1
|
|
835
|
+
name: Plugin 1
|
|
836
|
+
- id: plugin2
|
|
837
|
+
type: type2
|
|
838
|
+
name: Plugin 2
|
|
839
|
+
`;
|
|
840
|
+
|
|
841
|
+
const result = YamlUtils.insertBlockWithPath({
|
|
842
|
+
source: srcWithTriggers,
|
|
843
|
+
parentPath: "triggers[0].conditions",
|
|
844
|
+
newBlock: newValue,
|
|
845
|
+
});;
|
|
846
|
+
expect(result).toMatchInlineSnapshot(`
|
|
847
|
+
"triggers:
|
|
848
|
+
- id: plugin1
|
|
849
|
+
type: type1
|
|
850
|
+
name: Plugin 1
|
|
851
|
+
conditions:
|
|
852
|
+
- id: plugin3
|
|
853
|
+
type: type3
|
|
854
|
+
name: Plugin 3
|
|
855
|
+
- id: plugin2
|
|
856
|
+
type: type2
|
|
857
|
+
name: Plugin 2
|
|
858
|
+
"
|
|
859
|
+
`)
|
|
860
|
+
})
|
|
861
|
+
})
|
|
862
|
+
|
|
863
|
+
describe("deleteBlockWithPath", () => {
|
|
864
|
+
test("deleting a trigger", () => {
|
|
865
|
+
const yamlString = `
|
|
866
|
+
triggers:
|
|
867
|
+
- id: plugin1
|
|
868
|
+
type: type1
|
|
869
|
+
name: Plugin 1
|
|
870
|
+
- id: plugin2
|
|
871
|
+
type: type2
|
|
872
|
+
name: Plugin 2
|
|
873
|
+
`;
|
|
874
|
+
const result = YamlUtils.deleteBlockWithPath({
|
|
875
|
+
source: yamlString,
|
|
876
|
+
path: "triggers[0]"
|
|
877
|
+
});
|
|
878
|
+
expect(result).not.toContain("- id: plugin1");
|
|
879
|
+
})
|
|
880
|
+
|
|
881
|
+
test("deleting a task", () => {
|
|
882
|
+
const yamlString = `
|
|
883
|
+
tasks:
|
|
884
|
+
- id: plugin1
|
|
885
|
+
type: type1
|
|
886
|
+
name: Plugin 1
|
|
887
|
+
- id: plugin2
|
|
888
|
+
type: type2
|
|
889
|
+
name: Plugin 2
|
|
890
|
+
`;
|
|
891
|
+
const result = YamlUtils.deleteBlockWithPath({
|
|
892
|
+
source: yamlString,
|
|
893
|
+
path: "tasks[1]",
|
|
894
|
+
});
|
|
895
|
+
expect(result).not.toContain("- id: plugin2");
|
|
896
|
+
})
|
|
897
|
+
|
|
898
|
+
test("deleting a task with subtask", () => {
|
|
899
|
+
const yamlString = `
|
|
900
|
+
tasks:
|
|
901
|
+
- id: plugin1
|
|
902
|
+
type: type1
|
|
903
|
+
name: Plugin 1
|
|
904
|
+
tasks:
|
|
905
|
+
- id: plugin2
|
|
906
|
+
type: type2
|
|
907
|
+
name: Plugin 2
|
|
908
|
+
- id: plugin3
|
|
909
|
+
type: type3
|
|
910
|
+
name: Plugin 3
|
|
911
|
+
`;
|
|
912
|
+
const result = YamlUtils.deleteBlockWithPath({
|
|
913
|
+
source: yamlString,
|
|
914
|
+
path:"tasks[0].tasks[0]",
|
|
915
|
+
});
|
|
916
|
+
expect(result).not.toContain("- id: plugin2");
|
|
917
|
+
})
|
|
918
|
+
|
|
919
|
+
test("deleting a pluginDefaults", () => {
|
|
920
|
+
const yamlString = `
|
|
921
|
+
pluginDefaults:
|
|
922
|
+
- type: type1
|
|
923
|
+
name: Plugin 1
|
|
924
|
+
- type: type2
|
|
925
|
+
name: Plugin 2
|
|
926
|
+
`;
|
|
927
|
+
const result = YamlUtils.deleteBlockWithPath({
|
|
928
|
+
source: yamlString,
|
|
929
|
+
path:"pluginDefaults[0]",
|
|
930
|
+
});
|
|
931
|
+
expect(result).not.toContain("- type: type1");
|
|
932
|
+
})
|
|
933
|
+
})
|
|
934
|
+
|
|
935
|
+
describe("extractBlockWithPath", () => {
|
|
936
|
+
test("extracting a trigger", () => {
|
|
937
|
+
const yamlString = `
|
|
938
|
+
triggers:
|
|
939
|
+
- id: plugin1
|
|
940
|
+
type: type1
|
|
941
|
+
name: Plugin 1
|
|
942
|
+
- id: plugin2
|
|
943
|
+
type: type2
|
|
944
|
+
name: Plugin 2
|
|
945
|
+
`;
|
|
946
|
+
|
|
947
|
+
const result = YamlUtils.extractBlockWithPath({
|
|
948
|
+
source: yamlString,
|
|
949
|
+
path: "triggers[1]",
|
|
950
|
+
})
|
|
951
|
+
expect(result).toMatchInlineSnapshot(`
|
|
952
|
+
"id: plugin2
|
|
953
|
+
type: type2
|
|
954
|
+
name: Plugin 2
|
|
955
|
+
"
|
|
956
|
+
`);
|
|
957
|
+
})
|
|
958
|
+
test("extracting a sub-subtask", () => {
|
|
959
|
+
const yamlString = `
|
|
960
|
+
tasks:
|
|
961
|
+
- id: plugin1
|
|
962
|
+
type: type1
|
|
963
|
+
name: Plugin 1
|
|
964
|
+
tasks:
|
|
965
|
+
- id: plugin2
|
|
966
|
+
type: type2
|
|
967
|
+
name: Plugin 2
|
|
968
|
+
- id: plugin3
|
|
969
|
+
type: type3
|
|
970
|
+
name: Plugin 3
|
|
971
|
+
tasks:
|
|
972
|
+
- id: plugin4
|
|
973
|
+
type: type4
|
|
974
|
+
name: Plugin 4
|
|
975
|
+
- id: plugin5
|
|
976
|
+
type: type5
|
|
977
|
+
name: Plugin 5
|
|
978
|
+
`;
|
|
979
|
+
|
|
980
|
+
const result = YamlUtils.extractBlockWithPath({
|
|
981
|
+
source: yamlString,
|
|
982
|
+
path: "tasks[0].tasks[1].tasks[0]",
|
|
983
|
+
})
|
|
984
|
+
expect(result).toMatchInlineSnapshot(`
|
|
985
|
+
"id: plugin4
|
|
986
|
+
type: type4
|
|
987
|
+
name: Plugin 4
|
|
988
|
+
"
|
|
989
|
+
`)
|
|
990
|
+
})
|
|
991
|
+
})
|
|
992
|
+
|
|
993
|
+
describe("replaceBlockWithPath", () => {
|
|
994
|
+
test("replacing a trigger", () => {
|
|
995
|
+
const yamlString = `
|
|
996
|
+
triggers:
|
|
997
|
+
- id: plugin1
|
|
998
|
+
type: type1
|
|
999
|
+
name: Plugin 1
|
|
1000
|
+
- id: plugin2
|
|
1001
|
+
type: type2
|
|
1002
|
+
name: Plugin 2
|
|
1003
|
+
`;
|
|
1004
|
+
|
|
1005
|
+
const newValue = `
|
|
1006
|
+
id: plugin3
|
|
1007
|
+
type: type3
|
|
1008
|
+
name: Plugin 3
|
|
1009
|
+
`;
|
|
1010
|
+
|
|
1011
|
+
const result = YamlUtils.replaceBlockWithPath({
|
|
1012
|
+
source: yamlString,
|
|
1013
|
+
path: "triggers[1]",
|
|
1014
|
+
newContent: newValue
|
|
1015
|
+
})
|
|
1016
|
+
expect(result).toMatchInlineSnapshot(`
|
|
1017
|
+
"triggers:
|
|
1018
|
+
- id: plugin1
|
|
1019
|
+
type: type1
|
|
1020
|
+
name: Plugin 1
|
|
1021
|
+
- id: plugin3
|
|
1022
|
+
type: type3
|
|
1023
|
+
name: Plugin 3
|
|
1024
|
+
"
|
|
1025
|
+
`);
|
|
1026
|
+
})
|
|
1027
|
+
test("replacing a task", () => {
|
|
1028
|
+
const yamlString = `
|
|
1029
|
+
tasks:
|
|
1030
|
+
- id: plugin1
|
|
1031
|
+
type: type1
|
|
1032
|
+
name: Plugin 1
|
|
1033
|
+
- id: plugin2
|
|
1034
|
+
type: type2
|
|
1035
|
+
name: Plugin 2
|
|
1036
|
+
`;
|
|
1037
|
+
|
|
1038
|
+
const newValue = `
|
|
1039
|
+
id: plugin3
|
|
1040
|
+
type: type3
|
|
1041
|
+
name: Plugin 3
|
|
1042
|
+
`;
|
|
1043
|
+
|
|
1044
|
+
const result = YamlUtils.replaceBlockWithPath({
|
|
1045
|
+
source: yamlString,
|
|
1046
|
+
path: "tasks[1]",
|
|
1047
|
+
newContent: newValue
|
|
1048
|
+
})
|
|
1049
|
+
expect(result).toMatchInlineSnapshot(`
|
|
1050
|
+
"tasks:
|
|
1051
|
+
- id: plugin1
|
|
1052
|
+
type: type1
|
|
1053
|
+
name: Plugin 1
|
|
1054
|
+
- id: plugin3
|
|
1055
|
+
type: type3
|
|
1056
|
+
name: Plugin 3
|
|
1057
|
+
"
|
|
1058
|
+
`)
|
|
1059
|
+
})
|
|
1060
|
+
|
|
1061
|
+
test("replacing a task with subtask", () => {
|
|
1062
|
+
const yamlString = `
|
|
1063
|
+
tasks:
|
|
1064
|
+
- id: plugin1
|
|
1065
|
+
type: type1
|
|
1066
|
+
name: Plugin 1
|
|
1067
|
+
tasks:
|
|
1068
|
+
- id: plugin2
|
|
1069
|
+
type: type2
|
|
1070
|
+
name: Plugin 2
|
|
1071
|
+
- id: plugin3
|
|
1072
|
+
type: type3
|
|
1073
|
+
name: Plugin 3
|
|
1074
|
+
`;
|
|
1075
|
+
|
|
1076
|
+
const newValue = `
|
|
1077
|
+
id: plugin4
|
|
1078
|
+
type: type4
|
|
1079
|
+
name: Plugin 4
|
|
1080
|
+
`;
|
|
1081
|
+
|
|
1082
|
+
const result = YamlUtils.replaceBlockWithPath({
|
|
1083
|
+
source: yamlString,
|
|
1084
|
+
path: "tasks[0].tasks[1]",
|
|
1085
|
+
newContent: newValue
|
|
1086
|
+
})
|
|
1087
|
+
expect(result).toMatchInlineSnapshot(`
|
|
1088
|
+
"tasks:
|
|
1089
|
+
- id: plugin1
|
|
1090
|
+
type: type1
|
|
1091
|
+
name: Plugin 1
|
|
1092
|
+
tasks:
|
|
1093
|
+
- id: plugin2
|
|
1094
|
+
type: type2
|
|
1095
|
+
name: Plugin 2
|
|
1096
|
+
- id: plugin4
|
|
1097
|
+
type: type4
|
|
1098
|
+
name: Plugin 4
|
|
1099
|
+
"
|
|
1100
|
+
`)
|
|
1101
|
+
})
|
|
1102
|
+
|
|
1103
|
+
test("replace a condition in a trigger", () => {
|
|
1104
|
+
const yamlString = `
|
|
1105
|
+
triggers:
|
|
1106
|
+
- id: plugin1
|
|
1107
|
+
type: type1
|
|
1108
|
+
name: Plugin 1
|
|
1109
|
+
conditions:
|
|
1110
|
+
- id: plugin2
|
|
1111
|
+
type: type2
|
|
1112
|
+
name: Plugin 2
|
|
1113
|
+
- id: plugin3
|
|
1114
|
+
type: type3
|
|
1115
|
+
name: Plugin 3
|
|
1116
|
+
`;
|
|
1117
|
+
|
|
1118
|
+
const newValue = `
|
|
1119
|
+
id: plugin4
|
|
1120
|
+
type: type4
|
|
1121
|
+
name: Plugin 4
|
|
1122
|
+
`;
|
|
1123
|
+
|
|
1124
|
+
const result = YamlUtils.replaceBlockWithPath({
|
|
1125
|
+
source: yamlString,
|
|
1126
|
+
path: "triggers[0].conditions[1]",
|
|
1127
|
+
newContent: newValue
|
|
1128
|
+
})
|
|
1129
|
+
expect(result).toMatchInlineSnapshot(`
|
|
1130
|
+
"triggers:
|
|
1131
|
+
- id: plugin1
|
|
1132
|
+
type: type1
|
|
1133
|
+
name: Plugin 1
|
|
1134
|
+
conditions:
|
|
1135
|
+
- id: plugin2
|
|
1136
|
+
type: type2
|
|
1137
|
+
name: Plugin 2
|
|
1138
|
+
- id: plugin4
|
|
1139
|
+
type: type4
|
|
1140
|
+
name: Plugin 4
|
|
1141
|
+
"
|
|
1142
|
+
`)
|
|
1143
|
+
})
|
|
1144
|
+
})
|
|
@@ -152,7 +152,7 @@ function extractBlockFromDocument({yamlDoc, keyName, key, callback}: {
|
|
|
152
152
|
* Callback function to modify the found element
|
|
153
153
|
* @param element The found YAMLMap element
|
|
154
154
|
*/
|
|
155
|
-
callback?: (element: YAMLMap<{ value: string }, string | Node>) =>
|
|
155
|
+
callback?: (element: YAMLMap<{ value: string }, string | Node>) => any,
|
|
156
156
|
}) {
|
|
157
157
|
function find(element?: Node): Node | void {
|
|
158
158
|
if (!element) {
|
|
@@ -199,6 +199,51 @@ function extractBlockFromDocument({yamlDoc, keyName, key, callback}: {
|
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
201
|
|
|
202
|
+
export function extractBlockWithPath({source, path}: {
|
|
203
|
+
source: string,
|
|
204
|
+
path: string
|
|
205
|
+
}) {
|
|
206
|
+
const doc = extractBlockWithPathFromDocument({
|
|
207
|
+
yamlDoc: parseDocument(source) as Document<YAMLMap<{ value: string }, Node>>,
|
|
208
|
+
path
|
|
209
|
+
});
|
|
210
|
+
if (!doc) {
|
|
211
|
+
return undefined;
|
|
212
|
+
}
|
|
213
|
+
return new Document(doc).toString(TOSTRING_OPTIONS);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function extractBlockWithPathFromDocument({yamlDoc, path, callback}: {
|
|
217
|
+
yamlDoc: Document<YAMLMap<{ value: string }, Node>>,
|
|
218
|
+
path: string,
|
|
219
|
+
callback?: (element: YAMLMap<{ value: string }, Node>) => any
|
|
220
|
+
}) {
|
|
221
|
+
const parsedPath = parsePath(path);
|
|
222
|
+
const element = yamlDoc.getIn(parsedPath) as YAMLMap<{ value: string }, Node>;
|
|
223
|
+
if (element === undefined) {
|
|
224
|
+
return undefined;
|
|
225
|
+
}
|
|
226
|
+
if (callback) {
|
|
227
|
+
const replacedEl = callback(element);
|
|
228
|
+
yamlDoc.setIn(parsedPath, replacedEl);
|
|
229
|
+
return new Document(replacedEl);
|
|
230
|
+
}
|
|
231
|
+
return new Document(element);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export function replaceBlockWithPath({source, path, newContent}: {
|
|
235
|
+
source: string,
|
|
236
|
+
path: string,
|
|
237
|
+
newContent: string
|
|
238
|
+
}) {
|
|
239
|
+
const {yamlDoc} = getSectionNodeAndDocumentFromSource({source, section: ""});
|
|
240
|
+
const newItem = yamlDoc.createNode(parseDocument(newContent));
|
|
241
|
+
|
|
242
|
+
yamlDoc.setIn(parsePath(path), newItem);
|
|
243
|
+
|
|
244
|
+
return yamlDoc.toString(TOSTRING_OPTIONS);
|
|
245
|
+
}
|
|
246
|
+
|
|
202
247
|
export function replaceBlockInDocument({source, section, keyName, key, newContent}: {
|
|
203
248
|
source: string,
|
|
204
249
|
section: string,
|
|
@@ -381,6 +426,90 @@ export function insertBlock({source,
|
|
|
381
426
|
return cleanMetadataDocument(yamlDoc).toString(TOSTRING_OPTIONS);
|
|
382
427
|
}
|
|
383
428
|
|
|
429
|
+
function getNodeIndexInParent(
|
|
430
|
+
yamlDoc: Document<YAMLMap<{ value: string }, Node>>,
|
|
431
|
+
patentNode: YAMLMap<{ value: string }, Node>,
|
|
432
|
+
parentPath: (string|number)[],
|
|
433
|
+
refPath?: string | number,
|
|
434
|
+
position: "before" | "after" = "after"
|
|
435
|
+
) {
|
|
436
|
+
if (refPath === undefined) {
|
|
437
|
+
return position === "before" ? 0 : patentNode.items.length - 1;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
const indexNode = yamlDoc.getIn([...parentPath, refPath]) as any;
|
|
441
|
+
|
|
442
|
+
return patentNode.items.indexOf(indexNode);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
export function parsePath(path: string) {
|
|
446
|
+
const pathParts = path.split(".");
|
|
447
|
+
return pathParts.reduce((acc: (string|number)[], part) => {
|
|
448
|
+
// if the path has a number, it will look like this
|
|
449
|
+
// path[0]
|
|
450
|
+
|
|
451
|
+
const numberPath = part.match(/\[(\d+)\]$/)
|
|
452
|
+
if (numberPath?.[0]) {
|
|
453
|
+
acc.push(part.slice(0, numberPath.index));
|
|
454
|
+
acc.push(parseInt(numberPath[1], 10));
|
|
455
|
+
} else {
|
|
456
|
+
acc.push(part);
|
|
457
|
+
}
|
|
458
|
+
return acc;
|
|
459
|
+
}, [])
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
export function insertBlockWithPath({
|
|
463
|
+
source,
|
|
464
|
+
newBlock,
|
|
465
|
+
refPath,
|
|
466
|
+
position,
|
|
467
|
+
parentPath,
|
|
468
|
+
}: {
|
|
469
|
+
source: string,
|
|
470
|
+
parentPath: string,
|
|
471
|
+
newBlock: string,
|
|
472
|
+
refPath?: string | number,
|
|
473
|
+
position?: "before" | "after",
|
|
474
|
+
}){
|
|
475
|
+
if (!position) {
|
|
476
|
+
position = "after";
|
|
477
|
+
}
|
|
478
|
+
const yamlDoc = parseDocument(source) as Document<YAMLMap<{ value: string }, Node>>;
|
|
479
|
+
const newPropNode = yamlDoc.createNode(parseDocument(newBlock)) as any;
|
|
480
|
+
|
|
481
|
+
const parsedPath = parsePath(parentPath);
|
|
482
|
+
|
|
483
|
+
const parentNode = yamlDoc.getIn(parsedPath) as YAMLMap<{ value: string }, Node>;
|
|
484
|
+
if (!parentNode) {
|
|
485
|
+
const newParentNode = new YAMLSeq();
|
|
486
|
+
newParentNode.add(newPropNode);
|
|
487
|
+
const parentKey = parentPath.split(".").pop() as string;
|
|
488
|
+
const parentKeyNode = new Pair(new Scalar(parentKey), newParentNode);
|
|
489
|
+
if(parentKey.length === parentPath.length){
|
|
490
|
+
yamlDoc.contents?.items.push(parentKeyNode);
|
|
491
|
+
return yamlDoc.toString(TOSTRING_OPTIONS);
|
|
492
|
+
} else {
|
|
493
|
+
const parentPathWithoutKey = parentPath.substring(0, parentPath.length - parentKey.length - 1);
|
|
494
|
+
const parentNode = yamlDoc.getIn(parsePath(parentPathWithoutKey)) as YAMLMap<{ value: string }, Node>;
|
|
495
|
+
if (!parentNode) {
|
|
496
|
+
throw new Error(`Parent block with path ${parentPathWithoutKey} not found`);
|
|
497
|
+
}
|
|
498
|
+
parentNode.items.push(parentKeyNode);
|
|
499
|
+
return yamlDoc.toString(TOSTRING_OPTIONS);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
const index = getNodeIndexInParent(yamlDoc, parentNode, parsedPath, refPath);
|
|
503
|
+
if (position === "before") {
|
|
504
|
+
parentNode.items.splice(index, 0, newPropNode);
|
|
505
|
+
} else {
|
|
506
|
+
parentNode.items.splice(index + 1, 0, newPropNode);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
return yamlDoc.toString(TOSTRING_OPTIONS);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
|
|
384
513
|
export function deleteBlock({source, section, key, keyName}: {
|
|
385
514
|
source: string,
|
|
386
515
|
section: string,
|
|
@@ -416,6 +545,22 @@ export function deleteBlock({source, section, key, keyName}: {
|
|
|
416
545
|
return yamlDoc.toString(TOSTRING_OPTIONS);
|
|
417
546
|
}
|
|
418
547
|
|
|
548
|
+
|
|
549
|
+
export function deleteBlockWithPath({source, path}: {
|
|
550
|
+
source: string,
|
|
551
|
+
path: string,
|
|
552
|
+
}) {
|
|
553
|
+
const yamlDoc = parseDocument(source) as Document<YAMLMap<{ value: string }, Node>>;
|
|
554
|
+
const parsedPath = parsePath(path)
|
|
555
|
+
const parentNode = yamlDoc.getIn(parsedPath.slice(0, -1)) as YAMLMap<{ value: string }, Node>;
|
|
556
|
+
if (!parentNode) {
|
|
557
|
+
return source;
|
|
558
|
+
}
|
|
559
|
+
const index = getNodeIndexInParent(yamlDoc, parentNode, parsedPath.slice(0, -1), parsedPath[parsedPath.length - 1]);
|
|
560
|
+
parentNode.items.splice(index, 1);
|
|
561
|
+
return yamlDoc.toString(TOSTRING_OPTIONS);
|
|
562
|
+
}
|
|
563
|
+
|
|
419
564
|
function isChildrenOf(source: string, section: string, parentKey: string, childKey: string, keyName: string) {
|
|
420
565
|
const {sectionNode} = getSectionNodeAndDocumentFromSource({source, section});
|
|
421
566
|
if (!sectionNode) {
|
|
@@ -483,8 +628,7 @@ export function getLastBlock({source, section, parentKey, keyName, subBlockName}
|
|
|
483
628
|
parentKey?: string,
|
|
484
629
|
keyName?: string,
|
|
485
630
|
subBlockName?: string
|
|
486
|
-
}
|
|
487
|
-
): string | undefined {
|
|
631
|
+
}): string | undefined {
|
|
488
632
|
if (!keyName) {
|
|
489
633
|
keyName = "id";
|
|
490
634
|
}
|