@esri/solution-viewer 4.1.2-alpha.0 → 5.0.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.
@@ -1,54 +1,54 @@
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
- * Provides the access to the solution's contents.
18
- *
19
- * @module viewer
20
- */
21
- import * as common from "@esri/solution-common";
22
- /**
23
- * Checks a Solution.
24
- *
25
- * @param item Solution id
26
- * @param authentication Credentials for the request to AGO
27
- * @returns List of results of checks of Solution
28
- */
29
- export declare function checkSolution(itemId: string, authentication?: common.UserSession): Promise<string[]>;
30
- /**
31
- * Compares two AGO items, fetching them if only their id is supplied.
32
- *
33
- * @param item1 First item or its AGO id
34
- * @param item2 Second item or its AGO id
35
- * @param authentication Credentials for the request to AGO
36
- * @returns True if objects are the same
37
- * @see Only comparable properties are compared; see deleteItemProps() in the `common` package
38
- */
39
- export declare function compareItems(item1: string | any, item2: string | any, authentication?: common.UserSession): Promise<boolean>;
40
- /**
41
- * Creates a hierarchy of the items in a Solution template.
42
- *
43
- * @param templates Array of templates from a Solution
44
- * @returns List of top-level items, each containing a recursive list of its dependencies
45
- */
46
- export declare function getItemHierarchy(templates: common.IItemTemplate[]): common.IHierarchyElement[];
47
- /**
48
- * Finds the top-level items in a Solution template--the items that are not dependencies of any other item.
49
- *
50
- * @param templates Array of templates from a Solution
51
- * @returns List of top-level item ids
52
- * @private
53
- */
54
- export declare function _getTopLevelItemIds(templates: common.IItemTemplate[]): string[];
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
+ * Provides the access to the solution's contents.
18
+ *
19
+ * @module viewer
20
+ */
21
+ import * as common from "@esri/solution-common";
22
+ /**
23
+ * Checks a Solution.
24
+ *
25
+ * @param item Solution id
26
+ * @param authentication Credentials for the request to AGO
27
+ * @returns List of results of checks of Solution
28
+ */
29
+ export declare function checkSolution(itemId: string, authentication?: common.UserSession): Promise<string[]>;
30
+ /**
31
+ * Compares two AGO items, fetching them if only their id is supplied.
32
+ *
33
+ * @param item1 First item or its AGO id
34
+ * @param item2 Second item or its AGO id
35
+ * @param authentication Credentials for the request to AGO
36
+ * @returns True if objects are the same
37
+ * @see Only comparable properties are compared; see deleteItemProps() in the `common` package
38
+ */
39
+ export declare function compareItems(item1: string | any, item2: string | any, authentication?: common.UserSession): Promise<boolean>;
40
+ /**
41
+ * Creates a hierarchy of the items in a Solution template.
42
+ *
43
+ * @param templates Array of templates from a Solution
44
+ * @returns List of top-level items, each containing a recursive list of its dependencies
45
+ */
46
+ export declare function getItemHierarchy(templates: common.IItemTemplate[]): common.IHierarchyElement[];
47
+ /**
48
+ * Finds the top-level items in a Solution template--the items that are not dependencies of any other item.
49
+ *
50
+ * @param templates Array of templates from a Solution
51
+ * @returns List of top-level item ids
52
+ * @private
53
+ */
54
+ export declare function _getTopLevelItemIds(templates: common.IItemTemplate[]): string[];
@@ -1,254 +1,254 @@
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
- * Provides the access to the solution's contents.
18
- *
19
- * @module viewer
20
- */
21
- import * as common from "@esri/solution-common";
22
- // ------------------------------------------------------------------------------------------------------------------ //
23
- /**
24
- * Checks a Solution.
25
- *
26
- * @param item Solution id
27
- * @param authentication Credentials for the request to AGO
28
- * @returns List of results of checks of Solution
29
- */
30
- export function checkSolution(itemId, authentication = null) {
31
- const resultsHtml = [`Item ${itemId}`];
32
- let item;
33
- let isTemplate = true;
34
- let templateItems;
35
- let templateItemIds;
36
- let currentAction = " while getting complete item";
37
- return (common
38
- .getCompleteItem(itemId, authentication)
39
- // ---------- Is it a Template or Deployed Solution? -----------------------------------------------------------//
40
- .then((results) => {
41
- currentAction = "";
42
- item = results;
43
- if (!item) {
44
- throw new Error(`item is not found`);
45
- }
46
- else if (item.base.type !== "Solution") {
47
- throw new Error(`item is not a Solution`);
48
- }
49
- else if (item.base.typeKeywords.includes("Template")) {
50
- resultsHtml.push(`&#x2714; item is a Template Solution`);
51
- }
52
- else if (item.base.typeKeywords.includes("Deployed")) {
53
- isTemplate = false;
54
- resultsHtml.push(`&#x2714; item is a Deployed Solution`);
55
- }
56
- else {
57
- throw new Error(`item is neither a Template Solution nor a Deployed Solution`);
58
- }
59
- // base: IItem; text/plain JSON
60
- // data: File; */*
61
- // thumbnail: File; image/*
62
- // metadata: File; application/xml
63
- // resources: File[]; list of */*
64
- // fwdRelatedItems: IRelatedItems[]; list of forward relationshipType/relatedItems[] pairs
65
- // revRelatedItems: IRelatedItems[]; list of reverse relationshipType/relatedItems[] pairs
66
- return common.blobToJson(item.data);
67
- })
68
- // ---------- Check the Solution2Item relationship from a Deployed Solution to each deployed item --------------//
69
- .then(itemDataJson => {
70
- templateItems = itemDataJson?.templates;
71
- /* istanbul ignore else */
72
- if (!templateItems || templateItems.length === 0) {
73
- throw new Error(`Solution's data are not valid JSON or the Solution contains no items`);
74
- }
75
- templateItemIds = templateItems
76
- .map((template) => template.itemId)
77
- .sort();
78
- if (!isTemplate) {
79
- // Make sure that there's a Solution2Item relationship to each deployed item
80
- const fwdRelatedItemIds = item.fwdRelatedItems
81
- .filter(relationshipSet => relationshipSet.relationshipType === "Solution2Item")
82
- .reduce((flatSet, relationshipSet) => flatSet.concat(relationshipSet.relatedItemIds), [])
83
- .sort();
84
- if (templateItemIds.length < fwdRelatedItemIds.length) {
85
- resultsHtml.push("&#x2716; there are forward Solution2Item relationship(s) to unknown item(s)");
86
- }
87
- else if (templateItemIds.length > fwdRelatedItemIds.length) {
88
- resultsHtml.push("&#x2716; missing forward Solution2Item relationship(s)");
89
- }
90
- else if (JSON.stringify(templateItemIds) !==
91
- JSON.stringify(fwdRelatedItemIds)) {
92
- resultsHtml.push("&#x2716; mismatching forward Solution2Item relationship(s)");
93
- }
94
- else {
95
- resultsHtml.push("&#x2714; matching forward Solution2Item relationship(s)");
96
- }
97
- }
98
- return resultsHtml;
99
- })
100
- // ---------- Check that all dependency references are items in Solution ---------------------------------------//
101
- .then(() => {
102
- const dependencyIds = templateItems
103
- .reduce((flatSet, template) => flatSet.concat(template.dependencies), [])
104
- .reduce((noDupSet, dependency) => {
105
- /* istanbul ignore else */
106
- if (!noDupSet.includes(dependency))
107
- noDupSet.push(dependency);
108
- return noDupSet;
109
- }, [])
110
- .sort();
111
- const missingItems = dependencyIds.filter((dependencyId) => !templateItemIds.includes(dependencyId));
112
- if (missingItems.length === 0) {
113
- resultsHtml.push("&#x2714; all dependencies are in Solution");
114
- }
115
- else {
116
- resultsHtml.push("&#x2716; dependencies that aren't in Solution: " +
117
- JSON.stringify(missingItems));
118
- }
119
- return resultsHtml;
120
- })
121
- // ---------- Done ---------------------------------------------------------------------------------------------//
122
- .then(() => {
123
- return resultsHtml;
124
- })
125
- // ---------- Fatal error --------------------------------------------------------------------------------------//
126
- .catch(error => {
127
- resultsHtml.push(`&#x2716; error${currentAction}: ${error.message}`);
128
- return resultsHtml;
129
- }));
130
- }
131
- /**
132
- * Compares two AGO items, fetching them if only their id is supplied.
133
- *
134
- * @param item1 First item or its AGO id
135
- * @param item2 Second item or its AGO id
136
- * @param authentication Credentials for the request to AGO
137
- * @returns True if objects are the same
138
- * @see Only comparable properties are compared; see deleteItemProps() in the `common` package
139
- */
140
- export function compareItems(item1, item2, authentication = null) {
141
- return new Promise((resolve, reject) => {
142
- // If an input is a string, fetch the item; otherwise, clone the input because we will modify the
143
- // item base to remove incomparable properties
144
- let itemBaseDef1;
145
- if (typeof item1 === "string") {
146
- itemBaseDef1 = common.getItemBase(item1, authentication);
147
- }
148
- else {
149
- itemBaseDef1 = Promise.resolve(common.cloneObject(item1));
150
- }
151
- let itemBaseDef2;
152
- if (typeof item2 === "string") {
153
- itemBaseDef2 = common.getItemBase(item2, authentication);
154
- }
155
- else {
156
- itemBaseDef2 = Promise.resolve(common.cloneObject(item2));
157
- }
158
- Promise.all([itemBaseDef1, itemBaseDef2]).then(responses => {
159
- const [itemBase1, itemBase2] = responses;
160
- common.deleteItemProps(itemBase1);
161
- common.deleteItemProps(itemBase2);
162
- if (itemBase1.type === "Solution") {
163
- delete itemBase1.typeKeywords;
164
- delete itemBase1.size;
165
- delete itemBase2.typeKeywords;
166
- delete itemBase2.size;
167
- }
168
- /*console.log("----------------------------------------------------------------");
169
- console.log("item 1 " + item1 + ": ", JSON.stringify(itemBase1, null, 2));
170
- console.log("item 2 " + item2 + ": ", JSON.stringify(itemBase2, null, 2));
171
- console.log("----------------------------------------------------------------");*/
172
- resolve(common.compareJSONNoEmptyStrings(itemBase1, itemBase2));
173
- }, e => reject(e));
174
- });
175
- }
176
- /**
177
- * Creates a hierarchy of the items in a Solution template.
178
- *
179
- * @param templates Array of templates from a Solution
180
- * @returns List of top-level items, each containing a recursive list of its dependencies
181
- */
182
- export function getItemHierarchy(templates) {
183
- const hierarchy = [];
184
- // Get the template specified by id out of a list of templates
185
- function getTemplateInSolution(templates, id) {
186
- const iTemplate = templates.findIndex((template) => id === template.itemId);
187
- return iTemplate >= 0 ? templates[iTemplate] : null;
188
- }
189
- // Hierarchically list the dependencies of specified node
190
- function traceItemId(id, accumulatedHierarchy, alreadyVisitedIds = []) {
191
- // Get the dependencies of the node
192
- const template = getTemplateInSolution(templates, id);
193
- /* istanbul ignore else */
194
- if (template) {
195
- const templateEntry = {
196
- id,
197
- dependencies: []
198
- };
199
- // Visit each dependency, but only if this template is not in the alreadyVisitedIds list to avoid infinite loops
200
- if (alreadyVisitedIds.indexOf(id) < 0) {
201
- // Add dependency to alreadyVisitedIds list
202
- alreadyVisitedIds.push(id);
203
- template.dependencies.forEach(dependencyId => {
204
- // Remove dependency from list of templates to visit in the top-level loop
205
- const iDependencyTemplate = templateItemIds.indexOf(dependencyId);
206
- if (iDependencyTemplate >= 0) {
207
- templateItemIds.splice(iDependencyTemplate, 1);
208
- }
209
- traceItemId(dependencyId, templateEntry.dependencies, alreadyVisitedIds);
210
- });
211
- }
212
- accumulatedHierarchy.push(templateEntry);
213
- }
214
- }
215
- // Start with top-level nodes and add in the rest of the nodes to catch cycles without top-level nodes
216
- let templateItemIds = _getTopLevelItemIds(templates);
217
- const otherItems = templates
218
- .filter(template => templateItemIds.indexOf(template.itemId) < 0) // only keep non-top-level nodes
219
- .sort((a, b) => b.dependencies.length - a.dependencies.length); // sort so that nodes with more dependencies come first--reduces stubs
220
- templateItemIds = templateItemIds.concat(otherItems.map(template => template.itemId));
221
- // Step through the list of nodes; we'll also remove nodes as we visit them
222
- let itemId = templateItemIds.shift();
223
- while (typeof itemId !== "undefined") {
224
- traceItemId(itemId, hierarchy);
225
- itemId = templateItemIds.shift();
226
- }
227
- return hierarchy;
228
- }
229
- // ------------------------------------------------------------------------------------------------------------------ //
230
- /**
231
- * Finds the top-level items in a Solution template--the items that are not dependencies of any other item.
232
- *
233
- * @param templates Array of templates from a Solution
234
- * @returns List of top-level item ids
235
- * @private
236
- */
237
- export function _getTopLevelItemIds(templates) {
238
- // Find the top-level nodes. Start with all nodes, then remove those that other nodes depend on
239
- const topLevelItemCandidateIds = templates.map(function (template) { return template.itemId; });
240
- templates.forEach(function (template) {
241
- (template.dependencies || []).forEach(function (dependencyId) {
242
- const iNode = topLevelItemCandidateIds.indexOf(dependencyId);
243
- /* istanbul ignore else */
244
- if (iNode >= 0) {
245
- // Node is somebody's dependency, so remove the node from the list of top-level nodes
246
- // If iNode == -1, then it's a shared dependency and it has already been removed
247
- topLevelItemCandidateIds.splice(iNode, 1);
248
- }
249
- });
250
- });
251
- return topLevelItemCandidateIds;
252
- }
253
- ;
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
+ * Provides the access to the solution's contents.
18
+ *
19
+ * @module viewer
20
+ */
21
+ import * as common from "@esri/solution-common";
22
+ // ------------------------------------------------------------------------------------------------------------------ //
23
+ /**
24
+ * Checks a Solution.
25
+ *
26
+ * @param item Solution id
27
+ * @param authentication Credentials for the request to AGO
28
+ * @returns List of results of checks of Solution
29
+ */
30
+ export function checkSolution(itemId, authentication = null) {
31
+ const resultsHtml = [`Item ${itemId}`];
32
+ let item;
33
+ let isTemplate = true;
34
+ let templateItems;
35
+ let templateItemIds;
36
+ let currentAction = " while getting complete item";
37
+ return (common
38
+ .getCompleteItem(itemId, authentication)
39
+ // ---------- Is it a Template or Deployed Solution? -----------------------------------------------------------//
40
+ .then((results) => {
41
+ currentAction = "";
42
+ item = results;
43
+ if (!item) {
44
+ throw new Error(`item is not found`);
45
+ }
46
+ else if (item.base.type !== "Solution") {
47
+ throw new Error(`item is not a Solution`);
48
+ }
49
+ else if (item.base.typeKeywords.includes("Template")) {
50
+ resultsHtml.push(`&#x2714; item is a Template Solution`);
51
+ }
52
+ else if (item.base.typeKeywords.includes("Deployed")) {
53
+ isTemplate = false;
54
+ resultsHtml.push(`&#x2714; item is a Deployed Solution`);
55
+ }
56
+ else {
57
+ throw new Error(`item is neither a Template Solution nor a Deployed Solution`);
58
+ }
59
+ // base: IItem; text/plain JSON
60
+ // data: File; */*
61
+ // thumbnail: File; image/*
62
+ // metadata: File; application/xml
63
+ // resources: File[]; list of */*
64
+ // fwdRelatedItems: IRelatedItems[]; list of forward relationshipType/relatedItems[] pairs
65
+ // revRelatedItems: IRelatedItems[]; list of reverse relationshipType/relatedItems[] pairs
66
+ return common.blobToJson(item.data);
67
+ })
68
+ // ---------- Check the Solution2Item relationship from a Deployed Solution to each deployed item --------------//
69
+ .then(itemDataJson => {
70
+ templateItems = itemDataJson?.templates;
71
+ /* istanbul ignore else */
72
+ if (!templateItems || templateItems.length === 0) {
73
+ throw new Error(`Solution's data are not valid JSON or the Solution contains no items`);
74
+ }
75
+ templateItemIds = templateItems
76
+ .map((template) => template.itemId)
77
+ .sort();
78
+ if (!isTemplate) {
79
+ // Make sure that there's a Solution2Item relationship to each deployed item
80
+ const fwdRelatedItemIds = item.fwdRelatedItems
81
+ .filter(relationshipSet => relationshipSet.relationshipType === "Solution2Item")
82
+ .reduce((flatSet, relationshipSet) => flatSet.concat(relationshipSet.relatedItemIds), [])
83
+ .sort();
84
+ if (templateItemIds.length < fwdRelatedItemIds.length) {
85
+ resultsHtml.push("&#x2716; there are forward Solution2Item relationship(s) to unknown item(s)");
86
+ }
87
+ else if (templateItemIds.length > fwdRelatedItemIds.length) {
88
+ resultsHtml.push("&#x2716; missing forward Solution2Item relationship(s)");
89
+ }
90
+ else if (JSON.stringify(templateItemIds) !==
91
+ JSON.stringify(fwdRelatedItemIds)) {
92
+ resultsHtml.push("&#x2716; mismatching forward Solution2Item relationship(s)");
93
+ }
94
+ else {
95
+ resultsHtml.push("&#x2714; matching forward Solution2Item relationship(s)");
96
+ }
97
+ }
98
+ return resultsHtml;
99
+ })
100
+ // ---------- Check that all dependency references are items in Solution ---------------------------------------//
101
+ .then(() => {
102
+ const dependencyIds = templateItems
103
+ .reduce((flatSet, template) => flatSet.concat(template.dependencies), [])
104
+ .reduce((noDupSet, dependency) => {
105
+ /* istanbul ignore else */
106
+ if (!noDupSet.includes(dependency))
107
+ noDupSet.push(dependency);
108
+ return noDupSet;
109
+ }, [])
110
+ .sort();
111
+ const missingItems = dependencyIds.filter((dependencyId) => !templateItemIds.includes(dependencyId));
112
+ if (missingItems.length === 0) {
113
+ resultsHtml.push("&#x2714; all dependencies are in Solution");
114
+ }
115
+ else {
116
+ resultsHtml.push("&#x2716; dependencies that aren't in Solution: " +
117
+ JSON.stringify(missingItems));
118
+ }
119
+ return resultsHtml;
120
+ })
121
+ // ---------- Done ---------------------------------------------------------------------------------------------//
122
+ .then(() => {
123
+ return resultsHtml;
124
+ })
125
+ // ---------- Fatal error --------------------------------------------------------------------------------------//
126
+ .catch(error => {
127
+ resultsHtml.push(`&#x2716; error${currentAction}: ${error.message}`);
128
+ return resultsHtml;
129
+ }));
130
+ }
131
+ /**
132
+ * Compares two AGO items, fetching them if only their id is supplied.
133
+ *
134
+ * @param item1 First item or its AGO id
135
+ * @param item2 Second item or its AGO id
136
+ * @param authentication Credentials for the request to AGO
137
+ * @returns True if objects are the same
138
+ * @see Only comparable properties are compared; see deleteItemProps() in the `common` package
139
+ */
140
+ export function compareItems(item1, item2, authentication = null) {
141
+ return new Promise((resolve, reject) => {
142
+ // If an input is a string, fetch the item; otherwise, clone the input because we will modify the
143
+ // item base to remove incomparable properties
144
+ let itemBaseDef1;
145
+ if (typeof item1 === "string") {
146
+ itemBaseDef1 = common.getItemBase(item1, authentication);
147
+ }
148
+ else {
149
+ itemBaseDef1 = Promise.resolve(common.cloneObject(item1));
150
+ }
151
+ let itemBaseDef2;
152
+ if (typeof item2 === "string") {
153
+ itemBaseDef2 = common.getItemBase(item2, authentication);
154
+ }
155
+ else {
156
+ itemBaseDef2 = Promise.resolve(common.cloneObject(item2));
157
+ }
158
+ Promise.all([itemBaseDef1, itemBaseDef2]).then(responses => {
159
+ const [itemBase1, itemBase2] = responses;
160
+ common.deleteItemProps(itemBase1);
161
+ common.deleteItemProps(itemBase2);
162
+ if (itemBase1.type === "Solution") {
163
+ delete itemBase1.typeKeywords;
164
+ delete itemBase1.size;
165
+ delete itemBase2.typeKeywords;
166
+ delete itemBase2.size;
167
+ }
168
+ /*console.log("----------------------------------------------------------------");
169
+ console.log("item 1 " + item1 + ": ", JSON.stringify(itemBase1, null, 2));
170
+ console.log("item 2 " + item2 + ": ", JSON.stringify(itemBase2, null, 2));
171
+ console.log("----------------------------------------------------------------");*/
172
+ resolve(common.compareJSONNoEmptyStrings(itemBase1, itemBase2));
173
+ }, e => reject(e));
174
+ });
175
+ }
176
+ /**
177
+ * Creates a hierarchy of the items in a Solution template.
178
+ *
179
+ * @param templates Array of templates from a Solution
180
+ * @returns List of top-level items, each containing a recursive list of its dependencies
181
+ */
182
+ export function getItemHierarchy(templates) {
183
+ const hierarchy = [];
184
+ // Get the template specified by id out of a list of templates
185
+ function getTemplateInSolution(templates, id) {
186
+ const iTemplate = templates.findIndex((template) => id === template.itemId);
187
+ return iTemplate >= 0 ? templates[iTemplate] : null;
188
+ }
189
+ // Hierarchically list the dependencies of specified node
190
+ function traceItemId(id, accumulatedHierarchy, alreadyVisitedIds = []) {
191
+ // Get the dependencies of the node
192
+ const template = getTemplateInSolution(templates, id);
193
+ /* istanbul ignore else */
194
+ if (template) {
195
+ const templateEntry = {
196
+ id,
197
+ dependencies: []
198
+ };
199
+ // Visit each dependency, but only if this template is not in the alreadyVisitedIds list to avoid infinite loops
200
+ if (alreadyVisitedIds.indexOf(id) < 0) {
201
+ // Add dependency to alreadyVisitedIds list
202
+ alreadyVisitedIds.push(id);
203
+ template.dependencies.forEach(dependencyId => {
204
+ // Remove dependency from list of templates to visit in the top-level loop
205
+ const iDependencyTemplate = templateItemIds.indexOf(dependencyId);
206
+ if (iDependencyTemplate >= 0) {
207
+ templateItemIds.splice(iDependencyTemplate, 1);
208
+ }
209
+ traceItemId(dependencyId, templateEntry.dependencies, alreadyVisitedIds);
210
+ });
211
+ }
212
+ accumulatedHierarchy.push(templateEntry);
213
+ }
214
+ }
215
+ // Start with top-level nodes and add in the rest of the nodes to catch cycles without top-level nodes
216
+ let templateItemIds = _getTopLevelItemIds(templates);
217
+ const otherItems = templates
218
+ .filter(template => templateItemIds.indexOf(template.itemId) < 0) // only keep non-top-level nodes
219
+ .sort((a, b) => b.dependencies.length - a.dependencies.length); // sort so that nodes with more dependencies come first--reduces stubs
220
+ templateItemIds = templateItemIds.concat(otherItems.map(template => template.itemId));
221
+ // Step through the list of nodes; we'll also remove nodes as we visit them
222
+ let itemId = templateItemIds.shift();
223
+ while (typeof itemId !== "undefined") {
224
+ traceItemId(itemId, hierarchy);
225
+ itemId = templateItemIds.shift();
226
+ }
227
+ return hierarchy;
228
+ }
229
+ // ------------------------------------------------------------------------------------------------------------------ //
230
+ /**
231
+ * Finds the top-level items in a Solution template--the items that are not dependencies of any other item.
232
+ *
233
+ * @param templates Array of templates from a Solution
234
+ * @returns List of top-level item ids
235
+ * @private
236
+ */
237
+ export function _getTopLevelItemIds(templates) {
238
+ // Find the top-level nodes. Start with all nodes, then remove those that other nodes depend on
239
+ const topLevelItemCandidateIds = templates.map(function (template) { return template.itemId; });
240
+ templates.forEach(function (template) {
241
+ (template.dependencies || []).forEach(function (dependencyId) {
242
+ const iNode = topLevelItemCandidateIds.indexOf(dependencyId);
243
+ /* istanbul ignore else */
244
+ if (iNode >= 0) {
245
+ // Node is somebody's dependency, so remove the node from the list of top-level nodes
246
+ // If iNode == -1, then it's a shared dependency and it has already been removed
247
+ topLevelItemCandidateIds.splice(iNode, 1);
248
+ }
249
+ });
250
+ });
251
+ return topLevelItemCandidateIds;
252
+ }
253
+ ;
254
254
  //# sourceMappingURL=viewer.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@esri/solution-viewer",
3
- "version": "4.1.2-alpha.0",
3
+ "version": "5.0.0",
4
4
  "description": "Simplifies access to @esri/solution.js.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -27,7 +27,7 @@
27
27
  "@esri/hub-initiatives": "^13.0.0",
28
28
  "@esri/hub-sites": "^13.0.1",
29
29
  "@esri/hub-teams": "^13.0.0",
30
- "@esri/solution-common": "^4.1.2-alpha.0",
30
+ "@esri/solution-common": "^5.0.0",
31
31
  "rollup": "2.79.1"
32
32
  },
33
33
  "dependencies": {
@@ -85,5 +85,5 @@
85
85
  "esri",
86
86
  "ES6"
87
87
  ],
88
- "gitHead": "9740175be347ee23b5b788eda6e369b948d907fe"
88
+ "gitHead": "a6cbcc049fb712d19e98b7d59a94734aad4dd17f"
89
89
  }