@halospv3/hce.shared-config
Version:
Automate commit message quality, changelogs, and CI/CD releases. Its `main` entry point is a Semantic Release config. Functions and classes are exposed for customization. An ESLint config, a Commitlint config, and addl. resources for .NET projects are als
1 lines • 10.4 kB
Source Map (JSON)
{"version":3,"file":"inheritance.mjs","names":[],"sources":["../../../src/utils/reflection/inheritance.ts"],"sourcesContent":["/* eslint-disable unicorn/name-replacements */\nimport type { Increment } from '../GracefulRecursion.d.ts';\nimport type { Integer } from '../miscTypes.ts';\nimport type { FunctionLike } from './FunctionLike.d.ts';\nimport { getPrototypeOf } from './getPrototypeOf.ts';\nimport type { PropertyDescriptorMap } from './PropertyDescriptorMap.d.ts';\n\n/**\n * The `[[Prototype]]` (i.e. `__proto__`) of any base class.\n * @since 3.0.0\n */\nexport type BaseClassProto = (() => object) & {\n /** @example BaseClass.__proto__.__proto__.toString() === '[object Object]' */\n ['__proto__']: ObjectConstructor['prototype'] & {\n ['__proto__']: null;\n constructor: ObjectConstructor;\n };\n constructor: IBaseClass;\n length: 0;\n name: '';\n};\n\n/**\n * The `[[Prototype]]` of all base classes.\n * @since 3.0.0\n */\nexport const baseClassProto: BaseClassProto = getPrototypeOf(Object as BaseClass<ObjectConstructor>);\n\n/**\n * [INTERNAL]\n * An interface representing for attaching base class properties to a class type.\n * This kept separate from {@link BaseClass} so it can be used by {@link BaseClassProto}.\n * @since 3.0.0\n */\ninterface IBaseClass {\n /**\n * Readable for compatibility reasons, but invisible and non-enumerable in Node.js runtime.\n * @example BaseClass.__proto__.toString() === 'function () { [native code] }'\n */\n ['__proto__']: BaseClassProto;\n\n constructor: FunctionConstructor & { name: 'Function' };\n}\n\n/**\n * Type a class type as a base class.\n * Note: is `Class & ...`\n * @since 3.0.0\n */\nexport type BaseClass<Class extends ConstructorConstraint<Class>>\n = IClass<Class> & IBaseClass;\n\n/**\n * A type representing any unknown constructor.\n * @since 3.0.0\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Constructor_Unknown = abstract new (...arguments_: any[]) => any;\n\n/**\n * The constraint for constructor types.\n * This is intended for generic type constraints.\n * For conditional return types, use `T extends Constructor<T>` instead.\n * @template T Any newable constructor type\n * @since 3.0.0\n */\nexport type ConstructorConstraint<T extends abstract new (...arguments_: ConstructorParameters<T>) => InstanceType<T>> = abstract new (...arguments_: ConstructorParameters<T>) => InstanceType<T>;\n\n/**\n * {@link T} is a class constructor or unknown constructor. Else, `never`.\n *\n * Consider using {@link ClassLike} where walking the inheritance chain is necessary.\n * @template [T=Constructor_Unknown]\n * @since 3.0.0\n */\nexport type ConstructorLike<T = Constructor_Unknown>\n = T extends Constructor_Unknown\n ? T extends ConstructorConstraint<T>\n ? T & ConstructorConstraint<T>\n : T & Constructor_Unknown\n : never;\n\n/**\n * A type representing unknown {@link ClassLike} types.\n * @since 3.0.0\n */\nexport type ClassLike_Unknown\n = IClass<\n Constructor_Unknown\n & WithProto<SuperClassLike | BaseClassProto>\n >;\n\n/**\n * A subset of {@link ProtoOrSuperClass} suitable for a class's `[[Prototype]]`\n * @since 3.0.0\n */\nexport type SuperClassLike = BaseClass<Constructor_Unknown> | ClassLike_Unknown;\n\n/**\n * A terrible type. Use it if you must, but prefer other types when possible.\n *\n * Covers most SuperClass/Prototype types.\n * A class that does not extend another class will satisfy {@link BaseClass}.\n *\n * If a type extends {@link ProtoOrSuperClass} and is `null`, you cannot get the\n * type's keys. See {@link ./OwnKeyOf.ts}.\n * @template [T=ReturnType<typeof Reflect.getPrototypeOf>] `null` or an `object`-like type.\n * @since 3.0.0\n */\nexport type ProtoOrSuperClass<T extends object | null = ReturnType<typeof Reflect.getPrototypeOf>>\n = T extends null ? null\n : T extends object\n ? T extends ConstructorLike<T>\n ? T extends ClassLike<T & WithProto<SuperClassLike | BaseClassProto>>\n ? T extends BaseClass<T> ? ClassLike<BaseClass<T>>\n : ClassLike<T>\n : T extends BaseClass<T>\n ? BaseClass<T>\n : ConstructorLike<T>\n : T extends FunctionLike<infer FunctionConstraint>\n ? T extends FunctionConstraint\n ? FunctionLike<T>\n : T & FunctionLike<FunctionConstraint>\n : T extends object\n ? T & object\n : never\n : never;\n\n/**\n * The {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Inheritance_and_the_prototype_chain prototype chain} of any `object`-like type.\n * Not to be confused with the _instance_ `.prototype` chain!\n * ```\n * > util.isDeepStrictEqual(Object.getOwnPropertyDescriptors({}.__proto__), Object.getOwnPropertyDescriptors(Object.prototype))\n * true\n * ```\n * @template Object0 Any type with its `[[Prototype]]` attached as a `__proto__` property. The type of `__proto__` must extend {@link ProtoOrSuperClass}.\n * @template [Limit=16]\n * The maximum depth of recursion.\n * Affects the maximum length of the returned type.\\\n * CAUTION: Larger values will severely degrade performance.\n * 50 or more will trigger infinite-or-near-infinite-recursion errors.\n * @template [CurrentLevel=0] (INTERNAL) The current depth of the prototype chain.\n * @since 3.0.0\n */\nexport type ProtoChainOfObject<\n Object0 extends WithProto<ProtoOrSuperClass>,\n Limit extends Integer<number> = 16,\n CurrentLevel extends Integer<number> = 0,\n> = PropertyDescriptorMap<Object0['__proto__']> extends PropertyDescriptorMap<ObjectConstructor['prototype']>\n ? [Object0]\n : Object0['__proto__'] extends WithProto<ProtoOrSuperClass>\n ? CurrentLevel extends Limit ? [Object0]\n : [\n Object0,\n ...ProtoChainOfObject<Object0['__proto__'], Limit, Increment<CurrentLevel>>,\n ]\n : never;\n\n/**\n * The {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Inheritance_and_the_prototype_chain prototype chain} of an object (particularly, a class).\n * @template Class Any type with its `[[Prototype]]` attached as a `__proto__` property.\n * The type of `__proto__` must extend {@link SuperClassLike} or {@link BaseClassProto}.\n * @template [Limit=16]\n * The maximum depth of recursion.\n * Affects the maximum length of the returned type.\\\n * CAUTION: Larger values will severely degrade performance.\n * 50 or more will trigger infinite-or-near-infinite-recursion errors.\n * @template [CurrentLevel=0] (INTERNAL) The current depth of the prototype chain.\n * @since 3.0.0\n */\nexport type ProtoChainOfClass<\n Class extends WithProto<SuperClassLike | BaseClassProto>,\n Limit extends Integer<number> = 16,\n CurrentLevel extends Integer<number> = 0,\n> = Class['__proto__'] extends BaseClassProto ? [Class]\n : Class['__proto__'] extends SuperClassLike\n ? CurrentLevel extends Limit ? [Class]\n : [\n Class,\n ...ProtoChainOfClass<Class['__proto__'], Limit, Increment<CurrentLevel>>,\n ]\n : never;\n\n/**\n * The {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Inheritance_and_the_prototype_chain prototype chain} of a class instance.\n * @template Class A constructor type with its `[[Prototype]]` attached as a `__proto__` property.\n * @template [Limit=16]\n * The maximum depth of recursion.\n * Affects the maximum length of the returned type.\\\n * CAUTION: Larger values will severely degrade performance.\n * 50 or more will trigger infinite-or-near-infinite-recursion errors.\n * @template [CurrentLevel=0] (INTERNAL) The current depth of the prototype chain.\n * @since 3.0.0\n */\nexport type ProtoChainOfClassInstance<\n Class extends ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>,\n Limit extends Integer<number> = 16,\n CurrentLevel extends Integer<number> = 0,\n> = Class['__proto__'] extends BaseClassProto ? [InstanceType<Class>]\n : Class['__proto__'] extends SuperClassLike\n ? CurrentLevel extends Limit ? [InstanceType<Class>]\n : [\n InstanceType<Class>,\n ...ProtoChainOfClassInstance<Class['__proto__'], Limit, Increment<CurrentLevel>>,\n ]\n : never;\n\n/**\n * Augment a class type to expose properties not exposed by TypeScript by default.\n * Note: is `Class & ...`\n * @template Class The typeof any class. If the type is unknown, wrap it with {@link ConstructorConstraint}.\n * @since 3.0.0\n */\n// defined as `type` because interfaces cannot extend their generic parameters\nexport type IClass<Class extends ConstructorConstraint<Class>>\n = Class\n & {\n prototype: InstanceType<Class>;\n name: ConstructorConstraint<Class>['name'];\n length: ConstructorConstraint<Class>['length'];\n };\n\n/**\n * A more fleshed-out Class type.\n *\n * Note: is `Class & ...`\n *\n * In addition to the Constructor constraint, this type...\n * - Sets the type of the immediate superclass.\n * - Sets `prototype` to {@link InstanceType}\n * @template Class The `typeof MyClass`. If this class extends a class, pass `typeof MySuperClass` to the generic argument {@link Class}.\n * @example\n * type Class_MyClass = ClassLike<typeof MyClass & WithProto<BaseClass<typeof MyBaseClass>>;\n * @since 3.0.0\n */\nexport type ClassLike<\n Class extends ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>,\n> = Class extends BaseClass<Class> ? Class\n : Class['__proto__'] extends BaseClassProto ? BaseClass<Class>\n : Class['__proto__'] extends ConstructorLike<Class['__proto__']>\n ? IClass<Class> & WithProto<ConstructorLike<Class['__proto__']>>\n // Here, __proto__ is retained via Class\n : IClass<Class>;\n\n/**\n * If {@link T} is a class or constructor, {@link InstanceType}<{@link T}>. Else, {@link T}.\n * @template T `null` or any `object`-like type.\n * @since 3.0.0\n */\nexport type InstanceTypeOrSelf<T extends object | null> = T extends ConstructorLike\n ? T extends ConstructorLike<T>\n ? InstanceType<T>\n : T\n : T;\n\n/**\n * Interface for attaching a `__proto__` to an object e.g. `T0 & WithProto<T1>`\n * @template __proto__ the type of the an object's `[[Prototype]]`.\n * @since 3.0.0\n */\nexport interface WithProto<__prototype__ extends ProtoOrSuperClass> {\n ['__proto__']: __prototype__;\n}\n"],"mappings":";;;;;;AA0BA,MAAa,iBAAiC,eAAe,MAAsC"}