@andrew_l/toolkit 0.2.5 → 0.2.8

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/dist/index.cjs CHANGED
@@ -822,14 +822,14 @@ function createWithCache({
822
822
  getPointer,
823
823
  argToKeyOptions
824
824
  };
825
- const wrapFn = (...args) => {
825
+ const wrapFn = function(...args) {
826
826
  const storage = getBucket(getPointer());
827
827
  const cacheKey = args.map((v) => argToKey(v, argToKeyOptions)).join("_");
828
828
  if (storage.has(cacheKey)) {
829
829
  const value = storage.get(cacheKey);
830
830
  return isAsync ? Promise.resolve(value) : value;
831
831
  }
832
- const newValue = fn(...args);
832
+ const newValue = fn.apply(this, args);
833
833
  if (isPromise(newValue)) {
834
834
  return newValue.then((value) => {
835
835
  storage.set(cacheKey, value);
@@ -1388,13 +1388,13 @@ function withCacheBucketBatch({
1388
1388
  }
1389
1389
  return fnCache;
1390
1390
  };
1391
- const wrapFn = async (values) => {
1391
+ const wrapFn = async function(values) {
1392
1392
  const result = /* @__PURE__ */ new Map();
1393
1393
  let fnCache = getBucket();
1394
1394
  const batchSet = /* @__PURE__ */ new Set();
1395
1395
  const drainMaybe = async () => {
1396
1396
  if (!batchSet.size) return;
1397
- const items = await resolver(Array.from(batchSet));
1397
+ const items = await resolver.call(this, Array.from(batchSet));
1398
1398
  for (let idx = 0; idx < items.length; idx++) {
1399
1399
  const item = items[idx];
1400
1400
  if (!isObject(item)) continue;
@@ -3491,19 +3491,37 @@ function tryStringify(o) {
3491
3491
  }
3492
3492
  }
3493
3493
 
3494
- const IS_DEV = env.isDevelopment || env.bool("DEV", false);
3494
+ const LEVEL_NUM = {
3495
+ debug: 0,
3496
+ log: 1,
3497
+ info: 2,
3498
+ warn: 3,
3499
+ error: 4
3500
+ };
3501
+ let currentLogLevel = LEVEL_NUM.log;
3502
+ const loggerSetLevel = (level) => {
3503
+ number$1(LEVEL_NUM[level], `Invalid log level: ${level}`);
3504
+ currentLogLevel = LEVEL_NUM[level];
3505
+ };
3495
3506
  const logger = (...baseArgs) => {
3507
+ if (isString(baseArgs[0]?.url)) {
3508
+ baseArgs[0] = baseArgs[0]?.url;
3509
+ }
3496
3510
  if (typeof baseArgs[0] === "string" && baseArgs[0][0] !== "[") {
3497
3511
  baseArgs[0] = `[${baseArgs[0].split("/").at(-1).split("?", 1)[0]}]`;
3498
3512
  }
3499
3513
  const writeLog = (level, ...[pattern, ...args]) => {
3514
+ const levelNum = LEVEL_NUM[level];
3515
+ if (levelNum < currentLogLevel) {
3516
+ return;
3517
+ }
3500
3518
  if (!isString(pattern)) {
3501
3519
  console[level](...baseArgs, pattern, ...args);
3502
3520
  return;
3503
3521
  }
3504
3522
  const unusedArgs = [];
3505
3523
  const formatted = sprintf(pattern, args, unusedArgs);
3506
- console[level](...baseArgs, ...formatted, ...unusedArgs);
3524
+ console[level](...baseArgs, formatted, ...unusedArgs);
3507
3525
  };
3508
3526
  const log = writeLog.bind(null, "log");
3509
3527
  const info = writeLog.bind(null, "info");
@@ -3521,9 +3539,6 @@ const logger = (...baseArgs) => {
3521
3539
  debug,
3522
3540
  extend
3523
3541
  };
3524
- Object.defineProperty(instance, "debug", {
3525
- get: () => IS_DEV ? debug : noop
3526
- });
3527
3542
  return instance;
3528
3543
  };
3529
3544
 
@@ -4562,6 +4577,7 @@ exports.isoToFlagEmoji = isoToFlagEmoji;
4562
4577
  exports.kebabCase = kebabCase;
4563
4578
  exports.keyBy = keyBy;
4564
4579
  exports.logger = logger;
4580
+ exports.loggerSetLevel = loggerSetLevel;
4565
4581
  exports.lowerCase = lowerCase;
4566
4582
  exports.luminance = luminance;
4567
4583
  exports.maskingEmail = maskingEmail;