/
DynamicValues.ts
169 lines (154 loc) · 4.25 KB
/
DynamicValues.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import { IQuery } from "../../search/types/IHubCatalog";
import { IConfigurationSchema } from "../schemas";
import { IReference } from "./IReference";
/**
* The source for a dynamic value. Used to determine how to resolve the value
*/
export type DynamicValueType =
| "static-value"
| "item-query"
| "service-query"
| "portal";
/**
* Options used to defined a feature service query
*/
export interface IServiceQueryOptions {
/**
* The url of the feature service, including the layer
*/
url: string;
/**
* Field on which to run an aggregation
*/
field: string;
/**
* The type of server-side aggregation to run
*/
statisticType: ServiceAggregation;
/**
* Where clause to apply to the query. Defaults to "1=1" if not provided
*/
where?: string;
}
/**
* Aggregations that can be done on a service
*/
export type ServiceAggregation = "count" | "sum" | "min" | "max" | "avg";
/**
* Aggregations that can be applied to a set of dynamic values
*/
export type DynamicAggregation = ServiceAggregation | "countByValue";
/**
* Properties shared by all DynamicValueDefinitions
*/
interface IBaseValueDefinition {
type: DynamicValueType;
/**
* The property path used to connect the resolved value to the parent object
*/
outPath: string;
/**
* JSON schema used to validate the value. If not provided, the value will not be validated
* NOTE: This may be swapped for a smaller set of props that would be used to generate the schema
*/
schema?: Partial<IConfigurationSchema>;
}
/**
* Definition for a static value that is not resolved via a query.
* Enables workflows where the dynamic value source is not yet configured, or the value is known ahead of time
*/
export interface IStaticValueDefinition extends IBaseValueDefinition {
type: "static-value";
/**
* Enables a static value to be provided vs forcing a dynamic value
*/
value: string | number;
}
/**
* Definition for a dynamic value that is resolved from the portal/self
*/
export interface IDynamicPortalSelfDefinition extends IBaseValueDefinition {
type: "portal";
/**
* The path to the property on the portal/self response to return
*/
sourcePath: string;
}
/**
* Definition for a dynamic value that is resolved from an item query to the portal
*/
export interface IDynamicItemQueryDefinition extends IBaseValueDefinition {
type: "item-query";
/**
* The path to the property on the item to return
*/
sourcePath: string;
/**
* Portal Query to be exectute to return the set of items
*/
query?: IQuery | IReference;
/**
* The type of aggregation to apply to the set of results
*/
aggregation: DynamicAggregation;
scope?: IQuery | IReference;
/**
* Indicates if the raw values should be returned
*/
includeRawValues?: boolean;
}
/**
* Definition for a dynamic value that is resolved from a feature service query
*/
export interface IDynamicServiceQueryDefinition extends IBaseValueDefinition {
type: "service-query";
/**
* Options used for the service query
*/
options: IServiceQueryOptions;
/**
* The type of aggregation to apply to the set of results
*/
aggregation: DynamicAggregation;
}
// FUTURE: Add a telemetry definition
// export interface IDynamicTelemetryQueryDefinition
// extends IBaseValueDefinition {
// type: "telemetry-query";
// /**
// * Other props TBD
// */
// tbd: string;
// /**
// * The type of aggregation to apply to the set of results
// */
// aggregation: DynamicAggregation;
// }
/**
* Union of all the dynamic value definitions
*/
export type DynamicValueDefinition =
| IStaticValueDefinition
| IDynamicPortalSelfDefinition
| IDynamicItemQueryDefinition
| IDynamicServiceQueryDefinition;
/**
* Type to hold a count-by-value result
* ```js
* { "value1": 2, "value2": 1}
* ```
*/
export type CountByValue = Record<string, number>;
/**
* A dynamic value can be a string, number, or another definition
* which will be recursively resolved.
*/
export type DynamicValue = string | number | DynamicValueDefinition;
/**
* The output of the resolution of a dynamic value
*/
export type DynamicValueResult = string | number | CountByValue;
/**
* A set of dynamic values, keyed by the outPath
*/
export type DynamicValues = Record<string, DynamicValue>;