@lbdudc/linea-core 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (249) hide show
  1. package/README.md +132 -260
  2. package/dist/analysis/analyze.d.ts +0 -54
  3. package/dist/analysis/analyze.js +1 -70
  4. package/dist/analysis/analyze.js.map +1 -1
  5. package/dist/analysis/runtime.d.ts +4 -73
  6. package/dist/analysis/runtime.js +7 -100
  7. package/dist/analysis/runtime.js.map +1 -1
  8. package/dist/analysis/uvl-text.d.ts +8 -0
  9. package/dist/analysis/uvl-text.js +70 -0
  10. package/dist/analysis/uvl-text.js.map +1 -0
  11. package/dist/assets.d.ts +0 -12
  12. package/dist/assets.js +0 -25
  13. package/dist/assets.js.map +1 -1
  14. package/dist/ci/annotations.d.ts +6 -0
  15. package/dist/ci/annotations.js +12 -0
  16. package/dist/ci/annotations.js.map +1 -0
  17. package/dist/ci/leftovers.d.ts +25 -0
  18. package/dist/ci/leftovers.js +50 -0
  19. package/dist/ci/leftovers.js.map +1 -0
  20. package/dist/ci/pairwise.d.ts +11 -0
  21. package/dist/ci/pairwise.js +35 -0
  22. package/dist/ci/pairwise.js.map +1 -0
  23. package/dist/ci/pipeline.d.ts +18 -0
  24. package/dist/ci/pipeline.js +26 -0
  25. package/dist/ci/pipeline.js.map +1 -0
  26. package/dist/ci/select.d.ts +28 -0
  27. package/dist/ci/select.js +43 -0
  28. package/dist/ci/select.js.map +1 -0
  29. package/dist/ci/validate-specs.d.ts +52 -0
  30. package/dist/ci/validate-specs.js +212 -0
  31. package/dist/ci/validate-specs.js.map +1 -0
  32. package/dist/constants.d.ts +1 -60
  33. package/dist/constants.js +1 -58
  34. package/dist/constants.js.map +1 -1
  35. package/dist/derivation/derive.d.ts +0 -56
  36. package/dist/derivation/derive.js +21 -72
  37. package/dist/derivation/derive.js.map +1 -1
  38. package/dist/derivation/engine.d.ts +10 -42
  39. package/dist/derivation/engine.js +37 -68
  40. package/dist/derivation/engine.js.map +1 -1
  41. package/dist/derivation/selection-error.d.ts +7 -0
  42. package/dist/derivation/selection-error.js +13 -0
  43. package/dist/derivation/selection-error.js.map +1 -0
  44. package/dist/errors.d.ts +19 -47
  45. package/dist/errors.js +28 -47
  46. package/dist/errors.js.map +1 -1
  47. package/dist/feature-model/uvl.d.ts +52 -0
  48. package/dist/feature-model/uvl.js +191 -0
  49. package/dist/feature-model/uvl.js.map +1 -0
  50. package/dist/fs/archive.d.ts +0 -16
  51. package/dist/fs/archive.js +0 -36
  52. package/dist/fs/archive.js.map +1 -1
  53. package/dist/fs/diff.d.ts +0 -30
  54. package/dist/fs/diff.js +4 -65
  55. package/dist/fs/diff.js.map +1 -1
  56. package/dist/fs/format.d.ts +0 -16
  57. package/dist/fs/format.js +0 -52
  58. package/dist/fs/format.js.map +1 -1
  59. package/dist/fs/workspace.d.ts +0 -52
  60. package/dist/fs/workspace.js +0 -56
  61. package/dist/fs/workspace.js.map +1 -1
  62. package/dist/index.d.ts +23 -29
  63. package/dist/index.js +15 -35
  64. package/dist/index.js.map +1 -1
  65. package/dist/internal/guards.d.ts +0 -13
  66. package/dist/internal/guards.js +0 -13
  67. package/dist/internal/guards.js.map +1 -1
  68. package/dist/line/deletion.d.ts +33 -0
  69. package/dist/line/deletion.js +23 -0
  70. package/dist/line/deletion.js.map +1 -0
  71. package/dist/line/platform-files.d.ts +15 -64
  72. package/dist/line/platform-files.js +18 -94
  73. package/dist/line/platform-files.js.map +1 -1
  74. package/dist/line/restoration.d.ts +27 -0
  75. package/dist/line/restoration.js +27 -0
  76. package/dist/line/restoration.js.map +1 -0
  77. package/dist/line/scaffold.d.ts +26 -57
  78. package/dist/line/scaffold.js +32 -93
  79. package/dist/line/scaffold.js.map +1 -1
  80. package/dist/line/templates/core/transformation.js +17 -5
  81. package/dist/line/templates/pipeline/github-ci.yml +50 -0
  82. package/dist/line/templates/pipeline/spl-gitlab-ci.yml +182 -0
  83. package/dist/modules/configuration/configure.d.ts +52 -0
  84. package/dist/modules/configuration/configure.js +101 -0
  85. package/dist/modules/configuration/configure.js.map +1 -0
  86. package/dist/modules/configuration/constants.d.ts +17 -0
  87. package/dist/modules/configuration/constants.js +14 -0
  88. package/dist/modules/configuration/constants.js.map +1 -0
  89. package/dist/modules/configuration/index.d.ts +6 -0
  90. package/dist/modules/configuration/index.js +5 -0
  91. package/dist/modules/configuration/index.js.map +1 -0
  92. package/dist/modules/configuration/names.d.ts +9 -0
  93. package/dist/modules/configuration/names.js +7 -0
  94. package/dist/modules/configuration/names.js.map +1 -0
  95. package/dist/modules/configuration/selection.d.ts +32 -0
  96. package/dist/modules/configuration/selection.js +49 -0
  97. package/dist/modules/configuration/selection.js.map +1 -0
  98. package/dist/modules/diagnostics.d.ts +2 -0
  99. package/dist/modules/diagnostics.js +2 -0
  100. package/dist/modules/diagnostics.js.map +1 -0
  101. package/dist/modules/index.d.ts +18 -0
  102. package/dist/modules/index.js +18 -0
  103. package/dist/modules/index.js.map +1 -0
  104. package/dist/modules/metamodels/engine.d.ts +93 -0
  105. package/dist/modules/metamodels/engine.js +10 -0
  106. package/dist/modules/metamodels/engine.js.map +1 -0
  107. package/dist/modules/metamodels/files.d.ts +40 -0
  108. package/dist/modules/metamodels/files.js +58 -0
  109. package/dist/modules/metamodels/files.js.map +1 -0
  110. package/dist/modules/metamodels/index.d.ts +8 -0
  111. package/dist/modules/metamodels/index.js +5 -0
  112. package/dist/modules/metamodels/index.js.map +1 -0
  113. package/dist/modules/metamodels/layout.d.ts +23 -0
  114. package/dist/modules/metamodels/layout.js +29 -0
  115. package/dist/modules/metamodels/layout.js.map +1 -0
  116. package/dist/modules/metamodels/offered.d.ts +15 -0
  117. package/dist/modules/metamodels/offered.js +14 -0
  118. package/dist/modules/metamodels/offered.js.map +1 -0
  119. package/dist/modules/metamodels/prepare.d.ts +20 -0
  120. package/dist/modules/metamodels/prepare.js +155 -0
  121. package/dist/modules/metamodels/prepare.js.map +1 -0
  122. package/dist/modules/packages/index.d.ts +4 -0
  123. package/dist/modules/packages/index.js +4 -0
  124. package/dist/modules/packages/index.js.map +1 -0
  125. package/dist/modules/packages/location.d.ts +21 -0
  126. package/dist/modules/packages/location.js +34 -0
  127. package/dist/modules/packages/location.js.map +1 -0
  128. package/dist/modules/packages/manifests.d.ts +33 -0
  129. package/dist/modules/packages/manifests.js +231 -0
  130. package/dist/modules/packages/manifests.js.map +1 -0
  131. package/dist/modules/packages/source.d.ts +34 -0
  132. package/dist/modules/packages/source.js +128 -0
  133. package/dist/modules/packages/source.js.map +1 -0
  134. package/dist/modules/products/check.d.ts +28 -0
  135. package/dist/modules/products/check.js +61 -0
  136. package/dist/modules/products/check.js.map +1 -0
  137. package/dist/modules/products/derive.d.ts +30 -0
  138. package/dist/modules/products/derive.js +56 -0
  139. package/dist/modules/products/derive.js.map +1 -0
  140. package/dist/modules/products/index.d.ts +5 -0
  141. package/dist/modules/products/index.js +4 -0
  142. package/dist/modules/products/index.js.map +1 -0
  143. package/dist/modules/products/seed.d.ts +18 -0
  144. package/dist/modules/products/seed.js +23 -0
  145. package/dist/modules/products/seed.js.map +1 -0
  146. package/dist/modules/registry/catalog.d.ts +64 -0
  147. package/dist/modules/registry/catalog.js +91 -0
  148. package/dist/modules/registry/catalog.js.map +1 -0
  149. package/dist/modules/registry/index.d.ts +5 -0
  150. package/dist/modules/registry/index.js +4 -0
  151. package/dist/modules/registry/index.js.map +1 -0
  152. package/dist/modules/registry/registry.d.ts +34 -0
  153. package/dist/modules/registry/registry.js +37 -0
  154. package/dist/modules/registry/registry.js.map +1 -0
  155. package/dist/modules/registry/routing.d.ts +8 -0
  156. package/dist/modules/registry/routing.js +23 -0
  157. package/dist/modules/registry/routing.js.map +1 -0
  158. package/dist/modules/resolution/closure.d.ts +28 -0
  159. package/dist/modules/resolution/closure.js +105 -0
  160. package/dist/modules/resolution/closure.js.map +1 -0
  161. package/dist/modules/resolution/index.d.ts +4 -0
  162. package/dist/modules/resolution/index.js +3 -0
  163. package/dist/modules/resolution/index.js.map +1 -0
  164. package/dist/modules/resolution/resolve.d.ts +33 -0
  165. package/dist/modules/resolution/resolve.js +59 -0
  166. package/dist/modules/resolution/resolve.js.map +1 -0
  167. package/dist/modules/resolution/resolvers.d.ts +23 -0
  168. package/dist/modules/resolution/resolvers.js +34 -0
  169. package/dist/modules/resolution/resolvers.js.map +1 -0
  170. package/dist/modules/spl/check.d.ts +25 -0
  171. package/dist/modules/spl/check.js +21 -0
  172. package/dist/modules/spl/check.js.map +1 -0
  173. package/dist/modules/spl/cip.d.ts +67 -0
  174. package/dist/modules/spl/cip.js +98 -0
  175. package/dist/modules/spl/cip.js.map +1 -0
  176. package/dist/modules/spl/feature-model.d.ts +39 -0
  177. package/dist/modules/spl/feature-model.js +106 -0
  178. package/dist/modules/spl/feature-model.js.map +1 -0
  179. package/dist/modules/spl/index.d.ts +6 -0
  180. package/dist/modules/spl/index.js +4 -0
  181. package/dist/modules/spl/index.js.map +1 -0
  182. package/dist/modules/spl/platform.d.ts +49 -0
  183. package/dist/modules/spl/platform.js +316 -0
  184. package/dist/modules/spl/platform.js.map +1 -0
  185. package/dist/modules/types.d.ts +132 -0
  186. package/dist/modules/types.js +2 -0
  187. package/dist/modules/types.js.map +1 -0
  188. package/dist/product/engine-spec.d.ts +0 -16
  189. package/dist/product/engine-spec.js +4 -50
  190. package/dist/product/engine-spec.js.map +1 -1
  191. package/dist/product/spec.d.ts +0 -82
  192. package/dist/product/spec.js +0 -79
  193. package/dist/product/spec.js.map +1 -1
  194. package/dist/product/version.d.ts +0 -23
  195. package/dist/product/version.js +0 -28
  196. package/dist/product/version.js.map +1 -1
  197. package/dist/products-index/products-index.d.ts +0 -165
  198. package/dist/products-index/products-index.js +0 -176
  199. package/dist/products-index/products-index.js.map +1 -1
  200. package/dist/workspace/context.d.ts +25 -0
  201. package/dist/workspace/context.js +43 -0
  202. package/dist/workspace/context.js.map +1 -0
  203. package/dist/workspace/gitExclude.d.ts +2 -0
  204. package/dist/workspace/gitExclude.js +19 -0
  205. package/dist/workspace/gitExclude.js.map +1 -0
  206. package/dist/workspace/host.d.ts +14 -0
  207. package/dist/workspace/host.js +13 -0
  208. package/dist/workspace/host.js.map +1 -0
  209. package/dist/workspace/index.d.ts +12 -0
  210. package/dist/workspace/index.js +12 -0
  211. package/dist/workspace/index.js.map +1 -0
  212. package/dist/workspace/local.d.ts +81 -0
  213. package/dist/workspace/local.js +287 -0
  214. package/dist/workspace/local.js.map +1 -0
  215. package/dist/workspace/modular.d.ts +95 -0
  216. package/dist/workspace/modular.js +301 -0
  217. package/dist/workspace/modular.js.map +1 -0
  218. package/dist/workspace/operations.d.ts +35 -0
  219. package/dist/workspace/operations.js +57 -0
  220. package/dist/workspace/operations.js.map +1 -0
  221. package/dist/workspace/origin.d.ts +20 -0
  222. package/dist/workspace/origin.js +19 -0
  223. package/dist/workspace/origin.js.map +1 -0
  224. package/package.json +22 -7
  225. package/dist/feature-model/convert.d.ts +0 -35
  226. package/dist/feature-model/convert.js +0 -47
  227. package/dist/feature-model/convert.js.map +0 -1
  228. package/dist/feature-model/engine.d.ts +0 -60
  229. package/dist/feature-model/engine.js +0 -139
  230. package/dist/feature-model/engine.js.map +0 -1
  231. package/dist/feature-model/inspect.d.ts +0 -67
  232. package/dist/feature-model/inspect.js +0 -113
  233. package/dist/feature-model/inspect.js.map +0 -1
  234. package/dist/feature-model/io.d.ts +0 -66
  235. package/dist/feature-model/io.js +0 -92
  236. package/dist/feature-model/io.js.map +0 -1
  237. package/dist/feature-model/parse.d.ts +0 -30
  238. package/dist/feature-model/parse.js +0 -36
  239. package/dist/feature-model/parse.js.map +0 -1
  240. package/dist/feature-model/text.d.ts +0 -54
  241. package/dist/feature-model/text.js +0 -126
  242. package/dist/feature-model/text.js.map +0 -1
  243. package/dist/line/templates/metamodels/dataModel/extra.js +0 -328
  244. package/dist/line/templates/metamodels/dataModel/transformation.js +0 -211
  245. package/dist/line/templates/metamodels/sensor/extra.js +0 -36
  246. package/dist/line/templates/metamodels/sensor/transformation.js +0 -47
  247. package/dist/selection/selection.d.ts +0 -126
  248. package/dist/selection/selection.js +0 -152
  249. package/dist/selection/selection.js.map +0 -1
@@ -1,211 +0,0 @@
1
- registerMetamodelProcessor(function processDataModel(ret, input) {
2
- if (input.data && input.data.dataModel) {
3
- ret.data.dataModel = input.data.dataModel;
4
- } else if (input.dataModel) {
5
- ret.data.dataModel = dataModel(input.dataModel);
6
- } else {
7
- ret.data.dataModel = { entities: [], enums: [] };
8
- }
9
-
10
- if (ret.features.indexOf("GUI_Forms") !== -1) {
11
- ret.data.forms = forms(ret.data.dataModel.entities, ret.features);
12
- } else {
13
- ret.data.forms = [];
14
- }
15
-
16
- if (ret.features.indexOf("GUI_Lists") !== -1) {
17
- ret.data.lists = lists(ret.data.dataModel.entities, ret.features, ret.data.forms);
18
- } else {
19
- ret.data.lists = [];
20
- }
21
- });
22
-
23
- function enums(input) {
24
- return input.map((e) => ({
25
- name: normalize(e.name, true),
26
- values: e.values,
27
- }));
28
- }
29
-
30
- function entities(input) {
31
- return input.map((e) => ({
32
- name: normalize(e.name, true),
33
- properties: properties(e),
34
- displayString: "$" + _getDisplayString(e, input),
35
- superclass: e.superclass && e.superclass.name,
36
- abstract: e.abstract,
37
- traceable: e.traceable,
38
- }));
39
- }
40
-
41
- function properties(entity) {
42
- const ret = [];
43
- entity.properties.forEach((p) => {
44
- if (p.name === "id") {
45
- ret.push({ name: "id", class: "Long (autoinc)", pk: true, required: true, unique: true });
46
- } else {
47
- ret.push({
48
- name: p.name,
49
- class: normalize(p.class, true),
50
- required: p.required,
51
- unique: p.unique,
52
- patternType: p.patternType,
53
- pattern: p.pattern,
54
- min: p.min,
55
- max: p.max,
56
- });
57
- }
58
- });
59
- return ret;
60
- }
61
-
62
- function relationships(ret, input) {
63
- const rels = input.cells.filter((o) => o.type === "custom.Association");
64
-
65
- rels.forEach((r) => {
66
- const source = findEntityByName(normalize(findEntityById(r.source.id, input.cells).name, true), ret);
67
- const target = findEntityByName(normalize(findEntityById(r.target.id, input.cells).name, true), ret);
68
-
69
- source.properties.push({
70
- name: r.sourceOpts.label || normalize(target.name),
71
- class: target.name,
72
- owner: _getRelationshipOwner(r, r.source.id),
73
- bidirectional: r.targetOpts.label || normalize(source.name),
74
- multiple: multiple(r.sourceOpts.multiplicity),
75
- required: required(r.sourceOpts.multiplicity),
76
- });
77
-
78
- target.properties.push({
79
- name: r.targetOpts.label || normalize(source.name),
80
- class: source.name,
81
- owner: _getRelationshipOwner(r, r.target.id),
82
- bidirectional: r.sourceOpts.label || normalize(target.name),
83
- multiple: multiple(r.targetOpts.multiplicity),
84
- required: required(r.targetOpts.multiplicity),
85
- });
86
- });
87
-
88
- return ret;
89
- }
90
-
91
- function dataModel(input) {
92
- const ret = {};
93
- ret.enums = enums(input.cells.filter((o) => o.type === "custom.Enum"));
94
- ret.entities = entities(input.cells.filter((o) => o.type === "custom.Class"));
95
- relationships(ret.entities, input);
96
- return ret;
97
- }
98
-
99
- function forms(entities, features) {
100
- return entities.map((e) => {
101
- const props = _getProperties(e, entities);
102
- return {
103
- id: e.name + " Form",
104
- properties: _sortProperties(props, e),
105
- entity: e.name,
106
- abstract: e.abstract,
107
- creatable: features.indexOf("GUI_F_Creatable") !== -1,
108
- editable: features.indexOf("GUI_F_Editable") !== -1,
109
- removable: features.indexOf("GUI_F_Removable") !== -1,
110
- confirmation: features.indexOf("GUI_F_R_ConfirmationAlert") !== -1,
111
- };
112
- });
113
- }
114
-
115
- function lists(entities, features, forms) {
116
- const formNeeded = features.indexOf("GUI_L_FormLink") !== -1;
117
- return entities
118
- .filter((e) => !e.abstract)
119
- .map((e) => {
120
- const entityForm = _getForm(e.name, forms);
121
- const props = _getProperties(e, entities, forms);
122
- return {
123
- id: e.name + " List",
124
- abstract: e.abstract,
125
- properties: _sortProperties(props, e),
126
- entity: e.name,
127
- form: entityForm && entityForm.id,
128
- removeLink: formNeeded && entityForm && entityForm.removable,
129
- sorting: features.indexOf("GUI_L_Sortable") !== -1,
130
- searching: features.indexOf("GUI_L_F_BasicSearch") !== -1,
131
- filtering: features.indexOf("GUI_L_F_RowFilter") !== -1,
132
- };
133
- });
134
- }
135
-
136
- function _getForm(entityName, forms) {
137
- return forms.find((f) => f.entity === entityName);
138
- }
139
-
140
- function _getProperties(e, entities, forms) {
141
- if (forms === undefined) forms = [];
142
- const props = forms.length ? _getPropertiesLists(e, forms) : _getPropertiesForms(e);
143
- const superclass = e.superclass ? entities.find((entity) => entity.name === e.superclass) : null;
144
- return superclass ? props.concat(_getProperties(superclass, entities, forms)) : props;
145
- }
146
-
147
- function _getPropertiesLists(e, forms) {
148
- return e.properties
149
- .filter((p) => p.owner === undefined || p.owner)
150
- .map((p) => ({
151
- property: p.name,
152
- form: _getForm(e.name, forms) && _getForm(e.name, forms).id,
153
- owner: e.name,
154
- }));
155
- }
156
-
157
- function _getPropertiesForms(e) {
158
- return e.properties
159
- .filter((p) => p.owner === undefined || p.owner)
160
- .map((p) => ({
161
- property: p.name,
162
- viewing: true,
163
- editing: p.name !== "id",
164
- owner: e.name,
165
- }));
166
- }
167
-
168
- function _sortProperties(props, entity) {
169
- const displayString = entity.displayString.replace("$", "");
170
- const idProp = props.find((p) => p.property === "id");
171
- const displayProp = props.find((p) => p.property === displayString);
172
- props = props.filter((p) => p !== idProp && p !== displayProp);
173
- return displayProp !== idProp ? [idProp, displayProp].concat(props) : [idProp].concat(props);
174
- }
175
-
176
- function _getDisplayString(entity, entities) {
177
- const displayString = entity.properties.find((e) => e.displayString);
178
- if (!displayString && entity.superclass) {
179
- return _getDisplayString(entities.find((e) => e.name === entity.superclass.name), entities);
180
- } else if (displayString) {
181
- return displayString.name;
182
- } else {
183
- return "id";
184
- }
185
- }
186
-
187
- function _getRelationshipOwner(rel, entityId) {
188
- const isSource = rel.source.id === entityId;
189
- const relType =
190
- (multiple(rel.targetOpts.multiplicity) ? "Many" : "One") +
191
- "To" +
192
- (multiple(rel.sourceOpts.multiplicity) ? "Many" : "One");
193
- if (relType === "OneToMany") return !isSource;
194
- else return isSource;
195
- }
196
-
197
- function findEntityById(id, col) {
198
- return col.find((o) => o.id === id);
199
- }
200
-
201
- function findEntityByName(name, col) {
202
- return col.find((o) => o.name === name);
203
- }
204
-
205
- function multiple(multiplicity) {
206
- return ["1", "0..1"].find((a) => a === multiplicity) == null;
207
- }
208
-
209
- function required() {
210
- return false;
211
- }
@@ -1,36 +0,0 @@
1
- // Sensor metamodel helper functions
2
- // These are appended to core/extra.js and made available to codegen templates.
3
-
4
- function getSensors(data) {
5
- return (data.dataWarehouse && data.dataWarehouse.sensors) || [];
6
- }
7
-
8
- function getSensor(data, sensorId) {
9
- return getSensors(data).find(function (s) {
10
- return s.id === sensorId;
11
- });
12
- }
13
-
14
- function getSensorMeasurements(sensor) {
15
- return (sensor && sensor.measureData) || [];
16
- }
17
-
18
- function getSensorDimensions(sensor) {
19
- return (sensor && sensor.dimensions) || [];
20
- }
21
-
22
- function getSensorSpatialDimensions(sensor) {
23
- return getSensorDimensions(sensor).filter(function (d) {
24
- return d.type === 'SPATIAL';
25
- });
26
- }
27
-
28
- function getSensorCategoricalDimensions(sensor) {
29
- return getSensorDimensions(sensor).filter(function (d) {
30
- return d.type === 'CATEGORICAL';
31
- });
32
- }
33
-
34
- function getSensorGroups(data) {
35
- return (data.dataWarehouse && data.dataWarehouse.sensorGroups) || [];
36
- }
@@ -1,47 +0,0 @@
1
- // Fallback path: runs when #buildEngineSpec in ProductService did NOT trigger the engine's
2
- // fast-path shortcut (i.e. parsed.data.basicData was absent). For fully-valid sensor products
3
- // the fast-path fires instead and this processor receives input.sensor === undefined.
4
- registerMetamodelProcessor(function processSensor(ret, input) {
5
- const sensor = input.sensor;
6
- if (!sensor || !sensor.parsed) return;
7
-
8
- const parsed = sensor.parsed;
9
-
10
- // The sensor DSL produces its own feature set (SensorViewer, SV_*, etc.).
11
- // Override the FM-selected features so the correct platform capabilities are activated.
12
- if (Array.isArray(parsed.features) && parsed.features.length) {
13
- ret.features = parsed.features;
14
- }
15
-
16
- const data = parsed.data;
17
- if (!data) return;
18
-
19
- // Use the parser's basicData which already has the correct packageInfo key names
20
- // (artifactId / groupId) and the SET DEPLOYMENT extra values.
21
- // Merge database credentials from the product document (user-configured, not in DSL).
22
- if (data.basicData) {
23
- ret.data.basicData = Object.assign({}, data.basicData, {
24
- database: (input.basicData && input.basicData.database) || {}
25
- });
26
- }
27
-
28
- // The sensor DSL parser already outputs a ready-to-use dataModel
29
- // (entities/enums) — pass it through directly, overriding any UML-sourced value.
30
- if (data.dataModel) {
31
- ret.data.dataModel = data.dataModel;
32
- }
33
-
34
- // Sensor-specific data warehouse (sensors, sensorGroups, maps, layers, styles)
35
- if (data.dataWarehouse) {
36
- ret.data.dataWarehouse = data.dataWarehouse;
37
- }
38
-
39
- if (data.mapViewer) {
40
- ret.data.mapViewer = data.mapViewer;
41
- }
42
-
43
- // forms/lists come from the parser (empty for most sensor products, but respect parsed output).
44
- // menus and statics are set by the core transformation AFTER processors run.
45
- ret.data.forms = data.forms || [];
46
- ret.data.lists = data.lists || [];
47
- });
@@ -1,126 +0,0 @@
1
- import { type FeatureModelValue } from '../feature-model/engine.js';
2
- /** The three historical shapes of `spec.features` accepted by the monolith. */
3
- export type FeatureSelectionInput = string[] | Record<string, boolean> | undefined;
4
- /** Minimal view of a product spec needed to read its feature selection. */
5
- export interface SelectionBearingSpec {
6
- features?: FeatureSelectionInput;
7
- /** Deprecated field name, still present in old specs. */
8
- selection?: string[];
9
- [key: string]: unknown;
10
- }
11
- /**
12
- * Normalises a spec's feature selection into a plain string array.
13
- *
14
- * Verbatim behaviour of `utils.js:normalizeFeatureSelection`, covering all three
15
- * historical shapes:
16
- * - `string[]` — canonical form.
17
- * - `{ FeatureName: true | false }` — object map used by early client builds;
18
- * only truthy keys are kept.
19
- * - `spec.selection` — legacy field name, used as a fallback when `features` is
20
- * absent **or an empty array**. That second condition is easy to miss and is
21
- * load-bearing: a spec with `features: []` and a populated `selection` must
22
- * resolve to `selection`.
23
- *
24
- * @param params.spec Product spec (or anything spec-shaped). May be nullish.
25
- * @returns The selected feature names. Always an array, never `undefined`.
26
- */
27
- export declare const normalizeFeatureSelection: ({ spec }: {
28
- spec: SelectionBearingSpec | null | undefined;
29
- }) => string[];
30
- /** Outcome of checking a selection against a feature model. */
31
- export interface FeatureSelectionVerdict {
32
- /** Whether the selection is satisfiable under the model. */
33
- readonly valid: boolean;
34
- /** The expanded selection when valid, `null` otherwise. */
35
- readonly completed: string[] | null;
36
- /** Failure reason when invalid, `null` otherwise. */
37
- readonly error: string | null;
38
- /**
39
- * Engine discriminator when invalid: `'TOO_MANY_CHILDS'`, `'MISSING_CHILD'`,
40
- * or `null` when the engine did not supply one.
41
- */
42
- readonly errorType: string | null;
43
- }
44
- /**
45
- * Checks a feature selection against a model **without throwing**.
46
- *
47
- * Same contract as `ProductService.js:getProductHealth`, which reports
48
- * `{ valid, error, errorType }` so the UI can show why a product no longer fits
49
- * its line. `completed` is the expansion that `completeFeatureSelection` returns,
50
- * exposed so callers do not have to validate twice.
51
- *
52
- * @param params.model A model returned by `parseFeatureModel`.
53
- * @param params.features Selected feature names.
54
- * @returns The verdict. Never throws for an invalid selection.
55
- * @throws {InvalidArgumentError} only when the arguments themselves are wrong.
56
- */
57
- export declare const validateFeatureSelection: ({ model, features }: {
58
- model: FeatureModelValue;
59
- features: string[];
60
- }) => FeatureSelectionVerdict;
61
- /**
62
- * Checks a feature selection and throws when it is invalid.
63
- *
64
- * This is the guard `ProductService.js:#validateSpecFeatures` puts on
65
- * create/update so a bad selection surfaces at the door instead of blowing up
66
- * during generation. The monolith lets the engine's raw `FeatureSelectionError`
67
- * escape (its `onError` maps it to a 400); linea-core wraps it in
68
- * `FeatureSelectionInvalidError` so callers get the `LineaCoreError` taxonomy
69
- * with a stable `.code` (ADR-018) — and, unlike the engine's class, a real
70
- * `Error` with a stack.
71
- *
72
- * Note the monolith's guard is best-effort in a different sense: it *skips*
73
- * validation when the selection is empty or the model cannot be read. That
74
- * skipping is a caller policy (it depends on GitLab availability), so it stays
75
- * in linea-server; here an empty selection is validated like any other.
76
- *
77
- * @param params.model A model returned by `parseFeatureModel`.
78
- * @param params.features Selected feature names.
79
- * @returns The expanded selection.
80
- * @throws {FeatureSelectionInvalidError} when the selection is not satisfiable.
81
- * @throws {InvalidArgumentError} when the arguments themselves are wrong.
82
- */
83
- export declare const assertFeatureSelection: ({ model, features }: {
84
- model: FeatureModelValue;
85
- features: string[];
86
- }) => string[];
87
- /** A named feature selection, e.g. one product's. */
88
- export interface NamedSelection {
89
- /** Identifier reported back in `broken`. */
90
- readonly name: string;
91
- /** Selected feature names. */
92
- readonly features: string[];
93
- }
94
- /** Why a particular named selection no longer fits the model. */
95
- export interface BrokenSelection {
96
- readonly name: string;
97
- readonly reason: string;
98
- }
99
- /** Result of checking a whole portfolio of selections against one model. */
100
- export interface ModelAgainstSelectionsVerdict {
101
- readonly valid: boolean;
102
- readonly broken: BrokenSelection[];
103
- }
104
- /**
105
- * Answers "does this model still admit every one of these selections?".
106
- *
107
- * Migrated from `harvest.js:validateModelAgainstProducts` (~113-133), used to
108
- * decide whether a proposed feature-model edit would break existing products.
109
- *
110
- * DELIBERATE SIGNATURE CHANGE (ADR-014): the monolith takes Mongo product
111
- * documents and digs out `product.spec` and `product.spec.basicData.name`
112
- * itself. linea-core knows nothing about persisted products, so it takes
113
- * `[{ name, features }]`. Whoever reads them — from `products.json` (ADR-011) or
114
- * from GitLab — is linea-server; pair this with `normalizeFeatureSelection` to
115
- * go from a spec to `features`.
116
- *
117
- * @param params.model A model returned by `parseFeatureModel`.
118
- * @param params.selections The named selections to check.
119
- * @returns `valid` plus one entry per broken selection. Never throws for a
120
- * broken selection.
121
- * @throws {InvalidArgumentError} when the arguments themselves are wrong.
122
- */
123
- export declare const validateModelAgainstSelections: ({ model, selections }: {
124
- model: FeatureModelValue;
125
- selections: readonly NamedSelection[];
126
- }) => ModelAgainstSelectionsVerdict;
@@ -1,152 +0,0 @@
1
- /**
2
- * Feature selection normalisation and validation.
3
- *
4
- * Migrated from:
5
- * - `linea/server/src/model/services/utils.js:normalizeFeatureSelection` (~172-186)
6
- * - `linea/server/src/model/services/ProductService.js:#validateSpecFeatures` (~37-58)
7
- * - `linea/server/src/model/services/ProductService.js:getProductHealth` (~481-519),
8
- * which is where the `{ valid, features, error, errorType }` shape comes from
9
- * - `linea/server/src/agents/tools/harvest.js:validateModelAgainstProducts` (~113-133)
10
- *
11
- * The monolith spreads this logic across a service that also reads GitLab and a
12
- * Mongo-backed agent tool. Here it is pure: the caller supplies the parsed model
13
- * and the selections, and nothing reaches the network or a database.
14
- */
15
- import { InvalidArgumentError, FeatureSelectionInvalidError } from '../errors.js';
16
- import { completeSelection, describeSelectionFailure } from '../feature-model/engine.js';
17
- import { isArray } from '../internal/guards.js';
18
- const assertModel = (model) => {
19
- if (model === null || typeof model !== 'object') {
20
- throw new InvalidArgumentError('"model" must be a value returned by parseFeatureModel().');
21
- }
22
- return model;
23
- };
24
- const assertFeatureArray = (features) => {
25
- if (!Array.isArray(features) || features.some((f) => typeof f !== 'string')) {
26
- throw new InvalidArgumentError('"features" must be an array of strings.');
27
- }
28
- return features;
29
- };
30
- /**
31
- * Normalises a spec's feature selection into a plain string array.
32
- *
33
- * Verbatim behaviour of `utils.js:normalizeFeatureSelection`, covering all three
34
- * historical shapes:
35
- * - `string[]` — canonical form.
36
- * - `{ FeatureName: true | false }` — object map used by early client builds;
37
- * only truthy keys are kept.
38
- * - `spec.selection` — legacy field name, used as a fallback when `features` is
39
- * absent **or an empty array**. That second condition is easy to miss and is
40
- * load-bearing: a spec with `features: []` and a populated `selection` must
41
- * resolve to `selection`.
42
- *
43
- * @param params.spec Product spec (or anything spec-shaped). May be nullish.
44
- * @returns The selected feature names. Always an array, never `undefined`.
45
- */
46
- export const normalizeFeatureSelection = ({ spec }) => {
47
- let features = spec?.features;
48
- // Object-map shape: { FeatureName: true/false }
49
- if (features !== null && typeof features === 'object' && !Array.isArray(features)) {
50
- const map = features;
51
- features = Object.keys(map).filter((key) => map[key]);
52
- }
53
- // Fall back to spec.selection when features is absent OR empty.
54
- if (!Array.isArray(features) || features.length === 0) {
55
- features = spec?.selection ?? [];
56
- }
57
- return Array.isArray(features) ? features : [];
58
- };
59
- /**
60
- * Checks a feature selection against a model **without throwing**.
61
- *
62
- * Same contract as `ProductService.js:getProductHealth`, which reports
63
- * `{ valid, error, errorType }` so the UI can show why a product no longer fits
64
- * its line. `completed` is the expansion that `completeFeatureSelection` returns,
65
- * exposed so callers do not have to validate twice.
66
- *
67
- * @param params.model A model returned by `parseFeatureModel`.
68
- * @param params.features Selected feature names.
69
- * @returns The verdict. Never throws for an invalid selection.
70
- * @throws {InvalidArgumentError} only when the arguments themselves are wrong.
71
- */
72
- export const validateFeatureSelection = ({ model, features }) => {
73
- const checked = assertModel(model);
74
- const selection = assertFeatureArray(features);
75
- try {
76
- const completed = completeSelection(checked, selection);
77
- return { valid: true, completed, error: null, errorType: null };
78
- }
79
- catch (error) {
80
- const { message, errorType } = describeSelectionFailure(error);
81
- return { valid: false, completed: null, error: message, errorType };
82
- }
83
- };
84
- /**
85
- * Checks a feature selection and throws when it is invalid.
86
- *
87
- * This is the guard `ProductService.js:#validateSpecFeatures` puts on
88
- * create/update so a bad selection surfaces at the door instead of blowing up
89
- * during generation. The monolith lets the engine's raw `FeatureSelectionError`
90
- * escape (its `onError` maps it to a 400); linea-core wraps it in
91
- * `FeatureSelectionInvalidError` so callers get the `LineaCoreError` taxonomy
92
- * with a stable `.code` (ADR-018) — and, unlike the engine's class, a real
93
- * `Error` with a stack.
94
- *
95
- * Note the monolith's guard is best-effort in a different sense: it *skips*
96
- * validation when the selection is empty or the model cannot be read. That
97
- * skipping is a caller policy (it depends on GitLab availability), so it stays
98
- * in linea-server; here an empty selection is validated like any other.
99
- *
100
- * @param params.model A model returned by `parseFeatureModel`.
101
- * @param params.features Selected feature names.
102
- * @returns The expanded selection.
103
- * @throws {FeatureSelectionInvalidError} when the selection is not satisfiable.
104
- * @throws {InvalidArgumentError} when the arguments themselves are wrong.
105
- */
106
- export const assertFeatureSelection = ({ model, features }) => {
107
- const verdict = validateFeatureSelection({ model, features });
108
- if (!verdict.valid || verdict.completed === null) {
109
- throw new FeatureSelectionInvalidError(verdict.error ?? 'The feature selection is not valid for this feature model.');
110
- }
111
- return verdict.completed;
112
- };
113
- /**
114
- * Answers "does this model still admit every one of these selections?".
115
- *
116
- * Migrated from `harvest.js:validateModelAgainstProducts` (~113-133), used to
117
- * decide whether a proposed feature-model edit would break existing products.
118
- *
119
- * DELIBERATE SIGNATURE CHANGE (ADR-014): the monolith takes Mongo product
120
- * documents and digs out `product.spec` and `product.spec.basicData.name`
121
- * itself. linea-core knows nothing about persisted products, so it takes
122
- * `[{ name, features }]`. Whoever reads them — from `products.json` (ADR-011) or
123
- * from GitLab — is linea-server; pair this with `normalizeFeatureSelection` to
124
- * go from a spec to `features`.
125
- *
126
- * @param params.model A model returned by `parseFeatureModel`.
127
- * @param params.selections The named selections to check.
128
- * @returns `valid` plus one entry per broken selection. Never throws for a
129
- * broken selection.
130
- * @throws {InvalidArgumentError} when the arguments themselves are wrong.
131
- */
132
- export const validateModelAgainstSelections = ({ model, selections }) => {
133
- const checked = assertModel(model);
134
- if (!isArray(selections)) {
135
- throw new InvalidArgumentError('"selections" must be an array of { name, features }.');
136
- }
137
- const broken = [];
138
- for (const selection of selections) {
139
- if (selection === null || typeof selection !== 'object') {
140
- throw new InvalidArgumentError('Every entry of "selections" must be an object.');
141
- }
142
- if (typeof selection.name !== 'string' || selection.name === '') {
143
- throw new InvalidArgumentError('Every entry of "selections" needs a non-empty "name".');
144
- }
145
- const verdict = validateFeatureSelection({ model: checked, features: selection.features });
146
- if (!verdict.valid) {
147
- broken.push({ name: selection.name, reason: verdict.error ?? 'unknown reason' });
148
- }
149
- }
150
- return { valid: broken.length === 0, broken };
151
- };
152
- //# sourceMappingURL=selection.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"selection.js","sourceRoot":"","sources":["../../src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,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;AAC/C,CAAC,CAAA","sourcesContent":["/**\n * Feature selection normalisation and validation.\n *\n * Migrated from:\n * - `linea/server/src/model/services/utils.js:normalizeFeatureSelection` (~172-186)\n * - `linea/server/src/model/services/ProductService.js:#validateSpecFeatures` (~37-58)\n * - `linea/server/src/model/services/ProductService.js:getProductHealth` (~481-519),\n * which is where the `{ valid, features, error, errorType }` shape comes from\n * - `linea/server/src/agents/tools/harvest.js:validateModelAgainstProducts` (~113-133)\n *\n * The monolith spreads this logic across a service that also reads GitLab and a\n * Mongo-backed agent tool. Here it is pure: the caller supplies the parsed model\n * and the selections, and nothing reaches the network or a database.\n */\nimport { InvalidArgumentError, FeatureSelectionInvalidError } from '../errors.js'\nimport {\n completeSelection,\n describeSelectionFailure,\n type FeatureModelValue\n} from '../feature-model/engine.js'\nimport { isArray } from '../internal/guards.js'\n\n/** The three historical shapes of `spec.features` accepted by the monolith. */\nexport type FeatureSelectionInput = string[] | Record<string, boolean> | undefined\n\n/** Minimal view of a product spec needed to read its feature selection. */\nexport interface SelectionBearingSpec {\n features?: FeatureSelectionInput\n /** Deprecated field name, still present in old specs. */\n selection?: string[]\n [key: string]: unknown\n}\n\nconst assertModel = (model: unknown): FeatureModelValue => {\n if (model === null || typeof model !== 'object') {\n throw new InvalidArgumentError('\"model\" must be a value returned by parseFeatureModel().')\n }\n return model as FeatureModelValue\n}\n\nconst assertFeatureArray = (features: unknown): string[] => {\n if (!Array.isArray(features) || features.some((f) => typeof f !== 'string')) {\n throw new InvalidArgumentError('\"features\" must be an array of strings.')\n }\n return features as string[]\n}\n\n/**\n * Normalises a spec's feature selection into a plain string array.\n *\n * Verbatim behaviour of `utils.js:normalizeFeatureSelection`, covering all three\n * historical shapes:\n * - `string[]` — canonical form.\n * - `{ FeatureName: true | false }` — object map used by early client builds;\n * only truthy keys are kept.\n * - `spec.selection` — legacy field name, used as a fallback when `features` is\n * absent **or an empty array**. That second condition is easy to miss and is\n * load-bearing: a spec with `features: []` and a populated `selection` must\n * resolve to `selection`.\n *\n * @param params.spec Product spec (or anything spec-shaped). May be nullish.\n * @returns The selected feature names. Always an array, never `undefined`.\n */\nexport const normalizeFeatureSelection = ({\n spec\n}: {\n spec: SelectionBearingSpec | null | undefined\n}): string[] => {\n let features: unknown = spec?.features\n\n // Object-map shape: { FeatureName: true/false }\n if (features !== null && typeof features === 'object' && !Array.isArray(features)) {\n const map = features as Record<string, boolean>\n features = Object.keys(map).filter((key) => map[key])\n }\n\n // Fall back to spec.selection when features is absent OR empty.\n if (!Array.isArray(features) || features.length === 0) {\n features = spec?.selection ?? []\n }\n\n return Array.isArray(features) ? (features as string[]) : []\n}\n\n/** Outcome of checking a selection against a feature model. */\nexport interface FeatureSelectionVerdict {\n /** Whether the selection is satisfiable under the model. */\n readonly valid: boolean\n /** The expanded selection when valid, `null` otherwise. */\n readonly completed: string[] | null\n /** Failure reason when invalid, `null` otherwise. */\n readonly error: string | null\n /**\n * Engine discriminator when invalid: `'TOO_MANY_CHILDS'`, `'MISSING_CHILD'`,\n * or `null` when the engine did not supply one.\n */\n readonly errorType: string | null\n}\n\n/**\n * Checks a feature selection against a model **without throwing**.\n *\n * Same contract as `ProductService.js:getProductHealth`, which reports\n * `{ valid, error, errorType }` so the UI can show why a product no longer fits\n * its line. `completed` is the expansion that `completeFeatureSelection` returns,\n * exposed so callers do not have to validate twice.\n *\n * @param params.model A model returned by `parseFeatureModel`.\n * @param params.features Selected feature names.\n * @returns The verdict. Never throws for an invalid selection.\n * @throws {InvalidArgumentError} only when the arguments themselves are wrong.\n */\nexport const validateFeatureSelection = ({\n model,\n features\n}: {\n model: FeatureModelValue\n features: string[]\n}): FeatureSelectionVerdict => {\n const checked = assertModel(model)\n const selection = assertFeatureArray(features)\n try {\n const completed = completeSelection(checked, selection)\n return { valid: true, completed, error: null, errorType: null }\n } catch (error) {\n const { message, errorType } = describeSelectionFailure(error)\n return { valid: false, completed: null, error: message, errorType }\n }\n}\n\n/**\n * Checks a feature selection and throws when it is invalid.\n *\n * This is the guard `ProductService.js:#validateSpecFeatures` puts on\n * create/update so a bad selection surfaces at the door instead of blowing up\n * during generation. The monolith lets the engine's raw `FeatureSelectionError`\n * escape (its `onError` maps it to a 400); linea-core wraps it in\n * `FeatureSelectionInvalidError` so callers get the `LineaCoreError` taxonomy\n * with a stable `.code` (ADR-018) — and, unlike the engine's class, a real\n * `Error` with a stack.\n *\n * Note the monolith's guard is best-effort in a different sense: it *skips*\n * validation when the selection is empty or the model cannot be read. That\n * skipping is a caller policy (it depends on GitLab availability), so it stays\n * in linea-server; here an empty selection is validated like any other.\n *\n * @param params.model A model returned by `parseFeatureModel`.\n * @param params.features Selected feature names.\n * @returns The expanded selection.\n * @throws {FeatureSelectionInvalidError} when the selection is not satisfiable.\n * @throws {InvalidArgumentError} when the arguments themselves are wrong.\n */\nexport const assertFeatureSelection = ({\n model,\n features\n}: {\n model: FeatureModelValue\n features: string[]\n}): string[] => {\n const verdict = validateFeatureSelection({ model, features })\n if (!verdict.valid || verdict.completed === null) {\n throw new FeatureSelectionInvalidError(\n verdict.error ?? 'The feature selection is not valid for this feature model.'\n )\n }\n return verdict.completed\n}\n\n/** A named feature selection, e.g. one product's. */\nexport interface NamedSelection {\n /** Identifier reported back in `broken`. */\n readonly name: string\n /** Selected feature names. */\n readonly features: string[]\n}\n\n/** Why a particular named selection no longer fits the model. */\nexport interface BrokenSelection {\n readonly name: string\n readonly reason: string\n}\n\n/** Result of checking a whole portfolio of selections against one model. */\nexport interface ModelAgainstSelectionsVerdict {\n readonly valid: boolean\n readonly broken: BrokenSelection[]\n}\n\n/**\n * Answers \"does this model still admit every one of these selections?\".\n *\n * Migrated from `harvest.js:validateModelAgainstProducts` (~113-133), used to\n * decide whether a proposed feature-model edit would break existing products.\n *\n * DELIBERATE SIGNATURE CHANGE (ADR-014): the monolith takes Mongo product\n * documents and digs out `product.spec` and `product.spec.basicData.name`\n * itself. linea-core knows nothing about persisted products, so it takes\n * `[{ name, features }]`. Whoever reads them — from `products.json` (ADR-011) or\n * from GitLab — is linea-server; pair this with `normalizeFeatureSelection` to\n * go from a spec to `features`.\n *\n * @param params.model A model returned by `parseFeatureModel`.\n * @param params.selections The named selections to check.\n * @returns `valid` plus one entry per broken selection. Never throws for a\n * broken selection.\n * @throws {InvalidArgumentError} when the arguments themselves are wrong.\n */\nexport const validateModelAgainstSelections = ({\n model,\n selections\n}: {\n model: FeatureModelValue\n selections: readonly NamedSelection[]\n}): ModelAgainstSelectionsVerdict => {\n const checked = assertModel(model)\n if (!isArray(selections)) {\n throw new InvalidArgumentError('\"selections\" must be an array of { name, features }.')\n }\n\n const broken: BrokenSelection[] = []\n for (const selection of selections) {\n if (selection === null || typeof selection !== 'object') {\n throw new InvalidArgumentError('Every entry of \"selections\" must be an object.')\n }\n if (typeof selection.name !== 'string' || selection.name === '') {\n throw new InvalidArgumentError('Every entry of \"selections\" needs a non-empty \"name\".')\n }\n const verdict = validateFeatureSelection({ model: checked, features: selection.features })\n if (!verdict.valid) {\n broken.push({ name: selection.name, reason: verdict.error ?? 'unknown reason' })\n }\n }\n\n return { valid: broken.length === 0, broken }\n}\n"]}