{"version":3,"sources":["../../src/utils/decorators/autobind.ts","../../src/utils/decorators/bound.ts","../../src/lib/ms.ts","../../src/utils/serialize.ts","../../src/utils/decorators/cached.ts","../../src/utils/decorators/memoized.ts","../../src/utils/decorators/sealed.ts"],"names":["autobind","target","_","args","names","name","__name","bound","context","regex","ms","str","groups","n","serialize","value","cached","duration","cache","AspectraMap","now","key","entry","result","memoized","sealed","SealedClassExtentionError"],"mappings":"oEA4BO,SAASA,CAAAA,CACdC,EACAC,CACG,CAAA,CACH,OAAO,cAAcD,CAAO,CAC1B,WAAeE,CAAAA,GAAAA,CAAAA,CAA4B,CACzC,KAAM,CAAA,GAAGA,CAAI,CACb,CAAA,IAAMC,EAAQ,MAAO,CAAA,mBAAA,CAAoBH,CAAO,CAAA,SAAS,CAGzD,CAAA,IAAA,IAAWI,KAAQD,CACb,CAAA,OAAO,KAAKC,CAAI,CAAA,EAAM,YAAcA,CAAS,GAAA,aAAA,GAC/C,KAAKA,CAAI,CAAA,CAAI,KAAKA,CAAI,CAAA,CAAE,KAAK,IAAI,CAAA,EAGvC,CACF,CACF,CAjBgBC,mBAAAN,CAAAA,CAAAA,CAAA,UCNT,CAAA,CAAA,SAASO,EACdN,CACAO,CAAAA,CAAAA,CACM,CACNA,CAAQ,CAAA,cAAA,CAAe,UAAY,CACjC,IAAA,CAAKA,EAAQ,IAAe,CAAA,CAAIP,EAAO,IAAK,CAAA,IAAI,EAClD,CAAC,EACH,CAPgBK,mBAAAC,CAAAA,CAAAA,CAAA,OC+BhB,CAAA,CAAA,IAAME,CACJ,CAAA,iJAAA,CAEK,SAASC,CAAGC,CAAAA,CAAAA,CAAqB,CACtC,GAAIA,CAAAA,CAAI,SAAW,CAAKA,EAAAA,CAAAA,CAAI,OAAS,GACnC,CAAA,MAAM,IAAI,KACR,CAAA,wEACF,EAEF,IAAMC,CAAAA,CAASH,EAAM,IAAKE,CAAAA,CAAG,CAAG,EAAA,MAAA,CAChC,GAAI,CAACC,EACH,OAAO,MAAA,C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ASC,CAAAA,CACdxB,EACAC,CACG,CAAA,CACH,OAAO,cAAcD,CAAO,CAC1B,WAAeC,CAAAA,GAAAA,CAAAA,CAAyB,CACtC,MAAA,KAAA,EACM,CAAA,IAAIwB,oBAA0BzB,CAAO,CAAA,IAAA,CAAM,KAAK,WAAY,CAAA,IAAI,CACxE,CACF,CACF,CAVgBK,mBAAAA,CAAAmB,CAAA,CAAA,QAAA,CAAA","file":"index.cjs","sourcesContent":["import type { Class, MixinConstructorArgs } from '../../types'\n\n/**\n * # Autobind\n *\n * Automatically binds all class methods to the instance.\n *\n * ```typescript\n * import { autobind } from 'aspectra/utils'\n *\n * @autobind\n * class Greeting {\n *   private readonly name = 'John'\n *\n *   public hello() {\n *     console.log(`Hello from ${this.name}`)\n *   }\n *\n *   public farewell() {\n *     console.log(`Goodbye from ${this.name}`)\n *   }\n * }\n *\n * const { hello, farewell } = new Greeting()\n * hello()\n * farewell()\n * ```\n */\nexport function autobind<T extends Class<object, MixinConstructorArgs>>(\n  target: T,\n  _: ClassDecoratorContext<T>,\n): T {\n  return class extends target {\n    constructor(...args: MixinConstructorArgs) {\n      super(...args)\n      const names = Object.getOwnPropertyNames(target.prototype) as Array<\n        keyof this\n      >\n      for (const name of names) {\n        if (typeof this[name] === 'function' && name !== 'constructor') {\n          this[name] = this[name].bind(this)\n        }\n      }\n    }\n  }\n}\n","import type { Fun, UnknownArgs } from '../../types'\n\n/**\n * # Bound\n *\n * Binds a class method to its instance.\n *\n * ```typescript\n * import { bound } from 'aspectra/utils'\n *\n * class Example {\n *   private readonly name = 'John'\n *\n *   @bound public greet() {\n *     console.log(`Hello from ${this.name}`)\n *   }\n * }\n *\n * const { greet } = new Example()\n * greet()\n * ```\n */\nexport function bound<A extends UnknownArgs, R, T>(\n  target: Fun<A, R, T>,\n  context: ClassMethodDecoratorContext<T, typeof target>,\n): void {\n  context.addInitializer(function () {\n    this[context.name as keyof T] = target.bind(this) as T[keyof T]\n  })\n}\n","/**\n * This file uses code from `ms` by Vercel, Inc.,\n * licensed under the MIT License. See https://github.com/vercel/ms\n *\n * The file has been modified by Shun Ueda <me@shu.nu>.\n */\nconst s = 1000\nconst m = s * 60\nconst h = m * 60\nconst d = h * 24\nconst w = d * 7\nconst y = d * 365.25\n\ntype Unit =\n  | 'Years'\n  | 'Year'\n  | 'Yrs'\n  | 'Yr'\n  | 'Y'\n  | 'Weeks'\n  | 'Week'\n  | 'W'\n  | 'Days'\n  | 'Day'\n  | 'D'\n  | 'Hours'\n  | 'Hour'\n  | 'Hrs'\n  | 'Hr'\n  | 'H'\n  | 'Minutes'\n  | 'Minute'\n  | 'Mins'\n  | 'Min'\n  | 'M'\n  | 'Seconds'\n  | 'Second'\n  | 'Secs'\n  | 'Sec'\n  | 's'\n  | 'Milliseconds'\n  | 'Millisecond'\n  | 'Msecs'\n  | 'Msec'\n  | 'Ms'\n\ntype UnitAnyCase = Unit | Uppercase<Unit> | Lowercase<Unit>\n\nexport type TimeString =\n  | `${number}`\n  | `${number}${UnitAnyCase}`\n  | `${number} ${UnitAnyCase}`\n\nconst regex =\n  /^(?<value>-?(?:\\d+)?\\.?\\d+) *(?<type>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i\n\nexport function ms(str: string): number {\n  if (str.length === 0 || str.length > 100) {\n    throw new Error(\n      'Value provided to parse must be a string with length between 1 and 99.',\n    )\n  }\n  const groups = regex.exec(str)?.groups\n  if (!groups) {\n    return Number.NaN\n  }\n  const n = Number.parseFloat(groups.value || '')\n  switch ((groups.type || 'ms').toLowerCase()) {\n    case 'years':\n    case 'year':\n    case 'yrs':\n    case 'yr':\n    case 'y':\n      return n * y\n    case 'weeks':\n    case 'week':\n    case 'w':\n      return n * w\n    case 'days':\n    case 'day':\n    case 'd':\n      return n * d\n    case 'hours':\n    case 'hour':\n    case 'hrs':\n    case 'hr':\n    case 'h':\n      return n * h\n    case 'minutes':\n    case 'minute':\n    case 'mins':\n    case 'min':\n    case 'm':\n      return n * m\n    case 'seconds':\n    case 'second':\n    case 'secs':\n    case 'sec':\n    case 's':\n      return n * s\n    case 'milliseconds':\n    case 'millisecond':\n    case 'msecs':\n    case 'msec':\n    case 'ms':\n      return n\n    default:\n      // This should never occur.\n      throw new Error()\n  }\n}\n","import { name } from '../../package.json'\n\nexport type Serializable =\n  | string\n  | number\n  | boolean\n  | bigint\n  | null\n  | undefined\n  | { [_: string]: Serializable }\n  | Serializable[]\n  | Date\n\n/**\n * @internal\n */\nexport function serialize(value: Serializable): string {\n  if (value === undefined) {\n    return `__${name}_undefined__`\n  }\n  if (value === null) {\n    return `__${name}_null__`\n  }\n  if (typeof value === 'bigint') {\n    return `__${name}_bigint_${value.toString()}n__`\n  }\n  if (value instanceof Date) {\n    return value.toISOString()\n  }\n  return JSON.stringify(value)\n}\n","import { AspectraMap } from '../../collections/map'\nimport { type TimeString, ms } from '../../lib/ms'\nimport type { Fun } from '../../types'\nimport { type Serializable, serialize } from '../serialize'\n\ninterface CacheEntry<T> {\n  value: T\n  expiration: number\n}\n\n/**\n * # Cached\n *\n * Similar to `memoized`, but with an expiration time.\n *\n * <Callout type='info'>\n *   Duration can be specified in milliseconds or using a human-readable\n *   string, powered by [`ms`](https://github.com/vercel/ms?tab=readme-ov-file#ms).\n * </Callout>\n *\n * ```typescript\n * import { cached } from 'aspectra/utils'\n *\n * class Database {\n *   @cached('2h') public queryAll() {\n *     // sql: SELECT * FROM table\n *   }\n * }\n * ```\n */\nexport function cached<T, U extends Serializable[], R>(\n  duration: TimeString | number,\n) {\n  return (\n    target: Fun<U, R, T>,\n    context: ClassMethodDecoratorContext<T, typeof target>,\n  ): void => {\n    const cache = new AspectraMap<string, CacheEntry<R>>()\n    context.addInitializer(function () {\n      this[context.name as keyof T] = ((...args: U) => {\n        const now = Date.now()\n        const key = serialize(args)\n        const entry = cache.get(key)\n        if (entry && entry?.expiration > now) {\n          return entry.value\n        }\n        const result = target.call(this, ...args)\n        cache.set(key, {\n          value: result,\n          expiration:\n            now + (typeof duration === 'number' ? duration : ms(duration)),\n        } satisfies CacheEntry<R>)\n        return result\n      }) as T[keyof T]\n    })\n  }\n}\n","import { AspectraMap } from '../../collections/map'\nimport type { Fun } from '../../types'\nimport { type Serializable, serialize } from '../serialize'\n\n/**\n * # Memoized\n *\n * Memoizes the method. Usful for optimizing expensive computations.\n *\n * ```typescript\n * import { memoized } from 'aspectra/utils'\n *\n * class Calculator {\n *   @memoized public square(num: number): number {\n *     console.log('Calculating...')\n *     return num * num\n *   }\n * }\n *\n * const calculator = new Calculator()\n * console.log(calculator.square(2))\n * console.log(calculator.square(2))\n * ```\n */\nexport function memoized<T, U extends Serializable[], R>(\n  target: Fun<U, R, T>,\n  context: ClassMethodDecoratorContext<T, typeof target>,\n): void {\n  const cache = new AspectraMap<string, R>()\n  context.addInitializer(function () {\n    this[context.name as keyof T] = ((...args: U) => {\n      const key = serialize(args)\n      return cache.getOrPut(key, () => {\n        return target.call(this, ...args)\n      })\n    }) as T[keyof T]\n  })\n}\n","import { SealedClassExtentionError } from '../../lib/error'\nimport type { Class, MixinConstructorArgs } from '../../types'\n\n/**\n * # Sealed\n *\n * Seals a class, preventing it from being extended.\n *\n * <Callout type='info'>\n *   Error is thrown when attempting to instantiate a derived class.\n * </Callout>\n *\n * ```typescript\n * import { sealed } from 'aspectra/utils'\n *\n * @sealed\n * class Base {}\n *\n * class Derived extends Base {}\n *\n * try {\n *   new Derived()\n * } catch (error) {\n *   console.table(error)\n * }\n * ```\n */\nexport function sealed<T extends Class<object, MixinConstructorArgs>>(\n  target: T,\n  _: ClassDecoratorContext<T>,\n): T {\n  return class extends target {\n    constructor(..._: MixinConstructorArgs) {\n      super()\n      throw new SealedClassExtentionError(target.name, this.constructor.name)\n    }\n  }\n}\n"]}