Socket
Socket
Sign inDemoInstall

@cubejs-client/core

Package Overview
Dependencies
Maintainers
3
Versions
226
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cubejs-client/core - npm Package Compare versions

Comparing version 0.29.23 to 0.29.29

src/index.test.js

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

## [0.29.29](https://github.com/cube-js/cube.js/compare/v0.29.28...v0.29.29) (2022-03-03)
### Features
* Compact JSON array based response data format support ([#4046](https://github.com/cube-js/cube.js/issues/4046)) ([e74d73c](https://github.com/cube-js/cube.js/commit/e74d73c140f56e71a24c35a5f03e9af63022bced)), closes [#1](https://github.com/cube-js/cube.js/issues/1)
## [0.29.23](https://github.com/cube-js/cube.js/compare/v0.29.22...v0.29.23) (2022-01-26)

@@ -8,0 +19,0 @@

15

index.d.ts

@@ -30,3 +30,8 @@ /**

export interface ITransportResponse<R> {
subscribe: <CBResult>(cb: (result: R, resubscribe: () => Promise<CBResult>) => CBResult) => Promise<CBResult>;
subscribe: <CBResult>(
cb: (
result: R,
resubscribe: () => Promise<CBResult>
) => CBResult
) => Promise<CBResult>;
// Optional, supported in WebSocketTransport

@@ -37,3 +42,6 @@ unsubscribe?: () => Promise<void>;

export interface ITransport<R> {
request(method: string, params: Record<string, unknown>): ITransportResponse<R>;
request(
method: string,
params: Record<string, unknown>
): ITransportResponse<R>;
}

@@ -85,2 +93,3 @@

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

@@ -796,2 +805,3 @@

ungrouped?: boolean;
responseFormat?: 'compact' | 'default'
}

@@ -1000,2 +1010,3 @@

load(query: Query | Query[], options?: LoadMethodOptions, callback?: LoadMethodCallback<ResultSet>): void;
load(query: Query | Query[], options?: LoadMethodOptions, callback?: LoadMethodCallback<ResultSet>, responseFormat?: string): Promise<ResultSet>;

@@ -1002,0 +1013,0 @@ /**

5

package.json
{
"name": "@cubejs-client/core",
"version": "0.29.23",
"version": "0.29.29",
"engines": {},

@@ -16,2 +16,3 @@ "repository": {

"dependencies": {
"@babel/plugin-transform-runtime": "^7.17.0",
"@babel/runtime": "^7.1.2",

@@ -49,3 +50,3 @@ "core-js": "^3.6.5",

},
"gitHead": "da516571691c103ecbd035c3319653766622b083"
"gitHead": "23638ee42cceb8fc80e821486ab30825e2b9a483"
}

@@ -13,2 +13,10 @@ import { v4 as uuidv4 } from 'uuid';

/**
* Query result dataset formats enum.
*/
const ResultType = {
DEFAULT: 'default',
COMPACT: 'compact'
};
function mutexPromise(promise) {

@@ -57,3 +65,6 @@ return new Promise(async (resolve, reject) => {

request(method, params) {
return this.transport.request(method, { baseRequestId: uuidv4(), ...params });
return this.transport.request(method, {
baseRequestId: uuidv4(),
...params
});
}

@@ -75,3 +86,5 @@

const requestPromise = this.updateTransportAuthorization().then(() => request());
const requestPromise = this
.updateTransportAuthorization()
.then(() => request());

@@ -84,3 +97,6 @@ let skipAuthorizationUpdate = true;

if (options.mutexObj && options.mutexObj[mutexKey] !== mutexValue) {
if (
options.mutexObj &&
options.mutexObj[mutexKey] !== mutexValue
) {
unsubscribed = true;

@@ -220,9 +236,73 @@ if (requestInstance.unsubscribe) {

load(query, options, callback) {
/**
* Add system properties to a query object.
* @param {Query} query
* @param {string} responseFormat
* @returns {void}
* @private
*/
patchQueryInternal(query, responseFormat) {
if (
responseFormat === ResultType.COMPACT &&
query.responseFormat !== ResultType.COMPACT
) {
query.responseFormat = ResultType.COMPACT;
}
}
/**
* Process result fetched from the gateway#load method according
* to the network protocol.
* @param {*} response
* @returns ResultSet
* @private
*/
loadResponseInternal(response) {
if (
response.results.length &&
response.results[0].query.responseFormat &&
response.results[0].query.responseFormat === ResultType.COMPACT
) {
response.results.forEach((result, j) => {
const data = [];
result.data.dataset.forEach((r) => {
const row = {};
result.data.members.forEach((m, i) => {
row[m] = r[i];
});
data.push(row);
});
response.results[j].data = data;
});
}
return new ResultSet(response, {
parseDateMeasures: this.parseDateMeasures
});
}
/**
* Fetch data for the passed `query`. Operates with the
* `ApiGateway#load` method to fetch the data.
* @param {Query | Query[]} query
* @param {LoadMethodOptions | undefined} options
* @param {LoadMethodCallback<ResultSet> | undefined} callback
* @param {string} responseFormat
* @returns {undefined | Promise<ResultSet>}
*/
load(query, options, callback, responseFormat = ResultType.DEFAULT) {
if (responseFormat === ResultType.COMPACT) {
if (Array.isArray(query)) {
query.forEach((q) => {
this.patchQueryInternal(q, ResultType.COMPACT);
});
} else {
this.patchQueryInternal(query, ResultType.COMPACT);
}
}
return this.loadMethod(
() => this.request('load', {
query,
queryType: 'multi'
queryType: 'multi',
}),
(response) => new ResultSet(response, { parseDateMeasures: this.parseDateMeasures }),
this.loadResponseInternal.bind(this),
options,

@@ -233,2 +313,33 @@ callback

/**
* Allows you to fetch data and receive updates over time. Operates
* with the `ApiGateway#load` method to fetch the data.
* @link real-time-data-fetch
* @param {Query | Query[]} query
* @param {LoadMethodOptions | null} options
* @param {LoadMethodCallback<ResultSet> | undefined} callback
* @param {string} responseFormat
* @returns {void}
*/
subscribe(query, options, callback, responseFormat = ResultType.DEFAULT) {
if (responseFormat === ResultType.COMPACT) {
if (Array.isArray(query)) {
query.forEach((q) => {
this.patchQueryInternal(q, ResultType.COMPACT);
});
} else {
this.patchQueryInternal(query, ResultType.COMPACT);
}
}
return this.loadMethod(
() => this.request('subscribe', {
query,
queryType: 'multi',
}),
this.loadResponseInternal.bind(this),
{ ...options, subscribe: true },
callback
);
}
sql(query, options, callback) {

@@ -260,14 +371,2 @@ return this.loadMethod(

}
subscribe(query, options, callback) {
return this.loadMethod(
() => this.request('subscribe', {
query,
queryType: 'multi'
}),
(body) => new ResultSet(body, { parseDateMeasures: this.parseDateMeasures }),
{ ...options, subscribe: true },
callback
);
}
}

@@ -274,0 +373,0 @@

@@ -0,1 +1,9 @@

/**
* @license Apache-2.0
* @copyright Cube Dev, Inc.
* @fileoverview ResultSet class unit tests.
*/
/* globals describe,test,expect */
import 'jest';

@@ -2,0 +10,0 @@ import ResultSet from '../ResultSet';

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

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc