@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
@@ -0,0 +1,316 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { PLATFORM_PATHS } from '../../constants.js';
4
+ import { ensureDir } from '../../fs/workspace.js';
5
+ import { isPlainObject } from '../../internal/guards.js';
6
+ import { DEFAULT_PLATFORM_CONFIG } from '../../line/scaffold.js';
7
+ import { buildExtraJs, buildTransformationJs } from '../../line/platform-files.js';
8
+ import { readPackageText } from '../packages/source.js';
9
+ import { rootFeatureName } from '../configuration/names.js';
10
+ import { spliceCip } from 'spl-js-engine';
11
+ import { CIP_DEFAULT_END, CIP_DEFAULT_START, cipFragmentPath, cipKind, cipTarget } from './cip.js';
12
+ import { featureNamesOfSections, featuresOfConstraint, graftModules, parseUvlSections } from './feature-model.js';
13
+ const CODE_DIR = 'src/platform/code';
14
+ const MODULE_CODE_DIR = 'code';
15
+ // what every module is asked for, one by one, when it is added: named up front so a source that fetches can do it side by side
16
+ const MODULE_FILES = ['.linea/model.uvl', '.linea/config/config.json', ...['extra', 'transformation'].flatMap((name) => [`.linea/config/${name}.js`, `.linea/config/${name}.cipmain.js`, `.linea/config/${name}.cip.js`])];
17
+ // reads that are all needed, made this many at a time
18
+ const READ_CONCURRENCY = 8;
19
+ const readAll = async (items, read) => {
20
+ const results = new Array(items.length);
21
+ let next = 0;
22
+ const worker = async () => {
23
+ for (let index = next++; index < items.length; index = next++)
24
+ results[index] = await read(items[index]);
25
+ };
26
+ await Promise.all(Array.from({ length: Math.min(READ_CONCURRENCY, items.length) }, worker));
27
+ return results;
28
+ };
29
+ const sameBytes = (a, b) => a.length === b.length && a.every((byte, index) => byte === b[index]);
30
+ const delimiterKey = (delimiter) => [...delimiter.extension].sort().join(',');
31
+ const parseConfig = (content, where, file, diagnostics) => {
32
+ try {
33
+ const raw = JSON.parse(content);
34
+ if (!isPlainObject(raw))
35
+ throw new Error('it is not an object');
36
+ return {
37
+ ...(Array.isArray(raw.ignore) ? { ignore: raw.ignore.filter((value) => typeof value === 'string') } : {}),
38
+ ...(Array.isArray(raw.delimiters) ? { delimiters: raw.delimiters } : {})
39
+ };
40
+ }
41
+ catch (error) {
42
+ diagnostics.push({ severity: 'error', package: where, file, message: `${file} is not valid: ${error.message}` });
43
+ return {};
44
+ }
45
+ };
46
+ const copyConfig = () => ({
47
+ ignore: [...DEFAULT_PLATFORM_CONFIG.ignore],
48
+ delimiters: DEFAULT_PLATFORM_CONFIG.delimiters.map((delimiter) => ({ ...delimiter, extension: [...delimiter.extension] }))
49
+ });
50
+ /**
51
+ * Composes the platform of an SPL: the feature models of its modules grafted under its root, their code laid over each other, their
52
+ * helper functions and transformations chained after the core ones. What the SPL has of its own (`src/platform/...`) comes last, so it wins.
53
+ * Problems (a file two modules both provide, a feature name used twice...) are returned, not thrown.
54
+ */
55
+ export const planPlatform = async ({ resolved, spl, ownFeatureModel, loadCode = true }) => {
56
+ const diagnostics = [];
57
+ const config = copyConfig();
58
+ const delimiterOwner = new Map(config.delimiters.map((delimiter) => [delimiterKey(delimiter), 'linea']));
59
+ const extra = [buildExtraJs()];
60
+ const transformation = [buildTransformationJs()];
61
+ const files = new Map();
62
+ const sections = [];
63
+ const featureOwner = new Map();
64
+ const constraintsOf = [];
65
+ const mergeConfig = (partial, owner, override) => {
66
+ for (const ignored of partial.ignore ?? [])
67
+ if (!config.ignore.includes(ignored))
68
+ config.ignore.push(ignored);
69
+ for (const delimiter of partial.delimiters ?? []) {
70
+ const key = delimiterKey(delimiter);
71
+ const index = config.delimiters.findIndex((existing) => delimiterKey(existing) === key);
72
+ if (index < 0) {
73
+ config.delimiters.push(delimiter);
74
+ delimiterOwner.set(key, owner);
75
+ continue;
76
+ }
77
+ const existing = config.delimiters[index];
78
+ if (existing.start === delimiter.start && existing.end === delimiter.end)
79
+ continue;
80
+ if (override) {
81
+ config.delimiters[index] = delimiter;
82
+ delimiterOwner.set(key, owner);
83
+ }
84
+ else {
85
+ diagnostics.push({
86
+ severity: 'error',
87
+ package: owner,
88
+ file: '.linea/config/config.json',
89
+ message: `The delimiters for ${key} (${delimiter.start} ... ${delimiter.end}) clash with those of ${delimiterOwner.get(key) ?? 'linea'} (${existing.start} ... ${existing.end}).`
90
+ });
91
+ }
92
+ }
93
+ };
94
+ // code insertion points: the main files and the fragments are not code of the product, they are spliced into one file when all packages are in
95
+ const cipMains = new Map();
96
+ const cipFragments = new Map();
97
+ const decoder = new TextDecoder();
98
+ const addFragment = (key, content, from) => {
99
+ const list = cipFragments.get(key);
100
+ if (list === undefined)
101
+ cipFragments.set(key, [{ content, from }]);
102
+ else
103
+ list.push({ content, from });
104
+ };
105
+ const applyCode = ({ file, dir, destination, owner, override }, content) => {
106
+ const kind = cipKind({ file: destination });
107
+ if (kind === 'main') {
108
+ const existingMain = cipMains.get(destination);
109
+ if (existingMain !== undefined && !override && !sameBytes(existingMain.content, content)) {
110
+ diagnostics.push({
111
+ severity: 'error',
112
+ package: owner,
113
+ file: `${dir}/${file.slice(dir.length + 1)}`,
114
+ message: `${destination.slice(CODE_DIR.length + 1)} is also provided by ${existingMain.from}, with other content.`
115
+ });
116
+ return;
117
+ }
118
+ cipMains.set(destination, { content, from: owner });
119
+ return;
120
+ }
121
+ if (kind === 'fragment') {
122
+ addFragment(destination, decoder.decode(content), owner);
123
+ return;
124
+ }
125
+ const existing = files.get(destination);
126
+ if (existing !== undefined && !override && !sameBytes(existing.content, content)) {
127
+ diagnostics.push({
128
+ severity: 'error',
129
+ package: owner,
130
+ file: `${dir}/${file.slice(dir.length + 1)}`,
131
+ message: `${destination.slice(CODE_DIR.length + 1)} is also provided by ${existing.from}, with other content.`
132
+ });
133
+ return;
134
+ }
135
+ files.set(destination, { content, from: owner });
136
+ };
137
+ // without `loadCode` the files are only listed here, in the order they would have been read, and settled once everything is listed
138
+ const deferred = [];
139
+ const addCode = async (files_, dir, target, owner, override) => {
140
+ const listed = await files_.list({ dir });
141
+ if (loadCode)
142
+ files_.prefetch?.(listed);
143
+ for (const file of listed) {
144
+ const entry = { files: files_, file, dir, destination: `${target}/${file.slice(dir.length + 1)}`, owner, override };
145
+ if (!loadCode) {
146
+ deferred.push(entry);
147
+ continue;
148
+ }
149
+ const content = await files_.read({ path: file });
150
+ if (content === undefined)
151
+ continue;
152
+ applyCode(entry, content);
153
+ }
154
+ };
155
+ const settleCode = async () => {
156
+ const providers = new Map();
157
+ for (const { destination } of deferred)
158
+ providers.set(destination, (providers.get(destination) ?? 0) + 1);
159
+ // a plain file that one package alone provides cannot clash with anything: its bytes are not needed to know that
160
+ const alone = (entry) => cipKind({ file: entry.destination }) === undefined && providers.get(entry.destination) === 1;
161
+ const needed = deferred.filter((entry) => !alone(entry));
162
+ // what is needed is read side by side, and applied in the order it was listed: the report does not depend on which read came first
163
+ const contents = new Map();
164
+ const bytes = await readAll(needed, (entry) => entry.files.read({ path: entry.file }));
165
+ needed.forEach((entry, index) => contents.set(entry, bytes[index]));
166
+ for (const entry of deferred) {
167
+ if (alone(entry)) {
168
+ files.set(entry.destination, { content: new Uint8Array(0), from: entry.owner });
169
+ continue;
170
+ }
171
+ const content = contents.get(entry);
172
+ if (content === undefined)
173
+ continue;
174
+ applyCode(entry, content);
175
+ }
176
+ deferred.length = 0;
177
+ };
178
+ const readSections = async (files_, filePath, owner) => {
179
+ const content = await readPackageText({ files: files_, path: filePath });
180
+ if (content === undefined)
181
+ return undefined;
182
+ return sectionsOf(content, filePath, owner);
183
+ };
184
+ const sectionsOf = (content, filePath, owner) => {
185
+ const parsed = parseUvlSections({ content });
186
+ constraintsOf.push({ owner, file: filePath, sections: parsed });
187
+ for (const name of featureNamesOfSections({ features: parsed.features })) {
188
+ const other = featureOwner.get(name);
189
+ if (other !== undefined && other !== owner) {
190
+ diagnostics.push({ severity: 'error', package: owner, file: filePath, message: `The feature "${name}" is also declared by ${other}.` });
191
+ }
192
+ else
193
+ featureOwner.set(name, owner);
194
+ }
195
+ return parsed;
196
+ };
197
+ // `extra.js` and `transformation.js` of a module can be a code insertion point too (`extra.cipmain.js` filled by `extra.cip.js` of others)
198
+ const rootJs = { extra: [], transformation: [] };
199
+ const rootFragments = { extra: [], transformation: [] };
200
+ const addModule = async (module) => {
201
+ const owner = module.location;
202
+ const model = await readSections(module.files, '.linea/model.uvl', owner);
203
+ if (model !== undefined)
204
+ sections.push(model);
205
+ const moduleConfig = await readPackageText({ files: module.files, path: '.linea/config/config.json' });
206
+ if (moduleConfig !== undefined)
207
+ mergeConfig(parseConfig(moduleConfig, owner, '.linea/config/config.json', diagnostics), owner, false);
208
+ for (const name of ['extra', 'transformation']) {
209
+ const plain = await readPackageText({ files: module.files, path: `.linea/config/${name}.js` });
210
+ const main = plain === undefined ? await readPackageText({ files: module.files, path: `.linea/config/${name}.cipmain.js` }) : undefined;
211
+ const fragment = await readPackageText({ files: module.files, path: `.linea/config/${name}.cip.js` });
212
+ if (plain !== undefined)
213
+ rootJs[name].push({ text: plain, main: false });
214
+ else if (main !== undefined)
215
+ rootJs[name].push({ text: main, main: true });
216
+ if (fragment !== undefined)
217
+ rootFragments[name].push(fragment);
218
+ }
219
+ await addCode(module.files, MODULE_CODE_DIR, CODE_DIR, owner, false);
220
+ };
221
+ for (const module of resolved.modules)
222
+ module.files.prefetch?.(MODULE_FILES);
223
+ for (const module of resolved.modules)
224
+ await addModule(module);
225
+ const cipDelimiter = config.delimiters.find((delimiter) => delimiter.extension.includes('cip'));
226
+ const cipDelimiters = { start: cipDelimiter?.start ?? CIP_DEFAULT_START, end: cipDelimiter?.end ?? CIP_DEFAULT_END };
227
+ for (const name of ['extra', 'transformation']) {
228
+ const target = name === 'extra' ? extra : transformation;
229
+ for (const { text, main } of rootJs[name]) {
230
+ target.push(main ? spliceCip({ main: text, fragments: rootFragments[name], ...cipDelimiters }) : text);
231
+ }
232
+ }
233
+ const own = ownFeatureModel === undefined ? undefined : sectionsOf(ownFeatureModel, 'models/featuremodel', 'spl');
234
+ if (spl !== undefined) {
235
+ const ownConfig = await readPackageText({ files: spl, path: PLATFORM_PATHS.config });
236
+ if (ownConfig !== undefined)
237
+ mergeConfig(parseConfig(ownConfig, 'spl', PLATFORM_PATHS.config, diagnostics), 'spl', true);
238
+ const ownExtra = await readPackageText({ files: spl, path: PLATFORM_PATHS.extraJs });
239
+ if (ownExtra !== undefined)
240
+ extra.push(ownExtra);
241
+ const ownTransformation = await readPackageText({ files: spl, path: PLATFORM_PATHS.transformation });
242
+ if (ownTransformation !== undefined)
243
+ transformation.push(ownTransformation);
244
+ await addCode(spl, PLATFORM_PATHS.code, CODE_DIR, 'spl', true);
245
+ }
246
+ await settleCode();
247
+ const encoder = new TextEncoder();
248
+ for (const [main, { content, from }] of cipMains) {
249
+ const key = cipFragmentPath({ main });
250
+ const spliced = spliceCip({
251
+ main: decoder.decode(content),
252
+ fragments: (cipFragments.get(key) ?? []).map((fragment) => fragment.content),
253
+ ...cipDelimiters
254
+ });
255
+ // an empty result is no file, as for any other template
256
+ if (spliced.trim() === '')
257
+ continue;
258
+ const destination = cipTarget({ file: main });
259
+ const existing = files.get(destination);
260
+ if (existing !== undefined) {
261
+ diagnostics.push({
262
+ severity: 'error',
263
+ package: from,
264
+ file: destination.slice(CODE_DIR.length + 1),
265
+ message: `${destination.slice(CODE_DIR.length + 1)} is made from a code insertion point, and also provided by ${existing.from}.`
266
+ });
267
+ continue;
268
+ }
269
+ files.set(destination, { content: encoder.encode(spliced), from });
270
+ }
271
+ // a constraint can tie features of different packages together, but every feature it names has to be declared by one of them
272
+ for (const { owner, file, sections: declared } of constraintsOf) {
273
+ for (const { text } of declared.constraints) {
274
+ for (const name of featuresOfConstraint({ text })) {
275
+ if (!featureOwner.has(name)) {
276
+ diagnostics.push({ severity: 'error', package: owner, file, message: `The constraint "${text}" names the feature "${name}", which no module or the SPL declares.` });
277
+ }
278
+ }
279
+ }
280
+ }
281
+ const root = own ?? { preamble: [], features: [{ level: 1, text: rootFeatureName({ name: resolved.spl.name }) }], constraints: [] };
282
+ let featureModel;
283
+ try {
284
+ featureModel = graftModules({ spl: root, modules: sections });
285
+ }
286
+ catch (error) {
287
+ diagnostics.push({ severity: 'error', package: 'spl', file: PLATFORM_PATHS.model, message: error.message });
288
+ featureModel = '';
289
+ }
290
+ return {
291
+ featureModel,
292
+ config,
293
+ extraJs: extra.join('\n\n'),
294
+ transformation: transformation.join('\n\n'),
295
+ files,
296
+ diagnostics
297
+ };
298
+ };
299
+ /** Writes a platform plan under `lineDir` as an ordinary line (`src/platform/...`), so the usual derivation runs on it. */
300
+ export const writePlatform = ({ plan, lineDir }) => {
301
+ const root = ensureDir({ dirPath: lineDir });
302
+ const write = (relative, content) => {
303
+ const target = path.join(root, relative);
304
+ fs.mkdirSync(path.dirname(target), { recursive: true });
305
+ fs.writeFileSync(target, content);
306
+ };
307
+ write(PLATFORM_PATHS.model, plan.featureModel);
308
+ write(PLATFORM_PATHS.config, JSON.stringify(plan.config, null, 2) + '\n');
309
+ write(PLATFORM_PATHS.extraJs, plan.extraJs + '\n');
310
+ write(PLATFORM_PATHS.transformation, plan.transformation + '\n');
311
+ fs.mkdirSync(path.join(root, PLATFORM_PATHS.code), { recursive: true });
312
+ for (const [relative, { content }] of plan.files)
313
+ write(relative, content);
314
+ return { lineDir: root };
315
+ };
316
+ //# sourceMappingURL=platform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform.js","sourceRoot":"","sources":["../../../src/modules/spl/platform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAA;AAChE,OAAO,EAAE,YAAY,EAAE,qBAAqB,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OAAO,EAAE,CAAC,IAAI,IAAI,CAAC,KAAK;QAAE,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IAC1E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;AAC1B,CAAC,CAAA","sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\nimport { PLATFORM_PATHS } from '../../constants.js'\nimport { ensureDir } from '../../fs/workspace.js'\nimport { isPlainObject } from '../../internal/guards.js'\nimport { DEFAULT_PLATFORM_CONFIG } from '../../line/scaffold.js'\nimport { buildExtraJs, buildTransformationJs } from '../../line/platform-files.js'\nimport { readPackageText } from '../packages/source.js'\nimport { rootFeatureName } from '../configuration/names.js'\nimport { spliceCip } from 'spl-js-engine'\nimport { CIP_DEFAULT_END, CIP_DEFAULT_START, cipFragmentPath, cipKind, cipTarget } from './cip.js'\nimport { featureNamesOfSections, featuresOfConstraint, graftModules, parseUvlSections, type UvlSections } from './feature-model.js'\nimport type { Diagnostic, PackageFiles, ResolvedModule, ResolvedSpl } from '../types.js'\n\nconst CODE_DIR = 'src/platform/code'\nconst MODULE_CODE_DIR = 'code'\n// what every module is asked for, one by one, when it is added: named up front so a source that fetches can do it side by side\nconst MODULE_FILES = ['.linea/model.uvl', '.linea/config/config.json', ...['extra', 'transformation'].flatMap((name) => [`.linea/config/${name}.js`, `.linea/config/${name}.cipmain.js`, `.linea/config/${name}.cip.js`])]\n// reads that are all needed, made this many at a time\nconst READ_CONCURRENCY = 8\n\nconst readAll = async <T>(items: readonly T[], read: (item: T) => Promise<Uint8Array | undefined>): Promise<(Uint8Array | undefined)[]> => {\n const results = new Array<Uint8Array | undefined>(items.length)\n let next = 0\n const worker = async (): Promise<void> => {\n for (let index = next++; index < items.length; index = next++) results[index] = await read(items[index] as T)\n }\n await Promise.all(Array.from({ length: Math.min(READ_CONCURRENCY, items.length) }, worker))\n return results\n}\n\ninterface Delimiter {\n extension: string[]\n start: string\n end: string\n}\n\ninterface PlatformConfig {\n ignore: string[]\n delimiters: Delimiter[]\n}\n\n/** Everything a derivation needs, composed from the modules of an SPL, before it is written anywhere. */\nexport interface PlatformPlan {\n /** Merged UVL feature model. */\n readonly featureModel: string\n readonly config: PlatformConfig\n readonly extraJs: string\n readonly transformation: string\n /** Code files, as paths relative to the line directory (`src/platform/code/...`). */\n readonly files: ReadonlyMap<string, { readonly content: Uint8Array, readonly from: string }>\n readonly diagnostics: readonly Diagnostic[]\n}\n\nconst sameBytes = (a: Uint8Array, b: Uint8Array): boolean =>\n a.length === b.length && a.every((byte, index) => byte === b[index])\n\nconst delimiterKey = (delimiter: Delimiter): string => [...delimiter.extension].sort().join(',')\n\nconst parseConfig = (content: string, where: string, file: string, diagnostics: Diagnostic[]): Partial<PlatformConfig> => {\n try {\n const raw: unknown = JSON.parse(content)\n if (!isPlainObject(raw)) throw new Error('it is not an object')\n return {\n ...(Array.isArray(raw.ignore) ? { ignore: raw.ignore.filter((value): value is string => typeof value === 'string') } : {}),\n ...(Array.isArray(raw.delimiters) ? { delimiters: raw.delimiters as Delimiter[] } : {})\n }\n } catch (error) {\n diagnostics.push({ severity: 'error', package: where, file, message: `${file} is not valid: ${(error as Error).message}` })\n return {}\n }\n}\n\nconst copyConfig = (): PlatformConfig => ({\n ignore: [...DEFAULT_PLATFORM_CONFIG.ignore],\n delimiters: DEFAULT_PLATFORM_CONFIG.delimiters.map((delimiter) => ({ ...delimiter, extension: [...delimiter.extension] }))\n})\n\n/**\n * Composes the platform of an SPL: the feature models of its modules grafted under its root, their code laid over each other, their\n * helper functions and transformations chained after the core ones. What the SPL has of its own (`src/platform/...`) comes last, so it wins.\n * Problems (a file two modules both provide, a feature name used twice...) are returned, not thrown.\n */\nexport const planPlatform = async ({\n resolved,\n spl,\n ownFeatureModel,\n loadCode = true\n}: {\n resolved: ResolvedSpl\n spl?: PackageFiles\n /** The SPL's own feature model, as UVL (its model of the feature metamodel): the modules' are grafted under its root. Without it, the root alone. */\n ownFeatureModel?: string\n /**\n * `false` for a check, where the code is not written anywhere: the code of a package is only listed, and a file is read when its bytes\n * decide something (a file that two packages both provide, and the files of a code insertion point). The diagnostics are the same;\n * `files` then holds those files with no content (`from` says who provides each). A derivation needs `true`, the default.\n */\n loadCode?: boolean\n}): Promise<PlatformPlan> => {\n const diagnostics: Diagnostic[] = []\n const config = copyConfig()\n const delimiterOwner = new Map<string, string>(config.delimiters.map((delimiter) => [delimiterKey(delimiter), 'linea']))\n const extra: string[] = [buildExtraJs()]\n const transformation: string[] = [buildTransformationJs()]\n const files = new Map<string, { content: Uint8Array, from: string }>()\n const sections: UvlSections[] = []\n const featureOwner = new Map<string, string>()\n const constraintsOf: { owner: string, file: string, sections: UvlSections }[] = []\n\n const mergeConfig = (partial: Partial<PlatformConfig>, owner: string, override: boolean): void => {\n for (const ignored of partial.ignore ?? []) if (!config.ignore.includes(ignored)) config.ignore.push(ignored)\n for (const delimiter of partial.delimiters ?? []) {\n const key = delimiterKey(delimiter)\n const index = config.delimiters.findIndex((existing) => delimiterKey(existing) === key)\n if (index < 0) {\n config.delimiters.push(delimiter)\n delimiterOwner.set(key, owner)\n continue\n }\n const existing = config.delimiters[index]!\n if (existing.start === delimiter.start && existing.end === delimiter.end) continue\n if (override) {\n config.delimiters[index] = delimiter\n delimiterOwner.set(key, owner)\n } else {\n diagnostics.push({\n severity: 'error',\n package: owner,\n file: '.linea/config/config.json',\n message: `The delimiters for ${key} (${delimiter.start} ... ${delimiter.end}) clash with those of ${delimiterOwner.get(key) ?? 'linea'} (${existing.start} ... ${existing.end}).`\n })\n }\n }\n }\n\n // code insertion points: the main files and the fragments are not code of the product, they are spliced into one file when all packages are in\n const cipMains = new Map<string, { content: Uint8Array, from: string }>()\n const cipFragments = new Map<string, { content: string, from: string }[]>()\n const decoder = new TextDecoder()\n const addFragment = (key: string, content: string, from: string): void => {\n const list = cipFragments.get(key)\n if (list === undefined) cipFragments.set(key, [{ content, from }])\n else list.push({ content, from })\n }\n\n interface CodeEntry {\n files: PackageFiles\n file: string\n dir: string\n destination: string\n owner: string\n override: boolean\n }\n\n const applyCode = ({ file, dir, destination, owner, override }: CodeEntry, content: Uint8Array): void => {\n const kind = cipKind({ file: destination })\n if (kind === 'main') {\n const existingMain = cipMains.get(destination)\n if (existingMain !== undefined && !override && !sameBytes(existingMain.content, content)) {\n diagnostics.push({\n severity: 'error',\n package: owner,\n file: `${dir}/${file.slice(dir.length + 1)}`,\n message: `${destination.slice(CODE_DIR.length + 1)} is also provided by ${existingMain.from}, with other content.`\n })\n return\n }\n cipMains.set(destination, { content, from: owner })\n return\n }\n if (kind === 'fragment') {\n addFragment(destination, decoder.decode(content), owner)\n return\n }\n const existing = files.get(destination)\n if (existing !== undefined && !override && !sameBytes(existing.content, content)) {\n diagnostics.push({\n severity: 'error',\n package: owner,\n file: `${dir}/${file.slice(dir.length + 1)}`,\n message: `${destination.slice(CODE_DIR.length + 1)} is also provided by ${existing.from}, with other content.`\n })\n return\n }\n files.set(destination, { content, from: owner })\n }\n\n // without `loadCode` the files are only listed here, in the order they would have been read, and settled once everything is listed\n const deferred: CodeEntry[] = []\n\n const addCode = async (files_: PackageFiles, dir: string, target: string, owner: string, override: boolean): Promise<void> => {\n const listed = await files_.list({ dir })\n if (loadCode) files_.prefetch?.(listed)\n for (const file of listed) {\n const entry: CodeEntry = { files: files_, file, dir, destination: `${target}/${file.slice(dir.length + 1)}`, owner, override }\n if (!loadCode) {\n deferred.push(entry)\n continue\n }\n const content = await files_.read({ path: file })\n if (content === undefined) continue\n applyCode(entry, content)\n }\n }\n\n const settleCode = async (): Promise<void> => {\n const providers = new Map<string, number>()\n for (const { destination } of deferred) providers.set(destination, (providers.get(destination) ?? 0) + 1)\n // a plain file that one package alone provides cannot clash with anything: its bytes are not needed to know that\n const alone = (entry: CodeEntry): boolean => cipKind({ file: entry.destination }) === undefined && providers.get(entry.destination) === 1\n const needed = deferred.filter((entry) => !alone(entry))\n // what is needed is read side by side, and applied in the order it was listed: the report does not depend on which read came first\n const contents = new Map<CodeEntry, Uint8Array | undefined>()\n const bytes = await readAll(needed, (entry) => entry.files.read({ path: entry.file }))\n needed.forEach((entry, index) => contents.set(entry, bytes[index]))\n for (const entry of deferred) {\n if (alone(entry)) {\n files.set(entry.destination, { content: new Uint8Array(0), from: entry.owner })\n continue\n }\n const content = contents.get(entry)\n if (content === undefined) continue\n applyCode(entry, content)\n }\n deferred.length = 0\n }\n\n const readSections = async (files_: PackageFiles, filePath: string, owner: string): Promise<UvlSections | undefined> => {\n const content = await readPackageText({ files: files_, path: filePath })\n if (content === undefined) return undefined\n return sectionsOf(content, filePath, owner)\n }\n\n const sectionsOf = (content: string, filePath: string, owner: string): UvlSections => {\n const parsed = parseUvlSections({ content })\n constraintsOf.push({ owner, file: filePath, sections: parsed })\n for (const name of featureNamesOfSections({ features: parsed.features })) {\n const other = featureOwner.get(name)\n if (other !== undefined && other !== owner) {\n diagnostics.push({ severity: 'error', package: owner, file: filePath, message: `The feature \"${name}\" is also declared by ${other}.` })\n } else featureOwner.set(name, owner)\n }\n return parsed\n }\n\n // `extra.js` and `transformation.js` of a module can be a code insertion point too (`extra.cipmain.js` filled by `extra.cip.js` of others)\n const rootJs = { extra: [] as { text: string, main: boolean }[], transformation: [] as { text: string, main: boolean }[] }\n const rootFragments = { extra: [] as string[], transformation: [] as string[] }\n\n const addModule = async (module: ResolvedModule): Promise<void> => {\n const owner = module.location\n const model = await readSections(module.files, '.linea/model.uvl', owner)\n if (model !== undefined) sections.push(model)\n const moduleConfig = await readPackageText({ files: module.files, path: '.linea/config/config.json' })\n if (moduleConfig !== undefined) mergeConfig(parseConfig(moduleConfig, owner, '.linea/config/config.json', diagnostics), owner, false)\n for (const name of ['extra', 'transformation'] as const) {\n const plain = await readPackageText({ files: module.files, path: `.linea/config/${name}.js` })\n const main = plain === undefined ? await readPackageText({ files: module.files, path: `.linea/config/${name}.cipmain.js` }) : undefined\n const fragment = await readPackageText({ files: module.files, path: `.linea/config/${name}.cip.js` })\n if (plain !== undefined) rootJs[name].push({ text: plain, main: false })\n else if (main !== undefined) rootJs[name].push({ text: main, main: true })\n if (fragment !== undefined) rootFragments[name].push(fragment)\n }\n await addCode(module.files, MODULE_CODE_DIR, CODE_DIR, owner, false)\n }\n for (const module of resolved.modules) module.files.prefetch?.(MODULE_FILES)\n for (const module of resolved.modules) await addModule(module)\n const cipDelimiter = config.delimiters.find((delimiter) => delimiter.extension.includes('cip'))\n const cipDelimiters = { start: cipDelimiter?.start ?? CIP_DEFAULT_START, end: cipDelimiter?.end ?? CIP_DEFAULT_END }\n for (const name of ['extra', 'transformation'] as const) {\n const target = name === 'extra' ? extra : transformation\n for (const { text, main } of rootJs[name]) {\n target.push(main ? spliceCip({ main: text, fragments: rootFragments[name], ...cipDelimiters }) : text)\n }\n }\n\n const own: UvlSections | undefined = ownFeatureModel === undefined ? undefined : sectionsOf(ownFeatureModel, 'models/featuremodel', 'spl')\n if (spl !== undefined) {\n const ownConfig = await readPackageText({ files: spl, path: PLATFORM_PATHS.config })\n if (ownConfig !== undefined) mergeConfig(parseConfig(ownConfig, 'spl', PLATFORM_PATHS.config, diagnostics), 'spl', true)\n const ownExtra = await readPackageText({ files: spl, path: PLATFORM_PATHS.extraJs })\n if (ownExtra !== undefined) extra.push(ownExtra)\n const ownTransformation = await readPackageText({ files: spl, path: PLATFORM_PATHS.transformation })\n if (ownTransformation !== undefined) transformation.push(ownTransformation)\n await addCode(spl, PLATFORM_PATHS.code, CODE_DIR, 'spl', true)\n }\n await settleCode()\n\n const encoder = new TextEncoder()\n for (const [main, { content, from }] of cipMains) {\n const key = cipFragmentPath({ main })\n const spliced = spliceCip({\n main: decoder.decode(content),\n fragments: (cipFragments.get(key) ?? []).map((fragment) => fragment.content),\n ...cipDelimiters\n })\n // an empty result is no file, as for any other template\n if (spliced.trim() === '') continue\n const destination = cipTarget({ file: main })\n const existing = files.get(destination)\n if (existing !== undefined) {\n diagnostics.push({\n severity: 'error',\n package: from,\n file: destination.slice(CODE_DIR.length + 1),\n message: `${destination.slice(CODE_DIR.length + 1)} is made from a code insertion point, and also provided by ${existing.from}.`\n })\n continue\n }\n files.set(destination, { content: encoder.encode(spliced), from })\n }\n\n // a constraint can tie features of different packages together, but every feature it names has to be declared by one of them\n for (const { owner, file, sections: declared } of constraintsOf) {\n for (const { text } of declared.constraints) {\n for (const name of featuresOfConstraint({ text })) {\n if (!featureOwner.has(name)) {\n diagnostics.push({ severity: 'error', package: owner, file, message: `The constraint \"${text}\" names the feature \"${name}\", which no module or the SPL declares.` })\n }\n }\n }\n }\n\n const root = own ?? { preamble: [], features: [{ level: 1, text: rootFeatureName({ name: resolved.spl.name }) }], constraints: [] }\n let featureModel: string\n try {\n featureModel = graftModules({ spl: root, modules: sections })\n } catch (error) {\n diagnostics.push({ severity: 'error', package: 'spl', file: PLATFORM_PATHS.model, message: (error as Error).message })\n featureModel = ''\n }\n\n return {\n featureModel,\n config,\n extraJs: extra.join('\\n\\n'),\n transformation: transformation.join('\\n\\n'),\n files,\n diagnostics\n }\n}\n\n/** Writes a platform plan under `lineDir` as an ordinary line (`src/platform/...`), so the usual derivation runs on it. */\nexport const writePlatform = ({ plan, lineDir }: { plan: PlatformPlan, lineDir: string }): { lineDir: string } => {\n const root = ensureDir({ dirPath: lineDir })\n const write = (relative: string, content: string | Uint8Array): void => {\n const target = path.join(root, relative)\n fs.mkdirSync(path.dirname(target), { recursive: true })\n fs.writeFileSync(target, content)\n }\n write(PLATFORM_PATHS.model, plan.featureModel)\n write(PLATFORM_PATHS.config, JSON.stringify(plan.config, null, 2) + '\\n')\n write(PLATFORM_PATHS.extraJs, plan.extraJs + '\\n')\n write(PLATFORM_PATHS.transformation, plan.transformation + '\\n')\n fs.mkdirSync(path.join(root, PLATFORM_PATHS.code), { recursive: true })\n for (const [relative, { content }] of plan.files) write(relative, content)\n return { lineDir: root }\n}\n"]}
@@ -0,0 +1,132 @@
1
+ /** What a package (a module or a metamodel) is, in the registry. */
2
+ export type PackageKind = 'module' | 'metamodel';
3
+ /** The files of one version of one package. Paths are relative to the package root and use `/`. */
4
+ export interface PackageFiles {
5
+ /** The bytes of a file, or `undefined` when there is none. */
6
+ read: (args: {
7
+ path: string;
8
+ }) => Promise<Uint8Array | undefined>;
9
+ /** Every file under `dir` (`''` is the whole package), recursively, as paths relative to the package root. */
10
+ list: (args: {
11
+ dir: string;
12
+ }) => Promise<string[]>;
13
+ /**
14
+ * Optional: these files are about to be read, all of them. A source that has to fetch them can do it ahead and side by side instead of
15
+ * one at a time as they are asked for. Not calling it only makes reading slower; nothing depends on it.
16
+ */
17
+ prefetch?: (paths: string[]) => void;
18
+ }
19
+ /**
20
+ * Where packages come from. linea-core never fetches anything itself: a source is given to it (the filesystem, memory, GitLab...).
21
+ * A `location` is an opaque id such as `gitlab://host/group/project` or `file:modules/core`.
22
+ */
23
+ export interface PackageSource {
24
+ /** The published versions of a package, as plain `x.y.z` (a git tag `v1.2.3` is `1.2.3`). */
25
+ listVersions: (args: {
26
+ location: string;
27
+ }) => Promise<string[]>;
28
+ open: (args: {
29
+ location: string;
30
+ version: string;
31
+ }) => Promise<PackageFiles>;
32
+ /** An immutable id of that version (a commit sha), kept in the lockfile when there is one. */
33
+ revision?: (args: {
34
+ location: string;
35
+ version: string;
36
+ }) => Promise<string | undefined>;
37
+ }
38
+ /** `metamodel.json` */
39
+ export interface MetamodelManifest {
40
+ readonly name: string;
41
+ readonly version: string;
42
+ readonly description?: string;
43
+ /** Packages that provide the grammars this one imports: location -> semver range. */
44
+ readonly requires: Readonly<Record<string, string>>;
45
+ }
46
+ /** `module.json` */
47
+ export interface ModuleManifest {
48
+ readonly name: string;
49
+ readonly version: string;
50
+ readonly description?: string;
51
+ readonly requires: {
52
+ readonly modules: Readonly<Record<string, string>>;
53
+ readonly metamodels: Readonly<Record<string, string>>;
54
+ };
55
+ /** Read-only models this module offers: metamodel (grammar) name -> path of the instance in the module. */
56
+ readonly offers: Readonly<Record<string, string>>;
57
+ }
58
+ /**
59
+ * What an SPL is made of: a `plain` one has the feature metamodel only (its feature model, which the user does not see as a metamodel), a
60
+ * `project` has the metamodels its user chose (the feature metamodel is always among them), and a `modular` one is made of modules, which
61
+ * bring their own metamodels with them.
62
+ */
63
+ export type SplKind = 'plain' | 'project' | 'modular';
64
+ /** `spl.json` */
65
+ export interface SplManifest {
66
+ readonly name: string;
67
+ readonly version?: string;
68
+ readonly kind: SplKind;
69
+ /** The metamodels the SPL uses directly: location -> semver range. They always include the feature metamodel. */
70
+ readonly metamodels: Readonly<Record<string, string>>;
71
+ /** The modules the SPL uses directly: location -> semver range. */
72
+ readonly modules: Readonly<Record<string, string>>;
73
+ }
74
+ export interface LockEntry {
75
+ readonly kind: PackageKind;
76
+ readonly version: string;
77
+ readonly revision?: string;
78
+ }
79
+ /** `linea.lock.json`: every package the SPL needs, transitively, pinned. */
80
+ export interface Lock {
81
+ readonly lockVersion: 1;
82
+ readonly packages: Readonly<Record<string, LockEntry>>;
83
+ }
84
+ export interface ResolvedModule {
85
+ readonly kind: 'module';
86
+ readonly location: string;
87
+ readonly version: string;
88
+ readonly revision?: string;
89
+ readonly manifest: ModuleManifest;
90
+ readonly files: PackageFiles;
91
+ /** Who asked for it: `spl` or `<location>@<version>`. */
92
+ readonly requiredBy: readonly string[];
93
+ }
94
+ export interface ResolvedMetamodel {
95
+ readonly kind: 'metamodel';
96
+ readonly location: string;
97
+ readonly version: string;
98
+ readonly revision?: string;
99
+ readonly manifest: MetamodelManifest;
100
+ readonly files: PackageFiles;
101
+ readonly requiredBy: readonly string[];
102
+ }
103
+ /** The closure of an SPL's modules. Both lists have dependencies before dependants. */
104
+ export interface ResolvedSpl {
105
+ readonly spl: SplManifest;
106
+ readonly modules: readonly ResolvedModule[];
107
+ readonly metamodels: readonly ResolvedMetamodel[];
108
+ readonly lock: Lock;
109
+ }
110
+ export interface Diagnostic {
111
+ readonly severity: 'error' | 'warning';
112
+ /** A package location, `spl`, or `product`. */
113
+ readonly package: string;
114
+ readonly file?: string;
115
+ readonly message: string;
116
+ }
117
+ /** One registered package: the catalog says it exists; the package itself says what it is (`.linea/module.json`, `metamodel.json`). */
118
+ export interface RegistryEntry {
119
+ readonly kind: PackageKind;
120
+ /** `gitlab:group/x`, `github:owner/repo`, `file:...` */
121
+ readonly location: string;
122
+ readonly name: string;
123
+ readonly description?: string;
124
+ /** ISO date */
125
+ readonly addedAt: string;
126
+ readonly addedBy?: string;
127
+ }
128
+ /** `registry.json`: location -> entry. */
129
+ export interface RegistryIndex {
130
+ readonly registryVersion: 1;
131
+ readonly packages: Readonly<Record<string, Omit<RegistryEntry, 'location'>>>;
132
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/modules/types.ts"],"names":[],"mappings":"","sourcesContent":["/** What a package (a module or a metamodel) is, in the registry. */\nexport type PackageKind = 'module' | 'metamodel'\n\n/** The files of one version of one package. Paths are relative to the package root and use `/`. */\nexport interface PackageFiles {\n /** The bytes of a file, or `undefined` when there is none. */\n read: (args: { path: string }) => Promise<Uint8Array | undefined>\n /** Every file under `dir` (`''` is the whole package), recursively, as paths relative to the package root. */\n list: (args: { dir: string }) => Promise<string[]>\n /**\n * Optional: these files are about to be read, all of them. A source that has to fetch them can do it ahead and side by side instead of\n * one at a time as they are asked for. Not calling it only makes reading slower; nothing depends on it.\n */\n prefetch?: (paths: string[]) => void\n}\n\n/**\n * Where packages come from. linea-core never fetches anything itself: a source is given to it (the filesystem, memory, GitLab...).\n * A `location` is an opaque id such as `gitlab://host/group/project` or `file:modules/core`.\n */\nexport interface PackageSource {\n /** The published versions of a package, as plain `x.y.z` (a git tag `v1.2.3` is `1.2.3`). */\n listVersions: (args: { location: string }) => Promise<string[]>\n open: (args: { location: string, version: string }) => Promise<PackageFiles>\n /** An immutable id of that version (a commit sha), kept in the lockfile when there is one. */\n revision?: (args: { location: string, version: string }) => Promise<string | undefined>\n}\n\n/** `metamodel.json` */\nexport interface MetamodelManifest {\n readonly name: string\n readonly version: string\n readonly description?: string\n /** Packages that provide the grammars this one imports: location -> semver range. */\n readonly requires: Readonly<Record<string, string>>\n}\n\n/** `module.json` */\nexport interface ModuleManifest {\n readonly name: string\n readonly version: string\n readonly description?: string\n readonly requires: {\n readonly modules: Readonly<Record<string, string>>\n readonly metamodels: Readonly<Record<string, string>>\n }\n /** Read-only models this module offers: metamodel (grammar) name -> path of the instance in the module. */\n readonly offers: Readonly<Record<string, string>>\n}\n\n/**\n * What an SPL is made of: a `plain` one has the feature metamodel only (its feature model, which the user does not see as a metamodel), a\n * `project` has the metamodels its user chose (the feature metamodel is always among them), and a `modular` one is made of modules, which\n * bring their own metamodels with them.\n */\nexport type SplKind = 'plain' | 'project' | 'modular'\n\n/** `spl.json` */\nexport interface SplManifest {\n readonly name: string\n readonly version?: string\n readonly kind: SplKind\n /** The metamodels the SPL uses directly: location -> semver range. They always include the feature metamodel. */\n readonly metamodels: Readonly<Record<string, string>>\n /** The modules the SPL uses directly: location -> semver range. */\n readonly modules: Readonly<Record<string, string>>\n}\n\nexport interface LockEntry {\n readonly kind: PackageKind\n readonly version: string\n readonly revision?: string\n}\n\n/** `linea.lock.json`: every package the SPL needs, transitively, pinned. */\nexport interface Lock {\n readonly lockVersion: 1\n readonly packages: Readonly<Record<string, LockEntry>>\n}\n\nexport interface ResolvedModule {\n readonly kind: 'module'\n readonly location: string\n readonly version: string\n readonly revision?: string\n readonly manifest: ModuleManifest\n readonly files: PackageFiles\n /** Who asked for it: `spl` or `<location>@<version>`. */\n readonly requiredBy: readonly string[]\n}\n\nexport interface ResolvedMetamodel {\n readonly kind: 'metamodel'\n readonly location: string\n readonly version: string\n readonly revision?: string\n readonly manifest: MetamodelManifest\n readonly files: PackageFiles\n readonly requiredBy: readonly string[]\n}\n\n/** The closure of an SPL's modules. Both lists have dependencies before dependants. */\nexport interface ResolvedSpl {\n readonly spl: SplManifest\n readonly modules: readonly ResolvedModule[]\n readonly metamodels: readonly ResolvedMetamodel[]\n readonly lock: Lock\n}\n\nexport interface Diagnostic {\n readonly severity: 'error' | 'warning'\n /** A package location, `spl`, or `product`. */\n readonly package: string\n readonly file?: string\n readonly message: string\n}\n\n/** One registered package: the catalog says it exists; the package itself says what it is (`.linea/module.json`, `metamodel.json`). */\nexport interface RegistryEntry {\n readonly kind: PackageKind\n /** `gitlab:group/x`, `github:owner/repo`, `file:...` */\n readonly location: string\n readonly name: string\n readonly description?: string\n /** ISO date */\n readonly addedAt: string\n readonly addedBy?: string\n}\n\n/** `registry.json`: location -> entry. */\nexport interface RegistryIndex {\n readonly registryVersion: 1\n readonly packages: Readonly<Record<string, Omit<RegistryEntry, 'location'>>>\n}\n"]}
@@ -1,25 +1,9 @@
1
1
  import type { ProductSpec } from './spec.js';
2
- /** A spec in the engine's shortcut shape. */
3
2
  export interface EngineSpec {
4
3
  features: string[];
5
4
  data: Record<string, unknown>;
6
5
  [key: string]: unknown;
7
6
  }
8
- /**
9
- * Builds the spec handed to `DerivationEngine.generateProduct` / `generateZip`.
10
- *
11
- * Returns the input spec **by reference** when there is no sensor shortcut to
12
- * apply, exactly like the monolith — `generatePipeline.test.js:23-35` asserts
13
- * identity with `toBe(spec)`, so that is contractual, not incidental.
14
- *
15
- * The shortcut applies only when `spec.sensor.parsed` has BOTH `features` and
16
- * `data.basicData`. In that case `database` and `version` are carried over from
17
- * the product's own `basicData`, with `database` defaulting to `{}`.
18
- *
19
- * @param params.spec The product spec.
20
- * @returns Either the same spec, or a new object in the engine shortcut shape.
21
- * @throws {InvalidArgumentError} when `spec` is not an object.
22
- */
23
7
  export declare const buildEngineSpec: ({ spec }: {
24
8
  spec: ProductSpec;
25
9
  }) => ProductSpec | EngineSpec;
@@ -1,54 +1,7 @@
1
- /**
2
- * Adapts a product spec to the shape `spl-js-engine` expects.
3
- *
4
- * HARDENED PORT of
5
- * `linea/server/src/model/services/generatePipeline.js:buildEngineSpec` (~34-50).
6
- * The original guards the shortcut with plain truthiness
7
- * (`parsed?.features && parsed?.data?.basicData`), so a spec with
8
- * `sensor.parsed.features = 'ABC'` takes the shortcut and hands the engine a
9
- * string where it expects an array. Here the checks are `Array.isArray` and
10
- * `isPlainObject`, so such a spec passes through untouched instead.
11
- * Its comment explains the intent: when a product carries a parsed sensor DSL,
12
- * pipe it straight to the engine's shortcut path, which activates when both
13
- * `input.data` and `input.data.basicData` are present (see the mock platform's
14
- * `transformation.js:modelTransformation`). Otherwise the spec passes through.
15
- *
16
- * The sensor DSL itself is out of scope for linea-core in this batch; this
17
- * function only routes an ALREADY parsed `sensor.parsed` payload, which is why it
18
- * needs no DSL dependency.
19
- */
20
1
  import { InvalidArgumentError } from '../errors.js';
21
2
  import { isPlainObject } from '../internal/guards.js';
22
- /**
23
- * Reproduces the monolith's `spec.basicData?.database || {}`.
24
- *
25
- * `??` would NOT be equivalent: `||` also replaces falsy non-nullish values
26
- * (`''`, `0`, `0n`, `false`, `NaN`). The schema types `database` as an Object so
27
- * the difference is unreachable in practice, but parity is parity and a silent
28
- * behaviour change here would be invisible until a generation produced the wrong
29
- * config. Written as a ternary on the value itself, which IS `||` by definition
30
- * and therefore cannot drift from it.
31
- */
32
- // NOTE: `??` is precisely the WRONG operator here. The monolith uses `||`, so
33
- // falsy non-nullish values must fall back too; that is the entire point of this
34
- // helper, and the lint rule cannot know it.
35
3
  // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
36
4
  const truthyOr = (value, fallback) => (value ? value : fallback);
37
- /**
38
- * Builds the spec handed to `DerivationEngine.generateProduct` / `generateZip`.
39
- *
40
- * Returns the input spec **by reference** when there is no sensor shortcut to
41
- * apply, exactly like the monolith — `generatePipeline.test.js:23-35` asserts
42
- * identity with `toBe(spec)`, so that is contractual, not incidental.
43
- *
44
- * The shortcut applies only when `spec.sensor.parsed` has BOTH `features` and
45
- * `data.basicData`. In that case `database` and `version` are carried over from
46
- * the product's own `basicData`, with `database` defaulting to `{}`.
47
- *
48
- * @param params.spec The product spec.
49
- * @returns Either the same spec, or a new object in the engine shortcut shape.
50
- * @throws {InvalidArgumentError} when `spec` is not an object.
51
- */
52
5
  export const buildEngineSpec = ({ spec }) => {
53
6
  if (!isPlainObject(spec)) {
54
7
  throw new InvalidArgumentError('"spec" must be an object.');
@@ -67,11 +20,12 @@ export const buildEngineSpec = ({ spec }) => {
67
20
  basicData: {
68
21
  ...parsedData.basicData,
69
22
  database: truthyOr(specBasicData?.database, {}),
70
- // No default: the monolith passes `spec.basicData?.version` straight
71
- // through, so an absent version stays `undefined`.
72
23
  version: specBasicData?.version
73
24
  }
74
- }
25
+ },
26
+ // what the modules of a modular SPL read (`input.models`); absent for a plain line
27
+ ...(spec.models === undefined ? {} : { models: spec.models }),
28
+ ...(spec.modelsByMetamodel === undefined ? {} : { modelsByMetamodel: spec.modelsByMetamodel })
75
29
  };
76
30
  };
77
31
  //# sourceMappingURL=engine-spec.js.map