@esri/solution-viewer 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.
@@ -37,3 +37,17 @@ export declare function checkSolution(itemId: string, authentication?: common.Us
37
37
  * @see Only comparable properties are compared; see deleteItemProps() in the `common` package
38
38
  */
39
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
+ * @return 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
+ * @return List of top-level item ids
52
+ */
53
+ export declare function _getTopLevelItemIds(templates: common.IItemTemplate[]): string[];
@@ -1,7 +1,7 @@
1
1
  /* @preserve
2
- * @esri/solution-viewer - v1.1.2 - Apache-2.0
2
+ * @esri/solution-viewer - v1.2.0 - Apache-2.0
3
3
  * Copyright (c) 2018-2021 Esri, Inc.
4
- * Tue Aug 31 2021 00:00:08 GMT-0700 (Pacific Daylight Time)
4
+ * Thu Dec 09 2021 16:03:45 GMT-0800 (Pacific Standard Time)
5
5
  *
6
6
  * Licensed under the Apache License, Version 2.0 (the "License");
7
7
  * you may not use this file except in compliance with the License.
@@ -16,222 +16,283 @@
16
16
  * limitations under the License.
17
17
  */
18
18
  (function (global, factory) {
19
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@esri/solution-common')) :
20
- typeof define === 'function' && define.amd ? define(['exports', '@esri/solution-common'], factory) :
21
- (global = global || self, factory(global.arcgisSolution = global.arcgisSolution || {}, global.arcgisSolution));
22
- }(this, (function (exports, common) { 'use strict';
19
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@esri/solution-common')) :
20
+ typeof define === 'function' && define.amd ? define(['exports', '@esri/solution-common'], factory) :
21
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.arcgisSolution = global.arcgisSolution || {}, global.arcgisSolution));
22
+ })(this, (function (exports, common) { 'use strict';
23
23
 
24
- /*! *****************************************************************************
25
- Copyright (c) Microsoft Corporation. All rights reserved.
26
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
27
- this file except in compliance with the License. You may obtain a copy of the
28
- License at http://www.apache.org/licenses/LICENSE-2.0
29
-
30
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
31
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
32
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
33
- MERCHANTABLITY OR NON-INFRINGEMENT.
34
-
35
- See the Apache Version 2.0 License for specific language governing permissions
36
- and limitations under the License.
37
- ***************************************************************************** */
38
-
39
- function __read(o, n) {
40
- var m = typeof Symbol === "function" && o[Symbol.iterator];
41
- if (!m) return o;
42
- var i = m.call(o), r, ar = [], e;
43
- try {
44
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
45
- }
46
- catch (error) { e = { error: error }; }
47
- finally {
48
- try {
49
- if (r && !r.done && (m = i["return"])) m.call(i);
50
- }
51
- finally { if (e) throw e.error; }
52
- }
53
- return ar;
24
+ function _interopNamespace(e) {
25
+ if (e && e.__esModule) return e;
26
+ var n = Object.create(null);
27
+ if (e) {
28
+ Object.keys(e).forEach(function (k) {
29
+ if (k !== 'default') {
30
+ var d = Object.getOwnPropertyDescriptor(e, k);
31
+ Object.defineProperty(n, k, d.get ? d : {
32
+ enumerable: true,
33
+ get: function () { return e[k]; }
34
+ });
35
+ }
36
+ });
54
37
  }
38
+ n["default"] = e;
39
+ return Object.freeze(n);
40
+ }
55
41
 
56
- /** @license
57
- * Copyright 2018 Esri
58
- *
59
- * Licensed under the Apache License, Version 2.0 (the "License");
60
- * you may not use this file except in compliance with the License.
61
- * You may obtain a copy of the License at
62
- *
63
- * http://www.apache.org/licenses/LICENSE-2.0
64
- *
65
- * Unless required by applicable law or agreed to in writing, software
66
- * distributed under the License is distributed on an "AS IS" BASIS,
67
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
68
- * See the License for the specific language governing permissions and
69
- * limitations under the License.
70
- */
71
- // ------------------------------------------------------------------------------------------------------------------ //
72
- /**
73
- * Checks a Solution.
74
- *
75
- * @param item Solution id
76
- * @param authentication Credentials for the request to AGO
77
- * @return List of results of checks of Solution
78
- */
79
- function checkSolution(itemId, authentication) {
80
- if (authentication === void 0) { authentication = null; }
81
- var resultsHtml = ["Item " + itemId];
82
- var item;
83
- var isTemplate = true;
84
- var templateItems;
85
- var templateItemIds;
86
- var currentAction = " while getting complete item";
87
- return (common.getCompleteItem(itemId, authentication)
88
- // ---------- Is it a Template or Deployed Solution? ---------------------------------------------------------------//
89
- .then(function (results) {
90
- currentAction = "";
91
- item = results;
92
- if (!item) {
93
- throw new Error("item is not found");
94
- }
95
- else if (item.base.type !== "Solution") {
96
- throw new Error("item is not a Solution");
97
- }
98
- else if (item.base.typeKeywords.includes("Template")) {
99
- resultsHtml.push("&#x2714; item is a Template Solution");
100
- }
101
- else if (item.base.typeKeywords.includes("Deployed")) {
102
- isTemplate = false;
103
- resultsHtml.push("&#x2714; item is a Deployed Solution");
104
- }
105
- else {
106
- throw new Error("item is neither a Template Solution nor a Deployed Solution");
107
- }
108
- // base: IItem; text/plain JSON
109
- // data: File; */*
110
- // thumbnail: File; image/*
111
- // metadata: File; application/xml
112
- // resources: File[]; list of */*
113
- // fwdRelatedItems: IRelatedItems[]; list of forward relationshipType/relatedItems[] pairs
114
- // revRelatedItems: IRelatedItems[]; list of reverse relationshipType/relatedItems[] pairs
115
- return common.blobToJson(item.data);
116
- })
117
- // ---------- Check the Solution2Item relationship from a Deployed Solution to each deployed item ------------------//
118
- .then(function (itemDataJson) {
119
- templateItems = itemDataJson === null || itemDataJson === void 0 ? void 0 : itemDataJson.templates;
120
- /* istanbul ignore else */
121
- if (!templateItems || templateItems.length === 0) {
122
- throw new Error("Solution's data are not valid JSON or the Solution contains no items");
123
- }
124
- templateItemIds = templateItems
125
- .map(function (template) { return template.itemId; })
126
- .sort();
127
- if (!isTemplate) {
128
- // Make sure that there's a Solution2Item relationship to each deployed item
129
- var fwdRelatedItemIds = item.fwdRelatedItems
130
- .filter(function (relationshipSet) {
131
- return relationshipSet.relationshipType === "Solution2Item";
132
- })
133
- .reduce(function (flatSet, relationshipSet) {
134
- return flatSet.concat(relationshipSet.relatedItemIds);
135
- }, [])
136
- .sort();
137
- if (templateItemIds.length < fwdRelatedItemIds.length) {
138
- resultsHtml.push("&#x2716; there are forward Solution2Item relationship(s) to unknown item(s)");
139
- }
140
- else if (templateItemIds.length > fwdRelatedItemIds.length) {
141
- resultsHtml.push("&#x2716; missing forward Solution2Item relationship(s)");
142
- }
143
- else if (JSON.stringify(templateItemIds) !==
144
- JSON.stringify(fwdRelatedItemIds)) {
145
- resultsHtml.push("&#x2716; mismatching forward Solution2Item relationship(s)");
146
- }
147
- else {
148
- resultsHtml.push("&#x2714; matching forward Solution2Item relationship(s)");
149
- }
150
- }
151
- return resultsHtml;
152
- })
153
- // ---------- Check that all dependency references are items in Solution -------------------------------------------//
154
- .then(function () {
155
- var dependencyIds = templateItems
156
- .reduce(function (flatSet, template) { return flatSet.concat(template.dependencies); }, [])
157
- .reduce(function (noDupSet, dependency) {
158
- /* istanbul ignore else */
159
- if (!noDupSet.includes(dependency))
160
- noDupSet.push(dependency);
161
- return noDupSet;
162
- }, [])
163
- .sort();
164
- var missingItems = dependencyIds.filter(function (dependencyId) { return !templateItemIds.includes(dependencyId); });
165
- if (missingItems.length === 0) {
166
- resultsHtml.push("&#x2714; all dependencies are in Solution");
167
- }
168
- else {
169
- resultsHtml.push("&#x2716; dependencies that aren't in Solution: " +
170
- JSON.stringify(missingItems));
171
- }
172
- return resultsHtml;
173
- })
174
- // ---------- Done -------------------------------------------------------------------------------------------------//
175
- .then(function () {
176
- return resultsHtml;
177
- })
178
- // ---------- Fatal error ------------------------------------------------------------------------------------------//
179
- .catch(function (error) {
180
- resultsHtml.push("&#x2716; error" + currentAction + ": " + error.message);
181
- return resultsHtml;
182
- }));
183
- }
184
- /**
185
- * Compares two AGO items, fetching them if only their id is supplied.
186
- *
187
- * @param item1 First item or its AGO id
188
- * @param item2 Second item or its AGO id
189
- * @param authentication Credentials for the request to AGO
190
- * @return True if objects are the same
191
- * @see Only comparable properties are compared; see deleteItemProps() in the `common` package
192
- */
193
- function compareItems(item1, item2, authentication) {
194
- if (authentication === void 0) { authentication = null; }
195
- return new Promise(function (resolve, reject) {
196
- // If an input is a string, fetch the item; otherwise, clone the input because we will modify the
197
- // item base to remove incomparable properties
198
- var itemBaseDef1;
199
- if (typeof item1 === "string") {
200
- itemBaseDef1 = common.getItemBase(item1, authentication);
201
- }
202
- else {
203
- itemBaseDef1 = Promise.resolve(common.cloneObject(item1));
204
- }
205
- var itemBaseDef2;
206
- if (typeof item2 === "string") {
207
- itemBaseDef2 = common.getItemBase(item2, authentication);
208
- }
209
- else {
210
- itemBaseDef2 = Promise.resolve(common.cloneObject(item2));
211
- }
212
- Promise.all([itemBaseDef1, itemBaseDef2]).then(function (responses) {
213
- var _a = __read(responses, 2), itemBase1 = _a[0], itemBase2 = _a[1];
214
- common.deleteItemProps(itemBase1);
215
- common.deleteItemProps(itemBase2);
216
- if (itemBase1.type === "Solution") {
217
- delete itemBase1.typeKeywords;
218
- delete itemBase1.size;
219
- delete itemBase2.typeKeywords;
220
- delete itemBase2.size;
221
- }
222
- /*console.log("----------------------------------------------------------------");
223
- console.log("item 1 " + item1 + ": ", JSON.stringify(itemBase1, null, 2));
224
- console.log("item 2 " + item2 + ": ", JSON.stringify(itemBase2, null, 2));
225
- console.log("----------------------------------------------------------------");*/
226
- resolve(common.compareJSONNoEmptyStrings(itemBase1, itemBase2));
227
- }, function (e) { return reject(e); });
228
- });
229
- }
42
+ var common__namespace = /*#__PURE__*/_interopNamespace(common);
43
+
44
+ /** @license
45
+ * Copyright 2018 Esri
46
+ *
47
+ * Licensed under the Apache License, Version 2.0 (the "License");
48
+ * you may not use this file except in compliance with the License.
49
+ * You may obtain a copy of the License at
50
+ *
51
+ * http://www.apache.org/licenses/LICENSE-2.0
52
+ *
53
+ * Unless required by applicable law or agreed to in writing, software
54
+ * distributed under the License is distributed on an "AS IS" BASIS,
55
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
56
+ * See the License for the specific language governing permissions and
57
+ * limitations under the License.
58
+ */
59
+ // ------------------------------------------------------------------------------------------------------------------ //
60
+ /**
61
+ * Checks a Solution.
62
+ *
63
+ * @param item Solution id
64
+ * @param authentication Credentials for the request to AGO
65
+ * @return List of results of checks of Solution
66
+ */
67
+ function checkSolution(itemId, authentication = null) {
68
+ const resultsHtml = [`Item ${itemId}`];
69
+ let item;
70
+ let isTemplate = true;
71
+ let templateItems;
72
+ let templateItemIds;
73
+ let currentAction = " while getting complete item";
74
+ return (common__namespace
75
+ .getCompleteItem(itemId, authentication)
76
+ // ---------- Is it a Template or Deployed Solution? -----------------------------------------------------------//
77
+ .then((results) => {
78
+ currentAction = "";
79
+ item = results;
80
+ if (!item) {
81
+ throw new Error(`item is not found`);
82
+ }
83
+ else if (item.base.type !== "Solution") {
84
+ throw new Error(`item is not a Solution`);
85
+ }
86
+ else if (item.base.typeKeywords.includes("Template")) {
87
+ resultsHtml.push(`&#x2714; item is a Template Solution`);
88
+ }
89
+ else if (item.base.typeKeywords.includes("Deployed")) {
90
+ isTemplate = false;
91
+ resultsHtml.push(`&#x2714; item is a Deployed Solution`);
92
+ }
93
+ else {
94
+ throw new Error(`item is neither a Template Solution nor a Deployed Solution`);
95
+ }
96
+ // base: IItem; text/plain JSON
97
+ // data: File; */*
98
+ // thumbnail: File; image/*
99
+ // metadata: File; application/xml
100
+ // resources: File[]; list of */*
101
+ // fwdRelatedItems: IRelatedItems[]; list of forward relationshipType/relatedItems[] pairs
102
+ // revRelatedItems: IRelatedItems[]; list of reverse relationshipType/relatedItems[] pairs
103
+ return common__namespace.blobToJson(item.data);
104
+ })
105
+ // ---------- Check the Solution2Item relationship from a Deployed Solution to each deployed item --------------//
106
+ .then(itemDataJson => {
107
+ templateItems = itemDataJson?.templates;
108
+ /* istanbul ignore else */
109
+ if (!templateItems || templateItems.length === 0) {
110
+ throw new Error(`Solution's data are not valid JSON or the Solution contains no items`);
111
+ }
112
+ templateItemIds = templateItems
113
+ .map((template) => template.itemId)
114
+ .sort();
115
+ if (!isTemplate) {
116
+ // Make sure that there's a Solution2Item relationship to each deployed item
117
+ const fwdRelatedItemIds = item.fwdRelatedItems
118
+ .filter(relationshipSet => relationshipSet.relationshipType === "Solution2Item")
119
+ .reduce((flatSet, relationshipSet) => flatSet.concat(relationshipSet.relatedItemIds), [])
120
+ .sort();
121
+ if (templateItemIds.length < fwdRelatedItemIds.length) {
122
+ resultsHtml.push("&#x2716; there are forward Solution2Item relationship(s) to unknown item(s)");
123
+ }
124
+ else if (templateItemIds.length > fwdRelatedItemIds.length) {
125
+ resultsHtml.push("&#x2716; missing forward Solution2Item relationship(s)");
126
+ }
127
+ else if (JSON.stringify(templateItemIds) !==
128
+ JSON.stringify(fwdRelatedItemIds)) {
129
+ resultsHtml.push("&#x2716; mismatching forward Solution2Item relationship(s)");
130
+ }
131
+ else {
132
+ resultsHtml.push("&#x2714; matching forward Solution2Item relationship(s)");
133
+ }
134
+ }
135
+ return resultsHtml;
136
+ })
137
+ // ---------- Check that all dependency references are items in Solution ---------------------------------------//
138
+ .then(() => {
139
+ const dependencyIds = templateItems
140
+ .reduce((flatSet, template) => flatSet.concat(template.dependencies), [])
141
+ .reduce((noDupSet, dependency) => {
142
+ /* istanbul ignore else */
143
+ if (!noDupSet.includes(dependency))
144
+ noDupSet.push(dependency);
145
+ return noDupSet;
146
+ }, [])
147
+ .sort();
148
+ const missingItems = dependencyIds.filter((dependencyId) => !templateItemIds.includes(dependencyId));
149
+ if (missingItems.length === 0) {
150
+ resultsHtml.push("&#x2714; all dependencies are in Solution");
151
+ }
152
+ else {
153
+ resultsHtml.push("&#x2716; dependencies that aren't in Solution: " +
154
+ JSON.stringify(missingItems));
155
+ }
156
+ return resultsHtml;
157
+ })
158
+ // ---------- Done ---------------------------------------------------------------------------------------------//
159
+ .then(() => {
160
+ return resultsHtml;
161
+ })
162
+ // ---------- Fatal error --------------------------------------------------------------------------------------//
163
+ .catch(error => {
164
+ resultsHtml.push(`&#x2716; error${currentAction}: ${error.message}`);
165
+ return resultsHtml;
166
+ }));
167
+ }
168
+ /**
169
+ * Compares two AGO items, fetching them if only their id is supplied.
170
+ *
171
+ * @param item1 First item or its AGO id
172
+ * @param item2 Second item or its AGO id
173
+ * @param authentication Credentials for the request to AGO
174
+ * @return True if objects are the same
175
+ * @see Only comparable properties are compared; see deleteItemProps() in the `common` package
176
+ */
177
+ function compareItems(item1, item2, authentication = null) {
178
+ return new Promise((resolve, reject) => {
179
+ // If an input is a string, fetch the item; otherwise, clone the input because we will modify the
180
+ // item base to remove incomparable properties
181
+ let itemBaseDef1;
182
+ if (typeof item1 === "string") {
183
+ itemBaseDef1 = common__namespace.getItemBase(item1, authentication);
184
+ }
185
+ else {
186
+ itemBaseDef1 = Promise.resolve(common__namespace.cloneObject(item1));
187
+ }
188
+ let itemBaseDef2;
189
+ if (typeof item2 === "string") {
190
+ itemBaseDef2 = common__namespace.getItemBase(item2, authentication);
191
+ }
192
+ else {
193
+ itemBaseDef2 = Promise.resolve(common__namespace.cloneObject(item2));
194
+ }
195
+ Promise.all([itemBaseDef1, itemBaseDef2]).then(responses => {
196
+ const [itemBase1, itemBase2] = responses;
197
+ common__namespace.deleteItemProps(itemBase1);
198
+ common__namespace.deleteItemProps(itemBase2);
199
+ if (itemBase1.type === "Solution") {
200
+ delete itemBase1.typeKeywords;
201
+ delete itemBase1.size;
202
+ delete itemBase2.typeKeywords;
203
+ delete itemBase2.size;
204
+ }
205
+ /*console.log("----------------------------------------------------------------");
206
+ console.log("item 1 " + item1 + ": ", JSON.stringify(itemBase1, null, 2));
207
+ console.log("item 2 " + item2 + ": ", JSON.stringify(itemBase2, null, 2));
208
+ console.log("----------------------------------------------------------------");*/
209
+ resolve(common__namespace.compareJSONNoEmptyStrings(itemBase1, itemBase2));
210
+ }, e => reject(e));
211
+ });
212
+ }
213
+ /**
214
+ * Creates a hierarchy of the items in a Solution template.
215
+ *
216
+ * @param templates Array of templates from a Solution
217
+ * @return List of top-level items, each containing a recursive list of its dependencies
218
+ */
219
+ function getItemHierarchy(templates) {
220
+ const hierarchy = [];
221
+ // Get the template specified by id out of a list of templates
222
+ function getTemplateInSolution(templates, id) {
223
+ const iTemplate = templates.findIndex((template) => id === template.itemId);
224
+ return iTemplate >= 0 ? templates[iTemplate] : null;
225
+ }
226
+ // Hierarchically list the dependencies of specified node
227
+ function traceItemId(id, accumulatedHierarchy, alreadyVisitedIds = []) {
228
+ // Get the dependencies of the node
229
+ const template = getTemplateInSolution(templates, id);
230
+ /* istanbul ignore else */
231
+ if (template) {
232
+ const templateEntry = {
233
+ id,
234
+ dependencies: []
235
+ };
236
+ // Visit each dependency, but only if this template is not in the alreadyVisitedIds list to avoid infinite loops
237
+ if (alreadyVisitedIds.indexOf(id) < 0) {
238
+ // Add dependency to alreadyVisitedIds list
239
+ alreadyVisitedIds.push(id);
240
+ template.dependencies.forEach(dependencyId => {
241
+ // Remove dependency from list of templates to visit in the top-level loop
242
+ const iDependencyTemplate = templateItemIds.indexOf(dependencyId);
243
+ if (iDependencyTemplate >= 0) {
244
+ templateItemIds.splice(iDependencyTemplate, 1);
245
+ }
246
+ traceItemId(dependencyId, templateEntry.dependencies, alreadyVisitedIds);
247
+ });
248
+ }
249
+ accumulatedHierarchy.push(templateEntry);
250
+ }
251
+ }
252
+ // Start with top-level nodes and add in the rest of the nodes to catch cycles without top-level nodes
253
+ let templateItemIds = _getTopLevelItemIds(templates);
254
+ const otherItems = templates
255
+ .filter(template => templateItemIds.indexOf(template.itemId) < 0) // only keep non-top-level nodes
256
+ .sort((a, b) => b.dependencies.length - a.dependencies.length); // sort so that nodes with more dependencies come first--reduces stubs
257
+ templateItemIds = templateItemIds.concat(otherItems.map(template => template.itemId));
258
+ // Step through the list of nodes; we'll also remove nodes as we visit them
259
+ let itemId = templateItemIds.shift();
260
+ while (typeof itemId !== "undefined") {
261
+ traceItemId(itemId, hierarchy);
262
+ itemId = templateItemIds.shift();
263
+ }
264
+ return hierarchy;
265
+ }
266
+ // ------------------------------------------------------------------------------------------------------------------ //
267
+ /**
268
+ * Finds the top-level items in a Solution template--the items that are not dependencies of any other item.
269
+ *
270
+ * @param templates Array of templates from a Solution
271
+ * @return List of top-level item ids
272
+ */
273
+ function _getTopLevelItemIds(templates) {
274
+ // Find the top-level nodes. Start with all nodes, then remove those that other nodes depend on
275
+ const topLevelItemCandidateIds = templates.map(function (template) { return template.itemId; });
276
+ templates.forEach(function (template) {
277
+ (template.dependencies || []).forEach(function (dependencyId) {
278
+ const iNode = topLevelItemCandidateIds.indexOf(dependencyId);
279
+ /* istanbul ignore else */
280
+ if (iNode >= 0) {
281
+ // Node is somebody's dependency, so remove the node from the list of top-level nodes
282
+ // If iNode == -1, then it's a shared dependency and it has already been removed
283
+ topLevelItemCandidateIds.splice(iNode, 1);
284
+ }
285
+ });
286
+ });
287
+ return topLevelItemCandidateIds;
288
+ }
230
289
 
231
- exports.checkSolution = checkSolution;
232
- exports.compareItems = compareItems;
290
+ exports._getTopLevelItemIds = _getTopLevelItemIds;
291
+ exports.checkSolution = checkSolution;
292
+ exports.compareItems = compareItems;
293
+ exports.getItemHierarchy = getItemHierarchy;
233
294
 
234
- Object.defineProperty(exports, '__esModule', { value: true });
295
+ Object.defineProperty(exports, '__esModule', { value: true });
235
296
 
236
- })));
297
+ }));
237
298
  //# sourceMappingURL=viewer.umd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"viewer.umd.js","sources":["../../src/viewer.ts"],"sourcesContent":["/** @license\r\n * Copyright 2018 Esri\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\n\r\n/**\r\n * Provides the access to the solution's contents.\r\n *\r\n * @module viewer\r\n */\r\n\r\nimport * as common from \"@esri/solution-common\";\r\n\r\n// ------------------------------------------------------------------------------------------------------------------ //\r\n\r\n/**\r\n * Checks a Solution.\r\n *\r\n * @param item Solution id\r\n * @param authentication Credentials for the request to AGO\r\n * @return List of results of checks of Solution\r\n */\r\nexport function checkSolution(\r\n itemId: string,\r\n authentication: common.UserSession = null\r\n): Promise<string[]> {\r\n const resultsHtml: string[] = [`Item ${itemId}`];\r\n let item: common.ICompleteItem;\r\n let isTemplate = true;\r\n let templateItems: common.IItemTemplate[];\r\n let templateItemIds: string[];\r\n\r\n let currentAction: string = \" while getting complete item\";\r\n return (\r\n common\r\n .getCompleteItem(itemId, authentication)\r\n\r\n // ---------- Is it a Template or Deployed Solution? ---------------------------------------------------------------//\r\n .then((results: common.ICompleteItem) => {\r\n currentAction = \"\";\r\n item = results;\r\n\r\n if (!item) {\r\n throw new Error(`item is not found`);\r\n } else if (item.base.type !== \"Solution\") {\r\n throw new Error(`item is not a Solution`);\r\n } else if (item.base.typeKeywords.includes(\"Template\")) {\r\n resultsHtml.push(`&#x2714; item is a Template Solution`);\r\n } else if (item.base.typeKeywords.includes(\"Deployed\")) {\r\n isTemplate = false;\r\n resultsHtml.push(`&#x2714; item is a Deployed Solution`);\r\n } else {\r\n throw new Error(\r\n `item is neither a Template Solution nor a Deployed Solution`\r\n );\r\n }\r\n\r\n // base: IItem; text/plain JSON\r\n // data: File; */*\r\n // thumbnail: File; image/*\r\n // metadata: File; application/xml\r\n // resources: File[]; list of */*\r\n // fwdRelatedItems: IRelatedItems[]; list of forward relationshipType/relatedItems[] pairs\r\n // revRelatedItems: IRelatedItems[]; list of reverse relationshipType/relatedItems[] pairs\r\n return common.blobToJson(item.data);\r\n })\r\n\r\n // ---------- Check the Solution2Item relationship from a Deployed Solution to each deployed item ------------------//\r\n .then(itemDataJson => {\r\n templateItems = itemDataJson?.templates;\r\n /* istanbul ignore else */\r\n if (!templateItems || templateItems.length === 0) {\r\n throw new Error(\r\n `Solution's data are not valid JSON or the Solution contains no items`\r\n );\r\n }\r\n\r\n templateItemIds = templateItems\r\n .map((template: common.IItemTemplate) => template.itemId)\r\n .sort();\r\n\r\n if (!isTemplate) {\r\n // Make sure that there's a Solution2Item relationship to each deployed item\r\n const fwdRelatedItemIds = item.fwdRelatedItems\r\n .filter(\r\n relationshipSet =>\r\n relationshipSet.relationshipType === \"Solution2Item\"\r\n )\r\n .reduce(\r\n (flatSet, relationshipSet) =>\r\n flatSet.concat(relationshipSet.relatedItemIds),\r\n []\r\n )\r\n .sort();\r\n if (templateItemIds.length < fwdRelatedItemIds.length) {\r\n resultsHtml.push(\r\n \"&#x2716; there are forward Solution2Item relationship(s) to unknown item(s)\"\r\n );\r\n } else if (templateItemIds.length > fwdRelatedItemIds.length) {\r\n resultsHtml.push(\r\n \"&#x2716; missing forward Solution2Item relationship(s)\"\r\n );\r\n } else if (\r\n JSON.stringify(templateItemIds) !==\r\n JSON.stringify(fwdRelatedItemIds)\r\n ) {\r\n resultsHtml.push(\r\n \"&#x2716; mismatching forward Solution2Item relationship(s)\"\r\n );\r\n } else {\r\n resultsHtml.push(\r\n \"&#x2714; matching forward Solution2Item relationship(s)\"\r\n );\r\n }\r\n }\r\n return resultsHtml;\r\n })\r\n\r\n // ---------- Check that all dependency references are items in Solution -------------------------------------------//\r\n .then(() => {\r\n const dependencyIds = templateItems\r\n .reduce(\r\n (flatSet, template) => flatSet.concat(template.dependencies),\r\n []\r\n )\r\n .reduce((noDupSet, dependency) => {\r\n /* istanbul ignore else */\r\n if (!noDupSet.includes(dependency)) noDupSet.push(dependency);\r\n return noDupSet;\r\n }, [])\r\n .sort();\r\n\r\n const missingItems = dependencyIds.filter(\r\n (dependencyId: string) => !templateItemIds.includes(dependencyId)\r\n );\r\n\r\n if (missingItems.length === 0) {\r\n resultsHtml.push(\"&#x2714; all dependencies are in Solution\");\r\n } else {\r\n resultsHtml.push(\r\n \"&#x2716; dependencies that aren't in Solution: \" +\r\n JSON.stringify(missingItems)\r\n );\r\n }\r\n\r\n return resultsHtml;\r\n })\r\n\r\n // ---------- Done -------------------------------------------------------------------------------------------------//\r\n .then(() => {\r\n return resultsHtml;\r\n })\r\n\r\n // ---------- Fatal error ------------------------------------------------------------------------------------------//\r\n .catch(error => {\r\n resultsHtml.push(`&#x2716; error${currentAction}: ${error.message}`);\r\n return resultsHtml;\r\n })\r\n );\r\n}\r\n\r\n/**\r\n * Compares two AGO items, fetching them if only their id is supplied.\r\n *\r\n * @param item1 First item or its AGO id\r\n * @param item2 Second item or its AGO id\r\n * @param authentication Credentials for the request to AGO\r\n * @return True if objects are the same\r\n * @see Only comparable properties are compared; see deleteItemProps() in the `common` package\r\n */\r\nexport function compareItems(\r\n item1: string | any,\r\n item2: string | any,\r\n authentication: common.UserSession = null\r\n): Promise<boolean> {\r\n return new Promise<boolean>((resolve, reject) => {\r\n // If an input is a string, fetch the item; otherwise, clone the input because we will modify the\r\n // item base to remove incomparable properties\r\n let itemBaseDef1: Promise<any>;\r\n if (typeof item1 === \"string\") {\r\n itemBaseDef1 = common.getItemBase(item1, authentication);\r\n } else {\r\n itemBaseDef1 = Promise.resolve(common.cloneObject(item1));\r\n }\r\n\r\n let itemBaseDef2: Promise<any>;\r\n if (typeof item2 === \"string\") {\r\n itemBaseDef2 = common.getItemBase(item2, authentication);\r\n } else {\r\n itemBaseDef2 = Promise.resolve(common.cloneObject(item2));\r\n }\r\n\r\n Promise.all([itemBaseDef1, itemBaseDef2]).then(\r\n responses => {\r\n const [itemBase1, itemBase2] = responses;\r\n\r\n common.deleteItemProps(itemBase1);\r\n common.deleteItemProps(itemBase2);\r\n\r\n if (itemBase1.type === \"Solution\") {\r\n delete itemBase1.typeKeywords;\r\n delete itemBase1.size;\r\n delete itemBase2.typeKeywords;\r\n delete itemBase2.size;\r\n }\r\n\r\n /*console.log(\"----------------------------------------------------------------\");\r\n console.log(\"item 1 \" + item1 + \": \", JSON.stringify(itemBase1, null, 2));\r\n console.log(\"item 2 \" + item2 + \": \", JSON.stringify(itemBase2, null, 2));\r\n console.log(\"----------------------------------------------------------------\");*/\r\n\r\n resolve(common.compareJSONNoEmptyStrings(itemBase1, itemBase2));\r\n },\r\n e => reject(e)\r\n );\r\n });\r\n}\r\n"],"names":["common\r\n .getCompleteItem","common.blobToJson","common.getItemBase","common.cloneObject","common.deleteItemProps","common.compareJSONNoEmptyStrings"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAAA;;;;;;;;;;;;;;;IAwBA;IAEA;;;;;;;aAOgB,aAAa,CAC3B,MAAc,EACd,cAAyC;QAAzC,+BAAA,EAAA,qBAAyC;QAEzC,IAAM,WAAW,GAAa,CAAC,UAAQ,MAAQ,CAAC,CAAC;QACjD,IAAI,IAA0B,CAAC;QAC/B,IAAI,UAAU,GAAG,IAAI,CAAC;QACtB,IAAI,aAAqC,CAAC;QAC1C,IAAI,eAAyB,CAAC;QAE9B,IAAI,aAAa,GAAW,8BAA8B,CAAC;QAC3D,QACEA,sBACkB,CAAC,MAAM,EAAE,cAAc,CAAC;;aAGvC,IAAI,CAAC,UAAC,OAA6B;YAClC,aAAa,GAAG,EAAE,CAAC;YACnB,IAAI,GAAG,OAAO,CAAC;YAEf,IAAI,CAAC,IAAI,EAAE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AC;gBAElC,IAAI,SAAS,CAAC,IAAI,KAAK,UAAU,EAAE;oBACjC,OAAO,SAAS,CAAC,YAAY,CAAC;oBAC9B,OAAO,SAAS,CAAC,IAAI,CAAC;oBACtB,OAAO,SAAS,CAAC,YAAY,CAAC;oBAC9B,OAAO,SAAS,CAAC,IAAI,CAAC;iBACvB;;;;;gBAOD,OAAO,CAACC,gCAAgC,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC;aACjE,EACD,UAAA,CAAC,IAAI,OAAA,MAAM,CAAC,CAAC,CAAC,GAAA,CACf,CAAC;SACH,CAAC,CAAC;IACL;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"viewer.umd.js","sources":["../../src/viewer.ts"],"sourcesContent":["/** @license\r\n * Copyright 2018 Esri\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\n\r\n/**\r\n * Provides the access to the solution's contents.\r\n *\r\n * @module viewer\r\n */\r\n\r\nimport * as common from \"@esri/solution-common\";\r\n\r\n// ------------------------------------------------------------------------------------------------------------------ //\r\n\r\n/**\r\n * Checks a Solution.\r\n *\r\n * @param item Solution id\r\n * @param authentication Credentials for the request to AGO\r\n * @return List of results of checks of Solution\r\n */\r\nexport function checkSolution(\r\n itemId: string,\r\n authentication: common.UserSession = null\r\n): Promise<string[]> {\r\n const resultsHtml: string[] = [`Item ${itemId}`];\r\n let item: common.ICompleteItem;\r\n let isTemplate = true;\r\n let templateItems: common.IItemTemplate[];\r\n let templateItemIds: string[];\r\n\r\n let currentAction: string = \" while getting complete item\";\r\n return (\r\n common\r\n .getCompleteItem(itemId, authentication)\r\n\r\n // ---------- Is it a Template or Deployed Solution? -----------------------------------------------------------//\r\n .then((results: common.ICompleteItem) => {\r\n currentAction = \"\";\r\n item = results;\r\n\r\n if (!item) {\r\n throw new Error(`item is not found`);\r\n } else if (item.base.type !== \"Solution\") {\r\n throw new Error(`item is not a Solution`);\r\n } else if (item.base.typeKeywords.includes(\"Template\")) {\r\n resultsHtml.push(`&#x2714; item is a Template Solution`);\r\n } else if (item.base.typeKeywords.includes(\"Deployed\")) {\r\n isTemplate = false;\r\n resultsHtml.push(`&#x2714; item is a Deployed Solution`);\r\n } else {\r\n throw new Error(\r\n `item is neither a Template Solution nor a Deployed Solution`\r\n );\r\n }\r\n\r\n // base: IItem; text/plain JSON\r\n // data: File; */*\r\n // thumbnail: File; image/*\r\n // metadata: File; application/xml\r\n // resources: File[]; list of */*\r\n // fwdRelatedItems: IRelatedItems[]; list of forward relationshipType/relatedItems[] pairs\r\n // revRelatedItems: IRelatedItems[]; list of reverse relationshipType/relatedItems[] pairs\r\n return common.blobToJson(item.data);\r\n })\r\n\r\n // ---------- Check the Solution2Item relationship from a Deployed Solution to each deployed item --------------//\r\n .then(itemDataJson => {\r\n templateItems = itemDataJson?.templates;\r\n /* istanbul ignore else */\r\n if (!templateItems || templateItems.length === 0) {\r\n throw new Error(\r\n `Solution's data are not valid JSON or the Solution contains no items`\r\n );\r\n }\r\n\r\n templateItemIds = templateItems\r\n .map((template: common.IItemTemplate) => template.itemId)\r\n .sort();\r\n\r\n if (!isTemplate) {\r\n // Make sure that there's a Solution2Item relationship to each deployed item\r\n const fwdRelatedItemIds = item.fwdRelatedItems\r\n .filter(\r\n relationshipSet =>\r\n relationshipSet.relationshipType === \"Solution2Item\"\r\n )\r\n .reduce(\r\n (flatSet, relationshipSet) =>\r\n flatSet.concat(relationshipSet.relatedItemIds),\r\n []\r\n )\r\n .sort();\r\n if (templateItemIds.length < fwdRelatedItemIds.length) {\r\n resultsHtml.push(\r\n \"&#x2716; there are forward Solution2Item relationship(s) to unknown item(s)\"\r\n );\r\n } else if (templateItemIds.length > fwdRelatedItemIds.length) {\r\n resultsHtml.push(\r\n \"&#x2716; missing forward Solution2Item relationship(s)\"\r\n );\r\n } else if (\r\n JSON.stringify(templateItemIds) !==\r\n JSON.stringify(fwdRelatedItemIds)\r\n ) {\r\n resultsHtml.push(\r\n \"&#x2716; mismatching forward Solution2Item relationship(s)\"\r\n );\r\n } else {\r\n resultsHtml.push(\r\n \"&#x2714; matching forward Solution2Item relationship(s)\"\r\n );\r\n }\r\n }\r\n return resultsHtml;\r\n })\r\n\r\n // ---------- Check that all dependency references are items in Solution ---------------------------------------//\r\n .then(() => {\r\n const dependencyIds = templateItems\r\n .reduce(\r\n (flatSet, template) => flatSet.concat(template.dependencies),\r\n []\r\n )\r\n .reduce((noDupSet, dependency) => {\r\n /* istanbul ignore else */\r\n if (!noDupSet.includes(dependency)) noDupSet.push(dependency);\r\n return noDupSet;\r\n }, [])\r\n .sort();\r\n\r\n const missingItems = dependencyIds.filter(\r\n (dependencyId: string) => !templateItemIds.includes(dependencyId)\r\n );\r\n\r\n if (missingItems.length === 0) {\r\n resultsHtml.push(\"&#x2714; all dependencies are in Solution\");\r\n } else {\r\n resultsHtml.push(\r\n \"&#x2716; dependencies that aren't in Solution: \" +\r\n JSON.stringify(missingItems)\r\n );\r\n }\r\n\r\n return resultsHtml;\r\n })\r\n\r\n // ---------- Done ---------------------------------------------------------------------------------------------//\r\n .then(() => {\r\n return resultsHtml;\r\n })\r\n\r\n // ---------- Fatal error --------------------------------------------------------------------------------------//\r\n .catch(error => {\r\n resultsHtml.push(`&#x2716; error${currentAction}: ${error.message}`);\r\n return resultsHtml;\r\n })\r\n );\r\n}\r\n\r\n/**\r\n * Compares two AGO items, fetching them if only their id is supplied.\r\n *\r\n * @param item1 First item or its AGO id\r\n * @param item2 Second item or its AGO id\r\n * @param authentication Credentials for the request to AGO\r\n * @return True if objects are the same\r\n * @see Only comparable properties are compared; see deleteItemProps() in the `common` package\r\n */\r\nexport function compareItems(\r\n item1: string | any,\r\n item2: string | any,\r\n authentication: common.UserSession = null\r\n): Promise<boolean> {\r\n return new Promise<boolean>((resolve, reject) => {\r\n // If an input is a string, fetch the item; otherwise, clone the input because we will modify the\r\n // item base to remove incomparable properties\r\n let itemBaseDef1: Promise<any>;\r\n if (typeof item1 === \"string\") {\r\n itemBaseDef1 = common.getItemBase(item1, authentication);\r\n } else {\r\n itemBaseDef1 = Promise.resolve(common.cloneObject(item1));\r\n }\r\n\r\n let itemBaseDef2: Promise<any>;\r\n if (typeof item2 === \"string\") {\r\n itemBaseDef2 = common.getItemBase(item2, authentication);\r\n } else {\r\n itemBaseDef2 = Promise.resolve(common.cloneObject(item2));\r\n }\r\n\r\n Promise.all([itemBaseDef1, itemBaseDef2]).then(\r\n responses => {\r\n const [itemBase1, itemBase2] = responses;\r\n\r\n common.deleteItemProps(itemBase1);\r\n common.deleteItemProps(itemBase2);\r\n\r\n if (itemBase1.type === \"Solution\") {\r\n delete itemBase1.typeKeywords;\r\n delete itemBase1.size;\r\n delete itemBase2.typeKeywords;\r\n delete itemBase2.size;\r\n }\r\n\r\n /*console.log(\"----------------------------------------------------------------\");\r\n console.log(\"item 1 \" + item1 + \": \", JSON.stringify(itemBase1, null, 2));\r\n console.log(\"item 2 \" + item2 + \": \", JSON.stringify(itemBase2, null, 2));\r\n console.log(\"----------------------------------------------------------------\");*/\r\n\r\n resolve(common.compareJSONNoEmptyStrings(itemBase1, itemBase2));\r\n },\r\n e => reject(e)\r\n );\r\n });\r\n}\r\n\r\n/**\r\n * Creates a hierarchy of the items in a Solution template.\r\n *\r\n * @param templates Array of templates from a Solution\r\n * @return List of top-level items, each containing a recursive list of its dependencies\r\n */\r\nexport function getItemHierarchy(\r\n templates: common.IItemTemplate[]\r\n): common.IHierarchyElement[] {\r\n const hierarchy = [] as common.IHierarchyElement[];\r\n\r\n // Get the template specified by id out of a list of templates\r\n function getTemplateInSolution(templates: common.IItemTemplate[], id: string): common.IItemTemplate {\r\n const iTemplate = templates.findIndex((template) => id === template.itemId);\r\n return iTemplate >= 0 ? templates[iTemplate] : null;\r\n }\r\n\r\n // Hierarchically list the dependencies of specified node\r\n function traceItemId(id: string, accumulatedHierarchy: common.IHierarchyElement[], alreadyVisitedIds: string[] = []) {\r\n // Get the dependencies of the node\r\n const template = getTemplateInSolution(templates, id);\r\n /* istanbul ignore else */\r\n if (template) {\r\n const templateEntry = {\r\n id,\r\n dependencies: [] as common.IHierarchyElement[]\r\n };\r\n\r\n // Visit each dependency, but only if this template is not in the alreadyVisitedIds list to avoid infinite loops\r\n if (alreadyVisitedIds.indexOf(id) < 0) {\r\n // Add dependency to alreadyVisitedIds list\r\n alreadyVisitedIds.push(id);\r\n\r\n template.dependencies.forEach(\r\n dependencyId => {\r\n // Remove dependency from list of templates to visit in the top-level loop\r\n const iDependencyTemplate = templateItemIds.indexOf(dependencyId);\r\n if (iDependencyTemplate >= 0) {\r\n templateItemIds.splice(iDependencyTemplate, 1);\r\n }\r\n\r\n traceItemId(dependencyId, templateEntry.dependencies, alreadyVisitedIds);\r\n }\r\n );\r\n }\r\n accumulatedHierarchy.push(templateEntry);\r\n }\r\n }\r\n\r\n // Start with top-level nodes and add in the rest of the nodes to catch cycles without top-level nodes\r\n let templateItemIds: string[] = _getTopLevelItemIds(templates);\r\n\r\n const otherItems: common.IItemTemplate[] = templates\r\n .filter(template => templateItemIds.indexOf(template.itemId) < 0) // only keep non-top-level nodes\r\n .sort((a, b) => b.dependencies.length - a.dependencies.length); // sort so that nodes with more dependencies come first--reduces stubs\r\n\r\n templateItemIds = templateItemIds.concat(otherItems.map(template => template.itemId));\r\n\r\n // Step through the list of nodes; we'll also remove nodes as we visit them\r\n let itemId = templateItemIds.shift();\r\n while (typeof itemId !== \"undefined\") {\r\n traceItemId(itemId, hierarchy);\r\n itemId = templateItemIds.shift();\r\n }\r\n\r\n return hierarchy;\r\n}\r\n\r\n// ------------------------------------------------------------------------------------------------------------------ //\r\n\r\n/**\r\n * Finds the top-level items in a Solution template--the items that are not dependencies of any other item.\r\n *\r\n * @param templates Array of templates from a Solution\r\n * @return List of top-level item ids\r\n */\r\nexport function _getTopLevelItemIds(\r\n templates: common.IItemTemplate[]\r\n): string[] {\r\n // Find the top-level nodes. Start with all nodes, then remove those that other nodes depend on\r\n const topLevelItemCandidateIds = templates.map(function (template) { return template.itemId; });\r\n\r\n templates.forEach(function (template) {\r\n (template.dependencies || []).forEach(function (dependencyId) {\r\n const iNode = topLevelItemCandidateIds.indexOf(dependencyId);\r\n\r\n /* istanbul ignore else */\r\n if (iNode >= 0) {\r\n // Node is somebody's dependency, so remove the node from the list of top-level nodes\r\n // If iNode == -1, then it's a shared dependency and it has already been removed\r\n topLevelItemCandidateIds.splice(iNode, 1);\r\n }\r\n });\r\n });\r\n\r\n return topLevelItemCandidateIds;\r\n};\r\n"],"names":["common"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAA;;;;;;;;;;;;;;;EAwBA;EAEA;;;;;;;WAOgB,aAAa,CAC3B,MAAc,EACd,iBAAqC,IAAI;MAEzC,MAAM,WAAW,GAAa,CAAC,QAAQ,MAAM,EAAE,CAAC,CAAC;MACjD,IAAI,IAA0B,CAAC;MAC/B,IAAI,UAAU,GAAG,IAAI,CAAC;MACtB,IAAI,aAAqC,CAAC;MAC1C,IAAI,eAAyB,CAAC;MAE9B,IAAI,aAAa,GAAW,8BAA8B,CAAC;MAC3D,QACEA,iBAAM;WACH,eAAe,CAAC,MAAM,EAAE,cAAc,CAAC;;WAGvC,IAAI,CAAC,CAAC,OAA6B;UAClC,aAAa,GAAG,EAAE,CAAC;UACnB,IAAI,GAAG,OAAO,CAAC;UAEf,IAAI,CAAC,IAAI,EAAE;cACT,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;WACtC;eAAM,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,UAAU,EAAE;cACxC,MAAM,IAAI,KA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