@cbnventures/nova 0.19.0 → 0.20.0

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 (242) hide show
  1. package/build/package.json +6 -3
  2. package/build/src/cli/generate/github/issue-template.d.ts.map +1 -1
  3. package/build/src/cli/generate/github/issue-template.js +4 -93
  4. package/build/src/cli/generate/github/issue-template.js.map +1 -1
  5. package/build/src/cli/generate/must-haves/agent-conventions.d.ts.map +1 -1
  6. package/build/src/cli/generate/must-haves/agent-conventions.js +12 -3
  7. package/build/src/cli/generate/must-haves/agent-conventions.js.map +1 -1
  8. package/build/src/cli/generate/must-haves/dotenv.d.ts +4 -7
  9. package/build/src/cli/generate/must-haves/dotenv.d.ts.map +1 -1
  10. package/build/src/cli/generate/must-haves/dotenv.js +120 -417
  11. package/build/src/cli/generate/must-haves/dotenv.js.map +1 -1
  12. package/build/src/cli/generate/must-haves/gitignore.d.ts +0 -8
  13. package/build/src/cli/generate/must-haves/gitignore.d.ts.map +1 -1
  14. package/build/src/cli/generate/must-haves/gitignore.js +7 -395
  15. package/build/src/cli/generate/must-haves/gitignore.js.map +1 -1
  16. package/build/src/cli/recipe/github/sync-identity.js +1 -1
  17. package/build/src/cli/recipe/github/sync-identity.js.map +1 -1
  18. package/build/src/cli/recipe/github/sync-policies.d.ts.map +1 -1
  19. package/build/src/cli/recipe/github/sync-policies.js +8 -1
  20. package/build/src/cli/recipe/github/sync-policies.js.map +1 -1
  21. package/build/src/cli/utility/changelog.d.ts +2 -0
  22. package/build/src/cli/utility/changelog.d.ts.map +1 -1
  23. package/build/src/cli/utility/changelog.js +154 -2
  24. package/build/src/cli/utility/changelog.js.map +1 -1
  25. package/build/src/cli/utility/initialize.d.ts +3 -0
  26. package/build/src/cli/utility/initialize.d.ts.map +1 -1
  27. package/build/src/cli/utility/initialize.js +305 -1
  28. package/build/src/cli/utility/initialize.js.map +1 -1
  29. package/build/src/lib/dotenv.d.ts +3 -0
  30. package/build/src/lib/dotenv.d.ts.map +1 -0
  31. package/build/src/lib/dotenv.js +66 -0
  32. package/build/src/lib/dotenv.js.map +1 -0
  33. package/build/src/lib/file-discovery.d.ts +3 -0
  34. package/build/src/lib/file-discovery.d.ts.map +1 -0
  35. package/build/src/lib/file-discovery.js +32 -0
  36. package/build/src/lib/file-discovery.js.map +1 -0
  37. package/build/src/lib/item.d.ts +3 -1
  38. package/build/src/lib/item.d.ts.map +1 -1
  39. package/build/src/lib/item.js +9 -0
  40. package/build/src/lib/item.js.map +1 -1
  41. package/build/src/lib/markdown-slug.d.ts +4 -0
  42. package/build/src/lib/markdown-slug.d.ts.map +1 -0
  43. package/build/src/lib/markdown-slug.js +25 -0
  44. package/build/src/lib/markdown-slug.js.map +1 -0
  45. package/build/src/lib/nova-config.d.ts +5 -0
  46. package/build/src/lib/nova-config.d.ts.map +1 -1
  47. package/build/src/lib/nova-config.js +135 -13
  48. package/build/src/lib/nova-config.js.map +1 -1
  49. package/build/src/lib/regex.d.ts +68 -0
  50. package/build/src/lib/regex.d.ts.map +1 -1
  51. package/build/src/lib/regex.js +70 -2
  52. package/build/src/lib/regex.js.map +1 -1
  53. package/build/src/lib/type-declaration-engine.d.ts +32 -0
  54. package/build/src/lib/type-declaration-engine.d.ts.map +1 -0
  55. package/build/src/lib/type-declaration-engine.js +770 -0
  56. package/build/src/lib/type-declaration-engine.js.map +1 -0
  57. package/build/src/lib/utility.d.ts.map +1 -1
  58. package/build/src/lib/utility.js +8 -8
  59. package/build/src/lib/utility.js.map +1 -1
  60. package/build/src/rules/eslint/conventions/require-kebab-case-filename.d.ts.map +1 -1
  61. package/build/src/rules/eslint/conventions/require-kebab-case-filename.js.map +1 -1
  62. package/build/src/rules/eslint/jsdoc/require-jsdoc-hierarchy.d.ts.map +1 -1
  63. package/build/src/rules/eslint/jsdoc/require-jsdoc-hierarchy.js +3 -3
  64. package/build/src/rules/eslint/jsdoc/require-jsdoc-hierarchy.js.map +1 -1
  65. package/build/src/rules/eslint/jsdoc/require-jsdoc-param-alignment.d.ts.map +1 -1
  66. package/build/src/rules/eslint/jsdoc/require-jsdoc-param-alignment.js +3 -2
  67. package/build/src/rules/eslint/jsdoc/require-jsdoc-param-alignment.js.map +1 -1
  68. package/build/src/rules/eslint/jsdoc/require-jsdoc-param-name.js +2 -2
  69. package/build/src/rules/eslint/jsdoc/require-jsdoc-param-name.js.map +1 -1
  70. package/build/src/rules/eslint/jsdoc/require-jsdoc-since.d.ts +1 -1
  71. package/build/src/rules/eslint/jsdoc/require-jsdoc-since.d.ts.map +1 -1
  72. package/build/src/rules/eslint/jsdoc/require-jsdoc-since.js +102 -6
  73. package/build/src/rules/eslint/jsdoc/require-jsdoc-since.js.map +1 -1
  74. package/build/src/rules/eslint/regex/no-regex-literals.d.ts +1 -0
  75. package/build/src/rules/eslint/regex/no-regex-literals.d.ts.map +1 -1
  76. package/build/src/rules/eslint/regex/no-regex-literals.js +39 -1
  77. package/build/src/rules/eslint/regex/no-regex-literals.js.map +1 -1
  78. package/build/src/rules/eslint/typescript/require-type-naming.js +2 -2
  79. package/build/src/rules/eslint/typescript/require-type-naming.js.map +1 -1
  80. package/build/src/rules/vitest/dotenv/register.d.ts +3 -0
  81. package/build/src/rules/vitest/dotenv/register.d.ts.map +1 -0
  82. package/build/src/rules/vitest/dotenv/register.js +21 -0
  83. package/build/src/rules/vitest/dotenv/register.js.map +1 -0
  84. package/build/src/rules/vitest/dotenv/rules.d.ts +3 -0
  85. package/build/src/rules/vitest/dotenv/rules.d.ts.map +1 -0
  86. package/build/src/rules/vitest/dotenv/rules.js +32 -0
  87. package/build/src/rules/vitest/dotenv/rules.js.map +1 -0
  88. package/build/src/rules/vitest/enable.d.ts +3 -0
  89. package/build/src/rules/vitest/enable.d.ts.map +1 -0
  90. package/build/src/rules/vitest/enable.js +7 -0
  91. package/build/src/rules/vitest/enable.js.map +1 -0
  92. package/build/src/rules/vitest/frontmatter/register.d.ts +3 -0
  93. package/build/src/rules/vitest/frontmatter/register.d.ts.map +1 -0
  94. package/build/src/rules/vitest/frontmatter/register.js +51 -0
  95. package/build/src/rules/vitest/frontmatter/register.js.map +1 -0
  96. package/build/src/rules/vitest/frontmatter/rules.d.ts +15 -0
  97. package/build/src/rules/vitest/frontmatter/rules.d.ts.map +1 -0
  98. package/build/src/rules/vitest/frontmatter/rules.js +498 -0
  99. package/build/src/rules/vitest/frontmatter/rules.js.map +1 -0
  100. package/build/src/rules/vitest/index.d.ts +8 -0
  101. package/build/src/rules/vitest/index.d.ts.map +1 -0
  102. package/build/src/rules/vitest/index.js +7 -0
  103. package/build/src/rules/vitest/index.js.map +1 -0
  104. package/build/src/rules/vitest/link/register.d.ts +3 -0
  105. package/build/src/rules/vitest/link/register.d.ts.map +1 -0
  106. package/build/src/rules/vitest/link/register.js +43 -0
  107. package/build/src/rules/vitest/link/register.js.map +1 -0
  108. package/build/src/rules/vitest/link/rules.d.ts +12 -0
  109. package/build/src/rules/vitest/link/rules.d.ts.map +1 -0
  110. package/build/src/rules/vitest/link/rules.js +313 -0
  111. package/build/src/rules/vitest/link/rules.js.map +1 -0
  112. package/build/src/rules/vitest/markdown-table/register.d.ts +3 -0
  113. package/build/src/rules/vitest/markdown-table/register.d.ts.map +1 -0
  114. package/build/src/rules/vitest/markdown-table/register.js +25 -0
  115. package/build/src/rules/vitest/markdown-table/register.js.map +1 -0
  116. package/build/src/rules/vitest/markdown-table/rules.d.ts +3 -0
  117. package/build/src/rules/vitest/markdown-table/rules.d.ts.map +1 -0
  118. package/build/src/rules/vitest/markdown-table/rules.js +99 -0
  119. package/build/src/rules/vitest/markdown-table/rules.js.map +1 -0
  120. package/build/src/rules/vitest/terminology/register.d.ts +3 -0
  121. package/build/src/rules/vitest/terminology/register.d.ts.map +1 -0
  122. package/build/src/rules/vitest/terminology/register.js +38 -0
  123. package/build/src/rules/vitest/terminology/register.js.map +1 -0
  124. package/build/src/rules/vitest/terminology/rules.d.ts +10 -0
  125. package/build/src/rules/vitest/terminology/rules.d.ts.map +1 -0
  126. package/build/src/rules/vitest/terminology/rules.js +202 -0
  127. package/build/src/rules/vitest/terminology/rules.js.map +1 -0
  128. package/build/src/rules/vitest/type-declarations/register.d.ts +3 -0
  129. package/build/src/rules/vitest/type-declarations/register.d.ts.map +1 -0
  130. package/build/src/rules/vitest/type-declarations/register.js +30 -0
  131. package/build/src/rules/vitest/type-declarations/register.js.map +1 -0
  132. package/build/src/rules/vitest/type-declarations/rules.d.ts +11 -0
  133. package/build/src/rules/vitest/type-declarations/rules.d.ts.map +1 -0
  134. package/build/src/rules/vitest/type-declarations/rules.js +666 -0
  135. package/build/src/rules/vitest/type-declarations/rules.js.map +1 -0
  136. package/build/src/toolkit/logger.d.ts.map +1 -1
  137. package/build/src/toolkit/logger.js +3 -1
  138. package/build/src/toolkit/logger.js.map +1 -1
  139. package/build/src/types/cli/generate/github/issue-template.d.ts +10 -30
  140. package/build/src/types/cli/generate/github/workflows.d.ts +7 -7
  141. package/build/src/types/cli/generate/must-haves/agent-conventions.d.ts +8 -1
  142. package/build/src/types/cli/generate/must-haves/dotenv.d.ts +79 -327
  143. package/build/src/types/cli/generate/must-haves/gitignore.d.ts +12 -342
  144. package/build/src/types/cli/recipe/github/sync-features.d.ts +1 -1
  145. package/build/src/types/cli/recipe/github/sync-identity.d.ts +2 -2
  146. package/build/src/types/cli/recipe/github/sync-policies.d.ts +3 -1
  147. package/build/src/types/cli/utility/changelog.d.ts +92 -0
  148. package/build/src/types/cli/utility/initialize.d.ts +195 -0
  149. package/build/src/types/lib/constants.d.ts +1 -1
  150. package/build/src/types/lib/dotenv.d.ts +67 -0
  151. package/build/src/types/lib/file-discovery.d.ts +40 -0
  152. package/build/src/types/lib/item.d.ts +19 -0
  153. package/build/src/types/lib/markdown-slug.d.ts +25 -0
  154. package/build/src/types/lib/nova-config.d.ts +108 -16
  155. package/build/src/types/lib/regex.d.ts +193 -18
  156. package/build/src/types/lib/type-declaration-engine.d.ts +1036 -0
  157. package/build/src/types/lib/utility.d.ts +2 -2
  158. package/build/src/types/lib/workflow-templates.d.ts +1 -1
  159. package/build/src/types/rules/eslint/jsdoc/require-jsdoc-hierarchy.d.ts +2 -2
  160. package/build/src/types/rules/eslint/jsdoc/require-jsdoc-since.d.ts +71 -1
  161. package/build/src/types/rules/eslint/regex/no-regex-literals.d.ts +44 -0
  162. package/build/src/types/rules/eslint/typescript/require-type-naming.d.ts +3 -3
  163. package/build/src/types/rules/vitest/dotenv/register.d.ts +31 -0
  164. package/build/src/types/rules/vitest/dotenv/rules.d.ts +29 -0
  165. package/build/src/types/rules/vitest/enable.d.ts +12 -0
  166. package/build/src/types/rules/vitest/frontmatter/register.d.ts +63 -0
  167. package/build/src/types/rules/vitest/frontmatter/rules.d.ts +430 -0
  168. package/build/src/types/rules/vitest/index.d.ts +399 -0
  169. package/build/src/types/rules/vitest/link/register.d.ts +79 -0
  170. package/build/src/types/rules/vitest/link/rules.d.ts +368 -0
  171. package/build/src/types/rules/vitest/markdown-table/register.d.ts +33 -0
  172. package/build/src/types/rules/vitest/markdown-table/rules.d.ts +55 -0
  173. package/build/src/types/rules/vitest/terminology/register.d.ts +48 -0
  174. package/build/src/types/rules/vitest/terminology/rules.d.ts +190 -0
  175. package/build/src/types/rules/vitest/type-declarations/register.d.ts +46 -0
  176. package/build/src/types/rules/vitest/type-declarations/rules.d.ts +820 -0
  177. package/build/src/types/shared.d.ts +71 -4
  178. package/build/src/types/tests/cli/generate/github/issue-template.test.d.ts +34 -17
  179. package/build/src/types/tests/cli/generate/github/workflows-helpers.test.d.ts +8 -8
  180. package/build/src/types/tests/cli/generate/must-haves/agent-conventions.test.d.ts +79 -11
  181. package/build/src/types/tests/cli/generate/must-haves/dotenv.test.d.ts +105 -15
  182. package/build/src/types/tests/cli/generate/must-haves/gitignore.test.d.ts +11 -20
  183. package/build/src/types/tests/cli/recipe/github/handle-gh-failure.test.d.ts +3 -3
  184. package/build/src/types/tests/cli/recipe/github/sync-features.test.d.ts +17 -17
  185. package/build/src/types/tests/cli/recipe/github/sync-identity.test.d.ts +69 -23
  186. package/build/src/types/tests/cli/recipe/github/sync-policies.test.d.ts +89 -20
  187. package/build/src/types/tests/cli/scaffold/docs/docusaurus.test.d.ts +4 -0
  188. package/build/src/types/tests/cli/utility/changelog.test.d.ts +262 -0
  189. package/build/src/types/tests/cli/utility/initialize.test.d.ts +31 -0
  190. package/build/src/types/tests/lib/dotenv.test.d.ts +95 -0
  191. package/build/src/types/tests/lib/file-discovery.test.d.ts +37 -0
  192. package/build/src/types/tests/lib/item.test.d.ts +21 -0
  193. package/build/src/types/tests/lib/markdown-slug.test.d.ts +24 -0
  194. package/build/src/types/tests/lib/nova-config.test.d.ts +263 -0
  195. package/build/src/types/tests/lib/regex.test.d.ts +252 -0
  196. package/build/src/types/tests/rules/eslint/jsdoc/require-jsdoc-since.test.d.ts +18 -0
  197. package/build/src/types/tests/rules/vitest/dotenv.test.d.ts +19 -0
  198. package/build/src/types/tests/rules/vitest/enable.test.d.ts +27 -0
  199. package/build/src/types/tests/rules/vitest/frontmatter.test.d.ts +8 -0
  200. package/build/src/types/tests/rules/vitest/link.test.d.ts +74 -0
  201. package/build/src/types/tests/rules/vitest/markdown-table.test.d.ts +28 -0
  202. package/build/src/types/tests/rules/vitest/terminology.test.d.ts +39 -0
  203. package/build/src/types/tests/rules/vitest/type-declarations.test.d.ts +10 -0
  204. package/build/src/types/tests/scaffold-version-drift.test.d.ts +42 -0
  205. package/build/src/types/tests/since-version.test.d.ts +137 -0
  206. package/build/src/types/tests/toolkit/logger.test.d.ts +45 -0
  207. package/build/src/types/tests/type-declarations.test.d.ts +34 -1821
  208. package/build/src/types/toolkit/logger.d.ts +4 -0
  209. package/build/templates/generators/github/workflows/check-sponsor-gated-issues/base.yml +1 -1
  210. package/build/templates/generators/github/workflows/publish/base.yml +1 -1
  211. package/build/templates/generators/github/workflows/publish/targets/aws-amplify-nextjs.yml +1 -1
  212. package/build/templates/generators/github/workflows/publish/targets/cloudflare-pages-docusaurus.yml +1 -1
  213. package/build/templates/generators/github/workflows/publish/targets/docker-hub.yml +1 -1
  214. package/build/templates/generators/github/workflows/publish/targets/ghcr.yml +1 -1
  215. package/build/templates/generators/github/workflows/publish/targets/github-action.yml +1 -1
  216. package/build/templates/generators/github/workflows/publish/targets/github-packages.yml +1 -1
  217. package/build/templates/generators/github/workflows/publish/targets/github-pages-docusaurus.yml +4 -4
  218. package/build/templates/generators/github/workflows/publish/targets/npm.yml +1 -1
  219. package/build/templates/generators/github/workflows/publish/targets/vercel-nextjs.yml +1 -1
  220. package/build/templates/generators/must-haves/agent-conventions/AGENTS.md +1 -2
  221. package/build/templates/generators/must-haves/agent-conventions/CLAUDE.md +1 -2
  222. package/build/templates/generators/must-haves/agent-conventions/conventions/java.md +5 -5
  223. package/build/templates/generators/must-haves/agent-conventions/conventions/kotlin.md +4 -4
  224. package/build/templates/generators/must-haves/agent-conventions/conventions/php.md +2 -2
  225. package/build/templates/generators/must-haves/agent-conventions/conventions/typescript.md +6 -6
  226. package/build/templates/generators/must-haves/dotenv/env +5 -2
  227. package/build/templates/generators/must-haves/dotenv/env.sample +6 -3
  228. package/build/templates/generators/must-haves/gitignore/gitignore +6 -0
  229. package/build/templates/scaffold/app/express/package.json +5 -5
  230. package/build/templates/scaffold/app/nextjs/package.json +7 -7
  231. package/build/templates/scaffold/app/vite/package.json +3 -3
  232. package/build/templates/scaffold/app/workers/package.json +3 -3
  233. package/build/templates/scaffold/docs/docusaurus/docs/intro.md +6 -0
  234. package/build/templates/scaffold/docs/docusaurus/package.json +11 -7
  235. package/build/templates/scaffold/docs/docusaurus/src/tests/frontmatter.test.ts +21 -0
  236. package/build/templates/scaffold/docs/docusaurus/src/tests/link.test.ts +14 -0
  237. package/build/templates/scaffold/docs/docusaurus/src/tests/markdown-table.test.ts +14 -0
  238. package/build/templates/scaffold/docs/docusaurus/src/tests/terminology.test.ts +14 -0
  239. package/build/templates/scaffold/docs/docusaurus/vitest.config.ts +22 -0
  240. package/build/templates/scaffold/docs/docusaurus/vitest.setup.ts +26 -0
  241. package/package.json +6 -3
  242. package/build/templates/generators/must-haves/agent-conventions/cursorrules +0 -55
@@ -0,0 +1,770 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { relative, sep, } from 'node:path';
3
+ import { glob } from 'glob';
4
+ import { createSourceFile, forEachChild, isArrowFunction, isCallExpression, isClassDeclaration, isClassExpression, isConstructorDeclaration, isFunctionDeclaration, isFunctionExpression, isGetAccessorDeclaration, isIdentifier, isMethodDeclaration, isPrivateIdentifier, isSetAccessorDeclaration, isStringLiteral, isTypePredicateNode, isTypeReferenceNode, isVariableStatement, ScriptTarget, } from 'typescript';
5
+ import { LIB_REGEX_PATTERN_ANGLE_BRACKET_GENERIC, LIB_REGEX_PATTERN_CAMEL_CASE_WORDS, LIB_REGEX_PATTERN_COMPLEX_TYPE_RHS_CHARS, LIB_REGEX_PATTERN_DTS_ARRAY_ALIAS, LIB_REGEX_PATTERN_DTS_PROPERTY_LINE, LIB_REGEX_PATTERN_EMPTY_ARRAY_BRACKETS, LIB_REGEX_PATTERN_EXPORT_TYPE_NAME, LIB_REGEX_PATTERN_IMPORT_TYPE_BLOCK, LIB_REGEX_PATTERN_NON_ALPHANUMERIC_RUN, LIB_REGEX_PATTERN_REGEX_SPECIAL_CHARS, LIB_REGEX_PATTERN_SINGLE_PASCAL_TYPE, LIB_REGEX_PATTERN_TYPED_BODY_DECLARATION, } from './regex.js';
6
+ export const testConfig = {
7
+ standaloneTypeFiles: [
8
+ '/fetch-response.d.ts',
9
+ '/shared.d.ts',
10
+ ],
11
+ typeRoots: [
12
+ 'src',
13
+ 'utils',
14
+ ],
15
+ };
16
+ export async function discoverSourceFiles(config = {}) {
17
+ const packageRoot = config['packageRoot'] ?? process.cwd();
18
+ const typeRoots = config['typeRoots'] ?? ['src'];
19
+ const patterns = typeRoots.map((typeRoot) => `${typeRoot}/**/*.ts`);
20
+ const ignorePatterns = typeRoots.map((typeRoot) => `${typeRoot}/**/*.d.ts`);
21
+ const matched = await glob(patterns, {
22
+ cwd: packageRoot,
23
+ absolute: true,
24
+ ignore: ignorePatterns,
25
+ });
26
+ return matched.sort();
27
+ }
28
+ export async function discoverTypeFiles(config = {}) {
29
+ const packageRoot = config['packageRoot'] ?? process.cwd();
30
+ const typeRoots = config['typeRoots'] ?? ['src'];
31
+ const patterns = typeRoots.map((typeRoot) => `${typeRoot}/types/**/*.d.ts`);
32
+ const matched = await glob(patterns, {
33
+ cwd: packageRoot,
34
+ absolute: true,
35
+ });
36
+ return matched.sort();
37
+ }
38
+ export function deriveClassPrefix(filePath, config = {}) {
39
+ const packageRoot = config['packageRoot'] ?? process.cwd();
40
+ const typeRoots = config['typeRoots'] ?? ['src'];
41
+ const currentDirectory = packageRoot;
42
+ const relativePath = relative(currentDirectory, filePath);
43
+ let relativeCleaned = relativePath;
44
+ for (const typeRoot of typeRoots) {
45
+ relativeCleaned = relativeCleaned.replace(`${typeRoot}/types/`, '');
46
+ relativeCleaned = relativeCleaned.replace(`${typeRoot}/`, '');
47
+ }
48
+ const segments = relativeCleaned
49
+ .replace('.d.ts', '')
50
+ .replace('.ts', '')
51
+ .replace('.test', '')
52
+ .split(sep)
53
+ .join('/')
54
+ .split('/');
55
+ const camelCaseWordsPattern = new RegExp(LIB_REGEX_PATTERN_CAMEL_CASE_WORDS.source, 'g');
56
+ return segments.map((segment) => {
57
+ if (segment.includes('-') === false
58
+ && segment.charAt(0) === segment.charAt(0).toUpperCase()
59
+ && segment.length > 0) {
60
+ const words = segment.match(camelCaseWordsPattern);
61
+ if (words !== null) {
62
+ return words.map((word) => {
63
+ return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
64
+ }).join('');
65
+ }
66
+ }
67
+ return segment.split('-').map((part) => {
68
+ return part.charAt(0).toUpperCase() + part.slice(1);
69
+ }).join('');
70
+ }).join('_');
71
+ }
72
+ export function extractImportedNames(lines) {
73
+ const importedNames = new Set();
74
+ let inImportBlock = false;
75
+ for (const line of lines) {
76
+ if (line.startsWith('import type') === true) {
77
+ inImportBlock = true;
78
+ const inlineMatch = line.match(LIB_REGEX_PATTERN_IMPORT_TYPE_BLOCK);
79
+ if (inlineMatch !== null && inlineMatch[1] !== undefined) {
80
+ const inlineMatchCapture = inlineMatch[1];
81
+ const specifiers = inlineMatchCapture.split(',').map((specifier) => specifier.trim());
82
+ for (const specifier of specifiers) {
83
+ importedNames.add(specifier);
84
+ }
85
+ inImportBlock = false;
86
+ }
87
+ continue;
88
+ }
89
+ if (inImportBlock === true) {
90
+ const trimmed = line.trim().replace(',', '');
91
+ if (trimmed.startsWith('}') === true) {
92
+ inImportBlock = false;
93
+ }
94
+ else if (trimmed !== '' && trimmed.startsWith('//') === false) {
95
+ importedNames.add(trimmed);
96
+ }
97
+ }
98
+ }
99
+ return importedNames;
100
+ }
101
+ export function buildDtsSections(dtsLines, sourceSections, classPrefix) {
102
+ const sortedSections = [...sourceSections].sort((sectionA, sectionB) => sectionB.length - sectionA.length);
103
+ const sectionMap = new Map();
104
+ const sectionOrder = [];
105
+ for (const line of dtsLines) {
106
+ if (line.startsWith('export type ') === false) {
107
+ continue;
108
+ }
109
+ const match = line.match(LIB_REGEX_PATTERN_EXPORT_TYPE_NAME);
110
+ if (match === null || match[1] === undefined) {
111
+ continue;
112
+ }
113
+ const typeName = match[1];
114
+ let owningSection = '';
115
+ for (const candidate of sortedSections) {
116
+ if (typeName.startsWith(`${candidate}_`) === true) {
117
+ owningSection = candidate;
118
+ break;
119
+ }
120
+ }
121
+ if (owningSection === '' && typeName.startsWith(`${classPrefix}_`) === true) {
122
+ owningSection = classPrefix;
123
+ }
124
+ if (owningSection === '') {
125
+ continue;
126
+ }
127
+ if (sectionMap.has(owningSection) === false) {
128
+ sectionMap.set(owningSection, {
129
+ prefix: owningSection,
130
+ typeLines: [],
131
+ });
132
+ sectionOrder.push(owningSection);
133
+ }
134
+ const section = sectionMap.get(owningSection);
135
+ section['typeLines'].push(line);
136
+ }
137
+ return sectionOrder.map((prefix) => sectionMap.get(prefix));
138
+ }
139
+ export function extractReferencedTypes(line, classPrefix) {
140
+ const match = line.match(LIB_REGEX_PATTERN_EXPORT_TYPE_NAME);
141
+ if (match === null || match[1] === undefined) {
142
+ return [];
143
+ }
144
+ const typeName = match[1];
145
+ const rightSide = line.slice(line.indexOf('=') + 1);
146
+ const referencedTypes = [];
147
+ const typePattern = new RegExp(`${classPrefix}_\\w+`, 'g');
148
+ let typeMatch = typePattern.exec(rightSide);
149
+ while (typeMatch !== null) {
150
+ const referencedType = typeMatch[0];
151
+ if (referencedType !== typeName) {
152
+ referencedTypes.push(referencedType);
153
+ }
154
+ typeMatch = typePattern.exec(rightSide);
155
+ }
156
+ return referencedTypes;
157
+ }
158
+ export function deriveDtsMapping(typeRoots) {
159
+ return {
160
+ sourceToDts: (file) => {
161
+ let mapped = file;
162
+ for (const typeRoot of typeRoots) {
163
+ if (file.includes(`/${typeRoot}/`) === true) {
164
+ mapped = file.replace(`/${typeRoot}/`, `/${typeRoot}/types/`);
165
+ break;
166
+ }
167
+ }
168
+ return mapped.replace('.ts', '.d.ts');
169
+ },
170
+ dtsToSource: (file) => {
171
+ return file.replace('/types/', '/').replace('.d.ts', '.ts');
172
+ },
173
+ };
174
+ }
175
+ export function deriveSourcePath(dtsPath) {
176
+ return dtsPath.replace('/types/', '/').replace('.d.ts', '.ts');
177
+ }
178
+ export async function fileExists(filePath) {
179
+ try {
180
+ await readFile(filePath, 'utf-8');
181
+ return true;
182
+ }
183
+ catch {
184
+ return false;
185
+ }
186
+ }
187
+ export function extractTypeNames(typeLines) {
188
+ const typeNames = [];
189
+ for (const line of typeLines) {
190
+ const match = line.match(LIB_REGEX_PATTERN_EXPORT_TYPE_NAME);
191
+ if (match !== null && match[1] !== undefined) {
192
+ typeNames.push(match[1]);
193
+ }
194
+ }
195
+ return typeNames;
196
+ }
197
+ export function findFirstOccurrence(sourceLines, typeName) {
198
+ let inImportBlock = false;
199
+ for (let i = 0; i < sourceLines.length; i += 1) {
200
+ const line = sourceLines[i];
201
+ if (line === undefined) {
202
+ continue;
203
+ }
204
+ if (line.startsWith('import ') === true || line.startsWith('import type') === true) {
205
+ inImportBlock = true;
206
+ }
207
+ if (inImportBlock === true) {
208
+ if (line.includes(' from ') === true) {
209
+ inImportBlock = false;
210
+ }
211
+ continue;
212
+ }
213
+ const typeNamePattern = new RegExp(`\\b${typeName}\\b`);
214
+ if (typeNamePattern.test(line) === true) {
215
+ return i;
216
+ }
217
+ }
218
+ return -1;
219
+ }
220
+ export function extractObjectTypes(lines, classPrefix) {
221
+ const objectTypes = [];
222
+ const typeLineMap = new Map();
223
+ for (let i = 0; i < lines.length; i += 1) {
224
+ const line = lines[i];
225
+ if (line === undefined) {
226
+ continue;
227
+ }
228
+ const typeDefMatch = line.match(new RegExp(`^export type (${classPrefix}\\w+)`));
229
+ if (typeDefMatch !== null && typeDefMatch[1] !== undefined) {
230
+ typeLineMap.set(typeDefMatch[1], i);
231
+ }
232
+ }
233
+ for (let i = 0; i < lines.length; i += 1) {
234
+ const line2 = lines[i];
235
+ if (line2 === undefined) {
236
+ continue;
237
+ }
238
+ const objectMatch = line2.match(new RegExp(`^export type (${classPrefix}\\w+) = (?:Readonly<)?\\{$`));
239
+ if (objectMatch === null || objectMatch[1] === undefined) {
240
+ continue;
241
+ }
242
+ const properties = [];
243
+ for (let j = i + 1; j < lines.length; j += 1) {
244
+ const propertyLine = lines[j];
245
+ if (propertyLine === undefined) {
246
+ continue;
247
+ }
248
+ const trimmedProperty = propertyLine.trim();
249
+ if (trimmedProperty.startsWith('}') === true) {
250
+ break;
251
+ }
252
+ const propertyMatch = trimmedProperty.match(LIB_REGEX_PATTERN_DTS_PROPERTY_LINE);
253
+ if (propertyMatch !== null
254
+ && propertyMatch[1] !== undefined
255
+ && propertyMatch[2] !== undefined) {
256
+ const propertyKey = propertyMatch[1];
257
+ const propertyValueType = propertyMatch[2];
258
+ const typeLineIndex = typeLineMap.get(propertyValueType) ?? -1;
259
+ properties.push({
260
+ key: propertyKey,
261
+ valueType: propertyValueType,
262
+ typeLineIndex,
263
+ });
264
+ }
265
+ }
266
+ const objectName = objectMatch[1];
267
+ objectTypes.push({
268
+ name: objectName,
269
+ lineIndex: i,
270
+ properties,
271
+ });
272
+ }
273
+ return objectTypes;
274
+ }
275
+ const sourceFileCache = new Map();
276
+ export function parseSourceFile(filePath, content) {
277
+ const cached = sourceFileCache.get(filePath);
278
+ if (cached !== undefined && cached['content'] === content) {
279
+ return cached['sourceFile'];
280
+ }
281
+ const sourceFile = createSourceFile(filePath, content, ScriptTarget.Latest, true);
282
+ sourceFileCache.set(filePath, {
283
+ content, sourceFile,
284
+ });
285
+ return sourceFile;
286
+ }
287
+ export function extractFunctionParams(filePath, content) {
288
+ const sourceFile = parseSourceFile(filePath, content);
289
+ const params = [];
290
+ function visit(node) {
291
+ let parameterList = undefined;
292
+ if (isFunctionDeclaration(node) === true
293
+ || isMethodDeclaration(node) === true
294
+ || isConstructorDeclaration(node) === true) {
295
+ parameterList = node['parameters'];
296
+ }
297
+ else if (isVariableStatement(node) === true) {
298
+ for (const decl of node.declarationList.declarations) {
299
+ if (decl.initializer !== undefined
300
+ && (isArrowFunction(decl.initializer) === true
301
+ || isFunctionExpression(decl.initializer) === true)) {
302
+ parameterList = decl.initializer.parameters;
303
+ }
304
+ }
305
+ }
306
+ if (parameterList !== undefined) {
307
+ for (const param of parameterList) {
308
+ const paramNode = param;
309
+ if (paramNode['name'] !== undefined
310
+ && isIdentifier(paramNode['name']) === true
311
+ && paramNode['type'] !== undefined
312
+ && isTypeReferenceNode(paramNode['type']) === true
313
+ && isIdentifier(paramNode['type']['typeName']) === true) {
314
+ const lineNumber = sourceFile.getLineAndCharacterOfPosition((param).getStart()).line + 1;
315
+ const paramRecord = {
316
+ paramName: paramNode['name']['text'],
317
+ typeName: paramNode['type']['typeName']['text'],
318
+ lineNumber,
319
+ };
320
+ params.push(paramRecord);
321
+ }
322
+ }
323
+ }
324
+ forEachChild(node, visit);
325
+ return;
326
+ }
327
+ forEachChild(sourceFile, visit);
328
+ return params;
329
+ }
330
+ export function extractBodyDeclarations(lines) {
331
+ const declarations = [];
332
+ for (let i = 0; i < lines.length; i += 1) {
333
+ const line = lines[i];
334
+ if (line === undefined) {
335
+ continue;
336
+ }
337
+ const match = line.match(LIB_REGEX_PATTERN_TYPED_BODY_DECLARATION);
338
+ if (match !== null
339
+ && match[1] !== undefined
340
+ && match[2] !== undefined
341
+ && match[3] !== undefined) {
342
+ const declaration = {
343
+ keyword: match[1],
344
+ varName: match[2],
345
+ typeName: match[3],
346
+ lineNumber: i + 1,
347
+ };
348
+ declarations.push(declaration);
349
+ }
350
+ }
351
+ return declarations;
352
+ }
353
+ export function extractTopLevelIdentifiers(filePath, content) {
354
+ const sourceFile = parseSourceFile(filePath, content);
355
+ const identifiers = [];
356
+ function getLine(node) {
357
+ return sourceFile.getLineAndCharacterOfPosition(node.getStart()).line + 1;
358
+ }
359
+ forEachChild(sourceFile, (node) => {
360
+ if (isClassDeclaration(node) === true && node.name !== undefined) {
361
+ const identifier = {
362
+ name: node.name.text,
363
+ kind: 'class',
364
+ lineNumber: getLine(node),
365
+ };
366
+ identifiers.push(identifier);
367
+ return;
368
+ }
369
+ if (isFunctionDeclaration(node) === true && node.name !== undefined) {
370
+ const identifier2 = {
371
+ name: node.name.text,
372
+ kind: 'function',
373
+ lineNumber: getLine(node),
374
+ };
375
+ identifiers.push(identifier2);
376
+ return;
377
+ }
378
+ if (isVariableStatement(node) === true) {
379
+ for (const decl of node.declarationList.declarations) {
380
+ if (decl.name !== undefined
381
+ && isIdentifier(decl.name) === true
382
+ && decl.initializer !== undefined
383
+ && (isArrowFunction(decl.initializer) === true
384
+ || isFunctionExpression(decl.initializer) === true
385
+ || isClassExpression(decl.initializer) === true)) {
386
+ const identifier3 = {
387
+ name: decl.name.text,
388
+ kind: 'const',
389
+ lineNumber: getLine(decl),
390
+ };
391
+ identifiers.push(identifier3);
392
+ }
393
+ }
394
+ }
395
+ return;
396
+ });
397
+ return identifiers;
398
+ }
399
+ export function buildSourceSectionMap(filePath, content, classPrefix) {
400
+ const sourceFile = parseSourceFile(filePath, content);
401
+ const sectionMap = new Map();
402
+ const maxDepth = 5000;
403
+ function getLine(node) {
404
+ return sourceFile.getLineAndCharacterOfPosition(node.getStart()).line + 1;
405
+ }
406
+ function pascalCase(name) {
407
+ return name.charAt(0).toUpperCase() + name.slice(1);
408
+ }
409
+ let currentDepth = 0;
410
+ function tagAllChildren(node, section) {
411
+ if (currentDepth >= maxDepth) {
412
+ return;
413
+ }
414
+ currentDepth += 1;
415
+ forEachChild(node, (child) => visit(child, section));
416
+ currentDepth -= 1;
417
+ return;
418
+ }
419
+ function visit(node, section) {
420
+ if (isClassDeclaration(node) === true && node.name !== undefined) {
421
+ const newSection = `${section}_${pascalCase(node.name.text)}`;
422
+ sectionMap.set(getLine(node), newSection);
423
+ tagAllChildren(node, newSection);
424
+ return;
425
+ }
426
+ const accessor = node;
427
+ if ((isMethodDeclaration(node) === true
428
+ || isGetAccessorDeclaration(node) === true
429
+ || isSetAccessorDeclaration(node) === true)
430
+ && accessor.name !== undefined
431
+ && (isIdentifier(accessor.name) === true
432
+ || isPrivateIdentifier(accessor.name) === true)) {
433
+ const rawMethodName = accessor.name.text;
434
+ const cleanMethodName = (rawMethodName.startsWith('#') === true) ? rawMethodName.slice(1) : rawMethodName;
435
+ const newSection2 = `${section}_${pascalCase(cleanMethodName)}`;
436
+ sectionMap.set(getLine(node), newSection2);
437
+ tagAllChildren(node, newSection2);
438
+ return;
439
+ }
440
+ if (isConstructorDeclaration(node) === true) {
441
+ const newSection3 = `${section}_Constructor`;
442
+ sectionMap.set(getLine(node), newSection3);
443
+ tagAllChildren(node, newSection3);
444
+ return;
445
+ }
446
+ if (isFunctionDeclaration(node) === true && node.name !== undefined) {
447
+ const newSection4 = `${section}_${pascalCase(node.name.text)}`;
448
+ sectionMap.set(getLine(node), newSection4);
449
+ tagAllChildren(node, newSection4);
450
+ return;
451
+ }
452
+ if (isVariableStatement(node) === true) {
453
+ let hasInitializer = false;
454
+ let subSection = section;
455
+ for (const decl of node.declarationList.declarations) {
456
+ if (decl.name !== undefined
457
+ && isIdentifier(decl.name) === true
458
+ && decl.initializer !== undefined
459
+ && (isArrowFunction(decl.initializer) === true
460
+ || isFunctionExpression(decl.initializer) === true
461
+ || isClassExpression(decl.initializer) === true)) {
462
+ hasInitializer = true;
463
+ subSection = `${section}_${pascalCase(decl.name.text)}`;
464
+ }
465
+ }
466
+ sectionMap.set(getLine(node), section);
467
+ if (hasInitializer === true) {
468
+ for (const decl of node.declarationList.declarations) {
469
+ if (decl.initializer === undefined) {
470
+ continue;
471
+ }
472
+ if (isArrowFunction(decl.initializer) === true || isFunctionExpression(decl.initializer) === true) {
473
+ if (decl.initializer.body !== undefined) {
474
+ tagAllChildren(decl.initializer.body, subSection);
475
+ }
476
+ }
477
+ else if (isClassExpression(decl.initializer) === true) {
478
+ tagAllChildren(decl.initializer, subSection);
479
+ }
480
+ }
481
+ }
482
+ else {
483
+ tagAllChildren(node, section);
484
+ }
485
+ return;
486
+ }
487
+ if (isCallExpression(node) === true
488
+ && node.arguments.length >= 2
489
+ && node.arguments[0] !== undefined
490
+ && isStringLiteral(node.arguments[0]) === true) {
491
+ let callbackArg = undefined;
492
+ for (let argIndex = 1; argIndex < node.arguments.length; argIndex += 1) {
493
+ const arg = node.arguments[argIndex];
494
+ if (arg !== undefined
495
+ && (isArrowFunction(arg) === true
496
+ || isFunctionExpression(arg) === true)) {
497
+ callbackArg = arg;
498
+ break;
499
+ }
500
+ }
501
+ if (callbackArg !== undefined) {
502
+ const stringArg = node.arguments[0];
503
+ const chunk = parseDescribeString(stringArg.text);
504
+ if (chunk !== '') {
505
+ const newSection5 = `${section}_${chunk}`;
506
+ sectionMap.set(getLine(node), section);
507
+ tagAllChildren(callbackArg, newSection5);
508
+ return;
509
+ }
510
+ }
511
+ }
512
+ sectionMap.set(getLine(node), section);
513
+ tagAllChildren(node, section);
514
+ return;
515
+ }
516
+ forEachChild(sourceFile, (child) => visit(child, classPrefix));
517
+ return sectionMap;
518
+ }
519
+ export function parseDescribeString(input) {
520
+ const pieces = input
521
+ .split(LIB_REGEX_PATTERN_NON_ALPHANUMERIC_RUN)
522
+ .filter((piece) => piece.length > 0)
523
+ .map((piece) => piece.charAt(0).toUpperCase() + piece.slice(1));
524
+ return pieces.join('');
525
+ }
526
+ export function stripUnderscorePrefix(input) {
527
+ if (input.startsWith('_') === true) {
528
+ return input.slice(1);
529
+ }
530
+ return input;
531
+ }
532
+ export function checkTypeNameUniqueness(declarations) {
533
+ const violations = [];
534
+ const seen = new Map();
535
+ for (const declaration of declarations) {
536
+ const existing = seen.get(declaration['typeName']);
537
+ if (existing !== undefined) {
538
+ const violation = `Two declarations would produce the same type name '${declaration['typeName']}'. First: line ${existing['lineNumber']} ('${existing['name']}'); duplicate: line ${declaration['lineNumber']} ('${declaration['name']}'). Rename one of the declarations so the type names differ.`;
539
+ violations.push(violation);
540
+ }
541
+ else {
542
+ seen.set(declaration['typeName'], {
543
+ name: declaration['name'],
544
+ lineNumber: declaration['lineNumber'],
545
+ });
546
+ }
547
+ }
548
+ return violations;
549
+ }
550
+ export function detectInlineTypedCallbacks(filePath, content) {
551
+ const sourceFile = parseSourceFile(filePath, content);
552
+ const callbacks = [];
553
+ function visit(node) {
554
+ if ((isArrowFunction(node) === true
555
+ || isFunctionExpression(node) === true)
556
+ && node.parent !== undefined) {
557
+ let isFunctionTypedConst = false;
558
+ let walker = node.parent;
559
+ while (walker !== undefined) {
560
+ if (isVariableStatement(walker) === true) {
561
+ isFunctionTypedConst = true;
562
+ break;
563
+ }
564
+ if (walker['kind'] !== undefined
565
+ && (isCallExpression(walker) === true
566
+ || isArrowFunction(walker) === true
567
+ || isFunctionExpression(walker) === true)) {
568
+ break;
569
+ }
570
+ walker = walker['parent'];
571
+ }
572
+ if (isFunctionTypedConst === false) {
573
+ for (const param of node.parameters) {
574
+ const paramNode = param;
575
+ if (paramNode['name'] !== undefined
576
+ && isIdentifier(paramNode['name']) === true
577
+ && paramNode['type'] !== undefined
578
+ && isTypeReferenceNode(paramNode['type']) === true
579
+ && isIdentifier(paramNode['type']['typeName']) === true) {
580
+ const lineNumber = sourceFile.getLineAndCharacterOfPosition(param.getStart()).line + 1;
581
+ const callback = {
582
+ paramName: paramNode['name']['text'],
583
+ typeName: paramNode['type']['typeName']['text'],
584
+ lineNumber,
585
+ };
586
+ callbacks.push(callback);
587
+ }
588
+ }
589
+ }
590
+ }
591
+ forEachChild(node, visit);
592
+ return;
593
+ }
594
+ forEachChild(sourceFile, visit);
595
+ return callbacks;
596
+ }
597
+ export function extractArrayTypes(lines) {
598
+ const arrayTypes = [];
599
+ for (let i = 0; i < lines.length; i += 1) {
600
+ const line = lines[i];
601
+ if (line === undefined) {
602
+ continue;
603
+ }
604
+ const match = line.match(LIB_REGEX_PATTERN_DTS_ARRAY_ALIAS);
605
+ if (match !== null
606
+ && match[1] !== undefined
607
+ && match[2] !== undefined) {
608
+ const arrayType = {
609
+ arrayTypeName: match[1],
610
+ elementTypeName: match[2],
611
+ lineIndex: i,
612
+ };
613
+ arrayTypes.push(arrayType);
614
+ }
615
+ }
616
+ return arrayTypes;
617
+ }
618
+ export function extractFunctionReturns(filePath, content) {
619
+ const sourceFile = parseSourceFile(filePath, content);
620
+ const returnRecords = [];
621
+ function visit(node) {
622
+ if (isFunctionDeclaration(node) === true
623
+ || isMethodDeclaration(node) === true
624
+ || isConstructorDeclaration(node) === true) {
625
+ const fnNode = node;
626
+ const typeNode = fnNode['type'];
627
+ if (typeNode !== undefined) {
628
+ let returnType = '';
629
+ let typeGuardFlag = false;
630
+ if (isTypePredicateNode(typeNode) === true) {
631
+ typeGuardFlag = true;
632
+ const predicateNode = typeNode;
633
+ if (predicateNode['type'] !== undefined
634
+ && isTypeReferenceNode(predicateNode['type']) === true
635
+ && isIdentifier(predicateNode['type']['typeName']) === true) {
636
+ returnType = predicateNode['type']['typeName']['text'];
637
+ }
638
+ }
639
+ else if (isTypeReferenceNode(typeNode) === true && isIdentifier(typeNode['typeName']) === true) {
640
+ returnType = typeNode['typeName']['text'];
641
+ }
642
+ if (returnType !== '') {
643
+ const lineNumber = sourceFile.getLineAndCharacterOfPosition(node.getStart()).line + 1;
644
+ const returnRecord = {
645
+ returnType,
646
+ isTypeGuard: typeGuardFlag,
647
+ lineNumber,
648
+ };
649
+ returnRecords.push(returnRecord);
650
+ }
651
+ }
652
+ }
653
+ forEachChild(node, visit);
654
+ return;
655
+ }
656
+ forEachChild(sourceFile, visit);
657
+ return returnRecords;
658
+ }
659
+ export function isAliasToForeignType(typeName, dtsContent, classPrefix) {
660
+ const escapedTypeName = typeName.replace(new RegExp(LIB_REGEX_PATTERN_REGEX_SPECIAL_CHARS.source, 'g'), '\\$&');
661
+ const pattern = new RegExp(`^export type ${escapedTypeName}\\s*=\\s*([^;]+);`, 'm');
662
+ const match = dtsContent.match(pattern);
663
+ if (match === null || match[1] === undefined) {
664
+ return false;
665
+ }
666
+ let rhs = match[1].trim();
667
+ rhs = rhs.replace(new RegExp(LIB_REGEX_PATTERN_ANGLE_BRACKET_GENERIC.source, 'g'), '');
668
+ rhs = rhs.replace(new RegExp(LIB_REGEX_PATTERN_EMPTY_ARRAY_BRACKETS.source, 'g'), '');
669
+ if (LIB_REGEX_PATTERN_COMPLEX_TYPE_RHS_CHARS.test(rhs) === true) {
670
+ return false;
671
+ }
672
+ const typeMatch = rhs.trim().match(LIB_REGEX_PATTERN_SINGLE_PASCAL_TYPE);
673
+ if (typeMatch === null || typeMatch[1] === undefined) {
674
+ return false;
675
+ }
676
+ const leftmostType = typeMatch[1];
677
+ if (leftmostType.includes('_') === false) {
678
+ return false;
679
+ }
680
+ if (leftmostType.startsWith(`${classPrefix}_`) === true) {
681
+ return false;
682
+ }
683
+ return true;
684
+ }
685
+ export function isLocallyDefined(typeName, dtsContent) {
686
+ const escapedTypeName = typeName.replace(new RegExp(LIB_REGEX_PATTERN_REGEX_SPECIAL_CHARS.source, 'g'), '\\$&');
687
+ const pattern = new RegExp(`^export type ${escapedTypeName}\\b`, 'm');
688
+ return pattern.test(dtsContent);
689
+ }
690
+ export function isReservedSuffix(typeName) {
691
+ return (typeName.endsWith('_Returns') === true
692
+ || typeName.endsWith('_TypeGuard') === true
693
+ || typeName.endsWith('_Return') === true
694
+ || typeName.endsWith('Returns') === true
695
+ || typeName.endsWith('TypeGuard') === true
696
+ || typeName.endsWith('Return') === true);
697
+ }
698
+ export function validateLeaf(varName, typeName, sourceSection, classPrefix) {
699
+ const stripped = stripUnderscorePrefix(varName);
700
+ const titleVar = stripped.charAt(0).toUpperCase() + stripped.slice(1);
701
+ const expectedSection = `${sourceSection}_${titleVar}`;
702
+ const expectedClass = `${classPrefix}_${titleVar}`;
703
+ if (typeName === expectedSection || typeName === expectedClass) {
704
+ return null;
705
+ }
706
+ let actualLeaf = typeName;
707
+ if (typeName.startsWith(`${sourceSection}_`) === true) {
708
+ actualLeaf = typeName.slice(sourceSection.length + 1);
709
+ }
710
+ else if (typeName.startsWith(`${classPrefix}_`) === true) {
711
+ actualLeaf = typeName.slice(classPrefix.length + 1);
712
+ }
713
+ return {
714
+ actualLeaf,
715
+ expectedLeaf: titleVar,
716
+ };
717
+ }
718
+ export function validateReturnType(returnType, typeGuardFlag) {
719
+ if (returnType.endsWith('_Return') === true || returnType.endsWith('Return') === true) {
720
+ return `Return type '${returnType}' uses banned singular 'Return' suffix; rename to use 'Returns' (plural).`;
721
+ }
722
+ if (typeGuardFlag === true) {
723
+ if (returnType.endsWith('_TypeGuard') === false && returnType.endsWith('TypeGuard') === false) {
724
+ return `Type-guard return type '${returnType}' must end in 'TypeGuard'.`;
725
+ }
726
+ }
727
+ else if (returnType.endsWith('_Returns') === false && returnType.endsWith('Returns') === false) {
728
+ if (returnType.endsWith('_TypeGuard') === true || returnType.endsWith('TypeGuard') === true) {
729
+ return `Return type '${returnType}' ends in 'TypeGuard' but the function does not use 'value is T' form; either rename to '_Returns' or rewrite as a type guard.`;
730
+ }
731
+ return `Function return type '${returnType}' must end in 'Returns' (plural).`;
732
+ }
733
+ return null;
734
+ }
735
+ export function runRulePipeline(filePath, sourceContent, dtsContent, classPrefix) {
736
+ const sectionMap = buildSourceSectionMap(filePath, sourceContent, classPrefix);
737
+ const lines = sourceContent.split('\n');
738
+ const declarations = extractBodyDeclarations(lines);
739
+ const callbacks = detectInlineTypedCallbacks(filePath, sourceContent);
740
+ const fnReturnRecords = extractFunctionReturns(filePath, sourceContent);
741
+ const violations = [];
742
+ for (const callback of callbacks) {
743
+ violations.push(`7.4: ${callback['paramName']}: ${callback['typeName']}`);
744
+ }
745
+ for (const declaration of declarations) {
746
+ const sourceSection = sectionMap.get(declaration['lineNumber']) ?? classPrefix;
747
+ if (isReservedSuffix(declaration['typeName']) === true) {
748
+ violations.push(`7.3: ${declaration['varName']}: ${declaration['typeName']}`);
749
+ continue;
750
+ }
751
+ const leafResult = validateLeaf(declaration['varName'], declaration['typeName'], sourceSection, classPrefix);
752
+ if (leafResult !== null) {
753
+ violations.push(`7.1: ${declaration['varName']}: ${declaration['typeName']}`);
754
+ }
755
+ if (isLocallyDefined(declaration['typeName'], dtsContent) === false) {
756
+ violations.push(`7.2-not-defined: ${declaration['typeName']}`);
757
+ }
758
+ else if (isAliasToForeignType(declaration['typeName'], dtsContent, classPrefix) === true) {
759
+ violations.push(`7.2-alias: ${declaration['typeName']}`);
760
+ }
761
+ }
762
+ for (const fnReturn of fnReturnRecords) {
763
+ const reason = validateReturnType(fnReturn['returnType'], fnReturn['isTypeGuard']);
764
+ if (reason !== null) {
765
+ violations.push(`7.5/6/7: ${fnReturn['returnType']}`);
766
+ }
767
+ }
768
+ return violations;
769
+ }
770
+ //# sourceMappingURL=type-declaration-engine.js.map