@esri/hub-common 9.21.2 → 9.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es2017/content/_fetch.js +87 -0
- package/dist/es2017/content/_fetch.js.map +1 -0
- package/dist/es2017/content/_internal.js +75 -3
- package/dist/es2017/content/_internal.js.map +1 -1
- package/dist/es2017/content/compose.js +18 -10
- package/dist/es2017/content/compose.js.map +1 -1
- package/dist/es2017/content/fetch.js +78 -0
- package/dist/es2017/content/fetch.js.map +1 -0
- package/dist/es2017/content/index.js +9 -80
- package/dist/es2017/content/index.js.map +1 -1
- package/dist/es2017/content/slugs.js +63 -0
- package/dist/es2017/content/slugs.js.map +1 -0
- package/dist/es2017/content/types.js +1 -0
- package/dist/es2017/content/types.js.map +1 -0
- package/dist/es2017/items/_enrichments.js +176 -0
- package/dist/es2017/items/_enrichments.js.map +1 -0
- package/dist/esm/content/_fetch.js +102 -0
- package/dist/esm/content/_fetch.js.map +1 -0
- package/dist/esm/content/_internal.js +75 -3
- package/dist/esm/content/_internal.js.map +1 -1
- package/dist/esm/content/compose.js +18 -10
- package/dist/esm/content/compose.js.map +1 -1
- package/dist/esm/content/fetch.js +103 -0
- package/dist/esm/content/fetch.js.map +1 -0
- package/dist/esm/content/index.js +9 -80
- package/dist/esm/content/index.js.map +1 -1
- package/dist/esm/content/slugs.js +63 -0
- package/dist/esm/content/slugs.js.map +1 -0
- package/dist/esm/content/types.js +1 -0
- package/dist/esm/content/types.js.map +1 -0
- package/dist/esm/items/_enrichments.js +177 -0
- package/dist/esm/items/_enrichments.js.map +1 -0
- package/dist/node/content/_fetch.js +90 -0
- package/dist/node/content/_fetch.js.map +1 -0
- package/dist/node/content/_internal.js +76 -4
- package/dist/node/content/_internal.js.map +1 -1
- package/dist/node/content/compose.js +17 -9
- package/dist/node/content/compose.js.map +1 -1
- package/dist/node/content/fetch.js +81 -0
- package/dist/node/content/fetch.js.map +1 -0
- package/dist/node/content/index.js +11 -86
- package/dist/node/content/index.js.map +1 -1
- package/dist/node/content/slugs.js +70 -0
- package/dist/node/content/slugs.js.map +1 -0
- package/dist/node/content/types.js +3 -0
- package/dist/node/content/types.js.map +1 -0
- package/dist/node/items/_enrichments.js +179 -0
- package/dist/node/items/_enrichments.js.map +1 -0
- package/dist/types/content/_fetch.d.ts +61 -0
- package/dist/types/content/_internal.d.ts +76 -0
- package/dist/types/content/compose.d.ts +11 -0
- package/dist/types/content/fetch.d.ts +23 -0
- package/dist/types/content/index.d.ts +4 -41
- package/dist/types/content/slugs.d.ts +34 -0
- package/dist/types/content/types.d.ts +7 -0
- package/dist/types/items/_enrichments.d.ts +24 -0
- package/dist/umd/common.umd.js +2082 -850
- package/dist/umd/common.umd.js.map +1 -1
- package/dist/umd/common.umd.min.js +1 -1
- package/dist/umd/common.umd.min.js.map +1 -1
- package/package.json +2 -1
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { getCollection } from "../collections";
|
|
2
2
|
import { categories as allCategories } from "../categories";
|
|
3
|
-
import {
|
|
4
|
-
import { includes, isGuid } from "../utils";
|
|
3
|
+
import { includes } from "../utils";
|
|
5
4
|
import { getProp } from "../objects";
|
|
6
5
|
import { getServiceTypeFromUrl } from "../urls";
|
|
7
6
|
import { getHubRelativeUrl, isPageType } from "./_internal";
|
|
8
7
|
import { camelize } from "../util";
|
|
9
8
|
import { normalizeItemType, getContentTypeIcon, composeContent, } from "./compose";
|
|
10
9
|
import { getFamily } from "./get-family";
|
|
10
|
+
import { parseDatasetId, removeContextFromSlug } from "./slugs";
|
|
11
11
|
// re-export functions used in this file
|
|
12
12
|
export * from "./compose";
|
|
13
13
|
export * from "./get-family";
|
|
14
|
+
export * from "./slugs";
|
|
15
|
+
export * from "./fetch";
|
|
16
|
+
export * from "./types";
|
|
14
17
|
// TODO: remove this at next breaking version
|
|
15
18
|
/**
|
|
16
19
|
* ```js
|
|
@@ -123,67 +126,6 @@ export function getContentIdentifier(content, site) {
|
|
|
123
126
|
}
|
|
124
127
|
return content.hubId || content.id;
|
|
125
128
|
}
|
|
126
|
-
//////////////////////
|
|
127
|
-
// Slug Helpers
|
|
128
|
-
//////////////////////
|
|
129
|
-
/**
|
|
130
|
-
* Parse item ID and layer ID (if any) from dataset record ID
|
|
131
|
-
*
|
|
132
|
-
* @param datasetId Hub API dataset record id ({itemId}_{layerId} or {itemId})
|
|
133
|
-
* @returns A hash with the `itemId` and `layerId` (if any)
|
|
134
|
-
*/
|
|
135
|
-
export function parseDatasetId(datasetId) {
|
|
136
|
-
const [itemId, layerId] = datasetId ? datasetId.split("_") : [];
|
|
137
|
-
return { itemId, layerId };
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Determine if an identifier is a Hub API slug
|
|
141
|
-
*
|
|
142
|
-
* @param identifier Hub API slug ({orgKey}::{title-as-slug} or {title-as-slug})
|
|
143
|
-
* or record id ((itemId}_{layerId} or {itemId})
|
|
144
|
-
* @returns true if the identifier is valid _and_ is **not** a record id
|
|
145
|
-
*/
|
|
146
|
-
export function isSlug(identifier) {
|
|
147
|
-
const { itemId } = parseDatasetId(identifier);
|
|
148
|
-
if (!itemId || isGuid(itemId)) {
|
|
149
|
-
// it's either invalid, or an item id, or a dataset id
|
|
150
|
-
return false;
|
|
151
|
-
}
|
|
152
|
-
// otherwise assume it's a slug
|
|
153
|
-
return true;
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Add a context (prefix) to slug if it doesn't already have one
|
|
157
|
-
*
|
|
158
|
-
* @param slug Hub API slug (with or without context)
|
|
159
|
-
* @param context usually a portal's orgKey
|
|
160
|
-
* @returns slug with context ({context}::{slug})
|
|
161
|
-
*/
|
|
162
|
-
export function addContextToSlug(slug, context) {
|
|
163
|
-
// the slug has an org key already e.g. dc::crime-incidents
|
|
164
|
-
if (/.+::.+/.test(slug)) {
|
|
165
|
-
return slug;
|
|
166
|
-
// the slug belongs to the org that owns the site e.g. crime-incidents
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
return `${context}::${slug}`;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Remove context (prefix) from a slug
|
|
174
|
-
*
|
|
175
|
-
* @param slug Hub API slug with context
|
|
176
|
-
* @param context usually a portal's orgKey
|
|
177
|
-
* @returns slug without context
|
|
178
|
-
*/
|
|
179
|
-
export function removeContextFromSlug(slug, context) {
|
|
180
|
-
if (context && slug.match(`${context}::`)) {
|
|
181
|
-
return slug.split(`${context}::`)[1];
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
return slug;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
129
|
/**
|
|
188
130
|
* DEPRECATED: Use getFamily() instead.
|
|
189
131
|
*
|
|
@@ -229,7 +171,7 @@ export function datasetToContent(dataset) {
|
|
|
229
171
|
// map and feature server enrichments
|
|
230
172
|
server, layers, layer, recordCount, statistics,
|
|
231
173
|
// additional attributes needed
|
|
232
|
-
extent,
|
|
174
|
+
extent, searchDescription, } = dataset.attributes;
|
|
233
175
|
// get the layerId from the layer
|
|
234
176
|
const layerId = layer && layer.id;
|
|
235
177
|
// re-assemble the org as an enrichment
|
|
@@ -239,7 +181,7 @@ export function datasetToContent(dataset) {
|
|
|
239
181
|
extent: orgExtent,
|
|
240
182
|
};
|
|
241
183
|
// compose a content out of the above
|
|
242
|
-
|
|
184
|
+
return composeContent(item, {
|
|
243
185
|
layerId,
|
|
244
186
|
slug,
|
|
245
187
|
errors,
|
|
@@ -251,23 +193,10 @@ export function datasetToContent(dataset) {
|
|
|
251
193
|
layers,
|
|
252
194
|
recordCount,
|
|
253
195
|
boundary,
|
|
196
|
+
extent,
|
|
197
|
+
searchDescription,
|
|
254
198
|
statistics,
|
|
255
199
|
});
|
|
256
|
-
// TODO: need to add searchDescription logic to composeContent()
|
|
257
|
-
// or fetch it as a Hub enrichment like boundary
|
|
258
|
-
if (searchDescription) {
|
|
259
|
-
// overwrite default summary (from snippet) w/ search description
|
|
260
|
-
content.summary = searchDescription;
|
|
261
|
-
}
|
|
262
|
-
// TODO: need to add extent logic to composeContent()
|
|
263
|
-
// or fetch it as a Hub enrichment like boundary
|
|
264
|
-
if (!isBBox(item.extent) && extent && isBBox(extent.coordinates)) {
|
|
265
|
-
// we fall back to the extent derived by the API
|
|
266
|
-
// which prefers layer or service extents and ultimately
|
|
267
|
-
// falls back to the org's extent
|
|
268
|
-
content.extent = extent.coordinates;
|
|
269
|
-
}
|
|
270
|
-
return content;
|
|
271
200
|
}
|
|
272
201
|
/**
|
|
273
202
|
* Convert a Hub API dataset resource to a portal item
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/content/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/content/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,UAAU,IAAI,aAAa,EAAE,MAAM,eAAe,CAAC;AAE5D,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,GACf,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAGhE,wCAAwC;AACxC,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,SA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AAC;AAChC,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,OAAoB,EACpB,SAAiB,EACJ,EAAE;IACf,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,kBAAkB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAC5E,2CAA2C;IAC3C,OAAO,iBAAiB,CAAC,OAAO,EAAE;QAChC,QAAQ;QACR,IAAI;KACL,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,cAAc;AACd,MAAM,iBAAiB,GAAG,CACxB,OAAoB,EACpB,OAA+B,EAClB,EAAE;IACf,6DAA6D;IAC7D,MAAM,IAAI,mCAAQ,OAAO,CAAC,IAAI,GAAK,OAAO,CAAE,CAAC;IAC7C,uCAAY,OAAO,KAAE,IAAI,IAAG;AAC9B,CAAC,CAAC;AAEF,MAAM,qBAAqB,GAAG,CAC5B,OAAoB,EACpB,cAAuB,EACvB,EAAE;IACF,OAAO,iBAAiB,CACtB,OAAO,CAAC,IAAI,EACZ,cAAc,IAAI,OAAO,CAAC,UAAU,EACpC,OAAO,CAAC,YAAY,CACrB,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { isGuid } from "../utils";
|
|
2
|
+
//////////////////////
|
|
3
|
+
// Slug Helpers
|
|
4
|
+
//////////////////////
|
|
5
|
+
/**
|
|
6
|
+
* Parse item ID and layer ID (if any) from dataset record ID
|
|
7
|
+
*
|
|
8
|
+
* @param datasetId Hub API dataset record id ({itemId}_{layerId} or {itemId})
|
|
9
|
+
* @returns A hash with the `itemId` and `layerId` (if any)
|
|
10
|
+
*/
|
|
11
|
+
export function parseDatasetId(datasetId) {
|
|
12
|
+
const [itemId, layerId] = datasetId ? datasetId.split("_") : [];
|
|
13
|
+
return { itemId, layerId };
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Determine if an identifier is a Hub API slug
|
|
17
|
+
*
|
|
18
|
+
* @param identifier Hub API slug ({orgKey}::{title-as-slug} or {title-as-slug})
|
|
19
|
+
* or record id ((itemId}_{layerId} or {itemId})
|
|
20
|
+
* @returns true if the identifier is valid _and_ is **not** a record id
|
|
21
|
+
*/
|
|
22
|
+
export function isSlug(identifier) {
|
|
23
|
+
const { itemId } = parseDatasetId(identifier);
|
|
24
|
+
if (!itemId || isGuid(itemId)) {
|
|
25
|
+
// it's either invalid, or an item id, or a dataset id
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
// otherwise assume it's a slug
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Add a context (prefix) to slug if it doesn't already have one
|
|
33
|
+
*
|
|
34
|
+
* @param slug Hub API slug (with or without context)
|
|
35
|
+
* @param context usually a portal's orgKey
|
|
36
|
+
* @returns slug with context ({context}::{slug})
|
|
37
|
+
*/
|
|
38
|
+
export function addContextToSlug(slug, context) {
|
|
39
|
+
// the slug has an org key already e.g. dc::crime-incidents
|
|
40
|
+
if (/.+::.+/.test(slug)) {
|
|
41
|
+
return slug;
|
|
42
|
+
// the slug belongs to the org that owns the site e.g. crime-incidents
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
return `${context}::${slug}`;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Remove context (prefix) from a slug
|
|
50
|
+
*
|
|
51
|
+
* @param slug Hub API slug with context
|
|
52
|
+
* @param context usually a portal's orgKey
|
|
53
|
+
* @returns slug without context
|
|
54
|
+
*/
|
|
55
|
+
export function removeContextFromSlug(slug, context) {
|
|
56
|
+
if (context && slug.match(`${context}::`)) {
|
|
57
|
+
return slug.split(`${context}::`)[1];
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
return slug;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=slugs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+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0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/content/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { getItemData, getItemGroups, getUser, } from "@esri/arcgis-rest-portal";
|
|
2
|
+
import { getAllLayersAndTables, getService, } from "@esri/arcgis-rest-feature-layer";
|
|
3
|
+
import { createOperationPipeline } from "../utils";
|
|
4
|
+
import OperationStack from "../OperationStack";
|
|
5
|
+
// TODO: move these functions here under /items
|
|
6
|
+
import { getItemMetadata } from "@esri/arcgis-rest-portal";
|
|
7
|
+
import { parse } from "fast-xml-parser";
|
|
8
|
+
function parseMetadataXml(metadataXml) {
|
|
9
|
+
const opts = {
|
|
10
|
+
// options for fastXmlParser to read tag attrs
|
|
11
|
+
ignoreAttributes: false,
|
|
12
|
+
attributeNamePrefix: "@_",
|
|
13
|
+
textNodeName: "#value",
|
|
14
|
+
};
|
|
15
|
+
return parse(metadataXml, opts);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Fetch an [item's metadata](https://doc.arcgis.com/en/arcgis-online/manage-data/metadata.htm) from a portal
|
|
19
|
+
* and parse and return it as JSON
|
|
20
|
+
* @param id item id
|
|
21
|
+
* @param requestOptions
|
|
22
|
+
*/
|
|
23
|
+
function fetchContentMetadata(id, requestOptions) {
|
|
24
|
+
return getItemMetadata(id, requestOptions)
|
|
25
|
+
.then((metadataXml) => parseMetadataXml(metadataXml))
|
|
26
|
+
.catch(() => {
|
|
27
|
+
// many items don't have metadata and the request will 404
|
|
28
|
+
// in these cases we don't want to treat it as an error
|
|
29
|
+
// content.metadata === null signals to consumers that
|
|
30
|
+
// we attempted to fetch the metadata, but it doesn't exist
|
|
31
|
+
// TODO: we should probably still throw the error if it's not a 404
|
|
32
|
+
return null;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const enrichGroupIds = (input) => {
|
|
36
|
+
const { data, stack, requestOptions } = input;
|
|
37
|
+
const opId = stack.start("enrichGroupIds");
|
|
38
|
+
return getItemGroups(data.item.id, requestOptions)
|
|
39
|
+
.then((response) => {
|
|
40
|
+
const { admin, member, other } = response;
|
|
41
|
+
const groupIds = [...admin, ...member, ...other].map((group) => group.id);
|
|
42
|
+
stack.finish(opId);
|
|
43
|
+
return {
|
|
44
|
+
data: Object.assign(Object.assign({}, data), { groupIds }),
|
|
45
|
+
stack,
|
|
46
|
+
requestOptions,
|
|
47
|
+
};
|
|
48
|
+
})
|
|
49
|
+
.catch((error) => handleEnrichmentError(error, input, opId));
|
|
50
|
+
};
|
|
51
|
+
const enrichMetadata = (input) => {
|
|
52
|
+
const { data, stack, requestOptions } = input;
|
|
53
|
+
const opId = stack.start("enrichMetadata");
|
|
54
|
+
return fetchContentMetadata(data.item.id, requestOptions).then((metadata) => {
|
|
55
|
+
stack.finish(opId);
|
|
56
|
+
return {
|
|
57
|
+
data: Object.assign(Object.assign({}, data), { metadata }),
|
|
58
|
+
stack,
|
|
59
|
+
requestOptions,
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
// TODO: currently fetchContentMetadata will never throw, but
|
|
63
|
+
// if we update it to throw for non-404 errors, need to uncomment this:
|
|
64
|
+
// .catch((error) => handleEnrichmentError(error, input, opId));
|
|
65
|
+
};
|
|
66
|
+
const enrichOwnerUser = (input) => {
|
|
67
|
+
const { data, stack, requestOptions } = input;
|
|
68
|
+
const opId = stack.start("enrichOwner");
|
|
69
|
+
// w/o the : any here, I get a compile error about
|
|
70
|
+
// .authentication being incompatible w/ UserSession
|
|
71
|
+
const options = Object.assign({ username: data.item.owner }, requestOptions);
|
|
72
|
+
return getUser(options)
|
|
73
|
+
.then((ownerUser) => {
|
|
74
|
+
stack.finish(opId);
|
|
75
|
+
return {
|
|
76
|
+
data: Object.assign(Object.assign({}, data), { ownerUser }),
|
|
77
|
+
stack,
|
|
78
|
+
requestOptions,
|
|
79
|
+
};
|
|
80
|
+
})
|
|
81
|
+
.catch((error) => handleEnrichmentError(error, input, opId));
|
|
82
|
+
};
|
|
83
|
+
const enrichData = (input) => {
|
|
84
|
+
const { data, stack, requestOptions } = input;
|
|
85
|
+
const opId = stack.start("enrichData");
|
|
86
|
+
return getItemData(data.item.id, requestOptions)
|
|
87
|
+
.then((itemData) => {
|
|
88
|
+
stack.finish(opId);
|
|
89
|
+
return { data: Object.assign(Object.assign({}, data), { data: itemData }), stack, requestOptions };
|
|
90
|
+
})
|
|
91
|
+
.catch((error) => handleEnrichmentError(error, input, opId));
|
|
92
|
+
};
|
|
93
|
+
const enrichServer = (input) => {
|
|
94
|
+
const { data, stack, requestOptions } = input;
|
|
95
|
+
const opId = stack.start("enrichServer");
|
|
96
|
+
const url = data.item.url;
|
|
97
|
+
const options = Object.assign(Object.assign({}, requestOptions), { url });
|
|
98
|
+
return getService(options)
|
|
99
|
+
.then((server) => {
|
|
100
|
+
stack.finish(opId);
|
|
101
|
+
return { data: Object.assign(Object.assign({}, data), { server }), stack, requestOptions };
|
|
102
|
+
})
|
|
103
|
+
.catch((error) => handleEnrichmentError(error, input, opId));
|
|
104
|
+
};
|
|
105
|
+
const enrichLayers = (input) => {
|
|
106
|
+
const { data, stack, requestOptions } = input;
|
|
107
|
+
const opId = stack.start("enrichLayers");
|
|
108
|
+
const url = data.item.url;
|
|
109
|
+
const options = Object.assign(Object.assign({}, requestOptions), { url });
|
|
110
|
+
return (getAllLayersAndTables(options)
|
|
111
|
+
// merge layers and tables into a single array
|
|
112
|
+
// and filter out any group layers
|
|
113
|
+
.then((response) => {
|
|
114
|
+
const merged = [...response.layers, ...response.tables];
|
|
115
|
+
return merged.filter((layer) => layer.type !== "Group Layer");
|
|
116
|
+
})
|
|
117
|
+
.then((layers) => {
|
|
118
|
+
stack.finish(opId);
|
|
119
|
+
return { data: Object.assign(Object.assign({}, data), { layers }), stack, requestOptions };
|
|
120
|
+
})
|
|
121
|
+
.catch((error) => handleEnrichmentError(error, input, opId)));
|
|
122
|
+
};
|
|
123
|
+
// add the error to the content.errors,
|
|
124
|
+
// log current stack operation as finished with an error
|
|
125
|
+
// and return output that can be piped into the next operation
|
|
126
|
+
const handleEnrichmentError = (error, input, opId) => {
|
|
127
|
+
const { data, stack, requestOptions } = input;
|
|
128
|
+
stack.finish(opId, { error });
|
|
129
|
+
const message = typeof error === "string"
|
|
130
|
+
? /* istanbul ignore next our tests only throw Error objects */
|
|
131
|
+
error
|
|
132
|
+
: error.message;
|
|
133
|
+
const errors = data.errors || [];
|
|
134
|
+
errors.push({
|
|
135
|
+
// NOTE: for now we just return the message and type "Other"
|
|
136
|
+
// but we could later introspect for HTTP or AGO errors
|
|
137
|
+
// and/or return the status code if available
|
|
138
|
+
type: "Other",
|
|
139
|
+
message,
|
|
140
|
+
});
|
|
141
|
+
return { data: Object.assign(Object.assign({}, data), { errors }), stack, requestOptions };
|
|
142
|
+
};
|
|
143
|
+
const enrichmentOperations = {
|
|
144
|
+
groupIds: enrichGroupIds,
|
|
145
|
+
metadata: enrichMetadata,
|
|
146
|
+
ownerUser: enrichOwnerUser,
|
|
147
|
+
// TOOD: org
|
|
148
|
+
data: enrichData,
|
|
149
|
+
server: enrichServer,
|
|
150
|
+
layers: enrichLayers,
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* Fetch enrichments for an item
|
|
154
|
+
* @param item
|
|
155
|
+
* @param enrichments the list of enrichments to fetch
|
|
156
|
+
* @param requestOptions
|
|
157
|
+
* @returns an object with the item and enrichments
|
|
158
|
+
* @private
|
|
159
|
+
*/
|
|
160
|
+
export const fetchItemEnrichments = (item, enrichments, requestOptions) => {
|
|
161
|
+
// create a pipeline of enrichment operations
|
|
162
|
+
const operations = enrichments.reduce((ops, enrichment) => {
|
|
163
|
+
const operation = enrichmentOperations[enrichment];
|
|
164
|
+
// only include the enrichments that we know how to fetch
|
|
165
|
+
operation && ops.push(operation);
|
|
166
|
+
return ops;
|
|
167
|
+
}, []);
|
|
168
|
+
const pipeline = createOperationPipeline(operations);
|
|
169
|
+
// execute pipeline and return the item and enrichments
|
|
170
|
+
return pipeline({
|
|
171
|
+
data: { item },
|
|
172
|
+
stack: new OperationStack(),
|
|
173
|
+
requestOptions,
|
|
174
|
+
}).then((output) => output.data);
|
|
175
|
+
};
|
|
176
|
+
//# sourceMappingURL=_enrichments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_enrichments.js","sourceRoot":"","sources":["../../../src/items/_enrichments.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EACX,aAAa,EACb,OAAO,GACR,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,qBAAqB,EACrB,UAAU,GACX,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EAAa,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAC9D,OAAO,cAAc,MAAM,mBAAmB,CAAC;AAC/C,+CAA+C;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAoBxC,SAAS,gBAAgB,CAAC,WAAmB;IAC3C,MAAM,IAAI,GAAG;QACX,8CAA8C;QAC9C,gBAAgB,EAAE,KAAK;QACvB,mBAAmB,EAAE,IAAI;QACzB,YAAY,EAAE,QAAQ;KACvB,CAAC;IACF,OAAO,KAAK,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;AAClC,CAAC;AAED;;;;;GAKG;AACH,SAAS,oBAAoB,CAC3B,EAAU,EACV,cAAmC;IAEnC,OAAO,eAAe,CAAC,EAAE,EAAE,cAAc,CAAC;SACvC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC;SACpD,KAAK,CAAC,GAAG,EAAE;QACV,0DAA0D;QAC1D,uDAAuD;QACvD,sDAAsD;QACtD,2DAA2D;QAC3D,mEAAmE;QACnE,OAAO,IAAI,CAA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,kCAAO,IAAI,KAAE,MAAM,GAAE,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC;AAC9D,CAAC,CAAC;AAQF,MAAM,oBAAoB,GAA0B;IAClD,QAAQ,EAAE,cAAc;IACxB,QAAQ,EAAE,cAAc;IACxB,SAAS,EAAE,eAAe;IAC1B,YAAY;IACZ,IAAI,EAAE,UAAU;IAChB,MAAM,EAAE,YAAY;IACpB,MAAM,EAAE,YAAY;CACrB,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,IAAW,EACX,WAAqC,EACrC,cAAmC,EACnC,EAAE;IACF,6CAA6C;IAC7C,MAAM,UAAU,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,UAAU,EAAE,EAAE;QACxD,MAAM,SAAS,GAAG,oBAAoB,CAAC,UAAU,CAAC,CAAC;QACnD,yDAAyD;QACzD,SAAS,IAAI,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACjC,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,MAAM,QAAQ,GAAG,uBAAuB,CAAsB,UAAU,CAAC,CAAC;IAC1E,uDAAuD;IACvD,OAAO,QAAQ,CAAC;QACd,IAAI,EAAE,EAAE,IAAI,EAAE;QACd,KAAK,EAAE,IAAI,cAAc,EAAE;QAC3B,cAAc;KACf,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACnC,CAAC,CAAC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { __assign, __awaiter, __generator } from "tslib";
|
|
2
|
+
import { hubApiRequest } from "../request";
|
|
3
|
+
import { isMapOrFeatureServerUrl } from "../urls";
|
|
4
|
+
import { cloneObject } from "../util";
|
|
5
|
+
import { includes } from "../utils";
|
|
6
|
+
import { normalizeItemType } from "./compose";
|
|
7
|
+
import { getFamily } from "./get-family";
|
|
8
|
+
import { parseDatasetId } from "./slugs";
|
|
9
|
+
// TODO: need to fetch data for client-side layer views as well
|
|
10
|
+
// determine if we should fetch data for an item
|
|
11
|
+
var shouldFetchData = function (item) {
|
|
12
|
+
var type = normalizeItemType(item);
|
|
13
|
+
var family = getFamily(type);
|
|
14
|
+
var dataFamilies = ["template", "solution"];
|
|
15
|
+
var dataTypes = ["Web Map", "Web Scene"];
|
|
16
|
+
return includes(dataFamilies, family) || includes(dataTypes, type);
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* get the default list of enrichments to fetch for content
|
|
20
|
+
* @param item
|
|
21
|
+
* @returns the default list of enrichments to fetch for content
|
|
22
|
+
* @private
|
|
23
|
+
*/
|
|
24
|
+
export var getContentEnrichments = function (item) {
|
|
25
|
+
// we fetch these enrichments for all content types
|
|
26
|
+
var enrichments = [
|
|
27
|
+
"groupIds",
|
|
28
|
+
"metadata",
|
|
29
|
+
"ownerUser",
|
|
30
|
+
"org",
|
|
31
|
+
];
|
|
32
|
+
// we only fetch data for certain content
|
|
33
|
+
if (shouldFetchData(item)) {
|
|
34
|
+
enrichments.push("data");
|
|
35
|
+
}
|
|
36
|
+
// we fetch server and layers for map and feature services
|
|
37
|
+
return isMapOrFeatureServerUrl(item.url)
|
|
38
|
+
? enrichments.concat("server", "layers")
|
|
39
|
+
: enrichments;
|
|
40
|
+
};
|
|
41
|
+
// build up request options to only include the above enrichments
|
|
42
|
+
// that we fetch from the Hub API, and to optionally filter by slug
|
|
43
|
+
var getHubEnrichmentsOptions = function (requestOptions, slug) {
|
|
44
|
+
var opts = cloneObject(requestOptions);
|
|
45
|
+
opts.params = __assign(__assign({}, opts.params), { "fields[datasets]": "slug,boundary,extent,searchDescription,statistics" });
|
|
46
|
+
if (slug) {
|
|
47
|
+
opts.params["filter[slug]"] = slug;
|
|
48
|
+
}
|
|
49
|
+
return opts;
|
|
50
|
+
};
|
|
51
|
+
// extract the ids and enrichments from the Hub API response
|
|
52
|
+
var getDatasetEnrichments = function (dataset) {
|
|
53
|
+
var _a = parseDatasetId(dataset.id), itemId = _a.itemId, layerIdString = _a.layerId;
|
|
54
|
+
var layerId = layerIdString && parseInt(layerIdString, 10);
|
|
55
|
+
var _b = dataset.attributes, slug = _b.slug, boundary = _b.boundary, extent = _b.extent, searchDescription = _b.searchDescription, statistics = _b.statistics;
|
|
56
|
+
return {
|
|
57
|
+
itemId: itemId,
|
|
58
|
+
layerId: layerId,
|
|
59
|
+
slug: slug,
|
|
60
|
+
boundary: boundary,
|
|
61
|
+
extent: extent,
|
|
62
|
+
searchDescription: searchDescription,
|
|
63
|
+
statistics: statistics,
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* fetch enrichment from the Hub API by slug
|
|
68
|
+
* @param slug
|
|
69
|
+
* @param requestOptions
|
|
70
|
+
* @returns enrichments from the Hub API (slug, boundary, statistic, etc)
|
|
71
|
+
* @private
|
|
72
|
+
*/
|
|
73
|
+
export var fetchHubEnrichmentsBySlug = function (slug, requestOptions) { return __awaiter(void 0, void 0, void 0, function () {
|
|
74
|
+
var response;
|
|
75
|
+
return __generator(this, function (_a) {
|
|
76
|
+
switch (_a.label) {
|
|
77
|
+
case 0: return [4 /*yield*/, hubApiRequest("/datasets", getHubEnrichmentsOptions(requestOptions, slug))];
|
|
78
|
+
case 1:
|
|
79
|
+
response = _a.sent();
|
|
80
|
+
return [2 /*return*/, getDatasetEnrichments(response.data[0])];
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}); };
|
|
84
|
+
/**
|
|
85
|
+
* fetch enrichment from the Hub API by id
|
|
86
|
+
* @param slug
|
|
87
|
+
* @param requestOptions
|
|
88
|
+
* @returns enrichments from the Hub API (slug, boundary, statistic, etc)
|
|
89
|
+
* @private
|
|
90
|
+
*/
|
|
91
|
+
export var fetchHubEnrichmentsById = function (hubId, requestOptions) { return __awaiter(void 0, void 0, void 0, function () {
|
|
92
|
+
var response;
|
|
93
|
+
return __generator(this, function (_a) {
|
|
94
|
+
switch (_a.label) {
|
|
95
|
+
case 0: return [4 /*yield*/, hubApiRequest("/datasets/" + hubId, getHubEnrichmentsOptions(requestOptions))];
|
|
96
|
+
case 1:
|
|
97
|
+
response = _a.sent();
|
|
98
|
+
return [2 /*return*/, getDatasetEnrichments(response.data)];
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}); };
|
|
102
|
+
//# sourceMappingURL=_fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_fetch.js","sourceRoot":"","sources":["../../../src/content/_fetch.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAGzC,+DAA+D;AAC/D,gDAAgD;AAChD,IAAM,eAAe,GAAG,UAAC,IAAW;IAClC,IAAM,IAAI,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;IACrC,IAAM,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;IAC/B,IAAM,YAAY,GAAG,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAC9C,IAAM,SAAS,GAAG,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IAC3C,OAAO,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC,IAAI,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;AACrE,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,IAAM,qBAAqB,GAAG,UAAC,IAAW;IAC/C,mDAAmD;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