@driftsys/markspec 0.10.3 → 0.11.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 (376) hide show
  1. package/README.md +2 -2
  2. package/esm/compiler/deserialize.d.ts +49 -0
  3. package/esm/compiler/deserialize.d.ts.map +1 -0
  4. package/esm/compiler/deserialize.js +139 -0
  5. package/esm/compiler/manifest.d.ts +3 -0
  6. package/esm/compiler/manifest.d.ts.map +1 -1
  7. package/esm/compiler/manifest.js +9 -3
  8. package/esm/compiler/mod.d.ts.map +1 -1
  9. package/esm/compiler/mod.js +16 -7
  10. package/esm/config/markspec.d.ts +38 -1
  11. package/esm/config/markspec.d.ts.map +1 -1
  12. package/esm/config/markspec.js +127 -2
  13. package/esm/config/mod.d.ts.map +1 -1
  14. package/esm/config/mod.js +143 -147
  15. package/esm/decl/duplicates.d.ts +29 -0
  16. package/esm/decl/duplicates.d.ts.map +1 -0
  17. package/esm/decl/duplicates.js +28 -0
  18. package/esm/decl/mod.d.ts +4 -2
  19. package/esm/decl/mod.d.ts.map +1 -1
  20. package/esm/decl/mod.js +2 -1
  21. package/esm/decl/surfaces.d.ts +29 -7
  22. package/esm/decl/surfaces.d.ts.map +1 -1
  23. package/esm/decl/surfaces.js +31 -18
  24. package/esm/gates/mod.d.ts +13 -2
  25. package/esm/gates/mod.d.ts.map +1 -1
  26. package/esm/gates/mod.js +38 -11
  27. package/esm/lint/runner.d.ts.map +1 -1
  28. package/esm/lint/runner.js +3 -1
  29. package/esm/lock/acquire_compile.d.ts +31 -0
  30. package/esm/lock/acquire_compile.d.ts.map +1 -0
  31. package/esm/lock/acquire_compile.js +83 -0
  32. package/esm/lock/cache_check.d.ts +28 -0
  33. package/esm/lock/cache_check.d.ts.map +1 -0
  34. package/esm/lock/cache_check.js +51 -0
  35. package/esm/lock/check.d.ts +14 -3
  36. package/esm/lock/check.d.ts.map +1 -1
  37. package/esm/lock/check.js +41 -3
  38. package/esm/lock/git_intent.d.ts +46 -0
  39. package/esm/lock/git_intent.d.ts.map +1 -0
  40. package/esm/lock/git_intent.js +111 -0
  41. package/esm/lock/mod.d.ts +10 -3
  42. package/esm/lock/mod.d.ts.map +1 -1
  43. package/esm/lock/mod.js +7 -1
  44. package/esm/lock/model.d.ts +24 -1
  45. package/esm/lock/model.d.ts.map +1 -1
  46. package/esm/lock/parser.d.ts.map +1 -1
  47. package/esm/lock/parser.js +32 -0
  48. package/esm/lock/pin_assurance.d.ts +20 -0
  49. package/esm/lock/pin_assurance.d.ts.map +1 -0
  50. package/esm/lock/pin_assurance.js +34 -0
  51. package/esm/lock/resolve.d.ts +8 -17
  52. package/esm/lock/resolve.d.ts.map +1 -1
  53. package/esm/lock/resolve.js +7 -67
  54. package/esm/lock/serializer.d.ts.map +1 -1
  55. package/esm/lock/serializer.js +23 -0
  56. package/esm/lock/upstream_common.d.ts +29 -0
  57. package/esm/lock/upstream_common.d.ts.map +1 -0
  58. package/esm/lock/upstream_common.js +38 -0
  59. package/esm/lock/upstream_deps.d.ts +63 -0
  60. package/esm/lock/upstream_deps.d.ts.map +1 -0
  61. package/esm/lock/upstream_deps.js +172 -0
  62. package/esm/lock/upstream_refs.d.ts +69 -0
  63. package/esm/lock/upstream_refs.d.ts.map +1 -0
  64. package/esm/lock/upstream_refs.js +238 -0
  65. package/esm/mod.d.ts +16 -8
  66. package/esm/mod.d.ts.map +1 -1
  67. package/esm/mod.js +15 -5
  68. package/esm/model/mod.d.ts +93 -28
  69. package/esm/model/mod.d.ts.map +1 -1
  70. package/esm/model/mod.js +66 -13
  71. package/esm/model/profile.d.ts +13 -0
  72. package/esm/model/profile.d.ts.map +1 -1
  73. package/esm/parser/markdown.d.ts.map +1 -1
  74. package/esm/parser/markdown.js +7 -51
  75. package/esm/profile/manifest.d.ts.map +1 -1
  76. package/esm/profile/manifest.js +20 -3
  77. package/esm/profile/merge.js +7 -0
  78. package/esm/reporter/mod.d.ts +11 -0
  79. package/esm/reporter/mod.d.ts.map +1 -1
  80. package/esm/reporter/mod.js +19 -8
  81. package/esm/typl/assemble.d.ts +53 -0
  82. package/esm/typl/assemble.d.ts.map +1 -0
  83. package/esm/typl/assemble.js +238 -0
  84. package/esm/typl/ast.d.ts +7 -1
  85. package/esm/typl/ast.d.ts.map +1 -1
  86. package/esm/typl/ast.js +3 -0
  87. package/esm/typl/bullet.d.ts +9 -7
  88. package/esm/typl/bullet.d.ts.map +1 -1
  89. package/esm/typl/bullet.js +6 -4
  90. package/esm/typl/citations.d.ts +27 -0
  91. package/esm/typl/citations.d.ts.map +1 -0
  92. package/esm/typl/citations.js +16 -0
  93. package/esm/typl/diagnostics.d.ts +2 -2
  94. package/esm/typl/diagnostics.d.ts.map +1 -1
  95. package/esm/typl/diagnostics.js +18 -0
  96. package/esm/typl/grammar.d.ts.map +1 -1
  97. package/esm/typl/grammar.js +6 -0
  98. package/esm/typl/lexer.d.ts.map +1 -1
  99. package/esm/typl/lexer.js +25 -4
  100. package/esm/typl/mod.d.ts +8 -2
  101. package/esm/typl/mod.d.ts.map +1 -1
  102. package/esm/typl/mod.js +5 -1
  103. package/esm/typl/recognize.js +2 -2
  104. package/esm/typl/registry.d.ts +1 -1
  105. package/esm/typl/resolve.d.ts +31 -0
  106. package/esm/typl/resolve.d.ts.map +1 -0
  107. package/esm/typl/resolve.js +27 -0
  108. package/esm/typl/table.d.ts +52 -0
  109. package/esm/typl/table.d.ts.map +1 -0
  110. package/esm/typl/table.js +69 -0
  111. package/esm/typl/validator.d.ts +24 -5
  112. package/esm/typl/validator.d.ts.map +1 -1
  113. package/esm/typl/validator.js +55 -75
  114. package/esm/upstream/mod.d.ts +45 -0
  115. package/esm/upstream/mod.d.ts.map +1 -0
  116. package/esm/upstream/mod.js +98 -0
  117. package/esm/upstream/project.d.ts +33 -0
  118. package/esm/upstream/project.d.ts.map +1 -0
  119. package/esm/upstream/project.js +38 -0
  120. package/esm/upstream/refs.d.ts +23 -0
  121. package/esm/upstream/refs.d.ts.map +1 -0
  122. package/esm/upstream/refs.js +71 -0
  123. package/esm/util/paths.d.ts +14 -0
  124. package/esm/util/paths.d.ts.map +1 -0
  125. package/esm/util/paths.js +22 -0
  126. package/esm/uxil/assemble.d.ts +38 -0
  127. package/esm/uxil/assemble.d.ts.map +1 -0
  128. package/esm/uxil/assemble.js +268 -0
  129. package/esm/uxil/ast.d.ts +63 -0
  130. package/esm/uxil/ast.d.ts.map +1 -0
  131. package/esm/uxil/ast.js +9 -0
  132. package/esm/uxil/citations.d.ts +27 -0
  133. package/esm/uxil/citations.d.ts.map +1 -0
  134. package/esm/uxil/citations.js +25 -0
  135. package/esm/uxil/diagnostics.d.ts +39 -0
  136. package/esm/uxil/diagnostics.d.ts.map +1 -0
  137. package/esm/uxil/diagnostics.js +135 -0
  138. package/esm/uxil/grammar.d.ts +72 -0
  139. package/esm/uxil/grammar.d.ts.map +1 -0
  140. package/esm/uxil/grammar.js +505 -0
  141. package/esm/uxil/lexer.d.ts +23 -0
  142. package/esm/uxil/lexer.d.ts.map +1 -0
  143. package/esm/uxil/lexer.js +58 -0
  144. package/esm/uxil/mod.d.ts +32 -0
  145. package/esm/uxil/mod.d.ts.map +1 -0
  146. package/esm/uxil/mod.js +11 -0
  147. package/esm/uxil/projection.d.ts +40 -0
  148. package/esm/uxil/projection.d.ts.map +1 -0
  149. package/esm/uxil/projection.js +41 -0
  150. package/esm/uxil/recognize.d.ts +16 -0
  151. package/esm/uxil/recognize.d.ts.map +1 -0
  152. package/esm/uxil/recognize.js +28 -0
  153. package/esm/uxil/registry.d.ts +37 -0
  154. package/esm/uxil/registry.d.ts.map +1 -0
  155. package/esm/uxil/registry.js +29 -0
  156. package/esm/uxil/surfaces.d.ts +36 -0
  157. package/esm/uxil/surfaces.d.ts.map +1 -0
  158. package/esm/uxil/surfaces.js +34 -0
  159. package/esm/uxil/validator.d.ts +36 -0
  160. package/esm/uxil/validator.d.ts.map +1 -0
  161. package/esm/uxil/validator.js +139 -0
  162. package/esm/uxil/vocab.d.ts +33 -0
  163. package/esm/uxil/vocab.d.ts.map +1 -0
  164. package/esm/uxil/vocab.js +36 -0
  165. package/esm/validator/caption_convention.d.ts +2 -1
  166. package/esm/validator/caption_convention.d.ts.map +1 -1
  167. package/esm/validator/caption_convention.js +2 -1
  168. package/esm/validator/corpus.d.ts.map +1 -1
  169. package/esm/validator/corpus.js +40 -17
  170. package/esm/validator/discipline.d.ts +6 -4
  171. package/esm/validator/discipline.d.ts.map +1 -1
  172. package/esm/validator/discipline.js +6 -4
  173. package/esm/validator/mod.d.ts.map +1 -1
  174. package/esm/validator/mod.js +28 -15
  175. package/esm/validator/pipeline.d.ts +11 -1
  176. package/esm/validator/pipeline.d.ts.map +1 -1
  177. package/esm/validator/pipeline.js +68 -18
  178. package/esm/validator/trace_types.d.ts +9 -2
  179. package/esm/validator/trace_types.d.ts.map +1 -1
  180. package/esm/validator/trace_types.js +21 -5
  181. package/esm/validator/traceability.d.ts +15 -3
  182. package/esm/validator/traceability.d.ts.map +1 -1
  183. package/esm/validator/traceability.js +39 -4
  184. package/esm/validator/types.d.ts.map +1 -1
  185. package/esm/validator/types.js +11 -1
  186. package/esm/validator/uxil_family.d.ts +43 -0
  187. package/esm/validator/uxil_family.d.ts.map +1 -0
  188. package/esm/validator/uxil_family.js +52 -0
  189. package/package.json +1 -1
  190. package/script/compiler/deserialize.d.ts +49 -0
  191. package/script/compiler/deserialize.d.ts.map +1 -0
  192. package/script/compiler/deserialize.js +144 -0
  193. package/script/compiler/manifest.d.ts +3 -0
  194. package/script/compiler/manifest.d.ts.map +1 -1
  195. package/script/compiler/manifest.js +10 -3
  196. package/script/compiler/mod.d.ts.map +1 -1
  197. package/script/compiler/mod.js +15 -6
  198. package/script/config/markspec.d.ts +38 -1
  199. package/script/config/markspec.d.ts.map +1 -1
  200. package/script/config/markspec.js +129 -3
  201. package/script/config/mod.d.ts.map +1 -1
  202. package/script/config/mod.js +143 -147
  203. package/script/decl/duplicates.d.ts +29 -0
  204. package/script/decl/duplicates.d.ts.map +1 -0
  205. package/script/decl/duplicates.js +31 -0
  206. package/script/decl/mod.d.ts +4 -2
  207. package/script/decl/mod.d.ts.map +1 -1
  208. package/script/decl/mod.js +4 -2
  209. package/script/decl/surfaces.d.ts +29 -7
  210. package/script/decl/surfaces.d.ts.map +1 -1
  211. package/script/decl/surfaces.js +32 -19
  212. package/script/gates/mod.d.ts +13 -2
  213. package/script/gates/mod.d.ts.map +1 -1
  214. package/script/gates/mod.js +37 -10
  215. package/script/lint/runner.d.ts.map +1 -1
  216. package/script/lint/runner.js +3 -1
  217. package/script/lock/acquire_compile.d.ts +31 -0
  218. package/script/lock/acquire_compile.d.ts.map +1 -0
  219. package/script/lock/acquire_compile.js +86 -0
  220. package/script/lock/cache_check.d.ts +28 -0
  221. package/script/lock/cache_check.d.ts.map +1 -0
  222. package/script/lock/cache_check.js +54 -0
  223. package/script/lock/check.d.ts +14 -3
  224. package/script/lock/check.d.ts.map +1 -1
  225. package/script/lock/check.js +41 -3
  226. package/script/lock/git_intent.d.ts +46 -0
  227. package/script/lock/git_intent.d.ts.map +1 -0
  228. package/script/lock/git_intent.js +115 -0
  229. package/script/lock/mod.d.ts +10 -3
  230. package/script/lock/mod.d.ts.map +1 -1
  231. package/script/lock/mod.js +16 -2
  232. package/script/lock/model.d.ts +24 -1
  233. package/script/lock/model.d.ts.map +1 -1
  234. package/script/lock/parser.d.ts.map +1 -1
  235. package/script/lock/parser.js +32 -0
  236. package/script/lock/pin_assurance.d.ts +20 -0
  237. package/script/lock/pin_assurance.d.ts.map +1 -0
  238. package/script/lock/pin_assurance.js +37 -0
  239. package/script/lock/resolve.d.ts +8 -17
  240. package/script/lock/resolve.d.ts.map +1 -1
  241. package/script/lock/resolve.js +7 -68
  242. package/script/lock/serializer.d.ts.map +1 -1
  243. package/script/lock/serializer.js +23 -0
  244. package/script/lock/upstream_common.d.ts +29 -0
  245. package/script/lock/upstream_common.d.ts.map +1 -0
  246. package/script/lock/upstream_common.js +42 -0
  247. package/script/lock/upstream_deps.d.ts +63 -0
  248. package/script/lock/upstream_deps.d.ts.map +1 -0
  249. package/script/lock/upstream_deps.js +175 -0
  250. package/script/lock/upstream_refs.d.ts +69 -0
  251. package/script/lock/upstream_refs.d.ts.map +1 -0
  252. package/script/lock/upstream_refs.js +244 -0
  253. package/script/mod.d.ts +16 -8
  254. package/script/mod.d.ts.map +1 -1
  255. package/script/mod.js +40 -7
  256. package/script/model/mod.d.ts +93 -28
  257. package/script/model/mod.d.ts.map +1 -1
  258. package/script/model/mod.js +70 -14
  259. package/script/model/profile.d.ts +13 -0
  260. package/script/model/profile.d.ts.map +1 -1
  261. package/script/parser/markdown.d.ts.map +1 -1
  262. package/script/parser/markdown.js +6 -50
  263. package/script/profile/manifest.d.ts.map +1 -1
  264. package/script/profile/manifest.js +20 -3
  265. package/script/profile/merge.js +7 -0
  266. package/script/reporter/mod.d.ts +11 -0
  267. package/script/reporter/mod.d.ts.map +1 -1
  268. package/script/reporter/mod.js +18 -7
  269. package/script/typl/assemble.d.ts +53 -0
  270. package/script/typl/assemble.d.ts.map +1 -0
  271. package/script/typl/assemble.js +241 -0
  272. package/script/typl/ast.d.ts +7 -1
  273. package/script/typl/ast.d.ts.map +1 -1
  274. package/script/typl/ast.js +3 -0
  275. package/script/typl/bullet.d.ts +9 -7
  276. package/script/typl/bullet.d.ts.map +1 -1
  277. package/script/typl/bullet.js +6 -4
  278. package/script/typl/citations.d.ts +27 -0
  279. package/script/typl/citations.d.ts.map +1 -0
  280. package/script/typl/citations.js +20 -0
  281. package/script/typl/diagnostics.d.ts +2 -2
  282. package/script/typl/diagnostics.d.ts.map +1 -1
  283. package/script/typl/diagnostics.js +18 -0
  284. package/script/typl/grammar.d.ts.map +1 -1
  285. package/script/typl/grammar.js +6 -0
  286. package/script/typl/lexer.d.ts.map +1 -1
  287. package/script/typl/lexer.js +25 -4
  288. package/script/typl/mod.d.ts +8 -2
  289. package/script/typl/mod.d.ts.map +1 -1
  290. package/script/typl/mod.js +14 -2
  291. package/script/typl/recognize.js +2 -2
  292. package/script/typl/registry.d.ts +1 -1
  293. package/script/typl/resolve.d.ts +31 -0
  294. package/script/typl/resolve.d.ts.map +1 -0
  295. package/script/typl/resolve.js +33 -0
  296. package/script/typl/table.d.ts +52 -0
  297. package/script/typl/table.d.ts.map +1 -0
  298. package/script/typl/table.js +75 -0
  299. package/script/typl/validator.d.ts +24 -5
  300. package/script/typl/validator.d.ts.map +1 -1
  301. package/script/typl/validator.js +55 -75
  302. package/script/upstream/mod.d.ts +45 -0
  303. package/script/upstream/mod.d.ts.map +1 -0
  304. package/script/upstream/mod.js +101 -0
  305. package/script/upstream/project.d.ts +33 -0
  306. package/script/upstream/project.d.ts.map +1 -0
  307. package/script/upstream/project.js +41 -0
  308. package/script/upstream/refs.d.ts +23 -0
  309. package/script/upstream/refs.d.ts.map +1 -0
  310. package/script/upstream/refs.js +74 -0
  311. package/script/util/paths.d.ts +14 -0
  312. package/script/util/paths.d.ts.map +1 -0
  313. package/script/util/paths.js +25 -0
  314. package/script/uxil/assemble.d.ts +38 -0
  315. package/script/uxil/assemble.d.ts.map +1 -0
  316. package/script/uxil/assemble.js +272 -0
  317. package/script/uxil/ast.d.ts +63 -0
  318. package/script/uxil/ast.d.ts.map +1 -0
  319. package/script/uxil/ast.js +10 -0
  320. package/script/uxil/citations.d.ts +27 -0
  321. package/script/uxil/citations.d.ts.map +1 -0
  322. package/script/uxil/citations.js +29 -0
  323. package/script/uxil/diagnostics.d.ts +39 -0
  324. package/script/uxil/diagnostics.d.ts.map +1 -0
  325. package/script/uxil/diagnostics.js +140 -0
  326. package/script/uxil/grammar.d.ts +72 -0
  327. package/script/uxil/grammar.d.ts.map +1 -0
  328. package/script/uxil/grammar.js +511 -0
  329. package/script/uxil/lexer.d.ts +23 -0
  330. package/script/uxil/lexer.d.ts.map +1 -0
  331. package/script/uxil/lexer.js +61 -0
  332. package/script/uxil/mod.d.ts +32 -0
  333. package/script/uxil/mod.d.ts.map +1 -0
  334. package/script/uxil/mod.js +37 -0
  335. package/script/uxil/projection.d.ts +40 -0
  336. package/script/uxil/projection.d.ts.map +1 -0
  337. package/script/uxil/projection.js +44 -0
  338. package/script/uxil/recognize.d.ts +16 -0
  339. package/script/uxil/recognize.d.ts.map +1 -0
  340. package/script/uxil/recognize.js +31 -0
  341. package/script/uxil/registry.d.ts +37 -0
  342. package/script/uxil/registry.d.ts.map +1 -0
  343. package/script/uxil/registry.js +32 -0
  344. package/script/uxil/surfaces.d.ts +36 -0
  345. package/script/uxil/surfaces.d.ts.map +1 -0
  346. package/script/uxil/surfaces.js +39 -0
  347. package/script/uxil/validator.d.ts +36 -0
  348. package/script/uxil/validator.d.ts.map +1 -0
  349. package/script/uxil/validator.js +142 -0
  350. package/script/uxil/vocab.d.ts +33 -0
  351. package/script/uxil/vocab.d.ts.map +1 -0
  352. package/script/uxil/vocab.js +41 -0
  353. package/script/validator/caption_convention.d.ts +2 -1
  354. package/script/validator/caption_convention.d.ts.map +1 -1
  355. package/script/validator/caption_convention.js +2 -1
  356. package/script/validator/corpus.d.ts.map +1 -1
  357. package/script/validator/corpus.js +39 -16
  358. package/script/validator/discipline.d.ts +6 -4
  359. package/script/validator/discipline.d.ts.map +1 -1
  360. package/script/validator/discipline.js +6 -4
  361. package/script/validator/mod.d.ts.map +1 -1
  362. package/script/validator/mod.js +27 -14
  363. package/script/validator/pipeline.d.ts +11 -1
  364. package/script/validator/pipeline.d.ts.map +1 -1
  365. package/script/validator/pipeline.js +67 -17
  366. package/script/validator/trace_types.d.ts +9 -2
  367. package/script/validator/trace_types.d.ts.map +1 -1
  368. package/script/validator/trace_types.js +20 -4
  369. package/script/validator/traceability.d.ts +15 -3
  370. package/script/validator/traceability.d.ts.map +1 -1
  371. package/script/validator/traceability.js +38 -3
  372. package/script/validator/types.d.ts.map +1 -1
  373. package/script/validator/types.js +10 -0
  374. package/script/validator/uxil_family.d.ts +43 -0
  375. package/script/validator/uxil_family.d.ts.map +1 -0
  376. package/script/validator/uxil_family.js +56 -0
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @module core/lock/upstream_common
3
+ *
4
+ * Primitives shared by the two lock-mediated upstream acquirers —
5
+ * `upstream_refs.ts` (published `references:` snapshots) and
6
+ * `upstream_deps.ts` (git `dependencies:` trees). Both emit the same
7
+ * MSL-L213 "could not be locked" warning (differing only by the noun) and
8
+ * write a `[path, bytes][]` cache batch with identical error handling, so
9
+ * the primitive lives here once rather than duplicated in each module.
10
+ */
11
+ import type { Diagnostic } from "../model/mod.js";
12
+ /** The two upstream kinds, used only to word the shared MSL-L213 message. */
13
+ export type UpstreamNoun = "reference" | "dependency";
14
+ /**
15
+ * Warn-and-write diagnostic (design §4.2, decision 1): one upstream could
16
+ * not be locked. Identical shape for both kinds — `noun` selects the word.
17
+ */
18
+ export declare function upstreamNotLockable(noun: UpstreamNoun, id: string, detail: string): Diagnostic;
19
+ /**
20
+ * Write a batch of `[absolutePath, bytes]` cache files via the injected
21
+ * `writeFile` (which creates parent directories). Returns an MSL-L213
22
+ * warning naming the clean `id` (never the raw path) on the first failure,
23
+ * or `undefined` when every write succeeds. Shared by both acquirers' cache
24
+ * writers so a cache-write-failure message is worded identically.
25
+ */
26
+ export declare function writeCacheFiles(writes: ReadonlyArray<readonly [string, Uint8Array]>, noun: UpstreamNoun, id: string, writeFile: (path: string, bytes: Uint8Array) => Promise<{
27
+ error?: string;
28
+ }>): Promise<Diagnostic | undefined>;
29
+ //# sourceMappingURL=upstream_common.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upstream_common.d.ts","sourceRoot":"","sources":["../../src/lock/upstream_common.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,6EAA6E;AAC7E,MAAM,MAAM,YAAY,GAAG,WAAW,GAAG,YAAY,CAAC;AAEtD;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,YAAY,EAClB,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,MAAM,GACb,UAAU,CAOZ;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,EACpD,IAAI,EAAE,YAAY,EAClB,EAAE,EAAE,MAAM,EACV,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,KAAK,OAAO,CAAC;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,GAC1E,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAYjC"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ /**
3
+ * @module core/lock/upstream_common
4
+ *
5
+ * Primitives shared by the two lock-mediated upstream acquirers —
6
+ * `upstream_refs.ts` (published `references:` snapshots) and
7
+ * `upstream_deps.ts` (git `dependencies:` trees). Both emit the same
8
+ * MSL-L213 "could not be locked" warning (differing only by the noun) and
9
+ * write a `[path, bytes][]` cache batch with identical error handling, so
10
+ * the primitive lives here once rather than duplicated in each module.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.upstreamNotLockable = upstreamNotLockable;
14
+ exports.writeCacheFiles = writeCacheFiles;
15
+ /**
16
+ * Warn-and-write diagnostic (design §4.2, decision 1): one upstream could
17
+ * not be locked. Identical shape for both kinds — `noun` selects the word.
18
+ */
19
+ function upstreamNotLockable(noun, id, detail) {
20
+ return {
21
+ code: "MSL-L213",
22
+ severity: "warning",
23
+ message: `upstream ${noun} '${id}' could not be locked: ${detail}`,
24
+ location: undefined,
25
+ };
26
+ }
27
+ /**
28
+ * Write a batch of `[absolutePath, bytes]` cache files via the injected
29
+ * `writeFile` (which creates parent directories). Returns an MSL-L213
30
+ * warning naming the clean `id` (never the raw path) on the first failure,
31
+ * or `undefined` when every write succeeds. Shared by both acquirers' cache
32
+ * writers so a cache-write-failure message is worded identically.
33
+ */
34
+ async function writeCacheFiles(writes, noun, id, writeFile) {
35
+ for (const [path, bytes] of writes) {
36
+ const res = await writeFile(path, bytes);
37
+ if (res.error !== undefined) {
38
+ return upstreamNotLockable(noun, id, `cache write of '${path}' failed (${res.error})`);
39
+ }
40
+ }
41
+ return undefined;
42
+ }
@@ -0,0 +1,63 @@
1
+ /**
2
+ * @module core/lock/upstream_deps
3
+ *
4
+ * Lock-mediated acquisition of org-manifest `dependencies:` git repositories
5
+ * (design §4.3), the sibling of `upstream_refs.ts`. Unlike a `references:`
6
+ * published site (fetched as ready JSON), a dependency is a git tree we
7
+ * resolve, acquire at one sha, and compile in-process into the same cache
8
+ * layout. Three flows: first-lock (resolve intent → acquire → compile → pin),
9
+ * keep/restore (pin exists → verify cache offline, re-acquire the *pinned* sha
10
+ * only to repopulate), update (`--update` → re-resolve + move the pin).
11
+ *
12
+ * Warn-and-write policy (design §4.2, decision 1): an unreachable dependency
13
+ * yields a warning and the resolvable pins still lock. Pure — git, fs, and
14
+ * temp-dir access flow through {@linkcode UpstreamDepsIO}.
15
+ */
16
+ import type { Diagnostic, ProjectRef } from "../model/mod.js";
17
+ import type { UpstreamDependency } from "./model.js";
18
+ import type { ReadFile } from "./resolve.js";
19
+ import { type RefList } from "./git_intent.js";
20
+ import type { CompiledSnapshot } from "./acquire_compile.js";
21
+ export interface GitIO {
22
+ lsRemote(url: string): Promise<RefList | {
23
+ error: string;
24
+ }>;
25
+ acquireTree(url: string, sha: string, destDir: string): Promise<{
26
+ error?: string;
27
+ }>;
28
+ }
29
+ export interface UpstreamDepsIO {
30
+ readonly git: GitIO;
31
+ readonly compileTree: (treeRoot: string) => Promise<CompiledSnapshot | {
32
+ error: string;
33
+ }>;
34
+ readonly readFile: ReadFile;
35
+ readonly writeFile: (path: string, bytes: Uint8Array) => Promise<{
36
+ error?: string;
37
+ }>;
38
+ readonly makeTempDir: () => Promise<string>;
39
+ readonly removeDir: (path: string) => Promise<void>;
40
+ }
41
+ export interface ResolveProjectDependenciesOptions {
42
+ readonly dependencies: readonly ProjectRef[];
43
+ readonly existing: readonly UpstreamDependency[];
44
+ readonly cacheRoot: string;
45
+ readonly update: boolean | string;
46
+ readonly io: UpstreamDepsIO;
47
+ readonly lockedAt: string;
48
+ /**
49
+ * Upstream ids already claimed by declared `references:` entries. A
50
+ * dependency whose derived id collides with one is skipped with an
51
+ * MSL-L216 warning (warn-and-write) — the reference snapshot owns that
52
+ * cache namespace, and two rows under one id would clobber each other's
53
+ * cache and double-map the corpus. Defaults to empty (no cross-kind
54
+ * dedup) for callers that resolve dependencies in isolation.
55
+ */
56
+ readonly reservedIds?: ReadonlySet<string>;
57
+ }
58
+ export interface ResolveProjectDependenciesResult {
59
+ readonly dependencies: UpstreamDependency[];
60
+ readonly diagnostics: Diagnostic[];
61
+ }
62
+ export declare function resolveProjectDependencies(opts: ResolveProjectDependenciesOptions): Promise<ResolveProjectDependenciesResult>;
63
+ //# sourceMappingURL=upstream_deps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upstream_deps.d.ts","sourceRoot":"","sources":["../../src/lock/upstream_deps.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG7C,OAAO,EAAE,KAAK,OAAO,EAAiB,MAAM,iBAAiB,CAAC;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC5D,WAAW,CACT,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,GACd,OAAO,CAAC;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC;IACpB,QAAQ,CAAC,WAAW,EAAE,CACpB,QAAQ,EAAE,MAAM,KACb,OAAO,CAAC,gBAAgB,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACnD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,CAClB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,UAAU,KACd,OAAO,CAAC;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACjC,QAAQ,CAAC,WAAW,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IAC5C,QAAQ,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACrD;AAED,MAAM,WAAW,iCAAiC;IAChD,QAAQ,CAAC,YAAY,EAAE,SAAS,UAAU,EAAE,CAAC;IAC7C,QAAQ,CAAC,QAAQ,EAAE,SAAS,kBAAkB,EAAE,CAAC;IACjD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC;IAClC,QAAQ,CAAC,EAAE,EAAE,cAAc,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B;;;;;;;OAOG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAC5C;AAED,MAAM,WAAW,gCAAgC;IAC/C,QAAQ,CAAC,YAAY,EAAE,kBAAkB,EAAE,CAAC;IAC5C,QAAQ,CAAC,WAAW,EAAE,UAAU,EAAE,CAAC;CACpC;AAkID,wBAAsB,0BAA0B,CAC9C,IAAI,EAAE,iCAAiC,GACtC,OAAO,CAAC,gCAAgC,CAAC,CA+D3C"}
@@ -0,0 +1,175 @@
1
+ "use strict";
2
+ /**
3
+ * @module core/lock/upstream_deps
4
+ *
5
+ * Lock-mediated acquisition of org-manifest `dependencies:` git repositories
6
+ * (design §4.3), the sibling of `upstream_refs.ts`. Unlike a `references:`
7
+ * published site (fetched as ready JSON), a dependency is a git tree we
8
+ * resolve, acquire at one sha, and compile in-process into the same cache
9
+ * layout. Three flows: first-lock (resolve intent → acquire → compile → pin),
10
+ * keep/restore (pin exists → verify cache offline, re-acquire the *pinned* sha
11
+ * only to repopulate), update (`--update` → re-resolve + move the pin).
12
+ *
13
+ * Warn-and-write policy (design §4.2, decision 1): an unreachable dependency
14
+ * yields a warning and the resolvable pins still lock. Pure — git, fs, and
15
+ * temp-dir access flow through {@linkcode UpstreamDepsIO}.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.resolveProjectDependencies = resolveProjectDependencies;
19
+ const path_1 = require("@std/path");
20
+ const upstream_refs_js_1 = require("./upstream_refs.js");
21
+ const upstream_common_js_1 = require("./upstream_common.js");
22
+ const git_intent_js_1 = require("./git_intent.js");
23
+ /** Warn-and-write diagnostic — one dependency could not be locked (decision 1). */
24
+ function l213(id, detail) {
25
+ return (0, upstream_common_js_1.upstreamNotLockable)("dependency", id, detail);
26
+ }
27
+ /** Cross-kind id-collision diagnostic — a dependency id is already claimed
28
+ * by a `references:` entry (warn-and-write: the dependency is skipped). */
29
+ function l216(id) {
30
+ return {
31
+ code: "MSL-L216",
32
+ severity: "warning",
33
+ message: `upstream id '${id}' is claimed by both a 'references:' entry and a ` +
34
+ `'dependencies:' entry — skipping the dependency (the reference ` +
35
+ `snapshot owns the cache); set a distinct 'name:' on one of them`,
36
+ location: undefined,
37
+ };
38
+ }
39
+ /** Acquire the tree at `sha` into a fresh temp dir, compile it, clean up.
40
+ * A temp-dir creation failure is turned into a warn-and-write `{ error }`
41
+ * rather than propagating and aborting the whole lock. */
42
+ async function acquireAndCompile(url, sha, io) {
43
+ let tmp;
44
+ try {
45
+ tmp = await io.makeTempDir();
46
+ }
47
+ catch (err) {
48
+ return {
49
+ error: `temp dir creation failed (${err instanceof Error ? err.message : String(err)})`,
50
+ };
51
+ }
52
+ try {
53
+ const acq = await io.git.acquireTree(url, sha, tmp);
54
+ if (acq.error !== undefined) {
55
+ return { error: `acquire ${sha.slice(0, 12)} failed (${acq.error})` };
56
+ }
57
+ return await io.compileTree(tmp);
58
+ }
59
+ finally {
60
+ await io.removeDir(tmp);
61
+ }
62
+ }
63
+ /** Write `manifest.json` + `compiled.json` for a snapshot under `dir`. The
64
+ * clean `id` (not `dir`) is threaded through so a cache-write-failure
65
+ * warning names the upstream, not the raw cache path. */
66
+ function writeSnapshotCache(id, dir, snap, io) {
67
+ const writes = [
68
+ [
69
+ (0, path_1.join)(dir, "manifest.json"),
70
+ new TextEncoder().encode(JSON.stringify(snap.manifestJson, null, 2)),
71
+ ],
72
+ [(0, path_1.join)(dir, "compiled.json"), snap.compiledBytes],
73
+ ];
74
+ return (0, upstream_common_js_1.writeCacheFiles)(writes, "dependency", id, io.writeFile);
75
+ }
76
+ /**
77
+ * RESTORE — the pin exists but its cache is missing or hash-broken. Re-acquire
78
+ * the *pinned* sha (intent is NOT re-resolved) purely to repopulate the cache;
79
+ * the pin never moves. Returns a warning on any failure (unreachable, markspec
80
+ * version skew, or cache-write error) and `undefined` on a clean repopulate.
81
+ * In every case the caller keeps the existing row.
82
+ */
83
+ async function restore(id, existing, dir, io) {
84
+ const snap = await acquireAndCompile(existing.url, existing.sha, io);
85
+ if ("error" in snap)
86
+ return l213(id, `restore failed: ${snap.error}`);
87
+ if (snap.snapshot !== existing.snapshot) {
88
+ // Same sha but a different compiled hash → markspec wire-format skew
89
+ // (the source is byte-identical by git's guarantee). Keep the pin, do
90
+ // not clobber the cache; tell the user to re-pin explicitly.
91
+ return l213(id, `restore recompiled to a different snapshot (markspec version skew?) — run 'markspec lock --update=${id}' to re-pin`);
92
+ }
93
+ return await writeSnapshotCache(id, dir, snap, io);
94
+ }
95
+ /**
96
+ * FIRST-LOCK or UPDATE — resolve the declared intent to a sha, acquire,
97
+ * compile, and write the cache. Returns the new pinned row, or a warning
98
+ * (ls-remote / intent / acquire / cache-write failure). The caller decides
99
+ * whether to fall back to a prior `existing` row.
100
+ */
101
+ async function firstLockOrUpdate(ref, id, dir, intent, io, lockedAt) {
102
+ const refs = await io.git.lsRemote(ref.url);
103
+ if ("error" in refs)
104
+ return l213(id, `ls-remote failed (${refs.error})`);
105
+ const ri = (0, git_intent_js_1.resolveIntent)(intent, refs);
106
+ if ("error" in ri)
107
+ return l213(id, ri.error);
108
+ const snap = await acquireAndCompile(ref.url, ri.sha, io);
109
+ if ("error" in snap)
110
+ return l213(id, snap.error);
111
+ const writeErr = await writeSnapshotCache(id, dir, snap, io);
112
+ if (writeErr)
113
+ return writeErr;
114
+ return {
115
+ kind: "dependency",
116
+ id,
117
+ url: ref.url,
118
+ intent,
119
+ resolved: ri.resolved,
120
+ sha: ri.sha,
121
+ snapshot: snap.snapshot,
122
+ lockedAt,
123
+ };
124
+ }
125
+ async function resolveProjectDependencies(opts) {
126
+ const dependencies = [];
127
+ const diagnostics = [];
128
+ const byId = new Map(opts.existing.map((row) => [row.id, row]));
129
+ const seen = new Set();
130
+ for (const ref of opts.dependencies) {
131
+ const id = (0, upstream_refs_js_1.deriveUpstreamId)(ref);
132
+ if (id === undefined) {
133
+ diagnostics.push(l213(ref.name ?? ref.url, "no safe upstream id could be derived — set an explicit 'name:'"));
134
+ continue;
135
+ }
136
+ // Cross-kind collision: a `references:` entry already owns this id.
137
+ // Skip the dependency (warn-and-write) — it must not clobber the cache.
138
+ if (opts.reservedIds?.has(id)) {
139
+ diagnostics.push(l216(id));
140
+ continue;
141
+ }
142
+ if (seen.has(id)) {
143
+ diagnostics.push(l213(id, "duplicate upstream id — set distinct 'name:'"));
144
+ continue;
145
+ }
146
+ seen.add(id);
147
+ const dir = (0, path_1.join)(opts.cacheRoot, id);
148
+ const existing = byId.get(id);
149
+ const selectedForUpdate = opts.update === true || opts.update === id;
150
+ // KEEP / RESTORE
151
+ if (existing !== undefined && !selectedForUpdate) {
152
+ if (await (0, upstream_refs_js_1.probeCacheSnapshot)(dir, existing.snapshot, opts.io.readFile)) {
153
+ dependencies.push(existing); // idempotent — no git
154
+ continue;
155
+ }
156
+ const restoreDiag = await restore(id, existing, dir, opts.io);
157
+ if (restoreDiag)
158
+ diagnostics.push(restoreDiag);
159
+ dependencies.push(existing); // the pin never moves on restore
160
+ continue;
161
+ }
162
+ // FIRST-LOCK or UPDATE.
163
+ const intent = ref.version ?? "auto";
164
+ const outcome = await firstLockOrUpdate(ref, id, dir, intent, opts.io, opts.lockedAt);
165
+ if ("code" in outcome) {
166
+ diagnostics.push(outcome);
167
+ if (existing !== undefined)
168
+ dependencies.push(existing);
169
+ }
170
+ else {
171
+ dependencies.push(outcome);
172
+ }
173
+ }
174
+ return { dependencies, diagnostics };
175
+ }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * @module lock/upstream_refs
3
+ *
4
+ * Lock-mediated resolution of org-manifest `references:` projectRefs
5
+ * (design §4.2): fetch a published compile-output snapshot over https or
6
+ * `file://`, cache it under `.markspec/cache/upstreams/<id>/`, and pin it
7
+ * as an extended `[[upstream.registry]]` lockfile row. Three flows:
8
+ * first lock (new declaration → fetch + pin), keep/restore (pin exists →
9
+ * verify cache offline, refetch only to repopulate, never move the pin),
10
+ * update (`--update` → refetch + move the pin).
11
+ *
12
+ * Pure module: network and file access only via {@linkcode UpstreamRefsIO}.
13
+ */
14
+ import type { Diagnostic, ProjectRef } from "../model/mod.js";
15
+ import type { UpstreamRegistry } from "./model.js";
16
+ import type { FetchUrl, ReadFile } from "./resolve.js";
17
+ /**
18
+ * Root directory under which every upstream's cached snapshot is stored,
19
+ * one subdirectory per upstream id (`<root>/<id>/manifest.json`, etc.).
20
+ * Shared by `markspec lock` (the writer) and `markspec check` (the
21
+ * offline MSL-L212 prober) so the two commands can never disagree on
22
+ * where the cache lives.
23
+ */
24
+ export declare function upstreamCacheRoot(projectRoot: string): string;
25
+ /** IO seam — the CLI supplies Deno-backed implementations. */
26
+ export interface UpstreamRefsIO {
27
+ readonly fetchUrl: FetchUrl;
28
+ /** Bytes reader used to probe the existing cache (missing → `{error}`). */
29
+ readonly readFile: ReadFile;
30
+ /** Write `bytes` to `path`, creating parent directories. */
31
+ readonly writeFile: (path: string, bytes: Uint8Array) => Promise<{
32
+ error?: string;
33
+ }>;
34
+ }
35
+ /** See module doc. */
36
+ export interface ResolveProjectReferencesOptions {
37
+ readonly references: readonly ProjectRef[];
38
+ readonly existing: readonly UpstreamRegistry[];
39
+ readonly cacheRoot: string;
40
+ readonly update: boolean | string;
41
+ readonly io: UpstreamRefsIO;
42
+ readonly lockedAt: string;
43
+ }
44
+ /** Result of {@linkcode resolveProjectReferences}. */
45
+ export interface ResolveProjectReferencesResult {
46
+ readonly registries: UpstreamRegistry[];
47
+ readonly diagnostics: Diagnostic[];
48
+ }
49
+ /**
50
+ * Derive the upstream id for a projectRef: the explicit `name`, else the
51
+ * last non-empty path segment of the URL with any `.git` suffix stripped.
52
+ * Returns `undefined` when no safe id can be derived.
53
+ */
54
+ export declare function deriveUpstreamId(ref: ProjectRef): string | undefined;
55
+ /**
56
+ * Probe whether the cached snapshot under `dir` is present and hash-intact
57
+ * against `snapshot`: `manifest.json` must exist and parse, its
58
+ * `entries.file` must name a safe relative path, and the hashed bytes of
59
+ * that file must equal `snapshot`.
60
+ *
61
+ * Shared by {@linkcode cacheIntact} (this module's keep/restore flow) and
62
+ * `verifyUpstreamCache` (`cache_check.ts`'s MSL-L212 offline cache-drift
63
+ * gate) so the two never disagree on what "cache intact" means — the
64
+ * single probe implementation, not a duplicate.
65
+ */
66
+ export declare function probeCacheSnapshot(dir: string, snapshot: string, readFile: ReadFile): Promise<boolean>;
67
+ /** See module doc for the flow table. */
68
+ export declare function resolveProjectReferences(opts: ResolveProjectReferencesOptions): Promise<ResolveProjectReferencesResult>;
69
+ //# sourceMappingURL=upstream_refs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upstream_refs.d.ts","sourceRoot":"","sources":["../../src/lock/upstream_refs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAMvD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED,8DAA8D;AAC9D,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,2EAA2E;IAC3E,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,4DAA4D;IAC5D,QAAQ,CAAC,SAAS,EAAE,CAClB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,UAAU,KACd,OAAO,CAAC;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAClC;AAED,sBAAsB;AACtB,MAAM,WAAW,+BAA+B;IAC9C,QAAQ,CAAC,UAAU,EAAE,SAAS,UAAU,EAAE,CAAC;IAC3C,QAAQ,CAAC,QAAQ,EAAE,SAAS,gBAAgB,EAAE,CAAC;IAC/C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC;IAClC,QAAQ,CAAC,EAAE,EAAE,cAAc,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,sDAAsD;AACtD,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,CAAC,UAAU,EAAE,gBAAgB,EAAE,CAAC;IACxC,QAAQ,CAAC,WAAW,EAAE,UAAU,EAAE,CAAC;CACpC;AAMD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CASpE;AAwFD;;;;;;;;;;GAUG;AACH,wBAAsB,kBAAkB,CACtC,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,OAAO,CAAC,CAgBlB;AAgCD,yCAAyC;AACzC,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,+BAA+B,GACpC,OAAO,CAAC,8BAA8B,CAAC,CAkGzC"}
@@ -0,0 +1,244 @@
1
+ "use strict";
2
+ /**
3
+ * @module lock/upstream_refs
4
+ *
5
+ * Lock-mediated resolution of org-manifest `references:` projectRefs
6
+ * (design §4.2): fetch a published compile-output snapshot over https or
7
+ * `file://`, cache it under `.markspec/cache/upstreams/<id>/`, and pin it
8
+ * as an extended `[[upstream.registry]]` lockfile row. Three flows:
9
+ * first lock (new declaration → fetch + pin), keep/restore (pin exists →
10
+ * verify cache offline, refetch only to repopulate, never move the pin),
11
+ * update (`--update` → refetch + move the pin).
12
+ *
13
+ * Pure module: network and file access only via {@linkcode UpstreamRefsIO}.
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.upstreamCacheRoot = upstreamCacheRoot;
17
+ exports.deriveUpstreamId = deriveUpstreamId;
18
+ exports.probeCacheSnapshot = probeCacheSnapshot;
19
+ exports.resolveProjectReferences = resolveProjectReferences;
20
+ const path_1 = require("@std/path");
21
+ const hash_js_1 = require("./hash.js");
22
+ const upstream_common_js_1 = require("./upstream_common.js");
23
+ const deserialize_js_1 = require("../compiler/deserialize.js");
24
+ const paths_js_1 = require("../util/paths.js");
25
+ /**
26
+ * Root directory under which every upstream's cached snapshot is stored,
27
+ * one subdirectory per upstream id (`<root>/<id>/manifest.json`, etc.).
28
+ * Shared by `markspec lock` (the writer) and `markspec check` (the
29
+ * offline MSL-L212 prober) so the two commands can never disagree on
30
+ * where the cache lives.
31
+ */
32
+ function upstreamCacheRoot(projectRoot) {
33
+ return (0, path_1.join)(projectRoot, ".markspec", "cache", "upstreams");
34
+ }
35
+ /** Safe upstream id — a single path segment (also enforced by the config
36
+ * loader on explicit `name:` values). */
37
+ const UPSTREAM_ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
38
+ /**
39
+ * Derive the upstream id for a projectRef: the explicit `name`, else the
40
+ * last non-empty path segment of the URL with any `.git` suffix stripped.
41
+ * Returns `undefined` when no safe id can be derived.
42
+ */
43
+ function deriveUpstreamId(ref) {
44
+ if (ref.name !== undefined) {
45
+ return UPSTREAM_ID_RE.test(ref.name) ? ref.name : undefined;
46
+ }
47
+ const trimmed = ref.url.replace(/\/+$/, "");
48
+ const segment = trimmed.split(/[/:]/).filter((s) => s.length > 0).pop();
49
+ if (segment === undefined)
50
+ return undefined;
51
+ const id = segment.replace(/\.git$/, "");
52
+ return UPSTREAM_ID_RE.test(id) ? id : undefined;
53
+ }
54
+ function l213(id, detail) {
55
+ return (0, upstream_common_js_1.upstreamNotLockable)("reference", id, detail);
56
+ }
57
+ async function fetchSnapshot(id, baseUrl, fetchUrl) {
58
+ const manifestUrl = `${baseUrl}/manifest.json`;
59
+ const manifestBytes = await fetchUrl(manifestUrl);
60
+ if ("error" in manifestBytes) {
61
+ return l213(id, `fetch of ${manifestUrl} failed (${manifestBytes.error})`);
62
+ }
63
+ let manifest;
64
+ try {
65
+ manifest = JSON.parse(new TextDecoder().decode(manifestBytes));
66
+ }
67
+ catch (err) {
68
+ return l213(id, `manifest.json is not valid JSON: ${err instanceof Error ? err.message : String(err)}`);
69
+ }
70
+ const skew = (0, deserialize_js_1.checkSnapshotSchema)(manifest, manifestUrl);
71
+ if (skew)
72
+ return l213(id, skew.message);
73
+ const entriesFile = manifest.entries?.file;
74
+ if (entriesFile === undefined || (0, paths_js_1.isUnsafeRelPath)(entriesFile)) {
75
+ return l213(id, "manifest entries block missing or names an unsafe path");
76
+ }
77
+ const files = new Map();
78
+ const dataBytes = await fetchUrl(`${baseUrl}/${entriesFile}`);
79
+ if ("error" in dataBytes) {
80
+ return l213(id, `fetch of '${entriesFile}' failed (${dataBytes.error})`);
81
+ }
82
+ files.set(entriesFile, dataBytes);
83
+ const indexFile = manifest.entries?.index;
84
+ if (manifest.entries?.format === "ndjson" && indexFile !== undefined) {
85
+ if ((0, paths_js_1.isUnsafeRelPath)(indexFile)) {
86
+ return l213(id, "manifest entries index names an unsafe path");
87
+ }
88
+ const indexBytes = await fetchUrl(`${baseUrl}/${indexFile}`);
89
+ if ("error" in indexBytes) {
90
+ return l213(id, `fetch of '${indexFile}' failed (${indexBytes.error})`);
91
+ }
92
+ files.set(indexFile, indexBytes);
93
+ }
94
+ return {
95
+ manifestBytes,
96
+ manifest,
97
+ files,
98
+ snapshotHash: await (0, hash_js_1.sha256Bytes)(dataBytes),
99
+ };
100
+ }
101
+ function writeCache(id, dir, fetched, io) {
102
+ const writes = [
103
+ [(0, path_1.join)(dir, "manifest.json"), fetched.manifestBytes],
104
+ ...[...fetched.files].map(([rel, bytes]) => [(0, path_1.join)(dir, rel), bytes]),
105
+ ];
106
+ return (0, upstream_common_js_1.writeCacheFiles)(writes, "reference", id, io.writeFile);
107
+ }
108
+ /**
109
+ * Probe whether the cached snapshot under `dir` is present and hash-intact
110
+ * against `snapshot`: `manifest.json` must exist and parse, its
111
+ * `entries.file` must name a safe relative path, and the hashed bytes of
112
+ * that file must equal `snapshot`.
113
+ *
114
+ * Shared by {@linkcode cacheIntact} (this module's keep/restore flow) and
115
+ * `verifyUpstreamCache` (`cache_check.ts`'s MSL-L212 offline cache-drift
116
+ * gate) so the two never disagree on what "cache intact" means — the
117
+ * single probe implementation, not a duplicate.
118
+ */
119
+ async function probeCacheSnapshot(dir, snapshot, readFile) {
120
+ const manifestBytes = await readFile((0, path_1.join)(dir, "manifest.json"));
121
+ if ("error" in manifestBytes)
122
+ return false;
123
+ let entriesFile;
124
+ try {
125
+ const manifest = JSON.parse(new TextDecoder().decode(manifestBytes));
126
+ entriesFile = manifest.entries?.file;
127
+ }
128
+ catch {
129
+ return false;
130
+ }
131
+ if (entriesFile === undefined || (0, paths_js_1.isUnsafeRelPath)(entriesFile))
132
+ return false;
133
+ const dataBytes = await readFile((0, path_1.join)(dir, entriesFile));
134
+ if ("error" in dataBytes)
135
+ return false;
136
+ return await (0, hash_js_1.sha256Bytes)(dataBytes) === snapshot;
137
+ }
138
+ /** Is the cached snapshot for `row` present and hash-intact? */
139
+ async function cacheIntact(row, dir, readFile) {
140
+ if (row.snapshot === undefined)
141
+ return false;
142
+ return await probeCacheSnapshot(dir, row.snapshot, readFile);
143
+ }
144
+ function buildRow(id, baseUrl, fetched, manifestHash, lockedAt) {
145
+ const version = fetched.manifest.project?.version;
146
+ return {
147
+ kind: "registry",
148
+ id,
149
+ api: baseUrl,
150
+ resolvedManifestHash: manifestHash,
151
+ markspecSchema: fetched.manifest.markspecSchemaVersion,
152
+ ...(typeof version === "string" ? { version } : {}),
153
+ snapshot: fetched.snapshotHash,
154
+ lockedAt,
155
+ };
156
+ }
157
+ /** See module doc for the flow table. */
158
+ async function resolveProjectReferences(opts) {
159
+ const registries = [];
160
+ const diagnostics = [];
161
+ const byId = new Map(opts.existing.map((row) => [row.id, row]));
162
+ const seen = new Set();
163
+ for (const ref of opts.references) {
164
+ const id = deriveUpstreamId(ref);
165
+ if (id === undefined) {
166
+ diagnostics.push(l213(ref.name ?? ref.url, "no safe upstream id could be derived — set an explicit 'name:'"));
167
+ continue;
168
+ }
169
+ if (seen.has(id)) {
170
+ diagnostics.push(l213(id, `duplicate upstream id (also derived for an earlier entry) — set distinct 'name:' values`));
171
+ continue;
172
+ }
173
+ seen.add(id);
174
+ const baseUrl = ref.url.replace(/\/+$/, "");
175
+ // join() at construction (#771): a template concat would mix the
176
+ // platform separator with a literal `/` — the Windows drift class
177
+ // that bit slices 2 and 4. Writer and reader must agree byte-for-byte.
178
+ const dir = (0, path_1.join)(opts.cacheRoot, id);
179
+ const existing = byId.get(id);
180
+ const selectedForUpdate = opts.update === true || opts.update === id;
181
+ if (existing !== undefined && !selectedForUpdate) {
182
+ // Keep — verify offline; restore only when the cache is broken.
183
+ if (await cacheIntact(existing, dir, opts.io.readFile)) {
184
+ registries.push(existing);
185
+ continue;
186
+ }
187
+ const fetched = await fetchSnapshot(id, baseUrl, opts.io.fetchUrl);
188
+ if ("code" in fetched) {
189
+ diagnostics.push(fetched);
190
+ registries.push(existing); // keep the pin; cache stays broken
191
+ continue;
192
+ }
193
+ // A snapshot-less existing row (representable — e.g. a hand-edited
194
+ // or pre-existing lockfile entry) has no pin to verify the fetch
195
+ // against; comparing against `undefined` would always "mismatch".
196
+ // Treat it as a first-lock/re-pin instead of MSL-L214.
197
+ if (existing.snapshot !== undefined &&
198
+ fetched.snapshotHash !== existing.snapshot) {
199
+ diagnostics.push({
200
+ code: "MSL-L214",
201
+ severity: "warning",
202
+ message: `upstream reference '${id}' restore mismatch: fetched snapshot ` +
203
+ `${fetched.snapshotHash} does not match locked ${existing.snapshot} — ` +
204
+ `the published site moved; run 'markspec lock --update=${id}' to move the pin`,
205
+ location: undefined,
206
+ });
207
+ registries.push(existing);
208
+ continue;
209
+ }
210
+ const writeError = await writeCache(id, dir, fetched, opts.io);
211
+ if (writeError) {
212
+ diagnostics.push(writeError);
213
+ registries.push(existing);
214
+ continue;
215
+ }
216
+ if (existing.snapshot === undefined) {
217
+ const manifestHash = await (0, hash_js_1.sha256Bytes)(fetched.manifestBytes);
218
+ registries.push(buildRow(id, baseUrl, fetched, manifestHash, opts.lockedAt));
219
+ }
220
+ else {
221
+ registries.push(existing);
222
+ }
223
+ continue;
224
+ }
225
+ // First lock, or explicitly selected for update.
226
+ const fetched = await fetchSnapshot(id, baseUrl, opts.io.fetchUrl);
227
+ if ("code" in fetched) {
228
+ diagnostics.push(fetched);
229
+ if (existing !== undefined)
230
+ registries.push(existing);
231
+ continue;
232
+ }
233
+ const writeError = await writeCache(id, dir, fetched, opts.io);
234
+ if (writeError) {
235
+ diagnostics.push(writeError);
236
+ if (existing !== undefined)
237
+ registries.push(existing);
238
+ continue;
239
+ }
240
+ const manifestHash = await (0, hash_js_1.sha256Bytes)(fetched.manifestBytes);
241
+ registries.push(buildRow(id, baseUrl, fetched, manifestHash, opts.lockedAt));
242
+ }
243
+ return { registries, diagnostics };
244
+ }