@lbdudc/linea-core 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +132 -260
- package/dist/analysis/analyze.d.ts +0 -54
- package/dist/analysis/analyze.js +1 -70
- package/dist/analysis/analyze.js.map +1 -1
- package/dist/analysis/runtime.d.ts +4 -73
- package/dist/analysis/runtime.js +7 -100
- package/dist/analysis/runtime.js.map +1 -1
- package/dist/analysis/uvl-text.d.ts +8 -0
- package/dist/analysis/uvl-text.js +70 -0
- package/dist/analysis/uvl-text.js.map +1 -0
- package/dist/assets.d.ts +0 -12
- package/dist/assets.js +0 -25
- package/dist/assets.js.map +1 -1
- package/dist/ci/annotations.d.ts +6 -0
- package/dist/ci/annotations.js +12 -0
- package/dist/ci/annotations.js.map +1 -0
- package/dist/ci/leftovers.d.ts +25 -0
- package/dist/ci/leftovers.js +50 -0
- package/dist/ci/leftovers.js.map +1 -0
- package/dist/ci/pairwise.d.ts +11 -0
- package/dist/ci/pairwise.js +35 -0
- package/dist/ci/pairwise.js.map +1 -0
- package/dist/ci/pipeline.d.ts +18 -0
- package/dist/ci/pipeline.js +26 -0
- package/dist/ci/pipeline.js.map +1 -0
- package/dist/ci/select.d.ts +28 -0
- package/dist/ci/select.js +43 -0
- package/dist/ci/select.js.map +1 -0
- package/dist/ci/validate-specs.d.ts +52 -0
- package/dist/ci/validate-specs.js +212 -0
- package/dist/ci/validate-specs.js.map +1 -0
- package/dist/constants.d.ts +1 -60
- package/dist/constants.js +1 -58
- package/dist/constants.js.map +1 -1
- package/dist/derivation/derive.d.ts +0 -56
- package/dist/derivation/derive.js +21 -72
- package/dist/derivation/derive.js.map +1 -1
- package/dist/derivation/engine.d.ts +10 -42
- package/dist/derivation/engine.js +37 -68
- package/dist/derivation/engine.js.map +1 -1
- package/dist/derivation/selection-error.d.ts +7 -0
- package/dist/derivation/selection-error.js +13 -0
- package/dist/derivation/selection-error.js.map +1 -0
- package/dist/errors.d.ts +19 -47
- package/dist/errors.js +28 -47
- package/dist/errors.js.map +1 -1
- package/dist/feature-model/uvl.d.ts +52 -0
- package/dist/feature-model/uvl.js +191 -0
- package/dist/feature-model/uvl.js.map +1 -0
- package/dist/fs/archive.d.ts +0 -16
- package/dist/fs/archive.js +0 -36
- package/dist/fs/archive.js.map +1 -1
- package/dist/fs/diff.d.ts +0 -30
- package/dist/fs/diff.js +4 -65
- package/dist/fs/diff.js.map +1 -1
- package/dist/fs/format.d.ts +0 -16
- package/dist/fs/format.js +0 -52
- package/dist/fs/format.js.map +1 -1
- package/dist/fs/workspace.d.ts +0 -52
- package/dist/fs/workspace.js +0 -56
- package/dist/fs/workspace.js.map +1 -1
- package/dist/index.d.ts +23 -29
- package/dist/index.js +15 -35
- package/dist/index.js.map +1 -1
- package/dist/internal/guards.d.ts +0 -13
- package/dist/internal/guards.js +0 -13
- package/dist/internal/guards.js.map +1 -1
- package/dist/line/deletion.d.ts +33 -0
- package/dist/line/deletion.js +23 -0
- package/dist/line/deletion.js.map +1 -0
- package/dist/line/platform-files.d.ts +15 -64
- package/dist/line/platform-files.js +18 -94
- package/dist/line/platform-files.js.map +1 -1
- package/dist/line/restoration.d.ts +27 -0
- package/dist/line/restoration.js +27 -0
- package/dist/line/restoration.js.map +1 -0
- package/dist/line/scaffold.d.ts +26 -57
- package/dist/line/scaffold.js +32 -93
- package/dist/line/scaffold.js.map +1 -1
- package/dist/line/templates/core/transformation.js +17 -5
- package/dist/line/templates/pipeline/github-ci.yml +50 -0
- package/dist/line/templates/pipeline/spl-gitlab-ci.yml +182 -0
- package/dist/modules/configuration/configure.d.ts +52 -0
- package/dist/modules/configuration/configure.js +101 -0
- package/dist/modules/configuration/configure.js.map +1 -0
- package/dist/modules/configuration/constants.d.ts +17 -0
- package/dist/modules/configuration/constants.js +14 -0
- package/dist/modules/configuration/constants.js.map +1 -0
- package/dist/modules/configuration/index.d.ts +6 -0
- package/dist/modules/configuration/index.js +5 -0
- package/dist/modules/configuration/index.js.map +1 -0
- package/dist/modules/configuration/names.d.ts +9 -0
- package/dist/modules/configuration/names.js +7 -0
- package/dist/modules/configuration/names.js.map +1 -0
- package/dist/modules/configuration/selection.d.ts +32 -0
- package/dist/modules/configuration/selection.js +49 -0
- package/dist/modules/configuration/selection.js.map +1 -0
- package/dist/modules/diagnostics.d.ts +2 -0
- package/dist/modules/diagnostics.js +2 -0
- package/dist/modules/diagnostics.js.map +1 -0
- package/dist/modules/index.d.ts +18 -0
- package/dist/modules/index.js +18 -0
- package/dist/modules/index.js.map +1 -0
- package/dist/modules/metamodels/engine.d.ts +93 -0
- package/dist/modules/metamodels/engine.js +10 -0
- package/dist/modules/metamodels/engine.js.map +1 -0
- package/dist/modules/metamodels/files.d.ts +40 -0
- package/dist/modules/metamodels/files.js +58 -0
- package/dist/modules/metamodels/files.js.map +1 -0
- package/dist/modules/metamodels/index.d.ts +8 -0
- package/dist/modules/metamodels/index.js +5 -0
- package/dist/modules/metamodels/index.js.map +1 -0
- package/dist/modules/metamodels/layout.d.ts +23 -0
- package/dist/modules/metamodels/layout.js +29 -0
- package/dist/modules/metamodels/layout.js.map +1 -0
- package/dist/modules/metamodels/offered.d.ts +15 -0
- package/dist/modules/metamodels/offered.js +14 -0
- package/dist/modules/metamodels/offered.js.map +1 -0
- package/dist/modules/metamodels/prepare.d.ts +20 -0
- package/dist/modules/metamodels/prepare.js +155 -0
- package/dist/modules/metamodels/prepare.js.map +1 -0
- package/dist/modules/packages/index.d.ts +4 -0
- package/dist/modules/packages/index.js +4 -0
- package/dist/modules/packages/index.js.map +1 -0
- package/dist/modules/packages/location.d.ts +21 -0
- package/dist/modules/packages/location.js +34 -0
- package/dist/modules/packages/location.js.map +1 -0
- package/dist/modules/packages/manifests.d.ts +33 -0
- package/dist/modules/packages/manifests.js +231 -0
- package/dist/modules/packages/manifests.js.map +1 -0
- package/dist/modules/packages/source.d.ts +34 -0
- package/dist/modules/packages/source.js +128 -0
- package/dist/modules/packages/source.js.map +1 -0
- package/dist/modules/products/check.d.ts +28 -0
- package/dist/modules/products/check.js +61 -0
- package/dist/modules/products/check.js.map +1 -0
- package/dist/modules/products/derive.d.ts +30 -0
- package/dist/modules/products/derive.js +56 -0
- package/dist/modules/products/derive.js.map +1 -0
- package/dist/modules/products/index.d.ts +5 -0
- package/dist/modules/products/index.js +4 -0
- package/dist/modules/products/index.js.map +1 -0
- package/dist/modules/products/seed.d.ts +18 -0
- package/dist/modules/products/seed.js +23 -0
- package/dist/modules/products/seed.js.map +1 -0
- package/dist/modules/registry/catalog.d.ts +64 -0
- package/dist/modules/registry/catalog.js +91 -0
- package/dist/modules/registry/catalog.js.map +1 -0
- package/dist/modules/registry/index.d.ts +5 -0
- package/dist/modules/registry/index.js +4 -0
- package/dist/modules/registry/index.js.map +1 -0
- package/dist/modules/registry/registry.d.ts +34 -0
- package/dist/modules/registry/registry.js +37 -0
- package/dist/modules/registry/registry.js.map +1 -0
- package/dist/modules/registry/routing.d.ts +8 -0
- package/dist/modules/registry/routing.js +23 -0
- package/dist/modules/registry/routing.js.map +1 -0
- package/dist/modules/resolution/closure.d.ts +28 -0
- package/dist/modules/resolution/closure.js +105 -0
- package/dist/modules/resolution/closure.js.map +1 -0
- package/dist/modules/resolution/index.d.ts +4 -0
- package/dist/modules/resolution/index.js +3 -0
- package/dist/modules/resolution/index.js.map +1 -0
- package/dist/modules/resolution/resolve.d.ts +33 -0
- package/dist/modules/resolution/resolve.js +59 -0
- package/dist/modules/resolution/resolve.js.map +1 -0
- package/dist/modules/resolution/resolvers.d.ts +23 -0
- package/dist/modules/resolution/resolvers.js +34 -0
- package/dist/modules/resolution/resolvers.js.map +1 -0
- package/dist/modules/spl/check.d.ts +25 -0
- package/dist/modules/spl/check.js +21 -0
- package/dist/modules/spl/check.js.map +1 -0
- package/dist/modules/spl/cip.d.ts +67 -0
- package/dist/modules/spl/cip.js +98 -0
- package/dist/modules/spl/cip.js.map +1 -0
- package/dist/modules/spl/feature-model.d.ts +39 -0
- package/dist/modules/spl/feature-model.js +106 -0
- package/dist/modules/spl/feature-model.js.map +1 -0
- package/dist/modules/spl/index.d.ts +6 -0
- package/dist/modules/spl/index.js +4 -0
- package/dist/modules/spl/index.js.map +1 -0
- package/dist/modules/spl/platform.d.ts +49 -0
- package/dist/modules/spl/platform.js +316 -0
- package/dist/modules/spl/platform.js.map +1 -0
- package/dist/modules/types.d.ts +132 -0
- package/dist/modules/types.js +2 -0
- package/dist/modules/types.js.map +1 -0
- package/dist/product/engine-spec.d.ts +0 -16
- package/dist/product/engine-spec.js +4 -50
- package/dist/product/engine-spec.js.map +1 -1
- package/dist/product/spec.d.ts +0 -82
- package/dist/product/spec.js +0 -79
- package/dist/product/spec.js.map +1 -1
- package/dist/product/version.d.ts +0 -23
- package/dist/product/version.js +0 -28
- package/dist/product/version.js.map +1 -1
- package/dist/products-index/products-index.d.ts +0 -165
- package/dist/products-index/products-index.js +0 -176
- package/dist/products-index/products-index.js.map +1 -1
- package/dist/workspace/context.d.ts +25 -0
- package/dist/workspace/context.js +43 -0
- package/dist/workspace/context.js.map +1 -0
- package/dist/workspace/gitExclude.d.ts +2 -0
- package/dist/workspace/gitExclude.js +19 -0
- package/dist/workspace/gitExclude.js.map +1 -0
- package/dist/workspace/host.d.ts +14 -0
- package/dist/workspace/host.js +13 -0
- package/dist/workspace/host.js.map +1 -0
- package/dist/workspace/index.d.ts +12 -0
- package/dist/workspace/index.js +12 -0
- package/dist/workspace/index.js.map +1 -0
- package/dist/workspace/local.d.ts +81 -0
- package/dist/workspace/local.js +287 -0
- package/dist/workspace/local.js.map +1 -0
- package/dist/workspace/modular.d.ts +95 -0
- package/dist/workspace/modular.js +301 -0
- package/dist/workspace/modular.js.map +1 -0
- package/dist/workspace/operations.d.ts +35 -0
- package/dist/workspace/operations.js +57 -0
- package/dist/workspace/operations.js.map +1 -0
- package/dist/workspace/origin.d.ts +20 -0
- package/dist/workspace/origin.js +19 -0
- package/dist/workspace/origin.js.map +1 -0
- package/package.json +22 -7
- package/dist/feature-model/convert.d.ts +0 -35
- package/dist/feature-model/convert.js +0 -47
- package/dist/feature-model/convert.js.map +0 -1
- package/dist/feature-model/engine.d.ts +0 -60
- package/dist/feature-model/engine.js +0 -139
- package/dist/feature-model/engine.js.map +0 -1
- package/dist/feature-model/inspect.d.ts +0 -67
- package/dist/feature-model/inspect.js +0 -113
- package/dist/feature-model/inspect.js.map +0 -1
- package/dist/feature-model/io.d.ts +0 -66
- package/dist/feature-model/io.js +0 -92
- package/dist/feature-model/io.js.map +0 -1
- package/dist/feature-model/parse.d.ts +0 -30
- package/dist/feature-model/parse.js +0 -36
- package/dist/feature-model/parse.js.map +0 -1
- package/dist/feature-model/text.d.ts +0 -54
- package/dist/feature-model/text.js +0 -126
- package/dist/feature-model/text.js.map +0 -1
- package/dist/line/templates/metamodels/dataModel/extra.js +0 -328
- package/dist/line/templates/metamodels/dataModel/transformation.js +0 -211
- package/dist/line/templates/metamodels/sensor/extra.js +0 -36
- package/dist/line/templates/metamodels/sensor/transformation.js +0 -47
- package/dist/selection/selection.d.ts +0 -126
- package/dist/selection/selection.js +0 -152
- package/dist/selection/selection.js.map +0 -1
|
@@ -1,47 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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":["/**\n * Feature model notation conversion.\n *\n * Migrated from `linea/server/src/model/services/LineService.js:convertFeatureModel`\n * (~421-461), keeping ONLY the domain logic. Everything around it belongs to\n * linea-server (ADR-003): permission checks, the GitLab commit that creates the\n * new file and deletes the old one, the line version bump (`incrementVersion`)\n * and the Mongo transaction.\n *\n * Note that the monolith derives the target notation from the line's current\n * `featureModelType`; here both ends are explicit parameters, so the caller can\n * convert a document it holds in memory without owning a line.\n */\nimport { isFeatureModelType, type FeatureModelType } from '../constants.js'\nimport { InvalidArgumentError, UnsupportedConversionError } from '../errors.js'\nimport { modelToUvl, modelToXml } from './engine.js'\nimport { parseFeatureModel } from './parse.js'\n\n/**\n * Converts a feature model between UVL and XML.\n *\n * @param params.content Model document as plain text.\n * @param params.from Notation of `content`.\n * @param params.to Target notation.\n * @returns The converted document and its notation.\n * @throws {UnsupportedConversionError} when `from` equals `to` — there is no\n * such thing as a UVL-to-UVL conversion, and silently returning the input\n * would hide a caller bug.\n * @throws {InvalidArgumentError} when a notation is unknown.\n * @throws {UvlParseError} when `content` is not parseable UVL.\n */\nexport const convertFeatureModel = ({\n content,\n from,\n to\n}: {\n content: string\n from: FeatureModelType\n to: FeatureModelType\n}): { content: string, type: FeatureModelType } => {\n if (!isFeatureModelType(from)) {\n throw new InvalidArgumentError(`Unknown source feature model type \"${String(from)}\". Use \"UVL\" or \"XML\".`)\n }\n if (!isFeatureModelType(to)) {\n throw new InvalidArgumentError(`Unknown target feature model type \"${String(to)}\". Use \"UVL\" or \"XML\".`)\n }\n if (from === to) {\n throw new UnsupportedConversionError(`Cannot convert a feature model from \"${from}\" to itself.`)\n }\n\n const model = parseFeatureModel({ content, type: from })\n return {\n content: to === 'UVL' ? modelToUvl(model) : modelToXml(model),\n type: to\n }\n}\n"]}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import type { FeatureModelType } from '../constants.js';
|
|
2
|
-
declare const featureModelBrand: unique symbol;
|
|
3
|
-
/**
|
|
4
|
-
* A parsed feature model.
|
|
5
|
-
*
|
|
6
|
-
* Opaque on purpose: it is really a `FeatureModel` from `spl-js-engine`, but
|
|
7
|
-
* that type is not part of linea-core's contract. Pass the value back into
|
|
8
|
-
* linea-core functions; do not introspect it.
|
|
9
|
-
*/
|
|
10
|
-
export interface FeatureModelValue {
|
|
11
|
-
readonly [featureModelBrand]: 'linea-core/FeatureModel';
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Parses UVL or XML text into an opaque model value.
|
|
15
|
-
*
|
|
16
|
-
* Guards three engine quirks:
|
|
17
|
-
* - `FeatureModel.fromUVL` accepts a *path or* text. Neutralised by
|
|
18
|
-
* `asUvlContent`: whatever the caller passes is parsed as a document, and no
|
|
19
|
-
* file is ever opened.
|
|
20
|
-
* - The same path probe writes the entire document to stderr; see
|
|
21
|
-
* `withoutPathProbeNoise`.
|
|
22
|
-
* - `DerivationEngine.setFeatureModel` sniffs the notation with
|
|
23
|
-
* `featureModel.endsWith('uvl')` over the *content*. linea-core never relies
|
|
24
|
-
* on that: the notation is always an explicit parameter.
|
|
25
|
-
*/
|
|
26
|
-
export declare const parseModel: (content: string, type: FeatureModelType) => FeatureModelValue;
|
|
27
|
-
/** Serialises a model to UVL. */
|
|
28
|
-
export declare const modelToUvl: (value: FeatureModelValue) => string;
|
|
29
|
-
/** Serialises a model to XML. */
|
|
30
|
-
export declare const modelToXml: (value: FeatureModelValue) => string;
|
|
31
|
-
/** How a feature selection failed, normalised away from the engine's own shape. */
|
|
32
|
-
export interface SelectionFailure {
|
|
33
|
-
/** Human-readable reason. Never empty. */
|
|
34
|
-
readonly message: string;
|
|
35
|
-
/** Engine discriminator: `'TOO_MANY_CHILDS'`, `'MISSING_CHILD'`, or `null`. */
|
|
36
|
-
readonly errorType: string | null;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Whether `error` is the engine's `FeatureSelectionError`.
|
|
40
|
-
*
|
|
41
|
-
* Needed because it does not extend `Error`, so no generic guard identifies it.
|
|
42
|
-
* `runEngine` and `generateZip` in the monolith branch on exactly this check.
|
|
43
|
-
*/
|
|
44
|
-
export declare const isFeatureSelectionError: (error: unknown) => boolean;
|
|
45
|
-
/**
|
|
46
|
-
* Classifies whatever `completeSelection` threw.
|
|
47
|
-
*
|
|
48
|
-
* `FeatureSelectionError` does NOT extend `Error`, so an `instanceof Error`
|
|
49
|
-
* branch falls through to `String(err)` for the very error it cares about. The
|
|
50
|
-
* message survives that (the class defines `toString()`), but **`errorType` does
|
|
51
|
-
* not**: the `TOO_MANY_CHILDS` / `MISSING_CHILD` discriminator is silently lost.
|
|
52
|
-
* Checked explicitly here so callers can branch on it.
|
|
53
|
-
*/
|
|
54
|
-
export declare const describeSelectionFailure: (error: unknown) => SelectionFailure;
|
|
55
|
-
/**
|
|
56
|
-
* Expands a partial selection into the full set of implied features.
|
|
57
|
-
* @throws the engine's `FeatureSelectionError` when the selection is invalid.
|
|
58
|
-
*/
|
|
59
|
-
export declare const completeSelection: (value: FeatureModelValue, features: string[]) => string[];
|
|
60
|
-
export {};
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* INTERNAL adapter over `spl-js-engine`. This is the ONLY module in linea-core
|
|
3
|
-
* that imports the engine.
|
|
4
|
-
*
|
|
5
|
-
* Two reasons for the isolation:
|
|
6
|
-
*
|
|
7
|
-
* 1. The engine ships no types, so its declarations are hand-written
|
|
8
|
-
* (`src/types/spl-js-engine.d.ts`). Keeping every engine type out of the
|
|
9
|
-
* exported signatures below guarantees that no emitted `.d.ts` in `dist/`
|
|
10
|
-
* ever references `spl-js-engine` — consumers do not need our ambient
|
|
11
|
-
* declarations, and `skipLibCheck: false` on their side still works.
|
|
12
|
-
*
|
|
13
|
-
* 2. The engine API has sharp edges that must not reach linea-core's public
|
|
14
|
-
* surface (see `parseFeatureModel`).
|
|
15
|
-
*
|
|
16
|
-
* Not exported from `src/index.ts`.
|
|
17
|
-
*/
|
|
18
|
-
import { FeatureModel } from 'spl-js-engine';
|
|
19
|
-
import FeatureSelectionError from 'spl-js-engine/src/feature-model/feature-selection-error.js';
|
|
20
|
-
import { InvalidArgumentError, UvlParseError } from '../errors.js';
|
|
21
|
-
const toEngineModel = (value) => value;
|
|
22
|
-
const toValue = (model) => model;
|
|
23
|
-
const describe = (error) => error instanceof Error ? error.message : String(error);
|
|
24
|
-
/**
|
|
25
|
-
* Upstream noise filter for UVL parsing.
|
|
26
|
-
*
|
|
27
|
-
* `uvl-parser/src/FeatureModel.js:22-28` decides whether its argument is a path
|
|
28
|
-
* by calling `fs.statSync(str)` inside a try/catch that does
|
|
29
|
-
* `console.error('Error: ' + e)` before returning false. A UVL document is never
|
|
30
|
-
* a valid path, so EVERY successful parse dumps the whole model to stderr. For a
|
|
31
|
-
* library embedded in a TUI (linea-cli) that is corrupting output, not logging.
|
|
32
|
-
*
|
|
33
|
-
* This wrapper swallows exactly that message and forwards anything else. It is
|
|
34
|
-
* safe despite touching a global: `FeatureModel.fromUVL` is fully synchronous,
|
|
35
|
-
* so no other task can interleave, and the original `console.error` is restored
|
|
36
|
-
* in `finally`.
|
|
37
|
-
*/
|
|
38
|
-
const PARSER_PATH_PROBE_NOISE = /^Error: Error: (ENOENT|ENAMETOOLONG|ERR_INVALID_ARG_VALUE)/;
|
|
39
|
-
const withoutPathProbeNoise = (run) => {
|
|
40
|
-
const original = console.error;
|
|
41
|
-
console.error = (...args) => {
|
|
42
|
-
const first = args[0];
|
|
43
|
-
if (typeof first === 'string' && PARSER_PATH_PROBE_NOISE.test(first))
|
|
44
|
-
return;
|
|
45
|
-
original(...args);
|
|
46
|
-
};
|
|
47
|
-
try {
|
|
48
|
-
return run();
|
|
49
|
-
}
|
|
50
|
-
finally {
|
|
51
|
-
console.error = original;
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
/**
|
|
55
|
-
* Forces `FeatureModel.fromUVL` to treat its argument as CONTENT, never as a path.
|
|
56
|
-
*
|
|
57
|
-
* `uvl-parser` decides with `fs.statSync(str)`: when the string happens to name
|
|
58
|
-
* an existing file it reads that file through `antlr4.FileStream` instead of
|
|
59
|
-
* parsing what it was given. Since linea-server hands user-controlled bodies to
|
|
60
|
-
* `PUT /api/lines/:id/model` and `POST /api/lines/:id/model/convert` straight
|
|
61
|
-
* into these functions, that is an arbitrary-file-read primitive — and relative
|
|
62
|
-
* paths would resolve against `process.cwd()`, breaking the "no ambient state"
|
|
63
|
-
* invariant of ADR-009/ADR-014.
|
|
64
|
-
*
|
|
65
|
-
* A trailing newline makes `statSync` fail with ENOENT on both Windows and
|
|
66
|
-
* Linux, and is semantically inert in UVL. The monolith carries the same defect;
|
|
67
|
-
* linea-core is the layer that closes it.
|
|
68
|
-
*
|
|
69
|
-
* Appended UNCONDITIONALLY. A "only if it does not already end in \n" guard
|
|
70
|
-
* would leave a gap on Linux, where a file name may legally contain a newline,
|
|
71
|
-
* so `"/tmp/evil\n"` would reach `statSync` untouched. A doubled trailing
|
|
72
|
-
* newline is inert in UVL, so there is nothing to trade off.
|
|
73
|
-
*/
|
|
74
|
-
const asUvlContent = (content) => `${content}\n`;
|
|
75
|
-
/**
|
|
76
|
-
* Parses UVL or XML text into an opaque model value.
|
|
77
|
-
*
|
|
78
|
-
* Guards three engine quirks:
|
|
79
|
-
* - `FeatureModel.fromUVL` accepts a *path or* text. Neutralised by
|
|
80
|
-
* `asUvlContent`: whatever the caller passes is parsed as a document, and no
|
|
81
|
-
* file is ever opened.
|
|
82
|
-
* - The same path probe writes the entire document to stderr; see
|
|
83
|
-
* `withoutPathProbeNoise`.
|
|
84
|
-
* - `DerivationEngine.setFeatureModel` sniffs the notation with
|
|
85
|
-
* `featureModel.endsWith('uvl')` over the *content*. linea-core never relies
|
|
86
|
-
* on that: the notation is always an explicit parameter.
|
|
87
|
-
*/
|
|
88
|
-
export const parseModel = (content, type) => {
|
|
89
|
-
try {
|
|
90
|
-
return toValue(type === 'XML'
|
|
91
|
-
? FeatureModel.fromXml(content)
|
|
92
|
-
: withoutPathProbeNoise(() => FeatureModel.fromUVL(asUvlContent(content))));
|
|
93
|
-
}
|
|
94
|
-
catch (error) {
|
|
95
|
-
if (type === 'XML') {
|
|
96
|
-
throw new InvalidArgumentError(`Could not parse the XML feature model: ${describe(error)}`, {
|
|
97
|
-
cause: error
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
throw new UvlParseError(`Could not parse the UVL feature model: ${describe(error)}`, {
|
|
101
|
-
cause: error
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
/** Serialises a model to UVL. */
|
|
106
|
-
export const modelToUvl = (value) => toEngineModel(value).toUVL();
|
|
107
|
-
/** Serialises a model to XML. */
|
|
108
|
-
export const modelToXml = (value) => toEngineModel(value).toXml();
|
|
109
|
-
/**
|
|
110
|
-
* Whether `error` is the engine's `FeatureSelectionError`.
|
|
111
|
-
*
|
|
112
|
-
* Needed because it does not extend `Error`, so no generic guard identifies it.
|
|
113
|
-
* `runEngine` and `generateZip` in the monolith branch on exactly this check.
|
|
114
|
-
*/
|
|
115
|
-
export const isFeatureSelectionError = (error) => error instanceof FeatureSelectionError;
|
|
116
|
-
/**
|
|
117
|
-
* Classifies whatever `completeSelection` threw.
|
|
118
|
-
*
|
|
119
|
-
* `FeatureSelectionError` does NOT extend `Error`, so an `instanceof Error`
|
|
120
|
-
* branch falls through to `String(err)` for the very error it cares about. The
|
|
121
|
-
* message survives that (the class defines `toString()`), but **`errorType` does
|
|
122
|
-
* not**: the `TOO_MANY_CHILDS` / `MISSING_CHILD` discriminator is silently lost.
|
|
123
|
-
* Checked explicitly here so callers can branch on it.
|
|
124
|
-
*/
|
|
125
|
-
export const describeSelectionFailure = (error) => {
|
|
126
|
-
if (error instanceof FeatureSelectionError) {
|
|
127
|
-
return { message: error.message, errorType: error.errorType ?? null };
|
|
128
|
-
}
|
|
129
|
-
if (error instanceof Error) {
|
|
130
|
-
return { message: error.message, errorType: null };
|
|
131
|
-
}
|
|
132
|
-
return { message: String(error), errorType: null };
|
|
133
|
-
};
|
|
134
|
-
/**
|
|
135
|
-
* Expands a partial selection into the full set of implied features.
|
|
136
|
-
* @throws the engine's `FeatureSelectionError` when the selection is invalid.
|
|
137
|
-
*/
|
|
138
|
-
export const completeSelection = (value, features) => toEngineModel(value).completeFeatureSelection(features);
|
|
139
|
-
//# sourceMappingURL=engine.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/feature-model/engine.ts"],"names":[],"mappings":"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","sourcesContent":["/**\n * INTERNAL adapter over `spl-js-engine`. This is the ONLY module in linea-core\n * that imports the engine.\n *\n * Two reasons for the isolation:\n *\n * 1. The engine ships no types, so its declarations are hand-written\n * (`src/types/spl-js-engine.d.ts`). Keeping every engine type out of the\n * exported signatures below guarantees that no emitted `.d.ts` in `dist/`\n * ever references `spl-js-engine` — consumers do not need our ambient\n * declarations, and `skipLibCheck: false` on their side still works.\n *\n * 2. The engine API has sharp edges that must not reach linea-core's public\n * surface (see `parseFeatureModel`).\n *\n * Not exported from `src/index.ts`.\n */\nimport { FeatureModel } from 'spl-js-engine'\nimport FeatureSelectionError from 'spl-js-engine/src/feature-model/feature-selection-error.js'\nimport type { FeatureModelType } from '../constants.js'\nimport { InvalidArgumentError, UvlParseError } from '../errors.js'\n\ndeclare const featureModelBrand: unique symbol\n\n/**\n * A parsed feature model.\n *\n * Opaque on purpose: it is really a `FeatureModel` from `spl-js-engine`, but\n * that type is not part of linea-core's contract. Pass the value back into\n * linea-core functions; do not introspect it.\n */\nexport interface FeatureModelValue {\n readonly [featureModelBrand]: 'linea-core/FeatureModel'\n}\n\nconst toEngineModel = (value: FeatureModelValue): FeatureModel =>\n value as unknown as FeatureModel\n\nconst toValue = (model: FeatureModel): FeatureModelValue =>\n model as unknown as FeatureModelValue\n\nconst describe = (error: unknown): string =>\n error instanceof Error ? error.message : String(error)\n\n/**\n * Upstream noise filter for UVL parsing.\n *\n * `uvl-parser/src/FeatureModel.js:22-28` decides whether its argument is a path\n * by calling `fs.statSync(str)` inside a try/catch that does\n * `console.error('Error: ' + e)` before returning false. A UVL document is never\n * a valid path, so EVERY successful parse dumps the whole model to stderr. For a\n * library embedded in a TUI (linea-cli) that is corrupting output, not logging.\n *\n * This wrapper swallows exactly that message and forwards anything else. It is\n * safe despite touching a global: `FeatureModel.fromUVL` is fully synchronous,\n * so no other task can interleave, and the original `console.error` is restored\n * in `finally`.\n */\nconst PARSER_PATH_PROBE_NOISE = /^Error: Error: (ENOENT|ENAMETOOLONG|ERR_INVALID_ARG_VALUE)/\n\nconst withoutPathProbeNoise = <T>(run: () => T): T => {\n const original = console.error\n console.error = (...args: unknown[]): void => {\n const first = args[0]\n if (typeof first === 'string' && PARSER_PATH_PROBE_NOISE.test(first)) return\n original(...args)\n }\n try {\n return run()\n } finally {\n console.error = original\n }\n}\n\n/**\n * Forces `FeatureModel.fromUVL` to treat its argument as CONTENT, never as a path.\n *\n * `uvl-parser` decides with `fs.statSync(str)`: when the string happens to name\n * an existing file it reads that file through `antlr4.FileStream` instead of\n * parsing what it was given. Since linea-server hands user-controlled bodies to\n * `PUT /api/lines/:id/model` and `POST /api/lines/:id/model/convert` straight\n * into these functions, that is an arbitrary-file-read primitive — and relative\n * paths would resolve against `process.cwd()`, breaking the \"no ambient state\"\n * invariant of ADR-009/ADR-014.\n *\n * A trailing newline makes `statSync` fail with ENOENT on both Windows and\n * Linux, and is semantically inert in UVL. The monolith carries the same defect;\n * linea-core is the layer that closes it.\n *\n * Appended UNCONDITIONALLY. A \"only if it does not already end in \\n\" guard\n * would leave a gap on Linux, where a file name may legally contain a newline,\n * so `\"/tmp/evil\\n\"` would reach `statSync` untouched. A doubled trailing\n * newline is inert in UVL, so there is nothing to trade off.\n */\nconst asUvlContent = (content: string): string => `${content}\\n`\n\n/**\n * Parses UVL or XML text into an opaque model value.\n *\n * Guards three engine quirks:\n * - `FeatureModel.fromUVL` accepts a *path or* text. Neutralised by\n * `asUvlContent`: whatever the caller passes is parsed as a document, and no\n * file is ever opened.\n * - The same path probe writes the entire document to stderr; see\n * `withoutPathProbeNoise`.\n * - `DerivationEngine.setFeatureModel` sniffs the notation with\n * `featureModel.endsWith('uvl')` over the *content*. linea-core never relies\n * on that: the notation is always an explicit parameter.\n */\nexport const parseModel = (content: string, type: FeatureModelType): FeatureModelValue => {\n try {\n return toValue(\n type === 'XML'\n ? FeatureModel.fromXml(content)\n : withoutPathProbeNoise(() => FeatureModel.fromUVL(asUvlContent(content)))\n )\n } catch (error) {\n if (type === 'XML') {\n throw new InvalidArgumentError(`Could not parse the XML feature model: ${describe(error)}`, {\n cause: error\n })\n }\n throw new UvlParseError(`Could not parse the UVL feature model: ${describe(error)}`, {\n cause: error\n })\n }\n}\n\n/** Serialises a model to UVL. */\nexport const modelToUvl = (value: FeatureModelValue): string => toEngineModel(value).toUVL()\n\n/** Serialises a model to XML. */\nexport const modelToXml = (value: FeatureModelValue): string => toEngineModel(value).toXml()\n\n/** How a feature selection failed, normalised away from the engine's own shape. */\nexport interface SelectionFailure {\n /** Human-readable reason. Never empty. */\n readonly message: string\n /** Engine discriminator: `'TOO_MANY_CHILDS'`, `'MISSING_CHILD'`, or `null`. */\n readonly errorType: string | null\n}\n\n/**\n * Whether `error` is the engine's `FeatureSelectionError`.\n *\n * Needed because it does not extend `Error`, so no generic guard identifies it.\n * `runEngine` and `generateZip` in the monolith branch on exactly this check.\n */\nexport const isFeatureSelectionError = (error: unknown): boolean =>\n error instanceof FeatureSelectionError\n\n/**\n * Classifies whatever `completeSelection` threw.\n *\n * `FeatureSelectionError` does NOT extend `Error`, so an `instanceof Error`\n * branch falls through to `String(err)` for the very error it cares about. The\n * message survives that (the class defines `toString()`), but **`errorType` does\n * not**: the `TOO_MANY_CHILDS` / `MISSING_CHILD` discriminator is silently lost.\n * Checked explicitly here so callers can branch on it.\n */\nexport const describeSelectionFailure = (error: unknown): SelectionFailure => {\n if (error instanceof FeatureSelectionError) {\n return { message: error.message, errorType: error.errorType ?? null }\n }\n if (error instanceof Error) {\n return { message: error.message, errorType: null }\n }\n return { message: String(error), errorType: null }\n}\n\n/**\n * Expands a partial selection into the full set of implied features.\n * @throws the engine's `FeatureSelectionError` when the selection is invalid.\n */\nexport const completeSelection = (value: FeatureModelValue, features: string[]): string[] =>\n toEngineModel(value).completeFeatureSelection(features)\n"]}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Read-only inspection of feature models.
|
|
3
|
-
*
|
|
4
|
-
* Migrated from `linea/server/src/agents/tools/fmAnalysis.js`
|
|
5
|
-
* (`extractFeaturesFromModel`, `computeMandatoryFeatures`). The aggregate
|
|
6
|
-
* portfolio helpers of that file (`computePortfolioAnomalies`,
|
|
7
|
-
* `computePairCoverage`, `findCouplingSmells`) work over product verdicts, not
|
|
8
|
-
* over the model, and belong with the product operations.
|
|
9
|
-
*/
|
|
10
|
-
import { type FeatureModelType } from '../constants.js';
|
|
11
|
-
import { type FeatureModelValue } from './engine.js';
|
|
12
|
-
/**
|
|
13
|
-
* Extracts feature names from a model document without parsing it.
|
|
14
|
-
*
|
|
15
|
-
* Conservative by design, exactly as the monolith documents it: it prefers false
|
|
16
|
-
* positives over false negatives, so a few extra identifiers (type names, for
|
|
17
|
-
* instance) may show up. Callers that need exact names should parse the model
|
|
18
|
-
* and use the engine instead.
|
|
19
|
-
*
|
|
20
|
-
* HARDENED PORT, not a verbatim one. `fmAnalysis.js:extractFeaturesFromModel`
|
|
21
|
-
* coerces the notation with `(type ?? 'UVL').toUpperCase()`, defaulting a
|
|
22
|
-
* missing or lowercase value to UVL. This function requires an exact `'UVL'` or
|
|
23
|
-
* `'XML'` and throws otherwise.
|
|
24
|
-
*
|
|
25
|
-
* That matters when migrating callers: `line.featureModelType` can be
|
|
26
|
-
* `undefined` for lines created before the field existed, which is why
|
|
27
|
-
* `LineService.js:284,401,432` all write `(line.featureModelType ?? 'UVL')`.
|
|
28
|
-
* Applying that same default is now the CALLER's responsibility — whoever ports
|
|
29
|
-
* `lineHealthAgent.js:89` must pass `line.featureModelType ?? 'UVL'` explicitly
|
|
30
|
-
* or they will get an `InvalidArgumentError` on legacy lines.
|
|
31
|
-
*
|
|
32
|
-
* @param params.content Model document as plain text.
|
|
33
|
-
* @param params.type Notation of `content`. Exact, never coerced.
|
|
34
|
-
* @returns Feature names, de-duplicated, in order of first appearance.
|
|
35
|
-
* @throws {InvalidArgumentError} when `content` is not a string or `type` is unknown.
|
|
36
|
-
*/
|
|
37
|
-
export declare const extractFeatureNames: ({ content, type }: {
|
|
38
|
-
content: string;
|
|
39
|
-
type: FeatureModelType;
|
|
40
|
-
}) => string[];
|
|
41
|
-
/** Outcome of probing a model with an empty selection. */
|
|
42
|
-
export interface MandatoryFeaturesResult {
|
|
43
|
-
/** `true` when the model admits no valid configuration at all. */
|
|
44
|
-
readonly voidModel: boolean;
|
|
45
|
-
/** Features implied even by an empty selection. */
|
|
46
|
-
readonly mandatory: string[];
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Probes a model with an empty selection to detect the void-model case and the
|
|
50
|
-
* features that are always present.
|
|
51
|
-
*
|
|
52
|
-
* Port of `fmAnalysis.js:computeMandatoryFeatures`, keeping its
|
|
53
|
-
* degrade-gracefully contract intact: any failure from the ENGINE is reported as
|
|
54
|
-
* `voidModel: true` with an empty `mandatory`, never as a thrown error.
|
|
55
|
-
*
|
|
56
|
-
* HARDENED on one point: the monolith would happily accept a non-model and
|
|
57
|
-
* return `{ voidModel: true }` because its `try` swallows the `TypeError` too.
|
|
58
|
-
* Here an argument that is not a parsed model is a caller bug and throws, so it
|
|
59
|
-
* cannot masquerade as an unsatisfiable model.
|
|
60
|
-
*
|
|
61
|
-
* @param params.model A model returned by `parseFeatureModel`.
|
|
62
|
-
* @returns Whether the model is void, and its mandatory features.
|
|
63
|
-
* @throws {InvalidArgumentError} when `model` did not come from `parseFeatureModel`.
|
|
64
|
-
*/
|
|
65
|
-
export declare const computeMandatoryFeatures: ({ model }: {
|
|
66
|
-
model: FeatureModelValue;
|
|
67
|
-
}) => MandatoryFeaturesResult;
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Read-only inspection of feature models.
|
|
3
|
-
*
|
|
4
|
-
* Migrated from `linea/server/src/agents/tools/fmAnalysis.js`
|
|
5
|
-
* (`extractFeaturesFromModel`, `computeMandatoryFeatures`). The aggregate
|
|
6
|
-
* portfolio helpers of that file (`computePortfolioAnomalies`,
|
|
7
|
-
* `computePairCoverage`, `findCouplingSmells`) work over product verdicts, not
|
|
8
|
-
* over the model, and belong with the product operations.
|
|
9
|
-
*/
|
|
10
|
-
import { isFeatureModelType } from '../constants.js';
|
|
11
|
-
import { InvalidArgumentError } from '../errors.js';
|
|
12
|
-
import { completeSelection } from './engine.js';
|
|
13
|
-
/**
|
|
14
|
-
* UVL tokens that are never feature names.
|
|
15
|
-
* Verbatim from `fmAnalysis.js:UVL_KEYWORDS`.
|
|
16
|
-
*/
|
|
17
|
-
const UVL_KEYWORDS = new Set([
|
|
18
|
-
'features', 'constraints', 'mandatory', 'optional', 'alternative', 'or', 'and',
|
|
19
|
-
'as', 'type', 'String', 'Integer', 'Real', 'Boolean', 'include', 'namespace',
|
|
20
|
-
'cardinality', 'abstract', 'true', 'false', 'null'
|
|
21
|
-
]);
|
|
22
|
-
/** Port of `fmAnalysis.js:parseUvlFeatureNames`; same tokens, same output. */
|
|
23
|
-
const parseUvlFeatureNames = (uvl) => {
|
|
24
|
-
const names = new Set();
|
|
25
|
-
for (const line of uvl.split('\n')) {
|
|
26
|
-
const trimmed = line.trim();
|
|
27
|
-
if (!trimmed || trimmed.startsWith('//') || trimmed.startsWith('#'))
|
|
28
|
-
continue;
|
|
29
|
-
// Namespace declarations are not feature lines.
|
|
30
|
-
if (trimmed.startsWith('namespace'))
|
|
31
|
-
continue;
|
|
32
|
-
for (const match of trimmed.matchAll(/\b([A-Za-z_][A-Za-z0-9_]*)\b/g)) {
|
|
33
|
-
const name = match[1];
|
|
34
|
-
if (name !== undefined && !UVL_KEYWORDS.has(name))
|
|
35
|
-
names.add(name);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return [...names];
|
|
39
|
-
};
|
|
40
|
-
/** Port of `fmAnalysis.js:parseXmlFeatureNames`; same regex, same output. */
|
|
41
|
-
const parseXmlFeatureNames = (xml) => {
|
|
42
|
-
const names = new Set();
|
|
43
|
-
for (const match of xml.matchAll(/\bname="([^"]+)"/g)) {
|
|
44
|
-
const name = match[1];
|
|
45
|
-
if (name !== undefined)
|
|
46
|
-
names.add(name);
|
|
47
|
-
}
|
|
48
|
-
return [...names];
|
|
49
|
-
};
|
|
50
|
-
/**
|
|
51
|
-
* Extracts feature names from a model document without parsing it.
|
|
52
|
-
*
|
|
53
|
-
* Conservative by design, exactly as the monolith documents it: it prefers false
|
|
54
|
-
* positives over false negatives, so a few extra identifiers (type names, for
|
|
55
|
-
* instance) may show up. Callers that need exact names should parse the model
|
|
56
|
-
* and use the engine instead.
|
|
57
|
-
*
|
|
58
|
-
* HARDENED PORT, not a verbatim one. `fmAnalysis.js:extractFeaturesFromModel`
|
|
59
|
-
* coerces the notation with `(type ?? 'UVL').toUpperCase()`, defaulting a
|
|
60
|
-
* missing or lowercase value to UVL. This function requires an exact `'UVL'` or
|
|
61
|
-
* `'XML'` and throws otherwise.
|
|
62
|
-
*
|
|
63
|
-
* That matters when migrating callers: `line.featureModelType` can be
|
|
64
|
-
* `undefined` for lines created before the field existed, which is why
|
|
65
|
-
* `LineService.js:284,401,432` all write `(line.featureModelType ?? 'UVL')`.
|
|
66
|
-
* Applying that same default is now the CALLER's responsibility — whoever ports
|
|
67
|
-
* `lineHealthAgent.js:89` must pass `line.featureModelType ?? 'UVL'` explicitly
|
|
68
|
-
* or they will get an `InvalidArgumentError` on legacy lines.
|
|
69
|
-
*
|
|
70
|
-
* @param params.content Model document as plain text.
|
|
71
|
-
* @param params.type Notation of `content`. Exact, never coerced.
|
|
72
|
-
* @returns Feature names, de-duplicated, in order of first appearance.
|
|
73
|
-
* @throws {InvalidArgumentError} when `content` is not a string or `type` is unknown.
|
|
74
|
-
*/
|
|
75
|
-
export const extractFeatureNames = ({ content, type }) => {
|
|
76
|
-
if (typeof content !== 'string') {
|
|
77
|
-
throw new InvalidArgumentError('"content" must be a string.');
|
|
78
|
-
}
|
|
79
|
-
if (!isFeatureModelType(type)) {
|
|
80
|
-
throw new InvalidArgumentError(`Unknown feature model type "${String(type)}". Use "UVL" or "XML".`);
|
|
81
|
-
}
|
|
82
|
-
return type === 'XML' ? parseXmlFeatureNames(content) : parseUvlFeatureNames(content);
|
|
83
|
-
};
|
|
84
|
-
/**
|
|
85
|
-
* Probes a model with an empty selection to detect the void-model case and the
|
|
86
|
-
* features that are always present.
|
|
87
|
-
*
|
|
88
|
-
* Port of `fmAnalysis.js:computeMandatoryFeatures`, keeping its
|
|
89
|
-
* degrade-gracefully contract intact: any failure from the ENGINE is reported as
|
|
90
|
-
* `voidModel: true` with an empty `mandatory`, never as a thrown error.
|
|
91
|
-
*
|
|
92
|
-
* HARDENED on one point: the monolith would happily accept a non-model and
|
|
93
|
-
* return `{ voidModel: true }` because its `try` swallows the `TypeError` too.
|
|
94
|
-
* Here an argument that is not a parsed model is a caller bug and throws, so it
|
|
95
|
-
* cannot masquerade as an unsatisfiable model.
|
|
96
|
-
*
|
|
97
|
-
* @param params.model A model returned by `parseFeatureModel`.
|
|
98
|
-
* @returns Whether the model is void, and its mandatory features.
|
|
99
|
-
* @throws {InvalidArgumentError} when `model` did not come from `parseFeatureModel`.
|
|
100
|
-
*/
|
|
101
|
-
export const computeMandatoryFeatures = ({ model }) => {
|
|
102
|
-
if (model === null || typeof model !== 'object') {
|
|
103
|
-
throw new InvalidArgumentError('"model" must be a value returned by parseFeatureModel().');
|
|
104
|
-
}
|
|
105
|
-
try {
|
|
106
|
-
const result = completeSelection(model, []);
|
|
107
|
-
return { voidModel: false, mandatory: Array.isArray(result) ? result : [] };
|
|
108
|
-
}
|
|
109
|
-
catch {
|
|
110
|
-
return { voidModel: true, mandatory: [] };
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
//# sourceMappingURL=inspect.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"inspect.js","sourceRoot":"","sources":["../../src/feature-model/inspect.ts"],"names":[],"mappings":"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","sourcesContent":["/**\n * Read-only inspection of feature models.\n *\n * Migrated from `linea/server/src/agents/tools/fmAnalysis.js`\n * (`extractFeaturesFromModel`, `computeMandatoryFeatures`). The aggregate\n * portfolio helpers of that file (`computePortfolioAnomalies`,\n * `computePairCoverage`, `findCouplingSmells`) work over product verdicts, not\n * over the model, and belong with the product operations.\n */\nimport { isFeatureModelType, type FeatureModelType } from '../constants.js'\nimport { InvalidArgumentError } from '../errors.js'\nimport { completeSelection, type FeatureModelValue } from './engine.js'\n\n/**\n * UVL tokens that are never feature names.\n * Verbatim from `fmAnalysis.js:UVL_KEYWORDS`.\n */\nconst UVL_KEYWORDS: ReadonlySet<string> = new Set([\n 'features', 'constraints', 'mandatory', 'optional', 'alternative', 'or', 'and',\n 'as', 'type', 'String', 'Integer', 'Real', 'Boolean', 'include', 'namespace',\n 'cardinality', 'abstract', 'true', 'false', 'null'\n])\n\n/** Port of `fmAnalysis.js:parseUvlFeatureNames`; same tokens, same output. */\nconst parseUvlFeatureNames = (uvl: string): string[] => {\n const names = new Set<string>()\n for (const line of uvl.split('\\n')) {\n const trimmed = line.trim()\n if (!trimmed || trimmed.startsWith('//') || trimmed.startsWith('#')) continue\n // Namespace declarations are not feature lines.\n if (trimmed.startsWith('namespace')) continue\n for (const match of trimmed.matchAll(/\\b([A-Za-z_][A-Za-z0-9_]*)\\b/g)) {\n const name = match[1]\n if (name !== undefined && !UVL_KEYWORDS.has(name)) names.add(name)\n }\n }\n return [...names]\n}\n\n/** Port of `fmAnalysis.js:parseXmlFeatureNames`; same regex, same output. */\nconst parseXmlFeatureNames = (xml: string): string[] => {\n const names = new Set<string>()\n for (const match of xml.matchAll(/\\bname=\"([^\"]+)\"/g)) {\n const name = match[1]\n if (name !== undefined) names.add(name)\n }\n return [...names]\n}\n\n/**\n * Extracts feature names from a model document without parsing it.\n *\n * Conservative by design, exactly as the monolith documents it: it prefers false\n * positives over false negatives, so a few extra identifiers (type names, for\n * instance) may show up. Callers that need exact names should parse the model\n * and use the engine instead.\n *\n * HARDENED PORT, not a verbatim one. `fmAnalysis.js:extractFeaturesFromModel`\n * coerces the notation with `(type ?? 'UVL').toUpperCase()`, defaulting a\n * missing or lowercase value to UVL. This function requires an exact `'UVL'` or\n * `'XML'` and throws otherwise.\n *\n * That matters when migrating callers: `line.featureModelType` can be\n * `undefined` for lines created before the field existed, which is why\n * `LineService.js:284,401,432` all write `(line.featureModelType ?? 'UVL')`.\n * Applying that same default is now the CALLER's responsibility — whoever ports\n * `lineHealthAgent.js:89` must pass `line.featureModelType ?? 'UVL'` explicitly\n * or they will get an `InvalidArgumentError` on legacy lines.\n *\n * @param params.content Model document as plain text.\n * @param params.type Notation of `content`. Exact, never coerced.\n * @returns Feature names, de-duplicated, in order of first appearance.\n * @throws {InvalidArgumentError} when `content` is not a string or `type` is unknown.\n */\nexport const extractFeatureNames = ({\n content,\n type\n}: {\n content: string\n type: FeatureModelType\n}): string[] => {\n if (typeof content !== 'string') {\n throw new InvalidArgumentError('\"content\" must be a string.')\n }\n if (!isFeatureModelType(type)) {\n throw new InvalidArgumentError(`Unknown feature model type \"${String(type)}\". Use \"UVL\" or \"XML\".`)\n }\n return type === 'XML' ? parseXmlFeatureNames(content) : parseUvlFeatureNames(content)\n}\n\n/** Outcome of probing a model with an empty selection. */\nexport interface MandatoryFeaturesResult {\n /** `true` when the model admits no valid configuration at all. */\n readonly voidModel: boolean\n /** Features implied even by an empty selection. */\n readonly mandatory: string[]\n}\n\n/**\n * Probes a model with an empty selection to detect the void-model case and the\n * features that are always present.\n *\n * Port of `fmAnalysis.js:computeMandatoryFeatures`, keeping its\n * degrade-gracefully contract intact: any failure from the ENGINE is reported as\n * `voidModel: true` with an empty `mandatory`, never as a thrown error.\n *\n * HARDENED on one point: the monolith would happily accept a non-model and\n * return `{ voidModel: true }` because its `try` swallows the `TypeError` too.\n * Here an argument that is not a parsed model is a caller bug and throws, so it\n * cannot masquerade as an unsatisfiable model.\n *\n * @param params.model A model returned by `parseFeatureModel`.\n * @returns Whether the model is void, and its mandatory features.\n * @throws {InvalidArgumentError} when `model` did not come from `parseFeatureModel`.\n */\nexport const computeMandatoryFeatures = ({\n model\n}: {\n model: FeatureModelValue\n}): MandatoryFeaturesResult => {\n if (model === null || typeof model !== 'object') {\n throw new InvalidArgumentError('\"model\" must be a value returned by parseFeatureModel().')\n }\n try {\n const result = completeSelection(model, [])\n return { voidModel: false, mandatory: Array.isArray(result) ? result : [] }\n } catch {\n return { voidModel: true, mandatory: [] }\n }\n}\n"]}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { type FeatureModelType } from '../constants.js';
|
|
2
|
-
/**
|
|
3
|
-
* Where a line's feature model lives and in which notation.
|
|
4
|
-
*
|
|
5
|
-
* There is no `exists` flag: the function throws `LinePlatformNotFoundError`
|
|
6
|
-
* when no model is there, so a flag could only ever be `true`. Widening a public
|
|
7
|
-
* type later is cheap; narrowing it is a breaking change.
|
|
8
|
-
*/
|
|
9
|
-
export interface FeatureModelLocation {
|
|
10
|
-
/** Notation of the model found. */
|
|
11
|
-
readonly type: FeatureModelType;
|
|
12
|
-
/** Absolute path of the model file. */
|
|
13
|
-
readonly path: string;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Detects which feature model a line working directory holds.
|
|
17
|
-
*
|
|
18
|
-
* UVL wins when both files are present, matching the monolith: `readLineModel`
|
|
19
|
-
* tries `model.uvl` first, and `reconcileLines` only settles on XML when the
|
|
20
|
-
* UVL lookup fails.
|
|
21
|
-
*
|
|
22
|
-
* @param params.lineDir Root of the line working directory.
|
|
23
|
-
* @returns Notation and absolute path of the model found.
|
|
24
|
-
* @throws {LinePlatformNotFoundError} when neither `src/platform/model.uvl` nor
|
|
25
|
-
* `src/platform/model.xml` exists.
|
|
26
|
-
*/
|
|
27
|
-
export declare const detectFeatureModelType: ({ lineDir }: {
|
|
28
|
-
lineDir: string;
|
|
29
|
-
}) => FeatureModelLocation;
|
|
30
|
-
/**
|
|
31
|
-
* Reads the platform feature model of a line working directory.
|
|
32
|
-
*
|
|
33
|
-
* @param params.lineDir Root of the line working directory.
|
|
34
|
-
* @returns Notation, absolute path and contents of the model.
|
|
35
|
-
* @throws {LinePlatformNotFoundError} when the line has no platform model.
|
|
36
|
-
*/
|
|
37
|
-
export declare const readFeatureModel: ({ lineDir }: {
|
|
38
|
-
lineDir: string;
|
|
39
|
-
}) => {
|
|
40
|
-
type: FeatureModelType;
|
|
41
|
-
path: string;
|
|
42
|
-
content: string;
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* Writes the platform feature model of a line working directory, creating
|
|
46
|
-
* `src/platform` if needed.
|
|
47
|
-
*
|
|
48
|
-
* Mirrors the model half of `saveFeatureModel`: it overwrites the file for the
|
|
49
|
-
* given notation and nothing else. It deliberately does NOT delete the model of
|
|
50
|
-
* the other notation — that only happens in the convert flow, where the monolith
|
|
51
|
-
* issues a single GitLab commit with a `create` plus a `delete`
|
|
52
|
-
* (`LineService.js:convertFeatureModel`). That flow is a line-level operation
|
|
53
|
-
* and belongs to a later batch.
|
|
54
|
-
*
|
|
55
|
-
* @param params.lineDir Root of the line working directory.
|
|
56
|
-
* @param params.content Model document as plain text.
|
|
57
|
-
* @param params.type Notation of `content`.
|
|
58
|
-
* @returns The absolute path written.
|
|
59
|
-
*/
|
|
60
|
-
export declare const writeFeatureModel: ({ lineDir, content, type }: {
|
|
61
|
-
lineDir: string;
|
|
62
|
-
content: string;
|
|
63
|
-
type: FeatureModelType;
|
|
64
|
-
}) => {
|
|
65
|
-
path: string;
|
|
66
|
-
};
|
package/dist/feature-model/io.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Reading and writing the platform feature model of a line working directory.
|
|
3
|
-
*
|
|
4
|
-
* Migrated from:
|
|
5
|
-
* - `linea/server/src/model/services/LineService.js:getFeatureModel` (~277-293)
|
|
6
|
-
* and `saveFeatureModel` (~391-419) — domain logic only; permissions, the
|
|
7
|
-
* GitLab round-trip, the version bump and the Mongo transaction stay in
|
|
8
|
-
* linea-server (ADR-003).
|
|
9
|
-
* - `linea/server/src/agents/tools/harvest.js:readLineModel` (~97-107), which
|
|
10
|
-
* is where the "UVL preferred, XML fallback" rule comes from.
|
|
11
|
-
* - `linea/server/src/model/services/LineService.js:reconcileLines` (~152-156),
|
|
12
|
-
* which resolves the same ambiguity for repositories that are not in the DB:
|
|
13
|
-
* XML only when the XML file is there and the UVL one is not.
|
|
14
|
-
*
|
|
15
|
-
* The monolith decodes base64 (`atob(file.content)`) because files arrive from
|
|
16
|
-
* the GitLab API. Here everything is plain text on disk.
|
|
17
|
-
*/
|
|
18
|
-
import path from 'node:path';
|
|
19
|
-
import { PLATFORM_PATHS, isFeatureModelType } from '../constants.js';
|
|
20
|
-
import { InvalidArgumentError, LinePlatformNotFoundError } from '../errors.js';
|
|
21
|
-
import { fileExists, readTextFile, writeTextFile } from '../fs/workspace.js';
|
|
22
|
-
/** Absolute path of the model file of `lineDir` for a given notation. */
|
|
23
|
-
const modelPathFor = (lineDir, type) => path.join(path.resolve(lineDir), type === 'XML' ? PLATFORM_PATHS.modelXml : PLATFORM_PATHS.model);
|
|
24
|
-
const assertLineDir = (lineDir) => {
|
|
25
|
-
if (typeof lineDir !== 'string' || lineDir.trim() === '') {
|
|
26
|
-
throw new InvalidArgumentError('"lineDir" must be a non-empty path.');
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Detects which feature model a line working directory holds.
|
|
31
|
-
*
|
|
32
|
-
* UVL wins when both files are present, matching the monolith: `readLineModel`
|
|
33
|
-
* tries `model.uvl` first, and `reconcileLines` only settles on XML when the
|
|
34
|
-
* UVL lookup fails.
|
|
35
|
-
*
|
|
36
|
-
* @param params.lineDir Root of the line working directory.
|
|
37
|
-
* @returns Notation and absolute path of the model found.
|
|
38
|
-
* @throws {LinePlatformNotFoundError} when neither `src/platform/model.uvl` nor
|
|
39
|
-
* `src/platform/model.xml` exists.
|
|
40
|
-
*/
|
|
41
|
-
export const detectFeatureModelType = ({ lineDir }) => {
|
|
42
|
-
assertLineDir(lineDir);
|
|
43
|
-
const uvlPath = modelPathFor(lineDir, 'UVL');
|
|
44
|
-
if (fileExists({ filePath: uvlPath }))
|
|
45
|
-
return { type: 'UVL', path: uvlPath };
|
|
46
|
-
const xmlPath = modelPathFor(lineDir, 'XML');
|
|
47
|
-
if (fileExists({ filePath: xmlPath }))
|
|
48
|
-
return { type: 'XML', path: xmlPath };
|
|
49
|
-
throw new LinePlatformNotFoundError(`No feature model found in "${path.resolve(lineDir)}": expected "${PLATFORM_PATHS.model}" or "${PLATFORM_PATHS.modelXml}".`);
|
|
50
|
-
};
|
|
51
|
-
/**
|
|
52
|
-
* Reads the platform feature model of a line working directory.
|
|
53
|
-
*
|
|
54
|
-
* @param params.lineDir Root of the line working directory.
|
|
55
|
-
* @returns Notation, absolute path and contents of the model.
|
|
56
|
-
* @throws {LinePlatformNotFoundError} when the line has no platform model.
|
|
57
|
-
*/
|
|
58
|
-
export const readFeatureModel = ({ lineDir }) => {
|
|
59
|
-
const location = detectFeatureModelType({ lineDir });
|
|
60
|
-
return {
|
|
61
|
-
type: location.type,
|
|
62
|
-
path: location.path,
|
|
63
|
-
content: readTextFile({ filePath: location.path })
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
/**
|
|
67
|
-
* Writes the platform feature model of a line working directory, creating
|
|
68
|
-
* `src/platform` if needed.
|
|
69
|
-
*
|
|
70
|
-
* Mirrors the model half of `saveFeatureModel`: it overwrites the file for the
|
|
71
|
-
* given notation and nothing else. It deliberately does NOT delete the model of
|
|
72
|
-
* the other notation — that only happens in the convert flow, where the monolith
|
|
73
|
-
* issues a single GitLab commit with a `create` plus a `delete`
|
|
74
|
-
* (`LineService.js:convertFeatureModel`). That flow is a line-level operation
|
|
75
|
-
* and belongs to a later batch.
|
|
76
|
-
*
|
|
77
|
-
* @param params.lineDir Root of the line working directory.
|
|
78
|
-
* @param params.content Model document as plain text.
|
|
79
|
-
* @param params.type Notation of `content`.
|
|
80
|
-
* @returns The absolute path written.
|
|
81
|
-
*/
|
|
82
|
-
export const writeFeatureModel = ({ lineDir, content, type }) => {
|
|
83
|
-
assertLineDir(lineDir);
|
|
84
|
-
if (typeof content !== 'string') {
|
|
85
|
-
throw new InvalidArgumentError('"content" must be a string.');
|
|
86
|
-
}
|
|
87
|
-
if (!isFeatureModelType(type)) {
|
|
88
|
-
throw new InvalidArgumentError(`Unknown feature model type "${String(type)}". Use "UVL" or "XML".`);
|
|
89
|
-
}
|
|
90
|
-
return { path: writeTextFile({ filePath: modelPathFor(lineDir, type), content }) };
|
|
91
|
-
};
|
|
92
|
-
//# sourceMappingURL=io.js.map
|