@esri/hub-common 9.1.3 → 9.4.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.
Files changed (47) hide show
  1. package/dist/es2017/content.js +127 -19
  2. package/dist/es2017/content.js.map +1 -1
  3. package/dist/es2017/search/_searchContent.js +62 -0
  4. package/dist/es2017/search/_searchContent.js.map +1 -0
  5. package/dist/es2017/search/content-utils.js +422 -0
  6. package/dist/es2017/search/content-utils.js.map +1 -0
  7. package/dist/es2017/search/index.js +4 -0
  8. package/dist/es2017/search/index.js.map +1 -1
  9. package/dist/es2017/search/types.js +1 -0
  10. package/dist/es2017/search/types.js.map +1 -0
  11. package/dist/es2017/search/utils.js +344 -0
  12. package/dist/es2017/search/utils.js.map +1 -0
  13. package/dist/esm/content.js +129 -19
  14. package/dist/esm/content.js.map +1 -1
  15. package/dist/esm/search/_searchContent.js +70 -0
  16. package/dist/esm/search/_searchContent.js.map +1 -0
  17. package/dist/esm/search/content-utils.js +426 -0
  18. package/dist/esm/search/content-utils.js.map +1 -0
  19. package/dist/esm/search/index.js +4 -0
  20. package/dist/esm/search/index.js.map +1 -1
  21. package/dist/esm/search/types.js +1 -0
  22. package/dist/esm/search/types.js.map +1 -0
  23. package/dist/esm/search/utils.js +341 -0
  24. package/dist/esm/search/utils.js.map +1 -0
  25. package/dist/node/content.js +128 -20
  26. package/dist/node/content.js.map +1 -1
  27. package/dist/node/search/_searchContent.js +66 -0
  28. package/dist/node/search/_searchContent.js.map +1 -0
  29. package/dist/node/search/content-utils.js +432 -0
  30. package/dist/node/search/content-utils.js.map +1 -0
  31. package/dist/node/search/index.js +4 -0
  32. package/dist/node/search/index.js.map +1 -1
  33. package/dist/node/search/types.js +3 -0
  34. package/dist/node/search/types.js.map +1 -0
  35. package/dist/node/search/utils.js +357 -0
  36. package/dist/node/search/utils.js.map +1 -0
  37. package/dist/types/content.d.ts +23 -0
  38. package/dist/types/search/_searchContent.d.ts +7 -0
  39. package/dist/types/search/content-utils.d.ts +70 -0
  40. package/dist/types/search/index.d.ts +4 -0
  41. package/dist/types/search/types.d.ts +294 -0
  42. package/dist/types/search/utils.d.ts +92 -0
  43. package/dist/umd/common.umd.js +992 -25
  44. package/dist/umd/common.umd.js.map +1 -1
  45. package/dist/umd/common.umd.min.js +1 -1
  46. package/dist/umd/common.umd.min.js.map +1 -1
  47. package/package.json +3 -3
@@ -0,0 +1,294 @@
1
+ import { UserSession } from "@esri/arcgis-rest-auth";
2
+ import { IHubContent } from "..";
3
+ /**
4
+ * Generic filter used with various search functions.
5
+ *
6
+ * `Filter<T extends FilterType>` [FilterType](../FilterType) is constrained to
7
+ *
8
+ * - `Filter<"any">` [IAnyFilterDefinition](../IAnyFilterDefinition)
9
+ * - `Filter<"content">` [IContentFilterDefinition](../IContentFilterDefinition)
10
+ * - `Filter<"user">` [IUserFilterDefinition](../IUserFilterDefinition)
11
+ * - `Filter<"group">` [IGroupFilterDefinition](../IGroupFilterDefinition)
12
+ *
13
+ * When constructing a Filter as json, the `filterType` must be specified,
14
+ * and it must be `keyof` [FilterTypeMap](../FilterTypeMap)
15
+ *
16
+ * ```ts
17
+ * const f:Filter<"content"> = {
18
+ * filterType: "content" // must match the FilterType
19
+ * term: "water"
20
+ * }
21
+ * ```
22
+ */
23
+ export declare type Filter<T extends FilterType> = IFilterTypeMap[T] & {
24
+ filterType: T;
25
+ };
26
+ /**
27
+ * Defines the valid FilterTypes for use with `Filter<T extends FilterType>`
28
+ * See [Filter](../Filter)
29
+ */
30
+ export interface IFilterTypeMap {
31
+ any: IAnyFilterDefinition;
32
+ content: IContentFilterDefinition;
33
+ user: IUserFilterDefinition;
34
+ group: IGroupFilterDefinition;
35
+ event: IEventFilterDefinition;
36
+ }
37
+ export declare type FilterType = keyof IFilterTypeMap;
38
+ /**
39
+ * Common set of fields that are reasonable to apply at the
40
+ * top level of a Catalog
41
+ */
42
+ export interface IAnyFilterDefinition {
43
+ title?: string | string[] | IMatchOptions;
44
+ access?: string | string[] | IMatchOptions;
45
+ owner?: string | string[] | IMatchOptions;
46
+ tags?: string | string[] | IMatchOptions;
47
+ created?: IDateRange<number> | IRelativeDate;
48
+ modified?: IDateRange<number> | IRelativeDate;
49
+ description?: string | string[] | IMatchOptions;
50
+ group?: string | string[] | IMatchOptions;
51
+ orgid?: string | string[] | IMatchOptions;
52
+ type?: string | NamedContentFilter | Array<string | NamedContentFilter> | IMatchOptions;
53
+ }
54
+ /**
55
+ * Fields related to Content based searches
56
+ */
57
+ export interface IContentFilterDefinition {
58
+ access?: string | string[] | IMatchOptions;
59
+ owner?: string | string[] | IMatchOptions;
60
+ tags?: string | string[] | IMatchOptions;
61
+ created?: IDateRange<number> | IRelativeDate;
62
+ description?: string | string[] | IMatchOptions;
63
+ snippet?: string | string[] | IMatchOptions;
64
+ group?: string | string[] | IMatchOptions;
65
+ id?: string | string[] | IMatchOptions;
66
+ modified?: IDateRange<number> | IRelativeDate;
67
+ orgid?: string | string[] | IMatchOptions;
68
+ term?: string;
69
+ title?: string | string[] | IMatchOptions;
70
+ type?: string | NamedContentFilter | Array<string | NamedContentFilter> | IMatchOptions;
71
+ typekeywords?: string | string[] | IMatchOptions;
72
+ [key: string]: any;
73
+ /**
74
+ * @internal
75
+ * Support for complex OR queries; Used with various expansions
76
+ */
77
+ subFilters?: Array<IContentFilterDefinition | NamedContentFilter>;
78
+ }
79
+ export interface IContentFilter {
80
+ access?: IMatchOptions;
81
+ created?: IDateRange<number>;
82
+ description?: IMatchOptions;
83
+ group?: IMatchOptions;
84
+ id?: IMatchOptions;
85
+ modified?: IDateRange<number>;
86
+ orgid?: IMatchOptions;
87
+ owner?: IMatchOptions;
88
+ tags?: IMatchOptions;
89
+ term?: string;
90
+ title?: IMatchOptions;
91
+ type?: IMatchOptions;
92
+ typekeywords?: IMatchOptions;
93
+ [key: string]: any;
94
+ subFilters?: IContentFilter[];
95
+ }
96
+ export interface IWellKnownContentFilters {
97
+ $apps: IContentFilterDefinition[];
98
+ $dashboard: IContentFilterDefinition[];
99
+ $dataset: IContentFilterDefinition[];
100
+ $experience: IContentFilterDefinition[];
101
+ $site: IContentFilterDefinition[];
102
+ $storymap: IContentFilterDefinition[];
103
+ $initiative: IContentFilterDefinition[];
104
+ $document: IContentFilterDefinition[];
105
+ }
106
+ export declare type NamedContentFilter = keyof IWellKnownContentFilters;
107
+ export interface IUserFilterDefinition {
108
+ disabled?: boolean;
109
+ email?: string | string[] | IMatchOptions;
110
+ firstname?: string | string[] | IMatchOptions;
111
+ fullname?: string | string[] | IMatchOptions;
112
+ groups?: string | string[] | IMatchOptions;
113
+ lastname?: string | string[] | IMatchOptions;
114
+ username?: string | string[] | IMatchOptions;
115
+ }
116
+ export interface IGroupFilterDefinition {
117
+ access?: string | string[] | IMatchOptions;
118
+ created?: IDateRange<number> | IRelativeDate;
119
+ id?: string | string[] | IMatchOptions;
120
+ isInvitationOnly: boolean;
121
+ modified?: IDateRange<number> | IRelativeDate;
122
+ orgid?: string | string[] | IMatchOptions;
123
+ searchUserAccess?: "groupMember" | "admin";
124
+ tags?: string | string[] | IMatchOptions;
125
+ title?: string | string[] | IMatchOptions;
126
+ typekeywords?: string | string[] | IMatchOptions;
127
+ }
128
+ export interface IEventFilterDefinition {
129
+ created?: IDateRange<number> | IRelativeDate;
130
+ modified?: IDateRange<number> | IRelativeDate;
131
+ orgid?: string | string[] | IMatchOptions;
132
+ title?: string | string[] | IMatchOptions;
133
+ }
134
+ export interface IFacet {
135
+ label: string;
136
+ attribute?: string;
137
+ type: "single-select" | "multi-select" | "date-range" | "histogram";
138
+ options?: IFacetOption[];
139
+ }
140
+ export interface IFacetOption {
141
+ label: string;
142
+ value: string;
143
+ count?: number;
144
+ selected: boolean;
145
+ filter: Filter<FilterType>;
146
+ }
147
+ /**
148
+ * Catalog is the definition which powers what options
149
+ * are available in a Gallery. It controls not only
150
+ * the scoping of the search, but also the options
151
+ * available to the UX.
152
+ *
153
+ * Thus the lower-level `searchContent`, `searchUser`, `searchGroup` functions
154
+ * do not take Catalogs, rather they accept [Filters](../Filter)
155
+ *
156
+ * ```ts
157
+ * const simpleCatalog:Catalog = {
158
+ * title: "Select Map",
159
+ * filter: {
160
+ * filterType: "content",
161
+ * type: "Web Map",
162
+ * owner: "jsmith"
163
+ * }
164
+ * }
165
+ * ```
166
+ *
167
+ * ## Collections
168
+ * The key feature of a Catalog is the ability to defined [Collections](../Collection).
169
+ * These are essentially sub-sets of content, typically organized around
170
+ * generalized content types, i.e. "Datasets", vs "Maps", vs "Documents"
171
+ *
172
+ *
173
+ * ```ts
174
+ * const complex:Catalog = {
175
+ * filter: {
176
+ * type: "content",
177
+ * groups: ["3ef", "bc4"]
178
+ * },
179
+ * collections: [
180
+ * {
181
+ * label: "Documents",
182
+ * filter: {
183
+ * filterType: "content",
184
+ * type: ["Microsoft Word", "PDF", "Microsoft Excel"]
185
+ * }
186
+ * },
187
+ * {
188
+ * label: "Datasets",
189
+ * filter: {
190
+ * filterType: "content",
191
+ * type: ["Feature Layer", "Feature Service", "Map Service", "CSV"]
192
+ * }
193
+ * }
194
+ * ]
195
+ * }
196
+ * ```
197
+ */
198
+ export interface ICatalog {
199
+ /**
200
+ * Title for the Gallery
201
+ */
202
+ title?: string;
203
+ filter: Filter<FilterType>;
204
+ sort?: ISortOption[];
205
+ collections?: ICollection[];
206
+ facets?: IFacet[];
207
+ }
208
+ export interface ISortOption {
209
+ label: string;
210
+ attribute: string;
211
+ }
212
+ /**
213
+ * A Filter that defines a subset of a Catalog, aka a Collection
214
+ */
215
+ export interface ICollection {
216
+ label: string;
217
+ filter: Filter<FilterType>;
218
+ facets?: IFacet[];
219
+ }
220
+ export interface IDateRange<T> {
221
+ type?: "date-range";
222
+ from: T;
223
+ to: T;
224
+ }
225
+ export interface IRelativeDate {
226
+ type: "relative-date";
227
+ num: number;
228
+ unit: "minutes" | "hours" | "days" | "weeks" | "months" | "years";
229
+ }
230
+ /**
231
+ * Define how values should be matched
232
+ */
233
+ export interface IMatchOptions {
234
+ /**
235
+ * return results which have ANY of the listed values
236
+ * for the specified field
237
+ */
238
+ any?: string | string[];
239
+ /**
240
+ * return resutls which have ALL of the listed values
241
+ * for the specified field
242
+ */
243
+ all?: string | string[];
244
+ /**
245
+ * return results which do not have any of the listed
246
+ * values for the specified field
247
+ */
248
+ not?: string | string[];
249
+ /**
250
+ * Depending on the API being searched, `exact` will
251
+ * attempt to structure the query such that it is an
252
+ * exact match. For Portal API, this may involve using
253
+ * the `filter` parameter, if the specific field can
254
+ * be used with that parameter
255
+ */
256
+ exact?: string | string[];
257
+ }
258
+ /**
259
+ * Search Options
260
+ */
261
+ export interface IHubSearchOptions {
262
+ site?: string;
263
+ authentication?: UserSession;
264
+ sortField?: string;
265
+ sortOrder?: "desc" | "asc";
266
+ page?: string;
267
+ num?: number;
268
+ aggregations?: string[];
269
+ bbox?: string;
270
+ fields?: string;
271
+ apis?: Array<NamedApis | IApiDefinition>;
272
+ }
273
+ /**
274
+ * searchContent return
275
+ */
276
+ export interface IContentSearchResult {
277
+ content: IHubContent[];
278
+ facets?: IFacet[];
279
+ }
280
+ export interface IWellKnownApis {
281
+ arcgis: IApiDefinition;
282
+ arcgisQA: IApiDefinition;
283
+ arcgisDEV: IApiDefinition;
284
+ hub: IApiDefinition;
285
+ hubQA: IApiDefinition;
286
+ hubDEV: IApiDefinition;
287
+ }
288
+ export declare type NamedApis = keyof IWellKnownApis;
289
+ export interface IApiDefinition {
290
+ label?: string;
291
+ url: string;
292
+ type: "arcgis" | "arcgis-hub";
293
+ authentication?: UserSession;
294
+ }
@@ -0,0 +1,92 @@
1
+ import { ISearchOptions } from "@esri/arcgis-rest-portal";
2
+ import { IMatchOptions, IDateRange, IRelativeDate, IWellKnownApis, IApiDefinition, NamedApis, IContentSearchResult } from "./types";
3
+ /**
4
+ * Well known APIs
5
+ * Short-forms for specifying common APIs
6
+ */
7
+ export declare const SEARCH_APIS: IWellKnownApis;
8
+ /**
9
+ * @private
10
+ * Convert api "names" into full ApiDefinitions
11
+ * @param apis
12
+ * @returns
13
+ */
14
+ export declare function expandApis(apis: Array<NamedApis | IApiDefinition>): IApiDefinition[];
15
+ /**
16
+ * @private
17
+ * Merge multiple search responses
18
+ *
19
+ * Naieve implementation that just merges arrays
20
+ * @param responses
21
+ * @returns
22
+ */
23
+ export declare function mergeSearchResults(responses: IContentSearchResult[]): IContentSearchResult;
24
+ /**
25
+ * @private
26
+ * Merge two date ranges by taking the longest span
27
+ * @param dr1
28
+ * @param dr2
29
+ * @returns
30
+ */
31
+ export declare function mergeDateRange(dr1: IDateRange<number>, dr2: IDateRange<number>): IDateRange<number>;
32
+ /**
33
+ * @private
34
+ * Merge two [`MatchOptions`](../MatchOptions)
35
+ *
36
+ * Currently a naieve implementation where the arrays are simply merged
37
+ *
38
+ * @param mo1
39
+ * @param mo2
40
+ * @returns
41
+ */
42
+ export declare function mergeMatchOptions(mo1: IMatchOptions, mo2: IMatchOptions): IMatchOptions;
43
+ /**
44
+ * @private
45
+ * Convert a field value into a MatchOptions if it's not already one
46
+ * @param value
47
+ * @returns
48
+ */
49
+ export declare function valueToMatchOptions(value: string | string[] | IMatchOptions): IMatchOptions;
50
+ /**
51
+ * @private
52
+ * Convert a RelativeDate to a DateRange<number>
53
+ * @param relative
54
+ * @returns
55
+ */
56
+ export declare function relativeDateToDateRange(relative: IRelativeDate): IDateRange<number>;
57
+ /**
58
+ * @private
59
+ * As a final `ISearchOptions` object gets created, many such objects are created, and
60
+ * need to be systematically "merged" so as to return consistently structured `q` and `filter`
61
+ * values.
62
+ * @param so1
63
+ * @param so2
64
+ * @param join
65
+ * @returns
66
+ */
67
+ export declare function mergeSearchOptions(so1: ISearchOptions, so2: ISearchOptions, join: "AND" | "OR"): ISearchOptions;
68
+ /**
69
+ * @private
70
+ * Serialize a `MatchOptions` into `q` or `filter` on an `ISearchOptions`
71
+ * @param key
72
+ * @param opts
73
+ * @returns
74
+ */
75
+ export declare function serializeMatchOptions(key: string, opts: IMatchOptions): ISearchOptions;
76
+ /**
77
+ * @private
78
+ * Serialize a DateRange<number> into a Portal Query string
79
+ * @param key
80
+ * @param range
81
+ * @returns
82
+ */
83
+ export declare function serializeDateRange(key: string, range: IDateRange<number>): ISearchOptions;
84
+ /**
85
+ * @private
86
+ * Serialize a `string` or `string[]` into a string
87
+ * @param join
88
+ * @param key
89
+ * @param value
90
+ * @returns
91
+ */
92
+ export declare function serializeStringOrArray(join: "AND" | "OR", key: string, value: string | string[]): string;