@contrail/cli 3.5.3-alpha.73bd011 → 3.5.3-alpha.b5668f4
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 +11 -5
- package/dist/commands/workflow-templates/export.d.ts +3 -1
- package/dist/commands/workflow-templates/export.js +99 -28
- package/dist/helpers/workflow-templates/helper.d.ts +1 -0
- package/dist/helpers/workflow-templates/helper.js +32 -9
- package/node_modules/@contrail/org-config-migration/.github/workflows/publish-to-npm.yml +117 -0
- package/node_modules/@contrail/org-config-migration/.husky/pre-commit +0 -0
- package/node_modules/@contrail/org-config-migration/lib/index.d.ts +3 -3
- package/node_modules/@contrail/org-config-migration/lib/index.js +19 -19
- package/node_modules/@contrail/org-config-migration/lib/interfaces.d.ts +87 -97
- package/node_modules/@contrail/org-config-migration/lib/interfaces.js +2 -2
- package/node_modules/@contrail/org-config-migration/lib/services/index.d.ts +1 -1
- package/node_modules/@contrail/org-config-migration/lib/services/index.js +17 -17
- package/node_modules/@contrail/org-config-migration/lib/services/types.d.ts +12 -17
- package/node_modules/@contrail/org-config-migration/lib/services/types.js +115 -155
- package/node_modules/@contrail/org-config-migration/lib/types/exportAll.d.ts +2 -2
- package/node_modules/@contrail/org-config-migration/lib/types/exportAll.js +34 -40
- package/node_modules/@contrail/org-config-migration/lib/types/exportOptionSet.d.ts +2 -2
- package/node_modules/@contrail/org-config-migration/lib/types/exportOptionSet.js +20 -20
- package/node_modules/@contrail/org-config-migration/lib/types/exportOptionSetHierarchies.d.ts +2 -3
- package/node_modules/@contrail/org-config-migration/lib/types/exportOptionSetHierarchies.js +16 -47
- package/node_modules/@contrail/org-config-migration/lib/types/exportOverrides.d.ts +2 -2
- package/node_modules/@contrail/org-config-migration/lib/types/exportOverrides.js +8 -8
- package/node_modules/@contrail/org-config-migration/lib/types/exportRuleSets.d.ts +2 -3
- package/node_modules/@contrail/org-config-migration/lib/types/exportRuleSets.js +14 -39
- package/node_modules/@contrail/org-config-migration/lib/types/exportTypePolicies.d.ts +2 -3
- package/node_modules/@contrail/org-config-migration/lib/types/exportTypePolicies.js +44 -56
- package/node_modules/@contrail/org-config-migration/lib/types/exportTypePropertyPolicies.d.ts +2 -3
- package/node_modules/@contrail/org-config-migration/lib/types/exportTypePropertyPolicies.js +44 -71
- package/node_modules/@contrail/org-config-migration/lib/types/exportTypes.d.ts +2 -2
- package/node_modules/@contrail/org-config-migration/lib/types/exportTypes.js +85 -85
- package/node_modules/@contrail/org-config-migration/lib/types/importAll.d.ts +2 -2
- package/node_modules/@contrail/org-config-migration/lib/types/importAll.js +386 -451
- package/node_modules/@contrail/org-config-migration/lib/types/index.d.ts +8 -9
- package/node_modules/@contrail/org-config-migration/lib/types/index.js +24 -25
- package/node_modules/@contrail/org-config-migration/lib/types/parseOptionSetHierarchy.d.ts +3 -3
- package/node_modules/@contrail/org-config-migration/lib/types/parseOptionSetHierarchy.js +210 -210
- package/node_modules/@contrail/org-config-migration/lib/users/export.d.ts +2 -2
- package/node_modules/@contrail/org-config-migration/lib/users/export.js +40 -40
- package/node_modules/@contrail/org-config-migration/lib/users/import.d.ts +2 -2
- package/node_modules/@contrail/org-config-migration/lib/users/import.js +41 -41
- package/node_modules/@contrail/org-config-migration/lib/users/index.d.ts +2 -2
- package/node_modules/@contrail/org-config-migration/lib/users/index.js +18 -18
- package/node_modules/@contrail/org-config-migration/package.json +1 -1
- package/oclif.manifest.json +15 -5
- package/package.json +2 -2
- package/node_modules/@contrail/org-config-migration/lib/types/exportUsageInfo.d.ts +0 -2
- package/node_modules/@contrail/org-config-migration/lib/types/exportUsageInfo.js +0 -39
|
@@ -1,451 +1,386 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.importReducedData = void 0;
|
|
16
|
-
const sdk_1 = require("@contrail/sdk");
|
|
17
|
-
const p_limit_1 = __importDefault(require("p-limit"));
|
|
18
|
-
const lodash_1 = require("lodash");
|
|
19
|
-
const limit = (0, p_limit_1.default)(5);
|
|
20
|
-
function importReducedData(reducedData, skipPolicies = false) {
|
|
21
|
-
var _a, _b, _c, _d, _e, _f
|
|
22
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
if (!reducedData) {
|
|
24
|
-
throw new Error('Reduced data is required');
|
|
25
|
-
}
|
|
26
|
-
const entities = new sdk_1.Entities();
|
|
27
|
-
if (((_a = reducedData.reducedOptionSets) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
28
|
-
yield importOptionSets(reducedData.reducedOptionSets, entities);
|
|
29
|
-
}
|
|
30
|
-
if (((_b = reducedData.reducedTypes) === null || _b === void 0 ? void 0 : _b.length) > 0) {
|
|
31
|
-
yield importComplexTypes(reducedData.reducedTypes);
|
|
32
|
-
}
|
|
33
|
-
if (((_c = reducedData.reducedOptionSetHierarchies) === null || _c === void 0 ? void 0 : _c.length) > 0) {
|
|
34
|
-
yield importOptionSetHierarchies(reducedData.reducedOptionSetHierarchies, entities);
|
|
35
|
-
}
|
|
36
|
-
if (((_d = reducedData.
|
|
37
|
-
yield
|
|
38
|
-
}
|
|
39
|
-
if (
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
if (((
|
|
43
|
-
yield
|
|
44
|
-
}
|
|
45
|
-
if (((
|
|
46
|
-
yield
|
|
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
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
'
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
'
|
|
308
|
-
'
|
|
309
|
-
'
|
|
310
|
-
'
|
|
311
|
-
'
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
object: info,
|
|
388
|
-
});
|
|
389
|
-
}))));
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
function importRuleSets(ruleSets, entitiesInstance) {
|
|
393
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
394
|
-
yield Promise.all(ruleSets.map((ruleSet) => limit(() => __awaiter(this, void 0, void 0, function* () {
|
|
395
|
-
yield entitiesInstance.create({
|
|
396
|
-
entityName: 'rule-set',
|
|
397
|
-
object: ruleSet,
|
|
398
|
-
});
|
|
399
|
-
}))));
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
function importRuleSetLinks(links, entitiesInstance) {
|
|
403
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
404
|
-
yield Promise.all(links.map((link) => limit(() => __awaiter(this, void 0, void 0, function* () {
|
|
405
|
-
yield entitiesInstance.create({
|
|
406
|
-
entityName: 'rule-set-link',
|
|
407
|
-
object: link,
|
|
408
|
-
});
|
|
409
|
-
}))));
|
|
410
|
-
});
|
|
411
|
-
}
|
|
412
|
-
function importTypePropertyPolicies(policies, entitiesInstance) {
|
|
413
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
414
|
-
yield Promise.all(policies.map((policy) => limit(() => __awaiter(this, void 0, void 0, function* () {
|
|
415
|
-
yield entitiesInstance.create({
|
|
416
|
-
entityName: 'type-property-policy',
|
|
417
|
-
object: policy,
|
|
418
|
-
});
|
|
419
|
-
}))));
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
function importTypePropertyPolicyLinks(links, entitiesInstance) {
|
|
423
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
424
|
-
yield Promise.all(links.map((link) => limit(() => __awaiter(this, void 0, void 0, function* () {
|
|
425
|
-
yield entitiesInstance.create({
|
|
426
|
-
entityName: 'type-property-policy-link',
|
|
427
|
-
object: link,
|
|
428
|
-
});
|
|
429
|
-
}))));
|
|
430
|
-
});
|
|
431
|
-
}
|
|
432
|
-
function importTypePolicies(policies, entitiesInstance) {
|
|
433
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
434
|
-
yield Promise.all(policies.map((policy) => limit(() => __awaiter(this, void 0, void 0, function* () {
|
|
435
|
-
yield entitiesInstance.create({
|
|
436
|
-
entityName: 'type-policy',
|
|
437
|
-
object: policy,
|
|
438
|
-
});
|
|
439
|
-
}))));
|
|
440
|
-
});
|
|
441
|
-
}
|
|
442
|
-
function importTypePolicyLinks(links, entitiesInstance) {
|
|
443
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
444
|
-
yield Promise.all(links.map((link) => limit(() => __awaiter(this, void 0, void 0, function* () {
|
|
445
|
-
yield entitiesInstance.create({
|
|
446
|
-
entityName: 'type-policy-link',
|
|
447
|
-
object: link,
|
|
448
|
-
});
|
|
449
|
-
}))));
|
|
450
|
-
});
|
|
451
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.importReducedData = void 0;
|
|
16
|
+
const sdk_1 = require("@contrail/sdk");
|
|
17
|
+
const p_limit_1 = __importDefault(require("p-limit"));
|
|
18
|
+
const lodash_1 = require("lodash");
|
|
19
|
+
const limit = (0, p_limit_1.default)(5);
|
|
20
|
+
function importReducedData(reducedData, skipPolicies = false) {
|
|
21
|
+
var _a, _b, _c, _d, _e, _f;
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
if (!reducedData) {
|
|
24
|
+
throw new Error('Reduced data is required');
|
|
25
|
+
}
|
|
26
|
+
const entities = new sdk_1.Entities();
|
|
27
|
+
if (((_a = reducedData.reducedOptionSets) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
28
|
+
yield importOptionSets(reducedData.reducedOptionSets, entities);
|
|
29
|
+
}
|
|
30
|
+
if (((_b = reducedData.reducedTypes) === null || _b === void 0 ? void 0 : _b.length) > 0) {
|
|
31
|
+
yield importComplexTypes(reducedData.reducedTypes);
|
|
32
|
+
}
|
|
33
|
+
if (((_c = reducedData.reducedOptionSetHierarchies) === null || _c === void 0 ? void 0 : _c.length) > 0) {
|
|
34
|
+
yield importOptionSetHierarchies(reducedData.reducedOptionSetHierarchies, entities);
|
|
35
|
+
}
|
|
36
|
+
if (((_d = reducedData.reducedRuleSets) === null || _d === void 0 ? void 0 : _d.length) > 0) {
|
|
37
|
+
yield importRuleSets(reducedData.reducedRuleSets, entities);
|
|
38
|
+
}
|
|
39
|
+
if (skipPolicies) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (((_e = reducedData.reducedTypePropertyPolicies) === null || _e === void 0 ? void 0 : _e.length) > 0) {
|
|
43
|
+
yield importTypePropertyPolicies(reducedData.reducedTypePropertyPolicies, entities);
|
|
44
|
+
}
|
|
45
|
+
if (((_f = reducedData.reducedTypePolicies) === null || _f === void 0 ? void 0 : _f.length) > 0) {
|
|
46
|
+
yield importTypePolicies(reducedData.reducedTypePolicies, entities);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
exports.importReducedData = importReducedData;
|
|
51
|
+
function extractValueDifferences(object1, object2, keysToIgnore) {
|
|
52
|
+
const updates = [];
|
|
53
|
+
const object1Keys = Object.keys(object1);
|
|
54
|
+
const object2keys = Object.keys(object2);
|
|
55
|
+
const adds = object2keys.filter((key) => !object1Keys.includes(key) && !keysToIgnore.includes(key));
|
|
56
|
+
const deletions = object1Keys.filter((key) => !object2keys.includes(key) && !keysToIgnore.includes(key));
|
|
57
|
+
const shared = object1Keys.filter((key) => object2keys.includes(key) && !keysToIgnore.includes(key));
|
|
58
|
+
for (const key of shared) {
|
|
59
|
+
if (!(0, lodash_1.isEqual)(object1[key], object2[key])) {
|
|
60
|
+
updates.push(key);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
adds,
|
|
65
|
+
updates,
|
|
66
|
+
deletions,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function importComplexTypes(types) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
const currentTypesWithoutProperties = yield new sdk_1.Entities().get({
|
|
72
|
+
entityName: 'type',
|
|
73
|
+
});
|
|
74
|
+
const currentTypes = [];
|
|
75
|
+
yield Promise.all(currentTypesWithoutProperties.map((typeWithoutProps) => limit(() => __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
const typeWithProperties = yield new sdk_1.Entities().get({
|
|
77
|
+
entityName: 'type',
|
|
78
|
+
id: typeWithoutProps.id,
|
|
79
|
+
relations: ['typeProperties'],
|
|
80
|
+
});
|
|
81
|
+
currentTypes.push(typeWithProperties);
|
|
82
|
+
}))));
|
|
83
|
+
const currentTypesByTypePath = {};
|
|
84
|
+
for (const currentType of currentTypes) {
|
|
85
|
+
currentTypesByTypePath[currentType.typePath] = currentType;
|
|
86
|
+
}
|
|
87
|
+
const newTypesByTypePath = {};
|
|
88
|
+
for (const type of types) {
|
|
89
|
+
newTypesByTypePath[type.typePath] = type;
|
|
90
|
+
}
|
|
91
|
+
const optionSets = yield new sdk_1.Entities().get({
|
|
92
|
+
entityName: 'type-property-option-set',
|
|
93
|
+
});
|
|
94
|
+
for (const type of types) {
|
|
95
|
+
if (!type) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
const found = currentTypesByTypePath[type.typePath];
|
|
100
|
+
if (!found) {
|
|
101
|
+
if (!type.typePath.includes(':')) {
|
|
102
|
+
console.log(`Cannot create a base type. Skipping: ${type.slug}`);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
console.log(`Creating Type: ${type.typePath}`);
|
|
106
|
+
const createdType = yield new sdk_1.Entities().create({
|
|
107
|
+
entityName: 'type',
|
|
108
|
+
object: {
|
|
109
|
+
slug: type.slug,
|
|
110
|
+
label: type.label,
|
|
111
|
+
typePath: type.typePath,
|
|
112
|
+
isArchived: type.isArchived,
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
const newTypeProperties = (yield new sdk_1.Types().getType({ id: createdType.id })).typeProperties;
|
|
116
|
+
yield uploadReducedTypeProperties(createdType, newTypeProperties, type.typeProperties, optionSets);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
const proposedType = {
|
|
120
|
+
slug: type.slug,
|
|
121
|
+
label: type.label,
|
|
122
|
+
typePath: type.typePath,
|
|
123
|
+
isArchived: type.isArchived,
|
|
124
|
+
};
|
|
125
|
+
const differences = extractValueDifferences(found, proposedType, [
|
|
126
|
+
'id',
|
|
127
|
+
'createdOn',
|
|
128
|
+
'updatedOn',
|
|
129
|
+
'createdById',
|
|
130
|
+
'updatedById',
|
|
131
|
+
'orgId',
|
|
132
|
+
'typeRootId',
|
|
133
|
+
'parentId',
|
|
134
|
+
'typePolicyIds',
|
|
135
|
+
'typePolicies',
|
|
136
|
+
'typeProperties',
|
|
137
|
+
'typePropertyPolicies',
|
|
138
|
+
'typeRuleSets',
|
|
139
|
+
'typeOptionSetHierarchyLinks',
|
|
140
|
+
'relations',
|
|
141
|
+
'typeInterfaces',
|
|
142
|
+
]);
|
|
143
|
+
if (differences.updates.length || differences.adds.length || differences.deletions.length) {
|
|
144
|
+
console.log(`Updating Type: ${type.typePath}`);
|
|
145
|
+
yield new sdk_1.Entities().update({
|
|
146
|
+
entityName: 'type',
|
|
147
|
+
id: found.id,
|
|
148
|
+
object: proposedType,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
yield uploadReducedTypeProperties(found, found.typeProperties, type.typeProperties, optionSets);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
catch (err) {
|
|
155
|
+
console.error(`Error processing type ${type.typePath}: ${err}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
function importOptionSets(optionSets, entitiesInstance) {
|
|
161
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
162
|
+
yield Promise.all(optionSets.map((optionSet) => limit(() => __awaiter(this, void 0, void 0, function* () {
|
|
163
|
+
try {
|
|
164
|
+
const existingOptionSets = yield entitiesInstance.get({
|
|
165
|
+
entityName: 'option-set',
|
|
166
|
+
});
|
|
167
|
+
const matchingOptionSets = existingOptionSets.filter((os) => os.slug === optionSet.slug);
|
|
168
|
+
if (matchingOptionSets.length > 0) {
|
|
169
|
+
const existing = matchingOptionSets[0];
|
|
170
|
+
yield entitiesInstance.update({
|
|
171
|
+
entityName: 'option-set',
|
|
172
|
+
id: existing.id,
|
|
173
|
+
object: optionSet,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
yield entitiesInstance.create({
|
|
178
|
+
entityName: 'option-set',
|
|
179
|
+
object: optionSet,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
catch (err) {
|
|
184
|
+
console.error(`Error importing option set ${optionSet.slug}: ${err}`);
|
|
185
|
+
}
|
|
186
|
+
}))));
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
function importTypes(types, entitiesInstance) {
|
|
190
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
191
|
+
yield Promise.all(types.map((type) => limit(() => __awaiter(this, void 0, void 0, function* () {
|
|
192
|
+
yield entitiesInstance.create({
|
|
193
|
+
entityName: 'type',
|
|
194
|
+
object: type,
|
|
195
|
+
});
|
|
196
|
+
}))));
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
function uploadReducedTypeProperties(type, currentPropertyTypes, newPropertyTypes, optionSets) {
|
|
200
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
|
|
201
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
202
|
+
if (!type || !currentPropertyTypes || !newPropertyTypes) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const currentPropertyTypeBySlug = {};
|
|
206
|
+
for (const currentPropertyType of currentPropertyTypes) {
|
|
207
|
+
currentPropertyTypeBySlug[currentPropertyType.slug] = currentPropertyType;
|
|
208
|
+
}
|
|
209
|
+
const newPropertyTypesBySlug = {};
|
|
210
|
+
for (const newPropertyType of newPropertyTypes) {
|
|
211
|
+
newPropertyTypesBySlug[newPropertyType.slug] = newPropertyType;
|
|
212
|
+
}
|
|
213
|
+
const optionSetIdBySlug = {};
|
|
214
|
+
for (const optionSet of optionSets) {
|
|
215
|
+
optionSetIdBySlug[optionSet.slug] = optionSet.id;
|
|
216
|
+
}
|
|
217
|
+
const userLists = yield new sdk_1.Entities().get({ entityName: 'user-list' });
|
|
218
|
+
for (const newPropertyType of newPropertyTypes) {
|
|
219
|
+
try {
|
|
220
|
+
let typePropertyUserListId = null;
|
|
221
|
+
if (newPropertyType.typePropertyUserListName) {
|
|
222
|
+
const userList = userLists.find((ul) => ul.name === newPropertyType.typePropertyUserListName);
|
|
223
|
+
if (userList) {
|
|
224
|
+
typePropertyUserListId = userList.id;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
const found = currentPropertyTypeBySlug[newPropertyType.slug];
|
|
228
|
+
if (!found) {
|
|
229
|
+
console.log(`Creating Type-Property: ${newPropertyType.slug}`);
|
|
230
|
+
yield sdk_1.Request.request(`/types/${type.id}/type-properties`, {
|
|
231
|
+
method: 'POST',
|
|
232
|
+
body: JSON.stringify({
|
|
233
|
+
isArchived: newPropertyType.isArchived,
|
|
234
|
+
propertyType: newPropertyType.propertyType,
|
|
235
|
+
slug: newPropertyType.slug,
|
|
236
|
+
label: newPropertyType.label,
|
|
237
|
+
editable: newPropertyType.editable,
|
|
238
|
+
searchable: newPropertyType.searchable,
|
|
239
|
+
core: newPropertyType.core,
|
|
240
|
+
typePropertyOptionSetId: optionSetIdBySlug[newPropertyType.typePropertyOptionSetSlug],
|
|
241
|
+
formula: newPropertyType.formula,
|
|
242
|
+
referencedTypePath: newPropertyType.referencedTypePath,
|
|
243
|
+
carryOverBehavior: newPropertyType.carryOverBehavior,
|
|
244
|
+
carryOverDefault: newPropertyType.carryOverDefault,
|
|
245
|
+
referencedTypeRootSlug: newPropertyType.referencedTypeRootSlug,
|
|
246
|
+
defaultValue: newPropertyType.defaultValue,
|
|
247
|
+
typePropertyUserListId,
|
|
248
|
+
referencedTypeRole: newPropertyType.referencedTypeRole,
|
|
249
|
+
isUniqueProperty: newPropertyType.isUniqueProperty,
|
|
250
|
+
isUniquePropertyInFamily: newPropertyType.isUniquePropertyInFamily,
|
|
251
|
+
propertyLevel: newPropertyType.propertyLevel,
|
|
252
|
+
formulaFunction: newPropertyType.formulaFunction,
|
|
253
|
+
validationFunction: newPropertyType.validationFunction,
|
|
254
|
+
numberFormat: newPropertyType.numberFormat,
|
|
255
|
+
sequenceSeedValue: newPropertyType.sequenceSeedValue,
|
|
256
|
+
copyBehavior: newPropertyType.copyBehavior,
|
|
257
|
+
}),
|
|
258
|
+
headers: {
|
|
259
|
+
Accept: 'application/json',
|
|
260
|
+
'Content-Type': 'application/json',
|
|
261
|
+
},
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
const proposedTP = {
|
|
266
|
+
isArchived: (_a = newPropertyType.isArchived) !== null && _a !== void 0 ? _a : null,
|
|
267
|
+
propertyType: (_b = newPropertyType.propertyType) !== null && _b !== void 0 ? _b : null,
|
|
268
|
+
slug: (_c = newPropertyType.slug) !== null && _c !== void 0 ? _c : null,
|
|
269
|
+
label: (_d = newPropertyType.label) !== null && _d !== void 0 ? _d : null,
|
|
270
|
+
editable: (_e = newPropertyType.editable) !== null && _e !== void 0 ? _e : null,
|
|
271
|
+
searchable: (_f = newPropertyType.searchable) !== null && _f !== void 0 ? _f : null,
|
|
272
|
+
core: (_g = newPropertyType.core) !== null && _g !== void 0 ? _g : null,
|
|
273
|
+
typePropertyOptionSetId: (_h = optionSetIdBySlug[newPropertyType.typePropertyOptionSetSlug]) !== null && _h !== void 0 ? _h : null,
|
|
274
|
+
formula: (_j = newPropertyType.formula) !== null && _j !== void 0 ? _j : null,
|
|
275
|
+
referencedTypePath: (_k = newPropertyType.referencedTypePath) !== null && _k !== void 0 ? _k : null,
|
|
276
|
+
carryOverBehavior: (_l = newPropertyType.carryOverBehavior) !== null && _l !== void 0 ? _l : null,
|
|
277
|
+
carryOverDefault: (_m = newPropertyType.carryOverDefault) !== null && _m !== void 0 ? _m : null,
|
|
278
|
+
referencedTypeRootSlug: (_o = newPropertyType.referencedTypeRootSlug) !== null && _o !== void 0 ? _o : null,
|
|
279
|
+
defaultValue: (_p = newPropertyType.defaultValue) !== null && _p !== void 0 ? _p : null,
|
|
280
|
+
propertyLevel: (_q = newPropertyType.propertyLevel) !== null && _q !== void 0 ? _q : null,
|
|
281
|
+
typePropertyUserListId,
|
|
282
|
+
referencedTypeRole: (_r = newPropertyType.referencedTypeRole) !== null && _r !== void 0 ? _r : null,
|
|
283
|
+
isUniqueProperty: (_s = newPropertyType.isUniqueProperty) !== null && _s !== void 0 ? _s : null,
|
|
284
|
+
isUniquePropertyInFamily: (_t = newPropertyType.isUniquePropertyInFamily) !== null && _t !== void 0 ? _t : null,
|
|
285
|
+
formulaFunction: (_u = newPropertyType.formulaFunction) !== null && _u !== void 0 ? _u : null,
|
|
286
|
+
validationFunction: (_v = newPropertyType.validationFunction) !== null && _v !== void 0 ? _v : null,
|
|
287
|
+
numberFormat: (_w = newPropertyType.numberFormat) !== null && _w !== void 0 ? _w : null,
|
|
288
|
+
sequenceSeedValue: (_x = newPropertyType.sequenceSeedValue) !== null && _x !== void 0 ? _x : null,
|
|
289
|
+
copyBehavior: (_y = newPropertyType.copyBehavior) !== null && _y !== void 0 ? _y : null,
|
|
290
|
+
};
|
|
291
|
+
const differences = extractValueDifferences(found, proposedTP, [
|
|
292
|
+
'id',
|
|
293
|
+
'createdOn',
|
|
294
|
+
'updatedOn',
|
|
295
|
+
'createdById',
|
|
296
|
+
'updatedById',
|
|
297
|
+
'orgId',
|
|
298
|
+
'typePropertyUserListId',
|
|
299
|
+
'referencedTypeRole',
|
|
300
|
+
'referencedTypeFilterProperties',
|
|
301
|
+
'referencedTypeId',
|
|
302
|
+
'description',
|
|
303
|
+
'apiDetails',
|
|
304
|
+
'notes',
|
|
305
|
+
'isFederationProperty',
|
|
306
|
+
'required',
|
|
307
|
+
'optionsSet',
|
|
308
|
+
'options',
|
|
309
|
+
'inherited',
|
|
310
|
+
'used',
|
|
311
|
+
'typePropertyPolicyIds',
|
|
312
|
+
]);
|
|
313
|
+
if (differences.updates.length || differences.adds.length || differences.deletions.length) {
|
|
314
|
+
console.log(`Updating Type-Property: ${newPropertyType.slug}`);
|
|
315
|
+
yield new sdk_1.Entities().update({
|
|
316
|
+
entityName: 'type-property',
|
|
317
|
+
id: found.id,
|
|
318
|
+
object: proposedTP,
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
catch (err) {
|
|
324
|
+
console.error(`Error managing type property ${newPropertyType.slug}: ${err}`);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
for (const currentPropertyType of currentPropertyTypes) {
|
|
328
|
+
try {
|
|
329
|
+
const found = newPropertyTypesBySlug[currentPropertyType.slug];
|
|
330
|
+
if (!found && !currentPropertyType.inherited) {
|
|
331
|
+
console.log(`Deleting Type-Property: ${currentPropertyType.slug}`);
|
|
332
|
+
yield sdk_1.Request.request(`/types/${type.id}/type-properties/${currentPropertyType.id}`, {
|
|
333
|
+
method: 'DELETE',
|
|
334
|
+
headers: {
|
|
335
|
+
Accept: 'application/json',
|
|
336
|
+
'Content-Type': 'application/json',
|
|
337
|
+
},
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
catch (err) {
|
|
342
|
+
console.error(`Error deleting type property ${currentPropertyType.slug}: ${err}`);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
function importOptionSetHierarchies(hierarchies, entitiesInstance) {
|
|
348
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
349
|
+
yield Promise.all(hierarchies.map((hierarchy) => limit(() => __awaiter(this, void 0, void 0, function* () {
|
|
350
|
+
yield entitiesInstance.create({
|
|
351
|
+
entityName: 'option-set-hierarchy',
|
|
352
|
+
object: hierarchy,
|
|
353
|
+
});
|
|
354
|
+
}))));
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
function importRuleSets(ruleSets, entitiesInstance) {
|
|
358
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
359
|
+
yield Promise.all(ruleSets.map((ruleSet) => limit(() => __awaiter(this, void 0, void 0, function* () {
|
|
360
|
+
yield entitiesInstance.create({
|
|
361
|
+
entityName: 'rule-set',
|
|
362
|
+
object: ruleSet,
|
|
363
|
+
});
|
|
364
|
+
}))));
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
function importTypePropertyPolicies(policies, entitiesInstance) {
|
|
368
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
369
|
+
yield Promise.all(policies.map((policy) => limit(() => __awaiter(this, void 0, void 0, function* () {
|
|
370
|
+
yield entitiesInstance.create({
|
|
371
|
+
entityName: 'type-property-policy',
|
|
372
|
+
object: policy,
|
|
373
|
+
});
|
|
374
|
+
}))));
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
function importTypePolicies(policies, entitiesInstance) {
|
|
378
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
379
|
+
yield Promise.all(policies.map((policy) => limit(() => __awaiter(this, void 0, void 0, function* () {
|
|
380
|
+
yield entitiesInstance.create({
|
|
381
|
+
entityName: 'type-policy',
|
|
382
|
+
object: policy,
|
|
383
|
+
});
|
|
384
|
+
}))));
|
|
385
|
+
});
|
|
386
|
+
}
|