-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathgraphman-operation-slice.js
More file actions
executable file
·108 lines (96 loc) · 4.33 KB
/
Copy pathgraphman-operation-slice.js
File metadata and controls
executable file
·108 lines (96 loc) · 4.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright (c) 2025 Broadcom Inc. and its subsidiaries. All Rights Reserved.
const utils = require("./graphman-utils");
const butils = require("./graphman-bundle");
const graphman = require("./graphman");
module.exports = {
/**
* Slices a bundle as per the choice.
* @param params
* @param params.input input bundle file
* @param params.sections one or more sections of bundle
* @param params.output output bundle
*/
run: function (params) {
if (!params.input) {
throw "--input parameters are missing";
}
const bundle = utils.readFile(params.input);
const result = {};
if (Array.isArray(params.sections)) for (let section of params.sections) {
if (section === "*") {
Object.assign(result, bundle);
} else if (section.startsWith("-")) {
section = section.substring(1);
const typeInfo = graphman.typeInfoByPluralName(section);
if (typeInfo) {
utils.info("removing " + section);
delete result[section];
} else {
utils.warn("unknown section " + section);
}
} else {
if (section.startsWith("+")) {
section = section.substring(1);
}
const typeInfo = graphman.typeInfoByPluralName(section);
if (typeInfo) {
utils.info("adding " + section);
if (bundle.hasOwnProperty(section)) {
result[section] = bundle[section];
}
} else {
utils.warn("unknown section " + section);
}
}
}
if (params.filter) {
delete params.filter.by;
butils.filter(result, params.filter);
}
utils.writeResult(params.output, butils.sort(result));
},
initParams: function (params, config) {
if (!params.sections) {
params.sections = [];
}
if (!Array.isArray(params.sections)) {
params.sections = [params.sections];
}
return params;
},
usage: function () {
console.log("slice --input <input-file> [--sections <section> <section>...]");
console.log(" [--output <output-file>]");
console.log();
console.log("Slices the bundle as per the choice.");
console.log("When similar entities are encountered, entities from the rightmost bundle takes the precedence.");
console.log();
console.log(" --input <input-file>");
console.log(" specify two or more input bundles file(s)");
console.log();
console.log(" --sections <section> <section> ...");
console.log(" specify one or more sections of the bundle for inclusion");
console.log(" section refers to the plural name of the entity type");
console.log(" * is a special section name, used to refer all the sections of a bundle");
console.log(" use '-' prefix to exclude the section");
console.log();
console.log(" --filter.<section>.<field-name> [<matching-criteria>.]<field-value>]");
console.log(" use this option to filter the entities by one or more fields at section level");
console.log(" section refers to the plural name of the entity type");
console.log(" multiple fields used for section-level filtering will be chained together by and-logic");
console.log(" use '*' as a section for defining the global level filter; will only be used when no specific filters are defined for a given section");
console.log(" supported matching criteria are");
console.log(" eq, equals");
console.log(" neq, not equals");
console.log(" regex, regular expression");
console.log(" gt, greater than");
console.log(" lt, less than");
console.log(" gte, greater than or equals");
console.log(" lte, less than or equals");
console.log(" default matching criteria is [eq].");
console.log();
console.log(" --output <output-file>");
console.log(" specify the file to capture the combined gateway configuration as bundle");
console.log();
}
}