@contrail/cli 1.0.53 → 1.0.55

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.
Files changed (31) hide show
  1. package/lib/cli.js +59 -10
  2. package/lib/types/option-set-hierarchy-exporter.d.ts +1 -0
  3. package/lib/types/option-set-hierarchy-exporter.js +113 -0
  4. package/lib/types/option-set-hierarchy-parser.d.ts +2 -2
  5. package/lib/types/option-set-hierarchy-parser.js +9 -9
  6. package/lib/types/option-set-hierarchy-uploader.d.ts +1 -0
  7. package/lib/types/option-set-hierarchy-uploader.js +110 -0
  8. package/lib/types/option-set-uploader.js +1 -1
  9. package/lib/types/rule-set-uploader.d.ts +1 -0
  10. package/lib/types/rule-set-uploader.js +175 -0
  11. package/lib/types/type-property-policy-uploader.d.ts +1 -0
  12. package/lib/types/type-property-policy-uploader.js +173 -0
  13. package/lib/types/types-extractor.d.ts +51 -2
  14. package/lib/types/types-extractor.js +204 -48
  15. package/lib/types/types-properties-merger.js +14 -8
  16. package/lib/types/types-uploader.js +1 -1
  17. package/lib/types/usage-info-uploader.d.ts +1 -0
  18. package/lib/types/usage-info-uploader.js +128 -0
  19. package/package.json +2 -1
  20. package/src/cli.ts +59 -10
  21. package/src/types/option-set-hierarchy-exporter.ts +125 -0
  22. package/src/types/option-set-hierarchy-parser.ts +9 -9
  23. package/src/types/option-set-hierarchy-uploader.ts +119 -0
  24. package/src/types/option-set-uploader.ts +2 -4
  25. package/src/types/rule-set-uploader.ts +190 -0
  26. package/src/types/type-property-policy-uploader.ts +188 -0
  27. package/src/types/types-extractor.ts +222 -54
  28. package/src/types/types-properties-merger.ts +14 -9
  29. package/src/types/types-uploader.ts +1 -1
  30. package/src/types/usage-info-uploader.ts +135 -0
  31. /package/src/colors/{color-example.csv → colors.csv} +0 -0
@@ -0,0 +1,173 @@
1
+ import { Entities } from '@contrail/sdk';
2
+ import fs from 'fs';
3
+ import { getSeparatorByPlatform } from '../common';
4
+ import { authUser } from '../auth/login';
5
+ import chalk from 'chalk';
6
+ import { getTypes } from './types-extractor';
7
+ const yaml = require('js-yaml');
8
+ export async function uploadTypePropertyPolicies(args) {
9
+ try {
10
+ await authUser();
11
+ console.log('%s Uploading', chalk.yellow.bold('TYPE PROPERTY POLICY'));
12
+ const [reducedTypePropertyPolicies, reducedTypePropertyPolicyLinks] = await loadTPPolicies();
13
+ await uploadTPPolicyObjects(reducedTypePropertyPolicies);
14
+ await uploadTypePropertyPolicyLinks(reducedTypePropertyPolicyLinks);
15
+ console.log('%s Uploaded', chalk.yellow.bold('TYPE PROPERTY POLICY'));
16
+ }
17
+ catch (e) {
18
+ console.log(`%s Type Property Policy Upload Failed. ${e}`, chalk.red.bold('FAIL'));
19
+ return;
20
+ }
21
+ console.log('%s Type Property Policy Upload Complete.', chalk.green.bold('COMPLETE'));
22
+ }
23
+ function loadTPPolicies() {
24
+ const TARGET_DIR = process.cwd();
25
+ try {
26
+ const separator = getSeparatorByPlatform();
27
+ const doc = yaml.load(fs.readFileSync(TARGET_DIR + separator + 'types.yml', 'utf8'));
28
+ return [doc.reducedTypePropertyPolicies, doc.reducedTypePropertyPolicyLinks];
29
+ }
30
+ catch (e) {
31
+ throw new Error(`ERROR PARSING YAML: ${e}`);
32
+ }
33
+ }
34
+ async function uploadTPPolicyObjects(reducedTypePropertyPolicies) {
35
+ const currentTPPolicies = await new Entities().get({
36
+ entityName: 'type-property-policy',
37
+ });
38
+ const currentTPPByLabel = {};
39
+ for (const currentTPP of currentTPPolicies) {
40
+ currentTPPByLabel[currentTPP.label] = currentTPP;
41
+ }
42
+ const loadedTPPByName = {};
43
+ for (const loadedTPP of reducedTypePropertyPolicies) {
44
+ loadedTPPByName[loadedTPP.label] = loadedTPP;
45
+ }
46
+ console.debug('current tp policy:', currentTPPolicies);
47
+ console.debug('reduced tp policy:', reducedTypePropertyPolicies);
48
+ for (const [label, loadedTPP] of Object.entries(loadedTPPByName)) {
49
+ try {
50
+ const found = currentTPPByLabel[label];
51
+ if (!found) {
52
+ console.log('Creating: ', label);
53
+ await new Entities().create({
54
+ entityName: 'type-property-policy',
55
+ object: loadedTPP
56
+ });
57
+ }
58
+ else {
59
+ console.log('Updating: ', label);
60
+ await new Entities().update({
61
+ entityName: 'type-property-policy',
62
+ id: found.id,
63
+ object: loadedTPP,
64
+ });
65
+ }
66
+ }
67
+ catch (err) {
68
+ throw new Error(`Error Uploading Type Property Policy: ${err}`);
69
+ }
70
+ }
71
+ for (const [label, currentTPP] of Object.entries(currentTPPByLabel)) {
72
+ try {
73
+ const found = loadedTPPByName[label];
74
+ if (!found) {
75
+ console.log('Deleting: ', label);
76
+ await new Entities().delete({
77
+ entityName: 'type-property-policy',
78
+ id: currentTPP['id'],
79
+ });
80
+ }
81
+ }
82
+ catch (err) {
83
+ throw new Error(`Error Type Property Policy: ${err}`);
84
+ }
85
+ }
86
+ }
87
+ async function uploadTypePropertyPolicyLinks(reducedTypePropertyPolicyLinks) {
88
+ const typesWithProperties = await getTypes();
89
+ const typeProperties = typesWithProperties
90
+ .filter(t => !!t.typeProperties)
91
+ .map(t => t.typeProperties)
92
+ .reduce((a, b) => a.concat(b));
93
+ const currentTPPs = await new Entities().get({
94
+ entityName: 'type-property-policy',
95
+ });
96
+ const currentTPPLinks = await new Entities().get({
97
+ entityName: 'type-property-policy-link',
98
+ });
99
+ const currentLinksHashes = {};
100
+ for (const currentLink of currentTPPLinks) {
101
+ const foundTypeProperty = typeProperties.find(tp => tp.id === currentLink.typePropertyId);
102
+ const foundTPP = currentTPPs.find(tpp => tpp.id === currentLink.typePropertyPolicyId);
103
+ if (!foundTypeProperty || !foundTPP) {
104
+ console.log('skipping unhashable, invalid policy link:', currentLink);
105
+ }
106
+ const hash = `${foundTypeProperty.slug}|${foundTPP.label}`;
107
+ currentLinksHashes[hash] = currentLink;
108
+ }
109
+ const reducedLinksByHashes = {};
110
+ for (const loadedLink of reducedTypePropertyPolicyLinks) {
111
+ const hash = `${loadedLink.typePropertySlug}|${loadedLink.typePropertyPolicyLabel}`;
112
+ reducedLinksByHashes[hash] = loadedLink;
113
+ }
114
+ console.debug('current type property policy links:', currentLinksHashes);
115
+ console.debug('reduced type property policy links:', reducedLinksByHashes);
116
+ for (const loadedTPPLink of reducedTypePropertyPolicyLinks) {
117
+ try {
118
+ const found = currentLinksHashes[`${loadedTPPLink.typePropertySlug}|${loadedTPPLink.typePropertyPolicyLabel}`];
119
+ if (!found) {
120
+ if (!transformReducedLink(loadedTPPLink, typeProperties, currentTPPs)) {
121
+ continue;
122
+ }
123
+ console.log('Creating: ', loadedTPPLink);
124
+ await new Entities().create({
125
+ entityName: 'type-property-policy-link',
126
+ object: {
127
+ typePropertyPolicyId: loadedTPPLink.typePropertyPolicyId,
128
+ typePropertyId: loadedTPPLink.typePropertyId,
129
+ },
130
+ });
131
+ }
132
+ else {
133
+ if (!transformReducedLink(loadedTPPLink, typeProperties, currentTPPs)) {
134
+ continue;
135
+ }
136
+ console.log('skipping existing link: ', loadedTPPLink);
137
+ }
138
+ }
139
+ catch (err) {
140
+ throw new Error(`Error Uploading type property policy links: ${err}`);
141
+ }
142
+ }
143
+ for (const [currentLinkHash, currentLink] of Object.entries(currentLinksHashes)) {
144
+ try {
145
+ const found = reducedLinksByHashes[currentLinkHash];
146
+ if (!found) {
147
+ console.log('Deleting: ', currentLinkHash);
148
+ await new Entities().delete({
149
+ entityName: 'type-property-policy-link',
150
+ id: currentLink['id'],
151
+ });
152
+ }
153
+ }
154
+ catch (err) {
155
+ throw new Error(`Error Deleting rule set link: ${err}`);
156
+ }
157
+ }
158
+ }
159
+ function transformReducedLink(TPPLink, typeProperties, typePropertyPolicies) {
160
+ const foundTP = typeProperties.find(tp => tp.slug === TPPLink.typePropertySlug);
161
+ if (!foundTP) {
162
+ console.error('Could not find type property with label', TPPLink.typePropertySlug);
163
+ return false;
164
+ }
165
+ TPPLink.typePropertyId = foundTP.id;
166
+ const foundTPP = typePropertyPolicies.find(tpp => tpp.label === TPPLink.typePropertyPolicyLabel);
167
+ if (!foundTPP) {
168
+ console.error('Could not find type property policy with label', TPPLink.typePropertyPolicyLabel);
169
+ return false;
170
+ }
171
+ TPPLink.typePropertyPolicyId = foundTPP.id;
172
+ return true;
173
+ }
@@ -1,2 +1,51 @@
1
- export declare function getTypes(args: any): Promise<void>;
2
- export declare function getReducedTypes(optionSets: any): Promise<any[]>;
1
+ export interface DataHolder {
2
+ types: any[];
3
+ optionSets: any[];
4
+ optionSetHierarchies: any[];
5
+ ruleSets: any[];
6
+ ruleSetLinks: any[];
7
+ usageInfo: any[];
8
+ typePropertyPolicies: any[];
9
+ typePropertyPolicyLinks: any[];
10
+ }
11
+ export declare function getAll(args: any): Promise<void>;
12
+ /**
13
+ * stores reduced option sets and returns full option sets */
14
+ export declare function getOptionSets(): Promise<any>;
15
+ export declare function getTypes(): Promise<any[]>;
16
+ export declare function reduceTypes(dataHolder: DataHolder): any[];
17
+ export declare function reduceData(data: DataHolder): {
18
+ reducedTypes: any[];
19
+ reducedOptionSets: {
20
+ name: any;
21
+ isArchived: any;
22
+ optionSet: any;
23
+ }[];
24
+ reducedOptionSetHierarchies: {
25
+ hierarchy: any;
26
+ options: any;
27
+ name: any;
28
+ }[];
29
+ reducedRuleSets: {
30
+ ruleSet: any;
31
+ name: any;
32
+ }[];
33
+ reducedRuleSetLinks: any[];
34
+ reducedUsageInfo: {
35
+ used: any;
36
+ editable: any;
37
+ typeSlug: any;
38
+ typePropertySlug: any;
39
+ }[];
40
+ reducedTypePropertyPolicies: {
41
+ label: any;
42
+ policy: {
43
+ version: any;
44
+ statements: any;
45
+ };
46
+ }[];
47
+ reducedTypePropertyPolicyLinks: {
48
+ typePropertySlug: any;
49
+ typePropertyPolicyLabel: any;
50
+ }[];
51
+ };
@@ -3,23 +3,29 @@ import chalk from 'chalk';
3
3
  import fs from 'fs';
4
4
  import { authUser } from '../auth/login';
5
5
  import { getSeparatorByPlatform } from '../common';
6
+ import pLimit from 'p-limit';
7
+ const limit = pLimit(30);
6
8
  const yaml = require('js-yaml');
7
- export async function getTypes(args) {
9
+ export async function getAll(args) {
8
10
  try {
9
11
  const userConfig = await authUser();
10
12
  console.log(`%s Getting all types for orgId: ${userConfig.orgId}`, chalk.blue.bold('START'));
11
- console.log('%s Retrieving', chalk.yellow.bold('OPTION SETS'));
12
- const optionSets = await new Entities().get({
13
- entityName: 'type-property-option-set',
14
- });
15
- await getOptionSets(optionSets);
16
- console.log('%s Retrieved', chalk.yellow.bold('OPTION SETS'));
17
- console.log('%s Retrieving', chalk.yellow.bold('TYPES'));
18
- const reducedTypes = await getReducedTypes(optionSets);
19
- const typesHolder = {
20
- types: reducedTypes,
13
+ // make directory to house exports
14
+ const dir = `./types-${Date.now()}`;
15
+ fs.mkdirSync(dir);
16
+ const data = {
17
+ types: await getTypes(),
18
+ optionSets: await getOptionSets(),
19
+ optionSetHierarchies: await getOptionSetHierarchies(),
20
+ ruleSets: await getRuleSets(),
21
+ ruleSetLinks: await getRuleSetLinks(),
22
+ usageInfo: await getUsageInfo(),
23
+ typePropertyPolicies: await getTypePropertyPolicies(),
24
+ typePropertyPolicyLinks: await getTypePropertyPolicyLinks(),
21
25
  };
22
- saveData(typesHolder);
26
+ const reducedData = reduceData(data);
27
+ storeOptionSets(data, dir);
28
+ saveData(reducedData, dir);
23
29
  console.log('%s Retrieved', chalk.yellow.bold('TYPES'));
24
30
  }
25
31
  catch (e) {
@@ -28,43 +34,170 @@ export async function getTypes(args) {
28
34
  }
29
35
  console.log('%s Types Retrieval Complete.', chalk.green.bold('COMPLETE'));
30
36
  }
31
- async function getOptionSets(optionSets) {
32
- let reducedOptionSets = [];
33
- for (const optionSet of optionSets) {
34
- const reducedOptionSet = {
37
+ /**
38
+ * stores reduced option sets and returns full option sets */
39
+ export async function getOptionSets() {
40
+ console.log('%s Retrieving', chalk.yellow.bold('OPTION SETS'));
41
+ const optionSets = await new Entities().get({
42
+ entityName: 'type-property-option-set',
43
+ });
44
+ console.log('%s Retrieved', chalk.yellow.bold('OPTION SETS'));
45
+ return optionSets;
46
+ }
47
+ export async function getTypes() {
48
+ console.log('%s Retrieving', chalk.yellow.bold('TYPES'));
49
+ const entitiesClient = new Entities();
50
+ const types = await entitiesClient.get({
51
+ entityName: 'type',
52
+ });
53
+ console.log(`${chalk.yellow.bold('TYPES')} Found ${types.length} types`);
54
+ const typesWithProperties = [];
55
+ const promises = [];
56
+ for (const type of types) {
57
+ const promise = limit(async () => {
58
+ const t = await entitiesClient.get({
59
+ entityName: 'type',
60
+ id: type.id,
61
+ relations: ['typeProperties'],
62
+ });
63
+ typesWithProperties.push(t);
64
+ });
65
+ promises.push(promise);
66
+ }
67
+ await Promise.all(promises);
68
+ return typesWithProperties;
69
+ }
70
+ async function getOptionSetHierarchies() {
71
+ const entitiesClient = new Entities();
72
+ return await entitiesClient.get({
73
+ entityName: 'option-set-hierarchy',
74
+ });
75
+ }
76
+ async function getRuleSets() {
77
+ const entitiesClient = new Entities();
78
+ return await entitiesClient.get({
79
+ entityName: 'type-rule-set',
80
+ });
81
+ }
82
+ async function getRuleSetLinks() {
83
+ const entitiesClient = new Entities();
84
+ return await entitiesClient.get({
85
+ entityName: 'type-rule-set-link',
86
+ });
87
+ }
88
+ async function getUsageInfo() {
89
+ const entitiesClient = new Entities();
90
+ return await entitiesClient.get({
91
+ entityName: 'type-property-usage-info',
92
+ });
93
+ }
94
+ async function getTypePropertyPolicies() {
95
+ const entitiesClient = new Entities();
96
+ return await entitiesClient.get({
97
+ entityName: 'type-property-policy',
98
+ });
99
+ }
100
+ async function getTypePropertyPolicyLinks() {
101
+ const entitiesClient = new Entities();
102
+ return await entitiesClient.get({
103
+ entityName: 'type-property-policy-link',
104
+ });
105
+ }
106
+ function reduceTypePropertyPolicies(data) {
107
+ var _a;
108
+ return (_a = data === null || data === void 0 ? void 0 : data.typePropertyPolicies) === null || _a === void 0 ? void 0 : _a.map(x => {
109
+ return {
110
+ label: x.label,
111
+ policy: {
112
+ version: x.policy.version,
113
+ statements: x.policy.statements,
114
+ }
115
+ };
116
+ });
117
+ }
118
+ function reduceTypePropertyPolicyLinks(data) {
119
+ var _a, _b;
120
+ const typeProperties = (_a = data === null || data === void 0 ? void 0 : data.types) === null || _a === void 0 ? void 0 : _a.map(x => x.typeProperties).reduce((x, y) => x.concat(y));
121
+ return (_b = data === null || data === void 0 ? void 0 : data.typePropertyPolicyLinks) === null || _b === void 0 ? void 0 : _b.map(x => {
122
+ var _a, _b;
123
+ return {
124
+ typePropertySlug: (_a = typeProperties.find(y => y.id === x.typePropertyId)) === null || _a === void 0 ? void 0 : _a.slug,
125
+ typePropertyPolicyLabel: (_b = data.typePropertyPolicies.find(y => y.id === x.typePropertyPolicyId)) === null || _b === void 0 ? void 0 : _b.label,
126
+ };
127
+ });
128
+ }
129
+ function reduceUsageInfo(data) {
130
+ var _a, _b;
131
+ const typeProperties = (_a = data === null || data === void 0 ? void 0 : data.types) === null || _a === void 0 ? void 0 : _a.map(x => x.typeProperties).reduce((x, y) => x.concat(y));
132
+ return (_b = data === null || data === void 0 ? void 0 : data.usageInfo) === null || _b === void 0 ? void 0 : _b.map(x => {
133
+ var _a, _b;
134
+ return {
135
+ used: x.used,
136
+ editable: x.editable,
137
+ typeSlug: (_a = data.types.find(y => y.id === x.typeId)) === null || _a === void 0 ? void 0 : _a.slug,
138
+ typePropertySlug: (_b = typeProperties.find(y => y.id === x.typePropertyId)) === null || _b === void 0 ? void 0 : _b.slug,
139
+ };
140
+ });
141
+ }
142
+ function reduceRuleSetLinks(data) {
143
+ var _a, _b;
144
+ const reducedRuleSetLinks = [];
145
+ if (!(data === null || data === void 0 ? void 0 : data.ruleSetLinks.length)) {
146
+ return [];
147
+ }
148
+ for (const ruleSetLink of data.ruleSetLinks) {
149
+ const ruleSet = (_a = data === null || data === void 0 ? void 0 : data.ruleSets) === null || _a === void 0 ? void 0 : _a.find(x => x.id === ruleSetLink.typeRuleSetId);
150
+ const type = (_b = data === null || data === void 0 ? void 0 : data.types) === null || _b === void 0 ? void 0 : _b.find(x => x.id === ruleSetLink.typeId);
151
+ if (!ruleSet || !type) {
152
+ console.log('%s Skipping bad rule set link', ruleSetLink.id, chalk.red.bold('TYPES'));
153
+ }
154
+ reducedRuleSetLinks.push({
155
+ ruleSet: ruleSet.name,
156
+ type: type.slug
157
+ });
158
+ }
159
+ return reducedRuleSetLinks;
160
+ }
161
+ function reduceRuleSets(data) {
162
+ var _a;
163
+ return (_a = data === null || data === void 0 ? void 0 : data.ruleSets) === null || _a === void 0 ? void 0 : _a.map(x => {
164
+ return {
165
+ ruleSet: x.ruleSet,
166
+ name: x.name,
167
+ };
168
+ });
169
+ }
170
+ function reduceOptionSets(data) {
171
+ var _a;
172
+ return (_a = data.optionSets) === null || _a === void 0 ? void 0 : _a.map(optionSet => {
173
+ return {
35
174
  name: optionSet.name,
36
175
  isArchived: optionSet.isArchived,
37
176
  optionSet: optionSet.optionSet,
38
177
  };
39
- reducedOptionSets.push(reducedOptionSet);
40
- }
41
- const optionSetsHolder = {
42
- optionSets: reducedOptionSets,
43
- };
44
- reducedOptionSets = reducedOptionSets.sort((one, two) => (one.name < two.name ? -1 : 1));
45
- const CURRENT_DIR = process.cwd();
46
- const separator = getSeparatorByPlatform();
47
- const yamlStr = yaml.dump(optionSetsHolder);
48
- fs.writeFileSync(CURRENT_DIR + separator + 'option_sets.yml', yamlStr, 'utf8');
178
+ });
49
179
  }
50
- export async function getReducedTypes(optionSets) {
51
- const types = await new Entities().get({
52
- entityName: 'type',
180
+ function reduceOptionSetHierarchies(data) {
181
+ var _a;
182
+ return (_a = data.optionSetHierarchies) === null || _a === void 0 ? void 0 : _a.map(x => {
183
+ const hierarchyByName = x.hierarchy.map(optionSetId => { var _a, _b; return (_b = (_a = data.optionSets) === null || _a === void 0 ? void 0 : _a.find(x => x.id === optionSetId)) === null || _b === void 0 ? void 0 : _b.name; });
184
+ return {
185
+ hierarchy: hierarchyByName,
186
+ options: x.options,
187
+ name: x.name
188
+ };
53
189
  });
54
- console.log('Found types: ', types.length);
190
+ }
191
+ export function reduceTypes(dataHolder) {
192
+ console.log('Found types: ', dataHolder.types.length);
55
193
  let reducedTypes = [];
56
- for (const type of types) {
57
- const typeWithProperties = await new Entities().get({
58
- entityName: 'type',
59
- id: type.id,
60
- relations: ['typeProperties'],
61
- });
62
- const optionSetNameById = {};
63
- for (const optionSet of optionSets) {
64
- optionSetNameById[optionSet.id] = optionSet.name;
65
- }
194
+ const optionSetNameById = {};
195
+ for (const optionSet of dataHolder.optionSets) {
196
+ optionSetNameById[optionSet.id] = optionSet.name;
197
+ }
198
+ for (const type of dataHolder.types) {
66
199
  const reducedTypeProperties = [];
67
- for (const typeProperty of typeWithProperties.typeProperties) {
200
+ for (const typeProperty of type.typeProperties) {
68
201
  const reducedTypeProperty = {
69
202
  slug: typeProperty.slug,
70
203
  id: typeProperty.id,
@@ -86,10 +219,10 @@ export async function getReducedTypes(optionSets) {
86
219
  reducedTypeProperties.push(reducedTypeProperty);
87
220
  }
88
221
  const reducedType = {
89
- typePath: typeWithProperties.typePath,
90
- slug: typeWithProperties.slug,
91
- label: typeWithProperties.label,
92
- isArchived: typeWithProperties.isArchived,
222
+ typePath: type.typePath,
223
+ slug: type.slug,
224
+ label: type.label,
225
+ isArchived: type.isArchived,
93
226
  typeProperties: reducedTypeProperties,
94
227
  };
95
228
  reducedTypes.push(reducedType);
@@ -97,9 +230,32 @@ export async function getReducedTypes(optionSets) {
97
230
  reducedTypes = reducedTypes.sort((one, two) => (one.typePath < two.typePath ? -1 : 1));
98
231
  return reducedTypes;
99
232
  }
100
- function saveData(data) {
101
- const yamlStr = yaml.dump(data);
233
+ export function reduceData(data) {
234
+ return {
235
+ reducedTypes: reduceTypes(data),
236
+ reducedOptionSets: reduceOptionSets(data),
237
+ reducedOptionSetHierarchies: reduceOptionSetHierarchies(data),
238
+ reducedRuleSets: reduceRuleSets(data),
239
+ reducedRuleSetLinks: reduceRuleSetLinks(data),
240
+ reducedUsageInfo: reduceUsageInfo(data),
241
+ reducedTypePropertyPolicies: reduceTypePropertyPolicies(data),
242
+ reducedTypePropertyPolicyLinks: reduceTypePropertyPolicyLinks(data),
243
+ };
244
+ }
245
+ function storeOptionSets(data, dir) {
246
+ let reducedOptionSets = reduceOptionSets(data);
247
+ reducedOptionSets = reducedOptionSets.sort((one, two) => (one.name < two.name ? -1 : 1));
248
+ const optionSetsHolder = {
249
+ reducedOptionSets,
250
+ };
251
+ const CURRENT_DIR = process.cwd();
252
+ const separator = getSeparatorByPlatform();
253
+ const yamlStr = yaml.dump(optionSetsHolder);
254
+ fs.writeFileSync(CURRENT_DIR + separator + dir + separator + 'option_sets.yml', yamlStr, 'utf8');
255
+ }
256
+ function saveData(reducedData, dir) {
257
+ const yamlStr = yaml.dump(reducedData);
102
258
  const CURRENT_DIR = process.cwd();
103
259
  const separator = getSeparatorByPlatform();
104
- fs.writeFileSync(CURRENT_DIR + separator + 'types.yml', yamlStr, 'utf8');
260
+ fs.writeFileSync(CURRENT_DIR + separator + dir + separator + 'types.yml', yamlStr, 'utf8');
105
261
  }
@@ -1,5 +1,4 @@
1
- import { Entities } from '@contrail/sdk';
2
- import { getReducedTypes } from './types-extractor';
1
+ import { getOptionSets, getTypes, reduceData } from './types-extractor';
3
2
  import fs from 'fs';
4
3
  import { getSeparatorByPlatform } from '../common';
5
4
  import { authUser } from '../auth/login';
@@ -40,18 +39,25 @@ function loadTypeProperties(fileLocation) {
40
39
  async function mergeTypeProperties(fileLocation, typePaths) {
41
40
  const uploadedTypeProperties = loadTypeProperties(fileLocation);
42
41
  await authUser();
43
- const optionSets = await new Entities().get({
44
- entityName: 'type-property-option-set',
45
- });
46
- const reducedTypes = await getReducedTypes(optionSets);
42
+ const data = {
43
+ types: await getTypes(),
44
+ optionSets: await getOptionSets(),
45
+ optionSetHierarchies: [],
46
+ ruleSets: [],
47
+ ruleSetLinks: [],
48
+ usageInfo: [],
49
+ typePropertyPolicies: [],
50
+ typePropertyPolicyLinks: [],
51
+ };
52
+ const reducedData = await reduceData(data);
47
53
  for (const typePath of typePaths) {
48
- const foundType = reducedTypes.find(reducedTypes => reducedTypes.typePath === typePath);
54
+ const foundType = reducedData.reducedTypes.find(reducedTypes => reducedTypes.typePath === typePath);
49
55
  if (!foundType) {
50
56
  console.log(`%s No Type found for: ${typePath}`, chalk.red.bold('WARNING'));
51
57
  }
52
58
  mergeType(foundType, uploadedTypeProperties);
53
59
  }
54
- saveData({ types: reducedTypes });
60
+ saveData({ types: reducedData.reducedTypes });
55
61
  }
56
62
  function mergeType(reducedType, typePropertiesToAdd) {
57
63
  for (const typeProperty of typePropertiesToAdd) {
@@ -24,7 +24,7 @@ function loadReducedTypes() {
24
24
  try {
25
25
  const separator = getSeparatorByPlatform();
26
26
  const doc = yaml.load(fs.readFileSync(TARGET_DIR + separator + 'types.yml', 'utf8'));
27
- return doc.types;
27
+ return doc.reducedTypes;
28
28
  }
29
29
  catch (e) {
30
30
  throw new Error(`ERROR PARSING YAML: ${e}`);
@@ -0,0 +1 @@
1
+ export declare function uploadUsageInfo(args: any): Promise<void>;