@cubejs-client/react 1.7.12 → 1.7.14
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/CubeContext.d.ts +35 -0
- package/dist/CubeContext.d.ts.map +1 -0
- package/dist/CubeProvider.d.ts +31 -0
- package/dist/CubeProvider.d.ts.map +1 -0
- package/dist/QueryBuilder.d.ts +135 -0
- package/dist/QueryBuilder.d.ts.map +1 -0
- package/dist/QueryRenderer.d.ts +34 -0
- package/dist/QueryRenderer.d.ts.map +1 -0
- package/dist/QueryRendererWithTotals.d.ts +4 -0
- package/dist/QueryRendererWithTotals.d.ts.map +1 -0
- package/dist/cubejs-client-react.cjs.js +248 -23
- package/dist/cubejs-client-react.cjs.js.map +1 -1
- package/dist/cubejs-client-react.esm.js +253 -31
- package/dist/cubejs-client-react.esm.js.map +1 -1
- package/dist/cubejs-client-react.umd.js +248 -23
- package/dist/cubejs-client-react.umd.js.map +1 -1
- package/dist/hooks/cube-fetch.d.ts +6 -0
- package/dist/hooks/cube-fetch.d.ts.map +1 -0
- package/dist/hooks/cube-meta.d.ts +4 -0
- package/dist/hooks/cube-meta.d.ts.map +1 -0
- package/dist/hooks/cube-query.d.ts +39 -0
- package/dist/hooks/cube-query.d.ts.map +1 -0
- package/dist/hooks/cube-sql.d.ts +12 -0
- package/dist/hooks/cube-sql.d.ts.map +1 -0
- package/dist/hooks/deep-compare-memoize.d.ts +2 -0
- package/dist/hooks/deep-compare-memoize.d.ts.map +1 -0
- package/dist/hooks/dry-run.d.ts +7 -0
- package/dist/hooks/dry-run.d.ts.map +1 -0
- package/dist/hooks/lazy-dry-run.d.ts +7 -0
- package/dist/hooks/lazy-dry-run.d.ts.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/types.d.ts +765 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +14 -10
- package/src/CubeContext.ts +37 -0
- package/src/CubeProvider.tsx +42 -0
- package/src/{QueryBuilder.jsx → QueryBuilder.tsx} +238 -89
- package/src/{QueryRenderer.jsx → QueryRenderer.tsx} +39 -14
- package/src/QueryRendererWithTotals.tsx +24 -0
- package/src/hooks/cube-fetch.ts +98 -0
- package/src/hooks/cube-meta.ts +8 -0
- package/src/hooks/{cube-query.js → cube-query.ts} +90 -14
- package/src/hooks/cube-sql.ts +22 -0
- package/src/hooks/{deep-compare-memoize.js → deep-compare-memoize.ts} +2 -2
- package/src/hooks/dry-run.ts +17 -0
- package/src/hooks/lazy-dry-run.ts +24 -0
- package/src/index.ts +77 -0
- package/src/types.ts +837 -0
- package/src/{utils.js → utils.ts} +3 -3
- package/index.d.ts +0 -697
- package/src/CubeContext.js +0 -3
- package/src/CubeProvider.jsx +0 -14
- package/src/QueryRendererWithTotals.jsx +0 -20
- package/src/hooks/cube-fetch.js +0 -66
- package/src/hooks/cube-meta.js +0 -5
- package/src/hooks/cube-sql.js +0 -8
- package/src/hooks/dry-run.js +0 -8
- package/src/hooks/lazy-dry-run.js +0 -11
- package/src/index.js +0 -18
package/src/types.ts
ADDED
|
@@ -0,0 +1,837 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types of `@cubejs-client/react`.
|
|
3
|
+
*
|
|
4
|
+
* Everything exported from `src/index.ts` is part of the published API: the
|
|
5
|
+
* declarations shipped in `dist` are emitted from these sources, so a change
|
|
6
|
+
* here is a change to what consumers see.
|
|
7
|
+
*/
|
|
8
|
+
import type * as React from 'react';
|
|
9
|
+
import type {
|
|
10
|
+
BinaryOperator,
|
|
11
|
+
CacheMode,
|
|
12
|
+
CubeApi,
|
|
13
|
+
DateRange,
|
|
14
|
+
DeeplyReadonly,
|
|
15
|
+
DryRunResponse,
|
|
16
|
+
Filter,
|
|
17
|
+
FilterOperator,
|
|
18
|
+
LoadMethodOptions,
|
|
19
|
+
MemberType,
|
|
20
|
+
Meta,
|
|
21
|
+
PivotConfig,
|
|
22
|
+
ProgressResponse,
|
|
23
|
+
Query,
|
|
24
|
+
QueryOrder,
|
|
25
|
+
RequestError,
|
|
26
|
+
ResultSet,
|
|
27
|
+
SqlQuery,
|
|
28
|
+
TCubeDimension,
|
|
29
|
+
TCubeMeasure,
|
|
30
|
+
TCubeSegment,
|
|
31
|
+
TimeDimension,
|
|
32
|
+
TimeDimensionGranularity,
|
|
33
|
+
TOrderMember,
|
|
34
|
+
TSourceAxis,
|
|
35
|
+
UnaryOperator,
|
|
36
|
+
} from '@cubejs-client/core';
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Object the API methods store their MUTEX in.
|
|
40
|
+
*/
|
|
41
|
+
export type MutexObj = NonNullable<LoadMethodOptions['mutexObj']>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* A query as accepted by `useCubeQuery`.
|
|
45
|
+
*/
|
|
46
|
+
export type ReadonlyQueryInput = DeeplyReadonly<Query | Query[]>;
|
|
47
|
+
|
|
48
|
+
export type CubeProviderOptions = {
|
|
49
|
+
castNumerics?: boolean;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export type CubeProviderProps = {
|
|
53
|
+
cubeApi: CubeApi | null;
|
|
54
|
+
options?: CubeProviderOptions;
|
|
55
|
+
children: React.ReactNode;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export type CubeContextProps = {
|
|
59
|
+
cubeApi: CubeApi;
|
|
60
|
+
options?: CubeProviderOptions;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export type TLoadingState = {
|
|
64
|
+
isLoading: boolean;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export type ChartType = 'line' | 'bar' | 'table' | 'area' | 'number' | 'pie';
|
|
68
|
+
|
|
69
|
+
export type VizState = {
|
|
70
|
+
query?: Query;
|
|
71
|
+
pivotConfig?: PivotConfig;
|
|
72
|
+
chartType?: ChartType;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export type QueryRendererRenderProps = {
|
|
76
|
+
resultSet: ResultSet | null;
|
|
77
|
+
error: Error | null;
|
|
78
|
+
loadingState: TLoadingState;
|
|
79
|
+
sqlQuery: SqlQuery | null;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export type QueryRendererProps = {
|
|
83
|
+
/**
|
|
84
|
+
* Analytic query. [Learn more about it's format](/product/apis-integrations/rest-api/query-format)
|
|
85
|
+
*/
|
|
86
|
+
query: Query | Query[];
|
|
87
|
+
queries?: { [key: string]: Query };
|
|
88
|
+
/**
|
|
89
|
+
* Indicates whether the generated by `Cube.js` SQL Code should be requested. See [rest-api#sql](/reference/rest-api#v1sql). When set to `only` then only the request to [/v1/sql](/reference/rest-api#v1sql) will be performed. When set to `true` the sql request will be performed along with the query request. Will not be performed if set to `false`
|
|
90
|
+
*/
|
|
91
|
+
loadSql?: 'only' | boolean;
|
|
92
|
+
/**
|
|
93
|
+
* When `true` the **resultSet** will be reset to `null` first on every state change
|
|
94
|
+
*/
|
|
95
|
+
resetResultSetOnChange?: boolean;
|
|
96
|
+
updateOnlyOnStateChange?: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* `CubeApi` instance to use
|
|
99
|
+
*/
|
|
100
|
+
cubeApi?: CubeApi;
|
|
101
|
+
/**
|
|
102
|
+
* Server-side cache policy for query execution. Does not control client-side caching.
|
|
103
|
+
*/
|
|
104
|
+
cache?: CacheMode;
|
|
105
|
+
/**
|
|
106
|
+
* Output of this function will be rendered by the `QueryRenderer`
|
|
107
|
+
*/
|
|
108
|
+
render: (renderProps: QueryRendererRenderProps) => void;
|
|
109
|
+
/**
|
|
110
|
+
* @hidden
|
|
111
|
+
*/
|
|
112
|
+
children?: never;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* `resultSet` holds a map of result sets keyed by query name when the `queries`
|
|
117
|
+
* prop is used, and a single result set otherwise.
|
|
118
|
+
*
|
|
119
|
+
* @hidden
|
|
120
|
+
*/
|
|
121
|
+
export type QueryRendererState = {
|
|
122
|
+
isLoading?: boolean;
|
|
123
|
+
error?: RequestError | null;
|
|
124
|
+
sqlQuery?: SqlQuery | null;
|
|
125
|
+
resultSet?: ResultSet | { [key: string]: ResultSet } | null;
|
|
126
|
+
/**
|
|
127
|
+
* Never assigned — `render()` has always read it from state rather than from
|
|
128
|
+
* props, so the empty-object fallback for `resultSet` does not kick in.
|
|
129
|
+
*/
|
|
130
|
+
queries?: { [key: string]: Query };
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export type QueryRendererWithTotalsProps = Omit<QueryRendererProps, 'queries' | 'query'> & {
|
|
134
|
+
query: Query;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* What `QueryRenderer` passes to its render prop. `resultSet`,
|
|
139
|
+
* `loadingState.isLoading` and `sqlQuery` are only set once a request resolves.
|
|
140
|
+
*
|
|
141
|
+
* @hidden
|
|
142
|
+
*/
|
|
143
|
+
export type QueryRendererLoadState = {
|
|
144
|
+
error: Error | null;
|
|
145
|
+
resultSet: ResultSet | { [key: string]: ResultSet } | null | undefined;
|
|
146
|
+
loadingState: { isLoading?: boolean };
|
|
147
|
+
sqlQuery: SqlQuery | null | undefined;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* @hidden
|
|
152
|
+
*/
|
|
153
|
+
export type SchemaChangeProps = {
|
|
154
|
+
schemaVersion: number;
|
|
155
|
+
refresh: () => Promise<void>;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export type QueryBuilderState = VizState & {
|
|
159
|
+
query?: Query;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
export type QueryBuilderProps = {
|
|
163
|
+
/**
|
|
164
|
+
* `CubeApi` instance to use
|
|
165
|
+
*/
|
|
166
|
+
cubeApi?: CubeApi;
|
|
167
|
+
/**
|
|
168
|
+
* State for the QueryBuilder to start with. Pass in the value previously saved from onVizStateChanged to restore a session.
|
|
169
|
+
*/
|
|
170
|
+
initialVizState?: VizState;
|
|
171
|
+
/**
|
|
172
|
+
* Called by the `QueryBuilder` when the viz state has changed. Use it to save state outside of the `QueryBuilder` component.
|
|
173
|
+
*/
|
|
174
|
+
onVizStateChanged?: (vizState: VizState) => void;
|
|
175
|
+
/**
|
|
176
|
+
* @default defaultChartType line (used when initialVizState is not set or does not contain chartType)
|
|
177
|
+
*/
|
|
178
|
+
defaultChartType?: ChartType;
|
|
179
|
+
/**
|
|
180
|
+
* Default query (used when initialVizState is not set or does not contain query)
|
|
181
|
+
*/
|
|
182
|
+
defaultQuery?: Query;
|
|
183
|
+
/**
|
|
184
|
+
* Defaults to `false`. This means that the default heuristics will be applied. For example: when the query is empty and you select a measure that has a default time dimension it will be pushed to the query.
|
|
185
|
+
* @default disableHeuristics false
|
|
186
|
+
*/
|
|
187
|
+
disableHeuristics?: boolean;
|
|
188
|
+
wrapWithQueryRenderer?: boolean;
|
|
189
|
+
render: (renderProps: QueryBuilderRenderProps) => React.ReactNode;
|
|
190
|
+
/**
|
|
191
|
+
* A function that accepts the `newState` just before it's applied. You can use it to override the **defaultHeuristics** or to tweak the query or the vizState in any way.
|
|
192
|
+
*/
|
|
193
|
+
stateChangeHeuristics?: (state: QueryBuilderState, newState: QueryBuilderState) => QueryBuilderState;
|
|
194
|
+
/**
|
|
195
|
+
* @ignore @deprecated Controlled query
|
|
196
|
+
*/
|
|
197
|
+
query?: Query;
|
|
198
|
+
/**
|
|
199
|
+
* @ignore @deprecated Controlled query setter
|
|
200
|
+
*/
|
|
201
|
+
setQuery?: (query: Query) => void;
|
|
202
|
+
/**
|
|
203
|
+
* @ignore @deprecated Controlled vizState
|
|
204
|
+
*/
|
|
205
|
+
vizState?: VizState;
|
|
206
|
+
/**
|
|
207
|
+
* @ignore @deprecated Controlled vizState setter
|
|
208
|
+
*/
|
|
209
|
+
setVizState?: (vizState: VizState) => void;
|
|
210
|
+
/**
|
|
211
|
+
* @hidden
|
|
212
|
+
*/
|
|
213
|
+
schemaVersion?: number;
|
|
214
|
+
/**
|
|
215
|
+
* @hidden
|
|
216
|
+
*/
|
|
217
|
+
queryVersion?: number | string;
|
|
218
|
+
/**
|
|
219
|
+
* @hidden
|
|
220
|
+
*/
|
|
221
|
+
onSchemaChange?: (props: SchemaChangeProps) => void;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
export type QueryBuilderRenderProps = {
|
|
225
|
+
// Todo: should fix DRY, duplicate props from QueryRendererRenderProps, see https://github.com/cube-js/cube.js/issues/1192
|
|
226
|
+
resultSet?: ResultSet | null;
|
|
227
|
+
error?: Error | null;
|
|
228
|
+
loadingState?: TLoadingState;
|
|
229
|
+
|
|
230
|
+
meta: Meta | undefined;
|
|
231
|
+
metaError?: Error | null;
|
|
232
|
+
richMetaError?: Error | null;
|
|
233
|
+
metaErrorStack?: string | null;
|
|
234
|
+
isFetchingMeta: boolean;
|
|
235
|
+
/**
|
|
236
|
+
* Indicates whether the query is ready to be displayed or not
|
|
237
|
+
*/
|
|
238
|
+
isQueryPresent: boolean;
|
|
239
|
+
measures: (TCubeMeasure & { index: number })[];
|
|
240
|
+
dimensions: (TCubeDimension & { index: number })[];
|
|
241
|
+
segments: (TCubeSegment & { index: number })[];
|
|
242
|
+
timeDimensions: (TimeDimensionWithExtraFields & { index: number })[];
|
|
243
|
+
|
|
244
|
+
availableMembers: AvailableMembers;
|
|
245
|
+
|
|
246
|
+
availableFilterMembers: Array<AvailableCube<TCubeMeasure> | AvailableCube<TCubeDimension>>;
|
|
247
|
+
/**
|
|
248
|
+
* An array of available measures to select. They are loaded via the API from Cube.js Backend.
|
|
249
|
+
*/
|
|
250
|
+
availableMeasures: TCubeMeasure[];
|
|
251
|
+
/**
|
|
252
|
+
* An array of available dimensions to select. They are loaded via the API from Cube.js Backend.
|
|
253
|
+
*/
|
|
254
|
+
availableDimensions: TCubeDimension[];
|
|
255
|
+
/**
|
|
256
|
+
* An array of available time dimensions to select. They are loaded via the API from Cube.js Backend.
|
|
257
|
+
*/
|
|
258
|
+
availableTimeDimensions: TCubeDimension[];
|
|
259
|
+
/**
|
|
260
|
+
* An array of available segments to select. They are loaded via the API from Cube.js Backend.
|
|
261
|
+
*/
|
|
262
|
+
availableSegments: TCubeSegment[];
|
|
263
|
+
|
|
264
|
+
updateMeasures: MeasureUpdater;
|
|
265
|
+
updateDimensions: DimensionUpdater;
|
|
266
|
+
updateSegments: SegmentUpdater;
|
|
267
|
+
updateTimeDimensions: TimeDimensionUpdater;
|
|
268
|
+
updateFilters: FilterUpdater;
|
|
269
|
+
/**
|
|
270
|
+
* Used for partial of full query update
|
|
271
|
+
*/
|
|
272
|
+
updateQuery: (query: Query) => void;
|
|
273
|
+
filters: (FilterWithExtraFields & { index: number })[];
|
|
274
|
+
/**
|
|
275
|
+
* All possible order members for the query
|
|
276
|
+
*/
|
|
277
|
+
orderMembers: TOrderMember[];
|
|
278
|
+
/**
|
|
279
|
+
* Used for query order update
|
|
280
|
+
*/
|
|
281
|
+
updateOrder: OrderUpdater;
|
|
282
|
+
/**
|
|
283
|
+
* See [Pivot Config](@cubejs-client-core#types-pivot-config)
|
|
284
|
+
*/
|
|
285
|
+
pivotConfig?: PivotConfig;
|
|
286
|
+
/**
|
|
287
|
+
* Helper method for `pivotConfig` updates
|
|
288
|
+
*/
|
|
289
|
+
updatePivotConfig: PivotConfigUpdater;
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Selected chart type
|
|
293
|
+
*/
|
|
294
|
+
chartType?: ChartType;
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Used for chart type update
|
|
298
|
+
*/
|
|
299
|
+
updateChartType: (chartType: ChartType) => void;
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Used to set the initial query for this component. Note that adding this prop turns this into an
|
|
303
|
+
* uncontrolled component and will only be able to execute `dryRun` queries. To use this component
|
|
304
|
+
* as a controlled component, use `setQuery` instead.
|
|
305
|
+
*/
|
|
306
|
+
query: Query;
|
|
307
|
+
validatedQuery: Query;
|
|
308
|
+
refresh: () => void;
|
|
309
|
+
missingMembers: string[];
|
|
310
|
+
dryRunResponse?: DryRunResponse;
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* The state `QueryBuilder` keeps. It is a superset of `QueryBuilderState`:
|
|
315
|
+
* everything beyond `query`, `pivotConfig` and `chartType` is internal
|
|
316
|
+
* bookkeeping.
|
|
317
|
+
*
|
|
318
|
+
* @hidden
|
|
319
|
+
*/
|
|
320
|
+
export type QueryBuilderInternalState = QueryBuilderState & {
|
|
321
|
+
query: Query;
|
|
322
|
+
validatedQuery?: Query;
|
|
323
|
+
missingMembers: string[];
|
|
324
|
+
isFetchingMeta: boolean;
|
|
325
|
+
dryRunResponse?: DryRunResponse | null;
|
|
326
|
+
meta?: Meta;
|
|
327
|
+
metaError?: Error | null;
|
|
328
|
+
richMetaError?: Error | null;
|
|
329
|
+
metaErrorStack?: string | null;
|
|
330
|
+
queryError?: Error | null;
|
|
331
|
+
richQueryError?: Error | null;
|
|
332
|
+
sessionGranularity?: TimeDimensionGranularity | null;
|
|
333
|
+
shouldApplyHeuristicOrder?: boolean;
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* A state update on its way through `updateVizState`. Heuristics may return a
|
|
338
|
+
* partial state, and the missing pieces are filled in before it is applied.
|
|
339
|
+
*
|
|
340
|
+
* @hidden
|
|
341
|
+
*/
|
|
342
|
+
export type QueryBuilderStateUpdate = Partial<QueryBuilderInternalState>;
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* @hidden
|
|
346
|
+
*/
|
|
347
|
+
export type QueryMemberType = MemberType | 'timeDimensions';
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* State `QueryBuilder.resolveMember` resolves members against.
|
|
351
|
+
*
|
|
352
|
+
* @hidden
|
|
353
|
+
*/
|
|
354
|
+
export type ResolveMemberArgs = {
|
|
355
|
+
meta?: Meta;
|
|
356
|
+
query: Query | Query[];
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Resolved query members carry the position they hold in the query.
|
|
361
|
+
*
|
|
362
|
+
* @hidden
|
|
363
|
+
*/
|
|
364
|
+
export type IndexedMeasure = TCubeMeasure & { index: number };
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* @hidden
|
|
368
|
+
*/
|
|
369
|
+
export type IndexedDimension = TCubeDimension & { index: number };
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* @hidden
|
|
373
|
+
*/
|
|
374
|
+
export type IndexedSegment = TCubeSegment & { index: number };
|
|
375
|
+
|
|
376
|
+
export type AvailableMembers = {
|
|
377
|
+
measures: AvailableCube<TCubeMeasure>[];
|
|
378
|
+
dimensions: AvailableCube<TCubeDimension>[];
|
|
379
|
+
segments: AvailableCube<TCubeSegment>[];
|
|
380
|
+
timeDimensions: AvailableCube<TCubeDimension>[];
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
// todo: CubeMember
|
|
384
|
+
export type AvailableCube<T = any> = {
|
|
385
|
+
type: 'cube' | 'view';
|
|
386
|
+
public: boolean;
|
|
387
|
+
cubeName: string;
|
|
388
|
+
cubeTitle: string;
|
|
389
|
+
members: T[];
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
export type UseCubeQueryOptions = {
|
|
393
|
+
/**
|
|
394
|
+
* A `CubeApi` instance to use. Taken from the context if the param is not passed
|
|
395
|
+
*/
|
|
396
|
+
cubeApi?: CubeApi;
|
|
397
|
+
/**
|
|
398
|
+
* Query execution will be skipped when `skip` is set to `true`. You can use this flag to avoid sending incomplete queries.
|
|
399
|
+
*/
|
|
400
|
+
skip?: boolean;
|
|
401
|
+
/**
|
|
402
|
+
* Use continuous fetch behavior. See [Real-Time Data Fetch](/product/apis-integrations/rest-api/real-time-data-fetch)
|
|
403
|
+
*/
|
|
404
|
+
subscribe?: boolean;
|
|
405
|
+
/**
|
|
406
|
+
* When `true` the resultSet will be reset to `null` first
|
|
407
|
+
*/
|
|
408
|
+
resetResultSetOnChange?: boolean;
|
|
409
|
+
/**
|
|
410
|
+
* If enabled, all members of the 'number' type will be automatically converted to numerical values on the client side
|
|
411
|
+
*/
|
|
412
|
+
castNumerics?: boolean;
|
|
413
|
+
/**
|
|
414
|
+
* Server-side cache policy for query execution. Does not control client-side caching.
|
|
415
|
+
*/
|
|
416
|
+
cache?: CacheMode;
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* `ResultSet` constrains its data to `Record<string, any>`, while `Data` is
|
|
421
|
+
* unconstrained here, as it is in `useCubeQuery`.
|
|
422
|
+
*/
|
|
423
|
+
type ResultSetData<Data> = Data extends Record<string, any> ? Data : any;
|
|
424
|
+
|
|
425
|
+
export type UseCubeQueryResult<QueryInput, Data> = {
|
|
426
|
+
error: Error | null;
|
|
427
|
+
isLoading: boolean;
|
|
428
|
+
resultSet: ResultSet<ResultSetData<Data>> | null;
|
|
429
|
+
/**
|
|
430
|
+
* Set from the `Continue wait` messages of a long-running query.
|
|
431
|
+
*
|
|
432
|
+
* Note: this is `null` until the first such message arrives — the type is
|
|
433
|
+
* kept non-nullable for backwards compatibility, so read it with `progress?.`
|
|
434
|
+
*/
|
|
435
|
+
progress: ProgressResponse;
|
|
436
|
+
/**
|
|
437
|
+
* The query the current `resultSet` was loaded for.
|
|
438
|
+
*
|
|
439
|
+
* Note: this is `null` until the first query runs — the type is kept
|
|
440
|
+
* non-nullable for backwards compatibility.
|
|
441
|
+
*/
|
|
442
|
+
previousQuery: QueryInput;
|
|
443
|
+
refetch: () => Promise<void>;
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* What `useCubeQuery` builds, with `progress` and `previousQuery` as they
|
|
448
|
+
* actually are before the first response.
|
|
449
|
+
*
|
|
450
|
+
* @hidden
|
|
451
|
+
*/
|
|
452
|
+
export type UseCubeQueryInternalResult = {
|
|
453
|
+
error: Error | null;
|
|
454
|
+
isLoading: boolean;
|
|
455
|
+
resultSet: ResultSet | null;
|
|
456
|
+
progress: ProgressResponse | null;
|
|
457
|
+
previousQuery: ReadonlyQueryInput | null;
|
|
458
|
+
refetch: () => Promise<void>;
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* @hidden
|
|
463
|
+
*/
|
|
464
|
+
export type CubeFetchOptions = {
|
|
465
|
+
skip?: boolean;
|
|
466
|
+
cubeApi?: CubeApi;
|
|
467
|
+
query?: Query;
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* @hidden
|
|
472
|
+
*/
|
|
473
|
+
export type CubeFetchResult<T> = {
|
|
474
|
+
isLoading: boolean;
|
|
475
|
+
error: Error | null;
|
|
476
|
+
/**
|
|
477
|
+
* The response of the last request.
|
|
478
|
+
*
|
|
479
|
+
* Note: this is `null` until the first request resolves — the type is kept
|
|
480
|
+
* non-nullable for backwards compatibility, so check `isLoading` first.
|
|
481
|
+
*/
|
|
482
|
+
response: T;
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* The result of `useCubeMeta`, `useCubeSql` and `useDryRun`: a
|
|
487
|
+
* `CubeFetchResult` plus the `refetch` they expose.
|
|
488
|
+
*/
|
|
489
|
+
export type UseCubeFetchResult<T> = CubeFetchResult<T> & {
|
|
490
|
+
refetch: (options?: UseCubeFetchLoadOptions) => Promise<void>;
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* What `useCubeFetch` returns before the first request resolves.
|
|
495
|
+
*
|
|
496
|
+
* @hidden
|
|
497
|
+
*/
|
|
498
|
+
export type UseCubeFetchInternalResult<T> = CubeFetchState<T> & {
|
|
499
|
+
error: Error | null;
|
|
500
|
+
refetch: (options?: UseCubeFetchLoadOptions) => Promise<void>;
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* @hidden
|
|
505
|
+
*/
|
|
506
|
+
export type UseDryRunResult = CubeFetchResult<DryRunResponse>;
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* @hidden
|
|
510
|
+
*/
|
|
511
|
+
export type UseCubeSqlResponse = {
|
|
512
|
+
sql: string;
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* What `useCubeSql` resolves with. Its declared `response` is a
|
|
517
|
+
* `DryRunResponse` for backwards compatibility; cast to this to get at the
|
|
518
|
+
* `SqlQuery` it actually resolves with.
|
|
519
|
+
*/
|
|
520
|
+
export type UseCubeSqlResult = UseCubeFetchResult<SqlQuery>;
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* @hidden
|
|
524
|
+
*/
|
|
525
|
+
export type LoadLazyDryRunOptions = {
|
|
526
|
+
query?: Query | Query[];
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* `CubeApi` methods `useCubeFetch` can dispatch to.
|
|
531
|
+
*
|
|
532
|
+
* @hidden
|
|
533
|
+
*/
|
|
534
|
+
export type CubeFetchMethod = 'meta' | 'sql' | 'dryRun';
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* Options of `useCubeSql`, `useDryRun` and `useLazyDryRun`. Unlike
|
|
538
|
+
* `CubeFetchOptions` they accept an array of queries and a `baseRequestId`.
|
|
539
|
+
*/
|
|
540
|
+
export type UseCubeFetchOptions = Omit<CubeFetchOptions, 'query'> & {
|
|
541
|
+
query?: Query | Query[];
|
|
542
|
+
baseRequestId?: string;
|
|
543
|
+
onlyViews?: boolean;
|
|
544
|
+
};
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* The query a `refetch` — or `useLazyDryRun`'s loader — runs instead of the one
|
|
548
|
+
* the hook was called with.
|
|
549
|
+
*/
|
|
550
|
+
export type UseCubeFetchLoadOptions = {
|
|
551
|
+
query?: Query | Query[];
|
|
552
|
+
onlyViews?: boolean;
|
|
553
|
+
};
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* @hidden
|
|
557
|
+
*/
|
|
558
|
+
export type CubeMetaFetchOptions = Omit<CubeFetchOptions, 'query'> & {
|
|
559
|
+
/**
|
|
560
|
+
* Request views only — the response's `cubes` array then contains only entries
|
|
561
|
+
* whose `type` is `view`. Over HTTP, servers predating the flag ignore it and
|
|
562
|
+
* return the full model, so callers should not assume the response is filtered;
|
|
563
|
+
* over `WebSocketTransport` such servers reject the message with a 400.
|
|
564
|
+
*/
|
|
565
|
+
onlyViews?: boolean;
|
|
566
|
+
/**
|
|
567
|
+
* @hidden
|
|
568
|
+
*/
|
|
569
|
+
baseRequestId?: string;
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* What `useCubeFetch` keeps in state.
|
|
574
|
+
*
|
|
575
|
+
* @hidden
|
|
576
|
+
*/
|
|
577
|
+
export type CubeFetchState<T> = {
|
|
578
|
+
isLoading: boolean;
|
|
579
|
+
response: T | null;
|
|
580
|
+
};
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Arguments the dispatched `CubeApi` method is called with: `meta` takes only
|
|
584
|
+
* options, `sql` and `dryRun` take a query as well.
|
|
585
|
+
*
|
|
586
|
+
* @hidden
|
|
587
|
+
*/
|
|
588
|
+
export type CubeFetchArgs = [LoadMethodOptions] | [Query | Query[], LoadMethodOptions];
|
|
589
|
+
|
|
590
|
+
/**
|
|
591
|
+
* The `CubeApi` method `useCubeFetch` dispatches to. The three methods share
|
|
592
|
+
* neither their signatures nor their response type, so the response is narrowed
|
|
593
|
+
* by the caller.
|
|
594
|
+
*
|
|
595
|
+
* @hidden
|
|
596
|
+
*/
|
|
597
|
+
export type CubeFetchDispatch = (this: CubeApi, ...args: CubeFetchArgs) => Promise<unknown>;
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* `ProgressResult` keeps `progressResponse` private, but `useCubeQuery` has
|
|
601
|
+
* always read it to expose the raw response.
|
|
602
|
+
*
|
|
603
|
+
* @hidden
|
|
604
|
+
*/
|
|
605
|
+
export type ProgressResultWithResponse = {
|
|
606
|
+
progressResponse: ProgressResponse;
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* @hidden
|
|
611
|
+
*/
|
|
612
|
+
export type ProgressCallback = NonNullable<LoadMethodOptions['progressCallback']>;
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* You can use the following methods for member manipulaltion
|
|
616
|
+
* ```js
|
|
617
|
+
* <QueryBuilder
|
|
618
|
+
* // ...
|
|
619
|
+
* cubeApi={cubeApi}
|
|
620
|
+
* render={({
|
|
621
|
+
* // ...
|
|
622
|
+
* availableMeasures,
|
|
623
|
+
* updateMeasures,
|
|
624
|
+
* }) => {
|
|
625
|
+
* return (
|
|
626
|
+
* // ...
|
|
627
|
+
* <Select
|
|
628
|
+
* mode="multiple"
|
|
629
|
+
* placeholder="Please select"
|
|
630
|
+
* onSelect={(measure) => updateMeasures.add(measure)}
|
|
631
|
+
* onDeselect={(measure) => updateMeasures.remove(measure)}
|
|
632
|
+
* >
|
|
633
|
+
* {availableMeasures.map((measure) => (
|
|
634
|
+
* <Select.Option key={measure.name} value={measure}>
|
|
635
|
+
* {measure.title}
|
|
636
|
+
* </Select.Option>
|
|
637
|
+
* ))}
|
|
638
|
+
* </Select>
|
|
639
|
+
* );
|
|
640
|
+
* }}
|
|
641
|
+
* />
|
|
642
|
+
* ```
|
|
643
|
+
*
|
|
644
|
+
* NOTE: if you need to add or remove more than one member at a time you should use `updateQuery` prop of {@see QueryBuilderRenderProps}
|
|
645
|
+
* ```js
|
|
646
|
+
* <QueryBuilder
|
|
647
|
+
* // ...
|
|
648
|
+
* cubeApi={cubeApi}
|
|
649
|
+
* render={({
|
|
650
|
+
* // ...
|
|
651
|
+
* measures,
|
|
652
|
+
* updateMeasures,
|
|
653
|
+
* updateQuery,
|
|
654
|
+
* }) => {
|
|
655
|
+
* // ...
|
|
656
|
+
* return (
|
|
657
|
+
* <>
|
|
658
|
+
* // WRONG: This code will not work properly
|
|
659
|
+
* <button
|
|
660
|
+
* onClick={() =>
|
|
661
|
+
* measures.forEach((measure) => updateMeasures.remove(measure))
|
|
662
|
+
* }
|
|
663
|
+
* >
|
|
664
|
+
* Remove all
|
|
665
|
+
* </button>
|
|
666
|
+
*
|
|
667
|
+
* // CORRECT: Using `updateQuery` for removing all measures
|
|
668
|
+
* <button
|
|
669
|
+
* onClick={() =>
|
|
670
|
+
* updateQuery({
|
|
671
|
+
* measures: [],
|
|
672
|
+
* })
|
|
673
|
+
* }
|
|
674
|
+
* >
|
|
675
|
+
* Remove all
|
|
676
|
+
* </button>
|
|
677
|
+
* </>
|
|
678
|
+
* );
|
|
679
|
+
* }}
|
|
680
|
+
* />
|
|
681
|
+
* ```
|
|
682
|
+
*/
|
|
683
|
+
export type MemberUpdater<T> = {
|
|
684
|
+
add: (member: T) => void;
|
|
685
|
+
remove: (member: { index: number }) => void;
|
|
686
|
+
update: (member: { index: number }, updateWith: T) => void;
|
|
687
|
+
};
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* Builds the updater for one kind of query member. `toQuery` turns a member
|
|
691
|
+
* into its query representation, and defaults to reading its name.
|
|
692
|
+
*
|
|
693
|
+
* @hidden
|
|
694
|
+
*/
|
|
695
|
+
export type MemberUpdaterFactory = <Member>(
|
|
696
|
+
memberType: QueryMemberType | 'filters',
|
|
697
|
+
toQuery?: (member: Member) => unknown
|
|
698
|
+
) => MemberUpdater<Member>;
|
|
699
|
+
|
|
700
|
+
export type FilterExtraFields = {
|
|
701
|
+
dimension: TCubeDimension | TCubeMeasure;
|
|
702
|
+
operators: { name: string; title: string }[];
|
|
703
|
+
};
|
|
704
|
+
|
|
705
|
+
export type FilterWithExtraFields = Omit<Filter, 'dimension'> & FilterExtraFields;
|
|
706
|
+
|
|
707
|
+
export type GranularityOptions = {
|
|
708
|
+
granularities: { name: string; title: string }[];
|
|
709
|
+
};
|
|
710
|
+
|
|
711
|
+
export type TimeDimensionExtraFields = {
|
|
712
|
+
dimension: TCubeDimension & GranularityOptions;
|
|
713
|
+
};
|
|
714
|
+
|
|
715
|
+
export type TimeDimensionWithExtraFields = Omit<TimeDimension, 'dimension'> & TimeDimensionExtraFields;
|
|
716
|
+
|
|
717
|
+
export type DimensionUpdater = MemberUpdater<TCubeDimension>;
|
|
718
|
+
export type MeasureUpdater = MemberUpdater<TCubeMeasure>;
|
|
719
|
+
export type SegmentUpdater = MemberUpdater<TCubeSegment>;
|
|
720
|
+
|
|
721
|
+
// Only require the fields that are actually used (otherwise fields like `operators` are required just to add/update)
|
|
722
|
+
export type TimeDimensionRangedUpdateFields = {
|
|
723
|
+
granularity?: TimeDimensionGranularity;
|
|
724
|
+
dateRange?: DateRange;
|
|
725
|
+
dimension: TCubeDimension;
|
|
726
|
+
};
|
|
727
|
+
|
|
728
|
+
export type TimeDimensionComparisonUpdateFields = {
|
|
729
|
+
granularity?: TimeDimensionGranularity;
|
|
730
|
+
compareDateRange: Array<DateRange>;
|
|
731
|
+
dimension: TCubeDimension;
|
|
732
|
+
};
|
|
733
|
+
|
|
734
|
+
export type TimeDimensionUpdater = MemberUpdater<
|
|
735
|
+
TimeDimensionRangedUpdateFields | TimeDimensionComparisonUpdateFields
|
|
736
|
+
>;
|
|
737
|
+
|
|
738
|
+
export type FilterUpdateFields = {
|
|
739
|
+
member?: string;
|
|
740
|
+
operator: BinaryOperator | UnaryOperator;
|
|
741
|
+
values?: string[];
|
|
742
|
+
dimension: TCubeDimension | TCubeMeasure;
|
|
743
|
+
};
|
|
744
|
+
|
|
745
|
+
export type FilterUpdater = MemberUpdater<FilterUpdateFields>;
|
|
746
|
+
|
|
747
|
+
/**
|
|
748
|
+
* The fields `toTimeDimension` reads off a member. The updater takes either the
|
|
749
|
+
* ranged or the comparison variant, so both range fields are optional here.
|
|
750
|
+
*
|
|
751
|
+
* @hidden
|
|
752
|
+
*/
|
|
753
|
+
export type TimeDimensionUpdateInput = {
|
|
754
|
+
granularity?: TimeDimensionGranularity;
|
|
755
|
+
dateRange?: DateRange;
|
|
756
|
+
compareDateRange?: Array<DateRange>;
|
|
757
|
+
dimension: TCubeDimension;
|
|
758
|
+
};
|
|
759
|
+
|
|
760
|
+
/**
|
|
761
|
+
* The fields `toFilter` reads off a member. Unlike `FilterUpdateFields`, where
|
|
762
|
+
* `member` is declared as a string, the resolved member object is what is read
|
|
763
|
+
* here.
|
|
764
|
+
*
|
|
765
|
+
* @hidden
|
|
766
|
+
*/
|
|
767
|
+
export type FilterUpdateInput = {
|
|
768
|
+
member?: TCubeDimension | TCubeMeasure;
|
|
769
|
+
dimension?: TCubeDimension | TCubeMeasure;
|
|
770
|
+
operator: BinaryOperator | UnaryOperator;
|
|
771
|
+
values?: string[];
|
|
772
|
+
};
|
|
773
|
+
|
|
774
|
+
/**
|
|
775
|
+
* A time dimension as `QueryBuilder.resolveMember` returns it: the resolved
|
|
776
|
+
* dimension carries the granularity options the query builder offers.
|
|
777
|
+
*
|
|
778
|
+
* @hidden
|
|
779
|
+
*/
|
|
780
|
+
export type ResolvedTimeDimension = Omit<TimeDimension, 'dimension'> & {
|
|
781
|
+
dimension: TCubeDimension & { granularities: GranularityOption[] };
|
|
782
|
+
index: number;
|
|
783
|
+
};
|
|
784
|
+
|
|
785
|
+
/**
|
|
786
|
+
* A granularity the query builder offers. `name` is left out for the
|
|
787
|
+
* "w/o grouping" option.
|
|
788
|
+
*/
|
|
789
|
+
export type GranularityOption = {
|
|
790
|
+
name?: TimeDimensionGranularity;
|
|
791
|
+
title: string;
|
|
792
|
+
};
|
|
793
|
+
|
|
794
|
+
/**
|
|
795
|
+
* Either an `Error` or the `plainError` string from the API response, of which
|
|
796
|
+
* `fetchMeta` only reads `message`/`toString()`.
|
|
797
|
+
*
|
|
798
|
+
* @hidden
|
|
799
|
+
*/
|
|
800
|
+
export type MetaErrorSource = {
|
|
801
|
+
message?: string;
|
|
802
|
+
toString(): string;
|
|
803
|
+
};
|
|
804
|
+
|
|
805
|
+
/**
|
|
806
|
+
* A filter as it reaches the render props: the resolved member and the
|
|
807
|
+
* operators available for it, alongside the fields of the query filter.
|
|
808
|
+
*
|
|
809
|
+
* @hidden
|
|
810
|
+
*/
|
|
811
|
+
export type ResolvedFilter = Omit<Filter, 'dimension'> & {
|
|
812
|
+
dimension: TCubeDimension | TCubeMeasure;
|
|
813
|
+
operators: FilterOperator[];
|
|
814
|
+
index: number;
|
|
815
|
+
};
|
|
816
|
+
|
|
817
|
+
export type OrderUpdater = {
|
|
818
|
+
set: (memberId: string, order: QueryOrder | 'none') => void;
|
|
819
|
+
update: (order: Query['order']) => void;
|
|
820
|
+
reorder: (sourceIndex: number, destinationIndex: number) => void;
|
|
821
|
+
};
|
|
822
|
+
|
|
823
|
+
export type PivotConfigUpdaterArgs = {
|
|
824
|
+
sourceIndex: number;
|
|
825
|
+
destinationIndex: number;
|
|
826
|
+
sourceAxis: TSourceAxis;
|
|
827
|
+
destinationAxis: TSourceAxis;
|
|
828
|
+
};
|
|
829
|
+
|
|
830
|
+
export type PivotConfigExtraUpdateFields = {
|
|
831
|
+
limit?: number;
|
|
832
|
+
};
|
|
833
|
+
|
|
834
|
+
export type PivotConfigUpdater = {
|
|
835
|
+
moveItem: (args: PivotConfigUpdaterArgs) => void;
|
|
836
|
+
update: (pivotConfig: PivotConfig & PivotConfigExtraUpdateFields) => void;
|
|
837
|
+
};
|