Socket
Socket
Sign inDemoInstall

@cubejs-client/core

Package Overview
Dependencies
7
Maintainers
3
Versions
223
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.35.0 to 0.35.23

344

dist/cubejs-client-core.esm.js

@@ -46,3 +46,2 @@ import { v4 } from 'uuid';

}
if (key === 'order' && value) {

@@ -55,3 +54,2 @@ if (Array.isArray(value) && !value.length) {

}
return [key, value];

@@ -62,3 +60,4 @@ }).filter(Boolean));

const query = _query || {};
return removeEmptyQueryFields({ ...query,
return removeEmptyQueryFields({
...query,
filters: (query.filters || []).filter(f => f.operator),

@@ -73,3 +72,2 @@ timeDimensions: (query.timeDimensions || []).filter(td => !(!td.dateRange && !td.granularity))

const granularity = (query.timeDimensions || []).find(d => d.granularity);
if (granularity) {

@@ -88,3 +86,2 @@ return {

}
return {};

@@ -107,22 +104,20 @@ }

let newQuery = null;
if (!areQueriesEqual(query, oldQuery)) {
newQuery = query;
}
if (Array.isArray(newQuery) || Array.isArray(oldQuery)) {
return newState;
}
if (newQuery) {
if ((oldQuery.timeDimensions || []).length === 1 && (newQuery.timeDimensions || []).length === 1 && newQuery.timeDimensions[0].granularity && oldQuery.timeDimensions[0].granularity !== newQuery.timeDimensions[0].granularity) {
state = { ...state,
state = {
...state,
sessionGranularity: newQuery.timeDimensions[0].granularity
};
}
if ((oldQuery.measures || []).length === 0 && (newQuery.measures || []).length > 0 || (oldQuery.measures || []).length === 1 && (newQuery.measures || []).length === 1 && oldQuery.measures[0] !== newQuery.measures[0]) {
const [td] = newQuery.timeDimensions || [];
const defaultTimeDimension = meta.defaultTimeDimensionNameFor(newQuery.measures[0]);
newQuery = { ...newQuery,
newQuery = {
...newQuery,
timeDimensions: defaultTimeDimension ? [{

@@ -134,3 +129,4 @@ dimension: defaultTimeDimension,

};
return { ...state,
return {
...state,
pivotConfig: null,

@@ -142,10 +138,12 @@ shouldApplyHeuristicOrder: true,

}
if ((oldQuery.dimensions || []).length === 0 && (newQuery.dimensions || []).length > 0) {
newQuery = { ...newQuery,
timeDimensions: (newQuery.timeDimensions || []).map(td => ({ ...td,
newQuery = {
...newQuery,
timeDimensions: (newQuery.timeDimensions || []).map(td => ({
...td,
granularity: undefined
}))
};
return { ...state,
return {
...state,
pivotConfig: null,

@@ -157,10 +155,12 @@ shouldApplyHeuristicOrder: true,

}
if ((oldQuery.dimensions || []).length > 0 && (newQuery.dimensions || []).length === 0) {
newQuery = { ...newQuery,
timeDimensions: (newQuery.timeDimensions || []).map(td => ({ ...td,
newQuery = {
...newQuery,
timeDimensions: (newQuery.timeDimensions || []).map(td => ({
...td,
granularity: td.granularity || granularity
}))
};
return { ...state,
return {
...state,
pivotConfig: null,

@@ -172,9 +172,10 @@ shouldApplyHeuristicOrder: true,

}
if (((oldQuery.dimensions || []).length > 0 || (oldQuery.measures || []).length > 0) && (newQuery.dimensions || []).length === 0 && (newQuery.measures || []).length === 0) {
newQuery = { ...newQuery,
newQuery = {
...newQuery,
timeDimensions: [],
filters: []
};
return { ...state,
return {
...state,
pivotConfig: null,

@@ -186,15 +187,15 @@ shouldApplyHeuristicOrder: true,

}
return state;
}
if (state.chartType) {
const newChartType = state.chartType;
if ((newChartType === 'line' || newChartType === 'area') && (oldQuery.timeDimensions || []).length === 1 && !oldQuery.timeDimensions[0].granularity) {
const [td] = oldQuery.timeDimensions;
return { ...state,
return {
...state,
pivotConfig: null,
query: { ...oldQuery,
timeDimensions: [{ ...td,
query: {
...oldQuery,
timeDimensions: [{
...td,
granularity

@@ -205,10 +206,12 @@ }]

}
if ((newChartType === 'pie' || newChartType === 'table' || newChartType === 'number') && (oldQuery.timeDimensions || []).length === 1 && oldQuery.timeDimensions[0].granularity) {
const [td] = oldQuery.timeDimensions;
return { ...state,
return {
...state,
pivotConfig: null,
shouldApplyHeuristicOrder: true,
query: { ...oldQuery,
timeDimensions: [{ ...td,
query: {
...oldQuery,
timeDimensions: [{
...td,
granularity: undefined

@@ -220,3 +223,2 @@ }]

}
return state;

@@ -228,7 +230,7 @@ }

}
return (Array.isArray(query) ? query : [query]).every(q => q.measures && q.measures.length || q.dimensions && q.dimensions.length || q.timeDimensions && q.timeDimensions.length);
}
function movePivotItem(pivotConfig, sourceIndex, destinationIndex, sourceAxis, destinationAxis) {
const nextPivotConfig = { ...pivotConfig,
const nextPivotConfig = {
...pivotConfig,
x: [...pivotConfig.x],

@@ -239,3 +241,2 @@ y: [...pivotConfig.y]

const lastIndex = nextPivotConfig[destinationAxis].length - 1;
if (id === 'measures') {

@@ -248,3 +249,2 @@ destinationIndex = lastIndex + 1;

}
nextPivotConfig[sourceAxis].splice(sourceIndex, 1);

@@ -265,3 +265,2 @@ nextPivotConfig[destinationAxis].splice(destinationIndex, 0, id);

}
return [...memo, filter];

@@ -286,3 +285,4 @@ }, []);

ids.add(memberId);
nextOrderMembers.push({ ...indexedOrderMembers[memberId],
nextOrderMembers.push({
...indexedOrderMembers[memberId],
order: currentOrder

@@ -294,3 +294,4 @@ });

if (!ids.has(member.id)) {
nextOrderMembers.push({ ...member,
nextOrderMembers.push({
...member,
order: member.order || 'none'

@@ -304,3 +305,2 @@ });

const nonNullValues = values.filter(value => value != null);
if (pivotConfig && pivotConfig.aliasSeries && pivotConfig.aliasSeries[index]) {

@@ -311,13 +311,13 @@ return [pivotConfig.aliasSeries[index], ...nonNullValues];

}
return nonNullValues;
}
dayjs.extend(quarterOfYear); // When granularity is week, weekStart Value must be 1. However, since the client can change it globally (https://day.js.org/docs/en/i18n/changing-locale)
dayjs.extend(quarterOfYear);
// When granularity is week, weekStart Value must be 1. However, since the client can change it globally (https://day.js.org/docs/en/i18n/changing-locale)
// So the function below has been added.
const internalDayjs = (...args) => dayjs(...args).locale({ ...en,
const internalDayjs = (...args) => dayjs(...args).locale({
...en,
weekStart: 1
});
const TIME_SERIES = {

@@ -335,3 +335,2 @@ day: range => range.by('d').map(d => d.format('YYYY-MM-DDT00:00:00.000')),

const LocalDateRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z?$/;
const groupByToPairs = keyFn => {

@@ -342,7 +341,5 @@ const acc = new Map();

const key = keyFn(row);
if (!acc.has(key)) {
acc.set(key, []);
}
acc.get(key).push(row);

@@ -353,3 +350,2 @@ });

};
const unnest = arr => {

@@ -362,3 +358,2 @@ const res = [];

};
const dayRange = (from, to) => ({

@@ -369,3 +364,2 @@ by: value => {

const end = internalDayjs(to);
while (start.isBefore(end) || start.isSame(end)) {

@@ -375,3 +369,2 @@ results.push(start);

}
return results;

@@ -388,3 +381,2 @@ },

};
class ResultSet {

@@ -394,14 +386,10 @@ static measureFromAxis(axisValues) {

}
static timeDimensionMember(td) {
return `${td.dimension}.${td.granularity}`;
}
static deserialize(data, options = {}) {
return new ResultSet(data.loadResponse, options);
}
constructor(loadResponse, options = {}) {
this.loadResponse = loadResponse;
if (this.loadResponse.queryType != null) {

@@ -412,3 +400,4 @@ this.queryType = loadResponse.queryType;

this.queryType = QUERY_TYPE.REGULAR_QUERY;
this.loadResponse.pivotQuery = { ...loadResponse.query,
this.loadResponse.pivotQuery = {
...loadResponse.query,
queryType: this.queryType

@@ -418,7 +407,5 @@ };

}
if (!Object.values(QUERY_TYPE).includes(this.queryType)) {
throw new Error('Unknown query type');
}
this.parseDateMeasures = options.parseDateMeasures;

@@ -428,3 +415,2 @@ this.options = options;

}
drillDown(drillDownLocator, pivotConfig) {

@@ -434,7 +420,5 @@ if (this.queryType === QUERY_TYPE.COMPARE_DATE_RANGE_QUERY) {

}
if (this.queryType === QUERY_TYPE.BLENDING_QUERY) {
throw new Error('Data blending drillDown query is not currently supported');
}
const {

@@ -459,11 +443,8 @@ query

let [, measureName] = values.find(([member]) => member === 'measures') || [];
if (measureName === undefined) {
[measureName] = Object.keys(measures);
}
if (!(measures[measureName] && measures[measureName].drillMembers || []).length) {
return null;
}
const filters = [{

@@ -476,3 +457,2 @@ member: measureName,

const [cubeName, dimension, granularity] = member.split('.');
if (granularity !== undefined) {

@@ -482,3 +462,2 @@ const range = dayRange(value, value).snapTo(granularity);

let dateRange = [range.start, range.end];
if (originalTimeDimension?.dateRange) {

@@ -488,3 +467,2 @@ const [originalStart, originalEnd] = originalTimeDimension.dateRange;

}
timeDimensions.push({

@@ -507,8 +485,7 @@ dimension: [cubeName, dimension].join('.'),

});
if (timeDimensions.length === 0 && query.timeDimensions.length > 0 && query.timeDimensions[0].granularity == null) {
timeDimensions.push(query.timeDimensions[0]);
}
return { ...measures[measureName].drillMembersGrouped,
return {
...measures[measureName].drillMembersGrouped,
filters,

@@ -523,3 +500,2 @@ ...(segments.length > 0 ? {

}
series(pivotConfig) {

@@ -543,3 +519,2 @@ return this.seriesNames(pivotConfig).map(({

}
axisValues(axis, resultIndex = 0) {

@@ -551,11 +526,8 @@ const {

const value = measure => axis.filter(d => d !== 'measures').map(d => row[d] != null ? row[d] : null).concat(measure ? [measure] : []);
if (axis.find(d => d === 'measures') && (query.measures || []).length) {
return query.measures.map(value);
}
return [value()];
};
}
axisValuesString(axisValues, delimiter) {

@@ -571,6 +543,4 @@ const formatValue = v => {

};
return axisValues.map(formatValue).join(delimiter || ', ');
}
static getNormalizedPivotConfig(query = {}, pivotConfig = null) {

@@ -596,5 +566,3 @@ const defaultPivotConfig = {

pivotConfig = mergeDeepLeft(pivotConfig, defaultPivotConfig);
const substituteTimeDimensionMembers = axis => axis.map(subDim => timeDimensions.find(td => td.dimension === subDim) && !dimensions.find(d => d === subDim) ? ResultSet.timeDimensionMember(query.timeDimensions.find(td => td.dimension === subDim)) : subDim);
pivotConfig.x = substituteTimeDimensionMembers(pivotConfig.x);

@@ -604,16 +572,11 @@ pivotConfig.y = substituteTimeDimensionMembers(pivotConfig.y);

const allDimensions = timeDimensions.map(td => ResultSet.timeDimensionMember(td)).concat(dimensions);
const dimensionFilter = key => allDimensions.includes(key) || key === 'measures';
pivotConfig.x = pivotConfig.x.concat(allDimensions.filter(d => !allIncludedDimensions.includes(d) && d !== 'compareDateRange')).filter(dimensionFilter);
pivotConfig.y = pivotConfig.y.filter(dimensionFilter);
if (!pivotConfig.x.concat(pivotConfig.y).find(d => d === 'measures')) {
pivotConfig.y.push('measures');
}
if (dimensions.includes('compareDateRange') && !pivotConfig.y.concat(pivotConfig.x).includes('compareDateRange')) {
pivotConfig.y.unshift('compareDateRange');
}
if (!measures.length) {

@@ -623,10 +586,7 @@ pivotConfig.x = pivotConfig.x.filter(d => d !== 'measures');

}
return pivotConfig;
}
normalizePivotConfig(pivotConfig) {
return ResultSet.getNormalizedPivotConfig(this.loadResponse.pivotQuery, pivotConfig);
}
timeSeries(timeDimension, resultIndex) {

@@ -636,7 +596,5 @@ if (!timeDimension.granularity) {

}
let {
dateRange
} = timeDimension;
if (!dateRange) {

@@ -647,18 +605,13 @@ const member = ResultSet.timeDimensionMember(timeDimension);

}
if (!dateRange) {
return null;
}
const padToDay = timeDimension.dateRange ? timeDimension.dateRange.find(d => d.match(DateRegex)) : !['hour', 'minute', 'second'].includes(timeDimension.granularity);
const [start, end] = dateRange;
const range = dayRange(start, end);
if (!TIME_SERIES[timeDimension.granularity]) {
throw new Error(`Unsupported time granularity: ${timeDimension.granularity}`);
}
return TIME_SERIES[timeDimension.granularity](padToDay ? range.snapTo('d') : range);
}
pivot(pivotConfig) {

@@ -669,3 +622,2 @@ pivotConfig = this.normalizePivotConfig(pivotConfig);

} = this.loadResponse;
const pivotImpl = (resultIndex = 0) => {

@@ -675,8 +627,5 @@ let groupByXAxis = groupByToPairs(({

}) => this.axisValuesString(xValues));
const measureValue = (row, measure) => row[measure] || 0;
if (pivotConfig.fillMissingDates && pivotConfig.x.length === 1 && equals(pivotConfig.x, (query.timeDimensions || []).filter(td => Boolean(td.granularity)).map(td => ResultSet.timeDimensionMember(td)))) {
const series = this.loadResponses.map(loadResponse => this.timeSeries(loadResponse.query.timeDimensions[0], resultIndex));
if (series[0]) {

@@ -694,3 +643,2 @@ groupByXAxis = rows => {

}
const xGrouped = pipe(map(row => this.axisValues(pivotConfig.x, resultIndex)(row).map(xValues => ({

@@ -741,7 +689,5 @@ xValues,

};
const pivots = this.loadResponses.length > 1 ? this.loadResponses.map((_, index) => pivotImpl(index)) : [];
return pivots.length ? this.mergePivots(pivots, pivotConfig.joinDateRange) : pivotImpl();
}
mergePivots(pivots, joinDateRange) {

@@ -757,3 +703,2 @@ const minLengthPivot = pivots.reduce((memo, current) => memo != null && current.length >= memo.length ? memo : current, null);

}
pivotedRows(pivotConfig) {

@@ -763,3 +708,2 @@ // TODO

}
chartPivot(pivotConfig) {

@@ -772,8 +716,5 @@ const validate = value => {

}
return value;
};
const duplicateMeasures = new Set();
if (this.queryType === QUERY_TYPE.BLENDING_QUERY) {

@@ -785,3 +726,2 @@ const allMeasures = flatten(this.loadResponses.map(({

}
return this.pivot(pivotConfig).map(({

@@ -802,3 +742,2 @@ xValues,

}
tablePivot(pivotConfig) {

@@ -812,11 +751,10 @@ const normalizedPivotConfig = this.normalizePivotConfig(pivotConfig || {});

}
tableColumns(pivotConfig) {
const normalizedPivotConfig = this.normalizePivotConfig(pivotConfig || {});
const annotations = pipe(pluck('annotation'), reduce(mergeDeepLeft(), {}))(this.loadResponses);
const flatMeta = Object.values(annotations).reduce((a, b) => ({ ...a,
const flatMeta = Object.values(annotations).reduce((a, b) => ({
...a,
...b
}), {});
const schema = {};
const extractFields = key => {

@@ -839,3 +777,2 @@ const {

};
const pivot = this.pivot(normalizedPivotConfig);

@@ -855,3 +792,2 @@ (pivot[0] && pivot[0].yValuesArray || []).forEach(([yValues]) => {

});
const toColumns = (item = {}, path = []) => {

@@ -861,3 +797,2 @@ if (Object.keys(item).length === 0) {

}
return Object.values(item).map(({

@@ -874,5 +809,5 @@ key,

const dimensionValue = key !== currentItem.memberId || title == null ? key : '';
if (!children.length) {
return { ...fields,
return {
...fields,
key,

@@ -884,4 +819,4 @@ dataIndex: [...path, key].join(),

}
return { ...fields,
return {
...fields,
key,

@@ -894,12 +829,11 @@ title: [title, dimensionValue].join(' ').trim(),

};
let otherColumns = [];
if (!pivot.length && normalizedPivotConfig.y.includes('measures')) {
otherColumns = (this.loadResponses[0].query.measures || []).map(key => ({ ...extractFields(key),
otherColumns = (this.loadResponses[0].query.measures || []).map(key => ({
...extractFields(key),
dataIndex: key
}));
} // Syntatic column to display the measure value
}
// Syntatic column to display the measure value
if (!normalizedPivotConfig.y.length && normalizedPivotConfig.x.includes('measures')) {

@@ -914,3 +848,2 @@ otherColumns.push({

}
return normalizedPivotConfig.x.map(key => {

@@ -926,4 +859,4 @@ if (key === 'measures') {

}
return { ...extractFields(key),
return {
...extractFields(key),
dataIndex: key

@@ -933,7 +866,5 @@ };

}
totalRow(pivotConfig) {
return this.chartPivot(pivotConfig)[0];
}
categories(pivotConfig) {

@@ -943,3 +874,2 @@ // TODO

}
seriesNames(pivotConfig) {

@@ -950,3 +880,2 @@ pivotConfig = this.normalizePivotConfig(pivotConfig);

const duplicateMeasures = new Set();
if (this.queryType === QUERY_TYPE.BLENDING_QUERY) {

@@ -958,3 +887,2 @@ const allMeasures = flatten(this.loadResponses.map(({

}
return seriesNames.map((axisValues, i) => {

@@ -970,3 +898,2 @@ const aliasedAxis = aliasSeries(axisValues, i, pivotConfig, duplicateMeasures);

}
query() {

@@ -976,14 +903,10 @@ if (this.queryType !== QUERY_TYPE.REGULAR_QUERY) {

}
return this.loadResponses[0].query;
}
pivotQuery() {
return this.loadResponse.pivotQuery || null;
}
totalRows() {
return this.loadResponses[0].total;
}
rawData() {

@@ -993,6 +916,4 @@ if (this.queryType !== QUERY_TYPE.REGULAR_QUERY) {

}
return this.loadResponses[0].data;
}
annotation() {

@@ -1002,6 +923,4 @@ if (this.queryType !== QUERY_TYPE.REGULAR_QUERY) {

}
return this.loadResponses[0].annotation;
}
timeDimensionBackwardCompatibleData(resultIndex) {

@@ -1011,3 +930,2 @@ if (resultIndex === undefined) {

}
if (!this.backwardCompatibleData[resultIndex]) {

@@ -1019,14 +937,14 @@ const {

const timeDimensions = (query.timeDimensions || []).filter(td => Boolean(td.granularity));
this.backwardCompatibleData[resultIndex] = data.map(row => ({ ...row,
this.backwardCompatibleData[resultIndex] = data.map(row => ({
...row,
...fromPairs(Object.keys(row).filter(field => timeDimensions.find(d => d.dimension === field) && !row[ResultSet.timeDimensionMember(timeDimensions.find(d => d.dimension === field))]).map(field => [ResultSet.timeDimensionMember(timeDimensions.find(d => d.dimension === field)), row[field]]))
}));
}
return this.backwardCompatibleData[resultIndex];
}
decompose() {
return this.loadResponses.map(result => new ResultSet({
queryType: QUERY_TYPE.REGULAR_QUERY,
pivotQuery: { ...result.query,
pivotQuery: {
...result.query,
queryType: QUERY_TYPE.REGULAR_QUERY

@@ -1037,3 +955,2 @@ },

}
serialize() {

@@ -1044,3 +961,2 @@ return {

}
}

@@ -1052,11 +968,8 @@

}
rawQuery() {
return this.sqlQuery.sql;
}
sql() {
return this.rawQuery().sql[0];
}
}

@@ -1067,5 +980,3 @@

*/
const memberMap = memberArray => fromPairs(memberArray.map(m => [m.name, m]));
const operators = {

@@ -1154,6 +1065,6 @@ string: [{

};
/**
* Contains information about available cubes and it's members.
*/
class Meta {

@@ -1172,7 +1083,5 @@ constructor(metaResponse) {

}
membersForQuery(query, memberType) {
return unnest$1(this.cubes.map(c => c[memberType])).sort((a, b) => a.title > b.title ? 1 : -1);
}
membersGroupedByCube() {

@@ -1183,7 +1092,5 @@ const memberKeys = ['measures', 'dimensions', 'segments', 'timeDimensions'];

let members = cube[key];
if (key === 'timeDimensions') {
members = cube.dimensions.filter(m => m.type === 'time');
}
memo[key] = [...memo[key], {

@@ -1205,6 +1112,4 @@ cubeName: cube.name,

}
resolveMember(memberName, memberType) {
const [cube] = memberName.split('.');
if (!this.cubesMap[cube]) {

@@ -1216,6 +1121,4 @@ return {

}
const memberTypes = Array.isArray(memberType) ? memberType : [memberType];
const member = memberTypes.map(type => this.cubesMap[cube][type] && this.cubesMap[cube][type][memberName]).find(m => m);
if (!member) {

@@ -1227,16 +1130,11 @@ return {

}
return member;
}
defaultTimeDimensionNameFor(memberName) {
const [cube] = memberName.split('.');
if (!this.cubesMap[cube]) {
return null;
}
return Object.keys(this.cubesMap[cube].dimensions || {}).find(d => this.cubesMap[cube].dimensions[d].type === 'time');
}
filterOperatorsForMember(memberName, memberType) {

@@ -1246,3 +1144,2 @@ const member = this.resolveMember(memberName, memberType);

}
}

@@ -1254,11 +1151,8 @@

}
stage() {
return this.progressResponse.stage;
}
timeElapsed() {
return this.progressResponse.timeElapsed;
}
}

@@ -1280,3 +1174,2 @@

}
request(method, {

@@ -1289,3 +1182,4 @@ baseRequestId,

[k]: typeof params[k] === 'object' ? JSON.stringify(params[k]) : params[k]
})).reduce((a, b) => ({ ...a,
})).reduce((a, b) => ({
...a,
...b

@@ -1295,10 +1189,9 @@ }), {}));

const requestMethod = this.method || (url.length < 2000 ? 'GET' : 'POST');
if (requestMethod === 'POST') {
url = `${this.apiUrl}/${method}`;
this.headers['Content-Type'] = 'application/json';
} // Currently, all methods make GET requests. If a method makes a request with a body payload,
}
// Currently, all methods make GET requests. If a method makes a request with a body payload,
// remember to add {'Content-Type': 'application/json'} to the header.
const runRequest = () => fetch(url, {

@@ -1314,3 +1207,2 @@ method: requestMethod,

});
return {

@@ -1321,5 +1213,3 @@ /* eslint no-unsafe-finally: off */

error: 'network Error' // add default error message
};
try {

@@ -1331,6 +1221,4 @@ result = await runRequest();

}
};
}
}

@@ -1344,3 +1232,2 @@

}
}

@@ -1350,6 +1237,6 @@

const MUTEX_ERROR = 'Mutex has been changed';
/**
* Query result dataset formats enum.
*/
const ResultType = {

@@ -1359,3 +1246,2 @@ DEFAULT: 'default',

};
function mutexPromise(promise) {

@@ -1372,3 +1258,2 @@ return new Promise(async (resolve, reject) => {

}
class CubeApi {

@@ -1380,9 +1265,6 @@ constructor(apiToken, options) {

}
options = options || {};
if (!options.transport && !options.apiUrl) {
throw new Error('The `apiUrl` option is required');
}
this.apiToken = apiToken;

@@ -1402,5 +1284,5 @@ this.apiUrl = options.apiUrl;

this.parseDateMeasures = options.parseDateMeasures;
this.castNumerics = typeof options.castNumerics === 'boolean' ? options.castNumerics : false;
this.updateAuthorizationPromise = null;
}
request(method, params) {

@@ -1412,6 +1294,4 @@ return this.transport.request(method, {

}
loadMethod(request, toResult, options, callback) {
const mutexValue = ++mutexCounter;
if (typeof options === 'function' && !callback) {

@@ -1421,31 +1301,22 @@ callback = options;

}
options = options || {};
const mutexKey = options.mutexKey || 'default';
if (options.mutexObj) {
options.mutexObj[mutexKey] = mutexValue;
}
const requestPromise = this.updateTransportAuthorization().then(() => request());
let skipAuthorizationUpdate = true;
let unsubscribed = false;
const checkMutex = async () => {
const requestInstance = await requestPromise;
if (options.mutexObj && options.mutexObj[mutexKey] !== mutexValue) {
unsubscribed = true;
if (requestInstance.unsubscribe) {
await requestInstance.unsubscribe();
}
throw MUTEX_ERROR;
}
};
const loadImpl = async (response, next) => {
const requestInstance = await requestPromise;
const subscribeNext = async () => {

@@ -1460,6 +1331,4 @@ if (options.subscribe && !unsubscribed) {

}
return null;
};
const continueWait = async wait => {

@@ -1470,15 +1339,10 @@ if (!unsubscribed) {

}
return next();
}
return null;
};
if (options.subscribe && !skipAuthorizationUpdate) {
await this.updateTransportAuthorization();
}
skipAuthorizationUpdate = false;
if (response.status === 502) {

@@ -1488,6 +1352,4 @@ await checkMutex();

}
let body = {};
let text = '';
try {

@@ -1499,22 +1361,15 @@ text = await response.text();

}
if (body.error === 'Continue wait') {
await checkMutex();
if (options.progressCallback) {
options.progressCallback(new ProgressResult(body));
}
return continueWait();
}
if (response.status !== 200) {
await checkMutex();
if (!options.subscribe && requestInstance.unsubscribe) {
await requestInstance.unsubscribe();
}
const error = new RequestError(body.error, body, response.status); // TODO error class
if (callback) {

@@ -1525,14 +1380,9 @@ callback(error);

}
return subscribeNext();
}
await checkMutex();
if (!options.subscribe && requestInstance.unsubscribe) {
await requestInstance.unsubscribe();
}
const result = toResult(body);
if (callback) {

@@ -1543,8 +1393,5 @@ callback(null, result);

}
return subscribeNext();
};
const promise = requestPromise.then(requestInstance => mutexPromise(requestInstance.subscribe(loadImpl)));
if (callback) {

@@ -1555,7 +1402,5 @@ return {

unsubscribed = true;
if (requestInstance.unsubscribe) {
return requestInstance.unsubscribe();
}
return null;

@@ -1568,3 +1413,2 @@ }

}
async updateTransportAuthorization() {

@@ -1575,3 +1419,2 @@ if (this.updateAuthorizationPromise) {

}
if (typeof this.apiToken === 'function') {

@@ -1581,7 +1424,5 @@ this.updateAuthorizationPromise = new Promise(async (resolve, reject) => {

const token = await this.apiToken();
if (this.transport.authorization !== token) {
this.transport.authorization = token;
}
resolve();

@@ -1597,2 +1438,3 @@ } catch (error) {

}
/**

@@ -1605,7 +1447,6 @@ * Add system properties to a query object.

*/
patchQueryInternal(query, responseFormat) {
if (responseFormat === ResultType.COMPACT && query.responseFormat !== ResultType.COMPACT) {
return { ...query,
return {
...query,
responseFormat: ResultType.COMPACT

@@ -1617,2 +1458,3 @@ };

}
/**

@@ -1625,4 +1467,2 @@ * Process result fetched from the gateway#load method according

*/
loadResponseInternal(response, options = {}) {

@@ -1632,3 +1472,4 @@ if (response.results.length) {

response.results.forEach(result => {
const numericMembers = Object.entries({ ...result.annotation.measures,
const numericMembers = Object.entries({
...result.annotation.measures,
...result.annotation.dimensions

@@ -1639,3 +1480,2 @@ }).map(([k, v]) => {

}
return undefined;

@@ -1653,3 +1493,2 @@ }).filter(Boolean);

}
if (response.results[0].query.responseFormat && response.results[0].query.responseFormat === ResultType.COMPACT) {

@@ -1669,3 +1508,2 @@ response.results.forEach((result, j) => {

}
return new ResultSet(response, {

@@ -1675,4 +1513,7 @@ parseDateMeasures: this.parseDateMeasures

}
load(query, options, callback, responseFormat = ResultType.DEFAULT) {
options = {
castNumerics: this.castNumerics,
...options
};
if (responseFormat === ResultType.COMPACT) {

@@ -1685,3 +1526,2 @@ if (Array.isArray(query)) {

}
return this.loadMethod(() => this.request('load', {

@@ -1692,4 +1532,7 @@ query,

}
subscribe(query, options, callback, responseFormat = ResultType.DEFAULT) {
options = {
castNumerics: this.castNumerics,
...options
};
if (responseFormat === ResultType.COMPACT) {

@@ -1702,11 +1545,10 @@ if (Array.isArray(query)) {

}
return this.loadMethod(() => this.request('subscribe', {
query,
queryType: 'multi'
}), response => this.loadResponseInternal(response, options), { ...options,
}), response => this.loadResponseInternal(response, options), {
...options,
subscribe: true
}, callback);
}
sql(query, options, callback) {

@@ -1717,7 +1559,5 @@ return this.loadMethod(() => this.request('sql', {

}
meta(options, callback) {
return this.loadMethod(() => this.request('meta'), body => new Meta(body), options, callback);
}
dryRun(query, options, callback) {

@@ -1728,5 +1568,3 @@ return this.loadMethod(() => this.request('dry-run', {

}
}
var index = ((apiToken, options) => new CubeApi(apiToken, options));

@@ -1733,0 +1571,0 @@

@@ -83,2 +83,3 @@ /**

resType?: 'default' | 'compact';
castNumerics?: boolean;
};

@@ -85,0 +86,0 @@

{
"name": "@cubejs-client/core",
"version": "0.35.0",
"version": "0.35.23",
"engines": {},

@@ -48,3 +48,3 @@ "repository": {

},
"gitHead": "75bc6c3d96392b7823e714d17ac85ab435e55b05"
"gitHead": "50ddcfc277feb55a8781129e7b3a5579e00ea334"
}

@@ -59,2 +59,3 @@ import { v4 as uuidv4 } from 'uuid';

this.parseDateMeasures = options.parseDateMeasures;
this.castNumerics = typeof options.castNumerics === 'boolean' ? options.castNumerics : false;

@@ -312,2 +313,7 @@ this.updateAuthorizationPromise = null;

load(query, options, callback, responseFormat = ResultType.DEFAULT) {
options = {
castNumerics: this.castNumerics,
...options
};
if (responseFormat === ResultType.COMPACT) {

@@ -332,2 +338,7 @@ if (Array.isArray(query)) {

subscribe(query, options, callback, responseFormat = ResultType.DEFAULT) {
options = {
castNumerics: this.castNumerics,
...options
};
if (responseFormat === ResultType.COMPACT) {

@@ -334,0 +345,0 @@ if (Array.isArray(query)) {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc