@lbdudc/linea-core 0.1.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.
- package/README.md +358 -0
- package/dist/analysis/analyze.d.ts +105 -0
- package/dist/analysis/analyze.js +220 -0
- package/dist/analysis/analyze.js.map +1 -0
- package/dist/analysis/runtime.d.ts +97 -0
- package/dist/analysis/runtime.js +198 -0
- package/dist/analysis/runtime.js.map +1 -0
- package/dist/analysis/wheels/micropip-0.6.0-py3-none-any.whl +0 -0
- package/dist/analysis/wheels/packaging-23.2-py3-none-any.whl +0 -0
- package/dist/assets.d.ts +16 -0
- package/dist/assets.js +36 -0
- package/dist/assets.js.map +1 -0
- package/dist/constants.d.ts +77 -0
- package/dist/constants.js +76 -0
- package/dist/constants.js.map +1 -0
- package/dist/derivation/derive.d.ts +68 -0
- package/dist/derivation/derive.js +115 -0
- package/dist/derivation/derive.js.map +1 -0
- package/dist/derivation/engine.d.ts +48 -0
- package/dist/derivation/engine.js +98 -0
- package/dist/derivation/engine.js.map +1 -0
- package/dist/errors.d.ts +72 -0
- package/dist/errors.js +91 -0
- package/dist/errors.js.map +1 -0
- package/dist/feature-model/convert.d.ts +35 -0
- package/dist/feature-model/convert.js +47 -0
- package/dist/feature-model/convert.js.map +1 -0
- package/dist/feature-model/engine.d.ts +60 -0
- package/dist/feature-model/engine.js +139 -0
- package/dist/feature-model/engine.js.map +1 -0
- package/dist/feature-model/inspect.d.ts +67 -0
- package/dist/feature-model/inspect.js +113 -0
- package/dist/feature-model/inspect.js.map +1 -0
- package/dist/feature-model/io.d.ts +66 -0
- package/dist/feature-model/io.js +92 -0
- package/dist/feature-model/io.js.map +1 -0
- package/dist/feature-model/parse.d.ts +30 -0
- package/dist/feature-model/parse.js +36 -0
- package/dist/feature-model/parse.js.map +1 -0
- package/dist/feature-model/text.d.ts +54 -0
- package/dist/feature-model/text.js +126 -0
- package/dist/feature-model/text.js.map +1 -0
- package/dist/fs/archive.d.ts +23 -0
- package/dist/fs/archive.js +87 -0
- package/dist/fs/archive.js.map +1 -0
- package/dist/fs/diff.d.ts +40 -0
- package/dist/fs/diff.js +155 -0
- package/dist/fs/diff.js.map +1 -0
- package/dist/fs/format.d.ts +21 -0
- package/dist/fs/format.js +111 -0
- package/dist/fs/format.js.map +1 -0
- package/dist/fs/workspace.d.ts +77 -0
- package/dist/fs/workspace.js +103 -0
- package/dist/fs/workspace.js.map +1 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +48 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/guards.d.ts +15 -0
- package/dist/internal/guards.js +16 -0
- package/dist/internal/guards.js.map +1 -0
- package/dist/line/platform-files.d.ts +73 -0
- package/dist/line/platform-files.js +112 -0
- package/dist/line/platform-files.js.map +1 -0
- package/dist/line/scaffold.d.ts +88 -0
- package/dist/line/scaffold.js +145 -0
- package/dist/line/scaffold.js.map +1 -0
- package/dist/line/templates/core/extra.js +54 -0
- package/dist/line/templates/core/transformation.js +196 -0
- package/dist/line/templates/metamodels/dataModel/extra.js +328 -0
- package/dist/line/templates/metamodels/dataModel/transformation.js +211 -0
- package/dist/line/templates/metamodels/sensor/extra.js +36 -0
- package/dist/line/templates/metamodels/sensor/transformation.js +47 -0
- package/dist/line/templates/pipeline/.gitlab-ci.yml +51 -0
- package/dist/line/templates/pipeline/ci/test-client.sh +16 -0
- package/dist/line/templates/pipeline/ci/test-server.sh +16 -0
- package/dist/product/engine-spec.d.ts +25 -0
- package/dist/product/engine-spec.js +77 -0
- package/dist/product/engine-spec.js.map +1 -0
- package/dist/product/spec.d.ts +130 -0
- package/dist/product/spec.js +219 -0
- package/dist/product/spec.js.map +1 -0
- package/dist/product/version.d.ts +27 -0
- package/dist/product/version.js +49 -0
- package/dist/product/version.js.map +1 -0
- package/dist/products-index/products-index.d.ts +224 -0
- package/dist/products-index/products-index.js +395 -0
- package/dist/products-index/products-index.js.map +1 -0
- package/dist/selection/selection.d.ts +126 -0
- package/dist/selection/selection.js +152 -0
- package/dist/selection/selection.js.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { ProductSpec } from '../product/spec.js';
|
|
2
|
+
/**
|
|
3
|
+
* Derives a product into a directory.
|
|
4
|
+
*
|
|
5
|
+
* The spec goes through `buildEngineSpec` first, exactly as `runEngine` does, so
|
|
6
|
+
* a product carrying a parsed sensor DSL takes the engine's shortcut path.
|
|
7
|
+
*
|
|
8
|
+
* DELIBERATE DIVERGENCE 1: `runEngine` finishes with
|
|
9
|
+
* `fs.rmSync(lineOutput, { recursive: true, force: true })`, deleting the line
|
|
10
|
+
* directory it just consumed. linea-core deletes NOTHING. Those directories
|
|
11
|
+
* belong to the caller — in the monolith they happen to be throwaway temp dirs,
|
|
12
|
+
* but here `lineDir` may well be a user's working copy. Cleaning up is the
|
|
13
|
+
* caller's decision (ADR-009/ADR-014). A test pins this.
|
|
14
|
+
*
|
|
15
|
+
* DELIBERATE DIVERGENCE 2, and the one that matters most for whoever ports
|
|
16
|
+
* linea-server: `runEngine` writes
|
|
17
|
+
* `(await engine(lineOutput)).generateProduct(...)`. It awaits the CONSTRUCTOR
|
|
18
|
+
* — which does return a promise — but NOT the generation, which returns one
|
|
19
|
+
* too. So in the monolith the surrounding `try/catch` cannot catch anything
|
|
20
|
+
* thrown during generation: the `FeatureSelectionError` its very next line
|
|
21
|
+
* means to turn into a 400 becomes an unhandled rejection instead, and the
|
|
22
|
+
* `rmSync` above runs while generation may still be reading the directory.
|
|
23
|
+
*
|
|
24
|
+
* linea-core awaits (below), which fixes both. The consequence is that the
|
|
25
|
+
* error classification here does NOT merely replicate `runEngine`'s — it is
|
|
26
|
+
* strictly more effective, because in the monolith most of those errors never
|
|
27
|
+
* reach the `catch` at all.
|
|
28
|
+
*
|
|
29
|
+
* @param params.lineDir Line working directory (holding `src/platform/...`).
|
|
30
|
+
* @param params.spec Product spec.
|
|
31
|
+
* @param params.outputDir Directory to generate into. Created if missing.
|
|
32
|
+
* @returns The directory that was generated into.
|
|
33
|
+
* @throws {FeatureSelectionInvalidError} when the spec's feature selection is
|
|
34
|
+
* not valid for the line's feature model.
|
|
35
|
+
* @throws {LinePlatformNotFoundError} when the line has no usable platform, or
|
|
36
|
+
* for any other engine failure — including a template calling a helper that
|
|
37
|
+
* `extra.js` does not define, reported with the
|
|
38
|
+
* `error_messages.missing_function_error` key.
|
|
39
|
+
* @throws {InvalidArgumentError} when the arguments are malformed.
|
|
40
|
+
*/
|
|
41
|
+
export declare const deriveProduct: ({ lineDir, spec, outputDir }: {
|
|
42
|
+
lineDir: string;
|
|
43
|
+
spec: ProductSpec;
|
|
44
|
+
outputDir: string;
|
|
45
|
+
}) => Promise<{
|
|
46
|
+
outputDir: string;
|
|
47
|
+
}>;
|
|
48
|
+
/**
|
|
49
|
+
* Derives a product into a zip archive, without writing the generated tree.
|
|
50
|
+
*
|
|
51
|
+
* Same classification of failures as `deriveProduct`, matching `generateZip`.
|
|
52
|
+
*
|
|
53
|
+
* RETURN TYPE: the engine hands back a JSZip instance
|
|
54
|
+
* (`spl-js-engine/src/output.js:ZipOutput`), which the monolith's controller
|
|
55
|
+
* turns into base64 at the HTTP edge (`ProductController.js:117`). linea-core
|
|
56
|
+
* materialises it into a `Buffer` instead, so the result is a real artifact a
|
|
57
|
+
* caller can write, hash or feed to `extractArchive` without knowing anything
|
|
58
|
+
* about JSZip. linea-server gets its base64 with `buffer.toString('base64')`.
|
|
59
|
+
*
|
|
60
|
+
* @param params.lineDir Line working directory.
|
|
61
|
+
* @param params.spec Product spec.
|
|
62
|
+
* @returns The zip archive bytes.
|
|
63
|
+
* @throws The same errors as `deriveProduct`.
|
|
64
|
+
*/
|
|
65
|
+
export declare const deriveProductToZip: ({ lineDir, spec }: {
|
|
66
|
+
lineDir: string;
|
|
67
|
+
spec: ProductSpec;
|
|
68
|
+
}) => Promise<Buffer>;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { InvalidArgumentError } from '../errors.js';
|
|
2
|
+
import { ensureDir } from '../fs/workspace.js';
|
|
3
|
+
import { buildEngineSpec } from '../product/engine-spec.js';
|
|
4
|
+
import { createEngine, rethrowDerivationError } from './engine.js';
|
|
5
|
+
/**
|
|
6
|
+
* Hands the spec to the engine unchanged, as `runEngine` does.
|
|
7
|
+
*
|
|
8
|
+
* The cast is needed because linea-core's `ProductSpec.features` also admits the
|
|
9
|
+
* legacy object-map form `{ Feature: true }`, while the engine's
|
|
10
|
+
* `completeFeatureSelection` requires a string array.
|
|
11
|
+
*
|
|
12
|
+
* NOT normalised here, on purpose: the monolith passes `buildEngineSpec(spec)`
|
|
13
|
+
* straight through, so an object-map spec fails there too. Normalising silently
|
|
14
|
+
* would be a behaviour change hidden inside derivation. Callers holding a legacy
|
|
15
|
+
* spec should run it through `normalizeFeatureSelection` first.
|
|
16
|
+
*/
|
|
17
|
+
const toEngineSpec = (spec) => buildEngineSpec({ spec });
|
|
18
|
+
const assertLineDir = (lineDir) => {
|
|
19
|
+
if (typeof lineDir !== 'string' || lineDir.trim() === '') {
|
|
20
|
+
throw new InvalidArgumentError('"lineDir" must be a non-empty path.');
|
|
21
|
+
}
|
|
22
|
+
return lineDir;
|
|
23
|
+
};
|
|
24
|
+
const assertSpec = (spec) => {
|
|
25
|
+
if (typeof spec !== 'object' || spec === null || Array.isArray(spec)) {
|
|
26
|
+
throw new InvalidArgumentError('"spec" must be an object.');
|
|
27
|
+
}
|
|
28
|
+
return spec;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Derives a product into a directory.
|
|
32
|
+
*
|
|
33
|
+
* The spec goes through `buildEngineSpec` first, exactly as `runEngine` does, so
|
|
34
|
+
* a product carrying a parsed sensor DSL takes the engine's shortcut path.
|
|
35
|
+
*
|
|
36
|
+
* DELIBERATE DIVERGENCE 1: `runEngine` finishes with
|
|
37
|
+
* `fs.rmSync(lineOutput, { recursive: true, force: true })`, deleting the line
|
|
38
|
+
* directory it just consumed. linea-core deletes NOTHING. Those directories
|
|
39
|
+
* belong to the caller — in the monolith they happen to be throwaway temp dirs,
|
|
40
|
+
* but here `lineDir` may well be a user's working copy. Cleaning up is the
|
|
41
|
+
* caller's decision (ADR-009/ADR-014). A test pins this.
|
|
42
|
+
*
|
|
43
|
+
* DELIBERATE DIVERGENCE 2, and the one that matters most for whoever ports
|
|
44
|
+
* linea-server: `runEngine` writes
|
|
45
|
+
* `(await engine(lineOutput)).generateProduct(...)`. It awaits the CONSTRUCTOR
|
|
46
|
+
* — which does return a promise — but NOT the generation, which returns one
|
|
47
|
+
* too. So in the monolith the surrounding `try/catch` cannot catch anything
|
|
48
|
+
* thrown during generation: the `FeatureSelectionError` its very next line
|
|
49
|
+
* means to turn into a 400 becomes an unhandled rejection instead, and the
|
|
50
|
+
* `rmSync` above runs while generation may still be reading the directory.
|
|
51
|
+
*
|
|
52
|
+
* linea-core awaits (below), which fixes both. The consequence is that the
|
|
53
|
+
* error classification here does NOT merely replicate `runEngine`'s — it is
|
|
54
|
+
* strictly more effective, because in the monolith most of those errors never
|
|
55
|
+
* reach the `catch` at all.
|
|
56
|
+
*
|
|
57
|
+
* @param params.lineDir Line working directory (holding `src/platform/...`).
|
|
58
|
+
* @param params.spec Product spec.
|
|
59
|
+
* @param params.outputDir Directory to generate into. Created if missing.
|
|
60
|
+
* @returns The directory that was generated into.
|
|
61
|
+
* @throws {FeatureSelectionInvalidError} when the spec's feature selection is
|
|
62
|
+
* not valid for the line's feature model.
|
|
63
|
+
* @throws {LinePlatformNotFoundError} when the line has no usable platform, or
|
|
64
|
+
* for any other engine failure — including a template calling a helper that
|
|
65
|
+
* `extra.js` does not define, reported with the
|
|
66
|
+
* `error_messages.missing_function_error` key.
|
|
67
|
+
* @throws {InvalidArgumentError} when the arguments are malformed.
|
|
68
|
+
*/
|
|
69
|
+
export const deriveProduct = async ({ lineDir, spec, outputDir }) => {
|
|
70
|
+
assertLineDir(lineDir);
|
|
71
|
+
const checkedSpec = assertSpec(spec);
|
|
72
|
+
if (typeof outputDir !== 'string' || outputDir.trim() === '') {
|
|
73
|
+
throw new InvalidArgumentError('"outputDir" must be a non-empty path.');
|
|
74
|
+
}
|
|
75
|
+
const target = ensureDir({ dirPath: outputDir });
|
|
76
|
+
try {
|
|
77
|
+
const engine = await createEngine(lineDir);
|
|
78
|
+
await engine.generateProduct(target, toEngineSpec(checkedSpec));
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
rethrowDerivationError(error);
|
|
82
|
+
}
|
|
83
|
+
return { outputDir: target };
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Derives a product into a zip archive, without writing the generated tree.
|
|
87
|
+
*
|
|
88
|
+
* Same classification of failures as `deriveProduct`, matching `generateZip`.
|
|
89
|
+
*
|
|
90
|
+
* RETURN TYPE: the engine hands back a JSZip instance
|
|
91
|
+
* (`spl-js-engine/src/output.js:ZipOutput`), which the monolith's controller
|
|
92
|
+
* turns into base64 at the HTTP edge (`ProductController.js:117`). linea-core
|
|
93
|
+
* materialises it into a `Buffer` instead, so the result is a real artifact a
|
|
94
|
+
* caller can write, hash or feed to `extractArchive` without knowing anything
|
|
95
|
+
* about JSZip. linea-server gets its base64 with `buffer.toString('base64')`.
|
|
96
|
+
*
|
|
97
|
+
* @param params.lineDir Line working directory.
|
|
98
|
+
* @param params.spec Product spec.
|
|
99
|
+
* @returns The zip archive bytes.
|
|
100
|
+
* @throws The same errors as `deriveProduct`.
|
|
101
|
+
*/
|
|
102
|
+
export const deriveProductToZip = async ({ lineDir, spec }) => {
|
|
103
|
+
assertLineDir(lineDir);
|
|
104
|
+
const checkedSpec = assertSpec(spec);
|
|
105
|
+
try {
|
|
106
|
+
const engine = await createEngine(lineDir);
|
|
107
|
+
const zip = await engine.generateZip(toEngineSpec(checkedSpec));
|
|
108
|
+
const archive = zip;
|
|
109
|
+
return await archive.generateAsync({ type: 'nodebuffer' });
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
return rethrowDerivationError(error);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
//# sourceMappingURL=derive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"derive.js","sourceRoot":"","sources":["../../src/derivation/derive.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAE3D,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAElE;;;;;;;;;;;GAWG;AACH,MAAM,YAAY,GAAG,CAAC,IAAiB,EAAqB,EAAE,CAC5D,eAAe,CAAC,EAAE,IAAI,EAAE,CAAiC,CAAA;AAE3D,MAAM,aAAa,GAAG,CAAC,OAAgB,EAAU,EAAE;IACjD,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACzD,MAAM,IAAI,oBAAoB,CAAC,qCAAqC,CAAC,CAAA;IACvE,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAED,MAAM,UAAU,GAAG,CAAC,IAAa,EAAe,EAAE;IAChD,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACrE,MAAM,IAAI,oBAAoB,CAAC,2BAA2B,CAAC,CAAA;IAC7D,CAAC;IACD,OAAO,IAAmB,CAAA;AAC5B,CAAC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAAE,EAClC,OAAO,EACP,IAAI,EACJ,SAAS,EAKV,EAAkC,EAAE;IACnC,aAAa,CAAC,OAAO,CAAC,CAAA;IACtB,MAAM,WAAW,GAAG,UAAU,CAAC,IAAI,CAAC,CAAA;IACpC,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QAC7D,MAAM,IAAI,oBAAoB,CAAC,uCAAuC,CAAC,CAAA;IACzE,CAAC;IAED,MAAM,MAAM,GAAG,SAAS,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAA;IAEhD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,CAAA;QAC1C,MAAM,MAAM,CAAC,eAAe,CAAC,MAAM,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC,CAAA;IACjE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,sBAAsB,CAAC,KAAK,CAAC,CAAA;IAC/B,CAAC;IAED,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,CAAA;AAC9B,CAAC,CAAA;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EAAE,EACvC,OAAO,EACP,IAAI,EAIL,EAAmB,EAAE;IACpB,aAAa,CAAC,OAAO,CAAC,CAAA;IACtB,MAAM,WAAW,GAAG,UAAU,CAAC,IAAI,CAAC,CAAA;IAEpC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,CAAA;QAC1C,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,CAAA;QAC/D,MAAM,OAAO,GAAG,GAA8E,CAAA;QAC9F,OAAO,MAAM,OAAO,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAA;IAC5D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,sBAAsB,CAAC,KAAK,CAAC,CAAA;IACtC,CAAC;AACH,CAAC,CAAA","sourcesContent":["/**\r\n * Product derivation with spl-js-engine.\r\n *\r\n * Migrated from:\r\n * - `linea/server/src/model/services/generatePipeline.js:runEngine` (~132-147)\r\n * - `linea/server/src/model/services/ProductService.js:generateZip` (~352-394)\r\n *\r\n * Everything those two do around the engine belongs to linea-server (ADR-003):\r\n * downloading the line archive from GitLab, permission checks, the temp\r\n * directory dance and the Mongo transaction.\r\n */\r\nimport type { ProductSpec as EngineProductSpec } from 'spl-js-engine'\r\nimport { InvalidArgumentError } from '../errors.js'\r\nimport { ensureDir } from '../fs/workspace.js'\r\nimport { buildEngineSpec } from '../product/engine-spec.js'\r\nimport type { ProductSpec } from '../product/spec.js'\r\nimport { createEngine, rethrowDerivationError } from './engine.js'\r\n\r\n/**\r\n * Hands the spec to the engine unchanged, as `runEngine` does.\r\n *\r\n * The cast is needed because linea-core's `ProductSpec.features` also admits the\r\n * legacy object-map form `{ Feature: true }`, while the engine's\r\n * `completeFeatureSelection` requires a string array.\r\n *\r\n * NOT normalised here, on purpose: the monolith passes `buildEngineSpec(spec)`\r\n * straight through, so an object-map spec fails there too. Normalising silently\r\n * would be a behaviour change hidden inside derivation. Callers holding a legacy\r\n * spec should run it through `normalizeFeatureSelection` first.\r\n */\r\nconst toEngineSpec = (spec: ProductSpec): EngineProductSpec =>\r\n buildEngineSpec({ spec }) as unknown as EngineProductSpec\r\n\r\nconst assertLineDir = (lineDir: unknown): string => {\r\n if (typeof lineDir !== 'string' || lineDir.trim() === '') {\r\n throw new InvalidArgumentError('\"lineDir\" must be a non-empty path.')\r\n }\r\n return lineDir\r\n}\r\n\r\nconst assertSpec = (spec: unknown): ProductSpec => {\r\n if (typeof spec !== 'object' || spec === null || Array.isArray(spec)) {\r\n throw new InvalidArgumentError('\"spec\" must be an object.')\r\n }\r\n return spec as ProductSpec\r\n}\r\n\r\n/**\r\n * Derives a product into a directory.\r\n *\r\n * The spec goes through `buildEngineSpec` first, exactly as `runEngine` does, so\r\n * a product carrying a parsed sensor DSL takes the engine's shortcut path.\r\n *\r\n * DELIBERATE DIVERGENCE 1: `runEngine` finishes with\r\n * `fs.rmSync(lineOutput, { recursive: true, force: true })`, deleting the line\r\n * directory it just consumed. linea-core deletes NOTHING. Those directories\r\n * belong to the caller — in the monolith they happen to be throwaway temp dirs,\r\n * but here `lineDir` may well be a user's working copy. Cleaning up is the\r\n * caller's decision (ADR-009/ADR-014). A test pins this.\r\n *\r\n * DELIBERATE DIVERGENCE 2, and the one that matters most for whoever ports\r\n * linea-server: `runEngine` writes\r\n * `(await engine(lineOutput)).generateProduct(...)`. It awaits the CONSTRUCTOR\r\n * — which does return a promise — but NOT the generation, which returns one\r\n * too. So in the monolith the surrounding `try/catch` cannot catch anything\r\n * thrown during generation: the `FeatureSelectionError` its very next line\r\n * means to turn into a 400 becomes an unhandled rejection instead, and the\r\n * `rmSync` above runs while generation may still be reading the directory.\r\n *\r\n * linea-core awaits (below), which fixes both. The consequence is that the\r\n * error classification here does NOT merely replicate `runEngine`'s — it is\r\n * strictly more effective, because in the monolith most of those errors never\r\n * reach the `catch` at all.\r\n *\r\n * @param params.lineDir Line working directory (holding `src/platform/...`).\r\n * @param params.spec Product spec.\r\n * @param params.outputDir Directory to generate into. Created if missing.\r\n * @returns The directory that was generated into.\r\n * @throws {FeatureSelectionInvalidError} when the spec's feature selection is\r\n * not valid for the line's feature model.\r\n * @throws {LinePlatformNotFoundError} when the line has no usable platform, or\r\n * for any other engine failure — including a template calling a helper that\r\n * `extra.js` does not define, reported with the\r\n * `error_messages.missing_function_error` key.\r\n * @throws {InvalidArgumentError} when the arguments are malformed.\r\n */\r\nexport const deriveProduct = async ({\r\n lineDir,\r\n spec,\r\n outputDir\r\n}: {\r\n lineDir: string\r\n spec: ProductSpec\r\n outputDir: string\r\n}): Promise<{ outputDir: string }> => {\r\n assertLineDir(lineDir)\r\n const checkedSpec = assertSpec(spec)\r\n if (typeof outputDir !== 'string' || outputDir.trim() === '') {\r\n throw new InvalidArgumentError('\"outputDir\" must be a non-empty path.')\r\n }\r\n\r\n const target = ensureDir({ dirPath: outputDir })\r\n\r\n try {\r\n const engine = await createEngine(lineDir)\r\n await engine.generateProduct(target, toEngineSpec(checkedSpec))\r\n } catch (error) {\r\n rethrowDerivationError(error)\r\n }\r\n\r\n return { outputDir: target }\r\n}\r\n\r\n/**\r\n * Derives a product into a zip archive, without writing the generated tree.\r\n *\r\n * Same classification of failures as `deriveProduct`, matching `generateZip`.\r\n *\r\n * RETURN TYPE: the engine hands back a JSZip instance\r\n * (`spl-js-engine/src/output.js:ZipOutput`), which the monolith's controller\r\n * turns into base64 at the HTTP edge (`ProductController.js:117`). linea-core\r\n * materialises it into a `Buffer` instead, so the result is a real artifact a\r\n * caller can write, hash or feed to `extractArchive` without knowing anything\r\n * about JSZip. linea-server gets its base64 with `buffer.toString('base64')`.\r\n *\r\n * @param params.lineDir Line working directory.\r\n * @param params.spec Product spec.\r\n * @returns The zip archive bytes.\r\n * @throws The same errors as `deriveProduct`.\r\n */\r\nexport const deriveProductToZip = async ({\r\n lineDir,\r\n spec\r\n}: {\r\n lineDir: string\r\n spec: ProductSpec\r\n}): Promise<Buffer> => {\r\n assertLineDir(lineDir)\r\n const checkedSpec = assertSpec(spec)\r\n\r\n try {\r\n const engine = await createEngine(lineDir)\r\n const zip = await engine.generateZip(toEngineSpec(checkedSpec))\r\n const archive = zip as { generateAsync: (options: { type: 'nodebuffer' }) => Promise<Buffer> }\r\n return await archive.generateAsync({ type: 'nodebuffer' })\r\n } catch (error) {\r\n return rethrowDerivationError(error)\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The slice of the engine this module actually drives.
|
|
3
|
+
*
|
|
4
|
+
* Declared locally rather than importing `DerivationEngineInstance`, for the
|
|
5
|
+
* same reason as `SolvingType` in `analysis/runtime.ts`: `spl-js-engine` ships
|
|
6
|
+
* no declarations of its own, and our ambient ones under `src/types/` are never
|
|
7
|
+
* published. A third-party type on an exported signature therefore ends up as a
|
|
8
|
+
* dangling reference in `dist/**\/*.d.ts` and breaks any consumer building with
|
|
9
|
+
* `skipLibCheck: false`. This one was NOT yet reachable from `index.d.ts`, so it
|
|
10
|
+
* did not fail anything — it was a latent version of the bug that did.
|
|
11
|
+
* `npm run check:consumer` now compiles every emitted declaration, so a
|
|
12
|
+
* regression here fails immediately instead of waiting for the day something
|
|
13
|
+
* public happens to expose it.
|
|
14
|
+
*/
|
|
15
|
+
interface DerivationEngineHandle {
|
|
16
|
+
generateProduct: (outputDir: string, spec: unknown) => Promise<unknown>;
|
|
17
|
+
generateZip: (spec: unknown) => Promise<unknown>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Builds a `DerivationEngine` for a line working directory.
|
|
21
|
+
*
|
|
22
|
+
* Remember the engine's constructor RETURNS A PROMISE — `new DerivationEngine()`
|
|
23
|
+
* evaluates to a promise and must be awaited. The positional argument order
|
|
24
|
+
* mirrors `utils.js:engine()`.
|
|
25
|
+
*/
|
|
26
|
+
export declare const createEngine: (lineDir: string) => Promise<DerivationEngineHandle>;
|
|
27
|
+
/**
|
|
28
|
+
* Turns whatever the engine threw into linea-core's taxonomy.
|
|
29
|
+
*
|
|
30
|
+
* Replicates the classification of `generatePipeline.js:runEngine` (~132-147)
|
|
31
|
+
* and `ProductService.js:generateZip` (~375-382):
|
|
32
|
+
*
|
|
33
|
+
* - `FeatureSelectionError` propagates as such — it is the caller's fault, and
|
|
34
|
+
* the monolith maps it to a 400.
|
|
35
|
+
* - a `ReferenceError` means an annotation called a helper that `extra.js` does
|
|
36
|
+
* not define; the monolith logs `error_messages.missing_function_error` and
|
|
37
|
+
* then throws `LinePlatformNotFoundError` anyway.
|
|
38
|
+
* - anything else becomes `LinePlatformNotFoundError`.
|
|
39
|
+
*
|
|
40
|
+
* PARITY NOTE: in the monolith BOTH the ReferenceError branch and the catch-all
|
|
41
|
+
* throw `LinePlatformNotFoundError`; only the LOG MESSAGE differs. linea-core
|
|
42
|
+
* takes no log callback (generation logs are out of scope), so the distinction
|
|
43
|
+
* is preserved where it survives: the i18n key travels in the error MESSAGE
|
|
44
|
+
* instead of a log line, and the original error is attached as `cause`. The
|
|
45
|
+
* thrown TYPE is identical to the monolith's in every branch.
|
|
46
|
+
*/
|
|
47
|
+
export declare const rethrowDerivationError: (error: unknown) => never;
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* INTERNAL adapter that builds a configured `DerivationEngine` from a line
|
|
3
|
+
* working directory, and classifies whatever the engine throws.
|
|
4
|
+
*
|
|
5
|
+
* Migrated from `linea/server/src/model/services/utils.js:engine` and
|
|
6
|
+
* `getEngineModel` (~18-36). Not exported from `src/index.ts`.
|
|
7
|
+
*/
|
|
8
|
+
import fs from 'node:fs';
|
|
9
|
+
import { DerivationEngine } from 'spl-js-engine';
|
|
10
|
+
import { PLATFORM_PATHS } from '../constants.js';
|
|
11
|
+
import { FeatureSelectionInvalidError, LinePlatformNotFoundError } from '../errors.js';
|
|
12
|
+
import { describeSelectionFailure, isFeatureSelectionError } from '../feature-model/engine.js';
|
|
13
|
+
import { fileExists, readTextFile, resolveLinePaths } from '../fs/workspace.js';
|
|
14
|
+
/**
|
|
15
|
+
* The `featureModel` argument for `DerivationEngine`.
|
|
16
|
+
*
|
|
17
|
+
* PARITY QUIRK, forced by the engine rather than chosen. `setFeatureModel`
|
|
18
|
+
* sniffs the notation with `featureModel.endsWith('uvl')` over the ARGUMENT, so:
|
|
19
|
+
*
|
|
20
|
+
* - for UVL it must be handed the FILE PATH — the path ends in `.uvl`, the
|
|
21
|
+
* check passes and `FeatureModel.fromUVL` reads the file. Passing UVL *text*
|
|
22
|
+
* would fail the `endsWith` test and the engine would try `fromXml` on it.
|
|
23
|
+
* - for XML it must be handed the CONTENT — a path not ending in `uvl` would go
|
|
24
|
+
* to `fromXml`, which would then try to parse the path itself as a document.
|
|
25
|
+
*
|
|
26
|
+
* That is exactly what `getEngineModel` does, and why it looks inconsistent.
|
|
27
|
+
*
|
|
28
|
+
* Note this bypasses `parseFeatureModel`, so the `asUvlContent` guard (which
|
|
29
|
+
* appends a newline to stop `fromUVL` reading a file) is NOT in play here: for
|
|
30
|
+
* UVL we deliberately WANT the file to be read, and the argument is a path we
|
|
31
|
+
* built ourselves from `lineDir`, never caller-supplied content.
|
|
32
|
+
*/
|
|
33
|
+
const resolveEngineModel = (lineDir) => {
|
|
34
|
+
const paths = resolveLinePaths({ lineDir });
|
|
35
|
+
if (fileExists({ filePath: paths.model }))
|
|
36
|
+
return paths.model;
|
|
37
|
+
const xmlPath = paths.model.replace(/\.uvl$/, '.xml');
|
|
38
|
+
if (!fileExists({ filePath: xmlPath })) {
|
|
39
|
+
throw new LinePlatformNotFoundError(`No feature model in "${lineDir}": expected "${PLATFORM_PATHS.model}" or "${PLATFORM_PATHS.modelXml}".`);
|
|
40
|
+
}
|
|
41
|
+
return readTextFile({ filePath: xmlPath });
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Builds a `DerivationEngine` for a line working directory.
|
|
45
|
+
*
|
|
46
|
+
* Remember the engine's constructor RETURNS A PROMISE — `new DerivationEngine()`
|
|
47
|
+
* evaluates to a promise and must be awaited. The positional argument order
|
|
48
|
+
* mirrors `utils.js:engine()`.
|
|
49
|
+
*/
|
|
50
|
+
export const createEngine = async (lineDir) => {
|
|
51
|
+
const paths = resolveLinePaths({ lineDir });
|
|
52
|
+
const featureModel = resolveEngineModel(lineDir);
|
|
53
|
+
if (!fs.existsSync(paths.code)) {
|
|
54
|
+
throw new LinePlatformNotFoundError(`No annotated code in "${lineDir}": expected "${PLATFORM_PATHS.code}".`);
|
|
55
|
+
}
|
|
56
|
+
const config = JSON.parse(readTextFile({ filePath: paths.config }));
|
|
57
|
+
const extraJs = readTextFile({ filePath: paths.extraJs });
|
|
58
|
+
const transformation = readTextFile({ filePath: paths.transformation });
|
|
59
|
+
// The cast is the price of not leaking `DerivationEngineInstance` into the
|
|
60
|
+
// published declarations: the engine's own parameter types are narrower than
|
|
61
|
+
// the structural handle, and function parameters are contravariant. Widening
|
|
62
|
+
// is safe here because this module is the only caller and it always passes the
|
|
63
|
+
// output of `buildEngineSpec`.
|
|
64
|
+
const engine = await new DerivationEngine(paths.code, featureModel, config, extraJs, transformation);
|
|
65
|
+
return engine;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Turns whatever the engine threw into linea-core's taxonomy.
|
|
69
|
+
*
|
|
70
|
+
* Replicates the classification of `generatePipeline.js:runEngine` (~132-147)
|
|
71
|
+
* and `ProductService.js:generateZip` (~375-382):
|
|
72
|
+
*
|
|
73
|
+
* - `FeatureSelectionError` propagates as such — it is the caller's fault, and
|
|
74
|
+
* the monolith maps it to a 400.
|
|
75
|
+
* - a `ReferenceError` means an annotation called a helper that `extra.js` does
|
|
76
|
+
* not define; the monolith logs `error_messages.missing_function_error` and
|
|
77
|
+
* then throws `LinePlatformNotFoundError` anyway.
|
|
78
|
+
* - anything else becomes `LinePlatformNotFoundError`.
|
|
79
|
+
*
|
|
80
|
+
* PARITY NOTE: in the monolith BOTH the ReferenceError branch and the catch-all
|
|
81
|
+
* throw `LinePlatformNotFoundError`; only the LOG MESSAGE differs. linea-core
|
|
82
|
+
* takes no log callback (generation logs are out of scope), so the distinction
|
|
83
|
+
* is preserved where it survives: the i18n key travels in the error MESSAGE
|
|
84
|
+
* instead of a log line, and the original error is attached as `cause`. The
|
|
85
|
+
* thrown TYPE is identical to the monolith's in every branch.
|
|
86
|
+
*/
|
|
87
|
+
export const rethrowDerivationError = (error) => {
|
|
88
|
+
if (isFeatureSelectionError(error)) {
|
|
89
|
+
throw new FeatureSelectionInvalidError(describeSelectionFailure(error).message, { cause: error });
|
|
90
|
+
}
|
|
91
|
+
if (error instanceof LinePlatformNotFoundError)
|
|
92
|
+
throw error;
|
|
93
|
+
if (error instanceof ReferenceError) {
|
|
94
|
+
throw new LinePlatformNotFoundError('error_messages.missing_function_error', { cause: error });
|
|
95
|
+
}
|
|
96
|
+
throw new LinePlatformNotFoundError(error instanceof Error ? error.message : String(error), { cause: error });
|
|
97
|
+
};
|
|
98
|
+
//# sourceMappingURL=engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/derivation/engine.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,EAAE,gBAAgB,EAA+B,MAAM,eAAe,CAAA;AAC7E,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,4BAA4B,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AACtF,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAA;AAC9F,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAE/E;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,kBAAkB,GAAG,CAAC,OAAe,EAAU,EAAE;IACrD,MAAM,KAAK,GAAG,gBAAgB,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;IAC3C,IAAI,UAAU,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;QAAE,OAAO,KAAK,CAAC,KAAK,CAAA;IAE7D,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;IACrD,IAAI,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;QACvC,MAAM,IAAI,yBAAyB,CACjC,wBAAwB,OAAO,gBAAgB,cAAc,CAAC,KAAK,SAAS,cAAc,CAAC,QAAQ,IAAI,CACxG,CAAA;IACH,CAAC;IACD,OAAO,YAAY,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAA;AAC5C,CAAC,CAAA;AAqBD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAAE,OAAe,EAAmC,EAAE;IACrF,MAAM,KAAK,GAAG,gBAAgB,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;IAC3C,MAAM,YAAY,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAA;IAEhD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,yBAAyB,CACjC,yBAAyB,OAAO,gBAAgB,cAAc,CAAC,IAAI,IAAI,CACxE,CAAA;IACH,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAA2B,CAAA;IAC7F,MAAM,OAAO,GAAG,YAAY,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;IACzD,MAAM,cAAc,GAAG,YAAY,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,cAAc,EAAE,CAAC,CAAA;IAEvE,2EAA2E;IAC3E,6EAA6E;IAC7E,6EAA6E;IAC7E,+EAA+E;IAC/E,+BAA+B;IAC/B,MAAM,MAAM,GAAG,MAAM,IAAI,gBAAgB,CACvC,KAAK,CAAC,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,CAC1D,CAAA;IACD,OAAO,MAA2C,CAAA;AACpD,CAAC,CAAA;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,KAAc,EAAS,EAAE;IAC9D,IAAI,uBAAuB,CAAC,KAAK,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,4BAA4B,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;IACnG,CAAC;IACD,IAAI,KAAK,YAAY,yBAAyB;QAAE,MAAM,KAAK,CAAA;IAC3D,IAAI,KAAK,YAAY,cAAc,EAAE,CAAC;QACpC,MAAM,IAAI,yBAAyB,CAAC,uCAAuC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;IAChG,CAAC;IACD,MAAM,IAAI,yBAAyB,CACjC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EACtD,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAA;AACH,CAAC,CAAA","sourcesContent":["/**\r\n * INTERNAL adapter that builds a configured `DerivationEngine` from a line\r\n * working directory, and classifies whatever the engine throws.\r\n *\r\n * Migrated from `linea/server/src/model/services/utils.js:engine` and\r\n * `getEngineModel` (~18-36). Not exported from `src/index.ts`.\r\n */\r\nimport fs from 'node:fs'\r\nimport { DerivationEngine, type DerivationEngineConfig } from 'spl-js-engine'\r\nimport { PLATFORM_PATHS } from '../constants.js'\r\nimport { FeatureSelectionInvalidError, LinePlatformNotFoundError } from '../errors.js'\r\nimport { describeSelectionFailure, isFeatureSelectionError } from '../feature-model/engine.js'\r\nimport { fileExists, readTextFile, resolveLinePaths } from '../fs/workspace.js'\r\n\r\n/**\r\n * The `featureModel` argument for `DerivationEngine`.\r\n *\r\n * PARITY QUIRK, forced by the engine rather than chosen. `setFeatureModel`\r\n * sniffs the notation with `featureModel.endsWith('uvl')` over the ARGUMENT, so:\r\n *\r\n * - for UVL it must be handed the FILE PATH — the path ends in `.uvl`, the\r\n * check passes and `FeatureModel.fromUVL` reads the file. Passing UVL *text*\r\n * would fail the `endsWith` test and the engine would try `fromXml` on it.\r\n * - for XML it must be handed the CONTENT — a path not ending in `uvl` would go\r\n * to `fromXml`, which would then try to parse the path itself as a document.\r\n *\r\n * That is exactly what `getEngineModel` does, and why it looks inconsistent.\r\n *\r\n * Note this bypasses `parseFeatureModel`, so the `asUvlContent` guard (which\r\n * appends a newline to stop `fromUVL` reading a file) is NOT in play here: for\r\n * UVL we deliberately WANT the file to be read, and the argument is a path we\r\n * built ourselves from `lineDir`, never caller-supplied content.\r\n */\r\nconst resolveEngineModel = (lineDir: string): string => {\r\n const paths = resolveLinePaths({ lineDir })\r\n if (fileExists({ filePath: paths.model })) return paths.model\r\n\r\n const xmlPath = paths.model.replace(/\\.uvl$/, '.xml')\r\n if (!fileExists({ filePath: xmlPath })) {\r\n throw new LinePlatformNotFoundError(\r\n `No feature model in \"${lineDir}\": expected \"${PLATFORM_PATHS.model}\" or \"${PLATFORM_PATHS.modelXml}\".`\r\n )\r\n }\r\n return readTextFile({ filePath: xmlPath })\r\n}\r\n\r\n/**\r\n * The slice of the engine this module actually drives.\r\n *\r\n * Declared locally rather than importing `DerivationEngineInstance`, for the\r\n * same reason as `SolvingType` in `analysis/runtime.ts`: `spl-js-engine` ships\r\n * no declarations of its own, and our ambient ones under `src/types/` are never\r\n * published. A third-party type on an exported signature therefore ends up as a\r\n * dangling reference in `dist/**\\/*.d.ts` and breaks any consumer building with\r\n * `skipLibCheck: false`. This one was NOT yet reachable from `index.d.ts`, so it\r\n * did not fail anything — it was a latent version of the bug that did.\r\n * `npm run check:consumer` now compiles every emitted declaration, so a\r\n * regression here fails immediately instead of waiting for the day something\r\n * public happens to expose it.\r\n */\r\ninterface DerivationEngineHandle {\r\n generateProduct: (outputDir: string, spec: unknown) => Promise<unknown>\r\n generateZip: (spec: unknown) => Promise<unknown>\r\n}\r\n\r\n/**\r\n * Builds a `DerivationEngine` for a line working directory.\r\n *\r\n * Remember the engine's constructor RETURNS A PROMISE — `new DerivationEngine()`\r\n * evaluates to a promise and must be awaited. The positional argument order\r\n * mirrors `utils.js:engine()`.\r\n */\r\nexport const createEngine = async (lineDir: string): Promise<DerivationEngineHandle> => {\r\n const paths = resolveLinePaths({ lineDir })\r\n const featureModel = resolveEngineModel(lineDir)\r\n\r\n if (!fs.existsSync(paths.code)) {\r\n throw new LinePlatformNotFoundError(\r\n `No annotated code in \"${lineDir}\": expected \"${PLATFORM_PATHS.code}\".`\r\n )\r\n }\r\n\r\n const config = JSON.parse(readTextFile({ filePath: paths.config })) as DerivationEngineConfig\r\n const extraJs = readTextFile({ filePath: paths.extraJs })\r\n const transformation = readTextFile({ filePath: paths.transformation })\r\n\r\n // The cast is the price of not leaking `DerivationEngineInstance` into the\r\n // published declarations: the engine's own parameter types are narrower than\r\n // the structural handle, and function parameters are contravariant. Widening\r\n // is safe here because this module is the only caller and it always passes the\r\n // output of `buildEngineSpec`.\r\n const engine = await new DerivationEngine(\r\n paths.code, featureModel, config, extraJs, transformation\r\n )\r\n return engine as unknown as DerivationEngineHandle\r\n}\r\n\r\n/**\r\n * Turns whatever the engine threw into linea-core's taxonomy.\r\n *\r\n * Replicates the classification of `generatePipeline.js:runEngine` (~132-147)\r\n * and `ProductService.js:generateZip` (~375-382):\r\n *\r\n * - `FeatureSelectionError` propagates as such — it is the caller's fault, and\r\n * the monolith maps it to a 400.\r\n * - a `ReferenceError` means an annotation called a helper that `extra.js` does\r\n * not define; the monolith logs `error_messages.missing_function_error` and\r\n * then throws `LinePlatformNotFoundError` anyway.\r\n * - anything else becomes `LinePlatformNotFoundError`.\r\n *\r\n * PARITY NOTE: in the monolith BOTH the ReferenceError branch and the catch-all\r\n * throw `LinePlatformNotFoundError`; only the LOG MESSAGE differs. linea-core\r\n * takes no log callback (generation logs are out of scope), so the distinction\r\n * is preserved where it survives: the i18n key travels in the error MESSAGE\r\n * instead of a log line, and the original error is attached as `cause`. The\r\n * thrown TYPE is identical to the monolith's in every branch.\r\n */\r\nexport const rethrowDerivationError = (error: unknown): never => {\r\n if (isFeatureSelectionError(error)) {\r\n throw new FeatureSelectionInvalidError(describeSelectionFailure(error).message, { cause: error })\r\n }\r\n if (error instanceof LinePlatformNotFoundError) throw error\r\n if (error instanceof ReferenceError) {\r\n throw new LinePlatformNotFoundError('error_messages.missing_function_error', { cause: error })\r\n }\r\n throw new LinePlatformNotFoundError(\r\n error instanceof Error ? error.message : String(error),\r\n { cause: error }\r\n )\r\n}\r\n"]}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error taxonomy of linea-core.
|
|
3
|
+
*
|
|
4
|
+
* Migrated from `linea/server/src/model/errors/errors.js`, keeping only the
|
|
5
|
+
* subset that belongs to the offline engine. User-facing and GitLab-facing
|
|
6
|
+
* errors (`IncorrectCredentialsError`, `UserNotFoundError`, `PermissionError`,
|
|
7
|
+
* `AlreadyExistent*Error`, `LineNotFoundError`) stay in linea-server: linea-core
|
|
8
|
+
* knows nothing about users, sessions or repositories (ADR-002, ADR-003).
|
|
9
|
+
*
|
|
10
|
+
* Every error carries a stable `.code` so callers can branch on it without
|
|
11
|
+
* string-matching messages or relying on `instanceof` across module instances.
|
|
12
|
+
*/
|
|
13
|
+
/** Stable, machine-readable discriminator of a `LineaCoreError`. */
|
|
14
|
+
export type LineaCoreErrorCode = 'INVALID_ARGUMENT' | 'UVL_PARSE_ERROR' | 'UNSUPPORTED_CONVERSION' | 'FEATURE_SELECTION_INVALID' | 'LINE_PLATFORM_NOT_FOUND' | 'INVALID_PRODUCT_SPEC' | 'PRODUCTS_INDEX_ERROR' | 'ANALYSIS_RUNTIME_ERROR';
|
|
15
|
+
/** Base class of every error thrown by linea-core. */
|
|
16
|
+
export declare class LineaCoreError extends Error {
|
|
17
|
+
/** Stable discriminator; never changes for a given subclass. */
|
|
18
|
+
readonly code: LineaCoreErrorCode;
|
|
19
|
+
constructor(code: LineaCoreErrorCode, message: string, options?: ErrorOptions);
|
|
20
|
+
}
|
|
21
|
+
/** A parameter is missing, malformed or outside its allowed domain. */
|
|
22
|
+
export declare class InvalidArgumentError extends LineaCoreError {
|
|
23
|
+
constructor(message: string, options?: ErrorOptions);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A UVL document could not be parsed.
|
|
27
|
+
* Equivalent of `UVLValidationError` in the monolith.
|
|
28
|
+
*/
|
|
29
|
+
export declare class UvlParseError extends LineaCoreError {
|
|
30
|
+
constructor(message: string, options?: ErrorOptions);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The requested feature model conversion is not supported (e.g. UVL to UVL).
|
|
34
|
+
* Migrated from `UnsupportedConversionError`.
|
|
35
|
+
*/
|
|
36
|
+
export declare class UnsupportedConversionError extends LineaCoreError {
|
|
37
|
+
constructor(message: string, options?: ErrorOptions);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A feature selection is not valid against its feature model.
|
|
41
|
+
* Wraps `FeatureSelectionError` from spl-js-engine, which the monolith surfaces
|
|
42
|
+
* directly (e.g. `ProductService.js:14`, `agents/tools/evolution.js`).
|
|
43
|
+
*/
|
|
44
|
+
export declare class FeatureSelectionInvalidError extends LineaCoreError {
|
|
45
|
+
constructor(message: string, options?: ErrorOptions);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A line working directory has no platform feature model.
|
|
49
|
+
* Migrated from `LinePlatformNotFoundError` (used in `generatePipeline.js:27`).
|
|
50
|
+
*/
|
|
51
|
+
export declare class LinePlatformNotFoundError extends LineaCoreError {
|
|
52
|
+
constructor(message: string, options?: ErrorOptions);
|
|
53
|
+
}
|
|
54
|
+
/** A product spec fails the domain rules (name, version, features, SRID...). */
|
|
55
|
+
export declare class InvalidProductSpecError extends LineaCoreError {
|
|
56
|
+
constructor(message: string, options?: ErrorOptions);
|
|
57
|
+
}
|
|
58
|
+
/** The `products.json` index (ADR-011) is missing, unreadable or malformed. */
|
|
59
|
+
export declare class ProductsIndexError extends LineaCoreError {
|
|
60
|
+
constructor(message: string, options?: ErrorOptions);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The feature model analysis runtime could not start, failed its canary, or has
|
|
64
|
+
* already been disposed (ADR-021).
|
|
65
|
+
*
|
|
66
|
+
* Exists so a broken Pyodide bootstrap surfaces as an explicit failure. flamapy
|
|
67
|
+
* swallows those errors and then returns `undefined` from every operation, which
|
|
68
|
+
* would make an offline core report empty metrics without telling anyone.
|
|
69
|
+
*/
|
|
70
|
+
export declare class AnalysisRuntimeError extends LineaCoreError {
|
|
71
|
+
constructor(message: string, options?: ErrorOptions);
|
|
72
|
+
}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error taxonomy of linea-core.
|
|
3
|
+
*
|
|
4
|
+
* Migrated from `linea/server/src/model/errors/errors.js`, keeping only the
|
|
5
|
+
* subset that belongs to the offline engine. User-facing and GitLab-facing
|
|
6
|
+
* errors (`IncorrectCredentialsError`, `UserNotFoundError`, `PermissionError`,
|
|
7
|
+
* `AlreadyExistent*Error`, `LineNotFoundError`) stay in linea-server: linea-core
|
|
8
|
+
* knows nothing about users, sessions or repositories (ADR-002, ADR-003).
|
|
9
|
+
*
|
|
10
|
+
* Every error carries a stable `.code` so callers can branch on it without
|
|
11
|
+
* string-matching messages or relying on `instanceof` across module instances.
|
|
12
|
+
*/
|
|
13
|
+
/** Base class of every error thrown by linea-core. */
|
|
14
|
+
export class LineaCoreError extends Error {
|
|
15
|
+
/** Stable discriminator; never changes for a given subclass. */
|
|
16
|
+
code;
|
|
17
|
+
constructor(code, message, options) {
|
|
18
|
+
super(message, options);
|
|
19
|
+
this.name = new.target.name;
|
|
20
|
+
this.code = code;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** A parameter is missing, malformed or outside its allowed domain. */
|
|
24
|
+
export class InvalidArgumentError extends LineaCoreError {
|
|
25
|
+
constructor(message, options) {
|
|
26
|
+
super('INVALID_ARGUMENT', message, options);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A UVL document could not be parsed.
|
|
31
|
+
* Equivalent of `UVLValidationError` in the monolith.
|
|
32
|
+
*/
|
|
33
|
+
export class UvlParseError extends LineaCoreError {
|
|
34
|
+
constructor(message, options) {
|
|
35
|
+
super('UVL_PARSE_ERROR', message, options);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The requested feature model conversion is not supported (e.g. UVL to UVL).
|
|
40
|
+
* Migrated from `UnsupportedConversionError`.
|
|
41
|
+
*/
|
|
42
|
+
export class UnsupportedConversionError extends LineaCoreError {
|
|
43
|
+
constructor(message, options) {
|
|
44
|
+
super('UNSUPPORTED_CONVERSION', message, options);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A feature selection is not valid against its feature model.
|
|
49
|
+
* Wraps `FeatureSelectionError` from spl-js-engine, which the monolith surfaces
|
|
50
|
+
* directly (e.g. `ProductService.js:14`, `agents/tools/evolution.js`).
|
|
51
|
+
*/
|
|
52
|
+
export class FeatureSelectionInvalidError extends LineaCoreError {
|
|
53
|
+
constructor(message, options) {
|
|
54
|
+
super('FEATURE_SELECTION_INVALID', message, options);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* A line working directory has no platform feature model.
|
|
59
|
+
* Migrated from `LinePlatformNotFoundError` (used in `generatePipeline.js:27`).
|
|
60
|
+
*/
|
|
61
|
+
export class LinePlatformNotFoundError extends LineaCoreError {
|
|
62
|
+
constructor(message, options) {
|
|
63
|
+
super('LINE_PLATFORM_NOT_FOUND', message, options);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** A product spec fails the domain rules (name, version, features, SRID...). */
|
|
67
|
+
export class InvalidProductSpecError extends LineaCoreError {
|
|
68
|
+
constructor(message, options) {
|
|
69
|
+
super('INVALID_PRODUCT_SPEC', message, options);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/** The `products.json` index (ADR-011) is missing, unreadable or malformed. */
|
|
73
|
+
export class ProductsIndexError extends LineaCoreError {
|
|
74
|
+
constructor(message, options) {
|
|
75
|
+
super('PRODUCTS_INDEX_ERROR', message, options);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The feature model analysis runtime could not start, failed its canary, or has
|
|
80
|
+
* already been disposed (ADR-021).
|
|
81
|
+
*
|
|
82
|
+
* Exists so a broken Pyodide bootstrap surfaces as an explicit failure. flamapy
|
|
83
|
+
* swallows those errors and then returns `undefined` from every operation, which
|
|
84
|
+
* would make an offline core report empty metrics without telling anyone.
|
|
85
|
+
*/
|
|
86
|
+
export class AnalysisRuntimeError extends LineaCoreError {
|
|
87
|
+
constructor(message, options) {
|
|
88
|
+
super('ANALYSIS_RUNTIME_ERROR', message, options);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAaH,sDAAsD;AACtD,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC,gEAAgE;IACvD,IAAI,CAAoB;IAEjC,YAAa,IAAwB,EAAE,OAAe,EAAE,OAAsB;QAC5E,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QACvB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAA;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;CACF;AAED,uEAAuE;AACvE,MAAM,OAAO,oBAAqB,SAAQ,cAAc;IACtD,YAAa,OAAe,EAAE,OAAsB;QAClD,KAAK,CAAC,kBAAkB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IAC7C,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,aAAc,SAAQ,cAAc;IAC/C,YAAa,OAAe,EAAE,OAAsB;QAClD,KAAK,CAAC,iBAAiB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IAC5C,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,0BAA2B,SAAQ,cAAc;IAC5D,YAAa,OAAe,EAAE,OAAsB;QAClD,KAAK,CAAC,wBAAwB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IACnD,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OAAO,4BAA6B,SAAQ,cAAc;IAC9D,YAAa,OAAe,EAAE,OAAsB;QAClD,KAAK,CAAC,2BAA2B,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IACtD,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,yBAA0B,SAAQ,cAAc;IAC3D,YAAa,OAAe,EAAE,OAAsB;QAClD,KAAK,CAAC,yBAAyB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IACpD,CAAC;CACF;AAED,gFAAgF;AAChF,MAAM,OAAO,uBAAwB,SAAQ,cAAc;IACzD,YAAa,OAAe,EAAE,OAAsB;QAClD,KAAK,CAAC,sBAAsB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IACjD,CAAC;CACF;AAED,+EAA+E;AAC/E,MAAM,OAAO,kBAAmB,SAAQ,cAAc;IACpD,YAAa,OAAe,EAAE,OAAsB;QAClD,KAAK,CAAC,sBAAsB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IACjD,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,OAAO,oBAAqB,SAAQ,cAAc;IACtD,YAAa,OAAe,EAAE,OAAsB;QAClD,KAAK,CAAC,wBAAwB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IACnD,CAAC;CACF","sourcesContent":["/**\r\n * Error taxonomy of linea-core.\r\n *\r\n * Migrated from `linea/server/src/model/errors/errors.js`, keeping only the\r\n * subset that belongs to the offline engine. User-facing and GitLab-facing\r\n * errors (`IncorrectCredentialsError`, `UserNotFoundError`, `PermissionError`,\r\n * `AlreadyExistent*Error`, `LineNotFoundError`) stay in linea-server: linea-core\r\n * knows nothing about users, sessions or repositories (ADR-002, ADR-003).\r\n *\r\n * Every error carries a stable `.code` so callers can branch on it without\r\n * string-matching messages or relying on `instanceof` across module instances.\r\n */\r\n\r\n/** Stable, machine-readable discriminator of a `LineaCoreError`. */\r\nexport type LineaCoreErrorCode =\r\n | 'INVALID_ARGUMENT'\r\n | 'UVL_PARSE_ERROR'\r\n | 'UNSUPPORTED_CONVERSION'\r\n | 'FEATURE_SELECTION_INVALID'\r\n | 'LINE_PLATFORM_NOT_FOUND'\r\n | 'INVALID_PRODUCT_SPEC'\r\n | 'PRODUCTS_INDEX_ERROR'\r\n | 'ANALYSIS_RUNTIME_ERROR'\r\n\r\n/** Base class of every error thrown by linea-core. */\r\nexport class LineaCoreError extends Error {\r\n /** Stable discriminator; never changes for a given subclass. */\r\n readonly code: LineaCoreErrorCode\r\n\r\n constructor (code: LineaCoreErrorCode, message: string, options?: ErrorOptions) {\r\n super(message, options)\r\n this.name = new.target.name\r\n this.code = code\r\n }\r\n}\r\n\r\n/** A parameter is missing, malformed or outside its allowed domain. */\r\nexport class InvalidArgumentError extends LineaCoreError {\r\n constructor (message: string, options?: ErrorOptions) {\r\n super('INVALID_ARGUMENT', message, options)\r\n }\r\n}\r\n\r\n/**\r\n * A UVL document could not be parsed.\r\n * Equivalent of `UVLValidationError` in the monolith.\r\n */\r\nexport class UvlParseError extends LineaCoreError {\r\n constructor (message: string, options?: ErrorOptions) {\r\n super('UVL_PARSE_ERROR', message, options)\r\n }\r\n}\r\n\r\n/**\r\n * The requested feature model conversion is not supported (e.g. UVL to UVL).\r\n * Migrated from `UnsupportedConversionError`.\r\n */\r\nexport class UnsupportedConversionError extends LineaCoreError {\r\n constructor (message: string, options?: ErrorOptions) {\r\n super('UNSUPPORTED_CONVERSION', message, options)\r\n }\r\n}\r\n\r\n/**\r\n * A feature selection is not valid against its feature model.\r\n * Wraps `FeatureSelectionError` from spl-js-engine, which the monolith surfaces\r\n * directly (e.g. `ProductService.js:14`, `agents/tools/evolution.js`).\r\n */\r\nexport class FeatureSelectionInvalidError extends LineaCoreError {\r\n constructor (message: string, options?: ErrorOptions) {\r\n super('FEATURE_SELECTION_INVALID', message, options)\r\n }\r\n}\r\n\r\n/**\r\n * A line working directory has no platform feature model.\r\n * Migrated from `LinePlatformNotFoundError` (used in `generatePipeline.js:27`).\r\n */\r\nexport class LinePlatformNotFoundError extends LineaCoreError {\r\n constructor (message: string, options?: ErrorOptions) {\r\n super('LINE_PLATFORM_NOT_FOUND', message, options)\r\n }\r\n}\r\n\r\n/** A product spec fails the domain rules (name, version, features, SRID...). */\r\nexport class InvalidProductSpecError extends LineaCoreError {\r\n constructor (message: string, options?: ErrorOptions) {\r\n super('INVALID_PRODUCT_SPEC', message, options)\r\n }\r\n}\r\n\r\n/** The `products.json` index (ADR-011) is missing, unreadable or malformed. */\r\nexport class ProductsIndexError extends LineaCoreError {\r\n constructor (message: string, options?: ErrorOptions) {\r\n super('PRODUCTS_INDEX_ERROR', message, options)\r\n }\r\n}\r\n\r\n/**\r\n * The feature model analysis runtime could not start, failed its canary, or has\r\n * already been disposed (ADR-021).\r\n *\r\n * Exists so a broken Pyodide bootstrap surfaces as an explicit failure. flamapy\r\n * swallows those errors and then returns `undefined` from every operation, which\r\n * would make an offline core report empty metrics without telling anyone.\r\n */\r\nexport class AnalysisRuntimeError extends LineaCoreError {\r\n constructor (message: string, options?: ErrorOptions) {\r\n super('ANALYSIS_RUNTIME_ERROR', message, options)\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Feature model notation conversion.
|
|
3
|
+
*
|
|
4
|
+
* Migrated from `linea/server/src/model/services/LineService.js:convertFeatureModel`
|
|
5
|
+
* (~421-461), keeping ONLY the domain logic. Everything around it belongs to
|
|
6
|
+
* linea-server (ADR-003): permission checks, the GitLab commit that creates the
|
|
7
|
+
* new file and deletes the old one, the line version bump (`incrementVersion`)
|
|
8
|
+
* and the Mongo transaction.
|
|
9
|
+
*
|
|
10
|
+
* Note that the monolith derives the target notation from the line's current
|
|
11
|
+
* `featureModelType`; here both ends are explicit parameters, so the caller can
|
|
12
|
+
* convert a document it holds in memory without owning a line.
|
|
13
|
+
*/
|
|
14
|
+
import { type FeatureModelType } from '../constants.js';
|
|
15
|
+
/**
|
|
16
|
+
* Converts a feature model between UVL and XML.
|
|
17
|
+
*
|
|
18
|
+
* @param params.content Model document as plain text.
|
|
19
|
+
* @param params.from Notation of `content`.
|
|
20
|
+
* @param params.to Target notation.
|
|
21
|
+
* @returns The converted document and its notation.
|
|
22
|
+
* @throws {UnsupportedConversionError} when `from` equals `to` — there is no
|
|
23
|
+
* such thing as a UVL-to-UVL conversion, and silently returning the input
|
|
24
|
+
* would hide a caller bug.
|
|
25
|
+
* @throws {InvalidArgumentError} when a notation is unknown.
|
|
26
|
+
* @throws {UvlParseError} when `content` is not parseable UVL.
|
|
27
|
+
*/
|
|
28
|
+
export declare const convertFeatureModel: ({ content, from, to }: {
|
|
29
|
+
content: string;
|
|
30
|
+
from: FeatureModelType;
|
|
31
|
+
to: FeatureModelType;
|
|
32
|
+
}) => {
|
|
33
|
+
content: string;
|
|
34
|
+
type: FeatureModelType;
|
|
35
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Feature model notation conversion.
|
|
3
|
+
*
|
|
4
|
+
* Migrated from `linea/server/src/model/services/LineService.js:convertFeatureModel`
|
|
5
|
+
* (~421-461), keeping ONLY the domain logic. Everything around it belongs to
|
|
6
|
+
* linea-server (ADR-003): permission checks, the GitLab commit that creates the
|
|
7
|
+
* new file and deletes the old one, the line version bump (`incrementVersion`)
|
|
8
|
+
* and the Mongo transaction.
|
|
9
|
+
*
|
|
10
|
+
* Note that the monolith derives the target notation from the line's current
|
|
11
|
+
* `featureModelType`; here both ends are explicit parameters, so the caller can
|
|
12
|
+
* convert a document it holds in memory without owning a line.
|
|
13
|
+
*/
|
|
14
|
+
import { isFeatureModelType } from '../constants.js';
|
|
15
|
+
import { InvalidArgumentError, UnsupportedConversionError } from '../errors.js';
|
|
16
|
+
import { modelToUvl, modelToXml } from './engine.js';
|
|
17
|
+
import { parseFeatureModel } from './parse.js';
|
|
18
|
+
/**
|
|
19
|
+
* Converts a feature model between UVL and XML.
|
|
20
|
+
*
|
|
21
|
+
* @param params.content Model document as plain text.
|
|
22
|
+
* @param params.from Notation of `content`.
|
|
23
|
+
* @param params.to Target notation.
|
|
24
|
+
* @returns The converted document and its notation.
|
|
25
|
+
* @throws {UnsupportedConversionError} when `from` equals `to` — there is no
|
|
26
|
+
* such thing as a UVL-to-UVL conversion, and silently returning the input
|
|
27
|
+
* would hide a caller bug.
|
|
28
|
+
* @throws {InvalidArgumentError} when a notation is unknown.
|
|
29
|
+
* @throws {UvlParseError} when `content` is not parseable UVL.
|
|
30
|
+
*/
|
|
31
|
+
export const convertFeatureModel = ({ content, from, to }) => {
|
|
32
|
+
if (!isFeatureModelType(from)) {
|
|
33
|
+
throw new InvalidArgumentError(`Unknown source feature model type "${String(from)}". Use "UVL" or "XML".`);
|
|
34
|
+
}
|
|
35
|
+
if (!isFeatureModelType(to)) {
|
|
36
|
+
throw new InvalidArgumentError(`Unknown target feature model type "${String(to)}". Use "UVL" or "XML".`);
|
|
37
|
+
}
|
|
38
|
+
if (from === to) {
|
|
39
|
+
throw new UnsupportedConversionError(`Cannot convert a feature model from "${from}" to itself.`);
|
|
40
|
+
}
|
|
41
|
+
const model = parseFeatureModel({ content, type: from });
|
|
42
|
+
return {
|
|
43
|
+
content: to === 'UVL' ? modelToUvl(model) : modelToXml(model),
|
|
44
|
+
type: to
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=convert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.js","sourceRoot":"","sources":["../../src/feature-model/convert.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,kBAAkB,EAAyB,MAAM,iBAAiB,CAAA;AAC3E,OAAO,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAA;AAC/E,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAE9C;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,EAClC,OAAO,EACP,IAAI,EACJ,EAAE,EAKH,EAA+C,EAAE;IAChD,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,oBAAoB,CAAC,sCAAsC,MAAM,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAA;IAC5G,CAAC;IACD,IAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,oBAAoB,CAAC,sCAAsC,MAAM,CAAC,EAAE,CAAC,wBAAwB,CAAC,CAAA;IAC1G,CAAC;IACD,IAAI,IAAI,KAAK,EAAE,EAAE,CAAC;QAChB,MAAM,IAAI,0BAA0B,CAAC,wCAAwC,IAAI,cAAc,CAAC,CAAA;IAClG,CAAC;IAED,MAAM,KAAK,GAAG,iBAAiB,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;IACxD,OAAO;QACL,OAAO,EAAE,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC;QAC7D,IAAI,EAAE,EAAE;KACT,CAAA;AACH,CAAC,CAAA","sourcesContent":["/**\r\n * Feature model notation conversion.\r\n *\r\n * Migrated from `linea/server/src/model/services/LineService.js:convertFeatureModel`\r\n * (~421-461), keeping ONLY the domain logic. Everything around it belongs to\r\n * linea-server (ADR-003): permission checks, the GitLab commit that creates the\r\n * new file and deletes the old one, the line version bump (`incrementVersion`)\r\n * and the Mongo transaction.\r\n *\r\n * Note that the monolith derives the target notation from the line's current\r\n * `featureModelType`; here both ends are explicit parameters, so the caller can\r\n * convert a document it holds in memory without owning a line.\r\n */\r\nimport { isFeatureModelType, type FeatureModelType } from '../constants.js'\r\nimport { InvalidArgumentError, UnsupportedConversionError } from '../errors.js'\r\nimport { modelToUvl, modelToXml } from './engine.js'\r\nimport { parseFeatureModel } from './parse.js'\r\n\r\n/**\r\n * Converts a feature model between UVL and XML.\r\n *\r\n * @param params.content Model document as plain text.\r\n * @param params.from Notation of `content`.\r\n * @param params.to Target notation.\r\n * @returns The converted document and its notation.\r\n * @throws {UnsupportedConversionError} when `from` equals `to` — there is no\r\n * such thing as a UVL-to-UVL conversion, and silently returning the input\r\n * would hide a caller bug.\r\n * @throws {InvalidArgumentError} when a notation is unknown.\r\n * @throws {UvlParseError} when `content` is not parseable UVL.\r\n */\r\nexport const convertFeatureModel = ({\r\n content,\r\n from,\r\n to\r\n}: {\r\n content: string\r\n from: FeatureModelType\r\n to: FeatureModelType\r\n}): { content: string, type: FeatureModelType } => {\r\n if (!isFeatureModelType(from)) {\r\n throw new InvalidArgumentError(`Unknown source feature model type \"${String(from)}\". Use \"UVL\" or \"XML\".`)\r\n }\r\n if (!isFeatureModelType(to)) {\r\n throw new InvalidArgumentError(`Unknown target feature model type \"${String(to)}\". Use \"UVL\" or \"XML\".`)\r\n }\r\n if (from === to) {\r\n throw new UnsupportedConversionError(`Cannot convert a feature model from \"${from}\" to itself.`)\r\n }\r\n\r\n const model = parseFeatureModel({ content, type: from })\r\n return {\r\n content: to === 'UVL' ? modelToUvl(model) : modelToXml(model),\r\n type: to\r\n }\r\n}\r\n"]}
|