@kestra-io/ui-libs 0.0.193 → 0.0.194
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-2NapKS0O.js +1895 -0
- package/dist/FlowYamlUtils-2NapKS0O.js.map +1 -0
- package/dist/FlowYamlUtils-4gn3tdFh.cjs +2 -0
- package/dist/FlowYamlUtils-4gn3tdFh.cjs.map +1 -0
- package/dist/kestra-flowyamlutils.cjs.js +1 -1
- package/dist/kestra-flowyamlutils.es.js +24 -23
- 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 +11 -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 +64 -0
- package/src/utils/FlowYamlUtils.ts +56 -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
|
@@ -55,7 +55,7 @@ export declare function deleteBlock({ source, section, key, keyName }: {
|
|
|
55
55
|
section: string;
|
|
56
56
|
key: string;
|
|
57
57
|
keyName?: string;
|
|
58
|
-
}):
|
|
58
|
+
}): string;
|
|
59
59
|
export declare function deleteBlockWithPath({ source, path }: {
|
|
60
60
|
source: string;
|
|
61
61
|
path: string;
|
|
@@ -92,7 +92,7 @@ export declare function deleteMetadata(source: any, metadata: any): any;
|
|
|
92
92
|
export declare function flowHaveTasks(source: string): boolean;
|
|
93
93
|
export declare function extractPluginDefault(source: string, pluginType: string): string | undefined;
|
|
94
94
|
export declare function replacePluginDefaultsInDocument(source: string, pluginType: string, newContent: string): string | undefined;
|
|
95
|
-
export declare function deletePluginDefaults(source: string, pluginType: string):
|
|
95
|
+
export declare function deletePluginDefaults(source: string, pluginType: string): string;
|
|
96
96
|
export declare function insertErrorInFlowable(source: string, errorTask: string, flowableTask: string): any;
|
|
97
97
|
/**
|
|
98
98
|
* Specify a source yaml doc, the field to extract recursively in every map of the doc and optionally
|
|
@@ -100,7 +100,7 @@ export declare function insertErrorInFlowable(source: string, errorTask: string,
|
|
|
100
100
|
* will take a single argument which is the path of each parent property starting from the root doc (joined with ".")
|
|
101
101
|
* "my.parent.task" will mean that the field was retrieved in my -> parent -> task path.
|
|
102
102
|
*/
|
|
103
|
-
export declare function extractFieldFromMaps<T extends string>(source: string, fieldName: T, parentPathPredicate?: (_: any, __?: any) => boolean, valuePredicate?: (_: any) => boolean): (Record<T, any> & {
|
|
103
|
+
export declare function extractFieldFromMaps<T extends string>(source: string, fieldName: T, parentPathPredicate?: (_: any, __?: any) => boolean, valuePredicate?: (_: any) => boolean, keepEmptyFields?: boolean): (Record<T, any> & {
|
|
104
104
|
range: Range;
|
|
105
105
|
})[];
|
|
106
106
|
/**
|
|
@@ -111,6 +111,14 @@ export declare function getTypeAtPosition(source: string, position: {
|
|
|
111
111
|
lineNumber: number;
|
|
112
112
|
column: number;
|
|
113
113
|
}, validTypes: any): any;
|
|
114
|
+
/**
|
|
115
|
+
* Get task version at cursor position.
|
|
116
|
+
* Useful to display/update the live docs
|
|
117
|
+
*/
|
|
118
|
+
export declare function getVersionAtPosition(source: string, position: {
|
|
119
|
+
lineNumber: number;
|
|
120
|
+
column: number;
|
|
121
|
+
}): any;
|
|
114
122
|
export type YamlElement = {
|
|
115
123
|
key?: string;
|
|
116
124
|
value: Record<string, any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FlowYamlUtils.d.ts","sourceRoot":"","sources":["../../src/utils/Flow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aml 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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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", () => {
|
|
@@ -103,17 +103,21 @@ 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;
|
|
@@ -204,7 +208,7 @@ export function extractBlockWithPath({source, path}: {
|
|
|
204
208
|
path: string
|
|
205
209
|
}) {
|
|
206
210
|
const doc = extractBlockWithPathFromDocument({
|
|
207
|
-
yamlDoc:
|
|
211
|
+
yamlDoc: parseDocumentTyped(source),
|
|
208
212
|
path
|
|
209
213
|
});
|
|
210
214
|
if (!doc) {
|
|
@@ -236,7 +240,7 @@ export function replaceBlockWithPath({source, path, newContent}: {
|
|
|
236
240
|
path: string,
|
|
237
241
|
newContent: string
|
|
238
242
|
}) {
|
|
239
|
-
const
|
|
243
|
+
const yamlDoc = parseDocumentTyped(source);
|
|
240
244
|
const newItem = yamlDoc.createNode(parseDocument(newContent));
|
|
241
245
|
|
|
242
246
|
yamlDoc.setIn(parsePath(path), newItem);
|
|
@@ -475,7 +479,7 @@ export function insertBlockWithPath({
|
|
|
475
479
|
if (!position) {
|
|
476
480
|
position = "after";
|
|
477
481
|
}
|
|
478
|
-
const yamlDoc =
|
|
482
|
+
const yamlDoc = parseDocumentTyped(source);
|
|
479
483
|
const newPropNode = yamlDoc.createNode(parseDocument(newBlock)) as any;
|
|
480
484
|
|
|
481
485
|
const parsedPath = parsePath(parentPath);
|
|
@@ -519,7 +523,7 @@ export function deleteBlock({source, section, key, keyName}: {
|
|
|
519
523
|
if (!keyName) {
|
|
520
524
|
keyName = "id";
|
|
521
525
|
}
|
|
522
|
-
const yamlDoc =
|
|
526
|
+
const yamlDoc = parseDocumentTyped(source);
|
|
523
527
|
visit(yamlDoc, {
|
|
524
528
|
Pair(_, pair: any) {
|
|
525
529
|
if (pair.key.value === section) {
|
|
@@ -550,14 +554,19 @@ export function deleteBlockWithPath({source, path}: {
|
|
|
550
554
|
source: string,
|
|
551
555
|
path: string,
|
|
552
556
|
}) {
|
|
553
|
-
const yamlDoc =
|
|
557
|
+
const yamlDoc = parseDocumentTyped(source);
|
|
554
558
|
const parsedPath = parsePath(path)
|
|
555
|
-
const
|
|
559
|
+
const parsedParentPath = parsedPath.slice(0, -1);
|
|
560
|
+
const parentNode = yamlDoc.getIn(parsedParentPath) as YAMLMap<{ value: string }, Node>;
|
|
556
561
|
if (!parentNode) {
|
|
557
562
|
return source;
|
|
558
563
|
}
|
|
559
564
|
const index = getNodeIndexInParent(yamlDoc, parentNode, parsedPath.slice(0, -1), parsedPath[parsedPath.length - 1]);
|
|
560
|
-
parentNode.items.
|
|
565
|
+
if (parentNode.items.length === 1) {
|
|
566
|
+
yamlDoc.deleteIn(parsedParentPath);
|
|
567
|
+
} else {
|
|
568
|
+
parentNode.items.splice(index, 1);
|
|
569
|
+
}
|
|
561
570
|
return yamlDoc.toString(TOSTRING_OPTIONS);
|
|
562
571
|
}
|
|
563
572
|
|
|
@@ -741,7 +750,7 @@ function cleanMetadataDocument(yamlDoc: Document<YAMLMap<{ value: string }, Node
|
|
|
741
750
|
}
|
|
742
751
|
|
|
743
752
|
export function cleanMetadata(source: string) {
|
|
744
|
-
const yamlDoc =
|
|
753
|
+
const yamlDoc = parseDocumentTyped(source);
|
|
745
754
|
const cleanedYamlDoc = cleanMetadataDocument(yamlDoc);
|
|
746
755
|
return cleanedYamlDoc.toString(TOSTRING_OPTIONS);
|
|
747
756
|
}
|
|
@@ -834,7 +843,8 @@ export function extractFieldFromMaps<T extends string>(
|
|
|
834
843
|
source: string,
|
|
835
844
|
fieldName: T,
|
|
836
845
|
parentPathPredicate = (_: any, __?: any) => true,
|
|
837
|
-
valuePredicate = (_: any) => true
|
|
846
|
+
valuePredicate = (_: any) => true,
|
|
847
|
+
keepEmptyFields: boolean = false,
|
|
838
848
|
): (Record<T, any> & {range: Range})[] {
|
|
839
849
|
const yamlDoc = parseDocument(source) as any;
|
|
840
850
|
const maps: any[] = [];
|
|
@@ -849,6 +859,7 @@ export function extractFieldFromMaps<T extends string>(
|
|
|
849
859
|
) &&
|
|
850
860
|
map.items
|
|
851
861
|
) {
|
|
862
|
+
let matched = false;
|
|
852
863
|
for (const item of map.items as any[]) {
|
|
853
864
|
if (item?.key?.value === fieldName) {
|
|
854
865
|
const fieldValue = item?.value?.value ?? item.value?.items;
|
|
@@ -857,9 +868,17 @@ export function extractFieldFromMaps<T extends string>(
|
|
|
857
868
|
[fieldName]: fieldValue,
|
|
858
869
|
range: map.range,
|
|
859
870
|
});
|
|
871
|
+
matched = true;
|
|
860
872
|
}
|
|
861
873
|
}
|
|
862
874
|
}
|
|
875
|
+
if (!matched && keepEmptyFields) {
|
|
876
|
+
// add an empty entry if the field cannot be matched (i.e., optional property).
|
|
877
|
+
maps.push({
|
|
878
|
+
[fieldName]: undefined,
|
|
879
|
+
range: map.range,
|
|
880
|
+
});
|
|
881
|
+
}
|
|
863
882
|
}
|
|
864
883
|
},
|
|
865
884
|
});
|
|
@@ -897,6 +916,32 @@ export function getTypeAtPosition(
|
|
|
897
916
|
return null;
|
|
898
917
|
}
|
|
899
918
|
|
|
919
|
+
/**
|
|
920
|
+
* Get task version at cursor position.
|
|
921
|
+
* Useful to display/update the live docs
|
|
922
|
+
*/
|
|
923
|
+
export function getVersionAtPosition(
|
|
924
|
+
source: string,
|
|
925
|
+
position: { lineNumber: number; column: number }
|
|
926
|
+
) {
|
|
927
|
+
const versions = extractAllVersions(source);
|
|
928
|
+
const lineCounter = new LineCounter();
|
|
929
|
+
parseDocument(source, {lineCounter});
|
|
930
|
+
const cursorIndex =
|
|
931
|
+
lineCounter.lineStarts[position.lineNumber - 1] + position.column;
|
|
932
|
+
|
|
933
|
+
for (const version of versions.reverse()) {
|
|
934
|
+
if (cursorIndex >= version.range[0]) {
|
|
935
|
+
return version.version;
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
return null;
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
function extractAllVersions(source: string){
|
|
942
|
+
return extractFieldFromMaps(source, "version", () => true, () => true, true);
|
|
943
|
+
}
|
|
944
|
+
|
|
900
945
|
const TOSTRING_OPTIONS = {lineWidth: 0};
|
|
901
946
|
|
|
902
947
|
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
|
};
|