Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cubejs-backend/shared

Package Overview
Dependencies
Maintainers
2
Versions
188
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cubejs-backend/shared - npm Package Compare versions

Comparing version 0.26.35 to 0.26.45

16

CHANGELOG.md

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

## [0.26.45](https://github.com/cube-js/cube.js/compare/v0.26.44...v0.26.45) (2021-03-04)
### Bug Fixes
* **schema-compiler:** Lock antlr4ts to 0.5.0-alpha.4, fix [#2264](https://github.com/cube-js/cube.js/issues/2264) ([37b3a0d](https://github.com/cube-js/cube.js/commit/37b3a0d61433ae1b3e41c1264298d1409b7f95b7))
### Features
* Fetch JWK in background only ([954ce30](https://github.com/cube-js/cube.js/commit/954ce30a8d85e51360340558468a5ea4e2e4ca68))
## [0.26.35](https://github.com/cube-js/cube.js/compare/v0.26.34...v0.26.35) (2021-02-25)

@@ -8,0 +24,0 @@

26

dist/src/promises.d.ts

@@ -36,11 +36,23 @@ export interface CancelablePromise<T> extends Promise<T> {

*/
export declare const asyncDebounce: <ReturnType_1, Arguments>(fn: (...args: Arguments[]) => Promise<ReturnType_1>) => (...args: Arguments[]) => Promise<ReturnType_1>;
export declare type MemoizeOptions<ReturnType, Arguments> = {
export declare const asyncDebounce: <Ret, Arguments>(fn: (...args: Arguments[]) => Promise<Ret>) => (...args: Arguments[]) => Promise<Ret>;
export declare type MemoizeOptions<Ret, Arguments> = {
extractKey: (...args: Arguments[]) => string;
extractCacheLifetime: (result: ReturnType) => number;
extractCacheLifetime: (result: Ret) => number;
};
export declare const asyncMemoize: <ReturnType_1, Arguments>(fn: (...args: Arguments[]) => Promise<ReturnType_1>, options: MemoizeOptions<ReturnType_1, Arguments>) => {
(...args: Arguments[]): Promise<ReturnType_1>;
force(...args: Arguments[]): Promise<ReturnType_1>;
export declare const asyncMemoize: <Ret, Arguments>(fn: (...args: Arguments[]) => Promise<Ret>, options: MemoizeOptions<Ret, Arguments>) => {
(...args: Arguments[]): Promise<Ret>;
force(...args: Arguments[]): Promise<Ret>;
};
export declare type BackgroundMemoizeOptions<Ret, Arguments> = {
extractKey: (...args: Arguments[]) => string;
extractCacheLifetime: (result: Ret) => number;
backgroundRefreshInterval: number;
onBackgroundException: (err: Error) => void;
};
export declare const decorateWithCancel: <T, C = () => void>(fn: Promise<T>, cancel: C) => CancelablePromise<T>;
export declare const asyncMemoizeBackground: <Ret, Arguments>(fn: (...args: Arguments[]) => Promise<Ret>, options: BackgroundMemoizeOptions<Ret, Arguments>) => {
(...args: Arguments[]): Promise<Ret>;
force(...args: Arguments[]): Promise<Ret>;
release: (waitExecution?: boolean | undefined) => Promise<void>;
};
export declare type RetryOptions = {

@@ -52,4 +64,4 @@ times: number;

*/
export declare const asyncRetry: <ReturnType_1>(fn: () => Promise<ReturnType_1>, options: RetryOptions) => Promise<ReturnType_1>;
export declare const asyncRetry: <Ret>(fn: () => Promise<Ret>, options: RetryOptions) => Promise<Ret>;
export {};
//# sourceMappingURL=promises.d.ts.map

@@ -6,4 +6,4 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.asyncRetry = exports.asyncMemoize = exports.asyncDebounce = exports.retryWithTimeout = exports.withTimeoutRace = exports.withTimeout = exports.createCancelableInterval = exports.createCancelablePromise = exports.pausePromise = void 0;
/* eslint-disable arrow-body-style */
exports.asyncRetry = exports.asyncMemoizeBackground = exports.decorateWithCancel = exports.asyncMemoize = exports.asyncDebounce = exports.retryWithTimeout = exports.withTimeoutRace = exports.withTimeout = exports.createCancelableInterval = exports.createCancelablePromise = exports.pausePromise = void 0;
/* eslint-disable arrow-body-style,no-restricted-syntax */
const crypto_1 = __importDefault(require("crypto"));

@@ -192,3 +192,2 @@ function pausePromise(ms) {

const debouncedFn = exports.asyncDebounce(fn);
const debouncedFnForce = exports.asyncDebounce(fn);
const call = async (...args) => {

@@ -214,3 +213,3 @@ const key = options.extractKey(...args);

const key = options.extractKey(...args);
const item = await debouncedFnForce(...args);
const item = await debouncedFn(...args);
cache.set(key, {

@@ -225,2 +224,60 @@ lifetime: Date.now() + options.extractCacheLifetime(item),

exports.asyncMemoize = asyncMemoize;
const decorateWithCancel = (fn, cancel) => {
fn.cancel = cancel;
return fn;
};
exports.decorateWithCancel = decorateWithCancel;
const asyncMemoizeBackground = (fn, options) => {
const cache = new Map();
const debouncedFn = exports.asyncDebounce(fn);
const refreshBucket = async (bucket) => {
try {
const item = await debouncedFn(...bucket.args);
bucket.item = item;
bucket.lifetime = Date.now() + options.extractCacheLifetime(item);
}
catch (e) {
options.onBackgroundException(e);
}
};
const refreshInterval = createCancelableInterval(async () => {
const refreshBatch = [];
const now = Date.now();
for (const bucket of cache.values()) {
if (bucket.lifetime < now) {
refreshBatch.push(refreshBucket(bucket));
}
}
return Promise.all(refreshBatch);
}, {
interval: options.backgroundRefreshInterval,
});
const call = async (...args) => {
const key = options.extractKey(...args);
if (cache.has(key)) {
// If cache exists, only background timer or force can update it.
return cache.get(key).item;
}
const item = await debouncedFn(...args);
cache.set(key, {
lifetime: Date.now() + options.extractCacheLifetime(item),
args,
item,
});
return item;
};
call.force = async (...args) => {
const key = options.extractKey(...args);
const item = await debouncedFn(...args);
cache.set(key, {
lifetime: Date.now() + options.extractCacheLifetime(item),
args,
item,
});
return item;
};
call.release = refreshInterval.cancel;
return call;
};
exports.asyncMemoizeBackground = asyncMemoizeBackground;
/**

@@ -227,0 +284,0 @@ * High order function that do retry when async function throw an exception

{
"name": "@cubejs-backend/shared",
"version": "0.26.35",
"version": "0.26.45",
"description": "Shared code for Cube.js backend packages",

@@ -53,3 +53,3 @@ "main": "dist/src/index.js",

},
"gitHead": "b9187c793f11484aa82bd077ea420dbd33c6164e"
"gitHead": "d4286da4c671410e95e4537ac41ca028b2d6b103"
}

Sorry, the diff of this file is not supported yet

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