repopo 0.12.0 → 0.14.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 (345) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/README.md +57 -90
  3. package/THIRD-PARTY-LICENSES.txt +169 -11
  4. package/bin/dev.js +0 -0
  5. package/esm/adapters/fluidFramework.d.ts +13 -9
  6. package/esm/adapters/fluidFramework.d.ts.map +1 -1
  7. package/esm/adapters/fluidFramework.js +20 -43
  8. package/esm/adapters/fluidFramework.js.map +1 -1
  9. package/esm/api.d.ts +66 -1
  10. package/esm/api.d.ts.map +1 -1
  11. package/esm/api.js +18 -1
  12. package/esm/api.js.map +1 -1
  13. package/esm/baseCommand.d.ts.map +1 -1
  14. package/esm/baseCommand.js +2 -2
  15. package/esm/baseCommand.js.map +1 -1
  16. package/esm/commands/check-native.d.ts +5 -3
  17. package/esm/commands/check-native.d.ts.map +1 -1
  18. package/esm/commands/check-native.js +35 -7
  19. package/esm/commands/check-native.js.map +1 -1
  20. package/esm/commands/check.d.ts +8 -21
  21. package/esm/commands/check.d.ts.map +1 -1
  22. package/esm/commands/check.js +98 -154
  23. package/esm/commands/check.js.map +1 -1
  24. package/esm/commands/list.d.ts.map +1 -1
  25. package/esm/commands/list.js +1 -0
  26. package/esm/commands/list.js.map +1 -1
  27. package/esm/concurrency.d.ts +3 -0
  28. package/esm/concurrency.d.ts.map +1 -0
  29. package/esm/concurrency.js +8 -0
  30. package/esm/concurrency.js.map +1 -0
  31. package/esm/config.d.ts +10 -39
  32. package/esm/config.d.ts.map +1 -1
  33. package/esm/config.js +3 -7
  34. package/esm/config.js.map +1 -1
  35. package/esm/context.d.ts +10 -1
  36. package/esm/context.d.ts.map +1 -1
  37. package/esm/context.js +19 -1
  38. package/esm/context.js.map +1 -1
  39. package/esm/executionContractError.d.ts +4 -0
  40. package/esm/executionContractError.d.ts.map +1 -0
  41. package/esm/executionContractError.js +4 -0
  42. package/esm/executionContractError.js.map +1 -0
  43. package/esm/fileCache.d.ts +12 -0
  44. package/esm/fileCache.d.ts.map +1 -0
  45. package/esm/fileCache.js +37 -0
  46. package/esm/fileCache.js.map +1 -0
  47. package/esm/filePaths.d.ts +2 -0
  48. package/esm/filePaths.d.ts.map +1 -0
  49. package/esm/filePaths.js +9 -0
  50. package/esm/filePaths.js.map +1 -0
  51. package/esm/generators.d.ts +0 -20
  52. package/esm/generators.d.ts.map +1 -1
  53. package/esm/generators.js.map +1 -1
  54. package/esm/index.d.ts +3 -16
  55. package/esm/index.d.ts.map +1 -1
  56. package/esm/index.js +3 -17
  57. package/esm/index.js.map +1 -1
  58. package/esm/makePolicy.d.ts +20 -100
  59. package/esm/makePolicy.d.ts.map +1 -1
  60. package/esm/makePolicy.js +46 -132
  61. package/esm/makePolicy.js.map +1 -1
  62. package/esm/perf.d.ts +5 -2
  63. package/esm/perf.d.ts.map +1 -1
  64. package/esm/perf.js +10 -9
  65. package/esm/perf.js.map +1 -1
  66. package/esm/policies/CargoLicenceValidated.d.ts +4 -4
  67. package/esm/policies/CargoLicenceValidated.d.ts.map +1 -1
  68. package/esm/policies/CargoLicenceValidated.js +9 -7
  69. package/esm/policies/CargoLicenceValidated.js.map +1 -1
  70. package/esm/policies/CargoLintsConfigured.d.ts +4 -4
  71. package/esm/policies/CargoLintsConfigured.d.ts.map +1 -1
  72. package/esm/policies/CargoLintsConfigured.js +19 -15
  73. package/esm/policies/CargoLintsConfigured.js.map +1 -1
  74. package/esm/policies/CargoLockPolicy.d.ts +4 -4
  75. package/esm/policies/CargoLockPolicy.d.ts.map +1 -1
  76. package/esm/policies/CargoLockPolicy.js +15 -11
  77. package/esm/policies/CargoLockPolicy.js.map +1 -1
  78. package/esm/policies/CargoTomlRequired.d.ts +5 -5
  79. package/esm/policies/CargoTomlRequired.d.ts.map +1 -1
  80. package/esm/policies/CargoTomlRequired.js +7 -7
  81. package/esm/policies/CargoTomlRequired.js.map +1 -1
  82. package/esm/policies/CargoTomlSorted.d.ts +4 -4
  83. package/esm/policies/CargoTomlSorted.d.ts.map +1 -1
  84. package/esm/policies/CargoTomlSorted.js +21 -17
  85. package/esm/policies/CargoTomlSorted.js.map +1 -1
  86. package/esm/policies/ConditionalScripts.d.ts +10 -8
  87. package/esm/policies/ConditionalScripts.d.ts.map +1 -1
  88. package/esm/policies/ConditionalScripts.js +24 -22
  89. package/esm/policies/ConditionalScripts.js.map +1 -1
  90. package/esm/policies/ExactScripts.d.ts +8 -6
  91. package/esm/policies/ExactScripts.d.ts.map +1 -1
  92. package/esm/policies/ExactScripts.js +15 -18
  93. package/esm/policies/ExactScripts.js.map +1 -1
  94. package/esm/policies/GleamDepVersions.d.ts +5 -5
  95. package/esm/policies/GleamDepVersions.d.ts.map +1 -1
  96. package/esm/policies/GleamDepVersions.js +5 -5
  97. package/esm/policies/GleamDepVersions.js.map +1 -1
  98. package/esm/policies/GleamDocExists.d.ts +4 -4
  99. package/esm/policies/GleamDocExists.d.ts.map +1 -1
  100. package/esm/policies/GleamDocExists.js +6 -6
  101. package/esm/policies/GleamDocExists.js.map +1 -1
  102. package/esm/policies/GleamInternalModulesConfigured.d.ts +4 -4
  103. package/esm/policies/GleamInternalModulesConfigured.d.ts.map +1 -1
  104. package/esm/policies/GleamInternalModulesConfigured.js +8 -6
  105. package/esm/policies/GleamInternalModulesConfigured.js.map +1 -1
  106. package/esm/policies/GleamLicenceConfigured.d.ts +4 -4
  107. package/esm/policies/GleamLicenceConfigured.d.ts.map +1 -1
  108. package/esm/policies/GleamLicenceConfigured.js +8 -6
  109. package/esm/policies/GleamLicenceConfigured.js.map +1 -1
  110. package/esm/policies/GleamManifestCommitted.d.ts +10 -3
  111. package/esm/policies/GleamManifestCommitted.d.ts.map +1 -1
  112. package/esm/policies/GleamManifestCommitted.js +10 -9
  113. package/esm/policies/GleamManifestCommitted.js.map +1 -1
  114. package/esm/policies/GleamMonorepoConsistency.d.ts +13 -5
  115. package/esm/policies/GleamMonorepoConsistency.d.ts.map +1 -1
  116. package/esm/policies/GleamMonorepoConsistency.js +10 -10
  117. package/esm/policies/GleamMonorepoConsistency.js.map +1 -1
  118. package/esm/policies/GleamNameRestrictions.d.ts +4 -4
  119. package/esm/policies/GleamNameRestrictions.d.ts.map +1 -1
  120. package/esm/policies/GleamNameRestrictions.js +6 -6
  121. package/esm/policies/GleamNameRestrictions.js.map +1 -1
  122. package/esm/policies/GleamNoPathDepsInPublished.d.ts +4 -4
  123. package/esm/policies/GleamNoPathDepsInPublished.d.ts.map +1 -1
  124. package/esm/policies/GleamNoPathDepsInPublished.js +6 -6
  125. package/esm/policies/GleamNoPathDepsInPublished.js.map +1 -1
  126. package/esm/policies/GleamPathDepsValid.d.ts +3 -3
  127. package/esm/policies/GleamPathDepsValid.d.ts.map +1 -1
  128. package/esm/policies/GleamPathDepsValid.js +5 -5
  129. package/esm/policies/GleamPathDepsValid.js.map +1 -1
  130. package/esm/policies/GleamProjectStructure.d.ts +11 -4
  131. package/esm/policies/GleamProjectStructure.d.ts.map +1 -1
  132. package/esm/policies/GleamProjectStructure.js +7 -8
  133. package/esm/policies/GleamProjectStructure.js.map +1 -1
  134. package/esm/policies/GleamSharedDependencyVersions.d.ts +12 -4
  135. package/esm/policies/GleamSharedDependencyVersions.d.ts.map +1 -1
  136. package/esm/policies/GleamSharedDependencyVersions.js +10 -10
  137. package/esm/policies/GleamSharedDependencyVersions.js.map +1 -1
  138. package/esm/policies/GleamTomlRequired.d.ts +4 -4
  139. package/esm/policies/GleamTomlRequired.d.ts.map +1 -1
  140. package/esm/policies/GleamTomlRequired.js +5 -5
  141. package/esm/policies/GleamTomlRequired.js.map +1 -1
  142. package/esm/policies/GleamTomlSorted.d.ts +4 -4
  143. package/esm/policies/GleamTomlSorted.d.ts.map +1 -1
  144. package/esm/policies/GleamTomlSorted.js +21 -17
  145. package/esm/policies/GleamTomlSorted.js.map +1 -1
  146. package/esm/policies/GleamVersionConstraint.d.ts +4 -4
  147. package/esm/policies/GleamVersionConstraint.d.ts.map +1 -1
  148. package/esm/policies/GleamVersionConstraint.js +14 -10
  149. package/esm/policies/GleamVersionConstraint.js.map +1 -1
  150. package/esm/policies/HtmlFileHeaders.d.ts +4 -2
  151. package/esm/policies/HtmlFileHeaders.d.ts.map +1 -1
  152. package/esm/policies/HtmlFileHeaders.js +1 -1
  153. package/esm/policies/HtmlFileHeaders.js.map +1 -1
  154. package/esm/policies/JsTsFileHeaders.d.ts +4 -2
  155. package/esm/policies/JsTsFileHeaders.d.ts.map +1 -1
  156. package/esm/policies/JsTsFileHeaders.js +1 -1
  157. package/esm/policies/JsTsFileHeaders.js.map +1 -1
  158. package/esm/policies/LicenseFileExists.d.ts +10 -4
  159. package/esm/policies/LicenseFileExists.d.ts.map +1 -1
  160. package/esm/policies/LicenseFileExists.js +27 -20
  161. package/esm/policies/LicenseFileExists.js.map +1 -1
  162. package/esm/policies/MaxChangedFiles.d.ts +17 -0
  163. package/esm/policies/MaxChangedFiles.d.ts.map +1 -0
  164. package/esm/policies/MaxChangedFiles.js +22 -0
  165. package/esm/policies/MaxChangedFiles.js.map +1 -0
  166. package/esm/policies/MutuallyExclusiveScripts.d.ts +8 -6
  167. package/esm/policies/MutuallyExclusiveScripts.d.ts.map +1 -1
  168. package/esm/policies/MutuallyExclusiveScripts.js +9 -13
  169. package/esm/policies/MutuallyExclusiveScripts.js.map +1 -1
  170. package/esm/policies/NoBuildDirectory.d.ts +9 -3
  171. package/esm/policies/NoBuildDirectory.d.ts.map +1 -1
  172. package/esm/policies/NoBuildDirectory.js +8 -13
  173. package/esm/policies/NoBuildDirectory.js.map +1 -1
  174. package/esm/policies/NoJsFileExtensions.d.ts +9 -3
  175. package/esm/policies/NoJsFileExtensions.d.ts.map +1 -1
  176. package/esm/policies/NoJsFileExtensions.js +9 -14
  177. package/esm/policies/NoJsFileExtensions.js.map +1 -1
  178. package/esm/policies/NoLargeBinaryFiles.d.ts +9 -4
  179. package/esm/policies/NoLargeBinaryFiles.d.ts.map +1 -1
  180. package/esm/policies/NoLargeBinaryFiles.js +10 -16
  181. package/esm/policies/NoLargeBinaryFiles.js.map +1 -1
  182. package/esm/policies/NoPrivateWorkspaceDependencies.d.ts +10 -6
  183. package/esm/policies/NoPrivateWorkspaceDependencies.d.ts.map +1 -1
  184. package/esm/policies/NoPrivateWorkspaceDependencies.js +12 -14
  185. package/esm/policies/NoPrivateWorkspaceDependencies.js.map +1 -1
  186. package/esm/policies/NoTargetArtifacts.d.ts +9 -3
  187. package/esm/policies/NoTargetArtifacts.d.ts.map +1 -1
  188. package/esm/policies/NoTargetArtifacts.js +9 -14
  189. package/esm/policies/NoTargetArtifacts.js.map +1 -1
  190. package/esm/policies/NoUnsafeWithoutJustification.d.ts +11 -4
  191. package/esm/policies/NoUnsafeWithoutJustification.d.ts.map +1 -1
  192. package/esm/policies/NoUnsafeWithoutJustification.js +8 -9
  193. package/esm/policies/NoUnsafeWithoutJustification.js.map +1 -1
  194. package/esm/policies/NoWildcardDependencies.d.ts +5 -5
  195. package/esm/policies/NoWildcardDependencies.d.ts.map +1 -1
  196. package/esm/policies/NoWildcardDependencies.js +6 -6
  197. package/esm/policies/NoWildcardDependencies.js.map +1 -1
  198. package/esm/policies/PackageAllowedScopes.d.ts +9 -5
  199. package/esm/policies/PackageAllowedScopes.d.ts.map +1 -1
  200. package/esm/policies/PackageAllowedScopes.js +15 -16
  201. package/esm/policies/PackageAllowedScopes.js.map +1 -1
  202. package/esm/policies/PackageEsmType.d.ts +7 -5
  203. package/esm/policies/PackageEsmType.d.ts.map +1 -1
  204. package/esm/policies/PackageEsmType.js +31 -31
  205. package/esm/policies/PackageEsmType.js.map +1 -1
  206. package/esm/policies/PackageFolderName.d.ts +8 -6
  207. package/esm/policies/PackageFolderName.d.ts.map +1 -1
  208. package/esm/policies/PackageFolderName.js +13 -16
  209. package/esm/policies/PackageFolderName.js.map +1 -1
  210. package/esm/policies/PackageJsonProperties.d.ts +5 -3
  211. package/esm/policies/PackageJsonProperties.d.ts.map +1 -1
  212. package/esm/policies/PackageJsonProperties.js +6 -17
  213. package/esm/policies/PackageJsonProperties.js.map +1 -1
  214. package/esm/policies/PackageJsonRepoDirectoryProperty.d.ts +2 -7
  215. package/esm/policies/PackageJsonRepoDirectoryProperty.d.ts.map +1 -1
  216. package/esm/policies/PackageJsonRepoDirectoryProperty.js +28 -42
  217. package/esm/policies/PackageJsonRepoDirectoryProperty.js.map +1 -1
  218. package/esm/policies/PackageJsonSorted.d.ts +2 -2
  219. package/esm/policies/PackageJsonSorted.d.ts.map +1 -1
  220. package/esm/policies/PackageJsonSorted.js +15 -30
  221. package/esm/policies/PackageJsonSorted.js.map +1 -1
  222. package/esm/policies/PackageLicense.d.ts +4 -4
  223. package/esm/policies/PackageLicense.d.ts.map +1 -1
  224. package/esm/policies/PackageLicense.js +31 -52
  225. package/esm/policies/PackageLicense.js.map +1 -1
  226. package/esm/policies/PackagePrivateField.d.ts +12 -8
  227. package/esm/policies/PackagePrivateField.d.ts.map +1 -1
  228. package/esm/policies/PackagePrivateField.js +31 -23
  229. package/esm/policies/PackagePrivateField.js.map +1 -1
  230. package/esm/policies/PackageReadme.d.ts +6 -5
  231. package/esm/policies/PackageReadme.d.ts.map +1 -1
  232. package/esm/policies/PackageReadme.js +22 -59
  233. package/esm/policies/PackageReadme.js.map +1 -1
  234. package/esm/policies/PackageScripts.d.ts +26 -22
  235. package/esm/policies/PackageScripts.d.ts.map +1 -1
  236. package/esm/policies/PackageScripts.js +39 -36
  237. package/esm/policies/PackageScripts.js.map +1 -1
  238. package/esm/policies/PackageTestScripts.d.ts +10 -6
  239. package/esm/policies/PackageTestScripts.d.ts.map +1 -1
  240. package/esm/policies/PackageTestScripts.js +14 -16
  241. package/esm/policies/PackageTestScripts.js.map +1 -1
  242. package/esm/policies/PublicApiDocumented.d.ts +4 -4
  243. package/esm/policies/PublicApiDocumented.d.ts.map +1 -1
  244. package/esm/policies/PublicApiDocumented.js +10 -8
  245. package/esm/policies/PublicApiDocumented.js.map +1 -1
  246. package/esm/policies/RequireCompanionChanges.d.ts +16 -0
  247. package/esm/policies/RequireCompanionChanges.d.ts.map +1 -0
  248. package/esm/policies/RequireCompanionChanges.js +42 -0
  249. package/esm/policies/RequireCompanionChanges.js.map +1 -0
  250. package/esm/policies/RequiredGitignorePatterns.d.ts +11 -4
  251. package/esm/policies/RequiredGitignorePatterns.d.ts.map +1 -1
  252. package/esm/policies/RequiredGitignorePatterns.js +29 -36
  253. package/esm/policies/RequiredGitignorePatterns.js.map +1 -1
  254. package/esm/policies/RequiredScripts.d.ts +9 -7
  255. package/esm/policies/RequiredScripts.d.ts.map +1 -1
  256. package/esm/policies/RequiredScripts.js +24 -24
  257. package/esm/policies/RequiredScripts.js.map +1 -1
  258. package/esm/policies/RustDocExists.d.ts +4 -4
  259. package/esm/policies/RustDocExists.d.ts.map +1 -1
  260. package/esm/policies/RustDocExists.js +6 -6
  261. package/esm/policies/RustDocExists.js.map +1 -1
  262. package/esm/policies/RustToolchainExists.d.ts +11 -4
  263. package/esm/policies/RustToolchainExists.d.ts.map +1 -1
  264. package/esm/policies/RustToolchainExists.js +10 -9
  265. package/esm/policies/RustToolchainExists.js.map +1 -1
  266. package/esm/policies/RustfmtConfigExists.d.ts +11 -4
  267. package/esm/policies/RustfmtConfigExists.d.ts.map +1 -1
  268. package/esm/policies/RustfmtConfigExists.js +10 -9
  269. package/esm/policies/RustfmtConfigExists.js.map +1 -1
  270. package/esm/policies/ScriptContains.d.ts +9 -7
  271. package/esm/policies/ScriptContains.d.ts.map +1 -1
  272. package/esm/policies/ScriptContains.js +9 -13
  273. package/esm/policies/ScriptContains.js.map +1 -1
  274. package/esm/policies/SharedDependencyVersions.d.ts +9 -4
  275. package/esm/policies/SharedDependencyVersions.d.ts.map +1 -1
  276. package/esm/policies/SharedDependencyVersions.js +28 -20
  277. package/esm/policies/SharedDependencyVersions.js.map +1 -1
  278. package/esm/policies/WorkspaceInheritance.d.ts +11 -4
  279. package/esm/policies/WorkspaceInheritance.d.ts.map +1 -1
  280. package/esm/policies/WorkspaceInheritance.js +10 -11
  281. package/esm/policies/WorkspaceInheritance.js.map +1 -1
  282. package/esm/policies/WorkspaceMembersValid.d.ts +11 -4
  283. package/esm/policies/WorkspaceMembersValid.d.ts.map +1 -1
  284. package/esm/policies/WorkspaceMembersValid.js +10 -11
  285. package/esm/policies/WorkspaceMembersValid.js.map +1 -1
  286. package/esm/policies/constants.d.ts.map +1 -1
  287. package/esm/policies/constants.js +1 -1
  288. package/esm/policies/constants.js.map +1 -1
  289. package/esm/policies.d.ts +15 -5
  290. package/esm/policies.d.ts.map +1 -1
  291. package/esm/policies.js +14 -5
  292. package/esm/policies.js.map +1 -1
  293. package/esm/policy.d.ts +67 -289
  294. package/esm/policy.d.ts.map +1 -1
  295. package/esm/policy.js +1 -122
  296. package/esm/policy.js.map +1 -1
  297. package/esm/policyDefiners/defineCargoPolicy.d.ts +25 -9
  298. package/esm/policyDefiners/defineCargoPolicy.d.ts.map +1 -1
  299. package/esm/policyDefiners/defineCargoPolicy.js +10 -28
  300. package/esm/policyDefiners/defineCargoPolicy.js.map +1 -1
  301. package/esm/policyDefiners/defineFileHeaderPolicy.d.ts +27 -14
  302. package/esm/policyDefiners/defineFileHeaderPolicy.d.ts.map +1 -1
  303. package/esm/policyDefiners/defineFileHeaderPolicy.js +16 -35
  304. package/esm/policyDefiners/defineFileHeaderPolicy.js.map +1 -1
  305. package/esm/policyDefiners/defineGleamPolicy.d.ts +25 -9
  306. package/esm/policyDefiners/defineGleamPolicy.d.ts.map +1 -1
  307. package/esm/policyDefiners/defineGleamPolicy.js +10 -27
  308. package/esm/policyDefiners/defineGleamPolicy.js.map +1 -1
  309. package/esm/policyDefiners/definePackagePolicy.d.ts +24 -13
  310. package/esm/policyDefiners/definePackagePolicy.d.ts.map +1 -1
  311. package/esm/policyDefiners/definePackagePolicy.js +9 -32
  312. package/esm/policyDefiners/definePackagePolicy.js.map +1 -1
  313. package/esm/policyDefiners/spdxValidator.d.ts +4 -12
  314. package/esm/policyDefiners/spdxValidator.d.ts.map +1 -1
  315. package/esm/policyDefiners/spdxValidator.js +26 -14
  316. package/esm/policyDefiners/spdxValidator.js.map +1 -1
  317. package/esm/policyExecution.d.ts +20 -0
  318. package/esm/policyExecution.d.ts.map +1 -0
  319. package/esm/policyExecution.js +234 -0
  320. package/esm/policyExecution.js.map +1 -0
  321. package/esm/repositoryChanges.d.ts +26 -0
  322. package/esm/repositoryChanges.d.ts.map +1 -0
  323. package/esm/repositoryChanges.js +172 -0
  324. package/esm/repositoryChanges.js.map +1 -0
  325. package/esm/repositoryFiles.d.ts +6 -0
  326. package/esm/repositoryFiles.d.ts.map +1 -0
  327. package/esm/repositoryFiles.js +11 -0
  328. package/esm/repositoryFiles.js.map +1 -0
  329. package/esm/runner.d.ts +73 -47
  330. package/esm/runner.d.ts.map +1 -1
  331. package/esm/runner.js +158 -144
  332. package/esm/runner.js.map +1 -1
  333. package/esm/settlePolicyPromise.d.ts +4 -0
  334. package/esm/settlePolicyPromise.d.ts.map +1 -0
  335. package/esm/settlePolicyPromise.js +10 -0
  336. package/esm/settlePolicyPromise.js.map +1 -0
  337. package/esm/tsdoc-metadata.json +1 -1
  338. package/esm/utils/safePaths.d.ts +9 -0
  339. package/esm/utils/safePaths.d.ts.map +1 -0
  340. package/esm/utils/safePaths.js +40 -0
  341. package/esm/utils/safePaths.js.map +1 -0
  342. package/oclif.manifest.json +57 -2
  343. package/package.json +42 -27
  344. package/scripts/benchmark.mjs +341 -0
  345. package/sidecar/sidecar.mjs +388 -417
@@ -1,9 +1,9 @@
1
1
  import { type Operation } from "effection";
2
- import type { PolicyArgs, PolicyHandlerResult, PolicyShape } from "../policy.js";
2
+ import type { DefinedConfig, FilePolicyDefinition, PolicyArgs, PolicyResult } from "../policy.js";
3
3
  /**
4
4
  * A parsed Cargo.toml represented as a record of sections and values.
5
5
  *
6
- * @alpha
6
+ * @public
7
7
  */
8
8
  export type CargoToml = Record<string, unknown>;
9
9
  /**
@@ -12,13 +12,13 @@ export type CargoToml = Record<string, unknown>;
12
12
  * @remarks
13
13
  * Receives the parsed TOML content and the standard policy arguments.
14
14
  *
15
- * @alpha
15
+ * @public
16
16
  */
17
- export type CargoTomlHandler<C> = (toml: CargoToml, args: PolicyArgs<C>) => Operation<PolicyHandlerResult> | Promise<PolicyHandlerResult>;
17
+ export type CargoTomlHandler<C> = (toml: CargoToml, args: PolicyArgs<C>) => Operation<PolicyResult> | Promise<PolicyResult>;
18
18
  /**
19
19
  * Input arguments for defining a Cargo.toml policy.
20
20
  *
21
- * @alpha
21
+ * @public
22
22
  */
23
23
  export interface DefineCargoPolicyArgs<C> {
24
24
  /**
@@ -37,6 +37,7 @@ export interface DefineCargoPolicyArgs<C> {
37
37
  * Optional default configuration for the policy.
38
38
  */
39
39
  defaultConfig?: C;
40
+ requiresConfig?: boolean;
40
41
  }
41
42
  /**
42
43
  * Define a repo policy for Cargo.toml files.
@@ -45,6 +46,9 @@ export interface DefineCargoPolicyArgs<C> {
45
46
  * This is a helper function that creates a policy pre-configured to match
46
47
  * Cargo.toml files. The handler receives the parsed TOML content.
47
48
  *
49
+ * @param args - Policy metadata, parsed-TOML handler, and optional defaults.
50
+ * @returns A file policy that reads and parses matching Cargo.toml files.
51
+ *
48
52
  * @example
49
53
  * ```typescript
50
54
  * const MyCargoPolicy = defineCargoPolicy({
@@ -53,14 +57,26 @@ export interface DefineCargoPolicyArgs<C> {
53
57
  * handler: async (toml, { file }) => {
54
58
  * const pkg = toml.package as Record<string, unknown> | undefined;
55
59
  * if (!pkg?.name) {
56
- * return { error: "Missing package name", fixable: false };
60
+ * return [{ message: "Missing package name" }];
57
61
  * }
58
- * return true;
62
+ * return [];
59
63
  * },
60
64
  * });
61
65
  * ```
62
66
  *
63
- * @alpha
67
+ * @public
64
68
  */
65
- export declare function defineCargoPolicy<C = undefined>(args: DefineCargoPolicyArgs<C>): PolicyShape<C>;
69
+ export declare function defineCargoPolicy<C = void>(args: DefineCargoPolicyArgs<C> & {
70
+ defaultConfig: DefinedConfig<C>;
71
+ }): FilePolicyDefinition<C> & {
72
+ defaultConfig: DefinedConfig<C>;
73
+ };
74
+ /** Define a Cargo policy that requires explicit configuration. @public */
75
+ export declare function defineCargoPolicy<C = void>(args: DefineCargoPolicyArgs<C> & {
76
+ requiresConfig: true;
77
+ }): FilePolicyDefinition<C> & {
78
+ requiresConfig: true;
79
+ };
80
+ /** Define a Cargo policy with optional configuration. @public */
81
+ export declare function defineCargoPolicy<C = void>(args: DefineCargoPolicyArgs<C>): FilePolicyDefinition<C>;
66
82
  //# sourceMappingURL=defineCargoPolicy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"defineCargoPolicy.d.ts","sourceRoot":"","sources":["../../src/policyDefiners/defineCargoPolicy.ts"],"names":[],"mappings":"AACA,OAAO,EAAQ,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAGjD,OAAO,KAAK,EACX,UAAU,EACV,mBAAmB,EACnB,WAAW,EACX,MAAM,cAAc,CAAC;AAGtB;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEhD;;;;;;;GAOG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,CACjC,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KACf,SAAS,CAAC,mBAAmB,CAAC,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAcnE;;;;GAIG;AACH,MAAM,WAAW,qBAAqB,CAAC,CAAC;IACvC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAE7B;;OAEG;IACH,aAAa,CAAC,EAAE,CAAC,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,GAAG,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iB,CAAC,CAAC,GAAG,IAAI,EACzC,IAAI,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAAG;IAAE,cAAc,EAAE,IAAI,CAAA;CAAE,GACvD,oBAAoB,CAAC,CAAC,CAAC,GAAG;IAAE,cAAc,EAAE,IAAI,CAAA;CAAE,CAAC;AACtD,iEAAiE;AACjE,wBAAgB,iBAAiB,CAAC,CAAC,GAAG,IAAI,EACzC,IAAI,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAC5B,oBAAoB,CAAC,CAAC,CAAC,CAAC"}
@@ -1,7 +1,10 @@
1
1
  import { readFile } from "node:fs/promises";
2
2
  import { call } from "effection";
3
3
  import { resolve } from "pathe";
4
+ import { ExecutionContractError } from "../executionContractError.js";
5
+ import { readParsedFile } from "../fileCache.js";
4
6
  import { CargoTomlRegexMatch } from "../policies/constants.js";
7
+ import { settlePolicyPromise } from "../settlePolicyPromise.js";
5
8
  import { parseToml } from "./tomlParser.js";
6
9
  /**
7
10
  * Type guard to check if a value is an Effection Operation (generator).
@@ -12,30 +15,6 @@ function isOperation(value) {
12
15
  "next" in value &&
13
16
  typeof value.next === "function");
14
17
  }
15
- /**
16
- * Define a repo policy for Cargo.toml files.
17
- *
18
- * @remarks
19
- * This is a helper function that creates a policy pre-configured to match
20
- * Cargo.toml files. The handler receives the parsed TOML content.
21
- *
22
- * @example
23
- * ```typescript
24
- * const MyCargoPolicy = defineCargoPolicy({
25
- * name: "MyCargoPolicy",
26
- * description: "Ensures Cargo.toml has required fields",
27
- * handler: async (toml, { file }) => {
28
- * const pkg = toml.package as Record<string, unknown> | undefined;
29
- * if (!pkg?.name) {
30
- * return { error: "Missing package name", fixable: false };
31
- * }
32
- * return true;
33
- * },
34
- * });
35
- * ```
36
- *
37
- * @alpha
38
- */
39
18
  export function defineCargoPolicy(args) {
40
19
  const { name, description, handler: cargoHandler, defaultConfig } = args;
41
20
  return {
@@ -43,17 +22,20 @@ export function defineCargoPolicy(args) {
43
22
  description,
44
23
  match: CargoTomlRegexMatch,
45
24
  defaultConfig,
25
+ requiresConfig: args.requiresConfig,
46
26
  handler: function* (innerArgs) {
47
- const content = yield* call(() => readFile(resolve(innerArgs.root, innerArgs.file), "utf-8"));
48
- const toml = yield* call(() => parseToml(content));
27
+ const toml = yield* call(() => readParsedFile(innerArgs, "toml", async () => {
28
+ const content = await readFile(resolve(innerArgs.root, innerArgs.file), "utf-8");
29
+ return parseToml(content);
30
+ }));
49
31
  const result = cargoHandler(toml, innerArgs);
50
32
  if (result instanceof Promise) {
51
- return yield* call(() => result);
33
+ return yield* settlePolicyPromise(result);
52
34
  }
53
35
  if (isOperation(result)) {
54
36
  return yield* result;
55
37
  }
56
- throw new Error(`Unexpected handler result type: ${typeof result}`);
38
+ throw new ExecutionContractError(`Unexpected handler result type: ${typeof result}`);
57
39
  },
58
40
  };
59
41
  }
@@ -1 +1 @@
1
- {"version":3,"file":"defineCargoPolicy.js","sourceRoot":"","sources":["../../src/policyDefiners/defineCargoPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAkB,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAM/D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAsB5C;;GAEG;AACH,SAAS,WAAW,CAAI,KAAc;IACrC,OAAO,CACN,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,IAAI,KAAK;QACf,OAAQ,KAA2B,CAAC,IAAI,KAAK,UAAU,CACvD,CAAC;AACH,CAAC;AA6BD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,iBAAiB,CAChC,IAA8B;IAE9B,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,GAAG,IAAI,CAAC;IACzE,OAAO;QACN,IAAI;QACJ,WAAW;QACX,KAAK,EAAE,mBAAmB;QAC1B,aAAa;QACb,OAAO,EAAE,QAAQ,CAAC,EAAE,SAAS;YAC5B,MAAM,OAAO,GAAW,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CACxC,QAAQ,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,CAC1D,CAAC;YACF,MAAM,IAAI,GAAc,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;YAC9D,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;YAE7C,IAAI,MAAM,YAAY,OAAO,EAAE,CAAC;gBAC/B,OAAO,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC;YAClC,CAAC;YACD,IAAI,WAAW,CAAsB,MAAM,CAAC,EAAE,CAAC;gBAC9C,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC;YACtB,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,mCAAmC,OAAO,MAAM,EAAE,CAAC,CAAC;QACrE,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport { call, type Operation } from \"effection\";\nimport { resolve } from \"pathe\";\nimport { CargoTomlRegexMatch } from \"../policies/constants.js\";\nimport type {\n\tPolicyArgs,\n\tPolicyHandlerResult,\n\tPolicyShape,\n} from \"../policy.js\";\nimport { parseToml } from \"./tomlParser.js\";\n\n/**\n * A parsed Cargo.toml represented as a record of sections and values.\n *\n * @alpha\n */\nexport type CargoToml = Record<string, unknown>;\n\n/**\n * A policy handler for Cargo.toml policies.\n *\n * @remarks\n * Receives the parsed TOML content and the standard policy arguments.\n *\n * @alpha\n */\nexport type CargoTomlHandler<C> = (\n\ttoml: CargoToml,\n\targs: PolicyArgs<C>,\n) => Operation<PolicyHandlerResult> | Promise<PolicyHandlerResult>;\n\n/**\n * Type guard to check if a value is an Effection Operation (generator).\n */\nfunction isOperation<T>(value: unknown): value is Operation<T> {\n\treturn (\n\t\ttypeof value === \"object\" &&\n\t\tvalue !== null &&\n\t\t\"next\" in value &&\n\t\ttypeof (value as { next: unknown }).next === \"function\"\n\t);\n}\n\n/**\n * Input arguments for defining a Cargo.toml policy.\n *\n * @alpha\n */\nexport interface DefineCargoPolicyArgs<C> {\n\t/**\n\t * The name of the policy.\n\t */\n\tname: string;\n\n\t/**\n\t * A description of the policy's purpose.\n\t */\n\tdescription: string;\n\n\t/**\n\t * The handler function that receives the parsed Cargo.toml and policy arguments.\n\t */\n\thandler: CargoTomlHandler<C>;\n\n\t/**\n\t * Optional default configuration for the policy.\n\t */\n\tdefaultConfig?: C;\n}\n\n/**\n * Define a repo policy for Cargo.toml files.\n *\n * @remarks\n * This is a helper function that creates a policy pre-configured to match\n * Cargo.toml files. The handler receives the parsed TOML content.\n *\n * @example\n * ```typescript\n * const MyCargoPolicy = defineCargoPolicy({\n * name: \"MyCargoPolicy\",\n * description: \"Ensures Cargo.toml has required fields\",\n * handler: async (toml, { file }) => {\n * const pkg = toml.package as Record<string, unknown> | undefined;\n * if (!pkg?.name) {\n * return { error: \"Missing package name\", fixable: false };\n * }\n * return true;\n * },\n * });\n * ```\n *\n * @alpha\n */\nexport function defineCargoPolicy<C = undefined>(\n\targs: DefineCargoPolicyArgs<C>,\n): PolicyShape<C> {\n\tconst { name, description, handler: cargoHandler, defaultConfig } = args;\n\treturn {\n\t\tname,\n\t\tdescription,\n\t\tmatch: CargoTomlRegexMatch,\n\t\tdefaultConfig,\n\t\thandler: function* (innerArgs) {\n\t\t\tconst content: string = yield* call(() =>\n\t\t\t\treadFile(resolve(innerArgs.root, innerArgs.file), \"utf-8\"),\n\t\t\t);\n\t\t\tconst toml: CargoToml = yield* call(() => parseToml(content));\n\t\t\tconst result = cargoHandler(toml, innerArgs);\n\n\t\t\tif (result instanceof Promise) {\n\t\t\t\treturn yield* call(() => result);\n\t\t\t}\n\t\t\tif (isOperation<PolicyHandlerResult>(result)) {\n\t\t\t\treturn yield* result;\n\t\t\t}\n\t\t\tthrow new Error(`Unexpected handler result type: ${typeof result}`);\n\t\t},\n\t};\n}\n"]}
1
+ {"version":3,"file":"defineCargoPolicy.js","sourceRoot":"","sources":["../../src/policyDefiners/defineCargoPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAkB,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAO/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAsB5C;;GAEG;AACH,SAAS,WAAW,CAAI,KAAc;IACrC,OAAO,CACN,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,IAAI,KAAK;QACf,OAAQ,KAA2B,CAAC,IAAI,KAAK,UAAU,CACvD,CAAC;AACH,CAAC;AAoED,MAAM,UAAU,iBAAiB,CAChC,IAA8B;IAE9B,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,GAAG,IAAI,CAAC;IACzE,OAAO;QACN,IAAI;QACJ,WAAW;QACX,KAAK,EAAE,mBAAmB;QAC1B,aAAa;QACb,cAAc,EAAE,IAAI,CAAC,cAAc;QACnC,OAAO,EAAE,QAAQ,CAAC,EAAE,SAAS;YAC5B,MAAM,IAAI,GAAc,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CACxC,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,IAAI,EAAE;gBAC5C,MAAM,OAAO,GAAG,MAAM,QAAQ,CAC7B,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,EACvC,OAAO,CACP,CAAC;gBACF,OAAO,SAAS,CAAC,OAAO,CAAC,CAAC;YAC3B,CAAC,CAAC,CACF,CAAC;YACF,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;YAE7C,IAAI,MAAM,YAAY,OAAO,EAAE,CAAC;gBAC/B,OAAO,KAAK,CAAC,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC;YAC3C,CAAC;YACD,IAAI,WAAW,CAAe,MAAM,CAAC,EAAE,CAAC;gBACvC,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC;YACtB,CAAC;YACD,MAAM,IAAI,sBAAsB,CAC/B,mCAAmC,OAAO,MAAM,EAAE,CAClD,CAAC;QACH,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport { call, type Operation } from \"effection\";\nimport { resolve } from \"pathe\";\nimport { ExecutionContractError } from \"../executionContractError.js\";\nimport { readParsedFile } from \"../fileCache.js\";\nimport { CargoTomlRegexMatch } from \"../policies/constants.js\";\nimport type {\n\tDefinedConfig,\n\tFilePolicyDefinition,\n\tPolicyArgs,\n\tPolicyResult,\n} from \"../policy.js\";\nimport { settlePolicyPromise } from \"../settlePolicyPromise.js\";\nimport { parseToml } from \"./tomlParser.js\";\n\n/**\n * A parsed Cargo.toml represented as a record of sections and values.\n *\n * @public\n */\nexport type CargoToml = Record<string, unknown>;\n\n/**\n * A policy handler for Cargo.toml policies.\n *\n * @remarks\n * Receives the parsed TOML content and the standard policy arguments.\n *\n * @public\n */\nexport type CargoTomlHandler<C> = (\n\ttoml: CargoToml,\n\targs: PolicyArgs<C>,\n) => Operation<PolicyResult> | Promise<PolicyResult>;\n\n/**\n * Type guard to check if a value is an Effection Operation (generator).\n */\nfunction isOperation<T>(value: unknown): value is Operation<T> {\n\treturn (\n\t\ttypeof value === \"object\" &&\n\t\tvalue !== null &&\n\t\t\"next\" in value &&\n\t\ttypeof (value as { next: unknown }).next === \"function\"\n\t);\n}\n\n/**\n * Input arguments for defining a Cargo.toml policy.\n *\n * @public\n */\nexport interface DefineCargoPolicyArgs<C> {\n\t/**\n\t * The name of the policy.\n\t */\n\tname: string;\n\n\t/**\n\t * A description of the policy's purpose.\n\t */\n\tdescription: string;\n\n\t/**\n\t * The handler function that receives the parsed Cargo.toml and policy arguments.\n\t */\n\thandler: CargoTomlHandler<C>;\n\n\t/**\n\t * Optional default configuration for the policy.\n\t */\n\tdefaultConfig?: C;\n\trequiresConfig?: boolean;\n}\n\n/**\n * Define a repo policy for Cargo.toml files.\n *\n * @remarks\n * This is a helper function that creates a policy pre-configured to match\n * Cargo.toml files. The handler receives the parsed TOML content.\n *\n * @param args - Policy metadata, parsed-TOML handler, and optional defaults.\n * @returns A file policy that reads and parses matching Cargo.toml files.\n *\n * @example\n * ```typescript\n * const MyCargoPolicy = defineCargoPolicy({\n * name: \"MyCargoPolicy\",\n * description: \"Ensures Cargo.toml has required fields\",\n * handler: async (toml, { file }) => {\n * const pkg = toml.package as Record<string, unknown> | undefined;\n * if (!pkg?.name) {\n * return [{ message: \"Missing package name\" }];\n * }\n * return [];\n * },\n * });\n * ```\n *\n * @public\n */\nexport function defineCargoPolicy<C = void>(\n\targs: DefineCargoPolicyArgs<C> & { defaultConfig: DefinedConfig<C> },\n): FilePolicyDefinition<C> & { defaultConfig: DefinedConfig<C> };\n/** Define a Cargo policy that requires explicit configuration. @public */\nexport function defineCargoPolicy<C = void>(\n\targs: DefineCargoPolicyArgs<C> & { requiresConfig: true },\n): FilePolicyDefinition<C> & { requiresConfig: true };\n/** Define a Cargo policy with optional configuration. @public */\nexport function defineCargoPolicy<C = void>(\n\targs: DefineCargoPolicyArgs<C>,\n): FilePolicyDefinition<C>;\nexport function defineCargoPolicy<C = void>(\n\targs: DefineCargoPolicyArgs<C>,\n): FilePolicyDefinition<C> {\n\tconst { name, description, handler: cargoHandler, defaultConfig } = args;\n\treturn {\n\t\tname,\n\t\tdescription,\n\t\tmatch: CargoTomlRegexMatch,\n\t\tdefaultConfig,\n\t\trequiresConfig: args.requiresConfig,\n\t\thandler: function* (innerArgs) {\n\t\t\tconst toml: CargoToml = yield* call(() =>\n\t\t\t\treadParsedFile(innerArgs, \"toml\", async () => {\n\t\t\t\t\tconst content = await readFile(\n\t\t\t\t\t\tresolve(innerArgs.root, innerArgs.file),\n\t\t\t\t\t\t\"utf-8\",\n\t\t\t\t\t);\n\t\t\t\t\treturn parseToml(content);\n\t\t\t\t}),\n\t\t\t);\n\t\t\tconst result = cargoHandler(toml, innerArgs);\n\n\t\t\tif (result instanceof Promise) {\n\t\t\t\treturn yield* settlePolicyPromise(result);\n\t\t\t}\n\t\t\tif (isOperation<PolicyResult>(result)) {\n\t\t\t\treturn yield* result;\n\t\t\t}\n\t\t\tthrow new ExecutionContractError(\n\t\t\t\t`Unexpected handler result type: ${typeof result}`,\n\t\t\t);\n\t\t},\n\t};\n}\n"]}
@@ -1,6 +1,8 @@
1
- import type { PolicyShape } from "../policy.js";
1
+ import type { FilePolicyDefinition } from "../policy.js";
2
2
  /**
3
- * @alpha
3
+ * Header text required by a file-header policy.
4
+ *
5
+ * @public
4
6
  */
5
7
  export interface FileHeaderPolicyConfig {
6
8
  /**
@@ -19,13 +21,13 @@ export interface FileHeaderPolicyConfig {
19
21
  * This interface extends FileHeaderPolicyConfig and adds formatting-specific
20
22
  * properties to control how headers are inserted into different file types.
21
23
  *
22
- * @alpha
24
+ * @public
23
25
  */
24
26
  export interface FileHeaderGeneratorConfig extends Partial<FileHeaderPolicyConfig> {
25
27
  /** Regular expression that matches files this header generator applies to */
26
28
  match: RegExp;
27
29
  /**
28
- * Regex matching header prefix (e.g. `/*!\r?\n`)
30
+ * Regex matching the header prefix, such as a block-comment opener.
29
31
  */
30
32
  headerStart?: RegExp;
31
33
  /**
@@ -52,7 +54,7 @@ export interface FileHeaderGeneratorConfig extends Partial<FileHeaderPolicyConfi
52
54
  /**
53
55
  * Input arguments for defining a file header policy.
54
56
  *
55
- * @alpha
57
+ * @public
56
58
  */
57
59
  export interface DefineFileHeaderPolicyArgs {
58
60
  /**
@@ -67,10 +69,17 @@ export interface DefineFileHeaderPolicyArgs {
67
69
  * Configuration for how headers are detected and inserted.
68
70
  */
69
71
  config: FileHeaderGeneratorConfig;
72
+ /** Complete default instance configuration, if the policy is usable without an override. */
73
+ defaultConfig?: FileHeaderPolicyConfig;
70
74
  }
71
75
  /**
72
- * Given a {@link FileHeaderPolicyConfig}, produces a function that detects correct file headers
73
- * and returns an error string if the header is missing or incorrect.
76
+ * Creates a file-header policy that detects missing or incorrect headers and can replace them.
77
+ *
78
+ * Supply {@link FileHeaderPolicyConfig} when configuring the policy, unless
79
+ * the definition supplies a complete default.
80
+ *
81
+ * @param args - Policy metadata and header matching and replacement rules.
82
+ * @returns A file policy configured for the supplied file types.
74
83
  *
75
84
  * @example
76
85
  * ```typescript
@@ -81,12 +90,16 @@ export interface DefineFileHeaderPolicyArgs {
81
90
  * });
82
91
  * ```
83
92
  *
84
- * @alpha
85
- */
86
- export declare function defineFileHeaderPolicy(args: DefineFileHeaderPolicyArgs): PolicyShape<FileHeaderPolicyConfig>;
87
- /**
88
- * Alias for defineFileHeaderPolicy.
89
- * @alpha
93
+ * @public
90
94
  */
91
- export declare const fileHeaderPolicy: typeof defineFileHeaderPolicy;
95
+ export declare function defineFileHeaderPolicy(args: DefineFileHeaderPolicyArgs & {
96
+ defaultConfig: FileHeaderPolicyConfig;
97
+ }): FilePolicyDefinition<FileHeaderPolicyConfig> & {
98
+ requiresConfig: true;
99
+ defaultConfig: FileHeaderPolicyConfig;
100
+ };
101
+ /** Define a header policy that requires explicit header configuration. @public */
102
+ export declare function defineFileHeaderPolicy(args: DefineFileHeaderPolicyArgs): FilePolicyDefinition<FileHeaderPolicyConfig> & {
103
+ requiresConfig: true;
104
+ };
92
105
  //# sourceMappingURL=defineFileHeaderPolicy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"defineFileHeaderPolicy.d.ts","sourceRoot":"","sources":["../../src/policyDefiners/defineFileHeaderPolicy.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAkC,WAAW,EAAE,MAAM,cAAc,CAAC;AAIhF;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACtC;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,yBAChB,SAAQ,OAAO,CAAC,sBAAsB,CAAC;IACvC,6EAA6E;IAC7E,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;;;OAMG;IACH,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,sBAAsB,KAAK,MAAM,CAAC;CACtE;AAED;;;;GAIG;AACH,MAAM,WAAW,0BAA0B;IAC1C;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,MAAM,EAAE,yBAAyB,CAAC;CAClC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,sBAAsB,CACrC,IAAI,EAAE,0BAA0B,GAC9B,WAAW,CAAC,sBAAsB,CAAC,CAqErC;AAED;;;GAGG;AACH,eAAO,MAAM,gBAAgB,+BAAyB,CAAC"}
1
+ {"version":3,"file":"defineFileHeaderPolicy.d.ts","sourceRoot":"","sources":["../../src/policyDefiners/defineFileHeaderPolicy.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAiB,MAAM,cAAc,CAAC;AAKxE;;;;GAIG;AACH,MAAM,WAAW,sBAAsB;IACtC;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,yBAChB,SAAQ,OAAO,CAAC,sBAAsB,CAAC;IACvC,6EAA6E;IAC7E,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;;;OAMG;IACH,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,sBAAsB,KAAK,MAAM,CAAC;CACtE;AAED;;;;GAIG;AACH,MAAM,WAAW,0BAA0B;IAC1C;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,MAAM,EAAE,yBAAyB,CAAC;IAClC,4FAA4F;IAC5F,aAAa,CAAC,EAAE,sBAAsB,CAAC;CACvC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,sBAAsB,CACrC,IAAI,EAAE,0BAA0B,GAAG;IAAE,aAAa,EAAE,sBAAsB,CAAA;CAAE,GAC1E,oBAAoB,CAAC,sBAAsB,CAAC,GAAG;IACjD,cAAc,EAAE,IAAI,CAAC;IACrB,aAAa,EAAE,sBAAsB,CAAC;CACtC,CAAC;AACF,kFAAkF;AAClF,wBAAgB,sBAAsB,CACrC,IAAI,EAAE,0BAA0B,GAC9B,oBAAoB,CAAC,sBAAsB,CAAC,GAAG;IAAE,cAAc,EAAE,IAAI,CAAA;CAAE,CAAC"}
@@ -1,23 +1,9 @@
1
1
  import { readFile, writeFile } from "node:fs/promises";
2
2
  import { EOL as newline } from "node:os";
3
3
  import { call } from "effection";
4
- import { extname, resolve as resolvePath } from "pathe";
4
+ import { extname } from "pathe";
5
+ import { resolveRepoFilePath } from "../utils/safePaths.js";
5
6
  const trailingSpaces = /\s*\\r\?\\n/;
6
- /**
7
- * Given a {@link FileHeaderPolicyConfig}, produces a function that detects correct file headers
8
- * and returns an error string if the header is missing or incorrect.
9
- *
10
- * @example
11
- * ```typescript
12
- * const MyHeaderPolicy = defineFileHeaderPolicy({
13
- * name: "MyHeaderPolicy",
14
- * description: "Ensures files have required headers",
15
- * config: { match: /\.ts$/, lineStart: /\/\/ /, lineEnd: /\r?\n/, replacer: ... },
16
- * });
17
- * ```
18
- *
19
- * @alpha
20
- */
21
7
  export function defineFileHeaderPolicy(args) {
22
8
  const { name, description, config } = args;
23
9
  const pre = config.headerStart?.source ?? "";
@@ -35,44 +21,39 @@ export function defineFileHeaderPolicy(args) {
35
21
  name,
36
22
  description,
37
23
  match: config.match,
24
+ requiresConfig: true,
25
+ defaultConfig: args.defaultConfig,
38
26
  handler: function* ({ file, root, resolve, config: policyConfig }) {
39
27
  if (policyConfig === undefined) {
40
- return true;
28
+ throw new TypeError(`${name} requires config.`);
41
29
  }
42
30
  const regex = new RegExp(`^${pre}${toRegex(policyConfig.headerText)}(${toRegex(policyConfig.autoGenText ?? config.autoGenText ?? "")})?${post}`);
43
- const failResult = {
44
- name,
45
- file,
46
- autoFixable: true,
47
- errorMessages: [],
48
- };
31
+ const filePath = resolveRepoFilePath(root, file);
32
+ const failResult = [];
49
33
  // TODO: Consider reading only the first 512B or so since headers are typically
50
34
  // at the beginning of the file.
51
- const filePath = resolvePath(root, file);
52
35
  const content = yield* call(() => readFile(filePath, { encoding: "utf8" }));
53
36
  const failed = !regex.test(content);
54
37
  if (failed) {
55
- failResult.errorMessages.push(`${extname(file)} file missing header`);
38
+ failResult.push({
39
+ message: `${extname(file)} file missing header`,
40
+ fixStatus: "available",
41
+ });
56
42
  }
57
43
  if (failed) {
58
44
  if (resolve) {
59
45
  const newContent = config.replacer(content, policyConfig);
60
46
  yield* call(() => writeFile(filePath, newContent));
61
- const fixResult = {
62
- ...failResult,
63
- resolved: true,
64
- };
47
+ const fixResult = failResult.map((finding) => ({
48
+ ...finding,
49
+ fixStatus: "fixed",
50
+ }));
65
51
  return fixResult;
66
52
  }
67
53
  return failResult;
68
54
  }
69
- return true;
55
+ return [];
70
56
  },
71
57
  };
72
58
  }
73
- /**
74
- * Alias for defineFileHeaderPolicy.
75
- * @alpha
76
- */
77
- export const fileHeaderPolicy = defineFileHeaderPolicy;
78
59
  //# sourceMappingURL=defineFileHeaderPolicy.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"defineFileHeaderPolicy.js","sourceRoot":"","sources":["../../src/policyDefiners/defineFileHeaderPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,OAAO,CAAC;AAGxD,MAAM,cAAc,GAAG,aAAa,CAAC;AAmFrC;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,sBAAsB,CACrC,IAAgC;IAEhC,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAC3C,MAAM,GAAG,GAAG,MAAM,CAAC,WAAW,EAAE,MAAM,IAAI,EAAE,CAAC;IAC7C,MAAM,KAAK,GAAG,MAAM,CAAC,SAAS,CAAC,MAA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AQ,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CACxC,CAAC;YACF,MAAM,MAAM,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAEpC,IAAI,MAAM,EAAE,CAAC;gBACZ,UAAU,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;YACvE,CAAC;YAED,IAAI,MAAM,EAAE,CAAC;gBACZ,IAAI,OAAO,EAAE,CAAC;oBACb,MAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;oBAC1D,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC;oBAEnD,MAAM,SAAS,GAAoB;wBAClC,GAAG,UAAU;wBACb,QAAQ,EAAE,IAAI;qBACd,CAAC;oBAEF,OAAO,SAAS,CAAC;gBAClB,CAAC;gBACD,OAAO,UAAU,CAAC;YACnB,CAAC;YAED,OAAO,IAAI,CAAC;QACb,CAAC;KACD,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,sBAAsB,CAAC","sourcesContent":["import { readFile, writeFile } from \"node:fs/promises\";\nimport { EOL as newline } from \"node:os\";\nimport { call } from \"effection\";\nimport { extname, resolve as resolvePath } from \"pathe\";\nimport type { PolicyFailure, PolicyFixResult, PolicyShape } from \"../policy.js\";\n\nconst trailingSpaces = /\\s*\\\\r\\?\\\\n/;\n\n/**\n * @alpha\n */\nexport interface FileHeaderPolicyConfig {\n\t/**\n\t * The text to use as the header.\n\t */\n\theaderText: string;\n\n\t/**\n\t * An optional string that will be appended to the headerText.\n\t */\n\tautoGenText?: string;\n}\n\n/**\n * Configuration for generating file headers with specific formatting rules.\n *\n * @remarks\n * This interface extends FileHeaderPolicyConfig and adds formatting-specific\n * properties to control how headers are inserted into different file types.\n *\n * @alpha\n */\nexport interface FileHeaderGeneratorConfig\n\textends Partial<FileHeaderPolicyConfig> {\n\t/** Regular expression that matches files this header generator applies to */\n\tmatch: RegExp;\n\n\t/**\n\t * Regex matching header prefix (e.g. `/*!\\r?\\n`)\n\t */\n\theaderStart?: RegExp;\n\n\t/**\n\t * Regex matching beginning of each line (e.g. ' * ')\n\t */\n\tlineStart: RegExp;\n\n\t/**\n\t * Regex matching the end of each line (e.g., `\\r?\\n`)\n\t */\n\tlineEnd: RegExp;\n\n\t/**\n\t * Regex matching the header postfix.\n\t */\n\theaderEnd?: RegExp;\n\n\t/**\n\t * Function that generates the properly formatted header content for insertion into files.\n\t *\n\t * @param content - The original file content\n\t * @param config - The file header policy configuration\n\t * @returns The formatted header string to insert\n\t */\n\treplacer: (content: string, config: FileHeaderPolicyConfig) => string;\n}\n\n/**\n * Input arguments for defining a file header policy.\n *\n * @alpha\n */\nexport interface DefineFileHeaderPolicyArgs {\n\t/**\n\t * The name of the policy.\n\t */\n\tname: string;\n\n\t/**\n\t * A description of the policy's purpose.\n\t */\n\tdescription: string;\n\n\t/**\n\t * Configuration for how headers are detected and inserted.\n\t */\n\tconfig: FileHeaderGeneratorConfig;\n}\n\n/**\n * Given a {@link FileHeaderPolicyConfig}, produces a function that detects correct file headers\n * and returns an error string if the header is missing or incorrect.\n *\n * @example\n * ```typescript\n * const MyHeaderPolicy = defineFileHeaderPolicy({\n * name: \"MyHeaderPolicy\",\n * description: \"Ensures files have required headers\",\n * config: { match: /\\.ts$/, lineStart: /\\/\\/ /, lineEnd: /\\r?\\n/, replacer: ... },\n * });\n * ```\n *\n * @alpha\n */\nexport function defineFileHeaderPolicy(\n\targs: DefineFileHeaderPolicyArgs,\n): PolicyShape<FileHeaderPolicyConfig> {\n\tconst { name, description, config } = args;\n\tconst pre = config.headerStart?.source ?? \"\";\n\tconst start = config.lineStart.source;\n\tconst end = config.lineEnd.source;\n\tconst post = config.headerEnd?.source ?? \"\";\n\n\t// Helper which constructs a matching RegExp from a given multiline string.\n\t// (See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping)\n\tconst toRegex = (text: string): string =>\n\t\ttext\n\t\t\t.split(newline)\n\t\t\t.map(\n\t\t\t\t(line) =>\n\t\t\t\t\t`${start}${line.replace(/[$()*+.?[\\\\\\]^{|}]/g, \"\\\\$&\")}${end}`,\n\t\t\t)\n\t\t\t.join(\"\")\n\t\t\t.replace(trailingSpaces, \"\\\\r?\\\\n\"); // Trim trailing spaces at end-of-line.\n\n\treturn {\n\t\tname,\n\t\tdescription,\n\t\tmatch: config.match,\n\t\thandler: function* ({ file, root, resolve, config: policyConfig }) {\n\t\t\tif (policyConfig === undefined) {\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tconst regex = new RegExp(\n\t\t\t\t`^${pre}${toRegex(policyConfig.headerText)}(${toRegex(policyConfig.autoGenText ?? config.autoGenText ?? \"\")})?${post}`,\n\t\t\t);\n\n\t\t\tconst failResult: PolicyFailure = {\n\t\t\t\tname,\n\t\t\t\tfile,\n\t\t\t\tautoFixable: true,\n\t\t\t\terrorMessages: [],\n\t\t\t};\n\n\t\t\t// TODO: Consider reading only the first 512B or so since headers are typically\n\t\t\t// at the beginning of the file.\n\t\t\tconst filePath = resolvePath(root, file);\n\t\t\tconst content = yield* call(() =>\n\t\t\t\treadFile(filePath, { encoding: \"utf8\" }),\n\t\t\t);\n\t\t\tconst failed = !regex.test(content);\n\n\t\t\tif (failed) {\n\t\t\t\tfailResult.errorMessages.push(`${extname(file)} file missing header`);\n\t\t\t}\n\n\t\t\tif (failed) {\n\t\t\t\tif (resolve) {\n\t\t\t\t\tconst newContent = config.replacer(content, policyConfig);\n\t\t\t\t\tyield* call(() => writeFile(filePath, newContent));\n\n\t\t\t\t\tconst fixResult: PolicyFixResult = {\n\t\t\t\t\t\t...failResult,\n\t\t\t\t\t\tresolved: true,\n\t\t\t\t\t};\n\n\t\t\t\t\treturn fixResult;\n\t\t\t\t}\n\t\t\t\treturn failResult;\n\t\t\t}\n\n\t\t\treturn true;\n\t\t},\n\t};\n}\n\n/**\n * Alias for defineFileHeaderPolicy.\n * @alpha\n */\nexport const fileHeaderPolicy = defineFileHeaderPolicy;\n"]}
1
+ {"version":3,"file":"defineFileHeaderPolicy.js","sourceRoot":"","sources":["../../src/policyDefiners/defineFileHeaderPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,cAAc,GAAG,aAAa,CAAC;AAqHrC,MAAM,UAAU,sBAAsB,CACrC,IAAgC;IAEhC,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAC3C,MAAM,GAAG,GAAG,MAAM,CAAC,WAAW,EAAE,MAAM,IAAI,EAAE,CAAC;IAC7C,MAAM,KAAK,GAAG,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC;IACtC,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;IAClC,MAAM,IAAI,GAAG,MAAM,CAAC,SAAS,EAAE,MAAM,IAAI,EAAE,CAAC;IAE5C,2EAA2E;IAC3E,mGAAmG;IACnG,MAAM,OAAO,GAAG,CAAC,IAAY,EAAU,EAAE,CACxC,IAAI;SACF,KAAK,CAAC,OAAO,CAAC;SACd,GAAG,CACH,CAAC,IAAI,EAAE,EAAE,CACR,GAAG,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,GAAG,GAAG,EAAE,CAC/D;SACA,IAAI,C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MAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;oBAC1D,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC;oBACnD,MAAM,SAAS,GAAoB,UAAU,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;wBAC/D,GAAG,OAAO;wBACV,SAAS,EAAE,OAAO;qBAClB,CAAC,CAAC,CAAC;oBACJ,OAAO,SAAS,CAAC;gBAClB,CAAC;gBACD,OAAO,UAAU,CAAC;YACnB,CAAC;YACD,OAAO,EAAE,CAAC;QACX,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { readFile, writeFile } from \"node:fs/promises\";\nimport { EOL as newline } from \"node:os\";\nimport { call } from \"effection\";\nimport { extname } from \"pathe\";\nimport type { FilePolicyDefinition, PolicyFinding } from \"../policy.js\";\nimport { resolveRepoFilePath } from \"../utils/safePaths.js\";\n\nconst trailingSpaces = /\\s*\\\\r\\?\\\\n/;\n\n/**\n * Header text required by a file-header policy.\n *\n * @public\n */\nexport interface FileHeaderPolicyConfig {\n\t/**\n\t * The text to use as the header.\n\t */\n\theaderText: string;\n\n\t/**\n\t * An optional string that will be appended to the headerText.\n\t */\n\tautoGenText?: string;\n}\n\n/**\n * Configuration for generating file headers with specific formatting rules.\n *\n * @remarks\n * This interface extends FileHeaderPolicyConfig and adds formatting-specific\n * properties to control how headers are inserted into different file types.\n *\n * @public\n */\nexport interface FileHeaderGeneratorConfig\n\textends Partial<FileHeaderPolicyConfig> {\n\t/** Regular expression that matches files this header generator applies to */\n\tmatch: RegExp;\n\n\t/**\n\t * Regex matching the header prefix, such as a block-comment opener.\n\t */\n\theaderStart?: RegExp;\n\n\t/**\n\t * Regex matching beginning of each line (e.g. ' * ')\n\t */\n\tlineStart: RegExp;\n\n\t/**\n\t * Regex matching the end of each line (e.g., `\\r?\\n`)\n\t */\n\tlineEnd: RegExp;\n\n\t/**\n\t * Regex matching the header postfix.\n\t */\n\theaderEnd?: RegExp;\n\n\t/**\n\t * Function that generates the properly formatted header content for insertion into files.\n\t *\n\t * @param content - The original file content\n\t * @param config - The file header policy configuration\n\t * @returns The formatted header string to insert\n\t */\n\treplacer: (content: string, config: FileHeaderPolicyConfig) => string;\n}\n\n/**\n * Input arguments for defining a file header policy.\n *\n * @public\n */\nexport interface DefineFileHeaderPolicyArgs {\n\t/**\n\t * The name of the policy.\n\t */\n\tname: string;\n\n\t/**\n\t * A description of the policy's purpose.\n\t */\n\tdescription: string;\n\n\t/**\n\t * Configuration for how headers are detected and inserted.\n\t */\n\tconfig: FileHeaderGeneratorConfig;\n\t/** Complete default instance configuration, if the policy is usable without an override. */\n\tdefaultConfig?: FileHeaderPolicyConfig;\n}\n\n/**\n * Creates a file-header policy that detects missing or incorrect headers and can replace them.\n *\n * Supply {@link FileHeaderPolicyConfig} when configuring the policy, unless\n * the definition supplies a complete default.\n *\n * @param args - Policy metadata and header matching and replacement rules.\n * @returns A file policy configured for the supplied file types.\n *\n * @example\n * ```typescript\n * const MyHeaderPolicy = defineFileHeaderPolicy({\n * name: \"MyHeaderPolicy\",\n * description: \"Ensures files have required headers\",\n * config: { match: /\\.ts$/, lineStart: /\\/\\/ /, lineEnd: /\\r?\\n/, replacer: ... },\n * });\n * ```\n *\n * @public\n */\nexport function defineFileHeaderPolicy(\n\targs: DefineFileHeaderPolicyArgs & { defaultConfig: FileHeaderPolicyConfig },\n): FilePolicyDefinition<FileHeaderPolicyConfig> & {\n\trequiresConfig: true;\n\tdefaultConfig: FileHeaderPolicyConfig;\n};\n/** Define a header policy that requires explicit header configuration. @public */\nexport function defineFileHeaderPolicy(\n\targs: DefineFileHeaderPolicyArgs,\n): FilePolicyDefinition<FileHeaderPolicyConfig> & { requiresConfig: true };\nexport function defineFileHeaderPolicy(\n\targs: DefineFileHeaderPolicyArgs,\n): FilePolicyDefinition<FileHeaderPolicyConfig> & { requiresConfig: true } {\n\tconst { name, description, config } = args;\n\tconst pre = config.headerStart?.source ?? \"\";\n\tconst start = config.lineStart.source;\n\tconst end = config.lineEnd.source;\n\tconst post = config.headerEnd?.source ?? \"\";\n\n\t// Helper which constructs a matching RegExp from a given multiline string.\n\t// (See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping)\n\tconst toRegex = (text: string): string =>\n\t\ttext\n\t\t\t.split(newline)\n\t\t\t.map(\n\t\t\t\t(line) =>\n\t\t\t\t\t`${start}${line.replace(/[$()*+.?[\\\\\\]^{|}]/g, \"\\\\$&\")}${end}`,\n\t\t\t)\n\t\t\t.join(\"\")\n\t\t\t.replace(trailingSpaces, \"\\\\r?\\\\n\"); // Trim trailing spaces at end-of-line.\n\n\treturn {\n\t\tname,\n\t\tdescription,\n\t\tmatch: config.match,\n\t\trequiresConfig: true,\n\t\tdefaultConfig: args.defaultConfig,\n\t\thandler: function* ({ file, root, resolve, config: policyConfig }) {\n\t\t\tif (policyConfig === undefined) {\n\t\t\t\tthrow new TypeError(`${name} requires config.`);\n\t\t\t}\n\n\t\t\tconst regex = new RegExp(\n\t\t\t\t`^${pre}${toRegex(policyConfig.headerText)}(${toRegex(policyConfig.autoGenText ?? config.autoGenText ?? \"\")})?${post}`,\n\t\t\t);\n\t\t\tconst filePath = resolveRepoFilePath(root, file);\n\t\t\tconst failResult: PolicyFinding[] = [];\n\t\t\t// TODO: Consider reading only the first 512B or so since headers are typically\n\t\t\t// at the beginning of the file.\n\t\t\tconst content = yield* call(() =>\n\t\t\t\treadFile(filePath, { encoding: \"utf8\" }),\n\t\t\t);\n\t\t\tconst failed = !regex.test(content);\n\n\t\t\tif (failed) {\n\t\t\t\tfailResult.push({\n\t\t\t\t\tmessage: `${extname(file)} file missing header`,\n\t\t\t\t\tfixStatus: \"available\",\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (failed) {\n\t\t\t\tif (resolve) {\n\t\t\t\t\tconst newContent = config.replacer(content, policyConfig);\n\t\t\t\t\tyield* call(() => writeFile(filePath, newContent));\n\t\t\t\t\tconst fixResult: PolicyFinding[] = failResult.map((finding) => ({\n\t\t\t\t\t\t...finding,\n\t\t\t\t\t\tfixStatus: \"fixed\",\n\t\t\t\t\t}));\n\t\t\t\t\treturn fixResult;\n\t\t\t\t}\n\t\t\t\treturn failResult;\n\t\t\t}\n\t\t\treturn [];\n\t\t},\n\t};\n}\n"]}
@@ -1,9 +1,9 @@
1
1
  import { type Operation } from "effection";
2
- import type { PolicyArgs, PolicyHandlerResult, PolicyShape } from "../policy.js";
2
+ import type { DefinedConfig, FilePolicyDefinition, PolicyArgs, PolicyResult } from "../policy.js";
3
3
  /**
4
4
  * A parsed gleam.toml represented as a record of sections and values.
5
5
  *
6
- * @alpha
6
+ * @public
7
7
  */
8
8
  export type GleamToml = Record<string, unknown>;
9
9
  /**
@@ -12,13 +12,13 @@ export type GleamToml = Record<string, unknown>;
12
12
  * @remarks
13
13
  * Receives the parsed TOML content and the standard policy arguments.
14
14
  *
15
- * @alpha
15
+ * @public
16
16
  */
17
- export type GleamTomlHandler<C> = (toml: GleamToml, args: PolicyArgs<C>) => Operation<PolicyHandlerResult> | Promise<PolicyHandlerResult>;
17
+ export type GleamTomlHandler<C> = (toml: GleamToml, args: PolicyArgs<C>) => Operation<PolicyResult> | Promise<PolicyResult>;
18
18
  /**
19
19
  * Input arguments for defining a gleam.toml policy.
20
20
  *
21
- * @alpha
21
+ * @public
22
22
  */
23
23
  export interface DefineGleamPolicyArgs<C> {
24
24
  /**
@@ -37,6 +37,7 @@ export interface DefineGleamPolicyArgs<C> {
37
37
  * Optional default configuration for the policy.
38
38
  */
39
39
  defaultConfig?: C;
40
+ requiresConfig?: boolean;
40
41
  }
41
42
  /**
42
43
  * Define a repo policy for gleam.toml files.
@@ -45,6 +46,9 @@ export interface DefineGleamPolicyArgs<C> {
45
46
  * This is a helper function that creates a policy pre-configured to match
46
47
  * gleam.toml files. The handler receives the parsed TOML content.
47
48
  *
49
+ * @param args - Policy metadata, parsed-TOML handler, and optional defaults.
50
+ * @returns A file policy that reads and parses matching gleam.toml files.
51
+ *
48
52
  * @example
49
53
  * ```typescript
50
54
  * const MyGleamPolicy = defineGleamPolicy({
@@ -52,14 +56,26 @@ export interface DefineGleamPolicyArgs<C> {
52
56
  * description: "Ensures gleam.toml has required fields",
53
57
  * handler: async (toml, { file }) => {
54
58
  * if (!toml.name) {
55
- * return { error: "Missing name field", fixable: false };
59
+ * return [{ message: "Missing name field" }];
56
60
  * }
57
- * return true;
61
+ * return [];
58
62
  * },
59
63
  * });
60
64
  * ```
61
65
  *
62
- * @alpha
66
+ * @public
63
67
  */
64
- export declare function defineGleamPolicy<C = undefined>(args: DefineGleamPolicyArgs<C>): PolicyShape<C>;
68
+ export declare function defineGleamPolicy<C = void>(args: DefineGleamPolicyArgs<C> & {
69
+ defaultConfig: DefinedConfig<C>;
70
+ }): FilePolicyDefinition<C> & {
71
+ defaultConfig: DefinedConfig<C>;
72
+ };
73
+ /** Define a Gleam policy that requires explicit configuration. @public */
74
+ export declare function defineGleamPolicy<C = void>(args: DefineGleamPolicyArgs<C> & {
75
+ requiresConfig: true;
76
+ }): FilePolicyDefinition<C> & {
77
+ requiresConfig: true;
78
+ };
79
+ /** Define a Gleam policy with optional configuration. @public */
80
+ export declare function defineGleamPolicy<C = void>(args: DefineGleamPolicyArgs<C>): FilePolicyDefinition<C>;
65
81
  //# sourceMappingURL=defineGleamPolicy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"defineGleamPolicy.d.ts","sourceRoot":"","sources":["../../src/policyDefiners/defineGleamPolicy.ts"],"names":[],"mappings":"AACA,OAAO,EAAQ,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAGjD,OAAO,KAAK,EACX,UAAU,EACV,mBAAmB,EACnB,WAAW,EACX,MAAM,cAAc,CAAC;AAGtB;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM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OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAE7B;;OAEG;IACH,aAAa,CAAC,EAAE,CAAC,CAAC;IAClB,cAAc,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,GAAG,IAAI,EACzC,IAAI,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAAG;IAAE,aAAa,EAAE,aAAa,CAAC,CAAC,CAAC,CAAA;CAAE,GAClE,oBAAoB,CAAC,CAAC,CAAC,GAAG;IAAE,aAAa,EAAE,aAAa,CAAC,CAAC,CAAC,CAAA;CAAE,CAAC;AACjE,0EAA0E;AAC1E,wBAAgB,iBAAiB,CAAC,CAAC,GAAG,IAAI,EACzC,IAAI,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAAG;IAAE,cAAc,EAAE,IAAI,CAAA;CAAE,GACvD,oBAAoB,CAAC,CAAC,CAAC,GAAG;IAAE,cAAc,EAAE,IAAI,CAAA;CAAE,CAAC;AACtD,iEAAiE;AACjE,wBAAgB,iBAAiB,CAAC,CAAC,GAAG,IAAI,EACzC,IAAI,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAC5B,oBAAoB,CAAC,CAAC,CAAC,CAAC"}
@@ -1,7 +1,10 @@
1
1
  import { readFile } from "node:fs/promises";
2
2
  import { call } from "effection";
3
3
  import { resolve } from "pathe";
4
+ import { ExecutionContractError } from "../executionContractError.js";
5
+ import { readParsedFile } from "../fileCache.js";
4
6
  import { GleamTomlRegexMatch } from "../policies/constants.js";
7
+ import { settlePolicyPromise } from "../settlePolicyPromise.js";
5
8
  import { parseToml } from "./tomlParser.js";
6
9
  /**
7
10
  * Type guard to check if a value is an Effection Operation (generator).
@@ -12,29 +15,6 @@ function isOperation(value) {
12
15
  "next" in value &&
13
16
  typeof value.next === "function");
14
17
  }
15
- /**
16
- * Define a repo policy for gleam.toml files.
17
- *
18
- * @remarks
19
- * This is a helper function that creates a policy pre-configured to match
20
- * gleam.toml files. The handler receives the parsed TOML content.
21
- *
22
- * @example
23
- * ```typescript
24
- * const MyGleamPolicy = defineGleamPolicy({
25
- * name: "MyGleamPolicy",
26
- * description: "Ensures gleam.toml has required fields",
27
- * handler: async (toml, { file }) => {
28
- * if (!toml.name) {
29
- * return { error: "Missing name field", fixable: false };
30
- * }
31
- * return true;
32
- * },
33
- * });
34
- * ```
35
- *
36
- * @alpha
37
- */
38
18
  export function defineGleamPolicy(args) {
39
19
  const { name, description, handler: gleamHandler, defaultConfig } = args;
40
20
  return {
@@ -42,17 +22,20 @@ export function defineGleamPolicy(args) {
42
22
  description,
43
23
  match: GleamTomlRegexMatch,
44
24
  defaultConfig,
25
+ requiresConfig: args.requiresConfig,
45
26
  handler: function* (innerArgs) {
46
- const content = yield* call(() => readFile(resolve(innerArgs.root, innerArgs.file), "utf-8"));
47
- const toml = yield* call(() => parseToml(content));
27
+ const toml = yield* call(() => readParsedFile(innerArgs, "toml", async () => {
28
+ const content = await readFile(resolve(innerArgs.root, innerArgs.file), "utf-8");
29
+ return parseToml(content);
30
+ }));
48
31
  const result = gleamHandler(toml, innerArgs);
49
32
  if (result instanceof Promise) {
50
- return yield* call(() => result);
33
+ return yield* settlePolicyPromise(result);
51
34
  }
52
35
  if (isOperation(result)) {
53
36
  return yield* result;
54
37
  }
55
- throw new Error(`Unexpected handler result type: ${typeof result}`);
38
+ throw new ExecutionContractError(`Unexpected handler result type: ${typeof result}`);
56
39
  },
57
40
  };
58
41
  }
@@ -1 +1 @@
1
- {"version":3,"file":"defineGleamPolicy.js","sourceRoot":"","sources":["../../src/policyDefiners/defineGleamPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAkB,M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AM,CAAC;YACtB,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,mCAAmC,OAAO,MAAM,EAAE,CAAC,CAAC;QACrE,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport { call, type Operation } from \"effection\";\nimport { resolve } from \"pathe\";\nimport { GleamTomlRegexMatch } from \"../policies/constants.js\";\nimport type {\n\tPolicyArgs,\n\tPolicyHandlerResult,\n\tPolicyShape,\n} from \"../policy.js\";\nimport { parseToml } from \"./tomlParser.js\";\n\n/**\n * A parsed gleam.toml represented as a record of sections and values.\n *\n * @alpha\n */\nexport type GleamToml = Record<string, unknown>;\n\n/**\n * A policy handler for gleam.toml policies.\n *\n * @remarks\n * Receives the parsed TOML content and the standard policy arguments.\n *\n * @alpha\n */\nexport type GleamTomlHandler<C> = (\n\ttoml: GleamToml,\n\targs: PolicyArgs<C>,\n) => Operation<PolicyHandlerResult> | Promise<PolicyHandlerResult>;\n\n/**\n * Type guard to check if a value is an Effection Operation (generator).\n */\nfunction isOperation<T>(value: unknown): value is Operation<T> {\n\treturn (\n\t\ttypeof value === \"object\" &&\n\t\tvalue !== null &&\n\t\t\"next\" in value &&\n\t\ttypeof (value as { next: unknown }).next === \"function\"\n\t);\n}\n\n/**\n * Input arguments for defining a gleam.toml policy.\n *\n * @alpha\n */\nexport interface DefineGleamPolicyArgs<C> {\n\t/**\n\t * The name of the policy.\n\t */\n\tname: string;\n\n\t/**\n\t * A description of the policy's purpose.\n\t */\n\tdescription: string;\n\n\t/**\n\t * The handler function that receives the parsed gleam.toml and policy arguments.\n\t */\n\thandler: GleamTomlHandler<C>;\n\n\t/**\n\t * Optional default configuration for the policy.\n\t */\n\tdefaultConfig?: C;\n}\n\n/**\n * Define a repo policy for gleam.toml files.\n *\n * @remarks\n * This is a helper function that creates a policy pre-configured to match\n * gleam.toml files. The handler receives the parsed TOML content.\n *\n * @example\n * ```typescript\n * const MyGleamPolicy = defineGleamPolicy({\n * name: \"MyGleamPolicy\",\n * description: \"Ensures gleam.toml has required fields\",\n * handler: async (toml, { file }) => {\n * if (!toml.name) {\n * return { error: \"Missing name field\", fixable: false };\n * }\n * return true;\n * },\n * });\n * ```\n *\n * @alpha\n */\nexport function defineGleamPolicy<C = undefined>(\n\targs: DefineGleamPolicyArgs<C>,\n): PolicyShape<C> {\n\tconst { name, description, handler: gleamHandler, defaultConfig } = args;\n\treturn {\n\t\tname,\n\t\tdescription,\n\t\tmatch: GleamTomlRegexMatch,\n\t\tdefaultConfig,\n\t\thandler: function* (innerArgs) {\n\t\t\tconst content: string = yield* call(() =>\n\t\t\t\treadFile(resolve(innerArgs.root, innerArgs.file), \"utf-8\"),\n\t\t\t);\n\t\t\tconst toml: GleamToml = yield* call(() => parseToml(content));\n\t\t\tconst result = gleamHandler(toml, innerArgs);\n\n\t\t\tif (result instanceof Promise) {\n\t\t\t\treturn yield* call(() => result);\n\t\t\t}\n\t\t\tif (isOperation<PolicyHandlerResult>(result)) {\n\t\t\t\treturn yield* result;\n\t\t\t}\n\t\t\tthrow new Error(`Unexpected handler result type: ${typeof result}`);\n\t\t},\n\t};\n}\n"]}
1
+ {"version":3,"file":"defineGleamPolicy.js","sourceRoot":"","sources":["../../src/policyDefiners/defineGleamPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAkB,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAO/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAsB5C;;GAEG;AACH,SAA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from \"effection\";\nimport { resolve } from \"pathe\";\nimport { ExecutionContractError } from \"../executionContractError.js\";\nimport { readParsedFile } from \"../fileCache.js\";\nimport { GleamTomlRegexMatch } from \"../policies/constants.js\";\nimport type {\n\tDefinedConfig,\n\tFilePolicyDefinition,\n\tPolicyArgs,\n\tPolicyResult,\n} from \"../policy.js\";\nimport { settlePolicyPromise } from \"../settlePolicyPromise.js\";\nimport { parseToml } from \"./tomlParser.js\";\n\n/**\n * A parsed gleam.toml represented as a record of sections and values.\n *\n * @public\n */\nexport type GleamToml = Record<string, unknown>;\n\n/**\n * A policy handler for gleam.toml policies.\n *\n * @remarks\n * Receives the parsed TOML content and the standard policy arguments.\n *\n * @public\n */\nexport type GleamTomlHandler<C> = (\n\ttoml: GleamToml,\n\targs: PolicyArgs<C>,\n) => Operation<PolicyResult> | Promise<PolicyResult>;\n\n/**\n * Type guard to check if a value is an Effection Operation (generator).\n */\nfunction isOperation<T>(value: unknown): value is Operation<T> {\n\treturn (\n\t\ttypeof value === \"object\" &&\n\t\tvalue !== null &&\n\t\t\"next\" in value &&\n\t\ttypeof (value as { next: unknown }).next === \"function\"\n\t);\n}\n\n/**\n * Input arguments for defining a gleam.toml policy.\n *\n * @public\n */\nexport interface DefineGleamPolicyArgs<C> {\n\t/**\n\t * The name of the policy.\n\t */\n\tname: string;\n\n\t/**\n\t * A description of the policy's purpose.\n\t */\n\tdescription: string;\n\n\t/**\n\t * The handler function that receives the parsed gleam.toml and policy arguments.\n\t */\n\thandler: GleamTomlHandler<C>;\n\n\t/**\n\t * Optional default configuration for the policy.\n\t */\n\tdefaultConfig?: C;\n\trequiresConfig?: boolean;\n}\n\n/**\n * Define a repo policy for gleam.toml files.\n *\n * @remarks\n * This is a helper function that creates a policy pre-configured to match\n * gleam.toml files. The handler receives the parsed TOML content.\n *\n * @param args - Policy metadata, parsed-TOML handler, and optional defaults.\n * @returns A file policy that reads and parses matching gleam.toml files.\n *\n * @example\n * ```typescript\n * const MyGleamPolicy = defineGleamPolicy({\n * name: \"MyGleamPolicy\",\n * description: \"Ensures gleam.toml has required fields\",\n * handler: async (toml, { file }) => {\n * if (!toml.name) {\n * return [{ message: \"Missing name field\" }];\n * }\n * return [];\n * },\n * });\n * ```\n *\n * @public\n */\nexport function defineGleamPolicy<C = void>(\n\targs: DefineGleamPolicyArgs<C> & { defaultConfig: DefinedConfig<C> },\n): FilePolicyDefinition<C> & { defaultConfig: DefinedConfig<C> };\n/** Define a Gleam policy that requires explicit configuration. @public */\nexport function defineGleamPolicy<C = void>(\n\targs: DefineGleamPolicyArgs<C> & { requiresConfig: true },\n): FilePolicyDefinition<C> & { requiresConfig: true };\n/** Define a Gleam policy with optional configuration. @public */\nexport function defineGleamPolicy<C = void>(\n\targs: DefineGleamPolicyArgs<C>,\n): FilePolicyDefinition<C>;\nexport function defineGleamPolicy<C = void>(\n\targs: DefineGleamPolicyArgs<C>,\n): FilePolicyDefinition<C> {\n\tconst { name, description, handler: gleamHandler, defaultConfig } = args;\n\treturn {\n\t\tname,\n\t\tdescription,\n\t\tmatch: GleamTomlRegexMatch,\n\t\tdefaultConfig,\n\t\trequiresConfig: args.requiresConfig,\n\t\thandler: function* (innerArgs) {\n\t\t\tconst toml: GleamToml = yield* call(() =>\n\t\t\t\treadParsedFile(innerArgs, \"toml\", async () => {\n\t\t\t\t\tconst content = await readFile(\n\t\t\t\t\t\tresolve(innerArgs.root, innerArgs.file),\n\t\t\t\t\t\t\"utf-8\",\n\t\t\t\t\t);\n\t\t\t\t\treturn parseToml(content);\n\t\t\t\t}),\n\t\t\t);\n\t\t\tconst result = gleamHandler(toml, innerArgs);\n\n\t\t\tif (result instanceof Promise) {\n\t\t\t\treturn yield* settlePolicyPromise(result);\n\t\t\t}\n\t\t\tif (isOperation<PolicyResult>(result)) {\n\t\t\t\treturn yield* result;\n\t\t\t}\n\t\t\tthrow new ExecutionContractError(\n\t\t\t\t`Unexpected handler result type: ${typeof result}`,\n\t\t\t);\n\t\t},\n\t};\n}\n"]}