batchloader
Advanced tools
Comparing version 0.0.16 to 0.0.17
@@ -23,1 +23,2 @@ import { CacheLoader, ICache } from './cacheloader'; | ||
} | ||
//# sourceMappingURL=batchloader.d.ts.map |
@@ -1,17 +0,7 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const cacheloader_1 = require("./cacheloader"); | ||
const mappedbatchloader_1 = require("./mappedbatchloader"); | ||
import { CacheLoader } from './cacheloader'; | ||
import { MappedBatchLoader } from './mappedbatchloader'; | ||
const sleep = (ms) => new Promise((resolve) => { | ||
setTimeout(resolve, ms); | ||
}); | ||
class BatchLoader { | ||
export class BatchLoader { | ||
constructor(batchFn, keyToUniqueId, batchDelay = 0, batchSize = Number.MAX_SAFE_INTEGER) { | ||
@@ -42,6 +32,6 @@ this.batchFn = batchFn; | ||
mapLoader(mapFn) { | ||
return new mappedbatchloader_1.MappedBatchLoader(this, mapFn); | ||
return new MappedBatchLoader(this, mapFn); | ||
} | ||
cacheLoader(cache) { | ||
return new cacheloader_1.CacheLoader(this, cache); | ||
return new CacheLoader(this, cache); | ||
} | ||
@@ -88,24 +78,21 @@ triggerBatch() { | ||
} | ||
batchInChunks(keys) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { batchSize, batchDelay } = this; | ||
const promises = []; | ||
const kLen = keys.length; | ||
for (let i = 0; i < kLen; i += batchSize) { | ||
promises.push(this.batchFn(keys.slice(i, i + batchSize))); | ||
if (batchDelay) { | ||
yield sleep(batchDelay); | ||
} | ||
async batchInChunks(keys) { | ||
const { batchSize, batchDelay } = this; | ||
const promises = []; | ||
const kLen = keys.length; | ||
for (let i = 0; i < kLen; i += batchSize) { | ||
promises.push(this.batchFn(keys.slice(i, i + batchSize))); | ||
if (batchDelay) { | ||
await sleep(batchDelay); | ||
} | ||
const results = yield Promise.all(promises); | ||
const rLen = results.length; | ||
let values = []; | ||
for (let i = 0; i < rLen; i += 1) { | ||
values = values.concat(results[i]); | ||
} | ||
return values; | ||
}); | ||
} | ||
const results = await Promise.all(promises); | ||
const rLen = results.length; | ||
let values = []; | ||
for (let i = 0; i < rLen; i += 1) { | ||
values = values.concat(results[i]); | ||
} | ||
return values; | ||
} | ||
} | ||
exports.BatchLoader = BatchLoader; | ||
//# sourceMappingURL=batchloader.js.map |
@@ -22,1 +22,2 @@ import { MappedBatchLoader } from './mappedbatchloader'; | ||
} | ||
//# sourceMappingURL=cacheloader.d.ts.map |
@@ -1,5 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const mappedbatchloader_1 = require("./mappedbatchloader"); | ||
class CacheLoader { | ||
import { MappedBatchLoader } from './mappedbatchloader'; | ||
export class CacheLoader { | ||
constructor(loader, cache = new Map()) { | ||
@@ -31,3 +29,3 @@ this.loader = loader; | ||
mapLoader(mapFn) { | ||
return new mappedbatchloader_1.MappedBatchLoader(this, mapFn); | ||
return new MappedBatchLoader(this, mapFn); | ||
} | ||
@@ -61,3 +59,2 @@ get(key) { | ||
} | ||
exports.CacheLoader = CacheLoader; | ||
//# sourceMappingURL=cacheloader.js.map |
@@ -8,1 +8,2 @@ import { BatchLoader, KeyToUniqueId } from './batchloader'; | ||
export declare const proxyLoaderWithCache: <Key, Value>(cache: IBatchCache<Key, Value>, loader: IBatchLoader<Key, Value>, keyToUniqueId: KeyToUniqueId<Key> | null, batchDelay?: number | undefined, batchSize?: number | undefined) => BatchLoader<Key, Value>; | ||
//# sourceMappingURL=cacheproxyloader.d.ts.map |
@@ -1,14 +0,4 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const batchloader_1 = require("./batchloader"); | ||
exports.proxyLoaderWithCache = (cache, loader, keyToUniqueId, batchDelay, batchSize) => new batchloader_1.BatchLoader((keys) => __awaiter(this, void 0, void 0, function* () { | ||
const values = yield cache.mget(keys); | ||
import { BatchLoader } from './batchloader'; | ||
export const proxyLoaderWithCache = (cache, loader, keyToUniqueId, batchDelay, batchSize) => new BatchLoader(async (keys) => { | ||
const values = await cache.mget(keys); | ||
const len = values.length; | ||
@@ -24,3 +14,3 @@ const missingKeys = []; | ||
if (missingKeys.length) { | ||
const missingValues = yield loader.loadMany(missingKeys); | ||
const missingValues = await loader.loadMany(missingKeys); | ||
const mlen = missingValues.length; | ||
@@ -36,3 +26,3 @@ const missingKeyValues = []; | ||
return values; | ||
}), keyToUniqueId, batchDelay, batchSize); | ||
}, keyToUniqueId, batchDelay, batchSize); | ||
//# sourceMappingURL=cacheproxyloader.js.map |
export * from './batchloader'; | ||
export * from './mappedbatchloader'; | ||
export * from './cacheproxyloader'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,9 +0,4 @@ | ||
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(require("./batchloader")); | ||
__export(require("./mappedbatchloader")); | ||
__export(require("./cacheproxyloader")); | ||
export * from './batchloader'; | ||
export * from './mappedbatchloader'; | ||
export * from './cacheproxyloader'; | ||
//# sourceMappingURL=index.js.map |
@@ -10,1 +10,2 @@ import { IBatchLoader } from './types'; | ||
} | ||
//# sourceMappingURL=mappedbatchloader.d.ts.map |
@@ -1,4 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
class MappedBatchLoader { | ||
export class MappedBatchLoader { | ||
constructor(loader, mapFn) { | ||
@@ -30,3 +28,2 @@ this.loader = loader; | ||
} | ||
exports.MappedBatchLoader = MappedBatchLoader; | ||
//# sourceMappingURL=mappedbatchloader.js.map |
@@ -7,1 +7,2 @@ export interface IBatchLoader<Key, Value> { | ||
export declare type MaybePromise<T> = T | Promise<T>; | ||
//# sourceMappingURL=types.d.ts.map |
@@ -1,3 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=types.js.map |
{ | ||
"name": "batchloader", | ||
"version": "0.0.16", | ||
"version": "0.0.17", | ||
"description": "BatchLoader is a utility for data fetching layer to reduce requests via batching written in TypeScript. Inspired by Facebook's DataLoader", | ||
"main": "lib/index.js", | ||
"module": "lib/index.js", | ||
"main": "dist/node/index.js", | ||
"browser": "dist/browser/index.js", | ||
"types": "lib/index.d.ts", | ||
"scripts": { | ||
"all": "npm run clean && npm run format && npm run lint:fix && npm run test && npm run build && npm run build:es5", | ||
"build": "tsc -p ./tsconfig.json && tscpaths -p ./tsconfig.json -s ./src -o ./lib", | ||
"build:es5": "tsc -p ./tsconfig.es5.json && tscpaths -p ./tsconfig.es5.json -s ./src -o ./es5", | ||
"clean": "rm -rf ./lib ./es5 ./es6 ./coverage", | ||
"all": "npm run clean && npm run format && npm run lint:fix && npm run build:all && npm run test", | ||
"build:all": "npm run build:module && npm run build:node && npm run build:browser", | ||
"build:browser": "tsc -p ./tsconfig.browser.json && tscpaths -p ./tsconfig.browser.json -s ./src -o ./dist/browser", | ||
"build:module": "tsc -p ./tsconfig.module.json && tscpaths -p ./tsconfig.module.json -s ./src -o ./lib", | ||
"build:node": "tsc -p ./tsconfig.node.json && tscpaths -p ./tsconfig.node.json -s ./src -o ./dist/node", | ||
"clean": "rm -rf ./lib ./dist ./coverage", | ||
"format": "prettier --write \"./*.{js,jsx,ts,tsx}\" \"./src/**/*.{js,jsx,ts,tsx}\"", | ||
"lint": "tslint -c ./tslint.json \"src/**/*\"", | ||
"lint:fix": "tslint --fix -c ./tslint.json \"src/**/*\"", | ||
"lint": "tslint -c ./tslint.json \"src/**/*.ts\"", | ||
"lint:fix": "tslint --fix -c ./tslint.json \"src/**/*.ts\"", | ||
"precommit": "npm run all", | ||
"prepublish": "npm run all", | ||
"reinstall": "rm -rf ./node_modules ./package-lock.json ./yarn.lock && npm i", | ||
"reinstall": "rm -rf ./node_modules ./package-lock.json ./yarn.lock && yarn", | ||
"start": "npm run test", | ||
@@ -43,3 +47,3 @@ "test": "jest", | ||
"@types/jest": "^24.0.15", | ||
"@types/node": "^12.0.12", | ||
"@types/node": "^12.6.2", | ||
"coveralls": "^3.0.4", | ||
@@ -54,4 +58,4 @@ "jest": "^24.8.0", | ||
"tslint-config-prettier": "^1.18.0", | ||
"typescript": "^3.5.2" | ||
"typescript": "^3.5.3" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
89916
75
977
1