@esri/hub-common 12.29.0 → 12.30.1

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 (83) hide show
  1. package/dist/esm/core/behaviors/IWithMetricsBehavior.js +1 -0
  2. package/dist/esm/core/behaviors/IWithMetricsBehavior.js.map +1 -0
  3. package/dist/esm/core/traits/IWithMetrics.js +1 -0
  4. package/dist/esm/core/traits/IWithMetrics.js.map +1 -0
  5. package/dist/esm/core/types/IHubProject.js.map +1 -1
  6. package/dist/esm/core/types/IReference.js +5 -0
  7. package/dist/esm/core/types/IReference.js.map +1 -0
  8. package/dist/esm/core/types/Metrics.js +1 -0
  9. package/dist/esm/core/types/Metrics.js.map +1 -0
  10. package/dist/esm/core/types/index.js +2 -0
  11. package/dist/esm/core/types/index.js.map +1 -1
  12. package/dist/esm/index.js +1 -0
  13. package/dist/esm/index.js.map +1 -1
  14. package/dist/esm/initiatives/HubInitiative.js +18 -0
  15. package/dist/esm/initiatives/HubInitiative.js.map +1 -1
  16. package/dist/esm/initiatives/_internal/getPropertyMap.js +1 -0
  17. package/dist/esm/initiatives/_internal/getPropertyMap.js.map +1 -1
  18. package/dist/esm/metrics/aggregateMetrics.js +43 -0
  19. package/dist/esm/metrics/aggregateMetrics.js.map +1 -0
  20. package/dist/esm/metrics/getEntityMetrics.js +38 -0
  21. package/dist/esm/metrics/getEntityMetrics.js.map +1 -0
  22. package/dist/esm/metrics/index.js +4 -0
  23. package/dist/esm/metrics/index.js.map +1 -0
  24. package/dist/esm/metrics/resolveMetric.js +167 -0
  25. package/dist/esm/metrics/resolveMetric.js.map +1 -0
  26. package/dist/esm/projects/HubProject.js +18 -0
  27. package/dist/esm/projects/HubProject.js.map +1 -1
  28. package/dist/esm/projects/_internal/getPropertyMap.js +1 -0
  29. package/dist/esm/projects/_internal/getPropertyMap.js.map +1 -1
  30. package/dist/esm/utils/memoize.js +14 -4
  31. package/dist/esm/utils/memoize.js.map +1 -1
  32. package/dist/esm/versioning/updateVersionMetadata.js +1 -1
  33. package/dist/esm/versioning/updateVersionMetadata.js.map +1 -1
  34. package/dist/node/core/behaviors/IWithMetricsBehavior.js +3 -0
  35. package/dist/node/core/behaviors/IWithMetricsBehavior.js.map +1 -0
  36. package/dist/node/core/traits/IWithMetrics.js +3 -0
  37. package/dist/node/core/traits/IWithMetrics.js.map +1 -0
  38. package/dist/node/core/types/IHubProject.js.map +1 -1
  39. package/dist/node/core/types/IReference.js +7 -0
  40. package/dist/node/core/types/IReference.js.map +1 -0
  41. package/dist/node/core/types/Metrics.js +3 -0
  42. package/dist/node/core/types/Metrics.js.map +1 -0
  43. package/dist/node/core/types/index.js +2 -0
  44. package/dist/node/core/types/index.js.map +1 -1
  45. package/dist/node/index.js +1 -0
  46. package/dist/node/index.js.map +1 -1
  47. package/dist/node/initiatives/HubInitiative.js +18 -0
  48. package/dist/node/initiatives/HubInitiative.js.map +1 -1
  49. package/dist/node/initiatives/_internal/getPropertyMap.js +1 -0
  50. package/dist/node/initiatives/_internal/getPropertyMap.js.map +1 -1
  51. package/dist/node/metrics/aggregateMetrics.js +47 -0
  52. package/dist/node/metrics/aggregateMetrics.js.map +1 -0
  53. package/dist/node/metrics/getEntityMetrics.js +42 -0
  54. package/dist/node/metrics/getEntityMetrics.js.map +1 -0
  55. package/dist/node/metrics/index.js +7 -0
  56. package/dist/node/metrics/index.js.map +1 -0
  57. package/dist/node/metrics/resolveMetric.js +171 -0
  58. package/dist/node/metrics/resolveMetric.js.map +1 -0
  59. package/dist/node/projects/HubProject.js +18 -0
  60. package/dist/node/projects/HubProject.js.map +1 -1
  61. package/dist/node/projects/_internal/getPropertyMap.js +1 -0
  62. package/dist/node/projects/_internal/getPropertyMap.js.map +1 -1
  63. package/dist/node/utils/memoize.js +14 -4
  64. package/dist/node/utils/memoize.js.map +1 -1
  65. package/dist/node/versioning/updateVersionMetadata.js +1 -1
  66. package/dist/node/versioning/updateVersionMetadata.js.map +1 -1
  67. package/dist/types/core/behaviors/IWithMetricsBehavior.d.ts +10 -0
  68. package/dist/types/core/traits/IWithMetrics.d.ts +10 -0
  69. package/dist/types/core/types/DynamicValues.d.ts +1 -7
  70. package/dist/types/core/types/IHubInitiative.d.ts +2 -1
  71. package/dist/types/core/types/IHubProject.d.ts +2 -1
  72. package/dist/types/core/types/IReference.d.ts +7 -0
  73. package/dist/types/core/types/Metrics.d.ts +159 -0
  74. package/dist/types/core/types/index.d.ts +2 -0
  75. package/dist/types/index.d.ts +1 -0
  76. package/dist/types/initiatives/HubInitiative.d.ts +9 -2
  77. package/dist/types/metrics/aggregateMetrics.d.ts +10 -0
  78. package/dist/types/metrics/getEntityMetrics.d.ts +10 -0
  79. package/dist/types/metrics/index.d.ts +3 -0
  80. package/dist/types/metrics/resolveMetric.d.ts +11 -0
  81. package/dist/types/projects/HubProject.d.ts +9 -2
  82. package/dist/types/utils/memoize.d.ts +3 -1
  83. package/package.json +1 -1
@@ -0,0 +1,159 @@
1
+ /// <reference types="arcgis-js-api" />
2
+ import { IQuery } from "../../search/types/IHubCatalog";
3
+ import { ServiceAggregation } from "./DynamicValues";
4
+ import { IReference } from "./IReference";
5
+ /**
6
+ * Defines the information required from a Metric
7
+ */
8
+ export interface IMetric {
9
+ /**
10
+ * Identifier for the metric. This must be static over time or linkages
11
+ * between items will break. Can be the camelCase version of the name
12
+ * as long as it's a valid Javascript property name (can't start with numbers).
13
+ */
14
+ id: string;
15
+ /**
16
+ * Name of the metric. Will be shown in UI's
17
+ */
18
+ name?: string;
19
+ /**
20
+ * Description of the metric. Will be shown in UI when user is configuring
21
+ * the value or source of the value
22
+ */
23
+ description?: string;
24
+ /**
25
+ * Unit of the value. In the future this will be a list of well-known units
26
+ */
27
+ units?: string;
28
+ /**
29
+ * Source definition. This can be an `IReference` to another metric to enable
30
+ * re-use of the same metric source for multiple metrics.
31
+ */
32
+ source: MetricSource | IReference;
33
+ /**
34
+ * Information about the source entity that will be attached to the `IMetricFeature` when it's resolved.
35
+ * This will be added to the `IMetric` as it's processed.
36
+ */
37
+ entityInfo?: IEntityInfo;
38
+ }
39
+ /**
40
+ * Basic information about the source of the metric, that will be added to the `IMetricFeature` when it's resolved
41
+ */
42
+ export interface IEntityInfo {
43
+ /**
44
+ * The id of the entity from which the Metric was computed
45
+ */
46
+ id: string;
47
+ /**
48
+ * Name of the entity from which the value was computed
49
+ */
50
+ name: string;
51
+ /**
52
+ * The type of entity from which the value was computed
53
+ */
54
+ type: string;
55
+ }
56
+ /**
57
+ * Defines a query to a service
58
+ */
59
+ export interface IServiceQuery {
60
+ /**
61
+ * Feature Service Url
62
+ */
63
+ serviceUrl: string;
64
+ /**
65
+ * Layer Id
66
+ */
67
+ layerId: number;
68
+ /**
69
+ * Field to run stats on
70
+ */
71
+ field: string;
72
+ /**
73
+ * Statistic to run on the field
74
+ */
75
+ statistic: ServiceAggregation;
76
+ /**
77
+ * Optional where clause to filter the query
78
+ */
79
+ where?: string;
80
+ /**
81
+ * NOT IMPLEMENTED: Optional set of fields to group by.
82
+ */
83
+ groupBy?: {
84
+ fields: string[];
85
+ having: string;
86
+ };
87
+ /**
88
+ * NOT IMPLEMENTED: Optional set of fields to order by.
89
+ */
90
+ orderBy?: string[];
91
+ /**
92
+ * NOT IMPLEMENTED: Time instant to query
93
+ */
94
+ time?: number;
95
+ /**
96
+ * NOT IMPLEMENTED: Time range to query
97
+ */
98
+ timeRange?: [null | number, null | number];
99
+ }
100
+ /**
101
+ * Union type of all the valid metric sources.
102
+ * To add additional sources, add them to this union type
103
+ */
104
+ export declare type MetricSource = IStaticValueMetricSource | IServiceQueryMetricSource | IItemQueryMetricSource;
105
+ /**
106
+ * Defines a metric source that is a static value
107
+ */
108
+ export interface IStaticValueMetricSource {
109
+ type: "static-value";
110
+ /**
111
+ * Static value to use
112
+ */
113
+ value: string | number;
114
+ }
115
+ /**
116
+ * Defines a metric source that is a query to a service.
117
+ */
118
+ export interface IServiceQueryMetricSource extends IServiceQuery {
119
+ type: "service-query";
120
+ }
121
+ /**
122
+ * Defines a metric source that fetches values from a set of items.
123
+ */
124
+ export interface IItemQueryMetricSource {
125
+ type: "item-query";
126
+ /**
127
+ * Property path to get the value from the item
128
+ * e.g. `properties.numComments` or `properties.metrics[findBy(id,'funding_00c')].source`
129
+ */
130
+ propertyPath: string;
131
+ /**
132
+ * Keywords used in the query to search for items
133
+ */
134
+ keywords: string[];
135
+ /**
136
+ * Item types to limit the search
137
+ */
138
+ itemTypes?: string[];
139
+ /**
140
+ * Key of the collection to further limit the search
141
+ * This is resolved into an `IQuery` in the pre-processing step.
142
+ * If not defined, only the keyword and item types are used.
143
+ */
144
+ collectionKey?: string;
145
+ /**
146
+ * Scope query. This will be pulled from the collection if `collectionKey` is defined.
147
+ */
148
+ scope?: IQuery;
149
+ }
150
+ export interface IMetricAttributes extends IEntityInfo {
151
+ [key: string]: number | string | null;
152
+ }
153
+ /**
154
+ * Output of a metric, which merges the source info (id, label, type) with the value
155
+ */
156
+ export interface IMetricFeature {
157
+ attributes: IMetricAttributes;
158
+ geometry?: __esri.Geometry;
159
+ }
@@ -21,3 +21,5 @@ export * from "./IServerEnrichments";
21
21
  export * from "./ISystemStatus";
22
22
  export * from "./types";
23
23
  export * from "./DynamicValues";
24
+ export * from "./IReference";
25
+ export * from "./Metrics";
@@ -31,6 +31,7 @@ export * from "./users";
31
31
  export * from "./util";
32
32
  export * from "./utils";
33
33
  export * from "./versioning";
34
+ export * from "./metrics";
34
35
  export * from "./core/updateHubEntity";
35
36
  import OperationStack from "./OperationStack";
36
37
  import OperationError from "./OperationError";
@@ -1,12 +1,13 @@
1
- import { IHubInitiative, IWithCatalogBehavior, IWithStoreBehavior, IWithSharingBehavior, UiSchemaElementOptions, IEditorConfig } from "../core";
1
+ import { IHubInitiative, IWithCatalogBehavior, IWithStoreBehavior, IWithSharingBehavior, UiSchemaElementOptions, IEditorConfig, IMetricFeature } from "../core";
2
2
  import { Catalog } from "../search";
3
3
  import { IArcGISContext } from "../ArcGISContext";
4
4
  import { HubItemEntity } from "../core/HubItemEntity";
5
5
  import { InitiativeEditorType } from "./_internal/InitiativeSchema";
6
+ import { IWithMetricsBehavior } from "../core/behaviors/IWithMetricsBehavior";
6
7
  /**
7
8
  * Hub Initiative Class
8
9
  */
9
- export declare class HubInitiative extends HubItemEntity<IHubInitiative> implements IWithStoreBehavior<IHubInitiative>, IWithCatalogBehavior, IWithSharingBehavior {
10
+ export declare class HubInitiative extends HubItemEntity<IHubInitiative> implements IWithStoreBehavior<IHubInitiative>, IWithCatalogBehavior, IWithMetricsBehavior, IWithSharingBehavior {
10
11
  private _catalog;
11
12
  /**
12
13
  * Private constructor so we don't have `new` all over the place. Allows for
@@ -70,4 +71,10 @@ export declare class HubInitiative extends HubItemEntity<IHubInitiative> impleme
70
71
  * @returns
71
72
  */
72
73
  delete(): Promise<void>;
74
+ /**
75
+ * Resolve a single metric for this metric
76
+ * @param metricId
77
+ * @returns
78
+ */
79
+ resolveMetric(metricId: string): Promise<IMetricFeature[]>;
73
80
  }
@@ -0,0 +1,10 @@
1
+ import { IMetricFeature } from "../core";
2
+ import { DynamicAggregation } from "../core/types/DynamicValues";
3
+ /**
4
+ * Given an array of metrics, aggregate them using the specified aggregation
5
+ * Consumer must be aware of the type of the metrics and pass an appropriate aggregation
6
+ * @param metrics
7
+ * @param aggregation
8
+ * @returns
9
+ */
10
+ export declare function aggregateMetrics(metrics: IMetricFeature[], field: string, aggregation: DynamicAggregation): any;
@@ -0,0 +1,10 @@
1
+ import { IHubInitiative } from "../core/types/IHubInitiative";
2
+ import { IHubProject } from "../core/types/IHubProject";
3
+ import { IMetric } from "../core/types/Metrics";
4
+ /**
5
+ * Get the metrics from an entity applying some pre-processing
6
+ * and adding source info.
7
+ * @param entity
8
+ * @returns
9
+ */
10
+ export declare function getEntityMetrics(entity: IHubProject | IHubInitiative): IMetric[];
@@ -0,0 +1,3 @@
1
+ export * from "./getEntityMetrics";
2
+ export * from "./resolveMetric";
3
+ export * from "./aggregateMetrics";
@@ -0,0 +1,11 @@
1
+ import { IArcGISContext } from "../ArcGISContext";
2
+ import { IMetric, IMetricFeature } from "../core/types/Metrics";
3
+ /**
4
+ * Resolve a Metric into an array of `IMetricFeature` objects.
5
+ * This implementation is similar to DynamicValues, but is just different
6
+ * enough to warrant a separate implementation.
7
+ * @param metric
8
+ * @param context
9
+ * @returns
10
+ */
11
+ export declare function resolveMetric(metric: IMetric, context: IArcGISContext): Promise<IMetricFeature[]>;
@@ -1,13 +1,14 @@
1
- import { IHubProject, IWithCatalogBehavior, IWithStoreBehavior, IWithSharingBehavior, UiSchemaElementOptions } from "../core";
1
+ import { IHubProject, IWithCatalogBehavior, IWithStoreBehavior, IWithSharingBehavior, UiSchemaElementOptions, IMetricFeature } from "../core";
2
2
  import { Catalog } from "../search";
3
3
  import { IArcGISContext } from "../ArcGISContext";
4
4
  import { HubItemEntity } from "../core/HubItemEntity";
5
5
  import { IEditorConfig } from "../core/behaviors/IWithEditorBehavior";
6
6
  import { ProjectEditorType } from "./_internal/ProjectSchema";
7
+ import { IWithMetricsBehavior } from "../core/behaviors/IWithMetricsBehavior";
7
8
  /**
8
9
  * Hub Project Class
9
10
  */
10
- export declare class HubProject extends HubItemEntity<IHubProject> implements IWithStoreBehavior<IHubProject>, IWithCatalogBehavior, IWithSharingBehavior {
11
+ export declare class HubProject extends HubItemEntity<IHubProject> implements IWithStoreBehavior<IHubProject>, IWithCatalogBehavior, IWithMetricsBehavior, IWithSharingBehavior {
11
12
  private _catalog;
12
13
  /**
13
14
  * Private constructor so we don't have `new` all over the place. Allows for
@@ -70,4 +71,10 @@ export declare class HubProject extends HubItemEntity<IHubProject> implements IW
70
71
  * @returns
71
72
  */
72
73
  delete(): Promise<void>;
74
+ /**
75
+ * Resolve a single metric for this metric
76
+ * @param metricId
77
+ * @returns
78
+ */
79
+ resolveMetric(metricId: string): Promise<IMetricFeature[]>;
73
80
  }
@@ -8,6 +8,8 @@
8
8
  export declare const memoize: <ARGS extends unknown[], RET>(fn: (...args: ARGS) => RET) => any;
9
9
  /**
10
10
  * Clear the cache of a memoized function
11
+ * If no function name is provided, the entire cache is cleared
12
+ * This is useful for testing, but should not be used in production
11
13
  * @param fn
12
14
  */
13
- export declare const clearMemoizedCache: (fnName: string) => void;
15
+ export declare const clearMemoizedCache: (fnName?: string) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@esri/hub-common",
3
- "version": "12.29.0",
3
+ "version": "12.30.1",
4
4
  "description": "Common TypeScript types and utility functions for @esri/hub.js.",
5
5
  "main": "dist/node/index.js",
6
6
  "module": "dist/esm/index.js",