Skip to content

Commit 3dad82a

Browse files
authored
chore: deprecate cubejsApi prop in favor of cubeApi (#7300)
1 parent 38c2412 commit 3dad82a

File tree

5 files changed

+32
-12
lines changed

5 files changed

+32
-12
lines changed

packages/cubejs-client-core/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,5 +375,5 @@ class CubejsApi {
375375

376376
export default (apiToken, options) => new CubejsApi(apiToken, options);
377377

378-
export { CubejsApi, HttpTransport, ResultSet, RequestError, Meta };
378+
export { CubejsApi, CubejsApi as CubeApi, HttpTransport, ResultSet, RequestError, Meta };
379379
export * from './utils';

packages/cubejs-client-react/index.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,15 @@ declare module '@cubejs-client/react' {
457457

458458
type UseCubeQueryOptions = {
459459
/**
460+
* @deprecated Use the `cubeApi` option
460461
* A `CubejsApi` instance to use. Taken from the context if the param is not passed
461462
*/
462463
cubejsApi?: CubejsApi;
464+
465+
/**
466+
* A `CubejsApi` instance to use. Taken from the context if the param is not passed
467+
*/
468+
cubeApi?: CubejsApi;
463469
/**
464470
* Query execution will be skipped when `skip` is set to `true`. You can use this flag to avoid sending incomplete queries.
465471
*/
@@ -491,6 +497,7 @@ declare module '@cubejs-client/react' {
491497
*/
492498
type CubeFetchOptions = {
493499
skip?: boolean;
500+
cubeApi?: CubejsApi;
494501
cubejsApi?: CubejsApi;
495502
query?: Query;
496503
};

packages/cubejs-client-react/src/CubeProvider.jsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
import React from 'react';
1+
import React, { useEffect } from 'react';
22
import CubeContext from './CubeContext';
33

4-
export default function CubeProvider({ cubejsApi, children, options = {} }) {
4+
export default function CubeProvider({ cubeApi, cubejsApi, children, options = {} }) {
5+
useEffect(() => {
6+
if (cubejsApi && !cubeApi) {
7+
console.warn('"cubejsApi" is deprecated and will be removed in the following version. Use "cubeApi" instead.');
8+
}
9+
}, [cubeApi, cubejsApi]);
10+
511
return (
612
<CubeContext.Provider value={{
713
cubejsApi,
14+
cubeApi,
815
options
916
}}
1017
>

packages/cubejs-client-react/src/hooks/cube-fetch.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ export function useCubeFetch(method, options = {}) {
1919
const { skip = false } = options;
2020

2121
async function load(loadOptions = {}, ignoreSkip = false) {
22-
const cubejsApi = options.cubejsApi || context?.cubejsApi;
22+
const cubeApi = options.cubeApi || options.cubejsApi || context?.cubeApi || context?.cubejsApi;
2323
const query = loadOptions.query || options.query;
2424

2525
const queryCondition = method === 'meta' ? true : query && isQueryPresent(query);
2626

27-
if (cubejsApi && (ignoreSkip || !skip) && queryCondition) {
27+
if (cubeApi && (ignoreSkip || !skip) && queryCondition) {
2828
setError(null);
2929
setResponse({
3030
isLoading: true,
@@ -38,7 +38,7 @@ export function useCubeFetch(method, options = {}) {
3838
const args = method === 'meta' ? [coreOptions] : [query, coreOptions];
3939

4040
try {
41-
const response = await cubejsApi[method](...args);
41+
const response = await cubeApi[method](...args);
4242

4343
if (isMounted()) {
4444
setResponse({

packages/cubejs-client-react/src/hooks/cube-query.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,18 @@ export function useCubeQuery(query, options = {}) {
1818
let subscribeRequest = null;
1919

2020
const progressCallback = ({ progressResponse }) => setProgress(progressResponse);
21+
22+
useEffect(() => {
23+
if (options.cubejsApi && !options.cubeApi) {
24+
console.warn('"cubejsApi" is deprecated and will be removed in the following version. Use "cubeApi" instead.');
25+
}
26+
}, [options.cubeApi, options.cubejsApi]);
2127

2228
async function fetch() {
2329
const { resetResultSetOnChange } = options;
24-
const cubejsApi = options.cubejsApi || context?.cubejsApi;
30+
const cubeApi = options.cubeApi || options.cubejsApi || context?.cubeApi || context?.cubejsApi;
2531

26-
if (!cubejsApi) {
32+
if (!cubeApi) {
2733
throw new Error('Cube API client is not provided');
2834
}
2935

@@ -35,7 +41,7 @@ export function useCubeQuery(query, options = {}) {
3541
setLoading(true);
3642

3743
try {
38-
const response = await cubejsApi.load(query, {
44+
const response = await cubeApi.load(query, {
3945
mutexObj: mutexRef.current,
4046
mutexKey: 'query',
4147
progressCallback,
@@ -62,9 +68,9 @@ export function useCubeQuery(query, options = {}) {
6268
useEffect(() => {
6369
const { skip = false, resetResultSetOnChange } = options;
6470

65-
const cubejsApi = options.cubejsApi || context?.cubejsApi;
71+
const cubeApi = options.cubeApi || options.cubejsApi || context?.cubeApi || context?.cubejsApi;
6672

67-
if (!cubejsApi) {
73+
if (!cubeApi) {
6874
throw new Error('Cube API client is not provided');
6975
}
7076

@@ -87,7 +93,7 @@ export function useCubeQuery(query, options = {}) {
8793
}
8894

8995
if (options.subscribe) {
90-
subscribeRequest = cubejsApi.subscribe(
96+
subscribeRequest = cubeApi.subscribe(
9197
query,
9298
{
9399
mutexObj: mutexRef.current,

0 commit comments

Comments
 (0)