@halospv3/hce.shared-config 2.6.4 → 3.0.0-develop.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/CHANGELOG.md +356 -101
  2. package/README.md +100 -87
  3. package/dotnet/.github/workflows/_unit_test.yml +6 -3
  4. package/dotnet/.github/workflows/ci.yml +2 -2
  5. package/dotnet/.github/workflows/dotnet-release.yml +31 -28
  6. package/dotnet/.github/workflows/sample-dotnet-build.yml +16 -11
  7. package/dotnet/ExecNupkgDeterministicator.README.md +20 -0
  8. package/dotnet/ExecNupkgDeterministicator.targets +173 -0
  9. package/dotnet/GitVersion.yml +3 -1
  10. package/dotnet/GitVersion6.0.yml +3 -1
  11. package/dotnet/HCE.Shared.sln +34 -0
  12. package/dotnet/HCE.Shared.targets +1 -0
  13. package/dotnet/PublishAll.targets +2 -0
  14. package/dotnet/SignAfterPack.targets +104 -0
  15. package/dotnet/samples/HCE.Shared.DeterministicNupkg/Dummy.cs +6 -0
  16. package/dotnet/samples/HCE.Shared.DeterministicNupkg/HCE.Shared.DeterministicNupkg.csproj +21 -0
  17. package/dotnet/samples/HCE.Shared.SignAfterPack/Class1.cs +6 -0
  18. package/dotnet/samples/HCE.Shared.SignAfterPack/HCE.Shared.SignAfterPack.csproj +21 -0
  19. package/dotnet/samples/HCE.Shared.SignAfterPack/sampleCert.samplepfx +0 -0
  20. package/dotnet/samples/README.md +7 -0
  21. package/package.json +72 -73
  22. package/src/CaseInsensitiveMap.ts +34 -0
  23. package/src/commitlintConfig.ts +17 -9
  24. package/src/debug.ts +3 -3
  25. package/src/dotnet/GithubNugetRegistryInfo.ts +60 -0
  26. package/src/dotnet/GitlabNugetRegistryInfo.ts +112 -0
  27. package/src/dotnet/IsNextVersionAlreadyPublished.cli.ts +44 -0
  28. package/src/dotnet/MSBuildProject.ts +557 -76
  29. package/src/dotnet/MSBuildProjectProperties.ts +280 -15
  30. package/src/dotnet/NugetProjectProperties.ts +608 -0
  31. package/src/dotnet/NugetRegistryInfo.ts +939 -0
  32. package/src/dotnet/helpers.ts +448 -0
  33. package/src/eslintConfig.ts +174 -71
  34. package/src/index.ts +1 -3
  35. package/src/semantic-release__commit-analyzer.d.ts +44 -38
  36. package/src/semantic-release__exec.d.ts +15 -0
  37. package/src/semantic-release__git.d.ts +85 -88
  38. package/src/semantic-release__github.d.ts +139 -139
  39. package/src/semanticReleaseConfig.ts +106 -47
  40. package/src/semanticReleaseConfigDotnet.ts +394 -104
  41. package/src/setupGitPluginSpec.ts +149 -57
  42. package/src/tsconfig.json +8 -8
  43. package/src/utils/Exact.ts +49 -0
  44. package/src/utils/GracefulRecursion.d.ts +12 -0
  45. package/src/utils/env.ts +44 -0
  46. package/src/utils/execAsync.ts +77 -0
  47. package/src/utils/miscTypes.ts +17 -0
  48. package/src/utils/reflection/FunctionLike.d.ts +17 -0
  49. package/src/utils/reflection/GetterDescriptor.d.ts +8 -0
  50. package/src/utils/reflection/InstancePropertyDescriptorMap.d.ts +32 -0
  51. package/src/utils/reflection/InstanceTypeOrSelfPropertyDescriptorMap.d.ts +20 -0
  52. package/src/utils/reflection/OwnGetterDescriptorMap.d.ts +17 -0
  53. package/src/utils/reflection/OwnKeyOf.d.ts +20 -0
  54. package/src/utils/reflection/OwnPropertyDescriptorMap.d.ts +82 -0
  55. package/src/utils/reflection/PropertyDescriptorMap.d.ts +15 -0
  56. package/src/utils/reflection/filterForGetters.ts +59 -0
  57. package/src/utils/reflection/getOwnPropertyDescriptors.ts +52 -0
  58. package/src/utils/reflection/getOwnPropertyDescriptorsRecursively.ts +127 -0
  59. package/src/utils/reflection/getPrototypeChainOf.ts +85 -0
  60. package/src/utils/reflection/getPrototypeOf.ts +12 -0
  61. package/src/utils/reflection/inheritance.ts +262 -0
  62. package/src/utils/reflection/isConstructor.ts +74 -0
  63. package/src/utils/reflection/isGetterDescriptor.ts +11 -0
  64. package/src/utils/reflection/listOwnGetters.ts +80 -0
  65. package/src/utils/reflection.ts +18 -0
  66. package/cjs/commitlintConfig-wrapper.mjs +0 -6
  67. package/cjs/commitlintConfig.cjs +0 -14
  68. package/cjs/commitlintConfig.cjs.map +0 -1
  69. package/cjs/commitlintConfig.d.ts +0 -4
  70. package/cjs/commitlintConfig.d.ts.map +0 -1
  71. package/cjs/debug.cjs +0 -13
  72. package/cjs/debug.cjs.map +0 -1
  73. package/cjs/debug.d.ts +0 -4
  74. package/cjs/debug.d.ts.map +0 -1
  75. package/cjs/dotnet/MSBuildProject.cjs +0 -84
  76. package/cjs/dotnet/MSBuildProject.cjs.map +0 -1
  77. package/cjs/dotnet/MSBuildProject.d.ts +0 -42
  78. package/cjs/dotnet/MSBuildProject.d.ts.map +0 -1
  79. package/cjs/dotnet/MSBuildProjectProperties.cjs +0 -22
  80. package/cjs/dotnet/MSBuildProjectProperties.cjs.map +0 -1
  81. package/cjs/dotnet/MSBuildProjectProperties.d.ts +0 -13
  82. package/cjs/dotnet/MSBuildProjectProperties.d.ts.map +0 -1
  83. package/cjs/dotnet/createDummyNupkg.cjs +0 -26
  84. package/cjs/dotnet/createDummyNupkg.cjs.map +0 -1
  85. package/cjs/dotnet/createDummyNupkg.d.ts +0 -2
  86. package/cjs/dotnet/createDummyNupkg.d.ts.map +0 -1
  87. package/cjs/dotnet/dotnetGHPR.cjs +0 -173
  88. package/cjs/dotnet/dotnetGHPR.cjs.map +0 -1
  89. package/cjs/dotnet/dotnetGHPR.d.ts +0 -37
  90. package/cjs/dotnet/dotnetGHPR.d.ts.map +0 -1
  91. package/cjs/dotnet/dotnetGLPR.cjs +0 -41
  92. package/cjs/dotnet/dotnetGLPR.cjs.map +0 -1
  93. package/cjs/dotnet/dotnetGLPR.d.ts +0 -13
  94. package/cjs/dotnet/dotnetGLPR.d.ts.map +0 -1
  95. package/cjs/dotnet/dotnetHelpers.cjs +0 -141
  96. package/cjs/dotnet/dotnetHelpers.cjs.map +0 -1
  97. package/cjs/dotnet/dotnetHelpers.d.ts +0 -26
  98. package/cjs/dotnet/dotnetHelpers.d.ts.map +0 -1
  99. package/cjs/dotnet-wrapper.mjs +0 -6
  100. package/cjs/dotnet.cjs +0 -15
  101. package/cjs/dotnet.cjs.map +0 -1
  102. package/cjs/dotnet.d.ts +0 -7
  103. package/cjs/dotnet.d.ts.map +0 -1
  104. package/cjs/envUtils-wrapper.mjs +0 -6
  105. package/cjs/envUtils.cjs +0 -37
  106. package/cjs/envUtils.cjs.map +0 -1
  107. package/cjs/envUtils.d.ts +0 -15
  108. package/cjs/envUtils.d.ts.map +0 -1
  109. package/cjs/eslintConfig-wrapper.mjs +0 -6
  110. package/cjs/eslintConfig.cjs +0 -52
  111. package/cjs/eslintConfig.cjs.map +0 -1
  112. package/cjs/eslintConfig.d.ts +0 -3
  113. package/cjs/eslintConfig.d.ts.map +0 -1
  114. package/cjs/findStaticConfig-wrapper.mjs +0 -6
  115. package/cjs/findStaticConfig.cjs +0 -34
  116. package/cjs/findStaticConfig.cjs.map +0 -1
  117. package/cjs/findStaticConfig.d.ts +0 -2
  118. package/cjs/findStaticConfig.d.ts.map +0 -1
  119. package/cjs/index-wrapper.mjs +0 -6
  120. package/cjs/index.cjs +0 -10
  121. package/cjs/index.cjs.map +0 -1
  122. package/cjs/index.d.ts +0 -5
  123. package/cjs/index.d.ts.map +0 -1
  124. package/cjs/semantic-release__commit-analyzer.d.cjs +0 -2
  125. package/cjs/semantic-release__commit-analyzer.d.cjs.map +0 -1
  126. package/cjs/semantic-release__git.d.cjs +0 -2
  127. package/cjs/semantic-release__git.d.cjs.map +0 -1
  128. package/cjs/semantic-release__github.d.cjs +0 -2
  129. package/cjs/semantic-release__github.d.cjs.map +0 -1
  130. package/cjs/semanticReleaseConfig-wrapper.mjs +0 -6
  131. package/cjs/semanticReleaseConfig.cjs +0 -33
  132. package/cjs/semanticReleaseConfig.cjs.map +0 -1
  133. package/cjs/semanticReleaseConfig.d.ts +0 -4
  134. package/cjs/semanticReleaseConfig.d.ts.map +0 -1
  135. package/cjs/semanticReleaseConfigDotnet-wrapper.mjs +0 -7
  136. package/cjs/semanticReleaseConfigDotnet.cjs +0 -112
  137. package/cjs/semanticReleaseConfigDotnet.cjs.map +0 -1
  138. package/cjs/semanticReleaseConfigDotnet.d.ts +0 -51
  139. package/cjs/semanticReleaseConfigDotnet.d.ts.map +0 -1
  140. package/cjs/setupGitPluginSpec-wrapper.mjs +0 -6
  141. package/cjs/setupGitPluginSpec.cjs +0 -67
  142. package/cjs/setupGitPluginSpec.cjs.map +0 -1
  143. package/cjs/setupGitPluginSpec.d.ts +0 -19
  144. package/cjs/setupGitPluginSpec.d.ts.map +0 -1
  145. package/src/dotnet/createDummyNupkg.ts +0 -30
  146. package/src/dotnet/dotnetGHPR.ts +0 -232
  147. package/src/dotnet/dotnetGLPR.ts +0 -46
  148. package/src/dotnet/dotnetHelpers.ts +0 -184
  149. package/src/dotnet.ts +0 -6
  150. package/src/envUtils.ts +0 -36
  151. package/src/findStaticConfig.ts +0 -31
  152. package/static/.releaserc.yml +0 -35
@@ -0,0 +1,15 @@
1
+ /**
2
+ * A variant of TypeScript's ES5 PropertyDescriptorMap with an extra generic
3
+ * parameter for omitting inherited keys.
4
+ * @template T The type described by the {@link PropertyDescriptorMap}.
5
+ * @template [__proto__=null]
6
+ * The `null` or the `object`-like `[[Prototype]]` of {@link T}.
7
+ * @since 3.0.0
8
+ */
9
+ export type PropertyDescriptorMap<T, __proto__ extends object | null = null>
10
+ = __proto__ extends null
11
+ ? { [P0 in keyof T]: TypedPropertyDescriptor<T[P0]>; }
12
+ : Omit<
13
+ { [P0 in keyof T]: TypedPropertyDescriptor<T[P0]>; },
14
+ keyof { [P1 in keyof __proto__]: TypedPropertyDescriptor<__proto__[P1]> }
15
+ >;
@@ -0,0 +1,59 @@
1
+ import type {
2
+ BaseClassProto,
3
+ baseClassProto,
4
+ ClassLike,
5
+ ConstructorConstraint,
6
+ InstanceTypeOrSelf,
7
+ SuperClassLike,
8
+ WithProto,
9
+ } from './inheritance.js';
10
+ import type { InstancePropertyDescriptorMap } from './InstancePropertyDescriptorMap.js';
11
+ import type { OwnGetterDescriptorMap } from './OwnGetterDescriptorMap.js';
12
+ import type { OwnPropertyDescriptorMap } from './OwnPropertyDescriptorMap.js';
13
+ import type { PropertyDescriptorMap } from './PropertyDescriptorMap.js';
14
+
15
+ export function filterForGetters<
16
+ Class extends ClassLike<ConstructorConstraint<Class> & WithProto<SuperClassLike | typeof baseClassProto>>,
17
+ >(
18
+ descriptorMap: InstancePropertyDescriptorMap<Class>,
19
+ ): Partial<OwnGetterDescriptorMap<
20
+ InstanceType<Class>,
21
+ Class['__proto__'] extends BaseClassProto ? null : InstanceTypeOrSelf<Class['__proto__']>
22
+ >>;
23
+ export function filterForGetters<
24
+ Class extends ClassLike<ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>>,
25
+ >(
26
+ descriptorMap: OwnPropertyDescriptorMap<Class>,
27
+ ): Partial<OwnGetterDescriptorMap<Class, Class['__proto__']>>;
28
+ /**
29
+ * Iterates through the descriptors object, checking for property descriptors whose `get` is a function.
30
+ * Returns an {@link OwnGetterDescriptorMap} of the getters.
31
+ * If you want only own, non-inherited getters, you must filter sanitize the
32
+ * type the `descriptors` parameter yourself e.g. `Omit<Class, keyof
33
+ * SuperClass>`.
34
+ * @param descriptorMap An object like the return value of Object.getOwnPropertyDescriptors
35
+ * @template Class Any ClassLike type
36
+ * @template T Any `object`-like type.
37
+ * @template [__proto__=null] If {@link Class} is not {@link ClassLike}, the `__proto__` of {@link T}.
38
+ * @returns An {@link OwnGetterDescriptorMap}.
39
+ * @since 3.0.0
40
+ */
41
+ export function filterForGetters<
42
+ T extends object,
43
+ __proto__ extends object | null = null,
44
+ >(
45
+ descriptorMap: PropertyDescriptorMap<T, __proto__> | PropertyDescriptorMap<T>,
46
+ ): Partial<OwnGetterDescriptorMap<T, __proto__>> {
47
+ let getterDescriptorMap: Partial<OwnGetterDescriptorMap<T, __proto__>> = {};
48
+ for (const key in descriptorMap) {
49
+ const element = descriptorMap[key as keyof typeof descriptorMap];
50
+ if (typeof element.get === 'function') {
51
+ getterDescriptorMap = Object.assign(
52
+ getterDescriptorMap,
53
+ { [key]: element },
54
+ );
55
+ }
56
+ }
57
+
58
+ return getterDescriptorMap;
59
+ }
@@ -0,0 +1,52 @@
1
+ import type { InstanceOrStatic } from '../miscTypes.js';
2
+ import type { BaseClassProto, ClassLike, ConstructorConstraint, SuperClassLike, WithProto } from './inheritance.js';
3
+ import type { InstancePropertyDescriptorMap } from './InstancePropertyDescriptorMap.js';
4
+ import type { OwnPropertyDescriptorMap } from './OwnPropertyDescriptorMap.js';
5
+
6
+ /**
7
+ * Get the property descriptors of the class or constructor similar to {@link Object.getOwnPropertyDescriptors}, but with more options--including recursion.
8
+ * @template {InstanceOrStatic} _InstanceOrStatic 'Instance' or 'Static'. Determines the return type.
9
+ * @param classDefinition A class or constructor, cast to {@link ClassLike}.
10
+ * @param instanceOrStatic 'Instance' or 'Static'. Determines the return type.
11
+ * @template {ClassLike<ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>>} Class
12
+ * The typeof {@link classDefinition}.
13
+ * {@link WithProto}<{@link SuperClassLike}> is necessary for walking the
14
+ * prototype chain for both Instance and Static properties.
15
+ * If unspecified, the return type may be incorrect.
16
+ * @returns ({@link instanceOrStatic} === 'Instance') ? {@link InstancePropertyDescriptorMap<Class>}\
17
+ * : ({@link instanceOrStatic} === 'Static') ? {@link OwnPropertyDescriptorMap<Class>}\
18
+ * : never
19
+ * @throws {TypeError}
20
+ * @since 3.0.0
21
+ */
22
+ export function getOwnPropertyDescriptors<
23
+ Class extends ClassLike<ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>>,
24
+ _InstanceOrStatic extends InstanceOrStatic,
25
+ >(
26
+ classDefinition: Class,
27
+ instanceOrStatic: _InstanceOrStatic,
28
+ ): [_InstanceOrStatic] extends ['Instance']
29
+ ? InstancePropertyDescriptorMap<Class>
30
+ : [_InstanceOrStatic] extends ['Static']
31
+ ? OwnPropertyDescriptorMap<Class>
32
+ : never {
33
+ switch (instanceOrStatic) {
34
+ case 'Instance': {
35
+ return Object.getOwnPropertyDescriptors(classDefinition.prototype) as [Extract<typeof instanceOrStatic, 'Instance'>] extends ['Instance']
36
+ ? InstancePropertyDescriptorMap<Class>
37
+ : [_InstanceOrStatic] extends ['Static']
38
+ ? OwnPropertyDescriptorMap<Class>
39
+ : never;
40
+ }
41
+ case 'Static': {
42
+ return Object.getOwnPropertyDescriptors(classDefinition) as [Extract<typeof instanceOrStatic, 'Static'>] extends ['Instance']
43
+ ? InstancePropertyDescriptorMap<Class>
44
+ : [_InstanceOrStatic] extends ['Static']
45
+ ? OwnPropertyDescriptorMap<Class>
46
+ : never;
47
+ }
48
+ default: {
49
+ throw new TypeError('Argument `instanceOrStatic` must be "Instance" or "Static".');
50
+ }
51
+ }
52
+ }
@@ -0,0 +1,127 @@
1
+ import type { Increment } from '../GracefulRecursion.js';
2
+ import type { InstanceOrStatic, Integer } from '../miscTypes.js';
3
+ import { getOwnPropertyDescriptors } from './getOwnPropertyDescriptors.js';
4
+ import { getPrototypesChainOf } from './getPrototypeChainOf.js';
5
+ import type {
6
+ BaseClass,
7
+ BaseClassProto,
8
+ ClassLike,
9
+ ConstructorConstraint,
10
+ ConstructorLike,
11
+ ProtoChainOfClass,
12
+ SuperClassLike,
13
+ WithProto,
14
+ } from './inheritance.js';
15
+ import type { InstanceTypeOrSelfPropertyDescriptorMap } from './InstanceTypeOrSelfPropertyDescriptorMap.js';
16
+ import type { OwnPropertyDescriptorMap } from './OwnPropertyDescriptorMap.js';
17
+ /* eslint-disable jsdoc/check-tag-names */
18
+ /**
19
+ * JSDoc type imports
20
+ * @typedef {import('./getPrototypeOf.js').getPrototypeOf} getPrototypeOf
21
+ * @typedef {import('./listOwnGetters.js').listOwnGetters} listOwnGetters
22
+ * @typedef {import('./InstancePropertyDescriptorMap.js').InstancePropertyDescriptorMap} InstancePropertyDescriptorMap
23
+ */
24
+ /* eslint-enable jsdoc/check-tag-names */
25
+
26
+ /**
27
+ * A conditional wrapper for {@link InstanceTypeOrSelfPropertyDescriptorMap} and
28
+ * {@link OwnPropertyDescriptorMap}.
29
+ *
30
+ * If {@link _InstanceOrStatic} is 'Instance', {@link InstanceTypeOrSelfPropertyDescriptorMap}.\
31
+ * Else if {@link _InstanceOrStatic} is 'Static',
32
+ * {@link OwnPropertyDescriptorMap }.\
33
+ * Else, `never`.
34
+ * @template {ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>} Class
35
+ * A class definition cast to {@link ClassLike}.
36
+ * @template {InstanceOrStatic} _InstanceOrStatic
37
+ * 'Instance' or 'Static'. Determines the return type.
38
+ * @since 3.0.0
39
+ */
40
+ export type RecursedPropertyDescriptorMap<
41
+ Class extends ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>,
42
+ _InstanceOrStatic extends InstanceOrStatic,
43
+ > = [_InstanceOrStatic] extends ['Instance'] ? InstanceTypeOrSelfPropertyDescriptorMap<Class, Class['__proto__']>
44
+ : [_InstanceOrStatic] extends ['Static'] ? OwnPropertyDescriptorMap<Class>
45
+ : never;
46
+
47
+ /**
48
+ * An
49
+ * ordered array of {@link OwnPropertyDescriptorMap} or
50
+ * {@link InstancePropertyDescriptorMap} starting with {@link classDefinition}
51
+ * and ending with a {@link BaseClass}.
52
+ * @template {ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>} Class
53
+ * @template {'Instance' | 'Static'} InstanceOrStatic
54
+ * @template {Integer<number>} [Limit=16]
55
+ * @template {Integer<number>} [CurrentLevel=0]
56
+ */
57
+ export type RecursedPropertyDescriptorMapArray<
58
+ Class extends ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>,
59
+ InstanceOrStatic extends 'Instance' | 'Static',
60
+ Limit extends Integer<number> = 16,
61
+ CurrentLevel extends Integer<number> = 0,
62
+ > = Class['__proto__'] extends BaseClassProto['__proto__'] | BaseClassProto['__proto__']['__proto__'] ? never
63
+ : Class['__proto__'] extends BaseClassProto ? [RecursedPropertyDescriptorMap<BaseClass<Class>, InstanceOrStatic>]
64
+ : Class['__proto__'] extends ConstructorLike<Class['__proto__']>
65
+ ? [
66
+ RecursedPropertyDescriptorMap<Class, InstanceOrStatic>,
67
+ ...RecursedPropertyDescriptorMapArray<
68
+ ClassLike<Exclude<Class['__proto__'], BaseClassProto> & WithProto<SuperClassLike | BaseClassProto>>,
69
+ InstanceOrStatic,
70
+ Limit,
71
+ Increment<CurrentLevel>
72
+ >,
73
+ ]
74
+ : never;
75
+ /**
76
+ * Walks the class inheritance chain to get a PropertyDescriptorMap of each class.
77
+ *
78
+ * While you _can_ use this to get an array of getter names/keys, you should use {@link getPrototypeOf} and {@link listOwnGetters}, instead!
79
+ * @template Class Any class definition type-cast to {@link ClassLike}
80
+ * @template _InstanceOrStatic
81
+ * @param classDefinition Any class definition type-cast to {@link ClassLike}
82
+ * @param instanceOrStatic 'Instance' or 'Static'. Determines the return type.
83
+ * @returns An
84
+ * ordered array of {@link OwnPropertyDescriptorMap} or
85
+ * {@link InstancePropertyDescriptorMap} starting with {@link classDefinition}
86
+ * and ending with a {@link BaseClass}.
87
+ * @since 3.0.0
88
+ */
89
+ export function getOwnPropertyDescriptorsRecursively<
90
+ // Class extends ClassLike<ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>>,
91
+ Class extends ClassLike<ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>>,
92
+ _InstanceOrStatic extends InstanceOrStatic,
93
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
94
+ Limit extends Integer<number> = 16,
95
+ >(
96
+ classDefinition: Class,
97
+ instanceOrStatic: _InstanceOrStatic,
98
+ ): RecursedPropertyDescriptorMapArray<Class, _InstanceOrStatic> {
99
+ const staticProtoChain: ProtoChainOfClass<Class> = getPrototypesChainOf(classDefinition, 'classes');
100
+ if (isSingleTuple(staticProtoChain)) {
101
+ return [
102
+ getOwnPropertyDescriptors(
103
+ staticProtoChain[0],
104
+ instanceOrStatic,
105
+ ) as RecursedPropertyDescriptorMap<Class, _InstanceOrStatic>,
106
+ ] as unknown as RecursedPropertyDescriptorMapArray<Class, _InstanceOrStatic, Limit>;
107
+ }
108
+
109
+ const recursedPropertyDescriptorMapArray = staticProtoChain.map(classDefinition =>
110
+ getOwnPropertyDescriptors(
111
+ classDefinition,
112
+ instanceOrStatic,
113
+ ),
114
+ );
115
+
116
+ return recursedPropertyDescriptorMapArray as RecursedPropertyDescriptorMapArray<Class, _InstanceOrStatic>;
117
+ }
118
+
119
+ /**
120
+ * Simple utility for single-tuple type assertion
121
+ * @template {T} T T in T[]
122
+ * @param array an array
123
+ * @returns array is [T]
124
+ */
125
+ function isSingleTuple<T>(array: T[]): array is [T] {
126
+ return Array.isArray(array) && array.length === 1;
127
+ }
@@ -0,0 +1,85 @@
1
+ /* eslint-disable jsdoc/no-defaults */
2
+ import type { TupleIndices } from '../miscTypes.js';
3
+ import { getPrototypeOf } from './getPrototypeOf.js';
4
+ import {
5
+ baseClassProto,
6
+ type BaseClassProto,
7
+ type ClassLike,
8
+ type ConstructorConstraint,
9
+ type ProtoChainOfClass,
10
+ type ProtoChainOfClassInstance,
11
+ type SuperClassLike,
12
+ type WithProto,
13
+ } from './inheritance.js';
14
+ import { isConstructor } from './isConstructor.js';
15
+
16
+ type ProtoChain<
17
+ Class extends ClassLike<ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>>,
18
+ ClassesOrInstances extends 'classes' | 'classInstances',
19
+ > = [ClassesOrInstances] extends ['classInstances'] ? ProtoChainOfClassInstance<Class>
20
+ : [ClassesOrInstances] extends ['classes'] ? ProtoChainOfClass<Class>
21
+ : never;
22
+
23
+ /**
24
+ * Iterate through the class and its base/super classes until an anonymous function is reached. This is the default superclass all classes extend.
25
+ * @template Class Any {@link ClassLike} type.
26
+ * @template ClassesOrInstances 'classes' or 'classInstances'
27
+ * @param classDefinition Any class type satisfying {@link Class}. This class (or its instance type) is included in the return value.
28
+ * @param [returnType='classes'] Determines return type. If 'classInstances', the return type is an array of the classes' `.prototype`. Else, the classes themselves are returned.
29
+ * @since 3.0.0
30
+ * @returns
31
+ * `returnType extends 'classInstances' ? ClassLike<T>[] : ClassLike<T>[].map(c => c.prototype)`
32
+ * Excludes default superclasses e.g. anonymous functions, native code.
33
+ */
34
+ export function getPrototypesChainOf<
35
+ Class extends ClassLike<ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>>,
36
+ ClassesOrInstances extends 'classes' | 'classInstances',
37
+ >(
38
+ classDefinition: Class,
39
+ returnType: ClassesOrInstances,
40
+ ): ProtoChain<Class, ClassesOrInstances> {
41
+ // class definitions or their respective .prototype; exclude default superclasses.
42
+ let current: ProtoChainOfClass<Class>[TupleIndices<ProtoChainOfClass<Class>>] = classDefinition as ProtoChainOfClass<Class>[0 extends TupleIndices<ProtoChainOfClass<Class>> ? 0 : never];
43
+ let parent: typeof current & WithProto<SuperClassLike | BaseClassProto> | object;
44
+ const returnValue = [] as unknown as
45
+ ProtoChain<Class, ClassesOrInstances>;
46
+ let index: TupleIndices<typeof returnValue> = 0 as TupleIndices<typeof returnValue>;
47
+
48
+ while (baseClassProto !== current) {
49
+ parent = getPrototypeOf<typeof current>(current);
50
+ // current is a Class symbol/constructor. Object.getOwnPropertyDescriptors on current will include static properties.
51
+ if (!isConstructor(current))
52
+ break;
53
+ if (returnType === 'classInstances') {
54
+ const instanceOfCurrent = current.prototype as InstanceType<typeof current>;
55
+
56
+ returnValue[index] = instanceOfCurrent as typeof returnValue[typeof index];
57
+ }
58
+ else {
59
+ returnValue[index] = current as typeof returnValue[typeof index];
60
+ }
61
+
62
+ /**
63
+ * Assign the super class to current.
64
+ * If the argument is a class, Reflect.getPrototypeOf method returns the
65
+ * superclass.
66
+ */
67
+ if (
68
+ isConstructor(parent)
69
+ && 'name' in parent
70
+ && typeof parent.name === 'string'
71
+ && '' !== parent.name // it's possible for a Function/Constructor to be anonymous...
72
+ ) {
73
+ current = parent as ProtoChainOfClass<Class>[TupleIndices<ProtoChainOfClass<Class>>];
74
+ }
75
+ else {
76
+ break;
77
+ }
78
+ index++;
79
+ }
80
+ return returnValue;
81
+ /*
82
+ assuming current is NugetProjectProperties...
83
+ Reflect.getPrototypeOf(current).name is 'MSBuildProjectProperties'
84
+ */
85
+ }
@@ -0,0 +1,12 @@
1
+ import type { ProtoOrSuperClass, WithProto } from './inheritance.js';
2
+
3
+ /**
4
+ * A nearly useless wrapper for {@link Reflect.getPrototypeOf}
5
+ * @param object An object with the internal `__proto__` property present in its type.
6
+ * @returns The `__proto__` of the `object` param.
7
+ */
8
+ export function getPrototypeOf<
9
+ T extends WithProto<ProtoOrSuperClass>,
10
+ >(object: T): T['__proto__'] {
11
+ return Reflect.getPrototypeOf(object) as T['__proto__'];
12
+ }
@@ -0,0 +1,262 @@
1
+ import type { Increment } from '../GracefulRecursion.js';
2
+ import type { Integer } from '../miscTypes.js';
3
+ import type { FunctionLike } from './FunctionLike.js';
4
+ import { getPrototypeOf } from './getPrototypeOf.js';
5
+ import type { PropertyDescriptorMap } from './PropertyDescriptorMap.js';
6
+
7
+ /**
8
+ * The `[[Prototype]]` (i.e. `__proto__`) of any base class.
9
+ * @since 3.0.0
10
+ */
11
+ export type BaseClassProto = (() => object) & {
12
+ /** @example BaseClass.__proto__.__proto__.toString() === '[object Object]' */
13
+ ['__proto__']: ObjectConstructor['prototype'] & {
14
+ ['__proto__']: null;
15
+ constructor: ObjectConstructor;
16
+ };
17
+ constructor: IBaseClass;
18
+ length: 0;
19
+ name: '';
20
+ };
21
+
22
+ /**
23
+ * The `[[Prototype]]` of all base classes.
24
+ * @since 3.0.0
25
+ */
26
+ export const baseClassProto = getPrototypeOf(Object as BaseClass<ObjectConstructor>);
27
+
28
+ /**
29
+ * [INTERNAL]
30
+ * An interface representing for attaching base class properties to a class type.
31
+ * This kept separate from {@link BaseClass} so it can be used by {@link BaseClassProto}.
32
+ * @since 3.0.0
33
+ */
34
+ interface IBaseClass {
35
+ /**
36
+ * Readable for compatibility reasons, but invisible and non-enumerable in Node.js runtime.
37
+ * @example BaseClass.__proto__.toString() === 'function () { [native code] }'
38
+ */
39
+ ['__proto__']: BaseClassProto;
40
+
41
+ constructor: FunctionConstructor & { name: 'Function' };
42
+ }
43
+
44
+ /**
45
+ * Type a class type as a base class.
46
+ * Note: is `Class & ...`
47
+ * @since 3.0.0
48
+ */
49
+ export type BaseClass<Class extends ConstructorConstraint<Class>>
50
+ = IClass<Class> & IBaseClass;
51
+
52
+ /**
53
+ * A type representing any unknown constructor.
54
+ * @since 3.0.0
55
+ */
56
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
57
+ export type Constructor_Unknown = abstract new (...args: any[]) => any;
58
+
59
+ /**
60
+ * The constraint for constructor types.
61
+ * This is intended for generic type constraints.
62
+ * For conditional return types, use `T extends Constructor<T>` instead.
63
+ * @template T Any newable constructor type
64
+ * @since 3.0.0
65
+ */
66
+ export type ConstructorConstraint<T extends abstract new (...args: ConstructorParameters<T>) => InstanceType<T>> = abstract new (...arguments_: ConstructorParameters<T>) => InstanceType<T>;
67
+
68
+ /**
69
+ * {@link T} is a class constructor or unknown constructor. Else, `never`.
70
+ *
71
+ * Consider using {@link ClassLike} where walking the inheritance chain is necessary.
72
+ * @template [T=Constructor_Unknown]
73
+ * @since 3.0.0
74
+ */
75
+ export type ConstructorLike<T = Constructor_Unknown>
76
+ = T extends Constructor_Unknown
77
+ ? T extends ConstructorConstraint<T>
78
+ ? T & ConstructorConstraint<T>
79
+ : T & Constructor_Unknown
80
+ : never;
81
+
82
+ /**
83
+ * A type representing unknown {@link ClassLike} types.
84
+ * @since 3.0.0
85
+ */
86
+ export type ClassLike_Unknown
87
+ = IClass<
88
+ Constructor_Unknown
89
+ & WithProto<SuperClassLike | BaseClassProto>
90
+ >;
91
+
92
+ /**
93
+ * A subset of {@link ProtoOrSuperClass} suitable for a class's `[[Prototype]]`
94
+ * @since 3.0.0
95
+ */
96
+ export type SuperClassLike = BaseClass<Constructor_Unknown> | ClassLike_Unknown;
97
+
98
+ /**
99
+ * A terrible type. Use it if you must, but prefer other types when possible.
100
+ *
101
+ * Covers most SuperClass/Prototype types.
102
+ * A class that does not extend another class will satisfy {@link BaseClass}.
103
+ *
104
+ * If a type extends {@link ProtoOrSuperClass} and is `null`, you cannot get the
105
+ * type's keys. See {@link ./OwnKeyOf.ts}.
106
+ * @template [T=ReturnType<typeof Reflect.getPrototypeOf>] `null` or an `object`-like type.
107
+ * @since 3.0.0
108
+ */
109
+ export type ProtoOrSuperClass<T extends object | null = ReturnType<typeof Reflect.getPrototypeOf>>
110
+ = T extends null ? null
111
+ : T extends object
112
+ ? T extends ConstructorLike<T>
113
+ ? T extends ClassLike<T & WithProto<SuperClassLike | BaseClassProto>>
114
+ ? T extends BaseClass<T> ? ClassLike<BaseClass<T>>
115
+ : ClassLike<T>
116
+ : T extends BaseClass<T>
117
+ ? BaseClass<T>
118
+ : ConstructorLike<T>
119
+ : T extends FunctionLike<infer FunctionConstraint>
120
+ ? T extends FunctionConstraint
121
+ ? FunctionLike<T>
122
+ : T & FunctionLike<FunctionConstraint>
123
+ : T extends object
124
+ ? T & object
125
+ : never
126
+ : never;
127
+
128
+ /**
129
+ * The {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Inheritance_and_the_prototype_chain prototype chain} of any `object`-like type.
130
+ * Not to be confused with the _instance_ `.prototype` chain!
131
+ * ```
132
+ * > util.isDeepStrictEqual(Object.getOwnPropertyDescriptors({}.__proto__), Object.getOwnPropertyDescriptors(Object.prototype))
133
+ * true
134
+ * ```
135
+ * @template Object0 Any type with its `[[Prototype]]` attached as a `__proto__` property. The type of `__proto__` must extend {@link ProtoOrSuperClass}.
136
+ * @template [Limit=16]
137
+ * The maximum depth of recursion.
138
+ * Affects the maximum length of the returned type.\
139
+ * CAUTION: Larger values will severely degrade performance.
140
+ * 50 or more will trigger infinite-or-near-infinite-recursion errors.
141
+ * @template [CurrentLevel=0] (INTERNAL) The current depth of the prototype chain.
142
+ * @since 3.0.0
143
+ */
144
+ export type ProtoChainOfObject<
145
+ Object0 extends WithProto<ProtoOrSuperClass>,
146
+ Limit extends Integer<number> = 16,
147
+ CurrentLevel extends Integer<number> = 0,
148
+ > = PropertyDescriptorMap<Object0['__proto__']> extends PropertyDescriptorMap<ObjectConstructor['prototype']>
149
+ ? [Object0]
150
+ : Object0['__proto__'] extends WithProto<ProtoOrSuperClass>
151
+ ? CurrentLevel extends Limit ? [Object0]
152
+ : [
153
+ Object0,
154
+ ...ProtoChainOfObject<Object0['__proto__'], Limit, Increment<CurrentLevel>>,
155
+ ]
156
+ : never;
157
+
158
+ /**
159
+ * 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).
160
+ * @template Class Any type with its `[[Prototype]]` attached as a `__proto__` property.
161
+ * The type of `__proto__` must extend {@link SuperClassLike} or {@link BaseClassProto}.
162
+ * @template [Limit=16]
163
+ * The maximum depth of recursion.
164
+ * Affects the maximum length of the returned type.\
165
+ * CAUTION: Larger values will severely degrade performance.
166
+ * 50 or more will trigger infinite-or-near-infinite-recursion errors.
167
+ * @template [CurrentLevel=0] (INTERNAL) The current depth of the prototype chain.
168
+ * @since 3.0.0
169
+ */
170
+ export type ProtoChainOfClass<
171
+ Class extends WithProto<SuperClassLike | BaseClassProto>,
172
+ Limit extends Integer<number> = 16,
173
+ CurrentLevel extends Integer<number> = 0,
174
+ > = Class['__proto__'] extends BaseClassProto ? [Class]
175
+ : Class['__proto__'] extends SuperClassLike
176
+ ? CurrentLevel extends Limit ? [Class]
177
+ : [
178
+ Class,
179
+ ...ProtoChainOfClass<Class['__proto__'], Limit, Increment<CurrentLevel>>,
180
+ ]
181
+ : never;
182
+
183
+ /**
184
+ * The {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Inheritance_and_the_prototype_chain prototype chain} of a class instance.
185
+ * @template Class A constructor type with its `[[Prototype]]` attached as a `__proto__` property.
186
+ * @template [Limit=16]
187
+ * The maximum depth of recursion.
188
+ * Affects the maximum length of the returned type.\
189
+ * CAUTION: Larger values will severely degrade performance.
190
+ * 50 or more will trigger infinite-or-near-infinite-recursion errors.
191
+ * @template [CurrentLevel=0] (INTERNAL) The current depth of the prototype chain.
192
+ * @since 3.0.0
193
+ */
194
+ export type ProtoChainOfClassInstance<
195
+ Class extends ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>,
196
+ Limit extends Integer<number> = 16,
197
+ CurrentLevel extends Integer<number> = 0,
198
+ > = Class['__proto__'] extends BaseClassProto ? [InstanceType<Class>]
199
+ : Class['__proto__'] extends SuperClassLike
200
+ ? CurrentLevel extends Limit ? [InstanceType<Class>]
201
+ : [
202
+ InstanceType<Class>,
203
+ ...ProtoChainOfClassInstance<Class['__proto__'], Limit, Increment<CurrentLevel>>,
204
+ ]
205
+ : never;
206
+
207
+ /**
208
+ * Augment a class type to expose properties not exposed by TypeScript by default.
209
+ * Note: is `Class & ...`
210
+ * @template Class The typeof any class. If the type is unknown, wrap it with {@link ConstructorConstraint}.
211
+ * @since 3.0.0
212
+ */
213
+ // defined as `type` because interfaces cannot extend their generic parameters
214
+ export type IClass<Class extends ConstructorConstraint<Class>>
215
+ = Class
216
+ & {
217
+ prototype: InstanceType<Class>;
218
+ name: ConstructorConstraint<Class>['name'];
219
+ length: ConstructorConstraint<Class>['length'];
220
+ };
221
+
222
+ /**
223
+ * A more fleshed-out Class type.
224
+ *
225
+ * Note: is `Class & ...`
226
+ *
227
+ * In addition to the Constructor constraint, this type...
228
+ * - Sets the type of the immediate superclass.
229
+ * - Sets `prototype` to {@link InstanceType}
230
+ * @template Class The `typeof MyClass`. If this class extends a class, pass `typeof MySuperClass` to the generic argument {@link Class}.
231
+ * @example
232
+ * type Class_MyClass = ClassLike<typeof MyClass & WithProto<BaseClass<typeof MyBaseClass>>;
233
+ * @since 3.0.0
234
+ */
235
+ export type ClassLike<
236
+ Class extends ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>,
237
+ > = Class extends BaseClass<Class> ? Class
238
+ : Class['__proto__'] extends BaseClassProto ? BaseClass<Class>
239
+ : Class['__proto__'] extends ConstructorLike<Class['__proto__']>
240
+ ? IClass<Class> & WithProto<ConstructorLike<Class['__proto__']>>
241
+ // Here, __proto__ is retained via Class
242
+ : IClass<Class>;
243
+
244
+ /**
245
+ * If {@link T} is a class or constructor, {@link InstanceType}<{@link T}>. Else, {@link T}.
246
+ * @template T `null` or any `object`-like type.
247
+ * @since 3.0.0
248
+ */
249
+ export type InstanceTypeOrSelf<T extends object | null> = T extends ConstructorLike
250
+ ? T extends ConstructorLike<T>
251
+ ? InstanceType<T>
252
+ : T
253
+ : T;
254
+
255
+ /**
256
+ * Interface for attaching a `__proto__` to an object e.g. `T0 & WithProto<T1>`
257
+ * @template __proto__ the type of the an object's `[[Prototype]]`.
258
+ * @since 3.0.0
259
+ */
260
+ export interface WithProto<__proto__ extends ProtoOrSuperClass> {
261
+ ['__proto__']: __proto__;
262
+ }