@lbdudc/linea-core 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { featuresOf } from '../../feature-model/uvl.js';
|
|
2
|
+
import { InvalidArgumentError } from '../../errors.js';
|
|
3
|
+
import { FEATURE_MODEL_GRAMMAR, FEATURE_SELECTION_GRAMMAR } from './constants.js';
|
|
4
|
+
import { bangoName } from './names.js';
|
|
5
|
+
/** A feature selection as a model of the feature metamodel (`featureselection`): `selection of <model> { select ... }`. */
|
|
6
|
+
export const selectionText = ({ model, features }) => `selection of ${bangoName({ name: model })} {\n${features.map((feature) => ` select ${bangoName({ name: feature })}\n`).join('')}}\n`;
|
|
7
|
+
/** The least a group asks for: all of a mandatory one, none of an optional one, one of an alternative or an or, `min` of a cardinality one. */
|
|
8
|
+
const needed = (kind, size, min) => kind === 'mandatory' ? size : kind === 'alternative' || kind === 'or' ? 1 : kind === 'cardinality' ? Math.min(min ?? 0, size) : 0;
|
|
9
|
+
/**
|
|
10
|
+
* The smallest selection the tree of a feature model accepts, by its groups alone: what is mandatory, and the first features of every
|
|
11
|
+
* alternative, or and cardinality group that is in. (Constraints are not looked at: whoever uses it checks the result with the feature
|
|
12
|
+
* metamodel, which also adds what the constraints need.) The root is not listed: every selection has it.
|
|
13
|
+
*/
|
|
14
|
+
export const defaultSelection = ({ tree }) => {
|
|
15
|
+
const chosen = [];
|
|
16
|
+
const take = (node) => {
|
|
17
|
+
for (const group of node.groups) {
|
|
18
|
+
const count = needed(group.kind, group.features.length, group.min);
|
|
19
|
+
for (const child of group.features.slice(0, count)) {
|
|
20
|
+
chosen.push(child);
|
|
21
|
+
take(child);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
take(tree.root);
|
|
26
|
+
// in the order of the model
|
|
27
|
+
const order = new Map(featuresOf({ tree }).map((node, index) => [node, index]));
|
|
28
|
+
return chosen.sort((a, b) => (order.get(a) ?? 0) - (order.get(b) ?? 0)).map((node) => node.name);
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* What the feature metamodel says of selections of features against a feature model: whether each is valid, and with what it is completed.
|
|
32
|
+
* `engine` is one prepared for an SPL (`prepareEngine`), so the feature metamodel is loaded; the model is offered to the selections
|
|
33
|
+
* as it is to a product. Selections are independent of each other.
|
|
34
|
+
*/
|
|
35
|
+
export const checkSelections = async ({ engine, tree, selections }) => {
|
|
36
|
+
const model = (await engine.importJson({ featureModel: tree })).texts[FEATURE_MODEL_GRAMMAR];
|
|
37
|
+
if (model === undefined)
|
|
38
|
+
throw new InvalidArgumentError('The feature metamodel did not make a model of the feature tree.');
|
|
39
|
+
await engine.setContributed([{ origin: 'level-1', metamodel: FEATURE_MODEL_GRAMMAR, text: model }]);
|
|
40
|
+
const verdicts = [];
|
|
41
|
+
for (const features of selections) {
|
|
42
|
+
const states = await engine.setInstances({ [FEATURE_SELECTION_GRAMMAR]: selectionText({ model: tree.name, features }) });
|
|
43
|
+
const problems = states.flatMap((state) => state.problems).filter((problem) => problem.severity === 'error').map((problem) => problem.message);
|
|
44
|
+
const json = (await engine.toJson(FEATURE_SELECTION_GRAMMAR));
|
|
45
|
+
verdicts.push({ valid: problems.length === 0, problems, completed: json?.features ?? [] });
|
|
46
|
+
}
|
|
47
|
+
return verdicts;
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=selection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selection.js","sourceRoot":"","sources":["../../../src/modules/configuration/selection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA2C,MAAM,4BAA4B,CAAA;AAChG,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAEtD,OAAO,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAA;AACjF,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEtC,2HAA2H;AAC3H,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAkD,EAAU,EAAE,CAC3G,gBAAgB,SAAS,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,YAAY,SAAS,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAA;AAExI,+IAA+I;AAC/I,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,IAAY,EAAE,GAAuB,EAAU,EAAE,CAC7E,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,KAAK,aAAa,IAAI,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,aAAa,CAAC,CAAC,CAAC,IAAI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AE,QAAQ,IAAI,EAAE,EAAE,CAAC,CAAA;IAC5F,CAAC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA","sourcesContent":["import { featuresOf, type FeatureModelTree, type FeatureNode } from '../../feature-model/uvl.js'\nimport { InvalidArgumentError } from '../../errors.js'\nimport type { MetamodelEngine } from '../metamodels/engine.js'\nimport { FEATURE_MODEL_GRAMMAR, FEATURE_SELECTION_GRAMMAR } from './constants.js'\nimport { bangoName } from './names.js'\n\n/** A feature selection as a model of the feature metamodel (`featureselection`): `selection of <model> { select ... }`. */\nexport const selectionText = ({ model, features }: { model: string, features: readonly string[] }): string =>\n `selection of ${bangoName({ name: model })} {\\n${features.map((feature) => ` select ${bangoName({ name: feature })}\\n`).join('')}}\\n`\n\n/** The least a group asks for: all of a mandatory one, none of an optional one, one of an alternative or an or, `min` of a cardinality one. */\nconst needed = (kind: string, size: number, min: number | undefined): number =>\n kind === 'mandatory' ? size : kind === 'alternative' || kind === 'or' ? 1 : kind === 'cardinality' ? Math.min(min ?? 0, size) : 0\n\n/**\n * The smallest selection the tree of a feature model accepts, by its groups alone: what is mandatory, and the first features of every\n * alternative, or and cardinality group that is in. (Constraints are not looked at: whoever uses it checks the result with the feature\n * metamodel, which also adds what the constraints need.) The root is not listed: every selection has it.\n */\nexport const defaultSelection = ({ tree }: { tree: FeatureModelTree }): string[] => {\n const chosen: FeatureNode[] = []\n const take = (node: FeatureNode): void => {\n for (const group of node.groups) {\n const count = needed(group.kind, group.features.length, group.min)\n for (const child of group.features.slice(0, count)) {\n chosen.push(child)\n take(child)\n }\n }\n }\n take(tree.root)\n // in the order of the model\n const order = new Map(featuresOf({ tree }).map((node, index) => [node, index]))\n return chosen.sort((a, b) => (order.get(a) ?? 0) - (order.get(b) ?? 0)).map((node) => node.name)\n}\n\nexport interface SelectionVerdict {\n readonly valid: boolean\n /** What the feature metamodel finds wrong with the selection, one message each. */\n readonly problems: readonly string[]\n /** The selection once what the model implies is added (the root, ancestors, mandatory features, what the constraints need). */\n readonly completed: readonly string[]\n}\n\n/**\n * What the feature metamodel says of selections of features against a feature model: whether each is valid, and with what it is completed.\n * `engine` is one prepared for an SPL (`prepareEngine`), so the feature metamodel is loaded; the model is offered to the selections\n * as it is to a product. Selections are independent of each other.\n */\nexport const checkSelections = async ({\n engine,\n tree,\n selections\n}: {\n engine: MetamodelEngine\n tree: FeatureModelTree\n selections: readonly (readonly string[])[]\n}): Promise<SelectionVerdict[]> => {\n const model = (await engine.importJson({ featureModel: tree })).texts[FEATURE_MODEL_GRAMMAR]\n if (model === undefined) throw new InvalidArgumentError('The feature metamodel did not make a model of the feature tree.')\n await engine.setContributed([{ origin: 'level-1', metamodel: FEATURE_MODEL_GRAMMAR, text: model }])\n const verdicts: SelectionVerdict[] = []\n for (const features of selections) {\n const states = await engine.setInstances({ [FEATURE_SELECTION_GRAMMAR]: selectionText({ model: tree.name, features }) })\n const problems = states.flatMap((state) => state.problems).filter((problem) => problem.severity === 'error').map((problem) => problem.message)\n const json = (await engine.toJson(FEATURE_SELECTION_GRAMMAR)) as { features?: string[] } | undefined\n verdicts.push({ valid: problems.length === 0, problems, completed: json?.features ?? [] })\n }\n return verdicts\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../../src/modules/diagnostics.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,WAAkC,EAAW,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAA","sourcesContent":["import type { Diagnostic } from './types.js'\n\nexport const hasErrors = (diagnostics: readonly Diagnostic[]): boolean => diagnostics.some(({ severity }) => severity === 'error')\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SPLs made of modules. From the bottom up:
|
|
3
|
+
* packages/ what a package is (manifests, locations) and where its files come from (a `PackageSource`)
|
|
4
|
+
* registry/ one registry per kind (modules, metamodels) over a source, and a router that sends each location to its host
|
|
5
|
+
* resolution/ from the modules an SPL lists to every package it needs, pinned by a lockfile
|
|
6
|
+
* metamodels/ loading the metamodels of an SPL into a metamodel engine (bango) and the models the modules offer
|
|
7
|
+
* configuration/ the SPL's models of the levels above 0 (its feature model, a model of bango's feature metamodel) and the platform composed with them
|
|
8
|
+
* spl/ the SPL as a whole: its feature model and code composed from the modules, and its check
|
|
9
|
+
* products/ a product of such an SPL: its models, its check and its derivation
|
|
10
|
+
*/
|
|
11
|
+
export * from './packages/index.js';
|
|
12
|
+
export * from './registry/index.js';
|
|
13
|
+
export * from './resolution/index.js';
|
|
14
|
+
export * from './metamodels/index.js';
|
|
15
|
+
export * from './configuration/index.js';
|
|
16
|
+
export * from './spl/index.js';
|
|
17
|
+
export * from './products/index.js';
|
|
18
|
+
export type { SplKind, PackageKind, PackageFiles, PackageSource, MetamodelManifest, ModuleManifest, SplManifest, Lock, LockEntry, ResolvedModule, ResolvedMetamodel, ResolvedSpl, Diagnostic, RegistryEntry, RegistryIndex } from './types.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SPLs made of modules. From the bottom up:
|
|
3
|
+
* packages/ what a package is (manifests, locations) and where its files come from (a `PackageSource`)
|
|
4
|
+
* registry/ one registry per kind (modules, metamodels) over a source, and a router that sends each location to its host
|
|
5
|
+
* resolution/ from the modules an SPL lists to every package it needs, pinned by a lockfile
|
|
6
|
+
* metamodels/ loading the metamodels of an SPL into a metamodel engine (bango) and the models the modules offer
|
|
7
|
+
* configuration/ the SPL's models of the levels above 0 (its feature model, a model of bango's feature metamodel) and the platform composed with them
|
|
8
|
+
* spl/ the SPL as a whole: its feature model and code composed from the modules, and its check
|
|
9
|
+
* products/ a product of such an SPL: its models, its check and its derivation
|
|
10
|
+
*/
|
|
11
|
+
export * from './packages/index.js';
|
|
12
|
+
export * from './registry/index.js';
|
|
13
|
+
export * from './resolution/index.js';
|
|
14
|
+
export * from './metamodels/index.js';
|
|
15
|
+
export * from './configuration/index.js';
|
|
16
|
+
export * from './spl/index.js';
|
|
17
|
+
export * from './products/index.js';
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/modules/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,uBAAuB,CAAA;AACrC,cAAc,uBAAuB,CAAA;AACrC,cAAc,0BAA0B,CAAA;AACxC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,qBAAqB,CAAA","sourcesContent":["/**\n * SPLs made of modules. From the bottom up:\n * packages/ what a package is (manifests, locations) and where its files come from (a `PackageSource`)\n * registry/ one registry per kind (modules, metamodels) over a source, and a router that sends each location to its host\n * resolution/ from the modules an SPL lists to every package it needs, pinned by a lockfile\n * metamodels/ loading the metamodels of an SPL into a metamodel engine (bango) and the models the modules offer\n * configuration/ the SPL's models of the levels above 0 (its feature model, a model of bango's feature metamodel) and the platform composed with them\n * spl/ the SPL as a whole: its feature model and code composed from the modules, and its check\n * products/ a product of such an SPL: its models, its check and its derivation\n */\nexport * from './packages/index.js'\nexport * from './registry/index.js'\nexport * from './resolution/index.js'\nexport * from './metamodels/index.js'\nexport * from './configuration/index.js'\nexport * from './spl/index.js'\nexport * from './products/index.js'\nexport type {\n SplKind,\n PackageKind,\n PackageFiles,\n PackageSource,\n MetamodelManifest,\n ModuleManifest,\n SplManifest,\n Lock,\n LockEntry,\n ResolvedModule,\n ResolvedMetamodel,\n ResolvedSpl,\n Diagnostic,\n RegistryEntry,\n RegistryIndex\n} from './types.js'\n"]}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { Diagnostic } from '../types.js';
|
|
2
|
+
/** What linea-core needs of a metamodel engine (bango's `Bango` fits): the engine is given to it, so linea-core does not depend on bango. */
|
|
3
|
+
export interface EngineProblem {
|
|
4
|
+
readonly severity: string;
|
|
5
|
+
readonly message: string;
|
|
6
|
+
readonly startLine: number;
|
|
7
|
+
readonly startColumn: number;
|
|
8
|
+
}
|
|
9
|
+
export interface EngineGrammarInfo {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
readonly extension?: string;
|
|
12
|
+
/** The level of its models (`// @level n` in the grammar; 0, the final ones, without it). Engines that have no levels leave it out. */
|
|
13
|
+
readonly level?: number;
|
|
14
|
+
readonly imports: readonly string[];
|
|
15
|
+
readonly requires: readonly string[];
|
|
16
|
+
readonly description?: string;
|
|
17
|
+
readonly problems: readonly EngineProblem[];
|
|
18
|
+
}
|
|
19
|
+
export interface EngineContributedState {
|
|
20
|
+
readonly origin: string;
|
|
21
|
+
readonly metamodel: string;
|
|
22
|
+
readonly available: boolean;
|
|
23
|
+
readonly problems: readonly EngineProblem[];
|
|
24
|
+
}
|
|
25
|
+
export interface EngineInstanceState {
|
|
26
|
+
readonly metamodel: string;
|
|
27
|
+
readonly available: boolean;
|
|
28
|
+
readonly problems: readonly EngineProblem[];
|
|
29
|
+
}
|
|
30
|
+
export interface MetamodelEngine {
|
|
31
|
+
setGrammar: (name: string, text: string) => Promise<void>;
|
|
32
|
+
setConstraints: (metamodel: string, code: string) => Promise<void>;
|
|
33
|
+
setSpec: (metamodel: string, code: string) => Promise<void>;
|
|
34
|
+
setImport: (metamodel: string, code: string) => Promise<void>;
|
|
35
|
+
setScope: (metamodel: string, code: string) => Promise<void>;
|
|
36
|
+
listMetamodels: () => Promise<readonly EngineGrammarInfo[]>;
|
|
37
|
+
compose: (selection: string[]) => Promise<{
|
|
38
|
+
readonly problems: readonly {
|
|
39
|
+
readonly message: string;
|
|
40
|
+
}[];
|
|
41
|
+
readonly grammars: readonly EngineGrammarInfo[];
|
|
42
|
+
readonly renames: readonly {
|
|
43
|
+
readonly file: string;
|
|
44
|
+
readonly original: string;
|
|
45
|
+
readonly renamed: string;
|
|
46
|
+
readonly keeper: string;
|
|
47
|
+
}[];
|
|
48
|
+
}>;
|
|
49
|
+
setContributed: (items: {
|
|
50
|
+
origin: string;
|
|
51
|
+
metamodel: string;
|
|
52
|
+
text: string;
|
|
53
|
+
}[]) => Promise<readonly EngineContributedState[]>;
|
|
54
|
+
setInstances: (texts: Record<string, string>) => Promise<readonly EngineInstanceState[]>;
|
|
55
|
+
createInstance: (metamodel: string) => Promise<{
|
|
56
|
+
readonly text: string;
|
|
57
|
+
}>;
|
|
58
|
+
/** The JSON of the model of a metamodel, by the metamodel's own mapping (what the platform reads). */
|
|
59
|
+
toJson(metamodel: string): Promise<unknown>;
|
|
60
|
+
/** Models made from the JSON of a whole project, by the import mappings of the metamodels that have one. */
|
|
61
|
+
importJson(json: unknown): Promise<{
|
|
62
|
+
readonly texts: Readonly<Record<string, string>>;
|
|
63
|
+
readonly errors: readonly string[];
|
|
64
|
+
}>;
|
|
65
|
+
build: (project: string) => Promise<{
|
|
66
|
+
readonly ok: boolean;
|
|
67
|
+
readonly errors: readonly string[];
|
|
68
|
+
readonly warnings: readonly string[];
|
|
69
|
+
readonly model?: {
|
|
70
|
+
readonly spec: unknown;
|
|
71
|
+
readonly instances: readonly {
|
|
72
|
+
readonly metamodel: string;
|
|
73
|
+
readonly spec: unknown;
|
|
74
|
+
}[];
|
|
75
|
+
};
|
|
76
|
+
}>;
|
|
77
|
+
}
|
|
78
|
+
/** A metamodel a product has to give a model of. */
|
|
79
|
+
export interface MetamodelInfo {
|
|
80
|
+
readonly name: string;
|
|
81
|
+
readonly extension: string;
|
|
82
|
+
/** The level of its models: 0 for the ones a product has, more for the ones its models are made from (the SPL's feature model is level 1). */
|
|
83
|
+
readonly level: number;
|
|
84
|
+
readonly description?: string;
|
|
85
|
+
/** The metamodels it needs a model of too. */
|
|
86
|
+
readonly requires: readonly string[];
|
|
87
|
+
/** Location of the package that defines it. */
|
|
88
|
+
readonly package: string;
|
|
89
|
+
}
|
|
90
|
+
export declare const toDiagnostics: (problems: readonly EngineProblem[], context: {
|
|
91
|
+
package: string;
|
|
92
|
+
file?: string;
|
|
93
|
+
}) => Diagnostic[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const where = (problem) => `${problem.startLine + 1}:${problem.startColumn + 1} ${problem.message}`;
|
|
2
|
+
export const toDiagnostics = (problems, context) => problems
|
|
3
|
+
.filter(({ severity }) => severity === 'error' || severity === 'warning')
|
|
4
|
+
.map((problem) => ({
|
|
5
|
+
severity: problem.severity === 'error' ? 'error' : 'warning',
|
|
6
|
+
package: context.package,
|
|
7
|
+
...(context.file === undefined ? {} : { file: context.file }),
|
|
8
|
+
message: where(problem)
|
|
9
|
+
}));
|
|
10
|
+
//# sourceMappingURL=engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../../../src/modules/metamodels/engine.ts"],"names":[],"mappings":"AA6EA,MAAM,KAAK,GAAG,CAAC,OAAsB,EAAU,EAAE,CAAC,GAAG,OAAO,CAAC,SAAS,GAAG,CAAC,IAAI,OAAO,CAAC,WAAW,GAAG,CAAC,IAAI,OAAO,CAAC,OAAO,EAAE,CAAA;AAE1H,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,QAAkC,EAClC,OAA2C,EAC7B,EAAE,CAChB,QAAQ;KACL,MAAM,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,QAAQ,KAAK,OAAO,IAAI,QAAQ,KAAK,SAAS,CAAC;KACxE,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,OAAgB,CAAC,CAAC,CAAC,SAAkB;IAC9E,OAAO,EAAE,OAAO,CAAC,OAAO;IACxB,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC;IAC7D,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC;CACxB,CAAC,CAAC,CAAA","sourcesContent":["import type { Diagnostic } from '../types.js'\n\n/** What linea-core needs of a metamodel engine (bango's `Bango` fits): the engine is given to it, so linea-core does not depend on bango. */\nexport interface EngineProblem {\n readonly severity: string\n readonly message: string\n readonly startLine: number\n readonly startColumn: number\n}\n\nexport interface EngineGrammarInfo {\n readonly name: string\n readonly extension?: string\n /** The level of its models (`// @level n` in the grammar; 0, the final ones, without it). Engines that have no levels leave it out. */\n readonly level?: number\n readonly imports: readonly string[]\n readonly requires: readonly string[]\n readonly description?: string\n readonly problems: readonly EngineProblem[]\n}\n\nexport interface EngineContributedState {\n readonly origin: string\n readonly metamodel: string\n readonly available: boolean\n readonly problems: readonly EngineProblem[]\n}\n\nexport interface EngineInstanceState {\n readonly metamodel: string\n readonly available: boolean\n readonly problems: readonly EngineProblem[]\n}\n\nexport interface MetamodelEngine {\n setGrammar: (name: string, text: string) => Promise<void>\n setConstraints: (metamodel: string, code: string) => Promise<void>\n setSpec: (metamodel: string, code: string) => Promise<void>\n setImport: (metamodel: string, code: string) => Promise<void>\n setScope: (metamodel: string, code: string) => Promise<void>\n listMetamodels: () => Promise<readonly EngineGrammarInfo[]>\n compose: (selection: string[]) => Promise<{\n readonly problems: readonly { readonly message: string }[]\n readonly grammars: readonly EngineGrammarInfo[]\n readonly renames: readonly { readonly file: string, readonly original: string, readonly renamed: string, readonly keeper: string }[]\n }>\n setContributed: (items: { origin: string, metamodel: string, text: string }[]) => Promise<readonly EngineContributedState[]>\n setInstances: (texts: Record<string, string>) => Promise<readonly EngineInstanceState[]>\n createInstance: (metamodel: string) => Promise<{ readonly text: string }>\n /** The JSON of the model of a metamodel, by the metamodel's own mapping (what the platform reads). */\n toJson(metamodel: string): Promise<unknown>\n /** Models made from the JSON of a whole project, by the import mappings of the metamodels that have one. */\n importJson(json: unknown): Promise<{ readonly texts: Readonly<Record<string, string>>, readonly errors: readonly string[] }>\n build: (project: string) => Promise<{\n readonly ok: boolean\n readonly errors: readonly string[]\n readonly warnings: readonly string[]\n readonly model?: {\n readonly spec: unknown\n readonly instances: readonly { readonly metamodel: string, readonly spec: unknown }[]\n }\n }>\n}\n\n/** A metamodel a product has to give a model of. */\nexport interface MetamodelInfo {\n readonly name: string\n readonly extension: string\n /** The level of its models: 0 for the ones a product has, more for the ones its models are made from (the SPL's feature model is level 1). */\n readonly level: number\n readonly description?: string\n /** The metamodels it needs a model of too. */\n readonly requires: readonly string[]\n /** Location of the package that defines it. */\n readonly package: string\n}\n\nconst where = (problem: EngineProblem): string => `${problem.startLine + 1}:${problem.startColumn + 1} ${problem.message}`\n\nexport const toDiagnostics = (\n problems: readonly EngineProblem[],\n context: { package: string, file?: string }\n): Diagnostic[] =>\n problems\n .filter(({ severity }) => severity === 'error' || severity === 'warning')\n .map((problem) => ({\n severity: problem.severity === 'error' ? 'error' as const : 'warning' as const,\n package: context.package,\n ...(context.file === undefined ? {} : { file: context.file }),\n message: where(problem)\n }))\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type MetamodelFileKind } from './layout.js';
|
|
2
|
+
import type { ResolvedMetamodel, ResolvedSpl } from '../types.js';
|
|
3
|
+
declare const SCRIPT_KINDS: readonly ["constraints", "spec", "import", "scope"];
|
|
4
|
+
export type ScriptKind = (typeof SCRIPT_KINDS)[number];
|
|
5
|
+
export interface MetamodelFile {
|
|
6
|
+
readonly grammar: string;
|
|
7
|
+
/** path of the grammar in the package */
|
|
8
|
+
readonly file: string;
|
|
9
|
+
readonly text: string;
|
|
10
|
+
readonly level: number;
|
|
11
|
+
readonly scripts: Partial<Record<ScriptKind, string>>;
|
|
12
|
+
/** the views of its instances that the metamodel brings (`visualizations/<grammar>.js`). Code for the page that edits the models, never run by the engine */
|
|
13
|
+
readonly visualizations?: string;
|
|
14
|
+
}
|
|
15
|
+
type Files = Pick<ResolvedMetamodel, 'files'>['files'];
|
|
16
|
+
/** The text of a file of a grammar, in its folder of the package; `undefined` when it has none. */
|
|
17
|
+
export declare const readMetamodelText: ({ files, kind, grammar }: {
|
|
18
|
+
files: Files;
|
|
19
|
+
kind: MetamodelFileKind;
|
|
20
|
+
grammar: string;
|
|
21
|
+
}) => Promise<string | undefined>;
|
|
22
|
+
/** The grammars a metamodel package provides: every `grammars/<name>.langium`, with the scripts that belong to each. */
|
|
23
|
+
export declare const readMetamodelFiles: ({ pkg }: {
|
|
24
|
+
pkg: Pick<ResolvedMetamodel, "files">;
|
|
25
|
+
}) => Promise<MetamodelFile[]>;
|
|
26
|
+
/** Everything a metamodel engine needs to know the metamodels of an SPL: grammars and the scripts of each, by grammar name. */
|
|
27
|
+
export interface MetamodelBundle {
|
|
28
|
+
readonly grammars: Record<string, string>;
|
|
29
|
+
readonly constraints: Record<string, string>;
|
|
30
|
+
readonly specs: Record<string, string>;
|
|
31
|
+
readonly imports: Record<string, string>;
|
|
32
|
+
readonly scopes: Record<string, string>;
|
|
33
|
+
/** by grammar name: what the metamodel brings to draw its instances with (page code, so it is not part of what an engine is given) */
|
|
34
|
+
readonly visualizations: Record<string, string>;
|
|
35
|
+
}
|
|
36
|
+
/** The grammars and scripts of the metamodels an SPL resolved to, to load into an engine somewhere else (a browser, say). */
|
|
37
|
+
export declare const readMetamodelBundle: ({ resolved }: {
|
|
38
|
+
resolved: ResolvedSpl;
|
|
39
|
+
}) => Promise<MetamodelBundle>;
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { readPackageText } from '../packages/source.js';
|
|
2
|
+
import { METAMODEL_FOLDERS, metamodelPath } from './layout.js';
|
|
3
|
+
const SCRIPT_KINDS = ['constraints', 'spec', 'import', 'scope'];
|
|
4
|
+
const LEVEL_COMMENT = /^\s*\/\/\s*@level\s+(\d+)\s*$/m;
|
|
5
|
+
const parseLevel = ({ text }) => Number(LEVEL_COMMENT.exec(text)?.[1] ?? 0);
|
|
6
|
+
/** The text of a file of a grammar, in its folder of the package; `undefined` when it has none. */
|
|
7
|
+
export const readMetamodelText = ({ files, kind, grammar }) => readPackageText({ files, path: metamodelPath({ kind, grammar }) });
|
|
8
|
+
/** The grammars a metamodel package provides: every `grammars/<name>.langium`, with the scripts that belong to each. */
|
|
9
|
+
export const readMetamodelFiles = async ({ pkg }) => {
|
|
10
|
+
const { files } = pkg;
|
|
11
|
+
const folder = `${METAMODEL_FOLDERS.grammar}/`;
|
|
12
|
+
const names = new Map();
|
|
13
|
+
for (const file of await files.list({ dir: METAMODEL_FOLDERS.grammar })) {
|
|
14
|
+
if (file.startsWith(folder) && !file.slice(folder.length).includes('/') && file.endsWith('.langium'))
|
|
15
|
+
names.set(file.slice(folder.length, -'.langium'.length), file);
|
|
16
|
+
}
|
|
17
|
+
files.prefetch?.([...names.values(), ...[...names.keys()].flatMap((grammar) => [
|
|
18
|
+
...SCRIPT_KINDS.map((kind) => metamodelPath({ kind, grammar })),
|
|
19
|
+
metamodelPath({ kind: 'visualizations', grammar })
|
|
20
|
+
])]);
|
|
21
|
+
const found = [];
|
|
22
|
+
for (const [grammar, file] of names) {
|
|
23
|
+
const scripts = {};
|
|
24
|
+
for (const kind of SCRIPT_KINDS) {
|
|
25
|
+
const code = await readMetamodelText({ files, kind, grammar });
|
|
26
|
+
if (code !== undefined)
|
|
27
|
+
scripts[kind] = code;
|
|
28
|
+
}
|
|
29
|
+
const visualizations = await readMetamodelText({ files, kind: 'visualizations', grammar });
|
|
30
|
+
const text = (await readPackageText({ files, path: file })) ?? '';
|
|
31
|
+
found.push({ grammar, file, text, level: parseLevel({ text }), scripts, ...(visualizations === undefined ? {} : { visualizations }) });
|
|
32
|
+
}
|
|
33
|
+
return found.sort((a, b) => a.grammar.localeCompare(b.grammar));
|
|
34
|
+
};
|
|
35
|
+
const BUNDLE_KEYS = {
|
|
36
|
+
constraints: 'constraints',
|
|
37
|
+
spec: 'specs',
|
|
38
|
+
import: 'imports',
|
|
39
|
+
scope: 'scopes'
|
|
40
|
+
};
|
|
41
|
+
/** The grammars and scripts of the metamodels an SPL resolved to, to load into an engine somewhere else (a browser, say). */
|
|
42
|
+
export const readMetamodelBundle = async ({ resolved }) => {
|
|
43
|
+
const bundle = { grammars: {}, constraints: {}, specs: {}, imports: {}, scopes: {}, visualizations: {} };
|
|
44
|
+
for (const pkg of resolved.metamodels) {
|
|
45
|
+
for (const { grammar, text, scripts, visualizations } of await readMetamodelFiles({ pkg })) {
|
|
46
|
+
bundle.grammars[grammar] = text;
|
|
47
|
+
if (visualizations !== undefined)
|
|
48
|
+
bundle.visualizations[grammar] = visualizations;
|
|
49
|
+
for (const kind of SCRIPT_KINDS) {
|
|
50
|
+
const code = scripts[kind];
|
|
51
|
+
if (code !== undefined)
|
|
52
|
+
bundle[BUNDLE_KEYS[kind]][grammar] = code;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return bundle;
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.js","sourceRoot":"","sources":["../../../src/modules/metamodels/files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAA0B,MAAM,aAAa,CAAA;AAGtF,MAAM,YAAY,GAAG,CAAC,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAU,CAAA;AAexE,MAAM,aAAa,GAAG,gCAAgC,CAAA;AAEtD,MAAM,UAAU,GAAG,CAAC,EAAE,IAAI,EAAoB,EAAU,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;AAIrG,mGAAmG;AACnG,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAAE,KAAK,EAAE,IAAI,E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AM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EAAE,EAAE,QAAQ,EAA6B,EAA4B,EAAE;IAC7G,MAAM,MAAM,GAAoB,EAAE,QAAQ,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,cAAc,EAAE,EAAE,EAAE,CAAA;IACzH,KAAK,MAAM,GAAG,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC;QACtC,KAAK,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,cAAc,EAAE,IAAI,MAAM,kBAAkB,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;YAC3F,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,IAAI,CAAA;YAC/B,IAAI,cAAc,KAAK,SAAS;gBAAE,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,cAAc,CAAA;YACjF,KAAK,MAAM,IAAI,IAAI,YAAY,EAAE,CAAC;gBAChC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;gBAC1B,IAAI,IAAI,KAAK,SAAS;oBAAE,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,IAAI,CAAA;YACnE,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC,CAAA","sourcesContent":["import { readPackageText } from '../packages/source.js'\nimport { METAMODEL_FOLDERS, metamodelPath, type MetamodelFileKind } from './layout.js'\nimport type { ResolvedMetamodel, ResolvedSpl } from '../types.js'\n\nconst SCRIPT_KINDS = ['constraints', 'spec', 'import', 'scope'] as const\n\nexport type ScriptKind = (typeof SCRIPT_KINDS)[number]\n\nexport interface MetamodelFile {\n readonly grammar: string\n /** path of the grammar in the package */\n readonly file: string\n readonly text: string\n readonly level: number\n readonly scripts: Partial<Record<ScriptKind, string>>\n /** the views of its instances that the metamodel brings (`visualizations/<grammar>.js`). Code for the page that edits the models, never run by the engine */\n readonly visualizations?: string\n}\n\nconst LEVEL_COMMENT = /^\\s*\\/\\/\\s*@level\\s+(\\d+)\\s*$/m\n\nconst parseLevel = ({ text }: { text: string }): number => Number(LEVEL_COMMENT.exec(text)?.[1] ?? 0)\n\ntype Files = Pick<ResolvedMetamodel, 'files'>['files']\n\n/** The text of a file of a grammar, in its folder of the package; `undefined` when it has none. */\nexport const readMetamodelText = ({ files, kind, grammar }: { files: Files, kind: MetamodelFileKind, grammar: string }): Promise<string | undefined> =>\n readPackageText({ files, path: metamodelPath({ kind, grammar }) })\n\n/** The grammars a metamodel package provides: every `grammars/<name>.langium`, with the scripts that belong to each. */\nexport const readMetamodelFiles = async ({ pkg }: { pkg: Pick<ResolvedMetamodel, 'files'> }): Promise<MetamodelFile[]> => {\n const { files } = pkg\n const folder = `${METAMODEL_FOLDERS.grammar}/`\n const names = new Map<string, string>()\n for (const file of await files.list({ dir: METAMODEL_FOLDERS.grammar })) {\n if (file.startsWith(folder) && !file.slice(folder.length).includes('/') && file.endsWith('.langium')) names.set(file.slice(folder.length, -'.langium'.length), file)\n }\n files.prefetch?.([...names.values(), ...[...names.keys()].flatMap((grammar) => [\n ...SCRIPT_KINDS.map((kind) => metamodelPath({ kind, grammar })),\n metamodelPath({ kind: 'visualizations', grammar })\n ])])\n\n const found: MetamodelFile[] = []\n for (const [grammar, file] of names) {\n const scripts: Partial<Record<ScriptKind, string>> = {}\n for (const kind of SCRIPT_KINDS) {\n const code = await readMetamodelText({ files, kind, grammar })\n if (code !== undefined) scripts[kind] = code\n }\n const visualizations = await readMetamodelText({ files, kind: 'visualizations', grammar })\n const text = (await readPackageText({ files, path: file })) ?? ''\n found.push({ grammar, file, text, level: parseLevel({ text }), scripts, ...(visualizations === undefined ? {} : { visualizations }) })\n }\n return found.sort((a, b) => a.grammar.localeCompare(b.grammar))\n}\n\n/** Everything a metamodel engine needs to know the metamodels of an SPL: grammars and the scripts of each, by grammar name. */\nexport interface MetamodelBundle {\n readonly grammars: Record<string, string>\n readonly constraints: Record<string, string>\n readonly specs: Record<string, string>\n readonly imports: Record<string, string>\n readonly scopes: Record<string, string>\n /** by grammar name: what the metamodel brings to draw its instances with (page code, so it is not part of what an engine is given) */\n readonly visualizations: Record<string, string>\n}\n\nconst BUNDLE_KEYS: Record<ScriptKind, Exclude<keyof MetamodelBundle, 'grammars'>> = {\n constraints: 'constraints',\n spec: 'specs',\n import: 'imports',\n scope: 'scopes'\n}\n\n/** The grammars and scripts of the metamodels an SPL resolved to, to load into an engine somewhere else (a browser, say). */\nexport const readMetamodelBundle = async ({ resolved }: { resolved: ResolvedSpl }): Promise<MetamodelBundle> => {\n const bundle: MetamodelBundle = { grammars: {}, constraints: {}, specs: {}, imports: {}, scopes: {}, visualizations: {} }\n for (const pkg of resolved.metamodels) {\n for (const { grammar, text, scripts, visualizations } of await readMetamodelFiles({ pkg })) {\n bundle.grammars[grammar] = text\n if (visualizations !== undefined) bundle.visualizations[grammar] = visualizations\n for (const kind of SCRIPT_KINDS) {\n const code = scripts[kind]\n if (code !== undefined) bundle[BUNDLE_KEYS[kind]][grammar] = code\n }\n }\n }\n return bundle\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { prepareEngine } from './prepare.js';
|
|
2
|
+
export { readMetamodelBundle, readMetamodelFiles, readMetamodelText } from './files.js';
|
|
3
|
+
export { METAMODEL_FOLDERS, metamodelPath } from './layout.js';
|
|
4
|
+
export type { MetamodelFileKind } from './layout.js';
|
|
5
|
+
export type { MetamodelBundle, MetamodelFile } from './files.js';
|
|
6
|
+
export { listOfferedModels } from './offered.js';
|
|
7
|
+
export type { OfferedModel } from './offered.js';
|
|
8
|
+
export type { MetamodelEngine, EngineProblem, EngineGrammarInfo, EngineContributedState, EngineInstanceState, MetamodelInfo } from './engine.js';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { prepareEngine } from './prepare.js';
|
|
2
|
+
export { readMetamodelBundle, readMetamodelFiles, readMetamodelText } from './files.js';
|
|
3
|
+
export { METAMODEL_FOLDERS, metamodelPath } from './layout.js';
|
|
4
|
+
export { listOfferedModels } from './offered.js';
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/metamodels/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AACvF,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAG9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA","sourcesContent":["export { prepareEngine } from './prepare.js'\nexport { readMetamodelBundle, readMetamodelFiles, readMetamodelText } from './files.js'\nexport { METAMODEL_FOLDERS, metamodelPath } from './layout.js'\nexport type { MetamodelFileKind } from './layout.js'\nexport type { MetamodelBundle, MetamodelFile } from './files.js'\nexport { listOfferedModels } from './offered.js'\nexport type { OfferedModel } from './offered.js'\nexport type {\n MetamodelEngine,\n EngineProblem,\n EngineGrammarInfo,\n EngineContributedState,\n EngineInstanceState,\n MetamodelInfo\n} from './engine.js'\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the files of a metamodel are in its package: one folder per kind, each file named after the grammar it belongs to.
|
|
3
|
+
*
|
|
4
|
+
* grammars/<g>.langium constraints/<g>.js specs/<g>.js imports/<g>.js
|
|
5
|
+
* scopes/<g>.js visualizations/<g>.js cases/<g>.json
|
|
6
|
+
*
|
|
7
|
+
* The same folders are in the metamodels repository and in bango's examples.
|
|
8
|
+
*/
|
|
9
|
+
export declare const METAMODEL_FOLDERS: {
|
|
10
|
+
readonly grammar: "grammars";
|
|
11
|
+
readonly constraints: "constraints";
|
|
12
|
+
readonly spec: "specs";
|
|
13
|
+
readonly import: "imports";
|
|
14
|
+
readonly scope: "scopes";
|
|
15
|
+
readonly visualizations: "visualizations";
|
|
16
|
+
readonly cases: "cases";
|
|
17
|
+
};
|
|
18
|
+
export type MetamodelFileKind = keyof typeof METAMODEL_FOLDERS;
|
|
19
|
+
/** The path of a file of the grammar `grammar` in a package: `constraints/datamodel.js`. */
|
|
20
|
+
export declare const metamodelPath: ({ kind, grammar }: {
|
|
21
|
+
kind: MetamodelFileKind;
|
|
22
|
+
grammar: string;
|
|
23
|
+
}) => string;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the files of a metamodel are in its package: one folder per kind, each file named after the grammar it belongs to.
|
|
3
|
+
*
|
|
4
|
+
* grammars/<g>.langium constraints/<g>.js specs/<g>.js imports/<g>.js
|
|
5
|
+
* scopes/<g>.js visualizations/<g>.js cases/<g>.json
|
|
6
|
+
*
|
|
7
|
+
* The same folders are in the metamodels repository and in bango's examples.
|
|
8
|
+
*/
|
|
9
|
+
export const METAMODEL_FOLDERS = {
|
|
10
|
+
grammar: 'grammars',
|
|
11
|
+
constraints: 'constraints',
|
|
12
|
+
spec: 'specs',
|
|
13
|
+
import: 'imports',
|
|
14
|
+
scope: 'scopes',
|
|
15
|
+
visualizations: 'visualizations',
|
|
16
|
+
cases: 'cases'
|
|
17
|
+
};
|
|
18
|
+
const EXTENSIONS = {
|
|
19
|
+
grammar: '.langium',
|
|
20
|
+
constraints: '.js',
|
|
21
|
+
spec: '.js',
|
|
22
|
+
import: '.js',
|
|
23
|
+
scope: '.js',
|
|
24
|
+
visualizations: '.js',
|
|
25
|
+
cases: '.json'
|
|
26
|
+
};
|
|
27
|
+
/** The path of a file of the grammar `grammar` in a package: `constraints/datamodel.js`. */
|
|
28
|
+
export const metamodelPath = ({ kind, grammar }) => `${METAMODEL_FOLDERS[kind]}/${grammar}${EXTENSIONS[kind]}`;
|
|
29
|
+
//# sourceMappingURL=layout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layout.js","sourceRoot":"","sources":["../../../src/modules/metamodels/layout.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,OAAO,EAAE,UAAU;IACnB,WAAW,EAAE,aAAa;IAC1B,IAAI,EAAE,OAAO;IACb,MAAM,EAAE,SAAS;IACjB,KAAK,EAAE,QAAQ;IACf,cAAc,EAAE,gBAAgB;IAChC,KAAK,EAAE,OAAO;CACN,CAAA;AAIV,MAAM,UAAU,GAAsC;IACpD,OAAO,EAAE,UAAU;IACnB,WAAW,EAAE,KAAK;IAClB,IAAI,EAAE,KAAK;IACX,MAAM,EAAE,KAAK;IACb,KAAK,EAAE,KAAK;IACZ,cAAc,EAAE,KAAK;IACrB,KAAK,EAAE,OAAO;CACf,CAAA;AAED,4FAA4F;AAC5F,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,EAAE,IAAI,EAAE,OAAO,EAAgD,EAAU,EAAE,CACvG,GAAG,iBAAiB,CAAC,IAAI,CAAC,IAAI,OAAO,GAAG,UAAU,CAAC,IAAI,CAAC,EAAE,CAAA","sourcesContent":["/**\n * Where the files of a metamodel are in its package: one folder per kind, each file named after the grammar it belongs to.\n *\n * grammars/<g>.langium constraints/<g>.js specs/<g>.js imports/<g>.js\n * scopes/<g>.js visualizations/<g>.js cases/<g>.json\n *\n * The same folders are in the metamodels repository and in bango's examples.\n */\nexport const METAMODEL_FOLDERS = {\n grammar: 'grammars',\n constraints: 'constraints',\n spec: 'specs',\n import: 'imports',\n scope: 'scopes',\n visualizations: 'visualizations',\n cases: 'cases'\n} as const\n\nexport type MetamodelFileKind = keyof typeof METAMODEL_FOLDERS\n\nconst EXTENSIONS: Record<MetamodelFileKind, string> = {\n grammar: '.langium',\n constraints: '.js',\n spec: '.js',\n import: '.js',\n scope: '.js',\n visualizations: '.js',\n cases: '.json'\n}\n\n/** The path of a file of the grammar `grammar` in a package: `constraints/datamodel.js`. */\nexport const metamodelPath = ({ kind, grammar }: { kind: MetamodelFileKind, grammar: string }): string =>\n `${METAMODEL_FOLDERS[kind]}/${grammar}${EXTENSIONS[kind]}`\n\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ResolvedSpl } from '../types.js';
|
|
2
|
+
/** A model a module offers, as the product editor shows it: read-only. */
|
|
3
|
+
export interface OfferedModel {
|
|
4
|
+
/** Name of the module that offers it. */
|
|
5
|
+
readonly origin: string;
|
|
6
|
+
readonly metamodel: string;
|
|
7
|
+
/** Location of the module, and the file in it. */
|
|
8
|
+
readonly package: string;
|
|
9
|
+
readonly file: string;
|
|
10
|
+
readonly text: string;
|
|
11
|
+
}
|
|
12
|
+
/** The models the modules of an SPL offer (the ones that exist; `checkSpl` says what is wrong with the others). */
|
|
13
|
+
export declare const listOfferedModels: ({ resolved }: {
|
|
14
|
+
resolved: ResolvedSpl;
|
|
15
|
+
}) => Promise<OfferedModel[]>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { readPackageText } from '../packages/source.js';
|
|
2
|
+
/** The models the modules of an SPL offer (the ones that exist; `checkSpl` says what is wrong with the others). */
|
|
3
|
+
export const listOfferedModels = async ({ resolved }) => {
|
|
4
|
+
const offered = [];
|
|
5
|
+
for (const module of resolved.modules) {
|
|
6
|
+
for (const [metamodel, file] of Object.entries(module.manifest.offers)) {
|
|
7
|
+
const text = await readPackageText({ files: module.files, path: file });
|
|
8
|
+
if (text !== undefined)
|
|
9
|
+
offered.push({ origin: module.manifest.name, metamodel, package: module.location, file, text });
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return offered;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=offered.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"offered.js","sourceRoot":"","sources":["../../../src/modules/metamodels/offered.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAcvD,mHAAmH;AACnH,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EAAE,EAAE,QAAQ,EAA6B,EAA2B,EAAE;IAC1G,MAAM,OAAO,GAAmB,EAAE,CAAA;IAClC,KAAK,MAAM,MAAM,IAAI,QAAQ,CAAC,OAAO,EAAE,CAAC;QACtC,KAAK,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YACvE,MAAM,IAAI,GAAG,MAAM,eAAe,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;YACvE,IAAI,IAAI,KAAK,SAAS;gBAAE,OAAO,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;QACzH,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA","sourcesContent":["import { readPackageText } from '../packages/source.js'\nimport type { ResolvedSpl } from '../types.js'\n\n/** A model a module offers, as the product editor shows it: read-only. */\nexport interface OfferedModel {\n /** Name of the module that offers it. */\n readonly origin: string\n readonly metamodel: string\n /** Location of the module, and the file in it. */\n readonly package: string\n readonly file: string\n readonly text: string\n}\n\n/** The models the modules of an SPL offer (the ones that exist; `checkSpl` says what is wrong with the others). */\nexport const listOfferedModels = async ({ resolved }: { resolved: ResolvedSpl }): Promise<OfferedModel[]> => {\n const offered: OfferedModel[] = []\n for (const module of resolved.modules) {\n for (const [metamodel, file] of Object.entries(module.manifest.offers)) {\n const text = await readPackageText({ files: module.files, path: file })\n if (text !== undefined) offered.push({ origin: module.manifest.name, metamodel, package: module.location, file, text })\n }\n }\n return offered\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Diagnostic, ResolvedSpl } from '../types.js';
|
|
2
|
+
import { type MetamodelEngine, type MetamodelInfo } from './engine.js';
|
|
3
|
+
/**
|
|
4
|
+
* Loads the metamodels of an SPL into a fresh engine and composes them, then gives it the models the modules offer (read-only).
|
|
5
|
+
* What is wrong with any of it is returned as diagnostics.
|
|
6
|
+
*/
|
|
7
|
+
export declare const prepareEngine: ({ resolved, createEngine }: {
|
|
8
|
+
resolved: ResolvedSpl;
|
|
9
|
+
createEngine: () => MetamodelEngine;
|
|
10
|
+
}) => Promise<{
|
|
11
|
+
engine: MetamodelEngine;
|
|
12
|
+
metamodels: MetamodelInfo[];
|
|
13
|
+
diagnostics: Diagnostic[];
|
|
14
|
+
/** What the engine was given to offer, read-only: the models of the modules. The models of the SPL's levels are added to these. */
|
|
15
|
+
contributed: {
|
|
16
|
+
origin: string;
|
|
17
|
+
metamodel: string;
|
|
18
|
+
text: string;
|
|
19
|
+
}[];
|
|
20
|
+
}>;
|