@esri/solution-deployer 1.1.2 → 1.2.0
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/esm/deploySolutionFromTemplate.js +70 -66
- package/dist/esm/deploySolutionFromTemplate.js.map +1 -1
- package/dist/esm/deploySolutionItems.js +159 -166
- package/dist/esm/deploySolutionItems.js.map +1 -1
- package/dist/esm/deployer.js +13 -14
- package/dist/esm/deployer.js.map +1 -1
- package/dist/esm/deployerUtils.js +17 -22
- package/dist/esm/deployerUtils.js.map +1 -1
- package/dist/esm/helpers/post-process.js +12 -14
- package/dist/esm/helpers/post-process.js.map +1 -1
- package/dist/esm/helpers/share-templates-to-groups.js +29 -6
- package/dist/esm/helpers/share-templates-to-groups.js.map +1 -1
- package/dist/esm/helpers/sortTemplates.js +2 -4
- package/dist/esm/helpers/sortTemplates.js.map +1 -1
- package/dist/esm/module-map.js +2 -2
- package/dist/esm/module-map.js.map +1 -1
- package/dist/node/deploySolutionFromTemplate.js +76 -72
- package/dist/node/deploySolutionFromTemplate.js.map +1 -1
- package/dist/node/deploySolutionItems.js +161 -168
- package/dist/node/deploySolutionItems.js.map +1 -1
- package/dist/node/deployer.js +16 -17
- package/dist/node/deployer.js.map +1 -1
- package/dist/node/deployerUtils.js +18 -23
- package/dist/node/deployerUtils.js.map +1 -1
- package/dist/node/helpers/post-process.js +16 -18
- package/dist/node/helpers/post-process.js.map +1 -1
- package/dist/node/helpers/share-templates-to-groups.js +30 -7
- package/dist/node/helpers/share-templates-to-groups.js.map +1 -1
- package/dist/node/helpers/sortTemplates.js +2 -4
- package/dist/node/helpers/sortTemplates.js.map +1 -1
- package/dist/node/index.js +1 -1
- package/dist/node/module-map.js +9 -9
- package/dist/node/module-map.js.map +1 -1
- package/dist/umd/deployer.umd.js +1647 -1651
- package/dist/umd/deployer.umd.js.map +1 -1
- package/dist/umd/deployer.umd.min.js +3 -3
- package/dist/umd/deployer.umd.min.js.map +1 -1
- package/package.json +33 -33
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
*/
|
|
21
21
|
import * as common from "@esri/solution-common";
|
|
22
22
|
import { moduleMap } from "./module-map";
|
|
23
|
-
|
|
23
|
+
const UNSUPPORTED = null;
|
|
24
24
|
// ------------------------------------------------------------------------------------------------------------------ //
|
|
25
25
|
/**
|
|
26
26
|
* Deploys a set of items defined by templates.
|
|
@@ -36,28 +36,26 @@ var UNSUPPORTED = null;
|
|
|
36
36
|
* @return A promise that will resolve with the list of information about the created items
|
|
37
37
|
*/
|
|
38
38
|
export function deploySolutionItems(portalSharingUrl, storageItemId, templates, storageAuthentication, templateDictionary, deployedSolutionId, destinationAuthentication, options) {
|
|
39
|
-
return new Promise(
|
|
40
|
-
var _a;
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
41
40
|
// Prepare feedback mechanism
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
const totalEstimatedCost = _estimateDeploymentCost(templates) + 1; // solution items, plus avoid divide by 0
|
|
42
|
+
let percentDone = 10; // allow for previous deployment work
|
|
43
|
+
const progressPercentStep = (99 - percentDone) / totalEstimatedCost; // leave some % for caller for wrapup
|
|
44
|
+
const failedTemplateItemIds = [];
|
|
45
|
+
const deployedItemIds = [];
|
|
46
|
+
let statusOK = true;
|
|
48
47
|
// TODO: move to separate fn
|
|
49
|
-
|
|
50
|
-
) {
|
|
51
|
-
var _a;
|
|
48
|
+
const itemProgressCallback = (itemId, status, costUsed, createdItemId // supplied when status is EItemProgressStatus.Created or .Finished
|
|
49
|
+
) => {
|
|
52
50
|
percentDone += progressPercentStep * costUsed;
|
|
53
51
|
/* istanbul ignore else */
|
|
54
52
|
if (options.progressCallback) {
|
|
55
53
|
if (status === common.EItemProgressStatus.Finished) {
|
|
56
|
-
|
|
54
|
+
const event = {
|
|
57
55
|
event: common.SItemProgressStatus[status],
|
|
58
56
|
data: itemId
|
|
59
57
|
};
|
|
60
|
-
options.progressCallback(Math.round(percentDone), options.jobId,
|
|
58
|
+
options.progressCallback(Math.round(percentDone), options.jobId, event);
|
|
61
59
|
}
|
|
62
60
|
else {
|
|
63
61
|
options.progressCallback(Math.round(percentDone), options.jobId);
|
|
@@ -65,7 +63,7 @@ export function deploySolutionItems(portalSharingUrl, storageItemId, templates,
|
|
|
65
63
|
}
|
|
66
64
|
/* istanbul ignore if */
|
|
67
65
|
if (options.consoleProgress) {
|
|
68
|
-
console.log(Date.now(), itemId,
|
|
66
|
+
console.log(Date.now(), itemId, options.jobId ?? "", common.SItemProgressStatus[status], percentDone.toFixed(0) + "%", costUsed, createdItemId ? "==> " + createdItemId : "");
|
|
69
67
|
}
|
|
70
68
|
if (status === common.EItemProgressStatus.Created) {
|
|
71
69
|
deployedItemIds.push(createdItemId);
|
|
@@ -85,27 +83,27 @@ export function deploySolutionItems(portalSharingUrl, storageItemId, templates,
|
|
|
85
83
|
// Create an ordered graph of the templates so that dependencies are created before the items that need them.
|
|
86
84
|
// Because cycles are permitted, we also keep track of items that need to be patched later because their
|
|
87
85
|
// dependencies are necessarily created after they are created.
|
|
88
|
-
|
|
86
|
+
const { buildOrder, itemsToBePatched } = common.topologicallySortItems(templates);
|
|
89
87
|
// For each item in order from no dependencies to dependent on other items,
|
|
90
88
|
// * replace template symbols using template dictionary
|
|
91
89
|
// * create item in destination group
|
|
92
90
|
// * add created item's id into the template dictionary
|
|
93
|
-
|
|
94
|
-
|
|
91
|
+
const awaitAllItems = [];
|
|
92
|
+
const reuseItemsDef = _reuseDeployedItems(templates, options.enableItemReuse ?? false, templateDictionary, destinationAuthentication);
|
|
95
93
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
96
|
-
reuseItemsDef.then(
|
|
97
|
-
|
|
94
|
+
reuseItemsDef.then(() => {
|
|
95
|
+
const useExistingItemsDef = _useExistingItems(templates, common.getProp(templateDictionary, "params.useExisting"), templateDictionary, destinationAuthentication);
|
|
98
96
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
99
|
-
useExistingItemsDef.then(
|
|
97
|
+
useExistingItemsDef.then(() => {
|
|
100
98
|
templates = common.setNamesAndTitles(templates, templateDictionary.solutionItemId);
|
|
101
|
-
buildOrder.forEach(
|
|
99
|
+
buildOrder.forEach((id) => {
|
|
102
100
|
// Get the item's template out of the list of templates
|
|
103
|
-
|
|
101
|
+
const template = common.findTemplateInList(templates, id);
|
|
104
102
|
awaitAllItems.push(_createItemFromTemplateWhenReady(template, common.generateStorageFilePaths(portalSharingUrl, storageItemId, template.resources, options.storageVersion), storageAuthentication, templateDictionary, destinationAuthentication, itemProgressCallback));
|
|
105
103
|
});
|
|
106
104
|
// Wait until all items have been created
|
|
107
105
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
108
|
-
Promise.all(awaitAllItems).then(
|
|
106
|
+
Promise.all(awaitAllItems).then((clonedSolutionItems) => {
|
|
109
107
|
if (failedTemplateItemIds.length === 0) {
|
|
110
108
|
// Do we have any items to be patched (i.e., they refer to dependencies using the template id rather
|
|
111
109
|
// than the cloned id because the item had to be created before the dependency)? Flag these items
|
|
@@ -115,19 +113,17 @@ export function deploySolutionItems(portalSharingUrl, storageItemId, templates,
|
|
|
115
113
|
}
|
|
116
114
|
else {
|
|
117
115
|
// Delete created items
|
|
118
|
-
|
|
116
|
+
const progressOptions = {
|
|
119
117
|
consoleProgress: true
|
|
120
118
|
};
|
|
121
119
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
122
120
|
common
|
|
123
121
|
.deleteSolutionByComponents(deployedSolutionId, deployedItemIds, templates, templateDictionary, destinationAuthentication, progressOptions)
|
|
124
|
-
.then(
|
|
125
|
-
return reject(common.failWithIds(failedTemplateItemIds));
|
|
126
|
-
});
|
|
122
|
+
.then(() => reject(common.failWithIds(failedTemplateItemIds)));
|
|
127
123
|
}
|
|
128
124
|
});
|
|
129
125
|
});
|
|
130
|
-
},
|
|
126
|
+
}, e => {
|
|
131
127
|
console.error(e);
|
|
132
128
|
reject(common.fail(e));
|
|
133
129
|
});
|
|
@@ -141,13 +137,13 @@ export function deploySolutionItems(portalSharingUrl, storageItemId, templates,
|
|
|
141
137
|
* @param templates A collection of AGO item templates
|
|
142
138
|
*/
|
|
143
139
|
export function _flagPatchItemsForPostProcessing(itemsToBePatched, templateDictionary, templates) {
|
|
144
|
-
|
|
140
|
+
let itemIdsToBePatched = Object.keys(itemsToBePatched);
|
|
145
141
|
/* istanbul ignore else */
|
|
146
142
|
if (itemIdsToBePatched.length > 0) {
|
|
147
143
|
// Replace the ids of the items to be patched (which are template ids) with their cloned versions
|
|
148
|
-
itemIdsToBePatched = itemIdsToBePatched.map(
|
|
144
|
+
itemIdsToBePatched = itemIdsToBePatched.map(id => templateDictionary[id].itemId);
|
|
149
145
|
// Make sure that the items to be patched are flagged for post processing
|
|
150
|
-
templates.forEach(
|
|
146
|
+
templates.forEach(item => {
|
|
151
147
|
/* istanbul ignore else */
|
|
152
148
|
if (itemIdsToBePatched.includes(item.id)) {
|
|
153
149
|
item.postProcess = true;
|
|
@@ -168,16 +164,16 @@ export function _flagPatchItemsForPostProcessing(itemsToBePatched, templateDicti
|
|
|
168
164
|
export function _evaluateSharedViewSources(templates) {
|
|
169
165
|
// update the templates so we can defer the deployment when more than one view shares the same source
|
|
170
166
|
// these are not classic dependencies but are in some ways similar
|
|
171
|
-
|
|
167
|
+
const views = _getViews(templates);
|
|
172
168
|
_updateViewTemplates(templates, views);
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
Object.keys(viewHash).forEach(
|
|
177
|
-
|
|
178
|
-
_views.forEach(
|
|
179
|
-
|
|
180
|
-
|
|
169
|
+
const viewHash = _getViewHash(views);
|
|
170
|
+
let processed = [];
|
|
171
|
+
const visited = [];
|
|
172
|
+
Object.keys(viewHash).forEach(k => {
|
|
173
|
+
const _views = viewHash[k];
|
|
174
|
+
_views.forEach(cv => {
|
|
175
|
+
const template = common.findTemplateInList(templates, cv);
|
|
176
|
+
const syncViews = common.getProp(template, "properties.syncViews");
|
|
181
177
|
/* istanbul ignore else */
|
|
182
178
|
if (visited.indexOf(template.itemId) > -1) {
|
|
183
179
|
processed = processed.concat(syncViews);
|
|
@@ -212,9 +208,9 @@ export function _evaluateSharedViewSources(templates) {
|
|
|
212
208
|
*
|
|
213
209
|
*/
|
|
214
210
|
export function _updateViewTemplates(templates, views) {
|
|
215
|
-
views.forEach(
|
|
216
|
-
v.dependencies.forEach(
|
|
217
|
-
templates = templates.map(
|
|
211
|
+
views.forEach(v => {
|
|
212
|
+
v.dependencies.forEach((id) => {
|
|
213
|
+
templates = templates.map(t => {
|
|
218
214
|
/* istanbul ignore else */
|
|
219
215
|
if (common.getProp(t, "properties.service.isView") &&
|
|
220
216
|
t.dependencies.indexOf(id) > -1 &&
|
|
@@ -245,9 +241,9 @@ export function _updateViewTemplates(templates, views) {
|
|
|
245
241
|
* @protected
|
|
246
242
|
*/
|
|
247
243
|
export function _getViewHash(views) {
|
|
248
|
-
|
|
249
|
-
views.forEach(
|
|
250
|
-
v.dependencies.forEach(
|
|
244
|
+
const viewHash = {};
|
|
245
|
+
views.forEach(v => {
|
|
246
|
+
v.dependencies.forEach((d) => {
|
|
251
247
|
/* istanbul ignore else */
|
|
252
248
|
if (Object.keys(viewHash).indexOf(d) < 0) {
|
|
253
249
|
viewHash[d] = [v.id];
|
|
@@ -269,7 +265,7 @@ export function _getViewHash(views) {
|
|
|
269
265
|
* @protected
|
|
270
266
|
*/
|
|
271
267
|
export function _getViews(templates) {
|
|
272
|
-
return templates.reduce(
|
|
268
|
+
return templates.reduce((acc, v) => {
|
|
273
269
|
/* istanbul ignore else */
|
|
274
270
|
if (common.getProp(v, "properties.service.isView")) {
|
|
275
271
|
acc.push({
|
|
@@ -293,17 +289,17 @@ export function _getViews(templates) {
|
|
|
293
289
|
* @protected
|
|
294
290
|
*/
|
|
295
291
|
export function _reuseDeployedItems(templates, reuseItems, templateDictionary, authentication) {
|
|
296
|
-
return new Promise(
|
|
292
|
+
return new Promise((resolve, reject) => {
|
|
297
293
|
if (reuseItems) {
|
|
298
|
-
|
|
299
|
-
Promise.all(existingItemsByKeyword).then(
|
|
300
|
-
|
|
301
|
-
Promise.all(existingItemsByTag).then(
|
|
294
|
+
const existingItemsByKeyword = _findExistingItemByKeyword(templates, templateDictionary, authentication);
|
|
295
|
+
Promise.all(existingItemsByKeyword).then((existingItemsByKeywordResponse) => {
|
|
296
|
+
const existingItemsByTag = _handleExistingItems(existingItemsByKeywordResponse, templateDictionary, authentication, true);
|
|
297
|
+
Promise.all(existingItemsByTag).then(existingItemsByTagResponse => {
|
|
302
298
|
_handleExistingItems(existingItemsByTagResponse, templateDictionary, authentication, false);
|
|
303
299
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
304
300
|
_updateTemplateDictionary(templates, templateDictionary, authentication).then(resolve);
|
|
305
|
-
},
|
|
306
|
-
},
|
|
301
|
+
}, e => reject(common.fail(e)));
|
|
302
|
+
}, e => reject(common.fail(e)));
|
|
307
303
|
}
|
|
308
304
|
else {
|
|
309
305
|
resolve(null);
|
|
@@ -331,30 +327,30 @@ export function _reuseDeployedItems(templates, reuseItems, templateDictionary, a
|
|
|
331
327
|
* @protected
|
|
332
328
|
*/
|
|
333
329
|
export function _useExistingItems(templates, useExisting, templateDictionary, authentication) {
|
|
334
|
-
return new Promise(
|
|
330
|
+
return new Promise(resolve => {
|
|
335
331
|
if (useExisting) {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
Object.keys(templateDictionary.params).forEach(
|
|
340
|
-
|
|
332
|
+
const itemDefs = [];
|
|
333
|
+
const sourceIdHash = {};
|
|
334
|
+
const itemIds = [];
|
|
335
|
+
Object.keys(templateDictionary.params).forEach(k => {
|
|
336
|
+
const v = templateDictionary.params[k];
|
|
341
337
|
/* istanbul ignore else */
|
|
342
338
|
if (v.itemId && /[0-9A-F]{32}/i.test(k)) {
|
|
343
339
|
_updateTemplateDictionaryById(templateDictionary, k, v.itemId, v);
|
|
344
340
|
// need to check and set the typeKeyword if it doesn't exist on this service yet
|
|
345
341
|
// when the user has passed in an itemId that does not come from a previous deployment
|
|
346
|
-
|
|
347
|
-
|
|
342
|
+
itemDefs.push(common.getItemBase(v.itemId, authentication));
|
|
343
|
+
sourceIdHash[v.itemId] = k;
|
|
348
344
|
/* istanbul ignore else */
|
|
349
|
-
if (
|
|
350
|
-
|
|
345
|
+
if (itemIds.indexOf(k) < 0) {
|
|
346
|
+
itemIds.push(k);
|
|
351
347
|
}
|
|
352
348
|
}
|
|
353
349
|
});
|
|
354
350
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
355
|
-
_setTypekeywordForExisting(
|
|
351
|
+
_setTypekeywordForExisting(itemDefs, sourceIdHash, authentication).then(() => {
|
|
356
352
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
357
|
-
_updateTemplateDictionary(
|
|
353
|
+
_updateTemplateDictionary(itemIds.map(id => common.getTemplateById(templates, id)), templateDictionary, authentication).then(resolve);
|
|
358
354
|
});
|
|
359
355
|
}
|
|
360
356
|
else {
|
|
@@ -374,32 +370,32 @@ export function _useExistingItems(templates, useExisting, templateDictionary, au
|
|
|
374
370
|
* @return a promise to indicate when the requests are complete
|
|
375
371
|
*/
|
|
376
372
|
export function _setTypekeywordForExisting(itemDefs, sourceIdHash, authentication) {
|
|
377
|
-
return new Promise(
|
|
373
|
+
return new Promise(resolve => {
|
|
378
374
|
if (itemDefs.length > 0) {
|
|
379
|
-
Promise.all(itemDefs).then(
|
|
380
|
-
|
|
381
|
-
results.forEach(
|
|
382
|
-
|
|
375
|
+
Promise.all(itemDefs).then(results => {
|
|
376
|
+
const itemUpdateDefs = [];
|
|
377
|
+
results.forEach(result => {
|
|
378
|
+
const sourceId = sourceIdHash[result.id];
|
|
383
379
|
/* istanbul ignore else */
|
|
384
380
|
if (result && sourceId && result.typeKeywords) {
|
|
385
|
-
|
|
386
|
-
|
|
381
|
+
const sourceKeyword = `source-${sourceId}`;
|
|
382
|
+
const typeKeywords = result.typeKeywords;
|
|
387
383
|
/* istanbul ignore else */
|
|
388
384
|
if (typeKeywords.indexOf(sourceKeyword) < 0) {
|
|
389
385
|
typeKeywords.push(sourceKeyword);
|
|
390
|
-
|
|
386
|
+
const itemUpdate = { id: result.id, typeKeywords };
|
|
391
387
|
itemUpdateDefs.push(common.updateItem(itemUpdate, authentication));
|
|
392
388
|
}
|
|
393
389
|
}
|
|
394
390
|
});
|
|
395
391
|
// wait for updates to finish before we resolve
|
|
396
392
|
if (itemUpdateDefs.length > 0) {
|
|
397
|
-
Promise.all(itemUpdateDefs).then(resolve,
|
|
393
|
+
Promise.all(itemUpdateDefs).then(resolve, () => resolve(undefined));
|
|
398
394
|
}
|
|
399
395
|
else {
|
|
400
396
|
resolve(undefined);
|
|
401
397
|
}
|
|
402
|
-
},
|
|
398
|
+
}, () => resolve(undefined));
|
|
403
399
|
}
|
|
404
400
|
else {
|
|
405
401
|
resolve(undefined);
|
|
@@ -415,18 +411,18 @@ export function _setTypekeywordForExisting(itemDefs, sourceIdHash, authenticatio
|
|
|
415
411
|
* @protected
|
|
416
412
|
*/
|
|
417
413
|
export function _updateTemplateDictionary(templates, templateDictionary, authentication) {
|
|
418
|
-
return new Promise(
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
templates.forEach(
|
|
424
|
-
|
|
414
|
+
return new Promise(resolve => {
|
|
415
|
+
const defs = [];
|
|
416
|
+
const urls = [];
|
|
417
|
+
const types = [];
|
|
418
|
+
const ids = [];
|
|
419
|
+
templates.forEach(t => {
|
|
420
|
+
const templateInfo = templateDictionary[t.itemId];
|
|
425
421
|
/* istanbul ignore else */
|
|
426
422
|
if (templateInfo && templateInfo.url && templateInfo.itemId) {
|
|
427
423
|
/* istanbul ignore else */
|
|
428
424
|
if (t.item.type === "Feature Service") {
|
|
429
|
-
|
|
425
|
+
const enterpriseIDMapping = common.getProp(templateDictionary, `params.${t.itemId}.enterpriseIDMapping`);
|
|
430
426
|
Object.assign(templateDictionary[t.itemId], common.getLayerSettings(common.getLayersAndTables(t), templateInfo.url, templateInfo.itemId, enterpriseIDMapping));
|
|
431
427
|
// if the service has veiws keep track of the fields so we can use them to
|
|
432
428
|
// compare with the view fields
|
|
@@ -442,7 +438,7 @@ export function _updateTemplateDictionary(templates, templateDictionary, authent
|
|
|
442
438
|
/* istanbul ignore else */
|
|
443
439
|
if (urls.indexOf(templateInfo.url) < 0) {
|
|
444
440
|
defs.push(t.item.type === "Feature Service"
|
|
445
|
-
? common.rest_request(templateInfo.url, { authentication
|
|
441
|
+
? common.rest_request(templateInfo.url, { authentication })
|
|
446
442
|
: common.getItemBase(templateInfo.itemId, authentication));
|
|
447
443
|
urls.push(templateInfo.url);
|
|
448
444
|
types.push(t.item.type);
|
|
@@ -452,23 +448,23 @@ export function _updateTemplateDictionary(templates, templateDictionary, authent
|
|
|
452
448
|
});
|
|
453
449
|
if (defs.length > 0) {
|
|
454
450
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
455
|
-
Promise.all(defs.map(
|
|
451
|
+
Promise.all(defs.map(p => p.catch(e => e))).then(results => {
|
|
456
452
|
/* istanbul ignore else */
|
|
457
453
|
if (Array.isArray(results) && results.length > 0) {
|
|
458
|
-
|
|
459
|
-
results.forEach(
|
|
454
|
+
const fieldDefs = [];
|
|
455
|
+
results.forEach((r, i) => {
|
|
460
456
|
// a feature service result will contain a serviceItemId if it was successfully fetched
|
|
461
457
|
if (r.serviceItemId && types[i] === "Feature Service") {
|
|
462
|
-
Object.keys(templateDictionary).forEach(
|
|
463
|
-
|
|
458
|
+
Object.keys(templateDictionary).forEach(k => {
|
|
459
|
+
const v = templateDictionary[k];
|
|
464
460
|
/* istanbul ignore else */
|
|
465
461
|
if (v.itemId && v.itemId === r.serviceItemId) {
|
|
466
462
|
common.setDefaultSpatialReference(templateDictionary, k, r.spatialReference);
|
|
467
463
|
// keep the extent values from these responses as well
|
|
468
|
-
common.setCreateProp(templateDictionary, k
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
464
|
+
common.setCreateProp(templateDictionary, `${k}.defaultExtent`, r.fullExtent || r.initialExtent);
|
|
465
|
+
const layerIds = (r.layers || []).map((l) => l.id);
|
|
466
|
+
const tablesIds = (r.tables || []).map((t) => t.id);
|
|
467
|
+
fieldDefs.push(common.getExistingLayersAndTables(urls[i], layerIds.concat(tablesIds), authentication));
|
|
472
468
|
}
|
|
473
469
|
});
|
|
474
470
|
}
|
|
@@ -481,26 +477,26 @@ export function _updateTemplateDictionary(templates, templateDictionary, authent
|
|
|
481
477
|
}
|
|
482
478
|
}
|
|
483
479
|
});
|
|
484
|
-
if (
|
|
480
|
+
if (fieldDefs.length > 0) {
|
|
485
481
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
486
|
-
Promise.all(
|
|
487
|
-
layerTableResult.forEach(
|
|
488
|
-
l.forEach(
|
|
489
|
-
Object.keys(templateDictionary).forEach(
|
|
482
|
+
Promise.all(fieldDefs).then(layerTableResult => {
|
|
483
|
+
layerTableResult.forEach(l => {
|
|
484
|
+
l.forEach((ll) => {
|
|
485
|
+
Object.keys(templateDictionary).forEach(k => {
|
|
490
486
|
/* istanbul ignore else */
|
|
491
487
|
if (templateDictionary[k].itemId === ll.serviceItemId) {
|
|
492
|
-
|
|
493
|
-
Object.keys(templateDictionary).some(
|
|
488
|
+
let sourceId = "";
|
|
489
|
+
Object.keys(templateDictionary).some(_k => {
|
|
494
490
|
/* istanbul ignore else */
|
|
495
491
|
if (templateDictionary[_k].itemId === ll.serviceItemId) {
|
|
496
|
-
|
|
492
|
+
sourceId = _k;
|
|
497
493
|
return true;
|
|
498
494
|
}
|
|
499
495
|
});
|
|
500
|
-
|
|
501
|
-
if (
|
|
502
|
-
Object.keys(
|
|
503
|
-
if (
|
|
496
|
+
const enterpriseIDMapping = common.getProp(templateDictionary, `params.${sourceId}.enterpriseIDMapping`);
|
|
497
|
+
if (enterpriseIDMapping) {
|
|
498
|
+
Object.keys(enterpriseIDMapping).forEach(id => {
|
|
499
|
+
if (enterpriseIDMapping[id].toString() ===
|
|
504
500
|
ll.id.toString()) {
|
|
505
501
|
_setFields(templateDictionary, k, id, ll.fields);
|
|
506
502
|
}
|
|
@@ -541,7 +537,7 @@ export function _updateTemplateDictionary(templates, templateDictionary, authent
|
|
|
541
537
|
* @protected
|
|
542
538
|
*/
|
|
543
539
|
export function _setFields(templateDictionary, itemId, layerId, fields) {
|
|
544
|
-
|
|
540
|
+
const layerInfo = common.getProp(templateDictionary, `${itemId}.layer${layerId}`);
|
|
545
541
|
/* istanbul ignore else */
|
|
546
542
|
if (layerInfo && fields) {
|
|
547
543
|
layerInfo.fields = fields;
|
|
@@ -562,17 +558,17 @@ export function _setFields(templateDictionary, itemId, layerId, fields) {
|
|
|
562
558
|
export function _updateTemplateDictionaryForError(templateDictionary, itemId) {
|
|
563
559
|
/* istanbul ignore else */
|
|
564
560
|
if (itemId) {
|
|
565
|
-
|
|
566
|
-
Object.keys(templateDictionary).some(
|
|
561
|
+
let removeKey = "";
|
|
562
|
+
Object.keys(templateDictionary).some(k => {
|
|
567
563
|
/* istanbul ignore else */
|
|
568
564
|
if (templateDictionary[k].itemId === itemId) {
|
|
569
|
-
|
|
565
|
+
removeKey = k;
|
|
570
566
|
return true;
|
|
571
567
|
}
|
|
572
568
|
});
|
|
573
569
|
/* istanbul ignore else */
|
|
574
|
-
if (
|
|
575
|
-
delete templateDictionary[
|
|
570
|
+
if (removeKey !== "") {
|
|
571
|
+
delete templateDictionary[removeKey];
|
|
576
572
|
}
|
|
577
573
|
}
|
|
578
574
|
return templateDictionary;
|
|
@@ -589,30 +585,28 @@ export function _updateTemplateDictionaryForError(templateDictionary, itemId) {
|
|
|
589
585
|
*/
|
|
590
586
|
export function _handleExistingItems(existingItemsResponse, templateDictionary, authentication, addTagQuery) {
|
|
591
587
|
// if items are not found by type keyword search by tag
|
|
592
|
-
|
|
588
|
+
const existingItemsByTag = [Promise.resolve(null)];
|
|
593
589
|
/* istanbul ignore else */
|
|
594
590
|
if (existingItemsResponse && Array.isArray(existingItemsResponse)) {
|
|
595
|
-
existingItemsResponse.forEach(
|
|
591
|
+
existingItemsResponse.forEach(existingItem => {
|
|
596
592
|
/* istanbul ignore else */
|
|
597
|
-
if (Array.isArray(existingItem
|
|
598
|
-
|
|
599
|
-
|
|
593
|
+
if (Array.isArray(existingItem?.results)) {
|
|
594
|
+
let result;
|
|
595
|
+
const results = existingItem.results;
|
|
600
596
|
if (results.length === 1) {
|
|
601
597
|
result = results[0];
|
|
602
598
|
}
|
|
603
599
|
else if (results.length > 1) {
|
|
604
|
-
result = results.reduce(
|
|
605
|
-
return a.created > b.created ? a : b;
|
|
606
|
-
});
|
|
600
|
+
result = results.reduce((a, b) => a.created > b.created ? a : b);
|
|
607
601
|
}
|
|
608
602
|
else {
|
|
609
603
|
if (addTagQuery && existingItem.query) {
|
|
610
|
-
|
|
604
|
+
const tagQuery = existingItem.query.replace("typekeywords", "tags");
|
|
611
605
|
existingItemsByTag.push(_findExistingItem(tagQuery, authentication));
|
|
612
606
|
}
|
|
613
607
|
}
|
|
614
608
|
if (result) {
|
|
615
|
-
|
|
609
|
+
const sourceId = existingItem.query
|
|
616
610
|
? existingItem.query.match(/[0-9A-F]{32}/i)[0]
|
|
617
611
|
: existingItem.sourceId;
|
|
618
612
|
/* istanbul ignore else */
|
|
@@ -628,7 +622,7 @@ export function _handleExistingItems(existingItemsResponse, templateDictionary,
|
|
|
628
622
|
export function _updateTemplateDictionaryById(templateDictionary, sourceId, itemId, v) {
|
|
629
623
|
templateDictionary[sourceId] = Object.assign(templateDictionary[sourceId] || {}, {
|
|
630
624
|
def: Promise.resolve(common.generateEmptyCreationResponse(v.type, itemId)),
|
|
631
|
-
itemId
|
|
625
|
+
itemId,
|
|
632
626
|
name: v.name,
|
|
633
627
|
title: v.title,
|
|
634
628
|
url: v.url
|
|
@@ -643,17 +637,16 @@ export function _updateTemplateDictionaryById(templateDictionary, sourceId, item
|
|
|
643
637
|
* @protected
|
|
644
638
|
*/
|
|
645
639
|
export function _findExistingItemByKeyword(templates, templateDictionary, authentication) {
|
|
646
|
-
|
|
647
|
-
templates.forEach(
|
|
648
|
-
var _a;
|
|
640
|
+
const existingItemsDefs = [];
|
|
641
|
+
templates.forEach(template => {
|
|
649
642
|
if (template.item.type === "Group") {
|
|
650
|
-
|
|
643
|
+
const userGroups = templateDictionary.user?.groups;
|
|
651
644
|
/* istanbul ignore else */
|
|
652
645
|
if (Array.isArray(userGroups)) {
|
|
653
646
|
existingItemsDefs.push(Promise.resolve({
|
|
654
647
|
results: userGroups
|
|
655
|
-
.filter(
|
|
656
|
-
.map(
|
|
648
|
+
.filter(g => g.tags.indexOf(`source-${template.itemId}`) > -1)
|
|
649
|
+
.map(g => {
|
|
657
650
|
g.type = "Group";
|
|
658
651
|
return g;
|
|
659
652
|
}),
|
|
@@ -662,7 +655,7 @@ export function _findExistingItemByKeyword(templates, templateDictionary, authen
|
|
|
662
655
|
}
|
|
663
656
|
}
|
|
664
657
|
else {
|
|
665
|
-
existingItemsDefs.push(_findExistingItem(
|
|
658
|
+
existingItemsDefs.push(_findExistingItem(`typekeywords:source-${template.itemId} type:${template.item.type} owner:${templateDictionary.user.username}`, authentication));
|
|
666
659
|
}
|
|
667
660
|
});
|
|
668
661
|
return existingItemsDefs;
|
|
@@ -676,7 +669,7 @@ export function _findExistingItemByKeyword(templates, templateDictionary, authen
|
|
|
676
669
|
* @protected
|
|
677
670
|
*/
|
|
678
671
|
export function _findExistingItem(query, authentication) {
|
|
679
|
-
|
|
672
|
+
const searchOptions = {
|
|
680
673
|
q: query,
|
|
681
674
|
authentication: authentication,
|
|
682
675
|
pagingParam: { start: 1, num: 100 }
|
|
@@ -702,16 +695,16 @@ export function _createItemFromTemplateWhenReady(template, resourceFilePaths, st
|
|
|
702
695
|
// or if we have a basic entry without the deferred request for its creation, add it
|
|
703
696
|
if (!templateDictionary.hasOwnProperty(template.itemId) ||
|
|
704
697
|
!common.getProp(templateDictionary[template.itemId], "def")) {
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
698
|
+
let createResponse;
|
|
699
|
+
let statusCode = common.EItemProgressStatus.Unknown;
|
|
700
|
+
let itemHandler;
|
|
708
701
|
templateDictionary[template.itemId] =
|
|
709
702
|
templateDictionary[template.itemId] || {};
|
|
710
703
|
// Save the deferred for the use of items that depend on this item being created first
|
|
711
|
-
templateDictionary[template.itemId].def = new Promise(
|
|
704
|
+
templateDictionary[template.itemId].def = new Promise(resolve => {
|
|
712
705
|
// Wait until all of the item's dependencies are deployed
|
|
713
|
-
|
|
714
|
-
|
|
706
|
+
const _awaitDependencies = template.dependencies.reduce((acc, id) => {
|
|
707
|
+
const def = common.getProp(templateDictionary, `${id}.def`);
|
|
715
708
|
// can't use maybePush as that clones the object, which does not work for Promises
|
|
716
709
|
/* istanbul ignore else */
|
|
717
710
|
if (def) {
|
|
@@ -719,10 +712,10 @@ export function _createItemFromTemplateWhenReady(template, resourceFilePaths, st
|
|
|
719
712
|
}
|
|
720
713
|
return acc;
|
|
721
714
|
}, []);
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
? syncViews.reduce(
|
|
725
|
-
|
|
715
|
+
const syncViews = common.getProp(template, "properties.syncViews");
|
|
716
|
+
const awaitDependencies = syncViews && syncViews.length > 0
|
|
717
|
+
? syncViews.reduce((acc, v) => {
|
|
718
|
+
const def = common.getProp(templateDictionary, `${v}.def`);
|
|
726
719
|
/* istanbul ignore else */
|
|
727
720
|
if (def) {
|
|
728
721
|
acc.push(def);
|
|
@@ -731,55 +724,55 @@ export function _createItemFromTemplateWhenReady(template, resourceFilePaths, st
|
|
|
731
724
|
}, _awaitDependencies)
|
|
732
725
|
: _awaitDependencies;
|
|
733
726
|
Promise.all(awaitDependencies)
|
|
734
|
-
.then(
|
|
727
|
+
.then(() => {
|
|
735
728
|
// Find the conversion handler for this item type
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
if (!
|
|
739
|
-
if (
|
|
740
|
-
|
|
729
|
+
const templateType = template.type;
|
|
730
|
+
itemHandler = moduleMap[templateType];
|
|
731
|
+
if (!itemHandler || itemHandler === UNSUPPORTED) {
|
|
732
|
+
if (itemHandler === UNSUPPORTED) {
|
|
733
|
+
statusCode = common.EItemProgressStatus.Ignored;
|
|
741
734
|
throw new Error();
|
|
742
735
|
}
|
|
743
736
|
else {
|
|
744
|
-
|
|
737
|
+
statusCode = common.EItemProgressStatus.Failed;
|
|
745
738
|
throw new Error();
|
|
746
739
|
}
|
|
747
740
|
}
|
|
748
741
|
// Get the item's thumbnail
|
|
749
742
|
return common.getThumbnailFromStorageItem(storageAuthentication, resourceFilePaths);
|
|
750
743
|
})
|
|
751
|
-
.then(
|
|
744
|
+
.then(thumbnail => {
|
|
752
745
|
template.item.thumbnail = thumbnail;
|
|
753
746
|
// Delegate the creation of the item to the handler
|
|
754
747
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
755
|
-
return
|
|
748
|
+
return itemHandler.createItemFromTemplate(template, templateDictionary, destinationAuthentication, itemProgressCallback);
|
|
756
749
|
})
|
|
757
|
-
.then(
|
|
750
|
+
.then((response) => {
|
|
758
751
|
if (response.id === "") {
|
|
759
|
-
|
|
752
|
+
statusCode = common.EItemProgressStatus.Failed;
|
|
760
753
|
throw new Error("handled"); // fails to create item
|
|
761
754
|
}
|
|
762
755
|
/* istanbul ignore else */
|
|
763
|
-
|
|
764
|
-
if (
|
|
765
|
-
common.setCreateProp(templateDictionary, template.itemId + ".url",
|
|
756
|
+
createResponse = response;
|
|
757
|
+
if (createResponse.item.item.url) {
|
|
758
|
+
common.setCreateProp(templateDictionary, template.itemId + ".url", createResponse.item.item.url);
|
|
766
759
|
}
|
|
767
760
|
if (resourceFilePaths.length > 0) {
|
|
768
761
|
// Copy resources, metadata, form
|
|
769
|
-
return common.copyFilesFromStorageItem(storageAuthentication, resourceFilePaths, templateDictionary.folderId,
|
|
762
|
+
return common.copyFilesFromStorageItem(storageAuthentication, resourceFilePaths, templateDictionary.folderId, createResponse.id, destinationAuthentication, createResponse.item);
|
|
770
763
|
}
|
|
771
764
|
else {
|
|
772
765
|
return Promise.resolve(null);
|
|
773
766
|
}
|
|
774
767
|
})
|
|
775
|
-
.then(
|
|
776
|
-
resolve(
|
|
768
|
+
.then(() => {
|
|
769
|
+
resolve(createResponse);
|
|
777
770
|
})
|
|
778
|
-
.catch(
|
|
771
|
+
.catch(error => {
|
|
779
772
|
if (!error || error.message !== "handled") {
|
|
780
|
-
itemProgressCallback(template.itemId,
|
|
773
|
+
itemProgressCallback(template.itemId, statusCode === common.EItemProgressStatus.Unknown
|
|
781
774
|
? common.EItemProgressStatus.Failed
|
|
782
|
-
:
|
|
775
|
+
: statusCode, 0);
|
|
783
776
|
}
|
|
784
777
|
// Item type not supported or fails to get item dependencies
|
|
785
778
|
resolve(common.generateEmptyCreationResponse(template.type));
|
|
@@ -796,15 +789,15 @@ export function _createItemFromTemplateWhenReady(template, resourceFilePaths, st
|
|
|
796
789
|
* @protected
|
|
797
790
|
*/
|
|
798
791
|
export function _estimateDeploymentCost(templates) {
|
|
799
|
-
return templates.reduce(
|
|
792
|
+
return templates.reduce((accumulatedEstimatedCost, template) => {
|
|
800
793
|
return (accumulatedEstimatedCost + (template.estimatedDeploymentCostFactor || 1));
|
|
801
794
|
}, 0);
|
|
802
795
|
}
|
|
803
796
|
// TODO: Return a Promise vs array of promises
|
|
804
797
|
export function _getGroupUpdates(template, authentication, templateDictionary) {
|
|
805
|
-
|
|
806
|
-
return groups.map(
|
|
807
|
-
return common.shareItem(templateDictionary[sourceGroupId].itemId, template.itemId, authentication);
|
|
798
|
+
const groups = template.groups || [];
|
|
799
|
+
return groups.map((sourceGroupId) => {
|
|
800
|
+
return common.shareItem(templateDictionary[sourceGroupId].itemId, template.itemId, authentication, common.isTrackingViewTemplate(template) ? templateDictionary.locationTracking.owner : undefined);
|
|
808
801
|
});
|
|
809
802
|
}
|
|
810
803
|
//# sourceMappingURL=deploySolutionItems.js.map
|