@halospv3/hce.shared-config 3.4.7 → 3.4.8-develop.1

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 (72) hide show
  1. package/CHANGELOG.md +19 -4
  2. package/mjs/CaseInsensitiveMap.mjs +27 -1
  3. package/mjs/CaseInsensitiveMap.mjs.map +1 -1
  4. package/mjs/commitlintConfig.mjs +13 -1
  5. package/mjs/commitlintConfig.mjs.map +1 -1
  6. package/mjs/debug.mjs +8 -1
  7. package/mjs/debug.mjs.map +1 -1
  8. package/mjs/dotnet/GithubNugetRegistryInfo.mjs +39 -1
  9. package/mjs/dotnet/GithubNugetRegistryInfo.mjs.map +1 -1
  10. package/mjs/dotnet/GitlabNugetRegistryInfo.mjs +81 -1
  11. package/mjs/dotnet/GitlabNugetRegistryInfo.mjs.map +1 -1
  12. package/mjs/dotnet/IsNextVersionAlreadyPublished.cli.mjs +42 -1
  13. package/mjs/dotnet/IsNextVersionAlreadyPublished.cli.mjs.map +1 -1
  14. package/mjs/dotnet/MSBuildProject.mjs +345 -2
  15. package/mjs/dotnet/MSBuildProject.mjs.map +1 -1
  16. package/mjs/dotnet/MSBuildProjectProperties.mjs +233 -1
  17. package/mjs/dotnet/MSBuildProjectProperties.mjs.map +1 -1
  18. package/mjs/dotnet/NugetProjectProperties.mjs +520 -1
  19. package/mjs/dotnet/NugetProjectProperties.mjs.map +1 -1
  20. package/mjs/dotnet/NugetRegistryInfo.mjs +599 -3
  21. package/mjs/dotnet/NugetRegistryInfo.mjs.map +1 -1
  22. package/mjs/dotnet/helpers.mjs +222 -1
  23. package/mjs/dotnet/helpers.mjs.map +1 -1
  24. package/mjs/dotnet/index.mjs +9 -1
  25. package/mjs/dotnet.mjs +9 -1
  26. package/mjs/eslintConfig.mjs +97 -1
  27. package/mjs/eslintConfig.mjs.map +1 -1
  28. package/mjs/index.mjs +2 -1
  29. package/mjs/insertPlugins.mjs +35 -1
  30. package/mjs/insertPlugins.mjs.map +1 -1
  31. package/mjs/semanticReleaseConfig.mjs +63 -1
  32. package/mjs/semanticReleaseConfig.mjs.map +1 -1
  33. package/mjs/semanticReleaseConfigDotnet.mjs +223 -6
  34. package/mjs/semanticReleaseConfigDotnet.mjs.map +1 -1
  35. package/mjs/setupGitPluginSpec.default.mjs +18 -2
  36. package/mjs/setupGitPluginSpec.default.mjs.map +1 -1
  37. package/mjs/setupGitPluginSpec.mjs +108 -1
  38. package/mjs/setupGitPluginSpec.mjs.map +1 -1
  39. package/mjs/utils/Exact.d.mts +10 -10
  40. package/mjs/utils/Exact.d.mts.map +1 -1
  41. package/mjs/utils/env.mjs +39 -1
  42. package/mjs/utils/env.mjs.map +1 -1
  43. package/mjs/utils/execAsync.mjs +54 -7
  44. package/mjs/utils/execAsync.mjs.map +1 -1
  45. package/mjs/utils/isError.mjs +17 -1
  46. package/mjs/utils/isError.mjs.map +1 -1
  47. package/mjs/utils/miscTypes.mjs +7 -1
  48. package/mjs/utils/miscTypes.mjs.map +1 -1
  49. package/mjs/utils/reflection/filterForGetters.mjs +25 -1
  50. package/mjs/utils/reflection/filterForGetters.mjs.map +1 -1
  51. package/mjs/utils/reflection/getOwnPropertyDescriptors.mjs +27 -1
  52. package/mjs/utils/reflection/getOwnPropertyDescriptors.mjs.map +1 -1
  53. package/mjs/utils/reflection/getOwnPropertyDescriptorsRecursively.mjs +34 -1
  54. package/mjs/utils/reflection/getOwnPropertyDescriptorsRecursively.mjs.map +1 -1
  55. package/mjs/utils/reflection/getPrototypeChainOf.mjs +39 -1
  56. package/mjs/utils/reflection/getPrototypeChainOf.mjs.map +1 -1
  57. package/mjs/utils/reflection/getPrototypeOf.mjs +12 -1
  58. package/mjs/utils/reflection/getPrototypeOf.mjs.map +1 -1
  59. package/mjs/utils/reflection/inheritance.mjs +10 -1
  60. package/mjs/utils/reflection/inheritance.mjs.map +1 -1
  61. package/mjs/utils/reflection/isConstructor.mjs +30 -1
  62. package/mjs/utils/reflection/isConstructor.mjs.map +1 -1
  63. package/mjs/utils/reflection/isGetterDescriptor.mjs +13 -1
  64. package/mjs/utils/reflection/isGetterDescriptor.mjs.map +1 -1
  65. package/mjs/utils/reflection/listOwnGetters.mjs +29 -1
  66. package/mjs/utils/reflection/listOwnGetters.mjs.map +1 -1
  67. package/mjs/utils/reflection.mjs +10 -1
  68. package/package.json +17 -43
  69. package/src/utils/Exact.d.ts +17 -0
  70. package/mjs/utils/Exact.mjs +0 -2
  71. package/mjs/utils/Exact.mjs.map +0 -1
  72. package/src/utils/Exact.ts +0 -49
package/mjs/utils/env.mjs CHANGED
@@ -1,2 +1,40 @@
1
- import{env as e}from"node:process";import t from"@dotenvx/dotenvx";const{get:n,config:r}=t;function i(t,n){return r(t),n&&Object.assign(e,n),e}function a(t,r){r??={ignore:[`MISSING_KEY`,`MISSING_ENV_FILE`]};let i=e[t],a=n(t,r);return typeof a==`string`&&(i=a),i===``||i===`undefined`?void 0:i}export{i as getEnv,a as getEnvVarValue};
1
+ import { env } from "node:process";
2
+ import dotenvx from "@dotenvx/dotenvx";
3
+ //#region src/utils/env.ts
4
+ const { get, config: loadDotenv } = dotenvx;
5
+ /**
6
+ * A thin wrapper for {@link loadDotenv}. Loads a .env file from {@link process.cwd()} with the given options (or defaults), returns the new value of {@link process.env} with optional overrides.
7
+ * @param [dotenvOptions] An optional {@link DotenvConfigOptions} object to pass to {@link loadDotenv}.
8
+ * @param [overrides] If provided, this {@link NodeJS.ProcessEnv} object is merged into the return value, overriding existing properties where overlap occurs.
9
+ * @returns A {@link NodeJS.ProcessEnv} object whose properties are variables loaded from the
10
+ * process environment, the nearest .env file, and {@link overrides} (if provided). Where
11
+ * overlap occurs, the later source takes priority.
12
+ */
13
+ function getEnv(dotenvOptions, overrides) {
14
+ loadDotenv(dotenvOptions);
15
+ if (overrides) Object.assign(env, overrides);
16
+ return env;
17
+ }
18
+ /**
19
+ * Get the value from the given env var in the current process or nearby .env file.
20
+ * If found in process environment, its value is returned.
21
+ * Else, try to get it from the nearest .env file.
22
+ * If NOT found, return `undefined`
23
+ * @param envVar The environment variable to lookup.
24
+ * @param [options] Options to pass to {@link get}
25
+ * @returns The string value of the environment variable or `undefined`.
26
+ * `undefined` may be returned when the variable is undefined or its string is
27
+ * empty, whitespace, or appears to have been converted from `null` or
28
+ * `undefined`.
29
+ */
30
+ function getEnvVarValue(envVar, options) {
31
+ options ??= { ignore: ["MISSING_KEY", "MISSING_ENV_FILE"] };
32
+ let value = env[envVar];
33
+ const x = get(envVar, options);
34
+ if (typeof x === "string") value = x;
35
+ return value === "" || value === "undefined" ? void 0 : value;
36
+ }
37
+ //#endregion
38
+ export { getEnv, getEnvVarValue };
39
+
2
40
  //# sourceMappingURL=env.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"env.mjs","names":[],"sources":["../../src/utils/env.ts"],"sourcesContent":["import dotenvx, {\n type DotenvConfigOptions,\n type GetOptions,\n} from '@dotenvx/dotenvx';\nimport { env } from 'node:process';\n\n// I hate importing CommonJS modules with their broken default exports\nconst {\n get,\n config: loadDotenv,\n} = dotenvx;\n\n/** `get` can return `undefined`. It can also return a `Record`, but that's internal. */\ntype Get = (key: string, options?: GetOptions) => string | undefined;\n\n/**\n * A thin wrapper for {@link loadDotenv}. Loads a .env file from {@link process.cwd()} with the given options (or defaults), returns the new value of {@link process.env} with optional overrides.\n * @param [dotenvOptions] An optional {@link DotenvConfigOptions} object to pass to {@link loadDotenv}.\n * @param [overrides] If provided, this {@link NodeJS.ProcessEnv} object is merged into the return value, overriding existing properties where overlap occurs.\n * @returns A {@link NodeJS.ProcessEnv} object whose properties are variables loaded from the\n * process environment, the nearest .env file, and {@link overrides} (if provided). Where\n * overlap occurs, the later source takes priority.\n */\nexport function getEnv(dotenvOptions?: DotenvConfigOptions, overrides?: NodeJS.ProcessEnv): NodeJS.ProcessEnv {\n loadDotenv(dotenvOptions);\n\n if (overrides)\n Object.assign(env, overrides);\n\n return env;\n}\n\n/**\n * Get the value from the given env var in the current process or nearby .env file.\n * If found in process environment, its value is returned.\n * Else, try to get it from the nearest .env file.\n * If NOT found, return `undefined`\n * @param envVar The environment variable to lookup.\n * @param [options] Options to pass to {@link get}\n * @returns The string value of the environment variable or `undefined`.\n * `undefined` may be returned when the variable is undefined or its string is\n * empty, whitespace, or appears to have been converted from `null` or\n * `undefined`.\n */\nexport function getEnvVarValue(envVar: string, options?: GetOptions): string | undefined {\n options ??= { ignore: ['MISSING_KEY', 'MISSING_ENV_FILE'] };\n let value = env[envVar];\n const x = (get as Get)(envVar, options);\n if (typeof x === 'string')\n value = x;\n // I hate this. Why is undefined converted to a string?\n return value === '' || value === 'undefined'\n ? undefined\n : value;\n}\n"],"mappings":"mEAOA,KAAM,CACJ,MACA,OAAQ,GACN,EAaJ,SAAgB,EAAO,EAAqC,EAAkD,CAM5G,OALA,EAAW,EAAc,CAErB,GACF,OAAO,OAAO,EAAK,EAAU,CAExB,EAeT,SAAgB,EAAe,EAAgB,EAA0C,CACvF,IAAY,CAAE,OAAQ,CAAC,cAAe,mBAAmB,CAAE,CAC3D,IAAI,EAAQ,EAAI,GACV,EAAK,EAAY,EAAQ,EAAQ,CAIvC,OAHI,OAAO,GAAM,WACf,EAAQ,GAEH,IAAU,IAAM,IAAU,YAC7B,IAAA,GACA"}
1
+ {"version":3,"file":"env.mjs","names":[],"sources":["../../src/utils/env.ts"],"sourcesContent":["import dotenvx, {\n type DotenvConfigOptions,\n type GetOptions,\n} from '@dotenvx/dotenvx';\nimport { env } from 'node:process';\n\n// I hate importing CommonJS modules with their broken default exports\nconst {\n get,\n config: loadDotenv,\n} = dotenvx;\n\n/** `get` can return `undefined`. It can also return a `Record`, but that's internal. */\ntype Get = (key: string, options?: GetOptions) => string | undefined;\n\n/**\n * A thin wrapper for {@link loadDotenv}. Loads a .env file from {@link process.cwd()} with the given options (or defaults), returns the new value of {@link process.env} with optional overrides.\n * @param [dotenvOptions] An optional {@link DotenvConfigOptions} object to pass to {@link loadDotenv}.\n * @param [overrides] If provided, this {@link NodeJS.ProcessEnv} object is merged into the return value, overriding existing properties where overlap occurs.\n * @returns A {@link NodeJS.ProcessEnv} object whose properties are variables loaded from the\n * process environment, the nearest .env file, and {@link overrides} (if provided). Where\n * overlap occurs, the later source takes priority.\n */\nexport function getEnv(dotenvOptions?: DotenvConfigOptions, overrides?: NodeJS.ProcessEnv): NodeJS.ProcessEnv {\n loadDotenv(dotenvOptions);\n\n if (overrides)\n Object.assign(env, overrides);\n\n return env;\n}\n\n/**\n * Get the value from the given env var in the current process or nearby .env file.\n * If found in process environment, its value is returned.\n * Else, try to get it from the nearest .env file.\n * If NOT found, return `undefined`\n * @param envVar The environment variable to lookup.\n * @param [options] Options to pass to {@link get}\n * @returns The string value of the environment variable or `undefined`.\n * `undefined` may be returned when the variable is undefined or its string is\n * empty, whitespace, or appears to have been converted from `null` or\n * `undefined`.\n */\nexport function getEnvVarValue(envVar: string, options?: GetOptions): string | undefined {\n options ??= { ignore: ['MISSING_KEY', 'MISSING_ENV_FILE'] };\n let value = env[envVar];\n const x = (get as Get)(envVar, options);\n if (typeof x === 'string')\n value = x;\n // I hate this. Why is undefined converted to a string?\n return value === '' || value === 'undefined'\n ? undefined\n : value;\n}\n"],"mappings":";;;AAOA,MAAM,EACJ,KACA,QAAQ,eACN;;;;;;;;;AAaJ,SAAgB,OAAO,eAAqC,WAAkD;AAC5G,YAAW,cAAc;AAEzB,KAAI,UACF,QAAO,OAAO,KAAK,UAAU;AAE/B,QAAO;;;;;;;;;;;;;;AAeT,SAAgB,eAAe,QAAgB,SAA0C;AACvF,aAAY,EAAE,QAAQ,CAAC,eAAe,mBAAmB,EAAE;CAC3D,IAAI,QAAQ,IAAI;CAChB,MAAM,IAAK,IAAY,QAAQ,QAAQ;AACvC,KAAI,OAAO,MAAM,SACf,SAAQ;AAEV,QAAO,UAAU,MAAM,UAAU,cAC7B,KAAA,IACA"}
@@ -1,10 +1,57 @@
1
- import{isError as e}from"./isError.mjs";import{promisify as t}from"node:util";import{type as n}from"arktype";import{exec as r}from"node:child_process";import{constants as i}from"node:os";async function a(n,i=!1){return await t(r)(n).catch(t=>{throw e(t)?(i&&`stderr`in t&&typeof t.stderr==`string`&&t.stderr!==``&&(t.cause??=t.stderr),`stdout`in t&&typeof t.stdout==`string`&&(t.message+=`
1
+ import { isError } from "./isError.mjs";
2
+ import { promisify } from "node:util";
3
+ import { type } from "arktype";
4
+ import { exec } from "node:child_process";
5
+ import { constants } from "node:os";
6
+ //#region src/utils/execAsync.ts
7
+ /**
8
+ * A `promisify(exec)` wrapper to optionally assign the child process's STDERR as the {@link Error.prototype.cause}.
9
+ * @see {@link promisify}, {@link exec}
10
+ * @param command The command to run, with space-separated arguments.
11
+ * @param [setStderrAsCause=false] If true and the child process's stderr is available, the thrown Error's {@link Error.prototype.cause} is assigned the stderr string.
12
+ * @returns A promise of the child process's STDOUT and STDERR streams as strings
13
+ * @throws {Error | ChildProcessSpawnException}
14
+ */
15
+ async function execAsync(command, setStderrAsCause = false) {
16
+ return await promisify(exec)(command).catch((error) => {
17
+ if (!isError(error)) throw new Error(JSON.stringify(error));
18
+ if (setStderrAsCause && "stderr" in error && typeof error.stderr === "string" && error.stderr !== "") error.cause ??= error.stderr;
19
+ if ("stdout" in error && typeof error.stdout === "string") error.message += `
2
20
  STDOUT:
3
- ${t.stdout.replaceAll(`
4
- `,`
5
- `)}`),`stderr`in t&&typeof t.stderr==`string`&&(t.message+=`
21
+ ${error.stdout.replaceAll("\n", "\n ")}`;
22
+ if ("stderr" in error && typeof error.stderr === "string") error.message += `
6
23
  STDERR:
7
- ${t.stderr.replaceAll(`
8
- `,`
9
- `)}`),new s(t.message,t)):Error(JSON.stringify(t))})}const o=n(`Error`).and({"cmd?":`string | null`,"killed?":`boolean | null`,"code?":`number | null`,"signal?":n.null.or(Object.keys(i.signals).map(e=>n(`'${e}'`)).reduce((e,t)=>e.or(t))),"stdout?":`string`,"stderr?":`string`});var s=class extends Error{constructor(e,t){t=o.from(t),super(e,t),this.cmd=t.cmd,this.code=t.code,this.killed=t.killed,this.signal=t.signal,this.stderr=t.stderr,this.stdout=t.stdout}cmd;code;killed;signal;stderr;stdout};export{s as ChildProcessSpawnException,a as execAsync};
24
+ ${error.stderr.replaceAll("\n", "\n ")}`;
25
+ throw new ChildProcessSpawnException(error.message, error);
26
+ });
27
+ }
28
+ const T_ExecException = type("Error").and({
29
+ "cmd?": "string | null",
30
+ "killed?": "boolean | null",
31
+ "code?": "number | null",
32
+ "signal?": type.null.or(Object.keys(constants.signals).map((v) => type(`'${v}'`)).reduce((previous, current) => previous.or(current))),
33
+ "stdout?": "string",
34
+ "stderr?": "string"
35
+ });
36
+ var ChildProcessSpawnException = class extends Error {
37
+ constructor(message, options) {
38
+ options = T_ExecException.from(options);
39
+ super(message, options);
40
+ this.cmd = options.cmd;
41
+ this.code = options.code;
42
+ this.killed = options.killed;
43
+ this.signal = options.signal;
44
+ this.stderr = options.stderr;
45
+ this.stdout = options.stdout;
46
+ }
47
+ cmd;
48
+ code;
49
+ killed;
50
+ signal;
51
+ stderr;
52
+ stdout;
53
+ };
54
+ //#endregion
55
+ export { ChildProcessSpawnException, execAsync };
56
+
10
57
  //# sourceMappingURL=execAsync.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"execAsync.mjs","names":[],"sources":["../../src/utils/execAsync.ts"],"sourcesContent":["/* eslint-disable jsdoc/no-defaults */\nimport { type, type Type } from 'arktype';\nimport { exec } from 'node:child_process';\nimport { constants } from 'node:os';\nimport { promisify } from 'node:util';\nimport { isError } from './isError.ts';\n\n/**\n * A `promisify(exec)` wrapper to optionally assign the child process's STDERR as the {@link Error.prototype.cause}.\n * @see {@link promisify}, {@link exec}\n * @param command The command to run, with space-separated arguments.\n * @param [setStderrAsCause=false] If true and the child process's stderr is available, the thrown Error's {@link Error.prototype.cause} is assigned the stderr string.\n * @returns A promise of the child process's STDOUT and STDERR streams as strings\n * @throws {Error | ChildProcessSpawnException}\n */\nexport async function execAsync(command: string, setStderrAsCause = false): Promise<{\n stdout: string;\n stderr: string;\n}> {\n return await promisify(exec)(command).catch((error: unknown): never => {\n if (!isError(error))\n throw new Error(JSON.stringify(error));\n\n if (setStderrAsCause && 'stderr' in error && typeof error.stderr === 'string' && error.stderr !== '')\n error.cause ??= error.stderr;\n\n if ('stdout' in error && typeof error.stdout === 'string') {\n error.message\n += '\\nSTDOUT:\\n'\n + ` ${error.stdout.replaceAll('\\n', '\\n ')}`;\n }\n if ('stderr' in error && typeof error.stderr === 'string') {\n error.message\n += '\\nSTDERR:\\n'\n + ` ${error.stderr.replaceAll('\\n', '\\n ')}`;\n }\n\n throw new ChildProcessSpawnException(error.message, error);\n });\n}\n\nconst T_ExecException: Type<{\n name: string;\n message: string;\n stack?: string | undefined;\n cause?: unknown;\n cmd?: string | null | undefined;\n killed?: boolean | null | undefined;\n code?: number | null | undefined;\n signal?: 'SIGABRT' | 'SIGALRM' | 'SIGBUS' | 'SIGCHLD' | 'SIGCONT' | 'SIGFPE' | 'SIGHUP' | 'SIGILL' | 'SIGINT' | 'SIGIO' | 'SIGIOT' | 'SIGKILL' | 'SIGPIPE' | 'SIGPOLL' | 'SIGPROF' | 'SIGPWR' | 'SIGQUIT' | 'SIGSEGV' | 'SIGSTKFLT' | 'SIGSTOP' | 'SIGSYS' | 'SIGTERM' | 'SIGTRAP' | 'SIGTSTP' | 'SIGTTIN' | 'SIGTTOU' | 'SIGUNUSED' | 'SIGURG' | 'SIGUSR1' | 'SIGUSR2' | 'SIGVTALRM' | 'SIGWINCH' | 'SIGXCPU' | 'SIGXFSZ' | 'SIGBREAK' | 'SIGLOST' | 'SIGINFO' | null | undefined;\n stdout?: string | undefined;\n stderr?: string | undefined;\n}> = type('Error').and({\n 'cmd?': 'string | null',\n 'killed?': 'boolean | null',\n 'code?': 'number | null',\n 'signal?': type.null.or((Object.keys(constants.signals) as NodeJS.Signals[])\n .map(v => type(`'${v}'`))\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce((previous, current) => previous.or(current))),\n 'stdout?': 'string',\n 'stderr?': 'string',\n});\n\ntype _ExecException = typeof T_ExecException.inferOut;\n\nexport class ChildProcessSpawnException extends Error implements _ExecException {\n constructor(\n message: Parameters<typeof Error>[0],\n options: typeof T_ExecException.inferIn,\n ) {\n options = T_ExecException.from(options);\n super(message, options);\n this.cmd = options.cmd;\n this.code = options.code;\n this.killed = options.killed;\n this.signal = options.signal;\n this.stderr = options.stderr;\n this.stdout = options.stdout;\n }\n\n cmd: typeof T_ExecException.inferOut.cmd;\n code: typeof T_ExecException.inferOut.code;\n killed: typeof T_ExecException.inferOut.killed;\n signal: typeof T_ExecException.inferOut.signal;\n stderr: typeof T_ExecException.inferOut.stderr;\n stdout: typeof T_ExecException.inferOut.stdout;\n}\n"],"mappings":"2LAeA,eAAsB,EAAU,EAAiB,EAAmB,GAGjE,CACD,OAAO,MAAM,EAAU,EAAK,CAAC,EAAQ,CAAC,MAAO,GAA0B,CAkBrE,MAjBK,EAAQ,EAAM,EAGf,GAAoB,WAAY,GAAS,OAAO,EAAM,QAAW,UAAY,EAAM,SAAW,KAChG,EAAM,QAAU,EAAM,QAEpB,WAAY,GAAS,OAAO,EAAM,QAAW,WAC/C,EAAM,SACD;;IACM,EAAM,OAAO,WAAW;EAAM;IAAO,IAE9C,WAAY,GAAS,OAAO,EAAM,QAAW,WAC/C,EAAM,SACD;;IACM,EAAM,OAAO,WAAW;EAAM;IAAO,IAG5C,IAAI,EAA2B,EAAM,QAAS,EAAM,EAhB9C,MAAM,KAAK,UAAU,EAAM,CAAC,EAiBxC,CAGJ,MAAM,EAWD,EAAK,QAAQ,CAAC,IAAI,CACrB,OAAQ,gBACR,UAAW,iBACX,QAAS,gBACT,UAAW,EAAK,KAAK,GAAI,OAAO,KAAK,EAAU,QAAQ,CACpD,IAAI,GAAK,EAAK,IAAI,EAAE,GAAG,CAAC,CAExB,QAAQ,EAAU,IAAY,EAAS,GAAG,EAAQ,CAAC,CAAC,CACvD,UAAW,SACX,UAAW,SACZ,CAAC,CAIF,IAAa,EAAb,cAAgD,KAAgC,CAC9E,YACE,EACA,EACA,CACA,EAAU,EAAgB,KAAK,EAAQ,CACvC,MAAM,EAAS,EAAQ,CACvB,KAAK,IAAM,EAAQ,IACnB,KAAK,KAAO,EAAQ,KACpB,KAAK,OAAS,EAAQ,OACtB,KAAK,OAAS,EAAQ,OACtB,KAAK,OAAS,EAAQ,OACtB,KAAK,OAAS,EAAQ,OAGxB,IACA,KACA,OACA,OACA,OACA"}
1
+ {"version":3,"file":"execAsync.mjs","names":[],"sources":["../../src/utils/execAsync.ts"],"sourcesContent":["/* eslint-disable jsdoc/no-defaults */\nimport { type, type Type } from 'arktype';\nimport { exec } from 'node:child_process';\nimport { constants } from 'node:os';\nimport { promisify } from 'node:util';\nimport { isError } from './isError.ts';\n\n/**\n * A `promisify(exec)` wrapper to optionally assign the child process's STDERR as the {@link Error.prototype.cause}.\n * @see {@link promisify}, {@link exec}\n * @param command The command to run, with space-separated arguments.\n * @param [setStderrAsCause=false] If true and the child process's stderr is available, the thrown Error's {@link Error.prototype.cause} is assigned the stderr string.\n * @returns A promise of the child process's STDOUT and STDERR streams as strings\n * @throws {Error | ChildProcessSpawnException}\n */\nexport async function execAsync(command: string, setStderrAsCause = false): Promise<{\n stdout: string;\n stderr: string;\n}> {\n return await promisify(exec)(command).catch((error: unknown): never => {\n if (!isError(error))\n throw new Error(JSON.stringify(error));\n\n if (setStderrAsCause && 'stderr' in error && typeof error.stderr === 'string' && error.stderr !== '')\n error.cause ??= error.stderr;\n\n if ('stdout' in error && typeof error.stdout === 'string') {\n error.message\n += '\\nSTDOUT:\\n'\n + ` ${error.stdout.replaceAll('\\n', '\\n ')}`;\n }\n if ('stderr' in error && typeof error.stderr === 'string') {\n error.message\n += '\\nSTDERR:\\n'\n + ` ${error.stderr.replaceAll('\\n', '\\n ')}`;\n }\n\n throw new ChildProcessSpawnException(error.message, error);\n });\n}\n\nconst T_ExecException: Type<{\n name: string;\n message: string;\n stack?: string | undefined;\n cause?: unknown;\n cmd?: string | null | undefined;\n killed?: boolean | null | undefined;\n code?: number | null | undefined;\n signal?: 'SIGABRT' | 'SIGALRM' | 'SIGBUS' | 'SIGCHLD' | 'SIGCONT' | 'SIGFPE' | 'SIGHUP' | 'SIGILL' | 'SIGINT' | 'SIGIO' | 'SIGIOT' | 'SIGKILL' | 'SIGPIPE' | 'SIGPOLL' | 'SIGPROF' | 'SIGPWR' | 'SIGQUIT' | 'SIGSEGV' | 'SIGSTKFLT' | 'SIGSTOP' | 'SIGSYS' | 'SIGTERM' | 'SIGTRAP' | 'SIGTSTP' | 'SIGTTIN' | 'SIGTTOU' | 'SIGUNUSED' | 'SIGURG' | 'SIGUSR1' | 'SIGUSR2' | 'SIGVTALRM' | 'SIGWINCH' | 'SIGXCPU' | 'SIGXFSZ' | 'SIGBREAK' | 'SIGLOST' | 'SIGINFO' | null | undefined;\n stdout?: string | undefined;\n stderr?: string | undefined;\n}> = type('Error').and({\n 'cmd?': 'string | null',\n 'killed?': 'boolean | null',\n 'code?': 'number | null',\n 'signal?': type.null.or((Object.keys(constants.signals) as NodeJS.Signals[])\n .map(v => type(`'${v}'`))\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce((previous, current) => previous.or(current))),\n 'stdout?': 'string',\n 'stderr?': 'string',\n});\n\ntype _ExecException = typeof T_ExecException.inferOut;\n\nexport class ChildProcessSpawnException extends Error implements _ExecException {\n constructor(\n message: Parameters<typeof Error>[0],\n options: typeof T_ExecException.inferIn,\n ) {\n options = T_ExecException.from(options);\n super(message, options);\n this.cmd = options.cmd;\n this.code = options.code;\n this.killed = options.killed;\n this.signal = options.signal;\n this.stderr = options.stderr;\n this.stdout = options.stdout;\n }\n\n cmd: typeof T_ExecException.inferOut.cmd;\n code: typeof T_ExecException.inferOut.code;\n killed: typeof T_ExecException.inferOut.killed;\n signal: typeof T_ExecException.inferOut.signal;\n stderr: typeof T_ExecException.inferOut.stderr;\n stdout: typeof T_ExecException.inferOut.stdout;\n}\n"],"mappings":";;;;;;;;;;;;;;AAeA,eAAsB,UAAU,SAAiB,mBAAmB,OAGjE;AACD,QAAO,MAAM,UAAU,KAAK,CAAC,QAAQ,CAAC,OAAO,UAA0B;AACrE,MAAI,CAAC,QAAQ,MAAM,CACjB,OAAM,IAAI,MAAM,KAAK,UAAU,MAAM,CAAC;AAExC,MAAI,oBAAoB,YAAY,SAAS,OAAO,MAAM,WAAW,YAAY,MAAM,WAAW,GAChG,OAAM,UAAU,MAAM;AAExB,MAAI,YAAY,SAAS,OAAO,MAAM,WAAW,SAC/C,OAAM,WACD;;IACM,MAAM,OAAO,WAAW,MAAM,OAAO;AAElD,MAAI,YAAY,SAAS,OAAO,MAAM,WAAW,SAC/C,OAAM,WACD;;IACM,MAAM,OAAO,WAAW,MAAM,OAAO;AAGlD,QAAM,IAAI,2BAA2B,MAAM,SAAS,MAAM;GAC1D;;AAGJ,MAAM,kBAWD,KAAK,QAAQ,CAAC,IAAI;CACrB,QAAQ;CACR,WAAW;CACX,SAAS;CACT,WAAW,KAAK,KAAK,GAAI,OAAO,KAAK,UAAU,QAAQ,CACpD,KAAI,MAAK,KAAK,IAAI,EAAE,GAAG,CAAC,CAExB,QAAQ,UAAU,YAAY,SAAS,GAAG,QAAQ,CAAC,CAAC;CACvD,WAAW;CACX,WAAW;CACZ,CAAC;AAIF,IAAa,6BAAb,cAAgD,MAAgC;CAC9E,YACE,SACA,SACA;AACA,YAAU,gBAAgB,KAAK,QAAQ;AACvC,QAAM,SAAS,QAAQ;AACvB,OAAK,MAAM,QAAQ;AACnB,OAAK,OAAO,QAAQ;AACpB,OAAK,SAAS,QAAQ;AACtB,OAAK,SAAS,QAAQ;AACtB,OAAK,SAAS,QAAQ;AACtB,OAAK,SAAS,QAAQ;;CAGxB;CACA;CACA;CACA;CACA;CACA"}
@@ -1,2 +1,18 @@
1
- import{isNativeError as e}from"node:util/types";function t(t){return`isError`in Error&&typeof Error.isError==`function`&&Error.isError.length>0?Error.isError(t):e(t)}export{t as isError};
1
+ import { isNativeError } from "node:util/types";
2
+ //#region src/utils/isError.ts
3
+ /** @import 'typescript/lib/lib.esnext.error.d.ts' */
4
+ /**
5
+ * Compatibility wrapper for ES2026 (Node.js 25)
6
+ * {@link Error.isError Error.isError}
7
+ * with failover to the deprecated {@link isNativeError utils.types.isNativeError}.
8
+ * @param error A parameter which may be an Error.
9
+ * @returns `true` if {@link error} is derived from or is sufficiently similar to {@link Error}. Else, `false`.
10
+ * Note: DOMExceptions will result in `false`
11
+ */
12
+ function isError(error) {
13
+ return "isError" in Error && typeof Error.isError === "function" && Error.isError.length > 0 ? Error.isError(error) : isNativeError(error);
14
+ }
15
+ //#endregion
16
+ export { isError };
17
+
2
18
  //# sourceMappingURL=isError.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"isError.mjs","names":[],"sources":["../../src/utils/isError.ts"],"sourcesContent":["import { isNativeError } from 'node:util/types';\n\n/** @import 'typescript/lib/lib.esnext.error.d.ts' */\n\n/**\n * Compatibility wrapper for ES2026 (Node.js 25)\n * {@link Error.isError Error.isError}\n * with failover to the deprecated {@link isNativeError utils.types.isNativeError}.\n * @param error A parameter which may be an Error.\n * @returns `true` if {@link error} is derived from or is sufficiently similar to {@link Error}. Else, `false`.\n * Note: DOMExceptions will result in `false`\n */\nexport function isError(error: unknown): error is Error {\n return 'isError' in Error && typeof Error.isError === 'function' && Error.isError.length > 0\n ? (Error.isError as typeof isError)(error)\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n : isNativeError(error);\n}\n"],"mappings":"gDAYA,SAAgB,EAAQ,EAAgC,CACtD,MAAO,YAAa,OAAS,OAAO,MAAM,SAAY,YAAc,MAAM,QAAQ,OAAS,EACtF,MAAM,QAA2B,EAAM,CAExC,EAAc,EAAM"}
1
+ {"version":3,"file":"isError.mjs","names":[],"sources":["../../src/utils/isError.ts"],"sourcesContent":["import { isNativeError } from 'node:util/types';\n\n/** @import 'typescript/lib/lib.esnext.error.d.ts' */\n\n/**\n * Compatibility wrapper for ES2026 (Node.js 25)\n * {@link Error.isError Error.isError}\n * with failover to the deprecated {@link isNativeError utils.types.isNativeError}.\n * @param error A parameter which may be an Error.\n * @returns `true` if {@link error} is derived from or is sufficiently similar to {@link Error}. Else, `false`.\n * Note: DOMExceptions will result in `false`\n */\nexport function isError(error: unknown): error is Error {\n return 'isError' in Error && typeof Error.isError === 'function' && Error.isError.length > 0\n ? (Error.isError as typeof isError)(error)\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n : isNativeError(error);\n}\n"],"mappings":";;;;;;;;;;;AAYA,SAAgB,QAAQ,OAAgC;AACtD,QAAO,aAAa,SAAS,OAAO,MAAM,YAAY,cAAc,MAAM,QAAQ,SAAS,IACtF,MAAM,QAA2B,MAAM,GAExC,cAAc,MAAM"}
@@ -1,2 +1,8 @@
1
- import{type as e}from"arktype";const t=e(`"true" | "false"`),n=e(t.or(`""`));export{t as tBooleanString,n as tEmptyOrBooleanString};
1
+ import { type } from "arktype";
2
+ //#region src/utils/miscTypes.ts
3
+ const tBooleanString = type("\"true\" | \"false\"");
4
+ const tEmptyOrBooleanString = type(tBooleanString.or("\"\""));
5
+ //#endregion
6
+ export { tBooleanString, tEmptyOrBooleanString };
7
+
2
8
  //# sourceMappingURL=miscTypes.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"miscTypes.mjs","names":[],"sources":["../../src/utils/miscTypes.ts"],"sourcesContent":["import { type, type Type } from 'arktype';\n\nexport const tBooleanString: Type<'false' | 'true'> = type('\"true\" | \"false\"');\nexport type BooleanString = typeof tBooleanString.infer;\n\nexport const tEmptyOrBooleanString: Type<'' | 'false' | 'true'> = type(tBooleanString.or('\"\"'));\nexport type EmptyOrBooleanString = typeof tEmptyOrBooleanString.infer;\n\nexport type Integer<N extends number> = `${N}` extends `${number}.${number}` ? never : N;\n\n/**\n * @see https://stackoverflow.com/a/73920140/14894786\n */\nexport type TupleIndices<T extends readonly unknown[]>\n = Extract<keyof T, `${number}`> extends `${infer N extends number}` ? N : never;\n\nexport type InstanceOrStatic = 'Instance' | 'Static';\n"],"mappings":"+BAEA,MAAa,EAAyC,EAAK,mBAAmB,CAGjE,EAAqD,EAAK,EAAe,GAAG,KAAK,CAAC"}
1
+ {"version":3,"file":"miscTypes.mjs","names":[],"sources":["../../src/utils/miscTypes.ts"],"sourcesContent":["import { type, type Type } from 'arktype';\n\nexport const tBooleanString: Type<'false' | 'true'> = type('\"true\" | \"false\"');\nexport type BooleanString = typeof tBooleanString.infer;\n\nexport const tEmptyOrBooleanString: Type<'' | 'false' | 'true'> = type(tBooleanString.or('\"\"'));\nexport type EmptyOrBooleanString = typeof tEmptyOrBooleanString.infer;\n\nexport type Integer<N extends number> = `${N}` extends `${number}.${number}` ? never : N;\n\n/**\n * @see https://stackoverflow.com/a/73920140/14894786\n */\nexport type TupleIndices<T extends readonly unknown[]>\n = Extract<keyof T, `${number}`> extends `${infer N extends number}` ? N : never;\n\nexport type InstanceOrStatic = 'Instance' | 'Static';\n"],"mappings":";;AAEA,MAAa,iBAAyC,KAAK,uBAAmB;AAG9E,MAAa,wBAAqD,KAAK,eAAe,GAAG,OAAK,CAAC"}
@@ -1,2 +1,26 @@
1
- function e(e){let t={};for(let n in e){let r=e[n];typeof r.get==`function`&&(t=Object.assign(t,{[n]:r}))}return t}export{e as filterForGetters};
1
+ //#region src/utils/reflection/filterForGetters.ts
2
+ /**
3
+ * Iterates through the descriptors object, checking for property descriptors whose `get` is a function.
4
+ * Returns an {@link OwnGetterDescriptorMap} of the getters.
5
+ * If you want only own, non-inherited getters, you must filter sanitize the
6
+ * type the `descriptors` parameter yourself e.g. `Omit<Class, keyof
7
+ * SuperClass>`.
8
+ * @param descriptorMap An object like the return value of Object.getOwnPropertyDescriptors
9
+ * @template Class Any ClassLike type
10
+ * @template T Any `object`-like type.
11
+ * @template [__proto__=null] If {@link Class} is not {@link ClassLike}, the `__proto__` of {@link T}.
12
+ * @returns An {@link OwnGetterDescriptorMap}.
13
+ * @since 3.0.0
14
+ */
15
+ function filterForGetters(descriptorMap) {
16
+ let getterDescriptorMap = {};
17
+ for (const key in descriptorMap) {
18
+ const element = descriptorMap[key];
19
+ if (typeof element.get === "function") getterDescriptorMap = Object.assign(getterDescriptorMap, { [key]: element });
20
+ }
21
+ return getterDescriptorMap;
22
+ }
23
+ //#endregion
24
+ export { filterForGetters };
25
+
2
26
  //# sourceMappingURL=filterForGetters.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"filterForGetters.mjs","names":[],"sources":["../../../src/utils/reflection/filterForGetters.ts"],"sourcesContent":["import type {\n BaseClassProto,\n baseClassProto,\n ClassLike,\n ConstructorConstraint,\n InstanceTypeOrSelf,\n SuperClassLike,\n WithProto,\n} from './inheritance.ts';\nimport type { InstancePropertyDescriptorMap } from './InstancePropertyDescriptorMap.d.ts';\nimport type { OwnGetterDescriptorMap } from './OwnGetterDescriptorMap.d.ts';\nimport type { OwnPropertyDescriptorMap } from './OwnPropertyDescriptorMap.d.ts';\nimport type { PropertyDescriptorMap } from './PropertyDescriptorMap.d.ts';\n\nexport function filterForGetters<\n Class extends ClassLike<ConstructorConstraint<Class> & WithProto<SuperClassLike | typeof baseClassProto>>,\n>(\n descriptorMap: InstancePropertyDescriptorMap<Class>,\n): Partial<OwnGetterDescriptorMap<\n InstanceType<Class>,\n Class['__proto__'] extends BaseClassProto ? null : InstanceTypeOrSelf<Class['__proto__']>\n>>;\nexport function filterForGetters<\n Class extends ClassLike<ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>>,\n>(\n descriptorMap: OwnPropertyDescriptorMap<Class>,\n): Partial<OwnGetterDescriptorMap<Class, Class['__proto__']>>;\n/**\n * Iterates through the descriptors object, checking for property descriptors whose `get` is a function.\n * Returns an {@link OwnGetterDescriptorMap} of the getters.\n * If you want only own, non-inherited getters, you must filter sanitize the\n * type the `descriptors` parameter yourself e.g. `Omit<Class, keyof\n * SuperClass>`.\n * @param descriptorMap An object like the return value of Object.getOwnPropertyDescriptors\n * @template Class Any ClassLike type\n * @template T Any `object`-like type.\n * @template [__proto__=null] If {@link Class} is not {@link ClassLike}, the `__proto__` of {@link T}.\n * @returns An {@link OwnGetterDescriptorMap}.\n * @since 3.0.0\n */\nexport function filterForGetters<\n T extends object,\n __proto__ extends object | null = null,\n>(\n descriptorMap: PropertyDescriptorMap<T, __proto__> | PropertyDescriptorMap<T>,\n): Partial<OwnGetterDescriptorMap<T, __proto__>> {\n let getterDescriptorMap: Partial<OwnGetterDescriptorMap<T, __proto__>> = {};\n for (const key in descriptorMap) {\n const element = descriptorMap[key as keyof typeof descriptorMap];\n if (typeof element.get === 'function') {\n getterDescriptorMap = Object.assign(\n getterDescriptorMap,\n { [key]: element },\n );\n }\n }\n\n return getterDescriptorMap;\n}\n"],"mappings":"AAwCA,SAAgB,EAId,EAC+C,CAC/C,IAAI,EAAqE,EAAE,CAC3E,IAAK,IAAM,KAAO,EAAe,CAC/B,IAAM,EAAU,EAAc,GAC1B,OAAO,EAAQ,KAAQ,aACzB,EAAsB,OAAO,OAC3B,EACA,EAAG,GAAM,EAAS,CACnB,EAIL,OAAO"}
1
+ {"version":3,"file":"filterForGetters.mjs","names":[],"sources":["../../../src/utils/reflection/filterForGetters.ts"],"sourcesContent":["import type {\n BaseClassProto,\n baseClassProto,\n ClassLike,\n ConstructorConstraint,\n InstanceTypeOrSelf,\n SuperClassLike,\n WithProto,\n} from './inheritance.ts';\nimport type { InstancePropertyDescriptorMap } from './InstancePropertyDescriptorMap.d.ts';\nimport type { OwnGetterDescriptorMap } from './OwnGetterDescriptorMap.d.ts';\nimport type { OwnPropertyDescriptorMap } from './OwnPropertyDescriptorMap.d.ts';\nimport type { PropertyDescriptorMap } from './PropertyDescriptorMap.d.ts';\n\nexport function filterForGetters<\n Class extends ClassLike<ConstructorConstraint<Class> & WithProto<SuperClassLike | typeof baseClassProto>>,\n>(\n descriptorMap: InstancePropertyDescriptorMap<Class>,\n): Partial<OwnGetterDescriptorMap<\n InstanceType<Class>,\n Class['__proto__'] extends BaseClassProto ? null : InstanceTypeOrSelf<Class['__proto__']>\n>>;\nexport function filterForGetters<\n Class extends ClassLike<ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>>,\n>(\n descriptorMap: OwnPropertyDescriptorMap<Class>,\n): Partial<OwnGetterDescriptorMap<Class, Class['__proto__']>>;\n/**\n * Iterates through the descriptors object, checking for property descriptors whose `get` is a function.\n * Returns an {@link OwnGetterDescriptorMap} of the getters.\n * If you want only own, non-inherited getters, you must filter sanitize the\n * type the `descriptors` parameter yourself e.g. `Omit<Class, keyof\n * SuperClass>`.\n * @param descriptorMap An object like the return value of Object.getOwnPropertyDescriptors\n * @template Class Any ClassLike type\n * @template T Any `object`-like type.\n * @template [__proto__=null] If {@link Class} is not {@link ClassLike}, the `__proto__` of {@link T}.\n * @returns An {@link OwnGetterDescriptorMap}.\n * @since 3.0.0\n */\nexport function filterForGetters<\n T extends object,\n __proto__ extends object | null = null,\n>(\n descriptorMap: PropertyDescriptorMap<T, __proto__> | PropertyDescriptorMap<T>,\n): Partial<OwnGetterDescriptorMap<T, __proto__>> {\n let getterDescriptorMap: Partial<OwnGetterDescriptorMap<T, __proto__>> = {};\n for (const key in descriptorMap) {\n const element = descriptorMap[key as keyof typeof descriptorMap];\n if (typeof element.get === 'function') {\n getterDescriptorMap = Object.assign(\n getterDescriptorMap,\n { [key]: element },\n );\n }\n }\n\n return getterDescriptorMap;\n}\n"],"mappings":";;;;;;;;;;;;;;AAwCA,SAAgB,iBAId,eAC+C;CAC/C,IAAI,sBAAqE,EAAE;AAC3E,MAAK,MAAM,OAAO,eAAe;EAC/B,MAAM,UAAU,cAAc;AAC9B,MAAI,OAAO,QAAQ,QAAQ,WACzB,uBAAsB,OAAO,OAC3B,qBACA,GAAG,MAAM,SAAS,CACnB;;AAIL,QAAO"}
@@ -1,2 +1,28 @@
1
- function e(e,t){switch(t){case`Instance`:return Object.getOwnPropertyDescriptors(e.prototype);case`Static`:return Object.getOwnPropertyDescriptors(e);default:throw TypeError('Argument `instanceOrStatic` must be "Instance" or "Static".')}}export{e as getOwnPropertyDescriptors};
1
+ //#region src/utils/reflection/getOwnPropertyDescriptors.ts
2
+ /**
3
+ * Get the property descriptors of the class or constructor similar to {@link Object.getOwnPropertyDescriptors}, but with more options--including recursion.
4
+ * @template {InstanceOrStatic} _InstanceOrStatic 'Instance' or 'Static'. Determines the return type.
5
+ * @param classDefinition A class or constructor, cast to {@link ClassLike}.
6
+ * @param instanceOrStatic 'Instance' or 'Static'. Determines the return type.
7
+ * @template {ClassLike<ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>>} Class
8
+ * The typeof {@link classDefinition}.
9
+ * {@link WithProto}<{@link SuperClassLike}> is necessary for walking the
10
+ * prototype chain for both Instance and Static properties.
11
+ * If unspecified, the return type may be incorrect.
12
+ * @returns ({@link instanceOrStatic} === 'Instance') ? {@link InstancePropertyDescriptorMap<Class>}\
13
+ * : ({@link instanceOrStatic} === 'Static') ? {@link OwnPropertyDescriptorMap<Class>}\
14
+ * : never
15
+ * @throws {TypeError}
16
+ * @since 3.0.0
17
+ */
18
+ function getOwnPropertyDescriptors(classDefinition, instanceOrStatic) {
19
+ switch (instanceOrStatic) {
20
+ case "Instance": return Object.getOwnPropertyDescriptors(classDefinition.prototype);
21
+ case "Static": return Object.getOwnPropertyDescriptors(classDefinition);
22
+ default: throw new TypeError("Argument `instanceOrStatic` must be \"Instance\" or \"Static\".");
23
+ }
24
+ }
25
+ //#endregion
26
+ export { getOwnPropertyDescriptors };
27
+
2
28
  //# sourceMappingURL=getOwnPropertyDescriptors.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"getOwnPropertyDescriptors.mjs","names":[],"sources":["../../../src/utils/reflection/getOwnPropertyDescriptors.ts"],"sourcesContent":["import type { InstanceOrStatic } from '../miscTypes.ts';\nimport type { BaseClassProto, ClassLike, ConstructorConstraint, SuperClassLike, WithProto } from './inheritance.ts';\nimport type { InstancePropertyDescriptorMap } from './InstancePropertyDescriptorMap.d.ts';\nimport type { OwnPropertyDescriptorMap } from './OwnPropertyDescriptorMap.d.ts';\n\n/**\n * Get the property descriptors of the class or constructor similar to {@link Object.getOwnPropertyDescriptors}, but with more options--including recursion.\n * @template {InstanceOrStatic} _InstanceOrStatic 'Instance' or 'Static'. Determines the return type.\n * @param classDefinition A class or constructor, cast to {@link ClassLike}.\n * @param instanceOrStatic 'Instance' or 'Static'. Determines the return type.\n * @template {ClassLike<ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>>} Class\n * The typeof {@link classDefinition}.\n * {@link WithProto}<{@link SuperClassLike}> is necessary for walking the\n * prototype chain for both Instance and Static properties.\n * If unspecified, the return type may be incorrect.\n * @returns ({@link instanceOrStatic} === 'Instance') ? {@link InstancePropertyDescriptorMap<Class>}\\\n * : ({@link instanceOrStatic} === 'Static') ? {@link OwnPropertyDescriptorMap<Class>}\\\n * : never\n * @throws {TypeError}\n * @since 3.0.0\n */\nexport function getOwnPropertyDescriptors<\n Class extends ClassLike<ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>>,\n _InstanceOrStatic extends InstanceOrStatic,\n>(\n classDefinition: Class,\n instanceOrStatic: _InstanceOrStatic,\n): [_InstanceOrStatic] extends ['Instance']\n ? InstancePropertyDescriptorMap<Class>\n : [_InstanceOrStatic] extends ['Static']\n ? OwnPropertyDescriptorMap<Class>\n : never {\n switch (instanceOrStatic) {\n case 'Instance': {\n return Object.getOwnPropertyDescriptors(classDefinition.prototype) as [Extract<typeof instanceOrStatic, 'Instance'>] extends ['Instance']\n ? InstancePropertyDescriptorMap<Class>\n : [_InstanceOrStatic] extends ['Static']\n ? OwnPropertyDescriptorMap<Class>\n : never;\n }\n case 'Static': {\n return Object.getOwnPropertyDescriptors(classDefinition) as [Extract<typeof instanceOrStatic, 'Static'>] extends ['Instance']\n ? InstancePropertyDescriptorMap<Class>\n : [_InstanceOrStatic] extends ['Static']\n ? OwnPropertyDescriptorMap<Class>\n : never;\n }\n default: {\n throw new TypeError('Argument `instanceOrStatic` must be \"Instance\" or \"Static\".');\n }\n }\n}\n"],"mappings":"AAqBA,SAAgB,EAId,EACA,EAKY,CACZ,OAAQ,EAAR,CACE,IAAK,WACH,OAAO,OAAO,0BAA0B,EAAgB,UAAU,CAMpE,IAAK,SACH,OAAO,OAAO,0BAA0B,EAAgB,CAM1D,QACE,MAAU,UAAU,8DAA8D"}
1
+ {"version":3,"file":"getOwnPropertyDescriptors.mjs","names":[],"sources":["../../../src/utils/reflection/getOwnPropertyDescriptors.ts"],"sourcesContent":["import type { InstanceOrStatic } from '../miscTypes.ts';\nimport type { BaseClassProto, ClassLike, ConstructorConstraint, SuperClassLike, WithProto } from './inheritance.ts';\nimport type { InstancePropertyDescriptorMap } from './InstancePropertyDescriptorMap.d.ts';\nimport type { OwnPropertyDescriptorMap } from './OwnPropertyDescriptorMap.d.ts';\n\n/**\n * Get the property descriptors of the class or constructor similar to {@link Object.getOwnPropertyDescriptors}, but with more options--including recursion.\n * @template {InstanceOrStatic} _InstanceOrStatic 'Instance' or 'Static'. Determines the return type.\n * @param classDefinition A class or constructor, cast to {@link ClassLike}.\n * @param instanceOrStatic 'Instance' or 'Static'. Determines the return type.\n * @template {ClassLike<ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>>} Class\n * The typeof {@link classDefinition}.\n * {@link WithProto}<{@link SuperClassLike}> is necessary for walking the\n * prototype chain for both Instance and Static properties.\n * If unspecified, the return type may be incorrect.\n * @returns ({@link instanceOrStatic} === 'Instance') ? {@link InstancePropertyDescriptorMap<Class>}\\\n * : ({@link instanceOrStatic} === 'Static') ? {@link OwnPropertyDescriptorMap<Class>}\\\n * : never\n * @throws {TypeError}\n * @since 3.0.0\n */\nexport function getOwnPropertyDescriptors<\n Class extends ClassLike<ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>>,\n _InstanceOrStatic extends InstanceOrStatic,\n>(\n classDefinition: Class,\n instanceOrStatic: _InstanceOrStatic,\n): [_InstanceOrStatic] extends ['Instance']\n ? InstancePropertyDescriptorMap<Class>\n : [_InstanceOrStatic] extends ['Static']\n ? OwnPropertyDescriptorMap<Class>\n : never {\n switch (instanceOrStatic) {\n case 'Instance': {\n return Object.getOwnPropertyDescriptors(classDefinition.prototype) as [Extract<typeof instanceOrStatic, 'Instance'>] extends ['Instance']\n ? InstancePropertyDescriptorMap<Class>\n : [_InstanceOrStatic] extends ['Static']\n ? OwnPropertyDescriptorMap<Class>\n : never;\n }\n case 'Static': {\n return Object.getOwnPropertyDescriptors(classDefinition) as [Extract<typeof instanceOrStatic, 'Static'>] extends ['Instance']\n ? InstancePropertyDescriptorMap<Class>\n : [_InstanceOrStatic] extends ['Static']\n ? OwnPropertyDescriptorMap<Class>\n : never;\n }\n default: {\n throw new TypeError('Argument `instanceOrStatic` must be \"Instance\" or \"Static\".');\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAqBA,SAAgB,0BAId,iBACA,kBAKY;AACZ,SAAQ,kBAAR;EACE,KAAK,WACH,QAAO,OAAO,0BAA0B,gBAAgB,UAAU;EAMpE,KAAK,SACH,QAAO,OAAO,0BAA0B,gBAAgB;EAM1D,QACE,OAAM,IAAI,UAAU,kEAA8D"}
@@ -1,2 +1,35 @@
1
- import{getOwnPropertyDescriptors as e}from"./getOwnPropertyDescriptors.mjs";import{getPrototypesChainOf as t}from"./getPrototypeChainOf.mjs";function n(n,i){let a=t(n,`classes`);return r(a)?[e(a[0],i)]:a.map(t=>e(t,i))}function r(e){return Array.isArray(e)&&e.length===1}export{n as getOwnPropertyDescriptorsRecursively};
1
+ import { getOwnPropertyDescriptors } from "./getOwnPropertyDescriptors.mjs";
2
+ import { getPrototypesChainOf } from "./getPrototypeChainOf.mjs";
3
+ //#region src/utils/reflection/getOwnPropertyDescriptorsRecursively.ts
4
+ /**
5
+ * Walks the class inheritance chain to get a PropertyDescriptorMap of each class.
6
+ *
7
+ * While you _can_ use this to get an array of getter names/keys, you should use {@link getPrototypeOf} and {@link listOwnGetters}, instead!
8
+ * @template Class Any class definition type-cast to {@link ClassLike}
9
+ * @template _InstanceOrStatic
10
+ * @param classDefinition Any class definition type-cast to {@link ClassLike}
11
+ * @param instanceOrStatic 'Instance' or 'Static'. Determines the return type.
12
+ * @returns An
13
+ * ordered array of {@link OwnPropertyDescriptorMap} or
14
+ * {@link InstancePropertyDescriptorMap} starting with {@link classDefinition}
15
+ * and ending with a {@link BaseClass}.
16
+ * @since 3.0.0
17
+ */
18
+ function getOwnPropertyDescriptorsRecursively(classDefinition, instanceOrStatic) {
19
+ const staticProtoChain = getPrototypesChainOf(classDefinition, "classes");
20
+ if (isSingleTuple(staticProtoChain)) return [getOwnPropertyDescriptors(staticProtoChain[0], instanceOrStatic)];
21
+ return staticProtoChain.map((classDefinition) => getOwnPropertyDescriptors(classDefinition, instanceOrStatic));
22
+ }
23
+ /**
24
+ * Simple utility for single-tuple type assertion
25
+ * @template {T} T T in T[]
26
+ * @param array an array
27
+ * @returns array is [T]
28
+ */
29
+ function isSingleTuple(array) {
30
+ return Array.isArray(array) && array.length === 1;
31
+ }
32
+ //#endregion
33
+ export { getOwnPropertyDescriptorsRecursively };
34
+
2
35
  //# sourceMappingURL=getOwnPropertyDescriptorsRecursively.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"getOwnPropertyDescriptorsRecursively.mjs","names":[],"sources":["../../../src/utils/reflection/getOwnPropertyDescriptorsRecursively.ts"],"sourcesContent":["import type { Increment } from '../GracefulRecursion.d.ts';\nimport type { InstanceOrStatic, Integer } from '../miscTypes.ts';\nimport { getOwnPropertyDescriptors } from './getOwnPropertyDescriptors.ts';\nimport { getPrototypesChainOf } from './getPrototypeChainOf.ts';\nimport type {\n BaseClass,\n BaseClassProto,\n ClassLike,\n ConstructorConstraint,\n ConstructorLike,\n ProtoChainOfClass,\n SuperClassLike,\n WithProto,\n} from './inheritance.ts';\nimport type { InstanceTypeOrSelfPropertyDescriptorMap } from './InstanceTypeOrSelfPropertyDescriptorMap.d.ts';\nimport type { OwnPropertyDescriptorMap } from './OwnPropertyDescriptorMap.d.ts';\n/**\n * JSDoc type imports\n */\n/* eslint-disable @typescript-eslint/no-unused-vars */\nimport type { getPrototypeOf as _getPrototypeOf } from './getPrototypeOf.ts';\nimport type { listOwnGetters as _listOwnGetters } from './listOwnGetters.ts';\nimport type { InstancePropertyDescriptorMap as _InstancePropertyDescriptorMap } from './InstancePropertyDescriptorMap.d.ts';\n/* eslint-enable @typescript-eslint/no-unused-vars */\n\n/**\n * A conditional wrapper for {@link InstanceTypeOrSelfPropertyDescriptorMap} and\n * {@link OwnPropertyDescriptorMap}.\n *\n * If {@link _InstanceOrStatic} is 'Instance', {@link InstanceTypeOrSelfPropertyDescriptorMap}.\\\n * Else if {@link _InstanceOrStatic} is 'Static',\n * {@link OwnPropertyDescriptorMap }.\\\n * Else, `never`.\n * @template {ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>} Class\n * A class definition cast to {@link ClassLike}.\n * @template {InstanceOrStatic} _InstanceOrStatic\n * 'Instance' or 'Static'. Determines the return type.\n * @since 3.0.0\n */\nexport type RecursedPropertyDescriptorMap<\n Class extends ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>,\n _InstanceOrStatic extends InstanceOrStatic,\n> = [_InstanceOrStatic] extends ['Instance'] ? InstanceTypeOrSelfPropertyDescriptorMap<Class, Class['__proto__']>\n : [_InstanceOrStatic] extends ['Static'] ? OwnPropertyDescriptorMap<Class>\n : never;\n\n/**\n * An\n * ordered array of {@link OwnPropertyDescriptorMap} or\n * {@link InstancePropertyDescriptorMap} starting with {@link classDefinition}\n * and ending with a {@link BaseClass}.\n * @template {ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>} Class\n * @template {'Instance' | 'Static'} InstanceOrStatic\n * @template {Integer<number>} [Limit=16]\n * @template {Integer<number>} [CurrentLevel=0]\n */\nexport type RecursedPropertyDescriptorMapArray<\n Class extends ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>,\n InstanceOrStatic extends 'Instance' | 'Static',\n Limit extends Integer<number> = 16,\n CurrentLevel extends Integer<number> = 0,\n> = Class['__proto__'] extends BaseClassProto['__proto__'] | BaseClassProto['__proto__']['__proto__'] ? never\n : Class['__proto__'] extends BaseClassProto ? [RecursedPropertyDescriptorMap<BaseClass<Class>, InstanceOrStatic>]\n : Class['__proto__'] extends ConstructorLike<Class['__proto__']>\n ? [\n RecursedPropertyDescriptorMap<Class, InstanceOrStatic>,\n ...RecursedPropertyDescriptorMapArray<\n ClassLike<Exclude<Class['__proto__'], BaseClassProto> & WithProto<SuperClassLike | BaseClassProto>>,\n InstanceOrStatic,\n Limit,\n Increment<CurrentLevel>\n >,\n ]\n : never;\n/**\n * Walks the class inheritance chain to get a PropertyDescriptorMap of each class.\n *\n * While you _can_ use this to get an array of getter names/keys, you should use {@link getPrototypeOf} and {@link listOwnGetters}, instead!\n * @template Class Any class definition type-cast to {@link ClassLike}\n * @template _InstanceOrStatic\n * @param classDefinition Any class definition type-cast to {@link ClassLike}\n * @param instanceOrStatic 'Instance' or 'Static'. Determines the return type.\n * @returns An\n * ordered array of {@link OwnPropertyDescriptorMap} or\n * {@link InstancePropertyDescriptorMap} starting with {@link classDefinition}\n * and ending with a {@link BaseClass}.\n * @since 3.0.0\n */\nexport function getOwnPropertyDescriptorsRecursively<\n // Class extends ClassLike<ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>>,\n Class extends ClassLike<ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>>,\n _InstanceOrStatic extends InstanceOrStatic,\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters\n Limit extends Integer<number> = 16,\n>(\n classDefinition: Class,\n instanceOrStatic: _InstanceOrStatic,\n): RecursedPropertyDescriptorMapArray<Class, _InstanceOrStatic> {\n const staticProtoChain: ProtoChainOfClass<Class> = getPrototypesChainOf(classDefinition, 'classes');\n if (isSingleTuple(staticProtoChain)) {\n return [\n getOwnPropertyDescriptors(\n staticProtoChain[0],\n instanceOrStatic,\n ) as RecursedPropertyDescriptorMap<Class, _InstanceOrStatic>,\n ] as unknown as RecursedPropertyDescriptorMapArray<Class, _InstanceOrStatic, Limit>;\n }\n\n const recursedPropertyDescriptorMapArray = staticProtoChain.map(classDefinition =>\n getOwnPropertyDescriptors(\n classDefinition,\n instanceOrStatic,\n ),\n );\n\n return recursedPropertyDescriptorMapArray as RecursedPropertyDescriptorMapArray<Class, _InstanceOrStatic>;\n}\n\n/**\n * Simple utility for single-tuple type assertion\n * @template {T} T T in T[]\n * @param array an array\n * @returns array is [T]\n */\nfunction isSingleTuple<T>(array: T[]): array is [T] {\n return Array.isArray(array) && array.length === 1;\n}\n"],"mappings":"6IAwFA,SAAgB,EAOd,EACA,EAC8D,CAC9D,IAAM,EAA6C,EAAqB,EAAiB,UAAU,CAiBnG,OAhBI,EAAc,EAAiB,CAC1B,CACL,EACE,EAAiB,GACjB,EACD,CACF,CAGwC,EAAiB,IAAI,GAC9D,EACE,EACA,EACD,CACF,CAWH,SAAS,EAAiB,EAA0B,CAClD,OAAO,MAAM,QAAQ,EAAM,EAAI,EAAM,SAAW"}
1
+ {"version":3,"file":"getOwnPropertyDescriptorsRecursively.mjs","names":[],"sources":["../../../src/utils/reflection/getOwnPropertyDescriptorsRecursively.ts"],"sourcesContent":["import type { Increment } from '../GracefulRecursion.d.ts';\nimport type { InstanceOrStatic, Integer } from '../miscTypes.ts';\nimport { getOwnPropertyDescriptors } from './getOwnPropertyDescriptors.ts';\nimport { getPrototypesChainOf } from './getPrototypeChainOf.ts';\nimport type {\n BaseClass,\n BaseClassProto,\n ClassLike,\n ConstructorConstraint,\n ConstructorLike,\n ProtoChainOfClass,\n SuperClassLike,\n WithProto,\n} from './inheritance.ts';\nimport type { InstanceTypeOrSelfPropertyDescriptorMap } from './InstanceTypeOrSelfPropertyDescriptorMap.d.ts';\nimport type { OwnPropertyDescriptorMap } from './OwnPropertyDescriptorMap.d.ts';\n/**\n * JSDoc type imports\n */\n/* eslint-disable @typescript-eslint/no-unused-vars */\nimport type { getPrototypeOf as _getPrototypeOf } from './getPrototypeOf.ts';\nimport type { listOwnGetters as _listOwnGetters } from './listOwnGetters.ts';\nimport type { InstancePropertyDescriptorMap as _InstancePropertyDescriptorMap } from './InstancePropertyDescriptorMap.d.ts';\n/* eslint-enable @typescript-eslint/no-unused-vars */\n\n/**\n * A conditional wrapper for {@link InstanceTypeOrSelfPropertyDescriptorMap} and\n * {@link OwnPropertyDescriptorMap}.\n *\n * If {@link _InstanceOrStatic} is 'Instance', {@link InstanceTypeOrSelfPropertyDescriptorMap}.\\\n * Else if {@link _InstanceOrStatic} is 'Static',\n * {@link OwnPropertyDescriptorMap }.\\\n * Else, `never`.\n * @template {ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>} Class\n * A class definition cast to {@link ClassLike}.\n * @template {InstanceOrStatic} _InstanceOrStatic\n * 'Instance' or 'Static'. Determines the return type.\n * @since 3.0.0\n */\nexport type RecursedPropertyDescriptorMap<\n Class extends ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>,\n _InstanceOrStatic extends InstanceOrStatic,\n> = [_InstanceOrStatic] extends ['Instance'] ? InstanceTypeOrSelfPropertyDescriptorMap<Class, Class['__proto__']>\n : [_InstanceOrStatic] extends ['Static'] ? OwnPropertyDescriptorMap<Class>\n : never;\n\n/**\n * An\n * ordered array of {@link OwnPropertyDescriptorMap} or\n * {@link InstancePropertyDescriptorMap} starting with {@link classDefinition}\n * and ending with a {@link BaseClass}.\n * @template {ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>} Class\n * @template {'Instance' | 'Static'} InstanceOrStatic\n * @template {Integer<number>} [Limit=16]\n * @template {Integer<number>} [CurrentLevel=0]\n */\nexport type RecursedPropertyDescriptorMapArray<\n Class extends ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>,\n InstanceOrStatic extends 'Instance' | 'Static',\n Limit extends Integer<number> = 16,\n CurrentLevel extends Integer<number> = 0,\n> = Class['__proto__'] extends BaseClassProto['__proto__'] | BaseClassProto['__proto__']['__proto__'] ? never\n : Class['__proto__'] extends BaseClassProto ? [RecursedPropertyDescriptorMap<BaseClass<Class>, InstanceOrStatic>]\n : Class['__proto__'] extends ConstructorLike<Class['__proto__']>\n ? [\n RecursedPropertyDescriptorMap<Class, InstanceOrStatic>,\n ...RecursedPropertyDescriptorMapArray<\n ClassLike<Exclude<Class['__proto__'], BaseClassProto> & WithProto<SuperClassLike | BaseClassProto>>,\n InstanceOrStatic,\n Limit,\n Increment<CurrentLevel>\n >,\n ]\n : never;\n/**\n * Walks the class inheritance chain to get a PropertyDescriptorMap of each class.\n *\n * While you _can_ use this to get an array of getter names/keys, you should use {@link getPrototypeOf} and {@link listOwnGetters}, instead!\n * @template Class Any class definition type-cast to {@link ClassLike}\n * @template _InstanceOrStatic\n * @param classDefinition Any class definition type-cast to {@link ClassLike}\n * @param instanceOrStatic 'Instance' or 'Static'. Determines the return type.\n * @returns An\n * ordered array of {@link OwnPropertyDescriptorMap} or\n * {@link InstancePropertyDescriptorMap} starting with {@link classDefinition}\n * and ending with a {@link BaseClass}.\n * @since 3.0.0\n */\nexport function getOwnPropertyDescriptorsRecursively<\n // Class extends ClassLike<ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>>,\n Class extends ClassLike<ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>>,\n _InstanceOrStatic extends InstanceOrStatic,\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters\n Limit extends Integer<number> = 16,\n>(\n classDefinition: Class,\n instanceOrStatic: _InstanceOrStatic,\n): RecursedPropertyDescriptorMapArray<Class, _InstanceOrStatic> {\n const staticProtoChain: ProtoChainOfClass<Class> = getPrototypesChainOf(classDefinition, 'classes');\n if (isSingleTuple(staticProtoChain)) {\n return [\n getOwnPropertyDescriptors(\n staticProtoChain[0],\n instanceOrStatic,\n ) as RecursedPropertyDescriptorMap<Class, _InstanceOrStatic>,\n ] as unknown as RecursedPropertyDescriptorMapArray<Class, _InstanceOrStatic, Limit>;\n }\n\n const recursedPropertyDescriptorMapArray = staticProtoChain.map(classDefinition =>\n getOwnPropertyDescriptors(\n classDefinition,\n instanceOrStatic,\n ),\n );\n\n return recursedPropertyDescriptorMapArray as RecursedPropertyDescriptorMapArray<Class, _InstanceOrStatic>;\n}\n\n/**\n * Simple utility for single-tuple type assertion\n * @template {T} T T in T[]\n * @param array an array\n * @returns array is [T]\n */\nfunction isSingleTuple<T>(array: T[]): array is [T] {\n return Array.isArray(array) && array.length === 1;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAwFA,SAAgB,qCAOd,iBACA,kBAC8D;CAC9D,MAAM,mBAA6C,qBAAqB,iBAAiB,UAAU;AACnG,KAAI,cAAc,iBAAiB,CACjC,QAAO,CACL,0BACE,iBAAiB,IACjB,iBACD,CACF;AAUH,QAP2C,iBAAiB,KAAI,oBAC9D,0BACE,iBACA,iBACD,CACF;;;;;;;;AAWH,SAAS,cAAiB,OAA0B;AAClD,QAAO,MAAM,QAAQ,MAAM,IAAI,MAAM,WAAW"}
@@ -1,2 +1,40 @@
1
- import{getPrototypeOf as e}from"./getPrototypeOf.mjs";import{baseClassProto as t}from"./inheritance.mjs";import{isConstructor as n}from"./isConstructor.mjs";function r(r,i){let a=r,o,s=[],c=0;for(;t!==a&&(o=e(a),n(a))&&(i===`classInstances`?s[c]=a.prototype:s[c]=a,n(o)&&`name`in o&&typeof o.name==`string`&&o.name!==``);)a=o,c++;return s}export{r as getPrototypesChainOf};
1
+ import { getPrototypeOf } from "./getPrototypeOf.mjs";
2
+ import { baseClassProto } from "./inheritance.mjs";
3
+ import { isConstructor } from "./isConstructor.mjs";
4
+ //#region src/utils/reflection/getPrototypeChainOf.ts
5
+ /**
6
+ * Iterate through the class and its base/super classes until an anonymous function is reached. This is the default superclass all classes extend.
7
+ * @template Class Any {@link ClassLike} type.
8
+ * @template ClassesOrInstances 'classes' or 'classInstances'
9
+ * @param classDefinition Any class type satisfying {@link Class}. This class (or its instance type) is included in the return value.
10
+ * @param [returnType='classes'] Determines return type. If 'classInstances', the return type is an array of the classes' `.prototype`. Else, the classes themselves are returned.
11
+ * @since 3.0.0
12
+ * @returns
13
+ * `returnType extends 'classInstances' ? ClassLike<T>[] : ClassLike<T>[].map(c => c.prototype)`
14
+ * Excludes default superclasses e.g. anonymous functions, native code.
15
+ */
16
+ function getPrototypesChainOf(classDefinition, returnType) {
17
+ let current = classDefinition;
18
+ let parent;
19
+ const returnValue = [];
20
+ let index = 0;
21
+ while (baseClassProto !== current) {
22
+ parent = getPrototypeOf(current);
23
+ if (!isConstructor(current)) break;
24
+ if (returnType === "classInstances") returnValue[index] = current.prototype;
25
+ else returnValue[index] = current;
26
+ /**
27
+ * Assign the super class to current.
28
+ * If the argument is a class, Reflect.getPrototypeOf method returns the
29
+ * superclass.
30
+ */
31
+ if (isConstructor(parent) && "name" in parent && typeof parent.name === "string" && "" !== parent.name) current = parent;
32
+ else break;
33
+ index++;
34
+ }
35
+ return returnValue;
36
+ }
37
+ //#endregion
38
+ export { getPrototypesChainOf };
39
+
2
40
  //# sourceMappingURL=getPrototypeChainOf.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"getPrototypeChainOf.mjs","names":[],"sources":["../../../src/utils/reflection/getPrototypeChainOf.ts"],"sourcesContent":["/* eslint-disable jsdoc/no-defaults */\nimport type { TupleIndices } from '../miscTypes.ts';\nimport { getPrototypeOf } from './getPrototypeOf.ts';\nimport {\n baseClassProto,\n type BaseClassProto,\n type ClassLike,\n type ConstructorConstraint,\n type ProtoChainOfClass,\n type ProtoChainOfClassInstance,\n type SuperClassLike,\n type WithProto,\n} from './inheritance.ts';\nimport { isConstructor } from './isConstructor.ts';\n\ntype ProtoChain<\n Class extends ClassLike<ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>>,\n ClassesOrInstances extends 'classes' | 'classInstances',\n> = [ClassesOrInstances] extends ['classInstances'] ? ProtoChainOfClassInstance<Class>\n : [ClassesOrInstances] extends ['classes'] ? ProtoChainOfClass<Class>\n : never;\n\n/**\n * Iterate through the class and its base/super classes until an anonymous function is reached. This is the default superclass all classes extend.\n * @template Class Any {@link ClassLike} type.\n * @template ClassesOrInstances 'classes' or 'classInstances'\n * @param classDefinition Any class type satisfying {@link Class}. This class (or its instance type) is included in the return value.\n * @param [returnType='classes'] Determines return type. If 'classInstances', the return type is an array of the classes' `.prototype`. Else, the classes themselves are returned.\n * @since 3.0.0\n * @returns\n * `returnType extends 'classInstances' ? ClassLike<T>[] : ClassLike<T>[].map(c => c.prototype)`\n * Excludes default superclasses e.g. anonymous functions, native code.\n */\nexport function getPrototypesChainOf<\n Class extends ClassLike<ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>>,\n ClassesOrInstances extends 'classes' | 'classInstances',\n>(\n classDefinition: Class,\n returnType: ClassesOrInstances,\n): ProtoChain<Class, ClassesOrInstances> {\n // class definitions or their respective .prototype; exclude default superclasses.\n let current: ProtoChainOfClass<Class>[TupleIndices<ProtoChainOfClass<Class>>] = classDefinition as ProtoChainOfClass<Class>[0 extends TupleIndices<ProtoChainOfClass<Class>> ? 0 : never];\n let parent: typeof current & WithProto<SuperClassLike | BaseClassProto> | object;\n const returnValue = [] as unknown as\n ProtoChain<Class, ClassesOrInstances>;\n let index: TupleIndices<typeof returnValue> = 0 as TupleIndices<typeof returnValue>;\n\n while (baseClassProto !== current) {\n parent = getPrototypeOf(current);\n // current is a Class symbol/constructor. Object.getOwnPropertyDescriptors on current will include static properties.\n if (!isConstructor(current))\n break;\n if (returnType === 'classInstances') {\n const instanceOfCurrent = current.prototype as InstanceType<typeof current>;\n\n returnValue[index] = instanceOfCurrent as typeof returnValue[typeof index];\n }\n else {\n returnValue[index] = current as typeof returnValue[typeof index];\n }\n\n /**\n * Assign the super class to current.\n * If the argument is a class, Reflect.getPrototypeOf method returns the\n * superclass.\n */\n if (\n isConstructor(parent)\n && 'name' in parent\n && typeof parent.name === 'string'\n && '' !== parent.name // it's possible for a Function/Constructor to be anonymous...\n ) {\n current = parent as ProtoChainOfClass<Class>[TupleIndices<ProtoChainOfClass<Class>>];\n }\n else {\n break;\n }\n index++;\n }\n return returnValue;\n /*\n assuming current is NugetProjectProperties...\n Reflect.getPrototypeOf(current).name is 'MSBuildProjectProperties'\n */\n}\n"],"mappings":"6JAiCA,SAAgB,EAId,EACA,EACuC,CAEvC,IAAI,EAA4E,EAC5E,EACE,EAAc,EAAE,CAElB,EAA0C,EAE9C,KAAO,IAAmB,IACxB,EAAS,EAAe,EAAQ,CAE3B,EAAc,EAAQ,IAEvB,IAAe,iBAGjB,EAAY,GAFc,EAAQ,UAKlC,EAAY,GAAS,EASrB,EAAc,EAAO,EAClB,SAAU,GACV,OAAO,EAAO,MAAS,UAChB,EAAO,OAAd,KAEH,EAAU,EAKZ,IAEF,OAAO"}
1
+ {"version":3,"file":"getPrototypeChainOf.mjs","names":[],"sources":["../../../src/utils/reflection/getPrototypeChainOf.ts"],"sourcesContent":["/* eslint-disable jsdoc/no-defaults */\nimport type { TupleIndices } from '../miscTypes.ts';\nimport { getPrototypeOf } from './getPrototypeOf.ts';\nimport {\n baseClassProto,\n type BaseClassProto,\n type ClassLike,\n type ConstructorConstraint,\n type ProtoChainOfClass,\n type ProtoChainOfClassInstance,\n type SuperClassLike,\n type WithProto,\n} from './inheritance.ts';\nimport { isConstructor } from './isConstructor.ts';\n\ntype ProtoChain<\n Class extends ClassLike<ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>>,\n ClassesOrInstances extends 'classes' | 'classInstances',\n> = [ClassesOrInstances] extends ['classInstances'] ? ProtoChainOfClassInstance<Class>\n : [ClassesOrInstances] extends ['classes'] ? ProtoChainOfClass<Class>\n : never;\n\n/**\n * Iterate through the class and its base/super classes until an anonymous function is reached. This is the default superclass all classes extend.\n * @template Class Any {@link ClassLike} type.\n * @template ClassesOrInstances 'classes' or 'classInstances'\n * @param classDefinition Any class type satisfying {@link Class}. This class (or its instance type) is included in the return value.\n * @param [returnType='classes'] Determines return type. If 'classInstances', the return type is an array of the classes' `.prototype`. Else, the classes themselves are returned.\n * @since 3.0.0\n * @returns\n * `returnType extends 'classInstances' ? ClassLike<T>[] : ClassLike<T>[].map(c => c.prototype)`\n * Excludes default superclasses e.g. anonymous functions, native code.\n */\nexport function getPrototypesChainOf<\n Class extends ClassLike<ConstructorConstraint<Class> & WithProto<SuperClassLike | BaseClassProto>>,\n ClassesOrInstances extends 'classes' | 'classInstances',\n>(\n classDefinition: Class,\n returnType: ClassesOrInstances,\n): ProtoChain<Class, ClassesOrInstances> {\n // class definitions or their respective .prototype; exclude default superclasses.\n let current: ProtoChainOfClass<Class>[TupleIndices<ProtoChainOfClass<Class>>] = classDefinition as ProtoChainOfClass<Class>[0 extends TupleIndices<ProtoChainOfClass<Class>> ? 0 : never];\n let parent: typeof current & WithProto<SuperClassLike | BaseClassProto> | object;\n const returnValue = [] as unknown as\n ProtoChain<Class, ClassesOrInstances>;\n let index: TupleIndices<typeof returnValue> = 0 as TupleIndices<typeof returnValue>;\n\n while (baseClassProto !== current) {\n parent = getPrototypeOf(current);\n // current is a Class symbol/constructor. Object.getOwnPropertyDescriptors on current will include static properties.\n if (!isConstructor(current))\n break;\n if (returnType === 'classInstances') {\n const instanceOfCurrent = current.prototype as InstanceType<typeof current>;\n\n returnValue[index] = instanceOfCurrent as typeof returnValue[typeof index];\n }\n else {\n returnValue[index] = current as typeof returnValue[typeof index];\n }\n\n /**\n * Assign the super class to current.\n * If the argument is a class, Reflect.getPrototypeOf method returns the\n * superclass.\n */\n if (\n isConstructor(parent)\n && 'name' in parent\n && typeof parent.name === 'string'\n && '' !== parent.name // it's possible for a Function/Constructor to be anonymous...\n ) {\n current = parent as ProtoChainOfClass<Class>[TupleIndices<ProtoChainOfClass<Class>>];\n }\n else {\n break;\n }\n index++;\n }\n return returnValue;\n /*\n assuming current is NugetProjectProperties...\n Reflect.getPrototypeOf(current).name is 'MSBuildProjectProperties'\n */\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiCA,SAAgB,qBAId,iBACA,YACuC;CAEvC,IAAI,UAA4E;CAChF,IAAI;CACJ,MAAM,cAAc,EAAE;CAEtB,IAAI,QAA0C;AAE9C,QAAO,mBAAmB,SAAS;AACjC,WAAS,eAAe,QAAQ;AAEhC,MAAI,CAAC,cAAc,QAAQ,CACzB;AACF,MAAI,eAAe,iBAGjB,aAAY,SAFc,QAAQ;MAKlC,aAAY,SAAS;;;;;;AAQvB,MACE,cAAc,OAAO,IAClB,UAAU,UACV,OAAO,OAAO,SAAS,YACvB,OAAO,OAAO,KAEjB,WAAU;MAGV;AAEF;;AAEF,QAAO"}
@@ -1,2 +1,13 @@
1
- function e(e){return Reflect.getPrototypeOf(e)}export{e as getPrototypeOf};
1
+ //#region src/utils/reflection/getPrototypeOf.ts
2
+ /**
3
+ * A nearly useless wrapper for {@link Reflect.getPrototypeOf}
4
+ * @param object An object with the internal `__proto__` property present in its type.
5
+ * @returns The `__proto__` of the `object` param.
6
+ */
7
+ function getPrototypeOf(object) {
8
+ return Reflect.getPrototypeOf(object);
9
+ }
10
+ //#endregion
11
+ export { getPrototypeOf };
12
+
2
13
  //# sourceMappingURL=getPrototypeOf.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"getPrototypeOf.mjs","names":[],"sources":["../../../src/utils/reflection/getPrototypeOf.ts"],"sourcesContent":["import type { ProtoOrSuperClass, WithProto } from './inheritance.ts';\n\n/**\n * A nearly useless wrapper for {@link Reflect.getPrototypeOf}\n * @param object An object with the internal `__proto__` property present in its type.\n * @returns The `__proto__` of the `object` param.\n */\nexport function getPrototypeOf<\n T extends WithProto<ProtoOrSuperClass>,\n>(object: T): T['__proto__'] {\n return Reflect.getPrototypeOf(object) as T['__proto__'];\n}\n"],"mappings":"AAOA,SAAgB,EAEd,EAA2B,CAC3B,OAAO,QAAQ,eAAe,EAAO"}
1
+ {"version":3,"file":"getPrototypeOf.mjs","names":[],"sources":["../../../src/utils/reflection/getPrototypeOf.ts"],"sourcesContent":["import type { ProtoOrSuperClass, WithProto } from './inheritance.ts';\n\n/**\n * A nearly useless wrapper for {@link Reflect.getPrototypeOf}\n * @param object An object with the internal `__proto__` property present in its type.\n * @returns The `__proto__` of the `object` param.\n */\nexport function getPrototypeOf<\n T extends WithProto<ProtoOrSuperClass>,\n>(object: T): T['__proto__'] {\n return Reflect.getPrototypeOf(object) as T['__proto__'];\n}\n"],"mappings":";;;;;;AAOA,SAAgB,eAEd,QAA2B;AAC3B,QAAO,QAAQ,eAAe,OAAO"}
@@ -1,2 +1,11 @@
1
- import{getPrototypeOf as e}from"./getPrototypeOf.mjs";const t=e(Object);export{t as baseClassProto};
1
+ import { getPrototypeOf } from "./getPrototypeOf.mjs";
2
+ //#region src/utils/reflection/inheritance.ts
3
+ /**
4
+ * The `[[Prototype]]` of all base classes.
5
+ * @since 3.0.0
6
+ */
7
+ const baseClassProto = getPrototypeOf(Object);
8
+ //#endregion
9
+ export { baseClassProto };
10
+
2
11
  //# sourceMappingURL=inheritance.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"inheritance.mjs","names":[],"sources":["../../../src/utils/reflection/inheritance.ts"],"sourcesContent":["import 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 (...args: 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 (...args: 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<__proto__ extends ProtoOrSuperClass> {\n ['__proto__']: __proto__;\n}\n"],"mappings":"sDAyBA,MAAa,EAAiC,EAAe,OAAuC"}
1
+ {"version":3,"file":"inheritance.mjs","names":[],"sources":["../../../src/utils/reflection/inheritance.ts"],"sourcesContent":["import 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 (...args: 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 (...args: 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<__proto__ extends ProtoOrSuperClass> {\n ['__proto__']: __proto__;\n}\n"],"mappings":";;;;;;AAyBA,MAAa,iBAAiC,eAAe,OAAuC"}
@@ -1,2 +1,31 @@
1
- function e(e){if(typeof e!=`function`)return!1;if(/^class\s/.test(e.toString()))return!0;let t=e.prototype;if((typeof t==`object`||typeof t==`function`)&&t!==null&&`constructor`in t&&typeof t.constructor==`function`){let n=t.constructor,r=Reflect.getOwnPropertyDescriptor(n,`name`);return n===e&&r?.writable===!1&&r.enumerable===!1&&r.configurable===!0}return!1}export{e as isConstructor};
1
+ //#region src/utils/reflection/isConstructor.ts
2
+ /**
3
+ * A very jank function to determine if an object can be the target of Reflect.construct.
4
+ * Unfortunately, many functions have a constructor in their prototype. These
5
+ * functions are treated like classes due to JavaScript's poor distinction between
6
+ * classes and functions.\
7
+ * Typescript can enforce "new" keyword usage, but overriding the type
8
+ * allows you to `new isConstructor()` despite this function not intended to be
9
+ * used with the `new` keyword.
10
+ * #### NOTE: Only works when targeting ES6/ES2015 or later.
11
+ * > If your project or a dependent project is compiled to < ES6, this function will always return `false`; classes and constructors were introduced in ES6/ES2015.
12
+ * @param obj Anything.
13
+ * @returns `true` if the obj is a constructor. Else, `false`.
14
+ * @since 3.0.0
15
+ * @see https://stackoverflow.com/a/49510834
16
+ */
17
+ function isConstructor(obj) {
18
+ if (typeof obj !== "function") return false;
19
+ if (/^class\s/.test(obj.toString())) return true;
20
+ const prototype = obj.prototype;
21
+ if ((typeof prototype === "object" || typeof prototype === "function") && prototype !== null && "constructor" in prototype && typeof prototype.constructor === "function") {
22
+ const _ctor = prototype.constructor;
23
+ const _name = Reflect.getOwnPropertyDescriptor(_ctor, "name");
24
+ return _ctor === obj && _name?.writable === false && _name.enumerable === false && _name.configurable === true;
25
+ }
26
+ return false;
27
+ }
28
+ //#endregion
29
+ export { isConstructor };
30
+
2
31
  //# sourceMappingURL=isConstructor.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"isConstructor.mjs","names":[],"sources":["../../../src/utils/reflection/isConstructor.ts"],"sourcesContent":["/**\n * A very jank function to determine if an object can be the target of Reflect.construct.\n * Unfortunately, many functions have a constructor in their prototype. These\n * functions are treated like classes due to JavaScript's poor distinction between\n * classes and functions.\\\n * Typescript can enforce \"new\" keyword usage, but overriding the type\n * allows you to `new isConstructor()` despite this function not intended to be\n * used with the `new` keyword.\n * #### NOTE: Only works when targeting ES6/ES2015 or later.\n * > If your project or a dependent project is compiled to < ES6, this function will always return `false`; classes and constructors were introduced in ES6/ES2015.\n * @param obj Anything.\n * @returns `true` if the obj is a constructor. Else, `false`.\n * @since 3.0.0\n * @see https://stackoverflow.com/a/49510834\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isConstructor(obj: unknown): obj is abstract new (...args: any[]) => any {\n // Method 0 - filter\n if (typeof obj !== 'function')\n return false;\n\n // Method 1\n // statically-defined class\n if (/^class\\s/.test(obj.toString()))\n return true;\n\n /* Method 2\n * > class class_ {}; function func(){}\n * undefined\n * > class_.prototype.constructor.name === class_.name\n * true\n * > func.prototype?.constructor?.name === func.name\n * false\n * typeof String.prototype ==='object'\n * > true\n * typeof Function.prototype === 'object';\n * > false\n * typeof Function.prototype\n * > 'function'\n */\n const prototype: unknown = obj.prototype;\n if ((typeof prototype === 'object' || typeof prototype === 'function')\n && prototype !== null\n && 'constructor' in prototype\n && typeof prototype.constructor === 'function') {\n const _ctor = prototype.constructor as (new (...arguments_: unknown[]) => unknown);\n const _name = Reflect.getOwnPropertyDescriptor(\n _ctor,\n 'name',\n );\n // short-circuit if `obj.prototype.constructor` is a function, but not a constructor. Return false.\n return (\n _ctor === obj\n && _name?.writable === false\n && _name.enumerable === false\n && _name.configurable === true\n );\n }\n\n // Short-circuit\n // Method 3 catches exceptions when !isConstructor. When debugging, that's annoying.\n return false;\n\n // Method 3\n // isConstructable (See https://stackoverflow.com/a/49510834)\n // try {\n // // @ts-expect-error ts(2351): Type 'Function' has no construct signatures.\n // new new Proxy(obj, { construct: () => ({}) })()\n // return true\n // }\n // catch {\n // return false\n // }\n}\n"],"mappings":"AAgBA,SAAgB,EAAc,EAA2D,CAEvF,GAAI,OAAO,GAAQ,WACjB,MAAO,GAIT,GAAI,WAAW,KAAK,EAAI,UAAU,CAAC,CACjC,MAAO,GAgBT,IAAM,EAAqB,EAAI,UAC/B,IAAK,OAAO,GAAc,UAAY,OAAO,GAAc,aACtD,IAAc,MACd,gBAAiB,GACjB,OAAO,EAAU,aAAgB,WAAY,CAChD,IAAM,EAAQ,EAAU,YAClB,EAAQ,QAAQ,yBACpB,EACA,OACD,CAED,OACE,IAAU,GACP,GAAO,WAAa,IACpB,EAAM,aAAe,IACrB,EAAM,eAAiB,GAM9B,MAAO"}
1
+ {"version":3,"file":"isConstructor.mjs","names":[],"sources":["../../../src/utils/reflection/isConstructor.ts"],"sourcesContent":["/**\n * A very jank function to determine if an object can be the target of Reflect.construct.\n * Unfortunately, many functions have a constructor in their prototype. These\n * functions are treated like classes due to JavaScript's poor distinction between\n * classes and functions.\\\n * Typescript can enforce \"new\" keyword usage, but overriding the type\n * allows you to `new isConstructor()` despite this function not intended to be\n * used with the `new` keyword.\n * #### NOTE: Only works when targeting ES6/ES2015 or later.\n * > If your project or a dependent project is compiled to < ES6, this function will always return `false`; classes and constructors were introduced in ES6/ES2015.\n * @param obj Anything.\n * @returns `true` if the obj is a constructor. Else, `false`.\n * @since 3.0.0\n * @see https://stackoverflow.com/a/49510834\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isConstructor(obj: unknown): obj is abstract new (...args: any[]) => any {\n // Method 0 - filter\n if (typeof obj !== 'function')\n return false;\n\n // Method 1\n // statically-defined class\n if (/^class\\s/.test(obj.toString()))\n return true;\n\n /* Method 2\n * > class class_ {}; function func(){}\n * undefined\n * > class_.prototype.constructor.name === class_.name\n * true\n * > func.prototype?.constructor?.name === func.name\n * false\n * typeof String.prototype ==='object'\n * > true\n * typeof Function.prototype === 'object';\n * > false\n * typeof Function.prototype\n * > 'function'\n */\n const prototype: unknown = obj.prototype;\n if ((typeof prototype === 'object' || typeof prototype === 'function')\n && prototype !== null\n && 'constructor' in prototype\n && typeof prototype.constructor === 'function') {\n const _ctor = prototype.constructor as (new (...arguments_: unknown[]) => unknown);\n const _name = Reflect.getOwnPropertyDescriptor(\n _ctor,\n 'name',\n );\n // short-circuit if `obj.prototype.constructor` is a function, but not a constructor. Return false.\n return (\n _ctor === obj\n && _name?.writable === false\n && _name.enumerable === false\n && _name.configurable === true\n );\n }\n\n // Short-circuit\n // Method 3 catches exceptions when !isConstructor. When debugging, that's annoying.\n return false;\n\n // Method 3\n // isConstructable (See https://stackoverflow.com/a/49510834)\n // try {\n // // @ts-expect-error ts(2351): Type 'Function' has no construct signatures.\n // new new Proxy(obj, { construct: () => ({}) })()\n // return true\n // }\n // catch {\n // return false\n // }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,SAAgB,cAAc,KAA2D;AAEvF,KAAI,OAAO,QAAQ,WACjB,QAAO;AAIT,KAAI,WAAW,KAAK,IAAI,UAAU,CAAC,CACjC,QAAO;CAgBT,MAAM,YAAqB,IAAI;AAC/B,MAAK,OAAO,cAAc,YAAY,OAAO,cAAc,eACtD,cAAc,QACd,iBAAiB,aACjB,OAAO,UAAU,gBAAgB,YAAY;EAChD,MAAM,QAAQ,UAAU;EACxB,MAAM,QAAQ,QAAQ,yBACpB,OACA,OACD;AAED,SACE,UAAU,OACP,OAAO,aAAa,SACpB,MAAM,eAAe,SACrB,MAAM,iBAAiB;;AAM9B,QAAO"}