UNPKG

@halospv3/hce.shared-config

Version:

Automate commit message quality, changelogs, and CI/CD releases. Exports a semantic-release shareable configuration deserialized from this package's '.releaserc.yml'. Shared resources for .NET projects are also distributed with this package.

73 lines (67 loc) 3.07 kB
import { getOwnPropertyDescriptors } from './getOwnPropertyDescriptors.mjs'; import { getPrototypesChainOf } from './getPrototypeChainOf.mjs'; /* eslint-disable jsdoc/check-tag-names */ /** * JSDoc type imports * @typedef {import('./getPrototypeOf.js').getPrototypeOf} getPrototypeOf * @typedef {import('./listOwnGetters.js').listOwnGetters} listOwnGetters * @typedef {import('./InstancePropertyDescriptorMap.js').InstancePropertyDescriptorMap} InstancePropertyDescriptorMap */ /* eslint-enable jsdoc/check-tag-names */ /** * A conditional wrapper for {@link InstanceTypeOrSelfPropertyDescriptorMap} and * {@link OwnPropertyDescriptorMap}. * * If {@link _InstanceOrStatic} is 'Instance', {@link InstanceTypeOrSelfPropertyDescriptorMap}.\ * Else if {@link _InstanceOrStatic} is 'Static', * {@link OwnPropertyDescriptorMap }.\ * Else, `never`. * @template {ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>} Class * A class definition cast to {@link ClassLike}. * @template {InstanceOrStatic} _InstanceOrStatic * 'Instance' or 'Static'. Determines the return type. * @since 3.0.0 */ /** * An * ordered array of {@link OwnPropertyDescriptorMap} or * {@link InstancePropertyDescriptorMap} starting with {@link classDefinition} * and ending with a {@link BaseClass}. * @template {ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>} Class * @template {'Instance' | 'Static'} InstanceOrStatic * @template {Integer<number>} [Limit=16] * @template {Integer<number>} [CurrentLevel=0] */ /** * Walks the class inheritance chain to get a PropertyDescriptorMap of each class. * * While you _can_ use this to get an array of getter names/keys, you should use {@link getPrototypeOf} and {@link listOwnGetters}, instead! * @template Class Any class definition type-cast to {@link ClassLike} * @template _InstanceOrStatic * @param classDefinition Any class definition type-cast to {@link ClassLike} * @param instanceOrStatic 'Instance' or 'Static'. Determines the return type. * @returns An * ordered array of {@link OwnPropertyDescriptorMap} or * {@link InstancePropertyDescriptorMap} starting with {@link classDefinition} * and ending with a {@link BaseClass}. * @since 3.0.0 */ function getOwnPropertyDescriptorsRecursively(classDefinition, instanceOrStatic) { const staticProtoChain = getPrototypesChainOf(classDefinition, 'classes'); if (isSingleTuple(staticProtoChain)) { return [getOwnPropertyDescriptors(staticProtoChain[0], instanceOrStatic)]; } const recursedPropertyDescriptorMapArray = staticProtoChain.map(classDefinition => getOwnPropertyDescriptors(classDefinition, instanceOrStatic)); return recursedPropertyDescriptorMapArray; } /** * Simple utility for single-tuple type assertion * @template {T} T T in T[] * @param array an array * @returns array is [T] */ function isSingleTuple(array) { return Array.isArray(array) && array.length === 1; } export { getOwnPropertyDescriptorsRecursively }; //# sourceMappingURL=getOwnPropertyDescriptorsRecursively.mjs.map