{"version":3,"file":"listOwnGetters.mjs","names":[],"sources":["../../../src/utils/reflection/listOwnGetters.ts"],"sourcesContent":["import type { InstanceOrStatic } from '../miscTypes.ts';\nimport { filterForGetters } from './filterForGetters.ts';\nimport { getOwnPropertyDescriptors } from './getOwnPropertyDescriptors.ts';\nimport type {\n  BaseClassProto as BaseClassPrototype,\n  ClassLike,\n  ConstructorConstraint,\n  InstanceTypeOrSelf,\n  SuperClassLike,\n  WithProto as WithPrototype,\n} from './inheritance.ts';\nimport type { InstancePropertyDescriptorMap } from './InstancePropertyDescriptorMap.d.ts';\nimport type { OwnPropertyDescriptorMap } from './OwnPropertyDescriptorMap.d.ts';\n\n/**\n * Description placeholder\n * @template {ClassLike<ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>>} Class\n * @template {InstanceOrStatic} _InstanceOrStatic\n * @since 3.0.0\n */\ntype OwnGetters<\n  Class extends ClassLike<ConstructorConstraint<Class> & WithPrototype<SuperClassLike | BaseClassPrototype>>,\n  _InstanceOrStatic extends InstanceOrStatic,\n>\n  = [_InstanceOrStatic] extends ['Instance']\n    ? Exclude<\n      (Class['__proto__'] extends BaseClassPrototype ? null : InstanceTypeOrSelf<Class['__proto__']>) extends null\n        ? keyof InstanceType<Class>\n        : Exclude<\n          keyof InstanceType<Class>,\n          keyof (Class['__proto__'] extends BaseClassPrototype ? null : InstanceTypeOrSelf<Class['__proto__']>)\n        >,\n      '__proto__'\n    >[]\n    : [_InstanceOrStatic] extends ['Static']\n        ? Exclude<\n          Class['__proto__'] extends null ? keyof Class : Exclude<keyof Class, keyof Class['__proto__']>,\n          '__proto__'\n        >[]\n        : never;\n\n/**\n * # !WARNING!\n * > If you don't specify the Class's SuperClass (or `BaseClassProto`) via WithProto, the return type will wrongly include inherited property names! This is a design limitation of TypeScript.\n *\n * Returns the names of the instantiated (or static), noninherited getters derived from the\n * given prototype or prototype of the given object.\n * @template {ClassLike<ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>>} Class\n * @template {InstanceOrStatic} _InstanceOrStatic 'Instance' or 'Static'. Determines the return type.\n * @param classDefinition Any class cast to ClassLike\n * @param instanceOrStatic 'Instance' or 'Static'. Determines the return type.\n * @since 3.0.0\n * @returns\n * An array of names of getters that were not inherited from a parent class. If {@link classDefinition} is a class instance, the names of instanced getters are returned. Otherwise, the names of static getters are returned;\n */\nexport function listOwnGetters<\n  Class extends ClassLike<ConstructorConstraint<Class> & WithPrototype<SuperClassLike | BaseClassPrototype>>,\n  _InstanceOrStatic extends InstanceOrStatic,\n>(\n  classDefinition: Class,\n  instanceOrStatic: Extract<_InstanceOrStatic, InstanceOrStatic>,\n): OwnGetters<Class, _InstanceOrStatic> {\n  if (instanceOrStatic === 'Instance') {\n    const descriptorMap: InstancePropertyDescriptorMap<Class> = getOwnPropertyDescriptors(classDefinition, instanceOrStatic as 'Instance');\n    const getterDescriptorMap = filterForGetters(descriptorMap);\n    const keyArray = Reflect.ownKeys(getterDescriptorMap) as (keyof typeof getterDescriptorMap)[];\n    return keyArray as [typeof instanceOrStatic & 'Instance'] extends ['Instance'] ? typeof keyArray : never;\n  }\n  if (instanceOrStatic === 'Static') {\n    const descriptorMap: OwnPropertyDescriptorMap<Class> = getOwnPropertyDescriptors(classDefinition, instanceOrStatic as 'Static');\n    const getterDescriptorMap = filterForGetters(descriptorMap);\n    const keyArray = Reflect.ownKeys(getterDescriptorMap) as (keyof typeof getterDescriptorMap)[];\n    return keyArray as [_InstanceOrStatic] extends ['Instance']\n      ? never\n      : [_InstanceOrStatic] extends ['Static']\n          ? typeof keyArray\n          : never;\n  }\n  throw new TypeError('Argument `instanceOrStatic` must be \"Instance\" or \"Static\".');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAuDA,SAAgB,eAId,iBACA,kBACsC;CACtC,IAAI,qBAAqB,YAAY;EAEnC,MAAM,sBAAsB,iBADgC,0BAA0B,iBAAiB,gBAC9C,CAAC;EAE1D,OADiB,QAAQ,QAAQ,mBACnB;CAChB;CACA,IAAI,qBAAqB,UAAU;EAEjC,MAAM,sBAAsB,iBAD2B,0BAA0B,iBAAiB,gBACzC,CAAC;EAE1D,OADiB,QAAQ,QAAQ,mBACnB;CAKhB;CACA,MAAM,IAAI,UAAU,iEAA6D;AACnF"}