@lbdudc/linea-core 0.1.0 → 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 (253) hide show
  1. package/README.md +230 -358
  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/extra.js +54 -54
  81. package/dist/line/templates/core/transformation.js +208 -196
  82. package/dist/line/templates/pipeline/.gitlab-ci.yml +51 -51
  83. package/dist/line/templates/pipeline/ci/test-client.sh +16 -16
  84. package/dist/line/templates/pipeline/ci/test-server.sh +16 -16
  85. package/dist/line/templates/pipeline/github-ci.yml +50 -0
  86. package/dist/line/templates/pipeline/spl-gitlab-ci.yml +182 -0
  87. package/dist/modules/configuration/configure.d.ts +52 -0
  88. package/dist/modules/configuration/configure.js +101 -0
  89. package/dist/modules/configuration/configure.js.map +1 -0
  90. package/dist/modules/configuration/constants.d.ts +17 -0
  91. package/dist/modules/configuration/constants.js +14 -0
  92. package/dist/modules/configuration/constants.js.map +1 -0
  93. package/dist/modules/configuration/index.d.ts +6 -0
  94. package/dist/modules/configuration/index.js +5 -0
  95. package/dist/modules/configuration/index.js.map +1 -0
  96. package/dist/modules/configuration/names.d.ts +9 -0
  97. package/dist/modules/configuration/names.js +7 -0
  98. package/dist/modules/configuration/names.js.map +1 -0
  99. package/dist/modules/configuration/selection.d.ts +32 -0
  100. package/dist/modules/configuration/selection.js +49 -0
  101. package/dist/modules/configuration/selection.js.map +1 -0
  102. package/dist/modules/diagnostics.d.ts +2 -0
  103. package/dist/modules/diagnostics.js +2 -0
  104. package/dist/modules/diagnostics.js.map +1 -0
  105. package/dist/modules/index.d.ts +18 -0
  106. package/dist/modules/index.js +18 -0
  107. package/dist/modules/index.js.map +1 -0
  108. package/dist/modules/metamodels/engine.d.ts +93 -0
  109. package/dist/modules/metamodels/engine.js +10 -0
  110. package/dist/modules/metamodels/engine.js.map +1 -0
  111. package/dist/modules/metamodels/files.d.ts +40 -0
  112. package/dist/modules/metamodels/files.js +58 -0
  113. package/dist/modules/metamodels/files.js.map +1 -0
  114. package/dist/modules/metamodels/index.d.ts +8 -0
  115. package/dist/modules/metamodels/index.js +5 -0
  116. package/dist/modules/metamodels/index.js.map +1 -0
  117. package/dist/modules/metamodels/layout.d.ts +23 -0
  118. package/dist/modules/metamodels/layout.js +29 -0
  119. package/dist/modules/metamodels/layout.js.map +1 -0
  120. package/dist/modules/metamodels/offered.d.ts +15 -0
  121. package/dist/modules/metamodels/offered.js +14 -0
  122. package/dist/modules/metamodels/offered.js.map +1 -0
  123. package/dist/modules/metamodels/prepare.d.ts +20 -0
  124. package/dist/modules/metamodels/prepare.js +155 -0
  125. package/dist/modules/metamodels/prepare.js.map +1 -0
  126. package/dist/modules/packages/index.d.ts +4 -0
  127. package/dist/modules/packages/index.js +4 -0
  128. package/dist/modules/packages/index.js.map +1 -0
  129. package/dist/modules/packages/location.d.ts +21 -0
  130. package/dist/modules/packages/location.js +34 -0
  131. package/dist/modules/packages/location.js.map +1 -0
  132. package/dist/modules/packages/manifests.d.ts +33 -0
  133. package/dist/modules/packages/manifests.js +231 -0
  134. package/dist/modules/packages/manifests.js.map +1 -0
  135. package/dist/modules/packages/source.d.ts +34 -0
  136. package/dist/modules/packages/source.js +128 -0
  137. package/dist/modules/packages/source.js.map +1 -0
  138. package/dist/modules/products/check.d.ts +28 -0
  139. package/dist/modules/products/check.js +61 -0
  140. package/dist/modules/products/check.js.map +1 -0
  141. package/dist/modules/products/derive.d.ts +30 -0
  142. package/dist/modules/products/derive.js +56 -0
  143. package/dist/modules/products/derive.js.map +1 -0
  144. package/dist/modules/products/index.d.ts +5 -0
  145. package/dist/modules/products/index.js +4 -0
  146. package/dist/modules/products/index.js.map +1 -0
  147. package/dist/modules/products/seed.d.ts +18 -0
  148. package/dist/modules/products/seed.js +23 -0
  149. package/dist/modules/products/seed.js.map +1 -0
  150. package/dist/modules/registry/catalog.d.ts +64 -0
  151. package/dist/modules/registry/catalog.js +91 -0
  152. package/dist/modules/registry/catalog.js.map +1 -0
  153. package/dist/modules/registry/index.d.ts +5 -0
  154. package/dist/modules/registry/index.js +4 -0
  155. package/dist/modules/registry/index.js.map +1 -0
  156. package/dist/modules/registry/registry.d.ts +34 -0
  157. package/dist/modules/registry/registry.js +37 -0
  158. package/dist/modules/registry/registry.js.map +1 -0
  159. package/dist/modules/registry/routing.d.ts +8 -0
  160. package/dist/modules/registry/routing.js +23 -0
  161. package/dist/modules/registry/routing.js.map +1 -0
  162. package/dist/modules/resolution/closure.d.ts +28 -0
  163. package/dist/modules/resolution/closure.js +105 -0
  164. package/dist/modules/resolution/closure.js.map +1 -0
  165. package/dist/modules/resolution/index.d.ts +4 -0
  166. package/dist/modules/resolution/index.js +3 -0
  167. package/dist/modules/resolution/index.js.map +1 -0
  168. package/dist/modules/resolution/resolve.d.ts +33 -0
  169. package/dist/modules/resolution/resolve.js +59 -0
  170. package/dist/modules/resolution/resolve.js.map +1 -0
  171. package/dist/modules/resolution/resolvers.d.ts +23 -0
  172. package/dist/modules/resolution/resolvers.js +34 -0
  173. package/dist/modules/resolution/resolvers.js.map +1 -0
  174. package/dist/modules/spl/check.d.ts +25 -0
  175. package/dist/modules/spl/check.js +21 -0
  176. package/dist/modules/spl/check.js.map +1 -0
  177. package/dist/modules/spl/cip.d.ts +67 -0
  178. package/dist/modules/spl/cip.js +98 -0
  179. package/dist/modules/spl/cip.js.map +1 -0
  180. package/dist/modules/spl/feature-model.d.ts +39 -0
  181. package/dist/modules/spl/feature-model.js +106 -0
  182. package/dist/modules/spl/feature-model.js.map +1 -0
  183. package/dist/modules/spl/index.d.ts +6 -0
  184. package/dist/modules/spl/index.js +4 -0
  185. package/dist/modules/spl/index.js.map +1 -0
  186. package/dist/modules/spl/platform.d.ts +49 -0
  187. package/dist/modules/spl/platform.js +316 -0
  188. package/dist/modules/spl/platform.js.map +1 -0
  189. package/dist/modules/types.d.ts +132 -0
  190. package/dist/modules/types.js +2 -0
  191. package/dist/modules/types.js.map +1 -0
  192. package/dist/product/engine-spec.d.ts +0 -16
  193. package/dist/product/engine-spec.js +4 -50
  194. package/dist/product/engine-spec.js.map +1 -1
  195. package/dist/product/spec.d.ts +0 -82
  196. package/dist/product/spec.js +0 -79
  197. package/dist/product/spec.js.map +1 -1
  198. package/dist/product/version.d.ts +0 -23
  199. package/dist/product/version.js +0 -28
  200. package/dist/product/version.js.map +1 -1
  201. package/dist/products-index/products-index.d.ts +0 -165
  202. package/dist/products-index/products-index.js +0 -176
  203. package/dist/products-index/products-index.js.map +1 -1
  204. package/dist/workspace/context.d.ts +25 -0
  205. package/dist/workspace/context.js +43 -0
  206. package/dist/workspace/context.js.map +1 -0
  207. package/dist/workspace/gitExclude.d.ts +2 -0
  208. package/dist/workspace/gitExclude.js +19 -0
  209. package/dist/workspace/gitExclude.js.map +1 -0
  210. package/dist/workspace/host.d.ts +14 -0
  211. package/dist/workspace/host.js +13 -0
  212. package/dist/workspace/host.js.map +1 -0
  213. package/dist/workspace/index.d.ts +12 -0
  214. package/dist/workspace/index.js +12 -0
  215. package/dist/workspace/index.js.map +1 -0
  216. package/dist/workspace/local.d.ts +81 -0
  217. package/dist/workspace/local.js +287 -0
  218. package/dist/workspace/local.js.map +1 -0
  219. package/dist/workspace/modular.d.ts +95 -0
  220. package/dist/workspace/modular.js +301 -0
  221. package/dist/workspace/modular.js.map +1 -0
  222. package/dist/workspace/operations.d.ts +35 -0
  223. package/dist/workspace/operations.js +57 -0
  224. package/dist/workspace/operations.js.map +1 -0
  225. package/dist/workspace/origin.d.ts +20 -0
  226. package/dist/workspace/origin.js +19 -0
  227. package/dist/workspace/origin.js.map +1 -0
  228. package/package.json +82 -67
  229. package/dist/feature-model/convert.d.ts +0 -35
  230. package/dist/feature-model/convert.js +0 -47
  231. package/dist/feature-model/convert.js.map +0 -1
  232. package/dist/feature-model/engine.d.ts +0 -60
  233. package/dist/feature-model/engine.js +0 -139
  234. package/dist/feature-model/engine.js.map +0 -1
  235. package/dist/feature-model/inspect.d.ts +0 -67
  236. package/dist/feature-model/inspect.js +0 -113
  237. package/dist/feature-model/inspect.js.map +0 -1
  238. package/dist/feature-model/io.d.ts +0 -66
  239. package/dist/feature-model/io.js +0 -92
  240. package/dist/feature-model/io.js.map +0 -1
  241. package/dist/feature-model/parse.d.ts +0 -30
  242. package/dist/feature-model/parse.js +0 -36
  243. package/dist/feature-model/parse.js.map +0 -1
  244. package/dist/feature-model/text.d.ts +0 -54
  245. package/dist/feature-model/text.js +0 -126
  246. package/dist/feature-model/text.js.map +0 -1
  247. package/dist/line/templates/metamodels/dataModel/extra.js +0 -328
  248. package/dist/line/templates/metamodels/dataModel/transformation.js +0 -211
  249. package/dist/line/templates/metamodels/sensor/extra.js +0 -36
  250. package/dist/line/templates/metamodels/sensor/transformation.js +0 -47
  251. package/dist/selection/selection.d.ts +0 -126
  252. package/dist/selection/selection.js +0 -152
  253. package/dist/selection/selection.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"engine-spec.js","sourceRoot":"","sources":["../../src/product/engine-spec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAUrD;;;;;;;;;GASG;AACH,8EAA8E;AAC9E,gFAAgF;AAChF,4CAA4C;AAC5C,wEAAwE;AACxE,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAE,QAAiB,EAAW,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAA;AAE3F;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,EAAE,IAAI,EAAyB,EAA4B,EAAE;IAC3F,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,oBAAoB,CAAC,2BAA2B,CAAC,CAAA;IAC7D,CAAC;IAED,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAA;IAC1E,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC;QAAE,OAAO,IAAI,CAAA;IAEvC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAA;IACvE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,UAAU,EAAE,SAAS,CAAC;QAAE,OAAO,IAAI,CAAA;IAEzF,MAAM,aAAa,GAAG,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAA;IAEhF,OAAO;QACL,QAAQ,EAAE,MAAM,CAAC,QAAoB;QACrC,IAAI,EAAE;YACJ,GAAG,UAAU;YACb,SAAS,EAAE;gBACT,GAAG,UAAU,CAAC,SAAS;gBACvB,QAAQ,EAAE,QAAQ,CAAC,aAAa,EAAE,QAAQ,EAAE,EAAE,CAAC;gBAC/C,qEAAqE;gBACrE,mDAAmD;gBACnD,OAAO,EAAE,aAAa,EAAE,OAAO;aAChC;SACF;KACF,CAAA;AACH,CAAC,CAAA","sourcesContent":["/**\r\n * Adapts a product spec to the shape `spl-js-engine` expects.\r\n *\r\n * HARDENED PORT of\r\n * `linea/server/src/model/services/generatePipeline.js:buildEngineSpec` (~34-50).\r\n * The original guards the shortcut with plain truthiness\r\n * (`parsed?.features && parsed?.data?.basicData`), so a spec with\r\n * `sensor.parsed.features = 'ABC'` takes the shortcut and hands the engine a\r\n * string where it expects an array. Here the checks are `Array.isArray` and\r\n * `isPlainObject`, so such a spec passes through untouched instead.\r\n * Its comment explains the intent: when a product carries a parsed sensor DSL,\r\n * pipe it straight to the engine's shortcut path, which activates when both\r\n * `input.data` and `input.data.basicData` are present (see the mock platform's\r\n * `transformation.js:modelTransformation`). Otherwise the spec passes through.\r\n *\r\n * The sensor DSL itself is out of scope for linea-core in this batch; this\r\n * function only routes an ALREADY parsed `sensor.parsed` payload, which is why it\r\n * needs no DSL dependency.\r\n */\r\nimport { InvalidArgumentError } from '../errors.js'\r\nimport { isPlainObject } from '../internal/guards.js'\r\nimport type { ProductSpec } from './spec.js'\r\n\r\n/** A spec in the engine's shortcut shape. */\r\nexport interface EngineSpec {\r\n features: string[]\r\n data: Record<string, unknown>\r\n [key: string]: unknown\r\n}\r\n\r\n/**\r\n * Reproduces the monolith's `spec.basicData?.database || {}`.\r\n *\r\n * `??` would NOT be equivalent: `||` also replaces falsy non-nullish values\r\n * (`''`, `0`, `0n`, `false`, `NaN`). The schema types `database` as an Object so\r\n * the difference is unreachable in practice, but parity is parity and a silent\r\n * behaviour change here would be invisible until a generation produced the wrong\r\n * config. Written as a ternary on the value itself, which IS `||` by definition\r\n * and therefore cannot drift from it.\r\n */\r\n// NOTE: `??` is precisely the WRONG operator here. The monolith uses `||`, so\r\n// falsy non-nullish values must fall back too; that is the entire point of this\r\n// helper, and the lint rule cannot know it.\r\n// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\r\nconst truthyOr = (value: unknown, fallback: unknown): unknown => (value ? value : fallback)\r\n\r\n/**\r\n * Builds the spec handed to `DerivationEngine.generateProduct` / `generateZip`.\r\n *\r\n * Returns the input spec **by reference** when there is no sensor shortcut to\r\n * apply, exactly like the monolith — `generatePipeline.test.js:23-35` asserts\r\n * identity with `toBe(spec)`, so that is contractual, not incidental.\r\n *\r\n * The shortcut applies only when `spec.sensor.parsed` has BOTH `features` and\r\n * `data.basicData`. In that case `database` and `version` are carried over from\r\n * the product's own `basicData`, with `database` defaulting to `{}`.\r\n *\r\n * @param params.spec The product spec.\r\n * @returns Either the same spec, or a new object in the engine shortcut shape.\r\n * @throws {InvalidArgumentError} when `spec` is not an object.\r\n */\r\nexport const buildEngineSpec = ({ spec }: { spec: ProductSpec }): ProductSpec | EngineSpec => {\r\n if (!isPlainObject(spec)) {\r\n throw new InvalidArgumentError('\"spec\" must be an object.')\r\n }\r\n\r\n const parsed = isPlainObject(spec.sensor) ? spec.sensor.parsed : undefined\r\n if (!isPlainObject(parsed)) return spec\r\n\r\n const parsedData = isPlainObject(parsed.data) ? parsed.data : undefined\r\n if (!Array.isArray(parsed.features) || !isPlainObject(parsedData?.basicData)) return spec\r\n\r\n const specBasicData = isPlainObject(spec.basicData) ? spec.basicData : undefined\r\n\r\n return {\r\n features: parsed.features as string[],\r\n data: {\r\n ...parsedData,\r\n basicData: {\r\n ...parsedData.basicData,\r\n database: truthyOr(specBasicData?.database, {}),\r\n // No default: the monolith passes `spec.basicData?.version` straight\r\n // through, so an absent version stays `undefined`.\r\n version: specBasicData?.version\r\n }\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"engine-spec.js","sourceRoot":"","sources":["../../src/product/engine-spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AASrD,wEAAwE;AACxE,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAE,QAAiB,EAAW,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAA;AAE3F,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,EAAE,IAAI,EAAyB,EAA4B,EAAE;IAC3F,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,oBAAoB,CAAC,2BAA2B,CAAC,CAAA;IAC7D,CAAC;IAED,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAA;IAC1E,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC;QAAE,OAAO,IAAI,CAAA;IAEvC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAA;IACvE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,UAAU,EAAE,SAAS,CAAC;QAAE,OAAO,IAAI,CAAA;IAEzF,MAAM,aAAa,GAAG,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAA;IAEhF,OAAO;QACL,QAAQ,EAAE,MAAM,CAAC,QAAoB;QACrC,IAAI,EAAE;YACJ,GAAG,UAAU;YACb,SAAS,EAAE;gBACT,GAAG,UAAU,CAAC,SAAS;gBACvB,QAAQ,EAAE,QAAQ,CAAC,aAAa,EAAE,QAAQ,EAAE,EAAE,CAAC;gBAC/C,OAAO,EAAE,aAAa,EAAE,OAAO;aAChC;SACF;QACD,mFAAmF;QACnF,GAAG,CAAC,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;QAC7D,GAAG,CAAC,IAAI,CAAC,iBAAiB,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,iBAAiB,EAAE,IAAI,CAAC,iBAAiB,EAAE,CAAC;KAC/F,CAAA;AACH,CAAC,CAAA","sourcesContent":["import { InvalidArgumentError } from '../errors.js'\nimport { isPlainObject } from '../internal/guards.js'\nimport type { ProductSpec } from './spec.js'\n\nexport interface EngineSpec {\n features: string[]\n data: Record<string, unknown>\n [key: string]: unknown\n}\n\n// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\nconst truthyOr = (value: unknown, fallback: unknown): unknown => (value ? value : fallback)\n\nexport const buildEngineSpec = ({ spec }: { spec: ProductSpec }): ProductSpec | EngineSpec => {\n if (!isPlainObject(spec)) {\n throw new InvalidArgumentError('\"spec\" must be an object.')\n }\n\n const parsed = isPlainObject(spec.sensor) ? spec.sensor.parsed : undefined\n if (!isPlainObject(parsed)) return spec\n\n const parsedData = isPlainObject(parsed.data) ? parsed.data : undefined\n if (!Array.isArray(parsed.features) || !isPlainObject(parsedData?.basicData)) return spec\n\n const specBasicData = isPlainObject(spec.basicData) ? spec.basicData : undefined\n\n return {\n features: parsed.features as string[],\n data: {\n ...parsedData,\n basicData: {\n ...parsedData.basicData,\n database: truthyOr(specBasicData?.database, {}),\n version: specBasicData?.version\n }\n },\n // what the modules of a modular SPL read (`input.models`); absent for a plain line\n ...(spec.models === undefined ? {} : { models: spec.models }),\n ...(spec.modelsByMetamodel === undefined ? {} : { modelsByMetamodel: spec.modelsByMetamodel })\n }\n}\n"]}
@@ -1,4 +1,3 @@
1
- /** `spec.basicData` — product identity and generation-wide settings. */
2
1
  export interface ProductBasicData {
3
2
  name?: string;
4
3
  version?: string;
@@ -13,7 +12,6 @@ export interface ProductBasicData {
13
12
  createdAt?: unknown;
14
13
  [key: string]: unknown;
15
14
  }
16
- /** A product spec as stored by the monolith and consumed by the engine. */
17
15
  export interface ProductSpec {
18
16
  basicData?: ProductBasicData;
19
17
  dataModel?: {
@@ -26,105 +24,25 @@ export interface ProductSpec {
26
24
  dsl?: string;
27
25
  parsed?: unknown;
28
26
  };
29
- /** Legacy feature-selection field. */
30
27
  selection?: string[];
31
28
  [key: string]: unknown;
32
29
  }
33
- /** A single spec problem. */
34
30
  export interface ProductSpecError {
35
- /** Dotted path of the offending field, e.g. `spec.basicData.name`. */
36
31
  readonly path: string;
37
- /** Stable machine-readable discriminator. */
38
32
  readonly code: ProductSpecErrorCode;
39
- /**
40
- * An i18n KEY, never a human-readable sentence. Always pass it through the
41
- * consumer's translation function; there is nothing sensible to render raw.
42
- *
43
- * Five keys are INHERITED verbatim from the monolith and already have
44
- * translations in `linea/client/src/i18n/{en,es,gl}`:
45
- * `spec_object_validation`, `basicData_object_validation`,
46
- * `basicData_name_validation`, `invalid_name_characters`,
47
- * `basicData_version_format`.
48
- *
49
- * Four keys are NEW and have NO translation yet, because the monolith enforced
50
- * these constraints through the Mongoose schema rather than express-validator,
51
- * so there was no key to copy: `basicData_languages_validation`,
52
- * `basicData_SRID_validation`, `spec_features_validation`,
53
- * `spec_statics_validation`. Until webui and linea-cli add them, vue-i18n will
54
- * render the key itself. Tracked in CHANGELOG.md.
55
- */
56
33
  readonly messageKey: string;
57
34
  }
58
- /** Stable discriminators for spec problems. */
59
35
  export type ProductSpecErrorCode = 'SPEC_NOT_OBJECT' | 'BASIC_DATA_NOT_OBJECT' | 'NAME_REQUIRED' | 'NAME_INVALID_CHARACTERS' | 'VERSION_FORMAT' | 'LANGUAGES_NOT_STRING_ARRAY' | 'SRID_NOT_STRING' | 'FEATURES_INVALID_SHAPE' | 'STATICS_NOT_ARRAY';
60
- /** Result of validating a spec. */
61
36
  export interface ProductSpecValidation {
62
37
  readonly valid: boolean;
63
38
  readonly errors: ProductSpecError[];
64
39
  }
65
- /**
66
- * Validates a product spec **without throwing**.
67
- *
68
- * Reproduces `createProductValidator` / `updateProductValidator` with their exact
69
- * i18n keys, and ADDS shape checks for the fields whose type the Mongoose schema
70
- * used to enforce (`languages`, `SRID`, `features`, `statics`). Those four carry
71
- * new keys with no translation yet — see `ProductSpecError.messageKey`.
72
- *
73
- * `lineId` is NOT validated here: it is a GitLab/persistence concern that lives
74
- * in linea-server (ADR-003), even though `createProductValidator` checks it.
75
- *
76
- * @param params.spec The spec to validate. Anything, including nullish.
77
- * @returns `valid` plus one entry per problem, in a stable order.
78
- */
79
40
  export declare const validateProductSpec: ({ spec }: {
80
41
  spec: unknown;
81
42
  }) => ProductSpecValidation;
82
- /**
83
- * Validates a product spec and throws when it is not acceptable.
84
- *
85
- * The throwing counterpart of `validateProductSpec`, mirroring the
86
- * `validateFeatureSelection` / `assertFeatureSelection` pair. It is what makes
87
- * `InvalidProductSpecError` reachable: the monolith's equivalent is
88
- * express-validator short-circuiting the request with a 400 before
89
- * `ProductService.createProduct` ever runs, which has no direct analogue in a
90
- * library.
91
- *
92
- * The message lists every problem with its i18n key. Callers that need the
93
- * problems as DATA (to build an HTTP response body, say) should call
94
- * `validateProductSpec` instead — that is precisely what it is for, and it keeps
95
- * this error free of ad-hoc payload properties.
96
- *
97
- * @param params.spec The spec to validate.
98
- * @returns The spec, unchanged, when it is valid.
99
- * @throws {InvalidProductSpecError} listing every problem found.
100
- */
101
43
  export declare const assertProductSpec: ({ spec }: {
102
44
  spec: ProductSpec;
103
45
  }) => ProductSpec;
104
- /**
105
- * Fills a product spec with the domain defaults.
106
- *
107
- * Union of the two places the monolith applies defaults:
108
- * - `entities/product.js` (Mongoose schema): `version` `'0.0.0'`, `database` `{}`,
109
- * `extra` `{}`, `testEnvironment` `{ image: '', command: '' }`, `languages`
110
- * `['en','es','gl']`, `SRID` `'4326'`, `dataModel.cells` `[]`, `features` `[]`,
111
- * `statics` `[]`, `sensor` `{ dsl: '', parsed: null }`.
112
- * - `generatePipeline.js:saveProductVersion` (~212-222), which re-applies
113
- * `database`, `extra`, `languages` and `SRID` with `||` right before returning.
114
- *
115
- * `||` semantics are preserved for those four, which is subtler than it looks:
116
- * an empty-string `SRID` falls back to `'4326'` because `''` is falsy, but an
117
- * EMPTY `languages` array is kept because `[]` is truthy. Both match the monolith.
118
- *
119
- * PURE: returns a new object and never mutates the input. `basicData.createdAt`
120
- * is deliberately NOT filled — the schema defaults it to `Date.now`, which would
121
- * make this function non-deterministic. Timestamping is persistence metadata and
122
- * belongs to linea-server.
123
- *
124
- * @param params.spec The spec to complete.
125
- * @returns A new spec with defaults applied.
126
- * @throws {InvalidArgumentError} when `spec` is not an object.
127
- */
128
46
  export declare const normalizeProductSpec: ({ spec }: {
129
47
  spec: ProductSpec;
130
48
  }) => ProductSpec;
@@ -1,38 +1,6 @@
1
- /**
2
- * Product spec validation and default filling.
3
- *
4
- * Migrated from:
5
- * - `linea/server/src/rest/validators/productValidators.js` (createProductValidator,
6
- * updateProductValidator) and `commonValidators.js` (`nameRule`, `versionRule`)
7
- * - `linea/server/src/model/entities/product.js` — the Mongoose schema defaults
8
- * - `linea/server/src/model/services/generatePipeline.js:saveProductVersion`
9
- * (~212-222) — the defaults applied right before returning a generated product
10
- *
11
- * The monolith validates at the HTTP edge with express-validator and fills
12
- * defaults twice: once through the Mongoose schema and once again in
13
- * `saveProductVersion`. Neither mechanism exists in linea-core, so both collapse
14
- * into these two functions.
15
- *
16
- * `linea-cli/src/core/specSchema.ts` duplicates the same rules with Zod today and
17
- * is meant to call this instead.
18
- */
19
1
  import { DEFAULT_LANGUAGES, DEFAULT_SRID, NAME_PATTERN, VERSION_PATTERN } from '../constants.js';
20
2
  import { InvalidArgumentError, InvalidProductSpecError } from '../errors.js';
21
3
  import { isPlainObject } from '../internal/guards.js';
22
- /**
23
- * Validates a product spec **without throwing**.
24
- *
25
- * Reproduces `createProductValidator` / `updateProductValidator` with their exact
26
- * i18n keys, and ADDS shape checks for the fields whose type the Mongoose schema
27
- * used to enforce (`languages`, `SRID`, `features`, `statics`). Those four carry
28
- * new keys with no translation yet — see `ProductSpecError.messageKey`.
29
- *
30
- * `lineId` is NOT validated here: it is a GitLab/persistence concern that lives
31
- * in linea-server (ADR-003), even though `createProductValidator` checks it.
32
- *
33
- * @param params.spec The spec to validate. Anything, including nullish.
34
- * @returns `valid` plus one entry per problem, in a stable order.
35
- */
36
4
  export const validateProductSpec = ({ spec }) => {
37
5
  const errors = [];
38
6
  if (!isPlainObject(spec)) {
@@ -114,25 +82,6 @@ export const validateProductSpec = ({ spec }) => {
114
82
  }
115
83
  return { valid: errors.length === 0, errors };
116
84
  };
117
- /**
118
- * Validates a product spec and throws when it is not acceptable.
119
- *
120
- * The throwing counterpart of `validateProductSpec`, mirroring the
121
- * `validateFeatureSelection` / `assertFeatureSelection` pair. It is what makes
122
- * `InvalidProductSpecError` reachable: the monolith's equivalent is
123
- * express-validator short-circuiting the request with a 400 before
124
- * `ProductService.createProduct` ever runs, which has no direct analogue in a
125
- * library.
126
- *
127
- * The message lists every problem with its i18n key. Callers that need the
128
- * problems as DATA (to build an HTTP response body, say) should call
129
- * `validateProductSpec` instead — that is precisely what it is for, and it keeps
130
- * this error free of ad-hoc payload properties.
131
- *
132
- * @param params.spec The spec to validate.
133
- * @returns The spec, unchanged, when it is valid.
134
- * @throws {InvalidProductSpecError} listing every problem found.
135
- */
136
85
  export const assertProductSpec = ({ spec }) => {
137
86
  const { valid, errors } = validateProductSpec({ spec });
138
87
  if (!valid) {
@@ -141,30 +90,6 @@ export const assertProductSpec = ({ spec }) => {
141
90
  }
142
91
  return spec;
143
92
  };
144
- /**
145
- * Fills a product spec with the domain defaults.
146
- *
147
- * Union of the two places the monolith applies defaults:
148
- * - `entities/product.js` (Mongoose schema): `version` `'0.0.0'`, `database` `{}`,
149
- * `extra` `{}`, `testEnvironment` `{ image: '', command: '' }`, `languages`
150
- * `['en','es','gl']`, `SRID` `'4326'`, `dataModel.cells` `[]`, `features` `[]`,
151
- * `statics` `[]`, `sensor` `{ dsl: '', parsed: null }`.
152
- * - `generatePipeline.js:saveProductVersion` (~212-222), which re-applies
153
- * `database`, `extra`, `languages` and `SRID` with `||` right before returning.
154
- *
155
- * `||` semantics are preserved for those four, which is subtler than it looks:
156
- * an empty-string `SRID` falls back to `'4326'` because `''` is falsy, but an
157
- * EMPTY `languages` array is kept because `[]` is truthy. Both match the monolith.
158
- *
159
- * PURE: returns a new object and never mutates the input. `basicData.createdAt`
160
- * is deliberately NOT filled — the schema defaults it to `Date.now`, which would
161
- * make this function non-deterministic. Timestamping is persistence metadata and
162
- * belongs to linea-server.
163
- *
164
- * @param params.spec The spec to complete.
165
- * @returns A new spec with defaults applied.
166
- * @throws {InvalidArgumentError} when `spec` is not an object.
167
- */
168
93
  export const normalizeProductSpec = ({ spec }) => {
169
94
  if (!isPlainObject(spec)) {
170
95
  throw new InvalidArgumentError('"spec" must be an object.');
@@ -190,10 +115,6 @@ export const normalizeProductSpec = ({ spec }) => {
190
115
  image: typeof testEnvironment.image === 'string' ? testEnvironment.image : '',
191
116
  command: typeof testEnvironment.command === 'string' ? testEnvironment.command : ''
192
117
  },
193
- // An EMPTY array is kept. `saveProductVersion` uses `languages || [...]`
194
- // and `[]` is truthy in JavaScript, so the monolith preserves it; the
195
- // Mongoose default only fires when the path is `undefined`. A user who
196
- // deselected every language must generate the same product here.
197
118
  languages: Array.isArray(languages) ? [...languages] : [...DEFAULT_LANGUAGES],
198
119
  SRID: typeof basicData.SRID === 'string' && basicData.SRID !== ''
199
120
  ? basicData.SRID
@@ -1 +1 @@
1
- {"version":3,"file":"spec.js","sourceRoot":"","sources":["../../src/product/spec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,eAAe,EAChB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAA;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAuErD;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,EAAE,IAAI,EAAqB,EAAyB,EAAE;IACxF,MAAM,MAAM,GAAuB,EAAE,CAAA;IAErC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;QACzB,OAAO;YACL,KAAK,EAAE,KAAK;YACZ,MAAM,EAAE,CAAC;oBACP,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,iBAAiB;oBACvB,UAAU,EAAE,uCAAuC;iBACpD,CAAC;SACH,CAAA;IACH,CAAC;IAED,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAA;IAChC,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,EAAE,CAAC;QAC9B,OAAO;YACL,KAAK,EAAE,KAAK;YACZ,MAAM,EAAE,CAAC;oBACP,IAAI,EAAE,gBAAgB;oBACtB,IAAI,EAAE,uBAAuB;oBAC7B,UAAU,EAAE,4CAA4C;iBACzD,CAAC;SACH,CAAA;IACH,CAAC;IAED,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAA;I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AAC,IAAI,CAAC,QAAQ,CAAC;gBAC5B,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE;gBACtB,CAAC,CAAC,EAAE;QACR,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE;QAC7D,MAAM,EAAE;YACN,GAAG,MAAM;YACT,GAAG,EAAE,OAAO,MAAM,CAAC,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;YACrD,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,IAAI;SAC9B;KACF,CAAA;AACH,CAAC,CAAA","sourcesContent":["/**\r\n * Product spec validation and default filling.\r\n *\r\n * Migrated from:\r\n * - `linea/server/src/rest/validators/productValidators.js` (createProductValidator,\r\n * updateProductValidator) and `commonValidators.js` (`nameRule`, `versionRule`)\r\n * - `linea/server/src/model/entities/product.js` — the Mongoose schema defaults\r\n * - `linea/server/src/model/services/generatePipeline.js:saveProductVersion`\r\n * (~212-222) — the defaults applied right before returning a generated product\r\n *\r\n * The monolith validates at the HTTP edge with express-validator and fills\r\n * defaults twice: once through the Mongoose schema and once again in\r\n * `saveProductVersion`. Neither mechanism exists in linea-core, so both collapse\r\n * into these two functions.\r\n *\r\n * `linea-cli/src/core/specSchema.ts` duplicates the same rules with Zod today and\r\n * is meant to call this instead.\r\n */\r\nimport {\r\n DEFAULT_LANGUAGES,\r\n DEFAULT_SRID,\r\n NAME_PATTERN,\r\n VERSION_PATTERN\r\n} from '../constants.js'\r\nimport { InvalidArgumentError, InvalidProductSpecError } from '../errors.js'\r\nimport { isPlainObject } from '../internal/guards.js'\r\n\r\n/** `spec.basicData` — product identity and generation-wide settings. */\r\nexport interface ProductBasicData {\r\n name?: string\r\n version?: string\r\n languages?: string[]\r\n SRID?: string\r\n database?: Record<string, unknown>\r\n extra?: Record<string, unknown>\r\n testEnvironment?: { image?: string, command?: string }\r\n createdAt?: unknown\r\n [key: string]: unknown\r\n}\r\n\r\n/** A product spec as stored by the monolith and consumed by the engine. */\r\nexport interface ProductSpec {\r\n basicData?: ProductBasicData\r\n dataModel?: { cells?: unknown[], [key: string]: unknown }\r\n features?: string[] | Record<string, boolean>\r\n statics?: unknown[]\r\n sensor?: { dsl?: string, parsed?: unknown }\r\n /** Legacy feature-selection field. */\r\n selection?: string[]\r\n [key: string]: unknown\r\n}\r\n\r\n/** A single spec problem. */\r\nexport interface ProductSpecError {\r\n /** Dotted path of the offending field, e.g. `spec.basicData.name`. */\r\n readonly path: string\r\n /** Stable machine-readable discriminator. */\r\n readonly code: ProductSpecErrorCode\r\n /**\r\n * An i18n KEY, never a human-readable sentence. Always pass it through the\r\n * consumer's translation function; there is nothing sensible to render raw.\r\n *\r\n * Five keys are INHERITED verbatim from the monolith and already have\r\n * translations in `linea/client/src/i18n/{en,es,gl}`:\r\n * `spec_object_validation`, `basicData_object_validation`,\r\n * `basicData_name_validation`, `invalid_name_characters`,\r\n * `basicData_version_format`.\r\n *\r\n * Four keys are NEW and have NO translation yet, because the monolith enforced\r\n * these constraints through the Mongoose schema rather than express-validator,\r\n * so there was no key to copy: `basicData_languages_validation`,\r\n * `basicData_SRID_validation`, `spec_features_validation`,\r\n * `spec_statics_validation`. Until webui and linea-cli add them, vue-i18n will\r\n * render the key itself. Tracked in CHANGELOG.md.\r\n */\r\n readonly messageKey: string\r\n}\r\n\r\n/** Stable discriminators for spec problems. */\r\nexport type ProductSpecErrorCode =\r\n | 'SPEC_NOT_OBJECT'\r\n | 'BASIC_DATA_NOT_OBJECT'\r\n | 'NAME_REQUIRED'\r\n | 'NAME_INVALID_CHARACTERS'\r\n | 'VERSION_FORMAT'\r\n | 'LANGUAGES_NOT_STRING_ARRAY'\r\n | 'SRID_NOT_STRING'\r\n | 'FEATURES_INVALID_SHAPE'\r\n | 'STATICS_NOT_ARRAY'\r\n\r\n/** Result of validating a spec. */\r\nexport interface ProductSpecValidation {\r\n readonly valid: boolean\r\n readonly errors: ProductSpecError[]\r\n}\r\n\r\n/**\r\n * Validates a product spec **without throwing**.\r\n *\r\n * Reproduces `createProductValidator` / `updateProductValidator` with their exact\r\n * i18n keys, and ADDS shape checks for the fields whose type the Mongoose schema\r\n * used to enforce (`languages`, `SRID`, `features`, `statics`). Those four carry\r\n * new keys with no translation yet — see `ProductSpecError.messageKey`.\r\n *\r\n * `lineId` is NOT validated here: it is a GitLab/persistence concern that lives\r\n * in linea-server (ADR-003), even though `createProductValidator` checks it.\r\n *\r\n * @param params.spec The spec to validate. Anything, including nullish.\r\n * @returns `valid` plus one entry per problem, in a stable order.\r\n */\r\nexport const validateProductSpec = ({ spec }: { spec: unknown }): ProductSpecValidation => {\r\n const errors: ProductSpecError[] = []\r\n\r\n if (!isPlainObject(spec)) {\r\n return {\r\n valid: false,\r\n errors: [{\r\n path: 'spec',\r\n code: 'SPEC_NOT_OBJECT',\r\n messageKey: 'error_messages.spec_object_validation'\r\n }]\r\n }\r\n }\r\n\r\n const basicData = spec.basicData\r\n if (!isPlainObject(basicData)) {\r\n return {\r\n valid: false,\r\n errors: [{\r\n path: 'spec.basicData',\r\n code: 'BASIC_DATA_NOT_OBJECT',\r\n messageKey: 'error_messages.basicData_object_validation'\r\n }]\r\n }\r\n }\r\n\r\n const name = basicData.name\r\n if (typeof name !== 'string' || name === '') {\r\n errors.push({\r\n path: 'spec.basicData.name',\r\n code: 'NAME_REQUIRED',\r\n messageKey: 'error_messages.basicData_name_validation'\r\n })\r\n } else if (!NAME_PATTERN.test(name)) {\r\n errors.push({\r\n path: 'spec.basicData.name',\r\n code: 'NAME_INVALID_CHARACTERS',\r\n messageKey: 'error_messages.invalid_name_characters'\r\n })\r\n }\r\n\r\n if (typeof basicData.version !== 'string' || !VERSION_PATTERN.test(basicData.version)) {\r\n errors.push({\r\n path: 'spec.basicData.version',\r\n code: 'VERSION_FORMAT',\r\n messageKey: 'error_messages.basicData_version_format'\r\n })\r\n }\r\n\r\n const { languages } = basicData\r\n if (\r\n languages !== undefined &&\r\n (!Array.isArray(languages) || languages.some((l) => typeof l !== 'string'))\r\n ) {\r\n errors.push({\r\n path: 'spec.basicData.languages',\r\n code: 'LANGUAGES_NOT_STRING_ARRAY',\r\n messageKey: 'error_messages.basicData_languages_validation'\r\n })\r\n }\r\n\r\n if (basicData.SRID !== undefined && typeof basicData.SRID !== 'string') {\r\n errors.push({\r\n path: 'spec.basicData.SRID',\r\n code: 'SRID_NOT_STRING',\r\n messageKey: 'error_messages.basicData_SRID_validation'\r\n })\r\n }\r\n\r\n const { features } = spec\r\n const featuresValid =\r\n features === undefined ||\r\n (Array.isArray(features) && features.every((f) => typeof f === 'string')) ||\r\n isPlainObject(features)\r\n if (!featuresValid) {\r\n errors.push({\r\n path: 'spec.features',\r\n code: 'FEATURES_INVALID_SHAPE',\r\n messageKey: 'error_messages.spec_features_validation'\r\n })\r\n }\r\n\r\n if (spec.statics !== undefined && !Array.isArray(spec.statics)) {\r\n errors.push({\r\n path: 'spec.statics',\r\n code: 'STATICS_NOT_ARRAY',\r\n messageKey: 'error_messages.spec_statics_validation'\r\n })\r\n }\r\n\r\n return { valid: errors.length === 0, errors }\r\n}\r\n\r\n/**\r\n * Validates a product spec and throws when it is not acceptable.\r\n *\r\n * The throwing counterpart of `validateProductSpec`, mirroring the\r\n * `validateFeatureSelection` / `assertFeatureSelection` pair. It is what makes\r\n * `InvalidProductSpecError` reachable: the monolith's equivalent is\r\n * express-validator short-circuiting the request with a 400 before\r\n * `ProductService.createProduct` ever runs, which has no direct analogue in a\r\n * library.\r\n *\r\n * The message lists every problem with its i18n key. Callers that need the\r\n * problems as DATA (to build an HTTP response body, say) should call\r\n * `validateProductSpec` instead — that is precisely what it is for, and it keeps\r\n * this error free of ad-hoc payload properties.\r\n *\r\n * @param params.spec The spec to validate.\r\n * @returns The spec, unchanged, when it is valid.\r\n * @throws {InvalidProductSpecError} listing every problem found.\r\n */\r\nexport const assertProductSpec = ({ spec }: { spec: ProductSpec }): ProductSpec => {\r\n const { valid, errors } = validateProductSpec({ spec })\r\n if (!valid) {\r\n const summary = errors.map((error) => `${error.path}: ${error.messageKey}`).join('; ')\r\n throw new InvalidProductSpecError(`Invalid product spec: ${summary}`)\r\n }\r\n return spec\r\n}\r\n\r\n/**\r\n * Fills a product spec with the domain defaults.\r\n *\r\n * Union of the two places the monolith applies defaults:\r\n * - `entities/product.js` (Mongoose schema): `version` `'0.0.0'`, `database` `{}`,\r\n * `extra` `{}`, `testEnvironment` `{ image: '', command: '' }`, `languages`\r\n * `['en','es','gl']`, `SRID` `'4326'`, `dataModel.cells` `[]`, `features` `[]`,\r\n * `statics` `[]`, `sensor` `{ dsl: '', parsed: null }`.\r\n * - `generatePipeline.js:saveProductVersion` (~212-222), which re-applies\r\n * `database`, `extra`, `languages` and `SRID` with `||` right before returning.\r\n *\r\n * `||` semantics are preserved for those four, which is subtler than it looks:\r\n * an empty-string `SRID` falls back to `'4326'` because `''` is falsy, but an\r\n * EMPTY `languages` array is kept because `[]` is truthy. Both match the monolith.\r\n *\r\n * PURE: returns a new object and never mutates the input. `basicData.createdAt`\r\n * is deliberately NOT filled — the schema defaults it to `Date.now`, which would\r\n * make this function non-deterministic. Timestamping is persistence metadata and\r\n * belongs to linea-server.\r\n *\r\n * @param params.spec The spec to complete.\r\n * @returns A new spec with defaults applied.\r\n * @throws {InvalidArgumentError} when `spec` is not an object.\r\n */\r\nexport const normalizeProductSpec = ({ spec }: { spec: ProductSpec }): ProductSpec => {\r\n if (!isPlainObject(spec)) {\r\n throw new InvalidArgumentError('\"spec\" must be an object.')\r\n }\r\n const basicData = isPlainObject(spec.basicData) ? spec.basicData : {}\r\n const dataModel = isPlainObject(spec.dataModel) ? spec.dataModel : {}\r\n const sensor = isPlainObject(spec.sensor) ? spec.sensor : {}\r\n const testEnvironment = isPlainObject(basicData.testEnvironment)\r\n ? basicData.testEnvironment\r\n : {}\r\n\r\n const { languages } = basicData\r\n\r\n return {\r\n ...spec,\r\n basicData: {\r\n ...basicData,\r\n name: typeof basicData.name === 'string' ? basicData.name : '',\r\n version: typeof basicData.version === 'string' && basicData.version !== ''\r\n ? basicData.version\r\n : '0.0.0',\r\n database: isPlainObject(basicData.database) ? basicData.database : {},\r\n extra: isPlainObject(basicData.extra) ? basicData.extra : {},\r\n testEnvironment: {\r\n image: typeof testEnvironment.image === 'string' ? testEnvironment.image : '',\r\n command: typeof testEnvironment.command === 'string' ? testEnvironment.command : ''\r\n },\r\n // An EMPTY array is kept. `saveProductVersion` uses `languages || [...]`\r\n // and `[]` is truthy in JavaScript, so the monolith preserves it; the\r\n // Mongoose default only fires when the path is `undefined`. A user who\r\n // deselected every language must generate the same product here.\r\n languages: Array.isArray(languages) ? [...languages] : [...DEFAULT_LANGUAGES],\r\n SRID: typeof basicData.SRID === 'string' && basicData.SRID !== ''\r\n ? basicData.SRID\r\n : DEFAULT_SRID\r\n },\r\n dataModel: {\r\n ...dataModel,\r\n cells: Array.isArray(dataModel.cells) ? [...dataModel.cells] : []\r\n },\r\n features: Array.isArray(spec.features)\r\n ? [...spec.features]\r\n : isPlainObject(spec.features)\r\n ? { ...spec.features }\r\n : [],\r\n statics: Array.isArray(spec.statics) ? [...spec.statics] : [],\r\n sensor: {\r\n ...sensor,\r\n dsl: typeof sensor.dsl === 'string' ? sensor.dsl : '',\r\n parsed: sensor.parsed ?? null\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"spec.js","sourceRoot":"","sources":["../../src/product/spec.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,eAAe,EAChB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAA;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AA8CrD,MAAM,CAAC,MAAM,mBAAmB,G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AAiB,CAAC;YAC7E,IAAI,EAAE,OAAO,SAAS,CAAC,IAAI,KAAK,QAAQ,IAAI,SAAS,CAAC,IAAI,KAAK,EAAE;gBAC/D,CAAC,CAAC,SAAS,CAAC,IAAI;gBAChB,CAAC,CAAC,YAAY;SACjB;QACD,SAAS,EAAE;YACT,GAAG,SAAS;YACZ,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;SAClE;QACD,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC;YACpC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC;YACpB,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC;gBAC5B,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE;gBACtB,CAAC,CAAC,EAAE;QACR,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE;QAC7D,MAAM,EAAE;YACN,GAAG,MAAM;YACT,GAAG,EAAE,OAAO,MAAM,CAAC,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;YACrD,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,IAAI;SAC9B;KACF,CAAA;AACH,CAAC,CAAA","sourcesContent":["import {\n DEFAULT_LANGUAGES,\n DEFAULT_SRID,\n NAME_PATTERN,\n VERSION_PATTERN\n} from '../constants.js'\nimport { InvalidArgumentError, InvalidProductSpecError } from '../errors.js'\nimport { isPlainObject } from '../internal/guards.js'\n\nexport interface ProductBasicData {\n name?: string\n version?: string\n languages?: string[]\n SRID?: string\n database?: Record<string, unknown>\n extra?: Record<string, unknown>\n testEnvironment?: { image?: string, command?: string }\n createdAt?: unknown\n [key: string]: unknown\n}\n\nexport interface ProductSpec {\n basicData?: ProductBasicData\n dataModel?: { cells?: unknown[], [key: string]: unknown }\n features?: string[] | Record<string, boolean>\n statics?: unknown[]\n sensor?: { dsl?: string, parsed?: unknown }\n selection?: string[]\n [key: string]: unknown\n}\n\nexport interface ProductSpecError {\n readonly path: string\n readonly code: ProductSpecErrorCode\n readonly messageKey: string\n}\n\nexport type ProductSpecErrorCode =\n | 'SPEC_NOT_OBJECT'\n | 'BASIC_DATA_NOT_OBJECT'\n | 'NAME_REQUIRED'\n | 'NAME_INVALID_CHARACTERS'\n | 'VERSION_FORMAT'\n | 'LANGUAGES_NOT_STRING_ARRAY'\n | 'SRID_NOT_STRING'\n | 'FEATURES_INVALID_SHAPE'\n | 'STATICS_NOT_ARRAY'\n\nexport interface ProductSpecValidation {\n readonly valid: boolean\n readonly errors: ProductSpecError[]\n}\n\nexport const validateProductSpec = ({ spec }: { spec: unknown }): ProductSpecValidation => {\n const errors: ProductSpecError[] = []\n\n if (!isPlainObject(spec)) {\n return {\n valid: false,\n errors: [{\n path: 'spec',\n code: 'SPEC_NOT_OBJECT',\n messageKey: 'error_messages.spec_object_validation'\n }]\n }\n }\n\n const basicData = spec.basicData\n if (!isPlainObject(basicData)) {\n return {\n valid: false,\n errors: [{\n path: 'spec.basicData',\n code: 'BASIC_DATA_NOT_OBJECT',\n messageKey: 'error_messages.basicData_object_validation'\n }]\n }\n }\n\n const name = basicData.name\n if (typeof name !== 'string' || name === '') {\n errors.push({\n path: 'spec.basicData.name',\n code: 'NAME_REQUIRED',\n messageKey: 'error_messages.basicData_name_validation'\n })\n } else if (!NAME_PATTERN.test(name)) {\n errors.push({\n path: 'spec.basicData.name',\n code: 'NAME_INVALID_CHARACTERS',\n messageKey: 'error_messages.invalid_name_characters'\n })\n }\n\n if (typeof basicData.version !== 'string' || !VERSION_PATTERN.test(basicData.version)) {\n errors.push({\n path: 'spec.basicData.version',\n code: 'VERSION_FORMAT',\n messageKey: 'error_messages.basicData_version_format'\n })\n }\n\n const { languages } = basicData\n if (\n languages !== undefined &&\n (!Array.isArray(languages) || languages.some((l) => typeof l !== 'string'))\n ) {\n errors.push({\n path: 'spec.basicData.languages',\n code: 'LANGUAGES_NOT_STRING_ARRAY',\n messageKey: 'error_messages.basicData_languages_validation'\n })\n }\n\n if (basicData.SRID !== undefined && typeof basicData.SRID !== 'string') {\n errors.push({\n path: 'spec.basicData.SRID',\n code: 'SRID_NOT_STRING',\n messageKey: 'error_messages.basicData_SRID_validation'\n })\n }\n\n const { features } = spec\n const featuresValid =\n features === undefined ||\n (Array.isArray(features) && features.every((f) => typeof f === 'string')) ||\n isPlainObject(features)\n if (!featuresValid) {\n errors.push({\n path: 'spec.features',\n code: 'FEATURES_INVALID_SHAPE',\n messageKey: 'error_messages.spec_features_validation'\n })\n }\n\n if (spec.statics !== undefined && !Array.isArray(spec.statics)) {\n errors.push({\n path: 'spec.statics',\n code: 'STATICS_NOT_ARRAY',\n messageKey: 'error_messages.spec_statics_validation'\n })\n }\n\n return { valid: errors.length === 0, errors }\n}\n\nexport const assertProductSpec = ({ spec }: { spec: ProductSpec }): ProductSpec => {\n const { valid, errors } = validateProductSpec({ spec })\n if (!valid) {\n const summary = errors.map((error) => `${error.path}: ${error.messageKey}`).join('; ')\n throw new InvalidProductSpecError(`Invalid product spec: ${summary}`)\n }\n return spec\n}\n\nexport const normalizeProductSpec = ({ spec }: { spec: ProductSpec }): ProductSpec => {\n if (!isPlainObject(spec)) {\n throw new InvalidArgumentError('\"spec\" must be an object.')\n }\n const basicData = isPlainObject(spec.basicData) ? spec.basicData : {}\n const dataModel = isPlainObject(spec.dataModel) ? spec.dataModel : {}\n const sensor = isPlainObject(spec.sensor) ? spec.sensor : {}\n const testEnvironment = isPlainObject(basicData.testEnvironment)\n ? basicData.testEnvironment\n : {}\n\n const { languages } = basicData\n\n return {\n ...spec,\n basicData: {\n ...basicData,\n name: typeof basicData.name === 'string' ? basicData.name : '',\n version: typeof basicData.version === 'string' && basicData.version !== ''\n ? basicData.version\n : '0.0.0',\n database: isPlainObject(basicData.database) ? basicData.database : {},\n extra: isPlainObject(basicData.extra) ? basicData.extra : {},\n testEnvironment: {\n image: typeof testEnvironment.image === 'string' ? testEnvironment.image : '',\n command: typeof testEnvironment.command === 'string' ? testEnvironment.command : ''\n },\n languages: Array.isArray(languages) ? [...languages] : [...DEFAULT_LANGUAGES],\n SRID: typeof basicData.SRID === 'string' && basicData.SRID !== ''\n ? basicData.SRID\n : DEFAULT_SRID\n },\n dataModel: {\n ...dataModel,\n cells: Array.isArray(dataModel.cells) ? [...dataModel.cells] : []\n },\n features: Array.isArray(spec.features)\n ? [...spec.features]\n : isPlainObject(spec.features)\n ? { ...spec.features }\n : [],\n statics: Array.isArray(spec.statics) ? [...spec.statics] : [],\n sensor: {\n ...sensor,\n dsl: typeof sensor.dsl === 'string' ? sensor.dsl : '',\n parsed: sensor.parsed ?? null\n }\n }\n}\n"]}
@@ -1,26 +1,3 @@
1
- /**
2
- * Bumps one component of an `x.y.z` version, zeroing everything to its right.
3
- *
4
- * Verbatim algorithm of the monolith: the component at `index` is incremented
5
- * and every component after it is reset to 0.
6
- *
7
- * incrementVersion({ version: '1.2.3', index: 0 }) === '2.0.0'
8
- * incrementVersion({ version: '1.2.3', index: 1 }) === '1.3.0'
9
- * incrementVersion({ version: '1.2.3', index: 2 }) === '1.2.4'
10
- *
11
- * The monolith bumps index 1 on a feature-model save (`LineService.js:406`) and
12
- * on a conversion, and index 2 on a product generation.
13
- *
14
- * HARDENED (ADR-019): the original does `version.split('.').map(Number)` with no
15
- * validation, so `'abc'` silently yields `'NaN.NaN.NaN'` and would be persisted.
16
- * Here a version that does not match `VERSION_PATTERN` is rejected.
17
- *
18
- * @param params.version Current version, `x.y.z`.
19
- * @param params.index Zero-based component to bump: 0 major, 1 minor, 2 patch.
20
- * @returns The bumped version.
21
- * @throws {InvalidArgumentError} when `version` is not `x.y.z` or `index` is not
22
- * an integer in `[0, 2]`.
23
- */
24
1
  export declare const incrementVersion: ({ version, index }: {
25
2
  version: string;
26
3
  index: number;
@@ -1,33 +1,5 @@
1
- /**
2
- * Product version arithmetic.
3
- *
4
- * Migrated from `linea/server/src/model/services/utils.js:incrementVersion` (~152-163).
5
- */
6
1
  import { VERSION_PATTERN } from '../constants.js';
7
2
  import { InvalidArgumentError } from '../errors.js';
8
- /**
9
- * Bumps one component of an `x.y.z` version, zeroing everything to its right.
10
- *
11
- * Verbatim algorithm of the monolith: the component at `index` is incremented
12
- * and every component after it is reset to 0.
13
- *
14
- * incrementVersion({ version: '1.2.3', index: 0 }) === '2.0.0'
15
- * incrementVersion({ version: '1.2.3', index: 1 }) === '1.3.0'
16
- * incrementVersion({ version: '1.2.3', index: 2 }) === '1.2.4'
17
- *
18
- * The monolith bumps index 1 on a feature-model save (`LineService.js:406`) and
19
- * on a conversion, and index 2 on a product generation.
20
- *
21
- * HARDENED (ADR-019): the original does `version.split('.').map(Number)` with no
22
- * validation, so `'abc'` silently yields `'NaN.NaN.NaN'` and would be persisted.
23
- * Here a version that does not match `VERSION_PATTERN` is rejected.
24
- *
25
- * @param params.version Current version, `x.y.z`.
26
- * @param params.index Zero-based component to bump: 0 major, 1 minor, 2 patch.
27
- * @returns The bumped version.
28
- * @throws {InvalidArgumentError} when `version` is not `x.y.z` or `index` is not
29
- * an integer in `[0, 2]`.
30
- */
31
3
  export const incrementVersion = ({ version, index }) => {
32
4
  if (typeof version !== 'string' || !VERSION_PATTERN.test(version)) {
33
5
  throw new InvalidArgumentError(`"version" must match x.y.z, got ${JSON.stringify(version)}.`);
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/product/version.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAEnD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,EAC/B,OAAO,EACP,KAAK,EAIN,EAAU,EAAE;IACX,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAClE,MAAM,IAAI,oBAAoB,CAC5B,mCAAmC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,CAC9D,CAAA;IACH,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACvD,MAAM,IAAI,oBAAoB,CAAC,6CAA6C,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC/F,CAAC;IAED,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IAC5C,OAAO,KAAK;SACT,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE;QACf,IAAI,CAAC,KAAK,KAAK;YAAE,OAAO,IAAI,GAAG,CAAC,CAAA;QAChC,IAAI,CAAC,GAAG,KAAK;YAAE,OAAO,CAAC,CAAA;QACvB,OAAO,IAAI,CAAA;IACb,CAAC,CAAC;SACD,IAAI,CAAC,GAAG,CAAC,CAAA;AACd,CAAC,CAAA","sourcesContent":["/**\r\n * Product version arithmetic.\r\n *\r\n * Migrated from `linea/server/src/model/services/utils.js:incrementVersion` (~152-163).\r\n */\r\nimport { VERSION_PATTERN } from '../constants.js'\r\nimport { InvalidArgumentError } from '../errors.js'\r\n\r\n/**\r\n * Bumps one component of an `x.y.z` version, zeroing everything to its right.\r\n *\r\n * Verbatim algorithm of the monolith: the component at `index` is incremented\r\n * and every component after it is reset to 0.\r\n *\r\n * incrementVersion({ version: '1.2.3', index: 0 }) === '2.0.0'\r\n * incrementVersion({ version: '1.2.3', index: 1 }) === '1.3.0'\r\n * incrementVersion({ version: '1.2.3', index: 2 }) === '1.2.4'\r\n *\r\n * The monolith bumps index 1 on a feature-model save (`LineService.js:406`) and\r\n * on a conversion, and index 2 on a product generation.\r\n *\r\n * HARDENED (ADR-019): the original does `version.split('.').map(Number)` with no\r\n * validation, so `'abc'` silently yields `'NaN.NaN.NaN'` and would be persisted.\r\n * Here a version that does not match `VERSION_PATTERN` is rejected.\r\n *\r\n * @param params.version Current version, `x.y.z`.\r\n * @param params.index Zero-based component to bump: 0 major, 1 minor, 2 patch.\r\n * @returns The bumped version.\r\n * @throws {InvalidArgumentError} when `version` is not `x.y.z` or `index` is not\r\n * an integer in `[0, 2]`.\r\n */\r\nexport const incrementVersion = ({\r\n version,\r\n index\r\n}: {\r\n version: string\r\n index: number\r\n}): string => {\r\n if (typeof version !== 'string' || !VERSION_PATTERN.test(version)) {\r\n throw new InvalidArgumentError(\r\n `\"version\" must match x.y.z, got ${JSON.stringify(version)}.`\r\n )\r\n }\r\n if (!Number.isInteger(index) || index < 0 || index > 2) {\r\n throw new InvalidArgumentError(`\"index\" must be an integer in [0, 2], got ${String(index)}.`)\r\n }\r\n\r\n const parts = version.split('.').map(Number)\r\n return parts\r\n .map((part, i) => {\r\n if (i === index) return part + 1\r\n if (i > index) return 0\r\n return part\r\n })\r\n .join('.')\r\n}\r\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/product/version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAEnD,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,EAC/B,OAAO,EACP,KAAK,EAIN,EAAU,EAAE;IACX,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAClE,MAAM,IAAI,oBAAoB,CAC5B,mCAAmC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,CAC9D,CAAA;IACH,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACvD,MAAM,IAAI,oBAAoB,CAAC,6CAA6C,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC/F,CAAC;IAED,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IAC5C,OAAO,KAAK;SACT,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE;QACf,IAAI,CAAC,KAAK,KAAK;YAAE,OAAO,IAAI,GAAG,CAAC,CAAA;QAChC,IAAI,CAAC,GAAG,KAAK;YAAE,OAAO,CAAC,CAAA;QACvB,OAAO,IAAI,CAAA;IACb,CAAC,CAAC;SACD,IAAI,CAAC,GAAG,CAAC,CAAA;AACd,CAAC,CAAA","sourcesContent":["import { VERSION_PATTERN } from '../constants.js'\nimport { InvalidArgumentError } from '../errors.js'\n\nexport const incrementVersion = ({\n version,\n index\n}: {\n version: string\n index: number\n}): string => {\n if (typeof version !== 'string' || !VERSION_PATTERN.test(version)) {\n throw new InvalidArgumentError(\n `\"version\" must match x.y.z, got ${JSON.stringify(version)}.`\n )\n }\n if (!Number.isInteger(index) || index < 0 || index > 2) {\n throw new InvalidArgumentError(`\"index\" must be an integer in [0, 2], got ${String(index)}.`)\n }\n\n const parts = version.split('.').map(Number)\n return parts\n .map((part, i) => {\n if (i === index) return part + 1\n if (i > index) return 0\n return part\n })\n .join('.')\n}\n"]}
@@ -1,223 +1,58 @@
1
- /** One product of a line, as recorded in `products.json`. */
2
1
  export interface ProductsIndexEntry {
3
- /** Product name; same rules as any other name (`NAME_PATTERN`). */
4
2
  readonly name: string;
5
- /** Path of the product repository in the laboratory's GitLab. */
6
3
  readonly repositorio: string;
7
- /**
8
- * Current product version (`VERSION_PATTERN`, i.e. `x.y.z`). **Optional**:
9
- * every index written before this field existed is still valid, and an entry
10
- * without it is never given one implicitly.
11
- *
12
- * It duplicates `spec.basicData.version`, which lives in the product's own
13
- * repository. That is the point: the enrolled-products listing needs every
14
- * version at once, and reading one file per product would be one GitLab
15
- * request per row. The product repository stays the source of truth; this is
16
- * the copy the line keeps to be able to list without fanning out.
17
- */
18
4
  readonly version?: string;
19
5
  }
20
- /** The whole index. */
21
6
  export interface ProductsIndex {
22
7
  readonly productos: ProductsIndexEntry[];
23
8
  }
24
- /** A problem found in an index. */
25
9
  export interface ProductsIndexProblem {
26
- /** Dotted path of the offending field, e.g. `productos[2].repositorio`. */
27
10
  readonly path: string;
28
- /** Stable machine-readable discriminator. */
29
11
  readonly code: ProductsIndexProblemCode;
30
- /**
31
- * An i18n KEY, never a human-readable sentence — same policy as
32
- * `ProductSpecError.messageKey`, so a consumer never has to guess whether to
33
- * translate a value or render it raw.
34
- *
35
- * Two keys are inherited from the monolith and already translated:
36
- * `invalid_name_characters` and `basicData_version_format` (the latter reads
37
- * "Version must follow the format X.Y.Z", which is exactly the fact being
38
- * reported, so it is reused instead of minting an untranslated twin). The
39
- * rest are NEW (there was no products index to validate before ADR-011) and
40
- * have no translation yet; they are listed in CHANGELOG.md for whoever
41
- * migrates webui and linea-cli.
42
- */
43
12
  readonly messageKey: string;
44
13
  }
45
- /** Stable discriminators for index problems. */
46
14
  export type ProductsIndexProblemCode = 'INDEX_NOT_OBJECT' | 'PRODUCTOS_NOT_ARRAY' | 'ENTRY_NOT_OBJECT' | 'NAME_REQUIRED' | 'NAME_INVALID_CHARACTERS' | 'NAME_DUPLICATED' | 'REPOSITORIO_REQUIRED' | 'VERSION_INVALID_FORMAT';
47
- /** Result of validating an index. */
48
15
  export interface ProductsIndexValidation {
49
16
  readonly valid: boolean;
50
17
  readonly errors: ProductsIndexProblem[];
51
18
  }
52
- /**
53
- * An empty index.
54
- *
55
- * @returns A fresh `{ productos: [] }`. A new object every call, so callers can
56
- * safely treat it as their own.
57
- */
58
19
  export declare const emptyProductsIndex: () => ProductsIndex;
59
- /**
60
- * Validates an index **without throwing**.
61
- *
62
- * Checks the ADR-011 shape plus the domain rules that make the index usable:
63
- * names must be valid (`NAME_PATTERN`) and unique, and every entry needs a
64
- * `repositorio`.
65
- *
66
- * @param params.index The index to validate. Anything, including nullish.
67
- * @returns `valid` plus one entry per problem, in document order.
68
- */
69
20
  export declare const validateProductsIndex: ({ index }: {
70
21
  index: unknown;
71
22
  }) => ProductsIndexValidation;
72
- /**
73
- * Parses the JSON contents of a `products.json`.
74
- *
75
- * @param params.content Raw file contents.
76
- * @returns The index, with only the normative fields kept per entry: `name`,
77
- * `repositorio` and, when the file has it, `version`. An index written before
78
- * `version` existed parses exactly as it always did.
79
- * @throws {ProductsIndexError} when the JSON is malformed or does not satisfy
80
- * the ADR-011 shape — which includes a `version` present but not `x.y.z`.
81
- */
82
23
  export declare const parseProductsIndex: ({ content }: {
83
24
  content: string;
84
25
  }) => ProductsIndex;
85
- /**
86
- * Serialises an index deterministically.
87
- *
88
- * Stability is a feature, not a detail: linea-server commits this file to the
89
- * line repository on every product create/rename/delete, so an unstable
90
- * serialisation would produce noisy diffs and spurious merge conflicts.
91
- * Guarantees: entries sorted alphabetically by `name`, only the normative fields
92
- * emitted and always in the same order (`name`, `repositorio`, `version`),
93
- * two-space indentation, single trailing newline.
94
- *
95
- * An entry with no version emits **no `version` key** — not `null`, not `''`.
96
- * That is what keeps an index written before this field byte-identical after a
97
- * read/write round trip.
98
- *
99
- * @param params.index The index to serialise.
100
- * @returns The JSON text to write.
101
- * @throws {InvalidArgumentError} when `index` is not index-shaped.
102
- */
103
26
  export declare const serializeProductsIndex: ({ index }: {
104
27
  index: ProductsIndex;
105
28
  }) => string;
106
- /**
107
- * Adds a product to the index.
108
- *
109
- * @param params.index Current index. Not mutated.
110
- * @param params.product Entry to add. `version` is optional; when given it must
111
- * be `x.y.z`, and when omitted the entry simply has no version.
112
- * @returns A new, sorted index.
113
- * @throws {ProductsIndexError} when a product with that name is already there.
114
- * @throws {InvalidArgumentError} when the arguments are malformed.
115
- */
116
29
  export declare const addProductToIndex: ({ index, product }: {
117
30
  index: ProductsIndex;
118
31
  product: ProductsIndexEntry;
119
32
  }) => ProductsIndex;
120
- /**
121
- * Renames a product in the index, keeping its `repositorio` and its `version`.
122
- *
123
- * Note the repository path is intentionally left untouched: renaming a GitLab
124
- * project does not necessarily move it, and linea-server is the only component
125
- * that knows the new path. It should follow up with the real value if it changed.
126
- *
127
- * @param params.index Current index. Not mutated.
128
- * @param params.from Current product name.
129
- * @param params.to New product name.
130
- * @returns A new, sorted index.
131
- * @throws {ProductsIndexError} when `from` is missing or `to` already exists.
132
- * @throws {InvalidArgumentError} when the arguments are malformed.
133
- */
134
33
  export declare const renameProductInIndex: ({ index, from, to }: {
135
34
  index: ProductsIndex;
136
35
  from: string;
137
36
  to: string;
138
37
  }) => ProductsIndex;
139
- /**
140
- * Removes a product from the index.
141
- *
142
- * IDEMPOTENT: removing a product that is not there returns an equivalent index
143
- * instead of throwing, so a retried or replayed delete cannot fail half-way.
144
- *
145
- * @param params.index Current index. Not mutated.
146
- * @param params.name Product to remove.
147
- * @returns A new, sorted index.
148
- * @throws {InvalidArgumentError} when the arguments are malformed.
149
- */
150
38
  export declare const removeProductFromIndex: ({ index, name }: {
151
39
  index: ProductsIndex;
152
40
  name: string;
153
41
  }) => ProductsIndex;
154
- /**
155
- * Reads the index of a line working directory.
156
- *
157
- * A line with no `products.json` is a line with no products, not an error: the
158
- * file only appears once the first product is created, and every line predating
159
- * ADR-011 lacks it. A file that EXISTS but is corrupt is a different story and
160
- * does throw — silently treating it as empty would let linea-server commit a
161
- * fresh index over a real one and lose the product list.
162
- *
163
- * @param params.lineDir Root of the line working directory.
164
- * @returns The index, or an empty one when the file is absent.
165
- * @throws {ProductsIndexError} when the file exists but is malformed.
166
- */
167
42
  export declare const readProductsIndex: ({ lineDir }: {
168
43
  lineDir: string;
169
44
  }) => ProductsIndex;
170
- /**
171
- * Writes the index of a line working directory, creating it if needed.
172
- *
173
- * @param params.lineDir Root of the line working directory.
174
- * @param params.index The index to write.
175
- * @returns The absolute path written.
176
- * @throws {InvalidArgumentError} when the arguments are malformed.
177
- */
178
45
  export declare const writeProductsIndex: ({ lineDir, index }: {
179
46
  lineDir: string;
180
47
  index: ProductsIndex;
181
48
  }) => {
182
49
  path: string;
183
50
  };
184
- /** Outcome of reconciling an index against the repositories actually observed. */
185
51
  export interface ProductsIndexReconciliation {
186
- /** The index with the newly discovered repositories added. */
187
52
  readonly index: ProductsIndex;
188
- /**
189
- * Entries added because a repository existed but was not indexed. They carry
190
- * a `version` only if the caller observed one.
191
- */
192
53
  readonly added: ProductsIndexEntry[];
193
- /**
194
- * Entries indexed but with no observed repository.
195
- *
196
- * REPORTED ONLY — they stay in `index`. The monolith's `prune` archived such
197
- * rows in Mongo; without a database, dropping them here would silently destroy
198
- * the record of a product whose repository the caller merely could not see
199
- * (a permissions hiccup, a partial listing). linea-server decides.
200
- */
201
54
  readonly removed: ProductsIndexEntry[];
202
55
  }
203
- /**
204
- * Reconciles an index against the repositories a caller actually observed.
205
- *
206
- * Adapted from the `reconcile*` pair of the monolith, which discovers GitLab
207
- * projects by topic and creates the rows that are missing.
208
- *
209
- * Versions already recorded in the index are preserved verbatim, exactly like
210
- * `repositorio`: the observation the caller makes is "this repository exists",
211
- * not "this is the product's version", so it never overwrites what is indexed.
212
- * A newly added entry keeps the `version` the caller supplied, if any.
213
- *
214
- * @param params.index Current index. Not mutated.
215
- * @param params.repositories Repositories observed, as `{ name, repositorio }`
216
- * plus an optional `version`. linea-server builds this from GitLab; linea-core
217
- * never looks.
218
- * @returns The reconciled index plus what was added and what is missing.
219
- * @throws {InvalidArgumentError} when the arguments are malformed.
220
- */
221
56
  export declare const reconcileProductsIndex: ({ index, repositories }: {
222
57
  index: ProductsIndex;
223
58
  repositories: readonly ProductsIndexEntry[];