@cubejs-client/core 0.29.8 → 0.29.33
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/CHANGELOG.md +34 -0
- package/dist/cubejs-client-core.esm.js +122 -32
- package/dist/cubejs-client-core.esm.js.map +1 -1
- package/dist/cubejs-client-core.js +122 -32
- package/dist/cubejs-client-core.js.map +1 -1
- package/dist/cubejs-client-core.umd.js +157 -62
- package/dist/cubejs-client-core.umd.js.map +1 -1
- package/index.d.ts +19 -7
- package/package.json +3 -3
- package/src/index.js +118 -19
- package/src/index.test.js +454 -0
- package/src/tests/ResultSet.test.js +8 -0
|
@@ -6,8 +6,6 @@ require('core-js/modules/es.object.keys.js');
|
|
|
6
6
|
require('core-js/modules/es.symbol.js');
|
|
7
7
|
require('core-js/modules/es.array.filter.js');
|
|
8
8
|
require('core-js/modules/es.object.get-own-property-descriptor.js');
|
|
9
|
-
require('core-js/modules/es.array.for-each.js');
|
|
10
|
-
require('core-js/modules/web.dom-collections.for-each.js');
|
|
11
9
|
require('core-js/modules/es.object.get-own-property-descriptors.js');
|
|
12
10
|
require('core-js/modules/es.object.define-properties.js');
|
|
13
11
|
require('core-js/modules/es.object.define-property.js');
|
|
@@ -19,8 +17,11 @@ var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
|
|
|
19
17
|
var _regeneratorRuntime = require('@babel/runtime/regenerator');
|
|
20
18
|
require('core-js/modules/es.object.to-string.js');
|
|
21
19
|
require('core-js/modules/es.promise.js');
|
|
22
|
-
require('core-js/modules/web.timers.js');
|
|
23
20
|
require('core-js/modules/es.array.is-array.js');
|
|
21
|
+
require('core-js/modules/web.timers.js');
|
|
22
|
+
require('core-js/modules/es.array.for-each.js');
|
|
23
|
+
require('core-js/modules/web.dom-collections.for-each.js');
|
|
24
|
+
require('core-js/modules/es.function.bind.js');
|
|
24
25
|
require('core-js/modules/es.array.map.js');
|
|
25
26
|
var uuid = require('uuid');
|
|
26
27
|
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
@@ -1646,6 +1647,14 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
1646
1647
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default['default'](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
1647
1648
|
var mutexCounter = 0;
|
|
1648
1649
|
var MUTEX_ERROR = 'Mutex has been changed';
|
|
1650
|
+
/**
|
|
1651
|
+
* Query result dataset formats enum.
|
|
1652
|
+
*/
|
|
1653
|
+
|
|
1654
|
+
var ResultType = {
|
|
1655
|
+
DEFAULT: 'default',
|
|
1656
|
+
COMPACT: 'compact'
|
|
1657
|
+
};
|
|
1649
1658
|
|
|
1650
1659
|
function mutexPromise(promise) {
|
|
1651
1660
|
return new Promise( /*#__PURE__*/function () {
|
|
@@ -1691,7 +1700,7 @@ var CubejsApi = /*#__PURE__*/function () {
|
|
|
1691
1700
|
function CubejsApi(apiToken, options) {
|
|
1692
1701
|
_classCallCheck__default['default'](this, CubejsApi);
|
|
1693
1702
|
|
|
1694
|
-
if (_typeof__default['default'](apiToken) === 'object') {
|
|
1703
|
+
if (apiToken !== null && !Array.isArray(apiToken) && _typeof__default['default'](apiToken) === 'object') {
|
|
1695
1704
|
options = apiToken;
|
|
1696
1705
|
apiToken = undefined;
|
|
1697
1706
|
}
|
|
@@ -2168,29 +2177,128 @@ var CubejsApi = /*#__PURE__*/function () {
|
|
|
2168
2177
|
|
|
2169
2178
|
return updateTransportAuthorization;
|
|
2170
2179
|
}()
|
|
2180
|
+
/**
|
|
2181
|
+
* Add system properties to a query object.
|
|
2182
|
+
* @param {Query} query
|
|
2183
|
+
* @param {string} responseFormat
|
|
2184
|
+
* @returns {void}
|
|
2185
|
+
* @private
|
|
2186
|
+
*/
|
|
2187
|
+
|
|
2188
|
+
}, {
|
|
2189
|
+
key: "patchQueryInternal",
|
|
2190
|
+
value: function patchQueryInternal(query, responseFormat) {
|
|
2191
|
+
if (responseFormat === ResultType.COMPACT && query.responseFormat !== ResultType.COMPACT) {
|
|
2192
|
+
query.responseFormat = ResultType.COMPACT;
|
|
2193
|
+
}
|
|
2194
|
+
}
|
|
2195
|
+
/**
|
|
2196
|
+
* Process result fetched from the gateway#load method according
|
|
2197
|
+
* to the network protocol.
|
|
2198
|
+
* @param {*} response
|
|
2199
|
+
* @returns ResultSet
|
|
2200
|
+
* @private
|
|
2201
|
+
*/
|
|
2202
|
+
|
|
2203
|
+
}, {
|
|
2204
|
+
key: "loadResponseInternal",
|
|
2205
|
+
value: function loadResponseInternal(response) {
|
|
2206
|
+
if (response.results.length && response.results[0].query.responseFormat && response.results[0].query.responseFormat === ResultType.COMPACT) {
|
|
2207
|
+
response.results.forEach(function (result, j) {
|
|
2208
|
+
var data = [];
|
|
2209
|
+
result.data.dataset.forEach(function (r) {
|
|
2210
|
+
var row = {};
|
|
2211
|
+
result.data.members.forEach(function (m, i) {
|
|
2212
|
+
row[m] = r[i];
|
|
2213
|
+
});
|
|
2214
|
+
data.push(row);
|
|
2215
|
+
});
|
|
2216
|
+
response.results[j].data = data;
|
|
2217
|
+
});
|
|
2218
|
+
}
|
|
2219
|
+
|
|
2220
|
+
return new ResultSet(response, {
|
|
2221
|
+
parseDateMeasures: this.parseDateMeasures
|
|
2222
|
+
});
|
|
2223
|
+
}
|
|
2224
|
+
/**
|
|
2225
|
+
* Fetch data for the passed `query`. Operates with the
|
|
2226
|
+
* `ApiGateway#load` method to fetch the data.
|
|
2227
|
+
* @param {Query | Query[]} query
|
|
2228
|
+
* @param {LoadMethodOptions | undefined} options
|
|
2229
|
+
* @param {LoadMethodCallback<ResultSet> | undefined} callback
|
|
2230
|
+
* @param {string} responseFormat
|
|
2231
|
+
* @returns {undefined | Promise<ResultSet>}
|
|
2232
|
+
*/
|
|
2233
|
+
|
|
2171
2234
|
}, {
|
|
2172
2235
|
key: "load",
|
|
2173
2236
|
value: function load(query, options, callback) {
|
|
2174
2237
|
var _this3 = this;
|
|
2175
2238
|
|
|
2239
|
+
var responseFormat = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ResultType.DEFAULT;
|
|
2240
|
+
|
|
2241
|
+
if (responseFormat === ResultType.COMPACT) {
|
|
2242
|
+
if (Array.isArray(query)) {
|
|
2243
|
+
query.forEach(function (q) {
|
|
2244
|
+
_this3.patchQueryInternal(q, ResultType.COMPACT);
|
|
2245
|
+
});
|
|
2246
|
+
} else {
|
|
2247
|
+
this.patchQueryInternal(query, ResultType.COMPACT);
|
|
2248
|
+
}
|
|
2249
|
+
}
|
|
2250
|
+
|
|
2176
2251
|
return this.loadMethod(function () {
|
|
2177
2252
|
return _this3.request('load', {
|
|
2178
2253
|
query: query,
|
|
2179
2254
|
queryType: 'multi'
|
|
2180
2255
|
});
|
|
2181
|
-
},
|
|
2182
|
-
|
|
2183
|
-
|
|
2256
|
+
}, this.loadResponseInternal.bind(this), options, callback);
|
|
2257
|
+
}
|
|
2258
|
+
/**
|
|
2259
|
+
* Allows you to fetch data and receive updates over time. Operates
|
|
2260
|
+
* with the `ApiGateway#load` method to fetch the data.
|
|
2261
|
+
* @link real-time-data-fetch
|
|
2262
|
+
* @param {Query | Query[]} query
|
|
2263
|
+
* @param {LoadMethodOptions | null} options
|
|
2264
|
+
* @param {LoadMethodCallback<ResultSet> | undefined} callback
|
|
2265
|
+
* @param {string} responseFormat
|
|
2266
|
+
* @returns {void}
|
|
2267
|
+
*/
|
|
2268
|
+
|
|
2269
|
+
}, {
|
|
2270
|
+
key: "subscribe",
|
|
2271
|
+
value: function subscribe(query, options, callback) {
|
|
2272
|
+
var _this4 = this;
|
|
2273
|
+
|
|
2274
|
+
var responseFormat = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ResultType.DEFAULT;
|
|
2275
|
+
|
|
2276
|
+
if (responseFormat === ResultType.COMPACT) {
|
|
2277
|
+
if (Array.isArray(query)) {
|
|
2278
|
+
query.forEach(function (q) {
|
|
2279
|
+
_this4.patchQueryInternal(q, ResultType.COMPACT);
|
|
2280
|
+
});
|
|
2281
|
+
} else {
|
|
2282
|
+
this.patchQueryInternal(query, ResultType.COMPACT);
|
|
2283
|
+
}
|
|
2284
|
+
}
|
|
2285
|
+
|
|
2286
|
+
return this.loadMethod(function () {
|
|
2287
|
+
return _this4.request('subscribe', {
|
|
2288
|
+
query: query,
|
|
2289
|
+
queryType: 'multi'
|
|
2184
2290
|
});
|
|
2185
|
-
}, options,
|
|
2291
|
+
}, this.loadResponseInternal.bind(this), _objectSpread(_objectSpread({}, options), {}, {
|
|
2292
|
+
subscribe: true
|
|
2293
|
+
}), callback);
|
|
2186
2294
|
}
|
|
2187
2295
|
}, {
|
|
2188
2296
|
key: "sql",
|
|
2189
2297
|
value: function sql(query, options, callback) {
|
|
2190
|
-
var
|
|
2298
|
+
var _this5 = this;
|
|
2191
2299
|
|
|
2192
2300
|
return this.loadMethod(function () {
|
|
2193
|
-
return
|
|
2301
|
+
return _this5.request('sql', {
|
|
2194
2302
|
query: query
|
|
2195
2303
|
});
|
|
2196
2304
|
}, function (response) {
|
|
@@ -2202,10 +2310,10 @@ var CubejsApi = /*#__PURE__*/function () {
|
|
|
2202
2310
|
}, {
|
|
2203
2311
|
key: "meta",
|
|
2204
2312
|
value: function meta(options, callback) {
|
|
2205
|
-
var
|
|
2313
|
+
var _this6 = this;
|
|
2206
2314
|
|
|
2207
2315
|
return this.loadMethod(function () {
|
|
2208
|
-
return
|
|
2316
|
+
return _this6.request('meta');
|
|
2209
2317
|
}, function (body) {
|
|
2210
2318
|
return new Meta(body);
|
|
2211
2319
|
}, options, callback);
|
|
@@ -2213,34 +2321,16 @@ var CubejsApi = /*#__PURE__*/function () {
|
|
|
2213
2321
|
}, {
|
|
2214
2322
|
key: "dryRun",
|
|
2215
2323
|
value: function dryRun(query, options, callback) {
|
|
2216
|
-
var
|
|
2324
|
+
var _this7 = this;
|
|
2217
2325
|
|
|
2218
2326
|
return this.loadMethod(function () {
|
|
2219
|
-
return
|
|
2327
|
+
return _this7.request('dry-run', {
|
|
2220
2328
|
query: query
|
|
2221
2329
|
});
|
|
2222
2330
|
}, function (response) {
|
|
2223
2331
|
return response;
|
|
2224
2332
|
}, options, callback);
|
|
2225
2333
|
}
|
|
2226
|
-
}, {
|
|
2227
|
-
key: "subscribe",
|
|
2228
|
-
value: function subscribe(query, options, callback) {
|
|
2229
|
-
var _this7 = this;
|
|
2230
|
-
|
|
2231
|
-
return this.loadMethod(function () {
|
|
2232
|
-
return _this7.request('subscribe', {
|
|
2233
|
-
query: query,
|
|
2234
|
-
queryType: 'multi'
|
|
2235
|
-
});
|
|
2236
|
-
}, function (body) {
|
|
2237
|
-
return new ResultSet(body, {
|
|
2238
|
-
parseDateMeasures: _this7.parseDateMeasures
|
|
2239
|
-
});
|
|
2240
|
-
}, _objectSpread(_objectSpread({}, options), {}, {
|
|
2241
|
-
subscribe: true
|
|
2242
|
-
}), callback);
|
|
2243
|
-
}
|
|
2244
2334
|
}]);
|
|
2245
2335
|
|
|
2246
2336
|
return CubejsApi;
|