@cubejs-client/react 0.28.33 → 0.28.38

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/index.d.ts CHANGED
@@ -318,6 +318,7 @@ declare module '@cubejs-client/react' {
318
318
  timeDimensions: AvailableCube<TCubeDimension>[];
319
319
  };
320
320
 
321
+ // todo: CubeMember
321
322
  export type AvailableCube<T = any> = {
322
323
  cubeName: string;
323
324
  cubeTitle: string;
@@ -459,6 +460,8 @@ declare module '@cubejs-client/react' {
459
460
  */
460
461
  type CubeFetchOptions = {
461
462
  skip?: boolean;
463
+ cubejsApi?: CubejsApi;
464
+ query?: Query;
462
465
  };
463
466
 
464
467
  /**
@@ -502,6 +505,8 @@ declare module '@cubejs-client/react' {
502
505
  sql: string;
503
506
  };
504
507
 
508
+ export function useCubeMeta(options?: Omit<CubeFetchOptions, 'query'>): CubeFetchResult<Meta>;
509
+
505
510
  /**
506
511
  * @hidden
507
512
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cubejs-client/react",
3
- "version": "0.28.33",
3
+ "version": "0.28.38",
4
4
  "author": "Cube Dev, Inc.",
5
5
  "license": "MIT",
6
6
  "engines": {},
@@ -24,7 +24,7 @@
24
24
  ],
25
25
  "dependencies": {
26
26
  "@babel/runtime": "^7.1.2",
27
- "@cubejs-client/core": "^0.28.25",
27
+ "@cubejs-client/core": "^0.28.38",
28
28
  "anser": "^2.0.1",
29
29
  "core-js": "^3.6.5",
30
30
  "html-entities": "^2.3.2",
@@ -44,5 +44,5 @@
44
44
  "peerDependencies": {
45
45
  "react": ">=16.10.2"
46
46
  },
47
- "gitHead": "1ff7d93b9f5029136cccdf9ae747ba6bb493babf"
47
+ "gitHead": "b6ac84b0ec679a40886a19e85d24619e0ca6a2ec"
48
48
  }
@@ -22,22 +22,23 @@ export function useCubeFetch(method, options = {}) {
22
22
  const cubejsApi = options.cubejsApi || context?.cubejsApi;
23
23
  const query = loadOptions.query || options.query;
24
24
 
25
- if (!cubejsApi) {
26
- throw new Error('Cube.js API client is not provided');
27
- }
25
+ const queryCondition = method === 'meta' ? true : query && isQueryPresent(query);
28
26
 
29
- if ((ignoreSkip || !skip) && query && isQueryPresent(query)) {
27
+ if (cubejsApi && (ignoreSkip || !skip) && queryCondition) {
30
28
  setError(null);
31
29
  setResponse({
32
30
  isLoading: true,
33
31
  response: null,
34
32
  });
35
33
 
34
+ const coreOptions = {
35
+ mutexObj: mutexRef.current,
36
+ mutexKey: method,
37
+ };
38
+ const args = method === 'meta' ? [coreOptions] : [query, coreOptions];
39
+
36
40
  try {
37
- const response = await cubejsApi[method](query, {
38
- mutexObj: mutexRef.current,
39
- mutexKey: method,
40
- });
41
+ const response = await cubejsApi[method](...args);
41
42
 
42
43
  if (isMounted()) {
43
44
  setResponse({
@@ -45,9 +46,9 @@ export function useCubeFetch(method, options = {}) {
45
46
  isLoading: false,
46
47
  });
47
48
  }
48
- } catch (err) {
49
+ } catch (error) {
49
50
  if (isMounted()) {
50
- setError(err);
51
+ setError(error);
51
52
  setResponse({
52
53
  isLoading: false,
53
54
  response: null,
@@ -0,0 +1,5 @@
1
+ import { useCubeFetch } from './cube-fetch';
2
+
3
+ export function useCubeMeta(options = {}) {
4
+ return useCubeFetch('meta', options);
5
+ }
@@ -3,6 +3,6 @@ import { useCubeFetch } from './cube-fetch';
3
3
  export function useDryRun(query, options = {}) {
4
4
  return useCubeFetch('dryRun', {
5
5
  ...options,
6
- query
7
- })
6
+ query,
7
+ });
8
8
  }
package/src/index.js CHANGED
@@ -8,6 +8,7 @@ export * from './hooks/cube-sql';
8
8
  export * from './hooks/dry-run';
9
9
  export * from './hooks/lazy-dry-run';
10
10
  export * from './hooks/cube-query';
11
+ export * from './hooks/cube-meta';
11
12
  export {
12
13
  QueryRenderer,
13
14
  QueryRendererWithTotals,
package/src/utils.js CHANGED
@@ -77,9 +77,19 @@ export function generateAnsiHTML(txt) {
77
77
  }
78
78
 
79
79
  export function removeEmpty(obj) {
80
+ if (typeof obj !== 'object') {
81
+ return obj;
82
+ }
83
+
80
84
  return Object.fromEntries(
81
85
  Object.entries(obj)
82
86
  .filter(([, v]) => v != null)
83
- .map(([k, v]) => [k, typeof v === 'object' && !Array.isArray(v) ? removeEmpty(v) : v])
87
+ .map(([k, v]) => {
88
+ if (Array.isArray(v)) {
89
+ return [k, v.map(removeEmpty)];
90
+ }
91
+
92
+ return [k, typeof v === 'object' ? removeEmpty(v) : v];
93
+ })
84
94
  );
85
95
  }