/** * @file Lazy-getter primitives + `createConstantsObject`. * `createConstantsObject` is the most-used factory in this module — Socket * repos use it to assemble frozen settings objects with a mix of eager * values, lazy-computed values, and internals reachable through * `kInternalsSymbol`. The `defineLazyGetter*` helpers underneath are the * building blocks; `createLazyGetter` is the memoizing primitive. Cycle: * `defineLazyGetters` → `defineLazyGetter` → `defineGetter` + * `createLazyGetter`. All function-only references, no eager top- level * evaluation between siblings, so ESM tolerates. */ import type { ConstantsObjectOptions, GetterDefObj, LazyGetterStats } from './types.js'; /** * Create a frozen constants object with lazy getters and internal properties. * * This function creates an immutable object with: - Regular properties from * `props` - Lazy getters that compute values on first access - Internal * properties accessible via `kInternalsSymbol` - Mixin properties (lower * priority, won't override existing) - Alphabetically sorted keys for * consistency. * * The resulting object is deeply frozen and cannot be modified. * * @example * ;```ts * const config = createConstantsObject( * { apiUrl: 'https://api.example.com' }, * { * getters: { client: () => new APIClient() }, * internals: { version: '1.0.0' }, * }, * ) * console.log(config.apiUrl) // 'https://api.example.com' * console.log(config.client) // APIClient (lazy) * console.log(config[kInternalsSymbol].version) // '1.0.0' * ``` * * @param props - Regular properties to include on the object. * @param options_ - Configuration options. * * @returns A frozen object with all specified properties */ export declare function createConstantsObject(props: object, options_?: ConstantsObjectOptions | undefined): Readonly; /** * Create a lazy getter function that memoizes its result. * * The returned function will only call the getter once, caching the result for * subsequent calls. This is useful for expensive computations or operations * that should only happen when needed. * * @example * ;```ts * const stats = { initialized: new Set() } * const getLargeData = createLazyGetter('data', () => expensive(), stats) * getLargeData() // Computes and caches * getLargeData() // Returns cached * stats.initialized.has('data') // true * ``` * * @param name - The property key name for the getter (used for debugging and * stats) * @param getter - Function that computes the value on first access. * @param stats - Optional stats object to track initialization. * * @returns A memoized getter function */ export declare function createLazyGetter(name: PropertyKey, getter: () => T, stats?: LazyGetterStats | undefined): () => T; /** * Define a getter property on an object. * * The getter is non-enumerable and configurable, meaning it won't show up in * `for...in` loops or `Object.keys()`, but can be redefined later. * * @example * ;```ts * const obj = {} * defineGetter(obj, 'timestamp', () => Date.now()) * obj.timestamp // Current timestamp (computed each access) * Object.keys(obj) // [] (non-enumerable) * ``` * * @param object - The object to define the getter on. * @param propKey - The property key for the getter. * @param getter - Function that computes the property value. * * @returns The modified object, returned for chaining. */ export declare function defineGetter(object: object, propKey: PropertyKey, getter: () => T): object; /** * Define a lazy getter property on an object. * * Unlike `defineGetter()`, this version memoizes the result so the getter * function is only called once. Subsequent accesses return the cached value. * * @param object - The object to define the lazy getter on. * @param propKey - The property key for the lazy getter. * @param getter - Function that computes the value on first access. * @param stats - Optional stats object to track initialization. * * @returns The modified object, returned for chaining. */ export declare function defineLazyGetter(object: object, propKey: PropertyKey, getter: () => T, stats?: LazyGetterStats | undefined): object; /** * Define multiple lazy getter properties on an object. * * Each getter in the provided object will be converted to a lazy getter and * attached to the target object. All getters share the same stats object for * tracking initialization. * * @param object - The object to define lazy getters on. * @param getterDefObj - Object mapping property keys to getter functions. * @param stats - Optional stats object to track initialization. * * @returns The modified object, returned for chaining. */ export declare function defineLazyGetters(object: object, getterDefObj: GetterDefObj | undefined, stats?: LazyGetterStats | undefined): object;