{"version":3,"file":"index-node20.mjs","sources":["../src/index.ts"],"sourcesContent":["export interface DefinePropertyOptions {\n  configurable?: boolean;\n  enumerable?: boolean;\n  writable?: boolean;\n}\n\nexport interface EnumerableOptions {\n  enumerable?: boolean;\n}\n\nexport interface ConfigurableEnumerableOptions {\n  configurable?: boolean;\n  enumerable?: boolean;\n}\n\n/**\n * Defines a property on an object with optional configuration\n *\n * @example\n * const obj = {};\n * defineProperty(obj, 'name', 'John');\n * console.log(obj.name); // 'John'\n *\n * // With options\n * defineProperty(obj, 'age', 25, { writable: false });\n * obj.age = 30; // Will not change the value\n * console.log(obj.age); // 25\n *\n * @param {Object} target\n * @param {string} property name of the property\n * @param {*} value value\n * @param {Object} [options]\n * @param {boolean} [options.writable=true]\n * @param {boolean} [options.configurable=true]\n * @param {boolean} [options.enumerable=false]\n * @return {Object} target\n */\nexport function defineProperty<T, P extends string, V>(\n  target: T,\n  property: P,\n  value: V,\n  options?: DefinePropertyOptions,\n): any | (Record<P, V> & T) {\n  Object.defineProperty(target, property, {\n    value,\n    writable: options?.writable !== false,\n    configurable: options?.configurable !== false,\n    enumerable: options?.enumerable,\n  });\n  return target;\n}\n\n/**\n * Defines a non-writable and non-configurable property\n *\n * @example\n * const obj = {};\n * defineConstant(obj, 'PI', 3.14);\n * obj.PI = 3.15; // Will not change the value\n * console.log(obj.PI); // 3.14\n *\n * // With enumerable option\n * defineConstant(obj, 'E', 2.718, { enumerable: true });\n * console.log(Object.keys(obj)); // ['E']\n *\n * @param {Object} target\n * @param {string} property name of the property\n * @param {*} value value\n * @param {Object} [options]\n * @param {boolean} [options.enumerable=false]\n * @return {Object} target\n */\nexport function defineConstant<T, P extends string, V>(\n  target: T,\n  property: P,\n  value: V,\n  options?: EnumerableOptions,\n): any | (Readonly<Record<P, V>> & T) {\n  Object.defineProperty(target, property, {\n    value,\n    writable: false,\n    configurable: false,\n    enumerable: options?.enumerable,\n  });\n  return target;\n}\n\nexport type Getter<V> = () => V;\n\n/**\n * Defines a getter property\n *\n * @example\n * const person = { firstName: 'John', lastName: 'Doe' };\n * defineGetter(person, 'fullName', function() {\n *   return `${this.firstName} ${this.lastName}`;\n * });\n * console.log(person.fullName); // 'John Doe'\n *\n * @param {Object} target\n * @param {string} property name of the property\n * @param {Function} getter getter function\n * @param {Object} [options]\n * @param {boolean} [options.configurable=true]\n * @param {boolean} [options.enumerable=false]\n * @return {Object} target\n */\nexport function defineGetter<T, P extends string, V>(\n  target: T,\n  property: P,\n  getter: Getter<V>,\n  options?: ConfigurableEnumerableOptions,\n): any | (Readonly<Record<P, V>> & T) {\n  Object.defineProperty(target, property, {\n    get: getter,\n    configurable: options?.configurable !== false,\n    enumerable: options?.enumerable,\n  });\n  return target;\n}\n\nexport type Setter<T, V> = (value: T) => V;\n\n/**\n * Defines a setter property\n *\n * @example\n * const person = { };\n * defineSetter(person, 'age', function(value) {\n *   if (value < 0) throw new Error('Age cannot be negative');\n *   this._age = value;\n * });\n * person.age = 25; // Sets _age to 25\n * person.age = -1; // Throws error\n *\n * @param {Object} target\n * @param {string} property name of the property\n * @param {Function} setter setter function\n * @param {Object} [options]\n * @param {boolean} [options.configurable=true]\n * @param {boolean} [options.enumerable=false]\n * @return {Object} target\n */\nexport function defineSetter<T, P extends string, V>(\n  target: T,\n  property: P,\n  setter: Setter<any, V>,\n  options?: ConfigurableEnumerableOptions,\n): any | (Partial<Record<P, V>> & T) {\n  Object.defineProperty(target, property, {\n    set: setter,\n    configurable: options?.configurable !== false,\n    enumerable: options?.enumerable,\n  });\n  return target;\n}\n\nexport type LazyCallback<V> = () => V;\n\n/**\n * Defines a property that is initialized only when first accessed\n *\n * @example\n * const obj = {};\n * defineLazyProperty(obj, 'expensiveData', function() {\n *   return someExpensiveComputation();\n * });\n * // expensiveData is not computed until accessed\n * console.log(obj.expensiveData); // Computes and returns the value\n *\n * @param {Object} target\n * @param {string} property name of the property\n * @param {Function} callback function called when the property is accessed the first time\n * @param {Object} [options]\n * @param {boolean} [options.writable=true]\n * @param {boolean} [options.configurable=true]\n * @param {boolean} [options.enumerable=false]\n * @return {Object} target\n */\nexport function defineLazyProperty<T, P extends string, V>(\n  target: T,\n  property: P,\n  callback: LazyCallback<V>,\n  options?: DefinePropertyOptions,\n): any | (Record<P, V> & T) {\n  defineGetter(\n    target,\n    property,\n    function (this: any): V {\n      const value = callback.call(this);\n      defineProperty(this, property, value, options);\n      return value;\n    },\n    { configurable: true, enumerable: options?.enumerable },\n  );\n  return target;\n}\n\n/**\n * Defines a constant property that is initialized only when first accessed\n *\n * @example\n * const obj = {};\n * defineLazyConstant(obj, 'config', function() {\n *   return loadConfigurationFile();\n * });\n * // config is loaded only when first accessed\n * console.log(obj.config); // Loads and returns the config\n * obj.config = {}; // Will not change the value\n *\n * @param {Object} target\n * @param {string} property name of the property\n * @param {Function} callback function called when the property is accessed the first time\n * @param {Object} [options]\n * @param {boolean} [options.enumerable=false]\n * @return {Object} target\n */\nexport function defineLazyConstant<T, P extends string, V>(\n  target: T,\n  property: P,\n  callback: LazyCallback<V>,\n  options?: EnumerableOptions,\n): any | (Readonly<Record<P, V>> & T) {\n  defineGetter(\n    target,\n    property,\n    function (this: any): V {\n      const value = callback.call(this);\n      defineConstant(this, property, value, options);\n      return value;\n    },\n    { configurable: true, enumerable: options?.enumerable },\n  );\n  return target;\n}\n\n/**\n * Defines a property on a class prototype\n *\n * @example\n * class Person {}\n * definePrototypeProperty(Person, 'species', 'human');\n * const person = new Person();\n * console.log(person.species); // 'human'\n *\n * @param {Function} Class\n * @param {string} property name of the property\n * @param {*} value value\n * @param {Object} [options]\n * @param {boolean} [options.writable=true]\n * @param {boolean} [options.configurable=true]\n * @param {boolean} [options.enumerable=false]\n * @return {Object} target\n */\nexport function definePrototypeProperty<\n  T extends { prototype: unknown },\n  P extends string,\n  V,\n>(\n  Class: T,\n  property: P,\n  value: V,\n  options?: DefinePropertyOptions,\n): any | (Record<P, V> & T) {\n  defineProperty(Class.prototype, property, value, options);\n  return Class;\n}\n\n/**\n * Defines a constant property on a class prototype\n *\n * @example\n * class ValidationRule {\n *   constructor(value) {\n *     this.value = value;\n *   }\n *\n *   validate() {\n *     return this.value <= this.MAX_LENGTH && this.value >= this.MIN_LENGTH;\n *   }\n * }\n * definePrototypeConstant(ValidationRule, 'MIN_LENGTH', 3);\n * definePrototypeConstant(ValidationRule, 'MAX_LENGTH', 50);\n *\n * const rule = new ValidationRule('hello');\n * console.log(rule.MIN_LENGTH); // 3\n * rule.MIN_LENGTH = 1; // Will not change the value\n *\n * @param {Function} Class\n * @param {string} property name of the property\n * @param {*} value value\n * @param {Object} [options]\n * @param {boolean} [options.enumerable=false]\n * @return {Object} target\n */\nexport function definePrototypeConstant<\n  T extends { prototype: unknown },\n  P extends string,\n  V,\n>(\n  Class: T,\n  property: P,\n  value: V,\n  options?: EnumerableOptions,\n): any | (Readonly<Record<P, V>> & T) {\n  defineConstant(Class.prototype, property, value, options);\n  return Class;\n}\n\n/**\n * Defines a getter on a class prototype\n *\n * @example\n * class Rectangle {\n *   constructor(width, height) {\n *     this.width = width;\n *     this.height = height;\n *   }\n * }\n * definePrototypeGetter(Rectangle, 'area', function() {\n *   return this.width * this.height;\n * });\n * const rect = new Rectangle(5, 3);\n * console.log(rect.area); // 15\n *\n * @param {Function} Class\n * @param {string} property name of the property\n * @param {Function} getter getter function\n * @param {Object} [options]\n * @param {boolean} [options.configurable=true]\n * @param {boolean} [options.enumerable=false]\n * @return {Object} target\n */\nexport function definePrototypeGetter<\n  T extends { prototype: unknown },\n  P extends string,\n  V,\n>(\n  Class: T,\n  property: P,\n  getter: Getter<V>,\n  options?: ConfigurableEnumerableOptions,\n): any | (Record<P, V> & T) {\n  defineGetter(Class.prototype, property, getter, options);\n  return Class;\n}\n\n/**\n * Defines a setter on a class prototype\n *\n * @example\n * class Circle {\n *   constructor() {\n *     this._radius = 0;\n *   }\n * }\n * definePrototypeSetter(Circle, 'radius', function(value) {\n *   if (value < 0) throw new Error('Radius cannot be negative');\n *   this._radius = value;\n * });\n * const circle = new Circle();\n * circle.radius = 5; // Sets _radius to 5\n *\n * @param {Function} Class\n * @param {string} property name of the property\n * @param {Function} setter setter function\n * @param {Object} [options]\n * @param {boolean} [options.configurable=true]\n * @param {boolean} [options.enumerable=false]\n * @return {Object} target\n */\nexport function definePrototypeSetter<\n  T extends { prototype: unknown },\n  P extends string,\n  V,\n>(\n  Class: T,\n  property: P,\n  setter: Setter<any, V>,\n  options?: ConfigurableEnumerableOptions,\n): any | (Partial<Record<P, V>> & T) {\n  defineSetter(Class.prototype, property, setter, options);\n  return Class;\n}\n\n/**\n * Defines a lazy property on a class prototype\n *\n * @example\n * class User {\n *   constructor(id) {\n *     this.id = id;\n *   }\n * }\n * definePrototypeLazyProperty(User, 'details', function() {\n *   return fetchUserDetails(this.id);\n * });\n * const user = new User(1);\n * // details are fetched only when accessed\n * console.log(user.details); // Fetches and returns user details\n *\n * @param {Function} Class\n * @param {string} property name of the property\n * @param {Function} callback function called when the property is accessed the first time\n * @param {Object} [options]\n * @param {boolean} [options.writable=true]\n * @param {boolean} [options.configurable=true]\n * @param {boolean} [options.enumerable=false]\n * @return {Object} target\n */\nexport function definePrototypeLazyProperty<\n  T extends { prototype: unknown },\n  P extends string,\n  V,\n>(\n  Class: T,\n  property: P,\n  callback: LazyCallback<V>,\n  options?: DefinePropertyOptions,\n): any | (Record<P, V> & T) {\n  defineLazyProperty(Class.prototype, property, callback, options);\n  return Class;\n}\n\n/**\n * Defines a lazy constant on a class prototype\n *\n * @example\n * class Database {\n *   constructor(url) {\n *     this.url = url;\n *   }\n * }\n * definePrototypeLazyConstant(Database, 'connection', function() {\n *   return createDatabaseConnection(this.url);\n * });\n * const db = new Database('mongodb://localhost');\n * // Connection is established only when first accessed\n * console.log(db.connection);\n *\n * @param {Function} Class\n * @param {string} property name of the property\n * @param {Function} callback function called when the property is accessed the first time\n * @param {Object} [options]\n * @param {boolean} [options.enumerable=false]\n * @return {Object} target\n */\nexport function definePrototypeLazyConstant<\n  T extends { prototype: unknown },\n  P extends string,\n  V,\n>(\n  Class: T,\n  property: P,\n  callback: LazyCallback<V>,\n  options?: EnumerableOptions,\n): any | (Readonly<Record<P, V>> & T) {\n  defineLazyConstant(Class.prototype, property, callback, options);\n  return Class;\n}\n\n/**\n * Defines multiple properties on an object at once\n *\n * @example\n * const person = {};\n * defineProperties(person, {\n *   name: 'John',\n *   age: 30,\n *   city: 'New York'\n * });\n * console.log(person.name); // 'John'\n * console.log(person.age); // 30\n *\n * // With options\n * defineProperties(person, {\n *   country: 'USA',\n *   zipCode: '10001'\n * }, { enumerable: true });\n *\n * @param {Object} target\n * @param {Object} [properties]\n * @param {Object} [options]\n * @param {boolean} [options.writable=true]\n * @param {boolean} [options.configurable=true]\n * @param {boolean} [options.enumerable=false]\n * @return {Object} target\n */\nexport function defineProperties<T, P extends Record<string, any>>(\n  target: T,\n  properties?: P,\n  options?: DefinePropertyOptions,\n): T | any | (P & T) {\n  if (!properties) {\n    return target;\n  }\n\n  const optionsObject: DefinePropertyOptions = {\n    writable: options?.writable !== false,\n    configurable: options?.configurable !== false,\n    enumerable: !!options?.enumerable,\n  };\n\n  Object.keys(properties).forEach((key: string) => {\n    Object.defineProperty(target, key, {\n      value: properties[key],\n      writable: optionsObject.writable,\n      configurable: optionsObject.configurable,\n      enumerable: optionsObject.enumerable,\n    });\n  });\n  return target;\n}\n\n/**\n * Defines multiple constant properties on an object at once\n *\n * @example\n * const config = {};\n * defineConstants(config, {\n *   API_URL: 'https://api.example.com',\n *   MAX_RETRIES: 3,\n *   TIMEOUT: 5000\n * });\n *\n * config.API_URL = 'new-url'; // Will not change the value\n * console.log(config.API_URL); // 'https://api.example.com'\n *\n * @param {Object} target\n * @param {Object} [properties]\n * @param {Object} [options]\n * @param {boolean} [options.enumerable=false]\n * @return {Object} target\n */\nexport function defineConstants<T, P extends Record<string, any>>(\n  target: T,\n  properties?: P,\n  options?: EnumerableOptions,\n): Readonly<P> & T {\n  // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n  return defineProperties(target, properties, {\n    writable: false,\n    configurable: false,\n    enumerable: options?.enumerable,\n  });\n}\n"],"names":[],"mappings":"AAqCO,SAAS,cACd,CAAA,MAAA,EACA,QACA,EAAA,KAAA,EACA,OAC0B,EAAA;AAC1B,EAAO,MAAA,CAAA,cAAA,CAAe,QAAQ,QAAU,EAAA;AAAA,IACtC,KAAA;AAAA,IACA,QAAA,EAAU,SAAS,QAAa,KAAA,KAAA;AAAA,IAChC,YAAA,EAAc,SAAS,YAAiB,KAAA,KAAA;AAAA,IACxC,YAAY,OAAS,EAAA;AAAA,GACtB,CAAA;AACD,EAAO,OAAA,MAAA;AACT;AAsBO,SAAS,cACd,CAAA,MAAA,EACA,QACA,EAAA,KAAA,EACA,OACoC,EAAA;AACpC,EAAO,MAAA,CAAA,cAAA,CAAe,QAAQ,QAAU,EAAA;AAAA,IACtC,KAAA;AAAA,IACA,QAAU,EAAA,KAAA;AAAA,IACV,YAAc,EAAA,KAAA;AAAA,IACd,YAAY,OAAS,EAAA;AAAA,GACtB,CAAA;AACD,EAAO,OAAA,MAAA;AACT;AAsBO,SAAS,YACd,CAAA,MAAA,EACA,QACA,EAAA,MAAA,EACA,OACoC,EAAA;AACpC,EAAO,MAAA,CAAA,cAAA,CAAe,QAAQ,QAAU,EAAA;AAAA,IACtC,GAAK,EAAA,MAAA;AAAA,IACL,YAAA,EAAc,SAAS,YAAiB,KAAA,KAAA;AAAA,IACxC,YAAY,OAAS,EAAA;AAAA,GACtB,CAAA;AACD,EAAO,OAAA,MAAA;AACT;AAwBO,SAAS,YACd,CAAA,MAAA,EACA,QACA,EAAA,MAAA,EACA,OACmC,EAAA;AACnC,EAAO,MAAA,CAAA,cAAA,CAAe,QAAQ,QAAU,EAAA;AAAA,IACtC,GAAK,EAAA,MAAA;AAAA,IACL,YAAA,EAAc,SAAS,YAAiB,KAAA,KAAA;AAAA,IACxC,YAAY,OAAS,EAAA;AAAA,GACtB,CAAA;AACD,EAAO,OAAA,MAAA;AACT;AAw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