@lbdudc/linea-core 0.1.0 → 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 +230 -358
- 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/extra.js +54 -54
- package/dist/line/templates/core/transformation.js +208 -196
- package/dist/line/templates/pipeline/.gitlab-ci.yml +51 -51
- package/dist/line/templates/pipeline/ci/test-client.sh +16 -16
- package/dist/line/templates/pipeline/ci/test-server.sh +16 -16
- 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 +82 -67
- 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,128 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { InvalidArgumentError, ModuleResolutionError } from '../../errors.js';
|
|
4
|
+
import { METAMODEL_MANIFEST_PATH, MODULE_MANIFEST_PATH } from './manifests.js';
|
|
5
|
+
const SKIPPED_DIRS = new Set(['.git', 'node_modules']);
|
|
6
|
+
const decoder = new TextDecoder();
|
|
7
|
+
const encoder = new TextEncoder();
|
|
8
|
+
/** A file of a package as text; `undefined` when it does not exist. */
|
|
9
|
+
export const readPackageText = async ({ files, path: filePath }) => {
|
|
10
|
+
const bytes = await files.read({ path: filePath });
|
|
11
|
+
return bytes === undefined ? undefined : decoder.decode(bytes);
|
|
12
|
+
};
|
|
13
|
+
const normalizeDir = (dir) => dir.replace(/\\/g, '/').replace(/^\/+|\/+$/g, '');
|
|
14
|
+
/** Whether `file` is inside `dir` (`''` is everything). */
|
|
15
|
+
const isUnder = (file, dir) => {
|
|
16
|
+
const prefix = normalizeDir(dir);
|
|
17
|
+
return prefix === '' || file.startsWith(prefix + '/');
|
|
18
|
+
};
|
|
19
|
+
/** The files of a directory on disk, as `PackageFiles`. `.git` and `node_modules` are not part of a package. */
|
|
20
|
+
export const createFsFiles = ({ dir }) => {
|
|
21
|
+
const root = path.resolve(dir);
|
|
22
|
+
const walk = (current, found) => {
|
|
23
|
+
for (const entry of fs.readdirSync(current, { withFileTypes: true })) {
|
|
24
|
+
if (entry.isDirectory()) {
|
|
25
|
+
if (!SKIPPED_DIRS.has(entry.name))
|
|
26
|
+
walk(path.join(current, entry.name), found);
|
|
27
|
+
}
|
|
28
|
+
else if (entry.isFile()) {
|
|
29
|
+
found.push(path.relative(root, path.join(current, entry.name)).split(path.sep).join('/'));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return found;
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
read: ({ path: filePath }) => {
|
|
36
|
+
const absolute = path.resolve(root, filePath);
|
|
37
|
+
// a path that climbs out of the package is no file of it
|
|
38
|
+
if (absolute !== root && !absolute.startsWith(root + path.sep))
|
|
39
|
+
return Promise.resolve(undefined);
|
|
40
|
+
try {
|
|
41
|
+
return Promise.resolve(new Uint8Array(fs.readFileSync(absolute)));
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return Promise.resolve(undefined);
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
list: ({ dir: sub }) => {
|
|
48
|
+
if (!fs.existsSync(root))
|
|
49
|
+
return Promise.resolve([]);
|
|
50
|
+
return Promise.resolve(walk(root, []).filter((file) => isUnder(file, sub)).sort());
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
/** A fixed set of packages held in memory: for tests, and for a server that has already fetched what it needs. */
|
|
55
|
+
export const createMemoryPackageSource = ({ packages, revisions = {} }) => ({
|
|
56
|
+
listVersions: ({ location }) => Promise.resolve(Object.keys(packages[location] ?? {})),
|
|
57
|
+
open: ({ location, version }) => {
|
|
58
|
+
const files = packages[location]?.[version];
|
|
59
|
+
if (files === undefined) {
|
|
60
|
+
return Promise.reject(new ModuleResolutionError(`${location} has no version ${version}.`));
|
|
61
|
+
}
|
|
62
|
+
const paths = Object.keys(files).sort();
|
|
63
|
+
const memory = {
|
|
64
|
+
read: ({ path: filePath }) => {
|
|
65
|
+
const content = files[filePath];
|
|
66
|
+
return Promise.resolve(content === undefined ? undefined : typeof content === 'string' ? encoder.encode(content) : content);
|
|
67
|
+
},
|
|
68
|
+
list: ({ dir }) => Promise.resolve(paths.filter((file) => isUnder(file, dir)))
|
|
69
|
+
};
|
|
70
|
+
return Promise.resolve(memory);
|
|
71
|
+
},
|
|
72
|
+
revision: ({ location, version }) => Promise.resolve(revisions[location]?.[version])
|
|
73
|
+
});
|
|
74
|
+
const FILE_PREFIX = 'file:';
|
|
75
|
+
/**
|
|
76
|
+
* Packages in folders on disk: the location `file:<folder>` is a folder under `root`. A folder is one working copy, so it has exactly one
|
|
77
|
+
* version, the one its manifest (`module.json` or `metamodel.json`) declares. This is what a local workspace (and the CLI) uses.
|
|
78
|
+
*/
|
|
79
|
+
export const createFsPackageSource = ({ root }) => {
|
|
80
|
+
const folderOf = (location) => {
|
|
81
|
+
if (!location.startsWith(FILE_PREFIX) || location.length === FILE_PREFIX.length) {
|
|
82
|
+
throw new InvalidArgumentError(`"${location}" is not a file: location.`);
|
|
83
|
+
}
|
|
84
|
+
const absolute = path.resolve(root, location.slice(FILE_PREFIX.length));
|
|
85
|
+
const base = path.resolve(root);
|
|
86
|
+
if (absolute !== base && !absolute.startsWith(base + path.sep)) {
|
|
87
|
+
throw new InvalidArgumentError(`"${location}" points outside the workspace.`);
|
|
88
|
+
}
|
|
89
|
+
return absolute;
|
|
90
|
+
};
|
|
91
|
+
const declaredVersion = (folder) => {
|
|
92
|
+
for (const manifest of [MODULE_MANIFEST_PATH, METAMODEL_MANIFEST_PATH]) {
|
|
93
|
+
const file = path.join(folder, manifest);
|
|
94
|
+
if (!fs.existsSync(file))
|
|
95
|
+
continue;
|
|
96
|
+
try {
|
|
97
|
+
const { version } = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
98
|
+
if (typeof version === 'string')
|
|
99
|
+
return version;
|
|
100
|
+
}
|
|
101
|
+
catch { /* a manifest that does not parse is reported when it is read */ }
|
|
102
|
+
}
|
|
103
|
+
return undefined;
|
|
104
|
+
};
|
|
105
|
+
return {
|
|
106
|
+
listVersions: ({ location }) => {
|
|
107
|
+
const version = declaredVersion(folderOf(location));
|
|
108
|
+
return Promise.resolve(version === undefined ? [] : [version]);
|
|
109
|
+
},
|
|
110
|
+
open: ({ location, version }) => {
|
|
111
|
+
const folder = folderOf(location);
|
|
112
|
+
if (declaredVersion(folder) !== version) {
|
|
113
|
+
return Promise.reject(new ModuleResolutionError(`${location} has no version ${version}.`));
|
|
114
|
+
}
|
|
115
|
+
return Promise.resolve(createFsFiles({ dir: folder }));
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* A source that answers for a few locations itself (a package made up on the spot, to check one on its own)
|
|
121
|
+
* and leaves every other to `base`.
|
|
122
|
+
*/
|
|
123
|
+
export const withOverlay = ({ base, overlay, locations }) => ({
|
|
124
|
+
listVersions: (args) => (locations.has(args.location) ? overlay.listVersions(args) : base.listVersions(args)),
|
|
125
|
+
open: (args) => (locations.has(args.location) ? overlay.open(args) : base.open(args)),
|
|
126
|
+
revision: (args) => (locations.has(args.location) ? Promise.resolve(undefined) : (base.revision?.(args) ?? Promise.resolve(undefined)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C,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;CACxI,CAAC,CAAA","sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\nimport { InvalidArgumentError, ModuleResolutionError } from '../../errors.js'\nimport { METAMODEL_MANIFEST_PATH, MODULE_MANIFEST_PATH } from './manifests.js'\nimport type { PackageFiles, PackageSource } from '../types.js'\n\nconst SKIPPED_DIRS: ReadonlySet<string> = new Set(['.git', 'node_modules'])\n\nconst decoder = new TextDecoder()\nconst encoder = new TextEncoder()\n\n/** A file of a package as text; `undefined` when it does not exist. */\nexport const readPackageText = async ({ files, path: filePath }: { files: PackageFiles, path: string }): Promise<string | undefined> => {\n const bytes = await files.read({ path: filePath })\n return bytes === undefined ? undefined : decoder.decode(bytes)\n}\n\nconst normalizeDir = (dir: string): string => dir.replace(/\\\\/g, '/').replace(/^\\/+|\\/+$/g, '')\n\n/** Whether `file` is inside `dir` (`''` is everything). */\nconst isUnder = (file: string, dir: string): boolean => {\n const prefix = normalizeDir(dir)\n return prefix === '' || file.startsWith(prefix + '/')\n}\n\n/** The files of a directory on disk, as `PackageFiles`. `.git` and `node_modules` are not part of a package. */\nexport const createFsFiles = ({ dir }: { dir: string }): PackageFiles => {\n const root = path.resolve(dir)\n const walk = (current: string, found: string[]): string[] => {\n for (const entry of fs.readdirSync(current, { withFileTypes: true })) {\n if (entry.isDirectory()) {\n if (!SKIPPED_DIRS.has(entry.name)) walk(path.join(current, entry.name), found)\n } else if (entry.isFile()) {\n found.push(path.relative(root, path.join(current, entry.name)).split(path.sep).join('/'))\n }\n }\n return found\n }\n return {\n read: ({ path: filePath }) => {\n const absolute = path.resolve(root, filePath)\n // a path that climbs out of the package is no file of it\n if (absolute !== root && !absolute.startsWith(root + path.sep)) return Promise.resolve(undefined)\n try {\n return Promise.resolve(new Uint8Array(fs.readFileSync(absolute)))\n } catch {\n return Promise.resolve(undefined)\n }\n },\n list: ({ dir: sub }) => {\n if (!fs.existsSync(root)) return Promise.resolve([])\n return Promise.resolve(walk(root, []).filter((file) => isUnder(file, sub)).sort())\n }\n }\n}\n\n/** location -> version -> path -> content */\nexport type MemoryPackages = Record<string, Record<string, Record<string, string | Uint8Array>>>\n\n/** A fixed set of packages held in memory: for tests, and for a server that has already fetched what it needs. */\nexport const createMemoryPackageSource = ({\n packages,\n revisions = {}\n}: {\n packages: MemoryPackages\n /** location -> version -> revision */\n revisions?: Record<string, Record<string, string>>\n}): PackageSource => ({\n listVersions: ({ location }) => Promise.resolve(Object.keys(packages[location] ?? {})),\n open: ({ location, version }) => {\n const files = packages[location]?.[version]\n if (files === undefined) {\n return Promise.reject(new ModuleResolutionError(`${location} has no version ${version}.`))\n }\n const paths = Object.keys(files).sort()\n const memory: PackageFiles = {\n read: ({ path: filePath }) => {\n const content = files[filePath]\n return Promise.resolve(content === undefined ? undefined : typeof content === 'string' ? encoder.encode(content) : content)\n },\n list: ({ dir }) => Promise.resolve(paths.filter((file) => isUnder(file, dir)))\n }\n return Promise.resolve(memory)\n },\n revision: ({ location, version }) => Promise.resolve(revisions[location]?.[version])\n})\n\nconst FILE_PREFIX = 'file:'\n\n/**\n * Packages in folders on disk: the location `file:<folder>` is a folder under `root`. A folder is one working copy, so it has exactly one\n * version, the one its manifest (`module.json` or `metamodel.json`) declares. This is what a local workspace (and the CLI) uses.\n */\nexport const createFsPackageSource = ({ root }: { root: string }): PackageSource => {\n const folderOf = (location: string): string => {\n if (!location.startsWith(FILE_PREFIX) || location.length === FILE_PREFIX.length) {\n throw new InvalidArgumentError(`\"${location}\" is not a file: location.`)\n }\n const absolute = path.resolve(root, location.slice(FILE_PREFIX.length))\n const base = path.resolve(root)\n if (absolute !== base && !absolute.startsWith(base + path.sep)) {\n throw new InvalidArgumentError(`\"${location}\" points outside the workspace.`)\n }\n return absolute\n }\n const declaredVersion = (folder: string): string | undefined => {\n for (const manifest of [MODULE_MANIFEST_PATH, METAMODEL_MANIFEST_PATH]) {\n const file = path.join(folder, manifest)\n if (!fs.existsSync(file)) continue\n try {\n const { version } = JSON.parse(fs.readFileSync(file, 'utf8')) as { version?: unknown }\n if (typeof version === 'string') return version\n } catch { /* a manifest that does not parse is reported when it is read */ }\n }\n return undefined\n }\n return {\n listVersions: ({ location }) => {\n const version = declaredVersion(folderOf(location))\n return Promise.resolve(version === undefined ? [] : [version])\n },\n open: ({ location, version }) => {\n const folder = folderOf(location)\n if (declaredVersion(folder) !== version) {\n return Promise.reject(new ModuleResolutionError(`${location} has no version ${version}.`))\n }\n return Promise.resolve(createFsFiles({ dir: folder }))\n }\n }\n}\n\n/**\n * A source that answers for a few locations itself (a package made up on the spot, to check one on its own)\n * and leaves every other to `base`.\n */\nexport const withOverlay = ({ base, overlay, locations }: { base: PackageSource, overlay: PackageSource, locations: ReadonlySet<string> }): PackageSource => ({\n listVersions: (args) => (locations.has(args.location) ? overlay.listVersions(args) : base.listVersions(args)),\n open: (args) => (locations.has(args.location) ? overlay.open(args) : base.open(args)),\n revision: (args) => (locations.has(args.location) ? Promise.resolve(undefined) : (base.revision?.(args) ?? Promise.resolve(undefined)))\n})\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type Configuration } from '../configuration/configure.js';
|
|
2
|
+
import type { MetamodelEngine, MetamodelInfo } from '../metamodels/engine.js';
|
|
3
|
+
import type { Diagnostic, PackageFiles, ResolvedSpl } from '../types.js';
|
|
4
|
+
export interface ProductCheckReport {
|
|
5
|
+
readonly ok: boolean;
|
|
6
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
7
|
+
/** The metamodels the product has to give a model of: the ones whose models are final (level 0). */
|
|
8
|
+
readonly metamodels: readonly MetamodelInfo[];
|
|
9
|
+
/** The product's models merged into one JSON document (what the derivation gets as `models`); only when everything is valid. */
|
|
10
|
+
readonly models?: unknown;
|
|
11
|
+
/** The JSON of each model on its own (`modelsByMetamodel`): its metamodel's mapping when it has one, else the plain tree of the model. */
|
|
12
|
+
readonly modelsByMetamodel?: Record<string, unknown>;
|
|
13
|
+
/** The SPL's models of the levels above (its feature model) and the platform composed with them. */
|
|
14
|
+
readonly configuration: Configuration;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Whether a product is right for its SPL: one model of each metamodel with final models (and no others), all valid together, against what
|
|
18
|
+
* the modules offer and against the SPL's models of the levels above: its feature selection is checked against its feature model by the
|
|
19
|
+
* feature metamodel itself. `models` is metamodel name -> text of the model.
|
|
20
|
+
*/
|
|
21
|
+
export declare const checkProduct: ({ resolved, spl, models, createEngine, loadCode }: {
|
|
22
|
+
resolved: ResolvedSpl;
|
|
23
|
+
spl?: PackageFiles;
|
|
24
|
+
models: Record<string, string>;
|
|
25
|
+
createEngine: () => MetamodelEngine;
|
|
26
|
+
/** `true` when the platform composed in the report (`configuration.plan`) is going to be written: it then has the code of the modules, not only the list of it. */
|
|
27
|
+
loadCode?: boolean;
|
|
28
|
+
}) => Promise<ProductCheckReport>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { configure } from '../configuration/configure.js';
|
|
2
|
+
import { hasErrors } from '../diagnostics.js';
|
|
3
|
+
import { prepareEngine } from '../metamodels/prepare.js';
|
|
4
|
+
const problemsOf = (problems, file) => problems
|
|
5
|
+
.filter(({ severity }) => severity === 'error' || severity === 'warning')
|
|
6
|
+
.map((problem) => ({
|
|
7
|
+
severity: problem.severity === 'error' ? 'error' : 'warning',
|
|
8
|
+
package: 'product',
|
|
9
|
+
file,
|
|
10
|
+
message: `${problem.startLine + 1}:${problem.startColumn + 1} ${problem.message}`
|
|
11
|
+
}));
|
|
12
|
+
/**
|
|
13
|
+
* Whether a product is right for its SPL: one model of each metamodel with final models (and no others), all valid together, against what
|
|
14
|
+
* the modules offer and against the SPL's models of the levels above: its feature selection is checked against its feature model by the
|
|
15
|
+
* feature metamodel itself. `models` is metamodel name -> text of the model.
|
|
16
|
+
*/
|
|
17
|
+
export const checkProduct = async ({ resolved, spl, models, createEngine, loadCode = false }) => {
|
|
18
|
+
const { engine, metamodels: all, diagnostics, contributed } = await prepareEngine({ resolved, createEngine });
|
|
19
|
+
// what cannot be composed cannot be derived, so it counts against the product too
|
|
20
|
+
const configuration = await configure({ engine, resolved, spl, metamodels: all, offered: contributed, diagnostics, loadCode });
|
|
21
|
+
const metamodels = all.filter((info) => info.level === 0);
|
|
22
|
+
const byName = new Map(metamodels.map((info) => [info.name, info]));
|
|
23
|
+
for (const info of metamodels) {
|
|
24
|
+
if (models[info.name] === undefined) {
|
|
25
|
+
diagnostics.push({ severity: 'error', package: 'product', file: `.linea/models/${info.name}.${info.extension}`, message: `There is no model of "${info.name}".` });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
for (const name of Object.keys(models)) {
|
|
29
|
+
if (!byName.has(name)) {
|
|
30
|
+
diagnostics.push({ severity: 'error', package: 'product', file: `.linea/models/${name}`, message: `"${name}" is not a metamodel of the products of this SPL.` });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
let merged;
|
|
34
|
+
let byMetamodel;
|
|
35
|
+
if (!hasErrors(diagnostics)) {
|
|
36
|
+
const states = await engine.setInstances(Object.fromEntries(Object.entries(models).filter(([name]) => byName.has(name))));
|
|
37
|
+
for (const state of states) {
|
|
38
|
+
const info = byName.get(state.metamodel);
|
|
39
|
+
diagnostics.push(...problemsOf(state.problems, `.linea/models/${state.metamodel}.${info?.extension ?? ''}`));
|
|
40
|
+
}
|
|
41
|
+
const built = await engine.build(resolved.spl.name);
|
|
42
|
+
// the problems of each model are already listed: what is left is what only the whole shows
|
|
43
|
+
if (!hasErrors(diagnostics)) {
|
|
44
|
+
for (const message of built.errors)
|
|
45
|
+
diagnostics.push({ severity: 'error', package: 'product', message });
|
|
46
|
+
}
|
|
47
|
+
if (built.ok) {
|
|
48
|
+
merged = built.model?.spec;
|
|
49
|
+
byMetamodel = Object.fromEntries((built.model?.instances ?? []).map((instance) => [instance.metamodel, instance.spec]));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const ok = !hasErrors(diagnostics);
|
|
53
|
+
return {
|
|
54
|
+
ok,
|
|
55
|
+
diagnostics,
|
|
56
|
+
metamodels,
|
|
57
|
+
configuration,
|
|
58
|
+
...(ok && merged !== undefined ? { models: merged, modelsByMetamodel: byMetamodel } : {})
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=check.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.js","sourceRoot":"","sources":["../../../src/modules/products/check.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAsB,MAAM,+BAA+B,CAAA;AAC7E,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAE7C,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAgBxD,MAAM,UAAU,GAAG,CAAC,QAAkC,EAAE,IAAY,EAAgB,EAAE,CACpF,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,SAAS;IAClB,IAAI;IACJ,OAAO,EAAE,GAAG,OAAO,CAAC,SAAS,GAAG,CAAC,IAAI,OAAO,CAAC,WAAW,GAAG,CAAC,IAAI,OAAO,CAAC,OAAO,EAAE;CAClF,CAAC,CAAC,CAAA;AAEP;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAAE,EACjC,QAAQ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,CAAA;YAC1B,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACzH,CAAC;IACH,CAAC;IAED,MAAM,EAAE,GAAG,CAAC,SAAS,CAAC,WAAW,CAAC,CAAA;IAClC,OAAO;QACL,EAAE;QACF,WAAW;QACX,UAAU;QACV,aAAa;QACb,GAAG,CAAC,EAAE,IAAI,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC1F,CAAA;AACH,CAAC,CAAA","sourcesContent":["import { configure, type Configuration } from '../configuration/configure.js'\nimport { hasErrors } from '../diagnostics.js'\nimport type { EngineProblem, MetamodelEngine, MetamodelInfo } from '../metamodels/engine.js'\nimport { prepareEngine } from '../metamodels/prepare.js'\nimport type { Diagnostic, PackageFiles, ResolvedSpl } from '../types.js'\n\nexport interface ProductCheckReport {\n readonly ok: boolean\n readonly diagnostics: readonly Diagnostic[]\n /** The metamodels the product has to give a model of: the ones whose models are final (level 0). */\n readonly metamodels: readonly MetamodelInfo[]\n /** The product's models merged into one JSON document (what the derivation gets as `models`); only when everything is valid. */\n readonly models?: unknown\n /** The JSON of each model on its own (`modelsByMetamodel`): its metamodel's mapping when it has one, else the plain tree of the model. */\n readonly modelsByMetamodel?: Record<string, unknown>\n /** The SPL's models of the levels above (its feature model) and the platform composed with them. */\n readonly configuration: Configuration\n}\n\nconst problemsOf = (problems: readonly EngineProblem[], file: string): 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: 'product',\n file,\n message: `${problem.startLine + 1}:${problem.startColumn + 1} ${problem.message}`\n }))\n\n/**\n * Whether a product is right for its SPL: one model of each metamodel with final models (and no others), all valid together, against what\n * the modules offer and against the SPL's models of the levels above: its feature selection is checked against its feature model by the\n * feature metamodel itself. `models` is metamodel name -> text of the model.\n */\nexport const checkProduct = async ({\n resolved,\n spl,\n models,\n createEngine,\n loadCode = false\n}: {\n resolved: ResolvedSpl\n spl?: PackageFiles\n models: Record<string, string>\n createEngine: () => MetamodelEngine\n /** `true` when the platform composed in the report (`configuration.plan`) is going to be written: it then has the code of the modules, not only the list of it. */\n loadCode?: boolean\n}): Promise<ProductCheckReport> => {\n const { engine, metamodels: all, diagnostics, contributed } = await prepareEngine({ resolved, createEngine })\n // what cannot be composed cannot be derived, so it counts against the product too\n const configuration = await configure({ engine, resolved, spl, metamodels: all, offered: contributed, diagnostics, loadCode })\n const metamodels = all.filter((info) => info.level === 0)\n const byName = new Map(metamodels.map((info) => [info.name, info]))\n\n for (const info of metamodels) {\n if (models[info.name] === undefined) {\n diagnostics.push({ severity: 'error', package: 'product', file: `.linea/models/${info.name}.${info.extension}`, message: `There is no model of \"${info.name}\".` })\n }\n }\n for (const name of Object.keys(models)) {\n if (!byName.has(name)) {\n diagnostics.push({ severity: 'error', package: 'product', file: `.linea/models/${name}`, message: `\"${name}\" is not a metamodel of the products of this SPL.` })\n }\n }\n\n let merged: unknown\n let byMetamodel: Record<string, unknown> | undefined\n if (!hasErrors(diagnostics)) {\n const states = await engine.setInstances(Object.fromEntries(Object.entries(models).filter(([name]) => byName.has(name))))\n for (const state of states) {\n const info = byName.get(state.metamodel)\n diagnostics.push(...problemsOf(state.problems, `.linea/models/${state.metamodel}.${info?.extension ?? ''}`))\n }\n const built = await engine.build(resolved.spl.name)\n // the problems of each model are already listed: what is left is what only the whole shows\n if (!hasErrors(diagnostics)) {\n for (const message of built.errors) diagnostics.push({ severity: 'error', package: 'product', message })\n }\n if (built.ok) {\n merged = built.model?.spec\n byMetamodel = Object.fromEntries((built.model?.instances ?? []).map((instance) => [instance.metamodel, instance.spec]))\n }\n }\n\n const ok = !hasErrors(diagnostics)\n return {\n ok,\n diagnostics,\n metamodels,\n configuration,\n ...(ok && merged !== undefined ? { models: merged, modelsByMetamodel: byMetamodel } : {})\n }\n}\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ProductSpec } from '../../product/spec.js';
|
|
2
|
+
import type { MetamodelEngine } from '../metamodels/engine.js';
|
|
3
|
+
import type { Diagnostic, PackageFiles, ResolvedSpl } from '../types.js';
|
|
4
|
+
/** Which phase of deriving a modular product is running, in order. */
|
|
5
|
+
export type DerivationPhase = 'check' | 'platform' | 'derive';
|
|
6
|
+
/**
|
|
7
|
+
* Derives a product of a modular SPL: the platform is composed from the modules in a scratch directory, the product's models are checked
|
|
8
|
+
* and merged, and the usual derivation runs with them as `spec.models` (what the transformations of the modules read).
|
|
9
|
+
* Throws `ModuleCheckError` (with the diagnostics) when the product does not fit its SPL.
|
|
10
|
+
*/
|
|
11
|
+
export declare const deriveModularProduct: ({ resolved, spl, spec, models, createEngine, outputDir, onProgress }: {
|
|
12
|
+
resolved: ResolvedSpl;
|
|
13
|
+
spl?: PackageFiles;
|
|
14
|
+
spec: ProductSpec;
|
|
15
|
+
models: Record<string, string>;
|
|
16
|
+
createEngine: () => MetamodelEngine;
|
|
17
|
+
outputDir: string;
|
|
18
|
+
onProgress?: (phase: DerivationPhase) => void | Promise<void>;
|
|
19
|
+
}) => Promise<{
|
|
20
|
+
outputDir: string;
|
|
21
|
+
diagnostics: readonly Diagnostic[];
|
|
22
|
+
}>;
|
|
23
|
+
/** Like `deriveModularProduct`, but the product comes back as a zip. */
|
|
24
|
+
export declare const deriveModularProductToZip: ({ resolved, spl, spec, models, createEngine }: {
|
|
25
|
+
resolved: ResolvedSpl;
|
|
26
|
+
spl?: PackageFiles;
|
|
27
|
+
spec: ProductSpec;
|
|
28
|
+
models: Record<string, string>;
|
|
29
|
+
createEngine: () => MetamodelEngine;
|
|
30
|
+
}) => Promise<Buffer>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { ModuleCheckError } from '../../errors.js';
|
|
5
|
+
import { deriveProduct, deriveProductToZip } from '../../derivation/derive.js';
|
|
6
|
+
import { writePlatform } from '../spl/platform.js';
|
|
7
|
+
import { checkProduct } from './check.js';
|
|
8
|
+
/** Checks the product and composes the platform of its SPL in a scratch directory, ready to derive from. */
|
|
9
|
+
const prepareDerivation = async ({ resolved, spl, spec, models, createEngine, onProgress }) => {
|
|
10
|
+
await onProgress?.('check');
|
|
11
|
+
const report = await checkProduct({ resolved, spl, models, createEngine, loadCode: true });
|
|
12
|
+
if (!report.ok) {
|
|
13
|
+
const errors = report.diagnostics.filter(({ severity }) => severity === 'error');
|
|
14
|
+
throw new ModuleCheckError(`The product does not fit its SPL:\n- ${errors.map(({ package: from, file, message }) => `${from}${file === undefined ? '' : ` ${file}`}: ${message}`).join('\n- ')}`, report.diagnostics);
|
|
15
|
+
}
|
|
16
|
+
const scratch = fs.mkdtempSync(path.join(os.tmpdir(), 'linea-spl-'));
|
|
17
|
+
const dispose = () => { fs.rmSync(scratch, { recursive: true, force: true }); };
|
|
18
|
+
try {
|
|
19
|
+
await onProgress?.('platform');
|
|
20
|
+
const { lineDir } = writePlatform({ plan: report.configuration.plan, lineDir: scratch });
|
|
21
|
+
// the features of the product are its feature selection's: the feature metamodel works out what the feature model implies
|
|
22
|
+
const features = report.models?.features;
|
|
23
|
+
return { lineDir, spec: { ...spec, ...(features === undefined ? {} : { features }), models: report.models, modelsByMetamodel: report.modelsByMetamodel }, diagnostics: report.diagnostics, dispose };
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
dispose();
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Derives a product of a modular SPL: the platform is composed from the modules in a scratch directory, the product's models are checked
|
|
32
|
+
* and merged, and the usual derivation runs with them as `spec.models` (what the transformations of the modules read).
|
|
33
|
+
* Throws `ModuleCheckError` (with the diagnostics) when the product does not fit its SPL.
|
|
34
|
+
*/
|
|
35
|
+
export const deriveModularProduct = async ({ resolved, spl, spec, models, createEngine, outputDir, onProgress }) => {
|
|
36
|
+
const prepared = await prepareDerivation({ resolved, spl, spec, models, createEngine, onProgress });
|
|
37
|
+
try {
|
|
38
|
+
await onProgress?.('derive');
|
|
39
|
+
const result = await deriveProduct({ lineDir: prepared.lineDir, spec: prepared.spec, outputDir });
|
|
40
|
+
return { outputDir: result.outputDir, diagnostics: prepared.diagnostics };
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
prepared.dispose();
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
/** Like `deriveModularProduct`, but the product comes back as a zip. */
|
|
47
|
+
export const deriveModularProductToZip = async ({ resolved, spl, spec, models, createEngine }) => {
|
|
48
|
+
const prepared = await prepareDerivation({ resolved, spl, spec, models, createEngine });
|
|
49
|
+
try {
|
|
50
|
+
return await deriveProductToZip({ lineDir: prepared.lineDir, spec: prepared.spec });
|
|
51
|
+
}
|
|
52
|
+
finally {
|
|
53
|
+
prepared.dispose();
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=derive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"derive.js","sourceRoot":"","sources":["../../../src/modules/products/derive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAG9E,OAAO,EAAE,aAAa,EAAE,M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,MAAM,CAAC,SAAS,EAAE,WAAW,EAAE,QAAQ,CAAC,WAAW,EAAE,CAAA;IAC3E,CAAC;YAAS,CAAC;QACT,QAAQ,CAAC,OAAO,EAAE,CAAA;IACpB,CAAC;AACH,CAAC,CAAA;AAED,wEAAwE;AACxE,MAAM,CAAC,MAAM,yBAAyB,GAAG,KAAK,EAAE,EAC9C,QAAQ,EACR,GAAG,EACH,IAAI,EACJ,MAAM,EACN,YAAY,EAOb,EAAmB,EAAE;IACpB,MAAM,QAAQ,GAAG,MAAM,iBAAiB,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,CAAA;IACvF,IAAI,CAAC;QACH,OAAO,MAAM,kBAAkB,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;IACrF,CAAC;YAAS,CAAC;QACT,QAAQ,CAAC,OAAO,EAAE,CAAA;IACpB,CAAC;AACH,CAAC,CAAA","sourcesContent":["import fs from 'node:fs'\nimport os from 'node:os'\nimport path from 'node:path'\nimport { ModuleCheckError } from '../../errors.js'\nimport { deriveProduct, deriveProductToZip } from '../../derivation/derive.js'\nimport type { ProductSpec } from '../../product/spec.js'\nimport type { MetamodelEngine } from '../metamodels/engine.js'\nimport { writePlatform } from '../spl/platform.js'\nimport type { Diagnostic, PackageFiles, ResolvedSpl } from '../types.js'\nimport { checkProduct } from './check.js'\n\ninterface Scratch {\n readonly lineDir: string\n readonly spec: ProductSpec\n readonly diagnostics: readonly Diagnostic[]\n readonly dispose: () => void\n}\n\n/** Which phase of deriving a modular product is running, in order. */\nexport type DerivationPhase = 'check' | 'platform' | 'derive'\n\n/** Checks the product and composes the platform of its SPL in a scratch directory, ready to derive from. */\nconst prepareDerivation = async ({\n resolved,\n spl,\n spec,\n models,\n createEngine,\n onProgress\n}: {\n resolved: ResolvedSpl\n spl?: PackageFiles\n spec: ProductSpec\n models: Record<string, string>\n createEngine: () => MetamodelEngine\n onProgress?: (phase: DerivationPhase) => void | Promise<void>\n}): Promise<Scratch> => {\n await onProgress?.('check')\n const report = await checkProduct({ resolved, spl, models, createEngine, loadCode: true })\n if (!report.ok) {\n const errors = report.diagnostics.filter(({ severity }) => severity === 'error')\n throw new ModuleCheckError(\n `The product does not fit its SPL:\\n- ${errors.map(({ package: from, file, message }) => `${from}${file === undefined ? '' : ` ${file}`}: ${message}`).join('\\n- ')}`,\n report.diagnostics\n )\n }\n const scratch = fs.mkdtempSync(path.join(os.tmpdir(), 'linea-spl-'))\n const dispose = (): void => { fs.rmSync(scratch, { recursive: true, force: true }) }\n try {\n await onProgress?.('platform')\n const { lineDir } = writePlatform({ plan: report.configuration.plan, lineDir: scratch })\n // the features of the product are its feature selection's: the feature metamodel works out what the feature model implies\n const features = (report.models as { features?: string[] } | undefined)?.features\n return { lineDir, spec: { ...spec, ...(features === undefined ? {} : { features }), models: report.models, modelsByMetamodel: report.modelsByMetamodel }, diagnostics: report.diagnostics, dispose }\n } catch (error) {\n dispose()\n throw error\n }\n}\n\n/**\n * Derives a product of a modular SPL: the platform is composed from the modules in a scratch directory, the product's models are checked\n * and merged, and the usual derivation runs with them as `spec.models` (what the transformations of the modules read).\n * Throws `ModuleCheckError` (with the diagnostics) when the product does not fit its SPL.\n */\nexport const deriveModularProduct = async ({\n resolved,\n spl,\n spec,\n models,\n createEngine,\n outputDir,\n onProgress\n}: {\n resolved: ResolvedSpl\n spl?: PackageFiles\n spec: ProductSpec\n models: Record<string, string>\n createEngine: () => MetamodelEngine\n outputDir: string\n onProgress?: (phase: DerivationPhase) => void | Promise<void>\n}): Promise<{ outputDir: string, diagnostics: readonly Diagnostic[] }> => {\n const prepared = await prepareDerivation({ resolved, spl, spec, models, createEngine, onProgress })\n try {\n await onProgress?.('derive')\n const result = await deriveProduct({ lineDir: prepared.lineDir, spec: prepared.spec, outputDir })\n return { outputDir: result.outputDir, diagnostics: prepared.diagnostics }\n } finally {\n prepared.dispose()\n }\n}\n\n/** Like `deriveModularProduct`, but the product comes back as a zip. */\nexport const deriveModularProductToZip = async ({\n resolved,\n spl,\n spec,\n models,\n createEngine\n}: {\n resolved: ResolvedSpl\n spl?: PackageFiles\n spec: ProductSpec\n models: Record<string, string>\n createEngine: () => MetamodelEngine\n}): Promise<Buffer> => {\n const prepared = await prepareDerivation({ resolved, spl, spec, models, createEngine })\n try {\n return await deriveProductToZip({ lineDir: prepared.lineDir, spec: prepared.spec })\n } finally {\n prepared.dispose()\n }\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { checkProduct } from './check.js';
|
|
2
|
+
export type { ProductCheckReport } from './check.js';
|
|
3
|
+
export { seedProductModels } from './seed.js';
|
|
4
|
+
export { deriveModularProduct, deriveModularProductToZip } from './derive.js';
|
|
5
|
+
export type { DerivationPhase } from './derive.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/products/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAEzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAC7C,OAAO,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA","sourcesContent":["export { checkProduct } from './check.js'\nexport type { ProductCheckReport } from './check.js'\nexport { seedProductModels } from './seed.js'\nexport { deriveModularProduct, deriveModularProductToZip } from './derive.js'\nexport type { DerivationPhase } from './derive.js'\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type Configuration } from '../configuration/configure.js';
|
|
2
|
+
import type { MetamodelEngine, MetamodelInfo } from '../metamodels/engine.js';
|
|
3
|
+
import type { Diagnostic, PackageFiles, ResolvedSpl } from '../types.js';
|
|
4
|
+
/**
|
|
5
|
+
* The first text of each model of a product: what the metamodel says is the smallest valid one. For a new product, so it starts with
|
|
6
|
+
* a file for every metamodel with final models (level 0); the SPL's models of the levels above are offered while they are made, so a
|
|
7
|
+
* feature selection starts out as a selection of the SPL's feature model.
|
|
8
|
+
*/
|
|
9
|
+
export declare const seedProductModels: ({ resolved, spl, createEngine }: {
|
|
10
|
+
resolved: ResolvedSpl;
|
|
11
|
+
spl?: PackageFiles;
|
|
12
|
+
createEngine: () => MetamodelEngine;
|
|
13
|
+
}) => Promise<{
|
|
14
|
+
models: Record<string, string>;
|
|
15
|
+
metamodels: readonly MetamodelInfo[];
|
|
16
|
+
diagnostics: readonly Diagnostic[];
|
|
17
|
+
configuration: Configuration;
|
|
18
|
+
}>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { configure } from '../configuration/configure.js';
|
|
2
|
+
import { FEATURE_SELECTION_GRAMMAR } from '../configuration/constants.js';
|
|
3
|
+
import { defaultSelection, selectionText } from '../configuration/selection.js';
|
|
4
|
+
import { prepareEngine } from '../metamodels/prepare.js';
|
|
5
|
+
/**
|
|
6
|
+
* The first text of each model of a product: what the metamodel says is the smallest valid one. For a new product, so it starts with
|
|
7
|
+
* a file for every metamodel with final models (level 0); the SPL's models of the levels above are offered while they are made, so a
|
|
8
|
+
* feature selection starts out as a selection of the SPL's feature model.
|
|
9
|
+
*/
|
|
10
|
+
export const seedProductModels = async ({ resolved, spl, createEngine }) => {
|
|
11
|
+
const { engine, metamodels: all, diagnostics, contributed } = await prepareEngine({ resolved, createEngine });
|
|
12
|
+
const configuration = await configure({ engine, resolved, spl, metamodels: all, offered: contributed, diagnostics, loadCode: false });
|
|
13
|
+
const metamodels = all.filter((info) => info.level === 0);
|
|
14
|
+
const models = {};
|
|
15
|
+
for (const info of metamodels)
|
|
16
|
+
models[info.name] = (await engine.createInstance(info.name)).text;
|
|
17
|
+
// a new product starts from the smallest selection its feature model accepts, so it is not born invalid
|
|
18
|
+
if (configuration.featureModel !== undefined && models[FEATURE_SELECTION_GRAMMAR] !== undefined) {
|
|
19
|
+
models[FEATURE_SELECTION_GRAMMAR] = selectionText({ model: configuration.featureModel.name, features: defaultSelection({ tree: configuration.featureModel }) });
|
|
20
|
+
}
|
|
21
|
+
return { models, metamodels, diagnostics, configuration };
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=seed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seed.js","sourceRoot":"","sources":["../../../src/modules/products/seed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAsB,MAAM,+BAA+B,CAAA;AAC7E,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAA;AACzE,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAA;AAE/E,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAGxD;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EAAE,EACtC,QAAQ,EACR,GAAG,EACH,YAAY,EAKb,EAAuJ,EAAE;IACxJ,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,MAAM,aAAa,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC,CAAA;IAC7G,MAAM,aAAa,GAAG,MAAM,SAAS,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAA;IACrI,MAAM,UAAU,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,KAAK,CAAC,CAAC,CAAA;IACzD,MAAM,MAAM,GAA2B,EAAE,CAAA;IACzC,KAAK,MAAM,IAAI,IAAI,UAAU;QAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAA;IAChG,wGAAwG;IACxG,IAAI,aAAa,CAAC,YAAY,KAAK,SAAS,IAAI,MAAM,CAAC,yBAAyB,CAAC,KAAK,SAAS,EAAE,CAAC;QAChG,MAAM,CAAC,yBAAyB,CAAC,GAAG,aAAa,CAAC,EAAE,KAAK,EAAE,aAAa,CAAC,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,gBAAgB,CAAC,EAAE,IAAI,EAAE,aAAa,CAAC,YAAY,EAAE,CAAC,EAAE,CAAC,CAAA;IACjK,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,aAAa,EAAE,CAAA;AAC3D,CAAC,CAAA","sourcesContent":["import { configure, type Configuration } from '../configuration/configure.js'\nimport { FEATURE_SELECTION_GRAMMAR } from '../configuration/constants.js'\nimport { defaultSelection, selectionText } from '../configuration/selection.js'\nimport type { MetamodelEngine, MetamodelInfo } from '../metamodels/engine.js'\nimport { prepareEngine } from '../metamodels/prepare.js'\nimport type { Diagnostic, PackageFiles, ResolvedSpl } from '../types.js'\n\n/**\n * The first text of each model of a product: what the metamodel says is the smallest valid one. For a new product, so it starts with\n * a file for every metamodel with final models (level 0); the SPL's models of the levels above are offered while they are made, so a\n * feature selection starts out as a selection of the SPL's feature model.\n */\nexport const seedProductModels = async ({\n resolved,\n spl,\n createEngine\n}: {\n resolved: ResolvedSpl\n spl?: PackageFiles\n createEngine: () => MetamodelEngine\n}): Promise<{ models: Record<string, string>, metamodels: readonly MetamodelInfo[], diagnostics: readonly Diagnostic[], configuration: Configuration }> => {\n const { engine, metamodels: all, diagnostics, contributed } = await prepareEngine({ resolved, createEngine })\n const configuration = await configure({ engine, resolved, spl, metamodels: all, offered: contributed, diagnostics, loadCode: false })\n const metamodels = all.filter((info) => info.level === 0)\n const models: Record<string, string> = {}\n for (const info of metamodels) models[info.name] = (await engine.createInstance(info.name)).text\n // a new product starts from the smallest selection its feature model accepts, so it is not born invalid\n if (configuration.featureModel !== undefined && models[FEATURE_SELECTION_GRAMMAR] !== undefined) {\n models[FEATURE_SELECTION_GRAMMAR] = selectionText({ model: configuration.featureModel.name, features: defaultSelection({ tree: configuration.featureModel }) })\n }\n return { models, metamodels, diagnostics, configuration }\n}\n"]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { PackageKind, PackageSource, RegistryEntry, RegistryIndex } from '../types.js';
|
|
2
|
+
import { type PackageRegistry } from './registry.js';
|
|
3
|
+
/**
|
|
4
|
+
* Which packages a LINEA installation lists. A catalog only SAYS what is registered; it neither fetches packages (that is a
|
|
5
|
+
* `PackageSource`) nor decides what may be resolved: an SPL can still require a location that is not in it.
|
|
6
|
+
* Modules and metamodels share one catalog, each entry with its kind.
|
|
7
|
+
*/
|
|
8
|
+
export interface PackageCatalog {
|
|
9
|
+
list: (args?: {
|
|
10
|
+
kind?: PackageKind;
|
|
11
|
+
}) => Promise<RegistryEntry[]>;
|
|
12
|
+
get: (args: {
|
|
13
|
+
location: string;
|
|
14
|
+
}) => Promise<RegistryEntry | undefined>;
|
|
15
|
+
/** Adds the entry, or replaces the one at its location. */
|
|
16
|
+
add: (args: {
|
|
17
|
+
entry: RegistryEntry;
|
|
18
|
+
}) => Promise<void>;
|
|
19
|
+
/** Does nothing when the location is not registered. */
|
|
20
|
+
remove: (args: {
|
|
21
|
+
location: string;
|
|
22
|
+
}) => Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
/** A catalog held in memory: for tests, and for a server that keeps the catalog somewhere else and loads it whole. */
|
|
25
|
+
export declare const createMemoryCatalog: ({ index }?: {
|
|
26
|
+
index?: RegistryIndex;
|
|
27
|
+
}) => PackageCatalog;
|
|
28
|
+
/**
|
|
29
|
+
* A catalog kept in ONE text file (`registry.json`). `read` gives its content, or `undefined` when there is none yet (an empty
|
|
30
|
+
* catalog); `write` stores the new content. Where the file lives (a folder, a git repository) is up to the caller.
|
|
31
|
+
*/
|
|
32
|
+
export declare const createFileCatalog: ({ read, write }: {
|
|
33
|
+
read: () => Promise<string | undefined>;
|
|
34
|
+
write: (args: {
|
|
35
|
+
content: string;
|
|
36
|
+
message: string;
|
|
37
|
+
}) => Promise<void>;
|
|
38
|
+
}) => PackageCatalog;
|
|
39
|
+
/**
|
|
40
|
+
* Registers a package after reading it: its latest version must have a valid manifest of the registry's kind, which gives the
|
|
41
|
+
* entry its name and description. A location already registered as the other kind is refused (`resolveSpl` refuses it too).
|
|
42
|
+
*/
|
|
43
|
+
export declare const registerPackage: ({ catalog, registry, location, addedBy, now }: {
|
|
44
|
+
catalog: PackageCatalog;
|
|
45
|
+
registry: PackageRegistry<{
|
|
46
|
+
name: string;
|
|
47
|
+
version: string;
|
|
48
|
+
description?: string;
|
|
49
|
+
}>;
|
|
50
|
+
location: string;
|
|
51
|
+
addedBy?: string;
|
|
52
|
+
now?: () => Date;
|
|
53
|
+
}) => Promise<RegistryEntry>;
|
|
54
|
+
/**
|
|
55
|
+
* Registers a location without being told what it is: a package says so with its manifest (`module.json` or `metamodel.json`) at its
|
|
56
|
+
* latest version. One without a published version is refused like in `registerPackage`.
|
|
57
|
+
*/
|
|
58
|
+
export declare const registerLocation: ({ catalog, source, location, addedBy, now }: {
|
|
59
|
+
catalog: PackageCatalog;
|
|
60
|
+
source: PackageSource;
|
|
61
|
+
location: string;
|
|
62
|
+
addedBy?: string;
|
|
63
|
+
now?: () => Date;
|
|
64
|
+
}) => Promise<RegistryEntry>;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import semver from 'semver';
|
|
2
|
+
import { ModuleResolutionError } from '../../errors.js';
|
|
3
|
+
import { MODULE_MANIFEST_PATH, emptyRegistryIndex, parseRegistryIndex, serializeRegistryIndex } from '../packages/manifests.js';
|
|
4
|
+
import { createMetamodelRegistry, createModuleRegistry } from './registry.js';
|
|
5
|
+
const entriesOf = (index) => Object.entries(index.packages)
|
|
6
|
+
.map(([location, entry]) => ({ location, ...entry }))
|
|
7
|
+
.sort((a, b) => (a.location < b.location ? -1 : a.location > b.location ? 1 : 0));
|
|
8
|
+
const catalogOver = ({ load, save }) => ({
|
|
9
|
+
list: async ({ kind } = {}) => entriesOf(await load()).filter((entry) => kind === undefined || entry.kind === kind),
|
|
10
|
+
get: async ({ location }) => entriesOf(await load()).find((entry) => entry.location === location),
|
|
11
|
+
add: async ({ entry: { location, ...rest } }) => {
|
|
12
|
+
const index = await load();
|
|
13
|
+
await save({ registryVersion: 1, packages: { ...index.packages, [location]: rest } }, `Register ${location}`);
|
|
14
|
+
},
|
|
15
|
+
remove: async ({ location }) => {
|
|
16
|
+
const index = await load();
|
|
17
|
+
if (index.packages[location] === undefined)
|
|
18
|
+
return;
|
|
19
|
+
const packages = Object.fromEntries(Object.entries(index.packages).filter(([key]) => key !== location));
|
|
20
|
+
await save({ registryVersion: 1, packages }, `Unregister ${location}`);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
/** A catalog held in memory: for tests, and for a server that keeps the catalog somewhere else and loads it whole. */
|
|
24
|
+
export const createMemoryCatalog = ({ index } = {}) => {
|
|
25
|
+
let current = index ?? emptyRegistryIndex();
|
|
26
|
+
return catalogOver({
|
|
27
|
+
load: () => Promise.resolve(current),
|
|
28
|
+
save: (next) => {
|
|
29
|
+
current = next;
|
|
30
|
+
return Promise.resolve();
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* A catalog kept in ONE text file (`registry.json`). `read` gives its content, or `undefined` when there is none yet (an empty
|
|
36
|
+
* catalog); `write` stores the new content. Where the file lives (a folder, a git repository) is up to the caller.
|
|
37
|
+
*/
|
|
38
|
+
export const createFileCatalog = ({ read, write }) => {
|
|
39
|
+
return catalogOver({
|
|
40
|
+
load: async () => {
|
|
41
|
+
const content = await read();
|
|
42
|
+
return content === undefined ? emptyRegistryIndex() : parseRegistryIndex({ content });
|
|
43
|
+
},
|
|
44
|
+
save: async (index, message) => {
|
|
45
|
+
const before = await read();
|
|
46
|
+
const after = serializeRegistryIndex({ index });
|
|
47
|
+
if (before !== after)
|
|
48
|
+
await write({ content: after, message });
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Registers a package after reading it: its latest version must have a valid manifest of the registry's kind, which gives the
|
|
54
|
+
* entry its name and description. A location already registered as the other kind is refused (`resolveSpl` refuses it too).
|
|
55
|
+
*/
|
|
56
|
+
export const registerPackage = async ({ catalog, registry, location, addedBy, now = () => new Date() }) => {
|
|
57
|
+
const existing = await catalog.get({ location });
|
|
58
|
+
if (existing !== undefined && existing.kind !== registry.kind) {
|
|
59
|
+
throw new ModuleResolutionError(`${location} is already registered as a ${existing.kind}, not a ${registry.kind}.`);
|
|
60
|
+
}
|
|
61
|
+
const latest = semver.rsort(await registry.versions({ location }))[0];
|
|
62
|
+
if (latest === undefined) {
|
|
63
|
+
throw new ModuleResolutionError(`${location} has no published version (a tag such as v1.0.0), so it cannot be registered.`);
|
|
64
|
+
}
|
|
65
|
+
const { manifest } = await registry.load({ location, version: latest });
|
|
66
|
+
const entry = {
|
|
67
|
+
kind: registry.kind,
|
|
68
|
+
location,
|
|
69
|
+
name: manifest.name,
|
|
70
|
+
...(manifest.description === undefined ? {} : { description: manifest.description }),
|
|
71
|
+
addedAt: existing?.addedAt ?? now().toISOString(),
|
|
72
|
+
...(addedBy === undefined ? {} : { addedBy: existing?.addedBy ?? addedBy })
|
|
73
|
+
};
|
|
74
|
+
await catalog.add({ entry });
|
|
75
|
+
return entry;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Registers a location without being told what it is: a package says so with its manifest (`module.json` or `metamodel.json`) at its
|
|
79
|
+
* latest version. One without a published version is refused like in `registerPackage`.
|
|
80
|
+
*/
|
|
81
|
+
export const registerLocation = async ({ catalog, source, location, addedBy, now }) => {
|
|
82
|
+
const latest = semver.rsort(await source.listVersions({ location }))[0];
|
|
83
|
+
let isModule = true; // with no version to read, the module registry gives the error ("no published version")
|
|
84
|
+
if (latest !== undefined) {
|
|
85
|
+
const files = await source.open({ location, version: latest });
|
|
86
|
+
isModule = (await files.read({ path: MODULE_MANIFEST_PATH })) !== undefined || (await files.read({ path: 'metamodel.json' })) === undefined;
|
|
87
|
+
}
|
|
88
|
+
const registry = isModule ? createModuleRegistry({ source }) : createMetamodelRegistry({ source });
|
|
89
|
+
return registerPackage({ catalog, registry, location, ...(addedBy === undefined ? {} : { addedBy }), ...(now === undefined ? {} : { now }) });
|
|
90
|
+
};
|
|
91
|
+
//# sourceMappingURL=catalog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.js","sourceRoot":"","sources":["../../../src/modules/registry/catalog.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AACvD,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AAE/H,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAwB,MAAM,eAAe,CAAA;AAgBnG,MAAM,SAAS,GAAG,CAAC,KAAoB,EAAmB,EAAE,CAC1D,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC;KAC3B,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;KACpD,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAErF,MAAM,WAAW,GAA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CAAC,EAAE,GAAG,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAA;AAC/I,CAAC,CAAA","sourcesContent":["import semver from 'semver'\nimport { ModuleResolutionError } from '../../errors.js'\nimport { MODULE_MANIFEST_PATH, emptyRegistryIndex, parseRegistryIndex, serializeRegistryIndex } from '../packages/manifests.js'\nimport type { PackageKind, PackageSource, RegistryEntry, RegistryIndex } from '../types.js'\nimport { createMetamodelRegistry, createModuleRegistry, type PackageRegistry } from './registry.js'\n\n/**\n * Which packages a LINEA installation lists. A catalog only SAYS what is registered; it neither fetches packages (that is a\n * `PackageSource`) nor decides what may be resolved: an SPL can still require a location that is not in it.\n * Modules and metamodels share one catalog, each entry with its kind.\n */\nexport interface PackageCatalog {\n list: (args?: { kind?: PackageKind }) => Promise<RegistryEntry[]>\n get: (args: { location: string }) => Promise<RegistryEntry | undefined>\n /** Adds the entry, or replaces the one at its location. */\n add: (args: { entry: RegistryEntry }) => Promise<void>\n /** Does nothing when the location is not registered. */\n remove: (args: { location: string }) => Promise<void>\n}\n\nconst entriesOf = (index: RegistryIndex): RegistryEntry[] =>\n Object.entries(index.packages)\n .map(([location, entry]) => ({ location, ...entry }))\n .sort((a, b) => (a.location < b.location ? -1 : a.location > b.location ? 1 : 0))\n\nconst catalogOver = ({ load, save }: { load: () => Promise<RegistryIndex>, save: (index: RegistryIndex, message: string) => Promise<void> }): PackageCatalog => ({\n list: async ({ kind } = {}) => entriesOf(await load()).filter((entry) => kind === undefined || entry.kind === kind),\n get: async ({ location }) => entriesOf(await load()).find((entry) => entry.location === location),\n add: async ({ entry: { location, ...rest } }) => {\n const index = await load()\n await save({ registryVersion: 1, packages: { ...index.packages, [location]: rest } }, `Register ${location}`)\n },\n remove: async ({ location }) => {\n const index = await load()\n if (index.packages[location] === undefined) return\n const packages = Object.fromEntries(Object.entries(index.packages).filter(([key]) => key !== location))\n await save({ registryVersion: 1, packages }, `Unregister ${location}`)\n }\n})\n\n/** A catalog held in memory: for tests, and for a server that keeps the catalog somewhere else and loads it whole. */\nexport const createMemoryCatalog = ({ index }: { index?: RegistryIndex } = {}): PackageCatalog => {\n let current = index ?? emptyRegistryIndex()\n return catalogOver({\n load: () => Promise.resolve(current),\n save: (next) => {\n current = next\n return Promise.resolve()\n }\n })\n}\n\n/**\n * A catalog kept in ONE text file (`registry.json`). `read` gives its content, or `undefined` when there is none yet (an empty\n * catalog); `write` stores the new content. Where the file lives (a folder, a git repository) is up to the caller.\n */\nexport const createFileCatalog = ({ read, write }: {\n read: () => Promise<string | undefined>\n write: (args: { content: string, message: string }) => Promise<void>\n}): PackageCatalog => {\n return catalogOver({\n load: async () => {\n const content = await read()\n return content === undefined ? emptyRegistryIndex() : parseRegistryIndex({ content })\n },\n save: async (index, message) => {\n const before = await read()\n const after = serializeRegistryIndex({ index })\n if (before !== after) await write({ content: after, message })\n }\n })\n}\n\n/**\n * Registers a package after reading it: its latest version must have a valid manifest of the registry's kind, which gives the\n * entry its name and description. A location already registered as the other kind is refused (`resolveSpl` refuses it too).\n */\nexport const registerPackage = async ({ catalog, registry, location, addedBy, now = () => new Date() }: {\n catalog: PackageCatalog\n registry: PackageRegistry<{ name: string, version: string, description?: string }>\n location: string\n addedBy?: string\n now?: () => Date\n}): Promise<RegistryEntry> => {\n const existing = await catalog.get({ location })\n if (existing !== undefined && existing.kind !== registry.kind) {\n throw new ModuleResolutionError(`${location} is already registered as a ${existing.kind}, not a ${registry.kind}.`)\n }\n const latest = semver.rsort(await registry.versions({ location }))[0]\n if (latest === undefined) {\n throw new ModuleResolutionError(`${location} has no published version (a tag such as v1.0.0), so it cannot be registered.`)\n }\n const { manifest } = await registry.load({ location, version: latest })\n const entry: RegistryEntry = {\n kind: registry.kind,\n location,\n name: manifest.name,\n ...(manifest.description === undefined ? {} : { description: manifest.description }),\n addedAt: existing?.addedAt ?? now().toISOString(),\n ...(addedBy === undefined ? {} : { addedBy: existing?.addedBy ?? addedBy })\n }\n await catalog.add({ entry })\n return entry\n}\n\n/**\n * Registers a location without being told what it is: a package says so with its manifest (`module.json` or `metamodel.json`) at its\n * latest version. One without a published version is refused like in `registerPackage`.\n */\nexport const registerLocation = async ({ catalog, source, location, addedBy, now }: {\n catalog: PackageCatalog\n source: PackageSource\n location: string\n addedBy?: string\n now?: () => Date\n}): Promise<RegistryEntry> => {\n const latest = semver.rsort(await source.listVersions({ location }))[0]\n let isModule = true // with no version to read, the module registry gives the error (\"no published version\")\n if (latest !== undefined) {\n const files = await source.open({ location, version: latest })\n isModule = (await files.read({ path: MODULE_MANIFEST_PATH })) !== undefined || (await files.read({ path: 'metamodel.json' })) === undefined\n }\n const registry = isModule ? createModuleRegistry({ source }) : createMetamodelRegistry({ source })\n return registerPackage({ catalog, registry, location, ...(addedBy === undefined ? {} : { addedBy }), ...(now === undefined ? {} : { now }) })\n}\n"]}
|