{
  "version": 3,
  "sources": ["../../../src/utils/decorators/define.mts"],
  "sourcesContent": ["import type {\n  AnyMethod,\n  Getter,\n  Method,\n  MethodKeys,\n  Setter,\n} from \"../../types/concepts.mjs\";\nimport type { PropertyConfig } from \"../object-operation.mjs\";\nimport { overwriteDescriptorConfig } from \"../object-operation.mjs\";\nimport type { ExtractToMethod } from \"./typed.mjs\";\nimport { method, property } from \"./typed.mjs\";\n\nexport const DefineProperty = <T extends unknown>(\n  descriptor: TypedPropertyDescriptor<T>\n): PropertyDecorator =>\n  property((target, key) => {\n    Object.defineProperty(target, key, descriptor);\n  });\n\nexport interface MethodDecoratorContext<This, Key extends MethodKeys<This>> {\n  target: This;\n  name: Key;\n  func: ExtractToMethod<This, Key>;\n}\n\nexport const WrappedMethod = <This, Key extends MethodKeys<This>>(\n  wrapper: Method<\n    This,\n    [\n      MethodDecoratorContext<This, Key>,\n      ...Parameters<Extract<This[Key], AnyMethod>>\n    ],\n    ReturnType<Extract<This[Key], AnyMethod>>\n  >,\n  overwrite?: PropertyConfig\n): MethodDecorator =>\n  method<This, Key>((target, methodName, descriptor) => {\n    const originalMethod = descriptor.value;\n    // @ts-expect-error Conditional type\n    descriptor.value = function (this: This, ...args: Parameters<This[Key]>) {\n      return wrapper.apply(this, [\n        { name: methodName, target, func: originalMethod! },\n        ...args,\n      ]);\n    };\n    overwriteDescriptorConfig(overwrite, descriptor);\n    return descriptor;\n  });\n\nexport interface Accessors<This, T> {\n  get: Getter<This, T>;\n  set: Setter<This, T>;\n}\n\nexport interface AccessorContext<\n  This,\n  Key extends keyof This,\n  Type extends keyof Accessors<This, This[Key]>\n> {\n  func: Accessors<This, This[Key]>[Type];\n  target: This;\n  name: Key;\n}\n\nexport const Accesser = <\n  This,\n  Key extends keyof This,\n  Type extends keyof Accessors<This, This[Key]>\n>(\n  type: Type,\n  handler: Method<\n    This,\n    [\n      AccessorContext<This, Key, Type>,\n      ...Parameters<Accessors<This, This[Key]>[Type]>\n    ],\n    ReturnType<Accessors<This, This[Key]>[Type]>\n  >,\n  overwrite?: PropertyConfig\n): MethodDecorator =>\n  method(\n    // @ts-expect-error Contravariance\n    (target: This, key: Key, describer: TypedPropertyDescriptor<This[Key]>) => {\n      const originalAccessor = describer[type]!;\n      // @ts-expect-error Index type inferred as union type\n      describer[type] = function (\n        this: This,\n        ...args: Parameters<Accessors<This, This[Key]>[Type]>\n      ) {\n        return handler.call(\n          this,\n          // @ts-expect-error Index type inferred as union type\n          { func: originalAccessor, name: key, target },\n          ...args\n        );\n      };\n      overwriteDescriptorConfig(overwrite, describer);\n      return describer;\n    }\n  );\n"],
  "mappings": "AAQA;AAEA;AAEO,MAAM,iBAAiB,CAC5B,eAEA,SAAS,CAAC,QAAQ,QAAQ;AACxB,SAAO,eAAe,QAAQ,KAAK;AAAA;AAShC,MAAM,gBAAgB,CAC3B,SAQA,cAEA,OAAkB,CAAC,QAAQ,YAAY,eAAe;AACpD,QAAM,iBAAiB,WAAW;AAElC,aAAW,QAAQ,YAAyB,MAA6B;AACvE,WAAO,QAAQ,MAAM,MAAM;AAAA,MACzB,EAAE,MAAM,YAAY,QAAQ,MAAM;AAAA,MAClC,GAAG;AAAA;AAAA;AAGP,4BAA0B,WAAW;AACrC,SAAO;AAAA;AAkBJ,MAAM,WAAW,CAKtB,MACA,SAQA,cAEA,OAEE,CAAC,QAAc,KAAU,cAAkD;AACzE,QAAM,mBAAmB,UAAU;AAEnC,YAAU,QAAQ,YAEb,MACH;AACA,WAAO,QAAQ,KACb,MAEA,EAAE,MAAM,kBAAkB,MAAM,KAAK,UACrC,GAAG;AAAA;AAGP,4BAA0B,WAAW;AACrC,SAAO;AAAA;",
  "names": []
}
