@halonicjs/testing 0.0.0 → 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 +41 -1
  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 +34 -3
@@ -0,0 +1,267 @@
1
+ import { assert } from "../../std/src/index.js";
2
+ import { Scalar, stringify } from "yaml";
3
+ // Line arithmetic and rendering for the splicer. Offsets are UTF-16 indexes
4
+ // into the whole text, as the yaml library's ranges are.
5
+ /** The line width `writeYamlFile` folds at; new text is folded to fit inside it. */
6
+ const fileLineWidth = 100;
7
+ /** Deeply indented text still gets this much room before it folds. */
8
+ const minimumLineWidth = 40;
9
+ const byteOrderMark = "\uFEFF";
10
+ /** The library's defaults, which `writeYamlFile` writes with. */
11
+ export const defaultIndentStyle = { indent: 2, indentSeq: true };
12
+ /**
13
+ * The text's line ending: `\r\n` when every line break is one, `\n` when every
14
+ * one is that or there are none, `undefined` when the text mixes them.
15
+ */
16
+ export function lineEndingOf(text) {
17
+ const breaks = new Set(text.match(/\r\n|\r|\n/g));
18
+ if (breaks.size === 0 || (breaks.size === 1 && breaks.has("\n"))) {
19
+ return "\n";
20
+ }
21
+ return breaks.size === 1 && breaks.has("\r\n") ? "\r\n" : undefined;
22
+ }
23
+ /** Where the line holding `offset` starts. A byte order mark isn't part of the first line. */
24
+ export function lineStart(text, offset) {
25
+ const start = text.lastIndexOf("\n", offset - 1) + 1;
26
+ return start === 0 && text.startsWith(byteOrderMark) ? 1 : start;
27
+ }
28
+ /** The column of `offset`, counting from 0. */
29
+ export function columnOf(text, offset) {
30
+ return offset - lineStart(text, offset);
31
+ }
32
+ /** True when only spaces come before `offset` on its line. */
33
+ export function startsItsLine(text, offset) {
34
+ return text.slice(lineStart(text, offset), offset).trim() === "";
35
+ }
36
+ /**
37
+ * Where the entry whose value ends at `valueEnd` ends: after its line break,
38
+ * so a trailing `# comment` goes with it. Block collections already end after
39
+ * a line break.
40
+ */
41
+ export function entryEnd(text, valueEnd) {
42
+ if (valueEnd > 0 && text[valueEnd - 1] === "\n") {
43
+ return valueEnd;
44
+ }
45
+ const lineBreak = text.indexOf("\n", valueEnd);
46
+ return lineBreak === -1 ? text.length : lineBreak + 1;
47
+ }
48
+ /** Moves `offset` (a line start) up over the comment lines right above it. */
49
+ export function aboveComments(text, offset) {
50
+ let start = offset;
51
+ while (start > 0) {
52
+ const previous = lineStart(text, start - 1);
53
+ if (!text.slice(previous, start).trim().startsWith("#")) {
54
+ break;
55
+ }
56
+ start = previous;
57
+ }
58
+ return start;
59
+ }
60
+ /**
61
+ * True when every comment line of `before`, outside `before[from, to)`, is
62
+ * still a line of `after`.
63
+ */
64
+ export function keepsComments(before, from, to, after) {
65
+ const left = new Map();
66
+ for (const line of commentLines(after)) {
67
+ left.set(line, (left.get(line) ?? 0) + 1);
68
+ }
69
+ return commentLines(before.slice(0, from) + before.slice(to)).every((line) => {
70
+ const count = left.get(line) ?? 0;
71
+ left.set(line, count - 1);
72
+ return count > 0;
73
+ });
74
+ }
75
+ /**
76
+ * Removes the lines from `from` to `to` (both line starts). When blank lines
77
+ * sat on both sides, one of them goes too, so two sections stay one blank
78
+ * line apart instead of two. At the start or the end of the file, the blank
79
+ * lines next to the removed ones go too, so none is left there.
80
+ */
81
+ export function removeLines(text, from, to) {
82
+ if (isBlank(text.slice(to))) {
83
+ // The last entry of the file: the blank lines above it go with it.
84
+ return text.slice(0, blankLinesAbove(text, from)) + text.slice(to);
85
+ }
86
+ if (from === lineStart(text, 0)) {
87
+ // The first entry of the file: the blank lines below it go with it.
88
+ return text.slice(0, from) + text.slice(blankLinesBelow(text, to));
89
+ }
90
+ const lineBefore = lineStart(text, from - 1);
91
+ const blankBefore = isBlank(text.slice(lineBefore, from));
92
+ const lineAfterEnd = lineEnd(text, to);
93
+ const blankAfter = isBlank(text.slice(to, lineAfterEnd));
94
+ const end = blankBefore && blankAfter ? lineAfterEnd : to;
95
+ return text.slice(0, from) + text.slice(end);
96
+ }
97
+ /**
98
+ * Moves the comment lines from `at` (a line start) down to the next entry to
99
+ * that entry's indent, when it starts at `column`. These are comments left
100
+ * indented under a block that is deleted above them; less indented ones stay.
101
+ */
102
+ export function alignComments(text, at, column) {
103
+ const comments = [];
104
+ let start = at;
105
+ while (start < text.length) {
106
+ const line = text.slice(start, lineEnd(text, start));
107
+ if (!isBlank(line) && !line.trim().startsWith("#")) {
108
+ break;
109
+ }
110
+ if (!isBlank(line) && indentOf(line) > column) {
111
+ comments.push(start);
112
+ }
113
+ start = lineEnd(text, start);
114
+ }
115
+ if (start === text.length || indentOf(text.slice(start, lineEnd(text, start))) !== column) {
116
+ return text;
117
+ }
118
+ const pad = " ".repeat(column);
119
+ // From the last, so the earlier offsets still hold.
120
+ return comments.reduceRight((result, comment) => {
121
+ const indent = indentOf(result.slice(comment, lineEnd(result, comment)));
122
+ return result.slice(0, comment) + pad + result.slice(comment + indent);
123
+ }, text);
124
+ }
125
+ /** Inserts whole lines at a line start; at the end of a text without a final line break, adds one first. */
126
+ export function insertLines(text, at, lines) {
127
+ if (at === text.length && text.length > 0 && !text.endsWith("\n")) {
128
+ return `${text}\n${lines.slice(0, -1)}`;
129
+ }
130
+ return text.slice(0, at) + lines + text.slice(at);
131
+ }
132
+ /**
133
+ * Replaces `text[from, to)` with `rendered`, keeping a line break at the end
134
+ * only when the replaced text had one.
135
+ */
136
+ export function replaceRange(text, from, to, rendered) {
137
+ const body = rendered.endsWith("\n") ? rendered.slice(0, -1) : rendered;
138
+ const ending = to > from && text[to - 1] === "\n" ? "\n" : "";
139
+ return text.slice(0, from) + body + ending + text.slice(to);
140
+ }
141
+ /**
142
+ * Moves a comment on the line where `text[from, to)` starts onto the first line of
143
+ * `rendered`, when only blanks, the `:` or `-` and a block text header come before it:
144
+ * `a: # about a` over a block value, or with no value. Comment lines inside the
145
+ * old value go with it.
146
+ *
147
+ * @returns where the replaced text ends (past the comment) and what replaces it
148
+ */
149
+ export function keepLineComment(text, from, to, rendered) {
150
+ const lineBreak = text.indexOf("\n", from);
151
+ const lineEnd = lineBreak === -1 ? text.length : lineBreak;
152
+ const comment = /^[ \t]*[:-]?(?:[ \t]+[|>][-+1-9]*)?[ \t]+(#.*)$/.exec(text.slice(from, lineEnd))?.[1];
153
+ if (comment === undefined) {
154
+ return { to, rendered };
155
+ }
156
+ const firstBreak = rendered.indexOf("\n");
157
+ const head = firstBreak === -1 ? rendered : rendered.slice(0, firstBreak);
158
+ return {
159
+ to: Math.max(to, lineEnd),
160
+ rendered: `${head} ${comment}${rendered.slice(head.length)}`,
161
+ };
162
+ }
163
+ /** `key: value` as whole lines, indented to `column`. Keys are quoted by the library, never pasted. */
164
+ export function renderPair(key, value, column, style) {
165
+ return indent(render({ [key]: value }, column, style), column, true);
166
+ }
167
+ /** `- value` as whole lines, indented to `column`. */
168
+ export function renderItem(value, column, style) {
169
+ return indent(render([value], column, style), column, true);
170
+ }
171
+ /**
172
+ * The text that follows a key to give it `value`: `: 1`, or `:` and the
173
+ * indented lines of a list or map. It starts right after the key.
174
+ */
175
+ export function renderAfterKey(value, column, style) {
176
+ // Render under a one-letter key and drop that key; the rest is ours.
177
+ const pair = render({ k: value }, column, style);
178
+ assert(pair.startsWith("k:"), "Expected the yaml library to write a plain key k.");
179
+ return indent(pair.slice(1), column, false);
180
+ }
181
+ /** `- value` starting at the dash, with following lines indented to `column`. */
182
+ export function renderAfterDash(value, column, style) {
183
+ return indent(render([value], column, style), column, false);
184
+ }
185
+ /** A whole document. */
186
+ export function renderDocument(value, style) {
187
+ return render(value, 0, style);
188
+ }
189
+ /**
190
+ * A list or map in flow style on one line, like `[a, b]`, with spaces inside
191
+ * the brackets when `padding` is set. `undefined` when it needs more than one
192
+ * line, as a text with a line break does.
193
+ */
194
+ export function renderFlow(value, padding) {
195
+ // Line width 0: the library never breaks a flow collection over lines.
196
+ const text = stringify(value, {
197
+ collectionStyle: "flow",
198
+ flowCollectionPadding: padding,
199
+ lineWidth: 0,
200
+ });
201
+ assert(text !== undefined, "Expected a value checked by checkValue.");
202
+ const line = text.replace(/\n$/, "");
203
+ return line.includes("\n") ? undefined : line;
204
+ }
205
+ /**
206
+ * A scalar on one line, keeping a quoted text quoted the same way. `undefined`
207
+ * when it needs more than one line.
208
+ */
209
+ export function renderScalar(value, quoteStyle, column) {
210
+ const keepQuotes = typeof value === "string" &&
211
+ (quoteStyle === Scalar.QUOTE_DOUBLE || quoteStyle === Scalar.QUOTE_SINGLE);
212
+ const node = new Scalar(value);
213
+ if (keepQuotes) {
214
+ node.type = quoteStyle;
215
+ }
216
+ const text = render(node, column, defaultIndentStyle).replace(/\n$/, "");
217
+ return text.includes("\n") ? undefined : text;
218
+ }
219
+ function render(value, column, style) {
220
+ const lineWidth = Math.max(fileLineWidth - column, minimumLineWidth);
221
+ const text = stringify(value, { lineWidth, ...style });
222
+ assert(text !== undefined, "Expected a value checked by checkValue.");
223
+ return text;
224
+ }
225
+ /** Indents every non-empty line (or every line after the first) by `column` spaces. */
226
+ function indent(text, column, firstLineToo) {
227
+ const pad = " ".repeat(column);
228
+ return text
229
+ .split("\n")
230
+ .map((line, index) => (line === "" || (index === 0 && !firstLineToo) ? line : pad + line))
231
+ .join("\n");
232
+ }
233
+ /** The lines that hold only a comment, without their indent. */
234
+ function commentLines(text) {
235
+ return text
236
+ .split("\n")
237
+ .map((line) => line.trim())
238
+ .filter((line) => line.startsWith("#"));
239
+ }
240
+ function isBlank(line) {
241
+ return line.trim() === "";
242
+ }
243
+ /** Where the line holding `offset` ends: after its line break, or at the end of the text. */
244
+ function lineEnd(text, offset) {
245
+ const lineBreak = text.indexOf("\n", offset);
246
+ return lineBreak === -1 ? text.length : lineBreak + 1;
247
+ }
248
+ /** How many spaces start `line`. */
249
+ function indentOf(line) {
250
+ return line.length - line.trimStart().length;
251
+ }
252
+ /** Moves `offset` (a line start) up over the blank lines right above it. */
253
+ function blankLinesAbove(text, offset) {
254
+ let start = offset;
255
+ while (start > lineStart(text, 0) && isBlank(text.slice(lineStart(text, start - 1), start))) {
256
+ start = lineStart(text, start - 1);
257
+ }
258
+ return start;
259
+ }
260
+ /** Moves `offset` (a line start) down over the blank lines from it. */
261
+ function blankLinesBelow(text, offset) {
262
+ let end = offset;
263
+ while (end < text.length && isBlank(text.slice(end, lineEnd(text, end)))) {
264
+ end = lineEnd(text, end);
265
+ }
266
+ return end;
267
+ }
@@ -0,0 +1,47 @@
1
+ import { type Result } from "../../std/src/index.js";
2
+ import { type YamlEdit } from "./edit-data.js";
3
+ import type { YamlProblem } from "./problem.js";
4
+ import { type YamlLimits } from "./read.js";
5
+ /** An edit that doesn't fit the data, or would give a file `readYaml` rejects. */
6
+ export interface YamlEditProblem {
7
+ readonly kind: "bad-edit";
8
+ /** The index of the edit in the list passed to `editYaml`. */
9
+ readonly edit: number;
10
+ /** One line that says what is wrong. */
11
+ readonly message: string;
12
+ }
13
+ /**
14
+ * How much of the file's layout an edit kept:
15
+ * - `kept`: only the edited text changed; every comment and line elsewhere stayed.
16
+ * - `reformatted`: the file was rendered again from the parsed document. Comments
17
+ * stay, but spacing and some quoting may change.
18
+ * - `rewritten`: the file was written from its data with `writeYamlFile`. Every
19
+ * comment is gone; warn before saving this.
20
+ */
21
+ export type YamlLayout = "kept" | "reformatted" | "rewritten";
22
+ /** The text after `editYaml`, and how much of its layout was kept. */
23
+ export interface YamlEdited {
24
+ readonly text: string;
25
+ readonly layout: YamlLayout;
26
+ }
27
+ /**
28
+ * Applies edits to a YAML text and keeps everything they don't touch: comments,
29
+ * key order, quoting, blank lines. Edits run in order; each sees the result
30
+ * of the one before. After each edit the text is read back and must give the
31
+ * expected data; when the splice can't manage that, the edit falls back to a
32
+ * `reformatted` and then a `rewritten` layout, so the data is always right.
33
+ *
34
+ * @param text - the whole file
35
+ * @param edits - the changes, applied in order
36
+ * @param limits - the same limits as `readYaml`; they apply to the result too
37
+ * @returns the new text and its layout; or the problem `readYaml` gives for an
38
+ * unreadable `text`; or a `bad-edit` for the first edit that doesn't fit, with
39
+ * no edit applied
40
+ *
41
+ * @example
42
+ * const edited = editYaml("name: Billing # shown in the list\n", [
43
+ * { kind: "set", path: ["name"], value: "Invoices" },
44
+ * ]);
45
+ * // { ok: true, value: { text: "name: Invoices # shown in the list\n", layout: "kept" } }
46
+ */
47
+ export declare function editYaml(text: string, edits: readonly YamlEdit[], limits?: YamlLimits): Result<YamlEdited, YamlProblem | YamlEditProblem>;
@@ -0,0 +1,198 @@
1
+ import { deepEqual, err, ok } from "../../std/src/index.js";
2
+ import { isCollection, isMap, isNode, isPair, isScalar, isSeq, parseDocument, } from "yaml";
3
+ import { applyEditToData, checkValue } from "./edit-data.js";
4
+ import { lineEndingOf } from "./edit-text.js";
5
+ import { defaultYamlLimits, readYaml } from "./read.js";
6
+ import { spliceEdit } from "./splice.js";
7
+ import { writeYamlFile } from "./write.js";
8
+ /**
9
+ * Applies edits to a YAML text and keeps everything they don't touch: comments,
10
+ * key order, quoting, blank lines. Edits run in order; each sees the result
11
+ * of the one before. After each edit the text is read back and must give the
12
+ * expected data; when the splice can't manage that, the edit falls back to a
13
+ * `reformatted` and then a `rewritten` layout, so the data is always right.
14
+ *
15
+ * @param text - the whole file
16
+ * @param edits - the changes, applied in order
17
+ * @param limits - the same limits as `readYaml`; they apply to the result too
18
+ * @returns the new text and its layout; or the problem `readYaml` gives for an
19
+ * unreadable `text`; or a `bad-edit` for the first edit that doesn't fit, with
20
+ * no edit applied
21
+ *
22
+ * @example
23
+ * const edited = editYaml("name: Billing # shown in the list\n", [
24
+ * { kind: "set", path: ["name"], value: "Invoices" },
25
+ * ]);
26
+ * // { ok: true, value: { text: "name: Invoices # shown in the list\n", layout: "kept" } }
27
+ */
28
+ export function editYaml(text, edits, limits = defaultYamlLimits) {
29
+ const read = readYaml(text, limits);
30
+ if (!read.ok) {
31
+ return read;
32
+ }
33
+ let current = { text, data: read.value.data, layout: "kept" };
34
+ for (const [index, edit] of edits.entries()) {
35
+ const step = applyEdit(current, edit, limits);
36
+ if (!step.ok) {
37
+ return err({ kind: "bad-edit", edit: index, message: step.error });
38
+ }
39
+ current = { ...step.value, layout: worseLayout(current.layout, step.value.layout) };
40
+ }
41
+ return ok({ text: current.text, layout: current.layout });
42
+ }
43
+ const layoutOrder = ["kept", "reformatted", "rewritten"];
44
+ function worseLayout(first, second) {
45
+ return layoutOrder.indexOf(first) >= layoutOrder.indexOf(second) ? first : second;
46
+ }
47
+ function applyEdit(before, edit, limits) {
48
+ const valueProblem = edit.kind === "delete" ? undefined : checkValue(edit.value, limits.maxDepth);
49
+ if (valueProblem !== undefined) {
50
+ return err(valueProblem);
51
+ }
52
+ const expected = applyEditToData(before.data, edit);
53
+ if (!expected.ok) {
54
+ return expected;
55
+ }
56
+ if (deepEqual(expected.value, before.data)) {
57
+ return ok({ text: before.text, data: before.data, layout: "kept" });
58
+ }
59
+ const attempts = [
60
+ ["kept", () => spliceEdit(before.text, edit)],
61
+ ["reformatted", () => renderWithDocument(before.text, edit, expected.value)],
62
+ ["rewritten", () => writeYamlFile(expected.value)],
63
+ ];
64
+ for (const [layout, attempt] of attempts) {
65
+ const text = attempt();
66
+ if (text === undefined) {
67
+ continue;
68
+ }
69
+ const readBack = readYaml(text, limits);
70
+ if (!readBack.ok &&
71
+ (readBack.error.kind === "too-deep" || readBack.error.kind === "too-large")) {
72
+ return err(readBack.error.message);
73
+ }
74
+ if (readBack.ok && deepEqual(readBack.value.data, expected.value)) {
75
+ return ok({ text, data: expected.value, layout });
76
+ }
77
+ }
78
+ return err("The new value doesn't read back the same from YAML.");
79
+ }
80
+ /**
81
+ * The first fallback: the same edit through the yaml library's Document API,
82
+ * rendered again. Comments stay; spacing may not.
83
+ */
84
+ function renderWithDocument(text, edit, expected) {
85
+ const document = parseDocument(text);
86
+ if (edit.kind === "delete") {
87
+ document.deleteIn(edit.path);
88
+ return render(text, document);
89
+ }
90
+ if (edit.kind === "insert") {
91
+ return insertIntoDocument(document, edit) ? render(text, document) : undefined;
92
+ }
93
+ return setInDocument(text, document, edit, expected);
94
+ }
95
+ function insertIntoDocument(document, edit) {
96
+ const { path } = edit;
97
+ const list = document.getIn(path.slice(0, -1), true);
98
+ if (!isSeq(list)) {
99
+ return false;
100
+ }
101
+ list.items.splice(path[path.length - 1], 0, document.createNode(edit.value));
102
+ return true;
103
+ }
104
+ function setInDocument(text, document, edit, expected) {
105
+ const { path } = edit;
106
+ const existing = document.getIn(path, true);
107
+ if (isScalar(existing) && (edit.value === null || typeof edit.value !== "object")) {
108
+ // Change the scalar in place, so a comment on its line stays.
109
+ existing.value = edit.value;
110
+ return render(text, document);
111
+ }
112
+ // Set from the first key that is missing or empty, so the maps under it are created too.
113
+ const from = firstEmpty(document, path);
114
+ const value = document.createNode(valueAt(expected, path.slice(0, from)));
115
+ if (from === 0) {
116
+ replaceContents(document, value);
117
+ }
118
+ else {
119
+ const isNewKey = from === path.length && !document.hasIn(path);
120
+ document.setIn(path.slice(0, from), value);
121
+ if (isNewKey && edit.kind === "set" && edit.after !== undefined) {
122
+ moveNewPair(document, path, edit.after);
123
+ }
124
+ }
125
+ return render(text, document);
126
+ }
127
+ /**
128
+ * Moves the pair `setIn` just added at the end of its map to where `after`
129
+ * says: right after that key, or first for `null`. A key `after` names that
130
+ * isn't there leaves it at the end.
131
+ */
132
+ function moveNewPair(document, path, after) {
133
+ const map = path.length === 1 ? document.contents : document.getIn(path.slice(0, -1), true);
134
+ if (!isMap(map)) {
135
+ return;
136
+ }
137
+ const added = map.items.pop();
138
+ if (added === undefined) {
139
+ return;
140
+ }
141
+ if (after === null) {
142
+ map.items.unshift(added);
143
+ return;
144
+ }
145
+ const previous = map.items.findIndex((pair) => isScalar(pair.key) && String(pair.key.value) === after);
146
+ if (previous === -1) {
147
+ map.items.push(added);
148
+ return;
149
+ }
150
+ map.items.splice(previous + 1, 0, added);
151
+ }
152
+ /** Replace the whole document, carrying over the comment at the top of the file. */
153
+ function replaceContents(document, value) {
154
+ const top = topCommentNode(document.contents);
155
+ if (top?.commentBefore) {
156
+ value.commentBefore = top.commentBefore;
157
+ }
158
+ if (top?.spaceBefore) {
159
+ value.spaceBefore = true;
160
+ }
161
+ document.contents = value;
162
+ }
163
+ function render(text, document) {
164
+ const lines = document.toString({ lineWidth: 100 });
165
+ // The library writes `\n` and drops a byte order mark; Windows editors expect both back.
166
+ const rendered = lineEndingOf(text) === "\r\n" ? lines.replaceAll("\n", "\r\n") : lines;
167
+ return text.startsWith(byteOrderMark) ? byteOrderMark + rendered : rendered;
168
+ }
169
+ const byteOrderMark = "\uFEFF";
170
+ /**
171
+ * The node that holds the comment at the top of the file, which a whole-document `set`
172
+ * must carry over. With a blank line after it, the comment is on the document and stays
173
+ * by itself. Without one, the library hangs it on the first key or item, or on the contents.
174
+ */
175
+ function topCommentNode(contents) {
176
+ if (contents?.commentBefore || !isCollection(contents)) {
177
+ return contents ?? undefined;
178
+ }
179
+ const first = contents.items[0];
180
+ const node = isPair(first) ? first.key : first;
181
+ return isNode(node) ? node : undefined;
182
+ }
183
+ function firstEmpty(document, path) {
184
+ for (let length = 0; length < path.length; length++) {
185
+ const node = length === 0 ? document.contents : document.getIn(path.slice(0, length), true);
186
+ if (node === undefined || node === null || document.getIn(path.slice(0, length)) === null) {
187
+ return length;
188
+ }
189
+ }
190
+ return path.length;
191
+ }
192
+ function valueAt(data, path) {
193
+ let value = data;
194
+ for (const key of path) {
195
+ value = value[key];
196
+ }
197
+ return value;
198
+ }
@@ -0,0 +1,5 @@
1
+ export { editYaml, type YamlEdited, type YamlEditProblem, type YamlLayout, } from "./edit.js";
2
+ export type { YamlEdit } from "./edit-data.js";
3
+ export type { SourcePosition, YamlProblem, YamlProblemKind } from "./problem.js";
4
+ export { defaultYamlLimits, readYaml, type YamlFile, type YamlLimits, type YamlPath, } from "./read.js";
5
+ export { type FrontMatterFields, writeFrontMatter, writeYamlFile } from "./write.js";
@@ -0,0 +1,4 @@
1
+ // The public API of @halonicjs/yaml. Everything else in src/ is internal.
2
+ export { editYaml, } from "./edit.js";
3
+ export { defaultYamlLimits, readYaml, } from "./read.js";
4
+ export { writeFrontMatter, writeYamlFile } from "./write.js";
@@ -0,0 +1,20 @@
1
+ /** A 1-based line and column in a YAML text. */
2
+ export interface SourcePosition {
3
+ readonly line: number;
4
+ readonly col: number;
5
+ }
6
+ /**
7
+ * Why a YAML text could not be read:
8
+ * - `syntax`: the text is not valid YAML.
9
+ * - `unsupported`: valid YAML that workspace files may not use (anchors,
10
+ * aliases, tags, several documents, lists or maps as keys).
11
+ * - `too-deep`: lists and maps nest deeper than the limit.
12
+ * - `too-large`: the text is longer than the limit.
13
+ */
14
+ export type YamlProblemKind = "syntax" | "unsupported" | "too-deep" | "too-large";
15
+ /** A YAML text that could not be read, and where the reason sits in it. */
16
+ export interface YamlProblem extends SourcePosition {
17
+ readonly kind: YamlProblemKind;
18
+ /** One line that says what is wrong, without the position. */
19
+ readonly message: string;
20
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,47 @@
1
+ import { type Result } from "../../std/src/index.js";
2
+ import type { SourcePosition, YamlProblem } from "./problem.js";
3
+ /** The keys and list indexes from the top of a file down to one value. */
4
+ export type YamlPath = readonly (string | number)[];
5
+ /** Limits that keep a hostile file from using up memory or the call stack. */
6
+ export interface YamlLimits {
7
+ /** The most levels lists and maps may nest. */
8
+ readonly maxDepth: number;
9
+ /** The longest text, in UTF-16 code units (what `string.length` counts). */
10
+ readonly maxLength: number;
11
+ }
12
+ /**
13
+ * Generous for workspace files, which nest about ten levels and stay well
14
+ * under a megabyte.
15
+ */
16
+ export declare const defaultYamlLimits: YamlLimits;
17
+ /** A YAML text that was read: its data, and where each value sits. */
18
+ export interface YamlFile {
19
+ /**
20
+ * The data, as plain objects, arrays, strings, numbers, booleans and
21
+ * `null`. An empty file, or one with only comments, gives `null`.
22
+ */
23
+ readonly data: unknown;
24
+ /**
25
+ * Where the value at `path` starts. When nothing sits at `path`, the
26
+ * nearest parent that exists answers instead. A missing key points at the
27
+ * key of the map that should hold it (or at the map itself when it has no
28
+ * key, like a list item or the top of the file). `undefined` only for a
29
+ * file with no data at all.
30
+ */
31
+ positionOf(path: YamlPath): SourcePosition | undefined;
32
+ }
33
+ /**
34
+ * Reads a workspace YAML file with the same YAML rules as the old app
35
+ * (YAML 1.2 core schema, so `yes` stays text), and rejects what workspace
36
+ * files may not use: anchors, aliases, tags, several documents and lists or
37
+ * maps as keys.
38
+ *
39
+ * @param text - the whole file
40
+ * @param limits - depth and length limits; the defaults suit workspace files
41
+ * @returns the data and positions, or the first problem with its line and column
42
+ *
43
+ * @example
44
+ * const read = readYaml("name: Billing\nsteps:\n - id: check\n");
45
+ * if (read.ok) read.value.positionOf(["steps", 0, "id"]); // { line: 3, col: 9 }
46
+ */
47
+ export declare function readYaml(text: string, limits?: YamlLimits): Result<YamlFile, YamlProblem>;