@cubejs-client/core
Advanced tools
Comparing version 0.29.23 to 0.29.29
@@ -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 @@ |
@@ -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 @@ /** |
{ | ||
"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" | ||
} |
135
src/index.js
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1826732
31
21286
8
+ Added@ampproject/remapping@2.3.0(transitive)
+ Added@babel/code-frame@7.25.7(transitive)
+ Added@babel/compat-data@7.25.7(transitive)
+ Added@babel/core@7.25.7(transitive)
+ Added@babel/generator@7.25.7(transitive)
+ Added@babel/helper-compilation-targets@7.25.7(transitive)
+ Added@babel/helper-define-polyfill-provider@0.6.2(transitive)
+ Added@babel/helper-module-imports@7.25.7(transitive)
+ Added@babel/helper-module-transforms@7.25.7(transitive)
+ Added@babel/helper-plugin-utils@7.25.7(transitive)
+ Added@babel/helper-simple-access@7.25.7(transitive)
+ Added@babel/helper-string-parser@7.25.7(transitive)
+ Added@babel/helper-validator-identifier@7.25.7(transitive)
+ Added@babel/helper-validator-option@7.25.7(transitive)
+ Added@babel/helpers@7.25.7(transitive)
+ Added@babel/highlight@7.25.7(transitive)
+ Added@babel/parser@7.25.7(transitive)
+ Added@babel/plugin-transform-runtime@7.25.7(transitive)
+ Added@babel/template@7.25.7(transitive)
+ Added@babel/traverse@7.25.7(transitive)
+ Added@babel/types@7.25.7(transitive)
+ Added@jridgewell/gen-mapping@0.3.5(transitive)
+ Added@jridgewell/resolve-uri@3.1.2(transitive)
+ Added@jridgewell/set-array@1.2.1(transitive)
+ Added@jridgewell/sourcemap-codec@1.5.0(transitive)
+ Added@jridgewell/trace-mapping@0.3.25(transitive)
+ Addedansi-styles@3.2.1(transitive)
+ Addedbabel-plugin-polyfill-corejs2@0.4.11(transitive)
+ Addedbabel-plugin-polyfill-corejs3@0.10.6(transitive)
+ Addedbabel-plugin-polyfill-regenerator@0.6.2(transitive)
+ Addedbrowserslist@4.24.0(transitive)
+ Addedcaniuse-lite@1.0.30001667(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedconvert-source-map@2.0.0(transitive)
+ Addedcore-js-compat@3.38.1(transitive)
+ Addeddebug@4.3.7(transitive)
+ Addedelectron-to-chromium@1.5.32(transitive)
+ Addedescalade@3.2.0(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedgensync@1.0.0-beta.2(transitive)
+ Addedglobals@11.12.0(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedis-core-module@2.15.1(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedjsesc@3.0.2(transitive)
+ Addedjson5@2.2.3(transitive)
+ Addedlodash.debounce@4.0.8(transitive)
+ Addedlru-cache@5.1.1(transitive)
+ Addedms@2.1.3(transitive)
+ Addednode-releases@2.0.18(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpicocolors@1.1.0(transitive)
+ Addedresolve@1.22.8(transitive)
+ Addedsemver@6.3.1(transitive)
+ Addedsupports-color@5.5.0(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedto-fast-properties@2.0.0(transitive)
+ Addedupdate-browserslist-db@1.1.1(transitive)
+ Addedyallist@3.1.1(transitive)