@statoscope/helpers
Advanced tools
Comparing version 5.7.1 to 5.9.0
@@ -8,5 +8,5 @@ "use strict"; | ||
function makeTree(node, prefix) { | ||
return archy_1.default(node, prefix); | ||
return (0, archy_1.default)(node, prefix); | ||
} | ||
exports.default = makeTree; | ||
//# sourceMappingURL=asciiTree.js.map |
@@ -0,4 +1,11 @@ | ||
export declare function normalizeId<TID>(id: TID): TID | string; | ||
export declare function getIdWrapper<TID, TEntity>(getId: GetIDFn<TID, TEntity>): GetIDFn<TID | string, TEntity>; | ||
export declare type Entities<TEntity> = TEntity[] | Set<TEntity> | Map<unknown, TEntity> | Record<string, TEntity>; | ||
export declare type Resolver<TID, TEntity> = (id: TID) => TEntity | null; | ||
export declare type ResolverAPI = { | ||
lock(): void; | ||
unlock(): void; | ||
}; | ||
export declare type ResolverFn<TID, TReturn> = (id: TID) => TReturn | null; | ||
export declare type Resolver<TID, TReturn> = ResolverFn<TID, TReturn> & ResolverAPI; | ||
export declare type GetIDFn<TID, TEntity> = (entity: TEntity) => TID; | ||
export default function makeResolver<TID, TEntity, TReturn = TEntity>(entities: Entities<TEntity>, getId: (entity: TEntity) => TID, get?: (entity: TEntity) => TReturn): Resolver<TID, TReturn>; | ||
export default function makeResolver<TID, TEntity, TReturn = TEntity>(entities: Entities<TEntity>, getId: (entity: TEntity) => TID, get?: ((entity: TEntity) => TReturn) | null, locked?: boolean): Resolver<TID, TReturn>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getIdWrapper = exports.normalizeId = void 0; | ||
function normalizeId(id) { | ||
return typeof id === 'number' || typeof id === 'bigint' ? String(id) : id; | ||
} | ||
exports.normalizeId = normalizeId; | ||
function getIdWrapper(getId) { | ||
return (entity) => { | ||
const id = getId(entity); | ||
return normalizeId(id); | ||
}; | ||
} | ||
exports.getIdWrapper = getIdWrapper; | ||
function warnCache(entities, getId, cache) { | ||
cache.clear(); | ||
if (Array.isArray(entities) || entities instanceof Set) { | ||
@@ -21,16 +34,19 @@ for (const entity of entities) { | ||
} | ||
function makeResolver(entities, getId, get) { | ||
function makeResolver(entities, getId, get, locked = true) { | ||
const wrappedGetId = getIdWrapper(getId); | ||
const cache = new Map(); | ||
warnCache(entities, getId, cache); | ||
return (id) => { | ||
const cached = cache.get(id); | ||
warnCache(entities, wrappedGetId, cache); | ||
const resolver = (id) => { | ||
const idForCache = normalizeId(id); | ||
const cached = cache.get(idForCache); | ||
if (cached) { | ||
return get ? get(cached) : cached; | ||
return (get ? get(cached) : cached); | ||
} | ||
else if (locked) { | ||
return null; | ||
} | ||
let result = null; | ||
if (Array.isArray(entities) || entities instanceof Set) { | ||
for (const entity of entities) { | ||
// disable eqeqeq cause id may be string or number | ||
// eslint-disable-next-line eqeqeq | ||
if (getId(entity) == id) { | ||
if (getId(entity) === id) { | ||
result = entity; | ||
@@ -43,4 +59,3 @@ break; | ||
for (const [, entity] of entities) { | ||
// eslint-disable-next-line eqeqeq | ||
if (getId(entity) == id) { | ||
if (getId(entity) === id) { | ||
result = entity; | ||
@@ -54,4 +69,3 @@ break; | ||
const entity = entities[name]; | ||
// eslint-disable-next-line eqeqeq | ||
if (getId(entity) == id) { | ||
if (getId(entity) === id) { | ||
result = entity; | ||
@@ -68,4 +82,10 @@ break; | ||
}; | ||
resolver.lock = () => { | ||
warnCache(entities, wrappedGetId, cache); | ||
locked = true; | ||
}; | ||
resolver.unlock = () => void (locked = false); | ||
return resolver; | ||
} | ||
exports.default = makeResolver; | ||
//# sourceMappingURL=entity-resolver.js.map |
@@ -124,3 +124,3 @@ "use strict"; | ||
}, | ||
color: (value) => colors_1.colorMap[value] ? colors_1.colorMap[value].color : colors_1.generateColor(value), | ||
color: (value) => colors_1.colorMap[value] ? colors_1.colorMap[value].color : (0, colors_1.generateColor)(value), | ||
fileExt: (value) => { | ||
@@ -169,24 +169,24 @@ if (value == null) { | ||
semverGT(a, b) { | ||
return gt_1.default(a, b); | ||
return (0, gt_1.default)(a, b); | ||
}, | ||
semverGTE(a, b) { | ||
return gte_1.default(a, b); | ||
return (0, gte_1.default)(a, b); | ||
}, | ||
semverLT(a, b) { | ||
return lt_1.default(a, b); | ||
return (0, lt_1.default)(a, b); | ||
}, | ||
semverLTE(a, b) { | ||
return lte_1.default(a, b); | ||
return (0, lte_1.default)(a, b); | ||
}, | ||
semverEQ(a, b) { | ||
return eq_1.default(a, b); | ||
return (0, eq_1.default)(a, b); | ||
}, | ||
semverDiff(a, b) { | ||
return diff_1.default(a, b); | ||
return (0, diff_1.default)(a, b); | ||
}, | ||
semverParse(version) { | ||
return parse_1.default(version); | ||
return (0, parse_1.default)(version); | ||
}, | ||
semverSatisfies(version, range) { | ||
return satisfies_1.default(version, range); | ||
return (0, satisfies_1.default)(version, range); | ||
}, | ||
@@ -202,4 +202,4 @@ formatDiff(value) { | ||
if (value.type === 'version') { | ||
const diff = diff_1.default(value.a, value.b); | ||
const type = gt_1.default(value.a, value.b) ? 'downgrade' : 'upgrade'; | ||
const diff = (0, diff_1.default)(value.a, value.b); | ||
const type = (0, gt_1.default)(value.a, value.b) ? 'downgrade' : 'upgrade'; | ||
return diff ? `${diff} ${type} from ${value.a}` : ''; | ||
@@ -206,0 +206,0 @@ } |
{ | ||
"name": "@statoscope/helpers", | ||
"version": "5.7.1", | ||
"version": "5.9.0", | ||
"description": "Statoscope utils", | ||
@@ -27,3 +27,3 @@ "main": "./dist/index.js", | ||
}, | ||
"gitHead": "064a4cec944bc1438f48afbe8c127f22d82b4a60" | ||
"gitHead": "f8e8a9cd721828a4bc53a2f808441d81e5fdbf84" | ||
} |
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
35062
23
993