@lbdudc/linea-core 0.1.1 → 0.1.2

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 (249) hide show
  1. package/README.md +132 -260
  2. package/dist/analysis/analyze.d.ts +0 -54
  3. package/dist/analysis/analyze.js +1 -70
  4. package/dist/analysis/analyze.js.map +1 -1
  5. package/dist/analysis/runtime.d.ts +4 -73
  6. package/dist/analysis/runtime.js +7 -100
  7. package/dist/analysis/runtime.js.map +1 -1
  8. package/dist/analysis/uvl-text.d.ts +8 -0
  9. package/dist/analysis/uvl-text.js +70 -0
  10. package/dist/analysis/uvl-text.js.map +1 -0
  11. package/dist/assets.d.ts +0 -12
  12. package/dist/assets.js +0 -25
  13. package/dist/assets.js.map +1 -1
  14. package/dist/ci/annotations.d.ts +6 -0
  15. package/dist/ci/annotations.js +12 -0
  16. package/dist/ci/annotations.js.map +1 -0
  17. package/dist/ci/leftovers.d.ts +25 -0
  18. package/dist/ci/leftovers.js +50 -0
  19. package/dist/ci/leftovers.js.map +1 -0
  20. package/dist/ci/pairwise.d.ts +11 -0
  21. package/dist/ci/pairwise.js +35 -0
  22. package/dist/ci/pairwise.js.map +1 -0
  23. package/dist/ci/pipeline.d.ts +18 -0
  24. package/dist/ci/pipeline.js +26 -0
  25. package/dist/ci/pipeline.js.map +1 -0
  26. package/dist/ci/select.d.ts +28 -0
  27. package/dist/ci/select.js +43 -0
  28. package/dist/ci/select.js.map +1 -0
  29. package/dist/ci/validate-specs.d.ts +52 -0
  30. package/dist/ci/validate-specs.js +212 -0
  31. package/dist/ci/validate-specs.js.map +1 -0
  32. package/dist/constants.d.ts +1 -60
  33. package/dist/constants.js +1 -58
  34. package/dist/constants.js.map +1 -1
  35. package/dist/derivation/derive.d.ts +0 -56
  36. package/dist/derivation/derive.js +21 -72
  37. package/dist/derivation/derive.js.map +1 -1
  38. package/dist/derivation/engine.d.ts +10 -42
  39. package/dist/derivation/engine.js +37 -68
  40. package/dist/derivation/engine.js.map +1 -1
  41. package/dist/derivation/selection-error.d.ts +7 -0
  42. package/dist/derivation/selection-error.js +13 -0
  43. package/dist/derivation/selection-error.js.map +1 -0
  44. package/dist/errors.d.ts +19 -47
  45. package/dist/errors.js +28 -47
  46. package/dist/errors.js.map +1 -1
  47. package/dist/feature-model/uvl.d.ts +52 -0
  48. package/dist/feature-model/uvl.js +191 -0
  49. package/dist/feature-model/uvl.js.map +1 -0
  50. package/dist/fs/archive.d.ts +0 -16
  51. package/dist/fs/archive.js +0 -36
  52. package/dist/fs/archive.js.map +1 -1
  53. package/dist/fs/diff.d.ts +0 -30
  54. package/dist/fs/diff.js +4 -65
  55. package/dist/fs/diff.js.map +1 -1
  56. package/dist/fs/format.d.ts +0 -16
  57. package/dist/fs/format.js +0 -52
  58. package/dist/fs/format.js.map +1 -1
  59. package/dist/fs/workspace.d.ts +0 -52
  60. package/dist/fs/workspace.js +0 -56
  61. package/dist/fs/workspace.js.map +1 -1
  62. package/dist/index.d.ts +23 -29
  63. package/dist/index.js +15 -35
  64. package/dist/index.js.map +1 -1
  65. package/dist/internal/guards.d.ts +0 -13
  66. package/dist/internal/guards.js +0 -13
  67. package/dist/internal/guards.js.map +1 -1
  68. package/dist/line/deletion.d.ts +33 -0
  69. package/dist/line/deletion.js +23 -0
  70. package/dist/line/deletion.js.map +1 -0
  71. package/dist/line/platform-files.d.ts +15 -64
  72. package/dist/line/platform-files.js +18 -94
  73. package/dist/line/platform-files.js.map +1 -1
  74. package/dist/line/restoration.d.ts +27 -0
  75. package/dist/line/restoration.js +27 -0
  76. package/dist/line/restoration.js.map +1 -0
  77. package/dist/line/scaffold.d.ts +26 -57
  78. package/dist/line/scaffold.js +32 -93
  79. package/dist/line/scaffold.js.map +1 -1
  80. package/dist/line/templates/core/transformation.js +17 -5
  81. package/dist/line/templates/pipeline/github-ci.yml +50 -0
  82. package/dist/line/templates/pipeline/spl-gitlab-ci.yml +182 -0
  83. package/dist/modules/configuration/configure.d.ts +52 -0
  84. package/dist/modules/configuration/configure.js +101 -0
  85. package/dist/modules/configuration/configure.js.map +1 -0
  86. package/dist/modules/configuration/constants.d.ts +17 -0
  87. package/dist/modules/configuration/constants.js +14 -0
  88. package/dist/modules/configuration/constants.js.map +1 -0
  89. package/dist/modules/configuration/index.d.ts +6 -0
  90. package/dist/modules/configuration/index.js +5 -0
  91. package/dist/modules/configuration/index.js.map +1 -0
  92. package/dist/modules/configuration/names.d.ts +9 -0
  93. package/dist/modules/configuration/names.js +7 -0
  94. package/dist/modules/configuration/names.js.map +1 -0
  95. package/dist/modules/configuration/selection.d.ts +32 -0
  96. package/dist/modules/configuration/selection.js +49 -0
  97. package/dist/modules/configuration/selection.js.map +1 -0
  98. package/dist/modules/diagnostics.d.ts +2 -0
  99. package/dist/modules/diagnostics.js +2 -0
  100. package/dist/modules/diagnostics.js.map +1 -0
  101. package/dist/modules/index.d.ts +18 -0
  102. package/dist/modules/index.js +18 -0
  103. package/dist/modules/index.js.map +1 -0
  104. package/dist/modules/metamodels/engine.d.ts +93 -0
  105. package/dist/modules/metamodels/engine.js +10 -0
  106. package/dist/modules/metamodels/engine.js.map +1 -0
  107. package/dist/modules/metamodels/files.d.ts +40 -0
  108. package/dist/modules/metamodels/files.js +58 -0
  109. package/dist/modules/metamodels/files.js.map +1 -0
  110. package/dist/modules/metamodels/index.d.ts +8 -0
  111. package/dist/modules/metamodels/index.js +5 -0
  112. package/dist/modules/metamodels/index.js.map +1 -0
  113. package/dist/modules/metamodels/layout.d.ts +23 -0
  114. package/dist/modules/metamodels/layout.js +29 -0
  115. package/dist/modules/metamodels/layout.js.map +1 -0
  116. package/dist/modules/metamodels/offered.d.ts +15 -0
  117. package/dist/modules/metamodels/offered.js +14 -0
  118. package/dist/modules/metamodels/offered.js.map +1 -0
  119. package/dist/modules/metamodels/prepare.d.ts +20 -0
  120. package/dist/modules/metamodels/prepare.js +155 -0
  121. package/dist/modules/metamodels/prepare.js.map +1 -0
  122. package/dist/modules/packages/index.d.ts +4 -0
  123. package/dist/modules/packages/index.js +4 -0
  124. package/dist/modules/packages/index.js.map +1 -0
  125. package/dist/modules/packages/location.d.ts +21 -0
  126. package/dist/modules/packages/location.js +34 -0
  127. package/dist/modules/packages/location.js.map +1 -0
  128. package/dist/modules/packages/manifests.d.ts +33 -0
  129. package/dist/modules/packages/manifests.js +231 -0
  130. package/dist/modules/packages/manifests.js.map +1 -0
  131. package/dist/modules/packages/source.d.ts +34 -0
  132. package/dist/modules/packages/source.js +128 -0
  133. package/dist/modules/packages/source.js.map +1 -0
  134. package/dist/modules/products/check.d.ts +28 -0
  135. package/dist/modules/products/check.js +61 -0
  136. package/dist/modules/products/check.js.map +1 -0
  137. package/dist/modules/products/derive.d.ts +30 -0
  138. package/dist/modules/products/derive.js +56 -0
  139. package/dist/modules/products/derive.js.map +1 -0
  140. package/dist/modules/products/index.d.ts +5 -0
  141. package/dist/modules/products/index.js +4 -0
  142. package/dist/modules/products/index.js.map +1 -0
  143. package/dist/modules/products/seed.d.ts +18 -0
  144. package/dist/modules/products/seed.js +23 -0
  145. package/dist/modules/products/seed.js.map +1 -0
  146. package/dist/modules/registry/catalog.d.ts +64 -0
  147. package/dist/modules/registry/catalog.js +91 -0
  148. package/dist/modules/registry/catalog.js.map +1 -0
  149. package/dist/modules/registry/index.d.ts +5 -0
  150. package/dist/modules/registry/index.js +4 -0
  151. package/dist/modules/registry/index.js.map +1 -0
  152. package/dist/modules/registry/registry.d.ts +34 -0
  153. package/dist/modules/registry/registry.js +37 -0
  154. package/dist/modules/registry/registry.js.map +1 -0
  155. package/dist/modules/registry/routing.d.ts +8 -0
  156. package/dist/modules/registry/routing.js +23 -0
  157. package/dist/modules/registry/routing.js.map +1 -0
  158. package/dist/modules/resolution/closure.d.ts +28 -0
  159. package/dist/modules/resolution/closure.js +105 -0
  160. package/dist/modules/resolution/closure.js.map +1 -0
  161. package/dist/modules/resolution/index.d.ts +4 -0
  162. package/dist/modules/resolution/index.js +3 -0
  163. package/dist/modules/resolution/index.js.map +1 -0
  164. package/dist/modules/resolution/resolve.d.ts +33 -0
  165. package/dist/modules/resolution/resolve.js +59 -0
  166. package/dist/modules/resolution/resolve.js.map +1 -0
  167. package/dist/modules/resolution/resolvers.d.ts +23 -0
  168. package/dist/modules/resolution/resolvers.js +34 -0
  169. package/dist/modules/resolution/resolvers.js.map +1 -0
  170. package/dist/modules/spl/check.d.ts +25 -0
  171. package/dist/modules/spl/check.js +21 -0
  172. package/dist/modules/spl/check.js.map +1 -0
  173. package/dist/modules/spl/cip.d.ts +67 -0
  174. package/dist/modules/spl/cip.js +98 -0
  175. package/dist/modules/spl/cip.js.map +1 -0
  176. package/dist/modules/spl/feature-model.d.ts +39 -0
  177. package/dist/modules/spl/feature-model.js +106 -0
  178. package/dist/modules/spl/feature-model.js.map +1 -0
  179. package/dist/modules/spl/index.d.ts +6 -0
  180. package/dist/modules/spl/index.js +4 -0
  181. package/dist/modules/spl/index.js.map +1 -0
  182. package/dist/modules/spl/platform.d.ts +49 -0
  183. package/dist/modules/spl/platform.js +316 -0
  184. package/dist/modules/spl/platform.js.map +1 -0
  185. package/dist/modules/types.d.ts +132 -0
  186. package/dist/modules/types.js +2 -0
  187. package/dist/modules/types.js.map +1 -0
  188. package/dist/product/engine-spec.d.ts +0 -16
  189. package/dist/product/engine-spec.js +4 -50
  190. package/dist/product/engine-spec.js.map +1 -1
  191. package/dist/product/spec.d.ts +0 -82
  192. package/dist/product/spec.js +0 -79
  193. package/dist/product/spec.js.map +1 -1
  194. package/dist/product/version.d.ts +0 -23
  195. package/dist/product/version.js +0 -28
  196. package/dist/product/version.js.map +1 -1
  197. package/dist/products-index/products-index.d.ts +0 -165
  198. package/dist/products-index/products-index.js +0 -176
  199. package/dist/products-index/products-index.js.map +1 -1
  200. package/dist/workspace/context.d.ts +25 -0
  201. package/dist/workspace/context.js +43 -0
  202. package/dist/workspace/context.js.map +1 -0
  203. package/dist/workspace/gitExclude.d.ts +2 -0
  204. package/dist/workspace/gitExclude.js +19 -0
  205. package/dist/workspace/gitExclude.js.map +1 -0
  206. package/dist/workspace/host.d.ts +14 -0
  207. package/dist/workspace/host.js +13 -0
  208. package/dist/workspace/host.js.map +1 -0
  209. package/dist/workspace/index.d.ts +12 -0
  210. package/dist/workspace/index.js +12 -0
  211. package/dist/workspace/index.js.map +1 -0
  212. package/dist/workspace/local.d.ts +81 -0
  213. package/dist/workspace/local.js +287 -0
  214. package/dist/workspace/local.js.map +1 -0
  215. package/dist/workspace/modular.d.ts +95 -0
  216. package/dist/workspace/modular.js +301 -0
  217. package/dist/workspace/modular.js.map +1 -0
  218. package/dist/workspace/operations.d.ts +35 -0
  219. package/dist/workspace/operations.js +57 -0
  220. package/dist/workspace/operations.js.map +1 -0
  221. package/dist/workspace/origin.d.ts +20 -0
  222. package/dist/workspace/origin.js +19 -0
  223. package/dist/workspace/origin.js.map +1 -0
  224. package/package.json +22 -7
  225. package/dist/feature-model/convert.d.ts +0 -35
  226. package/dist/feature-model/convert.js +0 -47
  227. package/dist/feature-model/convert.js.map +0 -1
  228. package/dist/feature-model/engine.d.ts +0 -60
  229. package/dist/feature-model/engine.js +0 -139
  230. package/dist/feature-model/engine.js.map +0 -1
  231. package/dist/feature-model/inspect.d.ts +0 -67
  232. package/dist/feature-model/inspect.js +0 -113
  233. package/dist/feature-model/inspect.js.map +0 -1
  234. package/dist/feature-model/io.d.ts +0 -66
  235. package/dist/feature-model/io.js +0 -92
  236. package/dist/feature-model/io.js.map +0 -1
  237. package/dist/feature-model/parse.d.ts +0 -30
  238. package/dist/feature-model/parse.js +0 -36
  239. package/dist/feature-model/parse.js.map +0 -1
  240. package/dist/feature-model/text.d.ts +0 -54
  241. package/dist/feature-model/text.js +0 -126
  242. package/dist/feature-model/text.js.map +0 -1
  243. package/dist/line/templates/metamodels/dataModel/extra.js +0 -328
  244. package/dist/line/templates/metamodels/dataModel/transformation.js +0 -211
  245. package/dist/line/templates/metamodels/sensor/extra.js +0 -36
  246. package/dist/line/templates/metamodels/sensor/transformation.js +0 -47
  247. package/dist/selection/selection.d.ts +0 -126
  248. package/dist/selection/selection.js +0 -152
  249. package/dist/selection/selection.js.map +0 -1
@@ -1,66 +1,12 @@
1
- /**
2
- * The `products.json` index that lives at the root of every line repository.
3
- *
4
- * ADR-011 fixes the normative format:
5
- *
6
- * { "productos": [ { "name": "...", "repositorio": "/ruta/en/gitlab" } ] }
7
- *
8
- * The Spanish key `productos` is part of the decision and is NOT anglicised.
9
- *
10
- * ADR-011 foresaw its own extension ("el esquema es versionable: si se amplía
11
- * (p. ej. versión del producto, estado), se hace de forma retrocompatible").
12
- * That extension is now here: an entry MAY carry a `version` (`x.y.z`).
13
- *
14
- * { "productos": [ { "name": "...", "repositorio": "...", "version": "1.2.3" } ] }
15
- *
16
- * It is OPTIONAL and the compatibility rule is strict in both directions:
17
- * - an index written before this change parses, validates and serialises
18
- * exactly as before — no key appears out of nowhere;
19
- * - an entry with no version does NOT emit `"version": null` or `""`, so
20
- * reading and rewriting an old index is a byte-for-byte no-op.
21
- * The reason it lives in the line's index at all — instead of in each product
22
- * repository, where the rest of the spec lives — is that listing the products of
23
- * a line has to show every version at once: one read per line instead of one
24
- * GitLab request per product.
25
- *
26
- * This index replaces the `products` Mongo collection of the monolith, so there
27
- * is no single function to migrate: the reconciliation semantics are adapted
28
- * from `linea/server/src/model/services/LineService.js:reconcileLines` (~134-193)
29
- * and `ProductService.js:reconcileProducts` (~232-295).
30
- *
31
- * Two deliberate departures from those (ADR-014, ADR-009):
32
- * - No database and no `archived` flag, so there is **no `prune`**. Entries that
33
- * no longer have a repository are REPORTED in `removed`, never dropped.
34
- * Deciding what to do about them is linea-server's call.
35
- * - Every mutation is pure: `add`/`rename`/`remove`/`reconcile` return a NEW
36
- * index and never touch the input, so a caller can diff before committing.
37
- */
38
1
  import path from 'node:path';
39
2
  import { NAME_PATTERN, PRODUCTS_INDEX_PATH, VERSION_PATTERN } from '../constants.js';
40
3
  import { InvalidArgumentError, ProductsIndexError } from '../errors.js';
41
4
  import { fileExists, readTextFile, writeTextFile } from '../fs/workspace.js';
42
5
  import { isArray, isPlainObject } from '../internal/guards.js';
43
- /** Alphabetical by `name`, so serialisation is stable across callers. */
44
6
  const byName = (a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
45
- /**
46
- * Builds a normalised entry, keeping ONLY the normative fields.
47
- *
48
- * The `version` key is omitted altogether when there is no usable version, and
49
- * that omission is the whole retro-compatibility guarantee: emitting `null` or
50
- * `''` would change the bytes of every pre-existing `products.json` the moment
51
- * linea-server read it and wrote it back.
52
- */
53
7
  const normalizeEntry = ({ name, repositorio, version }) => typeof version === 'string' && version !== ''
54
8
  ? { name, repositorio, version }
55
9
  : { name, repositorio };
56
- /**
57
- * Guards an incoming optional version. Absent (`undefined`) is fine; anything
58
- * else has to be a `x.y.z` string.
59
- *
60
- * The mutating functions THROW here rather than reporting, unlike
61
- * `validateProductsIndex`: they take their input from a caller's arguments, not
62
- * from a file on disk, so a bad value is a programming error (ADR-018).
63
- */
64
10
  const assertOptionalVersion = ({ version, label }) => {
65
11
  if (version === undefined)
66
12
  return;
@@ -74,23 +20,7 @@ const assertIndex = (index) => {
74
20
  }
75
21
  return index;
76
22
  };
77
- /**
78
- * An empty index.
79
- *
80
- * @returns A fresh `{ productos: [] }`. A new object every call, so callers can
81
- * safely treat it as their own.
82
- */
83
23
  export const emptyProductsIndex = () => ({ productos: [] });
84
- /**
85
- * Validates an index **without throwing**.
86
- *
87
- * Checks the ADR-011 shape plus the domain rules that make the index usable:
88
- * names must be valid (`NAME_PATTERN`) and unique, and every entry needs a
89
- * `repositorio`.
90
- *
91
- * @param params.index The index to validate. Anything, including nullish.
92
- * @returns `valid` plus one entry per problem, in document order.
93
- */
94
24
  export const validateProductsIndex = ({ index }) => {
95
25
  if (!isPlainObject(index)) {
96
26
  return {
@@ -156,10 +86,6 @@ export const validateProductsIndex = ({ index }) => {
156
86
  messageKey: 'error_messages.products_index_repositorio_required'
157
87
  });
158
88
  }
159
- // OPTIONAL: absent is valid, and only `undefined` counts as absent. `''`,
160
- // `null` and numbers are attempts at a version, and a wrong one is worth
161
- // reporting: silently accepting them would put junk in the field the
162
- // enrolled-products listing renders.
163
89
  if (version !== undefined && (typeof version !== 'string' || !VERSION_PATTERN.test(version))) {
164
90
  errors.push({
165
91
  path: `${at}.version`,
@@ -170,16 +96,6 @@ export const validateProductsIndex = ({ index }) => {
170
96
  });
171
97
  return { valid: errors.length === 0, errors };
172
98
  };
173
- /**
174
- * Parses the JSON contents of a `products.json`.
175
- *
176
- * @param params.content Raw file contents.
177
- * @returns The index, with only the normative fields kept per entry: `name`,
178
- * `repositorio` and, when the file has it, `version`. An index written before
179
- * `version` existed parses exactly as it always did.
180
- * @throws {ProductsIndexError} when the JSON is malformed or does not satisfy
181
- * the ADR-011 shape — which includes a `version` present but not `x.y.z`.
182
- */
183
99
  export const parseProductsIndex = ({ content }) => {
184
100
  if (typeof content !== 'string') {
185
101
  throw new InvalidArgumentError('"content" must be a string.');
@@ -201,39 +117,11 @@ export const parseProductsIndex = ({ content }) => {
201
117
  const index = parsed;
202
118
  return { productos: index.productos.map(normalizeEntry) };
203
119
  };
204
- /**
205
- * Serialises an index deterministically.
206
- *
207
- * Stability is a feature, not a detail: linea-server commits this file to the
208
- * line repository on every product create/rename/delete, so an unstable
209
- * serialisation would produce noisy diffs and spurious merge conflicts.
210
- * Guarantees: entries sorted alphabetically by `name`, only the normative fields
211
- * emitted and always in the same order (`name`, `repositorio`, `version`),
212
- * two-space indentation, single trailing newline.
213
- *
214
- * An entry with no version emits **no `version` key** — not `null`, not `''`.
215
- * That is what keeps an index written before this field byte-identical after a
216
- * read/write round trip.
217
- *
218
- * @param params.index The index to serialise.
219
- * @returns The JSON text to write.
220
- * @throws {InvalidArgumentError} when `index` is not index-shaped.
221
- */
222
120
  export const serializeProductsIndex = ({ index }) => {
223
121
  const checked = assertIndex(index);
224
122
  const productos = [...checked.productos].sort(byName).map(normalizeEntry);
225
123
  return `${JSON.stringify({ productos }, null, 2)}\n`;
226
124
  };
227
- /**
228
- * Adds a product to the index.
229
- *
230
- * @param params.index Current index. Not mutated.
231
- * @param params.product Entry to add. `version` is optional; when given it must
232
- * be `x.y.z`, and when omitted the entry simply has no version.
233
- * @returns A new, sorted index.
234
- * @throws {ProductsIndexError} when a product with that name is already there.
235
- * @throws {InvalidArgumentError} when the arguments are malformed.
236
- */
237
125
  export const addProductToIndex = ({ index, product }) => {
238
126
  const checked = assertIndex(index);
239
127
  if (!isPlainObject(product)) {
@@ -254,20 +142,6 @@ export const addProductToIndex = ({ index, product }) => {
254
142
  productos: [...checked.productos, normalizeEntry({ name, repositorio, version })].sort(byName)
255
143
  };
256
144
  };
257
- /**
258
- * Renames a product in the index, keeping its `repositorio` and its `version`.
259
- *
260
- * Note the repository path is intentionally left untouched: renaming a GitLab
261
- * project does not necessarily move it, and linea-server is the only component
262
- * that knows the new path. It should follow up with the real value if it changed.
263
- *
264
- * @param params.index Current index. Not mutated.
265
- * @param params.from Current product name.
266
- * @param params.to New product name.
267
- * @returns A new, sorted index.
268
- * @throws {ProductsIndexError} when `from` is missing or `to` already exists.
269
- * @throws {InvalidArgumentError} when the arguments are malformed.
270
- */
271
145
  export const renameProductInIndex = ({ index, from, to }) => {
272
146
  const checked = assertIndex(index);
273
147
  if (typeof from !== 'string' || from === '') {
@@ -288,17 +162,6 @@ export const renameProductInIndex = ({ index, from, to }) => {
288
162
  .sort(byName)
289
163
  };
290
164
  };
291
- /**
292
- * Removes a product from the index.
293
- *
294
- * IDEMPOTENT: removing a product that is not there returns an equivalent index
295
- * instead of throwing, so a retried or replayed delete cannot fail half-way.
296
- *
297
- * @param params.index Current index. Not mutated.
298
- * @param params.name Product to remove.
299
- * @returns A new, sorted index.
300
- * @throws {InvalidArgumentError} when the arguments are malformed.
301
- */
302
165
  export const removeProductFromIndex = ({ index, name }) => {
303
166
  const checked = assertIndex(index);
304
167
  if (typeof name !== 'string' || name === '') {
@@ -306,19 +169,6 @@ export const removeProductFromIndex = ({ index, name }) => {
306
169
  }
307
170
  return { productos: checked.productos.filter((entry) => entry.name !== name).sort(byName) };
308
171
  };
309
- /**
310
- * Reads the index of a line working directory.
311
- *
312
- * A line with no `products.json` is a line with no products, not an error: the
313
- * file only appears once the first product is created, and every line predating
314
- * ADR-011 lacks it. A file that EXISTS but is corrupt is a different story and
315
- * does throw — silently treating it as empty would let linea-server commit a
316
- * fresh index over a real one and lose the product list.
317
- *
318
- * @param params.lineDir Root of the line working directory.
319
- * @returns The index, or an empty one when the file is absent.
320
- * @throws {ProductsIndexError} when the file exists but is malformed.
321
- */
322
172
  export const readProductsIndex = ({ lineDir }) => {
323
173
  if (typeof lineDir !== 'string' || lineDir.trim() === '') {
324
174
  throw new InvalidArgumentError('"lineDir" must be a non-empty path.');
@@ -328,14 +178,6 @@ export const readProductsIndex = ({ lineDir }) => {
328
178
  return emptyProductsIndex();
329
179
  return parseProductsIndex({ content: readTextFile({ filePath }) });
330
180
  };
331
- /**
332
- * Writes the index of a line working directory, creating it if needed.
333
- *
334
- * @param params.lineDir Root of the line working directory.
335
- * @param params.index The index to write.
336
- * @returns The absolute path written.
337
- * @throws {InvalidArgumentError} when the arguments are malformed.
338
- */
339
181
  export const writeProductsIndex = ({ lineDir, index }) => {
340
182
  if (typeof lineDir !== 'string' || lineDir.trim() === '') {
341
183
  throw new InvalidArgumentError('"lineDir" must be a non-empty path.');
@@ -344,24 +186,6 @@ export const writeProductsIndex = ({ lineDir, index }) => {
344
186
  const filePath = path.join(path.resolve(lineDir), PRODUCTS_INDEX_PATH);
345
187
  return { path: writeTextFile({ filePath, content }) };
346
188
  };
347
- /**
348
- * Reconciles an index against the repositories a caller actually observed.
349
- *
350
- * Adapted from the `reconcile*` pair of the monolith, which discovers GitLab
351
- * projects by topic and creates the rows that are missing.
352
- *
353
- * Versions already recorded in the index are preserved verbatim, exactly like
354
- * `repositorio`: the observation the caller makes is "this repository exists",
355
- * not "this is the product's version", so it never overwrites what is indexed.
356
- * A newly added entry keeps the `version` the caller supplied, if any.
357
- *
358
- * @param params.index Current index. Not mutated.
359
- * @param params.repositories Repositories observed, as `{ name, repositorio }`
360
- * plus an optional `version`. linea-server builds this from GitLab; linea-core
361
- * never looks.
362
- * @returns The reconciled index plus what was added and what is missing.
363
- * @throws {InvalidArgumentError} when the arguments are malformed.
364
- */
365
189
  export const reconcileProductsIndex = ({ index, repositories }) => {
366
190
  const checked = assertIndex(index);
367
191
  if (!isArray(repositories)) {
@@ -1 +1 @@
1
- {"version":3,"file":"products-index.js","sourceRoot":"","sources":["../../src/products-index/products-index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACpF,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AACvE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAC5E,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAkE9D,yEAAyE;AACzE,MAAM,MAAM,GAAG,CAAC,CAAqB,EAAE,CAAqB,EAAU,EAAE,CACtE,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAEhD;;;;;;;GAOG;AACH,MAAM,cAAc,GAAG,CAAC,EACtB,IAAI,EACJ,WAAW,EACX,OAAO,EACY,EAAsB,EAAE,CAC3C,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,EAAE;IAC3C,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,OA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,CAAA;IACrE,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAA;IAE3E,MAAM,KAAK,GAAG,YAAY;SACvB,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;SACrD,GAAG,CAAC,cAAc,CAAC,CAAA;IAEtB,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS;SAC9B,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;SAC5C,GAAG,CAAC,cAAc,CAAC,CAAA;IAEtB,OAAO;QACL,KAAK,EAAE,EAAE,SAAS,EAAE,CAAC,GAAG,OAAO,CAAC,SAAS,EAAE,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;QACnE,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;QAC9B,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;KACnC,CAAA;AACH,CAAC,CAAA","sourcesContent":["/**\n * The `products.json` index that lives at the root of every line repository.\n *\n * ADR-011 fixes the normative format:\n *\n * { \"productos\": [ { \"name\": \"...\", \"repositorio\": \"/ruta/en/gitlab\" } ] }\n *\n * The Spanish key `productos` is part of the decision and is NOT anglicised.\n *\n * ADR-011 foresaw its own extension (\"el esquema es versionable: si se amplía\n * (p. ej. versión del producto, estado), se hace de forma retrocompatible\").\n * That extension is now here: an entry MAY carry a `version` (`x.y.z`).\n *\n * { \"productos\": [ { \"name\": \"...\", \"repositorio\": \"...\", \"version\": \"1.2.3\" } ] }\n *\n * It is OPTIONAL and the compatibility rule is strict in both directions:\n * - an index written before this change parses, validates and serialises\n * exactly as before — no key appears out of nowhere;\n * - an entry with no version does NOT emit `\"version\": null` or `\"\"`, so\n * reading and rewriting an old index is a byte-for-byte no-op.\n * The reason it lives in the line's index at all — instead of in each product\n * repository, where the rest of the spec lives — is that listing the products of\n * a line has to show every version at once: one read per line instead of one\n * GitLab request per product.\n *\n * This index replaces the `products` Mongo collection of the monolith, so there\n * is no single function to migrate: the reconciliation semantics are adapted\n * from `linea/server/src/model/services/LineService.js:reconcileLines` (~134-193)\n * and `ProductService.js:reconcileProducts` (~232-295).\n *\n * Two deliberate departures from those (ADR-014, ADR-009):\n * - No database and no `archived` flag, so there is **no `prune`**. Entries that\n * no longer have a repository are REPORTED in `removed`, never dropped.\n * Deciding what to do about them is linea-server's call.\n * - Every mutation is pure: `add`/`rename`/`remove`/`reconcile` return a NEW\n * index and never touch the input, so a caller can diff before committing.\n */\nimport path from 'node:path'\nimport { NAME_PATTERN, PRODUCTS_INDEX_PATH, VERSION_PATTERN } from '../constants.js'\nimport { InvalidArgumentError, ProductsIndexError } from '../errors.js'\nimport { fileExists, readTextFile, writeTextFile } from '../fs/workspace.js'\nimport { isArray, isPlainObject } from '../internal/guards.js'\n\n/** One product of a line, as recorded in `products.json`. */\nexport interface ProductsIndexEntry {\n /** Product name; same rules as any other name (`NAME_PATTERN`). */\n readonly name: string\n /** Path of the product repository in the laboratory's GitLab. */\n readonly repositorio: string\n /**\n * Current product version (`VERSION_PATTERN`, i.e. `x.y.z`). **Optional**:\n * every index written before this field existed is still valid, and an entry\n * without it is never given one implicitly.\n *\n * It duplicates `spec.basicData.version`, which lives in the product's own\n * repository. That is the point: the enrolled-products listing needs every\n * version at once, and reading one file per product would be one GitLab\n * request per row. The product repository stays the source of truth; this is\n * the copy the line keeps to be able to list without fanning out.\n */\n readonly version?: string\n}\n\n/** The whole index. */\nexport interface ProductsIndex {\n readonly productos: ProductsIndexEntry[]\n}\n\n/** A problem found in an index. */\nexport interface ProductsIndexProblem {\n /** Dotted path of the offending field, e.g. `productos[2].repositorio`. */\n readonly path: string\n /** Stable machine-readable discriminator. */\n readonly code: ProductsIndexProblemCode\n /**\n * An i18n KEY, never a human-readable sentence — same policy as\n * `ProductSpecError.messageKey`, so a consumer never has to guess whether to\n * translate a value or render it raw.\n *\n * Two keys are inherited from the monolith and already translated:\n * `invalid_name_characters` and `basicData_version_format` (the latter reads\n * \"Version must follow the format X.Y.Z\", which is exactly the fact being\n * reported, so it is reused instead of minting an untranslated twin). The\n * rest are NEW (there was no products index to validate before ADR-011) and\n * have no translation yet; they are listed in CHANGELOG.md for whoever\n * migrates webui and linea-cli.\n */\n readonly messageKey: string\n}\n\n/** Stable discriminators for index problems. */\nexport type ProductsIndexProblemCode =\n | 'INDEX_NOT_OBJECT'\n | 'PRODUCTOS_NOT_ARRAY'\n | 'ENTRY_NOT_OBJECT'\n | 'NAME_REQUIRED'\n | 'NAME_INVALID_CHARACTERS'\n | 'NAME_DUPLICATED'\n | 'REPOSITORIO_REQUIRED'\n | 'VERSION_INVALID_FORMAT'\n\n/** Result of validating an index. */\nexport interface ProductsIndexValidation {\n readonly valid: boolean\n readonly errors: ProductsIndexProblem[]\n}\n\n/** Alphabetical by `name`, so serialisation is stable across callers. */\nconst byName = (a: ProductsIndexEntry, b: ProductsIndexEntry): number =>\n a.name < b.name ? -1 : a.name > b.name ? 1 : 0\n\n/**\n * Builds a normalised entry, keeping ONLY the normative fields.\n *\n * The `version` key is omitted altogether when there is no usable version, and\n * that omission is the whole retro-compatibility guarantee: emitting `null` or\n * `''` would change the bytes of every pre-existing `products.json` the moment\n * linea-server read it and wrote it back.\n */\nconst normalizeEntry = ({\n name,\n repositorio,\n version\n}: ProductsIndexEntry): ProductsIndexEntry =>\n typeof version === 'string' && version !== ''\n ? { name, repositorio, version }\n : { name, repositorio }\n\n/**\n * Guards an incoming optional version. Absent (`undefined`) is fine; anything\n * else has to be a `x.y.z` string.\n *\n * The mutating functions THROW here rather than reporting, unlike\n * `validateProductsIndex`: they take their input from a caller's arguments, not\n * from a file on disk, so a bad value is a programming error (ADR-018).\n */\nconst assertOptionalVersion = ({\n version,\n label\n}: {\n version: unknown\n label: string\n}): void => {\n if (version === undefined) return\n if (typeof version !== 'string' || !VERSION_PATTERN.test(version)) {\n throw new InvalidArgumentError(\n `${label} must be a version like \"1.2.3\"; got ${JSON.stringify(version)}.`\n )\n }\n}\n\nconst assertIndex = (index: unknown): ProductsIndex => {\n if (!isPlainObject(index) || !Array.isArray(index.productos)) {\n throw new InvalidArgumentError('\"index\" must be a { productos: [...] } object.')\n }\n return index as unknown as ProductsIndex\n}\n\n/**\n * An empty index.\n *\n * @returns A fresh `{ productos: [] }`. A new object every call, so callers can\n * safely treat it as their own.\n */\nexport const emptyProductsIndex = (): ProductsIndex => ({ productos: [] })\n\n/**\n * Validates an index **without throwing**.\n *\n * Checks the ADR-011 shape plus the domain rules that make the index usable:\n * names must be valid (`NAME_PATTERN`) and unique, and every entry needs a\n * `repositorio`.\n *\n * @param params.index The index to validate. Anything, including nullish.\n * @returns `valid` plus one entry per problem, in document order.\n */\nexport const validateProductsIndex = ({ index }: { index: unknown }): ProductsIndexValidation => {\n if (!isPlainObject(index)) {\n return {\n valid: false,\n errors: [{\n path: '(root)',\n code: 'INDEX_NOT_OBJECT',\n messageKey: 'error_messages.products_index_not_object'\n }]\n }\n }\n if (!Array.isArray(index.productos)) {\n return {\n valid: false,\n errors: [{\n path: 'productos',\n code: 'PRODUCTOS_NOT_ARRAY',\n messageKey: 'error_messages.products_index_productos_not_array'\n }]\n }\n }\n\n const errors: ProductsIndexProblem[] = []\n const seen = new Set<string>()\n\n index.productos.forEach((entry: unknown, position: number) => {\n const at = `productos[${position}]`\n if (!isPlainObject(entry)) {\n errors.push({\n path: at,\n code: 'ENTRY_NOT_OBJECT',\n messageKey: 'error_messages.products_index_entry_not_object'\n })\n return\n }\n\n const { name, repositorio, version } = entry\n if (typeof name !== 'string' || name === '') {\n errors.push({\n path: `${at}.name`,\n code: 'NAME_REQUIRED',\n messageKey: 'error_messages.products_index_name_required'\n })\n } else if (!NAME_PATTERN.test(name)) {\n errors.push({\n path: `${at}.name`,\n code: 'NAME_INVALID_CHARACTERS',\n messageKey: 'error_messages.invalid_name_characters'\n })\n } else if (seen.has(name)) {\n errors.push({\n path: `${at}.name`,\n code: 'NAME_DUPLICATED',\n messageKey: 'error_messages.products_index_name_duplicated'\n })\n } else {\n seen.add(name)\n }\n\n if (typeof repositorio !== 'string' || repositorio === '') {\n errors.push({\n path: `${at}.repositorio`,\n code: 'REPOSITORIO_REQUIRED',\n messageKey: 'error_messages.products_index_repositorio_required'\n })\n }\n\n // OPTIONAL: absent is valid, and only `undefined` counts as absent. `''`,\n // `null` and numbers are attempts at a version, and a wrong one is worth\n // reporting: silently accepting them would put junk in the field the\n // enrolled-products listing renders.\n if (version !== undefined && (typeof version !== 'string' || !VERSION_PATTERN.test(version))) {\n errors.push({\n path: `${at}.version`,\n code: 'VERSION_INVALID_FORMAT',\n messageKey: 'error_messages.basicData_version_format'\n })\n }\n })\n\n return { valid: errors.length === 0, errors }\n}\n\n/**\n * Parses the JSON contents of a `products.json`.\n *\n * @param params.content Raw file contents.\n * @returns The index, with only the normative fields kept per entry: `name`,\n * `repositorio` and, when the file has it, `version`. An index written before\n * `version` existed parses exactly as it always did.\n * @throws {ProductsIndexError} when the JSON is malformed or does not satisfy\n * the ADR-011 shape — which includes a `version` present but not `x.y.z`.\n */\nexport const parseProductsIndex = ({ content }: { content: string }): ProductsIndex => {\n if (typeof content !== 'string') {\n throw new InvalidArgumentError('\"content\" must be a string.')\n }\n if (content.trim() === '') return emptyProductsIndex()\n\n let parsed: unknown\n try {\n parsed = JSON.parse(content)\n } catch (error) {\n throw new ProductsIndexError(\n `products.json is not valid JSON: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error }\n )\n }\n\n const validation = validateProductsIndex({ index: parsed })\n if (!validation.valid) {\n const summary = validation.errors.map((e) => `${e.path}: ${e.messageKey}`).join('; ')\n throw new ProductsIndexError(`products.json does not satisfy the ADR-011 format: ${summary}`)\n }\n\n const index = parsed as ProductsIndex\n return { productos: index.productos.map(normalizeEntry) }\n}\n\n/**\n * Serialises an index deterministically.\n *\n * Stability is a feature, not a detail: linea-server commits this file to the\n * line repository on every product create/rename/delete, so an unstable\n * serialisation would produce noisy diffs and spurious merge conflicts.\n * Guarantees: entries sorted alphabetically by `name`, only the normative fields\n * emitted and always in the same order (`name`, `repositorio`, `version`),\n * two-space indentation, single trailing newline.\n *\n * An entry with no version emits **no `version` key** — not `null`, not `''`.\n * That is what keeps an index written before this field byte-identical after a\n * read/write round trip.\n *\n * @param params.index The index to serialise.\n * @returns The JSON text to write.\n * @throws {InvalidArgumentError} when `index` is not index-shaped.\n */\nexport const serializeProductsIndex = ({ index }: { index: ProductsIndex }): string => {\n const checked = assertIndex(index)\n const productos = [...checked.productos].sort(byName).map(normalizeEntry)\n return `${JSON.stringify({ productos }, null, 2)}\\n`\n}\n\n/**\n * Adds a product to the index.\n *\n * @param params.index Current index. Not mutated.\n * @param params.product Entry to add. `version` is optional; when given it must\n * be `x.y.z`, and when omitted the entry simply has no version.\n * @returns A new, sorted index.\n * @throws {ProductsIndexError} when a product with that name is already there.\n * @throws {InvalidArgumentError} when the arguments are malformed.\n */\nexport const addProductToIndex = ({\n index,\n product\n}: {\n index: ProductsIndex\n product: ProductsIndexEntry\n}): ProductsIndex => {\n const checked = assertIndex(index)\n if (!isPlainObject(product)) {\n throw new InvalidArgumentError('\"product\" must be a { name, repositorio } object.')\n }\n const { name, repositorio, version } = product\n if (typeof name !== 'string' || !NAME_PATTERN.test(name)) {\n throw new InvalidArgumentError(`Invalid product name ${JSON.stringify(name)}.`)\n }\n if (typeof repositorio !== 'string' || repositorio === '') {\n throw new InvalidArgumentError('\"product.repositorio\" must be a non-empty string.')\n }\n assertOptionalVersion({ version, label: '\"product.version\"' })\n if (checked.productos.some((entry) => entry.name === name)) {\n throw new ProductsIndexError(`Product \"${name}\" is already in the index.`)\n }\n\n return {\n productos: [...checked.productos, normalizeEntry({ name, repositorio, version })].sort(byName)\n }\n}\n\n/**\n * Renames a product in the index, keeping its `repositorio` and its `version`.\n *\n * Note the repository path is intentionally left untouched: renaming a GitLab\n * project does not necessarily move it, and linea-server is the only component\n * that knows the new path. It should follow up with the real value if it changed.\n *\n * @param params.index Current index. Not mutated.\n * @param params.from Current product name.\n * @param params.to New product name.\n * @returns A new, sorted index.\n * @throws {ProductsIndexError} when `from` is missing or `to` already exists.\n * @throws {InvalidArgumentError} when the arguments are malformed.\n */\nexport const renameProductInIndex = ({\n index,\n from,\n to\n}: {\n index: ProductsIndex\n from: string\n to: string\n}): ProductsIndex => {\n const checked = assertIndex(index)\n if (typeof from !== 'string' || from === '') {\n throw new InvalidArgumentError('\"from\" must be a non-empty string.')\n }\n if (typeof to !== 'string' || !NAME_PATTERN.test(to)) {\n throw new InvalidArgumentError(`Invalid product name ${JSON.stringify(to)}.`)\n }\n if (!checked.productos.some((entry) => entry.name === from)) {\n throw new ProductsIndexError(`Product \"${from}\" is not in the index.`)\n }\n if (from !== to && checked.productos.some((entry) => entry.name === to)) {\n throw new ProductsIndexError(`Product \"${to}\" is already in the index.`)\n }\n\n return {\n productos: checked.productos\n .map((entry) => (entry.name === from ? normalizeEntry({ ...entry, name: to }) : entry))\n .sort(byName)\n }\n}\n\n/**\n * Removes a product from the index.\n *\n * IDEMPOTENT: removing a product that is not there returns an equivalent index\n * instead of throwing, so a retried or replayed delete cannot fail half-way.\n *\n * @param params.index Current index. Not mutated.\n * @param params.name Product to remove.\n * @returns A new, sorted index.\n * @throws {InvalidArgumentError} when the arguments are malformed.\n */\nexport const removeProductFromIndex = ({\n index,\n name\n}: {\n index: ProductsIndex\n name: string\n}): ProductsIndex => {\n const checked = assertIndex(index)\n if (typeof name !== 'string' || name === '') {\n throw new InvalidArgumentError('\"name\" must be a non-empty string.')\n }\n return { productos: checked.productos.filter((entry) => entry.name !== name).sort(byName) }\n}\n\n/**\n * Reads the index of a line working directory.\n *\n * A line with no `products.json` is a line with no products, not an error: the\n * file only appears once the first product is created, and every line predating\n * ADR-011 lacks it. A file that EXISTS but is corrupt is a different story and\n * does throw — silently treating it as empty would let linea-server commit a\n * fresh index over a real one and lose the product list.\n *\n * @param params.lineDir Root of the line working directory.\n * @returns The index, or an empty one when the file is absent.\n * @throws {ProductsIndexError} when the file exists but is malformed.\n */\nexport const readProductsIndex = ({ lineDir }: { lineDir: string }): ProductsIndex => {\n if (typeof lineDir !== 'string' || lineDir.trim() === '') {\n throw new InvalidArgumentError('\"lineDir\" must be a non-empty path.')\n }\n const filePath = path.join(path.resolve(lineDir), PRODUCTS_INDEX_PATH)\n if (!fileExists({ filePath })) return emptyProductsIndex()\n return parseProductsIndex({ content: readTextFile({ filePath }) })\n}\n\n/**\n * Writes the index of a line working directory, creating it if needed.\n *\n * @param params.lineDir Root of the line working directory.\n * @param params.index The index to write.\n * @returns The absolute path written.\n * @throws {InvalidArgumentError} when the arguments are malformed.\n */\nexport const writeProductsIndex = ({\n lineDir,\n index\n}: {\n lineDir: string\n index: ProductsIndex\n}): { path: string } => {\n if (typeof lineDir !== 'string' || lineDir.trim() === '') {\n throw new InvalidArgumentError('\"lineDir\" must be a non-empty path.')\n }\n const content = serializeProductsIndex({ index })\n const filePath = path.join(path.resolve(lineDir), PRODUCTS_INDEX_PATH)\n return { path: writeTextFile({ filePath, content }) }\n}\n\n/** Outcome of reconciling an index against the repositories actually observed. */\nexport interface ProductsIndexReconciliation {\n /** The index with the newly discovered repositories added. */\n readonly index: ProductsIndex\n /**\n * Entries added because a repository existed but was not indexed. They carry\n * a `version` only if the caller observed one.\n */\n readonly added: ProductsIndexEntry[]\n /**\n * Entries indexed but with no observed repository.\n *\n * REPORTED ONLY — they stay in `index`. The monolith's `prune` archived such\n * rows in Mongo; without a database, dropping them here would silently destroy\n * the record of a product whose repository the caller merely could not see\n * (a permissions hiccup, a partial listing). linea-server decides.\n */\n readonly removed: ProductsIndexEntry[]\n}\n\n/**\n * Reconciles an index against the repositories a caller actually observed.\n *\n * Adapted from the `reconcile*` pair of the monolith, which discovers GitLab\n * projects by topic and creates the rows that are missing.\n *\n * Versions already recorded in the index are preserved verbatim, exactly like\n * `repositorio`: the observation the caller makes is \"this repository exists\",\n * not \"this is the product's version\", so it never overwrites what is indexed.\n * A newly added entry keeps the `version` the caller supplied, if any.\n *\n * @param params.index Current index. Not mutated.\n * @param params.repositories Repositories observed, as `{ name, repositorio }`\n * plus an optional `version`. linea-server builds this from GitLab; linea-core\n * never looks.\n * @returns The reconciled index plus what was added and what is missing.\n * @throws {InvalidArgumentError} when the arguments are malformed.\n */\nexport const reconcileProductsIndex = ({\n index,\n repositories\n}: {\n index: ProductsIndex\n repositories: readonly ProductsIndexEntry[]\n}): ProductsIndexReconciliation => {\n const checked = assertIndex(index)\n if (!isArray(repositories)) {\n throw new InvalidArgumentError('\"repositories\" must be an array of { name, repositorio }.')\n }\n for (const repository of repositories) {\n if (!isPlainObject(repository) ||\n typeof repository.name !== 'string' || repository.name === '' ||\n typeof repository.repositorio !== 'string' || repository.repositorio === '') {\n throw new InvalidArgumentError(\n 'Every entry of \"repositories\" must be a { name, repositorio } object with non-empty strings.'\n )\n }\n assertOptionalVersion({\n version: repository.version,\n label: `\"repositories[${repository.name}].version\"`\n })\n }\n\n const indexed = new Set(checked.productos.map((entry) => entry.name))\n const observed = new Set(repositories.map((repository) => repository.name))\n\n const added = repositories\n .filter((repository) => !indexed.has(repository.name))\n .map(normalizeEntry)\n\n const removed = checked.productos\n .filter((entry) => !observed.has(entry.name))\n .map(normalizeEntry)\n\n return {\n index: { productos: [...checked.productos, ...added].sort(byName) },\n added: [...added].sort(byName),\n removed: [...removed].sort(byName)\n }\n}\n"]}
1
+ {"version":3,"file":"products-index.js","sourceRoot":"","sources":["../../src/products-index/products-index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,iBAAi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_PATH, VERSION_PATTERN } from '../constants.js'\nimport { InvalidArgumentError, ProductsIndexError } from '../errors.js'\nimport { fileExists, readTextFile, writeTextFile } from '../fs/workspace.js'\nimport { isArray, isPlainObject } from '../internal/guards.js'\n\nexport interface ProductsIndexEntry {\n readonly name: string\n readonly repositorio: string\n readonly version?: string\n}\n\nexport interface ProductsIndex {\n readonly productos: ProductsIndexEntry[]\n}\n\nexport interface ProductsIndexProblem {\n readonly path: string\n readonly code: ProductsIndexProblemCode\n readonly messageKey: string\n}\n\nexport type ProductsIndexProblemCode =\n | 'INDEX_NOT_OBJECT'\n | 'PRODUCTOS_NOT_ARRAY'\n | 'ENTRY_NOT_OBJECT'\n | 'NAME_REQUIRED'\n | 'NAME_INVALID_CHARACTERS'\n | 'NAME_DUPLICATED'\n | 'REPOSITORIO_REQUIRED'\n | 'VERSION_INVALID_FORMAT'\n\nexport interface ProductsIndexValidation {\n readonly valid: boolean\n readonly errors: ProductsIndexProblem[]\n}\n\nconst byName = (a: ProductsIndexEntry, b: ProductsIndexEntry): number =>\n a.name < b.name ? -1 : a.name > b.name ? 1 : 0\n\nconst normalizeEntry = ({\n name,\n repositorio,\n version\n}: ProductsIndexEntry): ProductsIndexEntry =>\n typeof version === 'string' && version !== ''\n ? { name, repositorio, version }\n : { name, repositorio }\n\nconst assertOptionalVersion = ({\n version,\n label\n}: {\n version: unknown\n label: string\n}): void => {\n if (version === undefined) return\n if (typeof version !== 'string' || !VERSION_PATTERN.test(version)) {\n throw new InvalidArgumentError(\n `${label} must be a version like \"1.2.3\"; got ${JSON.stringify(version)}.`\n )\n }\n}\n\nconst assertIndex = (index: unknown): ProductsIndex => {\n if (!isPlainObject(index) || !Array.isArray(index.productos)) {\n throw new InvalidArgumentError('\"index\" must be a { productos: [...] } object.')\n }\n return index as unknown as ProductsIndex\n}\n\nexport const emptyProductsIndex = (): ProductsIndex => ({ productos: [] })\n\nexport const validateProductsIndex = ({ index }: { index: unknown }): ProductsIndexValidation => {\n if (!isPlainObject(index)) {\n return {\n valid: false,\n errors: [{\n path: '(root)',\n code: 'INDEX_NOT_OBJECT',\n messageKey: 'error_messages.products_index_not_object'\n }]\n }\n }\n if (!Array.isArray(index.productos)) {\n return {\n valid: false,\n errors: [{\n path: 'productos',\n code: 'PRODUCTOS_NOT_ARRAY',\n messageKey: 'error_messages.products_index_productos_not_array'\n }]\n }\n }\n\n const errors: ProductsIndexProblem[] = []\n const seen = new Set<string>()\n\n index.productos.forEach((entry: unknown, position: number) => {\n const at = `productos[${position}]`\n if (!isPlainObject(entry)) {\n errors.push({\n path: at,\n code: 'ENTRY_NOT_OBJECT',\n messageKey: 'error_messages.products_index_entry_not_object'\n })\n return\n }\n\n const { name, repositorio, version } = entry\n if (typeof name !== 'string' || name === '') {\n errors.push({\n path: `${at}.name`,\n code: 'NAME_REQUIRED',\n messageKey: 'error_messages.products_index_name_required'\n })\n } else if (!NAME_PATTERN.test(name)) {\n errors.push({\n path: `${at}.name`,\n code: 'NAME_INVALID_CHARACTERS',\n messageKey: 'error_messages.invalid_name_characters'\n })\n } else if (seen.has(name)) {\n errors.push({\n path: `${at}.name`,\n code: 'NAME_DUPLICATED',\n messageKey: 'error_messages.products_index_name_duplicated'\n })\n } else {\n seen.add(name)\n }\n\n if (typeof repositorio !== 'string' || repositorio === '') {\n errors.push({\n path: `${at}.repositorio`,\n code: 'REPOSITORIO_REQUIRED',\n messageKey: 'error_messages.products_index_repositorio_required'\n })\n }\n\n if (version !== undefined && (typeof version !== 'string' || !VERSION_PATTERN.test(version))) {\n errors.push({\n path: `${at}.version`,\n code: 'VERSION_INVALID_FORMAT',\n messageKey: 'error_messages.basicData_version_format'\n })\n }\n })\n\n return { valid: errors.length === 0, errors }\n}\n\nexport const parseProductsIndex = ({ content }: { content: string }): ProductsIndex => {\n if (typeof content !== 'string') {\n throw new InvalidArgumentError('\"content\" must be a string.')\n }\n if (content.trim() === '') return emptyProductsIndex()\n\n let parsed: unknown\n try {\n parsed = JSON.parse(content)\n } catch (error) {\n throw new ProductsIndexError(\n `products.json is not valid JSON: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error }\n )\n }\n\n const validation = validateProductsIndex({ index: parsed })\n if (!validation.valid) {\n const summary = validation.errors.map((e) => `${e.path}: ${e.messageKey}`).join('; ')\n throw new ProductsIndexError(`products.json does not satisfy the ADR-011 format: ${summary}`)\n }\n\n const index = parsed as ProductsIndex\n return { productos: index.productos.map(normalizeEntry) }\n}\n\nexport const serializeProductsIndex = ({ index }: { index: ProductsIndex }): string => {\n const checked = assertIndex(index)\n const productos = [...checked.productos].sort(byName).map(normalizeEntry)\n return `${JSON.stringify({ productos }, null, 2)}\\n`\n}\n\nexport const addProductToIndex = ({\n index,\n product\n}: {\n index: ProductsIndex\n product: ProductsIndexEntry\n}): ProductsIndex => {\n const checked = assertIndex(index)\n if (!isPlainObject(product)) {\n throw new InvalidArgumentError('\"product\" must be a { name, repositorio } object.')\n }\n const { name, repositorio, version } = product\n if (typeof name !== 'string' || !NAME_PATTERN.test(name)) {\n throw new InvalidArgumentError(`Invalid product name ${JSON.stringify(name)}.`)\n }\n if (typeof repositorio !== 'string' || repositorio === '') {\n throw new InvalidArgumentError('\"product.repositorio\" must be a non-empty string.')\n }\n assertOptionalVersion({ version, label: '\"product.version\"' })\n if (checked.productos.some((entry) => entry.name === name)) {\n throw new ProductsIndexError(`Product \"${name}\" is already in the index.`)\n }\n\n return {\n productos: [...checked.productos, normalizeEntry({ name, repositorio, version })].sort(byName)\n }\n}\n\nexport const renameProductInIndex = ({\n index,\n from,\n to\n}: {\n index: ProductsIndex\n from: string\n to: string\n}): ProductsIndex => {\n const checked = assertIndex(index)\n if (typeof from !== 'string' || from === '') {\n throw new InvalidArgumentError('\"from\" must be a non-empty string.')\n }\n if (typeof to !== 'string' || !NAME_PATTERN.test(to)) {\n throw new InvalidArgumentError(`Invalid product name ${JSON.stringify(to)}.`)\n }\n if (!checked.productos.some((entry) => entry.name === from)) {\n throw new ProductsIndexError(`Product \"${from}\" is not in the index.`)\n }\n if (from !== to && checked.productos.some((entry) => entry.name === to)) {\n throw new ProductsIndexError(`Product \"${to}\" is already in the index.`)\n }\n\n return {\n productos: checked.productos\n .map((entry) => (entry.name === from ? normalizeEntry({ ...entry, name: to }) : entry))\n .sort(byName)\n }\n}\n\nexport const removeProductFromIndex = ({\n index,\n name\n}: {\n index: ProductsIndex\n name: string\n}): ProductsIndex => {\n const checked = assertIndex(index)\n if (typeof name !== 'string' || name === '') {\n throw new InvalidArgumentError('\"name\" must be a non-empty string.')\n }\n return { productos: checked.productos.filter((entry) => entry.name !== name).sort(byName) }\n}\n\nexport const readProductsIndex = ({ lineDir }: { lineDir: string }): ProductsIndex => {\n if (typeof lineDir !== 'string' || lineDir.trim() === '') {\n throw new InvalidArgumentError('\"lineDir\" must be a non-empty path.')\n }\n const filePath = path.join(path.resolve(lineDir), PRODUCTS_INDEX_PATH)\n if (!fileExists({ filePath })) return emptyProductsIndex()\n return parseProductsIndex({ content: readTextFile({ filePath }) })\n}\n\nexport const writeProductsIndex = ({\n lineDir,\n index\n}: {\n lineDir: string\n index: ProductsIndex\n}): { path: string } => {\n if (typeof lineDir !== 'string' || lineDir.trim() === '') {\n throw new InvalidArgumentError('\"lineDir\" must be a non-empty path.')\n }\n const content = serializeProductsIndex({ index })\n const filePath = path.join(path.resolve(lineDir), PRODUCTS_INDEX_PATH)\n return { path: writeTextFile({ filePath, content }) }\n}\n\nexport interface ProductsIndexReconciliation {\n readonly index: ProductsIndex\n readonly added: ProductsIndexEntry[]\n readonly removed: ProductsIndexEntry[]\n}\n\nexport const reconcileProductsIndex = ({\n index,\n repositories\n}: {\n index: ProductsIndex\n repositories: readonly ProductsIndexEntry[]\n}): ProductsIndexReconciliation => {\n const checked = assertIndex(index)\n if (!isArray(repositories)) {\n throw new InvalidArgumentError('\"repositories\" must be an array of { name, repositorio }.')\n }\n for (const repository of repositories) {\n if (!isPlainObject(repository) ||\n typeof repository.name !== 'string' || repository.name === '' ||\n typeof repository.repositorio !== 'string' || repository.repositorio === '') {\n throw new InvalidArgumentError(\n 'Every entry of \"repositories\" must be a { name, repositorio } object with non-empty strings.'\n )\n }\n assertOptionalVersion({\n version: repository.version,\n label: `\"repositories[${repository.name}].version\"`\n })\n }\n\n const indexed = new Set(checked.productos.map((entry) => entry.name))\n const observed = new Set(repositories.map((repository) => repository.name))\n\n const added = repositories\n .filter((repository) => !indexed.has(repository.name))\n .map(normalizeEntry)\n\n const removed = checked.productos\n .filter((entry) => !observed.has(entry.name))\n .map(normalizeEntry)\n\n return {\n index: { productos: [...checked.productos, ...added].sort(byName) },\n added: [...added].sort(byName),\n removed: [...removed].sort(byName)\n }\n}\n"]}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Where the current folder is, the way git knows which repository you are in: a workspace (`.linea/workspace.json`), an SPL (it
3
+ * has `spl.json`, or `src/platform`) and, inside an SPL, a product (`<spl>/<product>/.linea/spec.json`).
4
+ */
5
+ export interface FolderContext {
6
+ workspace?: string;
7
+ line?: {
8
+ name: string;
9
+ dir: string;
10
+ };
11
+ product?: {
12
+ name: string;
13
+ dir: string;
14
+ };
15
+ /** a module or metamodel: a folder with `module.json` / `metamodel.json` */
16
+ package?: {
17
+ kind: 'module' | 'metamodel';
18
+ name: string;
19
+ dir: string;
20
+ };
21
+ }
22
+ export declare const WORKSPACE_FILE: string;
23
+ export declare function findContext(start: string): FolderContext;
24
+ /** A folder becomes a workspace: the place the modules and metamodels of an SPL are looked for. */
25
+ export declare function initWorkspace(dir: string): string;
@@ -0,0 +1,43 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ export const WORKSPACE_FILE = path.join('.linea', 'workspace.json');
4
+ const isLine = (dir) => fs.existsSync(path.join(dir, 'spl.json')) || fs.existsSync(path.join(dir, 'src', 'platform'));
5
+ const isProduct = (dir) => fs.existsSync(path.join(dir, '.linea', 'spec.json'));
6
+ export function findContext(start) {
7
+ const ctx = {};
8
+ let dir = path.resolve(start);
9
+ let child;
10
+ for (;;) {
11
+ if (!ctx.package && !ctx.line) {
12
+ const kind = fs.existsSync(path.join(dir, '.linea', 'module.json')) ? 'module' : fs.existsSync(path.join(dir, 'metamodel.json')) ? 'metamodel' : undefined;
13
+ if (kind)
14
+ ctx.package = { kind, name: path.basename(dir), dir };
15
+ }
16
+ if (!ctx.line && isLine(dir)) {
17
+ ctx.line = { name: path.basename(dir), dir };
18
+ if (child && isProduct(child))
19
+ ctx.product = { name: path.basename(child), dir: child };
20
+ }
21
+ if (!ctx.workspace && fs.existsSync(path.join(dir, WORKSPACE_FILE)))
22
+ ctx.workspace = dir;
23
+ const parent = path.dirname(dir);
24
+ if (parent === dir)
25
+ break;
26
+ child = dir;
27
+ dir = parent;
28
+ }
29
+ // a product folder is not an SPL of its own: it was found as the child of the line, nothing else to do
30
+ return ctx;
31
+ }
32
+ /** A folder becomes a workspace: the place the modules and metamodels of an SPL are looked for. */
33
+ export function initWorkspace(dir) {
34
+ const abs = path.resolve(dir);
35
+ fs.mkdirSync(path.join(abs, '.linea'), { recursive: true });
36
+ fs.mkdirSync(path.join(abs, 'modules'), { recursive: true });
37
+ fs.mkdirSync(path.join(abs, 'metamodels'), { recursive: true });
38
+ const file = path.join(abs, WORKSPACE_FILE);
39
+ if (!fs.existsSync(file))
40
+ fs.writeFileSync(file, JSON.stringify({ version: 1 }, null, 2) + '\n');
41
+ return abs;
42
+ }
43
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/workspace/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAc5B,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAA;AAEnE,MAAM,MAAM,GAAG,CAAC,GAAW,EAAW,EAAE,CACtC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAA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AE,OAAO,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAA;IAChG,OAAO,GAAG,CAAA;AACZ,CAAC","sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\n\n/**\n * Where the current folder is, the way git knows which repository you are in: a workspace (`.linea/workspace.json`), an SPL (it\n * has `spl.json`, or `src/platform`) and, inside an SPL, a product (`<spl>/<product>/.linea/spec.json`).\n */\nexport interface FolderContext {\n workspace?: string\n line?: { name: string, dir: string }\n product?: { name: string, dir: string }\n /** a module or metamodel: a folder with `module.json` / `metamodel.json` */\n package?: { kind: 'module' | 'metamodel', name: string, dir: string }\n}\n\nexport const WORKSPACE_FILE = path.join('.linea', 'workspace.json')\n\nconst isLine = (dir: string): boolean =>\n fs.existsSync(path.join(dir, 'spl.json')) || fs.existsSync(path.join(dir, 'src', 'platform'))\n\nconst isProduct = (dir: string): boolean => fs.existsSync(path.join(dir, '.linea', 'spec.json'))\n\nexport function findContext(start: string): FolderContext {\n const ctx: FolderContext = {}\n let dir = path.resolve(start)\n let child: string | undefined\n for (;;) {\n if (!ctx.package && !ctx.line) {\n const kind = fs.existsSync(path.join(dir, '.linea', 'module.json')) ? 'module' : fs.existsSync(path.join(dir, 'metamodel.json')) ? 'metamodel' : undefined\n if (kind) ctx.package = { kind, name: path.basename(dir), dir }\n }\n if (!ctx.line && isLine(dir)) {\n ctx.line = { name: path.basename(dir), dir }\n if (child && isProduct(child)) ctx.product = { name: path.basename(child), dir: child }\n }\n if (!ctx.workspace && fs.existsSync(path.join(dir, WORKSPACE_FILE))) ctx.workspace = dir\n const parent = path.dirname(dir)\n if (parent === dir) break\n child = dir\n dir = parent\n }\n // a product folder is not an SPL of its own: it was found as the child of the line, nothing else to do\n return ctx\n}\n\n/** A folder becomes a workspace: the place the modules and metamodels of an SPL are looked for. */\nexport function initWorkspace(dir: string): string {\n const abs = path.resolve(dir)\n fs.mkdirSync(path.join(abs, '.linea'), { recursive: true })\n fs.mkdirSync(path.join(abs, 'modules'), { recursive: true })\n fs.mkdirSync(path.join(abs, 'metamodels'), { recursive: true })\n const file = path.join(abs, WORKSPACE_FILE)\n if (!fs.existsSync(file)) fs.writeFileSync(file, JSON.stringify({ version: 1 }, null, 2) + '\\n')\n return abs\n}\n"]}
@@ -0,0 +1,2 @@
1
+ /** Keeps a generated file out of `git status` of a checkout, without touching its tracked `.gitignore`. */
2
+ export declare function excludeFromGit(repoDir: string, pattern: string): void;
@@ -0,0 +1,19 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ /** Keeps a generated file out of `git status` of a checkout, without touching its tracked `.gitignore`. */
4
+ export function excludeFromGit(repoDir, pattern) {
5
+ const exclude = path.join(repoDir, '.git', 'info', 'exclude');
6
+ try {
7
+ if (!fs.statSync(path.join(repoDir, '.git')).isDirectory())
8
+ return;
9
+ }
10
+ catch {
11
+ return;
12
+ }
13
+ fs.mkdirSync(path.dirname(exclude), { recursive: true });
14
+ const current = fs.existsSync(exclude) ? fs.readFileSync(exclude, 'utf8') : '';
15
+ if (current.split(/\r?\n/).includes(pattern))
16
+ return;
17
+ fs.writeFileSync(exclude, `${current}${current && !current.endsWith('\n') ? '\n' : ''}${pattern}\n`);
18
+ }
19
+ //# sourceMappingURL=gitExclude.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gitExclude.js","sourceRoot":"","sources":["../../src/workspace/gitExclude.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,2GAA2G;AAC3G,MAAM,UAAU,cAAc,CAAE,OAAe,EAAE,OAAe;IAC9D,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;IAC7D,IAAI,CAAC;QACH,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,WAAW,EAAE;YAAE,OAAM;IACpE,CAAC;IAAC,MAAM,CAAC;QACP,OAAM;IACR,CAAC;IACD,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IACxD,MAAM,OAAO,GAAG,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IAC9E,IAAI,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC;QAAE,OAAM;IACpD,EAAE,CAAC,aAAa,CAAC,OAAO,EAAE,GAAG,OAAO,GAAG,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,IAAI,CAAC,CAAA;AACtG,CAAC","sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\n\n/** Keeps a generated file out of `git status` of a checkout, without touching its tracked `.gitignore`. */\nexport function excludeFromGit (repoDir: string, pattern: string): void {\n const exclude = path.join(repoDir, '.git', 'info', 'exclude')\n try {\n if (!fs.statSync(path.join(repoDir, '.git')).isDirectory()) return\n } catch {\n return\n }\n fs.mkdirSync(path.dirname(exclude), { recursive: true })\n const current = fs.existsSync(exclude) ? fs.readFileSync(exclude, 'utf8') : ''\n if (current.split(/\\r?\\n/).includes(pattern)) return\n fs.writeFileSync(exclude, `${current}${current && !current.endsWith('\\n') ? '\\n' : ''}${pattern}\\n`)\n}\n"]}
@@ -0,0 +1,14 @@
1
+ import type { MetamodelEngine } from '../modules/index.js';
2
+ import type { PackageSource } from '../modules/index.js';
3
+ /**
4
+ * What a workspace needs from whoever embeds it, and linea-core does not have: a metamodel engine (bango) and, when the workspace
5
+ * may use packages of a git host, a way to put that host behind the folders' own source. Set once, before the first call.
6
+ */
7
+ export interface WorkspaceHost {
8
+ createEngine: () => MetamodelEngine;
9
+ /** wraps the workspace's own package source so a location of a git host resolves too (default: the folders only) */
10
+ sourceOf?: (folders: PackageSource) => PackageSource;
11
+ }
12
+ export declare const configureWorkspace: (next: WorkspaceHost) => void;
13
+ export declare const createEngine: () => MetamodelEngine;
14
+ export declare const packageSourceOf: (folders: PackageSource) => PackageSource;
@@ -0,0 +1,13 @@
1
+ import { InvalidArgumentError } from '../errors.js';
2
+ let host;
3
+ export const configureWorkspace = (next) => {
4
+ host = next;
5
+ };
6
+ const workspaceHost = () => {
7
+ if (!host)
8
+ throw new InvalidArgumentError('The workspace has no metamodel engine: call configureWorkspace({ createEngine }) first.');
9
+ return host;
10
+ };
11
+ export const createEngine = () => workspaceHost().createEngine();
12
+ export const packageSourceOf = (folders) => workspaceHost().sourceOf?.(folders) ?? folders;
13
+ //# sourceMappingURL=host.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.js","sourceRoot":"","sources":["../../src/workspace/host.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAYnD,IAAI,IAA+B,CAAA;AAEnC,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,IAAmB,EAAQ,EAAE;IAC9D,IAAI,GAAG,IAAI,CAAA;AACb,CAAC,CAAA;AAED,MAAM,aAAa,GAAG,GAAkB,EAAE;IACxC,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,oBAAoB,CAAC,yFAAyF,CAAC,CAAA;IACpI,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,GAAoB,EAAE,CAAC,aAAa,EAAE,CAAC,YAAY,EAAE,CAAA;AACjF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,OAAsB,EAAiB,EAAE,CAAC,aAAa,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,IAAI,OAAO,CAAA","sourcesContent":["import type { MetamodelEngine } from '../modules/index.js'\nimport type { PackageSource } from '../modules/index.js'\nimport { InvalidArgumentError } from '../errors.js'\n\n/**\n * What a workspace needs from whoever embeds it, and linea-core does not have: a metamodel engine (bango) and, when the workspace\n * may use packages of a git host, a way to put that host behind the folders' own source. Set once, before the first call.\n */\nexport interface WorkspaceHost {\n createEngine: () => MetamodelEngine\n /** wraps the workspace's own package source so a location of a git host resolves too (default: the folders only) */\n sourceOf?: (folders: PackageSource) => PackageSource\n}\n\nlet host: WorkspaceHost | undefined\n\nexport const configureWorkspace = (next: WorkspaceHost): void => {\n host = next\n}\n\nconst workspaceHost = (): WorkspaceHost => {\n if (!host) throw new InvalidArgumentError('The workspace has no metamodel engine: call configureWorkspace({ createEngine }) first.')\n return host\n}\n\nexport const createEngine = (): MetamodelEngine => workspaceHost().createEngine()\nexport const packageSourceOf = (folders: PackageSource): PackageSource => workspaceHost().sourceOf?.(folders) ?? folders\n"]}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * A workspace on disk: SPLs, their products, and the modules and metamodels next to them, as plain folders (LOCAL mode of the CLI).
3
+ * What it does with them is what the server does with the same things on a git host: scaffold, check, derive.
4
+ */
5
+ export * from './local.js';
6
+ export * from './modular.js';
7
+ export * from './origin.js';
8
+ export { excludeFromGit } from './gitExclude.js';
9
+ export { configureWorkspace } from './host.js';
10
+ export type { WorkspaceHost } from './host.js';
11
+ export * from './context.js';
12
+ export * from './operations.js';
@@ -0,0 +1,12 @@
1
+ /**
2
+ * A workspace on disk: SPLs, their products, and the modules and metamodels next to them, as plain folders (LOCAL mode of the CLI).
3
+ * What it does with them is what the server does with the same things on a git host: scaffold, check, derive.
4
+ */
5
+ export * from './local.js';
6
+ export * from './modular.js';
7
+ export * from './origin.js';
8
+ export { excludeFromGit } from './gitExclude.js';
9
+ export { configureWorkspace } from './host.js';
10
+ export * from './context.js';
11
+ export * from './operations.js';
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/workspace/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAE9C,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA","sourcesContent":["/**\n * A workspace on disk: SPLs, their products, and the modules and metamodels next to them, as plain folders (LOCAL mode of the CLI).\n * What it does with them is what the server does with the same things on a git host: scaffold, check, derive.\n */\nexport * from './local.js'\nexport * from './modular.js'\nexport * from './origin.js'\nexport { excludeFromGit } from './gitExclude.js'\nexport { configureWorkspace } from './host.js'\nexport type { WorkspaceHost } from './host.js'\nexport * from './context.js'\nexport * from './operations.js'\n"]}