@contrail/cli 3.5.2 → 3.5.3-alpha.73bd011
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/README.md +1 -25
- package/dist/api/types.d.ts +0 -5
- package/dist/api/types.js +1 -36
- package/dist/commands/types/getAll.js +0 -18
- package/dist/commands/types/loadAll.js +0 -2
- package/dist/commands/types/mergeTypeProperties.js +0 -5
- package/dist/commands/types/uploadOptionSetHierarchies.js +0 -117
- package/dist/commands/types/uploadOptionSets.js +1 -1
- package/dist/commands/types/uploadRuleSets.js +2 -85
- package/dist/commands/types/uploadTypeOverrides.js +10 -2
- package/dist/commands/types/uploadTypePolicies.js +2 -86
- package/dist/commands/types/uploadTypePropertyPolicies.d.ts +0 -1
- package/dist/commands/types/uploadTypePropertyPolicies.js +3 -139
- package/dist/helpers/types/type-uploader.js +1 -1
- package/dist/interfaces.d.ts +0 -25
- package/dist/templates/typescript/tsup.config.ts +0 -0
- package/oclif.manifest.json +1 -52
- package/package.json +1 -1
- package/dist/commands/types/uploadUsageInfo.d.ts +0 -15
- package/dist/commands/types/uploadUsageInfo.js +0 -180
- package/dist/commands/types/uploadUsageInfo.spec.d.ts +0 -1
- package/dist/commands/types/uploadUsageInfo.spec.js +0 -249
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.uploadTypePropertyPolicies = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const sdk_1 = require("@contrail/sdk");
|
|
6
6
|
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
@@ -8,12 +8,10 @@ const path = tslib_1.__importStar(require("path"));
|
|
|
8
8
|
const login_1 = require("../../auth/login");
|
|
9
9
|
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
10
10
|
const core_1 = require("@oclif/core");
|
|
11
|
-
const type_extractor_1 = require("../../helpers/types/type-extractor");
|
|
12
11
|
const users_1 = require("../../api/users");
|
|
13
12
|
const basecommand_1 = require("../../basecommand");
|
|
14
13
|
const logger_1 = tslib_1.__importDefault(require("../../logger"));
|
|
15
14
|
const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
|
|
16
|
-
const _ = tslib_1.__importStar(require("lodash"));
|
|
17
15
|
class UploadTypePropertyPolicies extends basecommand_1.BaseCommand {
|
|
18
16
|
static description = 'Upload type property policies';
|
|
19
17
|
static examples = [
|
|
@@ -38,14 +36,12 @@ async function uploadTypePropertyPolicies(dir) {
|
|
|
38
36
|
try {
|
|
39
37
|
await (0, login_1.authUser)();
|
|
40
38
|
logger_1.default.info(`${chalk_1.default.yellow.bold('TYPE PROPERTY POLICY')} Uploading`);
|
|
41
|
-
const
|
|
39
|
+
const reducedTypePropertyPolicies = await loadTPPolicies(dir);
|
|
42
40
|
await uploadTPPolicyObjects(reducedTypePropertyPolicies);
|
|
43
|
-
await uploadTypePropertyPolicyLinks(reducedTypePropertyPolicyLinks);
|
|
44
41
|
logger_1.default.info(`${chalk_1.default.yellow.bold('TYPE PROPERTY POLICY')} Uploaded`);
|
|
45
42
|
}
|
|
46
43
|
catch (e) {
|
|
47
44
|
logger_1.default.info(`${chalk_1.default.red.bold('FAIL')} Type Property Policy Upload Failed . ${e}`);
|
|
48
|
-
//TODO make this only print if a debug flag is set
|
|
49
45
|
console.trace(e);
|
|
50
46
|
return;
|
|
51
47
|
}
|
|
@@ -54,15 +50,13 @@ async function uploadTypePropertyPolicies(dir) {
|
|
|
54
50
|
exports.uploadTypePropertyPolicies = uploadTypePropertyPolicies;
|
|
55
51
|
function loadTPPolicies(fromDir) {
|
|
56
52
|
const tpps = [];
|
|
57
|
-
let tppLinks = [];
|
|
58
53
|
const dir = path.join(fromDir, 'type-property-policies');
|
|
59
54
|
try {
|
|
60
55
|
const files = fs_1.default.readdirSync(dir);
|
|
61
56
|
for (const file of files) {
|
|
62
57
|
tpps.push(js_yaml_1.default.load(fs_1.default.readFileSync(path.join(dir, file), 'utf8')));
|
|
63
58
|
}
|
|
64
|
-
|
|
65
|
-
return [tpps, tppLinks];
|
|
59
|
+
return tpps;
|
|
66
60
|
}
|
|
67
61
|
catch (e) {
|
|
68
62
|
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
@@ -155,133 +149,3 @@ async function uploadTPPolicyObjects(reducedTypePropertyPolicies) {
|
|
|
155
149
|
}
|
|
156
150
|
}
|
|
157
151
|
}
|
|
158
|
-
async function uploadTypePropertyPolicyLinks(reducedTypePropertyPolicyLinks) {
|
|
159
|
-
const typesWithProperties = await (0, type_extractor_1.getTypes)();
|
|
160
|
-
const typeProperties = [];
|
|
161
|
-
typesWithProperties.forEach((type) => {
|
|
162
|
-
if (type.typeProperties) {
|
|
163
|
-
for (const tp of type.typeProperties) {
|
|
164
|
-
tp.typeId = type.id;
|
|
165
|
-
tp.typeSlug = type.slug;
|
|
166
|
-
typeProperties.push(tp);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
const currentTPPs = await new sdk_1.Entities().get({
|
|
171
|
-
entityName: 'type-property-policy',
|
|
172
|
-
});
|
|
173
|
-
const currentTPPLinks = await new sdk_1.Entities().get({
|
|
174
|
-
entityName: 'type-property-policy-link',
|
|
175
|
-
});
|
|
176
|
-
logger_1.default.info(`found ${currentTPPLinks.length} current type property policy links`);
|
|
177
|
-
logger_1.default.info(`found ${reducedTypePropertyPolicyLinks.length} type property policy links to load`);
|
|
178
|
-
const currentLinksHashes = {};
|
|
179
|
-
for (const currentLink of currentTPPLinks) {
|
|
180
|
-
const foundTPs = findAllOccurrences(typeProperties, (tp) => tp.id === currentLink.typePropertyId);
|
|
181
|
-
for (const foundTP of foundTPs) {
|
|
182
|
-
const foundTPP = currentTPPs.find((tpp) => tpp.id === currentLink.typePropertyPolicyId);
|
|
183
|
-
if (!foundTP || !foundTPP) {
|
|
184
|
-
logger_1.default.info(`skipping unhashable, invalid policy link: ${JSON.stringify(currentLink, null, 2)}`);
|
|
185
|
-
continue;
|
|
186
|
-
}
|
|
187
|
-
const hash = `${foundTP.typeSlug}|${foundTP.slug}|${foundTPP.identifier}`;
|
|
188
|
-
currentLinksHashes[hash] = currentLink;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
logger_1.default.debug(`current links hashes: ${JSON.stringify(currentLinksHashes, null, 2)}`);
|
|
192
|
-
const reducedLinksByHashes = {};
|
|
193
|
-
for (const loadedLink of reducedTypePropertyPolicyLinks) {
|
|
194
|
-
const hash = `${loadedLink.typeSlug}|${loadedLink.typePropertySlug}|${loadedLink.typePropertyPolicyIdentifier}`;
|
|
195
|
-
reducedLinksByHashes[hash] = loadedLink;
|
|
196
|
-
}
|
|
197
|
-
const toCreate = Object.keys(reducedLinksByHashes)
|
|
198
|
-
.filter((x) => !currentLinksHashes[x])
|
|
199
|
-
.map((x) => {
|
|
200
|
-
return {
|
|
201
|
-
[x]: reducedLinksByHashes[x],
|
|
202
|
-
};
|
|
203
|
-
})
|
|
204
|
-
.reduce((a, b) => Object.assign(a, b), {});
|
|
205
|
-
const toDelete = _.uniqBy(Object.keys(currentLinksHashes)
|
|
206
|
-
.filter((x) => !reducedLinksByHashes[x])
|
|
207
|
-
.map((x) => {
|
|
208
|
-
return {
|
|
209
|
-
[x]: currentLinksHashes[x],
|
|
210
|
-
};
|
|
211
|
-
}), 'id').reduce((a, b) => Object.assign(a, b), {});
|
|
212
|
-
logger_1.default.debug(`reduced links hashes: ${JSON.stringify(reducedLinksByHashes, null, 2)}`);
|
|
213
|
-
logger_1.default.info(`found ${Object.keys(toCreate).length} type property policy links to create`);
|
|
214
|
-
logger_1.default.info(`found ${Object.keys(toDelete).length} type property policy links to delete`);
|
|
215
|
-
logger_1.default.debug(`to create: ${JSON.stringify(toCreate, null, 2)}`);
|
|
216
|
-
logger_1.default.debug(`to delete: ${JSON.stringify(toDelete, null, 2)}`);
|
|
217
|
-
logger_1.default.debug(`current links hashes to delete: ${JSON.stringify(Object.keys(currentLinksHashes).filter((x) => !reducedLinksByHashes[x]), null, 2)}`);
|
|
218
|
-
// fs.writeFileSync('toCreate.json', JSON.stringify(toCreate, null, 2));
|
|
219
|
-
// fs.writeFileSync('toDelete.json', JSON.stringify(toDelete, null, 2));
|
|
220
|
-
// fs.writeFileSync('currentLinksHashes.json', JSON.stringify(currentLinksHashes, null, 2));
|
|
221
|
-
// fs.writeFileSync('reducedLinksByHashes.json', JSON.stringify(reducedLinksByHashes, null, 2));
|
|
222
|
-
// fs.writeFileSync(
|
|
223
|
-
// 'current_link_hashes_to_delete.json',
|
|
224
|
-
// JSON.stringify(
|
|
225
|
-
// Object.keys(currentLinksHashes).filter((x) => !reducedLinksByHashes[x]),
|
|
226
|
-
// null,
|
|
227
|
-
// 2,
|
|
228
|
-
// ),
|
|
229
|
-
// );
|
|
230
|
-
// return;
|
|
231
|
-
for (const [hash, link] of Object.entries(toCreate)) {
|
|
232
|
-
try {
|
|
233
|
-
if (!transformReducedLink(link, typeProperties, currentTPPs)) {
|
|
234
|
-
continue;
|
|
235
|
-
}
|
|
236
|
-
logger_1.default.info(`Creating: ${hash}: ${JSON.stringify(link, null, 2)}`);
|
|
237
|
-
await new sdk_1.Entities().create({
|
|
238
|
-
entityName: 'type-property-policy-link',
|
|
239
|
-
object: {
|
|
240
|
-
typePropertyPolicyId: link.typePropertyPolicyId,
|
|
241
|
-
typePropertyId: link.typePropertyId,
|
|
242
|
-
},
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
catch (err) {
|
|
246
|
-
logger_1.default.error(`Error Uploading type property policy links: ${err}`);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
for (const [hash, link] of Object.entries(toDelete)) {
|
|
250
|
-
try {
|
|
251
|
-
logger_1.default.info(`Deleting: ${hash}`);
|
|
252
|
-
await new sdk_1.Entities().delete({
|
|
253
|
-
entityName: 'type-property-policy-link',
|
|
254
|
-
id: link['id'],
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
catch (err) {
|
|
258
|
-
logger_1.default.error(`Error Deleting type property policy link: ${err}`);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
function transformReducedLink(TPPLink, typeProperties, typePropertyPolicies) {
|
|
262
|
-
const foundTP = typeProperties.find((tp) => tp.slug === TPPLink.typePropertySlug && tp.typeSlug === TPPLink.typeSlug);
|
|
263
|
-
if (!foundTP) {
|
|
264
|
-
logger_1.default.error(`Could not find type property with slug ${TPPLink.typePropertySlug} `);
|
|
265
|
-
return false;
|
|
266
|
-
}
|
|
267
|
-
TPPLink.typePropertyId = foundTP.id;
|
|
268
|
-
const foundTPP = typePropertyPolicies.find((tpp) => tpp.identifier === TPPLink.typePropertyPolicyIdentifier);
|
|
269
|
-
if (!foundTPP) {
|
|
270
|
-
logger_1.default.error(`Could not find type property policy with identifier ${TPPLink.typePropertyPolicyIdentifier} `);
|
|
271
|
-
return false;
|
|
272
|
-
}
|
|
273
|
-
TPPLink.typePropertyPolicyId = foundTPP.id;
|
|
274
|
-
return true;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
function findAllOccurrences(array, evaluator) {
|
|
278
|
-
const found = [];
|
|
279
|
-
for (let i = 0; i < array.length; i++) {
|
|
280
|
-
const element = array[i];
|
|
281
|
-
if (evaluator(element)) {
|
|
282
|
-
found.push(element);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
return found;
|
|
286
|
-
}
|
|
287
|
-
exports.findAllOccurrences = findAllOccurrences;
|
|
@@ -303,7 +303,7 @@ async function uploadReducedTypeProperties(type, currentPropertyTypes, newProper
|
|
|
303
303
|
}
|
|
304
304
|
}
|
|
305
305
|
catch (err) {
|
|
306
|
-
|
|
306
|
+
logger_1.default.error(`Error Deleting Type-Property ${currentPropertyType.slug}: ${err}`);
|
|
307
307
|
}
|
|
308
308
|
}
|
|
309
309
|
}
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -370,31 +370,6 @@ export interface ReducedOptionSet {
|
|
|
370
370
|
isArchived: boolean;
|
|
371
371
|
optionSet: any[];
|
|
372
372
|
}
|
|
373
|
-
export interface ReducedUsageInfo {
|
|
374
|
-
typeId: string;
|
|
375
|
-
typePropertyId: string;
|
|
376
|
-
typePath: string;
|
|
377
|
-
typePropertySlug: string;
|
|
378
|
-
editable: boolean;
|
|
379
|
-
used: boolean;
|
|
380
|
-
formulaFunction?: string;
|
|
381
|
-
validationFunction?: string;
|
|
382
|
-
numberFormat?: any;
|
|
383
|
-
defaultValue?: string;
|
|
384
|
-
label?: string;
|
|
385
|
-
required?: boolean;
|
|
386
|
-
searchable?: boolean;
|
|
387
|
-
isUniqueProperty?: boolean;
|
|
388
|
-
isUniquePropertyInFamily?: boolean;
|
|
389
|
-
copyBehavior?: string;
|
|
390
|
-
copyDefault?: string;
|
|
391
|
-
propertyLevel?: string;
|
|
392
|
-
isArchived: boolean;
|
|
393
|
-
isFederationProperty?: boolean;
|
|
394
|
-
carryOverBehavior?: string;
|
|
395
|
-
carryOverDefault?: string;
|
|
396
|
-
}
|
|
397
|
-
export type PersistReducedUsageInfo = Omit<ReducedUsageInfo, 'typePath' | 'typePropertySlug'>;
|
|
398
373
|
export declare enum PropertyType {
|
|
399
374
|
Text = "text",
|
|
400
375
|
String = "string",
|
|
File without changes
|
package/oclif.manifest.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "3.5.
|
|
2
|
+
"version": "3.5.3-alpha.73bd011",
|
|
3
3
|
"commands": {
|
|
4
4
|
"app:create": {
|
|
5
5
|
"id": "app:create",
|
|
@@ -2520,57 +2520,6 @@
|
|
|
2520
2520
|
},
|
|
2521
2521
|
"args": {}
|
|
2522
2522
|
},
|
|
2523
|
-
"types:uploadUsageInfo": {
|
|
2524
|
-
"id": "types:uploadUsageInfo",
|
|
2525
|
-
"description": "Upload extracted usage info",
|
|
2526
|
-
"strict": true,
|
|
2527
|
-
"pluginName": "@contrail/cli",
|
|
2528
|
-
"pluginAlias": "@contrail/cli",
|
|
2529
|
-
"pluginType": "core",
|
|
2530
|
-
"aliases": [],
|
|
2531
|
-
"examples": [
|
|
2532
|
-
"$ contrail types uploadUsageInfo\n"
|
|
2533
|
-
],
|
|
2534
|
-
"flags": {
|
|
2535
|
-
"logLevel": {
|
|
2536
|
-
"name": "logLevel",
|
|
2537
|
-
"type": "option",
|
|
2538
|
-
"char": "l",
|
|
2539
|
-
"description": "The Log Level",
|
|
2540
|
-
"required": false,
|
|
2541
|
-
"multiple": false,
|
|
2542
|
-
"options": [
|
|
2543
|
-
"error",
|
|
2544
|
-
"warn",
|
|
2545
|
-
"info",
|
|
2546
|
-
"debug"
|
|
2547
|
-
]
|
|
2548
|
-
},
|
|
2549
|
-
"alwaysConfirmEnv": {
|
|
2550
|
-
"name": "alwaysConfirmEnv",
|
|
2551
|
-
"type": "option",
|
|
2552
|
-
"char": "e",
|
|
2553
|
-
"description": "The Environment variables",
|
|
2554
|
-
"required": false,
|
|
2555
|
-
"multiple": false,
|
|
2556
|
-
"options": [
|
|
2557
|
-
"true",
|
|
2558
|
-
"false"
|
|
2559
|
-
],
|
|
2560
|
-
"default": "true"
|
|
2561
|
-
},
|
|
2562
|
-
"dir": {
|
|
2563
|
-
"name": "dir",
|
|
2564
|
-
"type": "option",
|
|
2565
|
-
"char": "d",
|
|
2566
|
-
"description": "The directory from which to export the usage info data. Defaults to the current directory. The usage info data will be loaded from $dir/usage-info.yml",
|
|
2567
|
-
"required": false,
|
|
2568
|
-
"multiple": false,
|
|
2569
|
-
"default": "."
|
|
2570
|
-
}
|
|
2571
|
-
},
|
|
2572
|
-
"args": {}
|
|
2573
|
-
},
|
|
2574
2523
|
"users:export": {
|
|
2575
2524
|
"id": "users:export",
|
|
2576
2525
|
"description": "Export all users in the org.",
|
package/package.json
CHANGED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { BaseCommand } from '../../basecommand';
|
|
2
|
-
import { PersistReducedUsageInfo } from '../../interfaces';
|
|
3
|
-
export default class UploadUsageInfo extends BaseCommand {
|
|
4
|
-
static description: string;
|
|
5
|
-
static examples: string[];
|
|
6
|
-
static flags: {
|
|
7
|
-
dir: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
8
|
-
alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
9
|
-
logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
10
|
-
};
|
|
11
|
-
run(): Promise<void>;
|
|
12
|
-
}
|
|
13
|
-
export declare function uploadUsageInfo(dir: string): Promise<void>;
|
|
14
|
-
export declare const persistReducedUsageInfoFields: readonly ["typeId", "typePropertyId", "editable", "used", "formulaFunction", "validationFunction", "numberFormat", "defaultValue", "label", "required", "searchable", "isUniqueProperty", "isUniquePropertyInFamily", "copyBehavior", "copyDefault", "propertyLevel", "isArchived", "isFederationProperty", "carryOverBehavior", "carryOverDefault"];
|
|
15
|
-
export declare function transformReducedUsageInfoToTypeIdsFromPath(reducedUsageInfo: any, types: any): PersistReducedUsageInfo | undefined;
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transformReducedUsageInfoToTypeIdsFromPath = exports.persistReducedUsageInfoFields = exports.uploadUsageInfo = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const sdk_1 = require("@contrail/sdk");
|
|
6
|
-
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
7
|
-
const login_1 = require("../../auth/login");
|
|
8
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
9
|
-
const path = tslib_1.__importStar(require("path"));
|
|
10
|
-
const core_1 = require("@oclif/core");
|
|
11
|
-
const type_extractor_1 = require("../../helpers/types/type-extractor");
|
|
12
|
-
const basecommand_1 = require("../../basecommand");
|
|
13
|
-
const logger_1 = tslib_1.__importDefault(require("../../logger"));
|
|
14
|
-
const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
|
|
15
|
-
class UploadUsageInfo extends basecommand_1.BaseCommand {
|
|
16
|
-
static description = 'Upload extracted usage info';
|
|
17
|
-
static examples = [
|
|
18
|
-
`$ contrail types uploadUsageInfo
|
|
19
|
-
`,
|
|
20
|
-
];
|
|
21
|
-
static flags = {
|
|
22
|
-
...basecommand_1.BaseCommand.baseFlags,
|
|
23
|
-
dir: core_1.Flags.string({
|
|
24
|
-
char: 'd',
|
|
25
|
-
description: 'The directory from which to export the usage info data. Defaults to the current directory. The usage info data will be loaded from $dir/usage-info.yml',
|
|
26
|
-
required: false,
|
|
27
|
-
default: '.',
|
|
28
|
-
}),
|
|
29
|
-
};
|
|
30
|
-
async run() {
|
|
31
|
-
await uploadUsageInfo(this.flags.dir);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.default = UploadUsageInfo;
|
|
35
|
-
async function uploadUsageInfo(dir) {
|
|
36
|
-
try {
|
|
37
|
-
await (0, login_1.authUser)();
|
|
38
|
-
logger_1.default.info(`${chalk_1.default.yellow.bold('USAGE INFO')} Uploading`);
|
|
39
|
-
const reducedUsageInfo = await loadUsageInfo(dir);
|
|
40
|
-
await uploadUsageInfoObjects(reducedUsageInfo);
|
|
41
|
-
logger_1.default.info(`${chalk_1.default.yellow.bold('USAGE INFO')} Uploaded`);
|
|
42
|
-
}
|
|
43
|
-
catch (e) {
|
|
44
|
-
logger_1.default.info(`${chalk_1.default.red.bold('FAIL')} Usage Info Upload Failed . ${e}`);
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
logger_1.default.info(`${chalk_1.default.green.bold('COMPLETE')} Usage Info Upload Complete.`);
|
|
48
|
-
}
|
|
49
|
-
exports.uploadUsageInfo = uploadUsageInfo;
|
|
50
|
-
function loadUsageInfo(dir) {
|
|
51
|
-
try {
|
|
52
|
-
const doc = js_yaml_1.default.load(fs_1.default.readFileSync(path.join(dir, 'usage-info.yml'), 'utf8'));
|
|
53
|
-
return doc;
|
|
54
|
-
}
|
|
55
|
-
catch (e) {
|
|
56
|
-
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
async function uploadUsageInfoObjects(loadedUsageInfo) {
|
|
60
|
-
const typesWithProperties = await (0, type_extractor_1.getTypes)();
|
|
61
|
-
const currentUsageInfo = await new sdk_1.Entities().get({
|
|
62
|
-
entityName: 'type-property-usage-info',
|
|
63
|
-
});
|
|
64
|
-
const currentUsageInfosHashes = {};
|
|
65
|
-
for (const currentUI of currentUsageInfo) {
|
|
66
|
-
const foundType = typesWithProperties.find((t) => t.id === currentUI.typeId);
|
|
67
|
-
const typeProperties = foundType?.typeProperties || [];
|
|
68
|
-
const foundTypeProperty = typeProperties.find((tp) => tp.id === currentUI.typePropertyId);
|
|
69
|
-
if (!foundType || !foundTypeProperty) {
|
|
70
|
-
logger_1.default.info(`skipping unhashable, invalid usage info: ${JSON.stringify(currentUI, null, 2)}`);
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
const hash = `${foundType.typePath}|${foundTypeProperty.slug}`;
|
|
74
|
-
currentUsageInfosHashes[hash] = currentUI;
|
|
75
|
-
}
|
|
76
|
-
const reducedUsageInfoHashes = {};
|
|
77
|
-
for (const loadedUI of loadedUsageInfo) {
|
|
78
|
-
const hash = `${loadedUI.typePath}|${loadedUI.typePropertySlug}`;
|
|
79
|
-
reducedUsageInfoHashes[hash] = loadedUI;
|
|
80
|
-
}
|
|
81
|
-
logger_1.default.debug(`current usage info: ${JSON.stringify(currentUsageInfo)}`);
|
|
82
|
-
logger_1.default.debug(`loaded usage info: ${JSON.stringify(loadedUsageInfo)}`);
|
|
83
|
-
for (const loadedUI of loadedUsageInfo) {
|
|
84
|
-
try {
|
|
85
|
-
const found = currentUsageInfosHashes[`${loadedUI.typePath}|${loadedUI.typePropertySlug}`];
|
|
86
|
-
const transformedUI = transformReducedUsageInfoToTypeIdsFromPath(loadedUI, typesWithProperties);
|
|
87
|
-
if (!transformedUI) {
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
if (!found) {
|
|
91
|
-
logger_1.default.debug(`Creating: ${JSON.stringify(transformedUI)}`);
|
|
92
|
-
await new sdk_1.Entities().create({
|
|
93
|
-
entityName: 'type-property-usage-info',
|
|
94
|
-
object: transformedUI,
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
logger_1.default.info(`Updating: ${JSON.stringify(transformedUI)}`);
|
|
99
|
-
await new sdk_1.Entities().update({
|
|
100
|
-
entityName: 'type-property-usage-info',
|
|
101
|
-
id: found.id,
|
|
102
|
-
object: transformedUI,
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
catch (err) {
|
|
107
|
-
logger_1.default.error(`Error Uploading usage info: ${err}`);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
for (const [hash, currentUI] of Object.entries(currentUsageInfosHashes)) {
|
|
111
|
-
try {
|
|
112
|
-
const found = reducedUsageInfoHashes[hash];
|
|
113
|
-
if (!found) {
|
|
114
|
-
logger_1.default.debug(`Creating: ${hash}`);
|
|
115
|
-
await new sdk_1.Entities().delete({
|
|
116
|
-
entityName: 'type-property-usage-info',
|
|
117
|
-
id: currentUI['id'],
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
catch (err) {
|
|
122
|
-
logger_1.default.error(`Error Deleting usage info: ${err}`);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
//This should contain the property keys in PersistReducedUsageInfo in interfaces.ts
|
|
127
|
-
//except for typePath and typePropertySlug which are used for transformation but not persisted to the database.
|
|
128
|
-
// If you add a new property to PersistReducedUsageInfo, you need to add it to this array to be persisted to the database.
|
|
129
|
-
exports.persistReducedUsageInfoFields = [
|
|
130
|
-
// 'typePath',
|
|
131
|
-
// 'typePropertySlug',
|
|
132
|
-
'typeId',
|
|
133
|
-
'typePropertyId',
|
|
134
|
-
'editable',
|
|
135
|
-
'used',
|
|
136
|
-
'formulaFunction',
|
|
137
|
-
'validationFunction',
|
|
138
|
-
'numberFormat',
|
|
139
|
-
'defaultValue',
|
|
140
|
-
'label',
|
|
141
|
-
'required',
|
|
142
|
-
'searchable',
|
|
143
|
-
'isUniqueProperty',
|
|
144
|
-
'isUniquePropertyInFamily',
|
|
145
|
-
'copyBehavior',
|
|
146
|
-
'copyDefault',
|
|
147
|
-
'propertyLevel',
|
|
148
|
-
'isArchived',
|
|
149
|
-
'isFederationProperty',
|
|
150
|
-
'carryOverBehavior',
|
|
151
|
-
'carryOverDefault',
|
|
152
|
-
];
|
|
153
|
-
// transforms the reduced Usage Info from name slugs to ids
|
|
154
|
-
function transformReducedUsageInfoToTypeIdsFromPath(reducedUsageInfo, types) {
|
|
155
|
-
const foundType = types.find((t) => t.typePath === reducedUsageInfo.typePath);
|
|
156
|
-
if (!foundType) {
|
|
157
|
-
logger_1.default.error(`Could not find type with typePath ${reducedUsageInfo.typePath} while transforming ${reducedUsageInfo.typePropertySlug}`);
|
|
158
|
-
return undefined;
|
|
159
|
-
}
|
|
160
|
-
const foundTypeProperty = foundType.typeProperties?.find((tp) => tp.slug === reducedUsageInfo.typePropertySlug);
|
|
161
|
-
if (!foundTypeProperty) {
|
|
162
|
-
logger_1.default.error(`Could not find type property with slug ${reducedUsageInfo.typePropertySlug} while transforming ${JSON.stringify(reducedUsageInfo)}`);
|
|
163
|
-
return undefined;
|
|
164
|
-
}
|
|
165
|
-
// Create a new object with only the properties that are in the persistReducedUsageInfoFields array
|
|
166
|
-
// If there is a compile error on the code below, it means you added a new property to PersistReducedUsageInfo
|
|
167
|
-
// interface in interfaces.ts but forgot to add it to the persistReducedUsageInfoFields array above,
|
|
168
|
-
// It needs to be added to be persisted to the database.
|
|
169
|
-
const persistedUsageInfo = {
|
|
170
|
-
typeId: foundType.id,
|
|
171
|
-
typePropertyId: foundTypeProperty.id,
|
|
172
|
-
};
|
|
173
|
-
for (const key of Object.keys(reducedUsageInfo)) {
|
|
174
|
-
if (exports.persistReducedUsageInfoFields.includes(key)) {
|
|
175
|
-
persistedUsageInfo[key] = reducedUsageInfo[key];
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return persistedUsageInfo;
|
|
179
|
-
}
|
|
180
|
-
exports.transformReducedUsageInfoToTypeIdsFromPath = transformReducedUsageInfoToTypeIdsFromPath;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|