@kestra-io/ui-libs 0.0.193 → 0.0.195
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-ASfcewm6.js +1935 -0
- package/dist/FlowYamlUtils-ASfcewm6.js.map +1 -0
- package/dist/FlowYamlUtils-CiOAxQr3.cjs +2 -0
- package/dist/FlowYamlUtils-CiOAxQr3.cjs.map +1 -0
- package/dist/kestra-flowyamlutils.cjs.js +1 -1
- package/dist/kestra-flowyamlutils.es.js +27 -25
- package/dist/kestra-index.cjs.js +1 -1
- package/dist/kestra-index.cjs.js.map +1 -1
- package/dist/kestra-index.es.js +1125 -1124
- package/dist/kestra-index.es.js.map +1 -1
- package/dist/utils/FlowYamlUtils.d.ts +16 -3
- package/dist/utils/FlowYamlUtils.d.ts.map +1 -1
- package/dist/utils/YamlUtilsLegacy.d.ts +3 -2
- package/dist/utils/YamlUtilsLegacy.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/utils/FlowYamlUtils.test.ts +133 -0
- package/src/utils/FlowYamlUtils.ts +126 -11
- package/src/utils/YamlUtilsLegacy.ts +4 -1
- package/dist/FlowYamlUtils-E3EN5bb4.js +0 -1874
- package/dist/FlowYamlUtils-E3EN5bb4.js.map +0 -1
- package/dist/FlowYamlUtils-wL6s2KD7.cjs +0 -2
- package/dist/FlowYamlUtils-wL6s2KD7.cjs.map +0 -1
|
@@ -3,6 +3,11 @@ export declare function parse<T = any>(item?: string, throwIfError?: boolean): T
|
|
|
3
3
|
export declare function stringify(item: any): string;
|
|
4
4
|
export declare function sort(value: Record<string, any>): string[];
|
|
5
5
|
export declare function pairsToMap(pairs?: any[]): YAMLMap<unknown, unknown>;
|
|
6
|
+
export declare function getPathFromSectionAndId({ source, section, id, }: {
|
|
7
|
+
source: string;
|
|
8
|
+
section: string;
|
|
9
|
+
id: string;
|
|
10
|
+
}): string | undefined;
|
|
6
11
|
export declare function extractBlock({ source, section, key, keyName }: {
|
|
7
12
|
source: string;
|
|
8
13
|
section: string;
|
|
@@ -55,7 +60,7 @@ export declare function deleteBlock({ source, section, key, keyName }: {
|
|
|
55
60
|
section: string;
|
|
56
61
|
key: string;
|
|
57
62
|
keyName?: string;
|
|
58
|
-
}):
|
|
63
|
+
}): string;
|
|
59
64
|
export declare function deleteBlockWithPath({ source, path }: {
|
|
60
65
|
source: string;
|
|
61
66
|
path: string;
|
|
@@ -92,7 +97,7 @@ export declare function deleteMetadata(source: any, metadata: any): any;
|
|
|
92
97
|
export declare function flowHaveTasks(source: string): boolean;
|
|
93
98
|
export declare function extractPluginDefault(source: string, pluginType: string): string | undefined;
|
|
94
99
|
export declare function replacePluginDefaultsInDocument(source: string, pluginType: string, newContent: string): string | undefined;
|
|
95
|
-
export declare function deletePluginDefaults(source: string, pluginType: string):
|
|
100
|
+
export declare function deletePluginDefaults(source: string, pluginType: string): string;
|
|
96
101
|
export declare function insertErrorInFlowable(source: string, errorTask: string, flowableTask: string): any;
|
|
97
102
|
/**
|
|
98
103
|
* Specify a source yaml doc, the field to extract recursively in every map of the doc and optionally
|
|
@@ -100,7 +105,7 @@ export declare function insertErrorInFlowable(source: string, errorTask: string,
|
|
|
100
105
|
* will take a single argument which is the path of each parent property starting from the root doc (joined with ".")
|
|
101
106
|
* "my.parent.task" will mean that the field was retrieved in my -> parent -> task path.
|
|
102
107
|
*/
|
|
103
|
-
export declare function extractFieldFromMaps<T extends string>(source: string, fieldName: T, parentPathPredicate?: (_: any, __?: any) => boolean, valuePredicate?: (_: any) => boolean): (Record<T, any> & {
|
|
108
|
+
export declare function extractFieldFromMaps<T extends string>(source: string, fieldName: T, parentPathPredicate?: (_: any, __?: any) => boolean, valuePredicate?: (_: any) => boolean, keepEmptyFields?: boolean): (Record<T, any> & {
|
|
104
109
|
range: Range;
|
|
105
110
|
})[];
|
|
106
111
|
/**
|
|
@@ -111,6 +116,14 @@ export declare function getTypeAtPosition(source: string, position: {
|
|
|
111
116
|
lineNumber: number;
|
|
112
117
|
column: number;
|
|
113
118
|
}, validTypes: any): any;
|
|
119
|
+
/**
|
|
120
|
+
* Get task version at cursor position.
|
|
121
|
+
* Useful to display/update the live docs
|
|
122
|
+
*/
|
|
123
|
+
export declare function getVersionAtPosition(source: string, position: {
|
|
124
|
+
lineNumber: number;
|
|
125
|
+
column: number;
|
|
126
|
+
}): any;
|
|
114
127
|
export type YamlElement = {
|
|
115
128
|
key?: string;
|
|
116
129
|
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,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;
|
|
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,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W,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"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import yaml from "yaml";
|
|
2
|
-
import { cleanMetadata, deleteMetadata, deletePluginDefaults, extractPluginDefault, flowHaveTasks, getAllCharts, getChartAtPosition, getMetadata, getTypeAtPosition as getTaskType, insertErrorInFlowable, localizeElementAtIndex, pairsToMap, parse, replaceIdAndNamespace, replacePluginDefaultsInDocument, sort, stringify, updateMetadata, extractFieldFromMaps } from "./FlowYamlUtils";
|
|
2
|
+
import { cleanMetadata, deleteMetadata, deletePluginDefaults, extractPluginDefault, flowHaveTasks, getAllCharts, getChartAtPosition, getMetadata, getVersionAtPosition, getTypeAtPosition as getTaskType, insertErrorInFlowable, localizeElementAtIndex, pairsToMap, parse, replaceIdAndNamespace, replacePluginDefaultsInDocument, sort, stringify, updateMetadata, extractFieldFromMaps } from "./FlowYamlUtils";
|
|
3
3
|
export type YamlElement = {
|
|
4
4
|
key?: string;
|
|
5
5
|
value: Record<string, any>;
|
|
@@ -32,7 +32,7 @@ export declare const YamlUtils: {
|
|
|
32
32
|
* @param id the id of the item to delete
|
|
33
33
|
* @returns yaml (source) without the item
|
|
34
34
|
*/
|
|
35
|
-
deleteSection(source: string, section: string, id: string):
|
|
35
|
+
deleteSection(source: string, section: string, id: string): string;
|
|
36
36
|
deleteTask(source: string, taskId: string, section: string): string;
|
|
37
37
|
getLastTask(source: string, parentTaskId?: string): string | undefined;
|
|
38
38
|
checkTaskAlreadyExist(source: string, taskYaml: string): any;
|
|
@@ -47,5 +47,6 @@ export declare const YamlUtils: {
|
|
|
47
47
|
replacePluginDefaultsInDocument: typeof replacePluginDefaultsInDocument;
|
|
48
48
|
deletePluginDefaults: typeof deletePluginDefaults;
|
|
49
49
|
extractFieldFromMaps: typeof extractFieldFromMaps;
|
|
50
|
+
getVersionAtPosition: typeof getVersionAtPosition;
|
|
50
51
|
};
|
|
51
52
|
//# sourceMappingURL=YamlUtilsLegacy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"YamlUtilsLegacy.d.ts","sourceRoot":"","sources":["../../src/utils/YamlUtilsLegacy.ts"],"names":[],"mappings":"AAAA,OAAO,IAGN,MAAM,MAAM,CAAC;AAEd,OAAO,EAEH,aAAa,EAAE,cAAc,EAC7B,oBAAoB,EAEpB,oBAAoB,EAEpB,aAAa,EAAE,YAAY,EAAE,kBAAkB,EAAgB,WAAW,
|
|
1
|
+
{"version":3,"file":"YamlUtilsLegacy.d.ts","sourceRoot":"","sources":["../../src/utils/YamlUtilsLegacy.ts"],"names":[],"mappings":"AAAA,OAAO,IAGN,MAAM,MAAM,CAAC;AAEd,OAAO,EAEH,aAAa,EAAE,cAAc,EAC7B,oBAAoB,EAEpB,oBAAoB,EAEpB,aAAa,EAAE,YAAY,EAAE,kBAAkB,EAAgB,WAAW,EAAE,oBAAoB,EAChG,iBAAiB,IAAI,WAAW,EAChC,qBAAqB,EAGrB,sBAAsB,EACtB,UAAU,EAAE,KAAK,EACjB,qBAAqB,EACrB,+BAA+B,EAE/B,IAAI,EAAE,SAAS,EAAE,cAAc,EAC/B,oBAAoB,EACvB,MAAM,iBAAiB,CAAC;AAEzB,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;AAYF;;GAEG;AACH,eAAO,MAAM,SAAS;;;;wBAIE,MAAM,UAAU,MAAM;0BAY7B,UAAU,CAAC,OAAO,IAAI,CAAC,aAAa,CAAC,UACtC,MAAM,aACH,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,KAAK,IAAI;kCAoD1B,MAAM,UAAU,MAAM,cAAc,MAAM,UAAS,MAAM,YAAqB,MAAM;;;;;;sBAoBhG,MAAM,WAAW,MAAM,WAAW,MAAM;uBA2B9C,MAAM,UACN,MAAM,WACL,MAAM,kBACC,QAAQ,GAAG,OAAO,iBACnB,MAAM;+BAME,MAAM,UAAU,MAAM,QAAQ,MAAM;;IAM/D;;;;;;OAMG;0BACmB,MAAM,WAAW,MAAM,MAAM,MAAM;uBAItC,MAAM,UAAU,MAAM,WAAW,MAAM;wBAMtC,MAAM,iBAAiB,MAAM,GAAG,MAAM,GAAG,SAAS;kCAIxC,MAAM,YAAY,MAAM;qCASrB,MAAM,SAAS,MAAM,SAAS,MAAM;;;;;;;;;;;;CAgCxE,CAAC"}
|
package/package.json
CHANGED
|
@@ -596,6 +596,56 @@ describe("extractFieldFromMaps", () => {
|
|
|
596
596
|
`;
|
|
597
597
|
const result = YamlUtils.extractFieldFromMaps(yaml, "labels");
|
|
598
598
|
expect(result).toEqual([]);
|
|
599
|
+
});
|
|
600
|
+
test("extract fields given keepEmptyFields equals true", () => {
|
|
601
|
+
const yaml = `
|
|
602
|
+
tasks:
|
|
603
|
+
- id: task1
|
|
604
|
+
type: io.kestra.plugin.core.log.Log
|
|
605
|
+
version: 0.0.1
|
|
606
|
+
- id: task2
|
|
607
|
+
type: io.kestra.plugin.core.log.Log
|
|
608
|
+
- id: task3
|
|
609
|
+
type: io.kestra.plugin.core.log.Log
|
|
610
|
+
version: 0.0.2
|
|
611
|
+
`;
|
|
612
|
+
const result = YamlUtils.extractFieldFromMaps(yaml, "version", () => true, () => true, true);
|
|
613
|
+
expect(result).toMatchInlineSnapshot(`
|
|
614
|
+
[
|
|
615
|
+
{
|
|
616
|
+
"range": [
|
|
617
|
+
9,
|
|
618
|
+
280,
|
|
619
|
+
280,
|
|
620
|
+
],
|
|
621
|
+
"version": undefined,
|
|
622
|
+
},
|
|
623
|
+
{
|
|
624
|
+
"range": [
|
|
625
|
+
28,
|
|
626
|
+
113,
|
|
627
|
+
113,
|
|
628
|
+
],
|
|
629
|
+
"version": "0.0.1",
|
|
630
|
+
},
|
|
631
|
+
{
|
|
632
|
+
"range": [
|
|
633
|
+
125,
|
|
634
|
+
183,
|
|
635
|
+
183,
|
|
636
|
+
],
|
|
637
|
+
"version": undefined,
|
|
638
|
+
},
|
|
639
|
+
{
|
|
640
|
+
"range": [
|
|
641
|
+
195,
|
|
642
|
+
280,
|
|
643
|
+
280,
|
|
644
|
+
],
|
|
645
|
+
"version": "0.0.2",
|
|
646
|
+
},
|
|
647
|
+
]
|
|
648
|
+
`);
|
|
599
649
|
})
|
|
600
650
|
})
|
|
601
651
|
|
|
@@ -930,6 +980,20 @@ describe("deleteBlockWithPath", () => {
|
|
|
930
980
|
});
|
|
931
981
|
expect(result).not.toContain("- type: type1");
|
|
932
982
|
})
|
|
983
|
+
|
|
984
|
+
test("deleting a section when empty", () => {
|
|
985
|
+
const yamlString = `
|
|
986
|
+
tasks:
|
|
987
|
+
- type: type1
|
|
988
|
+
name: Plugin 1
|
|
989
|
+
`;
|
|
990
|
+
const result = YamlUtils.deleteBlockWithPath({
|
|
991
|
+
source: yamlString,
|
|
992
|
+
path:"tasks[0]",
|
|
993
|
+
});
|
|
994
|
+
expect(result).not.toContain("tasks:");
|
|
995
|
+
})
|
|
996
|
+
|
|
933
997
|
})
|
|
934
998
|
|
|
935
999
|
describe("extractBlockWithPath", () => {
|
|
@@ -1142,3 +1206,72 @@ describe("replaceBlockWithPath", () => {
|
|
|
1142
1206
|
`)
|
|
1143
1207
|
})
|
|
1144
1208
|
})
|
|
1209
|
+
|
|
1210
|
+
describe("getPathFromSectionAndId", () => {
|
|
1211
|
+
test("get path from id", () => {
|
|
1212
|
+
const yamlString = `
|
|
1213
|
+
tasks:
|
|
1214
|
+
- id: plugin1
|
|
1215
|
+
type: type1
|
|
1216
|
+
name: Plugin 1
|
|
1217
|
+
- id: plugin2
|
|
1218
|
+
type: type2
|
|
1219
|
+
name: Plugin 2
|
|
1220
|
+
`;
|
|
1221
|
+
const result = YamlUtils.getPathFromSectionAndId({
|
|
1222
|
+
source: yamlString,
|
|
1223
|
+
section: "tasks",
|
|
1224
|
+
id: "plugin2"
|
|
1225
|
+
});
|
|
1226
|
+
expect(result).toBe("tasks[1]");
|
|
1227
|
+
})
|
|
1228
|
+
|
|
1229
|
+
test("get path from id with subtask", () => {
|
|
1230
|
+
const yamlString = `
|
|
1231
|
+
tasks:
|
|
1232
|
+
- id: plugin1
|
|
1233
|
+
type: type1
|
|
1234
|
+
name: Plugin 1
|
|
1235
|
+
tasks:
|
|
1236
|
+
- id: plugin2
|
|
1237
|
+
type: type2
|
|
1238
|
+
name: Plugin 2
|
|
1239
|
+
- id: plugin3
|
|
1240
|
+
type: type3
|
|
1241
|
+
name: Plugin 3
|
|
1242
|
+
`;
|
|
1243
|
+
const result = YamlUtils.getPathFromSectionAndId({
|
|
1244
|
+
source: yamlString,
|
|
1245
|
+
section: "tasks",
|
|
1246
|
+
id: "plugin3"
|
|
1247
|
+
});
|
|
1248
|
+
expect(result).toBe("tasks[0].tasks[1]");
|
|
1249
|
+
})
|
|
1250
|
+
|
|
1251
|
+
test("get path from id with subCondition", () => {
|
|
1252
|
+
const yamlString = `
|
|
1253
|
+
triggers:
|
|
1254
|
+
- id: plugin1
|
|
1255
|
+
type: type1
|
|
1256
|
+
name: Plugin 1
|
|
1257
|
+
conditions:
|
|
1258
|
+
- id: plugin2
|
|
1259
|
+
type: type2
|
|
1260
|
+
name: Plugin 2
|
|
1261
|
+
- id: plugin3
|
|
1262
|
+
type: type3
|
|
1263
|
+
name: Plugin 3
|
|
1264
|
+
- id: plugin4
|
|
1265
|
+
type: type4
|
|
1266
|
+
name: Plugin 4
|
|
1267
|
+
|
|
1268
|
+
`;
|
|
1269
|
+
const result = YamlUtils.getPathFromSectionAndId({
|
|
1270
|
+
source: yamlString,
|
|
1271
|
+
section: "triggers",
|
|
1272
|
+
id: "plugin3"
|
|
1273
|
+
});
|
|
1274
|
+
expect(result).toBe("triggers[0].conditions[1]");
|
|
1275
|
+
})
|
|
1276
|
+
|
|
1277
|
+
})
|
|
@@ -103,22 +103,96 @@ function getSectionNodeAndDocumentFromSource({source, section}: {
|
|
|
103
103
|
source: string,
|
|
104
104
|
section: string
|
|
105
105
|
}) {
|
|
106
|
-
const yamlDoc =
|
|
106
|
+
const yamlDoc = parseDocumentTyped(source);
|
|
107
107
|
const sectionNode = getSectionFromDocument({yamlDoc, section});
|
|
108
108
|
return {yamlDoc, sectionNode};
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
function parseDocumentTyped(source: string) {
|
|
112
|
+
return parseDocument(source) as Document<YAMLMap<{ value: string }, Node>>;
|
|
113
|
+
}
|
|
114
|
+
|
|
111
115
|
function getSectionFromDocument({yamlDoc, section}:
|
|
112
116
|
{
|
|
113
117
|
yamlDoc: Document<YAMLMap<{ value: string }, Node>>,
|
|
114
118
|
section: string
|
|
115
119
|
}) {
|
|
116
|
-
const sectionNode = yamlDoc.contents?.items
|
|
120
|
+
const sectionNode = yamlDoc.contents?.items?.find(
|
|
117
121
|
(e) => e.key.value === section
|
|
118
122
|
) as { value: YAMLSeq<YAMLMap<{ value: string }, Node>> } | undefined;
|
|
119
123
|
return sectionNode?.value;
|
|
120
124
|
}
|
|
121
125
|
|
|
126
|
+
function getPathFromId({node, id} : {
|
|
127
|
+
node: Node,
|
|
128
|
+
id: string
|
|
129
|
+
}): (string | number)[] {
|
|
130
|
+
// recursively search for the id in the node
|
|
131
|
+
if (isSeq<{ value: Node }>(node)) {
|
|
132
|
+
let index = 0
|
|
133
|
+
for (const item of node.items) {
|
|
134
|
+
if (isMap<{ value: string }, Node>(item)) {
|
|
135
|
+
const itemId = item.get("id") as string | undefined;
|
|
136
|
+
if (itemId === id) {
|
|
137
|
+
return [index];
|
|
138
|
+
} else {
|
|
139
|
+
const path = getPathFromId({node: item, id});
|
|
140
|
+
if (path.length > 0) {
|
|
141
|
+
return [index, ...path];
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
index++;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if( isMap<{ value: string }, Node>(node)) {
|
|
150
|
+
const itemId = node.get("id") as string | undefined;
|
|
151
|
+
if (itemId === id) {
|
|
152
|
+
return [];
|
|
153
|
+
} else {
|
|
154
|
+
for (const item of node.items) {
|
|
155
|
+
if(item.value) {
|
|
156
|
+
const path = getPathFromId({node: item.value, id});
|
|
157
|
+
if (path.length > 0) {
|
|
158
|
+
return [item.key.value, ...path];
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return []
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function getPathFromSectionAndId({
|
|
169
|
+
source,
|
|
170
|
+
section,
|
|
171
|
+
id,
|
|
172
|
+
}: {
|
|
173
|
+
source: string,
|
|
174
|
+
section: string,
|
|
175
|
+
id: string
|
|
176
|
+
}): string | undefined {
|
|
177
|
+
const {sectionNode} = getSectionNodeAndDocumentFromSource({source, section});
|
|
178
|
+
if (!sectionNode) {
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const pathArray = getPathFromId({node: sectionNode, id})
|
|
183
|
+
const path = pathArray.map((e) => {
|
|
184
|
+
if (typeof e === "string") {
|
|
185
|
+
return `.${e}`;
|
|
186
|
+
} else {
|
|
187
|
+
return `[${e}]`;
|
|
188
|
+
}
|
|
189
|
+
}).join("");
|
|
190
|
+
|
|
191
|
+
return `${section}${path}`;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
122
196
|
export function extractBlock({source, section, key, keyName}: {
|
|
123
197
|
source: string,
|
|
124
198
|
section: string,
|
|
@@ -204,7 +278,7 @@ export function extractBlockWithPath({source, path}: {
|
|
|
204
278
|
path: string
|
|
205
279
|
}) {
|
|
206
280
|
const doc = extractBlockWithPathFromDocument({
|
|
207
|
-
yamlDoc:
|
|
281
|
+
yamlDoc: parseDocumentTyped(source),
|
|
208
282
|
path
|
|
209
283
|
});
|
|
210
284
|
if (!doc) {
|
|
@@ -236,7 +310,7 @@ export function replaceBlockWithPath({source, path, newContent}: {
|
|
|
236
310
|
path: string,
|
|
237
311
|
newContent: string
|
|
238
312
|
}) {
|
|
239
|
-
const
|
|
313
|
+
const yamlDoc = parseDocumentTyped(source);
|
|
240
314
|
const newItem = yamlDoc.createNode(parseDocument(newContent));
|
|
241
315
|
|
|
242
316
|
yamlDoc.setIn(parsePath(path), newItem);
|
|
@@ -475,7 +549,7 @@ export function insertBlockWithPath({
|
|
|
475
549
|
if (!position) {
|
|
476
550
|
position = "after";
|
|
477
551
|
}
|
|
478
|
-
const yamlDoc =
|
|
552
|
+
const yamlDoc = parseDocumentTyped(source);
|
|
479
553
|
const newPropNode = yamlDoc.createNode(parseDocument(newBlock)) as any;
|
|
480
554
|
|
|
481
555
|
const parsedPath = parsePath(parentPath);
|
|
@@ -519,7 +593,7 @@ export function deleteBlock({source, section, key, keyName}: {
|
|
|
519
593
|
if (!keyName) {
|
|
520
594
|
keyName = "id";
|
|
521
595
|
}
|
|
522
|
-
const yamlDoc =
|
|
596
|
+
const yamlDoc = parseDocumentTyped(source);
|
|
523
597
|
visit(yamlDoc, {
|
|
524
598
|
Pair(_, pair: any) {
|
|
525
599
|
if (pair.key.value === section) {
|
|
@@ -550,14 +624,19 @@ export function deleteBlockWithPath({source, path}: {
|
|
|
550
624
|
source: string,
|
|
551
625
|
path: string,
|
|
552
626
|
}) {
|
|
553
|
-
const yamlDoc =
|
|
627
|
+
const yamlDoc = parseDocumentTyped(source);
|
|
554
628
|
const parsedPath = parsePath(path)
|
|
555
|
-
const
|
|
629
|
+
const parsedParentPath = parsedPath.slice(0, -1);
|
|
630
|
+
const parentNode = yamlDoc.getIn(parsedParentPath) as YAMLMap<{ value: string }, Node>;
|
|
556
631
|
if (!parentNode) {
|
|
557
632
|
return source;
|
|
558
633
|
}
|
|
559
634
|
const index = getNodeIndexInParent(yamlDoc, parentNode, parsedPath.slice(0, -1), parsedPath[parsedPath.length - 1]);
|
|
560
|
-
parentNode.items.
|
|
635
|
+
if (parentNode.items.length === 1) {
|
|
636
|
+
yamlDoc.deleteIn(parsedParentPath);
|
|
637
|
+
} else {
|
|
638
|
+
parentNode.items.splice(index, 1);
|
|
639
|
+
}
|
|
561
640
|
return yamlDoc.toString(TOSTRING_OPTIONS);
|
|
562
641
|
}
|
|
563
642
|
|
|
@@ -741,7 +820,7 @@ function cleanMetadataDocument(yamlDoc: Document<YAMLMap<{ value: string }, Node
|
|
|
741
820
|
}
|
|
742
821
|
|
|
743
822
|
export function cleanMetadata(source: string) {
|
|
744
|
-
const yamlDoc =
|
|
823
|
+
const yamlDoc = parseDocumentTyped(source);
|
|
745
824
|
const cleanedYamlDoc = cleanMetadataDocument(yamlDoc);
|
|
746
825
|
return cleanedYamlDoc.toString(TOSTRING_OPTIONS);
|
|
747
826
|
}
|
|
@@ -834,7 +913,8 @@ export function extractFieldFromMaps<T extends string>(
|
|
|
834
913
|
source: string,
|
|
835
914
|
fieldName: T,
|
|
836
915
|
parentPathPredicate = (_: any, __?: any) => true,
|
|
837
|
-
valuePredicate = (_: any) => true
|
|
916
|
+
valuePredicate = (_: any) => true,
|
|
917
|
+
keepEmptyFields: boolean = false,
|
|
838
918
|
): (Record<T, any> & {range: Range})[] {
|
|
839
919
|
const yamlDoc = parseDocument(source) as any;
|
|
840
920
|
const maps: any[] = [];
|
|
@@ -849,6 +929,7 @@ export function extractFieldFromMaps<T extends string>(
|
|
|
849
929
|
) &&
|
|
850
930
|
map.items
|
|
851
931
|
) {
|
|
932
|
+
let matched = false;
|
|
852
933
|
for (const item of map.items as any[]) {
|
|
853
934
|
if (item?.key?.value === fieldName) {
|
|
854
935
|
const fieldValue = item?.value?.value ?? item.value?.items;
|
|
@@ -857,9 +938,17 @@ export function extractFieldFromMaps<T extends string>(
|
|
|
857
938
|
[fieldName]: fieldValue,
|
|
858
939
|
range: map.range,
|
|
859
940
|
});
|
|
941
|
+
matched = true;
|
|
860
942
|
}
|
|
861
943
|
}
|
|
862
944
|
}
|
|
945
|
+
if (!matched && keepEmptyFields) {
|
|
946
|
+
// add an empty entry if the field cannot be matched (i.e., optional property).
|
|
947
|
+
maps.push({
|
|
948
|
+
[fieldName]: undefined,
|
|
949
|
+
range: map.range,
|
|
950
|
+
});
|
|
951
|
+
}
|
|
863
952
|
}
|
|
864
953
|
},
|
|
865
954
|
});
|
|
@@ -897,6 +986,32 @@ export function getTypeAtPosition(
|
|
|
897
986
|
return null;
|
|
898
987
|
}
|
|
899
988
|
|
|
989
|
+
/**
|
|
990
|
+
* Get task version at cursor position.
|
|
991
|
+
* Useful to display/update the live docs
|
|
992
|
+
*/
|
|
993
|
+
export function getVersionAtPosition(
|
|
994
|
+
source: string,
|
|
995
|
+
position: { lineNumber: number; column: number }
|
|
996
|
+
) {
|
|
997
|
+
const versions = extractAllVersions(source);
|
|
998
|
+
const lineCounter = new LineCounter();
|
|
999
|
+
parseDocument(source, {lineCounter});
|
|
1000
|
+
const cursorIndex =
|
|
1001
|
+
lineCounter.lineStarts[position.lineNumber - 1] + position.column;
|
|
1002
|
+
|
|
1003
|
+
for (const version of versions.reverse()) {
|
|
1004
|
+
if (cursorIndex >= version.range[0]) {
|
|
1005
|
+
return version.version;
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
return null;
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
function extractAllVersions(source: string){
|
|
1012
|
+
return extractFieldFromMaps(source, "version", () => true, () => true, true);
|
|
1013
|
+
}
|
|
1014
|
+
|
|
900
1015
|
const TOSTRING_OPTIONS = {lineWidth: 0};
|
|
901
1016
|
|
|
902
1017
|
const yamlKeyCapture = "([^:\\n]+): *";
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
deleteBlock,
|
|
11
11
|
extractPluginDefault,
|
|
12
12
|
extractBlock,
|
|
13
|
-
flowHaveTasks, getAllCharts, getChartAtPosition, getLastBlock, getMetadata,
|
|
13
|
+
flowHaveTasks, getAllCharts, getChartAtPosition, getLastBlock, getMetadata, getVersionAtPosition,
|
|
14
14
|
getTypeAtPosition as getTaskType,
|
|
15
15
|
insertErrorInFlowable,
|
|
16
16
|
insertBlock,
|
|
@@ -236,4 +236,7 @@ export const YamlUtils = {
|
|
|
236
236
|
deletePluginDefaults,
|
|
237
237
|
|
|
238
238
|
extractFieldFromMaps,
|
|
239
|
+
|
|
240
|
+
getVersionAtPosition
|
|
241
|
+
|
|
239
242
|
};
|