@mostra/protocol 0.13.0 → 0.15.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/dist/artifact-path.d.ts +22 -0
- package/dist/artifact-path.d.ts.map +1 -0
- package/dist/artifact-path.js +39 -0
- package/dist/artifact-path.js.map +1 -0
- package/dist/diagnostics/codes/index.d.ts +5 -2
- package/dist/diagnostics/codes/index.d.ts.map +1 -1
- package/dist/diagnostics/codes/index.js +7 -1
- package/dist/diagnostics/codes/index.js.map +1 -1
- package/dist/diagnostics/codes/license.d.ts +8 -0
- package/dist/diagnostics/codes/license.d.ts.map +1 -0
- package/dist/diagnostics/codes/license.js +55 -0
- package/dist/diagnostics/codes/license.js.map +1 -0
- package/dist/diagnostics/codes/pack.d.ts +8 -0
- package/dist/diagnostics/codes/pack.d.ts.map +1 -0
- package/dist/diagnostics/codes/pack.js +110 -0
- package/dist/diagnostics/codes/pack.js.map +1 -0
- package/dist/diagnostics/codes/plugin.d.ts +8 -0
- package/dist/diagnostics/codes/plugin.d.ts.map +1 -0
- package/dist/diagnostics/codes/plugin.js +154 -0
- package/dist/diagnostics/codes/plugin.js.map +1 -0
- package/dist/diagnostics/diagnostic.d.ts +1 -1
- package/dist/diagnostics/diagnostic.d.ts.map +1 -1
- package/dist/diagnostics/diagnostic.js +4 -1
- package/dist/diagnostics/diagnostic.js.map +1 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +13 -1
- package/dist/methods/deps/add.d.ts +6 -0
- package/dist/methods/deps/add.d.ts.map +1 -1
- package/dist/methods/deps/add.js +1 -0
- package/dist/methods/deps/add.js.map +1 -1
- package/dist/methods/index.d.ts.map +1 -1
- package/dist/methods/index.js +15 -1
- package/dist/methods/index.js.map +1 -1
- package/dist/methods/mostra/initialize.d.ts +7 -0
- package/dist/methods/mostra/initialize.d.ts.map +1 -1
- package/dist/methods/mostra/initialize.js +4 -2
- package/dist/methods/mostra/initialize.js.map +1 -1
- package/dist/methods/pack/add.d.ts +80 -0
- package/dist/methods/pack/add.d.ts.map +1 -0
- package/dist/methods/pack/add.js +59 -0
- package/dist/methods/pack/add.js.map +1 -0
- package/dist/methods/plugin/add.d.ts +43 -0
- package/dist/methods/plugin/add.d.ts.map +1 -0
- package/dist/methods/plugin/add.js +39 -0
- package/dist/methods/plugin/add.js.map +1 -0
- package/dist/methods/plugin/commands.d.ts +38 -0
- package/dist/methods/plugin/commands.d.ts.map +1 -0
- package/dist/methods/plugin/commands.js +33 -0
- package/dist/methods/plugin/commands.js.map +1 -0
- package/dist/methods/plugin/export.d.ts +58 -0
- package/dist/methods/plugin/export.d.ts.map +1 -0
- package/dist/methods/plugin/export.js +57 -0
- package/dist/methods/plugin/export.js.map +1 -0
- package/dist/methods/plugin/list.d.ts +26 -0
- package/dist/methods/plugin/list.d.ts.map +1 -0
- package/dist/methods/plugin/list.js +30 -0
- package/dist/methods/plugin/list.js.map +1 -0
- package/dist/methods/plugin/remove.d.ts +32 -0
- package/dist/methods/plugin/remove.d.ts.map +1 -0
- package/dist/methods/plugin/remove.js +33 -0
- package/dist/methods/plugin/remove.js.map +1 -0
- package/dist/methods/plugin/validate.d.ts +35 -0
- package/dist/methods/plugin/validate.d.ts.map +1 -0
- package/dist/methods/plugin/validate.js +33 -0
- package/dist/methods/plugin/validate.js.map +1 -0
- package/dist/plugin/contract-versions.generated.js +14 -0
- package/dist/plugin/contract-versions.generated.js.map +1 -0
- package/dist/plugin/contracts.d.ts +51 -0
- package/dist/plugin/contracts.d.ts.map +1 -0
- package/dist/plugin/contracts.js +129 -0
- package/dist/plugin/contracts.js.map +1 -0
- package/dist/plugin/license.d.ts +87 -0
- package/dist/plugin/license.d.ts.map +1 -0
- package/dist/plugin/license.js +243 -0
- package/dist/plugin/license.js.map +1 -0
- package/dist/plugin/manifest.d.ts +141 -0
- package/dist/plugin/manifest.d.ts.map +1 -0
- package/dist/plugin/manifest.js +281 -0
- package/dist/plugin/manifest.js.map +1 -0
- package/dist/plugin/registry-item.d.ts +171 -0
- package/dist/plugin/registry-item.d.ts.map +1 -0
- package/dist/plugin/registry-item.js +162 -0
- package/dist/plugin/registry-item.js.map +1 -0
- package/dist/plugin/spdx.generated.d.ts +9 -0
- package/dist/plugin/spdx.generated.d.ts.map +1 -0
- package/dist/plugin/spdx.generated.js +846 -0
- package/dist/plugin/spdx.generated.js.map +1 -0
- package/dist/plugin.d.ts +7 -0
- package/dist/plugin.js +6 -0
- package/dist/plugins.d.ts +118 -0
- package/dist/plugins.d.ts.map +1 -0
- package/dist/plugins.js +109 -0
- package/dist/plugins.js.map +1 -0
- package/package.json +19 -4
- package/schemas/plugin-manifest.draft-07.json +611 -0
- package/schemas/plugin-manifest.schema.json +607 -0
- package/schemas/protocol.draft-07.json +899 -1
- package/schemas/protocol.schema.json +875 -1
- package/src/artifact-path.ts +46 -0
- package/src/diagnostics/codes/index.ts +14 -2
- package/src/diagnostics/codes/license.ts +65 -0
- package/src/diagnostics/codes/pack.ts +125 -0
- package/src/diagnostics/codes/plugin.ts +173 -0
- package/src/diagnostics/diagnostic.ts +7 -1
- package/src/index.ts +57 -0
- package/src/methods/deps/add.ts +7 -0
- package/src/methods/index.ts +14 -0
- package/src/methods/mostra/initialize.ts +9 -1
- package/src/methods/pack/add.ts +133 -0
- package/src/methods/plugin/add.ts +70 -0
- package/src/methods/plugin/commands.ts +67 -0
- package/src/methods/plugin/export.ts +100 -0
- package/src/methods/plugin/list.ts +45 -0
- package/src/methods/plugin/remove.ts +58 -0
- package/src/methods/plugin/validate.ts +60 -0
- package/src/plugin/contract-versions.generated.ts +15 -0
- package/src/plugin/contracts.ts +171 -0
- package/src/plugin/license.ts +320 -0
- package/src/plugin/manifest.ts +546 -0
- package/src/plugin/registry-item.ts +330 -0
- package/src/plugin/spdx-tables.ts +74 -0
- package/src/plugin/spdx.generated.ts +844 -0
- package/src/plugin.ts +77 -0
- package/src/plugins.ts +239 -0
- package/LICENSE +0 -202
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Diagnostic } from "../../diagnostics/diagnostic.js";
|
|
2
|
+
import { MethodDefinition } from "../../method.js";
|
|
3
|
+
import { PluginSummary } from "../../plugins.js";
|
|
4
|
+
//#region src/methods/plugin/validate.d.ts
|
|
5
|
+
/** The params of `plugin/validate` (INTERFACES §14). */
|
|
6
|
+
export interface PluginValidateParams {
|
|
7
|
+
/** The plugin's package directory, which holds its `package.json` (absolute). */
|
|
8
|
+
readonly path: string;
|
|
9
|
+
/**
|
|
10
|
+
* Licenses acknowledged for what the package brings (D31): its entries are loaded only once
|
|
11
|
+
* every license that needs an acknowledgment has one, as an install would load them.
|
|
12
|
+
*/
|
|
13
|
+
readonly acceptLicenses?: readonly string[];
|
|
14
|
+
}
|
|
15
|
+
/** The result of `plugin/validate`. */
|
|
16
|
+
export interface PluginValidateResult {
|
|
17
|
+
/** Whether the plugin loads in this release: no diagnostic is an error. */
|
|
18
|
+
readonly valid: boolean;
|
|
19
|
+
/** The plugin as Mostra reads it, when its manifest has no error. */
|
|
20
|
+
readonly plugin?: PluginSummary;
|
|
21
|
+
/**
|
|
22
|
+
* Every problem, each with its location in `package.json` or the module it concerns: the
|
|
23
|
+
* manifest's fields, contract ranges, entries and their stamps, licenses.
|
|
24
|
+
*/
|
|
25
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* `plugin/validate`: checks a plugin package as Mostra would load it (EX-02), reporting every
|
|
29
|
+
* invalid field of its `"mostra"` manifest, every contract range this release doesn't implement,
|
|
30
|
+
* and every entry that doesn't export a definition stamped with its contract, without installing
|
|
31
|
+
* anything. The method behind `mostra plugin validate`.
|
|
32
|
+
*/
|
|
33
|
+
export declare const pluginValidateMethod: MethodDefinition<PluginValidateParams, PluginValidateResult>;
|
|
34
|
+
//#endregion
|
|
35
|
+
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.ts","names":[],"sources":["../../../src/methods/plugin/validate.ts"],"mappings":";;;;;iBAQiB;;WAEN;;;;;WAKA;;;iBAIM;;WAEN;;WAEA,SAAS;;;;;WAKT,sBAAsB;;;;;;;;qBAwBpB,sBAAsB,iBAAiB,sBAAsB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { wireRegistry } from "../../wire-registry.js";
|
|
2
|
+
import { AbsolutePath } from "../../artifact.js";
|
|
3
|
+
import { Diagnostic } from "../../diagnostics/diagnostic.js";
|
|
4
|
+
import { defineMethod } from "../../method.js";
|
|
5
|
+
import { PluginSummary } from "../../plugins.js";
|
|
6
|
+
import * as z from "zod";
|
|
7
|
+
//#region src/methods/plugin/validate.ts
|
|
8
|
+
const params = z.object({
|
|
9
|
+
path: AbsolutePath,
|
|
10
|
+
acceptLicenses: z.array(z.string().min(1).max(256)).readonly().exactOptional()
|
|
11
|
+
}).register(wireRegistry, { id: "PluginValidateParams" });
|
|
12
|
+
const result = z.object({
|
|
13
|
+
valid: z.boolean(),
|
|
14
|
+
plugin: PluginSummary.exactOptional(),
|
|
15
|
+
diagnostics: z.array(Diagnostic).readonly()
|
|
16
|
+
}).register(wireRegistry, { id: "PluginValidateResult" });
|
|
17
|
+
/**
|
|
18
|
+
* `plugin/validate`: checks a plugin package as Mostra would load it (EX-02), reporting every
|
|
19
|
+
* invalid field of its `"mostra"` manifest, every contract range this release doesn't implement,
|
|
20
|
+
* and every entry that doesn't export a definition stamped with its contract, without installing
|
|
21
|
+
* anything. The method behind `mostra plugin validate`.
|
|
22
|
+
*/
|
|
23
|
+
const pluginValidateMethod = defineMethod({
|
|
24
|
+
method: "plugin/validate",
|
|
25
|
+
direction: "client-to-instance",
|
|
26
|
+
mutating: false,
|
|
27
|
+
params,
|
|
28
|
+
result
|
|
29
|
+
});
|
|
30
|
+
//#endregion
|
|
31
|
+
export { pluginValidateMethod };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","names":[],"sources":["../../../src/methods/plugin/validate.ts"],"sourcesContent":["import * as z from \"zod\";\nimport { AbsolutePath } from \"../../artifact.ts\";\nimport { Diagnostic } from \"../../diagnostics/diagnostic.ts\";\nimport { defineMethod, type MethodDefinition } from \"../../method.ts\";\nimport { PluginSummary } from \"../../plugins.ts\";\nimport { wireRegistry } from \"../../wire-registry.ts\";\n\n/** The params of `plugin/validate` (INTERFACES §14). */\nexport interface PluginValidateParams {\n /** The plugin's package directory, which holds its `package.json` (absolute). */\n readonly path: string;\n /**\n * Licenses acknowledged for what the package brings (D31): its entries are loaded only once\n * every license that needs an acknowledgment has one, as an install would load them.\n */\n readonly acceptLicenses?: readonly string[];\n}\n\n/** The result of `plugin/validate`. */\nexport interface PluginValidateResult {\n /** Whether the plugin loads in this release: no diagnostic is an error. */\n readonly valid: boolean;\n /** The plugin as Mostra reads it, when its manifest has no error. */\n readonly plugin?: PluginSummary;\n /**\n * Every problem, each with its location in `package.json` or the module it concerns: the\n * manifest's fields, contract ranges, entries and their stamps, licenses.\n */\n readonly diagnostics: readonly Diagnostic[];\n}\n\nconst params: z.ZodType<PluginValidateParams> = z\n .object({\n path: AbsolutePath,\n acceptLicenses: z.array(z.string().min(1).max(256)).readonly().exactOptional(),\n })\n .register(wireRegistry, { id: \"PluginValidateParams\" });\n\nconst result: z.ZodType<PluginValidateResult> = z\n .object({\n valid: z.boolean(),\n plugin: PluginSummary.exactOptional(),\n diagnostics: z.array(Diagnostic).readonly(),\n })\n .register(wireRegistry, { id: \"PluginValidateResult\" });\n\n/**\n * `plugin/validate`: checks a plugin package as Mostra would load it (EX-02), reporting every\n * invalid field of its `\"mostra\"` manifest, every contract range this release doesn't implement,\n * and every entry that doesn't export a definition stamped with its contract, without installing\n * anything. The method behind `mostra plugin validate`.\n */\nexport const pluginValidateMethod: MethodDefinition<PluginValidateParams, PluginValidateResult> =\n defineMethod({\n method: \"plugin/validate\",\n direction: \"client-to-instance\",\n mutating: false,\n params,\n result,\n });\n"],"mappings":";;;;;;;AA+BA,MAAM,SAA0C,EAC7C,OAAO;CACN,MAAM;CACN,gBAAgB,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,cAAc;AAC/E,CAAC,CAAC,CACD,SAAS,cAAc,EAAE,IAAI,uBAAuB,CAAC;AAExD,MAAM,SAA0C,EAC7C,OAAO;CACN,OAAO,EAAE,QAAQ;CACjB,QAAQ,cAAc,cAAc;CACpC,aAAa,EAAE,MAAM,UAAU,CAAC,CAAC,SAAS;AAC5C,CAAC,CAAC,CACD,SAAS,cAAc,EAAE,IAAI,uBAAuB,CAAC;;;;;;;AAQxD,MAAa,uBACX,aAAa;CACX,QAAQ;CACR,WAAW;CACX,UAAU;CACV;CACA;AACF,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/plugin/contract-versions.generated.ts
|
|
2
|
+
/** The version of each contract package this release implements. */
|
|
3
|
+
const CONTRACT_VERSIONS = {
|
|
4
|
+
"anchor-provider": "0.1.0",
|
|
5
|
+
"cli-command": "0.1.0",
|
|
6
|
+
connector: "0.1.0",
|
|
7
|
+
"embed-engine": "0.1.0",
|
|
8
|
+
exporter: "0.1.0",
|
|
9
|
+
"verify-check": "0.1.0"
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
12
|
+
export { CONTRACT_VERSIONS };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=contract-versions.generated.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-versions.generated.js","names":[],"sources":["../../src/plugin/contract-versions.generated.ts"],"sourcesContent":["/**\n * Written by `node tools/release/versions.ts sync` from each `@mostra/contract-*` package's\n * version. Don't edit: the release's version step keeps it equal to the packages.\n */\nimport type { ContractName } from \"../plugins.ts\";\n\n/** The version of each contract package this release implements. */\nexport const CONTRACT_VERSIONS: Readonly<Record<ContractName, string>> = {\n \"anchor-provider\": \"0.1.0\",\n \"cli-command\": \"0.1.0\",\n connector: \"0.1.0\",\n \"embed-engine\": \"0.1.0\",\n exporter: \"0.1.0\",\n \"verify-check\": \"0.1.0\",\n};\n"],"mappings":";;AAOA,MAAa,oBAA4D;CACvE,mBAAmB;CACnB,eAAe;CACf,WAAW;CACX,gBAAgB;CAChB,UAAU;CACV,gBAAgB;AAClB"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ContractName, PluginScope } from "../plugins.js";
|
|
2
|
+
//#region src/plugin/contracts.d.ts
|
|
3
|
+
/** One contract as this release implements it. */
|
|
4
|
+
export interface ContractInfo {
|
|
5
|
+
/** Its name. */
|
|
6
|
+
readonly name: ContractName;
|
|
7
|
+
/** Its package: `@mostra/contract-<name>`. */
|
|
8
|
+
readonly package: string;
|
|
9
|
+
/**
|
|
10
|
+
* The versions of it this release serves, newest last. A plugin's range must admit one, and
|
|
11
|
+
* every stamp must be of a served line, at most that version (`stampCompatible`).
|
|
12
|
+
*/
|
|
13
|
+
readonly implements: readonly string[];
|
|
14
|
+
/** Where its contributions run: the artifact's page, or Node.js (a child of the instance). */
|
|
15
|
+
readonly runs: "browser" | "node";
|
|
16
|
+
/** The key of the manifest's `contributes` that lists its contributions. */
|
|
17
|
+
readonly key: ContributesKey;
|
|
18
|
+
/** Where a plugin contributing it may be installed (ROUND-3 §6.4). */
|
|
19
|
+
readonly scopes: readonly PluginScope[];
|
|
20
|
+
}
|
|
21
|
+
/** The keys of a manifest's `contributes`, each a list of one kind of contribution. */
|
|
22
|
+
export type ContributesKey = "embedEngines" | "exporters" | "verifyChecks" | "anchorProviders" | "connectors" | "cliCommands";
|
|
23
|
+
/**
|
|
24
|
+
* Every contract, by name. Exporters and CLI commands may also be installed for the whole home
|
|
25
|
+
* (ROUND-3 §6.4); the others change what an artifact's version is, so they belong to one artifact
|
|
26
|
+
* and its lockfile.
|
|
27
|
+
*/
|
|
28
|
+
export declare const PLUGIN_CONTRACTS: Readonly<Record<ContractName, ContractInfo>>;
|
|
29
|
+
/** The contracts in their manifest order. */
|
|
30
|
+
export declare const CONTRACT_NAMES: readonly ContractName[];
|
|
31
|
+
/** The exporters Mostra builds in (VR-07): a plugin's exporter can't take their IDs. */
|
|
32
|
+
export declare const BUILT_IN_EXPORTERS: readonly string[];
|
|
33
|
+
/**
|
|
34
|
+
* Every command `mostra` has of its own (D60, INTERFACES §9), as its words: a plugin's command
|
|
35
|
+
* may be none of them, nor a prefix of one, nor have one as its prefix. The CLI's tests keep this
|
|
36
|
+
* list equal to its command table, plus the commands later packages add (`review export`, WP-20;
|
|
37
|
+
* `term dump`, WP-22), which are reserved from today.
|
|
38
|
+
*/
|
|
39
|
+
export declare const CORE_COMMANDS: readonly (readonly string[])[];
|
|
40
|
+
/** Whether a command path is taken by `mostra` itself (equal, or a prefix either way). */
|
|
41
|
+
export declare function coreCommandTaken(path: readonly string[]): readonly string[] | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Whether this release serves a definition stamped `stamp` for `contract`: the stamp names the
|
|
44
|
+
* contract on a line this release implements (the major, and at 0.x the minor), as each contract
|
|
45
|
+
* package's `stampCompatible` judges it. The version within the line is the manifest's range's to
|
|
46
|
+
* decide, which the loader checks first (D172 item 2): a plugin whose caret range resolved a newer
|
|
47
|
+
* patch of the contract package than this release's loads where its range admits this release's.
|
|
48
|
+
*/
|
|
49
|
+
export declare function stampServed(stamp: unknown, contract: ContractName, implemented?: readonly string[]): boolean;
|
|
50
|
+
//#endregion
|
|
51
|
+
//# sourceMappingURL=contracts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contracts.d.ts","names":[],"sources":["../../src/plugin/contracts.ts"],"mappings":";;;iBASiB;;WAEN,MAAM;;WAEN;;;;;WAKA;;WAEA;;WAEA,KAAK;;WAEL,iBAAiB;;;YAIhB;;;;;;qBA2BC,kBAAkB,SAAS,OAAO,cAAc;;qBAUhD,yBAAyB;;qBAKzB;;;;;;;qBAQA;;wBAqDG,iBAAiB;;;;;;;;wBAuBjB,YACd,gBACA,UAAU,cAEV"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { CONTRACT_VERSIONS } from "./contract-versions.generated.js";
|
|
2
|
+
//#region src/plugin/contracts.ts
|
|
3
|
+
const info = (name, key, runs, scopes) => ({
|
|
4
|
+
name,
|
|
5
|
+
package: `@mostra/contract-${name}`,
|
|
6
|
+
implements: [CONTRACT_VERSIONS[name]],
|
|
7
|
+
runs,
|
|
8
|
+
key,
|
|
9
|
+
scopes
|
|
10
|
+
});
|
|
11
|
+
/**
|
|
12
|
+
* Every contract, by name. Exporters and CLI commands may also be installed for the whole home
|
|
13
|
+
* (ROUND-3 §6.4); the others change what an artifact's version is, so they belong to one artifact
|
|
14
|
+
* and its lockfile.
|
|
15
|
+
*/
|
|
16
|
+
const PLUGIN_CONTRACTS = {
|
|
17
|
+
"embed-engine": info("embed-engine", "embedEngines", "browser", ["artifact"]),
|
|
18
|
+
exporter: info("exporter", "exporters", "node", ["artifact", "home"]),
|
|
19
|
+
"verify-check": info("verify-check", "verifyChecks", "node", ["artifact"]),
|
|
20
|
+
"anchor-provider": info("anchor-provider", "anchorProviders", "browser", ["artifact"]),
|
|
21
|
+
connector: info("connector", "connectors", "node", ["artifact"]),
|
|
22
|
+
"cli-command": info("cli-command", "cliCommands", "node", ["artifact", "home"])
|
|
23
|
+
};
|
|
24
|
+
/** The contracts in their manifest order. */
|
|
25
|
+
const CONTRACT_NAMES = Object.keys(PLUGIN_CONTRACTS);
|
|
26
|
+
/** The exporters Mostra builds in (VR-07): a plugin's exporter can't take their IDs. */
|
|
27
|
+
const BUILT_IN_EXPORTERS = [
|
|
28
|
+
"static",
|
|
29
|
+
"html",
|
|
30
|
+
"bundle",
|
|
31
|
+
"snapshot"
|
|
32
|
+
];
|
|
33
|
+
/**
|
|
34
|
+
* Every command `mostra` has of its own (D60, INTERFACES §9), as its words: a plugin's command
|
|
35
|
+
* may be none of them, nor a prefix of one, nor have one as its prefix. The CLI's tests keep this
|
|
36
|
+
* list equal to its command table, plus the commands later packages add (`review export`, WP-20;
|
|
37
|
+
* `term dump`, WP-22), which are reserved from today.
|
|
38
|
+
*/
|
|
39
|
+
const CORE_COMMANDS = [
|
|
40
|
+
["add"],
|
|
41
|
+
["daemon", "install"],
|
|
42
|
+
["daemon", "restart"],
|
|
43
|
+
["daemon", "start"],
|
|
44
|
+
["daemon", "status"],
|
|
45
|
+
["daemon", "stop"],
|
|
46
|
+
["daemon", "uninstall"],
|
|
47
|
+
["dev"],
|
|
48
|
+
["docs"],
|
|
49
|
+
["doctor"],
|
|
50
|
+
["export"],
|
|
51
|
+
["gc"],
|
|
52
|
+
["host"],
|
|
53
|
+
["list"],
|
|
54
|
+
["login"],
|
|
55
|
+
["logout"],
|
|
56
|
+
["mcp"],
|
|
57
|
+
["new"],
|
|
58
|
+
["open"],
|
|
59
|
+
["pause"],
|
|
60
|
+
["plugin", "add"],
|
|
61
|
+
["plugin", "list"],
|
|
62
|
+
["plugin", "remove"],
|
|
63
|
+
["plugin", "validate"],
|
|
64
|
+
["publish"],
|
|
65
|
+
["push"],
|
|
66
|
+
["results"],
|
|
67
|
+
["review", "export"],
|
|
68
|
+
["resume"],
|
|
69
|
+
["roster", "add"],
|
|
70
|
+
["roster", "get"],
|
|
71
|
+
["roster", "remove"],
|
|
72
|
+
["run"],
|
|
73
|
+
["secret", "list"],
|
|
74
|
+
["secret", "rm"],
|
|
75
|
+
["secret", "set"],
|
|
76
|
+
["share"],
|
|
77
|
+
["share", "list"],
|
|
78
|
+
["share", "stop"],
|
|
79
|
+
["state", "get"],
|
|
80
|
+
["state", "patch"],
|
|
81
|
+
["state", "set"],
|
|
82
|
+
["status"],
|
|
83
|
+
["telemetry", "off"],
|
|
84
|
+
["telemetry", "on"],
|
|
85
|
+
["telemetry", "status"],
|
|
86
|
+
["term", "dump"],
|
|
87
|
+
["verify"],
|
|
88
|
+
["wait"]
|
|
89
|
+
];
|
|
90
|
+
/** Whether a command path is taken by `mostra` itself (equal, or a prefix either way). */
|
|
91
|
+
function coreCommandTaken(path) {
|
|
92
|
+
return CORE_COMMANDS.find((core) => {
|
|
93
|
+
const shorter = Math.min(core.length, path.length);
|
|
94
|
+
for (let index = 0; index < shorter; index += 1) if (core[index] !== path[index]) return false;
|
|
95
|
+
return true;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/** `major.minor.patch` of a release version, or `undefined`. */
|
|
99
|
+
function versionParts(version) {
|
|
100
|
+
const match = /^(\d+)\.(\d+)\.(\d+)(?:[-+].*)?$/.exec(version);
|
|
101
|
+
return match ? [
|
|
102
|
+
Number(match[1]),
|
|
103
|
+
Number(match[2]),
|
|
104
|
+
Number(match[3])
|
|
105
|
+
] : void 0;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Whether this release serves a definition stamped `stamp` for `contract`: the stamp names the
|
|
109
|
+
* contract on a line this release implements (the major, and at 0.x the minor), as each contract
|
|
110
|
+
* package's `stampCompatible` judges it. The version within the line is the manifest's range's to
|
|
111
|
+
* decide, which the loader checks first (D172 item 2): a plugin whose caret range resolved a newer
|
|
112
|
+
* patch of the contract package than this release's loads where its range admits this release's.
|
|
113
|
+
*/
|
|
114
|
+
function stampServed(stamp, contract, implemented = PLUGIN_CONTRACTS[contract].implements) {
|
|
115
|
+
if (typeof stamp !== "object" || stamp === null) return false;
|
|
116
|
+
const { name, version } = stamp;
|
|
117
|
+
if (name !== contract || typeof version !== "string") return false;
|
|
118
|
+
const theirs = versionParts(version);
|
|
119
|
+
if (theirs === void 0) return false;
|
|
120
|
+
return implemented.some((served) => {
|
|
121
|
+
const ours = versionParts(served);
|
|
122
|
+
if (ours === void 0 || theirs[0] !== ours[0]) return false;
|
|
123
|
+
return ours[0] !== 0 || theirs[1] === ours[1];
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
//#endregion
|
|
127
|
+
export { BUILT_IN_EXPORTERS, CONTRACT_NAMES, CORE_COMMANDS, PLUGIN_CONTRACTS, coreCommandTaken, stampServed };
|
|
128
|
+
|
|
129
|
+
//# sourceMappingURL=contracts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contracts.js","names":[],"sources":["../../src/plugin/contracts.ts"],"sourcesContent":["/**\n * The extension contracts Mostra implements (D30, ARCHITECTURE §13, ROUND-3 §6.1): each\n * contract's package, the versions of it this release serves, where its contributions run, the\n * manifest key that lists them and where a plugin with them may be installed.\n */\nimport type { ContractName, PluginScope } from \"../plugins.ts\";\nimport { CONTRACT_VERSIONS } from \"./contract-versions.generated.ts\";\n\n/** One contract as this release implements it. */\nexport interface ContractInfo {\n /** Its name. */\n readonly name: ContractName;\n /** Its package: `@mostra/contract-<name>`. */\n readonly package: string;\n /**\n * The versions of it this release serves, newest last. A plugin's range must admit one, and\n * every stamp must be of a served line, at most that version (`stampCompatible`).\n */\n readonly implements: readonly string[];\n /** Where its contributions run: the artifact's page, or Node.js (a child of the instance). */\n readonly runs: \"browser\" | \"node\";\n /** The key of the manifest's `contributes` that lists its contributions. */\n readonly key: ContributesKey;\n /** Where a plugin contributing it may be installed (ROUND-3 §6.4). */\n readonly scopes: readonly PluginScope[];\n}\n\n/** The keys of a manifest's `contributes`, each a list of one kind of contribution. */\nexport type ContributesKey =\n | \"embedEngines\"\n | \"exporters\"\n | \"verifyChecks\"\n | \"anchorProviders\"\n | \"connectors\"\n | \"cliCommands\";\n\nconst info = (\n name: ContractName,\n key: ContributesKey,\n runs: \"browser\" | \"node\",\n scopes: readonly PluginScope[],\n): ContractInfo => ({\n name,\n package: `@mostra/contract-${name}`,\n implements: [CONTRACT_VERSIONS[name]],\n runs,\n key,\n scopes,\n});\n\n/**\n * Every contract, by name. Exporters and CLI commands may also be installed for the whole home\n * (ROUND-3 §6.4); the others change what an artifact's version is, so they belong to one artifact\n * and its lockfile.\n */\nexport const PLUGIN_CONTRACTS: Readonly<Record<ContractName, ContractInfo>> = {\n \"embed-engine\": info(\"embed-engine\", \"embedEngines\", \"browser\", [\"artifact\"]),\n exporter: info(\"exporter\", \"exporters\", \"node\", [\"artifact\", \"home\"]),\n \"verify-check\": info(\"verify-check\", \"verifyChecks\", \"node\", [\"artifact\"]),\n \"anchor-provider\": info(\"anchor-provider\", \"anchorProviders\", \"browser\", [\"artifact\"]),\n connector: info(\"connector\", \"connectors\", \"node\", [\"artifact\"]),\n \"cli-command\": info(\"cli-command\", \"cliCommands\", \"node\", [\"artifact\", \"home\"]),\n};\n\n/** The contracts in their manifest order. */\nexport const CONTRACT_NAMES: readonly ContractName[] = Object.keys(\n PLUGIN_CONTRACTS,\n) as ContractName[];\n\n/** The exporters Mostra builds in (VR-07): a plugin's exporter can't take their IDs. */\nexport const BUILT_IN_EXPORTERS: readonly string[] = [\"static\", \"html\", \"bundle\", \"snapshot\"];\n\n/**\n * Every command `mostra` has of its own (D60, INTERFACES §9), as its words: a plugin's command\n * may be none of them, nor a prefix of one, nor have one as its prefix. The CLI's tests keep this\n * list equal to its command table, plus the commands later packages add (`review export`, WP-20;\n * `term dump`, WP-22), which are reserved from today.\n */\nexport const CORE_COMMANDS: readonly (readonly string[])[] = [\n [\"add\"],\n [\"daemon\", \"install\"],\n [\"daemon\", \"restart\"],\n [\"daemon\", \"start\"],\n [\"daemon\", \"status\"],\n [\"daemon\", \"stop\"],\n [\"daemon\", \"uninstall\"],\n [\"dev\"],\n [\"docs\"],\n [\"doctor\"],\n [\"export\"],\n [\"gc\"],\n [\"host\"],\n [\"list\"],\n [\"login\"],\n [\"logout\"],\n [\"mcp\"],\n [\"new\"],\n [\"open\"],\n [\"pause\"],\n [\"plugin\", \"add\"],\n [\"plugin\", \"list\"],\n [\"plugin\", \"remove\"],\n [\"plugin\", \"validate\"],\n [\"publish\"],\n [\"push\"],\n [\"results\"],\n [\"review\", \"export\"],\n [\"resume\"],\n [\"roster\", \"add\"],\n [\"roster\", \"get\"],\n [\"roster\", \"remove\"],\n [\"run\"],\n [\"secret\", \"list\"],\n [\"secret\", \"rm\"],\n [\"secret\", \"set\"],\n [\"share\"],\n [\"share\", \"list\"],\n [\"share\", \"stop\"],\n [\"state\", \"get\"],\n [\"state\", \"patch\"],\n [\"state\", \"set\"],\n [\"status\"],\n [\"telemetry\", \"off\"],\n [\"telemetry\", \"on\"],\n [\"telemetry\", \"status\"],\n [\"term\", \"dump\"],\n [\"verify\"],\n [\"wait\"],\n];\n\n/** Whether a command path is taken by `mostra` itself (equal, or a prefix either way). */\nexport function coreCommandTaken(path: readonly string[]): readonly string[] | undefined {\n return CORE_COMMANDS.find((core) => {\n const shorter = Math.min(core.length, path.length);\n for (let index = 0; index < shorter; index += 1) {\n if (core[index] !== path[index]) return false;\n }\n return true;\n });\n}\n\n/** `major.minor.patch` of a release version, or `undefined`. */\nfunction versionParts(version: string): [number, number, number] | undefined {\n const match = /^(\\d+)\\.(\\d+)\\.(\\d+)(?:[-+].*)?$/.exec(version);\n return match ? [Number(match[1]), Number(match[2]), Number(match[3])] : undefined;\n}\n\n/**\n * Whether this release serves a definition stamped `stamp` for `contract`: the stamp names the\n * contract on a line this release implements (the major, and at 0.x the minor), as each contract\n * package's `stampCompatible` judges it. The version within the line is the manifest's range's to\n * decide, which the loader checks first (D172 item 2): a plugin whose caret range resolved a newer\n * patch of the contract package than this release's loads where its range admits this release's.\n */\nexport function stampServed(\n stamp: unknown,\n contract: ContractName,\n /** The versions served; this release's by default (a test stands in an older runtime's). */\n implemented: readonly string[] = PLUGIN_CONTRACTS[contract].implements,\n): boolean {\n if (typeof stamp !== \"object\" || stamp === null) return false;\n const { name, version } = stamp as Record<string, unknown>;\n if (name !== contract || typeof version !== \"string\") return false;\n const theirs = versionParts(version);\n if (theirs === undefined) return false;\n return implemented.some((served) => {\n const ours = versionParts(served);\n if (ours === undefined || theirs[0] !== ours[0]) return false;\n return ours[0] !== 0 || theirs[1] === ours[1];\n });\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { LicenseClass } from "../plugins.js";
|
|
2
|
+
import { SPDX_LICENSE_LIST_VERSION } from "./spdx.generated.js";
|
|
3
|
+
//#region src/plugin/license.d.ts
|
|
4
|
+
/** The classes whose licenses need `--accept-license` (or a host's pre-acceptance) at install. */
|
|
5
|
+
export declare const ACKNOWLEDGED_CLASSES: ReadonlySet<LicenseClass>;
|
|
6
|
+
/** A license of the SPDX License List, as {@link spdxLicense} finds it. */
|
|
7
|
+
export interface SpdxEntry {
|
|
8
|
+
/** Its SPDX ID, in the List's own case. */
|
|
9
|
+
readonly id: string;
|
|
10
|
+
/** OSI-approved, as the List flags it. */
|
|
11
|
+
readonly osi: boolean;
|
|
12
|
+
/** Free (libre) by the FSF, as the List flags it. */
|
|
13
|
+
readonly free: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** An SPDX license ID in its canonical case with its flags, or `undefined` for one the list lacks. */
|
|
16
|
+
export declare function spdxLicense(id: string): SpdxEntry | undefined;
|
|
17
|
+
/** Whether `id` is a license reference (never OSI-approved: it names a license only its author knows). */
|
|
18
|
+
export declare function isLicenseRef(id: string): boolean;
|
|
19
|
+
/** A parsed SPDX license expression. */
|
|
20
|
+
export type LicenseExpression = {
|
|
21
|
+
readonly kind: "license";
|
|
22
|
+
readonly id: string;
|
|
23
|
+
readonly orLater: boolean;
|
|
24
|
+
} | {
|
|
25
|
+
readonly kind: "ref";
|
|
26
|
+
readonly id: string;
|
|
27
|
+
} | {
|
|
28
|
+
readonly kind: "with";
|
|
29
|
+
readonly license: LicenseExpression;
|
|
30
|
+
readonly exception: string;
|
|
31
|
+
} | {
|
|
32
|
+
readonly kind: "and" | "or";
|
|
33
|
+
readonly left: LicenseExpression;
|
|
34
|
+
readonly right: LicenseExpression;
|
|
35
|
+
};
|
|
36
|
+
/** Why an expression didn't parse. */
|
|
37
|
+
export declare class LicenseExpressionError extends Error {
|
|
38
|
+
/** `LicenseExpressionError`. */
|
|
39
|
+
override readonly name = "LicenseExpressionError";
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Parses an SPDX license expression. License and exception IDs take their canonical case;
|
|
43
|
+
* operators are read in either case, as npm's ecosystem writes them.
|
|
44
|
+
*
|
|
45
|
+
* @throws LicenseExpressionError naming what isn't valid.
|
|
46
|
+
*/
|
|
47
|
+
export declare function parseLicenseExpression(text: string): LicenseExpression;
|
|
48
|
+
/** The canonical text of an expression. */
|
|
49
|
+
export declare function formatLicenseExpression(expression: LicenseExpression, nested?: boolean): string;
|
|
50
|
+
/** One license an expression comes down to, with its class. */
|
|
51
|
+
export interface LicenseTerm {
|
|
52
|
+
/** The license's ID: an SPDX ID or a `LicenseRef-` reference, which `--accept-license` names. */
|
|
53
|
+
readonly id: string;
|
|
54
|
+
/** Its class (D31). */
|
|
55
|
+
readonly class: LicenseClass;
|
|
56
|
+
}
|
|
57
|
+
/** The class of one SPDX license ID (canonical case). */
|
|
58
|
+
export declare function spdxClass(id: string): LicenseClass;
|
|
59
|
+
/**
|
|
60
|
+
* What an expression comes down to: every license that applies, each with its class. A
|
|
61
|
+
* reference's class is `declared(id)` (what the plugin's manifest says of it, never an OSI class)
|
|
62
|
+
* or `unknown`. An `OR` keeps the branch that needs the fewest acknowledgments, then the first.
|
|
63
|
+
*/
|
|
64
|
+
export declare function licenseTerms(expression: LicenseExpression, declared?: (id: string) => LicenseClass | undefined): readonly LicenseTerm[];
|
|
65
|
+
/**
|
|
66
|
+
* The license reference Mostra gives a package whose license it can't read (no `license` field,
|
|
67
|
+
* `SEE LICENSE IN …`, a string that isn't an expression), so `--accept-license` can still name
|
|
68
|
+
* it: `LicenseRef-npm-<name>` with the name's `@` and `/` as `-`.
|
|
69
|
+
*/
|
|
70
|
+
export declare function unreadableLicenseRef(packageName: string): string;
|
|
71
|
+
/**
|
|
72
|
+
* The license expression a package's `package.json` declares: `license` (a string, or the old
|
|
73
|
+
* `{ type }` form) or the old `licenses` array (each an alternative), or `undefined`.
|
|
74
|
+
*/
|
|
75
|
+
export declare function packageLicense(manifest: {
|
|
76
|
+
readonly license?: unknown;
|
|
77
|
+
readonly licenses?: unknown;
|
|
78
|
+
}): string | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* The terms of a package's license field: its expression's, or, for a field Mostra can't read,
|
|
81
|
+
* one `unknown` term under {@link unreadableLicenseRef} (`UNLICENSED`, npm's word for "no license
|
|
82
|
+
* granted", is `proprietary`).
|
|
83
|
+
*/
|
|
84
|
+
export declare function packageLicenseTerms(packageName: string, license: string | undefined, declared?: (id: string) => LicenseClass | undefined): readonly LicenseTerm[];
|
|
85
|
+
//#endregion
|
|
86
|
+
export { SPDX_LICENSE_LIST_VERSION };
|
|
87
|
+
//# sourceMappingURL=license.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"license.d.ts","names":[],"sources":["../../src/plugin/license.ts"],"mappings":";;;;qBAaa,sBAAsB,YAAY;;iBA8B9B;;WAEN;;WAEA;;WAEA;;;wBAOK,YAAY,aAAa;;wBA2BzB,aAAa;;YAKjB;WACG;WAA0B;WAAqB;;WAC/C;WAAsB;;WACtB;WAAuB,SAAS;WAA4B;;WAE5D;WACA,MAAM;WACN,OAAO;;;qBAIT,+BAA+B;;oBAExB;;;;;;;;wBASJ,uBAAuB,eAAe;;wBA2EtC,wBAAwB,YAAY,mBAAmB;;iBAgBtD;;WAEN;;WAEA,OAAO;;;wBAIF,UAAU,aAAa;;;;;;wBAcvB,aACd,YAAY,mBACZ,YAAW,eAAe,oCAChB;;;;;;wBA2CI,qBAAqB;;;;;wBAQrB,eAAe;WACpB;WACA;;;;;;;wBAwBK,oBACd,qBACA,6BACA,YAAY,eAAe,oCACjB"}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { SPDX_EXCEPTIONS, SPDX_LICENSES, SPDX_LICENSE_LIST_VERSION } from "./spdx.generated.js";
|
|
2
|
+
//#region src/plugin/license.ts
|
|
3
|
+
/** The classes whose licenses need `--accept-license` (or a host's pre-acceptance) at install. */
|
|
4
|
+
const ACKNOWLEDGED_CLASSES = /* @__PURE__ */ new Set([
|
|
5
|
+
"source-available",
|
|
6
|
+
"proprietary",
|
|
7
|
+
"unknown"
|
|
8
|
+
]);
|
|
9
|
+
/**
|
|
10
|
+
* OSI-approved licenses that ask derivative or combined works to stay under them (copyleft,
|
|
11
|
+
* strong or weak), by family: everything else OSI-approved is `osi-permissive`. Either class
|
|
12
|
+
* needs no acknowledgment; the difference is shown.
|
|
13
|
+
*/
|
|
14
|
+
const COPYLEFT = /^(?:A?GPL|LGPL|MPL|EPL|EUPL|CDDL|CPL|OSL|RPL|SPL|Sleepycat|MS-RL|CECILL|CPAL|APSL|QPL|RPSL|NPOSL|SimPL|Watcom|IPL|OSET-PL|Motosoto|Nokia|LPL|CUA-OPL|ErlPL|SISSL|eCos|Interbase|NGPL|EFL|OCLC|LiLiQ-R|AFL)(?:[-.]|$)/;
|
|
15
|
+
/**
|
|
16
|
+
* Dedications to the public domain, and licenses that ask nothing at all: none needs an
|
|
17
|
+
* acknowledgment, OSI-approved or not (CC0 never was).
|
|
18
|
+
*/
|
|
19
|
+
const PUBLIC_DOMAIN = /* @__PURE__ */ new Set([
|
|
20
|
+
"CC0-1.0",
|
|
21
|
+
"PDDL-1.0",
|
|
22
|
+
"CC-PDDC",
|
|
23
|
+
"CC-PDM-1.0",
|
|
24
|
+
"Unlicense",
|
|
25
|
+
"0BSD",
|
|
26
|
+
"WTFPL",
|
|
27
|
+
"MIT-0"
|
|
28
|
+
]);
|
|
29
|
+
let byLowerCase;
|
|
30
|
+
let exceptionsByLowerCase;
|
|
31
|
+
/** An SPDX license ID in its canonical case with its flags, or `undefined` for one the list lacks. */
|
|
32
|
+
function spdxLicense(id) {
|
|
33
|
+
if (byLowerCase === void 0) {
|
|
34
|
+
byLowerCase = /* @__PURE__ */ new Map();
|
|
35
|
+
for (const entry of SPDX_LICENSES) {
|
|
36
|
+
const at = entry.lastIndexOf(":");
|
|
37
|
+
const licenseId = entry.slice(0, at);
|
|
38
|
+
const flags = entry.slice(at + 1);
|
|
39
|
+
byLowerCase.set(licenseId.toLowerCase(), {
|
|
40
|
+
id: licenseId,
|
|
41
|
+
osi: flags.includes("o"),
|
|
42
|
+
free: flags.includes("f")
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return byLowerCase.get(id.toLowerCase());
|
|
47
|
+
}
|
|
48
|
+
/** An SPDX exception ID in its canonical case, or `undefined`. */
|
|
49
|
+
function spdxException(id) {
|
|
50
|
+
exceptionsByLowerCase ??= new Map(SPDX_EXCEPTIONS.map((entry) => [entry.toLowerCase(), entry]));
|
|
51
|
+
return exceptionsByLowerCase.get(id.toLowerCase());
|
|
52
|
+
}
|
|
53
|
+
/** The pattern of a license reference: `LicenseRef-<idstring>`, optionally `DocumentRef-<idstring>:` first. */
|
|
54
|
+
const LICENSE_REF = /^(?:DocumentRef-[A-Za-z0-9.-]+:)?LicenseRef-[A-Za-z0-9.-]+$/;
|
|
55
|
+
/** Whether `id` is a license reference (never OSI-approved: it names a license only its author knows). */
|
|
56
|
+
function isLicenseRef(id) {
|
|
57
|
+
return LICENSE_REF.test(id);
|
|
58
|
+
}
|
|
59
|
+
/** Why an expression didn't parse. */
|
|
60
|
+
var LicenseExpressionError = class extends Error {
|
|
61
|
+
/** `LicenseExpressionError`. */
|
|
62
|
+
name = "LicenseExpressionError";
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Parses an SPDX license expression. License and exception IDs take their canonical case;
|
|
66
|
+
* operators are read in either case, as npm's ecosystem writes them.
|
|
67
|
+
*
|
|
68
|
+
* @throws LicenseExpressionError naming what isn't valid.
|
|
69
|
+
*/
|
|
70
|
+
function parseLicenseExpression(text) {
|
|
71
|
+
const tokens = text.match(/\(|\)|[^\s()]+/g) ?? [];
|
|
72
|
+
if (tokens.length === 0) throw new LicenseExpressionError("The license expression is empty.");
|
|
73
|
+
let at = 0;
|
|
74
|
+
const peek = () => tokens[at];
|
|
75
|
+
const operator = (word) => {
|
|
76
|
+
const upper = word?.toUpperCase();
|
|
77
|
+
return upper === "AND" || upper === "OR" || upper === "WITH" ? upper : void 0;
|
|
78
|
+
};
|
|
79
|
+
const simple = () => {
|
|
80
|
+
const token = tokens[at++];
|
|
81
|
+
if (token === void 0) throw new LicenseExpressionError("The expression ends too early.");
|
|
82
|
+
if (token === "(") {
|
|
83
|
+
const inner = or();
|
|
84
|
+
if (tokens[at++] !== ")") throw new LicenseExpressionError("A parenthesis isn't closed.");
|
|
85
|
+
return inner;
|
|
86
|
+
}
|
|
87
|
+
if (token === ")" || operator(token) !== void 0) throw new LicenseExpressionError(`"${token}" can't start a license.`);
|
|
88
|
+
if (isLicenseRef(token)) return {
|
|
89
|
+
kind: "ref",
|
|
90
|
+
id: token
|
|
91
|
+
};
|
|
92
|
+
const orLater = token.endsWith("+");
|
|
93
|
+
const known = spdxLicense(orLater ? token.slice(0, -1) : token);
|
|
94
|
+
if (known === void 0) throw new LicenseExpressionError(`"${token}" isn't an SPDX license ID or a LicenseRef- reference.`);
|
|
95
|
+
return {
|
|
96
|
+
kind: "license",
|
|
97
|
+
id: known.id,
|
|
98
|
+
orLater
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
const withExpression = () => {
|
|
102
|
+
const license = simple();
|
|
103
|
+
if (operator(peek()) !== "WITH") return license;
|
|
104
|
+
at += 1;
|
|
105
|
+
const token = tokens[at++];
|
|
106
|
+
const exception = token === void 0 ? void 0 : spdxException(token) ?? (/^(?:DocumentRef-[A-Za-z0-9.-]+:)?AdditionRef-[A-Za-z0-9.-]+$/.test(token) ? token : void 0);
|
|
107
|
+
if (exception === void 0) throw new LicenseExpressionError(`"${token ?? ""}" isn't an SPDX license exception.`);
|
|
108
|
+
if (license.kind !== "license" && license.kind !== "ref") throw new LicenseExpressionError("WITH applies to one license.");
|
|
109
|
+
return {
|
|
110
|
+
kind: "with",
|
|
111
|
+
license,
|
|
112
|
+
exception
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
const and = () => {
|
|
116
|
+
let left = withExpression();
|
|
117
|
+
while (operator(peek()) === "AND") {
|
|
118
|
+
at += 1;
|
|
119
|
+
left = {
|
|
120
|
+
kind: "and",
|
|
121
|
+
left,
|
|
122
|
+
right: withExpression()
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
return left;
|
|
126
|
+
};
|
|
127
|
+
const or = () => {
|
|
128
|
+
let left = and();
|
|
129
|
+
while (operator(peek()) === "OR") {
|
|
130
|
+
at += 1;
|
|
131
|
+
left = {
|
|
132
|
+
kind: "or",
|
|
133
|
+
left,
|
|
134
|
+
right: and()
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
return left;
|
|
138
|
+
};
|
|
139
|
+
const expression = or();
|
|
140
|
+
if (at < tokens.length) throw new LicenseExpressionError(`"${tokens[at]}" doesn't belong where it is.`);
|
|
141
|
+
return expression;
|
|
142
|
+
}
|
|
143
|
+
/** The canonical text of an expression. */
|
|
144
|
+
function formatLicenseExpression(expression, nested = false) {
|
|
145
|
+
switch (expression.kind) {
|
|
146
|
+
case "license": return `${expression.id}${expression.orLater ? "+" : ""}`;
|
|
147
|
+
case "ref": return expression.id;
|
|
148
|
+
case "with": return `${formatLicenseExpression(expression.license)} WITH ${expression.exception}`;
|
|
149
|
+
default: {
|
|
150
|
+
const text = `${formatLicenseExpression(expression.left, expression.kind === "and")} ${expression.kind.toUpperCase()} ${formatLicenseExpression(expression.right, expression.kind === "and")}`;
|
|
151
|
+
return nested && expression.kind === "or" ? `(${text})` : text;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/** The class of one SPDX license ID (canonical case). */
|
|
156
|
+
function spdxClass(id) {
|
|
157
|
+
const known = spdxLicense(id);
|
|
158
|
+
if (known === void 0) return "unknown";
|
|
159
|
+
if (PUBLIC_DOMAIN.has(known.id)) return "public-domain";
|
|
160
|
+
if (known.osi) return COPYLEFT.test(known.id) ? "osi-copyleft" : "osi-permissive";
|
|
161
|
+
if (known.free) return "free";
|
|
162
|
+
return "source-available";
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* What an expression comes down to: every license that applies, each with its class. A
|
|
166
|
+
* reference's class is `declared(id)` (what the plugin's manifest says of it, never an OSI class)
|
|
167
|
+
* or `unknown`. An `OR` keeps the branch that needs the fewest acknowledgments, then the first.
|
|
168
|
+
*/
|
|
169
|
+
function licenseTerms(expression, declared = () => void 0) {
|
|
170
|
+
const needs = (terms) => terms.filter((term) => ACKNOWLEDGED_CLASSES.has(term.class)).length;
|
|
171
|
+
const walk = (node) => {
|
|
172
|
+
switch (node.kind) {
|
|
173
|
+
case "license": return [{
|
|
174
|
+
id: node.id,
|
|
175
|
+
class: spdxClass(node.id)
|
|
176
|
+
}];
|
|
177
|
+
case "ref": {
|
|
178
|
+
const declaredClass = declared(node.id);
|
|
179
|
+
return [{
|
|
180
|
+
id: node.id,
|
|
181
|
+
class: declaredClass !== void 0 && ACKNOWLEDGED_CLASSES.has(declaredClass) ? declaredClass : "unknown"
|
|
182
|
+
}];
|
|
183
|
+
}
|
|
184
|
+
case "with": return walk(node.license);
|
|
185
|
+
case "and": {
|
|
186
|
+
const terms = [...walk(node.left)];
|
|
187
|
+
for (const term of walk(node.right)) if (!terms.some((other) => other.id === term.id)) terms.push(term);
|
|
188
|
+
return terms;
|
|
189
|
+
}
|
|
190
|
+
case "or": {
|
|
191
|
+
const left = walk(node.left);
|
|
192
|
+
const right = walk(node.right);
|
|
193
|
+
return needs(right) < needs(left) ? right : left;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
return walk(expression);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* The license reference Mostra gives a package whose license it can't read (no `license` field,
|
|
201
|
+
* `SEE LICENSE IN …`, a string that isn't an expression), so `--accept-license` can still name
|
|
202
|
+
* it: `LicenseRef-npm-<name>` with the name's `@` and `/` as `-`.
|
|
203
|
+
*/
|
|
204
|
+
function unreadableLicenseRef(packageName) {
|
|
205
|
+
return `LicenseRef-npm-${packageName.replace(/^@/, "").replace(/[^A-Za-z0-9.-]/g, "-")}`;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* The license expression a package's `package.json` declares: `license` (a string, or the old
|
|
209
|
+
* `{ type }` form) or the old `licenses` array (each an alternative), or `undefined`.
|
|
210
|
+
*/
|
|
211
|
+
function packageLicense(manifest) {
|
|
212
|
+
const text = (value) => typeof value === "string" ? value : typeof value === "object" && value !== null && typeof value.type === "string" ? value.type : void 0;
|
|
213
|
+
const single = text(manifest.license);
|
|
214
|
+
if (single !== void 0) return single.trim();
|
|
215
|
+
if (Array.isArray(manifest.licenses)) {
|
|
216
|
+
const all = manifest.licenses.map(text).filter((value) => value !== void 0);
|
|
217
|
+
if (all.length > 0) return all.length === 1 ? all[0] : `(${all.join(" OR ")})`;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* The terms of a package's license field: its expression's, or, for a field Mostra can't read,
|
|
222
|
+
* one `unknown` term under {@link unreadableLicenseRef} (`UNLICENSED`, npm's word for "no license
|
|
223
|
+
* granted", is `proprietary`).
|
|
224
|
+
*/
|
|
225
|
+
function packageLicenseTerms(packageName, license, declared) {
|
|
226
|
+
if (license === "UNLICENSED") return [{
|
|
227
|
+
id: unreadableLicenseRef(packageName),
|
|
228
|
+
class: "proprietary"
|
|
229
|
+
}];
|
|
230
|
+
if (license !== void 0) try {
|
|
231
|
+
return licenseTerms(parseLicenseExpression(license), declared);
|
|
232
|
+
} catch (error) {
|
|
233
|
+
if (!(error instanceof LicenseExpressionError)) throw error;
|
|
234
|
+
}
|
|
235
|
+
return [{
|
|
236
|
+
id: unreadableLicenseRef(packageName),
|
|
237
|
+
class: "unknown"
|
|
238
|
+
}];
|
|
239
|
+
}
|
|
240
|
+
//#endregion
|
|
241
|
+
export { ACKNOWLEDGED_CLASSES, LicenseExpressionError, SPDX_LICENSE_LIST_VERSION, formatLicenseExpression, isLicenseRef, licenseTerms, packageLicense, packageLicenseTerms, parseLicenseExpression, spdxClass, spdxLicense, unreadableLicenseRef };
|
|
242
|
+
|
|
243
|
+
//# sourceMappingURL=license.js.map
|