@grafana/async-query-data
Advanced tools
Comparing version 0.1.4 to 0.1.6
@@ -5,2 +5,3 @@ import { DataSourceWithBackend, getBackendSrv, toDataQueryResponse } from '@grafana/runtime'; | ||
import { map } from '../node_modules/rxjs/dist/esm5/internal/operators/map.js'; | ||
import { catchError } from '../node_modules/rxjs/dist/esm5/internal/operators/catchError.js'; | ||
@@ -130,3 +131,5 @@ var __defProp = Object.defineProperty; | ||
}; | ||
return getBackendSrv().fetch(options).pipe(map((result) => ({ data: toDataQueryResponse(result).data }))); | ||
return getBackendSrv().fetch(options).pipe(map((result) => ({ data: toDataQueryResponse(result).data })), catchError((err) => { | ||
return of(toDataQueryResponse(err)); | ||
})); | ||
}, | ||
@@ -133,0 +136,0 @@ /** |
@@ -39,2 +39,8 @@ 'use strict'; | ||
var isArrayLike = (function (x) { return x && typeof x.length === 'number' && typeof x !== 'function'; }); | ||
function isPromise(value) { | ||
return isFunction(value === null || value === void 0 ? void 0 : value.then); | ||
} | ||
function createErrorClass(createImpl) { | ||
@@ -239,2 +245,8 @@ var _super = function (instance) { | ||
function errorContext(cb) { | ||
{ | ||
cb(); | ||
} | ||
} | ||
var Subscriber = (function (_super) { | ||
@@ -400,2 +412,305 @@ tslib.__extends(Subscriber, _super); | ||
var observable = (function () { return (typeof Symbol === 'function' && Symbol.observable) || '@@observable'; })(); | ||
function identity(x) { | ||
return x; | ||
} | ||
function pipeFromArray(fns) { | ||
if (fns.length === 0) { | ||
return identity; | ||
} | ||
if (fns.length === 1) { | ||
return fns[0]; | ||
} | ||
return function piped(input) { | ||
return fns.reduce(function (prev, fn) { return fn(prev); }, input); | ||
}; | ||
} | ||
var Observable = (function () { | ||
function Observable(subscribe) { | ||
if (subscribe) { | ||
this._subscribe = subscribe; | ||
} | ||
} | ||
Observable.prototype.lift = function (operator) { | ||
var observable = new Observable(); | ||
observable.source = this; | ||
observable.operator = operator; | ||
return observable; | ||
}; | ||
Observable.prototype.subscribe = function (observerOrNext, error, complete) { | ||
var _this = this; | ||
var subscriber = isSubscriber(observerOrNext) ? observerOrNext : new SafeSubscriber(observerOrNext, error, complete); | ||
errorContext(function () { | ||
var _a = _this, operator = _a.operator, source = _a.source; | ||
subscriber.add(operator | ||
? | ||
operator.call(subscriber, source) | ||
: source | ||
? | ||
_this._subscribe(subscriber) | ||
: | ||
_this._trySubscribe(subscriber)); | ||
}); | ||
return subscriber; | ||
}; | ||
Observable.prototype._trySubscribe = function (sink) { | ||
try { | ||
return this._subscribe(sink); | ||
} | ||
catch (err) { | ||
sink.error(err); | ||
} | ||
}; | ||
Observable.prototype.forEach = function (next, promiseCtor) { | ||
var _this = this; | ||
promiseCtor = getPromiseCtor(promiseCtor); | ||
return new promiseCtor(function (resolve, reject) { | ||
var subscriber = new SafeSubscriber({ | ||
next: function (value) { | ||
try { | ||
next(value); | ||
} | ||
catch (err) { | ||
reject(err); | ||
subscriber.unsubscribe(); | ||
} | ||
}, | ||
error: reject, | ||
complete: resolve, | ||
}); | ||
_this.subscribe(subscriber); | ||
}); | ||
}; | ||
Observable.prototype._subscribe = function (subscriber) { | ||
var _a; | ||
return (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber); | ||
}; | ||
Observable.prototype[observable] = function () { | ||
return this; | ||
}; | ||
Observable.prototype.pipe = function () { | ||
var operations = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
operations[_i] = arguments[_i]; | ||
} | ||
return pipeFromArray(operations)(this); | ||
}; | ||
Observable.prototype.toPromise = function (promiseCtor) { | ||
var _this = this; | ||
promiseCtor = getPromiseCtor(promiseCtor); | ||
return new promiseCtor(function (resolve, reject) { | ||
var value; | ||
_this.subscribe(function (x) { return (value = x); }, function (err) { return reject(err); }, function () { return resolve(value); }); | ||
}); | ||
}; | ||
Observable.create = function (subscribe) { | ||
return new Observable(subscribe); | ||
}; | ||
return Observable; | ||
}()); | ||
function getPromiseCtor(promiseCtor) { | ||
var _a; | ||
return (_a = promiseCtor !== null && promiseCtor !== void 0 ? promiseCtor : config.Promise) !== null && _a !== void 0 ? _a : Promise; | ||
} | ||
function isObserver(value) { | ||
return value && isFunction(value.next) && isFunction(value.error) && isFunction(value.complete); | ||
} | ||
function isSubscriber(value) { | ||
return (value && value instanceof Subscriber) || (isObserver(value) && isSubscription(value)); | ||
} | ||
function isInteropObservable(input) { | ||
return isFunction(input[observable]); | ||
} | ||
function isAsyncIterable(obj) { | ||
return Symbol.asyncIterator && isFunction(obj === null || obj === void 0 ? void 0 : obj[Symbol.asyncIterator]); | ||
} | ||
function createInvalidObservableTypeError(input) { | ||
return new TypeError("You provided " + (input !== null && typeof input === 'object' ? 'an invalid object' : "'" + input + "'") + " where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable."); | ||
} | ||
function getSymbolIterator() { | ||
if (typeof Symbol !== 'function' || !Symbol.iterator) { | ||
return '@@iterator'; | ||
} | ||
return Symbol.iterator; | ||
} | ||
var iterator = getSymbolIterator(); | ||
function isIterable(input) { | ||
return isFunction(input === null || input === void 0 ? void 0 : input[iterator]); | ||
} | ||
function readableStreamLikeToAsyncGenerator(readableStream) { | ||
return tslib.__asyncGenerator(this, arguments, function readableStreamLikeToAsyncGenerator_1() { | ||
var reader, _a, value, done; | ||
return tslib.__generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
reader = readableStream.getReader(); | ||
_b.label = 1; | ||
case 1: | ||
_b.trys.push([1, , 9, 10]); | ||
_b.label = 2; | ||
case 2: | ||
return [4, tslib.__await(reader.read())]; | ||
case 3: | ||
_a = _b.sent(), value = _a.value, done = _a.done; | ||
if (!done) return [3, 5]; | ||
return [4, tslib.__await(void 0)]; | ||
case 4: return [2, _b.sent()]; | ||
case 5: return [4, tslib.__await(value)]; | ||
case 6: return [4, _b.sent()]; | ||
case 7: | ||
_b.sent(); | ||
return [3, 2]; | ||
case 8: return [3, 10]; | ||
case 9: | ||
reader.releaseLock(); | ||
return [7]; | ||
case 10: return [2]; | ||
} | ||
}); | ||
}); | ||
} | ||
function isReadableStreamLike(obj) { | ||
return isFunction(obj === null || obj === void 0 ? void 0 : obj.getReader); | ||
} | ||
function innerFrom(input) { | ||
if (input instanceof Observable) { | ||
return input; | ||
} | ||
if (input != null) { | ||
if (isInteropObservable(input)) { | ||
return fromInteropObservable(input); | ||
} | ||
if (isArrayLike(input)) { | ||
return fromArrayLike(input); | ||
} | ||
if (isPromise(input)) { | ||
return fromPromise(input); | ||
} | ||
if (isAsyncIterable(input)) { | ||
return fromAsyncIterable(input); | ||
} | ||
if (isIterable(input)) { | ||
return fromIterable(input); | ||
} | ||
if (isReadableStreamLike(input)) { | ||
return fromReadableStreamLike(input); | ||
} | ||
} | ||
throw createInvalidObservableTypeError(input); | ||
} | ||
function fromInteropObservable(obj) { | ||
return new Observable(function (subscriber) { | ||
var obs = obj[observable](); | ||
if (isFunction(obs.subscribe)) { | ||
return obs.subscribe(subscriber); | ||
} | ||
throw new TypeError('Provided object does not correctly implement Symbol.observable'); | ||
}); | ||
} | ||
function fromArrayLike(array) { | ||
return new Observable(function (subscriber) { | ||
for (var i = 0; i < array.length && !subscriber.closed; i++) { | ||
subscriber.next(array[i]); | ||
} | ||
subscriber.complete(); | ||
}); | ||
} | ||
function fromPromise(promise) { | ||
return new Observable(function (subscriber) { | ||
promise | ||
.then(function (value) { | ||
if (!subscriber.closed) { | ||
subscriber.next(value); | ||
subscriber.complete(); | ||
} | ||
}, function (err) { return subscriber.error(err); }) | ||
.then(null, reportUnhandledError); | ||
}); | ||
} | ||
function fromIterable(iterable) { | ||
return new Observable(function (subscriber) { | ||
var e_1, _a; | ||
try { | ||
for (var iterable_1 = tslib.__values(iterable), iterable_1_1 = iterable_1.next(); !iterable_1_1.done; iterable_1_1 = iterable_1.next()) { | ||
var value = iterable_1_1.value; | ||
subscriber.next(value); | ||
if (subscriber.closed) { | ||
return; | ||
} | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (iterable_1_1 && !iterable_1_1.done && (_a = iterable_1.return)) _a.call(iterable_1); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
subscriber.complete(); | ||
}); | ||
} | ||
function fromAsyncIterable(asyncIterable) { | ||
return new Observable(function (subscriber) { | ||
process(asyncIterable, subscriber).catch(function (err) { return subscriber.error(err); }); | ||
}); | ||
} | ||
function fromReadableStreamLike(readableStream) { | ||
return fromAsyncIterable(readableStreamLikeToAsyncGenerator(readableStream)); | ||
} | ||
function process(asyncIterable, subscriber) { | ||
var asyncIterable_1, asyncIterable_1_1; | ||
var e_2, _a; | ||
return tslib.__awaiter(this, void 0, void 0, function () { | ||
var value, e_2_1; | ||
return tslib.__generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
_b.trys.push([0, 5, 6, 11]); | ||
asyncIterable_1 = tslib.__asyncValues(asyncIterable); | ||
_b.label = 1; | ||
case 1: return [4, asyncIterable_1.next()]; | ||
case 2: | ||
if (!(asyncIterable_1_1 = _b.sent(), !asyncIterable_1_1.done)) return [3, 4]; | ||
value = asyncIterable_1_1.value; | ||
subscriber.next(value); | ||
if (subscriber.closed) { | ||
return [2]; | ||
} | ||
_b.label = 3; | ||
case 3: return [3, 1]; | ||
case 4: return [3, 11]; | ||
case 5: | ||
e_2_1 = _b.sent(); | ||
e_2 = { error: e_2_1 }; | ||
return [3, 11]; | ||
case 6: | ||
_b.trys.push([6, , 9, 10]); | ||
if (!(asyncIterable_1_1 && !asyncIterable_1_1.done && (_a = asyncIterable_1.return))) return [3, 8]; | ||
return [4, _a.call(asyncIterable_1)]; | ||
case 7: | ||
_b.sent(); | ||
_b.label = 8; | ||
case 8: return [3, 10]; | ||
case 9: | ||
if (e_2) throw e_2.error; | ||
return [7]; | ||
case 10: return [7]; | ||
case 11: | ||
subscriber.complete(); | ||
return [2]; | ||
} | ||
}); | ||
}); | ||
} | ||
function createOperatorSubscriber(destination, onNext, onComplete, onError, onFinalize) { | ||
@@ -459,2 +774,26 @@ return new OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize); | ||
function catchError(selector) { | ||
return operate(function (source, subscriber) { | ||
var innerSub = null; | ||
var syncUnsub = false; | ||
var handledResult; | ||
innerSub = source.subscribe(createOperatorSubscriber(subscriber, undefined, undefined, function (err) { | ||
handledResult = innerFrom(selector(err, catchError(selector)(source))); | ||
if (innerSub) { | ||
innerSub.unsubscribe(); | ||
innerSub = null; | ||
handledResult.subscribe(subscriber); | ||
} | ||
else { | ||
syncUnsub = true; | ||
} | ||
})); | ||
if (syncUnsub) { | ||
innerSub.unsubscribe(); | ||
innerSub = null; | ||
handledResult.subscribe(subscriber); | ||
} | ||
}); | ||
} | ||
function map(project, thisArg) { | ||
@@ -678,3 +1017,5 @@ return operate(function (source, subscriber) { | ||
}; | ||
return runtime.getBackendSrv().fetch(options).pipe(map((result) => ({ data: runtime.toDataQueryResponse(result).data }))); | ||
return runtime.getBackendSrv().fetch(options).pipe(map((result) => ({ data: runtime.toDataQueryResponse(result).data })), catchError((err) => { | ||
return rxjs.of(runtime.toDataQueryResponse(err)); | ||
})); | ||
}, | ||
@@ -681,0 +1022,0 @@ /** |
{ | ||
"name": "@grafana/async-query-data", | ||
"version": "0.1.4", | ||
"version": "0.1.6", | ||
"description": "Async query support for Grafana", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"dev": "watch 'npm run bundle' ./src", | ||
"dev": "yarn bundle --watch --watch.onStart=\"yarn typecheck\"", | ||
"build": "yarn clean && yarn typecheck && yarn bundle", | ||
@@ -9,0 +9,0 @@ "bundle": "rollup -c rollup.config.ts", |
Sorry, the diff of this file is not supported yet
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
270151
70
2265