@esri/solution-creator 6.0.2-alpha.24 → 6.0.2-alpha.250423
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/package.json +14 -14
- package/dist/cjs/createItemTemplate.d.ts +0 -117
- package/dist/cjs/createItemTemplate.js +0 -484
- package/dist/cjs/createItemTemplate.js.map +0 -1
- package/dist/cjs/creator.d.ts +0 -107
- package/dist/cjs/creator.js +0 -374
- package/dist/cjs/creator.js.map +0 -1
- package/dist/cjs/helpers/add-content-to-solution.d.ts +0 -159
- package/dist/cjs/helpers/add-content-to-solution.js +0 -561
- package/dist/cjs/helpers/add-content-to-solution.js.map +0 -1
- package/dist/cjs/helpers/template.d.ts +0 -30
- package/dist/cjs/helpers/template.js +0 -49
- package/dist/cjs/helpers/template.js.map +0 -1
- package/dist/cjs/index.d.ts +0 -23
- package/dist/cjs/index.js +0 -27
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/module-map.d.ts +0 -23
- package/dist/cjs/module-map.js +0 -234
- package/dist/cjs/module-map.js.map +0 -1
- package/dist/esm/createItemTemplate.d.ts +0 -117
- package/dist/esm/createItemTemplate.js +0 -471
- package/dist/esm/createItemTemplate.js.map +0 -1
- package/dist/esm/creator.d.ts +0 -107
- package/dist/esm/creator.js +0 -362
- package/dist/esm/creator.js.map +0 -1
- package/dist/esm/helpers/add-content-to-solution.d.ts +0 -159
- package/dist/esm/helpers/add-content-to-solution.js +0 -540
- package/dist/esm/helpers/add-content-to-solution.js.map +0 -1
- package/dist/esm/helpers/template.d.ts +0 -30
- package/dist/esm/helpers/template.js +0 -44
- package/dist/esm/helpers/template.js.map +0 -1
- package/dist/esm/index.d.ts +0 -23
- package/dist/esm/index.js +0 -24
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/module-map.d.ts +0 -23
- package/dist/esm/module-map.js +0 -230
- package/dist/esm/module-map.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@esri/solution-creator",
|
|
3
|
-
"version": "6.0.2-alpha.
|
|
3
|
+
"version": "6.0.2-alpha.250423",
|
|
4
4
|
"description": "Manages the creation of a Solution item for @esri/solution.js.",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -30,18 +30,18 @@
|
|
|
30
30
|
"@esri/arcgis-rest-request": "^3.7.0",
|
|
31
31
|
"@esri/arcgis-rest-service-admin": "^3.7.0",
|
|
32
32
|
"@esri/hub-common": "^15.23.2",
|
|
33
|
-
"@esri/solution-common": "^6.0.2-alpha.
|
|
34
|
-
"@esri/solution-feature-layer": "^6.0.2-alpha.
|
|
35
|
-
"@esri/solution-file": "^6.0.2-alpha.
|
|
36
|
-
"@esri/solution-form": "^6.0.2-alpha.
|
|
37
|
-
"@esri/solution-group": "^6.0.2-alpha.
|
|
38
|
-
"@esri/solution-hub-types": "^6.0.2-alpha.
|
|
39
|
-
"@esri/solution-simple-types": "^6.0.2-alpha.
|
|
40
|
-
"@esri/solution-storymap": "^6.0.2-alpha.
|
|
41
|
-
"@esri/solution-velocity": "^6.0.2-alpha.
|
|
42
|
-
"@esri/solution-web-experience": "^6.0.2-alpha.
|
|
43
|
-
"@esri/solution-web-tool": "^6.0.2-alpha.
|
|
44
|
-
"@esri/solution-workflow": "^6.0.2-alpha.
|
|
33
|
+
"@esri/solution-common": "^6.0.2-alpha.250423",
|
|
34
|
+
"@esri/solution-feature-layer": "^6.0.2-alpha.250423",
|
|
35
|
+
"@esri/solution-file": "^6.0.2-alpha.250423",
|
|
36
|
+
"@esri/solution-form": "^6.0.2-alpha.250423",
|
|
37
|
+
"@esri/solution-group": "^6.0.2-alpha.250423",
|
|
38
|
+
"@esri/solution-hub-types": "^6.0.2-alpha.250423",
|
|
39
|
+
"@esri/solution-simple-types": "^6.0.2-alpha.250423",
|
|
40
|
+
"@esri/solution-storymap": "^6.0.2-alpha.250423",
|
|
41
|
+
"@esri/solution-velocity": "^6.0.2-alpha.250423",
|
|
42
|
+
"@esri/solution-web-experience": "^6.0.2-alpha.250423",
|
|
43
|
+
"@esri/solution-web-tool": "^6.0.2-alpha.250423",
|
|
44
|
+
"@esri/solution-workflow": "^6.0.2-alpha.250423",
|
|
45
45
|
"tslib": "1.14.1"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
@@ -96,5 +96,5 @@
|
|
|
96
96
|
"esri",
|
|
97
97
|
"ES6"
|
|
98
98
|
],
|
|
99
|
-
"gitHead": "
|
|
99
|
+
"gitHead": "168358265a32ec53b2a718e3809001b15cddffe1"
|
|
100
100
|
}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
/** @license
|
|
2
|
-
* Copyright 2018 Esri
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
/**
|
|
17
|
-
* Manages creation of the template of a Solution item via the REST API.
|
|
18
|
-
*
|
|
19
|
-
* @module createItemTemplate
|
|
20
|
-
*/
|
|
21
|
-
import { IDatasourceInfo, IItemProgressCallback, IItemTemplate, ISourceFile, UserSession } from "@esri/solution-common";
|
|
22
|
-
/**
|
|
23
|
-
* Creates template for an AGO item and its dependencies
|
|
24
|
-
*
|
|
25
|
-
* @param solutionItemId The solution to contain the item
|
|
26
|
-
* @param itemId AGO id string
|
|
27
|
-
* @param templateDictionary Hash of facts
|
|
28
|
-
* @param srcAuthentication Credentials for requests to source items
|
|
29
|
-
* @param destAuthentication Authentication for requesting information from AGO about items to be included in solution item
|
|
30
|
-
* @param existingTemplates A collection of AGO item templates that can be referenced by newly-created templates
|
|
31
|
-
* @returns A promise which resolves with an array of resources for the item and its dependencies
|
|
32
|
-
* @private
|
|
33
|
-
*/
|
|
34
|
-
export declare function createItemTemplate(solutionItemId: string, itemId: string, templateDictionary: any, srcAuthentication: UserSession, destAuthentication: UserSession, existingTemplates: IItemTemplate[], itemProgressCallback: IItemProgressCallback): Promise<ISourceFile[]>;
|
|
35
|
-
/**
|
|
36
|
-
* Remove webtool resource files from Geoprocessing Service
|
|
37
|
-
* This needs to be done after fetched so we can read from the file before we remove it
|
|
38
|
-
*
|
|
39
|
-
* @param template The current template
|
|
40
|
-
* @param files The list of resource files for the given template
|
|
41
|
-
* @returns The updated template
|
|
42
|
-
*/
|
|
43
|
-
export declare function postProcessResourceFiles(template: IItemTemplate, files: ISourceFile[]): ISourceFile[];
|
|
44
|
-
/**
|
|
45
|
-
* Templatizes field references within specific template types.
|
|
46
|
-
* Currently only handles web applications
|
|
47
|
-
*
|
|
48
|
-
* @param templates List of solution templates
|
|
49
|
-
* @returns A list of templates that have templatized field references
|
|
50
|
-
*/
|
|
51
|
-
export declare function postProcessFieldReferences(templates: IItemTemplate[]): IItemTemplate[];
|
|
52
|
-
/**
|
|
53
|
-
* Get common properties that will support the templatization of field references
|
|
54
|
-
*
|
|
55
|
-
* @param templates List of solution templates
|
|
56
|
-
* @returns A list of IDataSourceInfo objects with key properties
|
|
57
|
-
* @private
|
|
58
|
-
*/
|
|
59
|
-
export declare function _getDatasourceInfos(templates: IItemTemplate[]): IDatasourceInfo[];
|
|
60
|
-
/**
|
|
61
|
-
* Creates a simple lookup object to quickly understand an items type and dependencies
|
|
62
|
-
* and associated web map layer ids based on itemId
|
|
63
|
-
*
|
|
64
|
-
* @param templates List of solution templates
|
|
65
|
-
* @returns The lookup object with type, dependencies, and webmap layer info
|
|
66
|
-
* @private
|
|
67
|
-
*/
|
|
68
|
-
export declare function _getTemplateTypeHash(templates: IItemTemplate[]): any;
|
|
69
|
-
/**
|
|
70
|
-
* Updates the lookup object with webmap layer info
|
|
71
|
-
* so we can know the id used within a map for a given feature service
|
|
72
|
-
*
|
|
73
|
-
* @param template A webmap solution template
|
|
74
|
-
* @returns The lookup object with webmap layer info added
|
|
75
|
-
* @private
|
|
76
|
-
*/
|
|
77
|
-
export declare function _updateWebMapHashInfo(template: IItemTemplate, hashItem: any): void;
|
|
78
|
-
/**
|
|
79
|
-
* Updates a templatized datasource URL with a layer id.
|
|
80
|
-
*
|
|
81
|
-
* @param dataSourceUrl Templatized datasource URL
|
|
82
|
-
* @param layerId Layer id
|
|
83
|
-
* @returns string Amended datasource URL
|
|
84
|
-
* @private
|
|
85
|
-
*/
|
|
86
|
-
export declare function _addLayerIdToDatasourceUrl(datasourceUrl?: string, layerId?: any): string;
|
|
87
|
-
/**
|
|
88
|
-
* Updates the datasource info objects by passing the webmap layer IDs from the lookup hash
|
|
89
|
-
* to the underlying feature service datasource infos
|
|
90
|
-
*
|
|
91
|
-
* @param datasourceInfos A webmap solution template
|
|
92
|
-
* @param templateTypeHash A simple lookup object populated with key item info
|
|
93
|
-
* @returns The updated datasource infos
|
|
94
|
-
* @private
|
|
95
|
-
*/
|
|
96
|
-
export declare function _addMapLayerIds(datasourceInfos: IDatasourceInfo[], templateTypeHash: any): IDatasourceInfo[];
|
|
97
|
-
/**
|
|
98
|
-
* Get feature service item IDs from applications webmaps
|
|
99
|
-
* As they are not explict dependencies of the application but are needed for field references
|
|
100
|
-
*
|
|
101
|
-
* @param template A webmap solution template
|
|
102
|
-
* @param templateTypeHash A simple lookup object populated with key item info
|
|
103
|
-
* @returns A list of feature service item IDs
|
|
104
|
-
* @private
|
|
105
|
-
*/
|
|
106
|
-
export declare function _getWebMapFSDependencies(template: IItemTemplate, templateTypeHash: any): string[];
|
|
107
|
-
/**
|
|
108
|
-
* Perform templatizations needed in an item's resources
|
|
109
|
-
*
|
|
110
|
-
* @param itemTemplate Item being templatized
|
|
111
|
-
* @param resourceItemFiles Resources for the item; these resources are modified as needed
|
|
112
|
-
* by the templatization
|
|
113
|
-
* @param srcAuthentication Credentials for requests to source items
|
|
114
|
-
*
|
|
115
|
-
* @returns A promise that resolves when all templatization has completed
|
|
116
|
-
*/
|
|
117
|
-
export declare function _templatizeResources(itemTemplate: IItemTemplate, resourceItemFiles: ISourceFile[], srcAuthentication: UserSession): Promise<void[]>;
|
|
@@ -1,484 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/** @license
|
|
3
|
-
* Copyright 2018 Esri
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports._templatizeResources = exports._getWebMapFSDependencies = exports._addMapLayerIds = exports._addLayerIdToDatasourceUrl = exports._updateWebMapHashInfo = exports._getTemplateTypeHash = exports._getDatasourceInfos = exports.postProcessFieldReferences = exports.postProcessResourceFiles = exports.createItemTemplate = void 0;
|
|
19
|
-
/**
|
|
20
|
-
* Manages creation of the template of a Solution item via the REST API.
|
|
21
|
-
*
|
|
22
|
-
* @module createItemTemplate
|
|
23
|
-
*/
|
|
24
|
-
const solution_common_1 = require("@esri/solution-common");
|
|
25
|
-
const hub_common_1 = require("@esri/hub-common");
|
|
26
|
-
const module_map_1 = require("./module-map");
|
|
27
|
-
// ------------------------------------------------------------------------------------------------------------------ //
|
|
28
|
-
/**
|
|
29
|
-
* Creates template for an AGO item and its dependencies
|
|
30
|
-
*
|
|
31
|
-
* @param solutionItemId The solution to contain the item
|
|
32
|
-
* @param itemId AGO id string
|
|
33
|
-
* @param templateDictionary Hash of facts
|
|
34
|
-
* @param srcAuthentication Credentials for requests to source items
|
|
35
|
-
* @param destAuthentication Authentication for requesting information from AGO about items to be included in solution item
|
|
36
|
-
* @param existingTemplates A collection of AGO item templates that can be referenced by newly-created templates
|
|
37
|
-
* @returns A promise which resolves with an array of resources for the item and its dependencies
|
|
38
|
-
* @private
|
|
39
|
-
*/
|
|
40
|
-
function createItemTemplate(solutionItemId, itemId, templateDictionary, srcAuthentication, destAuthentication, existingTemplates, itemProgressCallback) {
|
|
41
|
-
return new Promise((resolve) => {
|
|
42
|
-
// Check if item and its dependents are already in list or are queued
|
|
43
|
-
if ((0, solution_common_1.findTemplateInList)(existingTemplates, itemId)) {
|
|
44
|
-
resolve([]);
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
// Add the id as a placeholder to show that it is being fetched
|
|
48
|
-
existingTemplates.push((0, solution_common_1.createPlaceholderTemplate)(itemId));
|
|
49
|
-
itemProgressCallback(itemId, solution_common_1.EItemProgressStatus.Started, 0);
|
|
50
|
-
// Fetch the item
|
|
51
|
-
(0, solution_common_1.getItemBase)(itemId, srcAuthentication)
|
|
52
|
-
.catch(() => {
|
|
53
|
-
// If item query fails, try fetching item as a group
|
|
54
|
-
// Change its placeholder from an empty type to the Group type so that we can later distinguish
|
|
55
|
-
// between items and groups (the base info for a group doesn't include a type property)
|
|
56
|
-
(0, solution_common_1.replaceTemplate)(existingTemplates, itemId, (0, solution_common_1.createPlaceholderTemplate)(itemId, "Group"));
|
|
57
|
-
return (0, solution_common_1.getGroupBase)(itemId, srcAuthentication);
|
|
58
|
-
})
|
|
59
|
-
.then((itemInfo) => {
|
|
60
|
-
itemInfo = (0, solution_common_1.sanitizeJSON)(itemInfo);
|
|
61
|
-
// Save a record of items that we've added to the solution
|
|
62
|
-
templateDictionary[`${itemId}_type`] = {
|
|
63
|
-
type: itemInfo.type,
|
|
64
|
-
url: itemInfo.url,
|
|
65
|
-
};
|
|
66
|
-
if (!templateDictionary[itemId]) {
|
|
67
|
-
templateDictionary[itemId] = itemId;
|
|
68
|
-
}
|
|
69
|
-
// Save the URL as a symbol
|
|
70
|
-
if (itemInfo.url) {
|
|
71
|
-
templateDictionary[itemInfo.url] = "{{" + itemInfo.id + ".url}}";
|
|
72
|
-
itemInfo.origUrl = itemInfo.url;
|
|
73
|
-
}
|
|
74
|
-
const idTest = /^source-[0-9A-F]{32}/i;
|
|
75
|
-
// Remove any source-itemId type keywords
|
|
76
|
-
/* istanbul ignore else */
|
|
77
|
-
if (Array.isArray(itemInfo.typeKeywords)) {
|
|
78
|
-
itemInfo.typeKeywords = itemInfo.typeKeywords.filter((v) => (idTest.test(v) ? false : true));
|
|
79
|
-
}
|
|
80
|
-
// Remove any source-itemId tags
|
|
81
|
-
/* istanbul ignore else */
|
|
82
|
-
if (Array.isArray(itemInfo.tags)) {
|
|
83
|
-
itemInfo.tags = itemInfo.tags.filter((v) => (idTest.test(v) ? false : true));
|
|
84
|
-
}
|
|
85
|
-
const placeholder = (0, solution_common_1.findTemplateInList)(existingTemplates, itemId);
|
|
86
|
-
let itemType = placeholder.type;
|
|
87
|
-
if (!itemType) {
|
|
88
|
-
// Groups have this defined when their placeholder is created
|
|
89
|
-
itemType = itemInfo.type;
|
|
90
|
-
placeholder.type = itemType;
|
|
91
|
-
}
|
|
92
|
-
if (!itemInfo.type) {
|
|
93
|
-
itemInfo.type = itemType; // Groups don't have this property, so we'll patch it in
|
|
94
|
-
}
|
|
95
|
-
placeholder.item = {
|
|
96
|
-
...itemInfo,
|
|
97
|
-
};
|
|
98
|
-
// Interrupt process if progress callback returns `false`
|
|
99
|
-
if (!itemProgressCallback(itemId, solution_common_1.EItemProgressStatus.Created, 1)) {
|
|
100
|
-
itemProgressCallback(itemId, solution_common_1.EItemProgressStatus.Cancelled, 1);
|
|
101
|
-
resolve((0, solution_common_1.fail)("Cancelled"));
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
let itemHandler = module_map_1.moduleMap[itemType];
|
|
105
|
-
// Only allow processing of Geoprocessing Service if its defined as a Web Tool
|
|
106
|
-
if (itemType === "Geoprocessing Service") {
|
|
107
|
-
itemHandler = itemInfo.typeKeywords.indexOf("Web Tool") > -1 ? itemHandler : module_map_1.UNSUPPORTED;
|
|
108
|
-
}
|
|
109
|
-
if (!itemHandler || itemHandler === module_map_1.UNSUPPORTED) {
|
|
110
|
-
if (itemHandler === module_map_1.UNSUPPORTED) {
|
|
111
|
-
itemProgressCallback(itemId, solution_common_1.EItemProgressStatus.Ignored, 1);
|
|
112
|
-
resolve([]);
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
itemProgressCallback(itemId, solution_common_1.EItemProgressStatus.Failed, 1);
|
|
116
|
-
placeholder.properties["failed"] = true;
|
|
117
|
-
(0, solution_common_1.replaceTemplate)(existingTemplates, itemId, placeholder);
|
|
118
|
-
resolve((0, solution_common_1.fail)("The type of AGO item " + itemId + " ('" + itemType + "') is not supported at this time"));
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
// Handle original Story Maps with next-gen Story Maps
|
|
123
|
-
/* istanbul ignore else */
|
|
124
|
-
/* Not yet supported
|
|
125
|
-
if (storyMap.isAStoryMap(itemType, itemInfo.url)) {
|
|
126
|
-
itemHandler = storyMap;
|
|
127
|
-
} */
|
|
128
|
-
// Delegate the creation of the item to the handler
|
|
129
|
-
itemHandler
|
|
130
|
-
.convertItemToTemplate(itemInfo, destAuthentication, srcAuthentication, templateDictionary)
|
|
131
|
-
.then((itemTemplate) => {
|
|
132
|
-
let resourcePrepPromise = Promise.resolve([]);
|
|
133
|
-
// If the item type is Quick Capture, then we already have the resource files (except for the
|
|
134
|
-
// thumbnail) and just need to convert them into ISourceFile objects
|
|
135
|
-
if (itemTemplate.type === "QuickCapture Project") {
|
|
136
|
-
// Fetch thumbnail
|
|
137
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
138
|
-
resourcePrepPromise = (0, solution_common_1.getItemResourcesFilesFromPaths)([
|
|
139
|
-
(0, solution_common_1.generateSourceThumbnailPath)(srcAuthentication.portal, itemTemplate.itemId, itemTemplate.item.thumbnail),
|
|
140
|
-
], srcAuthentication).then((thumbnailFile) => {
|
|
141
|
-
itemTemplate.item.thumbnail = null; // not needed in this property; handled as a resource
|
|
142
|
-
const resourceSourceFiles = itemTemplate.resources
|
|
143
|
-
.map((file) => {
|
|
144
|
-
return {
|
|
145
|
-
itemId: itemTemplate.itemId,
|
|
146
|
-
file,
|
|
147
|
-
folder: itemTemplate.itemId,
|
|
148
|
-
filename: file.name,
|
|
149
|
-
};
|
|
150
|
-
})
|
|
151
|
-
.concat(thumbnailFile);
|
|
152
|
-
// Clear out the files from the itemTemplate.resources
|
|
153
|
-
itemTemplate.resources = [];
|
|
154
|
-
return resourceSourceFiles;
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
159
|
-
resourcePrepPromise = (0, solution_common_1.getItemResourcesPaths)(itemTemplate, solutionItemId, srcAuthentication, solution_common_1.SolutionTemplateFormatVersion).then((resourceItemFilePaths) => {
|
|
160
|
-
itemTemplate.item.thumbnail = null; // not needed in this property; handled as a resource
|
|
161
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
162
|
-
return (0, solution_common_1.getItemResourcesFilesFromPaths)(resourceItemFilePaths, srcAuthentication);
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
166
|
-
resourcePrepPromise.then(async (resourceItemFiles) => {
|
|
167
|
-
// Perform any custom processing needed on resource files
|
|
168
|
-
await _templatizeResources(itemTemplate, resourceItemFiles, srcAuthentication);
|
|
169
|
-
resourceItemFiles = postProcessResourceFiles(itemTemplate, resourceItemFiles);
|
|
170
|
-
// update the template's resources
|
|
171
|
-
itemTemplate.resources = itemTemplate.resources.concat(resourceItemFiles.map((file) => file.folder + "/" + file.filename));
|
|
172
|
-
// Set the value keyed by the id to the created template, replacing the placeholder template
|
|
173
|
-
(0, solution_common_1.replaceTemplate)(existingTemplates, itemTemplate.itemId, itemTemplate);
|
|
174
|
-
// Trace item dependencies
|
|
175
|
-
if (itemTemplate.dependencies.length === 0) {
|
|
176
|
-
itemProgressCallback(itemId, solution_common_1.EItemProgressStatus.Finished, 1);
|
|
177
|
-
resolve(resourceItemFiles);
|
|
178
|
-
}
|
|
179
|
-
else {
|
|
180
|
-
// Get its dependencies, asking each to get its dependents via
|
|
181
|
-
// recursive calls to this function
|
|
182
|
-
const dependentDfds = [];
|
|
183
|
-
itemTemplate.dependencies.forEach((dependentId) => {
|
|
184
|
-
if (!(0, solution_common_1.findTemplateInList)(existingTemplates, dependentId)) {
|
|
185
|
-
dependentDfds.push(createItemTemplate(solutionItemId, dependentId, templateDictionary, srcAuthentication, destAuthentication, existingTemplates, itemProgressCallback));
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
189
|
-
Promise.all(dependentDfds).then((dependentResourceItemFiles) => {
|
|
190
|
-
// Templatization of item and its dependencies done
|
|
191
|
-
itemProgressCallback(itemId, solution_common_1.EItemProgressStatus.Finished, 1);
|
|
192
|
-
resourceItemFiles = dependentResourceItemFiles.reduce((accumulator, currentValue) => accumulator.concat(currentValue), resourceItemFiles);
|
|
193
|
-
resolve(resourceItemFiles);
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
}, (error) => {
|
|
198
|
-
placeholder.properties["error"] = JSON.stringify(error);
|
|
199
|
-
(0, solution_common_1.replaceTemplate)(existingTemplates, itemId, placeholder);
|
|
200
|
-
itemProgressCallback(itemId, solution_common_1.EItemProgressStatus.Failed, 1);
|
|
201
|
-
resolve([]);
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
},
|
|
205
|
-
// Id not found or item is not accessible
|
|
206
|
-
() => {
|
|
207
|
-
// mock hasInvalidDesignations so this will be processed at the end
|
|
208
|
-
// as we do with living atlas layers
|
|
209
|
-
const t = (0, solution_common_1.findTemplateInList)(existingTemplates, itemId);
|
|
210
|
-
t.properties.hasInvalidDesignations = true;
|
|
211
|
-
// Skip items that we cannot fetch per issue #859
|
|
212
|
-
// Use finished rather than ignored
|
|
213
|
-
// ignored will cause the template to be removed before we can check for hasInvalidDesignations
|
|
214
|
-
itemProgressCallback(itemId, solution_common_1.EItemProgressStatus.Finished, 0);
|
|
215
|
-
resolve([]);
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
exports.createItemTemplate = createItemTemplate;
|
|
221
|
-
/**
|
|
222
|
-
* Remove webtool resource files from Geoprocessing Service
|
|
223
|
-
* This needs to be done after fetched so we can read from the file before we remove it
|
|
224
|
-
*
|
|
225
|
-
* @param template The current template
|
|
226
|
-
* @param files The list of resource files for the given template
|
|
227
|
-
* @returns The updated template
|
|
228
|
-
*/
|
|
229
|
-
function postProcessResourceFiles(template, files) {
|
|
230
|
-
return template.type === "Geoprocessing Service" ? files.filter((f) => f.filename.indexOf("webtool") < 0) : files;
|
|
231
|
-
}
|
|
232
|
-
exports.postProcessResourceFiles = postProcessResourceFiles;
|
|
233
|
-
/**
|
|
234
|
-
* Templatizes field references within specific template types.
|
|
235
|
-
* Currently only handles web applications
|
|
236
|
-
*
|
|
237
|
-
* @param templates List of solution templates
|
|
238
|
-
* @returns A list of templates that have templatized field references
|
|
239
|
-
*/
|
|
240
|
-
function postProcessFieldReferences(templates) {
|
|
241
|
-
const datasourceInfos = _getDatasourceInfos(templates);
|
|
242
|
-
const templateTypeHash = _getTemplateTypeHash(templates);
|
|
243
|
-
return templates.map((template) => {
|
|
244
|
-
/* istanbul ignore else */
|
|
245
|
-
if (template.type === "Web Mapping Application" || template.type === "Dashboard" || template.type === "Web Map") {
|
|
246
|
-
const webMapFSDependencies = _getWebMapFSDependencies(template, templateTypeHash);
|
|
247
|
-
const itemHandler = module_map_1.moduleMap[template.item.type];
|
|
248
|
-
/* istanbul ignore else */
|
|
249
|
-
if (itemHandler) {
|
|
250
|
-
const dependencies = webMapFSDependencies.concat(template.dependencies);
|
|
251
|
-
let dependentDatasources = datasourceInfos.filter((ds) => {
|
|
252
|
-
if (dependencies.indexOf(ds.itemId) > -1) {
|
|
253
|
-
return ds;
|
|
254
|
-
}
|
|
255
|
-
});
|
|
256
|
-
dependentDatasources = _addMapLayerIds(dependentDatasources, templateTypeHash);
|
|
257
|
-
if (dependentDatasources.length > 0) {
|
|
258
|
-
template = itemHandler.postProcessFieldReferences(template, dependentDatasources, template.item.type);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
return template;
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
exports.postProcessFieldReferences = postProcessFieldReferences;
|
|
266
|
-
// ------------------------------------------------------------------------------------------------------------------ //
|
|
267
|
-
/**
|
|
268
|
-
* Get common properties that will support the templatization of field references
|
|
269
|
-
*
|
|
270
|
-
* @param templates List of solution templates
|
|
271
|
-
* @returns A list of IDataSourceInfo objects with key properties
|
|
272
|
-
* @private
|
|
273
|
-
*/
|
|
274
|
-
function _getDatasourceInfos(templates) {
|
|
275
|
-
const datasourceInfos = [];
|
|
276
|
-
templates.forEach((t) => {
|
|
277
|
-
if (t.type === "Feature Service") {
|
|
278
|
-
const layers = (0, hub_common_1.getProp)(t, "properties.layers") || [];
|
|
279
|
-
const tables = (0, hub_common_1.getProp)(t, "properties.tables") || [];
|
|
280
|
-
const layersAndTables = layers.concat(tables);
|
|
281
|
-
layersAndTables.forEach((obj) => {
|
|
282
|
-
/* istanbul ignore else */
|
|
283
|
-
if (!(0, solution_common_1.hasDatasource)(datasourceInfos, t.itemId, obj.id)) {
|
|
284
|
-
datasourceInfos.push({
|
|
285
|
-
itemId: t.itemId,
|
|
286
|
-
layerId: obj.id,
|
|
287
|
-
fields: obj.fields,
|
|
288
|
-
basePath: t.itemId + ".layer" + obj.id + ".fields",
|
|
289
|
-
url: (0, hub_common_1.getProp)(t, "item.url"),
|
|
290
|
-
ids: [],
|
|
291
|
-
relationships: obj.relationships || [],
|
|
292
|
-
adminLayerInfo: obj.adminLayerInfo || {},
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
return datasourceInfos;
|
|
299
|
-
}
|
|
300
|
-
exports._getDatasourceInfos = _getDatasourceInfos;
|
|
301
|
-
/**
|
|
302
|
-
* Creates a simple lookup object to quickly understand an items type and dependencies
|
|
303
|
-
* and associated web map layer ids based on itemId
|
|
304
|
-
*
|
|
305
|
-
* @param templates List of solution templates
|
|
306
|
-
* @returns The lookup object with type, dependencies, and webmap layer info
|
|
307
|
-
* @private
|
|
308
|
-
*/
|
|
309
|
-
function _getTemplateTypeHash(templates) {
|
|
310
|
-
const templateTypeHash = {};
|
|
311
|
-
templates.forEach((template) => {
|
|
312
|
-
templateTypeHash[template.itemId] = {
|
|
313
|
-
type: template.type,
|
|
314
|
-
dependencies: template.dependencies,
|
|
315
|
-
};
|
|
316
|
-
if (template.type === "Web Map") {
|
|
317
|
-
_updateWebMapHashInfo(template, templateTypeHash[template.itemId]);
|
|
318
|
-
}
|
|
319
|
-
});
|
|
320
|
-
return templateTypeHash;
|
|
321
|
-
}
|
|
322
|
-
exports._getTemplateTypeHash = _getTemplateTypeHash;
|
|
323
|
-
/**
|
|
324
|
-
* Updates the lookup object with webmap layer info
|
|
325
|
-
* so we can know the id used within a map for a given feature service
|
|
326
|
-
*
|
|
327
|
-
* @param template A webmap solution template
|
|
328
|
-
* @returns The lookup object with webmap layer info added
|
|
329
|
-
* @private
|
|
330
|
-
*/
|
|
331
|
-
function _updateWebMapHashInfo(template, hashItem) {
|
|
332
|
-
const operationalLayers = (0, hub_common_1.getProp)(template, "data.operationalLayers") || [];
|
|
333
|
-
const tables = (0, hub_common_1.getProp)(template, "data.tables") || [];
|
|
334
|
-
const layersAndTables = operationalLayers.concat(tables);
|
|
335
|
-
if (layersAndTables && layersAndTables.length > 0) {
|
|
336
|
-
hashItem.layersAndTables = [];
|
|
337
|
-
layersAndTables.forEach((layer) => {
|
|
338
|
-
const obj = {};
|
|
339
|
-
let itemId;
|
|
340
|
-
/* istanbul ignore else */
|
|
341
|
-
if (layer.itemId) {
|
|
342
|
-
itemId = layer.itemId;
|
|
343
|
-
}
|
|
344
|
-
/* istanbul ignore else */
|
|
345
|
-
if (itemId) {
|
|
346
|
-
obj[(0, solution_common_1.cleanLayerBasedItemId)(itemId)] = {
|
|
347
|
-
id: layer.id,
|
|
348
|
-
url: layer.url,
|
|
349
|
-
};
|
|
350
|
-
hashItem.layersAndTables.push(obj);
|
|
351
|
-
}
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
exports._updateWebMapHashInfo = _updateWebMapHashInfo;
|
|
356
|
-
/**
|
|
357
|
-
* Updates a templatized datasource URL with a layer id.
|
|
358
|
-
*
|
|
359
|
-
* @param dataSourceUrl Templatized datasource URL
|
|
360
|
-
* @param layerId Layer id
|
|
361
|
-
* @returns string Amended datasource URL
|
|
362
|
-
* @private
|
|
363
|
-
*/
|
|
364
|
-
function _addLayerIdToDatasourceUrl(datasourceUrl, layerId) {
|
|
365
|
-
return datasourceUrl && !isNaN(layerId) ? datasourceUrl.replace(/[.]/, ".layer" + layerId + ".") : "";
|
|
366
|
-
}
|
|
367
|
-
exports._addLayerIdToDatasourceUrl = _addLayerIdToDatasourceUrl;
|
|
368
|
-
/**
|
|
369
|
-
* Updates the datasource info objects by passing the webmap layer IDs from the lookup hash
|
|
370
|
-
* to the underlying feature service datasource infos
|
|
371
|
-
*
|
|
372
|
-
* @param datasourceInfos A webmap solution template
|
|
373
|
-
* @param templateTypeHash A simple lookup object populated with key item info
|
|
374
|
-
* @returns The updated datasource infos
|
|
375
|
-
* @private
|
|
376
|
-
*/
|
|
377
|
-
function _addMapLayerIds(datasourceInfos, templateTypeHash) {
|
|
378
|
-
const webMapIds = Object.keys(templateTypeHash).filter((k) => {
|
|
379
|
-
if (templateTypeHash[k].type === "Web Map") {
|
|
380
|
-
return templateTypeHash[k];
|
|
381
|
-
}
|
|
382
|
-
});
|
|
383
|
-
return datasourceInfos.map((ds) => {
|
|
384
|
-
webMapIds.forEach((webMapId) => {
|
|
385
|
-
templateTypeHash[webMapId].layersAndTables.forEach((opLayer) => {
|
|
386
|
-
const opLayerInfo = opLayer[ds.itemId];
|
|
387
|
-
const url = _addLayerIdToDatasourceUrl(ds.url, ds.layerId);
|
|
388
|
-
if (opLayerInfo && url === opLayerInfo.url && ds.ids.indexOf(opLayerInfo.id) < 0) {
|
|
389
|
-
ds.ids.push(opLayerInfo.id);
|
|
390
|
-
}
|
|
391
|
-
});
|
|
392
|
-
});
|
|
393
|
-
return ds;
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
exports._addMapLayerIds = _addMapLayerIds;
|
|
397
|
-
/**
|
|
398
|
-
* Get feature service item IDs from applications webmaps
|
|
399
|
-
* As they are not explict dependencies of the application but are needed for field references
|
|
400
|
-
*
|
|
401
|
-
* @param template A webmap solution template
|
|
402
|
-
* @param templateTypeHash A simple lookup object populated with key item info
|
|
403
|
-
* @returns A list of feature service item IDs
|
|
404
|
-
* @private
|
|
405
|
-
*/
|
|
406
|
-
function _getWebMapFSDependencies(template, templateTypeHash) {
|
|
407
|
-
const webMapFSDependencies = [];
|
|
408
|
-
template.dependencies.forEach((dep) => {
|
|
409
|
-
const depObj = templateTypeHash[dep];
|
|
410
|
-
if (depObj.type === "Web Map") {
|
|
411
|
-
depObj.dependencies.forEach((depObjDependency) => {
|
|
412
|
-
/* istanbul ignore else */
|
|
413
|
-
if (templateTypeHash[depObjDependency].type === "Feature Service") {
|
|
414
|
-
webMapFSDependencies.push(depObjDependency);
|
|
415
|
-
}
|
|
416
|
-
});
|
|
417
|
-
}
|
|
418
|
-
});
|
|
419
|
-
return webMapFSDependencies;
|
|
420
|
-
}
|
|
421
|
-
exports._getWebMapFSDependencies = _getWebMapFSDependencies;
|
|
422
|
-
/**
|
|
423
|
-
* Perform templatizations needed in an item's resources
|
|
424
|
-
*
|
|
425
|
-
* @param itemTemplate Item being templatized
|
|
426
|
-
* @param resourceItemFiles Resources for the item; these resources are modified as needed
|
|
427
|
-
* by the templatization
|
|
428
|
-
* @param srcAuthentication Credentials for requests to source items
|
|
429
|
-
*
|
|
430
|
-
* @returns A promise that resolves when all templatization has completed
|
|
431
|
-
*/
|
|
432
|
-
function _templatizeResources(itemTemplate, resourceItemFiles, srcAuthentication) {
|
|
433
|
-
const synchronizePromises = [];
|
|
434
|
-
if (itemTemplate.type === "Vector Tile Service") {
|
|
435
|
-
// Get the root.json files
|
|
436
|
-
const rootJsonResources = resourceItemFiles.filter((file) => file.filename === "root.json");
|
|
437
|
-
const resourcePath = srcAuthentication.portal + "/content/items/" + itemTemplate.itemId;
|
|
438
|
-
const templatizedResourcePath = "{{" + itemTemplate.itemId + ".url}}";
|
|
439
|
-
const replacer = new RegExp(resourcePath, "g");
|
|
440
|
-
// Templatize the paths in the files that reference the source item id
|
|
441
|
-
rootJsonResources.forEach((rootFileResource) => {
|
|
442
|
-
synchronizePromises.push(new Promise((resolve) => {
|
|
443
|
-
// Read the file
|
|
444
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
445
|
-
(0, solution_common_1.blobToJson)(rootFileResource.file).then((fileJson) => {
|
|
446
|
-
// Templatize by turning JSON into string, replacing paths with template, and re-JSONing
|
|
447
|
-
const updatedFileJson = JSON.parse(JSON.stringify(fileJson).replace(replacer, templatizedResourcePath));
|
|
448
|
-
// Write the changes back into the file
|
|
449
|
-
rootFileResource.file = (0, solution_common_1.jsonToFile)(updatedFileJson, rootFileResource.filename);
|
|
450
|
-
resolve(null);
|
|
451
|
-
});
|
|
452
|
-
}));
|
|
453
|
-
});
|
|
454
|
-
}
|
|
455
|
-
else if (itemTemplate.type === "Geoprocessing Service") {
|
|
456
|
-
const rootJsonResources = resourceItemFiles.filter((file) => file.filename.indexOf(".json") > -1);
|
|
457
|
-
rootJsonResources.forEach((rootFileResource) => {
|
|
458
|
-
synchronizePromises.push(new Promise((resolve) => {
|
|
459
|
-
// Read the file
|
|
460
|
-
if (rootFileResource.filename.indexOf("webtoolDefinition") > -1) {
|
|
461
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
462
|
-
(0, solution_common_1.blobToJson)(rootFileResource.file).then((fileJson) => {
|
|
463
|
-
const notebookId = fileJson.jsonProperties.notebookId;
|
|
464
|
-
if (itemTemplate.dependencies.indexOf(notebookId) < 0) {
|
|
465
|
-
itemTemplate.dependencies.push(notebookId);
|
|
466
|
-
}
|
|
467
|
-
itemTemplate.data = {
|
|
468
|
-
name: fileJson.jsonProperties.tasks[0].name,
|
|
469
|
-
notebookId,
|
|
470
|
-
timeoutInMinutes: fileJson.jsonProperties.timeoutInMinutes,
|
|
471
|
-
};
|
|
472
|
-
resolve(null);
|
|
473
|
-
});
|
|
474
|
-
}
|
|
475
|
-
else {
|
|
476
|
-
resolve(null);
|
|
477
|
-
}
|
|
478
|
-
}));
|
|
479
|
-
});
|
|
480
|
-
}
|
|
481
|
-
return Promise.all(synchronizePromises);
|
|
482
|
-
}
|
|
483
|
-
exports._templatizeResources = _templatizeResources;
|
|
484
|
-
//# sourceMappingURL=createItemTemplate.js.map
|