const missing = Symbol();
class RecordProxyHandler {
  #toValue;
  #onMissing;
  #cache = /* @__PURE__ */ new Map();
  /**
   * @param toValue - Function to transform source values to destination values
   * @param onMissing - Optional function called when accessing a non-existent
   *   property. Can throw an error if desired.
   */
  constructor(toValue, onMissing) {
    this.#toValue = toValue;
    this.#onMissing = onMissing;
  }
  #getOwnValue(target, prop) {
    const v = this.#cache.get(prop);
    if (v !== void 0) {
      return v;
    }
    if (Object.hasOwn(target, prop)) {
      const value = this.#toValue(target[prop], prop);
      this.#cache.set(prop, value);
      return value;
    }
    return missing;
  }
  get(target, prop) {
    if (typeof prop !== "string") {
      return void 0;
    }
    const ownValue = this.#getOwnValue(target, prop);
    if (ownValue !== missing) {
      return ownValue;
    }
    this.#onMissing?.(prop);
    return target[prop];
  }
  getOwnPropertyDescriptor(target, p) {
    if (typeof p !== "string") {
      return void 0;
    }
    const value = this.#getOwnValue(target, p);
    if (value === missing) {
      return void 0;
    }
    const desc = Reflect.getOwnPropertyDescriptor(target, p);
    return { ...desc, value };
  }
}
function recordProxy(target, toValue, onMissing) {
  return new Proxy(
    target,
    new RecordProxyHandler(toValue, onMissing)
  );
}
export {
  recordProxy
};
//# sourceMappingURL=record-proxy.js.map
