@halonicjs/testing 0.0.0-stage → 0.1.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 (384) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +1 -0
  3. package/README.md +40 -2
  4. package/dist/adapters/http-kit/src/address-class.d.ts +34 -0
  5. package/dist/adapters/http-kit/src/address-class.js +109 -0
  6. package/dist/adapters/http-kit/src/index.d.ts +2 -0
  7. package/dist/adapters/http-kit/src/index.js +2 -0
  8. package/dist/adapters/http-kit/src/ip-address.d.ts +23 -0
  9. package/dist/adapters/http-kit/src/ip-address.js +89 -0
  10. package/dist/adapters/integration-kit/src/declaration.d.ts +14 -0
  11. package/dist/adapters/integration-kit/src/declaration.js +77 -0
  12. package/dist/adapters/integration-kit/src/host.d.ts +28 -0
  13. package/dist/adapters/integration-kit/src/host.js +30 -0
  14. package/dist/adapters/integration-kit/src/index.d.ts +14 -0
  15. package/dist/adapters/integration-kit/src/index.js +21 -0
  16. package/dist/adapters/integration-kit/src/leak-attempt.d.ts +14 -0
  17. package/dist/adapters/integration-kit/src/leak-attempt.js +16 -0
  18. package/dist/adapters/integration-kit/src/limited-http.d.ts +49 -0
  19. package/dist/adapters/integration-kit/src/limited-http.js +182 -0
  20. package/dist/adapters/integration-kit/src/load-problem.d.ts +20 -0
  21. package/dist/adapters/integration-kit/src/load-problem.js +1 -0
  22. package/dist/adapters/integration-kit/src/loader.d.ts +104 -0
  23. package/dist/adapters/integration-kit/src/loader.js +219 -0
  24. package/dist/adapters/integration-kit/src/local-address.d.ts +15 -0
  25. package/dist/adapters/integration-kit/src/local-address.js +25 -0
  26. package/dist/adapters/integration-kit/src/own-request.d.ts +33 -0
  27. package/dist/adapters/integration-kit/src/own-request.js +36 -0
  28. package/dist/adapters/integration-kit/src/plugin-load.d.ts +14 -0
  29. package/dist/adapters/integration-kit/src/plugin-load.js +58 -0
  30. package/dist/adapters/integration-kit/src/policy.d.ts +55 -0
  31. package/dist/adapters/integration-kit/src/policy.js +37 -0
  32. package/dist/adapters/integration-kit/src/request-body.d.ts +38 -0
  33. package/dist/adapters/integration-kit/src/request-body.js +68 -0
  34. package/dist/adapters/integration-kit/src/request-log.d.ts +25 -0
  35. package/dist/adapters/integration-kit/src/request-log.js +17 -0
  36. package/dist/adapters/integration-kit/src/response-body.d.ts +23 -0
  37. package/dist/adapters/integration-kit/src/response-body.js +117 -0
  38. package/dist/adapters/integration-kit/src/scoped-tokens.d.ts +14 -0
  39. package/dist/adapters/integration-kit/src/scoped-tokens.js +27 -0
  40. package/dist/adapters/integration-kit/src/secret-filter.d.ts +84 -0
  41. package/dist/adapters/integration-kit/src/secret-filter.js +205 -0
  42. package/dist/adapters/integration-kit/src/secret-in-request.d.ts +59 -0
  43. package/dist/adapters/integration-kit/src/secret-in-request.js +133 -0
  44. package/dist/adapters/integration-kit/src/secret-placement.d.ts +36 -0
  45. package/dist/adapters/integration-kit/src/secret-placement.js +190 -0
  46. package/dist/adapters/integration-kit/src/wait.d.ts +16 -0
  47. package/dist/adapters/integration-kit/src/wait.js +35 -0
  48. package/dist/core/events/src/add-usage.d.ts +10 -0
  49. package/dist/core/events/src/add-usage.js +27 -0
  50. package/dist/core/events/src/agent-resume.d.ts +24 -0
  51. package/dist/core/events/src/agent-resume.js +1 -0
  52. package/dist/core/events/src/home-path.d.ts +13 -0
  53. package/dist/core/events/src/home-path.js +26 -0
  54. package/dist/core/events/src/index.d.ts +13 -0
  55. package/dist/core/events/src/index.js +7 -0
  56. package/dist/core/events/src/run-basics.d.ts +205 -0
  57. package/dist/core/events/src/run-basics.js +1 -0
  58. package/dist/core/events/src/run-event.d.ts +434 -0
  59. package/dist/core/events/src/run-event.js +1 -0
  60. package/dist/core/events/src/run-summary.d.ts +108 -0
  61. package/dist/core/events/src/run-summary.js +1 -0
  62. package/dist/core/events/src/sandbox-blocked.d.ts +42 -0
  63. package/dist/core/events/src/sandbox-blocked.js +26 -0
  64. package/dist/core/events/src/sandbox-opened-read.d.ts +17 -0
  65. package/dist/core/events/src/sandbox-opened-read.js +63 -0
  66. package/dist/core/events/src/sandbox-opened.d.ts +94 -0
  67. package/dist/core/events/src/sandbox-opened.js +52 -0
  68. package/dist/core/events/src/summarize.d.ts +14 -0
  69. package/dist/core/events/src/summarize.js +188 -0
  70. package/dist/core/events/src/timeline-entry.d.ts +21 -0
  71. package/dist/core/events/src/timeline-entry.js +105 -0
  72. package/dist/core/events/src/upgrade.d.ts +23 -0
  73. package/dist/core/events/src/upgrade.js +49 -0
  74. package/dist/core/format/src/compact.d.ts +30 -0
  75. package/dist/core/format/src/compact.js +72 -0
  76. package/dist/core/format/src/index.d.ts +37 -0
  77. package/dist/core/format/src/index.js +23 -0
  78. package/dist/core/format/src/integration/index.d.ts +6 -0
  79. package/dist/core/format/src/integration/index.js +9 -0
  80. package/dist/core/format/src/json-schema.d.ts +26 -0
  81. package/dist/core/format/src/json-schema.js +48 -0
  82. package/dist/core/format/src/kind.d.ts +65 -0
  83. package/dist/core/format/src/kind.js +1 -0
  84. package/dist/core/format/src/kinds/agent/kind.d.ts +4 -0
  85. package/dist/core/format/src/kinds/agent/kind.js +10 -0
  86. package/dist/core/format/src/kinds/agent/sandbox-fields.d.ts +89 -0
  87. package/dist/core/format/src/kinds/agent/sandbox-fields.js +197 -0
  88. package/dist/core/format/src/kinds/agent/schema.d.ts +147 -0
  89. package/dist/core/format/src/kinds/agent/schema.js +107 -0
  90. package/dist/core/format/src/kinds/agent/working-folder-start.d.ts +74 -0
  91. package/dist/core/format/src/kinds/agent/working-folder-start.js +312 -0
  92. package/dist/core/format/src/kinds/collection/kind.d.ts +8 -0
  93. package/dist/core/format/src/kinds/collection/kind.js +14 -0
  94. package/dist/core/format/src/kinds/collection/schema.d.ts +89 -0
  95. package/dist/core/format/src/kinds/collection/schema.js +90 -0
  96. package/dist/core/format/src/kinds/connector/is-local.d.ts +10 -0
  97. package/dist/core/format/src/kinds/connector/is-local.js +43 -0
  98. package/dist/core/format/src/kinds/connector/kind.d.ts +4 -0
  99. package/dist/core/format/src/kinds/connector/kind.js +119 -0
  100. package/dist/core/format/src/kinds/connector/schema.d.ts +50 -0
  101. package/dist/core/format/src/kinds/connector/schema.js +92 -0
  102. package/dist/core/format/src/kinds/deployments/kind.d.ts +4 -0
  103. package/dist/core/format/src/kinds/deployments/kind.js +25 -0
  104. package/dist/core/format/src/kinds/deployments/schema.d.ts +37 -0
  105. package/dist/core/format/src/kinds/deployments/schema.js +42 -0
  106. package/dist/core/format/src/kinds/hub/kind.d.ts +4 -0
  107. package/dist/core/format/src/kinds/hub/kind.js +10 -0
  108. package/dist/core/format/src/kinds/hub/schema.d.ts +54 -0
  109. package/dist/core/format/src/kinds/hub/schema.js +34 -0
  110. package/dist/core/format/src/kinds/integration/kind.d.ts +16 -0
  111. package/dist/core/format/src/kinds/integration/kind.js +138 -0
  112. package/dist/core/format/src/kinds/integration/parse-sheet.d.ts +19 -0
  113. package/dist/core/format/src/kinds/integration/parse-sheet.js +24 -0
  114. package/dist/core/format/src/kinds/integration/policy.d.ts +67 -0
  115. package/dist/core/format/src/kinds/integration/policy.js +268 -0
  116. package/dist/core/format/src/kinds/integration/schema.d.ts +233 -0
  117. package/dist/core/format/src/kinds/integration/schema.js +233 -0
  118. package/dist/core/format/src/kinds/knowledge/kind.d.ts +4 -0
  119. package/dist/core/format/src/kinds/knowledge/kind.js +13 -0
  120. package/dist/core/format/src/kinds/knowledge/schema.d.ts +18 -0
  121. package/dist/core/format/src/kinds/knowledge/schema.js +25 -0
  122. package/dist/core/format/src/kinds/models/kind.d.ts +4 -0
  123. package/dist/core/format/src/kinds/models/kind.js +10 -0
  124. package/dist/core/format/src/kinds/models/schema.d.ts +92 -0
  125. package/dist/core/format/src/kinds/models/schema.js +38 -0
  126. package/dist/core/format/src/kinds/plugin/backend.d.ts +22 -0
  127. package/dist/core/format/src/kinds/plugin/backend.js +31 -0
  128. package/dist/core/format/src/kinds/plugin/checks.d.ts +13 -0
  129. package/dist/core/format/src/kinds/plugin/checks.js +131 -0
  130. package/dist/core/format/src/kinds/plugin/kind.d.ts +8 -0
  131. package/dist/core/format/src/kinds/plugin/kind.js +16 -0
  132. package/dist/core/format/src/kinds/plugin/problems.d.ts +24 -0
  133. package/dist/core/format/src/kinds/plugin/problems.js +65 -0
  134. package/dist/core/format/src/kinds/plugin/schema.d.ts +542 -0
  135. package/dist/core/format/src/kinds/plugin/schema.js +261 -0
  136. package/dist/core/format/src/kinds/plugin/setting-values.d.ts +17 -0
  137. package/dist/core/format/src/kinds/plugin/setting-values.js +38 -0
  138. package/dist/core/format/src/kinds/plugin/ui-checks.d.ts +8 -0
  139. package/dist/core/format/src/kinds/plugin/ui-checks.js +94 -0
  140. package/dist/core/format/src/kinds/provider/kind.d.ts +4 -0
  141. package/dist/core/format/src/kinds/provider/kind.js +24 -0
  142. package/dist/core/format/src/kinds/provider/schema.d.ts +17 -0
  143. package/dist/core/format/src/kinds/provider/schema.js +22 -0
  144. package/dist/core/format/src/kinds/routine/kind.d.ts +8 -0
  145. package/dist/core/format/src/kinds/routine/kind.js +25 -0
  146. package/dist/core/format/src/kinds/routine/schema.d.ts +84 -0
  147. package/dist/core/format/src/kinds/routine/schema.js +93 -0
  148. package/dist/core/format/src/kinds/runtime/kind.d.ts +4 -0
  149. package/dist/core/format/src/kinds/runtime/kind.js +13 -0
  150. package/dist/core/format/src/kinds/runtime/schema.d.ts +10 -0
  151. package/dist/core/format/src/kinds/runtime/schema.js +12 -0
  152. package/dist/core/format/src/kinds/skill/kind.d.ts +4 -0
  153. package/dist/core/format/src/kinds/skill/kind.js +10 -0
  154. package/dist/core/format/src/kinds/skill/schema.d.ts +17 -0
  155. package/dist/core/format/src/kinds/skill/schema.js +17 -0
  156. package/dist/core/format/src/kinds/skill/scripts-folder.d.ts +27 -0
  157. package/dist/core/format/src/kinds/skill/scripts-folder.js +37 -0
  158. package/dist/core/format/src/kinds/workflow/kind.d.ts +8 -0
  159. package/dist/core/format/src/kinds/workflow/kind.js +14 -0
  160. package/dist/core/format/src/kinds/workflow/schema.d.ts +162 -0
  161. package/dist/core/format/src/kinds/workflow/schema.js +106 -0
  162. package/dist/core/format/src/kinds/workflow-test/kind.d.ts +4 -0
  163. package/dist/core/format/src/kinds/workflow-test/kind.js +14 -0
  164. package/dist/core/format/src/kinds/workflow-test/schema.d.ts +67 -0
  165. package/dist/core/format/src/kinds/workflow-test/schema.js +59 -0
  166. package/dist/core/format/src/kinds/workspace/kind.d.ts +4 -0
  167. package/dist/core/format/src/kinds/workspace/kind.js +10 -0
  168. package/dist/core/format/src/kinds/workspace/schema.d.ts +72 -0
  169. package/dist/core/format/src/kinds/workspace/schema.js +66 -0
  170. package/dist/core/format/src/parse-file.d.ts +69 -0
  171. package/dist/core/format/src/parse-file.js +105 -0
  172. package/dist/core/format/src/recording/format.d.ts +81 -0
  173. package/dist/core/format/src/recording/format.js +102 -0
  174. package/dist/core/format/src/recording/index.d.ts +1 -0
  175. package/dist/core/format/src/recording/index.js +3 -0
  176. package/dist/core/format/src/registry.d.ts +64 -0
  177. package/dist/core/format/src/registry.js +61 -0
  178. package/dist/core/format/src/reserved.d.ts +20 -0
  179. package/dist/core/format/src/reserved.js +30 -0
  180. package/dist/core/format/src/shared/fields.d.ts +37 -0
  181. package/dist/core/format/src/shared/fields.js +54 -0
  182. package/dist/core/format/src/shared/guard.d.ts +32 -0
  183. package/dist/core/format/src/shared/guard.js +16 -0
  184. package/dist/core/format/src/shared/key-in-value.d.ts +28 -0
  185. package/dist/core/format/src/shared/key-in-value.js +82 -0
  186. package/dist/core/format/src/shared/legacy-keys.d.ts +8 -0
  187. package/dist/core/format/src/shared/legacy-keys.js +17 -0
  188. package/dist/core/format/src/shared/program-start.d.ts +60 -0
  189. package/dist/core/format/src/shared/program-start.js +99 -0
  190. package/dist/core/format/src/shared/relative-path.d.ts +29 -0
  191. package/dist/core/format/src/shared/relative-path.js +50 -0
  192. package/dist/core/format/src/shared/secret-name.d.ts +24 -0
  193. package/dist/core/format/src/shared/secret-name.js +107 -0
  194. package/dist/core/format/src/source.d.ts +16 -0
  195. package/dist/core/format/src/source.js +73 -0
  196. package/dist/core/ports/src/agent-placement-store.d.ts +74 -0
  197. package/dist/core/ports/src/agent-placement-store.js +27 -0
  198. package/dist/core/ports/src/blob-store.d.ts +33 -0
  199. package/dist/core/ports/src/blob-store.js +2 -0
  200. package/dist/core/ports/src/cant-try-error.d.ts +35 -0
  201. package/dist/core/ports/src/cant-try-error.js +44 -0
  202. package/dist/core/ports/src/chat.d.ts +127 -0
  203. package/dist/core/ports/src/chat.js +1 -0
  204. package/dist/core/ports/src/clock.d.ts +7 -0
  205. package/dist/core/ports/src/clock.js +2 -0
  206. package/dist/core/ports/src/connection-settings-store.d.ts +57 -0
  207. package/dist/core/ports/src/connection-settings-store.js +2 -0
  208. package/dist/core/ports/src/connector-client.d.ts +259 -0
  209. package/dist/core/ports/src/connector-client.js +2 -0
  210. package/dist/core/ports/src/coordination.d.ts +84 -0
  211. package/dist/core/ports/src/coordination.js +2 -0
  212. package/dist/core/ports/src/definition-store.d.ts +208 -0
  213. package/dist/core/ports/src/definition-store.js +122 -0
  214. package/dist/core/ports/src/digest.d.ts +14 -0
  215. package/dist/core/ports/src/digest.js +2 -0
  216. package/dist/core/ports/src/folder-reader.d.ts +89 -0
  217. package/dist/core/ports/src/folder-reader.js +2 -0
  218. package/dist/core/ports/src/harness-bridge-server.d.ts +189 -0
  219. package/dist/core/ports/src/harness-bridge-server.js +37 -0
  220. package/dist/core/ports/src/harness.d.ts +250 -0
  221. package/dist/core/ports/src/harness.js +45 -0
  222. package/dist/core/ports/src/http-client.d.ts +27 -0
  223. package/dist/core/ports/src/http-client.js +2 -0
  224. package/dist/core/ports/src/id-generator.d.ts +14 -0
  225. package/dist/core/ports/src/id-generator.js +2 -0
  226. package/dist/core/ports/src/index.d.ts +37 -0
  227. package/dist/core/ports/src/index.js +36 -0
  228. package/dist/core/ports/src/integration.d.ts +178 -0
  229. package/dist/core/ports/src/integration.js +13 -0
  230. package/dist/core/ports/src/knowledge-provider.d.ts +65 -0
  231. package/dist/core/ports/src/knowledge-provider.js +2 -0
  232. package/dist/core/ports/src/llm-cache.d.ts +13 -0
  233. package/dist/core/ports/src/llm-cache.js +2 -0
  234. package/dist/core/ports/src/llm-provider.d.ts +184 -0
  235. package/dist/core/ports/src/llm-provider.js +136 -0
  236. package/dist/core/ports/src/model-price.d.ts +34 -0
  237. package/dist/core/ports/src/model-price.js +25 -0
  238. package/dist/core/ports/src/password-hasher.d.ts +47 -0
  239. package/dist/core/ports/src/password-hasher.js +2 -0
  240. package/dist/core/ports/src/plugin-folder-writer.d.ts +104 -0
  241. package/dist/core/ports/src/plugin-folder-writer.js +95 -0
  242. package/dist/core/ports/src/port-versions.d.ts +44 -0
  243. package/dist/core/ports/src/port-versions.js +74 -0
  244. package/dist/core/ports/src/program-probe.d.ts +46 -0
  245. package/dist/core/ports/src/program-probe.js +2 -0
  246. package/dist/core/ports/src/record-store.d.ts +62 -0
  247. package/dist/core/ports/src/record-store.js +38 -0
  248. package/dist/core/ports/src/resource-probe.d.ts +59 -0
  249. package/dist/core/ports/src/resource-probe.js +2 -0
  250. package/dist/core/ports/src/run-executor.d.ts +302 -0
  251. package/dist/core/ports/src/run-executor.js +2 -0
  252. package/dist/core/ports/src/run-failure-error.d.ts +49 -0
  253. package/dist/core/ports/src/run-failure-error.js +47 -0
  254. package/dist/core/ports/src/run-store.d.ts +194 -0
  255. package/dist/core/ports/src/run-store.js +131 -0
  256. package/dist/core/ports/src/sandbox.d.ts +247 -0
  257. package/dist/core/ports/src/sandbox.js +34 -0
  258. package/dist/core/ports/src/scheduler.d.ts +85 -0
  259. package/dist/core/ports/src/scheduler.js +2 -0
  260. package/dist/core/ports/src/secrets.d.ts +128 -0
  261. package/dist/core/ports/src/secrets.js +144 -0
  262. package/dist/core/ports/src/token-store.d.ts +19 -0
  263. package/dist/core/ports/src/token-store.js +2 -0
  264. package/dist/core/ports/src/tool-approval-store.d.ts +211 -0
  265. package/dist/core/ports/src/tool-approval-store.js +57 -0
  266. package/dist/core/ports/src/trust-store.d.ts +72 -0
  267. package/dist/core/ports/src/trust-store.js +2 -0
  268. package/dist/core/ports/src/unfenced-run-consent-store.d.ts +43 -0
  269. package/dist/core/ports/src/unfenced-run-consent-store.js +2 -0
  270. package/dist/core/ports/src/vcs.d.ts +394 -0
  271. package/dist/core/ports/src/vcs.js +48 -0
  272. package/dist/core/schema-kit/src/builders.d.ts +50 -0
  273. package/dist/core/schema-kit/src/builders.js +72 -0
  274. package/dist/core/schema-kit/src/depth.d.ts +15 -0
  275. package/dist/core/schema-kit/src/depth.js +37 -0
  276. package/dist/core/schema-kit/src/index.d.ts +6 -0
  277. package/dist/core/schema-kit/src/index.js +6 -0
  278. package/dist/core/schema-kit/src/issue.d.ts +22 -0
  279. package/dist/core/schema-kit/src/issue.js +23 -0
  280. package/dist/core/schema-kit/src/json-schema.d.ts +23 -0
  281. package/dist/core/schema-kit/src/json-schema.js +22 -0
  282. package/dist/core/schema-kit/src/parse.d.ts +17 -0
  283. package/dist/core/schema-kit/src/parse.js +25 -0
  284. package/dist/core/schema-kit/src/schema.d.ts +12 -0
  285. package/dist/core/schema-kit/src/schema.js +1 -0
  286. package/dist/core/std/src/ascii-host.d.ts +18 -0
  287. package/dist/core/std/src/ascii-host.js +110 -0
  288. package/dist/core/std/src/assert.d.ts +39 -0
  289. package/dist/core/std/src/assert.js +59 -0
  290. package/dist/core/std/src/base64url.d.ts +23 -0
  291. package/dist/core/std/src/base64url.js +65 -0
  292. package/dist/core/std/src/canonical-json.d.ts +18 -0
  293. package/dist/core/std/src/canonical-json.js +56 -0
  294. package/dist/core/std/src/clock.d.ts +27 -0
  295. package/dist/core/std/src/clock.js +33 -0
  296. package/dist/core/std/src/constant-time.d.ts +16 -0
  297. package/dist/core/std/src/constant-time.js +26 -0
  298. package/dist/core/std/src/content-digest.d.ts +24 -0
  299. package/dist/core/std/src/content-digest.js +28 -0
  300. package/dist/core/std/src/deep-clone.d.ts +15 -0
  301. package/dist/core/std/src/deep-clone.js +59 -0
  302. package/dist/core/std/src/deep-equal.d.ts +23 -0
  303. package/dist/core/std/src/deep-equal.js +64 -0
  304. package/dist/core/std/src/emitter.d.ts +42 -0
  305. package/dist/core/std/src/emitter.js +74 -0
  306. package/dist/core/std/src/error-kind.d.ts +88 -0
  307. package/dist/core/std/src/error-kind.js +98 -0
  308. package/dist/core/std/src/hex.d.ts +10 -0
  309. package/dist/core/std/src/hex.js +16 -0
  310. package/dist/core/std/src/ids.d.ts +45 -0
  311. package/dist/core/std/src/ids.js +49 -0
  312. package/dist/core/std/src/index.d.ts +25 -0
  313. package/dist/core/std/src/index.js +26 -0
  314. package/dist/core/std/src/keyed-queue.d.ts +18 -0
  315. package/dist/core/std/src/keyed-queue.js +32 -0
  316. package/dist/core/std/src/line-diff.d.ts +83 -0
  317. package/dist/core/std/src/line-diff.js +179 -0
  318. package/dist/core/std/src/line-merge.d.ts +63 -0
  319. package/dist/core/std/src/line-merge.js +138 -0
  320. package/dist/core/std/src/plain-data.d.ts +32 -0
  321. package/dist/core/std/src/plain-data.js +57 -0
  322. package/dist/core/std/src/posix-path.d.ts +61 -0
  323. package/dist/core/std/src/posix-path.js +121 -0
  324. package/dist/core/std/src/result.d.ts +55 -0
  325. package/dist/core/std/src/result.js +52 -0
  326. package/dist/core/std/src/secret-scrubber.d.ts +54 -0
  327. package/dist/core/std/src/secret-scrubber.js +124 -0
  328. package/dist/core/std/src/secret-shape.d.ts +20 -0
  329. package/dist/core/std/src/secret-shape.js +53 -0
  330. package/dist/core/std/src/stop-signal.d.ts +44 -0
  331. package/dist/core/std/src/stop-signal.js +77 -0
  332. package/dist/core/std/src/text.d.ts +28 -0
  333. package/dist/core/std/src/text.js +54 -0
  334. package/dist/core/std/src/utf8.d.ts +23 -0
  335. package/dist/core/std/src/utf8.js +110 -0
  336. package/dist/core/std/src/version.d.ts +48 -0
  337. package/dist/core/std/src/version.js +103 -0
  338. package/dist/core/yaml/src/depth.d.ts +14 -0
  339. package/dist/core/yaml/src/depth.js +140 -0
  340. package/dist/core/yaml/src/edit-data.d.ts +47 -0
  341. package/dist/core/yaml/src/edit-data.js +286 -0
  342. package/dist/core/yaml/src/edit-text.d.ts +92 -0
  343. package/dist/core/yaml/src/edit-text.js +267 -0
  344. package/dist/core/yaml/src/edit.d.ts +47 -0
  345. package/dist/core/yaml/src/edit.js +198 -0
  346. package/dist/core/yaml/src/index.d.ts +5 -0
  347. package/dist/core/yaml/src/index.js +4 -0
  348. package/dist/core/yaml/src/problem.d.ts +20 -0
  349. package/dist/core/yaml/src/problem.js +1 -0
  350. package/dist/core/yaml/src/read.d.ts +47 -0
  351. package/dist/core/yaml/src/read.js +130 -0
  352. package/dist/core/yaml/src/splice-node.d.ts +47 -0
  353. package/dist/core/yaml/src/splice-node.js +333 -0
  354. package/dist/core/yaml/src/splice.d.ts +13 -0
  355. package/dist/core/yaml/src/splice.js +174 -0
  356. package/dist/core/yaml/src/unsupported.d.ts +26 -0
  357. package/dist/core/yaml/src/unsupported.js +70 -0
  358. package/dist/core/yaml/src/write.d.ts +35 -0
  359. package/dist/core/yaml/src/write.js +44 -0
  360. package/dist/testing/integration/src/canaries.d.ts +14 -0
  361. package/dist/testing/integration/src/canaries.js +17 -0
  362. package/dist/testing/integration/src/checks.d.ts +37 -0
  363. package/dist/testing/integration/src/checks.js +195 -0
  364. package/dist/testing/integration/src/describe.d.ts +35 -0
  365. package/dist/testing/integration/src/describe.js +74 -0
  366. package/dist/testing/integration/src/failure.d.ts +6 -0
  367. package/dist/testing/integration/src/failure.js +8 -0
  368. package/dist/testing/integration/src/fake-wait.d.ts +18 -0
  369. package/dist/testing/integration/src/fake-wait.js +21 -0
  370. package/dist/testing/integration/src/index.d.ts +10 -0
  371. package/dist/testing/integration/src/index.js +11 -0
  372. package/dist/testing/integration/src/load.d.ts +14 -0
  373. package/dist/testing/integration/src/load.js +45 -0
  374. package/dist/testing/integration/src/plugin-folder.d.ts +23 -0
  375. package/dist/testing/integration/src/plugin-folder.js +59 -0
  376. package/dist/testing/integration/src/plugin.d.ts +32 -0
  377. package/dist/testing/integration/src/plugin.js +57 -0
  378. package/dist/testing/integration/src/recording.d.ts +84 -0
  379. package/dist/testing/integration/src/recording.js +164 -0
  380. package/dist/testing/integration/src/run.d.ts +60 -0
  381. package/dist/testing/integration/src/run.js +81 -0
  382. package/dist/testing/integration/src/source-scan.d.ts +16 -0
  383. package/dist/testing/integration/src/source-scan.js +40 -0
  384. package/package.json +35 -4
@@ -0,0 +1,130 @@
1
+ import { err, ok } from "../../std/src/index.js";
2
+ import { isMap, isScalar, LineCounter, parseDocument, } from "yaml";
3
+ import { findDepthOffset } from "./depth.js";
4
+ import { findUnsupported, tooDeepMessage, unsupportedMessages } from "./unsupported.js";
5
+ /**
6
+ * Generous for workspace files, which nest about ten levels and stay well
7
+ * under a megabyte.
8
+ */
9
+ export const defaultYamlLimits = { maxDepth: 100, maxLength: 1_000_000 };
10
+ /**
11
+ * Reads a workspace YAML file with the same YAML rules as the old app
12
+ * (YAML 1.2 core schema, so `yes` stays text), and rejects what workspace
13
+ * files may not use: anchors, aliases, tags, several documents and lists or
14
+ * maps as keys.
15
+ *
16
+ * @param text - the whole file
17
+ * @param limits - depth and length limits; the defaults suit workspace files
18
+ * @returns the data and positions, or the first problem with its line and column
19
+ *
20
+ * @example
21
+ * const read = readYaml("name: Billing\nsteps:\n - id: check\n");
22
+ * if (read.ok) read.value.positionOf(["steps", 0, "id"]); // { line: 3, col: 9 }
23
+ */
24
+ export function readYaml(text, limits = defaultYamlLimits) {
25
+ if (text.length > limits.maxLength) {
26
+ return err({
27
+ kind: "too-large",
28
+ message: `The file is ${text.length} characters long; the limit is ${limits.maxLength}.`,
29
+ line: 1,
30
+ col: 1,
31
+ });
32
+ }
33
+ // Look at the nesting first: the yaml library builds the whole tree before
34
+ // we could, and a hostile file can use up memory doing that.
35
+ const tooDeepAt = findDepthOffset(text, limits.maxDepth);
36
+ if (tooDeepAt !== undefined) {
37
+ return err({
38
+ kind: "too-deep",
39
+ message: tooDeepMessage(limits.maxDepth),
40
+ ...positionAtOffset(text, tooDeepAt),
41
+ });
42
+ }
43
+ // The same options as the old app (784f78d, packages/core/config/src/workspace.ts).
44
+ const lines = new LineCounter();
45
+ const document = parseDocument(text, { lineCounter: lines, prettyErrors: false });
46
+ const parseError = document.errors[0];
47
+ if (parseError !== undefined) {
48
+ return err({ ...describeParseError(parseError, limits), ...lines.linePos(parseError.pos[0]) });
49
+ }
50
+ const unsupported = findUnsupported(document.contents, limits.maxDepth);
51
+ if (unsupported !== undefined) {
52
+ return err({
53
+ kind: unsupported.kind,
54
+ message: unsupported.message,
55
+ ...startOf(unsupported.node, lines),
56
+ });
57
+ }
58
+ return ok({
59
+ // Aliases are already rejected above; a limit of 0 keeps the library from
60
+ // expanding one if that ever changes.
61
+ data: document.toJS({ maxAliasCount: 0 }),
62
+ positionOf: (path) => positionOf(document, lines, path),
63
+ });
64
+ }
65
+ /**
66
+ * Turns an error from the `yaml` library into our problem kinds. Two of its
67
+ * errors get our own wording: a second document, and the call stack running
68
+ * out on deep nesting (it catches that itself and reports it as
69
+ * `RESOURCE_EXHAUSTION`).
70
+ */
71
+ function describeParseError(error, limits) {
72
+ switch (error.code) {
73
+ case "MULTIPLE_DOCS":
74
+ return { kind: "unsupported", message: unsupportedMessages.multipleDocuments };
75
+ case "RESOURCE_EXHAUSTION":
76
+ return { kind: "too-deep", message: tooDeepMessage(limits.maxDepth) };
77
+ default:
78
+ // The old app showed only the first line of the message too.
79
+ return { kind: "syntax", message: firstLine(error.message) };
80
+ }
81
+ }
82
+ /**
83
+ * Ported from the old app's `sourcePosition`: tries the full path, then each
84
+ * shorter one, then the top of the document. When a key is missing from a map
85
+ * that is itself a value, the answer is that map's key, as in the old app's
86
+ * parity cases: `run:` rather than the line below it.
87
+ */
88
+ function positionOf(document, lines, path) {
89
+ for (let length = path.length; length >= 0; length--) {
90
+ const node = length === 0 ? document.contents : document.getIn(path.slice(0, length), true);
91
+ if (isNodeWithRange(node)) {
92
+ const key = length < path.length && isMap(node) ? keyOf(document, path, length) : undefined;
93
+ return startOf(key ?? node, lines);
94
+ }
95
+ }
96
+ return undefined;
97
+ }
98
+ /** The key node that names the map at `path[0, length)`, if that map is a value in another map. */
99
+ function keyOf(document, path, length) {
100
+ const name = path[length - 1];
101
+ const parent = length === 1 ? document.contents : document.getIn(path.slice(0, length - 1), true);
102
+ if (!isMap(parent)) {
103
+ return undefined;
104
+ }
105
+ const pair = parent.items.find((item) => isScalar(item.key) && item.key.value === name);
106
+ return isNodeWithRange(pair?.key) ? pair.key : undefined;
107
+ }
108
+ function isNodeWithRange(value) {
109
+ return typeof value === "object" && value !== null && "range" in value && value.range != null;
110
+ }
111
+ function startOf(node, lines) {
112
+ // Every node the parser makes has a range; only nodes built in code lack one.
113
+ const start = node.range?.[0] ?? 0;
114
+ const { line, col } = lines.linePos(start);
115
+ return { line, col };
116
+ }
117
+ /** The line and column of a character offset, counting lines like the parser. */
118
+ function positionAtOffset(text, offset) {
119
+ let line = 1;
120
+ let lineStart = 0;
121
+ for (let at = text.indexOf("\n"); at !== -1 && at < offset; at = text.indexOf("\n", at + 1)) {
122
+ line++;
123
+ lineStart = at + 1;
124
+ }
125
+ return { line, col: offset - lineStart + 1 };
126
+ }
127
+ function firstLine(message) {
128
+ const end = message.indexOf("\n");
129
+ return end === -1 ? message : message.slice(0, end);
130
+ }
@@ -0,0 +1,47 @@
1
+ import { type Document, type Node, type YAMLMap, type YAMLSeq } from "yaml";
2
+ import { type IndentStyle } from "./edit-text.js";
3
+ import type { YamlPath } from "./read.js";
4
+ /**
5
+ * A parsed text with the source tokens that give the offsets of `-` markers,
6
+ * and the indent style new lines follow.
7
+ */
8
+ export interface Parsed {
9
+ readonly text: string;
10
+ readonly document: Document;
11
+ readonly style: IndentStyle;
12
+ }
13
+ export declare function parse(text: string): Parsed;
14
+ /**
15
+ * The node at `path`: `null` for an empty document, `undefined` when nothing
16
+ * is there. Keys are matched as text, the way `readYaml` reads them.
17
+ */
18
+ export declare function nodeAt(parsed: Parsed, path: YamlPath): Node | null | undefined;
19
+ /**
20
+ * How long the part of `path` is that leads to the outermost list or map in
21
+ * flow style, like `[a, b]`, that holds the node at `path` (the node itself
22
+ * excluded). `undefined` when there is none. An empty `{}` or `[]` doesn't
23
+ * count: adding to it rewrites it in block style.
24
+ */
25
+ export declare function flowAncestor(parsed: Parsed, path: YamlPath): number | undefined;
26
+ /** A list or map in flow style with at least one entry. */
27
+ export declare function isFilledFlow(node: unknown): node is YAMLMap | YAMLSeq;
28
+ /**
29
+ * Writes a flow collection that sits on one line again with `value`, on the
30
+ * same line and with the same spaces inside its brackets. `undefined` when it
31
+ * spans lines (it may hold comments) or `value` doesn't fit on one line.
32
+ */
33
+ export declare function replaceFlow(parsed: Parsed, node: YAMLMap | YAMLSeq, value: unknown): string | undefined;
34
+ /** Replaces the value at `path` (which exists, or is the document) with freshly rendered text. */
35
+ export declare function replaceValue(parsed: Parsed, path: YamlPath, value: unknown): string | undefined;
36
+ /** Replaces a one-line scalar's characters only, so a trailing comment and the quote style stay. */
37
+ export declare function replaceScalar(parsed: Parsed, node: Node, value: unknown): string | undefined;
38
+ /**
39
+ * Adds `key: value` to the block map at `mapPath`: after its last entry, or
40
+ * right after the entry `after` names, or first (above the comments over the
41
+ * first entry) when `after` is `null`.
42
+ */
43
+ export declare function addPair(parsed: Parsed, mapPath: YamlPath, key: string, value: unknown, after?: string | null): string | undefined;
44
+ /** Inserts `- value` into the block list at `listPath`, above the comments over item `index`. */
45
+ export declare function insertItem(parsed: Parsed, listPath: YamlPath, index: number, value: unknown): string | undefined;
46
+ /** Removes the lines of the entry at `path`. The last entry leaves `{}` or `[]` behind. */
47
+ export declare function deleteEntry(parsed: Parsed, path: YamlPath): string | undefined;
@@ -0,0 +1,333 @@
1
+ import { isCollection, isMap, isScalar, isSeq, parseDocument, } from "yaml";
2
+ import { aboveComments, alignComments, columnOf, defaultIndentStyle, entryEnd, insertLines, keepLineComment, keepsComments, lineStart, removeLines, renderAfterDash, renderAfterKey, renderDocument, renderFlow, renderItem, renderPair, renderScalar, replaceRange, startsItsLine, } from "./edit-text.js";
3
+ export function parse(text) {
4
+ const document = parseDocument(text, { keepSourceTokens: true });
5
+ return { text, document, style: indentStyleOf(text, document.contents) };
6
+ }
7
+ /**
8
+ * The indent style of the first block map and the first block list that sit
9
+ * under a key: how far right of the key their entries start. A text without
10
+ * them gets the library's defaults, as `writeYamlFile` writes.
11
+ */
12
+ function indentStyleOf(text, contents) {
13
+ const steps = {};
14
+ const visit = (node) => {
15
+ if (isSeq(node)) {
16
+ node.items.forEach(visit);
17
+ }
18
+ if (!isMap(node) || node.flow === true) {
19
+ return;
20
+ }
21
+ for (const pair of node.items) {
22
+ const step = stepUnder(text, pair);
23
+ if (step !== undefined && isMap(pair.value)) {
24
+ steps.map ??= step;
25
+ }
26
+ else if (step !== undefined) {
27
+ steps.list ??= step;
28
+ }
29
+ visit(pair.value);
30
+ }
31
+ };
32
+ visit(contents);
33
+ const indent = steps.map ?? (steps.list !== undefined && steps.list > 0 ? steps.list : 2);
34
+ if (steps.list === undefined) {
35
+ return { ...defaultIndentStyle, indent };
36
+ }
37
+ // Without `indentSeq` the library puts the `-` two columns left of the
38
+ // entries below it: at the key's column for an indent of 2. It can't go
39
+ // further left, so a wider file with its `-` at the key's column gets that.
40
+ return { indent, indentSeq: steps.list > indent - 2 };
41
+ }
42
+ /**
43
+ * How many columns right of its key the block map or list under `pair`
44
+ * starts, on the next line. `undefined` for any other value.
45
+ */
46
+ function stepUnder(text, pair) {
47
+ const keyStart = pair.key?.range?.[0];
48
+ const value = pair.value;
49
+ if (keyStart === undefined || !isCollection(value) || value.flow === true) {
50
+ return undefined;
51
+ }
52
+ const child = isMap(value)
53
+ ? value.items[0]?.key?.range?.[0]
54
+ : dashOffset(value, 0);
55
+ if (child === undefined || !startsItsLine(text, child)) {
56
+ return undefined;
57
+ }
58
+ return columnOf(text, child) - columnOf(text, keyStart);
59
+ }
60
+ /**
61
+ * The node at `path`: `null` for an empty document, `undefined` when nothing
62
+ * is there. Keys are matched as text, the way `readYaml` reads them.
63
+ */
64
+ export function nodeAt(parsed, path) {
65
+ let node = parsed.document.contents;
66
+ if (path.length === 0) {
67
+ return node ?? null;
68
+ }
69
+ for (const key of path) {
70
+ node = childNode(node, key);
71
+ if (node === undefined) {
72
+ return undefined;
73
+ }
74
+ }
75
+ return node;
76
+ }
77
+ /**
78
+ * How long the part of `path` is that leads to the outermost list or map in
79
+ * flow style, like `[a, b]`, that holds the node at `path` (the node itself
80
+ * excluded). `undefined` when there is none. An empty `{}` or `[]` doesn't
81
+ * count: adding to it rewrites it in block style.
82
+ */
83
+ export function flowAncestor(parsed, path) {
84
+ for (let length = 0; length < path.length; length++) {
85
+ if (isFilledFlow(nodeAt(parsed, path.slice(0, length)))) {
86
+ return length;
87
+ }
88
+ }
89
+ return undefined;
90
+ }
91
+ /** A list or map in flow style with at least one entry. */
92
+ export function isFilledFlow(node) {
93
+ return isCollection(node) && node.flow === true && node.items.length > 0;
94
+ }
95
+ /**
96
+ * Writes a flow collection that sits on one line again with `value`, on the
97
+ * same line and with the same spaces inside its brackets. `undefined` when it
98
+ * spans lines (it may hold comments) or `value` doesn't fit on one line.
99
+ */
100
+ export function replaceFlow(parsed, node, value) {
101
+ const { text } = parsed;
102
+ if (node.range == null) {
103
+ return undefined;
104
+ }
105
+ const [start, end] = node.range;
106
+ const old = text.slice(start, end);
107
+ if (old.includes("\n") || !/^[[{]/.test(old)) {
108
+ return undefined;
109
+ }
110
+ const rendered = renderFlow(value, old[1] === " ");
111
+ return rendered === undefined ? undefined : text.slice(0, start) + rendered + text.slice(end);
112
+ }
113
+ /** Replaces the value at `path` (which exists, or is the document) with freshly rendered text. */
114
+ export function replaceValue(parsed, path, value) {
115
+ const { text } = parsed;
116
+ if (path.length === 0) {
117
+ const contents = parsed.document.contents;
118
+ if (contents?.range == null) {
119
+ return insertLines(text, text.length, renderDocument(value, parsed.style));
120
+ }
121
+ return replaceRange(text, contents.range[0], contents.range[1], renderDocument(value, parsed.style));
122
+ }
123
+ const parent = nodeAt(parsed, path.slice(0, -1));
124
+ const key = path[path.length - 1];
125
+ if (isMap(parent)) {
126
+ const pair = pairOf(parent, key);
127
+ const keyNode = pair?.key;
128
+ if (keyNode?.range == null) {
129
+ return undefined;
130
+ }
131
+ const valueEnd = pair?.value?.range?.[1] ?? keyNode.range[1];
132
+ const column = columnOf(text, keyNode.range[0]);
133
+ const kept = keepLineComment(text, keyNode.range[1], valueEnd, renderAfterKey(value, column, parsed.style));
134
+ return replaceRange(text, keyNode.range[1], kept.to, kept.rendered);
135
+ }
136
+ if (isSeq(parent) && typeof key === "number") {
137
+ const dash = dashOffset(parent, key);
138
+ const itemEnd = parent.items[key]?.range?.[1];
139
+ if (dash === undefined || itemEnd === undefined) {
140
+ return undefined;
141
+ }
142
+ const kept = keepLineComment(text, dash, itemEnd, renderAfterDash(value, columnOf(text, dash), parsed.style));
143
+ return replaceRange(text, dash, kept.to, kept.rendered);
144
+ }
145
+ return undefined;
146
+ }
147
+ /** Replaces a one-line scalar's characters only, so a trailing comment and the quote style stay. */
148
+ export function replaceScalar(parsed, node, value) {
149
+ if (!isScalar(node) || node.range == null) {
150
+ return undefined;
151
+ }
152
+ const [start, end] = node.range;
153
+ const multiLine = parsed.text.slice(start, end).includes("\n");
154
+ // An empty value (`key:`) has no characters to replace; block texts render whole.
155
+ if (start === end || multiLine) {
156
+ return undefined;
157
+ }
158
+ const rendered = renderScalar(value, node.type, columnOf(parsed.text, start));
159
+ if (rendered === undefined) {
160
+ return undefined;
161
+ }
162
+ return parsed.text.slice(0, start) + rendered + parsed.text.slice(end);
163
+ }
164
+ /**
165
+ * Adds `key: value` to the block map at `mapPath`: after its last entry, or
166
+ * right after the entry `after` names, or first (above the comments over the
167
+ * first entry) when `after` is `null`.
168
+ */
169
+ export function addPair(parsed, mapPath, key, value, after) {
170
+ const map = nodeAt(parsed, mapPath);
171
+ if (!isMap(map)) {
172
+ return undefined;
173
+ }
174
+ if (map.flow === true) {
175
+ return map.items.length === 0 ? replaceValue(parsed, mapPath, { [key]: value }) : undefined;
176
+ }
177
+ const first = map.items[0]?.key;
178
+ if (first?.range == null) {
179
+ return undefined;
180
+ }
181
+ const at = newPairOffset(parsed.text, map, first.range[0], after);
182
+ if (at === undefined) {
183
+ return undefined;
184
+ }
185
+ return insertLines(parsed.text, at, renderPair(key, value, columnOf(parsed.text, first.range[0]), parsed.style));
186
+ }
187
+ /** Where a new pair's lines go in a block map whose first key starts at `firstKey`. */
188
+ function newPairOffset(text, map, firstKey, after) {
189
+ if (after === null) {
190
+ return aboveComments(text, lineStart(text, firstKey));
191
+ }
192
+ const previous = (after === undefined ? undefined : pairOf(map, after)) ?? map.items.at(-1);
193
+ return previous === undefined ? undefined : entryEnd(text, pairEnd(previous));
194
+ }
195
+ /** Inserts `- value` into the block list at `listPath`, above the comments over item `index`. */
196
+ export function insertItem(parsed, listPath, index, value) {
197
+ const { text } = parsed;
198
+ const list = nodeAt(parsed, listPath);
199
+ if (!isSeq(list)) {
200
+ return undefined;
201
+ }
202
+ if (list.flow === true) {
203
+ return list.items.length === 0 ? replaceValue(parsed, listPath, [value]) : undefined;
204
+ }
205
+ const atEnd = index === list.items.length;
206
+ const dash = dashOffset(list, atEnd ? index - 1 : index);
207
+ if (dash === undefined) {
208
+ return undefined;
209
+ }
210
+ const column = columnOf(text, dash);
211
+ if (atEnd) {
212
+ const lastEnd = list.items[index - 1]?.range?.[1];
213
+ const lines = renderItem(value, column, parsed.style);
214
+ return lastEnd === undefined ? undefined : insertLines(text, entryEnd(text, lastEnd), lines);
215
+ }
216
+ if (!startsItsLine(text, dash)) {
217
+ // The first item of a list on a `- ` line (`- - a`): the new item takes
218
+ // that place and the old one moves to the next line.
219
+ const item = `${renderAfterDash(value, column, parsed.style)}${" ".repeat(column)}`;
220
+ return text.slice(0, dash) + item + text.slice(dash);
221
+ }
222
+ return insertLines(text, aboveComments(text, lineStart(text, dash)), renderItem(value, column, parsed.style));
223
+ }
224
+ /** Removes the lines of the entry at `path`. The last entry leaves `{}` or `[]` behind. */
225
+ export function deleteEntry(parsed, path) {
226
+ const parentPath = path.slice(0, -1);
227
+ const parent = nodeAt(parsed, parentPath);
228
+ const key = path[path.length - 1];
229
+ if (!isCollection(parent) || parent.flow === true) {
230
+ return undefined;
231
+ }
232
+ if (parent.items.length === 1) {
233
+ return emptyCollection(parsed, parentPath, parent, key);
234
+ }
235
+ if (isMap(parent)) {
236
+ return deletePair(parsed, parent, key);
237
+ }
238
+ if (isSeq(parent) && typeof key === "number") {
239
+ return deleteItem(parsed, parent, key);
240
+ }
241
+ return undefined;
242
+ }
243
+ /**
244
+ * Writes `{}` or `[]` in place of a collection whose only entry goes. The
245
+ * comment lines right above that entry stay, under the `{}` or `[]`; when any
246
+ * other comment would go with it, this gives up.
247
+ */
248
+ function emptyCollection(parsed, path, collection, key) {
249
+ const { text } = parsed;
250
+ const entry = isMap(collection) ? pairOf(collection, key) : undefined;
251
+ const start = isMap(collection)
252
+ ? entry?.key?.range?.[0]
253
+ : dashOffset(collection, 0);
254
+ const valueEnd = entry !== undefined ? pairEnd(entry) : collection.items[0]?.range?.[1];
255
+ const end = collection.range?.[1];
256
+ const emptied = replaceValue(parsed, path, isMap(collection) ? {} : []);
257
+ if (start === undefined || valueEnd === undefined || end === undefined || emptied === undefined) {
258
+ return undefined;
259
+ }
260
+ const from = startsItsLine(text, start) ? lineStart(text, start) : start;
261
+ // At the top the comments above the first entry aren't replaced, so they stay anyway.
262
+ const above = path.length > 0 && from !== start ? text.slice(aboveComments(text, from), from) : "";
263
+ const at = emptied.length - (text.length - end);
264
+ if (at < emptied.length && emptied[at - 1] !== "\n") {
265
+ return undefined;
266
+ }
267
+ const result = above === "" ? emptied : insertLines(emptied, at, above);
268
+ return keepsComments(text, from, entryEnd(text, valueEnd), result) ? result : undefined;
269
+ }
270
+ function deletePair(parsed, map, key) {
271
+ const { text } = parsed;
272
+ const pair = pairOf(map, key);
273
+ const start = pair?.key?.range?.[0];
274
+ if (pair === undefined || start === undefined) {
275
+ return undefined;
276
+ }
277
+ const end = entryEnd(text, pairEnd(pair));
278
+ if (startsItsLine(text, start)) {
279
+ return removeLines(alignComments(text, end, columnOf(text, start)), lineStart(text, start), end);
280
+ }
281
+ // The first key of a map on a `- ` line: the next key moves up to its place.
282
+ const next = map.items[1]?.key?.range?.[0];
283
+ if (map.items[0] !== pair || next === undefined || text.slice(end, next).includes("#")) {
284
+ return undefined;
285
+ }
286
+ return text.slice(0, start) + text.slice(next);
287
+ }
288
+ function deleteItem(parsed, list, index) {
289
+ const { text } = parsed;
290
+ const dash = dashOffset(list, index);
291
+ const end = list.items[index]?.range?.[1];
292
+ if (dash === undefined || end === undefined) {
293
+ return undefined;
294
+ }
295
+ const lineEnd = entryEnd(text, end);
296
+ if (startsItsLine(text, dash)) {
297
+ return removeLines(alignComments(text, lineEnd, columnOf(text, dash)), lineStart(text, dash), lineEnd);
298
+ }
299
+ // The first item of a list on a `- ` line: the next item moves up to its place.
300
+ const next = dashOffset(list, 1);
301
+ if (index !== 0 || next === undefined || text.slice(lineEnd, next).includes("#")) {
302
+ return undefined;
303
+ }
304
+ return text.slice(0, dash) + text.slice(next);
305
+ }
306
+ function childNode(node, key) {
307
+ if (isMap(node)) {
308
+ return pairOf(node, key)?.value ?? undefined;
309
+ }
310
+ if (isSeq(node) && typeof key === "number") {
311
+ return node.items[key];
312
+ }
313
+ return undefined;
314
+ }
315
+ /** The pair whose key reads as `key`; `readYaml` turns every key into text. */
316
+ function pairOf(map, key) {
317
+ return map.items.find((pair) => isScalar(pair.key) && String(pair.key.value) === String(key));
318
+ }
319
+ function pairEnd(pair) {
320
+ const value = pair.value;
321
+ const key = pair.key;
322
+ return value?.range?.[1] ?? key.range?.[1] ?? 0;
323
+ }
324
+ /** The offset of the `-` that starts item `index` of a block list. */
325
+ function dashOffset(list, index) {
326
+ const token = list.srcToken;
327
+ if (token?.type !== "block-seq") {
328
+ return undefined;
329
+ }
330
+ // Only items with a `-` marker; trailing comments can form items without one.
331
+ const dashes = token.items.flatMap((item) => item.start.filter((start) => start.type === "seq-item-ind").map((start) => start.offset));
332
+ return dashes.length === list.items.length ? dashes[index] : undefined;
333
+ }
@@ -0,0 +1,13 @@
1
+ import { type YamlEdit } from "./edit-data.js";
2
+ /**
3
+ * Applies one edit by changing only the text of what it touches, so comments,
4
+ * key order, quoting and blank lines elsewhere stay byte for byte. Expects an
5
+ * edit that `applyEditToData` accepted on this text's data.
6
+ *
7
+ * New lines get the text's line ending and indent style. An edit inside a
8
+ * flow collection like `[a, b]` writes that collection again on its line.
9
+ *
10
+ * @returns the new text, or `undefined` for a layout it doesn't handle yet
11
+ * (a flow collection over several lines, or a text that mixes line endings)
12
+ */
13
+ export declare function spliceEdit(text: string, edit: YamlEdit): string | undefined;